[network-manager-applet/lr/bluetooth: 1/2] editor: Add support for creating Bluetooth connections



commit 9e06ebba21e63ea5b4efd30517e7569d59c716ad
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Mon Oct 27 11:54:57 2014 +0100

    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     |  153 ++++++++++++++++++++++++++++
 2 files changed, 155 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/connection-helpers.c b/src/connection-editor/connection-helpers.c
index c8ad16e..f298a50 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 36f2359..3fa07ee 100644
--- a/src/connection-editor/page-bluetooth.c
+++ b/src/connection-editor/page-bluetooth.c
@@ -31,6 +31,7 @@
 
 #include "page-bluetooth.h"
 #include "nm-connection-editor.h"
+#include "nm-mobile-wizard.h"
 
 G_DEFINE_TYPE (CEPageBluetooth, ce_page_bluetooth, CE_TYPE_PAGE)
 
@@ -172,3 +173,155 @@ ce_page_bluetooth_class_init (CEPageBluetoothClass *bluetooth_class)
        /* virtual methods */
        parent_class->validate = validate;
 }
+
+typedef struct {
+       NMRemoteSettings *settings;
+       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->settings,
+                                            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->settings);
+       g_free (info);
+}
+
+void
+bluetooth_connection_new (GtkWindow *parent,
+                          const char *detail,
+                          NMRemoteSettings *settings,
+                          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->settings = g_object_ref (settings);
+       info->user_data = user_data;
+       info->type = NM_SETTING_BLUETOOTH_TYPE_PANU;
+       info->type = NM_SETTING_BLUETOOTH_TYPE_DUN;
+
+
+       dialog = gtk_dialog_new_with_buttons (_("Select Bluetooth Connection Profile"),
+                                             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 Bluetooth Profile your device uses."));
+       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);
+               return;
+       } else {
+               new_connection_mobile_wizard_done (NULL, (response != GTK_RESPONSE_OK), NULL, info);
+       }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]