[gnome-settings-daemon] Sharing "show layout" dialog



commit 5dbeaaf0533dc678db44079483fbdcf951e261b2
Author: Sergey V. Udaltsov <svu gnome org>
Date:   Wed May 26 00:57:38 2010 +0100

    Sharing "show layout" dialog
    
    Now, this dialog is located in libgnomekbd, to be used by both g-c-c and
    g-s-d

 configure.ac                        |    2 +-
 plugins/keyboard/Makefile.am        |    2 +-
 plugins/keyboard/gsd-keyboard-xkb.c |  179 +++--------------------------------
 plugins/keyboard/show-layout.ui     |   83 ----------------
 4 files changed, 17 insertions(+), 249 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 0996fd0..98722e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -211,7 +211,7 @@ AC_CHECK_X_LIB(Xxf86misc, XF86MiscQueryExtension, [
 AC_SUBST(XF86MISC_LIBS)
 AC_CHECK_X_HEADERS([X11/extensions/XKB.h])
 
-PKG_CHECK_MODULES(LIBGNOMEKBDUI, [libgnomekbdui >= 2.29.5 libgnomekbd >= 2.29.5 libxklavier >= 5.0])
+PKG_CHECK_MODULES(LIBGNOMEKBDUI, [libgnomekbdui >= 2.31.2 libgnomekbd >= 2.29.5 libxklavier >= 5.0])
 AC_SUBST(LIBGNOMEKBDUI_CFLAGS)
 AC_SUBST(LIBGNOMEKBDUI_LIBS)
 
diff --git a/plugins/keyboard/Makefile.am b/plugins/keyboard/Makefile.am
index 0af3c03..4728792 100644
--- a/plugins/keyboard/Makefile.am
+++ b/plugins/keyboard/Makefile.am
@@ -14,7 +14,7 @@ icons_DATA = \
 	  kbd-capslock-on.png kbd-numlock-on.png kbd-scrolllock-on.png
 
 uidir   = $(pkgdatadir)
-ui_DATA = modmap-dialog.ui show-layout.ui
+ui_DATA = modmap-dialog.ui
 
 libkeyboard_la_SOURCES = 	\
 	gsd-keyboard-plugin.h	\
diff --git a/plugins/keyboard/gsd-keyboard-xkb.c b/plugins/keyboard/gsd-keyboard-xkb.c
index ed79f72..0026c93 100644
--- a/plugins/keyboard/gsd-keyboard-xkb.c
+++ b/plugins/keyboard/gsd-keyboard-xkb.c
@@ -203,191 +203,42 @@ popup_menu_launch_capplet ()
 }
 
 static void
-show_layout_response (GtkWidget * dialog, gint resp)
-{
-	GdkRectangle rect;
-	GtkWidget *kbdraw;
-	const gchar *groupName;
-
-	switch (resp) {
-	case GTK_RESPONSE_HELP:
-		gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (dialog)),
-			      "ghelp:gswitchit?layout-view",
-			      gtk_get_current_event_time (), NULL);
-		return;
-	case GTK_RESPONSE_CLOSE:
-		gtk_window_get_position (GTK_WINDOW (dialog), &rect.x,
-					 &rect.y);
-		gtk_window_get_size (GTK_WINDOW (dialog), &rect.width,
-				     &rect.height);
-		gkbd_preview_save_position (&rect);
-		gtk_widget_destroy (dialog);
-		break;
-	case GTK_RESPONSE_PRINT:
-		kbdraw =
-		    GTK_WIDGET (g_object_get_data
-				(G_OBJECT (dialog), "kbdraw"));
-		groupName =
-		    (const gchar *) g_object_get_data (G_OBJECT (dialog),
-						       "groupName");
-		gkbd_keyboard_drawing_print (GKBD_KEYBOARD_DRAWING
-					     (kbdraw), GTK_WINDOW (dialog),
-					     groupName ? groupName :
-					     _("Unknown"));
-	}
-}
-
-static void
 show_layout_destroy (GtkWidget * dialog, gint group)
 {
-	GtkBuilder *builder =
-	    GTK_BUILDER (g_object_get_data
-			 (G_OBJECT (dialog), "builderData"));
-	g_object_unref (G_OBJECT (builder));
 	g_hash_table_remove (preview_dialogs, GINT_TO_POINTER (group));
 }
 
 static void
 popup_menu_show_layout ()
 {
-	static GkbdKeyboardDrawingGroupLevel groupsLevels[] = { {
-								 0, 1}, {
-									 0,
-									 3},
-	{
-	 0, 0}, {
-		 0, 2}
-	};
-	static GkbdKeyboardDrawingGroupLevel *pGroupsLevels[] = {
-		groupsLevels, groupsLevels + 1, groupsLevels + 2,
-		groupsLevels + 3
-	};
-
-	GtkBuilder *builder;
-	GtkWidget *dialog, *kbdraw;
-	XkbComponentNamesRec component_names;
-	XklConfigRec *xkl_data;
-	GdkRectangle *rect;
-	GError *error = NULL;
-
+	GtkWidget *dialog;
 	XklEngine *engine = xkl_engine_get_instance (GDK_DISPLAY ());
 	XklState *xkl_state = xkl_engine_get_current_state (engine);
-	gchar **group_names = gkbd_status_get_group_names ();
 	gpointer p = g_hash_table_lookup (preview_dialogs,
 					  GINT_TO_POINTER
 					  (xkl_state->group));
+	gchar **group_names = gkbd_status_get_group_names ();
+
+	if (xkl_state->group < 0
+	    || xkl_state->group >= g_strv_length (group_names)) {
+		return;
+	}
+
 	if (p != NULL) {
 		/* existing window */
 		gtk_window_present (GTK_WINDOW (p));
 		return;
 	}
 
-	builder = gtk_builder_new ();
-	gtk_builder_add_from_file (builder, DATADIR "/show-layout.ui",
-				   &error);
-
-	if (error) {
-		g_error ("building ui from %s failed: %s",
-			 DATADIR "/show-layout.ui", error->message);
-		g_clear_error (&error);
-	}
-
-
 	dialog =
-	    GTK_WIDGET (gtk_builder_get_object
-			(builder, "gswitchit_layout_view"));
-	kbdraw = gkbd_keyboard_drawing_new ();
-
-	if (xkl_state->group >= 0 &&
-	    xkl_state->group < g_strv_length (group_names)) {
-		char title[128] = "";
-		snprintf (title, sizeof (title),
-			  _("Keyboard Layout \"%s\""),
-			  group_names[xkl_state->group]);
-		gtk_window_set_title (GTK_WINDOW (dialog), title);
-		g_object_set_data_full (G_OBJECT (dialog), "group_name",
-					g_strdup (group_names
-						  [xkl_state->group]),
-					g_free);
-	}
-
-	gkbd_keyboard_drawing_set_groups_levels (GKBD_KEYBOARD_DRAWING
-						 (kbdraw), pGroupsLevels);
-
-	xkl_data = xkl_config_rec_new ();
-	if (xkl_config_rec_get_from_server (xkl_data, engine)) {
-		int num_layouts = g_strv_length (xkl_data->layouts);
-		int num_variants = g_strv_length (xkl_data->variants);
-		if (xkl_state->group >= 0 &&
-		    xkl_state->group < num_layouts &&
-		    xkl_state->group < num_variants) {
-			char *l =
-			    g_strdup (xkl_data->layouts[xkl_state->group]);
-			char *v =
-			    g_strdup (xkl_data->variants
-				      [xkl_state->group]);
-			char **p;
-			int i;
-
-			if ((p = xkl_data->layouts) != NULL)
-				for (i = num_layouts; --i >= 0;)
-					g_free (*p++);
-
-			if ((p = xkl_data->variants) != NULL)
-				for (i = num_variants; --i >= 0;)
-					g_free (*p++);
-
-			xkl_data->layouts =
-			    g_realloc (xkl_data->layouts,
-				       sizeof (char *) * 2);
-			xkl_data->variants =
-			    g_realloc (xkl_data->variants,
-				       sizeof (char *) * 2);
-			xkl_data->layouts[0] = l;
-			xkl_data->variants[0] = v;
-			xkl_data->layouts[1] = xkl_data->variants[1] =
-			    NULL;
-		}
-
-		if (xkl_xkb_config_native_prepare
-		    (engine, xkl_data, &component_names)) {
-			gkbd_keyboard_drawing_set_keyboard
-			    (GKBD_KEYBOARD_DRAWING (kbdraw),
-			     &component_names);
-			xkl_xkb_config_native_cleanup (engine,
-						       &component_names);
-		}
-	}
-	g_object_unref (G_OBJECT (xkl_data));
-
-	g_object_set_data (G_OBJECT (dialog), "builderData", builder);
-	g_signal_connect (GTK_OBJECT (dialog),
-			  "destroy", G_CALLBACK (show_layout_destroy),
+	    gkbd_keyboard_drawing_new_dialog (xkl_state->group,
+					      group_names
+					      [xkl_state->group]);
+	g_signal_connect (GTK_OBJECT (dialog), "destroy",
+			  G_CALLBACK (show_layout_destroy),
 			  GINT_TO_POINTER (xkl_state->group));
-	g_signal_connect (G_OBJECT (dialog), "response",
-			  G_CALLBACK (show_layout_response), NULL);
-
-	rect = gkbd_preview_load_position ();
-	if (rect != NULL) {
-		gtk_window_move (GTK_WINDOW (dialog), rect->x, rect->y);
-		gtk_window_resize (GTK_WINDOW (dialog), rect->width,
-				   rect->height);
-		g_free (rect);
-	} else
-		gtk_window_resize (GTK_WINDOW (dialog), 700, 400);
-
-	gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE);
-
-	gtk_container_add (GTK_CONTAINER
-			   (gtk_builder_get_object
-			    (builder, "preview_vbox")), kbdraw);
-
-	g_object_set_data (G_OBJECT (dialog), "kbdraw", kbdraw);
-
 	g_hash_table_insert (preview_dialogs,
 			     GINT_TO_POINTER (xkl_state->group), dialog);
-
-	gtk_widget_show_all (GTK_WIDGET (dialog));
 }
 
 static void
@@ -587,8 +438,8 @@ filter_xkb_config (void)
 					current_kbd_config.layouts_variants
 					    =
 					    g_slist_delete_link
-					    (current_kbd_config.
-					     layouts_variants, filtered);
+					    (current_kbd_config.layouts_variants,
+					     filtered);
 					any_change = TRUE;
 					continue;
 				}



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