cheese r922 - in trunk: . data src



Author: fargiolas
Date: Sat Aug 16 18:36:46 2008
New Revision: 922
URL: http://svn.gnome.org/viewvc/cheese?rev=922&view=rev

Log:
Don't start cheese twice if another instance is running. First part of Felix Kaser's work with cheese and dbus. Fixes bug #527736.


Added:
   trunk/data/org.gnome.Cheese.service
   trunk/src/cheese-dbus-infos.xml
   trunk/src/cheese-dbus.c
   trunk/src/cheese-dbus.h
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/data/Makefile.am
   trunk/src/Makefile.am
   trunk/src/cheese-window.c
   trunk/src/cheese-window.h
   trunk/src/cheese.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Sat Aug 16 18:36:46 2008
@@ -35,6 +35,13 @@
   $3=`eval echo [$]ac_expand`
 ])
 
+#dbus
+AS_AC_EXPAND(DATADIR, $datadir)
+
+DBUS_SERVICES_DIR="$DATADIR/dbus-1/services"
+AC_SUBST(DBUS_SERVICES_DIR)
+AC_DEFINE_UNQUOTED(DBUS_SERVICES_DIR, "$DBUS_SERVICES_DIR", [Where services dir for DBUS is])
+
 # FULL_LIBEXECDIR is used for X-GNOME-Bugzilla-ExtraInfoScript expansion
 # in data/cheese.desktop.in.in
 CHEESE_FULLPATH(libexecdir, NONE, FULL_LIBEXECDIR)

Modified: trunk/data/Makefile.am
==============================================================================
--- trunk/data/Makefile.am	(original)
+++ trunk/data/Makefile.am	Sat Aug 16 18:36:46 2008
@@ -28,6 +28,15 @@
 bugreportdir      = $(libexecdir)/cheese
 bugreport_SCRIPTS = cheese-bugreport.sh
 
+# Dbus service file
+servicedir = $(DBUS_SERVICES_DIR)
+service_in_files = org.gnome.Cheese.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+
+# Rule to make the service file with bindir expanded
+$(service_DATA): $(service_in_files) Makefile
+	@sed -e "s|@bindir@|$(bindir)|" $<> $@
+
 if GCONF_SCHEMAS_INSTALL
 install-data-local:
 	-GCONF_CONFIG_SOURCE=$(GCONF_SCHEMA_CONFIG_SOURCE) \

Added: trunk/data/org.gnome.Cheese.service
==============================================================================
--- (empty file)
+++ trunk/data/org.gnome.Cheese.service	Sat Aug 16 18:36:46 2008
@@ -0,0 +1,21 @@
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sat Aug 16 18:36:46 2008
@@ -15,6 +15,8 @@
 	cheese.c \
 	cheese-countdown.c \
 	cheese-countdown.h \
+	cheese-dbus.c \
+	cheese-dbus.h \
 	cheese-effect-chooser.c \
 	cheese-effect-chooser.h \
 	cheese-fileutil.c \
@@ -60,3 +62,16 @@
   cheese_LDADD += $(HILDON_LIBS)
 endif
 
+#dbus
+BUILT_SOURCES = cheese-dbus-glue.h
+# We don't want to install this header
+noinst_HEADERS = $(BUILT_SOURCES)
+
+# Correctly clean the generated headers, but keep the xml description
+CLEANFILES = $(BUILT_SOURCES)
+EXTRA_DIST = cheese-dbus-infos.xml
+
+#Rule to generate the binding headers
+cheese-dbus-glue.h:  cheese-dbus-infos.xml
+	dbus-binding-tool --prefix=cheese_dbus --mode=glib-server $<> $@
+

Added: trunk/src/cheese-dbus-infos.xml
==============================================================================
--- (empty file)
+++ trunk/src/cheese-dbus-infos.xml	Sat Aug 16 18:36:46 2008
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<node name="/org/gnome/cheese">
+	<interface name="org.gnome.Cheese">
+		<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="cheese_dbus"/>
+		<method name="notify">
+		</method>
+	</interface>
+</node>

