From 98f8acdfe572cc9805b4bf492ca91e802e578ea1 Mon Sep 17 00:00:00 2001
From: Vincent Sanders <vince@kyllikki.org>
Date: Fri, 10 Apr 2015 13:19:22 +0100
Subject: [PATCH] Change gtk about dialog construction to use the API as
 intended.

The about dialog box construction was awkward and brittle using
several depricated interfaces. This changes it to use a more generic
dialog creation and uses the response API to simplify click
processing.

It would be even better to use the gtk about dialog but that is a more
invasive change.
---
 gtk/about.c           | 86 +++++++++++++++++++++++--------------------
 resources/FatMessages | 27 ++++++++++----
 2 files changed, 67 insertions(+), 46 deletions(-)

diff --git a/gtk/about.c b/gtk/about.c
index 5e8818cdc..dcc151f51 100644
--- a/gtk/about.c
+++ b/gtk/about.c
@@ -34,18 +34,19 @@
 #include "gtk/gui.h"
 #include "gtk/about.h"
 
+#define ABOUT_RESPONSE_ID_LICENCE 1
+#define ABOUT_RESPONSE_ID_CREDITS 2
+
+
 /**
- * About dialog information button click.
+ * Open a url and a browser window/tab
  *
- * \param button The button widget that was clicked
- * \param data The text of the url to open
+ * \param url_text The text of the url to open
  */
-static void
-nsgtk_about_dialog_info(GtkWidget *button, gpointer data)
+static void about_open(const char *url_text)
 {
 	nsurl *url;
 	nserror ret;
-	const char *url_text = data;
 	enum browser_window_create_flags flags = BW_CREATE_HISTORY;
 
 	if (nsoption_bool(show_single_tab) == true) {
@@ -61,30 +62,55 @@ nsgtk_about_dialog_info(GtkWidget *button, gpointer data)
 	if (ret != NSERROR_OK) {
 		warn_user(messages_get_errorcode(ret), 0);
 	}
+}
+
+/**
+ * About dialog response handling.
+ *
+ * \param dialog The dialog widget
+ * \param response_id The response ID from the user clicking.
+ * \param user_data The value from the signal connection.
+ */
+static void
+nsgtk_about_dialog_response(GtkDialog *dialog,
+			    gint response_id,
+			    gpointer user_data)
+{
+	switch (response_id) {
+
+	case ABOUT_RESPONSE_ID_LICENCE:
+		about_open("about:credits");
+		break;
+
+	case ABOUT_RESPONSE_ID_CREDITS:
+		about_open("about:licence");
+		break;
+	}
 
 	/* close about dialog */
-	gtk_widget_destroy(gtk_widget_get_toplevel(button));
+	gtk_widget_destroy(GTK_WIDGET(dialog));
 }
 
 void nsgtk_about_dialog_init(GtkWindow *parent)
 {
-	GtkWidget *dialog, *vbox, *button, *label;
+	GtkWidget *dialog, *vbox, *label;
 	gchar *name_string;
 	GList *pixbufs;
 
-	name_string = g_markup_printf_escaped ("<span size=\"xx-large\" weight=\"bold\">NetSurf %s</span>", netsurf_version);
-
-
-	/* Create the widgets */
+	/* Create the dialog */
 	dialog = gtk_dialog_new_with_buttons("About NetSurf",
 					     parent,
 					     GTK_DIALOG_DESTROY_WITH_PARENT,
+					     "Licence", ABOUT_RESPONSE_ID_LICENCE,
+					     "Credits", ABOUT_RESPONSE_ID_CREDITS,
+					     "Close", GTK_RESPONSE_CANCEL,
 					     NULL, NULL);
 
 	vbox = nsgtk_vbox_new(FALSE, 8);
 
 	gtk_box_pack_start(GTK_BOX(nsgtk_dialog_get_content_area(GTK_DIALOG(dialog))), vbox, TRUE, TRUE, 0);
 
+	/* NetSurf icon */
 	pixbufs = gtk_window_get_default_icon_list();
 	if (pixbufs != NULL) {
 		GtkWidget *image;
@@ -96,51 +122,33 @@ void nsgtk_about_dialog_init(GtkWindow *parent)
 		gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0);
 	}
 
-
+	/* version string */
 	label = gtk_label_new (NULL);
+	name_string = g_markup_printf_escaped("<span size=\"xx-large\" weight=\"bold\">NetSurf %s</span>", netsurf_version);
 	gtk_label_set_markup (GTK_LABEL (label), name_string);
-	g_free (name_string);
+	g_free(name_string);
 	gtk_label_set_selectable (GTK_LABEL (label), TRUE);
 	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
 	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
 
-	label = gtk_label_new("NetSurf is a small fast web browser");
+	label = gtk_label_new(messages_get("AboutDesc"));
 	gtk_label_set_selectable(GTK_LABEL (label), TRUE);
 	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
 	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
 	gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
 
-	label = gtk_label_new("Copyright © 2003 - 2011 The NetSurf Developers");
+	label = gtk_label_new(messages_get("NetSurfCopyright"));
 	gtk_label_set_selectable(GTK_LABEL(label), TRUE);
 	gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
 	gtk_box_pack_start(GTK_BOX (vbox), label, FALSE, FALSE, 0);
 
+	/* Remove separator */
+	nsgtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE);
 
