[libgnomekbd] Refactor widget_instances into GkbdConfiguration



commit bacfeb4afe34b69cf182ae5b9be16b10116ee566
Author: Sergey V. Udaltsov <svu gnome org>
Date:   Mon Jan 3 14:40:53 2011 +0000

    Refactor widget_instances into GkbdConfiguration
    
    Reducing the amount of repeated code.
    Additionally, signal handling fixed in GkbdStatus

 libgnomekbd/gkbd-configuration.c |  104 ++++++++++++++++++++++++++++++------
 libgnomekbd/gkbd-configuration.h |   36 +++++++++++--
 libgnomekbd/gkbd-indicator.c     |  107 ++++++++++---------------------------
 libgnomekbd/gkbd-status.c        |   78 +++++++++++++++------------
 4 files changed, 190 insertions(+), 135 deletions(-)
---
diff --git a/libgnomekbd/gkbd-configuration.c b/libgnomekbd/gkbd-configuration.c
index 6f3b727..ee22ffe 100644
--- a/libgnomekbd/gkbd-configuration.c
+++ b/libgnomekbd/gkbd-configuration.c
@@ -1,10 +1,10 @@
 /*
  * Copyright (C) 2010 Canonical Ltd.
+ * Copyright (C) 2010-2011 Sergey V. Udaltsov <svu gnome org>
  * 
  * Authors: Jan Arne Petersen <jpetersen openismus com>
+ *          Sergey V. Udaltsov <svu gnome org>
  * 
- * Based on gkbd-status.c by Sergey V. Udaltsov <svu gnome org>
- *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -46,6 +46,8 @@ struct _GkbdConfigurationPrivate {
 
 	gulong state_changed_handler;
 	gulong config_changed_handler;
+
+	GSList *widget_instances;
 };
 
 enum {
@@ -107,10 +109,8 @@ gkbd_configuration_load_group_names (GkbdConfiguration * configuration,
 							  xklrec->layouts,
 							  (const char **)
 							  xklrec->variants,
-							  &priv->
-							  short_group_names,
-							  &priv->
-							  full_group_names))
+							  &priv->short_group_names,
+							  &priv->full_group_names))
 	{
 		/* We just populate no short names (remain NULL) - 
 		 * full names are going to be used anyway */
