[gok] Use gtk_show_uri instead of gnome_help - bgo#584612



commit 46ca9986da042bbeccacfbdefce7ea1afed4cfa0
Author: Gerd Kohlberger <gerdk src gnome org>
Date:   Mon Jul 6 08:54:51 2009 +0200

    Use gtk_show_uri instead of gnome_help - bgo#584612
    
    This commit raises the minimum gtk+ dependency to 2.14.

 configure.in              |    2 +-
 gok/gok-keyboard.c        |    8 +-
 gok/gok-settings-dialog.c |   16 ++--
 gok/main.c                |  224 ++++++++++++++++++++++++++++-----------------
 gok/main.h                |    4 +-
 5 files changed, 152 insertions(+), 102 deletions(-)
---
diff --git a/configure.in b/configure.in
index cd1c53b..7418acd 100644
--- a/configure.in
+++ b/configure.in
@@ -169,7 +169,7 @@ PKG_CHECK_MODULES(GOK, \
 	libloginhelper-1.0 >= 1.5.2 \
 	libbonobo-2.0 >= 2.5.1  \
 	atk >= 1.3.0            \
-	gtk+-2.0 >= 2.12.0	\
+	gtk+-2.0 >= 2.14.0	\
 	gail                    \
 	libwnck-1.0             \
 	gnome-speech-1.0        \
diff --git a/gok/gok-keyboard.c b/gok/gok-keyboard.c
index e6961df..094bbc6 100644
--- a/gok/gok-keyboard.c
+++ b/gok/gok-keyboard.c
@@ -3586,8 +3586,6 @@ gok_keyboard_focus_object (Accessible *accessible)
 	return retval;
 }
 
-/* TODO: merge with duplicate code in gok-settings-dialog.c */
-
 /**
  * gok_keyboard_help:
  *
@@ -3597,11 +3595,9 @@ gok_keyboard_focus_object (Accessible *accessible)
  *
  **/
 void
-gok_keyboard_help (GokKey *pKey) 
+gok_keyboard_help (GokKey *pKey)
 {
-	GError *error = NULL;
-	/* TODO: detect error launching help, and give informative message */
-	gnome_help_display_desktop (NULL, "gok", "gok.xml", NULL, &error);
+	gok_main_display_help ("gok", NULL);
 }
 
 /**
diff --git a/gok/gok-settings-dialog.c b/gok/gok-settings-dialog.c
index 49e7253..26e49a3 100644
--- a/gok/gok-settings-dialog.c
+++ b/gok/gok-settings-dialog.c
@@ -355,32 +355,30 @@ void on_button_help (GtkButton* pButton, gpointer user_data)
 			break;
 			
 		case 1:
-			help_link_id = "gok-keyboards";
+			help_link_id = "gok-prefs-keyboards";
 			break;
 			
 		case 2:
-			help_link_id = "gok-prefs-Actions";
+			help_link_id = "gok-prefs-actions";
 			break;
 			
 		case 3:
-			help_link_id = "gok-prefs-Feedback";
+			help_link_id = "gok-prefs-feedback";
 			break;
 
 		case 4:
-			help_link_id = "gok-prefs-Access-Methods";
+			help_link_id = "gok-prefs-accessmethods";
 			break;
 			
 		case 5:
-			help_link_id = "gok-prefs-Prediction";
+			help_link_id = "gok-prefs-prediction";
 			break;
 			
 		default:
 			break;
 	}
-	if (help_link_id)
-	{
-		gnome_help_display_desktop (NULL, "gok", "gok.xml", help_link_id, NULL);
-	}
+
+	gok_main_display_help ("gok", help_link_id);
 }
 
 /**
diff --git a/gok/main.c b/gok/main.c
index 8baf57a..9ea666b 100644
--- a/gok/main.c
+++ b/gok/main.c
@@ -174,7 +174,6 @@ static void gok_main_initialize_access_methods (GokArgs *args);
 static void gok_main_initialize_wordcomplete (void);
 static void gok_main_initialize_commandprediction (void);
 static gboolean gok_main_display_scan_main(void);
-static void gok_main_display_geometry_error (void);
 static void gok_main_object_state_listener (Accessible* pAccessible);
 static gboolean gok_main_has_xkb_extension ();
 static gboolean gok_main_check_sticky_keys (GtkWidget *widget);
@@ -722,7 +721,10 @@ gok_main_open(gint argc, gchar *argv[])
 		}
 	    }
 	}
-	
+
+	/* set default icon early so it can be used by error dialogs */
+	gtk_window_set_default_icon_name ("gok");
+
 	/* Parse geometry */
 	if (gok_args.geometry != NULL)
 	{
@@ -753,9 +755,9 @@ gok_main_open(gint argc, gchar *argv[])
 		}
 		else
 		{
-			fprintf (stderr, _("gok: Unsupported geometry specification\n"));
-			fprintf (stderr, _("gok: Currently GOK requires that the x, y, width and height all be given\n"));
-			gok_main_display_geometry_error ();
+			gok_main_display_error (_("Unsupported geometry specification"),
+						_("Currently GOK requires that the x, y, width and height all be given. "
+						  "Sorry, your geometry specification will not be used."));
 		}
 	}
 
