summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquinn <quinn@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2006-12-18 13:21:42 +0000
committerquinn <quinn@d7aaf104-2d23-0410-ae22-9d23157bf5a3>2006-12-18 13:21:42 +0000
commit867e22842792db887e5bfc77837732614105fb18 (patch)
tree8a69110409aa37d6e57c86f878356bf388e85b50
parent5f37b86c9415e3651b4d29f9a783eb4a4ec436a8 (diff)
downloadmarex-dev-867e22842792db887e5bfc77837732614105fb18.tar.gz
marex-dev-867e22842792db887e5bfc77837732614105fb18.tar.bz2
libberylsettings:
-implement most of onestone's proposal, haven't updated any backends to set readonly/integrated or use profiles yet git-svn-id: file:///beryl/trunk@1869 d7aaf104-2d23-0410-ae22-9d23157bf5a3
-rw-r--r--beryl-core/include/beryl-settings-backend.h2
-rw-r--r--beryl-core/include/beryl-settings.h20
-rw-r--r--beryl-core/libberylsettings/main.c118
3 files changed, 132 insertions, 8 deletions
diff --git a/beryl-core/include/beryl-settings-backend.h b/beryl-core/include/beryl-settings-backend.h
index 39bbbc9..919635a 100644
--- a/beryl-core/include/beryl-settings-backend.h
+++ b/beryl-core/include/beryl-settings-backend.h
@@ -7,4 +7,6 @@ gboolean write_init (BerylSettingsContext * context);
void write_done (BerylSettingsContext * context);
void read_setting(BerylSettingsContext * context, BerylSetting * setting);
void write_setting(BerylSettingsContext * context, BerylSetting * setting);
+gboolean get_setting_is_integrated(BerylSetting * setting);
+gboolean get_setting_is_read_only(BerylSetting * setting);
#endif
diff --git a/beryl-core/include/beryl-settings.h b/beryl-core/include/beryl-settings.h
index 324062c..d480ea3 100644
--- a/beryl-core/include/beryl-settings.h
+++ b/beryl-core/include/beryl-settings.h
@@ -31,6 +31,9 @@ typedef void (*BerylSettingsContextReadSettingFunc)
typedef void (*BerylSettingsContextWriteSettingFunc)
(BerylSettingsContext * context, BerylSetting * setting);
+typedef gboolean (*BerylSettingGetIsIntegratedFunc) (BerylSetting * setting);
+typedef gboolean (*BerylSettingGetIsReadOnlyFunc) (BerylSetting * setting);
+
struct _BerylSettingsContext
{
GSList * plugins; // list_of(BerylSettingsPlugin *), including the core pseudo-plugin
@@ -40,6 +43,8 @@ struct _BerylSettingsContext
gpointer private_ptr;
gpointer backend_private_ptr;
+ BerylSettingGetIsIntegratedFunc get_setting_is_integrated;
+ BerylSettingGetIsReadOnlyFunc get_setting_is_read_only;
BerylSettingsContextReadInitFunc read_init;
BerylSettingsContextReadDoneFunc read_done;
BerylSettingsContextWriteInitFunc write_init;
@@ -230,10 +235,6 @@ struct _BerylSetting
// the set will occur and this of course will be set to FALSE
BerylSettingsPlugin * parent;
gpointer private_ptr;
-
- gboolean de_integrated; // this setting is integrated into the
- // desktop environment setting system
- gboolean read_only; // the backend ignores changes to this setting
};
BerylSettingsContext * beryl_settings_context_new(void);
@@ -529,4 +530,15 @@ const gchar * beryl_settings_plugin_category_get_name(BerylSettingsPluginCategor
const gchar * beryl_settings_plugin_category_get_short_desc(BerylSettingsPluginCategory * category);
const gchar * beryl_settings_plugin_category_get_long_desc(BerylSettingsPluginCategory * category);
GSList * beryl_settings_plugin_category_get_plugins(BerylSettingsPluginCategory * category);
+
+void beryl_settings_context_set_profile(BerylSettingsContext * context, gchar * profile);
+gchar * beryl_settings_context_get_profile(BerylSettingsContext * context);
+
+void beryl_settings_context_set_de_integration_enabled(BerylSettingsContext * context, gboolean enable_integration);
+
+gboolean beryl_settings_context_get_de_integration_enabled(BerylSettingsContext * context);
+
+gboolean beryl_settings_context_get_setting_is_read_only(BerylSettingsContext * context, BerylSetting * setting);
+gboolean beryl_settings_context_get_setting_is_de_integrated(BerylSettingsContext * context, BerylSetting * setting);
+
#endif
diff --git a/beryl-core/libberylsettings/main.c b/beryl-core/libberylsettings/main.c
index 75196f8..aa24d08 100644
--- a/beryl-core/libberylsettings/main.c
+++ b/beryl-core/libberylsettings/main.c
@@ -12,6 +12,12 @@
CompDisplay *display = NULL;
+typedef enum
+{
+ OPT_BACKEND,
+ OPT_PROFILE,
+} generalOption;
+
#define NEW(a,b) \
a * b = malloc(sizeof(a)); memset((b),0,sizeof(a))
@@ -249,8 +255,6 @@ static void init_option(BerylSettingsPlugin * plugin, CompOption * o, gboolean i
setting->displayHints=g_strdup(o->displayHints);
setting->type=translate_type(o->type);
setting->default_value.parent=setting;
- setting->read_only = FALSE;
- setting->de_integrated = FALSE;
if (setting->type==BERYL_SETTING_TYPE_LIST)
{
NEW(BerylSettingInfo,list_info);
@@ -837,6 +841,60 @@ static BerylSettingInfo * get_info(BerylSettingValue * value)
return &value->parent->info;
}
+static void init_general_options(BerylSettingsContext * context)
+{
+ GKeyFile * f;
+ gchar * s;
+ s = g_strconcat(g_get_home_dir(),"/.beryl/libberylsettings.ini",NULL);
+ f = g_key_file_new();
+ g_key_file_load_from_file(f,s,0,NULL);
+ g_free(s);
+ s=g_key_file_get_string(f,"general","backend",NULL);
+ if (!s)
+ beryl_settings_context_set_backend(context,"ini");
+ else
+ {
+ if (!beryl_settings_context_set_backend(context,s))
+ beryl_settings_context_set_backend(context,"ini");
+ g_free(s);
+ }
+ s=g_key_file_get_string(f,"general","profile",NULL);
+ beryl_settings_context_set_profile(context,s);
+ if (s)
+ g_free(s);
+ g_key_file_free(f);
+}
+
+static void save_general_option(BerylSettingsContext * context, generalOption opt)
+{
+ GKeyFile * f;
+ gchar * s;
+ s = g_strconcat(g_get_home_dir(),"/.beryl/",NULL);
+ g_mkdir_with_parents(s,0755);
+ g_free(s);
+ s = g_strconcat(g_get_home_dir(),"/.beryl/libberylsettings.ini",NULL);
+ f = g_key_file_new();
+ g_key_file_load_from_file(f,s,0,NULL);
+ switch(opt)
+ {
+ case OPT_BACKEND:
+ g_key_file_set_string(f,"general","backend",context->backend);
+ break;
+ case OPT_PROFILE:
+ if (!context->profile)
+ g_key_file_remove_key(f,"general","profile",NULL);
+ else
+ g_key_file_set_string(f,"general","profile",context->profile);
+ break;
+ }
+ gchar * d;
+ d=g_key_file_to_data(f,NULL,NULL);
+ g_file_set_contents(s,d,-1,NULL);
+ g_free(d);
+ g_free(s);
+ g_key_file_free(f);
+}
+
//EXPORTED FUNCTIONS
BerylSettingsContext * beryl_settings_context_new(void)
{
@@ -850,7 +908,7 @@ BerylSettingsContext * beryl_settings_context_new(void)
// will lead to the home version being loaded
g_free(homeplugins);
collate_categories(context);
- beryl_settings_context_set_backend(context,"ini");
+ init_general_options(context);
// by default we want de integration
context->de_integration = TRUE;
return context;
@@ -896,6 +954,7 @@ gboolean beryl_settings_context_set_backend(BerylSettingsContext * context,
g_free(dlname);
return FALSE;
}
+
context->backend=g_strdup(backend);
#define LOAD_ITEM(n) \
context->n =dlsym(context->backend_dlhand,#n);\
@@ -907,6 +966,10 @@ gboolean beryl_settings_context_set_backend(BerylSettingsContext * context,
LOAD_ITEM(read_done);
LOAD_ITEM(write_init);
LOAD_ITEM(write_done);
+ LOAD_ITEM(get_setting_is_integrated);
+ LOAD_ITEM(get_setting_is_read_only);
+
+ save_general_option(context,OPT_BACKEND);
return TRUE;
}
@@ -914,6 +977,7 @@ void beryl_settings_context_destroy(BerylSettingsContext * context)
{
int i;
g_slist_foreach(context->plugins,(GFunc)free_plugin,NULL);
+ if (context->profile) g_free(context->profile);
if (context->plugins) g_slist_free(context->plugins);
if (context->backend)
{
@@ -1045,7 +1109,7 @@ BerylSettingsContext * beryl_settings_context_comp_new(void)
context->categories=malloc(sizeof(PluginCategories));
memcpy(context->categories,&PluginCategories,sizeof(PluginCategories));
context->is_comp=TRUE;
- beryl_settings_context_set_backend(context,"ini");
+ init_general_options(context);
return context;
}
@@ -1792,3 +1856,49 @@ GSList * beryl_settings_plugin_category_get_plugins(BerylSettingsPluginCategory
{
return category->plugins;
}
+
+void beryl_settings_context_set_profile(BerylSettingsContext * context, gchar * profile)
+{
+ if (context->profile)
+ g_free(context->profile);
+ if (profile)
+ context->profile=g_strdup(profile);
+ else
+ context->profile=NULL;
+ save_general_option(context,OPT_PROFILE);
+}
+
+gchar * beryl_settings_context_get_profile(BerylSettingsContext * context)
+{
+ return context->profile;
+}
+
+void beryl_settings_context_set_de_integration_enabled(BerylSettingsContext * context, gboolean enable_integration)
+{
+ context->de_integration=enable_integration;
+}
+
+gboolean beryl_settings_context_get_de_integration_enabled(BerylSettingsContext * context)
+{
+ return context->de_integration;
+}
+
+
+/* gboolean de_integrated; // this setting is integrated into the
+ // desktop environment setting system
+ gboolean read_only; // the backend ignores changes to this setting*/
+gboolean beryl_settings_context_get_setting_is_de_integrated(BerylSettingsContext * context, BerylSetting * setting)
+{
+ if (context->get_setting_is_integrated)
+ return context->get_setting_is_integrated(setting);
+ else
+ return FALSE;
+}
+
+gboolean beryl_settings_context_get_setting_is_read_only(BerylSettingsContext * context, BerylSetting * setting)
+{
+ if (context->get_setting_is_read_only)
+ return context->get_setting_is_read_only(setting);
+ else
+ return FALSE;
+}