[gthumb] [PATCH] repair sm-client support



commit a0c7d3a23f1f75909f637031382dae67d485e8ac
Author: Josef Schmeisser <josef schmeisser freenet de>
Date:   Thu Jan 6 19:05:50 2011 +0100

    [PATCH] repair sm-client support

 configure.ac             |   35 +++++++++++++++++
 copy-n-paste/Makefile.am |   10 ++++-
 gthumb/Makefile.am       |    2 +
 gthumb/gth-main.c        |   12 ++++++
 gthumb/main.c            |   96 +++++++++++++++++++++++++++++++++++++++++----
 5 files changed, 144 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5c88493..38d6a4c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -458,6 +458,40 @@ AM_CONDITIONAL(ENABLE_WEB_ALBUMS, test "x$enable_web_albums" = xyes)
 
 dnl ===========================================================================
 
+GDK_TARGET="$($PKG_CONFIG --variable target gdk-2.0)"
+
+AC_MSG_CHECKING([which smclient backend to use])
+AC_ARG_WITH([smclient],
+  [AS_HELP_STRING([--with-smclient-backend=no|xsmp|win32],
+		  [Setting smclient backend (default:auto)])],
+  [],
+  [case "$GDK_TARGET" in
+    x11) with_smclient=xsmp ;;
+    win32) with_smclient=$GDK_TARGET ;;
+    *) with_smclient=no ;;
+   esac])
+   
+AC_MSG_RESULT([$with_smclient])
+
+if test "$with_smclient" != "no"; then
+  AC_DEFINE([WITH_SMCLIENT],[1],[Define if smclient is enabled])
+
+  case "$with_smclient" in
+    xsmp) SMCLIENT_PKGS="sm >= 1.0.0" ;;
+    *) SMCLIENT_PKGS="" ;;
+  esac
+
+  PKG_CHECK_MODULES([SMCLIENT],[$SMCLIENT_PKGS])
+  AC_SUBST([SMCLIENT_CFLAGS])
+  AC_SUBST([SMCLIENT_LIBS])
+fi
+
+AM_CONDITIONAL([WITH_SMCLIENT],[test "$with_smclient" != "no"])
+AM_CONDITIONAL([WITH_SMCLIENT_XSMP],[test "$with_smclient" = "xsmp"])
+AM_CONDITIONAL([WITH_SMCLIENT_WIN32],[test "$with_smclient" = "win32"])
+
+dnl ===========================================================================
+
 AC_CONFIG_FILES([
 Makefile
 copy-n-paste/Makefile
@@ -612,4 +646,5 @@ Configuration:
 	Use GNOME Keyring    : ${enable_gnome_keyring}
 	Burn disc support    : ${enable_libbrasero}
 	Web albums           : ${enable_web_albums}
+	SM client support    : ${with_smclient}
 "
diff --git a/copy-n-paste/Makefile.am b/copy-n-paste/Makefile.am
index 7f452e6..1eb10e5 100644
--- a/copy-n-paste/Makefile.am
+++ b/copy-n-paste/Makefile.am
@@ -1,7 +1,13 @@
 noinst_LTLIBRARIES = libeggsmclient.la
 
-libeggsmclient_la_LIBADD = $(GTK_LIBS)
-libeggsmclient_la_CFLAGS = $(GTK_CFLAGS)
+libeggsmclient_la_LIBADD = $(SMCLIENT_LIBS) \
+			   $(GTK_LIBS)
+
+libeggsmclient_la_CFLAGS = -DG_LOG_DOMAIN=\""EggSMClient"\" \
+			   -DEGG_SM_CLIENT_BACKEND_XSMP     \
+			   $(SMCLIENT_CFLAGS)               \
+			   $(GTK_CFLAGS)
+
 libeggsmclient_la_SOURCES = eggdesktopfile.h \
 			    eggdesktopfile.c \
 			    eggsmclient.h \
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index 280f0e4..f914a7e 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -257,6 +257,7 @@ gthumb_LDADD =						\
 	$(JPEG_LIBS)					\
 	$(TIFF_LIBS)					\
 	$(CLUTTER_LIBS)					\
+	$(SMCLIENT_LIBS)				\
 	$(GNOME_KEYRING_LIBS)				\
 	$(GSTREAMER_LIBS)				\
 	$(LIBBRASERO_LIBS)				\
@@ -287,6 +288,7 @@ gthumb_CFLAGS =							\
 	$(LIBBRASERO_CFLAGS)					\
 	$(LIBOPENRAW_CFLAGS)					\
 	$(LIBSOUP_CFLAGS)					\
+	$(SMCLIENT_CFLAGS)					\
 	-I$(top_srcdir)/copy-n-paste/				\
 	-DGTHUMB_LOCALEDIR=\"$(datadir)/locale\"		\
 	-DGTHUMB_PREFIX=\"$(prefix)\"           		\
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index f9016a1..43ce14a 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -37,6 +37,12 @@
 #include "pixbuf-io.h"
 #include "typedefs.h"
 
+#ifdef GDK_WINDOWING_X11
+#include <gdk/gdkx.h>
+#endif
+
+#include "eggsmclient.h"
+#include "eggdesktopfile.h"
 
 static GStaticMutex register_mutex = G_STATIC_MUTEX_INIT;
 
@@ -256,8 +262,14 @@ gth_main_initialize (void)
 		return;
 	Main = (GthMain*) g_object_new (GTH_TYPE_MAIN, NULL);
 
+#ifdef GDK_WINDOWING_X11
+	egg_set_desktop_file (GTHUMB_DATADIR "/applications/gthumb.desktop");
+#else
+	/* manually set name and icon */
 	g_set_application_name (_("gthumb"));
 	gtk_window_set_default_icon_name ("gthumb");
+#endif
+
 	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (), GTHUMB_ICON_DIR);
 	gtk_about_dialog_set_url_hook (about_dialog_activate_link_cb, NULL, NULL);
 	gtk_about_dialog_set_email_hook (about_dialog_activate_email_cb, NULL, NULL);
diff --git a/gthumb/main.c b/gthumb/main.c
index 989ac39..33fd1d7 100644
--- a/gthumb/main.c
+++ b/gthumb/main.c
@@ -113,16 +113,22 @@ gth_save_state (EggSMClient *client,
 
 	i = 0;
 	for (scan = gth_window_get_window_list (); scan; scan = scan->next) {
-		GtkWidget *window = scan->data;
-		GFile     *location;
-		char      *key;
-		char      *uri;
+		GtkWidget   *window = scan->data;
+		GFile       *location;
+		char        *key;
+		char        *uri;
+		GthFileData *focused_file = NULL;
+
+		focused_file = gth_browser_get_current_file (GTH_BROWSER (window));
+		if (focused_file == NULL)
+			location = gth_browser_get_location (GTH_BROWSER (window));
+		else
+			location = focused_file->file;
 
-		location = gth_browser_get_location (GTH_BROWSER (window));
 		if (location == NULL)
 			continue;
 
-		key = g_strdup_printf ("location%d", i++);
+		key = g_strdup_printf ("location%d", ++i);
 		uri = g_file_get_uri (location);
 		g_key_file_set_string (state, "Session", key, uri);
 
@@ -136,12 +142,76 @@ gth_save_state (EggSMClient *client,
 
 
 static void
+dialog_response (GtkDialog *dialog, int response, gpointer user_data)
+{
+	EggSMClient *client = user_data;
+
+	gtk_widget_destroy (GTK_WIDGET (dialog));
+	egg_sm_client_will_quit (client, (response != GTK_RESPONSE_NO));
+}
+
+
+/* quit_requested handler for the master client */
+static void
+client_quit_requested_cb (EggSMClient *client, gpointer data)
+{
+	GList      *scan;
+	gboolean    modified_file;
+	for (scan = gth_window_get_window_list (); scan; scan = scan->next) {
+		GtkWidget *window = scan->data;
+
+		g_assert (GTH_IS_BROWSER (window));
+		modified_file = gth_browser_get_file_modified (GTH_BROWSER (window));
+
+		if (modified_file) {
+			GtkWidget *dialog;
+
+			dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+							 GTK_DIALOG_MODAL,
+							 GTK_MESSAGE_QUESTION,
+							 GTK_BUTTONS_YES_NO,
+							 N_("There are unsaved changes, you want to log out?"));
+			g_signal_connect (dialog,
+					  "response",
+					  G_CALLBACK (dialog_response),
+					  client);
+			gtk_widget_show (GTK_WIDGET (dialog));
+			return;
+		}
+	}
+
+	egg_sm_client_will_quit (client, TRUE);
+}
+
+
+/* quit handler for the master client */
+static void
+client_quit_cb (EggSMClient *client, gpointer data)
+{
+	gtk_main_quit ();
+}
+
+
+static void
 gth_session_manager_init (void)
 {
 	EggSMClient *client = NULL;
-
 	client = egg_sm_client_get ();
-	g_signal_connect (client, "save-state", G_CALLBACK (gth_save_state), NULL);
+
+	g_signal_connect (client,
+			  "save_state",
+			  G_CALLBACK (gth_save_state),
+			  NULL);
+
+	g_signal_connect (client,
+			  "quit_requested",
+			  G_CALLBACK (client_quit_requested_cb),
+			  NULL);
+
+	g_signal_connect (client,
+			  "quit",
+			  G_CALLBACK (client_quit_cb),
+			  NULL);	
 }
 
 
@@ -154,18 +224,26 @@ gth_restore_session (EggSMClient *client)
 	state = egg_sm_client_get_state_file (client);
 
 	i = g_key_file_get_integer (state, "Session", "locations", NULL);
+	g_assert (i > 0);
 	for (; i > 0; i--) {
 		GtkWidget *window;
 		char      *key;
 		char      *location;
+		GFile     *file;
 
 		key = g_strdup_printf ("location%d", i);
 		location = g_key_file_get_string (state, "Session", key, NULL);
 		g_free (key);
 
-		window = gth_browser_new (location);
+		g_assert (location != NULL);
+
+		window = gth_browser_new (NULL);
 		gtk_widget_show (window);
 
+		file = g_file_new_for_uri (location);
+		gth_browser_load_location(GTH_BROWSER (window), file);
+
+		g_object_unref (file);
 		g_free (location);
 	}
 }



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