[network-manager-applet] bluetooth: add GNOME Bluetooth plugin for PAN connections
- From: Dan Williams <dcbw src gnome org>
- To: svn-commits-list gnome org
- Subject: [network-manager-applet] bluetooth: add GNOME Bluetooth plugin for PAN connections
- Date: Wed, 1 Jul 2009 18:21:45 +0000 (UTC)
commit 3bec17daa718354e22ca9b5116a91a4cf594eeee
Author: Bastien Nocera <hadess hadess net>
Date: Wed Jul 1 14:20:05 2009 -0400
bluetooth: add GNOME Bluetooth plugin for PAN connections
configure.ac | 10 ++
po/POTFILES.in | 1 +
src/Makefile.am | 2 +-
src/gnome-bluetooth/Makefile.am | 20 +++
src/gnome-bluetooth/network-manager-applet.c | 224 ++++++++++++++++++++++++++
5 files changed, 256 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 79d0c06..8fb6b51 100644
--- a/configure.ac
+++ b/configure.ac
@@ -189,6 +189,15 @@ else
fi
AC_SUBST(DBUS_SYS_DIR)
+dnl Check for gnome-bluetooth
+PKG_CHECK_MODULES(GNOME_BLUETOOTH,
+ gconf-2.0
+ gnome-bluetooth-1.0 >= 2.27.6
+ libnm-util
+ libnm_glib,
+ have_gbt=yes, have_gbt=no)
+AM_CONDITIONAL(HAVE_GBT, test x"$have_gbt" = "xyes")
+
GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
AC_SUBST(GLIB_GENMARSHAL)
@@ -203,6 +212,7 @@ src/gconf-helpers/Makefile
src/wireless-security/Makefile
src/polkit-helpers/Makefile
src/connection-editor/Makefile
+src/gnome-bluetooth/Makefile
icons/Makefile
icons/16/Makefile
icons/22/Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 29fbce2..80a3b60 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -36,6 +36,7 @@ src/connection-editor/nm-connection-editor.c
src/connection-editor/nm-connection-editor.glade
src/connection-editor/nm-connection-list.c
src/connection-editor/vpn-helpers.c
+src/gnome-bluetooth/network-manager-applet.c
src/keyring.png
src/main.c
src/utils/mobile-wizard.c
diff --git a/src/Makefile.am b/src/Makefile.am
index d85c5f5..69e32d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = marshallers utils gconf-helpers wireless-security polkit-helpers connection-editor
+SUBDIRS = marshallers utils gconf-helpers wireless-security polkit-helpers connection-editor gnome-bluetooth
bin_PROGRAMS = nm-applet
diff --git a/src/gnome-bluetooth/Makefile.am b/src/gnome-bluetooth/Makefile.am
new file mode 100644
index 0000000..164c9dc
--- /dev/null
+++ b/src/gnome-bluetooth/Makefile.am
@@ -0,0 +1,20 @@
+plugindir = $(libdir)/gnome-bluetooth/plugins/
+
+INCLUDES = \
+ -DDATADIR=\"$(datadir)\" \
+ -DICONDIR=\"$(icondir)\" \
+ -DLOCALEDIR="\"$(datadir)/locale\"" \
+ -I$(top_srcdir)/src/gconf-helpers/ \
+ -I$(top_builddir) \
+ $(GNOME_BLUETOOTH_CFLAGS) \
+ $(WARN_CFLAGS)
+
+if HAVE_GBT
+plugin_LTLIBRARIES = libnma.la
+
+libnma_la_SOURCES = network-manager-applet.c
+libnma_la_LDFLAGS = -module -avoid-version
+libnma_la_LIBADD = $(top_builddir)/src/gconf-helpers/libgconf-helpers.la $(GNOME_BLUETOOTH_LIBS)
+endif
+
+EXTRA_DIST = network-manager-applet.c
diff --git a/src/gnome-bluetooth/network-manager-applet.c b/src/gnome-bluetooth/network-manager-applet.c
new file mode 100644
index 0000000..3cdd5b5
--- /dev/null
+++ b/src/gnome-bluetooth/network-manager-applet.c
@@ -0,0 +1,224 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2009 Bastien Nocera <hadess hadess net>
+ *
+ *
+ * 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 <net/ethernet.h>
+#include <netinet/ether.h>
+#include <glib/gi18n-lib.h>
+
+#include <gtk/gtk.h>
+#include <bluetooth-plugin.h>
+#include <nm-setting-connection.h>
+#include <nm-setting-bluetooth.h>
+#include <nm-setting-ip4-config.h>
+#include <nm-utils.h>
+#include <nma-gconf-settings.h>
+
+static gboolean
+has_config_widget (const char *bdaddr, const char **uuids)
+{
+ guint i;
+
+ for (i = 0; uuids && uuids[i] != NULL; i++) {
+ g_message ("has_config_widget %s %s", bdaddr, uuids[i]);
+ if (g_str_equal (uuids[i], "PANU"))
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static GByteArray *
+get_array_from_bdaddr (const char *str)
+{
+ struct ether_addr *addr;
+ GByteArray *array;
+
+ addr = ether_aton (str);
+ if (addr) {
+ array = g_byte_array_sized_new (ETH_ALEN);
+ g_byte_array_append (array, (const guint8 *) addr->ether_addr_octet, ETH_ALEN);
+ return array;
+ }
+
+ return NULL;
+}
+
+static NMExportedConnection *
+add_setup (const char *bdaddr)
+{
+ NMConnection *connection;
+ NMSetting *setting, *bt_setting, *ip_setting;
+ NMAGConfSettings *gconf_settings;
+ NMAGConfConnection *exported;
+ GByteArray *mac;
+ char *id, *uuid;
+
+ mac = get_array_from_bdaddr (bdaddr);
+ if (mac == NULL)
+ return NULL;
+
+ /* The connection */
+ connection = nm_connection_new ();
+
+ /* The connection settings */
+ setting = nm_setting_connection_new ();
+ id = g_strdup_printf ("%s %s", bdaddr, "PANU");
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (G_OBJECT (setting),
+ NM_SETTING_CONNECTION_ID, id,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME,
+ NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
+ NULL);
+ g_free (id);
+ g_free (uuid);
+ nm_connection_add_setting (connection, setting);
+
+ /* The Bluetooth settings */
+ bt_setting = nm_setting_bluetooth_new ();
+ g_object_set (G_OBJECT (bt_setting),
+ NM_SETTING_BLUETOOTH_BDADDR, mac,
+ NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_PANU,
+ NULL);
+ g_byte_array_free (mac, TRUE);
+ nm_connection_add_setting (connection, bt_setting);
+
+ /* The IPv4 settings */
+ ip_setting = nm_setting_ip4_config_new ();
+ g_object_set (G_OBJECT (ip_setting),
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NULL);
+ nm_connection_add_setting (connection, ip_setting);
+
+ gconf_settings = nma_gconf_settings_new ();
+ exported = nma_gconf_settings_add_connection (gconf_settings, connection);
+
+ if (exported != NULL)
+ return NM_EXPORTED_CONNECTION (exported);
+ return NULL;
+}
+
+static void
+button_toggled (GtkToggleButton *button, gpointer user_data)
+{
+ NMExportedConnection *exported;
+ const char *bdaddr;
+
+ bdaddr = g_object_get_data (G_OBJECT (button), "bdaddr");
+ g_assert (bdaddr);
+
+ if (gtk_toggle_button_get_active (button) == FALSE) {
+ exported = g_object_get_data (G_OBJECT (button), "conn");
+ nm_exported_connection_delete (exported, NULL);
+ g_object_set_data (G_OBJECT (button), "conn", NULL);
+ } else {
+ exported = add_setup (bdaddr);
+ g_object_set_data (G_OBJECT (button), "conn", exported);
+ }
+}
+
+static NMExportedConnection *
+get_connection_for_bdaddr (const char *bdaddr)
+{
+ NMExportedConnection *result = NULL;
+ NMSettings *settings;
+ GSList *list, *l;
+ GByteArray *array;
+
+ array = get_array_from_bdaddr (bdaddr);
+ if (array == NULL)
+ return NULL;
+
+ settings = NM_SETTINGS (nma_gconf_settings_new ());
+ list = nm_settings_list_connections (settings);
+ for (l = list; l != NULL; l = l->next) {
+ NMExportedConnection *exported = l->data;
+ NMConnection *conn = nm_exported_connection_get_connection (exported);
+ NMSetting *setting;
+ const char *type;
+ const GByteArray *addr;
+
+ setting = nm_connection_get_setting_by_name (conn, NM_SETTING_BLUETOOTH_SETTING_NAME);
+ if (setting == NULL)
+ continue;
+ type = nm_setting_bluetooth_get_connection_type (NM_SETTING_BLUETOOTH (setting));
+ if (g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_PANU) != 0)
+ continue;
+ addr = nm_setting_bluetooth_get_bdaddr (NM_SETTING_BLUETOOTH (setting));
+ if (addr == NULL || memcmp (addr->data, array->data, addr->len) != 0)
+ continue;
+ result = exported;
+ break;
+ }
+ g_slist_free (list);
+
+ return result;
+}
+
+static GtkWidget *
+get_config_widgets (const char *bdaddr, const char **uuids)
+{
+ GtkWidget *button;
+ NMExportedConnection *conn;
+
+ button = gtk_check_button_new_with_label (_("Access the Internet using your mobile phone"));
+ g_object_set_data_full (G_OBJECT (button),
+ "bdaddr", g_strdup (bdaddr),
+ (GDestroyNotify) g_free);
+ conn = get_connection_for_bdaddr (bdaddr);
+ if (conn != NULL) {
+ g_object_set_data (G_OBJECT (button), "conn", conn);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ }
+ g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (button_toggled), NULL);
+
+ return button;
+}
+
+static void
+device_removed (const char *bdaddr)
+{
+ NMExportedConnection *exported;
+
+ g_message ("Device '%s' got removed", bdaddr);
+
+ // FIXME: don't just delete any random PAN conenction for this
+ // bdaddr, actually delete the one this plugin created
+ exported = get_connection_for_bdaddr (bdaddr);
+ if (exported)
+ nm_exported_connection_delete (exported, NULL);
+}
+
+static GbtPluginInfo plugin_info = {
+ "network-manager-applet",
+ has_config_widget,
+ get_config_widgets,
+ device_removed
+};
+
+GBT_INIT_PLUGIN(plugin_info)
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]