Added: trunk/src/cheese-dbus.c
==============================================================================
--- (empty file)
+++ trunk/src/cheese-dbus.c	Sat Aug 16 18:36:46 2008
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2007,2008 daniel g. siegel <dgsiegel gmail com>
+ * Copyright (C) 2007,2008 Jaap Haitsma <jaap haitsma org>
+ * Copyright (C) 2008 Felix Kaser <f kaser gmx net>
+ * 
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <cheese-config.h>
+#endif
+
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+#include "cheese-dbus.h"
+#include "cheese-dbus-glue.h"
+#include <glib.h>
+#include <glib-object.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <gtk/gtk.h>
+#include "cheese-window.h"
+
+gpointer window_pointer;
+
+G_DEFINE_TYPE (CheeseDbus, cheese_dbus, G_TYPE_OBJECT);
+
+void
+cheese_dbus_set_window (gpointer data)
+{
+  if (data != NULL)
+    window_pointer = data;
+}
+
+gboolean
+cheese_dbus_notify ()
+{
+  cheese_window_bring_to_front (window_pointer);
+  return TRUE;
+}
+
+void
+cheese_dbus_class_init (CheeseDbusClass *klass)
+{
+  GError *error = NULL;
+
+  /* Init the DBus connection, per-klass */
+  klass->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (klass->connection == NULL)
+  {
+    g_warning("Unable to connect to dbus: %s", error->message);
+    g_error_free (error);
+    return;
+  }
+                                               
+  dbus_g_object_type_install_info (CHEESE_TYPE_DBUS, &dbus_glib_cheese_dbus_object_info);
+}
+
+void
+cheese_dbus_init (CheeseDbus *server)
+{
+  CheeseDbusClass *klass = CHEESE_DBUS_GET_CLASS (server);
+
+  /* Register DBUS path */
+  dbus_g_connection_register_g_object (klass->connection,
+                                       "/org/gnome/cheese",
+                                       G_OBJECT (server));
+}
+
+CheeseDbus *
+cheese_dbus_new ()
+{
+  CheeseDbus *server;
+  GError *error = NULL;
+  DBusGProxy *proxy;
+  guint request_ret;
+  CheeseDbusClass *klass;
+	
+  server = g_object_new (CHEESE_TYPE_DBUS, NULL);
+  
+  klass = CHEESE_DBUS_GET_CLASS (server);
+  /* Register the service name, the constant here are defined in dbus-glib-bindings.h */
+  proxy = dbus_g_proxy_new_for_name (klass->connection,
+                                     DBUS_SERVICE_DBUS,
+                                     DBUS_PATH_DBUS,
+                                     DBUS_INTERFACE_DBUS);
+  
+  if(!org_freedesktop_DBus_request_name (proxy,
+                                         "org.gnome.Cheese",
+                                         0, &request_ret,    /* See tutorial for more infos about these */
+                                         &error))
+  {
+    g_warning("Unable to register service: %s", error->message);
+    g_error_free (error);
+  }
+	
+  /*check if there is already a instance running -> exit*/
+  if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS ||
+      request_ret == DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
+  {
+    gboolean return_value;
+	  
+    g_warning ("Another instance of cheese is already running!");
+	  
+    /*notify the other instance of cheese*/
+    proxy = dbus_g_proxy_new_for_name (klass->connection,
+                                       "org.gnome.Cheese",
+                                       "/org/gnome/cheese",
+                                       "org.gnome.Cheese");
+      
+    if(!dbus_g_proxy_call (proxy, "notify", &error, G_TYPE_INVALID, G_TYPE_INVALID))
+    {
+      /* Method failed, the GError is set, let's warn everyone */
+      g_warning ("Notifying the other cheese instance failed: %s", error->message);
+      g_error_free (error);
+    }
+    
+    g_object_unref (server);
+    server = NULL;
+  }
+
+  g_object_unref (proxy);
+	
+  return server;
+}

Added: trunk/src/cheese-dbus.h
==============================================================================
--- (empty file)
+++ trunk/src/cheese-dbus.h	Sat Aug 16 18:36:46 2008
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007,2008 daniel g. siegel <dgsiegel gmail com>
+ * Copyright (C) 2007,2008 Jaap Haitsma <jaap haitsma org>
+ * Copyright (C) 2008 Felix Kaser <f kaser gmx net>
+ * 
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CHEESE_DBUS_H_
+#define _CHEESE_DBUS_H_
+
+#include <dbus/dbus-glib.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct
+{
+  GObjectClass parent_class;
+  DBusGConnection *connection;
+}CheeseDbusClass;
+
+typedef struct _CheeseDbus{
+  GObject parent;
+}CheeseDbus;
+
+
+#define CHEESE_TYPE_DBUS            (cheese_dbus_get_type ())
+#define CHEESE_DBUS(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHEESE_TYPE_DBUS, CheeseDbus))
+#define CHEESE_DBUS_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  CHEESE_TYPE_DBUS, CheeseDbusClass))
+#define CHEESE_IS_DBUS(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHEESE_TYPE_DBUS))
+#define CHEESE_IS_DBUS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  CHEESE_TYPE_DBUS))
+#define CHEESE_DBUS_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  CHEESE_TYPE_DBUS, CheeseDbusClass))
+
+
+GType
+cheese_dbus_get_type (void);
+CheeseDbus *
+cheese_dbus_new (void);
+void
+cheese_dbus_set_window (gpointer);
+gboolean
+cheese_dbus_notify (void);
+
+G_END_DECLS
+
+#endif /* _CHEESE_DBUS_H_ */

