[brasero] Fix #622332 - Port to GApplication



commit 9849e06661d1f2af078ab3f4730dab5280cd3602
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Fri Jul 9 01:37:58 2010 +0200

    Fix #622332  - Port to GApplication

 configure.in      |   10 +-
 src/Makefile.am   |    8 +-
 src/brasero-app.c |  130 ++++++++++------
 src/brasero-app.h |    7 +-
 src/brasero-cli.c |  417 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/brasero-cli.h |   71 +++++++++
 src/main.c        |  430 +++--------------------------------------------------
 7 files changed, 594 insertions(+), 479 deletions(-)
---
diff --git a/configure.in b/configure.in
index 593549e..0599e23 100644
--- a/configure.in
+++ b/configure.in
@@ -137,7 +137,7 @@ dnl ***************** LARGE FILE SUPPORT ***********************
 AC_SYS_LARGEFILE
 
 dnl ********** Required libraries **********************
-GLIB_REQUIRED=2.22.0
+GLIB_REQUIRED=2.25.10
 GTHREAD_REQUIRED=2.6.0
 GMODULE_REQUIRED=2.6.0
 GMODULE_EXPORT_REQUIRED=2.6.0
@@ -148,7 +148,6 @@ GCONF_REQUIRED=2.31.1
 GSTREAMER_REQUIRED=0.10.15
 GSTREAMER_BASE_REQUIRED=0.10.0
 LIBXML2_REQUIRED=2.6.0
-LIBUNIQUE_REQUIRED=1.0.0
 DBUS_REQUIRED=0.7.2
 CANBERRA_REQUIRED=0.1
 
@@ -177,13 +176,6 @@ PKG_CHECK_MODULES(BRASERO_LIBXML, 	\
 AC_SUBST(BRASERO_LIBXML_CFLAGS)
 AC_SUBST(BRASERO_LIBXML_LIBS)
 
-dnl ** used by brasero
-PKG_CHECK_MODULES(BRASERO_LIBUNIQUE, 	\
-	unique-1.0 >= $LIBUNIQUE_REQUIRED)
-
-AC_SUBST(BRASERO_LIBUNIQUE_CFLAGS)
-AC_SUBST(BRASERO_LIBUNIQUE_LIBS)
-
 dnl ** used by brasero and both libraries
 PKG_CHECK_MODULES(BRASERO_GTHREAD, 		\
 	gthread-2.0 >= $GTHREAD_REQUIRED)
diff --git a/src/Makefile.am b/src/Makefile.am
index 424a21d..44010fb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,11 +20,9 @@ INCLUDES = \
 	$(BRASERO_GSTREAMER_BASE_CFLAGS)				\
 	$(BRASERO_GTK_CFLAGS)						\
 	$(BRASERO_DBUS_CFLAGS)						\
-	$(BRASERO_LIBUNIQUE_CFLAGS)                                     \
 	$(BRASERO_LIBXML_CFLAGS)					\
 	$(BRASERO_SEARCH_CFLAGS)					\
 	$(BRASERO_PL_PARSER_CFLAGS)					\
-	$(BRASERO_LIBUNIQUE_CFLAGS)					\
 	$(BRASERO_SM_CFLAGS)
 
 GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
@@ -122,7 +120,9 @@ brasero_SOURCES = \
 	brasero-drive-settings.h        \
 	brasero-drive-settings.c	\
 	brasero-song-control.h        \
-	brasero-song-control.c
+	brasero-song-control.c        \
+	brasero-cli.c        \
+	brasero-cli.h
 
 if BUILD_PLAYLIST
 brasero_SOURCES += \
@@ -166,11 +166,9 @@ brasero_LDADD =						\
 	$(BRASERO_GTK_LIBS)		\
 	$(BRASERO_GMODULE_LIBS)		\
 	$(BRASERO_DBUS_LIBS)		\
-	$(BRASERO_LIBUNIQUE_LIBS)	\
 	$(BRASERO_LIBXML_LIBS)		\
 	$(BRASERO_SEARCH_LIBS)		\
 	$(BRASERO_PL_PARSER_LIBS)	\
-	$(BRASERO_LIBUNIQUE_LIBS)	\
 	$(BRASERO_SM_LIBS)
 
 EXTRA_DIST =			\
diff --git a/src/brasero-app.c b/src/brasero-app.c
index 0851843..5daebc1 100644
--- a/src/brasero-app.c
+++ b/src/brasero-app.c
@@ -30,8 +30,6 @@
 
 #include <gtk/gtk.h>
 
-#include <unique/unique.h>
-
 #include "brasero-misc.h"
 #include "brasero-io.h"
 
@@ -69,6 +67,8 @@
 typedef struct _BraseroAppPrivate BraseroAppPrivate;
 struct _BraseroAppPrivate
 {
+	GApplication *gapp;
+
 	BraseroSetting *setting;
 
 	GdkWindow *parent;
@@ -100,6 +100,10 @@ struct _BraseroAppPrivate
 
 G_DEFINE_TYPE (BraseroApp, brasero_app, G_TYPE_OBJECT);
 
+enum {
+	PROP_NONE,
+	PROP_GAPP
+};
 
 /**
  * Menus and toolbar
@@ -422,15 +426,6 @@ brasero_app_alert (BraseroApp *app,
 	gtk_widget_destroy (alert);
 }
 
-GtkUIManager *
-brasero_app_get_ui_manager (BraseroApp *app)
-{
-	BraseroAppPrivate *priv;
-
-	priv = BRASERO_APP_PRIVATE (app);
-	return priv->manager;
-}
-
 GtkWidget *
 brasero_app_get_statusbar1 (BraseroApp *app)
 {
@@ -2004,58 +1999,42 @@ brasero_app_create_mainwin (BraseroApp *app)
 	brasero_app_load_window_state (app);
 }
 
-static UniqueResponse
-brasero_app_unique_message (UniqueApp *uapp,
-			    gint command,
-			    UniqueMessageData *message_data,
-			    guint time,
-			    BraseroApp *app)
+static void
+brasero_app_prepare_activation (GApplication *gapp,
+                                GVariant *arguments,
+                                GVariant *platform_data,
+                                BraseroApp *app)
 {
 	BraseroAppPrivate *priv;
 
 	priv = BRASERO_APP_PRIVATE (app);
-	if (command == UNIQUE_ACTIVATE) {
-		if (priv->mainwin_running) {
-			gtk_widget_show (priv->mainwin);
-			gtk_window_present (GTK_WINDOW (priv->mainwin));
-		}
-	}
 
-	return UNIQUE_RESPONSE_OK;
+	/* Except if we are supposed to quit show the window */
+	if (priv->mainwin_running) {
+		gtk_widget_show (priv->mainwin);
+		gtk_window_present (GTK_WINDOW (priv->mainwin));
+	}
 }
 
 gboolean
 brasero_app_run_mainwin (BraseroApp *app)
 {
 	BraseroAppPrivate *priv;
-	UniqueApp *uapp;
 
 	priv = BRASERO_APP_PRIVATE (app);
 
+	if (priv->mainwin_running)
+		return TRUE;
+
 	priv->mainwin_running = 1;
 	gtk_widget_show (GTK_WIDGET (priv->mainwin));
 
-	uapp = unique_app_new ("org.gnome.Brasero", NULL);
-	g_signal_connect (uapp,
-			  "message-received",
-			  G_CALLBACK (brasero_app_unique_message),
-			  app);
-
-	if (unique_app_is_running (uapp))
-	{
-		UniqueResponse response;
-
-		response = unique_app_send_message (uapp, UNIQUE_ACTIVATE, NULL);
-    		g_object_unref (uapp);
-		uapp = NULL;
-
-		/* FIXME: we should tell the user why it did not work. Or is it
-		 * handled by libunique? */
-		return (response == UNIQUE_RESPONSE_OK);
-	}
-
+	if (priv->gapp)
+		g_signal_connect (priv->gapp,
+				  "prepare-activation",
+				  G_CALLBACK (brasero_app_prepare_activation),
+				  app);
 	gtk_main ();
-
 	return TRUE;
 }
 
@@ -2119,6 +2098,51 @@ brasero_app_finalize (GObject *object)
 
 	G_OBJECT_CLASS (brasero_app_parent_class)->finalize (object);
 }