@@ -356,8 +356,8 @@ gkbd_configuration_get_image_filename (GkbdConfiguration * configuration,
 {
 	if (!configuration->priv->ind_cfg.show_flags)
 		return NULL;
-	return (gchar *) g_slist_nth_data (configuration->priv->ind_cfg.
-					   image_filenames, group);
+	return (gchar *) g_slist_nth_data (configuration->priv->
+					   ind_cfg.image_filenames, group);
 }
 
 /**
@@ -383,8 +383,8 @@ gkbd_configuration_get_current_tooltip (GkbdConfiguration * configuration)
 		return NULL;
 
 	return g_strdup_printf (configuration->priv->tooltips_format,
-				configuration->priv->
-				full_group_names[state->group]);
+				configuration->
+				priv->full_group_names[state->group]);
 }
 
 gboolean
@@ -405,8 +405,8 @@ gkbd_configuration_extract_layout_name (GkbdConfiguration * configuration,
 		if (xkl_engine_get_features (engine) &
 		    XKLF_MULTIPLE_LAYOUTS_SUPPORTED) {
 			char *full_layout_name =
-			    configuration->priv->kbd_cfg.
-			    layouts_variants[group];
+			    configuration->priv->
+			    kbd_cfg.layouts_variants[group];
 			char *variant_name;
 			if (!gkbd_keyboard_config_split_items
 			    (full_layout_name, &layout_name,
@@ -470,16 +470,38 @@ gkbd_configuration_get_keyboard_config (GkbdConfiguration * configuration)
  * Returns: (transfer full) (element-type GdkPixbuf): list of images
  */
 GSList *
+gkbd_configuration_get_all_objects (GkbdConfiguration * configuration)
+{
+	return configuration->priv->widget_instances;
+}
+
+extern void
+gkbd_configuration_append_object (GkbdConfiguration * configuration,
+				  GObject * obj)
+{
+	configuration->priv->widget_instances =
+	    g_slist_append (configuration->priv->widget_instances, obj);
+}
+
+extern void
+gkbd_configuration_remove_object (GkbdConfiguration * configuration,
+				  GObject * obj)
+{
+	configuration->priv->widget_instances =
+	    g_slist_remove (configuration->priv->widget_instances, obj);
+}
+
+GSList *
 gkbd_configuration_load_images (GkbdConfiguration * configuration)
 {
 	int i;
 	GSList *image_filename, *images;
 
 	images = NULL;
-	gkbd_indicator_config_load_image_filenames (&configuration->
-						    priv->ind_cfg,
-						    &configuration->
-						    priv->kbd_cfg);
+	gkbd_indicator_config_load_image_filenames (&configuration->priv->
+						    ind_cfg,
+						    &configuration->priv->
+						    kbd_cfg);
 
 	if (!configuration->priv->ind_cfg.show_flags)
 		return NULL;
@@ -515,8 +537,8 @@ gkbd_configuration_free_images (GkbdConfiguration * configuration,
 	GdkPixbuf *pi;
 	GSList *img_node;
 
-	gkbd_indicator_config_free_image_filenames (&configuration->
-						    priv->ind_cfg);
+	gkbd_indicator_config_free_image_filenames (&configuration->priv->
+						    ind_cfg);
 
 	while ((img_node = images) != NULL) {
 		pi = GDK_PIXBUF (img_node->data);
@@ -528,3 +550,49 @@ gkbd_configuration_free_images (GkbdConfiguration * configuration,
 		g_slist_free_1 (img_node);
 	}
 }
+
+gchar *
+gkbd_configuration_create_label_title (int group, GHashTable ** ln2cnt_map,
+				       gchar * layout_name)
+{
+	gpointer pcounter = NULL;
+	char *prev_layout_name = NULL;
+	char *lbl_title = NULL;
+	int counter = 0;
+
+	if (group == 0) {
+		*ln2cnt_map =
+		    g_hash_table_new_full (g_str_hash, g_str_equal,
+					   g_free, NULL);
+	}
+
+	/* Process layouts with repeating description */
+	if (g_hash_table_lookup_extended
+	    (*ln2cnt_map, layout_name, (gpointer *) & prev_layout_name,
+	     &pcounter)) {
+		/* "next" same description */
+		gchar appendix[10] = "";
+		gint utf8length;
+		gunichar cidx;
+		counter = GPOINTER_TO_INT (pcounter);
+		/* Unicode subscript 2, 3, 4 */
+		cidx = 0x2081 + counter;
+		utf8length = g_unichar_to_utf8 (cidx, appendix);
+		appendix[utf8length] = '\0';
+		lbl_title = g_strconcat (layout_name, appendix, NULL);
+	} else {
+		/* "first" time this description */
+		lbl_title = g_strdup (layout_name);
+	}
+	g_hash_table_insert (*ln2cnt_map, layout_name,
+			     GINT_TO_POINTER (counter + 1));
+	return lbl_title;
+}
+
+extern gboolean
+gkbd_configuration_if_any_object_exists (GkbdConfiguration * configuration)
+{
+	return (configuration != NULL)
+	    && (g_slist_length (configuration->priv->widget_instances) !=
+		0);
+}
diff --git a/libgnomekbd/gkbd-configuration.h b/libgnomekbd/gkbd-configuration.h
index 3caa1f8..ababc93 100644
--- a/libgnomekbd/gkbd-configuration.h
+++ b/libgnomekbd/gkbd-configuration.h
@@ -1,10 +1,10 @@
 /*
  * Copyright (C) 2010 Canonical Ltd.
+ * Copyright (C) 2010-2011 Sergey V. Udaltsov <svu gnome org>
  * 
  * Authors: Jan Arne Petersen <jpetersen openismus com>
+ *          Sergey V. Udaltsov <svu gnome org>
  * 
- * Based on gkbd-status.h by Sergey V. Udaltsov <svu gnome org>
- *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
@@ -78,8 +78,31 @@ extern GkbdIndicatorConfig
     * gkbd_configuration_get_indicator_config (GkbdConfiguration *
 					       configuration);
 extern GkbdKeyboardConfig
-    *gkbd_configuration_get_keyboard_config (GkbdConfiguration *
-					     configuration);
+    * gkbd_configuration_get_keyboard_config (GkbdConfiguration *
+					      configuration);
+
+extern GSList *gkbd_configuration_get_all_objects (GkbdConfiguration *
+						   configuration);
+
+extern gboolean gkbd_configuration_if_any_object_exists (GkbdConfiguration
+							 * configuration);
+
+extern void gkbd_configuration_append_object (GkbdConfiguration *
+					      configuration,
+					      GObject * obj);
+
+extern void gkbd_configuration_remove_object (GkbdConfiguration *
+					      configuration,
+					      GObject * obj);
+
+#define ForAllObjects(config) \
+	{ \
+		GSList* cur; \
+		for (cur = gkbd_configuration_get_all_objects (config); cur != NULL; cur = cur->next) { \
+			GObject* gki = (GObject*)cur->data;
+#define NextObject() \
+		} \
+	}
 
 extern GSList *gkbd_configuration_load_images (GkbdConfiguration *
 					       configuration);
@@ -88,5 +111,10 @@ extern void gkbd_configuration_free_images (GkbdConfiguration *
 					    configuration,
 					    GSList * images);
 
+extern gchar *gkbd_configuration_create_label_title (int group,
+						     GHashTable **
+						     ln2cnt_map,
+						     gchar * layout_name);
+
 G_END_DECLS
 #endif
diff --git a/libgnomekbd/gkbd-indicator.c b/libgnomekbd/gkbd-indicator.c
index f6cdb70..c59368b 100644
--- a/libgnomekbd/gkbd-indicator.c
+++ b/libgnomekbd/gkbd-indicator.c
@@ -38,7 +38,6 @@ typedef struct _gki_globals {
 	GkbdIndicatorPluginContainer plugin_container;
 	GkbdIndicatorPluginManager plugin_manager;
 
-	GSList *widget_instances;
 	GSList *images;
 } gki_globals;
 
@@ -50,15 +49,6 @@ struct _GkbdIndicatorPrivate {
 /* one instance for ALL widgets */
 static gki_globals globals;
 
-#define ForAllIndicators() \
-	{ \
-		GSList* cur; \
-		for (cur = globals.widget_instances; cur != NULL; cur = cur->next) { \
-			GkbdIndicator * gki = (GkbdIndicator*)cur->data;
-#define NextIndicator() \
-		} \
-	}
-
 G_DEFINE_TYPE (GkbdIndicator, gkbd_indicator, GTK_TYPE_NOTEBOOK)
 
 static void
@@ -152,8 +142,8 @@ gkbd_indicator_fill (GkbdIndicator * gki)
 		    gkbd_indicator_plugin_manager_decorate_widget
 		    (&globals.plugin_manager, page, grp,
 		     full_group_name,
-		     gkbd_configuration_get_keyboard_config (globals.
-							     config));
+		     gkbd_configuration_get_keyboard_config
+		     (globals.config));
 
 		page = decorated_page == NULL ? page : decorated_page;
 
@@ -233,44 +223,6 @@ flag_exposed (GtkWidget * flag, GdkEventExpose * event, GdkPixbuf * image)
 	cairo_destroy (cr);
 }
 
-gchar *
-gkbd_indicator_create_label_title (int group, GHashTable ** ln2cnt_map,
-				   gchar * layout_name)
-{
-	gpointer pcounter = NULL;
-	char *prev_layout_name = NULL;
-	char *lbl_title = NULL;
-	int counter = 0;
-
-	if (group == 0) {
-		*ln2cnt_map =
-		    g_hash_table_new_full (g_str_hash, g_str_equal,
-					   g_free, NULL);
-	}
-
-	/* Process layouts with repeating description */
-	if (g_hash_table_lookup_extended
-	    (*ln2cnt_map, layout_name, (gpointer *) & prev_layout_name,
-	     &pcounter)) {
-		/* "next" same description */
-		gchar appendix[10] = "";
-		gint utf8length;
-		gunichar cidx;
-		counter = GPOINTER_TO_INT (pcounter);
-		/* Unicode subscript 2, 3, 4 */
-		cidx = 0x2081 + counter;
-		utf8length = g_unichar_to_utf8 (cidx, appendix);
-		appendix[utf8length] = '\0';
-		lbl_title = g_strconcat (layout_name, appendix, NULL);
-	} else {
-		/* "first" time this description */
-		lbl_title = g_strdup (layout_name);
-	}
-	g_hash_table_insert (*ln2cnt_map, layout_name,
-			     GINT_TO_POINTER (counter + 1));
-	return lbl_title;
-}
-
 static GtkWidget *
 gkbd_indicator_prepare_drawing (GkbdIndicator * gki, int group)
 {
@@ -303,9 +255,9 @@ gkbd_indicator_prepare_drawing (GkbdIndicator * gki, int group)
 							    group);
 
 		lbl_title =
-		    gkbd_indicator_create_label_title (group,
-						       &ln2cnt_map,
-						       layout_name);
+		    gkbd_configuration_create_label_title (group,
+							   &ln2cnt_map,
+							   layout_name);
 
 		align = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
 		label = gtk_label_new (lbl_title);
@@ -370,16 +322,16 @@ gkbd_indicator_reinit_ui (GkbdIndicator * gki)
 
 /* Should be called once for all widgets */
 static void
-gkbd_indicator_kbd_cfg_callback (GkbdConfiguration * configuration)
+gkbd_indicator_cfg_callback (GkbdConfiguration * configuration)
 {
 	gkbd_indicator_plugin_manager_toggle_plugins
 	    (&globals.plugin_manager, &globals.plugin_container,
-	     gkbd_configuration_get_indicator_config (globals.config)->
-	     enabled_plugins);
+	     gkbd_configuration_get_indicator_config (globals.
+						      config)->enabled_plugins);
 
-	ForAllIndicators () {
-		gkbd_indicator_reinit_ui (gki);
-	} NextIndicator ();
+	ForAllObjects (configuration) {
+		gkbd_indicator_reinit_ui (GKBD_INDICATOR (gki));
+	} NextObject ()
 }
 
 /* Should be called once for all applets */
