network-manager-applet r467 - in trunk: . po src src/utils



Author: dcbw
Date: Mon Jan 21 19:21:05 2008
New Revision: 467
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=467&view=rev

Log:
2008-01-21  Dan Williams  <dcbw redhat com>

	* src/applet-device-gsm.c
		- (gsm_new_auto_connection): actually add the GSM setting to the
			connection object so it's valid
		- (gsm_get_icon): use wwan_icon member

	* src/applet.c
	  src/applet.h
		- (get_device_class): handle CDMA mobile broadband cards
		- (applet_menu_item_activate_helper): remove wrong check for connection
			!= NULL; if the connectoin is NULL then a default one should be
			created instead
		- (sort_devices): ethernet first, GSM second, CDMA third, wireless fourth
		- (nma_icons_free, nma_icons_load, constructor): gsm_icon -> wwan_icon

	* src/utils/utils.c
		- (connection_valid_for_cdma): new function
		- (utils_connection_valid_for_device): handle CDMA mobile broadband cards

	* src/applet-device-cdma.c
	  src/applet-device-cdma.h
	  src/Makefile.am
		- Add CDMA mobile broadband card support



Added:
   trunk/src/applet-device-cdma.c
   trunk/src/applet-device-cdma.h
Modified:
   trunk/ChangeLog
   trunk/po/POTFILES.in
   trunk/src/Makefile.am
   trunk/src/applet-device-gsm.c
   trunk/src/applet.c
   trunk/src/applet.h
   trunk/src/utils/utils.c

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Mon Jan 21 19:21:05 2008
@@ -3,6 +3,7 @@
 # Please keep this file sorted alphabetically.
 src/applet-dbus-manager.c
 src/applet-dbus-settings.c
+src/applet-device-cdma.c
 src/applet-device-gsm.c
 src/applet-device-wired.c
 src/applet-device-wireless.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Jan 21 19:21:05 2008
@@ -47,6 +47,8 @@
 	ap-menu-item.c \
 	applet-device-gsm.h \
 	applet-device-gsm.c \
+	applet-device-cdma.h \
+	applet-device-cdma.c \
 	$(NULL)
 
 nm_applet_LDADD = \