@@ -850,7 +852,7 @@ gok_main_open(gint argc, gchar *argv[])
 	/* check for xkb extension */
 	if (!gok_main_has_xkb_extension())
 	{
-		gok_main_display_error (_("XKB extension is required."));
+		gok_main_display_fatal_error (_("XKB extension is required."));
 		return GOK_ERROR_NO_XKB_EXTENSION;
 	}		
 
@@ -860,7 +862,7 @@ gok_main_open(gint argc, gchar *argv[])
 	/* initialize the actions */
 	if (gok_action_open() == FALSE)
 	{
-		gok_main_display_error (_("Can't initialize actions."));
+		gok_main_display_fatal_error (_("Can't initialize actions."));
 		return GOK_ERROR_ACTION_OPEN;
 	}
 
@@ -870,7 +872,7 @@ gok_main_open(gint argc, gchar *argv[])
 	/* initialize the feedbacks */
 	if (gok_feedback_open() == FALSE)
 	{
-		gok_main_display_error (_("Can't initialize feedbacks."));
+		gok_main_display_fatal_error (_("Can't initialize feedbacks."));
 		return GOK_ERROR_FEEDBACK_OPEN;
 	}
 
@@ -915,7 +917,7 @@ gok_main_open(gint argc, gchar *argv[])
 	
 		 if (g_strv_length(vid_pid) != 2) {
 		 	g_strfreev(vid_pid);
-		 	gok_main_display_error(_("can't initialize the libusb backend - can't parse USB VID:PID pair"));
+			gok_main_display_fatal_error(_("Can't initialize the libusb backend - can't parse USB VID:PID pair"));
 		 	return GOK_ERROR_LIBUSB;
 		 }
 
@@ -924,7 +926,7 @@ gok_main_open(gint argc, gchar *argv[])
 		g_strfreev(vid_pid);
 		
 		if ((vid == 0 || pid == 0) && errno == EINVAL) {
-			gok_main_display_error(_("can't initialize the libusb backend - can't parse USB VID:PID pair"));
+			gok_main_display_fatal_error(_("Can't initialize the libusb backend - can't parse USB VID:PID pair"));
 		 	return GOK_ERROR_LIBUSB;
 		}
 		
@@ -940,7 +942,7 @@ gok_main_open(gint argc, gchar *argv[])
 	m_pWindowMain = gok_main_create_window (window_realize_data);
 	if (m_pWindowMain == NULL)
 	{
-		gok_main_display_error (_("Can't create the main GOK window!"));
+		gok_main_display_fatal_error (_("Can't create the main GOK window!"));
 		return GOK_ERROR_MAIN_CREATE_WINDOW;
 	}
 	gtk_widget_show (m_pWindowMain);
@@ -959,7 +961,7 @@ gok_main_open(gint argc, gchar *argv[])
 	/* create the settings dialog */
 	if (gok_settingsdialog_open (gok_args.display_settings_dialog) == FALSE)
 	{
-		gok_main_display_error (_("Can't create the settings dialog window!"));
+		gok_main_display_fatal_error (_("Can't create the settings dialog window!"));
 		return GOK_ERROR_SETTINGSDIALOG_OPEN;
 	}
 