@@ -387,13 +339,14 @@ static void
 gkbd_indicator_state_callback (GkbdConfiguration * configuration,
 			       gint group)
 {
-	ForAllIndicators () {
+	ForAllObjects (configuration) {
 		gkbd_indicator_plugin_manager_group_changed
 		    (&globals.plugin_manager, GTK_WIDGET (gki), group);
 		xkl_debug (200, "do repaint\n");
-		gkbd_indicator_set_current_page_for_group (gki, group);
+		gkbd_indicator_set_current_page_for_group (GKBD_INDICATOR
+							   (gki), group);
 	}
-	NextIndicator ();
+	NextObject ()
 }
 
 
@@ -405,7 +358,8 @@ gkbd_indicator_set_current_page (GkbdIndicator * gki)
 	XklState *cur_state = xkl_engine_get_current_state (engine);
 	if (cur_state->group >= 0)
 		gkbd_indicator_set_current_page_for_group (gki,
-							   cur_state->group);
+							   cur_state->
+							   group);
 }
 
 void
@@ -432,7 +386,7 @@ gkbd_indicator_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
 		{
 			XReparentEvent *rne = (XReparentEvent *) xev;
 
-			ForAllIndicators () {
+			ForAllObjects (globals.config) {
 				GdkWindow *w =
 				    gtk_widget_get_parent_window
 				    (GTK_WIDGET (gki));
@@ -445,7 +399,7 @@ gkbd_indicator_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
 					    (engine, rne->window, TRUE);
 				}
 			}
-			NextIndicator ()
+			NextObject ()
 		}
 		break;
 	}