+static void
+brasero_app_set_property (GObject *object,
+                          guint prop_id,
+                          const GValue *value,
+                          GParamSpec *pspec)
+{
+	BraseroAppPrivate *priv;
+
+	g_return_if_fail (BRASERO_IS_APP (object));
+
+	priv = BRASERO_APP_PRIVATE (object);
+
+	switch (prop_id)
+	{
+	case PROP_GAPP:
+		priv->gapp = g_value_dup_object (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+brasero_app_get_property (GObject *object,
+			  guint prop_id,
+			  GValue *value,
+			  GParamSpec *pspec)
+{
+	BraseroAppPrivate *priv;
+
+	g_return_if_fail (BRASERO_IS_APP (object));
+
+	priv = BRASERO_APP_PRIVATE (object);
+
+	switch (prop_id)
+	{
+	case PROP_GAPP:
+		g_value_set_object (value, priv->gapp);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
 
 static void
 brasero_app_class_init (BraseroAppClass *klass)
@@ -2128,10 +2152,22 @@ brasero_app_class_init (BraseroAppClass *klass)
 	g_type_class_add_private (klass, sizeof (BraseroAppPrivate));
 
 	object_class->finalize = brasero_app_finalize;
+	object_class->set_property = brasero_app_set_property;
+	object_class->get_property = brasero_app_get_property;
+
+	g_object_class_install_property (object_class,
+	                                 PROP_GAPP,
+	                                 g_param_spec_object("gapp",
+	                                                     "GApplication",
+	                                                     "The GApplication object",
+	                                                     G_TYPE_APPLICATION,
+	                                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
 BraseroApp *
-brasero_app_new (void)
+brasero_app_new (GApplication *gapp)
 {
-	return g_object_new (BRASERO_TYPE_APP, NULL);
+	return g_object_new (BRASERO_TYPE_APP,
+	                     "gapp", gapp,
+	                     NULL);
 }
diff --git a/src/brasero-app.h b/src/brasero-app.h
index 383dc9a..c89f929 100644
--- a/src/brasero-app.h
+++ b/src/brasero-app.h
@@ -53,7 +53,7 @@ struct _BraseroApp
 GType brasero_app_get_type (void) G_GNUC_CONST;
 
 BraseroApp *
-brasero_app_new (void);
+brasero_app_new (GApplication *gapp);
 
 BraseroApp *
 brasero_app_get_default (void);
@@ -157,9 +157,6 @@ brasero_app_get_statusbar1 (BraseroApp *app);
 GtkWidget *
 brasero_app_get_statusbar2 (BraseroApp *app);
 
-GtkUIManager *
-brasero_app_get_ui_manager (BraseroApp *app);
-
 GtkWidget *
 brasero_app_get_project_manager (BraseroApp *app);
 
@@ -175,8 +172,6 @@ brasero_app_get_saved_contents (BraseroApp *app);
 gboolean
 brasero_app_save_contents (BraseroApp *app,
 			   gboolean cancellable);
-void
-brasero_app_save_window_state (BraseroApp *app);
 
 G_END_DECLS
 
diff --git a/src/brasero-cli.c b/src/brasero-cli.c
new file mode 100644
index 0000000..edfaad4
--- /dev/null
+++ b/src/brasero-cli.c
@@ -0,0 +1,417 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Brasero
+ * Copyright (C) Philippe Rouquier 2005-2010 <bonfire-app wanadoo fr>
+ * 
+ *  Brasero 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.
+ * 
+ * brasero 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 brasero.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib/gi18n-lib.h>
+
+#include "brasero-cli.h"
+#include "brasero-app.h"
+#include "brasero-project-manager.h"
+
+#include "brasero-burn-lib.h"
+
+#include "brasero-medium-monitor.h"
+#include "brasero-medium.h"
+
+#include "brasero-misc.h"
+
+
+BraseroCLI cmd_line_options;
+
+static gboolean
+brasero_cli_copy_project (const gchar *option_name,
+                          const gchar *value,
+                          gpointer data,
+                          GError **error);
+static gboolean
+brasero_cli_image_project (const gchar *option_name,
+                           const gchar *value,
+                           gpointer data,
+                           GError **error);
+
+static gboolean
+brasero_cli_fake_device (const gchar *option_name,
+                         const gchar *value,
+                         gpointer data,
+                         GError **error);
+
+static gboolean
+brasero_cli_burning_device (const gchar *option_name,
+                            const gchar *value,
+                            gpointer data,
+                            GError **error);
+
+const GOptionEntry prog_options [] = {
+	{ "project", 'p', 0, G_OPTION_ARG_FILENAME, &cmd_line_options.project_uri,
+	  N_("Open the specified project"),
+	  N_("PROJECT") },
+
+#ifdef BUILD_PLAYLIST
+
+	 { "playlist", 'l', 0, G_OPTION_ARG_FILENAME, &cmd_line_options.playlist_uri,
+	  N_("Open the specified playlist as an audio project"),
+	  N_("PLAYLIST") },
+
+#endif
+
+	{ "device", 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, brasero_cli_burning_device,
+	  N_("Set the drive to be used for burning"),
+	  N_("DEVICE PATH") },
+
+	{ "image-file", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, brasero_cli_fake_device,
+	  N_("Create an image file instead of burning"),
+	  NULL },
+
+	{ "audio", 'a', 0, G_OPTION_ARG_NONE, &cmd_line_options.audio_project,
+	  N_("Open an audio project adding the URIs given on the command line"),
+	  NULL },
+
+	{ "data", 'd', 0, G_OPTION_ARG_NONE, &cmd_line_options.data_project,
+         N_("Open a data project adding the URIs given on the command line"),
+          NULL },
+
+	{ "copy", 'c', G_OPTION_FLAG_OPTIONAL_ARG|G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, brasero_cli_copy_project,
+	  N_("Copy a disc"),
+	  N_("PATH TO DEVICE") },
+
+	{ "cover", 'j', 0, G_OPTION_ARG_FILENAME, &cmd_line_options.cover_project,
+	  N_("Cover to use"),
+	  N_("PATH TO COVER") },
+
+	{ "video", 'o', 0, G_OPTION_ARG_NONE, &cmd_line_options.video_project,
+	  N_("Open a video project adding the URIs given on the command line"),
+	  NULL },
+
+	{ "image", 'i', G_OPTION_FLAG_OPTIONAL_ARG|G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, brasero_cli_image_project,
+	 N_("URI of an image file to burn (autodetected)"),
+          N_("PATH TO IMAGE") },
+
+    	{ "empty", 'e', 0, G_OPTION_ARG_NONE, &cmd_line_options.empty_project,
+         N_("Force Brasero to display the project selection page"),
+          NULL },
+
+	{ "blank", 'b', 0, G_OPTION_ARG_NONE, &cmd_line_options.disc_blank,
+	  N_("Open the blank disc dialog"),
+	  N_("PATH TO DEVICE") },
+
+	{ "check", 'k', 0, G_OPTION_ARG_NONE, &cmd_line_options.disc_check,
+	  N_("Open the check disc dialog"),
+	  N_("PATH TO DEVICE") },
+
+	{ "ncb", 'n', 0, G_OPTION_ARG_NONE, &cmd_line_options.open_ncb,
+	  N_("Burn the contents of the burn:// URI"),
+	  NULL },
+
+	{ "immediately", 0, 0, G_OPTION_ARG_NONE, &cmd_line_options.burn_immediately,
+	  N_("Start burning immediately."),
+	  NULL },
+
+	 { "no-existing-session", 0, 0, G_OPTION_ARG_NONE, &cmd_line_options.not_unique,
+	  N_("Don't connect to an already-running instance"),
+	  NULL },
+
+	{ "burn-and-remove-project", 'r', 0, G_OPTION_ARG_FILENAME, &cmd_line_options.burn_project_uri,
+	  N_("Burn the specified project and remove it.\nThis option is mainly useful for integration with other applications."),
+	  N_("PATH") },
+
+	{ "transient-for", 'x', 0, G_OPTION_ARG_INT, &cmd_line_options.parent_window,
+	/* Translators: the xid is a number identifying each window in the X11
+	 * world (not Windows, MacOS X). The following sentence says that
+	 * brasero will be set to be always on top of the window identified by
+	 * xid. In other words, the window with the given xid will become brasero
+	 * parent as if brasero was a dialog for the parent application */
+	  N_("The XID of the parent window"), NULL },
+
+	{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &cmd_line_options.files,
+	  NULL, NULL }, /* collects file arguments */
+
+	{ NULL }
+};
+
+static gboolean
+brasero_cli_fake_device (const gchar *option_name,
+                         const gchar *value,
+                         gpointer data,
+                         GError **error)
+{
+	BraseroMediumMonitor *monitor;
+	GSList *list;
+
+	/* Wait for the libbrasero-media to be ready */
+	monitor = brasero_medium_monitor_get_default ();
+	while (brasero_medium_monitor_is_probing (monitor))
+		sleep (1);
+
+	list = brasero_medium_monitor_get_drives (monitor, BRASERO_DRIVE_TYPE_FILE);
+	if (!list)
+		return FALSE;
+
+	cmd_line_options.burner = list->data;
+	g_slist_free (list);
+
+	return TRUE;
+}
+
+static gboolean
+brasero_cli_burning_device (const gchar *option_name,
+                            const gchar *value,
+                            gpointer data,
+                            GError **error)
+{
+	BraseroDrive *burner;
+	BraseroMediumMonitor *monitor;
+
+	if (!value)
+		return FALSE;
+
+	/* Wait for the libbrasero-media to be ready */
+	monitor = brasero_medium_monitor_get_default ();
+	while (brasero_medium_monitor_is_probing (monitor))
+		sleep (1);
+
+	burner = brasero_medium_monitor_get_drive (monitor, value);
+	g_object_unref (monitor);
+
+	if (burner) {
+		if (!brasero_drive_can_write (burner)) {
+			gchar *string;
+
+			/* Translators: %s is the path of drive */
+			string = g_strdup_printf (_("\"%s\" cannot write."), value);
+			brasero_utils_message_dialog (NULL,
+						      _("Wrong command line option."),
+						      string,
+						      GTK_MESSAGE_ERROR);
+
+			g_object_unref (burner);
+			return FALSE;
+		}
+	}
+	else {
+		gchar *string;
+
+		/* Translators: %s is the path of a drive */
+		string = g_strdup_printf (_("\"%s\" cannot be found."), value);
+		brasero_utils_message_dialog (NULL,
+					      _("Wrong command line option."),
+					      string,
+					      GTK_MESSAGE_ERROR);
+		g_free (string);
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static gboolean
+brasero_cli_copy_project (const gchar *option_name,
+                          const gchar *value,
+                          gpointer data,
+                          GError **error)
+{
+	cmd_line_options.copy_project = TRUE;
+	cmd_line_options.copy_project_path = g_strdup (value);
+
+	return TRUE;
+}
+
+static gboolean
+brasero_cli_image_project (const gchar *option_name,
+                           const gchar *value,
+                           gpointer data,
+                           GError **error)
+{
+	cmd_line_options.image_project = TRUE;
+	cmd_line_options.image_project_uri = g_strdup (value);
+
+	return TRUE;
+}
+
+void
+brasero_cli_apply_options (BraseroApp *app)
+{
+	gint nb = 0;
+	GtkWidget *manager = NULL;
+
+	if (cmd_line_options.parent_window)
+		brasero_app_set_parent (app, cmd_line_options.parent_window);
+
+    	if (cmd_line_options.empty_project) {
+	    	brasero_app_create_mainwin (app);
+		manager = brasero_app_get_project_manager (app);
+		brasero_project_manager_empty (BRASERO_PROJECT_MANAGER (manager));
+		brasero_app_run_mainwin (app);
+		return;
+	}
+
+	/* we first check that only one of the options was given
+	 * (except for --debug, cover argument and device) */
+	if (cmd_line_options.copy_project)
+		nb ++;
+	if (cmd_line_options.image_project)
+		nb ++;
+	if (cmd_line_options.project_uri)
+		nb ++;
+	if (cmd_line_options.burn_project_uri)
+		nb ++;
+	if (cmd_line_options.playlist_uri)
+		nb ++;
+	if (cmd_line_options.audio_project)
+		nb ++;
+	if (cmd_line_options.data_project)
+		nb ++;
+	if (cmd_line_options.video_project)
+	    	nb ++;
+	if (cmd_line_options.disc_blank)
+	  	nb ++;
+	if (cmd_line_options.open_ncb)
+		nb ++;
+
+	if (nb > 1) {
+		brasero_app_create_mainwin (app);
+		brasero_app_alert (app,
+				   _("Incompatible command line options used."),
+				   _("Only one option can be given at a time"),
+				   GTK_MESSAGE_ERROR);
+
+		manager = brasero_app_get_project_manager (app);
+		brasero_project_manager_empty (BRASERO_PROJECT_MANAGER (manager));
+	}
+	else if (cmd_line_options.project_uri) {
+		brasero_app_open_project (app,
+					  cmd_line_options.burner,
+					  cmd_line_options.project_uri,
+					  FALSE,
+					  TRUE,
+					  cmd_line_options.burn_immediately != 0);
+		if (cmd_line_options.burn_immediately)
+			return;
+	}
+	else if (cmd_line_options.burn_project_uri) {
+		brasero_app_open_project (app,
+					  cmd_line_options.burner,
+					  cmd_line_options.burn_project_uri,
+					  FALSE,
+					  TRUE,
+					  cmd_line_options.burn_immediately != 0 /* This is to keep the current behavior which is open main window */);
+		if (g_remove (cmd_line_options.burn_project_uri) != 0) {
+			gchar *path;
+
+			path = g_filename_from_uri (cmd_line_options.burn_project_uri, NULL, NULL);
+			g_remove (path);
+			g_free (path);
+		}
+		return;
+	}
+
+#ifdef BUILD_PLAYLIST
+
+	else if (cmd_line_options.playlist_uri) {
+		brasero_app_open_project (app,
+					  cmd_line_options.burner,
+					  cmd_line_options.playlist_uri,
+					  TRUE,
+					  TRUE,
+					  cmd_line_options.burn_immediately != 0);
+		if (cmd_line_options.burn_immediately)
+			return;
+	}
+
+#endif
+	else if (cmd_line_options.copy_project) {
+		brasero_app_copy_disc (app,
+				       cmd_line_options.burner,
+				       cmd_line_options.copy_project_path,
+				       cmd_line_options.cover_project,
+				       cmd_line_options.burn_immediately != 0);
+		return;
+	}
+	else if (cmd_line_options.image_project) {
+		brasero_app_image (app,
+				   cmd_line_options.burner,
+				   cmd_line_options.image_project_uri,
+				   cmd_line_options.burn_immediately != 0);
+		return;
+	}
+	else if (cmd_line_options.open_ncb) {
+		brasero_app_burn_uri (app, cmd_line_options.burner, cmd_line_options.burn_immediately != 0);
+		return;
+	}
+	else if (cmd_line_options.disc_blank) {
+		brasero_app_blank (app, cmd_line_options.burner, cmd_line_options.burn_immediately != 0);
+		return;
+	}
+	else if (cmd_line_options.disc_check) {
+		brasero_app_check (app, cmd_line_options.burner, cmd_line_options.burn_immediately != 0);
+		return;
+	}
+	else if (cmd_line_options.audio_project) {
+		brasero_app_stream (app, cmd_line_options.burner, cmd_line_options.files, FALSE, cmd_line_options.burn_immediately != 0);
+		if (cmd_line_options.burn_immediately)
+			return;
+	}
+	else if (cmd_line_options.data_project) {
+		brasero_app_data (app, cmd_line_options.burner, cmd_line_options.files, cmd_line_options.burn_immediately != 0);
+		if (cmd_line_options.burn_immediately)
+			return;
+	}
+	else if (cmd_line_options.video_project) {
+		brasero_app_stream (app, cmd_line_options.burner, cmd_line_options.files, TRUE, cmd_line_options.burn_immediately != 0);
+		if (cmd_line_options.burn_immediately)
+			return;
+	}
+	else if (cmd_line_options.files) {
+		if (g_strv_length (cmd_line_options.files) == 1) {
+			gboolean result;
+
+			result = brasero_app_open_uri_drive_detection (app,
+			                                               cmd_line_options.burner,
+			                                               cmd_line_options.files [0],
+			                                               cmd_line_options.cover_project,
+			                                               cmd_line_options.burn_immediately);
+			/* Return here if the URI was related to a disc operation */
+			if (result)
+				return;
+
+			result = brasero_app_open_uri (app, cmd_line_options.files [0], FALSE);
+			if (!result)
+				brasero_app_data (app, cmd_line_options.burner, cmd_line_options.files, cmd_line_options.burn_immediately != 0);
+		}
+		else
+			brasero_app_data (app, cmd_line_options.burner, cmd_line_options.files, cmd_line_options.burn_immediately != 0);
+
+		if (cmd_line_options.burn_immediately)
+			return;
+	}
+	else {
+		brasero_app_create_mainwin (app);
+		manager = brasero_app_get_project_manager (app);
+		brasero_project_manager_empty (BRASERO_PROJECT_MANAGER (manager));
+	}
+
+	brasero_app_run_mainwin (app);
+}
diff --git a/src/brasero-cli.h b/src/brasero-cli.h
new file mode 100644
index 0000000..22dc040
--- /dev/null
+++ b/src/brasero-cli.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Brasero
+ * Copyright (C) Philippe Rouquier 2005-2010 <bonfire-app wanadoo fr>
+ * 
+ *  Brasero 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.
+ * 
+ * brasero 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 brasero.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#ifndef _BRASERO_CLI_H_
+#define _BRASERO_CLI_H_
+
+#include <glib.h>
+
+#include "brasero-app.h"
+#include "brasero-drive.h"
+
+G_BEGIN_DECLS
+
+struct _BraseroCLI {
+	gchar *burn_project_uri;
+	gchar *project_uri;
+	gchar *cover_project;
+	gchar *playlist_uri;
+	gchar *copy_project_path;
+	gchar *image_project_uri;
+
+	gint audio_project;
+	gint data_project;
+	gint video_project;
+	gint empty_project;
+	gint open_ncb;
+
+	gint disc_blank;
+	gint disc_check;
+
+	gint parent_window;
+	gint burn_immediately;
+
+	gboolean image_project;
+	gboolean copy_project;
+	gboolean not_unique;
+
+	BraseroDrive *burner;
+
+	gchar **files;
+};
+typedef struct _BraseroCLI BraseroCLI;
+
+extern BraseroCLI cmd_line_options;
+extern const GOptionEntry prog_options [];
+
+void
+brasero_cli_apply_options (BraseroApp *app);
+
+G_END_DECLS
+
+#endif
\ No newline at end of file
diff --git a/src/main.c b/src/main.c
index d9f9248..ac630a6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,422 +33,20 @@
 #include <locale.h>
 
 #include <glib.h>
-#include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
-#include <gio/gio.h>
-
 #include <gtk/gtk.h>
 
 #include <gst/gst.h>
-#include <gst/pbutils/pbutils.h>
-
-#include "brasero-medium-monitor.h"
 
-#include "brasero-project-manager.h"
-#include "brasero-multi-dnd.h"
-#include "brasero-utils.h"
-#include "brasero-misc.h"
-#include "brasero-app.h"
-
-#include "brasero-burn-lib.h"
-#include "brasero-session.h"
 
 #include "eggsmclient.h"
 
-BraseroDrive *burner = NULL;
-
-gchar *burn_project_uri;
-gchar *project_uri;
-gchar *cover_project;
-gchar *playlist_uri;
-gchar *copy_project_path;
-gchar *image_project_uri;
-
-gchar **files;
-
-gint audio_project;
-gint data_project;
-gint video_project;
-gint empty_project;
-gint open_ncb;
-gint parent_window;
-gint burn_immediately;
-gint disc_blank;
-gint disc_check;
-
-gboolean copy_project;
-gboolean image_project;
-
-static gboolean
-brasero_main_copy_project (const gchar *option_name,
-                           const gchar *value,
-                           gpointer data,
-                           GError **error);
-static gboolean
-brasero_main_image_project (const gchar *option_name,
-   			    const gchar *value,
-                            gpointer data,
-                            GError **error);
-
-static gboolean
-brasero_main_fake_device (const gchar *option_name,
-			  const gchar *value,
-			  gpointer data,
-			  GError **error);
-
-static gboolean
-brasero_main_burning_device (const gchar *option_name,
-			     const gchar *value,
-			     gpointer data,
-			     GError **error);
-
-static const GOptionEntry options [] = {
-	{ "project", 'p', 0, G_OPTION_ARG_FILENAME, &project_uri,
-	  N_("Open the specified project"),
-	  N_("PROJECT") },
-
-#ifdef BUILD_PLAYLIST
-
-	 { "playlist", 'l', 0, G_OPTION_ARG_FILENAME, &playlist_uri,
-	  N_("Open the specified playlist as an audio project"),
-	  N_("PLAYLIST") },
-
-#endif
-
-	{ "device", 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, brasero_main_burning_device,
-	  N_("Set the drive to be used for burning"),
-	  N_("DEVICE PATH") },
-
-	{ "image-file", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, brasero_main_fake_device,
-	  N_("Create an image file instead of burning"),
-	  NULL },
-
-	{ "audio", 'a', 0, G_OPTION_ARG_NONE, &audio_project,
-	  N_("Open an audio project adding the URIs given on the command line"),
-	  NULL },
-
-	{ "data", 'd', 0, G_OPTION_ARG_NONE, &data_project,
-         N_("Open a data project adding the URIs given on the command line"),
-          NULL },
-
-	{ "copy", 'c', G_OPTION_FLAG_OPTIONAL_ARG|G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, brasero_main_copy_project,
-	  N_("Copy a disc"),
-	  N_("PATH TO DEVICE") },
-
-	{ "cover", 'j', 0, G_OPTION_ARG_FILENAME, &cover_project,
-	  N_("Cover to use"),
-	  N_("PATH TO COVER") },
-
-	{ "video", 'o', 0, G_OPTION_ARG_NONE, &video_project,
-	  N_("Open a video project adding the URIs given on the command line"),
-	  NULL },
-
-	{ "image", 'i', G_OPTION_FLAG_OPTIONAL_ARG|G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, brasero_main_image_project,
-	 N_("URI of an image file to burn (autodetected)"),
-          N_("PATH TO IMAGE") },
-
-    	{ "empty", 'e', 0, G_OPTION_ARG_NONE, &empty_project,
-         N_("Force Brasero to display the project selection page"),
-          NULL },
-
-	{ "blank", 'b', 0, G_OPTION_ARG_NONE, &disc_blank,
-	  N_("Open the blank disc dialog"),
-	  N_("PATH TO DEVICE") },
-
-	{ "check", 'k', 0, G_OPTION_ARG_NONE, &disc_check,
-	  N_("Open the check disc dialog"),
-	  N_("PATH TO DEVICE") },
-
-	{ "ncb", 'n', 0, G_OPTION_ARG_NONE, &open_ncb,
-	  N_("Burn the contents of the burn:// URI"),
-	  NULL },
-
-	{ "immediately", 0, 0, G_OPTION_ARG_NONE, &burn_immediately,
-	  N_("Start burning immediately."),
-	  NULL },
-
-	{ "burn-and-remove-project", 'r', 0, G_OPTION_ARG_FILENAME, &burn_project_uri,
-	  N_("Burn the specified project and remove it.\nThis option is mainly useful for integration with other applications."),
-	  N_("PATH") },
-
-	{ "transient-for", 'x', 0, G_OPTION_ARG_INT, &parent_window,
-	/* Translators: the xid is a number identifying each window in the X11
-	 * world (not Windows, MacOS X). The following sentence says that
-	 * brasero will be set to be always on top of the window identified by
-	 * xid. In other word, the window with the given xid will become brasero
-	 * parent as if brasero was a dialog for the parent application */
-	  N_("The XID of the parent window"), NULL },
-
-	{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
-	  NULL, NULL }, /* collects file arguments */
-
-	{ NULL }
-};
-
-static gboolean
-brasero_main_fake_device (const gchar *option_name,
-                          const gchar *value,
-                          gpointer data,
-                          GError **error)
-{
-	BraseroMediumMonitor *monitor;
-	GSList *list;
-
-	/* Wait for the libbrasero-media to be ready */
-	monitor = brasero_medium_monitor_get_default ();
-	while (brasero_medium_monitor_is_probing (monitor))
-		sleep (1);
-
-	list = brasero_medium_monitor_get_drives (monitor, BRASERO_DRIVE_TYPE_FILE);
-	if (!list)
-		return FALSE;
-
-	burner = list->data;
-	g_slist_free (list);
-
-	return TRUE;
-}
-
-static gboolean
-brasero_main_burning_device (const gchar *option_name,
-			     const gchar *value,
-			     gpointer data,
-			     GError **error)
-{
-	BraseroDrive *burner;
-	BraseroMediumMonitor *monitor;
-
-	if (!value)
-		return FALSE;
-
-	/* Wait for the libbrasero-media to be ready */
-	monitor = brasero_medium_monitor_get_default ();
-	while (brasero_medium_monitor_is_probing (monitor))
-		sleep (1);
-
-	burner = brasero_medium_monitor_get_drive (monitor, value);
-	g_object_unref (monitor);
-
-	if (burner) {
-		if (!brasero_drive_can_write (burner)) {
-			gchar *string;
-
-			/* Translators: %s is the path of drive */
-			string = g_strdup_printf (_("\"%s\" cannot write."), value);
-			brasero_utils_message_dialog (NULL,
-						      _("Wrong command line option."),
-						      string,
-						      GTK_MESSAGE_ERROR);
-
-			g_object_unref (burner);
-			return FALSE;
-		}
-	}
-	else {
-		gchar *string;
-
-		/* Translators: %s is the path of a drive */
-		string = g_strdup_printf (_("\"%s\" cannot be found."), value);
-		brasero_utils_message_dialog (NULL,
-					      _("Wrong command line option."),
-					      string,
-					      GTK_MESSAGE_ERROR);
-		g_free (string);
-		return FALSE;
-	}
-
-	return TRUE;
-}
-
-static gboolean
-brasero_main_copy_project (const gchar *option_name,
-                           const gchar *value,
-                           gpointer data,
-                           GError **error)
-{
-	copy_project = TRUE;
-	copy_project_path = g_strdup (value);
-
-	return TRUE;
-}
-
-static gboolean
-brasero_main_image_project (const gchar *option_name,
-			    const gchar *value,
-        		    gpointer data,
-	                    GError **error)
-{
-	image_project = TRUE;
-	image_project_uri = g_strdup (value);
-
-	return TRUE;
-}
-
-static void
-brasero_app_parse_options (BraseroApp *app)
-{
-	gint nb = 0;
-	GtkWidget *manager = NULL;
-
-	if (parent_window)
-		brasero_app_set_parent (app, parent_window);
-
-    	if (empty_project) {
-	    	brasero_app_create_mainwin (app);
-		manager = brasero_app_get_project_manager (app);
-		brasero_project_manager_empty (BRASERO_PROJECT_MANAGER (manager));
-		brasero_app_run_mainwin (app);
-		return;
-	}
-
-	/* we first check that only one of the options was given
-	 * (except for --debug, cover argument and device) */
-	if (copy_project)
-		nb ++;
-	if (image_project)
-		nb ++;
-	if (project_uri)
-		nb ++;
-	if (burn_project_uri)
-		nb ++;
-	if (playlist_uri)
-		nb ++;
-	if (audio_project)
-		nb ++;
-	if (data_project)
-		nb ++;
-	if (video_project)
-	    	nb ++;
-	if (disc_blank)
-	  	nb ++;
-	if (open_ncb)
-		nb ++;
-
-	if (nb > 1) {
-		brasero_app_create_mainwin (app);
-		brasero_app_alert (app,
-				   _("Incompatible command line options used."),
-				   _("Only one option can be given at a time"),
-				   GTK_MESSAGE_ERROR);
-
-		manager = brasero_app_get_project_manager (app);
-		brasero_project_manager_empty (BRASERO_PROJECT_MANAGER (manager));
-	}
-	else if (project_uri) {
-		brasero_app_open_project (app,
-					  burner,
-					  project_uri,
-					  FALSE,
-					  TRUE,
-					  burn_immediately != 0);
-		if (burn_immediately)
-			return;
-	}
-	else if (burn_project_uri) {
-		brasero_app_open_project (app,
-					  burner,
-					  burn_project_uri,
-					  FALSE,
-					  TRUE,
-					  burn_immediately != 0 /* This is to keep the current behavior which is open main window */);
-		if (g_remove (burn_project_uri) != 0) {
-			gchar *path;
-
-			path = g_filename_from_uri (burn_project_uri, NULL, NULL);
-			g_remove (path);
-			g_free (path);
-		}
-		return;
-	}
-
-#ifdef BUILD_PLAYLIST
-
-	else if (playlist_uri) {
-		brasero_app_open_project (app,
-					  burner,
-					  playlist_uri,
-					  TRUE,
-					  TRUE,
-					  burn_immediately != 0);
-		if (burn_immediately)
-			return;
-	}
-
-#endif
-	else if (copy_project) {
-		brasero_app_copy_disc (app,
-				       burner,
-				       copy_project_path,
-				       cover_project,
-				       burn_immediately != 0);
-		return;
-	}
-	else if (image_project) {
-		brasero_app_image (app,
-				   burner,
-				   image_project_uri,
-				   burn_immediately != 0);
-		return;
-	}
-	else if (open_ncb) {
-		brasero_app_burn_uri (app, burner, burn_immediately != 0);
-		return;
-	}
-	else if (disc_blank) {
-		brasero_app_blank (app, burner, burn_immediately != 0);
-		return;
-	}
-	else if (disc_check) {
-		brasero_app_check (app, burner, burn_immediately != 0);
-		return;
-	}
-	else if (audio_project) {
-		brasero_app_stream (app, burner, files, FALSE, burn_immediately != 0);
-		if (burn_immediately)
-			return;
-	}
-	else if (data_project) {
-		brasero_app_data (app, burner, files, burn_immediately != 0);
-		if (burn_immediately)
-			return;
-	}
-	else if (video_project) {
-		brasero_app_stream (app, burner, files, TRUE, burn_immediately != 0);
-		if (burn_immediately)
-			return;
-	}
-	else if (files) {
-		if (g_strv_length (files) == 1) {
-			gboolean result;
-
-			result = brasero_app_open_uri_drive_detection (app,
-			                                               burner,
-			                                               files [0],
-			                                               cover_project,
-			                                               burn_immediately);
-			/* Return here if the URI was related to a disc operation */
-			if (result)
-				return;
-
-			result = brasero_app_open_uri (app, files [0], FALSE);
-			if (!result)
-				brasero_app_data (app, burner, files, burn_immediately != 0);
-		}
-		else
-			brasero_app_data (app, burner, files, burn_immediately != 0);
-
-		if (burn_immediately)
-			return;
-	}
-	else {
-		brasero_app_create_mainwin (app);
-		manager = brasero_app_get_project_manager (app);
-		brasero_project_manager_empty (BRASERO_PROJECT_MANAGER (manager));
-	}
+#include "brasero-burn-lib.h"
 
-	brasero_app_run_mainwin (app);
-}
+#include "brasero-multi-dnd.h"
+#include "brasero-app.h"
+#include "brasero-cli.h"
 
 static BraseroApp *current_app = NULL;
 
@@ -465,6 +63,7 @@ brasero_app_get_default (void)
 int
 main (int argc, char **argv)
 {
+	GApplication *gapp;
 	GOptionContext *context;
 
 	g_setenv ("GSETTINGS_BACKEND", "gconf", FALSE);
@@ -476,11 +75,12 @@ main (int argc, char **argv)
 #endif
 
 	g_thread_init (NULL);
-	g_type_init ();
+
+	memset (&cmd_line_options, 0, sizeof (cmd_line_options));
 
 	context = g_option_context_new (_("[URI] [URI] â?¦"));
 	g_option_context_add_main_entries (context,
-					   options,
+					   prog_options,
 					   GETTEXT_PACKAGE);
 	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
 
@@ -492,19 +92,25 @@ main (int argc, char **argv)
 	if (g_option_context_parse (context, &argc, &argv, NULL) == FALSE) {
 		g_print (_("Please type \"%s --help\" to see all available options\n"), argv [0]);
 		g_option_context_free (context);
-		exit (1);
+		return FALSE;
 	}
 	g_option_context_free (context);
 
-	brasero_burn_library_start (&argc, &argv);
+	if (cmd_line_options.not_unique == FALSE) {
+		/* Create GApplication and check if there is a process running already */
+		gapp = g_application_new ("org.gnome.Brasero", argc, argv);
+		if (g_application_is_remote (gapp))
+			return 0;
+	}
 
+	brasero_burn_library_start (&argc, &argv);
 	brasero_enable_multi_DND ();
 
-	current_app = brasero_app_new ();
+	current_app = brasero_app_new (gapp);
 	if (current_app == NULL)
 		return 1;
 
-	brasero_app_parse_options (current_app);
+	brasero_cli_apply_options (current_app);
 
 	g_object_unref (current_app);
 	current_app = NULL;



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