[gnome-bluetooth] Port bluetooth-properties to the new control-center



commit 8fb47ea30527cfc526c98ec9f5b780a836c3abc1
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jun 17 22:49:14 2010 +0100

    Port bluetooth-properties to the new control-center
    
    We do not cut down the exports to g_io_module_* functions
    otherwise the use of private BluetoothClient functions will fail.

 configure.ac                                  |    5 +-
 properties/Makefile.am                        |   16 ++-
 properties/bluetooth-properties.1             |   29 ----
 properties/bluetooth-properties.desktop.in.in |    4 +-
 properties/{main.c => cc-bluetooth-panel.c}   |  191 +++++++------------------
 properties/cc-bluetooth-panel.h               |   60 ++++++++
 6 files changed, 131 insertions(+), 174 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c79271f..b849584 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,11 +80,14 @@ PKG_CHECK_MODULES(GCONF,
 		  gconf-2.0 >= $GCONF_REQUIRED)
 
 dnl Requires for the properties window
+PANELS_DIR="${libdir}/control-center-1/panels"
+AC_SUBST(PANELS_DIR)
+
 PKG_CHECK_MODULES(PROPS,
 		  dbus-glib-1 >= $DBUS_GLIB_REQUIRED
 		  glib-2.0 >= $GLIB_REQUIRED
 		  gtk+-2.0
-		  unique-1.0)
+		  libgnome-control-center)
 
 dnl Requires for the applet
 PKG_CHECK_MODULES(APPLET,
diff --git a/properties/Makefile.am b/properties/Makefile.am
index 9e064c9..5b835a4 100644
--- a/properties/Makefile.am
+++ b/properties/Makefile.am
@@ -1,16 +1,22 @@
 
-bin_PROGRAMS = bluetooth-properties
+ccpanelsdir = $(PANELS_DIR)
+ccpanels_LTLIBRARIES = libbluetooth.la
 
-bluetooth_properties_SOURCES = main.c general.h general.c adapter.h adapter.c
+libbluetooth_la_SOURCES =			\
+	cc-bluetooth-panel.c			\
+	cc-bluetooth-panel.h			\
+	general.h				\
+	general.c				\
+	adapter.h				\
+	adapter.c
 
-bluetooth_properties_LDADD = $(top_builddir)/lib/libgnome-bluetooth.la $(top_builddir)/lib/libcommon.la $(PROPS_LIBS)
+libbluetooth_la_LIBADD = $(top_builddir)/lib/libgnome-bluetooth.la $(top_builddir)/lib/libcommon.la $(PROPS_LIBS)
+libbluetooth_la_LDFLAGS = -avoid-version -module
 
 AM_CFLAGS = $(PROPS_CFLAGS) $(WARN_CFLAGS) $(DISABLE_DEPRECATED) -DPKGDATADIR="\"$(pkgdatadir)\""
 
 INCLUDES = -I$(top_srcdir)/lib
 
-man_MANS = bluetooth-properties.1
-
 desktopdir = $(datadir)/applications
 desktop_in_in_files = bluetooth-properties.desktop.in.in
 desktop_in_files = bluetooth-properties.desktop.in
diff --git a/properties/bluetooth-properties.desktop.in.in b/properties/bluetooth-properties.desktop.in.in
index a8f7fe7..ce0bf74 100644
--- a/properties/bluetooth-properties.desktop.in.in
+++ b/properties/bluetooth-properties.desktop.in.in
@@ -2,7 +2,7 @@
 _Name=Bluetooth
 _Comment=Configure Bluetooth settings
 Icon=bluetooth
-Exec=bluetooth-properties
+Exec=gnome-control-center bluetooth
 Terminal=false
 Type=Application
 Categories=GTK;GNOME;Settings;X-GNOME-NetworkSettings;
@@ -13,4 +13,4 @@ X-GNOME-Bugzilla-Product=gnome-bluetooth
 X-GNOME-Bugzilla-Component=properties
 X-GNOME-Bugzilla-Version= VERSION@
 X-GNOME-Bugzilla-OtherBinaries=bluetooth-sendto;bluetooth-wizard;
-
+X-GNOME-Settings-Panel=bluetooth
diff --git a/properties/main.c b/properties/cc-bluetooth-panel.c
similarity index 51%
rename from properties/main.c
rename to properties/cc-bluetooth-panel.c
index 424d5d8..3b587ad 100644
--- a/properties/main.c
+++ b/properties/cc-bluetooth-panel.c
@@ -3,7 +3,7 @@
  *  BlueZ - Bluetooth protocol stack for Linux
  *
  *  Copyright (C) 2005-2008  Marcel Holtmann <marcel holtmann org>
- *  Copyright (C) 2006-2007  Bastien Nocera <hadess hadess net>
+ *  Copyright (C) 2006-2010  Bastien Nocera <hadess hadess net>
  *
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,11 +26,9 @@
 #include <config.h>
 #endif
 
-#include <glib/gi18n.h>
-#include <gdk/gdkkeysyms.h>
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-#include <unique/uniqueapp.h>
+#include <glib/gi18n-lib.h>
+
+#include "cc-bluetooth-panel.h"
 
 #include "bluetooth-plugin-manager.h"
 #include "bluetooth-client.h"
@@ -38,41 +36,12 @@
 #include "general.h"
 #include "adapter.h"
 
-#define SCHEMA_NAME		"org.gnome.Bluetooth"
-#define PREF_SHOW_ICON		"show-icon"
-
-static gboolean delete_callback(GtkWidget *window, GdkEvent *event,
-							gpointer user_data)
-{
-	gtk_widget_destroy(GTK_WIDGET(window));
-
-	gtk_main_quit();
-
-	return FALSE;
-}
+G_DEFINE_DYNAMIC_TYPE (CcBluetoothPanel, cc_bluetooth_panel, CC_TYPE_PANEL)
 
-static gboolean
-keypress_callback (GtkWidget *window,
-		   GdkEventKey *key,
-		   gpointer user_data)
-{
-	if (key->keyval == GDK_Escape) {
-		gtk_widget_destroy(GTK_WIDGET(window));
-
-		gtk_main_quit();
-	}
-
-	return FALSE;
-}
-
-static void close_callback(GtkWidget *button, gpointer user_data)
-{
-	GtkWidget *window = user_data;
+static void cc_bluetooth_panel_finalize (GObject *object);
 
-	gtk_widget_destroy(GTK_WIDGET(window));
-
-	gtk_main_quit();
-}
+#define SCHEMA_NAME		"org.gnome.Bluetooth"
+#define PREF_SHOW_ICON		"show-icon"
 
 static void
 receive_callback (GtkWidget *item, GtkWindow *window)
@@ -113,26 +82,14 @@ static void help_callback(GtkWidget *item)
 
 static GtkWidget *create_window(GtkWidget *notebook)
 {
-	GtkWidget *window;
 	GtkWidget *vbox;
 	GtkWidget *buttonbox;
 	GtkWidget *button;
 	GtkWidget *image;
 	GSettings *settings;
 
-	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-	gtk_window_set_title(GTK_WINDOW(window), _("Bluetooth Preferences"));
-	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-	gtk_window_set_default_size(GTK_WINDOW(window), 600, 420);
-	g_signal_connect(G_OBJECT(window), "delete-event",
-					G_CALLBACK(delete_callback), NULL);
-
-	g_signal_connect(G_OBJECT(window), "key-press-event",
-			 G_CALLBACK(keypress_callback), NULL);
-
 	vbox = gtk_vbox_new(FALSE, 6);
 	gtk_container_set_border_width(GTK_CONTAINER(vbox), 12);
-	gtk_container_add(GTK_CONTAINER(window), vbox);
 
 	gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
 
@@ -146,17 +103,12 @@ static GtkWidget *create_window(GtkWidget *notebook)
 	gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonbox), GTK_BUTTONBOX_END);
 	gtk_box_pack_start(GTK_BOX(vbox), buttonbox, FALSE, FALSE, 0);
 
