[gnome-bluetooth] Add a quit menu item in debug mode



commit 6651a171d9648eefb119b568f132c7e183e94ef6
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Apr 24 20:57:07 2009 +0100

    Add a quit menu item in debug mode
    
    Add a quit menu item when --debug is passed to the applet,
    to make valgrind debugging easier.
---
 applet/main.c        |   49 ++++++++++++++++++++++++++++++++++++-------------
 applet/popup-menu.ui |   10 ++++++++++
 2 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/applet/main.c b/applet/main.c
index ae443d1..9a93bfb 100644
--- a/applet/main.c
+++ b/applet/main.c
@@ -39,6 +39,7 @@
 #include "notify.h"
 #include "agent.h"
 
+static gboolean option_debug = FALSE;
 static BluetoothClient *client;
 static GtkTreeModel *devices_model;
 static guint num_adapters_present = 0;
@@ -63,6 +64,7 @@ static GtkActionGroup *devices_action_group = NULL;
 
 /* Signal callbacks */
 void settings_callback(GObject *widget, gpointer user_data);
+void quit_callback(GObject *widget, gpointer user_data);
 void browse_callback(GObject *widget, gpointer user_data);
 void bluetooth_status_callback (GObject *widget, gpointer user_data);
 void wizard_callback(GObject *widget, gpointer user_data);
@@ -70,6 +72,11 @@ void sendto_callback(GObject *widget, gpointer user_data);
 
 static void action_set_bold (GtkUIManager *manager, GtkAction *action, const char *path);
 
+void quit_callback(GObject *widget, gpointer user_data)
+{
+	gtk_main_quit ();
+}
+
 void settings_callback(GObject *widget, gpointer user_data)
 {
 	const char *command = "bluetooth-properties";
@@ -262,6 +269,12 @@ static GtkWidget *create_popupmenu(void)
 		object = gtk_builder_get_object (xml, "killswitch-label");
 		gtk_action_set_visible (GTK_ACTION (object), TRUE);
 	}
+	if (option_debug != FALSE) {
+		GObject *object;
+
+		object = gtk_builder_get_object (xml, "quit");
+		gtk_action_set_visible (GTK_ACTION (object), TRUE);
+	}
 
 	object = gtk_builder_get_object (xml, "bluetooth-applet-ui-manager");
 	devices_action_group = gtk_action_group_new ("devices-action-group");
@@ -711,6 +724,7 @@ static void gconf_callback(GConfClient *client, guint cnxn_id,
 }
 
 static GOptionEntry options[] = {
+	{ "debug", 'd', 0, G_OPTION_ARG_NONE, &option_debug, N_("Debug"), NULL },
 	{ NULL },
 };
 
@@ -720,27 +734,35 @@ int main(int argc, char *argv[])
 	GtkStatusIcon *statusicon;
 	GtkWidget *menu;
 	GConfValue *value;
+	GOptionContext *context;
 	GError *error = NULL;
 
 	bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
 	textdomain(GETTEXT_PACKAGE);
 
-	if (gtk_init_with_args(&argc, &argv, NULL,
-				options, GETTEXT_PACKAGE, &error) == FALSE) {
-		if (error) {
-			g_print("%s\n", error->message);
-			g_error_free(error);
-		} else
-			g_print("An unknown error occurred\n");
-
+	g_type_init ();
+
+	/* Parse command-line options */
+	context = g_option_context_new (N_("- Bluetooth applet"));
+	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
+	if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
+		g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"),
+			 error->message, argv[0]);
+		g_error_free (error);
 		return 1;
 	}
 
-	app = unique_app_new ("org.gnome.Bluetooth.applet", NULL);
-	if (unique_app_is_running (app)) {
-		g_warning ("Applet is already running, exiting");
-		return 0;
+	if (option_debug == FALSE) {
+		app = unique_app_new ("org.gnome.Bluetooth.applet", NULL);
+		if (unique_app_is_running (app)) {
+			g_warning ("Applet is already running, exiting");
+			return 0;
+		}
+	} else {
+		app = NULL;
 	}
 
 	g_set_application_name(_("Bluetooth Applet"));
@@ -811,7 +833,8 @@ int main(int argc, char *argv[])
 
 	g_object_unref(client);
 
-	g_object_unref (app);
+	if (app != NULL)
+		g_object_unref (app);
 
 	return 0;
 }
diff --git a/applet/popup-menu.ui b/applet/popup-menu.ui
index 036f55b..0060ae4 100644
--- a/applet/popup-menu.ui
+++ b/applet/popup-menu.ui
@@ -53,6 +53,14 @@
 						<signal name="activate" handler="settings_callback"/>
 					</object>
 				</child>
+				<child>
+					<object class="GtkAction" id="quit">
+						<property name="label" translatable="yes">Quit</property>
+						<property name="stock-id">gtk-quit</property>
+						<property name="visible">false</property>
+						<signal name="activate" handler="quit_callback"/>
+					</object>
+				</child>
 			</object>
 		</child>
 		<ui>
@@ -78,6 +86,8 @@
 				<separator name="setup-separator"/>
 
 				<menuitem name="preferences" action="preferences"/>
+
+				<menuitem name="quit" action="quit"/>
 			</popup>
 		</ui>
 	</object>



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