network-manager-applet r679 - in trunk: . po src/connection-editor



Author: dcbw
Date: Wed Apr 16 15:14:18 2008
New Revision: 679
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=679&view=rev

Log:
2008-04-16  Dan Williams  <dcbw redhat com>

	* src/connection-editor/ce-mobile-wizard.glade
	  src/connection-editor/mobile-wizard.c
	  src/connection-editor/mobile-wizard.h
	  src/connection-editor/Makefile.am
	  po/POTFILES.in
		- Add connection type chooser

	* src/connection-editor/nm-connection-list.c
		- (create_new_connection_for_type): handle mobile broadband too



Added:
   trunk/src/connection-editor/ce-mobile-wizard.glade
   trunk/src/connection-editor/mobile-wizard.c
   trunk/src/connection-editor/mobile-wizard.h
Modified:
   trunk/ChangeLog
   trunk/po/POTFILES.in
   trunk/src/connection-editor/Makefile.am
   trunk/src/connection-editor/nm-connection-list.c

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Wed Apr 16 15:14:18 2008
@@ -11,10 +11,12 @@
 src/applet.c
 src/applet.glade
 src/applet.h
+src/connection-editor/ce-mobile-wizard.glade
 src/connection-editor/ce-page-ip4.glade
 src/connection-editor/ce-page-wired.glade
 src/connection-editor/ce-page-wireless.glade
 src/connection-editor/ce-page-wireless-security.glade
+src/connection-editor/mobile-wizard.c
 src/connection-editor/page-ip4.c
 src/connection-editor/page-wired.c
 src/connection-editor/page-wired-security.c

Modified: trunk/src/connection-editor/Makefile.am
==============================================================================
--- trunk/src/connection-editor/Makefile.am	(original)
+++ trunk/src/connection-editor/Makefile.am	Wed Apr 16 15:14:18 2008
@@ -39,7 +39,9 @@
 	page-dsl.h \
 	page-dsl.c \
 	page-mobile.h \
-	page-mobile.c
+	page-mobile.c \
+	mobile-wizard.h \
+	mobile-wizard.c
 
 nm_connection_editor_LDADD = \
 	$(top_builddir)/src/gconf-helpers/libgconf-helpers.la \
@@ -55,7 +57,8 @@
 	ce-page-wireless-security.glade \
 	ce-page-ip4.glade \
 	ce-page-dsl.glade \
-	ce-page-mobile.glade
+	ce-page-mobile.glade \
+	ce-mobile-wizard.glade
 
 CLEANFILES = *.bak *.gladep
 

Added: trunk/src/connection-editor/ce-mobile-wizard.glade
==============================================================================
--- (empty file)
+++ trunk/src/connection-editor/ce-mobile-wizard.glade	Wed Apr 16 15:14:18 2008
@@ -0,0 +1,166 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd";>
+
+<glade-interface>
+<requires lib="gnome"/>
+
+<widget class="GtkDialog" id="new_connection_dialog">
+  <property name="border_width">6</property>
+  <property name="title" translatable="yes"> </property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_CENTER_ALWAYS</property>
+  <property name="modal">True</property>
+  <property name="resizable">False</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="icon_name">gtk-dialog-question</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
+  <property name="has_separator">False</property>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="vbox2">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">14</property>
+
+      <child internal-child="action_area">
+	<widget class="GtkHButtonBox" id="hbuttonbox1">
+	  <property name="visible">True</property>
+	  <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+	  <child>
+	    <widget class="GtkButton" id="cancel_button">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="has_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-cancel</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="response_id">-6</property>
+	    </widget>
+	  </child>
+
+	  <child>
+	    <widget class="GtkButton" id="ok_button">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-ok</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="response_id">-5</property>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">False</property>
+	  <property name="fill">True</property>
+	  <property name="pack_type">GTK_PACK_END</property>
+	</packing>
+      </child>
+
+      <child>
+	<widget class="GtkHBox" id="hbox2">
+	  <property name="border_width">5</property>
+	  <property name="visible">True</property>
+	  <property name="homogeneous">False</property>
+	  <property name="spacing">12</property>
+
+	  <child>
+	    <widget class="GtkImage" id="image2">
+	      <property name="visible">True</property>
+	      <property name="stock">gtk-dialog-question</property>
+	      <property name="icon_size">6</property>
+	      <property name="xalign">0.5</property>
+	      <property name="yalign">0</property>
+	      <property name="xpad">0</property>
+	      <property name="ypad">0</property>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">False</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkVBox" id="vbox3">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">12</property>
+
+	      <child>
+		<widget class="GtkLabel" id="label1">
+		  <property name="visible">True</property>
+		  <property name="label" translatable="yes">&lt;span weight=&quot;bold&quot; size=&quot;larger&quot;&gt;Choose a Mobile Broadband Connection&lt;/span&gt;
+
+Select or connect the mobile broadband device you wish to use for the new connection.  If the device is not availabe, you may select a generic connection type.</property>
+		  <property name="use_underline">False</property>
+		  <property name="use_markup">True</property>
+		  <property name="justify">GTK_JUSTIFY_LEFT</property>
+		  <property name="wrap">True</property>
+		  <property name="selectable">False</property>
+		  <property name="xalign">0</property>
+		  <property name="yalign">0.5</property>
+		  <property name="xpad">0</property>
+		  <property name="ypad">0</property>
+		  <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+		  <property name="width_chars">-1</property>
+		  <property name="single_line_mode">False</property>
+		  <property name="angle">0</property>
+		</widget>
+		<packing>
+		  <property name="padding">0</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+
+	      <child>
+		<widget class="GtkVBox" id="options_vbox">
+		  <property name="visible">True</property>
+		  <property name="homogeneous">False</property>
+		  <property name="spacing">0</property>
+
+		  <child>
+		    <placeholder/>
+		  </child>
+
+		  <child>
+		    <placeholder/>
+		  </child>
+		</widget>
+		<packing>
+		  <property name="padding">6</property>
+		  <property name="expand">False</property>
+		  <property name="fill">False</property>
+		</packing>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="padding">0</property>
+	      <property name="expand">True</property>
+	      <property name="fill">True</property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
+</glade-interface>