@@ -488,7 +442,7 @@ gkbd_indicator_init (GkbdIndicator * gki)
 	GtkWidget *def_drawing;
 	GtkNotebook *notebook;
 
-	if (!g_slist_length (globals.widget_instances))
+	if (!gkbd_configuration_if_any_object_exists (globals.config))
 		gkbd_indicator_global_init ();
 
 	gki->priv = g_new0 (GkbdIndicatorPrivate, 1);
@@ -523,8 +477,7 @@ gkbd_indicator_init (GkbdIndicator * gki)
 	gtk_widget_add_events (GTK_WIDGET (gki), GDK_BUTTON_PRESS_MASK);
 
 	/* append AFTER all initialization work is finished */
-	globals.widget_instances =
-	    g_slist_append (globals.widget_instances, gki);
+	gkbd_configuration_append_object (globals.config, G_OBJECT (gki));
 }
 
 static void
@@ -536,8 +489,7 @@ gkbd_indicator_finalize (GObject * obj)
 		   gki);
 
 	/* remove BEFORE all termination work is finished */
-	globals.widget_instances =
-	    g_slist_remove (globals.widget_instances, gki);
+	gkbd_configuration_remove_object (globals.config, G_OBJECT (gki));
 
 	gkbd_indicator_cleanup (gki);
 
@@ -548,7 +500,7 @@ gkbd_indicator_finalize (GObject * obj)
 
 	G_OBJECT_CLASS (gkbd_indicator_parent_class)->finalize (obj);
 
-	if (!g_slist_length (globals.widget_instances))
+	if (!gkbd_configuration_if_any_object_exists (globals.config))
 		gkbd_indicator_global_term ();
 }
 