Modified: trunk/src/cheese-window.c
==============================================================================
--- trunk/src/cheese-window.c	(original)
+++ trunk/src/cheese-window.c	Sat Aug 16 18:36:46 2008
@@ -94,6 +94,8 @@
   WebcamMode webcam_mode;
   CheeseGConf *gconf;
   CheeseFileUtil *fileutil;
+  
+  CheeseDbus *server;
 
   GtkWidget *window;
   GtkWidget *fullscreen_popup;
@@ -170,6 +172,13 @@
   int audio_play_counter;
 } CheeseWindow;
 
+void
+cheese_window_bring_to_front (gpointer data)
+{
+  CheeseWindow *cheese_window = data;
+  gtk_window_present (GTK_WINDOW (cheese_window->window));
+}
+
 /* Make url in about dialog clickable */
 static void
 cheese_about_dialog_handle_url (GtkAboutDialog *dialog, const char *url, gpointer data)
@@ -1860,7 +1869,7 @@
 }
 
 void
-cheese_window_init (char *hal_dev_udi)
+cheese_window_init (char *hal_dev_udi, CheeseDbus *dbus_server)
 {
   CheeseWindow *cheese_window;
 
@@ -1872,6 +1881,10 @@
   cheese_window->fileutil = cheese_fileutil_new ();
   cheese_window->isFullscreen = FALSE;
   
+  cheese_window->server = dbus_server;
+  //save a pointer to the cheese window in cheese dbus
+  cheese_dbus_set_window (cheese_window);
+  
   cheese_window->fullscreen_timeout_source = NULL;
 
   cheese_window_create_window (cheese_window);

Modified: trunk/src/cheese-window.h
==============================================================================
--- trunk/src/cheese-window.h	(original)
+++ trunk/src/cheese-window.h	Sat Aug 16 18:36:46 2008
@@ -21,8 +21,10 @@
 #define __CHEESE_WINDOW_H__
 
 #include <gtk/gtk.h>
+#include "cheese-dbus.h"
 
 
-void cheese_window_init (char *hal_dev_udi);
+void cheese_window_init (char *hal_dev_udi, CheeseDbus *dbus_server);
+void cheese_window_bring_to_front (gpointer data);
 
 #endif /* __CHEESE_WINDOW_H__ */

Modified: trunk/src/cheese.c
==============================================================================
--- trunk/src/cheese.c	(original)
+++ trunk/src/cheese.c	Sat Aug 16 18:36:46 2008
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2007,2008 daniel g. siegel <dgsiegel gmail com>
  * Copyright (C) 2007,2008 Jaap Haitsma <jaap haitsma org>
+ * Copyright (C) 2008 Felix Kaser <f kaser gmx net>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -31,6 +32,7 @@
 
 #include "cheese-fileutil.h"
 #include "cheese-window.h"
+#include "cheese-dbus.h"
 
 struct _CheeseOptions
 {
@@ -76,6 +78,7 @@
 main (int argc, char **argv)
 {
   GOptionContext *context;
+  CheeseDbus *dbus_server;
   
   GOptionEntry options[] = {
     { "verbose", 'v', 0, G_OPTION_ARG_NONE, &CheeseOptions.verbose, _("Be verbose"), NULL},
@@ -83,7 +86,7 @@
     { NULL }
   };
   CheeseOptions.hal_device_id = NULL;
-
+  
   bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALEDIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
@@ -102,6 +105,12 @@
   g_option_context_parse (context, &argc, &argv, NULL);
   g_option_context_free (context);
 
+  dbus_server = cheese_dbus_new ();
+  if (dbus_server == NULL)
+  {
+    return -1;
+  }
+
   /* Needed for gnome_thumbnail functions */
   gnome_vfs_init ();
 
@@ -111,7 +120,7 @@
   gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
                                      APPNAME_DATA_DIR G_DIR_SEPARATOR_S "icons");
 
-  cheese_window_init (CheeseOptions.hal_device_id);
+  cheese_window_init (CheeseOptions.hal_device_id, dbus_server);
   
   gdk_threads_enter ();
   gtk_main ();



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