changeset 289:6a7298988a7a

Simplify and unify gtk_window creation with the help of the new window_new() function, that wraps gtk_window_new() call. Subclass, title and icon are set in the same call.
author zas_
date Wed, 09 Apr 2008 16:37:54 +0000
parents d1f74154463e
children 4bbde8a38ad4
files src/collect.c src/dupe.c src/fullscreen.c src/img-view.c src/info.c src/layout.c src/main.c src/main.h src/pan-view.c src/preferences.c src/search.c src/ui_help.c src/ui_utildlg.c
diffstat 13 files changed, 47 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/src/collect.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/collect.c	Wed Apr 09 16:37:54 2008 +0000
@@ -1162,8 +1162,7 @@
 
 	cw->cd = collection_new(path);
 
-	cw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	window_set_icon(cw->window, PIXBUF_INLINE_ICON_BOOK, NULL);
+	cw->window = window_new(GTK_WINDOW_TOPLEVEL, "collection", PIXBUF_INLINE_ICON_BOOK, NULL, NULL);
 
 	geometry.min_width = 32;
 	geometry.min_height = 32;
@@ -1185,7 +1184,6 @@
 
 	gtk_window_set_resizable(GTK_WINDOW(cw->window), TRUE);
 	collection_window_update_title(cw);