-	button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
-	gtk_container_add(GTK_CONTAINER(buttonbox), button);
-	g_signal_connect(G_OBJECT(button), "clicked",
-					G_CALLBACK(close_callback), window);
-
 	button = gtk_button_new_from_stock(GTK_STOCK_HELP);
 	gtk_container_add(GTK_CONTAINER(buttonbox), button);
 	gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox),
-								button, TRUE);
+					   button, TRUE);
 	g_signal_connect(G_OBJECT(button), "clicked",
-					G_CALLBACK(help_callback), window);
+			 G_CALLBACK(help_callback), NULL); //FIXME parent?
 
 	image = gtk_image_new_from_stock (GTK_STOCK_JUMP_TO,
 					  GTK_ICON_SIZE_BUTTON);
@@ -164,111 +116,76 @@ static GtkWidget *create_window(GtkWidget *notebook)
 	gtk_button_set_image (GTK_BUTTON (button), image);
 	gtk_container_add(GTK_CONTAINER(buttonbox), button);
 	gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(buttonbox),
-								button, TRUE);
+					   button, TRUE);
 	g_signal_connect(G_OBJECT(button), "clicked",
-					G_CALLBACK(receive_callback), window);
+			 G_CALLBACK(receive_callback), NULL); //FIXME parent?
 