Added: trunk/src/connection-editor/mobile-wizard.c
==============================================================================
--- (empty file)
+++ trunk/src/connection-editor/mobile-wizard.c	Wed Apr 16 15:14:18 2008
@@ -0,0 +1,258 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * 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.
+ */
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include <glade/glade.h>
+#include <gtk/gtkdialog.h>
+#include <gtk/gtkbutton.h>
+#include <gtk/gtkradiobutton.h>
+#include <gtk/gtkbox.h>
+
+#include <NetworkManager.h>
+#include <nm-client.h>
+#include <nm-setting-gsm.h>
+#include <nm-setting-cdma.h>
+#include <nm-gsm-device.h>
+#include <nm-cdma-device.h>
+
+#include "mobile-wizard.h"
+#include "utils.h"
+
+#define DEVICE_TAG "device"
+#define TYPE_TAG "setting-type"
+
+static void
+ok_clicked (GtkButton *button, gpointer user_data)
+{
+	gtk_dialog_response (GTK_DIALOG (user_data), GTK_RESPONSE_OK);
+}
+
+static void
+cancel_clicked (GtkButton *button, gpointer user_data)
+{
+	gtk_dialog_response (GTK_DIALOG (user_data), GTK_RESPONSE_CANCEL);
+}
+
+typedef struct {
+	NMClient *client;
+	GladeXML *xml;
+	GtkWidget *dialog;
+	GtkWidget *radio;
+} MobileWizardInfo;
+
+static void
+device_added_cb (NMClient *client, NMDevice *device, MobileWizardInfo *info)
+{
+	GtkWidget *vbox;
+	GtkWidget *radio = NULL;
+	char *desc = (char *) utils_get_device_description (device);
+
+	vbox = glade_xml_get_widget (info->xml, "options_vbox");
+	g_assert (vbox);
+
+	if (G_OBJECT_TYPE (device) == NM_TYPE_GSM_DEVICE) {
+		if (!desc)
+			desc = _("Installed GSM device");
+
+		radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (info->radio), desc);
+
+		g_object_set_data (G_OBJECT (radio), TYPE_TAG,
+		                   GUINT_TO_POINTER (NM_TYPE_SETTING_GSM));
+		g_object_set_data_full (G_OBJECT (radio), DEVICE_TAG,
+		                        g_object_ref (device),
+		                        (GDestroyNotify) g_object_unref);
+	} else if (G_OBJECT_TYPE (device) == NM_TYPE_CDMA_DEVICE) {
+		if (!desc)
+			desc = _("Installed CDMA device");
+
+		radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (info->radio), desc);
+
+		g_object_set_data (G_OBJECT (radio), TYPE_TAG,
+		                   GUINT_TO_POINTER (NM_TYPE_SETTING_CDMA));
+		g_object_set_data_full (G_OBJECT (radio), DEVICE_TAG,
+		                        g_object_ref (device),
+		                        (GDestroyNotify) g_object_unref);
+	}
+
+	if (radio) {
+		gtk_box_pack_end (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
+		gtk_widget_show_all (radio);
+	}
+}
+
+static void
+device_removed_cb (NMClient *client, NMDevice *device, MobileWizardInfo *info)
+{
+	GtkWidget *vbox, *prev = NULL;
+	GList *children, *iter;
+
+	vbox = glade_xml_get_widget (info->xml, "options_vbox");
+	g_assert (vbox);
+
+	children = gtk_container_get_children (GTK_CONTAINER (vbox));
+	for (iter = children; iter; iter = g_list_next (iter)) {
+		if (g_object_get_data (G_OBJECT (iter->data), DEVICE_TAG) == device) {
+			gtk_widget_destroy (GTK_WIDGET (iter->data));
+			break;
+		}
+		prev = iter->data;
+	}
+
+	/* Select the item just above the removed item, or if there aren't
+	 * any device-based items left in the list, the default one.
+	 */
+	if (!prev)
+		prev = info->radio;
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (prev), TRUE);
+}
+
+static void
+add_initial_devices (MobileWizardInfo *info)
+{
+	GtkWidget *vbox;
+	const GPtrArray *devices;
+	int i;
+
+	vbox = glade_xml_get_widget (info->xml, "options_vbox");
+	g_assert (vbox);
+
+	devices = nm_client_get_devices (info->client);
+	for (i = 0; devices && (i < devices->len); i++)
+		device_added_cb (info->client, g_ptr_array_index (devices, i), info);
+
+	gtk_widget_show_all (vbox);
+}
+
+static GtkWidget *
+add_generic_options (GladeXML *xml)
+{
+	GtkWidget *vbox;
+	GtkWidget *radio;
+	const char *gsm_desc = _("Create a GSM connection");
+	const char *cdma_desc = _("Create a CDMA connection");
+
+	vbox = glade_xml_get_widget (xml, "options_vbox");
+	g_assert (vbox);
+
+	radio = gtk_radio_button_new_with_label (NULL, cdma_desc);
+	g_object_set_data (G_OBJECT (radio), TYPE_TAG, GUINT_TO_POINTER (NM_TYPE_SETTING_CDMA));
+	gtk_box_pack_end (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
+	gtk_widget_show (radio);
+
+	radio = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio), gsm_desc);
+	g_object_set_data (G_OBJECT (radio), TYPE_TAG, GUINT_TO_POINTER (NM_TYPE_SETTING_GSM));
+	gtk_box_pack_end (GTK_BOX (vbox), radio, FALSE, FALSE, 0);
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
+	gtk_widget_show (radio);
+
+	return radio;
+}
+
+static void
+remove_all_devices (GladeXML *xml)
+{
+	GtkWidget *vbox;
+	GList *children, *iter;
+
+	vbox = glade_xml_get_widget (xml, "options_vbox");
+	g_assert (vbox);
+
+	children = gtk_container_get_children (GTK_CONTAINER (vbox));
+	for (iter = children; iter; iter = g_list_next (iter)) {
+		if (g_object_get_data (G_OBJECT (iter->data), DEVICE_TAG))
+			gtk_widget_destroy (GTK_WIDGET (iter->data));
+	}
+}
+
+static void
+manager_running_cb (NMClient *client, GParamSpec *pspec, MobileWizardInfo *info)
+{
+	if (nm_client_get_manager_running (client))
+		add_initial_devices (info);
+	else
+		remove_all_devices (info->xml);
+}
+
+GType
+mobile_wizard_ask_connection_type (void)
+{
+	MobileWizardInfo info;
+	GType choice = 0;
+	gint response;
+	GtkWidget *widget;
+	GtkWidget *vbox;
+
+	info.xml = glade_xml_new (GLADEDIR "/ce-mobile-wizard.glade", "new_connection_dialog", NULL);
+	if (!info.xml) {
+		g_warning ("Could not load Glade file for new mobile broadband connection dialog");
+		return 0;
+	}
+
+	info.dialog = glade_xml_get_widget (info.xml, "new_connection_dialog");
+	if (!info.dialog) {
+		g_warning ("Could not load Glade file for new mobile broadband connection dialog");
+		return 0;
+	}
+
+	widget = glade_xml_get_widget (info.xml, "ok_button");
+	g_signal_connect (widget, "clicked", G_CALLBACK (ok_clicked), info.dialog);
+
+	widget = glade_xml_get_widget (info.xml, "cancel_button");
+	g_signal_connect (widget, "clicked", G_CALLBACK (cancel_clicked), info.dialog);
+
+	info.client = nm_client_new ();
+	g_signal_connect (info.client, "device-added", G_CALLBACK (device_added_cb), &info);
+	g_signal_connect (info.client, "device-removed", G_CALLBACK (device_removed_cb), &info);
+	g_signal_connect (info.client, "notify::manager-running", G_CALLBACK (manager_running_cb), &info);
+
+	vbox = glade_xml_get_widget (info.xml, "options_vbox");
+
+	info.radio = add_generic_options (info.xml);
+
+	/* If NM is running, add the mobile broadband devices it knows about */
+	if (nm_client_get_manager_running (info.client))
+		add_initial_devices (&info);
+
+	/* Ask the user which type of connection they want to create */
+	response = gtk_dialog_run (GTK_DIALOG (info.dialog));
+	gtk_widget_hide (info.dialog);
+	if (response == GTK_RESPONSE_OK) {
+		GList *children, *iter;
+
+		/* Get the radio button the user selected */
+		children = gtk_container_get_children (GTK_CONTAINER (vbox));
+		for (iter = children; iter; iter = g_list_next (iter)) {
+			if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (iter->data))) {
+				choice = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (iter->data), TYPE_TAG));
+				break;
+			}
+		}
+	}
+
+	g_object_unref (info.client);
+	g_object_unref (info.xml);	
+	return choice;
+}
+