@@ -602,8 +554,7 @@ gkbd_indicator_global_init (void)
 			  G_CALLBACK (gkbd_indicator_state_callback),
 			  NULL);
 	g_signal_connect (globals.config, "changed",
-			  G_CALLBACK (gkbd_indicator_kbd_cfg_callback),
-			  NULL);
+			  G_CALLBACK (gkbd_indicator_cfg_callback), NULL);
 
 	gkbd_indicator_plugin_container_init (&globals.plugin_container);
 
@@ -612,8 +563,8 @@ gkbd_indicator_global_init (void)
 	gkbd_indicator_plugin_manager_init (&globals.plugin_manager);
 	gkbd_indicator_plugin_manager_init_enabled_plugins
 	    (&globals.plugin_manager, &globals.plugin_container,
-	     gkbd_configuration_get_indicator_config (globals.config)->
-	     enabled_plugins);
+	     gkbd_configuration_get_indicator_config (globals.
+						      config)->enabled_plugins);
 
 	gkbd_indicator_start_listen ();
 
@@ -689,9 +640,9 @@ void
 gkbd_indicator_plugin_container_reinit_ui (GkbdIndicatorPluginContainer *
 					   pc)
 {
-	ForAllIndicators () {
-		gkbd_indicator_reinit_ui (gki);
-	} NextIndicator ();
+	ForAllObjects (globals.config) {
+		gkbd_indicator_reinit_ui (GKBD_INDICATOR (gki));
+	} NextObject ()
 }
 
 /**
diff --git a/libgnomekbd/gkbd-status.c b/libgnomekbd/gkbd-status.c
index 6aaf081..cc196d5 100644
--- a/libgnomekbd/gkbd-status.c
+++ b/libgnomekbd/gkbd-status.c
@@ -40,7 +40,6 @@ typedef struct _gki_globals {
 	int real_width;
 
 	GSList *icons;		/* list of GdkPixbuf */
