[gnome-commander] Use GSettingsSchemaSource to load GSettings when PREFIX is not the default directory
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Use GSettingsSchemaSource to load GSettings when PREFIX is not the default directory
- Date: Sat, 20 May 2017 21:59:39 +0000 (UTC)
commit 53ddf586b9f97d63949499db6c4efd2018ddaf93
Author: Uwe Scholz <uwescholz src gnome org>
Date: Sat May 20 23:57:36 2017 +0200
Use GSettingsSchemaSource to load GSettings when PREFIX is not the default directory
plugins/fileroller/file-roller-plugin.cc | 38 +++++++++++++++-
src/gnome-cmd-data.cc | 70 ++++++++++++++++++++++++++----
src/gnome-cmd-data.h | 3 +
src/gnome-cmd-dir-indicator.cc | 7 +++-
src/gnome-cmd-user-actions.cc | 12 ++++-
src/main.cc | 1 +
6 files changed, 117 insertions(+), 14 deletions(-)
---
diff --git a/plugins/fileroller/file-roller-plugin.cc b/plugins/fileroller/file-roller-plugin.cc
index 04db43c..00c81c5 100644
--- a/plugins/fileroller/file-roller-plugin.cc
+++ b/plugins/fileroller/file-roller-plugin.cc
@@ -19,7 +19,9 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <config.h>
#include <stdlib.h>
+#include <string>
#include <libgcmd/libgcmd.h>
#include "file-roller-plugin.h"
#include "file-roller.xpm"
@@ -30,7 +32,6 @@
#define AUTHOR "Marcus Bjurman <marbj499 student liu se>"
#define TRANSLATOR_CREDITS "Translations: https://l10n.gnome.org/module/gnome-commander/"
#define WEBPAGE "http://gcmd.github.io"
-#define VERSION "1.6.0"
#define GCMD_PLUGINS_FILE_ROLLER "org.gnome.gnome-commander.plugins.file-roller-plugin"
#define GCMD_PLUGINS_FILE_ROLLER_DEFAULT_TYPE "default-type"
@@ -85,6 +86,34 @@ static const gchar *handled_extensions[NUMBER_OF_EXTENSIONS + 1] =
* Functions for using GSettings
***********************************/
+static GSettingsSchemaSource* GetGlobalSchemaSource()
+{
+ GSettingsSchemaSource *global_schema_source;
+ std::string g_schema_path(PREFIX);
+
+ g_schema_path.append("/share/glib-2.0/schemas");
+
+ global_schema_source = g_settings_schema_source_get_default ();
+
+ GSettingsSchemaSource *parent = global_schema_source;
+ GError *error = NULL;
+
+ global_schema_source = g_settings_schema_source_new_from_directory
+ ((gchar*) g_schema_path.c_str(),
+ parent,
+ FALSE,
+ &error);
+
+ if (global_schema_source == NULL)
+ {
+ g_printerr(_("Could not load schemas from %s: %s\n"),
+ (gchar*) g_schema_path.c_str(), error->message);
+ g_clear_error (&error);
+ }
+
+ return global_schema_source;
+}
+
struct _PluginSettings
{
GObject parent;
@@ -122,7 +151,12 @@ PluginSettings *plugin_settings_new ()
static void plugin_settings_init (PluginSettings *gs)
{
- gs->file_roller_plugin = g_settings_new (GCMD_PLUGINS_FILE_ROLLER);
+ GSettingsSchemaSource *global_schema_source;
+ GSettingsSchema *global_schema;
+
+ global_schema_source = GetGlobalSchemaSource();
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PLUGINS_FILE_ROLLER, FALSE);
+ gs->file_roller_plugin = g_settings_new_full (global_schema, NULL, NULL);
}
diff --git a/src/gnome-cmd-data.cc b/src/gnome-cmd-data.cc
index 5d4c630..29686a3 100644
--- a/src/gnome-cmd-data.cc
+++ b/src/gnome-cmd-data.cc
@@ -62,6 +62,33 @@ struct GnomeCmdData::Private
gboolean settings_monitor_enabled;
};
+GSettingsSchemaSource* GnomeCmdData::GetGlobalSchemaSource()
+{
+ GSettingsSchemaSource *global_schema_source;
+ std::string g_schema_path(PREFIX);
+
+ g_schema_path.append("/share/glib-2.0/schemas");
+
+ global_schema_source = g_settings_schema_source_get_default ();
+
+ GSettingsSchemaSource *parent = global_schema_source;
+ GError *error = NULL;
+
+ global_schema_source = g_settings_schema_source_new_from_directory
+ ((gchar*) g_schema_path.c_str(),
+ parent,
+ FALSE,
+ &error);
+
+ if (global_schema_source == NULL)
+ {
+ g_printerr(_("Could not load schemas from %s: %s\n"),
+ (gchar*) g_schema_path.c_str(), error->message);
+ g_clear_error (&error);
+ }
+
+ return global_schema_source;
+}
struct _GcmdSettings
{
@@ -1267,14 +1294,35 @@ static void gcmd_connect_gsettings_signals(GcmdSettings *gs)
static void gcmd_settings_init (GcmdSettings *gs)
{
- gs->general = g_settings_new (GCMD_PREF_GENERAL);
- gs->filter = g_settings_new (GCMD_PREF_FILTER);
- gs->confirm = g_settings_new (GCMD_PREF_CONFIRM);
- gs->colors = g_settings_new (GCMD_PREF_COLORS);
- gs->programs = g_settings_new (GCMD_PREF_PROGRAMS);
- gs->network = g_settings_new (GCMD_PREF_NETWORK);
- gs->internalviewer = g_settings_new (GCMD_PREF_INTERNAL_VIEWER);
- gs->plugins = g_settings_new (GCMD_PREF_PLUGINS);
+ GSettingsSchemaSource *global_schema_source;
+ GSettingsSchema *global_schema;
+
+ global_schema_source = GnomeCmdData::GetGlobalSchemaSource();
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_GENERAL, FALSE);
+ gs->general = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_FILTER, FALSE);
+ gs->filter = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_CONFIRM, FALSE);
+ gs->confirm = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_COLORS, FALSE);
+ gs->colors = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_PROGRAMS, FALSE);
+ gs->programs = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_NETWORK, FALSE);
+ gs->network = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_INTERNAL_VIEWER, FALSE);
+ gs->internalviewer = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_PLUGINS, FALSE);
+ gs->plugins = g_settings_new_full (global_schema, NULL, NULL);
+
//TODO: Activate the following function in GCMD > 1.6
//gcmd_connect_gsettings_signals(gs);
}
@@ -2652,6 +2700,11 @@ void GnomeCmdData::free()
}
}
+void GnomeCmdData::gsettings_init()
+{
+ options.gcmd_settings = gcmd_settings_new();
+}
+
/**
* This method converts user settings from gcmds old config files, created via gnome config to
* GSettings. Therefore, it first looks for those files in question and then converts the data.
@@ -2660,7 +2713,6 @@ void GnomeCmdData::free()
void GnomeCmdData::migrate_all_data_to_gsettings()
{
guint temp_value;
- options.gcmd_settings = gcmd_settings_new();
gchar *package_config_path = gnome_config_get_real_path(PACKAGE);
///////////////////////////////////////////////////////////////////////
diff --git a/src/gnome-cmd-data.h b/src/gnome-cmd-data.h
index 987cc66..e3c3853 100644
--- a/src/gnome-cmd-data.h
+++ b/src/gnome-cmd-data.h
@@ -569,6 +569,8 @@ struct GnomeCmdData
typedef std::pair<std::string,triple<GnomeCmdFileList::ColumnID,GtkSortType,gboolean> > Tab;
+ static GSettingsSchemaSource* GetGlobalSchemaSource();
+
struct Private;
Private *priv;
@@ -641,6 +643,7 @@ struct GnomeCmdData
void free(); // FIXME: free() -> ~GnomeCmdData()
void load();
+ void gsettings_init();
void migrate_all_data_to_gsettings();
gint migrate_data_int_value_into_gsettings(gint user_value, GSettings *settings, const char *key);
gboolean migrate_data_string_value_into_gsettings(const char* user_value, GSettings *settings, const
char *key);
diff --git a/src/gnome-cmd-dir-indicator.cc b/src/gnome-cmd-dir-indicator.cc
index b276a26..744cdf1 100644
--- a/src/gnome-cmd-dir-indicator.cc
+++ b/src/gnome-cmd-dir-indicator.cc
@@ -361,7 +361,12 @@ void gnome_cmd_dir_indicator_show_history (GnomeCmdDirIndicator *indicator)
path);
}
- gnome_popup_menu_do_popup (indicator->priv->dir_history_popup, (GtkMenuPositionFunc) get_popup_pos,
indicator, NULL, NULL, NULL);
+ gnome_popup_menu_do_popup (indicator->priv->dir_history_popup,
+ (GtkMenuPositionFunc) get_popup_pos,
+ indicator,
+ NULL,
+ NULL,
+ NULL);
gint w = -1;
diff --git a/src/gnome-cmd-user-actions.cc b/src/gnome-cmd-user-actions.cc
index 0c6ef66..fa3a988 100644
--- a/src/gnome-cmd-user-actions.cc
+++ b/src/gnome-cmd-user-actions.cc
@@ -98,8 +98,16 @@ GcmdUserActionSettings *gcmd_user_action_settings_new ()
static void gcmd_user_action_settings_init (GcmdUserActionSettings *gs)
{
- gs->filter = g_settings_new (GCMD_PREF_FILTER);
- gs->general = g_settings_new (GCMD_PREF_GENERAL);
+ GSettingsSchemaSource *global_schema_source;
+ GSettingsSchema *global_schema;
+
+ global_schema_source = GnomeCmdData::GetGlobalSchemaSource();
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_FILTER, FALSE);
+ gs->filter = g_settings_new_full (global_schema, NULL, NULL);
+
+ global_schema = g_settings_schema_source_lookup (global_schema_source, GCMD_PREF_GENERAL, FALSE);
+ gs->general = g_settings_new_full (global_schema, NULL, NULL);
}
/***********************************
diff --git a/src/main.cc b/src/main.cc
index bbdd3a8..6d1dfaa 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -144,6 +144,7 @@ int main (int argc, char *argv[])
/* Load Settings */
IMAGE_init ();
gcmd_user_actions.init();
+ gnome_cmd_data.gsettings_init();
gnome_cmd_data.migrate_all_data_to_gsettings();
gnome_cmd_data.load();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]