Added: trunk/src/applet-device-cdma.c
==============================================================================
--- (empty file)
+++ trunk/src/applet-device-cdma.c	Mon Jan 21 19:21:05 2008
@@ -0,0 +1,289 @@
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * (C) Copyright 2008 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkcheckmenuitem.h>
+
+#include <nm-device.h>
+#include <nm-setting-connection.h>
+#include <nm-setting-cdma.h>
+#include <nm-setting-serial.h>
+#include <nm-setting-ppp.h>
+#include <nm-cdma-device.h>
+
+#include "applet.h"
+#include "applet-dbus-settings.h"
+#include "applet-device-cdma.h"
+#include "utils.h"
+
+typedef struct {
+	NMApplet *applet;
+	NMDevice *device;
+	NMConnection *connection;
+} CdmaMenuItemInfo;
+
+static void
+cdma_menu_item_info_destroy (gpointer data)
+{
+	g_slice_free (CdmaMenuItemInfo, data);
+}
+
+static NMConnection *
+cdma_new_auto_connection (NMDevice *device,
+                          NMApplet *applet,
+                          gpointer user_data)
+{
+	NMConnection *connection;
+	NMSettingCdma *s_cdma;
+	NMSettingSerial *s_serial;
+	NMSettingPPP *s_ppp;
+	NMSettingConnection *s_con;
+
+	connection = nm_connection_new ();
+
+	s_cdma = NM_SETTING_CDMA (nm_setting_cdma_new ());
+	s_cdma->number = g_strdup ("#777"); /* De-facto standard for CDMA */
+	nm_connection_add_setting (connection, NM_SETTING (s_cdma));
+
+	/* 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));
+
+	s_ppp = (NMSettingPPP *) nm_setting_ppp_new ();
+	s_ppp->usepeerdns = TRUE; /* This is probably a good default as well */
+	nm_connection_add_setting (connection, NM_SETTING (s_ppp));
+
+	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+	s_con->id = g_strdup (_("Auto CDMA dialup connection"));
+	s_con->type = g_strdup (NM_SETTING (s_cdma)->name);
+	s_con->autoconnect = FALSE;
+	nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+	return connection;
+}
+
+static void
+cdma_menu_item_activate (GtkMenuItem *item, gpointer user_data)
+{
+	CdmaMenuItemInfo *info = (CdmaMenuItemInfo *) user_data;
+
+	applet_menu_item_activate_helper (info->device,
+	                                  info->connection,
+	                                  "/",
+	                                  info->applet,
+	                                  user_data);
+}
+
+static void
+add_connection_items (NMDevice *device,
+                      GSList *connections,
+                      NMConnection *active,
+                      GtkWidget *menu,
+                      NMApplet *applet)
+{
+	GSList *iter;
+	CdmaMenuItemInfo *info;
+
+	for (iter = connections; iter; iter = g_slist_next (iter)) {
+		NMConnection *connection = NM_CONNECTION (iter->data);
+		NMSettingConnection *s_con;
+		GtkWidget *item;
+
+		s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+		item = gtk_check_menu_item_new_with_label (s_con->id);
+		gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+		if (connection == active)
+			gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+		info = g_slice_new0 (CdmaMenuItemInfo);
+		info->applet = applet;
+		info->device = g_object_ref (G_OBJECT (device));
+		info->connection = g_object_ref (connection);
+
+		g_signal_connect_data (item, "activate",
+		                       G_CALLBACK (cdma_menu_item_activate),
+		                       info,
+		                       (GClosureNotify) cdma_menu_item_info_destroy, 0);
+
+		gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+	}
+}
+
+static void
+cdma_add_menu_item (NMDevice *device,
+                    guint32 n_devices,
+                    NMConnection *active,
+                    GtkWidget *menu,
+                    NMApplet *applet)
+{
+	char *text;
+	GtkWidget *item;
+	GSList *connections, *all;
+
+	all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+	connections = utils_filter_connections_for_device (device, all);
+	g_slist_free (all);
+
+	if (n_devices > 1) {
+		const char *desc;
+		char *dev_name = NULL;
+
+		desc = utils_get_device_description (device);
+		if (desc)
+			dev_name = g_strdup (desc);
+		if (!dev_name)
+			dev_name = nm_device_get_iface (device);
+		g_assert (dev_name);
+
+		if (g_slist_length (connections) > 1)
+			text = g_strdup_printf (_("CDMA Connections (%s)"), dev_name);
+		else
+			text = g_strdup_printf (_("CDMA Card (%s)"), dev_name);
+		g_free (dev_name);
+	} else {
+		if (g_slist_length (connections) > 1)
+			text = g_strdup (_("CDMA Connections"));
+		else
+			text = g_strdup (_("_CDMA Card"));
+	}
+
+	if (g_slist_length (connections) > 1) {
+		item = gtk_menu_item_new_with_label (text);
+	} else {
+		item = gtk_check_menu_item_new_with_mnemonic (text);
+		gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
+	}
+	g_free (text);
+
+	gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+	if (g_slist_length (connections) > 1) {
+		GtkWidget *label;
+		char *bold_text;
+
+		label = gtk_bin_get_child (GTK_BIN (item));
+		bold_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
+		                                     gtk_label_get_text (GTK_LABEL (label)));
+		gtk_label_set_markup (GTK_LABEL (label), bold_text);
+		g_free (bold_text);
+
+		gtk_widget_set_sensitive (item, FALSE);
+
+		add_connection_items (device, connections, active, menu, applet);
+	} else {
+		CdmaMenuItemInfo *info;
+		NMConnection *connection;
+
+		info = g_slice_new0 (CdmaMenuItemInfo);
+		info->applet = applet;
+		info->device = g_object_ref (G_OBJECT (device));
+
+		if (g_slist_length (connections) == 1) {
+			connection = NM_CONNECTION (g_slist_nth_data (connections, 0));
+			info->connection = g_object_ref (G_OBJECT (connection));
+		}
+
+		if (   (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED)
+		    || (info->connection && info->connection == active))
+			gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+		g_signal_connect_data (item, "activate",
+		                       G_CALLBACK (cdma_menu_item_activate),
+		                       info,
+		                       (GClosureNotify) cdma_menu_item_info_destroy, 0);
+	}
+
+	gtk_widget_show (item);
+	g_slist_free (connections);
+}
+
+static void
+cdma_device_state_changed (NMDevice *device,
+                           NMDeviceState state,
+                           NMApplet *applet)
+{
+	if (state == NM_DEVICE_STATE_ACTIVATED) {
+		applet_do_notify (applet, NOTIFY_URGENCY_LOW,
+					      _("Connection Established"),
+						  _("You are now connected to the CDMA network."),
+						  "nm-adhoc");
+	}
+}
+
+static GdkPixbuf *
+cdma_get_icon (NMDevice *device,
+               NMDeviceState state,
+               char **tip,
+               NMApplet *applet)
+{
+	GdkPixbuf *pixbuf = NULL;
+	char *iface;
+
+	iface = nm_device_get_iface (NM_DEVICE (device));
+
+	switch (state) {
+	case NM_DEVICE_STATE_PREPARE:
+		*tip = g_strdup_printf (_("Dialing CDMA device %s..."), iface);
+		break;
+	case NM_DEVICE_STATE_CONFIG:
+		*tip = g_strdup_printf (_("Running PPP on device %s..."), iface);
+		break;
+	case NM_DEVICE_STATE_ACTIVATED:
+		*tip = g_strdup (_("CDMA connection"));
+		// FIXME: get a real icon
+		pixbuf = applet->wwan_icon;
+		break;
+	default:
+		break;
+	}
+
+	g_free (iface);
+	return pixbuf;
+}
+
+NMADeviceClass *
+applet_device_cdma_get_class (NMApplet *applet)
+{
+	NMADeviceClass *dclass;
+
+	dclass = g_slice_new0 (NMADeviceClass);
+	if (!dclass)
+		return NULL;
+
+	dclass->new_auto_connection = cdma_new_auto_connection;
+	dclass->add_menu_item = cdma_add_menu_item;
+	dclass->device_state_changed = cdma_device_state_changed;
+	dclass->get_icon = cdma_get_icon;
+
+	return dclass;
+}
+

