Commit 4c37ab02 authored by Patrick Welche's avatar Patrick Welche
Browse files

Store preferences using GSettings

* Make generate-schemas output GConf or GSettings XML, or a text dump,
  according to an option flag.

* Default is still to use GConf as many systems don't have the necessary
  file backed GSettingsBackends installed:

    GLib-GIO-Message: Using the 'memory' GSettings backend.  Your
    settings will not be saved or shared with other applications.

* Split GnomeSettingsStore.cpp into GSettingsStore.cpp, GConfStore.cpp and
  NoStore.cpp and compile conditionally.

* As the "Actions" box is gone (0f139f46), comment out all action code with
  #ifdef XXXPRLWACTIONSAREFIXED, and remove action specific source files
  from build.
  Actions were the only consumers of dasher_app_settings_{g,s}et_free_long.

* Removed GConf NotificationCallback as all it did was return.

* g/c another reference to an "intl" directory.
parent 51c1151e
......@@ -17,6 +17,7 @@ svgicon_DATA = dasher.svg
gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
if USE_GCONF
if GCONF_SCHEMAS_INSTALL
schemasdir = $(GCONF_SCHEMA_FILE_DIR)
schemas_DATA = dasher.schemas
......@@ -31,20 +32,43 @@ install-data-local: install-schemas
# which is then moved installed in the usual way. None of this happens
# if configure is told not to install schemas.
dasher.schemas: ../Src/Gtk2/generate-schema
echo -n "Generating schema ... "; \
../Src/Gtk2/generate-schema > dasher.schemas; \
dasher.schemas: $(top_builddir)/Src/Gtk2/generate-schema
echo -n "Generating GConf schema ... "; \
$(top_builddir)/Src/Gtk2/generate-schema -c > dasher.schemas; \
echo "done.";
install-schemas: dasher.schemas
GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \
gconftool-2 --makefile-install-rule dasher.schemas
compile-schemas:
# GCONF_SCHEMAS_INSTALL
endif
# !USE_GCONF
else
if USE_GSETTINGS
schemasdir = $(datadir)/glib-2.0/schemas
schemas_DATA = dasher.gschema.xml
check-local: check-schmemas
dasher.gschema.xml: $(top_builddir)/Src/Gtk2/generate-schema
echo -n "Generating GSettings schema ... "; \
$(top_builddir)/Src/Gtk2/generate-schema -s > dasher.gschema.xml; \
echo "done.";
compile-schemas: dasher.gschema.xml
$(GLIB_COMPILE_SCHEMAS) --allow-any-name $(schemasdir)
check-schemas: dasher.gschema.xml
$(GLIB_COMPILE_SCHEMAS) --allow-any-name --dry-run --schema-file=dasher.gschema.xml
else
install-data-local:
compile-schemas:
endif
endif
install-data-hook: update-icon-cache
install-data-hook: update-icon-cache compile-schemas
uninstall-hook: update-icon-cache
......@@ -62,5 +86,4 @@ EXTRA_DIST = \
$(icon_DATA) \
$(svgicon_DATA)
DISTCLEANFILES = dasher.schemas
CLEANFILES = dasher.schemas dasher.gschema.xml
......@@ -8,6 +8,10 @@
#include <gconf/gconf-enum-types.h>
#endif
#ifdef WITH_GSETTINGS
#include <gio/gio.h>
#endif
#include <cstring>
#include "DasherAppSettings.h"
#include "../Common/AppSettingsData.h"
......@@ -25,8 +29,10 @@
struct _DasherAppSettingsPrivate {
#ifdef WITH_GCONF
// GConf interface
GConfClient *pGConfClient;
#endif
#ifdef WITH_GSETTINGS
GSettings *psettings;
#endif
GtkDasherControl *pDasherWidget;
};
......@@ -37,10 +43,11 @@ typedef struct _DasherAppSettingsPrivate DasherAppSettingsPrivate;
static void dasher_app_settings_class_init(DasherAppSettingsClass *pClass);
static void dasher_app_settings_init(DasherAppSettings *pAppSettings);
static void dasher_app_settings_destroy(GObject *pObject);
static void dasher_app_settings_destroy(GObject*);
#ifdef WITH_GCONF
static void dasher_app_settings_init_gconf(DasherAppSettings *pSelf, int argc, char **argv);
static void dasher_app_settings_stop_gconf(DasherAppSettings *pSelf);
#endif
static void dasher_app_settings_load(DasherAppSettings *pSelf);
// Function declarations
......@@ -80,28 +87,35 @@ static void dasher_app_settings_init(DasherAppSettings *pDasherControl) {
#ifdef WITH_GCONF
pPrivate->pGConfClient = NULL;
#endif
#ifdef WITH_GSETTINGS
pPrivate->psettings = NULL;
#endif
pPrivate->pDasherWidget = NULL;
}
static void dasher_app_settings_destroy(GObject *pObject) {
DasherAppSettings *pSelf = DASHER_APP_SETTINGS(pObject);
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
#ifdef WITH_GCONF
dasher_app_settings_stop_gconf((DasherAppSettings *)pObject);
g_object_unref(pPrivate->pGConfClient);
#endif
#ifdef WITH_GSETTINGS
g_object_unref(pPrivate->psettings);
#endif
for(int i(0); i < NUM_OF_APP_SPS; ++i)
delete[] app_stringparamtable[i].value;
// FIXME - glib routines?
// FIXME - do we need a typecast here?
delete (DasherAppSettingsPrivate *)(((DasherAppSettings *)pObject)->private_data);
delete pPrivate;
// FIXME - I think we need to chain up through the finalize methods
// of the parent classes here...
}
static void dasher_app_settings_init_gconf(DasherAppSettings *pSelf, int argc, char **argv) {
#ifdef WITH_GCONF
static void dasher_app_settings_init_gconf(DasherAppSettings *pSelf, int argc, char **argv) {
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
GError *pGConfError;
......@@ -110,21 +124,13 @@ static void dasher_app_settings_init_gconf(DasherAppSettings *pSelf, int argc, c
g_error("Failed to initialise gconf: %s", pGConfError->message);
pPrivate->pGConfClient = gconf_client_get_default();
#endif
}
static void dasher_app_settings_stop_gconf(DasherAppSettings *pSelf) {
#ifdef WITH_GCONF
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pSelf->private_data);
g_object_unref(pPrivate->pGConfClient);
#endif
}
static void dasher_app_settings_load(DasherAppSettings *pSelf) {
#ifdef WITH_GCONF
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
#ifdef WITH_GCONF
GError *pGConfError = NULL;
GConfValue *pGConfValue;
......@@ -186,13 +192,44 @@ static void dasher_app_settings_load(DasherAppSettings *pSelf) {
}
}
#endif
#ifdef WITH_GSETTINGS
gchar *tmpstr;
for(int i(0); i < NUM_OF_APP_BPS; ++i ) {
if(app_boolparamtable[i].persistent) {
app_boolparamtable[i].value = g_settings_get_boolean(pPrivate->psettings,
app_boolparamtable[i].regName);
}
}
for(int i(0); i < NUM_OF_APP_LPS; ++i ) {
if(app_longparamtable[i].persistent) {
app_longparamtable[i].value = g_settings_get_int(pPrivate->psettings,
app_longparamtable[i].regName);
}
}
for(int i(0); i < NUM_OF_APP_SPS; ++i ) {
if(app_stringparamtable[i].persistent) {
tmpstr = g_settings_get_string(pPrivate->psettings,
app_stringparamtable[i].regName);
if(tmpstr) {
delete[] app_stringparamtable[i].value;
app_stringparamtable[i].value = new char[strlen(tmpstr) + 1];
strcpy(app_stringparamtable[i].value, tmpstr);
g_free(tmpstr);
}
}
}
#endif
}
// Public methods
DasherAppSettings *dasher_app_settings_new(int argc, char **argv) {
DasherAppSettings *pDasherControl;
pDasherControl = (DasherAppSettings *)(g_object_new(dasher_app_settings_get_type(), NULL));
DasherAppSettings *pNewAppSettings;
pNewAppSettings = (DasherAppSettings *)(g_object_new(dasher_app_settings_get_type(), NULL));
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate*)(pNewAppSettings->private_data);
for(int i(0); i < NUM_OF_APP_SPS; ++i) {
gchar *szNew;
......@@ -201,11 +238,14 @@ DasherAppSettings *dasher_app_settings_new(int argc, char **argv) {
app_stringparamtable[i].value = szNew;
}
#ifdef WITH_GCONF
dasher_app_settings_init_gconf(pDasherControl, argc, argv);
dasher_app_settings_init_gconf(pNewAppSettings, argc, argv);
#endif
#ifdef WITH_GSETTINGS
pPrivate->psettings = g_settings_new("org.gnome.Dasher");
#endif
dasher_app_settings_load(pDasherControl);
dasher_app_settings_load(pNewAppSettings);
return pDasherControl;
return pNewAppSettings;
}
void dasher_app_settings_reset(DasherAppSettings *pSelf, int iParameter) {
......@@ -275,6 +315,13 @@ void dasher_app_settings_set_bool(DasherAppSettings *pSelf, int iParameter, bool
g_message("Error");
}
#endif
#ifdef WITH_GSETTINGS
if(app_boolparamtable[ iParameter - FIRST_APP_BP ].persistent) {
g_settings_set_boolean(pPrivate->psettings,
app_boolparamtable[iParameter-FIRST_APP_BP].regName,
bValue);
}
#endif
// TODO: Use real signals to achieve this
parameter_notification(0, iParameter, 0);
......@@ -285,10 +332,8 @@ gint dasher_app_settings_get_long(DasherAppSettings *pSelf, int iParameter) {
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_LPS) {
if(pPrivate->pDasherWidget)
return gtk_dasher_control_get_parameter_long(pPrivate->pDasherWidget, iParameter);
else
return false;
DASHER_ASSERT_VALIDPTR_R(pPrivate->pDasherWidget);
return gtk_dasher_control_get_parameter_long(pPrivate->pDasherWidget, iParameter);
}
else
return app_longparamtable[ iParameter - FIRST_APP_LP ].value;
......@@ -298,8 +343,8 @@ void dasher_app_settings_set_long(DasherAppSettings *pSelf, int iParameter, gint
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
if( iParameter < END_OF_LPS) {
if(pPrivate->pDasherWidget)
gtk_dasher_control_set_parameter_long(pPrivate->pDasherWidget, iParameter, iValue);
DASHER_ASSERT_VALIDPTR_RW(pPrivate->pDasherWidget);
gtk_dasher_control_set_parameter_long(pPrivate->pDasherWidget, iParameter, iValue);
}
else {
if(dasher_app_settings_get_long(pSelf, iParameter) == iValue)
......@@ -320,16 +365,23 @@ void dasher_app_settings_set_long(DasherAppSettings *pSelf, int iParameter, gint
gconf_client_set_int(pPrivate->pGConfClient, szName, iValue, &pGConfError);
}
#endif
#ifdef WITH_GSETTINGS
if(app_longparamtable[ iParameter - FIRST_APP_LP ].persistent) {
g_settings_set_int(pPrivate->psettings,
app_longparamtable[iParameter-FIRST_APP_LP].regName,
iValue);
}
#endif
// TODO: Use real signals to achieve this
parameter_notification(0, iParameter, 0);
}
}
#ifdef XXXPRLWACTIONSAREFIXED
gboolean dasher_app_settings_get_free_long(DasherAppSettings *pSelf, const gchar *szName, gint &iValue) {
#ifdef WITH_GCONF
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
#ifdef WITH_GCONF
gchar szFullName[256];
strncpy(szFullName, "/apps/dasher4/", 256);
......@@ -352,7 +404,9 @@ gboolean dasher_app_settings_get_free_long(DasherAppSettings *pSelf, const gchar
return false;
#endif
}
#endif
#ifdef XXXPRLWACTIONSAREFIXED
void dasher_app_settings_set_free_long(DasherAppSettings *pSelf, const gchar *szName, gint iValue) {
#ifdef WITH_GCONF
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
......@@ -366,6 +420,7 @@ void dasher_app_settings_set_free_long(DasherAppSettings *pSelf, const gchar *sz
gconf_client_set_int(pPrivate->pGConfClient, szFullName, iValue, &pGConfError);
#endif
}
#endif
const gchar *dasher_app_settings_get_string(DasherAppSettings *pSelf, int iParameter) {
DasherAppSettingsPrivate *pPrivate = (DasherAppSettingsPrivate *)(pSelf->private_data);
......@@ -412,6 +467,13 @@ void dasher_app_settings_set_string(DasherAppSettings *pSelf, int iParameter, co
gconf_client_set_string(pPrivate->pGConfClient, szName, szValue, &pGConfError);
}
#endif
#ifdef WITH_GSETTINGS
if(app_stringparamtable[ iParameter - FIRST_APP_SP ].persistent) {
g_settings_set_string(pPrivate->psettings,
app_stringparamtable[iParameter-FIRST_APP_SP].regName,
szValue);
}
#endif
// TODO: Use real signals to achieve this
parameter_notification(0, iParameter, 0);
......
......@@ -60,8 +60,10 @@ bool dasher_app_settings_get_bool(DasherAppSettings *pSelf, int iParameter);
void dasher_app_settings_set_bool(DasherAppSettings *pSelf, int iParameter, bool bValue);
gint dasher_app_settings_get_long(DasherAppSettings *pSelf, int iParameter);
void dasher_app_settings_set_long(DasherAppSettings *pSelf, int iParameter, gint iValue);
#ifdef XXXPRLWACTIONSAREFIXED
gboolean dasher_app_settings_get_free_long(DasherAppSettings *pSelf, const gchar *szName, gint &iValue);
void dasher_app_settings_set_free_long(DasherAppSettings *pSelf, const gchar *szName, gint iValue);
#endif
const gchar *dasher_app_settings_get_string(DasherAppSettings *pSelf, int iParameter);
void dasher_app_settings_set_string(DasherAppSettings *pSelf, int iParameter, const gchar *szValue);
......
#ifndef __dasher_spi_h__
#define __dasher_spi_h__
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifndef __dasher_spi_h__
#define __dasher_spi_h__
#ifdef GNOME_A11Y
bool initSPI();
#endif
......
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "../Common/Common.h"
#include "GnomeSettingsStore.h"
#include <iostream>
// FIXME - need to handle gconf errors better here
#ifdef WITH_GCONF
extern "C" void ListenerCallback(GConfClient * pClient, guint iCNXN_ID, GConfEntry * pEntry, gpointer pUserData);
#endif
CGnomeSettingsStore::CGnomeSettingsStore(Dasher::CEventHandler *pEventHandler):CSettingsStore(pEventHandler) {
#ifdef WITH_GCONF
// GError *gconferror;
// gconf_init( argc, argv, &gconferror );
the_gconf_client = gconf_client_get_default();
gconf_client_add_dir(the_gconf_client, "/apps/dasher4", GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
gconf_client_notify_add(the_gconf_client, "/apps/dasher4", ListenerCallback, this, NULL, NULL);
#endif
LoadPersistent();
}
CGnomeSettingsStore::~CGnomeSettingsStore() {
#ifdef WITH_GCONF
g_object_unref(the_gconf_client);
#endif
}
bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
#ifdef WITH_GCONF
char keypath[1024];
snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
......@@ -52,13 +29,9 @@ bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
gconf_value_free(got_value);
return true;
#else
return false;
#endif
}
bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
#ifdef WITH_GCONF
char keypath[1024];
snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
......@@ -75,13 +48,9 @@ bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
gconf_value_free(got_value);
return true;
#else
return false;
#endif
}
bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value) {
#ifdef WITH_GCONF
char keypath[1024];
snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
......@@ -98,13 +67,9 @@ bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value
gconf_value_free(got_value);
return true;
#else
return false;
#endif
}
void CGnomeSettingsStore::SaveSetting(const std::string &Key, bool Value) {
#ifdef WITH_GCONF
char keypath[1024];
snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
......@@ -112,11 +77,9 @@ void CGnomeSettingsStore::SaveSetting(const std::string &Key, bool Value) {
GError *the_error = NULL;
gconf_client_set_bool(the_gconf_client, keypath, Value, &the_error);
#endif
}
void CGnomeSettingsStore::SaveSetting(const std::string &Key, long Value) {
#ifdef WITH_GCONF
char keypath[1024];
snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
......@@ -124,11 +87,9 @@ void CGnomeSettingsStore::SaveSetting(const std::string &Key, long Value) {
GError *the_error = NULL;
gconf_client_set_int(the_gconf_client, keypath, Value, &the_error);
#endif
}
void CGnomeSettingsStore::SaveSetting(const std::string &Key, const std::string &Value) {
#ifdef WITH_GCONF
char keypath[1024];
snprintf(keypath, 1024, "/apps/dasher4/%s", Key.c_str());
......@@ -136,68 +97,4 @@ void CGnomeSettingsStore::SaveSetting(const std::string &Key, const std::string
GError *the_error = NULL;
gconf_client_set_string(the_gconf_client, keypath, Value.c_str(), &the_error);
#endif
}
#ifdef WITH_GCONF
void CGnomeSettingsStore::NotificationCallback(GConfClient *pClient, guint iCNXN_ID, GConfEntry *pEntry) {
return;
std::string strKey(pEntry->key);
std::string strKeyName(strKey.substr(strKey.find_last_of("/") + 1));
for(int i(0); i < NUM_OF_BPS; ++i) {
if(s_oParamTables.BoolParamTable[i].regName == strKeyName) {
bool bValue;
LoadSetting(s_oParamTables.BoolParamTable[i].regName, &bValue);
bool bOldValue(s_oParamTables.BoolParamTable[i].value);
// We need to check that the value has actually changed, otherwise we'll get a loop
if(bValue != bOldValue) {
SetBoolParameter(i + FIRST_BP, bValue);
}
return;
}
}
for(int i(0); i < NUM_OF_LPS; ++i) {
if(s_oParamTables.LongParamTable[i].regName == strKeyName) {
long lValue;
LoadSetting(s_oParamTables.LongParamTable[i].regName, &lValue);
long lOldValue(s_oParamTables.LongParamTable[i].value);
if(lValue != lOldValue) {
SetLongParameter(i + FIRST_LP, lValue);
}
return;
}
}
for(int i(0); i < NUM_OF_SPS; ++i) {
if(s_oParamTables.StringParamTable[i].regName == strKeyName) {
std::string strValue;
LoadSetting(s_oParamTables.StringParamTable[i].regName, &strValue);
std::string strOldValue(s_oParamTables.StringParamTable[i].value);
if(strValue != strOldValue) {
SetStringParameter(i + FIRST_SP, strValue);
}
return;
}
}
}
extern "C" void ListenerCallback(GConfClient *pClient, guint iCnxn_ID, GConfEntry *pEntry, gpointer pUserData) {
static_cast < CGnomeSettingsStore * >(pUserData)->NotificationCallback(pClient, iCnxn_ID, pEntry);
}
#endif
#include "GnomeSettingsStore.h"
#include <iostream>
CGnomeSettingsStore::CGnomeSettingsStore(Dasher::CEventHandler *pEventHandler):CSettingsStore(pEventHandler) {
settings = g_settings_new("org.gnome.Dasher");
LoadPersistent();
}
CGnomeSettingsStore::~CGnomeSettingsStore() {
g_object_unref(settings);
}
bool CGnomeSettingsStore::LoadSetting(const std::string &Key, bool *Value) {
// If Key doesn't exist, or is not boolean, g_settings_get_boolean will
// return false.
*Value = g_settings_get_boolean(settings, Key.c_str());
return true;
}
bool CGnomeSettingsStore::LoadSetting(const std::string &Key, long *Value) {
// It seems that this has never been able to store a long, only an int.
*Value = g_settings_get_int(settings, Key.c_str());
return true;
}
bool CGnomeSettingsStore::LoadSetting(const std::string &Key, std::string *Value) {
*Value = g_settings_get_string(settings, Key.c_str());
return true;
}
void CGnomeSettingsStore::SaveSetting(const std::string &Key, bool Value) {
// g_settings_set_boolean returns fals if the key was not writable.
g_settings_set_boolean(settings, Key.c_str(), Value);
}
void CGnomeSettingsStore::SaveSetting(const std::string &Key, long Value) {
g_settings_set_int(settings, Key.c_str(), Value);
}
void CGnomeSettingsStore::SaveSetting(const std::string &Key, const std::string &Value) {
g_settings_set_string(settings, Key.c_str(), Value.c_str());
}
......@@ -3,69 +3,173 @@
#include "../DasherCore/Parameters.h"
#include "../Common/AppSettingsData.h"
#include <algorithm>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
enum{ TYPE_BOOL, TYPE_LONG, TYPE_STRING };
enum EValType { TYPE_BOOL, TYPE_LONG, TYPE_STRING };
enum EOutput { GCONF_OUTPUT, GSETTINGS_OUTPUT, TEXT_OUTPUT };
class CSchema {
public:
CSchema(const std::string &strKeyName, int iType,
CSchema(const std::string &strKeyName, EValType iType,
const std::string &strDefault, const std::string &strShort,
const std::string &strLong);
void Dump();
void Dump(EOutput);
private:
std::string m_strKeyName;
std::string m_strType;
EValType m_iType;
std::string m_strDefault;
std::string m_strShort;
std::string m_strLong;
};
CSchema::CSchema(const std::string &strKeyName, int iType,
struct lower_char
{
void operator()(char &c) {c = tolower(c);}
};
std::string lower(const std::string& in)
{
std::string out(in);
for_each(out.begin(), out.end(), lower_char());
return out;
}
CSchema::CSchema(const std::string &strKeyName, EValType iType,
const std::string &strDefault, const std::string &strShort,
const std::string &strLong) {
m_strKeyName = strKeyName;
switch(iType) {
case TYPE_BOOL:
m_strType="bool";
m_iType = iType;
m_strDefault = strDefault;
m_strShort = strShort;
m_strLong = strLong;
}