-	gtk_window_set_wmclass(GTK_WINDOW(cw->window), "collection", GQ_WMCLASS);
 	gtk_container_set_border_width (GTK_CONTAINER (cw->window), 0);
 
 	g_signal_connect(G_OBJECT(cw->window), "delete_event",
--- a/src/dupe.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/dupe.c	Wed Apr 09 16:37:54 2008 +0000
@@ -3103,9 +3103,8 @@
 
 	dw->second_set = FALSE;
 
-	dw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-        window_set_icon(dw->window, NULL, NULL);
-
+	dw->window = window_new(GTK_WINDOW_TOPLEVEL, "dupe", NULL, NULL, _("Find duplicates"));
+      
 	geometry.min_width = 32;
 	geometry.min_height = 32;
 	geometry.base_width = DUPE_DEF_WIDTH;
@@ -3116,12 +3115,6 @@
 	gtk_window_set_default_size(GTK_WINDOW(dw->window), DUPE_DEF_WIDTH, DUPE_DEF_HEIGHT);
 
 	gtk_window_set_resizable(GTK_WINDOW(dw->window), TRUE);
-	{
-	gchar *title = g_strdup_printf("%s - %s", _("Find duplicates"), GQ_APPNAME);
-	gtk_window_set_title(GTK_WINDOW(dw->window), title);
-	g_free(title);
-	}
-        gtk_window_set_wmclass(GTK_WINDOW(dw->window), "dupe", GQ_WMCLASS);
         gtk_container_set_border_width (GTK_CONTAINER (dw->window), 0);
 
         g_signal_connect(G_OBJECT(dw->window), "delete_event",
--- a/src/fullscreen.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/fullscreen.c	Wed Apr 09 16:37:54 2008 +0000
@@ -238,8 +238,7 @@
 	fullscreen_prefs_get_geometry(fullscreen_screen, window, &x, &y, &w, &h,
 				      &screen, &same);
 
-	fs->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_window_set_wmclass(GTK_WINDOW(fs->window), "fullscreen", GQ_WMCLASS);
+	fs->window = window_new(GTK_WINDOW_TOPLEVEL, "fullscreen", NULL, NULL, _("Full screen"));
 
 	/* this requests no decorations, if you still have them complain to the window manager author(s) */
 	gtk_window_set_decorated(GTK_WINDOW(fs->window), FALSE);
@@ -264,12 +263,6 @@
 	g_signal_connect(G_OBJECT(fs->window), "delete_event",
 			 G_CALLBACK(fullscreen_delete_cb), fs);
 
-	{
-	gchar *title = g_strdup_printf("%s - %s", _("Full screen"), GQ_APPNAME);
-	gtk_window_set_title(GTK_WINDOW(fs->window), title);
-	g_free(title);
-	}
-
 	geometry.min_width = w;
 	geometry.min_height = h;
 	geometry.max_width = w;
--- a/src/img-view.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/img-view.c	Wed Apr 09 16:37:54 2008 +0000
@@ -844,19 +844,15 @@
 	vw->list = NULL;
 	vw->list_pointer = NULL;
 
-	vw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	vw->window = window_new(GTK_WINDOW_TOPLEVEL, "view", PIXBUF_INLINE_ICON_VIEW, NULL, NULL);
 
 	geometry.min_width = 8;
 	geometry.min_height = 8;
 	gtk_window_set_geometry_hints(GTK_WINDOW(vw->window), NULL, &geometry, GDK_HINT_MIN_SIZE);
 
 	gtk_window_set_resizable(GTK_WINDOW(vw->window), TRUE);
-	gtk_window_set_title (GTK_WINDOW(vw->window), GQ_APPNAME);
-        gtk_window_set_wmclass(GTK_WINDOW(vw->window), "view", GQ_WMCLASS);
         gtk_container_set_border_width(GTK_CONTAINER(vw->window), 0);
 
-	window_set_icon(vw->window, PIXBUF_INLINE_ICON_VIEW, NULL);
-
 	vw->imd = image_new(FALSE);
 
 	image_background_set_color(vw->imd, user_specified_window_background ? &window_background_color : NULL);
--- a/src/info.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/info.c	Wed Apr 09 16:37:54 2008 +0000
@@ -775,17 +775,10 @@
 	id->fd = (FileData *)id->list->data;
 	id->updated = FALSE;
 
-	id->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	id->window = window_new(GTK_WINDOW_TOPLEVEL, "properties", NULL, NULL, _("Image properties"));
 	gtk_window_set_type_hint(GTK_WINDOW(id->window), GDK_WINDOW_TYPE_HINT_DIALOG);
-	window_set_icon(id->window, NULL, NULL);
 
 	gtk_window_set_resizable(GTK_WINDOW(id->window), TRUE);
-	{
-	gchar *title = g_strdup_printf("%s - %s", _("Image properties"), GQ_APPNAME); 
-	gtk_window_set_title(GTK_WINDOW(id->window), title);
-	g_free(title);
-	}
-	gtk_window_set_wmclass(GTK_WINDOW(id->window), "properties", GQ_WMCLASS);
 
 	geometry.min_width = 32;
 	geometry.min_height = 32;
--- a/src/layout.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/layout.c	Wed Apr 09 16:37:54 2008 +0000
@@ -1317,7 +1317,7 @@
 		GdkGeometry geometry;
 		GdkWindowHints hints;
 
-		lw->tools = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+		lw->tools = window_new(GTK_WINDOW_TOPLEVEL, "tools", PIXBUF_INLINE_ICON_TOOLS, NULL, _("Tools"));
 		g_signal_connect(G_OBJECT(lw->tools), "delete_event",
 				 G_CALLBACK(layout_tools_delete_cb), lw);
 		layout_keyboard_init(lw, lw->tools);
@@ -1340,16 +1340,8 @@
 
 
 		gtk_window_set_resizable(GTK_WINDOW(lw->tools), TRUE);
-		{
-		gchar *title = g_strdup_printf("%s - %s", _("Tools"), GQ_APPNAME);
-		gtk_window_set_title(GTK_WINDOW(lw->tools), title);
-		g_free(title);
-		}
-		gtk_window_set_wmclass(GTK_WINDOW(lw->tools), "tools", GQ_WMCLASS);
 		gtk_container_set_border_width(GTK_CONTAINER(lw->tools), 0);
-
-		window_set_icon(lw->tools, PIXBUF_INLINE_ICON_TOOLS, NULL);
-
+	
 		new_window = TRUE;
 		}
 	else
@@ -1930,15 +1922,10 @@
 
 	/* window */
 
-	lw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	lw->window = window_new(GTK_WINDOW_TOPLEVEL, GQ_WMCLASS, NULL, NULL, NULL);
 	gtk_window_set_resizable(GTK_WINDOW(lw->window), TRUE);
-
-	gtk_window_set_title(GTK_WINDOW(lw->window), GQ_APPNAME);
-	gtk_window_set_wmclass(GTK_WINDOW(lw->window), GQ_WMCLASS, GQ_WMCLASS);
 	gtk_container_set_border_width(GTK_CONTAINER(lw->window), 0);
 
-	window_set_icon(lw->window, NULL, NULL);
-
 	if (save_window_positions)
 		{
 		hint_mask = GDK_HINT_USER_POS;
--- a/src/main.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/main.c	Wed Apr 09 16:37:54 2008 +0000
@@ -52,6 +52,34 @@
  *-----------------------------------------------------------------------------
  */ 
 
+GtkWidget *window_new(GtkWindowType type, const gchar *name, const gchar *icon,
+		      const gchar *icon_file, const gchar *subtitle)
+{
+	gchar *title;
+	GtkWidget *window;
+
+	window = gtk_window_new(type);
+	if (!window) return NULL;
+	
+	if (subtitle)
+		{
+		title = g_strdup_printf("%s - %s", subtitle, GQ_APPNAME);
+		}
+	else
+		{
+		title = g_strdup_printf("%s", GQ_APPNAME);
+		}
+	
+	gtk_window_set_title(GTK_WINDOW(window), title);
+	g_free(title);
+
+	window_set_icon(window, icon, icon_file);
+	gtk_window_set_role(GTK_WINDOW(window), name);
+	gtk_window_set_wmclass(GTK_WINDOW(window), name, GQ_WMCLASS);
+
+	return window;
+}
+
 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file)
 {
 	if (!icon && !file) icon = PIXBUF_INLINE_ICON;
--- a/src/main.h	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/main.h	Wed Apr 09 16:37:54 2008 +0000
@@ -243,6 +243,8 @@
  * This also doubles as the main.c header.
  */
 
+GtkWidget *window_new(GtkWindowType type, const gchar *name, const gchar *icon,
+		      const gchar *icon_file, const gchar *subtitle);
 void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file);
 gint window_maximized(GtkWidget *window);
 
--- a/src/pan-view.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/pan-view.c	Wed Apr 09 16:37:54 2008 +0000
@@ -2354,24 +2354,15 @@
 	pw->overlay_id = -1;
 	pw->idle_id = -1;
 
-	pw->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	pw->window = window_new(GTK_WINDOW_TOPLEVEL, "panview", NULL, NULL, _("Pan View"));
 
 	geometry.min_width = 8;
 	geometry.min_height = 8;
 	gtk_window_set_geometry_hints(GTK_WINDOW(pw->window), NULL, &geometry, GDK_HINT_MIN_SIZE);
 
 	gtk_window_set_resizable(GTK_WINDOW(pw->window), TRUE);
-
-	{
-	gchar *title = g_strdup_printf("%s - %s",  _("Pan View"), GQ_APPNAME);
-	gtk_window_set_title(GTK_WINDOW(pw->window), title);
-	g_free(title);
-	}
-        gtk_window_set_wmclass(GTK_WINDOW(pw->window), "view", GQ_WMCLASS);
         gtk_container_set_border_width(GTK_CONTAINER(pw->window), 0);
 
-	window_set_icon(pw->window, NULL, NULL);
-
 	vbox = gtk_vbox_new(FALSE, 0);
 	gtk_container_add(GTK_CONTAINER(pw->window), vbox);
 	gtk_widget_show(vbox);
--- a/src/preferences.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/preferences.c	Wed Apr 09 16:37:54 2008 +0000
@@ -1508,22 +1508,14 @@
 	GtkWidget *button;
 	GtkWidget *ct_button;
 
-	configwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	configwindow = window_new(GTK_WINDOW_TOPLEVEL, "preferences", PIXBUF_INLINE_ICON_CONFIG, NULL, _("Preferences"));
 	gtk_window_set_type_hint(GTK_WINDOW(configwindow), GDK_WINDOW_TYPE_HINT_DIALOG);
 	g_signal_connect(G_OBJECT (configwindow), "delete_event",
 			 G_CALLBACK(config_window_delete), NULL);
 	gtk_window_set_default_size(GTK_WINDOW(configwindow), CONFIG_WINDOW_DEF_WIDTH, CONFIG_WINDOW_DEF_HEIGHT);		 
 	gtk_window_set_resizable(GTK_WINDOW(configwindow), TRUE);
-	{
-	gchar *title = g_strdup_printf("%s - %s", _("Preferences"), GQ_APPNAME);
-	gtk_window_set_title(GTK_WINDOW(configwindow), title);
-	g_free(title);
-	}
-	gtk_window_set_wmclass(GTK_WINDOW(configwindow), "config", GQ_WMCLASS);
 	gtk_container_set_border_width(GTK_CONTAINER(configwindow), PREF_PAD_BORDER);
 
-	window_set_icon(configwindow, PIXBUF_INLINE_ICON_CONFIG, NULL);
-
 	win_vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE);
 	gtk_container_add(GTK_CONTAINER(configwindow), win_vbox);
 	gtk_widget_show(win_vbox);