Added: trunk/src/applet-device-cdma.h
==============================================================================
--- (empty file)
+++ trunk/src/applet-device-cdma.h	Mon Jan 21 19:21:05 2008
@@ -0,0 +1,29 @@
+/* NetworkManager Wireless Applet -- Display wireless access points and allow user control
+ *
+ * Dan Williams <dcbw redhat com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * (C) Copyright 2008 Red Hat, Inc.
+ */
+
+#ifndef __APPLET_DEVICE_CDMA_H__
+#define __APPLET_DEVICE_CDMA_H__
+
+#include "applet.h"
+
+NMADeviceClass *applet_device_cdma_get_class (NMApplet *applet);
+
+#endif /* __APPLET_DEVICE_CDMA_H__ */

Modified: trunk/src/applet-device-gsm.c
==============================================================================
--- trunk/src/applet-device-gsm.c	(original)
+++ trunk/src/applet-device-gsm.c	Mon Jan 21 19:21:05 2008
@@ -67,6 +67,7 @@
 
 	s_gsm = NM_SETTING_GSM (nm_setting_gsm_new ());
 	s_gsm->number = g_strdup ("*99#"); /* This should be a sensible default as it's seems to be quite standard */
+	nm_connection_add_setting (connection, NM_SETTING (s_gsm));
 
 	/* Serial setting */
 	s_serial = (NMSettingSerial *) nm_setting_serial_new ();
