[phonemgr] Add a GNOME Bluetooth plugin
- From: Daniele Forsi <dforsi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [phonemgr] Add a GNOME Bluetooth plugin
- Date: Tue, 15 Feb 2011 20:00:38 +0000 (UTC)
commit 160e65fa872f0bc69db7a30542bfeb343f183367
Author: Daniele Forsi <dforsi src gnome org>
Date: Tue Feb 15 19:12:32 2011 +0100
Add a GNOME Bluetooth plugin
This extends the GNOME Bluetooth's new device wizard to allow 1-click
configuration of Phone Manager to use a newly paired phone.
https://bugzilla.gnome.org/show_bug.cgi?id=611616
Makefile.am | 2 +-
configure.in | 21 +++++-
gnome-bluetooth/Makefile.am | 23 ++++++
gnome-bluetooth/phonemgr.c | 185 +++++++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
src/Makefile.am | 1 +
src/app.h | 19 +----
src/phonemgr-conf.h | 42 ++++++++++
src/ui.c | 2 +-
9 files changed, 275 insertions(+), 21 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 0e7c6bd..d09b70c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in
-SUBDIRS = po libgsm cut-n-paste src telepathy data
+SUBDIRS = po libgsm cut-n-paste src gnome-bluetooth telepathy data
EXTRA_DIST = \
autogen.sh \
diff --git a/configure.in b/configure.in
index 3d557eb..82d8d11 100644
--- a/configure.in
+++ b/configure.in
@@ -10,7 +10,6 @@ AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE([1.9 dist-bzip2 no-dist-gzip check-news])
dnl Initialize libtool
-AM_DISABLE_SHARED
AM_PROG_LIBTOOL
GNOKII_REQS="gnokii >= 0.6.28"
@@ -86,6 +85,25 @@ if test x$HAVE_TELEPATHY = "xyes"; then
fi
AM_CONDITIONAL(HAVE_TELEPATHY, test x$HAVE_TELEPATHY = "xyes")
+dnl Check for gnome-bluetooth plugin build
+AC_ARG_ENABLE(bluetooth-plugin,
+ AC_HELP_STRING([--enable-bluetooth-plugin],[compile the gnome-bluetooth plugin]),
+ [case "${enableval}" in
+ yes) ENABLE_BLUETOOTH_PLUGIN=yes ;;
+ no) ENABLE_BLUETOOTH_PLUGIN=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-bluetooth-plugin) ;;
+ esac],
+ [ENABLE_BLUETOOTH_PLUGIN=yes]) dnl Default value
+
+if test x$ENABLE_BLUETOOTH_PLUGIN = "xyes" ; then
+ PKG_CHECK_MODULES(BLUETOOTH_PLUGIN, gnome-bluetooth-1.0 >= 2.27.6 gconf-2.0,
+ [HAVE_BLUETOOTH_PLUGIN=yes], [HAVE_BLUETOOTH_PLUGIN=no])
+fi
+if test x$HAVE_BLUETOOTH_PLUGIN = "xyes"; then
+ AC_DEFINE(HAVE_BLUETOOTH_PLUGIN, 1, [Defined to 1 if you build the gnome-bluetooth plugin.])
+fi
+AM_CONDITIONAL(HAVE_BLUETOOTH_PLUGIN, test x$HAVE_BLUETOOTH_PLUGIN = "xyes")
+
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal, no)
AC_SUBST(GLIB_GENMARSHAL)
@@ -128,6 +146,7 @@ cut-n-paste/Makefile
cut-n-paste/e-contact-entry/Makefile
cut-n-paste/gconf-bridge/Makefile
src/Makefile
+gnome-bluetooth/Makefile
telepathy/Makefile
po/Makefile.in
])
diff --git a/gnome-bluetooth/Makefile.am b/gnome-bluetooth/Makefile.am
new file mode 100644
index 0000000..f7f3446
--- /dev/null
+++ b/gnome-bluetooth/Makefile.am
@@ -0,0 +1,23 @@
+AM_CPPFLAGS = \
+ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
+ -DDATA_DIR="\"$(pkgdatadir)\"" \
+ -DVERSION="\"$(VERSION)\"" \
+ -DPACKAGE="\"$(PACKAGE)\"" \
+ -I$(srcdir)/../libgsm \
+ -I$(builddir)/../libgsm \
+ -I$(srcdir)/../src \
+ $(WARN_CFLAGS)
+
+BLUETOOTH_PLUGIN_SOURCES = \
+ phonemgr.c
+
+if HAVE_BLUETOOTH_PLUGIN
+plugindir = $(libdir)/gnome-bluetooth/plugins
+
+plugin_LTLIBRARIES = libphonemgr.la
+libphonemgr_la_CFLAGS = $(BLUETOOTH_PLUGIN_CFLAGS)
+libphonemgr_la_LDFLAGS = -module -avoid-version
+libphonemgr_la_LIBADD = $(BLUETOOTH_PLUGIN_LIBS)
+endif
+
+libphonemgr_la_SOURCES = $(BLUETOOTH_PLUGIN_SOURCES)
diff --git a/gnome-bluetooth/phonemgr.c b/gnome-bluetooth/phonemgr.c
new file mode 100644
index 0000000..9ebac12
--- /dev/null
+++ b/gnome-bluetooth/phonemgr.c
@@ -0,0 +1,185 @@
+/*
+ *
+ * Phone Manager plugin for GNOME Bluetooth
+ *
+ * Copyright (C) 2009 Bastien Nocera <hadess hadess net>
+ * Copyright (C) 2011 Daniele Forsi <daniele forsi it>
+ *
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+#include <gconf/gconf-client.h>
+
+#include <bluetooth-plugin.h>
+#include <bluetooth-client.h>
+
+#include "phonemgr-conf.h"
+
+static BluetoothType
+get_type (const char *address)
+{
+ BluetoothClient *client;
+ BluetoothType type = BLUETOOTH_TYPE_ANY;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ gboolean cont;
+
+ client = bluetooth_client_new ();
+ model = bluetooth_client_get_device_model (client, NULL);
+ if (model == NULL) {
+ g_object_unref (client);
+ return type;
+ }
+
+ for (cont = gtk_tree_model_get_iter_first (model, &iter);
+ cont != FALSE;
+ cont = gtk_tree_model_iter_next (model, &iter)) {
+ char *bdaddr;
+
+ gtk_tree_model_get (model, &iter,
+ BLUETOOTH_COLUMN_ADDRESS, &bdaddr,
+ -1);
+ if (g_strcmp0 (bdaddr, address) == 0) {
+ g_free (bdaddr);
+ gtk_tree_model_get (model, &iter,
+ BLUETOOTH_COLUMN_TYPE, &type,
+ -1);
+ break;
+ }
+ g_free (bdaddr);
+ }
+
+ g_object_unref (model);
+ g_object_unref (client);
+
+ return type;
+}
+
+static gboolean
+has_config_widget (const char *bdaddr, const char **uuids)
+{
+ gboolean has_sp;
+ BluetoothType type;
+ guint i;
+
+ if (uuids == NULL)
+ return FALSE;
+ for (i = 0; uuids[i] != NULL; i++) {
+ if (g_str_equal (uuids[i], "SerialPort")) {
+ has_sp = TRUE;
+ break;
+ }
+ }
+ if (has_sp == FALSE)
+ return FALSE;
+
+ type = get_type (bdaddr);
+
+ return type & PHONEMGR_DEVICE_TYPE_FILTER;
+}
+
+static void
+toggle_button (GtkToggleButton *button, gpointer user_data)
+{
+ gboolean state;
+ GConfClient *client;
+ const char *bdaddr;
+
+ client = g_object_get_data (G_OBJECT (button), "client");
+ bdaddr = g_object_get_data (G_OBJECT (button), "bdaddr");
+
+ state = gtk_toggle_button_get_active (button);
+ if (state == FALSE) {
+ gconf_client_set_string (client, CONFBASE"/bluetooth_addr", "", NULL);
+ gconf_client_set_int (client, CONFBASE"/connection_type", CONNECTION_NONE, NULL);
+ } else {
+ gconf_client_set_string (client, CONFBASE"/bluetooth_addr", bdaddr, NULL);
+ gconf_client_set_int (client, CONFBASE"/connection_type", CONNECTION_BLUETOOTH, NULL);
+ }
+}
+
+static GtkWidget *
+get_config_widgets (const char *bdaddr, const char **uuids)
+{
+ GtkWidget *button;
+ GConfClient *client;
+ char *old_bdaddr;
+ int connection_type;
+
+ client = gconf_client_get_default ();
+ if (client == NULL)
+ return NULL;
+
+ /* Translators: "device" is a phone or a modem */
+ button = gtk_check_button_new_with_label (_("Use this device with Phone Manager"));
+ g_object_set_data_full (G_OBJECT (button), "bdaddr", g_strdup (bdaddr), g_free);
+ g_object_set_data_full (G_OBJECT (button), "client", client, g_object_unref);
+
+ /* Is it already setup? */
+ old_bdaddr = gconf_client_get_string (client, CONFBASE"/bluetooth_addr", NULL);
+ connection_type = gconf_client_get_int (client, CONFBASE"/connection_type", NULL);
+ if (connection_type == CONNECTION_BLUETOOTH && old_bdaddr && g_strcmp0 (old_bdaddr, bdaddr) == 0) {
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ g_object_set_data (G_OBJECT (button), "bdaddr", old_bdaddr);
+ } else {
+ g_free (old_bdaddr);
+ }
+
+ /* And set the signal */
+ g_signal_connect (G_OBJECT (button), "toggled",
+ G_CALLBACK (toggle_button), NULL);
+
+ return button;
+}
+
+static void
+device_removed (const char *bdaddr)
+{
+ GConfClient *client;
+ char *str;
+
+ client = gconf_client_get_default ();
+ if (client == NULL)
+ return;
+
+ str = gconf_client_get_string (client, CONFBASE"/bluetooth_addr", NULL);
+ if (g_strcmp0 (str, bdaddr) == 0) {
+ gconf_client_set_string (client, CONFBASE"/bluetooth_addr", "", NULL);
+ if (gconf_client_get_int (client, CONFBASE"/connection_type", NULL) == CONNECTION_BLUETOOTH) {
+ gconf_client_set_int (client, CONFBASE"/connection_type", CONNECTION_NONE, NULL);
+ }
+ g_debug ("Device '%s' got disabled for use with Phone Manager", bdaddr);
+ }
+
+ g_free (str);
+ g_object_unref (client);
+}
+
+static GbtPluginInfo plugin_info = {
+ "phonemgr",
+ has_config_widget,
+ get_config_widgets,
+ device_removed
+};
+
+GBT_INIT_PLUGIN(plugin_info)
+
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4269933..d4d128f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@
# Please keep this file sorted alphabetically.
cut-n-paste/e-contact-entry/e-contact-entry.c
cut-n-paste/gconf-bridge/gconf-bridge.c
+gnome-bluetooth/phonemgr.c
src/connection.c
src/gnome-phone-manager.desktop.in
src/icon.c
diff --git a/src/Makefile.am b/src/Makefile.am
index ca32164..5288aa5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,6 +21,7 @@ gnome_phone_manager_SOURCES = \
main.c \
icon.c \
app.h \
+ phonemgr-conf.h \
menu.c \
ui.c \
connection.c \
diff --git a/src/app.h b/src/app.h
index 6d3d4d9..9c2c69a 100644
--- a/src/app.h
+++ b/src/app.h
@@ -97,23 +97,6 @@ void set_icon_state (MyApp *app);
void tray_icon_init (MyApp *app);
void tray_icon_hide (MyApp *app);
-enum {
- ICON_IDLE,
- ICON_CONNECTING,
- ICON_MESSAGE,
- ICON_ERROR
-};
-
-#define CONFBASE "/apps/gnome-phone-manager"
-
-enum {
- CONNECTION_BLUETOOTH,
- CONNECTION_SERIAL1,
- CONNECTION_SERIAL2,
- CONNECTION_IRCOMM,
- CONNECTION_OTHER,
- CONNECTION_LAST
-};
-
+#include "phonemgr-conf.h"
#endif
diff --git a/src/phonemgr-conf.h b/src/phonemgr-conf.h
new file mode 100644
index 0000000..4911980
--- /dev/null
+++ b/src/phonemgr-conf.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2002-2004 Edd Dumbill <edd usefulinc com>
+ * Copyright (C) 2005-2007 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef _PHONEMGR_CONF_H
+#define _PHONEMGR_CONF_H
+
+#include <gconf/gconf-client.h>
+
+#define CONFBASE "/apps/gnome-phone-manager"
+
+enum {
+ CONNECTION_BLUETOOTH,
+ CONNECTION_SERIAL1,
+ CONNECTION_SERIAL2,
+ CONNECTION_IRCOMM,
+ CONNECTION_OTHER,
+ CONNECTION_NONE,
+ CONNECTION_LAST
+};
+
+#define PHONEMGR_DEVICE_TYPE_FILTER (BLUETOOTH_TYPE_PHONE | BLUETOOTH_TYPE_MODEM)
+
+#endif
+
diff --git a/src/ui.c b/src/ui.c
index d224082..7daf22d 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -63,7 +63,7 @@ chooser_created (BluetoothChooserButton *button, BluetoothChooser *chooser, gpoi
"show-searching", FALSE,
"show-pairing", FALSE,
"show-device-type", FALSE,
- "device-type-filter", BLUETOOTH_TYPE_PHONE,
+ "device-type-filter", PHONEMGR_DEVICE_TYPE_FILTER,
"show-device-category", FALSE,
"device-category-filter", BLUETOOTH_CATEGORY_PAIRED,
NULL);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]