[cheese/three-point-oh] Made cheese single-instance using libunique-1.0



commit 9c18a898af6108775a244d03c060b33e361f04ed
Author: Yuvaraj Pandian T <yuvipanda gmail com>
Date:   Sun Jun 13 01:39:59 2010 +0530

    Made cheese single-instance using libunique-1.0

 configure.ac             |    5 ++++-
 valasrc/Makefile.am      |    1 +
 valasrc/cheese-main.vala |   32 ++++++++++++++++++++++++++++++--
 3 files changed, 35 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c1ef434..a64458a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,6 +91,7 @@ LIBRSVG_REQUIRED=2.18.0
 CLUTTER_REQUIRED=1.0
 CLUTTERGTK_REQUIRED=0.10
 CLUTTERGST_REQUIRED=0.10
+UNIQUE_REQUIRED=1.1
 
 #*******************************************************************************
 # Check for udev
@@ -149,7 +150,9 @@ PKG_CHECK_MODULES(CHEESE, \
   clutter-1.0 >= $CLUTTER_REQUIRED \
   clutter-gtk-0.10 >= $CLUTTERGTK_REQUIRED \
   clutter-gst-0.10 >= $CLUTTERGST_REQUIRED \
-  libcanberra-gtk $UDEV_PKG)
+  unique-1.0  >= $UNIQUE_REQUIRED \ 
+  libcanberra-gtk $UDEV_PKG 
+  )
 AC_SUBST(CHEESE_CFLAGS)
 
 CHEESE_LIBS="$CHEESE_LIBS -lgstinterfaces-0.10"
diff --git a/valasrc/Makefile.am b/valasrc/Makefile.am
index 1622476..d355087 100644
--- a/valasrc/Makefile.am
+++ b/valasrc/Makefile.am
@@ -8,6 +8,7 @@ VALAFLAGS = \
 	--pkg clutter-gtk-0.10 \
 	--pkg gconf-2.0 \
 	--pkg gstreamer-0.10 \
+	--pkg unique-1.0 \
 	--pkg eogthumbnav \
 	--pkg cheese-thumbview \
 	--pkg cheese-common
diff --git a/valasrc/cheese-main.vala b/valasrc/cheese-main.vala
index 6685f72..132dddb 100644
--- a/valasrc/cheese-main.vala
+++ b/valasrc/cheese-main.vala
@@ -2,6 +2,7 @@ using GLib;
 using Gtk;
 using Clutter;
 using Gst;
+using Unique;
 
 public class Cheese.Main {
 	static bool verbose;
@@ -9,6 +10,8 @@ public class Cheese.Main {
 	static bool version_only;
 	static FileStream log_file;
 
+	static Cheese.MainWindow main_window;
+
 	const OptionEntry[] options = {
 		{ "verbose", 'v', 0, OptionArg.NONE, ref verbose, N_("Be verbose"), null},
 		{ "wide", 'w', 0, OptionArg.NONE, ref wide, N_("Enable wide mode"), null},
@@ -23,7 +26,19 @@ public class Cheese.Main {
 		}
 	}
 
-	public static int main (string[] args) {
+	public static Unique.Response unique_message_received(int command,
+														  Unique.MessageData msg,
+														  uint time) {
+		Unique.Response res;
+		if (command == Unique.Command.ACTIVATE) {
+			main_window.set_screen(msg.get_screen());
+			main_window.activate();
+		}
+		return Unique.Response.OK;
+	}
+	
+	public static int main (string[] args) {		
+
 
 		Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.PACKAGE_LOCALEDIR);
   		Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
@@ -46,6 +61,19 @@ public class Cheese.Main {
 			return 1;
 		}
 
+		main_window = new Cheese.MainWindow();
+		
+		Unique.App app = new Unique.App("org.gnome.Cheese", null);
+		if (app.is_running) {
+			Unique.Response response;
+			response = app.send_message(Unique.Command.ACTIVATE, null);
+			return 0;
+		}
+		else {
+			app.watch_window(main_window);
+			app.message_received.connect(unique_message_received);
+		}		
+
  		Environment.set_application_name (_("Cheese"));
 		Window.set_default_icon_name ("cheese");
 
@@ -55,7 +83,7 @@ public class Cheese.Main {
 		set_print_handler (print_handler);
 
 		Gtk.IconTheme.get_default().append_search_path(GLib.Path.build_filename (Config.PACKAGE_DATADIR, "icons"));
-		Cheese.MainWindow main_window = new Cheese.MainWindow();
+		
 		main_window.setup_ui();
 		main_window.destroy.connect(Gtk.main_quit);
 		main_window.show_all();



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