@@ -259,7 +260,7 @@
 	case NM_DEVICE_STATE_ACTIVATED:
 		*tip = g_strdup (_("GSM connection"));
 		// FIXME: get a real icon
-		pixbuf = applet->adhoc_icon;
+		pixbuf = applet->wwan_icon;
 		break;
 	default:
 		break;

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Mon Jan 21 19:21:05 2008
@@ -44,6 +44,7 @@
 #include <nm-device-802-3-ethernet.h>
 #include <nm-device-802-11-wireless.h>
 #include <nm-gsm-device.h>
+#include <nm-cdma-device.h>
 #include <nm-utils.h>
 #include <nm-connection.h>
 #include <nm-vpn-connection.h>
@@ -60,6 +61,7 @@
 #include "applet-device-wired.h"
 #include "applet-device-wireless.h"
 #include "applet-device-gsm.h"
+#include "applet-device-cdma.h"
 #include "applet-dialogs.h"
 #include "vpn-password-dialog.h"
 #include "applet-dbus-manager.h"
@@ -102,6 +104,8 @@
 		return applet->wireless_class;
 	else if (NM_IS_GSM_DEVICE (device))
 		return applet->gsm_class;
+	else if (NM_IS_CDMA_DEVICE (device))
+		return applet->cdma_class;
 	else
 		g_message ("%s: Unknown device type '%s'", __func__, G_OBJECT_TYPE_NAME (device));
 	return NULL;
@@ -127,8 +131,6 @@
 	gboolean is_system = FALSE;
 
 	g_return_if_fail (NM_IS_DEVICE (device));
-	g_return_if_fail (connection != NULL);
-	g_return_if_fail (NM_IS_CONNECTION (connection));
 
 	if (connection) {
 		exported_con = applet_dbus_settings_user_get_by_connection (applet_settings, connection);
@@ -483,10 +485,20 @@
 
 	if (aa_type == NM_TYPE_DEVICE_802_3_ETHERNET && bb_type == NM_TYPE_DEVICE_802_11_WIRELESS)
 		return -1;
-	if (aa_type == NM_TYPE_DEVICE_802_11_WIRELESS && bb_type == NM_TYPE_DEVICE_802_3_ETHERNET)
-		return 1;
+	if (aa_type == NM_TYPE_DEVICE_802_3_ETHERNET && bb_type == NM_TYPE_GSM_DEVICE)
+		return -1;
+	if (aa_type == NM_TYPE_DEVICE_802_3_ETHERNET && bb_type == NM_TYPE_CDMA_DEVICE)
+		return -1;
 
-	return 0;
+	if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_CDMA_DEVICE)
+		return -1;
+	if (aa_type == NM_TYPE_GSM_DEVICE && bb_type == NM_TYPE_DEVICE_802_11_WIRELESS)
+		return -1;
+
+	if (aa_type == NM_TYPE_CDMA_DEVICE && bb_type == NM_TYPE_DEVICE_802_11_WIRELESS)
+		return -1;
+
+	return 1;
 }
 
 static NMConnection *
@@ -1433,7 +1445,7 @@
 	CLEAR_ICON(applet->no_connection_icon);
 	CLEAR_ICON(applet->wired_icon);
 	CLEAR_ICON(applet->adhoc_icon);
-	CLEAR_ICON(applet->gsm_icon);
+	CLEAR_ICON(applet->wwan_icon);
 	CLEAR_ICON(applet->vpn_lock_icon);
 	CLEAR_ICON(applet->wireless_00_icon);
 	CLEAR_ICON(applet->wireless_25_icon);
@@ -1479,7 +1491,7 @@
 	ICON_LOAD(applet->no_connection_icon, "nm-no-connection");
 	ICON_LOAD(applet->wired_icon, "nm-device-wired");
 	ICON_LOAD(applet->adhoc_icon, "nm-adhoc");
