summaryrefslogtreecommitdiff
path: root/settings-backend
diff options
context:
space:
mode:
Diffstat (limited to 'settings-backend')
-rw-r--r--settings-backend/Makefile.am13
-rw-r--r--settings-backend/kconfig_backend.cpp557
2 files changed, 570 insertions, 0 deletions
diff --git a/settings-backend/Makefile.am b/settings-backend/Makefile.am
new file mode 100644
index 0000000..b9d02f2
--- /dev/null
+++ b/settings-backend/Makefile.am
@@ -0,0 +1,13 @@
+INCLUDES = -I$(srcdir)/lib $(all_includes)
+
+if with_berylsettings
+
+libkconfig_la_LDFLAGS = -module -avoid-version -no-undefined $(all_libraries)
+libkconfig_la_LIBADD = $(BERYLSETTINGS_LIBS) $(LIB_KDECORE)
+libkconfig_la_SOURCES = kconfig_backend.cpp
+backenddir = $(plugindir)/backends
+KDE_CXXFLAGS = $(BERYLSETTINGS_CFLAGS)
+
+backend_LTLIBRARIES = libkconfig.la
+
+endif \ No newline at end of file
diff --git a/settings-backend/kconfig_backend.cpp b/settings-backend/kconfig_backend.cpp
new file mode 100644
index 0000000..8e900be
--- /dev/null
+++ b/settings-backend/kconfig_backend.cpp
@@ -0,0 +1,557 @@
+#include <kconfig.h>
+#include <ksimpleconfig.h>
+#include <kdebug.h>
+#include <kinstance.h>
+#include <stdlib.h>
+
+/*
+ * Aquamarine the KDE window decorator
+ *
+ * Copyright (c) 2006 Dennis Kasprzyk <onestone@beryl-project.org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+extern "C" {
+#include <beryl-settings-backend.h>
+}
+
+static KInstance *instance = NULL;
+
+const static char *edgeName[] = {
+ "Left",
+ "Right",
+ "Top",
+ "Bottom",
+ "TopLeft",
+ "TopRight",
+ "BottomLeft",
+ "BottomRight"
+};
+
+void read_setting(BerylSettingsContext * c, BerylSetting * setting)
+{
+ KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+
+ QString key(setting->name);
+ QString group(setting->parent->name);
+ if (setting->is_screen)
+ group += "_screen0";
+ cfg->setGroup(group);
+
+ if (setting->type != BERYL_SETTING_TYPE_BINDING && !cfg->hasKey(key))
+ return;
+
+ setting->is_default=FALSE;
+ switch (setting->type)
+ {
+ case BERYL_SETTING_TYPE_STRING:
+ setting->value.value.as_string =
+ g_strdup(cfg->readEntry(key,setting->value.value.as_string).ascii());
+ break;
+ case BERYL_SETTING_TYPE_FLOAT:
+ {
+ double val = cfg->readDoubleNumEntry(key);
+ // stupid rounding issue
+ val = MAX(val,setting->info.for_float.min);
+ val = MIN(val,setting->info.for_float.max);
+ beryl_setting_value_set_float(&setting->value,&val);
+ }
+ break;
+ case BERYL_SETTING_TYPE_INT:
+ {
+ int val = cfg->readNumEntry(key);
+ beryl_setting_value_set_int(&setting->value,&val);
+ }
+ break;
+ case BERYL_SETTING_TYPE_BOOL:
+ {
+
+ Bool val = (cfg->readBoolEntry(key))?TRUE:FALSE;
+ beryl_setting_value_set_bool(&setting->value,&val);
+ }
+ break;
+ case BERYL_SETTING_TYPE_COLOR:
+ {
+ QValueList<int> list = cfg->readIntListEntry(key);
+ BerylSettingColorValue color;
+ color.color.red = list[0];
+ color.color.green = list[1];
+ color.color.blue = list[2];
+ color.color.alpha = list[3];
+ beryl_setting_value_set_color(&setting->value,&color);
+ }
+ break;
+ case BERYL_SETTING_TYPE_LIST:
+ {
+ switch(setting->info.for_list.list_of_type)
+ {
+ case BERYL_SETTING_TYPE_BOOL:
+ {
+ QValueList<int> list = cfg->readIntListEntry(key);
+
+ beryl_setting_list_clear(setting);
+
+ QValueList<int>::iterator it;
+ for (it = list.begin(); it != list.end(); it++)
+ {
+ BerylSettingValue * value = beryl_setting_list_append(setting);
+ Bool val = ((*it))?TRUE:FALSE;
+ beryl_setting_value_set_bool(value,&val);
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_INT:
+ {
+ QValueList<int> list = cfg->readIntListEntry(key);
+
+ beryl_setting_list_clear(setting);
+
+ QValueList<int>::iterator it;
+ for (it = list.begin(); it != list.end(); it++)
+ {
+ BerylSettingValue * value = beryl_setting_list_append(setting);
+ beryl_setting_value_set_int(value,&(*it));
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_STRING:
+ {
+ QStringList list = cfg->readListEntry(key,';');
+
+ beryl_setting_list_clear(setting);
+
+ QStringList::iterator it;
+ for (it = list.begin(); it != list.end(); it++)
+ {
+ BerylSettingValue * value = beryl_setting_list_append(setting);
+ value->value.as_string = g_strdup((*it).ascii());
+ value->parent->is_default=FALSE;
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_FLOAT:
+ {
+ QStringList list = cfg->readListEntry(key,';');
+
+ beryl_setting_list_clear(setting);
+
+ QStringList::iterator it;
+ for (it = list.begin(); it != list.end(); it++)
+ {
+ BerylSettingValue * value = beryl_setting_list_append(setting);
+ double val = (*it).toDouble();
+ beryl_setting_value_set_float(value,&val);
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_COLOR:
+ {
+ QStringList list = cfg->readListEntry(key,';');
+
+ beryl_setting_list_clear(setting);
+
+ QStringList::iterator it;
+ for (it = list.begin(); it != list.end(); it++)
+ {
+ BerylSettingValue * value = beryl_setting_list_append(setting);
+ QStringList colorstr = QStringList::split(",",(*it));
+
+ BerylSettingColorValue color;
+ color.color.red = colorstr[0].toInt();
+ color.color.green = colorstr[1].toInt();
+ color.color.blue = colorstr[2].toInt();
+ color.color.alpha = colorstr[3].toInt();
+ beryl_setting_value_set_color(value,&color);
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_BINDING:
+ {
+ QStringList list = cfg->readListEntry(key,';');
+
+ beryl_setting_list_clear(setting);
+
+ QStringList::iterator it;
+ for (it = list.begin(); it != list.end(); it++)
+ {
+ BerylSettingValue * value = beryl_setting_list_append(setting);
+ QStringList binding = QStringList::split(",",(*it));
+
+ int val;
+ Bool bval;
+
+ val = binding[0].toInt();
+ beryl_setting_value_set_buttonmods(value,&val);
+ val = binding[1].toInt();
+ beryl_setting_value_set_button(value,&val);
+ val = binding[2].toInt();
+ beryl_setting_value_set_keymods(value,&val);
+ val = binding[3].toInt();
+ beryl_setting_value_set_keysym(value,&val);
+ val = binding[4].toInt();
+ beryl_setting_value_set_edgemask(value,&val);
+ bval = (binding[5].toInt())?TRUE:FALSE;
+ beryl_setting_value_set_bell(value,&bval);
+ bval = (binding[6].toInt())?TRUE:FALSE;
+ beryl_setting_value_set_button_enabled(value,&bval);
+ bval = (binding[7].toInt())?TRUE:FALSE;
+ beryl_setting_value_set_key_enabled(value,&bval);
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_BINDING:
+ {
+ setting->is_default=TRUE;
+ if (cfg->hasKey(key + "_key"))
+ {
+ setting->is_default=FALSE;
+ Bool bval = (cfg->readBoolEntry(key + "_key_enabled"))?TRUE:FALSE;
+ char * sval = strdup(cfg->readEntry(key + "_key").ascii());
+
+ int keysym = 0;
+ int keymods = 0;
+ gchar * spos;
+ keymods = beryl_settings_get_mods_and_endptr(sval,&spos);
+ if (spos && *spos)
+ {
+ keysym=XStringToKeysym(spos);
+ }
+ beryl_setting_value_set_keysym(&setting->value,&keysym);
+ beryl_setting_value_set_keymods(&setting->value,&keymods);
+ beryl_setting_value_set_key_enabled(&setting->value,&bval);
+ delete sval;
+ }
+ if (cfg->hasKey(key + "_button"))
+ {
+ setting->is_default=FALSE;
+ Bool bval = (cfg->readBoolEntry(key + "_button_enabled"))?TRUE:FALSE;
+ char * sval = strdup(cfg->readEntry(key + "_button").ascii());
+
+ int button = 0;
+ int buttonmods = 0;
+ char * spos;
+ buttonmods = beryl_settings_get_mods_and_endptr(sval,&spos);
+ if (spos && *spos)
+ {
+ spos=strcasestr(spos,"Button");
+ if (spos && *spos)
+ {
+ spos+=strlen("Button");
+ button=atoi(spos);
+ }
+ }
+ beryl_setting_value_set_button(&setting->value,&button);
+ beryl_setting_value_set_buttonmods(&setting->value,&buttonmods);
+ beryl_setting_value_set_button_enabled(&setting->value,&bval);
+ delete sval;
+ }
+ if (cfg->hasKey(key + "_edge"))
+ {
+ setting->is_default=FALSE;
+ QString sval = cfg->readEntry(key + "_edge");
+ int int_val = 0;
+
+ for (int i = 0; i < 8; i++)
+ {
+ if (sval == edgeName[i])
+ {
+ int_val=1<<i;
+ }
+ }
+ beryl_setting_value_set_edgemask(&setting->value,&int_val);
+ }
+ if (cfg->hasKey(key + "_bell"))
+ {
+ setting->is_default=FALSE;
+ Bool bval = (cfg->readBoolEntry(key + "_bell"))?TRUE:FALSE;
+ beryl_setting_value_set_bell(&setting->value,&bval);
+ }
+ }
+ break;
+ default:
+ kdDebug () << "Not supported setting type : " << setting->type << endl;
+ setting->is_default=TRUE;
+ break;
+ }
+}
+
+static void copy_bool(BerylSettingValue * value, QValueList<int> *list)
+{
+ list->append((value->value.as_bool)?1:0);
+}
+
+static void copy_int(BerylSettingValue * value, QValueList<int> *list)
+{
+ list->append(value->value.as_int);
+}
+
+static void copy_float(BerylSettingValue * value, QStringList *list)
+{
+ list->append(QString::number(value->value.as_float));
+}
+
+static void copy_binding(BerylSettingValue * value, QStringList *list)
+{
+ QString binding;
+ binding += QString::number(value->value.as_binding.button_mod_mask);
+ binding += ",";
+ binding += QString::number(value->value.as_binding.button);
+ binding += ",";
+ binding += QString::number(value->value.as_binding.key_mod_mask);
+ binding += ",";
+ binding += QString::number(value->value.as_binding.keysym);
+ binding += ",";
+ binding += QString::number(value->value.as_binding.edge_mask);
+ binding += ",";
+ binding += QString::number((value->value.as_binding.on_bell)?1:0);
+ binding += ",";
+ binding += QString::number((value->value.as_binding.enabled.value.button)?1:0);
+ binding += ",";
+ binding += QString::number((value->value.as_binding.enabled.value.key)?1:0);
+ list->append(binding);
+}
+
+static void copy_string(BerylSettingValue * value, QStringList *list)
+{
+ list->append(value->value.as_string);
+}
+
+static void copy_color(BerylSettingValue * value, QStringList *list)
+{
+ QString color;
+ color += QString::number(value->value.as_color.color.red);
+ color += ",";
+ color += QString::number(value->value.as_color.color.green);
+ color += ",";
+ color += QString::number(value->value.as_color.color.blue);
+ color += ",";
+ color += QString::number(value->value.as_color.color.alpha);
+ list->append(color);
+}
+
+void write_setting(BerylSettingsContext * c, BerylSetting * setting)
+{
+ KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+
+ QString key(setting->name);
+ QString group(setting->parent->name);
+ if (setting->is_screen)
+ group += "_screen0";
+ cfg->setGroup(group);
+
+ if (setting->is_default)
+ {
+ if (cfg->hasKey(key))
+ cfg->deleteEntry(key);
+ return;
+ }
+
+ switch (setting->type)
+ {
+ case BERYL_SETTING_TYPE_STRING:
+ cfg->writeEntry(key,setting->value.value.as_string);
+ break;
+ case BERYL_SETTING_TYPE_FLOAT:
+ cfg->writeEntry(key,setting->value.value.as_float);
+ break;
+ case BERYL_SETTING_TYPE_INT:
+ cfg->writeEntry(key,setting->value.value.as_int);
+ break;
+ case BERYL_SETTING_TYPE_BOOL:
+ cfg->writeEntry(key,bool(setting->value.value.as_bool));
+ break;
+ case BERYL_SETTING_TYPE_COLOR:
+ {
+ QValueList<int> list;
+ list.append(setting->value.value.as_color.color.red);
+ list.append(setting->value.value.as_color.color.green);
+ list.append(setting->value.value.as_color.color.blue);
+ list.append(setting->value.value.as_color.color.alpha);
+ cfg->writeEntry(key,list);
+ }
+ break;
+ case BERYL_SETTING_TYPE_LIST:
+ {
+ switch(setting->info.for_list.list_of_type)
+ {
+ case BERYL_SETTING_TYPE_BOOL:
+ {
+ QValueList<int> list;
+ g_slist_foreach(setting->value.value.as_list,(GFunc)copy_bool,&list);
+ cfg->writeEntry(key,list,';');
+ }
+ break;
+ case BERYL_SETTING_TYPE_INT:
+ {
+ QValueList<int> list;
+ g_slist_foreach(setting->value.value.as_list,(GFunc)copy_int,&list);
+ cfg->writeEntry(key,list,';');
+ }
+ break;
+ case BERYL_SETTING_TYPE_STRING:
+ {
+ QStringList list;
+ g_slist_foreach(setting->value.value.as_list,(GFunc)copy_string,&list);
+ cfg->writeEntry(key,list,';');
+ }
+ break;
+ case BERYL_SETTING_TYPE_FLOAT:
+ {
+ QStringList list;
+ g_slist_foreach(setting->value.value.as_list,(GFunc)copy_float,&list);
+ cfg->writeEntry(key,list,';');
+ }
+ break;
+ case BERYL_SETTING_TYPE_COLOR:
+ {
+ QStringList list;
+ g_slist_foreach(setting->value.value.as_list,(GFunc)copy_color,&list);
+ cfg->writeEntry(key,list,';');
+ }
+ break;
+ case BERYL_SETTING_TYPE_BINDING:
+ {
+ QStringList list;
+ g_slist_foreach(setting->value.value.as_list,(GFunc)copy_binding,&list);
+ cfg->writeEntry(key,list,';');
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ break;
+ case BERYL_SETTING_TYPE_BINDING:
+ {
+ gboolean bool_val;
+ if (beryl_setting_get_can_set_key(setting,&bool_val)
+ &&bool_val)
+ {
+ if (beryl_setting_value_get_key_enabled(
+ &setting->value,&bool_val)&&bool_val)
+ cfg->writeEntry(key + "_key_enabled",true);
+ else
+ cfg->writeEntry(key + "_key_enabled",false);
+
+ gint ire;
+ QString binding;
+ QString keysym;
+
+ if (beryl_setting_value_get_keymods(&setting->value,&ire))
+ binding += beryl_settings_mods_to_string(ire);
+
+ if (beryl_setting_value_get_keysym(&setting->value,&ire))
+ keysym = XKeysymToString(ire);
+ if (keysym.isEmpty()) keysym = "None";
+
+ binding += keysym;
+ cfg->writeEntry(key + "_key",binding);
+ }
+ if (beryl_setting_get_can_set_button(setting,&bool_val)
+ &&bool_val)
+ {
+ if (beryl_setting_value_get_button_enabled(
+ &setting->value,&bool_val)&&bool_val)
+ cfg->writeEntry(key + "_button_enabled",true);
+ else
+ cfg->writeEntry(key + "_button_enabled",false);
+
+
+ gint ire;
+ QString binding;
+ QString button = "Any";
+
+ if (beryl_setting_value_get_buttonmods(&setting->value,&ire))
+ binding += beryl_settings_mods_to_string(ire);
+
+ if (beryl_setting_value_get_button(&setting->value,&ire))
+ button = "Button" + QString::number(ire);
+
+ binding += button;
+ cfg->writeEntry(key + "_button",binding);
+ }
+ if (beryl_setting_get_can_set_edgemask(setting,&bool_val)
+ &&bool_val)
+ {
+ int ema;
+ QString edge = "None";
+
+ if (beryl_setting_value_get_edgemask(&setting->value,&ema))
+ {
+ int i;
+ for (i=0;i<8;i++)
+ if (ema & 1<<i)
+ edge = edgeName[i];
+ }
+ cfg->writeEntry(key + "_edge",edge);
+ }
+ if (beryl_setting_get_can_set_bell(setting,&bool_val)
+ &&bool_val)
+ {
+ if (beryl_setting_value_get_bell(&setting->value,&bool_val))
+ cfg->writeEntry(key + "_bell",bool(bool_val));
+ }
+ }
+ break;
+ default:
+ kdDebug () << "Not supported setting type : " << setting->type << endl;
+ break;
+ }
+}
+
+gboolean read_init(BerylSettingsContext * c)
+{
+ if (!instance)
+ instance = new KInstance("beryl-kconfig");
+
+ KSimpleConfig *cfg = new KSimpleConfig("berylrc",true);
+ c->backend_private_ptr=(void *)cfg;
+ return TRUE;
+}
+
+void read_done(BerylSettingsContext * c)
+{
+ KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+ c->backend_private_ptr=NULL;
+ delete cfg;
+}
+
+gboolean write_init(BerylSettingsContext * c)
+{
+ if (!instance)
+ instance = new KInstance("beryl-kconfig");
+
+ KSimpleConfig *cfg = new KSimpleConfig("berylrc");
+ c->backend_private_ptr=(void *)cfg;
+ return TRUE;
+}
+
+void write_done(BerylSettingsContext * c)
+{
+ KSimpleConfig *cfg = (KSimpleConfig *)c->backend_private_ptr;
+ c->backend_private_ptr=NULL;
+ cfg->sync();
+ delete cfg;
+}
+
+
+