[anjuta/gsettings-migration: 38/65] message-view: Ported to GSettings API



commit c6df4c842c6242ca2fb86ba023281f76aed698a0
Author: Johannes Schmid <jhs gnome org>
Date:   Sat Oct 9 12:52:29 2010 +0200

    message-view: Ported to GSettings API

 plugins/message-view/anjuta-msgman.c |   10 ++--
 plugins/message-view/anjuta-msgman.h |    4 +-
 plugins/message-view/message-view.c  |   65 +++++++++--------------
 plugins/message-view/plugin.c        |   94 +++------------------------------
 plugins/message-view/plugin.h        |    1 +
 5 files changed, 42 insertions(+), 132 deletions(-)
---
diff --git a/plugins/message-view/anjuta-msgman.c b/plugins/message-view/anjuta-msgman.c
index a8727c4..cb836b9 100644
--- a/plugins/message-view/anjuta-msgman.c
+++ b/plugins/message-view/anjuta-msgman.c
@@ -264,12 +264,12 @@ anjuta_msgman_class_init (AnjutaMsgmanClass * klass)
 }
 
 static void
-set_message_tab(AnjutaPreferences *pref, GtkNotebook *msgman)
+set_message_tab(GSettings* settings, GtkNotebook *msgman)
 {
 	gchar *tab_pos; 
 	GtkPositionType pos;
-	
-	tab_pos = anjuta_preferences_get (pref, MESSAGES_TABS_POS);
+
+	tab_pos = g_settings_get_string (settings, MESSAGES_TABS_POS);
 	pos = GTK_POS_TOP;
 	if (tab_pos)
 	{
@@ -285,10 +285,10 @@ set_message_tab(AnjutaPreferences *pref, GtkNotebook *msgman)
 }
 
 void
-on_notify_message_pref (AnjutaPreferences* prefs, const gchar* key,
+on_notify_message_pref (GSettings *settings, const gchar* key,
                         gpointer user_data)
 {
-	set_message_tab(prefs, GTK_NOTEBOOK (user_data));
+	set_message_tab(settings, GTK_NOTEBOOK (user_data));
 }
 
 
diff --git a/plugins/message-view/anjuta-msgman.h b/plugins/message-view/anjuta-msgman.h
index 587e81d..143749d 100644
--- a/plugins/message-view/anjuta-msgman.h
+++ b/plugins/message-view/anjuta-msgman.h
@@ -22,7 +22,7 @@
 #include <libanjuta/anjuta-preferences.h>
 #include "message-view.h"
 
-#define MESSAGES_TABS_POS  "messages.tab.position"
+#define MESSAGES_TABS_POS "messages-tab-position"
 
 #define ANJUTA_TYPE_MSGMAN        (anjuta_msgman_get_type ())
 #define ANJUTA_MSGMAN(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), ANJUTA_TYPE_MSGMAN, AnjutaMsgman))
@@ -82,7 +82,7 @@ gboolean anjuta_msgman_deserialize (AnjutaMsgman *msgman,
 GtkWidget* anjuta_msgman_get_tabber (AnjutaMsgman* msgman);
 
 void
-on_notify_message_pref (AnjutaPreferences* prefs, const gchar* key,
+on_notify_message_pref (GSettings* settings, const gchar* key,
                         gpointer user_data);
 
 #endif /* _ANJUTA_MSGMAN_H */
diff --git a/plugins/message-view/message-view.c b/plugins/message-view/message-view.c
index 71672d3..1d4fad6 100644
--- a/plugins/message-view/message-view.c
+++ b/plugins/message-view/message-view.c
@@ -22,7 +22,11 @@
 
 #include "message-view.h"
 #define MESSAGE_TYPE message_get_type()
-	
+
+#define PREFERENCES_SCHEMA "org.gnome.anjuta.message-manager"
+#define COLOR_ERROR "messages.color.error"
+#define COLOR_WARNING "messages.color.warning"
+
 struct _MessageViewPrivate
 {
 	//guint num_messages;
@@ -48,8 +52,7 @@ struct _MessageViewPrivate
 	gchar *pixmap;
 	gboolean highlite;
 	
-	/* gconf notification ids */
-	GList *notify_ids;
+	GSettings* settings;
 };
 
 typedef struct
@@ -432,11 +435,7 @@ static void
 message_view_dispose (GObject *obj)
 {
 	MessageView *mview = MESSAGE_VIEW (obj);
-	if (mview->privat->notify_ids)
-	{
-		prefs_finalize (mview);
-		mview->privat->notify_ids = NULL;
-	}
+	prefs_finalize (mview);
 	if (mview->privat->tree_view)
 	{
 		mview->privat->tree_view = NULL;
@@ -908,7 +907,7 @@ pref_change_color (MessageView *mview, IAnjutaMessageViewType type,
 	GtkTreeIter iter;
 	gboolean success;
 	
-	color = anjuta_preferences_get (anjuta_preferences_default(), color_pref_key);
+	color = g_settings_get_string (mview->privat->settings, color_pref_key);
 	store = GTK_LIST_STORE (mview->privat->model);
 	success = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
 	while (success)
@@ -927,45 +926,33 @@ pref_change_color (MessageView *mview, IAnjutaMessageViewType type,
 
 
 static void
-on_notify_color (AnjutaPreferences* prefs, const gchar* key,
+on_notify_color (GSettings* settings, const gchar* key,
                  gpointer user_data)
 {
-	pref_change_color (MESSAGE_VIEW (user_data),
-					   IANJUTA_MESSAGE_VIEW_TYPE_WARNING,
-					   key);
+	if (g_str_equal (key, COLOR_ERROR))
+	    pref_change_color (MESSAGE_VIEW (user_data),
+	                       IANJUTA_MESSAGE_VIEW_TYPE_ERROR,
+	                       key);
+	else
+	    pref_change_color (MESSAGE_VIEW (user_data),
+	                       IANJUTA_MESSAGE_VIEW_TYPE_WARNING,
+	                       key);
 }
 
 static void
 prefs_init (MessageView *mview)
 {
-	gint id;
-	id = anjuta_preferences_notify_add (anjuta_preferences_default (),
-	                                    "messages.color.error",
-	                                    on_notify_color,
-	                                    mview);
-	mview->privat->notify_ids = g_list_append (mview->privat->notify_ids,
-	                                           GINT_TO_POINTER (id));	
-	id = anjuta_preferences_notify_add (anjuta_preferences_default (),
-	                                    "messages.color.warning",
-	                                    on_notify_color,
-	                                    mview);
-	mview->privat->notify_ids = g_list_append (mview->privat->notify_ids,
-	                                         GINT_TO_POINTER (id));
+	mview->privat->settings = g_settings_new (PREFERENCES_SCHEMA);
+	g_signal_connect (mview->privat->settings, "changed::" COLOR_ERROR,
+	                  G_CALLBACK (on_notify_color), mview);
+	g_signal_connect (mview->privat->settings, "changed::" COLOR_WARNING,
+	                  G_CALLBACK (on_notify_color), mview);
 }
 
 static void
 prefs_finalize (MessageView *mview)
 {
-	GList *node;
-	node = mview->privat->notify_ids;
-	while (node)
-	{
-		anjuta_preferences_notify_remove (anjuta_preferences_default(),
-										  GPOINTER_TO_INT (node->data));
-		node = g_list_next (node);
-	}
-	g_list_free (mview->privat->notify_ids);
-	mview->privat->notify_ids = NULL;
+	g_object_unref (mview->privat->settings);
 }
 
 /* IAnjutaMessageView interface implementation */
@@ -1039,15 +1026,13 @@ imessage_view_append (IAnjutaMessageView *message_view,
 				stock_id = GTK_STOCK_INFO;
 				break;
 			case IANJUTA_MESSAGE_VIEW_TYPE_WARNING:
-				color = anjuta_preferences_get (anjuta_preferences_default(),
-									  "msgman-color-warning");
+				color = g_settings_get_string (view->privat->settings, COLOR_WARNING);
 				/* FIXME: There is no GTK_STOCK_WARNING which would fit better here */
 				view->privat->warn_count++;
 				stock_id = GTK_STOCK_DIALOG_WARNING;
 				break;
 			case IANJUTA_MESSAGE_VIEW_TYPE_ERROR:
-				color = anjuta_preferences_get (anjuta_preferences_default(),
-									  "msgman-color-error");
+				color = g_settings_get_string (view->privat->settings, COLOR_ERROR);
 				view->privat->error_count++;
 				stock_id = GTK_STOCK_STOP;
 				break;
diff --git a/plugins/message-view/plugin.c b/plugins/message-view/plugin.c
index 335cd70..0b14954 100644
--- a/plugins/message-view/plugin.c
+++ b/plugins/message-view/plugin.c
@@ -29,6 +29,7 @@
 
 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-message-manager.xml"
 #define PREFS_BUILDER PACKAGE_DATA_DIR"/glade/anjuta-message-manager-plugin.ui"
+#define PREFERENCES_SCHEMA "org.gnome.anjuta.message-manager"
 
 /* Pixmaps */
 #define ANJUTA_PIXMAP_MESSAGES                "anjuta-messages-plugin-48.png"
@@ -146,67 +147,6 @@ register_stock_icons (AnjutaPlugin *plugin)
 	END_REGISTER_ICON;
 }
 
-#if 0 /* Disable session saving/loading until a way is found to avoid
-       * number of message panes infinitely growing */
-static void
-on_session_save (AnjutaShell *shell, AnjutaSessionPhase phase,
-				 AnjutaSession *session, MessageViewPlugin *plugin)
-{
-	gboolean success;
-	const gchar *dir;
-	gchar *messages_file;
-	AnjutaSerializer *serializer;
-		
-	if (phase != ANJUTA_SESSION_PHASE_NORMAL)
-		return;
-	
-	dir = anjuta_session_get_session_directory (session);
-	messages_file = g_build_filename (dir, "messages.txt", NULL);
-	serializer = anjuta_serializer_new (messages_file,
-										ANJUTA_SERIALIZER_WRITE);
-	if (!serializer)
-	{
-		g_free (messages_file);
-		return;
-	}
-	success = anjuta_msgman_serialize (ANJUTA_MSGMAN (plugin->msgman),
-									   serializer);
-	g_object_unref (serializer);
-	if (!success)
-	{
-		g_warning ("Serialization failed: deleting %s", messages_file);
-		unlink (messages_file);
-	}
-	g_free (messages_file);
-}
-
-static void
-on_session_load (AnjutaShell *shell, AnjutaSessionPhase phase,
-				 AnjutaSession *session, MessageViewPlugin *plugin)
-{
-	const gchar *dir;
-	gchar *messages_file;
-	AnjutaSerializer *serializer;
-	
-	if (phase != ANJUTA_SESSION_PHASE_NORMAL)
-		return;
-	
-	dir = anjuta_session_get_session_directory (session);
-	messages_file = g_build_filename (dir, "messages.txt", NULL);
-	serializer = anjuta_serializer_new (messages_file,
-										ANJUTA_SERIALIZER_READ);
-	if (!serializer)
-	{
-		g_free (messages_file);
-		return;
-	}
-	anjuta_msgman_remove_all_views (ANJUTA_MSGMAN (plugin->msgman));
-	anjuta_msgman_deserialize (ANJUTA_MSGMAN (plugin->msgman), serializer);
-	g_object_unref (serializer);
-	g_free (messages_file);
-}
-#endif
-
 static gboolean
 activate_plugin (AnjutaPlugin *plugin)
 {
@@ -245,13 +185,6 @@ activate_plugin (AnjutaPlugin *plugin)
 	g_object_set (G_OBJECT (action_prev), "sensitive", FALSE, NULL);
 	g_object_set (G_OBJECT (action_copy), "sensitive", FALSE, NULL);
 	
-#if 0
-	/* Connect to save and load session */
-	g_signal_connect (G_OBJECT (plugin->shell), "save-session",
-					  G_CALLBACK (on_session_save), plugin);
-	g_signal_connect (G_OBJECT (plugin->shell), "load-session",
-					  G_CALLBACK (on_session_load), plugin);
-#endif
 	initialized = TRUE;
 	mv_plugin->widget_shown = FALSE;
 	return TRUE;
@@ -266,15 +199,7 @@ deactivate_plugin (AnjutaPlugin *plugin)
 	DEBUG_PRINT ("%s", "MessageViewPlugin: Dectivating message view plugin ...");
 	
 	mplugin = ANJUTA_PLUGIN_MESSAGE_VIEW (plugin);
-#if 0
-	/* Disconnect signals */
-	g_signal_handlers_disconnect_by_func (G_OBJECT (plugin->shell),
-										  G_CALLBACK (on_session_save),
-										  plugin);
-	g_signal_handlers_disconnect_by_func (G_OBJECT (plugin->shell),
-										  G_CALLBACK (on_session_load),
-										  plugin);
-#endif
+
 	/* Widget is removed as soon as it is destroyed */
 	if (mplugin->widget_shown)
 		gtk_widget_destroy (mplugin->msgman);
@@ -291,7 +216,8 @@ deactivate_plugin (AnjutaPlugin *plugin)
 static void
 message_view_plugin_dispose (GObject *obj)
 {
-	// MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
+	MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
+	g_object_unref (plugin->settings);
 	G_OBJECT_CLASS (parent_class)->dispose (obj);
 }
 
@@ -309,6 +235,7 @@ message_view_plugin_instance_init (GObject *obj)
 	plugin->action_group = NULL;
 	plugin->msgman = NULL;
 	plugin->uiid = 0;
+	plugin->settings = g_settings_new (PREFERENCES_SCHEMA);
 }
 
 static void
@@ -569,8 +496,6 @@ ianjuta_msgman_iface_init (IAnjutaMessageManagerIface *iface)
 	iface->set_view_icon_from_stock = ianjuta_msgman_set_view_icon_from_stock;
 }
 
-static guint notify_id;
-
 static void
 ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
 {
@@ -585,19 +510,18 @@ ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError**
 		g_error_free (error);
 		return;
 	}
-	anjuta_preferences_add_from_builder (prefs, bxml,
+	anjuta_preferences_add_from_builder (prefs, bxml, plugin->settings,
 									"Messages", _("Messages"),
 									 ANJUTA_PIXMAP_MESSAGES);
-	notify_id = anjuta_preferences_notify_add (prefs, MESSAGES_TABS_POS, 
-                                               on_notify_message_pref, plugin->msgman);
-		
+	
+	g_signal_connect (plugin->settings, "changed::messages-tab-position",
+	                  G_CALLBACK (on_notify_message_pref), plugin->msgman);		
 	g_object_unref (bxml);
 }
 
 static void
 ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
 {
-	anjuta_preferences_notify_remove(prefs, notify_id);
 	anjuta_preferences_remove_page(prefs, _("Messages"));
 }
 
diff --git a/plugins/message-view/plugin.h b/plugins/message-view/plugin.h
index 40accd8..b87fd57 100644
--- a/plugins/message-view/plugin.h
+++ b/plugins/message-view/plugin.h
@@ -44,6 +44,7 @@ struct _MessageViewPlugin {
 	GtkWidget* info;
 	
 	gboolean widget_shown;
+	GSettings* settings;
 };
 
 struct _MessageViewPluginClass {



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