Index: src/cheese-window.c
===================================================================
--- src/cheese-window.c	(Revision 913)
+++ src/cheese-window.c	(Arbeitskopie)
@@ -54,6 +54,7 @@
 #include "gedit-message-area.h"
 #include "cheese-no-camera.h"
 #include "cheese-prefs-dialog.h"
+#include "cheese-dbus.h"
 
 #define SHUTTER_SOUNDS 5
 #define FULLSCREEN_POPUP_HEIGHT 40
@@ -94,6 +95,8 @@
   WebcamMode webcam_mode;
   CheeseGConf *gconf;
   CheeseFileUtil *fileutil;
+  
+  CheeseDbus *server;
 
   GtkWidget *window;
   GtkWidget *fullscreen_popup;
@@ -375,7 +378,7 @@
 
 static void
 cheese_window_photo_saved_cb (CheeseWebcam *webcam, CheeseWindow *cheese_window)
-{  
+{
   // TODO look at this g_free
   g_free (cheese_window->photo_filename);
   cheese_window->photo_filename = NULL;
@@ -1868,13 +1871,15 @@
   CheeseWindow *cheese_window;
 
   cheese_window = g_new0 (CheeseWindow, 1);
+  
+  /*start dbus server, if there is a instance of cheese running --> exit*/
+  cheese_window->server = cheese_dbus_new ();
 
   cheese_window->startup_hal_dev_udi = hal_dev_udi;
   cheese_window->gconf = cheese_gconf_new ();
   cheese_window->audio_play_counter = 0;
   cheese_window->fileutil = cheese_fileutil_new ();
   cheese_window->isFullscreen = FALSE;
-  
   cheese_window->fullscreen_timeout_source = NULL;
 
   cheese_window_create_window (cheese_window);
Index: src/cheese-dbus-infos.xml
===================================================================
--- src/cheese-dbus-infos.xml	(Revision 0)
+++ src/cheese-dbus-infos.xml	(Revision 0)
@@ -0,0 +1,7 @@
+<?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"/>
+	</interface>
+</node>
Index: src/cheese-dbus.c
===================================================================
--- src/cheese-dbus.c	(Revision 0)
+++ src/cheese-dbus.c	(Revision 0)
@@ -0,0 +1,102 @@
+/*
+ * 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 <gtk/gtk.h>
+
+G_DEFINE_TYPE (CheeseDbus, cheese_dbus, G_TYPE_OBJECT);
+
+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)
+{
+	GError *error = NULL;
+	DBusGProxy *driver_proxy;
+	CheeseDbusClass *klass = CHEESE_DBUS_GET_CLASS (server);
+	int request_ret;
+
+	/* Register DBUS path */
+	dbus_g_connection_register_g_object (klass->connection,
+			"/org/gnome/cheese",
+			G_OBJECT (server));
+  
+  
+	/* Register the service name, the constant here are defined in dbus-glib-bindings.h */
+	driver_proxy = dbus_g_proxy_new_for_name (klass->connection,
+			DBUS_SERVICE_DBUS,
+			DBUS_PATH_DBUS,
+			DBUS_INTERFACE_DBUS);
+  
+	if(!org_freedesktop_DBus_request_name (driver_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)
+	{
+	  g_warning ("Another instance of cheese is already running!");
+		exit (1);
+	}
+
+	g_object_unref (driver_proxy);
+}
+
+CheeseDbus *
+cheese_dbus_new ()
+{
+  CheeseDbus *server;
+  server = g_object_new (CHEESE_TYPE_DBUS, NULL);
+  return server;
+}
Index: src/Makefile.am
===================================================================
--- src/Makefile.am	(Revision 913)
+++ src/Makefile.am	(Arbeitskopie)
@@ -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 $<> $@
+
Index: src/cheese-dbus.h
===================================================================
--- src/cheese-dbus.h	(Revision 0)
+++ src/cheese-dbus.h	(Revision 0)
@@ -0,0 +1,56 @@
+/*
+ * 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);
+
+G_END_DECLS
+
+#endif /* _CHEESE_DBUS_H_ */
Index: configure.ac
===================================================================
--- configure.ac	(Revision 913)
+++ configure.ac	(Arbeitskopie)
@@ -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)
Index: acinclude.m4
===================================================================
--- acinclude.m4	(Revision 0)
+++ acinclude.m4	(Revision 0)
@@ -0,0 +1,40 @@
+dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR)
+dnl
+dnl example
+dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir)
+dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local
+
+AC_DEFUN([AS_AC_EXPAND],
+[
+  EXP_VAR=[$1]
+  FROM_VAR=[$2]
+
+  dnl first expand prefix and exec_prefix if necessary
+  prefix_save=$prefix
+  exec_prefix_save=$exec_prefix
+
+  dnl if no prefix given, then use /usr/local, the default prefix
+  if test "x$prefix" = "xNONE"; then
+    prefix=$ac_default_prefix
+  fi
+  dnl if no exec_prefix given, then use prefix
+  if test "x$exec_prefix" = "xNONE"; then
+    exec_prefix=$prefix
+  fi
+
+  full_var="$FROM_VAR"
+  dnl loop until it doesn't change anymore
+  while true; do
+    new_full_var="`eval echo $full_var`"
+    if test "x$new_full_var"="x$full_var"; then break; fi
+    full_var=$new_full_var
+  done
+
+  dnl clean up
+  full_var=$new_full_var
+  AC_SUBST([$1], "$full_var")
+
+  dnl restore prefix and exec_prefix
+  prefix=$prefix_save
+  exec_prefix=$exec_prefix_save
+])
Index: data/org.gnome.Cheese.service.in
===================================================================
--- data/org.gnome.Cheese.service.in	(Revision 0)
+++ data/org.gnome.Cheese.service.in	(Revision 0)
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.gnome.Cheese
+Exec=/usr/bin/cheese
Index: data/Makefile.am
===================================================================
--- data/Makefile.am	(Revision 913)
+++ data/Makefile.am	(Arbeitskopie)
@@ -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) \