@@ -1022,7 +1024,7 @@ gok_main_display_scan_main()
 		/* if no "main" keyboard then display first keyboard in list */
 		if (gok_main_display_scan ((GokKeyboard*)NULL, NULL, KEYBOARD_TYPE_UNSPECIFIED, KEYBOARD_LAYOUT_NORMAL, KEYBOARD_SHAPE_BEST) == FALSE)
 		{
-			gok_main_display_error (_("No keyboards to display!"));
+			gok_main_display_fatal_error (_("No keyboards to display!"));
 			return FALSE;
 		}
 	}
@@ -1931,7 +1933,6 @@ GtkWidget* gok_main_create_window (struct gok_window_realize_data *window_realiz
 	gtk_window_set_keep_above (GTK_WINDOW (window1), TRUE); /* please! */
 	
 	g_set_application_name (_("GOK"));
-	gtk_window_set_default_icon_name ("gok");
 
 	m_OurResizeWidth = 200;
 	m_OurResizeHeight = 100;
@@ -2103,7 +2104,7 @@ void gok_main_read_keyboards ()
 
     if (m_pKeyboardFirst == NULL)
     {
-	gok_main_display_error (_("Can't create a compose keyboard!"));
+	gok_main_display_fatal_error (_("Can't create a compose keyboard!"));
 	exit (1);
     }
 
@@ -2145,7 +2146,7 @@ void gok_main_read_keyboards ()
     
     if ( gconf_keyboard_directory_error || (m_pKeyboardFirst == NULL) )
     {
-	gok_main_display_error (_("Can't read any keyboards!"));
+	gok_main_display_fatal_error (_("Can't read any keyboards!"));
 	exit (1);
     }
 }
@@ -2255,22 +2256,18 @@ gok_main_initialize_access_methods (GokArgs *args)
     else if (gconf_err != NULL) {
 		gok_log_x ("Error getting access method directory key from GConf");
 		g_error_free (gconf_err);
- 		gok_main_display_error
-			(_("could not access method directory key from GConf!"));
+		gok_main_display_fatal_error (
+			_("Could not get access method directory key from GConf."));
 		exit(2);		
     }
     else if (!(gok_scanner_initialize(directory_name, 
 				      args->accessmethodname, 
 				      args->selectactionname, 
 				      args->scanactionname))) {
- 		gok_main_display_error
-			(_("possibly unknown access method!"));
+		gok_main_display_fatal_error (_("Possibly unknown access method."));
 		exit(2);
-			
     }
-    
     g_free (directory_name);
-    
 }
 
 /**
@@ -2807,66 +2804,97 @@ gok_main_close()
 }
 
 /**
-* gok_main_display_error
-* @ErrorString: Fatal error message.
-* 
-* Displays a fatal error dialog (modal).
-*/
-void gok_main_display_error (gchar* ErrorString)
+ * gok_main_display_fatal_error:
+ * @ErrorString: Fatal error message.
+ *
+ * Displays a fatal error dialog (modal).
+ */
+void
+gok_main_display_fatal_error (const gchar *ErrorString)
 {
-	GtkWidget* pDialog;
-	gchar* buffer;
-	
-	buffer = g_strdup_printf (_("Sorry, GOK can't run because:\n%s"), ErrorString);
-	
+	GtkWidget* pDialog, *main;
+
+	g_return_if_fail (ErrorString != NULL);
+
 	pDialog = gtk_message_dialog_new (NULL,
-		GTK_DIALOG_DESTROY_WITH_PARENT,
-		GTK_MESSAGE_ERROR,
-		GTK_BUTTONS_CLOSE,
-		"%s", buffer);
-	
+					  GTK_DIALOG_DESTROY_WITH_PARENT,
+					  GTK_MESSAGE_ERROR,
+					  GTK_BUTTONS_CLOSE,
+					  "%s", _("Sorry, GOK can't run"));
+	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (pDialog),
+						  "%s", ErrorString);
+
+	/* use the same screen as the main window */
+	main = gok_main_get_main_window ();
+	if (main)
+	{
+		gtk_window_set_screen (GTK_WINDOW (pDialog),
+				       gtk_widget_get_screen (main));
+	}
 	gtk_window_set_title (GTK_WINDOW (pDialog), _("GOK Fatal Error"));
 	gtk_dialog_run (GTK_DIALOG (pDialog));
 	gtk_widget_destroy (pDialog);
