[network-manager-applet] applet: add private D-Bus API for new mobile broadband connections



commit 124fde5e8d4212da4fcee31485bc9f56a74e6c1f
Author: Dan Williams <dcbw redhat com>
Date:   Tue May 3 14:25:09 2011 -0500

    applet: add private D-Bus API for new mobile broadband connections
    
    Same as for 802.1x etc, let the shell applet call out to nm-applet
    for new mobile broadband connections.

 src/applet-device-cdma.c        |   70 ++++++++++++++++++++++++++++++++++++--
 src/applet-device-cdma.h        |    2 +
 src/applet-device-gsm.c         |   70 ++++++++++++++++++++++++++++++++++++--
 src/applet-device-gsm.h         |    2 +
 src/applet.c                    |   33 ++++++++++++++++++
 src/nm-applet-introspection.xml |    4 ++
 6 files changed, 173 insertions(+), 8 deletions(-)
---
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index 7e7f033..7b0bf85 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -160,10 +160,8 @@ done:
 }
 
 static gboolean
-cdma_new_auto_connection (NMDevice *device,
-                          gpointer dclass_data,
-                          AppletNewAutoConnectionCallback callback,
-                          gpointer callback_data)
+do_mobile_wizard (AppletNewAutoConnectionCallback callback,
+                  gpointer callback_data)
 {
 	MobileWizard *wizard;
 	AutoCdmaWizardInfo *info;
@@ -190,6 +188,70 @@ cdma_new_auto_connection (NMDevice *device,
 	return TRUE;
 }
 
+static gboolean
+cdma_new_auto_connection (NMDevice *device,
+                          gpointer dclass_data,
+                          AppletNewAutoConnectionCallback callback,
+                          gpointer callback_data)
+{
+	return do_mobile_wizard (callback, callback_data);
+}
+
+static void
+dbus_3g_add_and_activate_cb (NMClient *client,
+                             NMActiveConnection *active,
+                             const char *connection_path,
+                             GError *error,
+                             gpointer user_data)
+{
+	if (error)
+		g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
+}
+
+typedef struct {
+	NMApplet *applet;
+	NMDevice *device;
+} Dbus3gInfo;
+
+static void
+dbus_connect_3g_cb (NMConnection *connection,
+                    gboolean auto_created,
+                    gboolean canceled,
+                    gpointer user_data)
+{
+	Dbus3gInfo *info = user_data;
+
+	if (canceled == FALSE) {
+		g_return_if_fail (connection != NULL);
+
+		/* Ask NM to add the new connection and activate it; NM will fill in the
+		 * missing details based on the specific object and the device.
+		 */
+		nm_client_add_and_activate_connection (info->applet->nm_client,
+		                                       connection,
+		                                       info->device,
+		                                       "/",
+		                                       dbus_3g_add_and_activate_cb,
+		                                       info->applet);
+	}
+
+	g_object_unref (info->device);
+	memset (info, 0, sizeof (*info));
+	g_free (info);
+}
+
+void
+applet_cdma_connect_network (NMApplet *applet, NMDevice *device)
+{
+	Dbus3gInfo *info;
+
+	info = g_malloc0 (sizeof (*info));
+	info->applet = applet;
+	info->device = g_object_ref (device);
+
+	do_mobile_wizard (dbus_connect_3g_cb, info);
+}
+
 static void
 cdma_menu_item_activate (GtkMenuItem *item, gpointer user_data)
 {
diff --git a/src/applet-device-cdma.h b/src/applet-device-cdma.h
index dba2385..af74f69 100644
--- a/src/applet-device-cdma.h
+++ b/src/applet-device-cdma.h
@@ -27,4 +27,6 @@
 
 NMADeviceClass *applet_device_cdma_get_class (NMApplet *applet);
 
+void applet_cdma_connect_network (NMApplet *applet, NMDevice *device);
+
 #endif /* __APPLET_DEVICE_CDMA_H__ */
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index fc24c0e..5d0d584 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -186,10 +186,8 @@ done:
 }
 
 static gboolean
-gsm_new_auto_connection (NMDevice *device,
-                         gpointer dclass_data,
-                         AppletNewAutoConnectionCallback callback,
-                         gpointer callback_data)
+do_mobile_wizard (AppletNewAutoConnectionCallback callback,
+                  gpointer callback_data)
 {
 	MobileWizard *wizard;
 	AutoGsmWizardInfo *info;
@@ -216,6 +214,70 @@ gsm_new_auto_connection (NMDevice *device,
 	return TRUE;
 }
 
+static gboolean
+gsm_new_auto_connection (NMDevice *device,
+                         gpointer dclass_data,
+                         AppletNewAutoConnectionCallback callback,
+                         gpointer callback_data)
+{
+	return do_mobile_wizard (callback, callback_data);
+}
+
+static void
+dbus_3g_add_and_activate_cb (NMClient *client,
+                             NMActiveConnection *active,
+                             const char *connection_path,
+                             GError *error,
+                             gpointer user_data)
+{
+	if (error)
+		g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
+}
+
+typedef struct {
+	NMApplet *applet;
+	NMDevice *device;
+} Dbus3gInfo;
+
+static void
+dbus_connect_3g_cb (NMConnection *connection,
+                    gboolean auto_created,
+                    gboolean canceled,
+                    gpointer user_data)
+{
+	Dbus3gInfo *info = user_data;
+
+	if (canceled == FALSE) {
+		g_return_if_fail (connection != NULL);
+
+		/* Ask NM to add the new connection and activate it; NM will fill in the
+		 * missing details based on the specific object and the device.
+		 */
+		nm_client_add_and_activate_connection (info->applet->nm_client,
+		                                       connection,
+		                                       info->device,
+		                                       "/",
+		                                       dbus_3g_add_and_activate_cb,
+		                                       info->applet);
+	}
+
+	g_object_unref (info->device);
+	memset (info, 0, sizeof (*info));
+	g_free (info);
+}
+
+void
+applet_gsm_connect_network (NMApplet *applet, NMDevice *device)
+{
+	Dbus3gInfo *info;
+
+	info = g_malloc0 (sizeof (*info));
+	info->applet = applet;
+	info->device = g_object_ref (device);
+
+	do_mobile_wizard (dbus_connect_3g_cb, info);
+}
+
 static void
 gsm_menu_item_activate (GtkMenuItem *item, gpointer user_data)
 {
diff --git a/src/applet-device-gsm.h b/src/applet-device-gsm.h
index ff3615f..e25222a 100644
--- a/src/applet-device-gsm.h
+++ b/src/applet-device-gsm.h
@@ -28,4 +28,6 @@
 
 NMADeviceClass *applet_device_gsm_get_class (NMApplet *applet);
 
+void applet_gsm_connect_network (NMApplet *applet, NMDevice *device);
+
 #endif /* __APPLET_DEVICE_GSM_H__ */
diff --git a/src/applet.c b/src/applet.c
index dc25503..050b054 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -172,6 +172,39 @@ impl_dbus_connect_to_8021x_network (NMApplet *applet,
 	return TRUE;
 }
 
+static gboolean
+impl_dbus_connect_to_3g_network (NMApplet *applet,
+                                 const char *device_path,
+                                 GError **error)
+{
+	NMDevice *device;
+	NMDeviceModemCapabilities caps;
+
+	device = nm_client_get_device_by_path (applet->nm_client, device_path);
+	if (!device || NM_IS_DEVICE_MODEM (device) == FALSE) {
+		g_set_error_literal (error,
+		                     NM_SECRET_AGENT_ERROR,
+		                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
+		                     "The device could not be found.");
+		return FALSE;
+	}
+
+	caps = nm_device_modem_get_current_capabilities (NM_DEVICE_MODEM (device));
+	if (caps & NM_DEVICE_MODEM_CAPABILITY_GSM_UMTS) {
+		applet_gsm_connect_network (applet, device);
+	} else if (caps & NM_DEVICE_MODEM_CAPABILITY_CDMA_EVDO) {
+		applet_cdma_connect_network (applet, device);
+	} else {
+		g_set_error_literal (error,
+		                     NM_SECRET_AGENT_ERROR,
+		                     NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
+		                     "The device had no GSM or CDMA capabilities.");
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 #include "applet-dbus-bindings.h"
 
 /********************************************************************/
diff --git a/src/nm-applet-introspection.xml b/src/nm-applet-introspection.xml
index 81f47fb..5c1680c 100644
--- a/src/nm-applet-introspection.xml
+++ b/src/nm-applet-introspection.xml
@@ -12,5 +12,9 @@
     <method name="CreateWifiNetwork">
       <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_dbus_create_wifi_network"/>
     </method>
+    <method name="ConnectTo3gNetwork">
+      <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_dbus_connect_to_3g_network"/>
+      <arg name="device" type="o" direction="in"/>
+    </method>
   </interface>
 </node>



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