From 6df226246e69a70a9e203ef2226ea018eed6898c Mon Sep 17 00:00:00 2001 From: Lubomir Rintel Date: Mon, 27 Oct 2014 11:54:57 +0100 Subject: editor: Add support for creating Bluetooth connections We need to know if the connection is going to be PAN or DUN. --- src/connection-editor/connection-helpers.c | 2 + src/connection-editor/page-bluetooth.c | 151 ++++++++++++++++++++++++++++- 2 files changed, 152 insertions(+), 1 deletion(-) diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c index c8ad16e3..f298a502 100644 --- a/src/connection-editor/connection-helpers.c +++ b/src/connection-editor/connection-helpers.c @@ -29,6 +29,7 @@ #include "page-wifi.h" #include "page-mobile.h" #include "page-wimax.h" +#include "page-bluetooth.h" #include "page-dsl.h" #include "page-infiniband.h" #include "page-bond.h" @@ -128,6 +129,7 @@ get_connection_type_list (void) NM_TYPE_SETTING_CDMA, NM_TYPE_SETTING_BLUETOOTH, FALSE); + add_type_data_real (array, _("Bluetooth"), bluetooth_connection_new, NM_TYPE_SETTING_BLUETOOTH); add_type_data_real (array, _("WiMAX"), wimax_connection_new, NM_TYPE_SETTING_WIMAX); add_type_data_real (array, _("DSL"), dsl_connection_new, NM_TYPE_SETTING_PPPOE); add_type_data_real (array, _("InfiniBand"), infiniband_connection_new, NM_TYPE_SETTING_INFINIBAND); diff --git a/src/connection-editor/page-bluetooth.c b/src/connection-editor/page-bluetooth.c index 36f23596..aa20f061 100644 --- a/src/connection-editor/page-bluetooth.c +++ b/src/connection-editor/page-bluetooth.c @@ -17,7 +17,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * Copyright 2014 Red Hat, Inc. + * Copyright 2014 - 2015 Red Hat, Inc. */ #include "config.h" @@ -31,6 +31,7 @@ #include "page-bluetooth.h" #include "nm-connection-editor.h" +#include "nma-mobile-wizard.h" G_DEFINE_TYPE (CEPageBluetooth, ce_page_bluetooth, CE_TYPE_PAGE) @@ -172,3 +173,151 @@ ce_page_bluetooth_class_init (CEPageBluetoothClass *bluetooth_class) /* virtual methods */ parent_class->validate = validate; } + +typedef struct { + NMClient *client; + PageNewConnectionResultFunc result_func; + gpointer user_data; + const gchar *type; +} WizardInfo; + +static void +new_connection_mobile_wizard_done (NMAMobileWizard *wizard, + gboolean canceled, + NMAMobileWizardAccessMethod *method, + gpointer user_data) +{ + WizardInfo *info = user_data; + NMConnection *connection = NULL; + char *detail = NULL; + NMSetting *type_setting = NULL; + + if (canceled) + goto out; + + if (method) { + switch (method->devtype) { + case NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS: + type_setting = nm_setting_gsm_new (); + /* De-facto standard for GSM */ + g_object_set (type_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); + break; + case NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO: + type_setting = nm_setting_cdma_new (); + /* De-facto standard for CDMA */ + g_object_set (type_setting, + NM_SETTING_CDMA_NUMBER, "#777", + NM_SETTING_GSM_USERNAME, method->username, + NM_SETTING_GSM_PASSWORD, method->password, + NULL); + break; + default: + g_assert_not_reached (); + break; + } + + if (method->plan_name) + detail = g_strdup_printf ("%s %s %%d", method->provider_name, method->plan_name); + else + detail = g_strdup_printf ("%s connection %%d", method->provider_name); + } + + if (!detail) + detail = g_strdup (_("Bluetooth connection %d")); + connection = ce_page_new_connection (detail, + NM_SETTING_BLUETOOTH_SETTING_NAME, + FALSE, + info->client, + user_data); + g_free (detail); + nm_connection_add_setting (connection, nm_setting_bluetooth_new ()); + g_object_set (nm_connection_get_setting_bluetooth (connection), + NM_SETTING_BLUETOOTH_TYPE, info->type, NULL); + + if (type_setting) { + nm_connection_add_setting (connection, type_setting); + nm_connection_add_setting (connection, nm_setting_ppp_new ()); + } + +out: + (*info->result_func) (connection, canceled, NULL, info->user_data); + + if (wizard) + nma_mobile_wizard_destroy (wizard); + + g_object_unref (info->client); + g_free (info); +} + +void +bluetooth_connection_new (GtkWindow *parent, + const char *detail, + NMClient *client, + PageNewConnectionResultFunc result_func, + gpointer user_data) +{ + gint response; + NMAMobileWizard *wizard = NULL; + WizardInfo *info; + GtkWidget *dialog, *content, *alignment, *vbox, *label, *dun_radio, *panu_radio; + + info = g_malloc0 (sizeof (WizardInfo)); + info->result_func = result_func; + info->client = g_object_ref (client); + info->user_data = user_data; + info->type = NM_SETTING_BLUETOOTH_TYPE_PANU; + + dialog = gtk_dialog_new_with_buttons (_("Bluetooth Type"), + parent, + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, + GTK_RESPONSE_OK, + NULL); + + content = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + + alignment = gtk_alignment_new (0, 0, 0.5, 0.5); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 12, 12, 12, 12); + gtk_box_pack_start (GTK_BOX (content), alignment, TRUE, FALSE, 6); + + vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); + gtk_container_add (GTK_CONTAINER (alignment), vbox); + + label = gtk_label_new (_("Select the type of the Bluetooth connection profile.")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 12); + + panu_radio = gtk_radio_button_new_with_mnemonic (NULL, _("_Personal Area Network")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (panu_radio), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), panu_radio, FALSE, FALSE, 6); + + dun_radio = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (panu_radio), + _("_Dial-Up Network")); + gtk_box_pack_start (GTK_BOX (vbox), dun_radio, FALSE, FALSE, 6); + + gtk_widget_show_all (dialog); + response = gtk_dialog_run (GTK_DIALOG (dialog)); + if (response == GTK_RESPONSE_OK) { + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dun_radio))) { + info->type = NM_SETTING_BLUETOOTH_TYPE_DUN; + wizard = nma_mobile_wizard_new (parent, NULL, NM_DEVICE_MODEM_CAPABILITY_NONE, FALSE, + new_connection_mobile_wizard_done, info); + } else { + info->type = NM_SETTING_BLUETOOTH_TYPE_PANU; + } + } + gtk_widget_destroy (dialog); + + if (wizard) + nma_mobile_wizard_present (wizard); + else + new_connection_mobile_wizard_done (NULL, (response != GTK_RESPONSE_OK), NULL, info); +} -- cgit v1.2.1