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

Chris Rivera
2007-12-18T18:37:44Z

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

Updated patch attached.

Chris

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

> Hi Chris,
>
> > Please use use gtk_init_with_args and make the GOptionEntry
> > data global
> > and static. Look at bluetooth-analyzer for an example.
> >
> > This would force the singleton flag variable to be global. Is this
> > what you want?
>
> what is the difference? It is fine to have it global. I don't see any
> problem with it. I don't wanna introduce any complexity if it is not
> needed.
>
> Regards
>
> Marcel
>
>
>
> -------------------------------------------------------------------------
> 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
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>

[-- Attachment #1.2: Type: text/html, Size: 1751 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: 9127 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-17 19:16:29.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);
@@ -1780,17 +1781,34 @@ static void gconf_callback(GConfClient *
auto_authorize = gconf_value_get_bool(value);
}

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

bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);

- gtk_init(&argc, &argv);
+ if (gtk_init_with_args(&argc, &argv, "",
+ 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");
+
+ gtk_exit(1);
+ }

#ifdef HAVE_LIBNOTIFY
notify_init("bluetooth-manager");
@@ -1804,6 +1822,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 +1883,8 @@ int main(int argc, char *argv[])
g_list_foreach(adapter_list, adapter_free, NULL);

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

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-17 19:20:43.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,
@@ -139,18 +141,36 @@ static DBusGProxy *setup_manager(DBusGCo
return proxy;
}

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

- gtk_init(&argc, &argv);
+ if (gtk_init_with_args(&argc, &argv, "",
+ 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");
+
+ gtk_exit(1);
+ }

conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
if (error != NULL) {
@@ -163,12 +183,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 +207,8 @@ int main(int argc, char *argv[])
g_object_unref(manager);

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

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-17 19:21: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,52 @@ static void create_wizard(void)
gtk_widget_show_all(assistant);

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

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

- gtk_init(&argc, &argv);
+ if (gtk_init_with_args(&argc, &argv, "",
+ 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");

+ gtk_exit(1);
+ }
+
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);
+
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 --]