Added: trunk/src/connection-editor/mobile-wizard.h
==============================================================================
--- (empty file)
+++ trunk/src/connection-editor/mobile-wizard.h	Wed Apr 16 15:14:18 2008
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* NetworkManager Connection editor -- Connection editor for NetworkManager
+ *
+ * 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 MOBILE_WIZARD_H
+#define MOBILE_WIZARD_H
+
+#include <glib.h>
+
+GType mobile_wizard_ask_connection_type (void);
+
+
+#endif /* MOBILE_WIZARD_H */

Modified: trunk/src/connection-editor/nm-connection-list.c
==============================================================================
--- trunk/src/connection-editor/nm-connection-list.c	(original)
+++ trunk/src/connection-editor/nm-connection-list.c	Wed Apr 16 15:14:18 2008
@@ -43,10 +43,12 @@
 #include <nm-setting-gsm.h>
 #include <nm-setting-cdma.h>
 #include <nm-setting-pppoe.h>
+#include <nm-setting-serial.h>
 
 #include "nm-connection-editor.h"
 #include "nm-connection-list.h"
 #include "gconf-helpers.h"
+#include "mobile-wizard.h"
 
 G_DEFINE_TYPE (NMConnectionList, nm_connection_list, G_TYPE_OBJECT)
 
