[beryl-commits] r1460 - in trunk/beryl-core: include libberylsettings

quinn at server.beryl-project.org quinn at server.beryl-project.org
Sat Dec 2 00:22:06 CET 2006


Author: quinn
Date: 2006-12-02 00:22:06 +0100 (Sat, 02 Dec 2006)
New Revision: 1460

Modified:
   trunk/beryl-core/include/beryl-settings.h
   trunk/beryl-core/libberylsettings/main.c
Log:
lib-beryl-settings:
-basic framework for using loadable modules, loading not yet implemented


Modified: trunk/beryl-core/include/beryl-settings.h
===================================================================
--- trunk/beryl-core/include/beryl-settings.h	2006-11-29 22:52:29 UTC (rev 1459)
+++ trunk/beryl-core/include/beryl-settings.h	2006-12-01 23:22:06 UTC (rev 1460)
@@ -9,14 +9,34 @@
 //        the options of type STRING and LIST[STRING] that have a list
 //        of allowed values set.
 
-typedef struct _BerylSettingsContext
+typedef struct _BerylSettingsContext BerylSettingsContext;
+typedef struct _BerylSetting BerylSetting;
+
+typedef gboolean (*BerylSettingsContextReadInitFunc) (BerylSettingsContext * context);
+typedef void (*BerylSettingsContextReadDoneFunc) (BerylSettingsContext * context);
+typedef gboolean (*BerylSettingsContextWriteInitFunc) (BerylSettingsContext * context);
+typedef void (*BerylSettingsContextWriteDoneFunc) (BerylSettingsContext * context);
+typedef void (*BerylSettingsContextReadSettingFunc) 
+    (BerylSettingsContext * context, BerylSetting * setting);
+typedef void (*BerylSettingsContextWriteSettingFunc) 
+    (BerylSettingsContext * context, BerylSetting * setting);
+
+struct _BerylSettingsContext
 {
     GSList   *  plugins;    // list_of(BerylSettingsPlugin *), including the core pseudo-plugin
                             //      which is identified by name==NULL
     gboolean    is_comp;    // set to TRUE if this context is created by _comp_new
     gpointer    private_ptr;
-} BerylSettingsContext;
 
+    gpointer	backend_private_ptr;
+    BerylSettingsContextReadInitFunc		read_init;
+    BerylSettingsContextReadDoneFunc		read_done;
+    BerylSettingsContextWriteInitFunc		write_init;
+    BerylSettingsContextWriteDoneFunc		write_done;
+    BerylSettingsContextReadSettingFunc		read_setting;
+    BerylSettingsContextWriteSettingFunc	write_setting;
+};
+
 typedef struct _BerylSettingsPlugin
 {
     gchar    *  gettext_domain;     // gettext domain for the plugin
@@ -151,8 +171,6 @@
     GSList                    * as_list;        // list_of(BerylSettingValue *)
 } BerylSettingValueUnion;
 
-typedef struct _BerylSetting BerylSetting;
-
 typedef struct _BerylSettingValue
 {
     BerylSettingValueUnion      value;

Modified: trunk/beryl-core/libberylsettings/main.c
===================================================================
--- trunk/beryl-core/libberylsettings/main.c	2006-11-29 22:52:29 UTC (rev 1459)
+++ trunk/beryl-core/libberylsettings/main.c	2006-12-01 23:22:06 UTC (rev 1460)
@@ -734,8 +734,7 @@
     memcpy(color_val.array.array,array,sizeof(gint)*4);
     beryl_setting_value_set_color(value,&color_val);
 }
-
-static void read_setting(BerylSetting * setting, GKeyFile * f)
+static void read_setting_ini(BerylSetting * setting, GKeyFile * f)
 {
     const gchar * groupname;
     gchar * keyname;
@@ -965,7 +964,13 @@
     }
     g_free(keyname);
 }
-
+static void read_setting(BerylSetting * setting, BerylSettingsContext * c)
+{
+    if (c->read_setting)
+	c->read_setting(c,setting);
+    else
+	read_setting_ini(setting, c->backend_private_ptr);
+}
 static void set_array_from_binding(gint * array, BerylSettingValue * value)
 {
     array[0]=value->value.as_binding.button_mod_mask;
@@ -1017,7 +1022,7 @@
     *ptr+=4;
 }
 
-static void write_setting(BerylSetting * setting, GKeyFile * f)
+static void write_setting_ini(BerylSetting * setting, GKeyFile * f)
 {
     gchar * groupname=setting->parent->name?setting->parent->name:"_";
     gchar * keyname=g_strconcat(setting->is_screen?"s_":"a_",setting->name,NULL);
@@ -1109,7 +1114,7 @@
                 {
                     nkeyname=g_strconcat(keyname,"__edge",NULL);
                     int ema;
-                    gchar * edge="None";
+                    const gchar * edge="None";
                     if (beryl_setting_value_get_edgemask(&setting->value,&ema))
                     {
                         int i;
@@ -1210,15 +1215,23 @@
     }
     g_free(keyname);
 }
-
-static void read_settings_for_plugin(BerylSettingsPlugin * plugin, GKeyFile * f)
+static void write_setting(BerylSetting * setting, BerylSettingsContext * c)
 {
-    g_slist_foreach(plugin->settings,(GFunc)read_setting,f);
+    if (c->write_setting)
+	c->write_setting(c,setting);
+    else
+	write_setting_ini(setting,c->backend_private_ptr);
 }
+static void read_settings_for_plugin(BerylSettingsPlugin * plugin, 
+	BerylSettingsContext * c)
+{
+    g_slist_foreach(plugin->settings,(GFunc)read_setting,c);
+}
 
-static void write_settings_for_plugin(BerylSettingsPlugin * plugin, GKeyFile * f)
+static void write_settings_for_plugin(BerylSettingsPlugin * plugin, 
+	BerylSettingsContext * c)
 {
-    g_slist_foreach(plugin->settings,(GFunc)write_setting,f);
+    g_slist_foreach(plugin->settings,(GFunc)write_setting,c);
 }
 
 typedef struct _BerylFindListSettingIndex
@@ -1270,6 +1283,56 @@
         return &value->parent->info;
 }
 