@@ -1639,17 +1631,11 @@
 		return;
 		}
 
-	about = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	about = window_new(GTK_WINDOW_TOPLEVEL, "about", NULL, NULL, _("About"));
 	gtk_window_set_type_hint(GTK_WINDOW(about), GDK_WINDOW_TYPE_HINT_DIALOG);
-	gtk_window_set_wmclass(GTK_WINDOW(about), "about", GQ_WMCLASS);
 	g_signal_connect(G_OBJECT(about), "delete_event",
 			 G_CALLBACK(about_delete_cb), NULL);
 
-	{
-	gchar *title = g_strdup_printf("%s - %s", _("About"), GQ_APPNAME);
-	gtk_window_set_title(GTK_WINDOW(about), title);
-	g_free(title);
-	}
 	gtk_container_set_border_width(GTK_CONTAINER(about), PREF_PAD_BORDER);
 
 	vbox = gtk_vbox_new(FALSE, PREF_PAD_SPACE);
@@ -1694,7 +1680,6 @@
 	gtk_widget_grab_default(button);
 	gtk_widget_show(button);
 
-	window_set_icon(about, NULL, NULL);
 	gtk_widget_show(about);
 }
 
--- a/src/search.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/search.c	Wed Apr 09 16:37:54 2008 +0000
@@ -2552,16 +2552,9 @@
 	sd->search_idle_id = -1;
 	sd->update_idle_id = -1;
 