@@ -307,12 +309,26 @@
 	return cname;
 }
 
+static void
+add_default_serial_setting (NMConnection *connection)
+{
+	NMSettingSerial *s_serial;
+
+	s_serial = NM_SETTING_SERIAL (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));
+}
+
 static NMConnection *
 create_new_connection_for_type (NMConnectionList *list, GType ctype)
 {
 	NMConnection *connection = NULL;
 	NMSettingConnection *s_con;
 	NMSetting *type_setting = NULL;
+	GType mb_type;
 
 	connection = nm_connection_new ();
 	s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
@@ -331,9 +347,37 @@
 
 		type_setting = nm_setting_wireless_new ();
 	} else if (ctype == NM_TYPE_SETTING_GSM) {
-		/* Since GSM is a placeholder for both GSM and CDMA; as the user which
+		/* Since GSM is a placeholder for both GSM and CDMA; ask the user which
 		 * one they really want.
 		 */
+		mb_type = mobile_wizard_ask_connection_type ();
+		if (mb_type == NM_TYPE_SETTING_GSM) {
+			NMSettingGsm *s_gsm;
+
+			s_con->id = get_next_available_name (list, _("GSM connection %d"));
+			s_con->type = g_strdup (NM_SETTING_GSM_SETTING_NAME);
+			s_con->autoconnect = FALSE;
+
+			add_default_serial_setting (connection);
+
+			type_setting = nm_setting_gsm_new ();
+			s_gsm = NM_SETTING_GSM (type_setting);
+			s_gsm->number = g_strdup ("*99#"); /* De-facto standard for GSM */
+		} else if (mb_type == NM_TYPE_SETTING_CDMA) {
+			NMSettingCdma *s_cdma;
+
+			s_con->id = get_next_available_name (list, _("CDMA connection %d"));
+			s_con->type = g_strdup (NM_SETTING_CDMA_SETTING_NAME);
+			s_con->autoconnect = FALSE;
+
+			add_default_serial_setting (connection);
+
+			type_setting = nm_setting_cdma_new ();
+			s_cdma = NM_SETTING_CDMA (type_setting);
+			s_cdma->number = g_strdup ("#777"); /* De-facto standard for CDMA */
+		} else {
+			/* user canceled; do nothing */
+		}
 	} else if (ctype == NM_TYPE_SETTING_VPN) {
 		s_con->id = get_next_available_name (list, _("VPN connection %d"));
 		s_con->type = g_strdup (NM_SETTING_VPN_SETTING_NAME);



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