[anjuta/gsettings-migration: 55/65] anjuta: Ported to GSettings



commit 1c76d0611db769c6f1a03e6438388654ec4ca502
Author: Johannes Schmid <jhs gnome org>
Date:   Tue Oct 12 18:27:51 2010 +0200

    anjuta: Ported to GSettings

 src/action-callbacks.c |    8 +++--
 src/anjuta-app.c       |   94 +++++++++++++++++++++++++-----------------------
 src/anjuta-app.h       |    1 +
 src/anjuta.c           |   16 ++++----
 4 files changed, 63 insertions(+), 56 deletions(-)
---
diff --git a/src/action-callbacks.c b/src/action-callbacks.c
index ecd7983..db8dd84 100644
--- a/src/action-callbacks.c
+++ b/src/action-callbacks.c
@@ -38,6 +38,8 @@
 #include "action-callbacks.h"
 #include "anjuta.h"
 
+#define TOOLBAR_VISIBLE "toolbar-visible"
+
 void
 on_exit1_activate (GtkAction * action, AnjutaApp *app)
 {
@@ -86,9 +88,9 @@ on_toolbar_view_toggled (GtkAction *action, AnjutaApp *app)
 	{
 		gtk_widget_hide (app->toolbar);
 	}
-	anjuta_preferences_set_bool (app->preferences,
-								"toolbar-visible",
-								status);
+	g_settings_set_boolean (app->settings,
+	                        TOOLBAR_VISIBLE,
+	                        status);
 }
 
 void
diff --git a/src/anjuta-app.c b/src/anjuta-app.c
index 627dd28..e4362fc 100644
--- a/src/anjuta-app.c
+++ b/src/anjuta-app.c
@@ -46,6 +46,11 @@
 #define GLADE_FILE PACKAGE_DATA_DIR"/glade/preferences.ui"
 #define ICON_FILE "anjuta-preferences-general-48.png"
 
+#define PREF_SCHEMA "org.gnome.anjuta"
+#define GDL_STYLE "gdl-style"
+#define TOOLBAR_VISIBLE "toolbar-visible"
+#define TOOLBAR_STYLE "toolbar-style"
+
 static void anjuta_app_layout_load (AnjutaApp *app,
 									const gchar *layout_filename,
 									const gchar *name);
@@ -249,28 +254,23 @@ anjuta_app_unmaximize (AnjutaShell *shell,
 }
 
 static void
