Git-Url:
http://git.frugalware.org/gitweb/gitweb.cgi?p=fun.git;a=commitdiff;h=6f4a50a9143d1623cb03ab1de031a2736394bb6d
commit 6f4a50a9143d1623cb03ab1de031a2736394bb6d
Author: Priyank <[EMAIL PROTECTED]>
Date: Sat Nov 3 12:18:32 2007 +0530
fun-config: a wrapper to access the configuration file from wejpconfig
* Initial import
diff --git a/src/Makefile.am b/src/Makefile.am
index 078dcf3..966da1d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,7 +7,9 @@ sbin_PROGRAMS = fund
bin_PROGRAMS = fun
fund_SOURCES = fund.c
-fun_SOURCES = eggtrayicon.c \
+fun_SOURCES = wejpconfig.c \
+ fun-config.c \
+ eggtrayicon.c \
sexy-tooltip.c \
fun-tooltip.c \
fun-ui.c \
diff --git a/src/fun-config.c b/src/fun-config.c
new file mode 100644
index 0000000..47cee83
--- /dev/null
+++ b/src/fun-config.c
@@ -0,0 +1,112 @@
+/*
+ * fun-config.c for fun
+ *
+ * Copyright (C) 2007 by Priyank Gosalia <[EMAIL PROTECTED]>
+ * Portions of this code are borrowed fron 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 "fun-config.h"
+
+#define CONFIG_FILE ".funrc"
+
+static ConfigFile conf;
+
+bool
+fun_config_init (void)
+{
+ char *rcfile = NULL;
+
+ cfg_init_config_file_struct (&conf);
+ cfg_add_key (&conf, "update_interval", "60");
+ rcfile = cfg_get_path_to_config_file (CONFIG_FILE);
+ if (cfg_read_config_file (&conf, rcfile) != 0)
+ {
+ fun_config_save ();
+ g_free (rcfile);
+ return false;
+ }
+ else
+ {
+ g_free (rcfile);
+ return true;
+ }
+
+ return false;
+}
+
+char *
+fun_config_get_value_string (const char *key)
+{
+ char *ret = NULL;
+
+ ret = cfg_get_key_value (conf, (char*)key);
+
+ return ret;
+}
+
+int
+fun_config_get_value_int (const char *key)
+{
+ int ret = -1;
+
+ ret = atoi (cfg_get_key_value (conf, (char*)key));
+
+ return ret;
+}
+
+void
+fun_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
+fun_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
+fun_config_free (void)
+{
+ cfg_free_config_file_struct (&conf);
+
+ return;
+}
+
diff --git a/src/fun-config.h b/src/fun-config.h
new file mode 100644
index 0000000..ce8ff99
--- /dev/null
+++ b/src/fun-config.h
@@ -0,0 +1,26 @@
+#ifndef _FUN_CONFIG_H_
+#define _FUN_CONFIG_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include "wejpconfig.h"
+
+/* Returns true if file exists otherwise false */
+bool fun_config_exists (void);
+
+/* Parse config file and set the initial config values */
+bool fun_config_init (void);
+
+/* Save current settings back to funrc */
+void fun_config_save (void);
+
+/* Read a value from funrc and return it as a string */
+char * fun_config_get_value_string (const char *);
+
+/* Read a value from funrc and return it as an int */
+int fun_config_get_value_int (const char *);
+
+/* Free conf */
+void fun_config_free (void);
+
+#endif
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git