network-manager-applet r810 - in branches/mbca: . src src/connection-editor
- From: kaijanma svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r810 - in branches/mbca: . src src/connection-editor
- Date: Thu, 31 Jul 2008 12:31:04 +0000 (UTC)
Author: kaijanma
Date: Thu Jul 31 12:31:04 2008
New Revision: 810
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=810&view=rev
Log:
introduce libmbca
Modified:
branches/mbca/configure.ac
branches/mbca/src/applet-device-gsm.c
branches/mbca/src/applet.c
branches/mbca/src/applet.h
branches/mbca/src/connection-editor/nm-connection-list.c
Modified: branches/mbca/configure.ac
==============================================================================
--- branches/mbca/configure.ac (original)
+++ branches/mbca/configure.ac Thu Jul 31 12:31:04 2008
@@ -213,6 +213,16 @@
AC_MSG_RESULT(no)
fi
+AC_ARG_WITH(mbca, AC_HELP_STRING([--with-mbca], [use Mobile Broadband Configuration Assistant]))
+
+if ! test -z "$with_mbca" ; then
+ CFLAGS="$CFLAGS -DWITH_MBCA"
+ PKG_CHECK_MODULES(MBCA, libmbca)
+ NMA_CFLAGS="$NMA_CFLAGS $MBCA_CFLAGS"
+ NMA_LIBS="$NMA_LIBS $MBCA_LIBS"
+fi
+
+
AC_OUTPUT([
Makefile
src/Makefile
Modified: branches/mbca/src/applet-device-gsm.c
==============================================================================
--- branches/mbca/src/applet-device-gsm.c (original)
+++ branches/mbca/src/applet-device-gsm.c Thu Jul 31 12:31:04 2008
@@ -36,6 +36,13 @@
#include <nm-setting-ppp.h>
#include <nm-gsm-device.h>
+#ifdef WITH_MBCA
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <nm-setting-ip4-config.h>
+#include <nm-utils.h>
+#endif
+
#include "applet.h"
#include "applet-device-gsm.h"
#include "utils.h"
@@ -52,6 +59,183 @@
g_slice_free (GSMMenuItemInfo, data);
}
+#ifdef WITH_MBCA
+
+static void
+assistant_state_changed_cb (MBCAAssistant* assistant,
+ enum MBCAAssistantState state,
+ gpointer data)
+{
+ NMApplet *applet = data;
+ GSList* iter;
+
+ NMAGConfConnection *exported;
+
+ NMConnection *connection;
+ NMSettingGsm *s_gsm;
+ NMSettingSerial *s_serial;
+ NMSettingPPP *s_ppp;
+ NMSettingConnection *s_con;
+
+ NMSettingIP4Config* ipv4conf;
+ gboolean ignore_dhcp_dns = FALSE;
+ GArray *dns_servers = FALSE;
+ const char *method;
+
+ MBCAConfiguration* conf;
+
+ switch (state)
+ {
+ case MBCA_STATE_READY:
+ case MBCA_STATE_RUNNING:
+ {
+ break;
+ }
+ case MBCA_STATE_DONE:
+ {
+ conf = mbca_assistant_get_configuration (assistant);
+ connection = nm_connection_new ();
+
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ ipv4conf = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ nm_connection_add_setting (connection, NM_SETTING (ipv4conf));
+
+ s_con->id = g_strdup (conf->name);
+ s_con->type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
+ s_con->autoconnect = FALSE;
+
+ /* Serial setting */
+ s_serial = (NMSettingSerial *) nm_setting_serial_new ();
+ s_serial->baud = 115200;
+ s_serial->bits = 8;
+ s_serial->parity = 'n';
+ s_serial->stopbits = 1;
+ nm_connection_add_setting (connection, NM_SETTING (s_serial));
+
+ method = NM_SETTING_IP4_CONFIG_METHOD_DHCP;
+
+ s_gsm = NM_SETTING_GSM (nm_setting_gsm_new ());
+ s_gsm->number = g_strdup ("*99***1#");
+
+ s_gsm->apn = g_strdup (conf->provider->gsm.apn);
+
+ s_gsm->username = g_strdup (conf->provider->username);
+ s_gsm->password = g_strdup (conf->provider->password);
+
+ if (conf->provider->dns1) {
+ struct in_addr tmp_addr;
+ ignore_dhcp_dns = TRUE;
+ dns_servers = g_array_new (FALSE, FALSE, sizeof (guint));
+
+ inet_aton (conf->provider->dns1, &tmp_addr);
+ g_array_append_val (dns_servers, tmp_addr.s_addr);
+
+ if (conf->provider->dns2) {
+ inet_aton (conf->provider->dns2, &tmp_addr);
+ g_array_append_val (dns_servers, tmp_addr.s_addr);
+ }
+ }
+
+ /* TODO: gateway */
+
+ g_object_set (ipv4conf,
+ NM_SETTING_IP4_CONFIG_METHOD, method,
+ NM_SETTING_IP4_CONFIG_DNS, dns_servers,
+ NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS, ignore_dhcp_dns,
+ NULL);
+
+ nm_connection_add_setting (connection, NM_SETTING (s_gsm));
+
+ s_ppp = (NMSettingPPP *) nm_setting_ppp_new ();
+ nm_connection_add_setting (connection, NM_SETTING (s_ppp));
+
+
+ mbca_free_configuration (conf);
+ g_array_free (dns_servers, TRUE);
+
+ exported = nma_gconf_settings_add_connection (applet->gconf_settings, connection);
+ if (!exported) {
+ g_object_unref (connection);
+ g_return_if_reached ();
+ }
+ g_object_unref (connection);
+
+ applet_do_notify (applet, NOTIFY_URGENCY_LOW,
+ _("New Configuration Created"),
+ _("You can activate the connection by clicking this icon.\n"
+ "Use connection editor to add new and to change settings if necessary"),
+ "nm-device-wwan", NULL, NULL, NULL, NULL);
+
+ /* FALLTHROUGH */
+ }
+ case MBCA_STATE_ABORTED:
+ {
+ for (iter = applet->mbca_assistants; iter; iter = iter->next){
+ if ((MBCAAssistant*)(iter->data) == assistant) {
+ UdiAssistant* ua = iter->data;
+ g_object_unref (G_OBJECT (ua->assistant));
+ g_free (ua->udi);
+ applet->mbca_assistants = g_slist_remove_all (applet->mbca_assistants,
+ ua);
+
+ g_free (ua);
+
+ }
+ }
+ break;
+ }
+ default:
+ {
+ g_return_if_reached ();
+ }
+ }
+
+}
+
+static NMConnection *
+gsm_new_auto_connection (NMDevice *device,
+ NMApplet *applet,
+ gpointer user_data)
+{
+ UdiAssistant* ua;
+ const gchar* udi;
+ GSList* iter;
+
+ udi = nm_device_get_udi (device);
+
+ for (iter = applet->mbca_assistants; iter; iter = iter->next) {
+ UdiAssistant* tmp = iter->data;
+ if (!strcmp (tmp->udi, udi))
+ {
+ mbca_assistant_present (tmp->assistant);
+ break;
+ }
+ }
+ if (!iter)
+ {
+ /* not found */
+ ua = g_malloc (sizeof (UdiAssistant));
+ ua->udi = g_strdup (udi);
+ ua->assistant = mbca_assistant_new ();
+ g_signal_connect (G_OBJECT (ua->assistant), "state-changed",
+ G_CALLBACK (assistant_state_changed_cb), applet);
+ applet->mbca_assistants = g_slist_prepend (applet->mbca_assistants, ua);
+ mbca_assistant_run_for_device (ua->assistant,
+ MBCA_DEVICE_HAL,
+ ua->udi,
+ utils_get_device_description (device));
+ }
+
+ nm_warning ("There's a new GSM modem being configured and thus no "
+ "configuration is yet available. You can safely ignore next "
+ "warninig about missing default configuration.");
+ return NULL;
+}
+
+#else
+
#define DEFAULT_GSM_NAME _("Auto GSM network connection")
static NMConnection *
@@ -90,6 +274,8 @@
return connection;
}
+#endif
+
static void
gsm_menu_item_activate (GtkMenuItem *item, gpointer user_data)
@@ -146,8 +332,13 @@
{
GSMMenuItemInfo *info;
GtkWidget *item;
-
+
+#ifdef WITH_MBCA
+ item = gtk_check_menu_item_new_with_label (_("Configure..."));
+#else
item = gtk_check_menu_item_new_with_label (DEFAULT_GSM_NAME);
+#endif
+
gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
info = g_slice_new0 (GSMMenuItemInfo);
@@ -287,6 +478,47 @@
}
}
+#ifdef WITH_MBCA
+typedef struct {
+ NMDevice* device;
+ NMApplet* applet;
+} NotifyConfigureNewDeviceCbData;
+
+static void
+notify_configure_new_device_cb (NotifyNotification* notification, gchar* foo, gpointer data)
+{
+ NotifyConfigureNewDeviceCbData* d = data;
+ gsm_new_auto_connection (d->device, d->applet, NULL);
+ g_free (d);
+}
+
+static void
+gsm_device_added (NMDevice *device, NMApplet *applet)
+{
+ GSList *connections, *all;
+
+ all = applet_get_all_connections (applet);
+ connections = utils_filter_connections_for_device (device, all);
+ g_slist_free (all);
+
+ if (g_slist_length (connections) == 0)
+ {
+ NotifyConfigureNewDeviceCbData* d = g_malloc (sizeof (NotifyConfigureNewDeviceCbData));
+ d->device = device;
+ d->applet = applet;
+ applet_do_notify (applet, NOTIFY_URGENCY_LOW,
+ _("New Mobile Broadband Device Detected"),
+ _("Click here to configure the device..."),
+ "nm-device-wwan",
+ "configure",
+ "Configure",
+ notify_configure_new_device_cb,
+ d);
+ }
+
+}
+#endif
+
static GdkPixbuf *
gsm_get_icon (NMDevice *device,
NMDeviceState state,
@@ -604,6 +836,10 @@
dclass->get_icon = gsm_get_icon;
dclass->get_secrets = gsm_get_secrets;
+#ifdef WITH_MBCA
+ dclass->device_added = gsm_device_added;
+#endif
+
return dclass;
}
Modified: branches/mbca/src/applet.c
==============================================================================
--- branches/mbca/src/applet.c (original)
+++ branches/mbca/src/applet.c Thu Jul 31 12:31:04 2008
@@ -2243,6 +2243,17 @@
{
NMApplet *applet = NM_APPLET (object);
+#ifdef WITH_MBCA
+ GSList* iter = NULL;
+
+ for (iter = applet->mbca_assistants; iter; iter = iter->next) {
+ MBCAAssistant* assistant = iter->data;
+ mbca_assistant_abort (assistant);
+ /* let the cb handle freeing of resources */
+ }
+
+#endif
+
if (applet->update_timestamps_id)
g_source_remove (applet->update_timestamps_id);
@@ -2285,6 +2296,10 @@
applet->icon_theme = NULL;
applet->notification = NULL;
applet->size = -1;
+
+#ifdef WITH_MBCA
+ applet->mbca_assistants = NULL;
+#endif
}
static void nma_class_init (NMAppletClass *klass)
Modified: branches/mbca/src/applet.h
==============================================================================
--- branches/mbca/src/applet.h (original)
+++ branches/mbca/src/applet.h Thu Jul 31 12:31:04 2008
@@ -48,6 +48,10 @@
#include <nm-active-connection.h>
#include <nm-dbus-settings.h>
+#ifdef WITH_MBCA
+#include <mbca_assistant.h>
+#endif
+
#include "applet-dbus-manager.h"
#include "nma-gconf-settings.h"
@@ -58,6 +62,14 @@
#define NM_IS_APPLET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NM_TYPE_APPLET))
#define NM_APPLET_GET_CLASS(object)(G_TYPE_INSTANCE_GET_CLASS((object), NM_TYPE_APPLET, NMAppletClass))
+#ifdef WITH_MBCA
+typedef struct
+{
+ char* udi;
+ MBCAAssistant* assistant;
+} UdiAssistant;
+#endif
+
typedef struct
{
GObjectClass parent_class;
@@ -141,6 +153,10 @@
GladeXML * info_dialog_xml;
NotifyNotification* notification;
+
+#ifdef WITH_MBCA
+ GSList* mbca_assistants; /* list of UdiAssistant */
+#endif
} NMApplet;
Modified: branches/mbca/src/connection-editor/nm-connection-list.c
==============================================================================
--- branches/mbca/src/connection-editor/nm-connection-list.c (original)
+++ branches/mbca/src/connection-editor/nm-connection-list.c Thu Jul 31 12:31:04 2008
@@ -57,6 +57,14 @@
#include <nm-setting-serial.h>
#include <nm-vpn-plugin-ui-interface.h>
+#ifdef WITH_MBCA
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <nm-setting-ip4-config.h>
+#include <mbca_assistant.h>
+#include <nm-utils.h>
+#endif
+
#include "nm-connection-editor.h"
#include "nm-connection-list.h"
#include "gconf-helpers.h"
@@ -731,6 +739,120 @@
nm_connection_add_setting (connection, NM_SETTING (s_serial));
}
+#ifdef WITH_MBCA
+static void
+mbca_assistant_state_changed_cb (MBCAAssistant* assistant,
+ enum MBCAAssistantState state,
+ gpointer user_data)
+{
+ NMConnection *connection = NULL;
+ NMSettingConnection *s_con;
+ NMSetting *type_setting = NULL;
+ MBCAConfiguration* conf;
+
+ NMConnectionList *list = user_data;
+
+ NMSettingIP4Config* ipv4conf;
+ gboolean ignore_dhcp_dns = FALSE;
+ GArray *dns_servers = FALSE;
+ const char *method;
+
+ switch (state) {
+ case MBCA_STATE_READY:
+ case MBCA_STATE_RUNNING:
+ return;
+ case MBCA_STATE_DONE:
+ connection = nm_connection_new ();
+
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ ipv4conf = NM_SETTING_IP4_CONFIG (nm_setting_ip4_config_new ());
+ nm_connection_add_setting (connection, NM_SETTING (ipv4conf));
+
+ conf = mbca_assistant_get_configuration (assistant);
+
+ s_con->id = g_strdup (conf->name);
+ s_con->autoconnect = FALSE;
+
+ add_default_serial_setting (connection);
+
+ method = NM_SETTING_IP4_CONFIG_METHOD_DHCP;
+
+ if (conf->provider->type == MBCA_NETWORK_GSM) {
+ NMSettingGsm *s_gsm;
+
+ s_con->type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
+
+ type_setting = nm_setting_gsm_new ();
+ s_gsm = NM_SETTING_GSM (type_setting);
+ s_gsm->number = g_strdup ("*99#"); /* De-facto standard for GSM */
+
+ s_gsm->apn = g_strdup (conf->provider->gsm.apn);
+
+ s_gsm->username = g_strdup (conf->provider->username);
+ s_gsm->password = g_strdup (conf->provider->password);
+
+
+ if (conf->provider->dns1) {
+ struct in_addr tmp_addr;
+ ignore_dhcp_dns = TRUE;
+ dns_servers = g_array_new (FALSE, FALSE, sizeof (guint));
+
+ inet_aton (conf->provider->dns1, &tmp_addr);
+ g_array_append_val (dns_servers, tmp_addr.s_addr);
+
+ if (conf->provider->dns2) {
+ inet_aton (conf->provider->dns2, &tmp_addr);
+ g_array_append_val (dns_servers, tmp_addr.s_addr);
+ }
+ }
+
+ /* TODO: gateway */
+
+ } else if (conf->provider->type == MBCA_NETWORK_CDMA) {
+ NMSettingCdma *s_cdma;
+
+ s_con->type = g_strdup (NM_SETTING_CDMA_SETTING_NAME);
+
+ type_setting = nm_setting_cdma_new ();
+ s_cdma = NM_SETTING_CDMA (type_setting);
+ s_cdma->number = g_strdup ("#777"); /* De-facto standard for CDMA */
+
+ s_cdma->username = g_strdup (conf->provider->username);
+ s_cdma->password = g_strdup (conf->provider->password);
+ }
+ nm_connection_add_setting (connection, nm_setting_ppp_new ());
+
+ g_object_set (ipv4conf,
+ NM_SETTING_IP4_CONFIG_METHOD, method,
+ NM_SETTING_IP4_CONFIG_DNS, dns_servers,
+ NM_SETTING_IP4_CONFIG_IGNORE_DHCP_DNS, ignore_dhcp_dns,
+ NULL);
+
+ if (type_setting) {
+ nm_connection_add_setting (connection, type_setting);
+ } else {
+ g_object_unref (connection);
+ connection = NULL;
+ }
+
+ add_connection (list, connection, NULL, NULL);
+ g_hash_table_remove (list->editors, connection);
+
+ mbca_free_configuration (conf);
+ g_array_free (dns_servers, TRUE);
+ /* FALLTHROUGH */
+
+ case MBCA_STATE_ABORTED:
+ g_object_unref (assistant);
+ break;
+ default:
+ g_warn_if_reached ();
+ }
+}
+#endif
+
static NMConnection *
create_new_connection_for_type (NMConnectionList *list, const char *connection_type)
{
@@ -763,6 +885,21 @@
s_wireless = NM_SETTING_WIRELESS (type_setting);
s_wireless->mode = g_strdup ("infrastructure");
} else if ((ctype == NM_TYPE_SETTING_GSM) || (ctype == NM_TYPE_SETTING_CDMA)) {
+
+#ifdef WITH_MBCA
+
+ MBCAAssistant* assistant = mbca_assistant_new ();
+ g_signal_connect (G_OBJECT (assistant), "state-changed",
+ G_CALLBACK (mbca_assistant_state_changed_cb), list);
+ mbca_assistant_run (assistant);
+
+ mb_type = NM_TYPE_SETTING_GSM; /* get rid of compiler warning about
+ * unused variable */
+ g_warning ("You may safely ignore the next warning about failing to "
+ " add new connection");
+
+#else
+
/* Since GSM is a placeholder for both GSM and CDMA; ask the user which
* one they really want.
*/
@@ -798,6 +935,9 @@
} else {
/* user canceled; do nothing */
}
+
+#endif
+
} else if (ctype == NM_TYPE_SETTING_VPN) {
char *service = NULL;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]