Re: [Bluez-devel] [PATCH] [RESEND] make bluez GNOME UIs singletons

Chris Rivera
2007-12-17T19:29:14Z

[-- Attachment #1.1: Type: text/plain, Size: 906 bytes --]

On Dec 17, 2007 1:53 PM, Marcel Holtmann <marcel@holtmann.org> wrote:

> Hi Chris,
>
> > Updated patches attached.
>
> I added the generic singleton instance patch to the CVS. I did some
> minor modifications. The interface name is org.bluez.Instance. No need
> to duplicate the word Bluetooth here. And I removed the retval parameter
> from the register function. It is useless. Use the return value for it.
> If it is TRUE, everything is okay. If FALSE, cleanup and exit(1).
>
>
>
I wanted to distinguish between an instance already running and actual DBUS
errors. If an instance is already running then we can exit with 0 since the
intended action was successful (the launched application is now in the
foreground). If, however, there are errors connecting to the bus then we
exit with 1. It isn't a big deal though. I've attached an updated apps
patch that gets rid of the retval parameter.

Chris

[-- Attachment #1.2: Type: text/html, Size: 1189 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: bluez-gnome-singleton-apps.patch --]
[-- Type: text/x-patch; name=bluez-gnome-singleton-apps.patch, Size: 9435 bytes --]

diff -urpN gnome/applet/bluetooth-applet.1 gnome-new/applet/bluetooth-applet.1
--- gnome/applet/bluetooth-applet.1 2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.1 2007-12-16 18:31:09.000000000 -0500
@@ -10,8 +10,9 @@ whenever a passkey (aka PIN) is required
.I bluetooth-applet
is part of bluez-gnome, see also http://www.bluez.org
.SH OPTIONS
-.I bluetooth-applet
-takes no options
+.TP
+.BI \-\-singleton
+Ensure that only one instance is running.
.SH AUTHOR
Marcel Holtmann <marcel@holtmann.org>
.SH LICENSE
diff -urpN gnome/applet/bluetooth-applet.desktop.in gnome-new/applet/bluetooth-applet.desktop.in
--- gnome/applet/bluetooth-applet.desktop.in 2007-04-03 04:09:01.000000000 -0400
+++ gnome-new/applet/bluetooth-applet.desktop.in 2007-12-16 18:31:09.000000000 -0500
@@ -3,7 +3,7 @@ Encoding=UTF-8
_Name=Bluetooth Manager
_Comment=Bluetooth Manager applet
Icon=stock_bluetooth
-Exec=bluetooth-applet
+Exec=bluetooth-applet --singleton
Terminal=false
Type=Application
Categories=
diff -urpN gnome/applet/main.c gnome-new/applet/main.c
--- gnome/applet/main.c 2007-12-04 10:30:51.000000000 -0500
+++ gnome-new/applet/main.c 2007-12-16 22:11:44.000000000 -0500
@@ -49,6 +49,7 @@
#endif

#include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"

#define PASSKEY_AGENT_PATH "/org/bluez/passkey"
#define AUTH_AGENT_PATH "/org/bluez/auth"
@@ -1550,7 +1551,7 @@ static void about_callback(GtkWidget *it

static void settings_callback(GObject *widget, gpointer user_data)
{
- const char *command = "bluetooth-properties";
+ const char *command = "bluetooth-properties --singleton";

if (!g_spawn_command_line_async(command, NULL))
g_printerr("Couldn't execute command: %s\n", command);
@@ -1639,7 +1640,7 @@ static void sendto_callback(GObject *wid
#if 0
static void wizard_callback(GObject *widget, gpointer user_data)
{
- const char *command = "bluetooth-wizard";
+ const char *command = "bluetooth-wizard --singleton";

if (!g_spawn_command_line_async(command, NULL))
g_printerr("Couldn't execute command: %s\n", command);
@@ -1782,9 +1783,18 @@ static void gconf_callback(GConfClient *

int main(int argc, char *argv[])
{
+ GOptionContext *ctx;
GtkWidget *menu;
GError *error = NULL;
+ BluetoothInstance *app;
char *str;
+ gboolean singleton = FALSE;
+
+ GOptionEntry entries[] = {
+ { "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+ N_("Only allow one instance of this application"), NULL },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };

bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
@@ -1792,6 +1802,15 @@ int main(int argc, char *argv[])

gtk_init(&argc, &argv);

+ ctx = g_option_context_new("");
+ g_option_context_add_main_entries(ctx, entries, NULL);
+ if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+ g_printerr(_("parsing failed: %s\n"), error->message);
+ g_error_free(error);
+ g_option_context_free(ctx);
+ exit(EXIT_FAILURE);
+ }
+
#ifdef HAVE_LIBNOTIFY
notify_init("bluetooth-manager");
#endif
@@ -1804,6 +1823,11 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

+ app = bluetooth_instance_new();
+ if(!bluetooth_instance_register(app, singleton,
+ "/org/bluez/applet", "org.bluez.applet"))
+ exit(EXIT_FAILURE);
+
gconf = gconf_client_get_default();

#ifdef HAVE_HAL
@@ -1860,6 +1884,10 @@ int main(int argc, char *argv[])
g_list_foreach(adapter_list, adapter_free, NULL);

dbus_g_connection_unref(conn);
+
+ g_object_unref(app);

+ g_option_context_free(ctx);
+
return 0;
}
diff -urpN gnome/properties/bluetooth-properties.1 gnome-new/properties/bluetooth-properties.1
--- gnome/properties/bluetooth-properties.1 2007-07-22 11:33:13.000000000 -0400
+++ gnome-new/properties/bluetooth-properties.1 2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a dialog for changing Bluet
.I bluetooth-properties
is part of bluez-gnome, see also http://www.bluez.org
.SH OPTIONS
-.I bluetooth-properties
-takes no options
+.TP
+.BI \-\-singleton
+Ensure that only one instance is running.
.SH AUTHOR
Marcel Holtmann <marcel@holtmann.org>
.SH LICENSE
diff -urpN gnome/properties/main.c gnome-new/properties/main.c
--- gnome/properties/main.c 2007-07-31 17:37:29.000000000 -0400
+++ gnome-new/properties/main.c 2007-12-16 22:13:19.000000000 -0500
@@ -40,6 +40,7 @@
#include "general.h"
#include "service.h"
#include "adapter.h"
+#include "bluetooth-instance.h"

static void delete_callback(GtkWidget *window, GdkEvent *event,
gpointer user_data)
@@ -58,7 +59,7 @@ static void close_callback(GtkWidget *bu
gtk_main_quit();
}

-static void create_window(GtkWidget *notebook)
+static GtkWidget *create_window(GtkWidget *notebook)
{
GtkWidget *window;
GtkWidget *widget;
@@ -108,6 +109,7 @@ static void create_window(GtkWidget *not
widget, _("General"));

gtk_widget_show_all(window);
+ return window;
}

static void name_owner_changed(DBusGProxy *object, const char *name,
@@ -141,17 +143,36 @@ static DBusGProxy *setup_manager(DBusGCo

int main(int argc, char *argv[])
{
+ GOptionContext *ctx;
GtkWidget *notebook;
+ GtkWidget *window;
+ GError *error = NULL;
DBusGConnection *conn;
+ BluetoothInstance *app;
DBusGProxy *manager;
- GError *error = NULL;
+ gboolean singleton = FALSE;

+ GOptionEntry entries[] = {
+ { "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+ N_("Only allow one instance of this application"), NULL },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);

gtk_init(&argc, &argv);

+ ctx = g_option_context_new("");
+ g_option_context_add_main_entries(ctx, entries, NULL);
+ if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+ g_printerr(_("parsing failed: %s\n"), error->message);
+ g_error_free(error);
+ g_option_context_free(ctx);
+ exit(EXIT_FAILURE);
+ }
+
conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (error != NULL) {
g_printerr("Connecting to system bus failed: %s\n",
@@ -163,12 +184,18 @@ int main(int argc, char *argv[])
setup_general();

notebook = gtk_notebook_new();
-
+
assign_adapter(notebook);

- manager = setup_manager(conn);
+ window = create_window(notebook);

- create_window(notebook);
+ app = bluetooth_instance_new();
+ bluetooth_instance_set_window(app, GTK_WINDOW(window));
+ if(!bluetooth_instance_register(app, singleton,
+ "/org/bluez/properties", "org.bluez.properties"))
+ exit(EXIT_FAILURE);
+
+ manager = setup_manager(conn);

gtk_main();

@@ -181,6 +208,10 @@ int main(int argc, char *argv[])
g_object_unref(manager);

dbus_g_connection_unref(conn);
+
+ g_object_unref(app);

+ g_option_context_free(ctx);
+
return 0;
}
diff -urpN gnome/wizard/bluetooth-wizard.1 gnome-new/wizard/bluetooth-wizard.1
--- gnome/wizard/bluetooth-wizard.1 2007-07-22 11:33:12.000000000 -0400
+++ gnome-new/wizard/bluetooth-wizard.1 2007-12-16 18:31:09.000000000 -0500
@@ -9,8 +9,9 @@ will display a wizard for setting up Blu
.I bluetooth-wizard
is part of bluez-gnome, see also http://www.bluez.org
.SH OPTIONS
-.I bluetooth-wizard
-takes no options
+.TP
+.BI \-\-singleton
+Ensure that only one instance is running.
.SH AUTHOR
Marcel Holtmann <marcel@holtmann.org>
.SH LICENSE
diff -urpN gnome/wizard/main.c gnome-new/wizard/main.c
--- gnome/wizard/main.c 2007-08-15 03:04:03.000000000 -0400
+++ gnome-new/wizard/main.c 2007-12-16 22:12:13.000000000 -0500
@@ -26,6 +26,7 @@
#endif

#include <string.h>
+#include <stdlib.h>

#include <dbus/dbus-glib.h>

@@ -38,6 +39,7 @@
#include "dbus-glue.h"

#include "bluetooth-device-selection.h"
+#include "bluetooth-instance.h"

static BluetoothClient *client;

@@ -387,7 +389,7 @@ static void create_summary(GtkWidget *as
page_summary = vbox;
}

-static void create_wizard(void)
+static GtkWidget *create_wizard(void)
{
GtkWidget *assistant;

@@ -430,23 +432,55 @@ static void create_wizard(void)
gtk_widget_show_all(assistant);

gtk_assistant_update_buttons_state(GTK_ASSISTANT(assistant));
+ return assistant;
}

int main(int argc, char *argv[])
{
+ GOptionContext *ctx;
+ GtkWidget *window;
+ BluetoothInstance *app;
+ GError *error = NULL;
+ gboolean singleton = FALSE;
+
+ GOptionEntry entries[] = {
+ { "singleton", 0, 0, G_OPTION_ARG_NONE, &singleton,
+ N_("Only allow one instance of this application"), NULL },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);

gtk_init(&argc, &argv);

+ ctx = g_option_context_new("");
+ g_option_context_add_main_entries(ctx, entries, NULL);
+ if (!g_option_context_parse(ctx, &argc, &argv, &error)) {
+ g_printerr(_("parsing failed: %s\n"), error->message);
+ g_error_free(error);
+ g_option_context_free(ctx);
+ exit(EXIT_FAILURE);
+ }
+
client = bluetooth_client_new();

- create_wizard();
+ window = create_wizard();
+
+ app = bluetooth_instance_new();
+ bluetooth_instance_set_window(app, GTK_WINDOW(window));
+ if(!bluetooth_instance_register(app, singleton,
+ "/org/bluez/wizard", "org.bluez.wizard"))
+ exit(EXIT_FAILURE);

gtk_main();

g_object_unref(client);

+ g_object_unref(app);
+
+ g_option_context_free(ctx);
+
return 0;
}

[-- Attachment #3: Type: text/plain, Size: 308 bytes --]

-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services
for just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]