-	g_free (buffer);
 }
 
 /**
-* gok_main_display_gconf_error
-* 
-* Displays a gconf error message.
-*/
-void gok_main_display_gconf_error ()
+ * gok_main_display_error:
+ * @error_msg: Error message
+ * @detail: Error details
+ *
+ * Displays an error dialog.
+ */
+void
+gok_main_display_error (const gchar *error,
+			const gchar *detail)
 {
-    gok_main_display_error ( _("GOK uses GConf 2 to store its settings and requires certain settings to be in GConf to run.  GOK is currently unable to retrieve those settings.  If this is the first time that you have run gok after installing it you may need to restart gconfd, you can use this command: 'gconftool-2 --shutdown' or log out and back in."));
-}
+	GtkWidget *dialog, *main;
 
-/**
-* gok_main_display_geometry_error
-* 
-* Displays a dialog informing user that the given geometry was not correct.
-*/
-static void
-gok_main_display_geometry_error ()
-{
-	GtkWidget* dialog;
-        
-	dialog = gtk_message_dialog_new (NULL,
-	                                 GTK_DIALOG_DESTROY_WITH_PARENT,
-	                                 GTK_MESSAGE_ERROR,
-	                                 GTK_BUTTONS_CLOSE,
-	                                 _("Currently GOK requires that the x, y, width and height all be given.  Sorry, your geometry specification will not be used."));
-        
-	gtk_window_set_title (GTK_WINDOW (dialog), _("gok: Unsupported geometry specification"));
+	g_return_if_fail (error != NULL);
 
-	g_signal_connect_swapped (GTK_OBJECT (dialog), "response",
-	                          G_CALLBACK (gtk_widget_destroy),
-	                          GTK_OBJECT (dialog));
+	dialog = gtk_message_dialog_new (NULL, 
+					 GTK_DIALOG_DESTROY_WITH_PARENT,
+					 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+					 "%s", error);
+	if (detail)
+	{
+		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+							  "%s", detail);
+	}
+	/* use the same screen as the main window */
+	main = gok_main_get_main_window ();
+	if (main)
+	{
+		gtk_window_set_screen (GTK_WINDOW (dialog),
+				       gtk_widget_get_screen (main));
+	}
+	gtk_window_set_title (GTK_WINDOW (dialog), _("GOK Error"));
+	/* avoid self occlusion */
+	gtk_window_set_type_hint (GTK_WINDOW (dialog),
+				  GDK_WINDOW_TYPE_HINT_NORMAL);
+	gtk_window_set_position (GTK_WINDOW (dialog),
+				 GTK_WIN_POS_CENTER);
 
+	g_signal_connect_swapped (dialog, "response",
+				  G_CALLBACK (gtk_widget_destroy), dialog);
 	gtk_widget_show_all (dialog);
 }
 
 /**
+ * gok_main_display_gconf_error:
+ *
+ * Displays a gconf error message.
+ */
+void
+gok_main_display_gconf_error (void)
+{
+	gok_main_display_fatal_error (_("GOK uses GConf 2 to store its settings and requires certain settings "
+					"to be in GConf to run. GOK is currently unable to retrieve those settings. "
+					"If this is the first time that you have run gok after installing it you "
+					"may need to restart gconfd, you can use this command: "
+					"'gconftool-2 --shutdown' or log out and back in."));
+}
+
+/**
 * gok_main_get_use_geometry
 * 
 * returns: TRUE if the user has specified window geometry for the GOK.
@@ -3122,16 +3150,8 @@ gok_main_check_sticky_keys (GtkWidget *widget)
 	}
 	else {
 		if (!gok_args.is_login) {
-                /* post an error dialog */
-			dialog = gtk_message_dialog_new (NULL,
-						 GTK_DIALOG_DESTROY_WITH_PARENT,
-						 GTK_MESSAGE_ERROR,
-						 GTK_BUTTONS_CLOSE,
-						 _("GOK cannot run because XKB display extension is missing.\n"));
-			g_signal_connect_swapped (GTK_OBJECT (dialog), "response",
-					  G_CALLBACK (gtk_widget_destroy),
-					  GTK_OBJECT (dialog));
-			gtk_widget_show_all (dialog);
+			/* post an error dialog */
+			gok_main_display_fatal_error (_("XKB display extension is missing."));
 		}
 		else
 			g_warning ("XKB extension not present or non-functional.  GOK will exit.");