-	gtk_widget_show_all(window);
+	gtk_widget_show_all(vbox);
 
-	return window;
+	return vbox;
 }
 
-static UniqueResponse
-message_received_cb (UniqueApp         *app,
-                     int                command,
-                     UniqueMessageData *message_data,
-                     guint              time_,
-                     gpointer           user_data)
+static void
+cc_bluetooth_panel_class_init (CcBluetoothPanelClass *klass)
 {
-        gtk_window_present (GTK_WINDOW (user_data));
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-        return UNIQUE_RESPONSE_OK;
+	object_class->finalize = cc_bluetooth_panel_finalize;
 }
 
 static void
-dump_devices (void)
+cc_bluetooth_panel_class_finalize (CcBluetoothPanelClass *klass)
 {
-	BluetoothClient *client;
-	GtkTreeModel *model;
-	GtkTreeIter iter;
-
-	client = bluetooth_client_new ();
-	model = bluetooth_client_get_model (client);
-
-	if (gtk_tree_model_get_iter_first (model, &iter) == FALSE) {
-		g_print ("No known devices\n");
-		g_print ("Is bluetoothd running, and a Bluetooth adapter enabled?\n");
-		return;
-	}
-	bluetooth_client_dump_device (model, &iter, TRUE);
-	while (gtk_tree_model_iter_next (model, &iter))
-		bluetooth_client_dump_device (model, &iter, TRUE);
 }
 
-static gboolean option_dump = FALSE;
-
-static GOptionEntry options[] = {
-	{ "dump-devices", 'd', 0, G_OPTION_ARG_NONE, &option_dump, N_("Output a list of currently known devices"), NULL },
-	{ NULL },
-};
-
-int main(int argc, char *argv[])
+static void
+cc_bluetooth_panel_finalize (GObject *object)
 {
-	UniqueApp *app;
-	GtkWidget *window;
-	GtkWidget *notebook;
-	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");
-
-		return 1;
-	}
-
-	if (option_dump != FALSE) {
-		dump_devices ();
-		return 0;
-	}
+	bluetooth_plugin_manager_cleanup ();
 
-	app = unique_app_new ("org.gnome.Bluetooth.properties", NULL);
-	if (unique_app_is_running (app)) {
-		gdk_notify_startup_complete ();
-		unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
-		return 0;
-	}
+	cleanup_adapter();
 