-on_toolbar_style_changed (AnjutaPreferences* prefs,
+on_toolbar_style_changed (GSettings* settings,
                           const gchar* key,
                           gpointer user_data)
 {
 	AnjutaApp* app = ANJUTA_APP (user_data);
-	gchar* tb_style = anjuta_preferences_get (prefs, key);
-	
-	if (tb_style)
-	{	
-		if (strcasecmp (tb_style, "Default") == 0)
-			style = -1;
-		else if (strcasecmp (tb_style, "Both") == 0)
-			style = GTK_TOOLBAR_BOTH;
-		else if (strcasecmp (tb_style, "Horiz") == 0)
-			style = GTK_TOOLBAR_BOTH_HORIZ;
-		else if (strcasecmp (tb_style, "Icons") == 0)
-			style = GTK_TOOLBAR_ICONS;
-		else if (strcasecmp (tb_style, "Text") == 0)
-			style = GTK_TOOLBAR_TEXT;
-		
-		DEBUG_PRINT ("Toolbar style: %s", tb_style);
-	}
+	gchar* tb_style = g_settings_get_string (settings, key);
+
+	if (strcasecmp (tb_style, "Default") == 0)
+		style = -1;
+	else if (strcasecmp (tb_style, "Both") == 0)
+		style = GTK_TOOLBAR_BOTH;
+	else if (strcasecmp (tb_style, "Horiz") == 0)
+		style = GTK_TOOLBAR_BOTH_HORIZ;
+	else if (strcasecmp (tb_style, "Icons") == 0)
+		style = GTK_TOOLBAR_ICONS;
+	else if (strcasecmp (tb_style, "Text") == 0)
+		style = GTK_TOOLBAR_TEXT;
 	
 	if (style != -1)
 	{
@@ -284,30 +284,26 @@ on_toolbar_style_changed (AnjutaPreferences* prefs,
 }
 
 static void
-on_gdl_style_changed (AnjutaPreferences* prefs,
+on_gdl_style_changed (GSettings* settings,
                       const gchar* key,
                       gpointer user_data)
 {
 	AnjutaApp* app = ANJUTA_APP (user_data);
 	GdlSwitcherStyle style = GDL_SWITCHER_STYLE_BOTH;
 
-	gchar* pr_style = anjuta_preferences_get (prefs, key);
+	gchar* pr_style = g_settings_get_string (settings, key);
+
+	if (strcasecmp (pr_style, "Text") == 0)
+		style = GDL_SWITCHER_STYLE_TEXT;
+	else if (strcasecmp (pr_style, "Icon") == 0)
+		style = GDL_SWITCHER_STYLE_ICON;
+	else if (strcasecmp (pr_style, "Both") == 0)
+		style = GDL_SWITCHER_STYLE_BOTH;
+	else if (strcasecmp (pr_style, "Toolbar") == 0)
+		style = GDL_SWITCHER_STYLE_TOOLBAR;
+	else if (strcasecmp (pr_style, "Tabs") == 0)
+		style = GDL_SWITCHER_STYLE_TABS;
 	
-	if (pr_style)
-	{
-		if (strcasecmp (pr_style, "Text") == 0)
-			style = GDL_SWITCHER_STYLE_TEXT;
-		else if (strcasecmp (pr_style, "Icon") == 0)
-			style = GDL_SWITCHER_STYLE_ICON;
-		else if (strcasecmp (pr_style, "Both") == 0)
-			style = GDL_SWITCHER_STYLE_BOTH;
-		else if (strcasecmp (pr_style, "Toolbar") == 0)
-			style = GDL_SWITCHER_STYLE_TOOLBAR;
-		else if (strcasecmp (pr_style, "Tabs") == 0)
-			style = GDL_SWITCHER_STYLE_TABS;
-		
-		DEBUG_PRINT ("Switcher style: %s", pr_style);
-	}
 	g_object_set (G_OBJECT(app->layout_manager->master), "switcher-style",
 				  style, NULL);
 	g_free (pr_style);
@@ -510,6 +506,11 @@ anjuta_app_dispose (GObject *widget)
 		app->status = NULL;
 	}
 
+	if (app->settings) {
+		g_object_unref (app->settings);
+		app->settings = NULL;
+	}
+	
 	G_OBJECT_CLASS (parent_class)->dispose (widget);
 }
 
@@ -558,6 +559,9 @@ anjuta_app_instance_init (AnjutaApp *app)
 	app->values = NULL;
 	app->widgets = NULL;
 	app->maximized = FALSE;
+
+	/* Settings */
+	app->settings = g_settings_new (PREF_SCHEMA);
 	
 	/* Status bar */
 	app->status = ANJUTA_STATUS (anjuta_status_new ());
@@ -611,9 +615,9 @@ anjuta_app_instance_init (AnjutaApp *app)
 	g_object_add_weak_pointer (G_OBJECT (app->preferences),
 							   (gpointer)&app->preferences);
 	
-	anjuta_preferences_notify_add (app->preferences, "gdl-style",
-	                               on_gdl_style_changed, app);
-	on_gdl_style_changed (app->preferences, "gdl-style", app);
+	g_signal_connect (app->settings, "changed::" GDL_STYLE, 
+	                  G_CALLBACK (on_gdl_style_changed), app);
+	on_gdl_style_changed (app->settings, GDL_STYLE, app);
 	
 	/* Register actions */
 	anjuta_ui_add_action_group_entries (app->ui, "ActionGroupFile", _("File"),
@@ -654,17 +658,17 @@ anjuta_app_instance_init (AnjutaApp *app)
 	/* create toolbar */	
 	app->toolbar = gtk_ui_manager_get_widget (GTK_UI_MANAGER (app->ui),
 										 "/ToolbarMain");
-    if (!anjuta_preferences_get_bool (app->preferences, "toolbar-visible"))
+    if (!g_settings_get_boolean (app->settings, TOOLBAR_VISIBLE))
 		gtk_widget_hide (app->toolbar);
 	gtk_box_pack_start (GTK_BOX (main_box), app->toolbar, FALSE, FALSE, 0);
 	action = gtk_ui_manager_get_action (GTK_UI_MANAGER (app->ui),
 										"/MenuMain/MenuView/Toolbar");
 	gtk_toggle_action_set_active (GTK_TOGGLE_ACTION(action),
-								  anjuta_preferences_get_bool (app->preferences,
-								                               "toolbar-visible"));
-	anjuta_preferences_notify_add (app->preferences, "toolbar-style",
-								   on_toolbar_style_changed, app);
-	on_toolbar_style_changed (app->preferences, "toolbar-style", app);
+								  g_settings_get_boolean (app->settings,
+								                          TOOLBAR_VISIBLE));
+	g_signal_connect (app->settings, "changed::" TOOLBAR_STYLE,
+	                  G_CALLBACK (on_toolbar_style_changed), app);
+	on_toolbar_style_changed (app->settings, TOOLBAR_STYLE, app);
 
 	/* Create widgets menu */
 	view_menu = 
@@ -912,7 +916,7 @@ anjuta_app_install_preferences (AnjutaApp *app)
 		g_error_free (error);
 		return;
 	}
-	anjuta_preferences_add_from_builder (app->preferences, builder, 
+	anjuta_preferences_add_from_builder (app->preferences, builder, app->settings,
 								 "General", _("General"), ICON_FILE);
 	notebook = 	GTK_WIDGET (gtk_builder_get_object (builder, "General"));
 	shortcuts = anjuta_ui_get_accel_editor (ANJUTA_UI (app->ui));
diff --git a/src/anjuta-app.h b/src/anjuta-app.h
index b9fced6..d4f875d 100644
--- a/src/anjuta-app.h
+++ b/src/anjuta-app.h
@@ -57,6 +57,7 @@ struct _AnjutaApp
 	AnjutaStatus *status;
 	AnjutaUI *ui;
 	AnjutaPreferences *preferences;
+	GSettings* settings;
 	AnjutaPluginManager *plugin_manager;
 	AnjutaProfileManager *profile_manager;
 
diff --git a/src/anjuta.c b/src/anjuta.c
index 1347f84..a60c50e 100644
--- a/src/anjuta.c
+++ b/src/anjuta.c
@@ -56,9 +56,9 @@ on_anjuta_delete_event (AnjutaApp *app, GdkEvent *event, gpointer data)
 	/* Save remembered plugins */
 	remembered_plugins =
 		anjuta_plugin_manager_get_remembered_plugins (plugin_manager);
-	anjuta_preferences_set (app->preferences,
-							ANJUTA_REMEMBERED_PLUGINS,
-							remembered_plugins);
+	g_settings_set_string (app->settings,
+	                       ANJUTA_REMEMBERED_PLUGINS,
+	                       remembered_plugins);
 	g_free (remembered_plugins);
 	
 	/* Check for unsaved data */
@@ -271,7 +271,7 @@ anjuta_new (gchar *prog_name, gchar **files, gboolean no_splash,
 	
 	/* Restore remembered plugins */
 	remembered_plugins =
-		anjuta_preferences_get (app->preferences, ANJUTA_REMEMBERED_PLUGINS);
+		g_settings_get_string (app->settings, ANJUTA_REMEMBERED_PLUGINS);
 	if (remembered_plugins)
 		anjuta_plugin_manager_set_remembered_plugins (plugin_manager,
 													  remembered_plugins);
@@ -377,8 +377,8 @@ anjuta_new (gchar *prog_name, gchar **files, gboolean no_splash,
 		
 		/* If preferences is set to not load last session, clear it */
 		if (no_session ||
-			anjuta_preferences_get_bool (app->preferences,
-										ANJUTA_SESSION_SKIP_LAST))
+			g_settings_get_boolean (app->settings,
+			                        ANJUTA_SESSION_SKIP_LAST))
 		{
 			/* Reset default session */
 			session = anjuta_session_new (session_dir);
@@ -387,8 +387,8 @@ anjuta_new (gchar *prog_name, gchar **files, gboolean no_splash,
 		}
 		/* If preferences is set to not load last project, clear it */
 		else if (no_files ||
-				 anjuta_preferences_get_bool (app->preferences,
-											 ANJUTA_SESSION_SKIP_LAST_FILES))
+				g_settings_get_boolean (app->settings,
+				                        ANJUTA_SESSION_SKIP_LAST_FILES))
 		{
 			session = anjuta_session_new (session_dir);
 			anjuta_session_set_string_list (session, "File Loader",



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]