[gnome-commander/gcmd-1-3] one instance mode: libunique support



commit 5cca0cc88ad084d755be003c47e58fb43b51ea48
Author: Piotr Eljasiak <epiotr src gnome org>
Date:   Wed Mar 3 18:35:30 2010 +0100

    one instance mode: libunique support

 configure.in    |    6 ++++
 src/Makefile.am |    2 +
 src/main.cc     |   84 ++++++++++++++++++++++++++++++++++++++----------------
 3 files changed, 67 insertions(+), 25 deletions(-)
---
diff --git a/configure.in b/configure.in
index b17be16..b2e8503 100644
--- a/configure.in
+++ b/configure.in
@@ -48,6 +48,7 @@ GNOME_REQ=2.0.0
 GNOMEUI_REQ=2.4.0
 GNOMEVFS_REQ=2.0.0
 VTE_REQ=0.11
+UNIQUE_REQ=0.9.3
 PYTHON_REQ=2.5
 EXIV2_REQ=0.14
 TAGLIB_REQ=1.4
@@ -60,6 +61,7 @@ AC_SUBST(GNOME_REQ)
 AC_SUBST(GNOMEUI_REQ)
 AC_SUBST(GNOMEVFS_REQ)
 AC_SUBST(VTE_REQ)
+AC_SUBST(UNIQUE_REQ)
 AC_SUBST(PYTHON_REQ)
 AC_SUBST(EXIV2_REQ)
 AC_SUBST(TAGLIB_REQ)
@@ -197,6 +199,10 @@ dnl Check for vte support
 PKG_CHECK_MODULES(VTE, vte >= $VTE_REQ)
 
 
+dnl Check for libUnique
+PKG_CHECK_MODULES(UNIQUE, [ unique-1.0 >= ${UNIQUE_REQ} ])
+
+
 dnl Check for exiv2 support
 AC_ARG_WITH(libexiv2, [  --without-exiv2         disable EXIF and IPTC support])
 have_exiv2=no
diff --git a/src/Makefile.am b/src/Makefile.am
index 2241960..e1eaf04 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,6 +8,7 @@ AM_CPPFLAGS = \
 	$(GNOMEUI_CFLAGS) \
 	$(GNOMEVFS_CFLAGS) \
 	$(VTE_CFLAGS) \
+	$(UNIQUE_CFLAGS) \
 	$(PYTHON_CFLAGS) \
 	-DDATADIR=\""$(datadir)"\"\
 	-DPLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins"\"
@@ -106,6 +107,7 @@ gnome_commander_LDADD = \
 	$(GNOMEUI_LIBS) \
 	$(GNOMEVFS_LIBS) \
 	$(VTE_LIBS) \
+	$(UNIQUE_LIBS) \
 	$(EXIV2_LIBS) \
 	$(TAGLIB_LIBS) \
 	$(CHM_LIBS) \
diff --git a/src/main.cc b/src/main.cc
index 13c4ca2..a75e8f3 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -25,6 +25,7 @@ extern "C"
 
 #include <config.h>
 #include <locale.h>
+#include <unique/unique.h>
 
 #include "gnome-cmd-includes.h"
 #include "gnome-cmd-main-win.h"
@@ -79,11 +80,28 @@ static const GOptionEntry options [] =
 };
 
 
+static UniqueResponse on_message_received (UniqueApp *app, UniqueCommand cmd, UniqueMessageData *msg, guint t, gpointer  user_data)
+{
+    switch (cmd)
+    {
+        case UNIQUE_ACTIVATE:
+            gtk_window_set_screen (*main_win, unique_message_data_get_screen (msg));
+            gtk_window_present_with_time (*main_win, t);
+            break;
+
+        default:
+            break;
+    }
+
+    return UNIQUE_RESPONSE_OK;
+}
+
+
 int main (int argc, char *argv[])
 {
     GnomeProgram *program;
     GOptionContext *option_context;
-    gchar *conf_dir;
+    UniqueApp *app;
 
     main_win = NULL;
 
@@ -120,49 +138,65 @@ int main (int argc, char *argv[])
     gdk_rgb_init ();
     gnome_vfs_init ();
 
-    conf_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome-commander", NULL);
+    gchar *conf_dir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome-commander", NULL);
     create_dir_if_needed (conf_dir);
     g_free (conf_dir);
+
     IMAGE_init ();
     gcmd_user_actions.init();
     gnome_cmd_data.load();
-    gcmd_user_actions.set_defaults();
-    ls_colors_init ();
-    gnome_cmd_data.load_more();
 
-    if (gnome_cmd_data.use_gnome_auth_manager)
-        gnome_authentication_manager_init ();
+    app = unique_app_new_with_commands ("org.gnome.GnomeCommander", NULL,
+                                         NULL);
+
+    if (!gnome_cmd_data.allow_multiple_instances && unique_app_is_running (app))
+        unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
     else
-        gnome_cmd_smb_auth_init ();
+    {
+        gcmd_user_actions.set_defaults();
+        ls_colors_init ();
+        gnome_cmd_data.load_more();
+
+        if (gnome_cmd_data.use_gnome_auth_manager)
+            gnome_authentication_manager_init ();
+        else
+            gnome_cmd_smb_auth_init ();
+
+        gnome_cmd_style_create ();
+
+        main_win_widget = gnome_cmd_main_win_new ();
+        main_win = GNOME_CMD_MAIN_WIN (main_win_widget);
 
-    gnome_cmd_style_create ();
+        unique_app_watch_window (app, *main_win);
+        g_signal_connect (app, "message-received", G_CALLBACK (on_message_received), NULL);
 
-    main_win_widget = gnome_cmd_main_win_new ();
-    main_win = GNOME_CMD_MAIN_WIN (main_win_widget);
-    gtk_widget_show (GTK_WIDGET (main_win));
-    gcmd_owner.load_async();
+        gtk_widget_show (GTK_WIDGET (main_win));
+        gcmd_owner.load_async();
 
-    gcmd_tags_init();
-    plugin_manager_init ();
+        gcmd_tags_init();
+        plugin_manager_init ();
 #ifdef HAVE_PYTHON
-    python_plugin_manager_init ();
+        python_plugin_manager_init ();
 #endif
 
-    gtk_main ();
+        gtk_main ();
 
 #ifdef HAVE_PYTHON
-    python_plugin_manager_shutdown ();
+        python_plugin_manager_shutdown ();
 #endif
-    plugin_manager_shutdown ();
-    gcmd_tags_shutdown ();
-    gcmd_user_actions.shutdown();
-    gnome_cmd_data.save();
-    gnome_vfs_shutdown ();
-    IMAGE_free ();
+        plugin_manager_shutdown ();
+        gcmd_tags_shutdown ();
+        gcmd_user_actions.shutdown();
+        gnome_cmd_data.save();
+        IMAGE_free ();
+
+        remove_temp_download_dir ();
+    }
 
-    remove_temp_download_dir ();
+    gnome_vfs_shutdown ();
 
     g_option_context_free (option_context);
+    g_object_unref (app);
     g_object_unref (program);
 
     DEBUG ('c', "dirs total: %d remaining: %d\n", created_dirs_cnt, created_dirs_cnt - deleted_dirs_cnt);



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