Git-Url:
http://git.frugalware.org/gitweb/gitweb.cgi?p=gfpm.git;a=commitdiff;h=e21eca298d9b245c8dc6c0c69b5be94df7a8490d
commit e21eca298d9b245c8dc6c0c69b5be94df7a8490d
Author: Priyank <[EMAIL PROTECTED]>
Date: Sun Jul 6 20:48:25 2008 +0530
gfpm-config: initial import
diff --git a/src/gfpm-config.c b/src/gfpm-config.c
new file mode 100644
index 0000000..e58ac4f
--- /dev/null
+++ b/src/gfpm-config.c
@@ -0,0 +1,157 @@
+/*
+ * gfpm-config.c for gfpm
+ *
+ * Copyright (C) 2008 by Priyank Gosalia <[EMAIL PROTECTED]>
+ * Portions of this code are borrowed from gimmix
+ * gimmix is Copyright (C) 2006-2007 Priyank Gosalia <[EMAIL PROTECTED]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <gtk/gtk.h>
+#include "gfpm-config.h"
+
+#define CONFIG_FILE ".gfpmrc"
+
+static ConfigFile conf;
+
+void
+gfpm_config_init (void)
+{
+ char *rcfile = NULL;
+
+ cfg_init_config_file_struct (&conf);
+ cfg_add_key (&conf, "show_compressed_size", "false");
+ cfg_add_key (&conf, "show_uncompressed_size", "false");
+
+ rcfile = cfg_get_path_to_config_file (CONFIG_FILE);
+ if (cfg_read_config_file (&conf, rcfile) != 0)
+ {
+ goto cleanup;
+ }
+ else
+ {
+ if (!gfpm_config_get_value_bool("show_compressed_size"))
+ cfg_add_key (&conf, "show_compressed_size", "false");
+ if (!gfpm_config_get_value_bool("show_uncompressed_size"))
+ cfg_add_key (&conf, "show_uncompressed_size", "false");
+ }
+ cleanup:
+ gfpm_config_save ();
+ g_free (rcfile);
+
+ return;
+}
+
+char *
+gfpm_config_get_value_string (const char *key)
+{
+ char *ret = NULL;
+
+ ret = cfg_get_key_value (conf, (char*)key);
+
+ return ret;
+}
+
+gboolean
+gfpm_config_get_value_bool (const char *key)
+{
+ gboolean ret = FALSE;
+
+ if (!strcmp(cfg_get_key_value(conf,(char*)key),"true"))
+ ret = TRUE;
+
+ return ret;
+}
+
+int
+gfpm_config_get_value_int (const char *key)
+{
+ int ret = -1;
+
+ ret = atoi (cfg_get_key_value (conf, (char*)key));
+
+ return ret;
+}
+
+void
+gfpm_config_set_value_string (const char *key, char *value)
+{
+ cfg_add_key (&conf, (char*)key, value);
+
+ return;
+}
+
+void
+gfpm_config_set_value_int (const char *key, int value)
+{
+ char *val = g_strdup_printf ("%d", value);
+ cfg_add_key (&conf, (char*)key, val);
+ g_free (val);
+
+ return;
+}
+
+void
+gfpm_config_set_value_bool (const char *key, gboolean value)
+{
+ if (value)
+ cfg_add_key (&conf, (char*)key, "true");
+ else
+ cfg_add_key (&conf, (char*)key, "false");
+
+ return;
+}
+
+void
+gfpm_config_save (void)
+{
+ char *rcfile;
+
+ rcfile = cfg_get_path_to_config_file (CONFIG_FILE);
+ cfg_write_config_file (&conf, rcfile);
+ chmod (rcfile, S_IRUSR|S_IWUSR);
+ g_free (rcfile);
+
+ return;
+}
+
+bool
+gfpm_config_exists (void)
+{
+ char *config_file = NULL;
+ bool status;
+
+ config_file = cfg_get_path_to_config_file (CONFIG_FILE);
+ if (g_file_test(config_file, G_FILE_TEST_EXISTS))
+ status = true;
+ else
+ status = false;
+
+ free (config_file);
+ return status;
+}
+
+void
+gfpm_config_free (void)
+{
+ cfg_free_config_file_struct (&conf);
+
+ return;
+}
+
diff --git a/src/gfpm-config.h b/src/gfpm-config.h
new file mode 100644
index 0000000..7915355
--- /dev/null
+++ b/src/gfpm-config.h
@@ -0,0 +1,39 @@
+#ifndef _GFPM_CONFIG_H_
+#define _GFPM_CONFIG_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <glib.h>
+#include "wejpconfig.h"
+
+/* Returns true if file exists otherwise false */
+bool gfpm_config_exists (void);
+
+/* Parse config file and set the initial config values */
+void gfpm_config_init (void);
+
+/* Save current settings back to gfpmrc */
+void gfpm_config_save (void);
+
+/* Read a value from gfpmrc and return it as a string */
+char * gfpm_config_get_value_string (const char *);
+
+/* Read a value from gfpmrc and return it as a gboolean */
+gboolean gfpm_config_get_value_bool (const char *);
+
+/* Read a value from gfpmrc and return it as an int */
+int gfpm_config_get_value_int (const char *);
+
+/* Set a value for a particular key in gfpmrc (int) */
+void gfpm_config_set_value_int (const char *, int);
+
+/* Set a value for a particular key in gfpmrc (string) */
+void gfpm_config_set_value_string (const char *, char *);
+
+/* Set a value for a particular key in gfpmrc (gboolean) */
+void gfpm_config_set_value_bool (const char *, gboolean);
+
+/* Free conf */
+void gfpm_config_free (void);
+
+#endif
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git