-	nsgtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-
-	/* Add the OK button */
-	gtk_dialog_add_button(GTK_DIALOG(dialog), NSGTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
-	gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);
-
-	/* Add the credits button */
-	button = nsgtk_button_new_from_stock("Credits");
-	gtk_box_pack_end(GTK_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))),
-			 button, FALSE, TRUE, 0);
-	gtk_button_box_set_child_secondary (GTK_BUTTON_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))), button, TRUE);
-	g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_info), (gpointer)"about:credits");
-
-	/* Add the Licence button */
-	button = nsgtk_button_new_from_stock("Licence");
-	gtk_box_pack_end(GTK_BOX (nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))),
-			 button, FALSE, TRUE, 0);
-	gtk_button_box_set_child_secondary (GTK_BUTTON_BOX(nsgtk_dialog_get_action_area(GTK_DIALOG(dialog))), button, TRUE);
-	g_signal_connect(button, "clicked", G_CALLBACK(nsgtk_about_dialog_info), (gpointer)"about:licence");
-
-
-	/* Ensure that the dialog box is destroyed when the user responds. */
+	/* Ensure that the dialog box response is processed. */
 	g_signal_connect_swapped(dialog,
 				  "response",
-				  G_CALLBACK (gtk_widget_destroy),
+				  G_CALLBACK(nsgtk_about_dialog_response),
 				  dialog);
 
 	/* Add the label, and show everything we've added to the dialog. */
diff --git a/resources/FatMessages b/resources/FatMessages
index 5ecb751c1..50bc7df4e 100644
--- a/resources/FatMessages
+++ b/resources/FatMessages
@@ -29,16 +29,16 @@
 #  instead (currently en)
 #
 # If you find something tagged 'all', but it is only relevant to a specific
-#  front end, please change it.  Currently, we have 'all', 'ro', 'gtk' and
-#  'ami'.
+#  front end, please change it.  Currently, we have:
+#   'all', 'ro', 'gtk', 'ami', 'beos'
 #
+
 # Globals
 en.all.NetSurf:NetSurf
-en.all.NetSurfCopyright:Copyright © 2003 - 2014 The NetSurf Developers
-nl.all.NetSurfCopyright:Auteursrecht © 2003 - 2015 De NetSurf-ontwikkelaars
-en.ami.NetSurfDesc:Small as a mouse, fast as a cheetah and available for free. NetSurf is a multi-platform web browser.
-fr.ami.NetSurfDesc:Petit comme une souris, rapide comme un guépard. NetSurf est un navigateur Web multi-plate-forme libre.
-it.ami.NetSurfDesc:Piccolo come un mouse, veloce come un ghepardo. NetSurf è un browser web opensource e multi-piattaforma.
+
+en.all.NetSurfCopyright:© 2003-2015 The NetSurf Developers
+nl.all.NetSurfCopyright:© 2003-2015 De NetSurf-ontwikkelaars
+
 
 # Menus
 # =====
@@ -1306,6 +1306,19 @@ it.all.TreeHotlist:Segnalibri di NetSurf
 nl.all.TreeHotlist:NetSurf-favorieten
 
 
+# About user interface tokens
+# ===========================
+#
+# This secion is for tokens that have user information about the browser
+
+en.ami.NetSurfDesc:Small as a mouse, fast as a cheetah and available for free. NetSurf is a multi-platform web browser.
+fr.ami.NetSurfDesc:Petit comme une souris, rapide comme un guépard. NetSurf est un navigateur Web multi-plate-forme libre.
+it.ami.NetSurfDesc:Piccolo come un mouse, veloce come un ghepardo. NetSurf è un browser web opensource e multi-piattaforma.
+
+en.gtk.AboutDesc:NetSurf is a small and fast web browser.
+fr.gtk.AboutDesc:NetSurf est un navigateur Web multi-plate-forme libre.
+it.gtk.AboutDesc:NetSurf è un browser web opensource e multi-piattaforma.
+
 # Hotlist user interface tokens
 # =============================
 #