@@ -3175,15 +3195,49 @@ void check_accessibility_cb ( GObject* o, gpointer* data )
 
 }
 
+/**
+ * gok_main_display_help:
+ * @doc_name: name of the help document
+ * @link_id: id of the section to display or NULL
+ *
+ * Displays the GOK Help text in the gnome-help browser.
+ **/
 void
-gok_main_help_cb (gpointer data) 
+gok_main_display_help (const gchar *doc_name, const gchar *link_id)
 {
+	GtkWidget *main;
+	GdkScreen *screen;
+	gchar *uri;
 	GError *error = NULL;
-	gchar *helpuri = data;
-	/* TODO: detect error launching help, and give informative message */
-	/* TODO: remove hack for link below, if and when this method is called from more than one dialog */
 
-	gnome_help_display_desktop (NULL, "gnome-access-guide", helpuri, "sysadmin-37", &error);
+	g_return_if_fail (doc_name != NULL);
+
+	if (link_id)
+	{
+		uri = g_strdup_printf ("ghelp:%s?%s", doc_name, link_id);
+	}
+	else
+	{
+		uri = g_strdup_printf ("ghelp:%s", doc_name);
+	}
+
+	main = gok_main_get_main_window ();
+	screen = gtk_widget_get_screen (main);
+	gtk_show_uri (screen, uri, gtk_get_current_event_time (), &error);
+	g_free (uri);
+
+	if (error)
+	{
+		gok_main_display_error (_("Unable to open help file"),
+		                        error->message);
+		g_error_free (error);
+	}
+}
+
+static void
+gok_main_help_cb (GtkButton *button, gpointer data)
+{
+	gok_main_display_help ("gnome-access-guide", "sysadmin-37");
 }
 
 void
@@ -3257,8 +3311,8 @@ gok_main_warn (gchar *message, gboolean always, GCallback cancelfunc, GCallback
 			button = gtk_button_new_from_stock(GTK_STOCK_HELP);
 			gtk_container_add (GTK_CONTAINER (GTK_DIALOG(_corepointer_warning)->action_area),
 					   button);
-			g_signal_connect_swapped (G_OBJECT (button), "clicked", 
-						  G_CALLBACK (gok_main_help_cb), "sysadmin.xml");
+			g_signal_connect (button, "clicked",
+					  G_CALLBACK (gok_main_help_cb), NULL);
 			
 			button = gtk_button_new_from_stock(GTK_STOCK_PREFERENCES);
 			gtk_container_add (GTK_CONTAINER (GTK_DIALOG(_corepointer_warning)->action_area),
diff --git a/gok/main.h b/gok/main.h
index 38f35d5..6e474d5 100644
--- a/gok/main.h
+++ b/gok/main.h
@@ -82,8 +82,10 @@ void gok_main_read_keyboards (void);
 GokKeyboard* gok_main_read_keyboards_from_dir (const char *directory, GokKeyboard *first);
 void gok_main_on_window_position_change (void);
 void gok_main_get_our_window_size (gint* pWidth, gint* pHeight);
-void gok_main_display_error (gchar* ErrorString);
+void gok_main_display_error (const gchar *error, const gchar *detail);
+void gok_main_display_fatal_error (const gchar* ErrorString);
 void gok_main_display_gconf_error (void);
+void gok_main_display_help (const gchar *doc_name, const gchar *link_id);
 gboolean gok_main_window_contains_pointer (void);
 gboolean gok_main_attach_new_devices (void);
 Display *gok_main_display (void);



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