+static gboolean read_init_ini(BerylSettingsContext * c)
+{
+    GKeyFile * f;
+    gchar * path = g_strconcat(g_get_home_dir(),"/.beryl/settings",NULL);
+    f=g_key_file_new();
+    if (!g_key_file_load_from_file(f,path,0,NULL))
+    {
+        g_key_file_free(f);
+        g_free(path);
+        return FALSE;
+    }
+    g_free(path);
+    c->backend_private_ptr=f;
+    return TRUE;
+}
+static void read_done_ini(BerylSettingsContext * c)
+{
+    g_key_file_free(c->backend_private_ptr);
+}
+static gboolean write_init_ini(BerylSettingsContext * c)
+{
+    GKeyFile * f;
+    gchar * path = g_strconcat(g_get_home_dir(),"/.beryl/",NULL);
+    g_mkdir_with_parents(path,00755); // ensure path exists
+    g_free(path);
+    path=g_strconcat(g_get_home_dir(),"/.beryl/settings",NULL);
+    f=g_key_file_new();
+    g_key_file_load_from_file(f,path,0,NULL);
+    g_free(path);
+    c->backend_private_ptr=f;
+    return TRUE;
+}
+static void write_done_ini(BerylSettingsContext * c)
+{
+    GKeyFile * f = c->backend_private_ptr;
+    gchar * path=g_strconcat(g_get_home_dir(),"/.beryl/settings",NULL);
+    gchar * data;
+    if (g_file_test(path,G_FILE_TEST_IS_SYMLINK))
+    {
+        gchar * tmp = path;
+        path=g_file_read_link(path,NULL);
+        g_free(tmp);
+    }
+    data = g_key_file_to_data(f,NULL,NULL);
+    g_file_set_contents(path,data,-1,NULL);
+    g_free(path);
+    g_free(data);
+    g_key_file_free(f);
+}
+
 //EXPORTED FUNCTIONS
 BerylSettingsContext * beryl_settings_context_new(void)
 {
@@ -1313,42 +1376,36 @@
 
 void beryl_settings_context_read(BerylSettingsContext * context)
 {
-    GKeyFile * f;
-    gchar * path = g_strconcat(g_get_home_dir(),"/.beryl/settings",NULL);
-    f=g_key_file_new();
-    if (!g_key_file_load_from_file(f,path,0,NULL))
+    if (context->read_init)
     {
-        g_key_file_free(f);
-        g_free(path);
-        return;
+	if (!context->read_init(context)) return;
     }
-    g_free(path);
-    g_slist_foreach(context->plugins,(GFunc)read_settings_for_plugin,f);
-    g_key_file_free(f);
+    else
+    {
+	if (!read_init_ini(context)) return;
+    }
+    g_slist_foreach(context->plugins,(GFunc)read_settings_for_plugin,context);
+    if (context->read_done)
+	context->read_done(context);
+    else
+	read_done_ini(context);
 }
 
 void beryl_settings_context_write(BerylSettingsContext * context)
 {
-    GKeyFile * f;
-    gchar * path = g_strconcat(g_get_home_dir(),"/.beryl/",NULL);
-    gchar * data;
-    g_mkdir_with_parents(path,00755); // ensure path exists
-    g_free(path);
-    path=g_strconcat(g_get_home_dir(),"/.beryl/settings",NULL);
-    f=g_key_file_new();
-    g_key_file_load_from_file(f,path,0,NULL);
-    g_slist_foreach(context->plugins,(GFunc)write_settings_for_plugin,f);
-    if (g_file_test(path,G_FILE_TEST_IS_SYMLINK))
+    if (context->write_init)
     {
-        gchar * tmp = path;
-        path=g_file_read_link(path,NULL);
-        g_free(tmp);
+	if (!context->write_init(context)) return;
     }
-    data = g_key_file_to_data(f,NULL,NULL);
-    g_file_set_contents(path,data,-1,NULL);
-    g_free(path);
-    g_free(data);
-    g_key_file_free(f);
+    else
+    {
+	if (!write_init_ini(context)) return;
+    }
+    g_slist_foreach(context->plugins,(GFunc)write_settings_for_plugin,context);
+    if (context->write_done)
+	context->write_done(context);
+    else
+	write_done_ini(context);
 }
 
 BerylSettingsContext * beryl_settings_context_comp_new(void)




More information about the commits mailing list