-	sd->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	window_set_icon(sd->window, NULL, NULL);
+	sd->window = window_new(GTK_WINDOW_TOPLEVEL, "search", NULL, NULL, _("Image search"));
 
 	gtk_window_set_resizable(GTK_WINDOW(sd->window), TRUE);
-	{
-	gchar *title = g_strdup_printf("%s - %s", _("Image search"), GQ_APPNAME);
-	gtk_window_set_title(GTK_WINDOW(sd->window), title);
-	g_free(title);
-	}
-	gtk_window_set_wmclass(GTK_WINDOW(sd->window), "search", GQ_WMCLASS);
 
 	geometry.min_width = 32;
 	geometry.min_height = 32;
--- a/src/ui_help.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/ui_help.c	Wed Apr 09 16:37:54 2008 +0000
@@ -20,6 +20,7 @@
 
 #include <gtk/gtk.h>
 
+#include "main.h"
 #include "ui_help.h"
 
 #include "ui_fileops.h"
@@ -198,17 +199,13 @@
 
 	/* window */
 
-	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	window = window_new(GTK_WINDOW_TOPLEVEL, subclass, NULL, NULL, title);
 	gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
 #if 0
 	gtk_container_set_border_width(GTK_CONTAINER(window), PREF_PAD_BORDER);
 #endif
-	gtk_window_set_wmclass(GTK_WINDOW(window), subclass, wmclass);
-
 	gtk_window_set_default_size(GTK_WINDOW(window), HELP_WINDOW_WIDTH, HELP_WINDOW_HEIGHT);
 
-	gtk_window_set_title(GTK_WINDOW(window), title);
-
 	g_signal_connect(G_OBJECT(window), "delete_event",
 			 G_CALLBACK(help_window_delete_cb), NULL);
 
--- a/src/ui_utildlg.c	Wed Apr 09 13:53:01 2008 +0000
+++ b/src/ui_utildlg.c	Wed Apr 09 16:37:54 2008 +0000
@@ -217,9 +217,9 @@
 	gd->data = data;
 	gd->cancel_cb = cancel_cb;
 
-	gd->dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+	gd->dialog = window_new(GTK_WINDOW_TOPLEVEL, wmsubclass, NULL, NULL, title);
 	gtk_window_set_type_hint(GTK_WINDOW(gd->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
-	gtk_window_set_wmclass(GTK_WINDOW(gd->dialog), wmsubclass, wmclass);
+
 	if (parent)
 		{
 		GtkWindow *window = NULL;
@@ -245,7 +245,6 @@
 			 G_CALLBACK(generic_dialog_key_press_cb), gd);
 
 	gtk_window_set_resizable(GTK_WINDOW(gd->dialog), TRUE);
-	gtk_window_set_title(GTK_WINDOW (gd->dialog), title);
 	gtk_container_set_border_width(GTK_CONTAINER(gd->dialog), PREF_PAD_BORDER);
 
 	vbox = gtk_vbox_new(FALSE, PREF_PAD_BUTTON_SPACE);