diff options
author | Dan Winship <danw@redhat.com> | 2014-11-24 16:52:33 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2015-02-24 12:10:57 -0600 |
commit | eb36da69d35c95c84a4aaf12ba5983b0c1b4192f (patch) | |
tree | a31acb019ce2f4b2c88acc84578c7215775bbbd6 | |
parent | bac4091146ed1071357ce9560e2d8621794b8350 (diff) | |
download | network-manager-applet-eb36da69d35c95c84a4aaf12ba5983b0c1b4192f.tar.gz |
gnome-bluetooth: Drop the gnome-bluetooth plugin
The current version of gnome-bluetooth does not support plugins, so
there's no reason to keep this around any more.
-rw-r--r-- | configure.ac | 18 | ||||
-rw-r--r-- | po/POTFILES.in | 2 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/gnome-bluetooth/Makefile.am | 36 | ||||
-rw-r--r-- | src/gnome-bluetooth/bt-widget.c | 604 | ||||
-rw-r--r-- | src/gnome-bluetooth/nma-bt-device.c | 1123 | ||||
-rw-r--r-- | src/gnome-bluetooth/nma-bt-device.h | 84 |
7 files changed, 1 insertions, 1868 deletions
diff --git a/configure.ac b/configure.ac index 16bd67da..6843823b 100644 --- a/configure.ac +++ b/configure.ac @@ -100,23 +100,6 @@ AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) GTK_CFLAGS="$GTK_CFLAGS -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_4" -dnl Check for gnome-bluetooth -AC_ARG_WITH([bluetooth], - AS_HELP_STRING([--with-bluetooth|--without-bluetooth], [Enable Bluetooth support]), - with_bluetooth="$withval",with_bluetooth=yes) -have_gbt=no -case "${with_bluetooth}" in - no) AC_MSG_NOTICE(Bluetooth support disabled) - ;; - *) - PKG_CHECK_MODULES(GNOME_BLUETOOTH, - gnome-bluetooth-1.0 >= 2.27.6 - gnome-bluetooth-1.0 < 3.11.0 - libnm-util libnm-glib, - have_gbt=yes, have_gbt=no) - ;; -esac - AC_ARG_WITH([appindicator], AS_HELP_STRING([--with-appindicator|--without-appindicator], [Build with libappindicator support instead of xembed systray support.])) if test "$with_appindicator" == "yes"; then PKG_CHECK_MODULES(APPINDICATOR, appindicator3-0.1) @@ -180,7 +163,6 @@ src/utils/Makefile src/utils/tests/Makefile src/wireless-security/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 5df683ab..d8d30fac 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -73,8 +73,6 @@ src/connection-editor/page-wifi-security.c src/connection-editor/page-wimax.c src/connection-editor/vpn-helpers.c src/ethernet-dialog.c -src/gnome-bluetooth/bt-widget.c -src/gnome-bluetooth/nma-bt-device.c [type: gettext/glade]src/gsm-unlock.ui [type: gettext/glade]src/info.ui src/libnm-gtk/nm-mobile-wizard.c diff --git a/src/Makefile.am b/src/Makefile.am index d66c9d01..2aad0bf9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = utils wireless-security libnm-gtk connection-editor gnome-bluetooth +SUBDIRS = utils wireless-security libnm-gtk connection-editor bin_PROGRAMS = nm-applet diff --git a/src/gnome-bluetooth/Makefile.am b/src/gnome-bluetooth/Makefile.am deleted file mode 100644 index cdca2104..00000000 --- a/src/gnome-bluetooth/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ -AM_CPPFLAGS = \ - -DDATADIR=\"$(datadir)\" \ - -DICONDIR=\"$(icondir)\" \ - -DLOCALEDIR="\"$(datadir)/locale\"" \ - -I$(top_builddir) \ - -I${top_srcdir}/src/utils \ - -I${top_srcdir}/src/libnm-gtk \ - $(GNOME_BLUETOOTH_CFLAGS) \ - $(DISABLE_DEPRECATED) \ - $(WARN_CFLAGS) - -BT_WIDGET_SOURCES = \ - bt-widget.c \ - nma-bt-device.c \ - nma-bt-device.h - -if HAVE_GBT -plugindir = $(libdir)/gnome-bluetooth/plugins - -plugin_LTLIBRARIES = libnma.la - -libnma_la_SOURCES = $(BT_WIDGET_SOURCES) - -libnma_la_CPPFLAGS = $(AM_CPPFLAGS) $(MM_GLIB_CFLAGS) - -libnma_la_LDFLAGS = -module -avoid-version - -libnma_la_LIBADD = \ - $(top_builddir)/src/utils/libutils.la \ - $(top_builddir)/src/libnm-gtk/libnm-gtk.la \ - $(GNOME_BLUETOOTH_LIBS) \ - $(MM_GLIB_LIBS) - -endif - -EXTRA_DIST = $(BT_WIDGET_SOURCES) diff --git a/src/gnome-bluetooth/bt-widget.c b/src/gnome-bluetooth/bt-widget.c deleted file mode 100644 index 3195d6f8..00000000 --- a/src/gnome-bluetooth/bt-widget.c +++ /dev/null @@ -1,604 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * NetworkManager Applet - * - * 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 - * - * (C) Copyright 2009 - 2012 Red Hat, Inc. - * - */ - -#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 <dbus/dbus.h> -#include <bluetooth-plugin.h> -#include <bluetooth-client.h> -#include <nm-remote-settings.h> -#include <nm-remote-connection.h> - -#include "nma-bt-device.h" - -typedef struct { - NmaBtDevice *device; - BluetoothClient *btclient; - - GSList *sigids; - - GtkWidget *pan_button; - guint pan_toggled_id; - - GtkWidget *dun_button; - guint dun_toggled_id; - gboolean powered; - - GtkWidget *hbox; - GtkWidget *status; - GtkWidget *spinner; -} WidgetInfo; - -/***************************************************************/ - -static GHashTable *devices = NULL; - -static NmaBtDevice * -get_device (const char *bdaddr) -{ - if (G_UNLIKELY (devices == NULL)) - devices = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); - - return g_hash_table_lookup (devices, bdaddr); -} - -static void -add_device (NmaBtDevice *device) -{ - const char *bdaddr = nma_bt_device_get_bdaddr (device); - - if (get_device (bdaddr)) { - g_warning ("%s already exists in the device table!", bdaddr); - return; - } - - g_hash_table_insert (devices, (gpointer) bdaddr, device); -} - -static void -remove_device (NmaBtDevice *device) -{ - g_hash_table_remove (devices, device); -} - -/***************************************************************/ - -static void -get_capabilities (const char *bdaddr, - const char **uuids, - gboolean *pan, - gboolean *dun) -{ - guint i; - - g_return_if_fail (bdaddr != NULL); - g_return_if_fail (uuids != NULL); - g_return_if_fail (pan != NULL); - g_return_if_fail (*pan == FALSE); - g_return_if_fail (dun != NULL); - g_return_if_fail (*dun == FALSE); - - for (i = 0; uuids && uuids[i] != NULL; i++) { - g_message ("has_config_widget %s %s", bdaddr, uuids[i]); - if (g_str_equal (uuids[i], "NAP")) - *pan = TRUE; - if (g_str_equal (uuids[i], "DialupNetworking")) - *dun = TRUE; - } -} - -static gboolean -has_config_widget (const char *bdaddr, const char **uuids) -{ - gboolean pan = FALSE, dun = FALSE; - - get_capabilities (bdaddr, uuids, &pan, &dun); - return pan || dun; -} - -/***************************************************************/ - -static gboolean -get_device_iter (GtkTreeModel *model, const char *bdaddr, GtkTreeIter *out_iter) -{ - GtkTreeIter iter; - gboolean valid, child_valid; - - g_return_val_if_fail (model != NULL, FALSE); - g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE); - g_return_val_if_fail (bdaddr != NULL, FALSE); - g_return_val_if_fail (out_iter != NULL, FALSE); - - /* Loop over adapters */ - valid = gtk_tree_model_get_iter_first (model, &iter); - while (valid) { - /* Loop over devices */ - if (gtk_tree_model_iter_n_children (model, &iter)) { - child_valid = gtk_tree_model_iter_children (model, out_iter, &iter); - while (child_valid) { - char *addr = NULL; - gboolean good; - - gtk_tree_model_get (model, out_iter, BLUETOOTH_COLUMN_ADDRESS, &addr, -1); - good = (addr && !strcasecmp (addr, bdaddr)); - g_free (addr); - - if (good) - return TRUE; /* found */ - - child_valid = gtk_tree_model_iter_next (model, out_iter); - } - } - - valid = gtk_tree_model_iter_next (model, &iter); - } - - return FALSE; -} - -/*******************************************************************/ - -static void -pan_button_toggled (GtkToggleButton *button, WidgetInfo *info) -{ - nma_bt_device_set_pan_enabled (info->device, gtk_toggle_button_get_active (button)); -} - -static void -dun_button_toggled (GtkToggleButton *button, WidgetInfo *info) -{ - GtkWidget *parent; - - /* Update the toplevel for the mobile wizard now that the widget is - * realized. - */ - parent = gtk_widget_get_toplevel (info->hbox); - if (gtk_widget_is_toplevel (parent)) - nma_bt_device_set_parent_window (info->device, GTK_WINDOW (parent)); - - nma_bt_device_set_dun_enabled (info->device, gtk_toggle_button_get_active (button)); -} - -static void -widget_info_destroy (gpointer data) -{ - WidgetInfo *info = data; - GSList *iter; - - g_message ("%s: NM Bluetooth widget info being destroyed", __func__); - - g_signal_handlers_disconnect_matched (info->btclient, - G_SIGNAL_MATCH_DATA, 0, 0, NULL, - NULL, info); - g_object_unref (info->btclient); - - for (iter = info->sigids; iter; iter = g_slist_next (iter)) - g_signal_handler_disconnect (info->device, GPOINTER_TO_UINT (iter->data)); - g_slist_free (info->sigids); - - g_object_unref (info->device); - - memset (info, 0, sizeof (WidgetInfo)); - g_free (info); -} - -static void -set_dun_button_sensitive (WidgetInfo *info, gboolean sensitive) -{ - gtk_widget_set_sensitive (info->dun_button, - sensitive && info->powered && !nma_bt_device_get_busy (info->device)); -} - -static void -default_adapter_powered_changed (GObject *object, - GParamSpec *pspec, - WidgetInfo *info) -{ - gboolean powered = TRUE; - - g_object_get (G_OBJECT (info->btclient), "default-adapter-powered", &powered, NULL); - g_message ("Default Bluetooth adapter is %s", powered ? "powered" : "switched off"); - - /* If the default adapter isn't powered we can't inspect the device - * and create a connection for it. - */ - info->powered = powered; - if (powered) { - if (info->dun_button) { - gtk_label_set_text (GTK_LABEL (info->status), NULL); - set_dun_button_sensitive (info, TRUE); - } - } else { - /* powered only matters for DUN */ - if (info->dun_button) { - nma_bt_device_cancel_dun (info->device); - /* Can't toggle the DUN button unless the adapter is powered */ - set_dun_button_sensitive (info, FALSE); - } - } -} - -static void -default_adapter_changed (GObject *gobject, - GParamSpec *pspec, - WidgetInfo *info) -{ - char *adapter = NULL; - - g_object_get (G_OBJECT (gobject), "default-adapter", &adapter, NULL); - g_message ("Default Bluetooth adapter changed: %s", adapter ? adapter : "(none)"); - g_free (adapter); - - default_adapter_powered_changed (G_OBJECT (info->btclient), NULL, info); -} - -static void -device_pan_enabled_cb (NmaBtDevice *device, GParamSpec *pspec, WidgetInfo *info) -{ - g_signal_handler_block (info->pan_button, info->pan_toggled_id); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->pan_button), - nma_bt_device_get_pan_enabled (device)); - g_signal_handler_unblock (info->pan_button, info->pan_toggled_id); -} - -static void -device_dun_enabled_cb (NmaBtDevice *device, GParamSpec *pspec, WidgetInfo *info) -{ - g_signal_handler_block (info->dun_button, info->dun_toggled_id); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->dun_button), - nma_bt_device_get_dun_enabled (device)); - g_signal_handler_unblock (info->dun_button, info->dun_toggled_id); -} - -static void -device_busy_cb (NmaBtDevice *device, GParamSpec *pspec, WidgetInfo *info) -{ - gboolean busy = nma_bt_device_get_busy (device); - - if (info->pan_button) - gtk_widget_set_sensitive (info->pan_button, !busy); - if (info->dun_button) - set_dun_button_sensitive (info, !busy); - - if (busy) { - if (!info->spinner) { - info->spinner = gtk_spinner_new (); - gtk_box_pack_start (GTK_BOX (info->hbox), info->spinner, FALSE, FALSE, 6); - } - gtk_spinner_start (GTK_SPINNER (info->spinner)); - gtk_widget_show (info->spinner); - } else { - if (info->spinner) { - gtk_spinner_stop (GTK_SPINNER (info->spinner)); - gtk_widget_destroy (info->spinner); - info->spinner = NULL; - } - } -} - -static void -device_status_cb (NmaBtDevice *device, GParamSpec *pspec, WidgetInfo *info) -{ - gtk_label_set_text (GTK_LABEL (info->status), nma_bt_device_get_status (device)); -} - -static gboolean -nm_is_running (void) -{ - DBusConnection *bus; - DBusError error; - gboolean running = FALSE; - - dbus_error_init (&error); - bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error); - if (dbus_error_is_set (&error)) { - g_message (_("Bluetooth configuration not possible (failed to connect to D-Bus: (%s) %s)."), - error.name, error.message); - dbus_error_free (&error); - return FALSE; - } - - dbus_error_init (&error); - running = dbus_bus_name_has_owner (bus, NM_DBUS_SERVICE, &error); - if (dbus_error_is_set (&error)) { - g_message (_("Bluetooth configuration not possible (error finding NetworkManager: (%s) %s)."), - error.name, error.message); - } - - dbus_connection_unref (bus); - return running; -} - -static GtkWidget * -get_config_widgets (const char *bdaddr, const char **uuids) -{ - WidgetInfo *info; - NmaBtDevice *device; - GtkWidget *vbox, *hbox; - gboolean pan = FALSE, dun = FALSE, busy; - GtkTreeIter iter; - BluetoothClient *btclient; - GtkTreeModel *btmodel; - guint id; - - /* Don't allow configuration if NM isn't running; it just confuses people - * if they see the checkboxes but the configuration doesn't seem to have - * any visible effect since they aren't running NM/nm-applet. - */ - if (!nm_is_running ()) - return NULL; - - get_capabilities (bdaddr, uuids, &pan, &dun); - if (!pan && !dun) - return NULL; - - /* BluetoothClient setup */ - btclient = bluetooth_client_new (); - btmodel = bluetooth_client_get_model (btclient); - g_assert (btmodel); - - device = get_device (bdaddr); - if (!device) { - const char *op = NULL; - gpointer proxy; - char *alias; - - if (!get_device_iter (btmodel, bdaddr, &iter)) { - g_warning ("%s: failed to retrieve device %s from gnome-bluetooth!", __func__, bdaddr); - g_object_unref (btmodel); - g_object_unref (btclient); - return NULL; - } - - gtk_tree_model_get (btmodel, &iter, - BLUETOOTH_COLUMN_ALIAS, &alias, - BLUETOOTH_COLUMN_PROXY, &proxy, - -1); - g_assert (proxy); - - /* At some point gnome-bluetooth switched to gdbus, so we don't know - * if the proxy will be a DBusGProxy (dbus-glib) or a GDBusProxy (gdbus). - */ - if (G_IS_DBUS_PROXY (proxy)) - op = g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy)); - else if (DBUS_IS_G_PROXY (proxy)) - op = dbus_g_proxy_get_path (DBUS_G_PROXY (proxy)); - else - g_assert_not_reached (); - - device = nma_bt_device_new (bdaddr, alias, op, pan, dun); - g_free (alias); - g_object_unref (proxy); - - if (!device) { - g_warning ("%s: failed to create Bluetooth proxy object!", bdaddr); - g_object_unref (btmodel); - g_object_unref (btclient); - return NULL; - } - - add_device (device); - } - - info = g_malloc0 (sizeof (WidgetInfo)); - info->device = g_object_ref (device); - info->btclient = btclient; - - g_signal_connect (G_OBJECT (btclient), "notify::default-adapter", - G_CALLBACK (default_adapter_changed), info); - g_signal_connect (G_OBJECT (btclient), "notify::default-adapter-powered", - G_CALLBACK (default_adapter_powered_changed), info); - - id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_PAN_ENABLED, - G_CALLBACK (device_pan_enabled_cb), info); - info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id)); - - id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_DUN_ENABLED, - G_CALLBACK (device_dun_enabled_cb), info); - info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id)); - - id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_BUSY, - G_CALLBACK (device_busy_cb), info); - info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id)); - - id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_STATUS, - G_CALLBACK (device_status_cb), info); - info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id)); - - /* UI setup */ - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - g_object_set_data_full (G_OBJECT (vbox), "info", info, widget_info_destroy); - - busy = nma_bt_device_get_busy (device); - - if (pan) { - info->pan_button = gtk_check_button_new_with_label (_("Use your mobile phone as a network device (PAN/NAP)")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->pan_button), - nma_bt_device_get_pan_enabled (device)); - info->pan_toggled_id = g_signal_connect (G_OBJECT (info->pan_button), "toggled", G_CALLBACK (pan_button_toggled), info); - gtk_box_pack_start (GTK_BOX (vbox), info->pan_button, FALSE, TRUE, 6); - gtk_widget_set_sensitive (info->pan_button, !busy); - } - - if (dun) { - info->dun_button = gtk_check_button_new_with_label (_("Access the Internet using your mobile phone (DUN)")); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->dun_button), - nma_bt_device_get_dun_enabled (device)); - info->dun_toggled_id = g_signal_connect (G_OBJECT (info->dun_button), "toggled", G_CALLBACK (dun_button_toggled), info); - gtk_box_pack_start (GTK_BOX (vbox), info->dun_button, FALSE, TRUE, 6); - set_dun_button_sensitive (info, !busy); - } - - hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6); - - /* Spinner's hbox */ - info->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); - gtk_box_pack_start (GTK_BOX (hbox), info->hbox, FALSE, FALSE, 0); - - device_busy_cb (device, NULL, info); - - /* Status label */ - info->status = gtk_label_new (nma_bt_device_get_status (device)); - gtk_label_set_max_width_chars (GTK_LABEL (info->status), 80); - gtk_label_set_line_wrap (GTK_LABEL (info->status), TRUE); - gtk_box_pack_start (GTK_BOX (hbox), info->status, FALSE, TRUE, 6); - - default_adapter_powered_changed (G_OBJECT (info->btclient), NULL, info); - - return vbox; -} - -/**************************************************************/ - -typedef struct { - NMRemoteSettings *settings; - GByteArray *bdaddr; - char *str_bdaddr; - guint timeout_id; -} RemoveInfo; - -static void -remove_cleanup (RemoveInfo *info) -{ - g_object_unref (info->settings); - g_byte_array_free (info->bdaddr, TRUE); - g_free (info->str_bdaddr); - memset (info, 0, sizeof (RemoveInfo)); - g_free (info); -} - -static void -delete_cb (NMRemoteConnection *connection, GError *error, gpointer user_data) -{ - if (error) { - g_warning ("Error deleting connection: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); - } -} - -static void -remove_connections_read (NMRemoteSettings *settings, gpointer user_data) -{ - RemoveInfo *info = user_data; - GSList *list, *iter; - - g_source_remove (info->timeout_id); - - g_message ("Removing Bluetooth connections for %s", info->str_bdaddr); - - list = nm_remote_settings_list_connections (settings); - for (iter = list; iter != NULL; iter = g_slist_next (iter)) { - NMConnection *connection = iter->data; - NMSettingBluetooth *s_bt; - const GByteArray *tmp; - - s_bt = nm_connection_get_setting_bluetooth (connection); - if (s_bt) { - tmp = nm_setting_bluetooth_get_bdaddr (s_bt); - if (tmp && memcmp (tmp->data, info->bdaddr->data, tmp->len) == 0) - nm_remote_connection_delete (NM_REMOTE_CONNECTION (connection), delete_cb, NULL); - } - } - g_slist_free (list); - - remove_cleanup (info); -} - -static gboolean -remove_timeout (gpointer user_data) -{ - RemoveInfo *info = user_data; - - g_message ("Timed out removing Bluetooth connections for %s", info->str_bdaddr); - remove_cleanup (info); - return FALSE; -} - -static void -device_removed (const char *bdaddr) -{ - GError *error = NULL; - DBusGConnection *bus; - RemoveInfo *info; - struct ether_addr *addr; - NmaBtDevice *device; - - g_message ("Device '%s' was removed; deleting connections", bdaddr); - - /* Remove any connections associated with the deleted device */ - - addr = ether_aton (bdaddr); - if (!addr) { - g_warning ("Failed to convert Bluetooth address '%s'", bdaddr); - return; - } - - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (error || !bus) { - g_warning ("%s: failed to get a connection to D-Bus! %s", __func__, - error ? error->message : "(unknown)"); - g_clear_error (&error); - return; - } - - info = g_malloc0 (sizeof (RemoveInfo)); - info->settings = nm_remote_settings_new (bus); - - info->bdaddr = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (info->bdaddr, (const guint8 *) addr->ether_addr_octet, ETH_ALEN); - - info->str_bdaddr = g_strdup (bdaddr); - info->timeout_id = g_timeout_add_seconds (15, remove_timeout, info); - - g_signal_connect (info->settings, - NM_REMOTE_SETTINGS_CONNECTIONS_READ, - G_CALLBACK (remove_connections_read), - info); - - dbus_g_connection_unref (bus); - - /* Kill the device */ - device = get_device (bdaddr); - if (device) - remove_device (device); -} - -/**************************************************************/ - -static GbtPluginInfo plugin_info = { - "network-manager-applet", - has_config_widget, - get_config_widgets, - device_removed -}; - -GBT_INIT_PLUGIN(plugin_info) - diff --git a/src/gnome-bluetooth/nma-bt-device.c b/src/gnome-bluetooth/nma-bt-device.c deleted file mode 100644 index 853a6622..00000000 --- a/src/gnome-bluetooth/nma-bt-device.c +++ /dev/null @@ -1,1123 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * NetworkManager Applet - * - * Copyright (C) 2009 Bastien Nocera <hadess@hadess.net> - * Copyright (C) 2009 - 2010 Dan Williams <dcbw@redhat.com> - * - * 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 - * - * (C) Copyright 2009 - 2012 Red Hat, Inc. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <net/ethernet.h> -#include <netinet/ether.h> -#include <string.h> - -#include <glib.h> -#include <glib/gi18n-lib.h> - -#include <nm-remote-settings.h> -#include <nm-remote-connection.h> - -#include "nma-bt-device.h" -#include "nm-mobile-wizard.h" -#include "nm-utils.h" -#include "utils.h" - -#if WITH_WWAN -#include <libmm-glib.h> -#endif - -G_DEFINE_TYPE (NmaBtDevice, nma_bt_device, G_TYPE_OBJECT) - -#define NMA_BT_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NMA_TYPE_BT_DEVICE, NmaBtDevicePrivate)) - -typedef struct { - DBusGConnection *bus; - NMRemoteSettings *settings; - - char *bdaddr; - GByteArray *bdaddr_array; - char *alias; - char *object_path; - - char *status; - gboolean busy; - - gboolean has_pan; - gboolean pan_enabled; - gboolean has_dun; - gboolean dun_enabled; - - /* DUN stuff */ -#if WITH_WWAN - GDBusConnection *dbus_connection; - MMManager *modem_manager_1; - DBusGProxy *dun_proxy; - char *rfcomm_iface; - guint dun_timeout_id; -#endif - - GtkWindow *parent_window; - NMAMobileWizard *wizard; - GtkWindowGroup *window_group; -} NmaBtDevicePrivate; - - -enum { - PROP_0, - PROP_BDADDR, - PROP_ALIAS, - PROP_OBJECT_PATH, - PROP_HAS_PAN, - PROP_PAN_ENABLED, - PROP_HAS_DUN, - PROP_DUN_ENABLED, - PROP_BUSY, - PROP_STATUS, - - LAST_PROP -}; - -static void _set_pan_enabled (NmaBtDevice *device, gboolean enabled); -static void _set_dun_enabled (NmaBtDevice *device, gboolean enabled); - -#define DBUS_TYPE_G_MAP_OF_VARIANT (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) - -#define BLUEZ_SERVICE "org.bluez" -#define BLUEZ_MANAGER_PATH "/" -#define BLUEZ_MANAGER_INTERFACE "org.bluez.Manager" -#define BLUEZ_ADAPTER_INTERFACE "org.bluez.Adapter" -#define BLUEZ_DEVICE_INTERFACE "org.bluez.Device" -#define BLUEZ_SERIAL_INTERFACE "org.bluez.Serial" -#define BLUEZ_NETWORK_INTERFACE "org.bluez.Network" - -/*********************************************************************/ - -static gboolean -match_connection_bdaddr (NMConnection *connection, const GByteArray *bdaddr) -{ - NMSettingBluetooth *s_bt; - const GByteArray *tmp; - - s_bt = nm_connection_get_setting_bluetooth (connection); - if (s_bt) { - tmp = nm_setting_bluetooth_get_bdaddr (s_bt); - if (tmp && memcmp (tmp->data, bdaddr->data, tmp->len) == 0) - return TRUE; - } - return FALSE; -} - -static gboolean -match_connection_service (NMConnection *connection, - const GByteArray *bdaddr, - gboolean pan) -{ - NMSettingBluetooth *s_bt; - const char *type; - - if (!match_connection_bdaddr (connection, bdaddr)) - return FALSE; - - s_bt = nm_connection_get_setting_bluetooth (connection); - g_assert (s_bt); - type = nm_setting_bluetooth_get_connection_type (s_bt); - if (pan) { - if (g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_PANU) != 0) - return FALSE; - } else { - if (g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_DUN) != 0) - return FALSE; - } - - return TRUE; -} - -static void -delete_cb (NMRemoteConnection *connection, GError *error, gpointer user_data) -{ - if (error) { - g_warning ("Error deleting connection: (%d) %s", - error ? error->code : -1, - error && error->message ? error->message : "(unknown)"); - } -} - -static void -delete_connections_of_type (NMRemoteSettings *settings, - const GByteArray *bdaddr, - gboolean pan) -{ - GSList *list, *iter; - - list = nm_remote_settings_list_connections (settings); - for (iter = list; iter != NULL; iter = g_slist_next (iter)) { - NMRemoteConnection *remote = iter->data; - - if (match_connection_service (NM_CONNECTION (remote), bdaddr, pan)) - nm_remote_connection_delete (remote, delete_cb, NULL); - } - g_slist_free (list); -} - -static void -recheck_services_enabled (NmaBtDevice *self) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - GSList *list, *iter; - gboolean pan = FALSE, dun = FALSE; - - /* Retrieve initial enabled state for both PAN and DUN; if there are any - * existing Bluetooth connections for the given device for either PAN - * or DUN, then we consider that service enabled. - */ - list = nm_remote_settings_list_connections (priv->settings); - for (iter = list; iter != NULL; iter = g_slist_next (iter)) { - NMConnection *connection = iter->data; - - if (match_connection_bdaddr (connection, priv->bdaddr_array)) { - NMSettingBluetooth *s_bt; - const char *type; - - s_bt = nm_connection_get_setting_bluetooth (connection); - g_assert (s_bt); - type = nm_setting_bluetooth_get_connection_type (s_bt); - if (priv->has_pan && g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_PANU) == 0) - pan = TRUE; - else if (priv->has_dun && g_strcmp0 (type, NM_SETTING_BLUETOOTH_TYPE_DUN) == 0) - dun = TRUE; - } - } - g_slist_free (list); - - _set_pan_enabled (self, pan); - _set_dun_enabled (self, dun); -} - -/*********************************************************************/ - -const char * -nma_bt_device_get_bdaddr (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->bdaddr; -} - -gboolean -nma_bt_device_get_busy (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->busy; -} - -static void -_set_busy (NmaBtDevice *device, gboolean busy) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - - if (priv->busy != busy) { - priv->busy = busy; - g_object_notify (G_OBJECT (device), NMA_BT_DEVICE_BUSY); - } -} - -const char * -nma_bt_device_get_status (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->status; -} - -static void -_set_status (NmaBtDevice *device, const char *fmt, ...) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - va_list args; - - g_free (priv->status); - priv->status = NULL; - - if (fmt) { - va_start (args, fmt); - priv->status = g_strdup_vprintf (fmt, args); - va_end (args); - g_message ("%s", priv->status); - } - - g_object_notify (G_OBJECT (device), NMA_BT_DEVICE_STATUS); -} - -/*********************************************************************/ - -static void -dun_cleanup (NmaBtDevice *self) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - -#if WITH_WWAN - g_clear_object (&priv->dbus_connection); - g_clear_object (&priv->modem_manager_1); -#endif - - if (priv->dun_proxy && priv->rfcomm_iface) { - dbus_g_proxy_call_no_reply (priv->dun_proxy, "Disconnect", - G_TYPE_STRING, priv->rfcomm_iface, - G_TYPE_INVALID); - } - g_clear_object (&priv->dun_proxy); - - g_free (priv->rfcomm_iface); - priv->rfcomm_iface = NULL; - - if (priv->dun_timeout_id) { - g_source_remove (priv->dun_timeout_id); - priv->dun_timeout_id = 0; - } - - if (priv->wizard) { - nma_mobile_wizard_destroy (priv->wizard); - priv->wizard = NULL; - } -} - -static void -dun_error (NmaBtDevice *self, const char *func, GError *error, const char *fallback) -{ - g_warning ("%s: DUN error: %s", func, (error && error->message) ? error->message : fallback); - _set_status (self, _("Error: %s"), (error && error->message) ? error->message : fallback); - - _set_busy (self, FALSE); - dun_cleanup (self); - recheck_services_enabled (self); -} - -static NMConnection * -dun_new_cdma (NMAMobileWizardAccessMethod *method) -{ - NMConnection *connection; - NMSetting *setting; - char *uuid, *id; - - connection = nm_connection_new (); - - setting = nm_setting_cdma_new (); - g_object_set (setting, - NM_SETTING_CDMA_NUMBER, "#777", - NM_SETTING_CDMA_USERNAME, method->username, - NM_SETTING_CDMA_PASSWORD, method->password, - NULL); - nm_connection_add_setting (connection, setting); - - /* Serial setting */ - setting = nm_setting_serial_new (); - g_object_set (setting, - NM_SETTING_SERIAL_BAUD, 115200, - NM_SETTING_SERIAL_BITS, 8, - NM_SETTING_SERIAL_PARITY, 'n', - NM_SETTING_SERIAL_STOPBITS, 1, - NULL); - nm_connection_add_setting (connection, setting); - - nm_connection_add_setting (connection, nm_setting_ppp_new ()); - - setting = nm_setting_connection_new (); - id = utils_create_mobile_connection_id (method->provider_name, method->plan_name); - uuid = nm_utils_uuid_generate (); - g_object_set (setting, - NM_SETTING_CONNECTION_ID, id, - NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME, - NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, - NM_SETTING_CONNECTION_UUID, uuid, - NULL); - g_free (uuid); - g_free (id); - nm_connection_add_setting (connection, setting); - - return connection; -} - -static NMConnection * -dun_new_gsm (NMAMobileWizardAccessMethod *method) -{ - NMConnection *connection; - NMSetting *setting; - char *uuid, *id; - - connection = nm_connection_new (); - - setting = nm_setting_gsm_new (); - g_object_set (setting, - NM_SETTING_GSM_NUMBER, "*99#", - NM_SETTING_GSM_USERNAME, method->username, - NM_SETTING_GSM_PASSWORD, method->password, - NM_SETTING_GSM_APN, method->gsm_apn, - NULL); - nm_connection_add_setting (connection, setting); - - /* Serial setting */ - setting = nm_setting_serial_new (); - g_object_set (setting, - NM_SETTING_SERIAL_BAUD, 115200, - NM_SETTING_SERIAL_BITS, 8, - NM_SETTING_SERIAL_PARITY, 'n', - NM_SETTING_SERIAL_STOPBITS, 1, - NULL); - nm_connection_add_setting (connection, setting); - - nm_connection_add_setting (connection, nm_setting_ppp_new ()); - - setting = nm_setting_connection_new (); - id = utils_create_mobile_connection_id (method->provider_name, method->plan_name); - uuid = nm_utils_uuid_generate (); - g_object_set (setting, - NM_SETTING_CONNECTION_ID, id, - NM_SETTING_CONNECTION_TYPE, NM_SETTING_BLUETOOTH_SETTING_NAME, - NM_SETTING_CONNECTION_AUTOCONNECT, FALSE, - NM_SETTING_CONNECTION_UUID, uuid, - NULL); - g_free (uuid); - g_free (id); - nm_connection_add_setting (connection, setting); - - return connection; -} - -static void -dun_add_cb (NMRemoteSettings *settings, - NMRemoteConnection *connection, - GError *error, - gpointer user_data) -{ - NmaBtDevice *self = NMA_BT_DEVICE (user_data); - - if (error) - _set_status (self, _("Failed to create DUN connection: %s"), error->message); - else - _set_status (self, _("Your phone is now ready to use!")); - - _set_busy (self, FALSE); - dun_cleanup (self); - recheck_services_enabled (self); -} - -static void -wizard_done_cb (NMAMobileWizard *wizard, - gboolean canceled, - NMAMobileWizardAccessMethod *method, - gpointer user_data) -{ - NmaBtDevice *self = NMA_BT_DEVICE (user_data); - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - NMConnection *connection = NULL; - NMSetting *s_bt; - - g_return_if_fail (wizard == priv->wizard); - - g_message ("%s: mobile wizard done", __func__); - - if (canceled || !method) { - dun_error (self, __func__, NULL, _("Mobile wizard was canceled")); - return; - } - - if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) - connection = dun_new_cdma (method); - else if (method->devtype == NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) - connection = dun_new_gsm (method); - else { - dun_error (self, __func__, NULL, _("Unknown phone device type (not GSM or CDMA)")); - return; - } - - nma_mobile_wizard_destroy (priv->wizard); - priv->wizard = NULL; - - g_assert (connection); - - /* The Bluetooth settings */ - s_bt = nm_setting_bluetooth_new (); - g_object_set (G_OBJECT (s_bt), - NM_SETTING_BLUETOOTH_BDADDR, priv->bdaddr_array, - NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_DUN, - NULL); - nm_connection_add_setting (connection, s_bt); - - g_message ("%s: adding new setting", __func__); - - /* Add the connection to the settings service */ - nm_remote_settings_add_connection (priv->settings, - connection, - dun_add_cb, - self); - - g_message ("%s: waiting for add connection result...", __func__); -} - -static void -start_wizard (NmaBtDevice *self, - const gchar *path, - NMDeviceModemCapabilities caps) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - - if (priv->wizard) { - g_message ("%s: (%s) oops! not starting Wizard as one is already in progress", __func__, path); - return; - } - - g_message ("%s: (%s) starting the mobile wizard", __func__, path); - - g_source_remove (priv->dun_timeout_id); - priv->dun_timeout_id = 0; - - /* Start the mobile wizard */ - priv->wizard = nma_mobile_wizard_new (priv->parent_window, - priv->window_group, - caps, - FALSE, - wizard_done_cb, - self); - nma_mobile_wizard_present (priv->wizard); -} - -#if WITH_WWAN - -static gboolean -check_modem (NmaBtDevice *self, - MMObject *modem_object) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE; - MMModem *modem_iface; - const gchar *path; - const gchar *primary_port; - const gchar *iface_basename; - MMModemCapability mm_caps; - - path = mm_object_get_path (modem_object); - g_message ("%s: (%s) modem found", __func__, path); - - /* Ensure we have the 'Modem' interface at least */ - modem_iface = mm_object_peek_modem (modem_object); - g_return_val_if_fail (modem_iface != NULL, FALSE); - - /* Get modem's primary port */ - primary_port = mm_modem_get_primary_port (modem_iface); - g_return_val_if_fail (primary_port != NULL, FALSE); - - /* Get rfcomm iface name */ - iface_basename = g_path_get_basename (priv->rfcomm_iface); - - /* If not matched, just return */ - if (!g_str_equal (primary_port, iface_basename)) { - g_message ("%s: (%s) (%s) not the modem we're looking for (%s)", - __func__, path, primary_port, iface_basename); - return FALSE; - } - - /* This is the modem we were waiting for, so keep on */ - mm_caps = mm_modem_get_current_capabilities (modem_iface); - /* CDMA-only? */ - if (mm_caps == MM_MODEM_CAPABILITY_CDMA_EVDO) - caps = NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO; - /* GSM/UMTS-only? */ - else if (mm_caps == MM_MODEM_CAPABILITY_GSM_UMTS) - caps = NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS; - /* LTE? */ - else if (mm_caps & MM_MODEM_CAPABILITY_LTE) - caps = NM_DEVICE_MODEM_CAPABILITY_LTE; - else - g_message ("%s: (%s) unknown modem type", __func__, path); - - /* Launch wizard! */ - start_wizard (self, path, caps); - - return TRUE; -} - -static void -modem_object_added (MMManager *modem_manager, - MMObject *modem_object, - NmaBtDevice *self) -{ - check_modem (self, modem_object); -} - -#endif /* WITH_WWAN */ - -static void -dun_connect_cb (DBusGProxy *proxy, - DBusGProxyCall *call, - void *user_data) -{ - NmaBtDevice *self = NMA_BT_DEVICE (user_data); - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - GError *error = NULL; - char *device; -#if WITH_WWAN - GList *modems, *iter; - gboolean matched = FALSE; -#endif - - g_message ("%s: processing Connect reply", __func__); - - if (!dbus_g_proxy_end_call (proxy, call, &error, - G_TYPE_STRING, &device, - G_TYPE_INVALID)) { - dun_error (self, __func__, error, _("failed to connect to the phone.")); - g_clear_error (&error); - goto out; - } - - if (!device || !strlen (device)) { - dun_error (self, __func__, NULL, _("failed to connect to the phone.")); - g_free (device); - goto out; - } - - g_free (priv->rfcomm_iface); - priv->rfcomm_iface = device; - g_message ("%s: new rfcomm interface '%s'", __func__, device); - -#if WITH_WWAN - /* ModemManager1 stuff */ - priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error); - if (!priv->dbus_connection) { - dun_error (self, __func__, error, _("error getting bus connection")); - g_error_free (error); - goto out; - } - - priv->modem_manager_1 = mm_manager_new_sync (priv->dbus_connection, - G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, - NULL, - &error); - if (!priv->modem_manager_1) { - dun_error (self, __func__, error, "error creating modem manager"); - g_error_free (error); - goto out; - } - - modems = g_dbus_object_manager_get_objects (G_DBUS_OBJECT_MANAGER (priv->modem_manager_1)); - for (iter = modems; iter; iter = iter->next) { - if (check_modem (self, iter->data)) { - matched = TRUE; - break; - } - } - g_list_free_full (modems, g_object_unref); - - if (!matched) { - g_signal_connect (priv->modem_manager_1, - "object-added", - G_CALLBACK (modem_object_added), - self); - } -#endif - -out: - g_message ("%s: finished", __func__); -} - -static void -dun_property_changed (DBusGProxy *proxy, - const char *property, - GValue *value, - gpointer user_data) -{ - NmaBtDevice *self = NMA_BT_DEVICE (user_data); - gboolean connected; - - if (strcmp (property, "Connected") == 0) { - connected = g_value_get_boolean (value); - g_message ("%s: device property Connected changed to %s", - __func__, - connected ? "TRUE" : "FALSE"); - - if (connected) { - /* Wait for MM here ? */ - } else - dun_error (self, __func__, NULL, _("unexpectedly disconnected from the phone.")); - } -} - -static gboolean -dun_timeout_cb (gpointer user_data) -{ - NmaBtDevice *self = NMA_BT_DEVICE (user_data); - - NMA_BT_DEVICE_GET_PRIVATE (self)->dun_timeout_id = 0; - dun_error (self, __func__, NULL, _("timed out detecting phone details.")); - return FALSE; -} - -static void -dun_start (NmaBtDevice *self) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - - g_message ("%s: starting DUN device discovery...", __func__); - - _set_status (self, _("Detecting phone configuration...")); - - /* Bluez */ - priv->dun_proxy = dbus_g_proxy_new_for_name (priv->bus, - BLUEZ_SERVICE, - priv->object_path, - BLUEZ_SERIAL_INTERFACE); - g_assert (priv->dun_proxy); - - priv->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, self); - - g_message ("%s: calling Connect...", __func__); - - /* Watch for BT device property changes */ - dbus_g_object_register_marshaller (g_cclosure_marshal_generic, - G_TYPE_NONE, - G_TYPE_STRING, G_TYPE_VALUE, - G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->dun_proxy, "PropertyChanged", - G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->dun_proxy, "PropertyChanged", - G_CALLBACK (dun_property_changed), self, NULL); - - /* Request a connection to the device and get the port */ - dbus_g_proxy_begin_call_with_timeout (priv->dun_proxy, "Connect", - dun_connect_cb, - self, - NULL, - 20000, - G_TYPE_STRING, "dun", - G_TYPE_INVALID); - - g_message ("%s: waiting for Connect success...", __func__); -} - -gboolean -nma_bt_device_get_has_dun (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->has_dun; -} - -gboolean -nma_bt_device_get_dun_enabled (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->dun_enabled; -} - -static void -_set_dun_enabled (NmaBtDevice *device, gboolean enabled) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - - if (priv->dun_enabled != enabled) { - priv->dun_enabled = enabled; - g_object_notify (G_OBJECT (device), NMA_BT_DEVICE_DUN_ENABLED); - } -} - -void -nma_bt_device_set_dun_enabled (NmaBtDevice *device, gboolean enabled) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - - _set_dun_enabled (device, enabled); - - if (enabled) { - _set_busy (device, TRUE); - dun_start (device); - } else - delete_connections_of_type (priv->settings, priv->bdaddr_array, FALSE); -} - -void -nma_bt_device_cancel_dun (NmaBtDevice *device) -{ - dun_error (device, __func__, NULL, _("The default Bluetooth adapter must be enabled before setting up a Dial-Up-Networking connection.")); -} - -/*********************************************************************/ - -gboolean -nma_bt_device_get_has_pan (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->has_pan; -} - -gboolean -nma_bt_device_get_pan_enabled (NmaBtDevice *device) -{ - return NMA_BT_DEVICE_GET_PRIVATE (device)->pan_enabled; -} - -static void -_set_pan_enabled (NmaBtDevice *device, gboolean enabled) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - - if (priv->pan_enabled != enabled) { - priv->pan_enabled = enabled; - g_object_notify (G_OBJECT (device), NMA_BT_DEVICE_PAN_ENABLED); - } -} - -static void -pan_add_cb (NMRemoteSettings *settings, - NMRemoteConnection *connection, - GError *error, - gpointer user_data) -{ - NmaBtDevice *self = NMA_BT_DEVICE (user_data); - - if (error) - _set_status (self, _("Failed to create PAN connection: %s"), error->message); - else - _set_status (self, _("Your phone is now ready to use!")); - - recheck_services_enabled (self); - _set_busy (self, FALSE); -} - -static void -add_pan_connection (NmaBtDevice *self) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - NMSetting *setting, *bt_setting, *ip_setting; - char *id, *uuid; - - /* The connection */ - connection = nm_connection_new (); - - /* The connection settings */ - setting = nm_setting_connection_new (); - id = g_strdup_printf (_("%s Network"), priv->alias ? priv->alias : priv->bdaddr); - 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, priv->bdaddr_array, - NM_SETTING_BLUETOOTH_TYPE, NM_SETTING_BLUETOOTH_TYPE_PANU, - NULL); - nm_connection_add_setting (connection, bt_setting); - - /* IPv4 */ - 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, - NM_SETTING_IP4_CONFIG_MAY_FAIL, FALSE, - NULL); - nm_connection_add_setting (connection, ip_setting); - - /* IPv6 */ - ip_setting = nm_setting_ip6_config_new (); - g_object_set (G_OBJECT (ip_setting), - NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, - NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE, - NULL); - nm_connection_add_setting (connection, ip_setting); - - /* Add the connection to the settings service */ - nm_remote_settings_add_connection (priv->settings, - connection, - pan_add_cb, - self); -} - -void -nma_bt_device_set_pan_enabled (NmaBtDevice *device, gboolean enabled) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - - _set_pan_enabled (device, enabled); - - if (enabled) { - _set_busy (device, TRUE); - add_pan_connection (device); - } else - delete_connections_of_type (priv->settings, priv->bdaddr_array, TRUE); -} - -/*********************************************************************/ - -void -nma_bt_device_set_parent_window (NmaBtDevice *device, GtkWindow *window) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (device); - - if (window == priv->parent_window) - return; - - if (priv->parent_window) { - gtk_window_group_remove_window (priv->window_group, priv->parent_window); - g_object_unref (priv->parent_window); - } - priv->parent_window = g_object_ref (window); - gtk_window_group_add_window (priv->window_group, window); -} - -/*********************************************************************/ - -static void -connections_read (NMRemoteSettings *settings, gpointer user_data) -{ - recheck_services_enabled (NMA_BT_DEVICE (user_data)); -} - -NmaBtDevice * -nma_bt_device_new (const char *bdaddr, - const char *alias, - const char *object_path, - gboolean has_pan, - gboolean has_dun) -{ - NmaBtDevice *self; - GError *error = NULL; - - g_return_val_if_fail (bdaddr != NULL, NULL); - g_return_val_if_fail (object_path != NULL, NULL); - - self = (NmaBtDevice *) g_object_new (NMA_TYPE_BT_DEVICE, - NMA_BT_DEVICE_BDADDR, bdaddr, - NMA_BT_DEVICE_ALIAS, alias, - NMA_BT_DEVICE_OBJECT_PATH, object_path, - NMA_BT_DEVICE_HAS_PAN, has_pan, - NMA_BT_DEVICE_HAS_DUN, has_dun, - NULL); - if (self) { - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (self); - struct ether_addr *addr; - - g_assert (priv->bdaddr); - g_assert (priv->object_path); - - addr = ether_aton (priv->bdaddr); - if (!addr) { - g_warning ("%s: invalid Bluetooth address '%s'", __func__, priv->bdaddr); - g_object_unref (self); - return NULL; - } - - priv->bdaddr_array = g_byte_array_sized_new (ETH_ALEN); - g_byte_array_append (priv->bdaddr_array, (const guint8 *) addr->ether_addr_octet, ETH_ALEN); - - priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - if (error) { - g_warning ("%s: failed to connect to D-Bus: %s", __func__, error->message); - g_object_unref (self); - self = NULL; - } - - priv->window_group = gtk_window_group_new (); - - priv->settings = nm_remote_settings_new (priv->bus); - g_signal_connect (priv->settings, - NM_REMOTE_SETTINGS_CONNECTIONS_READ, - G_CALLBACK (connections_read), - self); - } - return self; -} - -static void -nma_bt_device_init (NmaBtDevice *self) -{ -} - -static void -get_property (GObject *object, guint prop_id, - GValue *value, GParamSpec *pspec) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_BDADDR: - g_value_set_string (value, priv->bdaddr); - break; - case PROP_ALIAS: - g_value_set_string (value, priv->alias); - break; - case PROP_OBJECT_PATH: - g_value_set_string (value, priv->object_path); - break; - case PROP_HAS_PAN: - g_value_set_boolean (value, priv->has_pan); - break; - case PROP_PAN_ENABLED: - g_value_set_boolean (value, priv->pan_enabled); - break; - case PROP_HAS_DUN: - g_value_set_boolean (value, priv->has_dun); - break; - case PROP_DUN_ENABLED: - g_value_set_boolean (value, priv->dun_enabled); - break; - case PROP_BUSY: - g_value_set_boolean (value, priv->busy); - break; - case PROP_STATUS: - g_value_set_string (value, priv->status); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -set_property (GObject *object, guint prop_id, - const GValue *value, GParamSpec *pspec) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (object); - - switch (prop_id) { - case PROP_BDADDR: - priv->bdaddr = g_value_dup_string (value); - break; - case PROP_ALIAS: - priv->alias = g_value_dup_string (value); - break; - case PROP_OBJECT_PATH: - priv->object_path = g_value_dup_string (value); - break; - case PROP_HAS_PAN: - priv->has_pan = g_value_get_boolean (value); - break; - case PROP_HAS_DUN: - priv->has_dun = g_value_get_boolean (value); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -dispose (GObject *object) -{ - NmaBtDevicePrivate *priv = NMA_BT_DEVICE_GET_PRIVATE (object); - - dun_cleanup (NMA_BT_DEVICE (object)); - - g_free (priv->bdaddr); - priv->bdaddr = NULL; - g_free (priv->alias); - priv->alias = NULL; - g_free (priv->object_path); - priv->object_path = NULL; - g_free (priv->status); - priv->status = NULL; - - g_clear_object (&priv->window_group); - g_clear_object (&priv->parent_window); - - if (priv->bdaddr_array) { - g_byte_array_free (priv->bdaddr_array, TRUE); - priv->bdaddr_array = NULL; - } - - G_OBJECT_CLASS (nma_bt_device_parent_class)->dispose (object); -} - -static void -nma_bt_device_class_init (NmaBtDeviceClass *btdevice_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (btdevice_class); - - g_type_class_add_private (btdevice_class, sizeof (NmaBtDevicePrivate)); - - /* virtual methods */ - object_class->get_property = get_property; - object_class->set_property = set_property; - object_class->dispose = dispose; - - /* properties */ - g_object_class_install_property (object_class, PROP_BDADDR, - g_param_spec_string (NMA_BT_DEVICE_BDADDR, - "Bluetooth address", - "Bluetooth address", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, PROP_ALIAS, - g_param_spec_string (NMA_BT_DEVICE_ALIAS, - "Bluetooth alias", - "Bluetooth alias", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, PROP_OBJECT_PATH, - g_param_spec_string (NMA_BT_DEVICE_OBJECT_PATH, - "Bluez object path", - "Bluez object path", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, PROP_HAS_PAN, - g_param_spec_boolean (NMA_BT_DEVICE_HAS_PAN, - "PAN capable", - "PAN capable", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, PROP_PAN_ENABLED, - g_param_spec_boolean (NMA_BT_DEVICE_PAN_ENABLED, - "PAN enabled", - "PAN enabled", - FALSE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_HAS_DUN, - g_param_spec_boolean (NMA_BT_DEVICE_HAS_DUN, - "DUN capable", - "DUN capable", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); - - g_object_class_install_property (object_class, PROP_DUN_ENABLED, - g_param_spec_boolean (NMA_BT_DEVICE_DUN_ENABLED, - "DUN enabled", - "DUN enabled", - FALSE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_BUSY, - g_param_spec_boolean (NMA_BT_DEVICE_BUSY, - "Busy", - "Busy", - FALSE, - G_PARAM_READABLE)); - - g_object_class_install_property (object_class, PROP_STATUS, - g_param_spec_string (NMA_BT_DEVICE_STATUS, - "Status", - "Status", - NULL, - G_PARAM_READABLE)); -} diff --git a/src/gnome-bluetooth/nma-bt-device.h b/src/gnome-bluetooth/nma-bt-device.h deleted file mode 100644 index a09fedbd..00000000 --- a/src/gnome-bluetooth/nma-bt-device.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* - * NetworkManager Applet - * - * 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 - * - * (C) Copyright 2009 - 2012 Red Hat, Inc. - * - */ - -#ifndef NMA_BT_DEVICE_H -#define NMA_BT_DEVICE_H - -#include <glib.h> -#include <glib-object.h> -#include <gtk/gtk.h> -#include <dbus/dbus-glib.h> - -#define NMA_TYPE_BT_DEVICE (nma_bt_device_get_type ()) -#define NMA_BT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMA_TYPE_BT_DEVICE, NmaBtDevice)) -#define NMA_BT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMA_TYPE_BT_DEVICE, NmaBtDeviceClass)) -#define NMA_IS_BT_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMA_TYPE_BT_DEVICE)) -#define NMA_IS_BT_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NMA_TYPE_BT_DEVICE)) -#define NMA_BT_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMA_TYPE_BT_DEVICE, NmaBtDeviceClass)) - -#define NMA_BT_DEVICE_BDADDR "bdaddr" -#define NMA_BT_DEVICE_ALIAS "alias" -#define NMA_BT_DEVICE_OBJECT_PATH "object-path" -#define NMA_BT_DEVICE_HAS_PAN "has-pan" -#define NMA_BT_DEVICE_PAN_ENABLED "pan-enabled" -#define NMA_BT_DEVICE_HAS_DUN "has-dun" -#define NMA_BT_DEVICE_DUN_ENABLED "dun-enabled" -#define NMA_BT_DEVICE_BUSY "busy" -#define NMA_BT_DEVICE_STATUS "status" - -typedef struct { - GObject parent; -} NmaBtDevice; - -typedef struct { - GObjectClass parent; -} NmaBtDeviceClass; - -GType nma_bt_device_get_type (void); - -NmaBtDevice *nma_bt_device_new (const char *bdaddr, - const char *alias, - const char *object_path, - gboolean has_pan, - gboolean has_dun); - -void nma_bt_device_set_parent_window (NmaBtDevice *device, - GtkWindow *window); - -const char *nma_bt_device_get_bdaddr (NmaBtDevice *device); - -gboolean nma_bt_device_get_has_dun (NmaBtDevice *device); -gboolean nma_bt_device_get_dun_enabled (NmaBtDevice *device); -void nma_bt_device_set_dun_enabled (NmaBtDevice *device, gboolean enabled); - -void nma_bt_device_cancel_dun (NmaBtDevice *device); - -gboolean nma_bt_device_get_has_pan (NmaBtDevice *device); -gboolean nma_bt_device_get_pan_enabled (NmaBtDevice *device); -void nma_bt_device_set_pan_enabled (NmaBtDevice *device, gboolean enabled); - -gboolean nma_bt_device_get_busy (NmaBtDevice *device); - -const char *nma_bt_device_get_status (NmaBtDevice *device); - -#endif /* NMA_BT_DEVICE_H */ - |