void setup_adapter(GtkNotebook *_notebook) { killswitch = bluetooth_killswitch_new (); notebook = _notebook; /* Create our static pages first */ create_killswitch_page (notebook); create_no_adapter_page (notebook, "properties-no-adapter.ui"); create_no_adapter_page (notebook, "properties-killed-adapter.ui"); client = bluetooth_client_new(); adapter_model = bluetooth_client_get_adapter_model(client); g_signal_connect_after(G_OBJECT(adapter_model), "row-inserted", G_CALLBACK(adapter_added), notebook); g_signal_connect_after(G_OBJECT(adapter_model), "row-deleted", G_CALLBACK(adapter_removed), notebook); g_signal_connect_after (G_OBJECT(adapter_model), "row-changed", G_CALLBACK (adapter_changed), notebook); gtk_tree_model_foreach(adapter_model, adapter_insert, notebook); set_current_page (notebook); }
int setup_agents(void) { dbus_g_error_domain_register(AGENT_ERROR, "org.bluez.Error", AGENT_ERROR_TYPE); client = bluetooth_client_new(); g_signal_connect (G_OBJECT (client), "notify::default-adapter", G_CALLBACK (default_adapter_changed), NULL); default_adapter_changed (G_OBJECT (client), NULL, NULL); return 0; }
static char * get_name_and_type (const char *address, BluetoothType *ret_type) { BluetoothClient *client; GtkTreeModel *model; GtkTreeIter iter; gboolean cont; char *found_name; found_name = NULL; *ret_type = 0; client = bluetooth_client_new (); model = bluetooth_client_get_device_model (client); if (model == NULL) { g_object_unref (client); return NULL; } cont = gtk_tree_model_get_iter_first(model, &iter); while (cont != FALSE) { char *bdaddr, *name; BluetoothType type; gtk_tree_model_get(model, &iter, BLUETOOTH_COLUMN_ADDRESS, &bdaddr, BLUETOOTH_COLUMN_ALIAS, &name, BLUETOOTH_COLUMN_TYPE, &type, -1); if (g_strcmp0 (bdaddr, address) == 0) { g_free (bdaddr); found_name = name; *ret_type = type; break; } g_free (bdaddr); g_free (name); cont = gtk_tree_model_iter_next(model, &iter); } g_object_unref (model); g_object_unref (client); return found_name; }
static void dump_devices (void) { 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 void bluetooth_chooser_button_init (BluetoothChooserButton *button) { gtk_button_set_label (GTK_BUTTON (button), _("Click to select device...")); button->image = gtk_image_new (); gtk_button_set_image (GTK_BUTTON (button), button->image); button->bdaddr = NULL; button->dialog = NULL; button->client = bluetooth_client_new (); g_signal_connect (G_OBJECT (button->client), "notify::default-adapter", G_CALLBACK (default_adapter_changed), button); g_signal_connect (G_OBJECT (button->client), "notify::default-adapter-powered", G_CALLBACK (default_adapter_changed), button); /* And set the default value already */ default_adapter_changed (NULL, NULL, button); set_btdevname (button, NULL, NULL, NULL); }
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; }
int main(int argc, char *argv[]) { UniqueApp *app; GtkStatusIcon *statusicon; GtkWidget *menu; GOptionContext *context; GError *error = NULL; bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); textdomain(GETTEXT_PACKAGE); #if !GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif /* Parse command-line options */ context = g_option_context_new (N_("- Bluetooth applet")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); return 1; } if (option_debug == FALSE) { app = unique_app_new ("org.mate.Bluetooth.applet", NULL); if (unique_app_is_running (app)) { gdk_notify_startup_complete (); g_warning ("Applet is already running, exiting"); return 0; } } else { app = NULL; } g_set_application_name(_("Bluetooth Applet")); gtk_window_set_default_icon_name("bluetooth"); killswitch = bluetooth_killswitch_new (); g_signal_connect (G_OBJECT (killswitch), "state-changed", G_CALLBACK (killswitch_state_changed), NULL); menu = create_popupmenu(); client = bluetooth_client_new(); devices_model = bluetooth_client_get_model(client); g_signal_connect(G_OBJECT(devices_model), "row-inserted", G_CALLBACK(device_added), NULL); g_signal_connect(G_OBJECT(devices_model), "row-deleted", G_CALLBACK(device_removed), NULL); g_signal_connect (G_OBJECT (devices_model), "row-changed", G_CALLBACK (device_changed), NULL); /* Set the default adapter */ device_changed (devices_model, NULL, NULL, NULL); if (bluetooth_killswitch_has_killswitches (killswitch) != FALSE) { killswitch_state_changed (killswitch, bluetooth_killswitch_get_state (killswitch)); } /* Make sure all the unblocked adapters are powered, * so as to avoid seeing unpowered, but unblocked * devices */ bluetooth_set_adapter_powered (); settings = g_settings_new (SCHEMA_NAME); show_icon_pref = g_settings_get_boolean (settings, PREF_SHOW_ICON); g_signal_connect (G_OBJECT (settings), "changed::" PREF_SHOW_ICON, G_CALLBACK (show_icon_changed), NULL); statusicon = init_notification(); update_icon_visibility(); g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), menu); g_signal_connect(statusicon, "popup-menu", G_CALLBACK(popup_callback), menu); setup_agents(); gtk_main(); gtk_widget_destroy(menu); g_object_unref(settings); cleanup_agents(); cleanup_notification(); g_object_unref(devices_model); g_object_unref(client); if (app != NULL) g_object_unref (app); return 0; }
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; }
static void bluetooth_chooser_init(BluetoothChooser *self) { BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self); GtkWidget *vbox; GtkWidget *hbox; gtk_widget_push_composite_child (); g_object_set (G_OBJECT (self), "orientation", GTK_ORIENTATION_VERTICAL, NULL); priv->client = bluetooth_client_new (); /* Setup the widget itself */ gtk_box_set_spacing (GTK_BOX(self), 18); gtk_container_set_border_width (GTK_CONTAINER(self), 0); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); gtk_widget_show (vbox); gtk_box_pack_start (GTK_BOX (self), vbox, TRUE, TRUE, 0); /* The treeview label */ priv->search_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 24); gtk_widget_set_name (priv->search_hbox, "search_hbox"); if (priv->show_searching) gtk_widget_show (priv->search_hbox); gtk_box_pack_end (GTK_BOX (vbox), priv->search_hbox, FALSE, TRUE, 0); gtk_widget_set_no_show_all (priv->search_hbox, TRUE); /* Setup the adapter disco mode callback for the search button */ priv->adapter_model = bluetooth_client_get_adapter_model (priv->client); g_signal_connect (priv->adapter_model, "row-changed", G_CALLBACK (adapter_model_row_changed), self); /* The searching label */ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); gtk_widget_set_name (hbox, "searching label hbox"); priv->spinner = gtk_spinner_new (); gtk_container_add (GTK_CONTAINER (hbox), priv->spinner); gtk_widget_show (priv->spinner); priv->search_label = gtk_label_new (_("Searching for devices…")); gtk_container_add (GTK_CONTAINER (hbox), priv->search_label); gtk_widget_show (priv->search_label); gtk_widget_show (hbox); if (priv->show_searching) { gboolean discovering; g_object_get (G_OBJECT (priv->client), "default-adapter-discovering", &discovering, NULL); set_search_label (self, discovering); } gtk_box_pack_start (GTK_BOX (priv->search_hbox), hbox, FALSE, TRUE, 0); /* The treeview */ priv->scrolled_window = create_treeview (self); gtk_widget_show_all (priv->scrolled_window); gtk_box_pack_start (GTK_BOX (vbox), priv->scrolled_window, TRUE, TRUE, 0); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_SHADOW_IN); /* The filters */ priv->device_type_filter_model = GTK_TREE_MODEL (gtk_list_store_new (DEVICE_TYPE_FILTER_NUM_COLS, G_TYPE_STRING, G_TYPE_INT)); priv->filters_vbox = bluetooth_filter_widget_new (); gtk_widget_show (priv->filters_vbox); gtk_box_pack_start (GTK_BOX (self), priv->filters_vbox, FALSE, TRUE, 0); gtk_widget_set_no_show_all (priv->filters_vbox, TRUE); /* if filters are not visible hide the vbox */ if (!priv->show_device_type && !priv->show_device_category) gtk_widget_hide (priv->filters_vbox); priv->default_adapter_changed_id = g_signal_connect (priv->client, "notify::default-adapter", G_CALLBACK (default_adapter_changed), self); g_signal_connect(self, "notify::device-type-filter", G_CALLBACK(filter_type_changed_cb), NULL); g_signal_connect(self, "notify::device-category-filter", G_CALLBACK(filter_category_changed_cb), NULL); gtk_widget_pop_composite_child (); }