-	GSList *widget_instances;	/* list of GkbdStatus */
 } gki_globals;
 
 static gchar *settings_signal_names[] = {
@@ -58,16 +57,8 @@ struct _GkbdStatusPrivate {
 /* one instance for ALL widgets */
 static gki_globals globals;
 
-#define ForAllIndicators() \
-	{ \
-		GSList* cur; \
-		for (cur = globals.widget_instances; cur != NULL; cur = cur->next) { \
-			GkbdStatus * gki = (GkbdStatus*)cur->data;
-#define NextIndicator() \
-		} \
-	}
-
 G_DEFINE_TYPE (GkbdStatus, gkbd_status, GTK_TYPE_STATUS_ICON)
+
 static void
 gkbd_status_global_init (void);
 static void
@@ -125,11 +116,6 @@ gkbd_status_activate (GkbdStatus * gki)
 	gkbd_configuration_lock_next_group (globals.config);
 }
 
-extern gchar *gkbd_indicator_create_label_title (int group,
-						 GHashTable **
-						 ln2cnt_map,
-						 gchar * layout_name);
-
 static void
 gkbd_status_render_cairo (cairo_t * cr, int group)
 {
@@ -196,8 +182,8 @@ gkbd_status_render_cairo (cairo_t * cr, int group)
 	layout_name =
 	    gkbd_configuration_extract_layout_name (globals.config, group);
 	lbl_title =
-	    gkbd_indicator_create_label_title (group, &ln2cnt_map,
-					       layout_name);
+	    gkbd_configuration_create_label_title (group, &ln2cnt_map,
+						   layout_name);
 
 	if (group + 1 ==
 	    xkl_engine_get_num_groups (gkbd_configuration_get_xkl_engine
@@ -289,10 +275,8 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 							   group);
 
 		image = gdk_pixbuf_new_from_file_at_size (image_filename,
-							  globals.
-							  current_width,
-							  globals.
-							  current_height,
+							  globals.current_width,
+							  globals.current_height,
 							  &gerror);
 
 		if (image == NULL) {
@@ -307,8 +291,7 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 								    NULL ?
 								    "Unknown"
 								    :
-								    gerror->
-								    message);
+								    gerror->message);
 			g_signal_connect (G_OBJECT (dialog), "response",
 					  G_CALLBACK (gtk_widget_destroy),
 					  NULL);
@@ -342,6 +325,7 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 		char pngfilename[20];
 		g_sprintf (pngfilename, "label%d.png", group);
 		cairo_surface_write_to_png (cs, pngfilename);
+		xkl_debug(150, "file %s is created\n", pngfilename);
 #endif
 		pixbuf_data =
 		    g_new0 (guchar,
@@ -395,6 +379,27 @@ gkbd_status_reinit_ui (GkbdStatus * gki)
 	gkbd_status_set_current_page (gki);
 }
 
+/* Should be called once for all widgets */
+static void
+gkbd_status_cfg_callback (GkbdConfiguration * configuration)
+{
+	ForAllObjects (configuration) {
+		gkbd_status_reinit_ui (GKBD_STATUS (gki));
+	} NextObject ()
+}
+
+/* Should be called once for all applets */
+static void
+gkbd_status_state_callback (GkbdConfiguration * configuration, gint group)
+{
+	ForAllObjects (configuration) {
+		xkl_debug (200, "do repaint\n");
+		gkbd_status_set_current_page_for_group (GKBD_STATUS (gki),
+							group);
+	}
+	NextObject ()
+}
+
 void
 gkbd_status_set_current_page (GkbdStatus * gki)
 {
@@ -434,7 +439,7 @@ gkbd_status_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
 		{
 			XReparentEvent *rne = (XReparentEvent *) xev;
 
-			ForAllIndicators () {
+			ForAllObjects (globals.config) {
 				guint32 xid =
 				    gtk_status_icon_get_x11_window_id
 				    (GTK_STATUS_ICON (gki));
@@ -446,7 +451,7 @@ gkbd_status_filter_x_evt (GdkXEvent * xev, GdkEvent * event)
 					    (engine, rne->window, TRUE);
 				}
 			}
-		NextIndicator ()}
+		NextObject ()}
 		break;
 	}
 	return GDK_FILTER_CONTINUE;
@@ -499,12 +504,12 @@ gkbd_status_init (GkbdStatus * gki)
 {
 	int i;
 
-	if (!g_slist_length (globals.widget_instances))
+	if (!gkbd_configuration_if_any_object_exists (globals.config))
 		gkbd_status_global_init ();
 
 	gki->priv = g_new0 (GkbdStatusPrivate, 1);
 
-	/* This should give NA a hint about the order */
+	/* This should give Notification Area a hint about the order of icons */
 	gtk_status_icon_set_name (GTK_STATUS_ICON (gki), "keyboard");
 
 	xkl_debug (100, "Initiating the widget startup process for %p\n",
@@ -522,8 +527,7 @@ gkbd_status_init (GkbdStatus * gki)
 	gkbd_status_set_current_page (gki);
 
 	/* append AFTER all initialization work is finished */
-	globals.widget_instances =
-	    g_slist_append (globals.widget_instances, gki);
+	gkbd_configuration_append_object (globals.config, G_OBJECT (gki));
 
 	g_signal_connect (gki, "size-changed",
 			  G_CALLBACK (gkbd_status_size_changed), NULL);
@@ -552,12 +556,12 @@ gkbd_status_finalize (GObject * obj)
 	for (i = sizeof (settings_signal_names) /
 	     sizeof (settings_signal_names[0]); --i >= 0;)
 		g_signal_handler_disconnect (gtk_settings_get_default (),
-					     gki->priv->
-					     settings_signal_handlers[i]);
+					     gki->
+					     priv->settings_signal_handlers
+					     [i]);
 
 	/* remove BEFORE all termination work is finished */
-	globals.widget_instances =
-	    g_slist_remove (globals.widget_instances, gki);
+	gkbd_configuration_remove_object (globals.config, G_OBJECT (gki));
 
 	gkbd_status_global_cleanup (gki);
 
@@ -568,7 +572,7 @@ gkbd_status_finalize (GObject * obj)
 
 	G_OBJECT_CLASS (gkbd_status_parent_class)->finalize (obj);
 
-	if (!g_slist_length (globals.widget_instances))
+	if (!gkbd_configuration_if_any_object_exists (globals.config))
 		gkbd_status_global_term ();
 }
 
@@ -602,6 +606,11 @@ gkbd_status_global_init (void)
 {
 	globals.config = gkbd_configuration_get ();
 
+	g_signal_connect (globals.config, "group-changed",
+			  G_CALLBACK (gkbd_status_state_callback), NULL);
+	g_signal_connect (globals.config, "changed",
+			  G_CALLBACK (gkbd_status_cfg_callback), NULL);
+
 	gkbd_status_start_listen ();
 
 	xkl_debug (100, "*** Inited globals *** \n");
@@ -637,4 +646,3 @@ gkbd_status_get_image_filename (guint group)
 	return gkbd_configuration_get_image_filename (globals.config,
 						      group);
 }
-



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