Esempio n. 1
0
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);
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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;
}
Esempio n. 4
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;
}