-	g_set_application_name(_("Bluetooth Properties"));
+	G_OBJECT_CLASS (cc_bluetooth_panel_parent_class)->finalize (object);
+}
 
-	gtk_window_set_default_icon_name("bluetooth");
+static void
+cc_bluetooth_panel_init (CcBluetoothPanel *self)
+{
+	GtkWidget *widget;
+	GtkWidget *notebook;
 
 	bluetooth_plugin_manager_init ();
 
 	notebook = gtk_notebook_new();
 	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
-
 	setup_adapter(GTK_NOTEBOOK(notebook));
+	widget = create_window(notebook);
 
-	window = create_window(notebook);
-
-	g_signal_connect (app, "message-received",
-			  G_CALLBACK (message_received_cb), window);
-
-	gtk_main();
+	gtk_container_add (GTK_CONTAINER (self), widget);
+}
 
-	bluetooth_plugin_manager_cleanup ();
+void
+cc_bluetooth_panel_register (GIOModule *module)
+{
+	cc_bluetooth_panel_register_type (G_TYPE_MODULE (module));
+	g_io_extension_point_implement (CC_SHELL_PANEL_EXTENSION_POINT,
+					CC_TYPE_BLUETOOTH_PANEL,
+					"bluetooth", 0);
+}
 
-	cleanup_adapter();
+/* GIO extension stuff */
+void
+g_io_module_load (GIOModule *module)
+{
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
-	g_object_unref(app);
+	/* register the panel */
+	cc_bluetooth_panel_register (module);
+}
 
-	return 0;
+void
+g_io_module_unload (GIOModule *module)
+{
 }
+
diff --git a/properties/cc-bluetooth-panel.h b/properties/cc-bluetooth-panel.h
new file mode 100644
index 0000000..86b8809
--- /dev/null
+++ b/properties/cc-bluetooth-panel.h
@@ -0,0 +1,60 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2005-2008  Marcel Holtmann <marcel holtmann org>
+ *  Copyright (C) 2006-2010  Bastien Nocera <hadess hadess net>
+ *
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef _CC_BLUETOOTH_PANEL_H
+#define _CC_BLUETOOTH_PANEL_H
+
+#include <libgnome-control-center/cc-panel.h>
+
+G_BEGIN_DECLS
+
+#define CC_TYPE_BLUETOOTH_PANEL cc_bluetooth_panel_get_type()
+#define CC_BLUETOOTH_PANEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CC_TYPE_BLUETOOTH_PANEL, CcBluetoothPanel))
+#define CC_BLUETOOTH_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CC_TYPE_BLUETOOTH_PANEL, CcBluetoothPanelClass))
+#define CC_IS_BLUETOOTH_PANEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CC_TYPE_BLUETOOTH_PANEL))
+#define CC_IS_BLUETOOTH_PANEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CC_TYPE_BLUETOOTH_PANEL))
+#define CC_BLUETOOTH_PANEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CC_TYPE_BLUETOOTH_PANEL, CcBluetoothPanelClass))
+
+typedef struct _CcBluetoothPanel CcBluetoothPanel;
+typedef struct _CcBluetoothPanelClass CcBluetoothPanelClass;
+typedef struct _CcBluetoothPanelPrivate CcBluetoothPanelPrivate;
+
+struct _CcBluetoothPanel {
+	CcPanel parent;
+
+	CcBluetoothPanelPrivate *priv;
+};
+
+struct _CcBluetoothPanelClass {
+	CcPanelClass parent_class;
+};
+
+GType cc_bluetooth_panel_get_type (void) G_GNUC_CONST;
+
+void  cc_bluetooth_panel_register (GIOModule *module);
+
+G_END_DECLS
+
+#endif /* _CC_BLUETOOTH_PANEL_H */
+



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