Пример #1
0
static BMSettingsConnectionInterface *
add_pan_connection (PluginInfo *info)
{
	BMConnection *connection;
	BMSetting *setting, *bt_setting, *ip_setting;
	BMAGConfSettings *gconf_settings;
	BMAGConfConnection *exported = NULL;
	GByteArray *mac;
	char *id, *uuid, *alias = NULL;
	GtkTreeIter iter;

	if (get_device_iter (info->btmodel, info->bdaddr, &iter))
		gtk_tree_model_get (info->btmodel, &iter, BLUETOOTH_COLUMN_ALIAS, &alias, -1);

	mac = get_array_from_bdaddr (info->bdaddr);
	if (mac == NULL)
		goto out;

	/* The connection */
	connection = bm_connection_new ();

	/* The connection settings */
	setting = bm_setting_connection_new ();
	id = g_strdup_printf (_("%s Network"), alias ? alias : info->bdaddr);
	uuid = bm_utils_uuid_generate ();
	g_object_set (G_OBJECT (setting),
	              BM_SETTING_CONNECTION_ID, id,
	              BM_SETTING_CONNECTION_UUID, uuid,
	              BM_SETTING_CONNECTION_TYPE, BM_SETTING_BLUETOOTH_SETTING_NAME,
	              BM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
	              NULL);
	g_free (id);
	g_free (uuid);
	bm_connection_add_setting (connection, setting);

	/* The Bluetooth settings */
	bt_setting = bm_setting_bluetooth_new ();
	g_object_set (G_OBJECT (bt_setting),
	              BM_SETTING_BLUETOOTH_BDADDR, mac,
	              BM_SETTING_BLUETOOTH_TYPE, BM_SETTING_BLUETOOTH_TYPE_PANU,
	              NULL);
	bm_connection_add_setting (connection, bt_setting);

	/* The IPv4 settings */
	ip_setting = bm_setting_ip4_config_new ();
	g_object_set (G_OBJECT (ip_setting),
	              BM_SETTING_IP4_CONFIG_METHOD, BM_SETTING_IP4_CONFIG_METHOD_AUTO,
	              NULL);
	bm_connection_add_setting (connection, ip_setting);

	gconf_settings = nma_gconf_settings_new (NULL);
	exported = nma_gconf_settings_add_connection (gconf_settings, connection);

out:
	g_byte_array_free (mac, TRUE);
	g_free (alias);
	return exported ? BM_SETTINGS_CONNECTION_INTERFACE (exported) : NULL;
}
Пример #2
0
static void
dun_start (PluginInfo *info)
{
	GError *error = NULL;
	GtkTreeIter iter;

	g_message ("%s: starting DUN device discovery...", __func__);

	/* Set up dbus */
	info->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
	if (error || !info->bus) {
		dun_error (info, __func__, error, _("could not connect to the system bus."));
		g_clear_error (&error);
		goto out;
	}

	gtk_label_set_text (GTK_LABEL (info->label), _("Detecting phone configuration..."));

	/* Start the spinner */
	if (!info->spinner) {
		info->spinner = nma_bling_spinner_new ();
		gtk_box_pack_start (GTK_BOX (info->hbox), info->spinner, FALSE, FALSE, 6);
	}
	nma_bling_spinner_start (BMA_BLING_SPINNER (info->spinner));
	gtk_widget_show_all (info->hbox);

	gtk_widget_set_sensitive (info->dun_button, FALSE);

	/* ModemManager stuff */
	info->mm_proxy = dbus_g_proxy_new_for_name (info->bus,
	                                            MM_SERVICE,
	                                            MM_PATH,
	                                            MM_INTERFACE);
	g_assert (info->mm_proxy);

	dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED,
	                                   G_TYPE_NONE,
	                                   G_TYPE_BOXED,
	                                   G_TYPE_INVALID);
	dbus_g_proxy_add_signal (info->mm_proxy, "DeviceAdded",
	                         DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (info->mm_proxy, "DeviceAdded",
								 G_CALLBACK (modem_added), info,
								 NULL);

	dbus_g_proxy_add_signal (info->mm_proxy, "DeviceRemoved",
	                         DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID);
	dbus_g_proxy_connect_signal (info->mm_proxy, "DeviceRemoved",
								 G_CALLBACK (modem_removed), info,
								 NULL);

	/* Get the device we're looking for */
	info->dun_proxy = NULL;
	if (get_device_iter (info->btmodel, info->bdaddr, &iter))
		gtk_tree_model_get (info->btmodel, &iter, BLUETOOTH_COLUMN_PROXY, &info->dun_proxy, -1);

	if (info->dun_proxy) {
		info->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, info);

		dbus_g_proxy_set_interface (info->dun_proxy, BLUEZ_SERIAL_INTERFACE);

		g_message ("%s: calling Connect...", __func__);

		/* Watch for BT device property changes */
		dbus_g_object_register_marshaller (nma_marshal_VOID__STRING_BOXED,
		                                   G_TYPE_NONE,
		                                   G_TYPE_STRING, G_TYPE_VALUE,
		                                   G_TYPE_INVALID);
		dbus_g_proxy_add_signal (info->dun_proxy, "PropertyChanged",
		                         G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
		dbus_g_proxy_connect_signal (info->dun_proxy, "PropertyChanged",
		                             G_CALLBACK (dun_property_changed), info, NULL);

		/* Request a connection to the device and get the port */
		dbus_g_proxy_begin_call_with_timeout (info->dun_proxy, "Connect",
		                                      dun_connect_cb,
		                                      info,
		                                      NULL,
		                                      20000,
		                                      G_TYPE_STRING, "dun",
		                                      G_TYPE_INVALID);
	} else
		dun_error (info, __func__, error, _("could not find the Bluetooth device."));

out:
	g_message ("%s: finished", __func__);
}
Пример #3
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;
}