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 GtkWidget * get_config_widgets (const char *bdaddr, const char **uuids) { PluginInfo *info; GtkWidget *vbox, *hbox; gboolean pan = FALSE, dun = FALSE; /* 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/bm-applet. */ if (!bm_is_running ()) return NULL; get_capabilities (bdaddr, uuids, &pan, &dun); if (!pan && !dun) return NULL; info = g_malloc0 (sizeof (PluginInfo)); info->settings = BM_SETTINGS_INTERFACE (nma_gconf_settings_new (NULL)); info->bdaddr = g_strdup (bdaddr); info->pan = pan; info->dun = dun; /* BluetoothClient setup */ info->btclient = bluetooth_client_new (); info->btmodel = bluetooth_client_get_model (info->btclient); g_signal_connect (G_OBJECT (info->btclient), "notify::default-adapter", G_CALLBACK (default_adapter_changed), info); g_signal_connect (G_OBJECT (info->btclient), "notify::default-adapter-powered", G_CALLBACK (default_adapter_powered_changed), info); /* UI setup */ vbox = gtk_vbox_new (FALSE, 6); g_object_set_data_full (G_OBJECT (vbox), "info", info, plugin_info_destroy); if (pan) { info->pan_connection = get_connection_for_bdaddr (info->settings, bdaddr, TRUE); info->pan_button = gtk_check_button_new_with_label (_("Use your mobile phone as a network device (PAN/NAP)")); if (info->pan_connection) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->pan_button), TRUE); 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); } if (dun) { info->dun_connection = get_connection_for_bdaddr (info->settings, bdaddr, FALSE); info->dun_button = gtk_check_button_new_with_label (_("Access the Internet using your mobile phone (DUN)")); if (info->dun_connection) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->dun_button), TRUE); 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); } hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6); /* Spinner's hbox */ info->hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (hbox), info->hbox, FALSE, FALSE, 0); info->label = gtk_label_new (""); gtk_box_pack_start (GTK_BOX (hbox), info->label, FALSE, TRUE, 6); default_adapter_powered_changed (G_OBJECT (info->btclient), NULL, info); return vbox; }
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; }