-	ICON_LOAD(applet->gsm_icon, "nm-adhoc"); /* FIXME: Until there's no GSM device icon */
+	ICON_LOAD(applet->wwan_icon, "nm-adhoc"); /* FIXME: Until there's no WWAN device icon */
 	ICON_LOAD(applet->vpn_lock_icon, "nm-vpn-lock");
 
 	ICON_LOAD(applet->wireless_00_icon, "nm-signal-00");
@@ -1703,6 +1715,9 @@
 	applet->gsm_class = applet_device_gsm_get_class (applet);
 	g_assert (applet->gsm_class);
 
+	applet->cdma_class = applet_device_cdma_get_class (applet);
+	g_assert (applet->cdma_class);
+
 	foo_client_setup (applet);
 	applet->vpn_manager = nm_vpn_manager_new ();
 	applet->vpn_connections = g_hash_table_new_full (g_str_hash, g_str_equal,

Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h	(original)
+++ trunk/src/applet.h	Mon Jan 21 19:21:05 2008
@@ -99,6 +99,7 @@
 	NMADeviceClass *wired_class;
 	NMADeviceClass *wireless_class;
 	NMADeviceClass *gsm_class;
+	NMADeviceClass *cdma_class;
 
 	/* Data model elements */
 	guint			update_icon_id;
@@ -109,7 +110,7 @@
 	GdkPixbuf *		no_connection_icon;
 	GdkPixbuf *		wired_icon;
 	GdkPixbuf *		adhoc_icon;
-	GdkPixbuf *		gsm_icon;
+	GdkPixbuf *		wwan_icon;
 	GdkPixbuf *		wireless_00_icon;
 	GdkPixbuf *		wireless_25_icon;
 	GdkPixbuf *		wireless_50_icon;

Modified: trunk/src/utils/utils.c
==============================================================================
--- trunk/src/utils/utils.c	(original)
+++ trunk/src/utils/utils.c	Mon Jan 21 19:21:05 2008
@@ -27,6 +27,7 @@
 #include <nm-device-802-3-ethernet.h>
 #include <nm-device-802-11-wireless.h>
 #include <nm-gsm-device.h>
+#include <nm-cdma-device.h>
 #include <nm-access-point.h>
 
 #include <nm-setting-connection.h>
@@ -34,6 +35,7 @@
 #include <nm-setting-wireless.h>
 #include <nm-setting-wireless-security.h>
 #include <nm-setting-gsm.h>
+#include <nm-setting-cdma.h>
 #include <nm-utils.h>
 
 #include "crypto.h"
@@ -660,6 +662,23 @@
 	return TRUE;
 }
 
+static gboolean
+connection_valid_for_cdma (NMConnection *connection,
+                           NMSettingConnection *s_con,
+                           NMDevice *device,
+                           gpointer specific_object)
+{
+	NMSettingCdma *s_cdma;
+	
+	if (strcmp (s_con->type, NM_SETTING_CDMA_SETTING_NAME))
+		return FALSE;
+
+	s_cdma = NM_SETTING_CDMA (nm_connection_get_setting (connection, NM_TYPE_SETTING_CDMA));
+	g_return_val_if_fail (s_cdma != NULL, FALSE);
+
+	return TRUE;
+}
+
 gboolean
 utils_connection_valid_for_device (NMConnection *connection,
                                    NMDevice *device,
@@ -680,8 +699,10 @@
 		return connection_valid_for_wireless (connection, s_con, device, specific_object);
 	else if (NM_IS_GSM_DEVICE (device))
 		return connection_valid_for_gsm (connection, s_con, device, specific_object);
+	else if (NM_IS_CDMA_DEVICE (device))
+		return connection_valid_for_cdma (connection, s_con, device, specific_object);
 	else
-		g_assert_not_reached ();
+		g_warning ("Unknown device type '%s'", g_type_name (G_OBJECT_TYPE(device)));
 
 	return FALSE;
 }



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