[network-manager-applet/wimax: 1/7] applet: add WiMAX device menu item and logic
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/wimax: 1/7] applet: add WiMAX device menu item and logic
- Date: Tue, 4 Jan 2011 22:22:46 +0000 (UTC)
commit a285037448995d7cf2ba246521a6a6c8f837a5d5
Author: Dan Williams <dcbw redhat com>
Date: Tue Jan 4 12:48:53 2011 -0600
applet: add WiMAX device menu item and logic
src/Makefile.am | 2 +
src/applet-device-wimax.c | 538 +++++++++++++++++++++++++++++++++++++++++++++
src/applet-device-wimax.h | 32 +++
src/applet.c | 12 +-
src/applet.h | 3 +-
src/mb-menu-item.c | 2 +
src/mobile-helpers.c | 13 +-
src/mobile-helpers.h | 1 +
src/utils/utils.c | 44 ++++
9 files changed, 640 insertions(+), 7 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 02bcad2..90902a6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,6 +51,8 @@ nm_applet_SOURCES = \
mobile-helpers.h \
applet-device-bt.h \
applet-device-bt.c \
+ applet-device-wimax.h \
+ applet-device-wimax.c \
fallback-icon.h
nm_applet_LDADD = \
diff --git a/src/applet-device-wimax.c b/src/applet-device-wimax.c
new file mode 100644
index 0000000..8a839b7
--- /dev/null
+++ b/src/applet-device-wimax.c
@@ -0,0 +1,538 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2008 - 2011 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include <nm-device.h>
+#include <nm-setting-connection.h>
+#include <nm-setting-wimax.h>
+#include <nm-device-wimax.h>
+#include <nm-utils.h>
+
+#include "applet.h"
+#include "applet-device-wimax.h"
+#include "utils.h"
+#include "applet-dialogs.h"
+#include "nma-marshal.h"
+#include "mb-menu-item.h"
+
+#define ACTIVE_NSP_TAG "active-nsp"
+
+typedef struct {
+ NMApplet *applet;
+ NMDevice *device;
+ NMConnection *connection;
+ NMWimaxNsp *nsp;
+} WimaxMenuItemInfo;
+
+static void
+wimax_menu_item_info_destroy (gpointer data)
+{
+ WimaxMenuItemInfo *info = data;
+
+ g_object_unref (G_OBJECT (info->device));
+ if (info->connection)
+ g_object_unref (info->connection);
+ g_object_unref (info->nsp);
+
+ g_slice_free (WimaxMenuItemInfo, data);
+}
+
+static gboolean
+wimax_new_auto_connection (NMDevice *device,
+ gpointer dclass_data,
+ AppletNewAutoConnectionCallback callback,
+ gpointer callback_data)
+{
+ WimaxMenuItemInfo *info = dclass_data;
+ NMConnection *connection;
+ NMSettingWimax *s_wimax = NULL;
+ NMSettingConnection *s_con;
+ char *uuid;
+ const char *nsp_name;
+
+ nsp_name = nm_wimax_nsp_get_name (info->nsp);
+
+ connection = nm_connection_new ();
+
+ s_wimax = NM_SETTING_WIMAX (nm_setting_wimax_new ());
+ g_object_set (s_wimax,
+ NM_SETTING_WIMAX_NETWORK_NAME, nsp_name,
+ NULL);
+ nm_connection_add_setting (connection, NM_SETTING (s_wimax));
+
+ s_con = NM_SETTING_CONNECTION (nm_setting_connection_new ());
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (s_con,
+ NM_SETTING_CONNECTION_ID, nsp_name,
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIMAX_SETTING_NAME,
+ NM_SETTING_CONNECTION_AUTOCONNECT, TRUE,
+ NM_SETTING_CONNECTION_UUID, uuid,
+ NULL);
+ g_free (uuid);
+
+ nm_connection_add_setting (connection, NM_SETTING (s_con));
+
+ (*callback) (connection, TRUE, FALSE, callback_data);
+ return TRUE;
+}
+
+static void
+wimax_menu_item_activate (GtkMenuItem *item, gpointer user_data)
+{
+ WimaxMenuItemInfo *info = (WimaxMenuItemInfo *) user_data;
+ const char *specific_object = NULL;
+
+ if (info->nsp)
+ specific_object = nm_object_get_path (NM_OBJECT (info->nsp));
+ applet_menu_item_activate_helper (info->device,
+ info->connection,
+ specific_object,
+ info->applet,
+ user_data);
+}
+
+static guint32
+nsp_type_to_mb_state (NMWimaxNspNetworkType nsp_type)
+{
+ switch (nsp_type) {
+ case NM_WIMAX_NSP_NETWORK_TYPE_HOME:
+ case NM_WIMAX_NSP_NETWORK_TYPE_PARTNER:
+ return MB_STATE_HOME;
+ case NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER:
+ return MB_STATE_ROAMING;
+ default:
+ break;
+ }
+
+ return MB_STATE_UNKNOWN;
+}
+
+static GtkWidget *
+new_nsp_menu_item (NMDeviceWimax *device,
+ NMConnection *connection,
+ NMWimaxNsp *nsp,
+ NMApplet *applet)
+{
+ GtkWidget *item;
+ const char *cname;
+ NMSettingConnection *s_con;
+ WimaxMenuItemInfo *info;
+
+ g_return_val_if_fail (nsp != NULL, NULL);
+
+ if (connection) {
+ s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+ g_assert (s_con);
+
+ cname = nm_setting_connection_get_id (s_con);
+ } else
+ cname = nm_wimax_nsp_get_name (nsp);
+
+ item = nm_mb_menu_item_new (cname,
+ nm_wimax_nsp_get_signal_quality (nsp),
+ nm_wimax_nsp_get_name (nsp),
+ MB_TECH_WIMAX,
+ nsp_type_to_mb_state (nm_wimax_nsp_get_network_type (nsp)),
+ TRUE,
+ applet);
+
+ info = g_slice_new0 (WimaxMenuItemInfo);
+ info->applet = applet;
+ info->device = g_object_ref (G_OBJECT (device));
+ info->connection = connection ? g_object_ref (connection) : NULL;
+ info->nsp = g_object_ref (nsp);
+
+ g_signal_connect_data (item, "activate",
+ G_CALLBACK (wimax_menu_item_activate),
+ info,
+ (GClosureNotify) wimax_menu_item_info_destroy, 0);
+
+ return item;
+}
+
+static NMConnection *
+get_connection_for_nsp (GSList *connections, NMWimaxNsp *nsp)
+{
+ GSList *iter;
+ const char *nsp_name, *candidate_name;
+
+ nsp_name = nm_wimax_nsp_get_name (nsp);
+ for (iter = connections; iter; iter = g_slist_next (iter)) {
+ NMConnection *candidate = NM_CONNECTION (iter->data);
+ NMSettingWimax *s_wimax;
+
+ s_wimax = (NMSettingWimax *) nm_connection_get_setting (candidate, NM_TYPE_SETTING_WIMAX);
+ if (s_wimax) {
+ candidate_name = nm_setting_wimax_get_network_name (s_wimax);
+ if (g_strcmp0 (nsp_name, candidate_name) == 0)
+ return candidate;
+ }
+ }
+ return NULL;
+}
+
+static gint
+sort_nsps (gconstpointer a, gconstpointer b)
+{
+ const char *name_a = NULL, *name_b = NULL;
+
+ if (a)
+ name_a = nm_wimax_nsp_get_name (NM_WIMAX_NSP (a));
+ if (b)
+ name_b = nm_wimax_nsp_get_name (NM_WIMAX_NSP (b));
+
+ return g_strcmp0 (name_a, name_b);
+}
+
+static void
+wimax_add_menu_item (NMDevice *device,
+ guint32 n_devices,
+ NMConnection *active,
+ GtkWidget *menu,
+ NMApplet *applet)
+{
+ NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device);
+ char *text;
+ GtkWidget *item;
+ GSList *connections, *all, *iter, *sorted = NULL;
+ const GPtrArray *nsps;
+ NMWimaxNsp *active_nsp = NULL;
+ gboolean wimax_enabled, wimax_hw_enabled;
+ int i;
+
+ nsps = nm_device_wimax_get_nsps (wimax);
+
+ if (n_devices > 1) {
+ char *desc;
+
+ desc = (char *) utils_get_device_description (device);
+ if (!desc)
+ desc = (char *) nm_device_get_iface (device);
+ g_assert (desc);
+
+ text = g_strdup_printf (_("Mobile Broadband WiMAX (%s)"), desc);
+ } else {
+ text = g_strdup (_("Mobile Broadband WiMAX"));
+ }
+
+ item = applet_menu_item_create_device_item_helper (device, applet, text);
+ gtk_widget_set_sensitive (item, FALSE);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ g_free (text);
+
+ /* Add the active NSP if we're connected to something and the device is available */
+ if (!nma_menu_device_check_unusable (device)) {
+ active_nsp = nm_device_wimax_get_active_nsp (wimax);
+ if (active_nsp) {
+ item = new_nsp_menu_item (wimax, active, active_nsp, applet);
+ if (item) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+ }
+ }
+
+ /* Notify user of unmanaged or unavailable device */
+ wimax_enabled = nm_client_wimax_get_enabled (applet->nm_client);
+ wimax_hw_enabled = nm_client_wimax_hardware_get_enabled (applet->nm_client);
+ item = nma_menu_device_get_menu_item (device, applet,
+ wimax_hw_enabled ?
+ (wimax_enabled ? NULL : _("WiMAX is disabled")) :
+ _("WiMAX is disabled by hardware switch"));
+ if (item) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+
+ /* If disabled or rfkilled or whatever, nothing left to do */
+ if (nma_menu_device_check_unusable (device))
+ return;
+
+ /* Create a sorted list of NSPs */
+ for (i = 0; nsps && (i < nsps->len); i++) {
+ NMWimaxNsp *nsp = g_ptr_array_index (nsps, i);
+
+ if (nsp != active_nsp)
+ sorted = g_slist_insert_sorted (sorted, nsp, sort_nsps);
+ }
+
+ if (g_slist_length (sorted)) {
+ applet_menu_item_add_complex_separator_helper (menu, applet, _("Available"), -1);
+
+ all = applet_get_all_connections (applet);
+ connections = utils_filter_connections_for_device (device, all);
+ g_slist_free (all);
+
+ /* And add menu items for each NSP */
+ for (iter = sorted; iter; iter = g_slist_next (iter)) {
+ NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data);
+ NMConnection *connection = NULL;
+
+ connection = get_connection_for_nsp (connections, nsp);
+ item = new_nsp_menu_item (wimax, connection, nsp, applet);
+ if (item) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+ }
+
+ g_slist_free (connections);
+ }
+
+ g_slist_free (sorted);
+}
+
+
+static void
+nsp_quality_changed (NMWimaxNsp *nsp, GParamSpec *pspec, gpointer user_data)
+{
+ applet_schedule_update_icon (NM_APPLET (user_data));
+}
+
+static NMWimaxNsp *
+update_active_nsp (NMDevice *device, NMDeviceState state, NMApplet *applet)
+{
+ NMWimaxNsp *new = NULL, *old;
+
+ if (state == NM_DEVICE_STATE_PREPARE ||
+ state == NM_DEVICE_STATE_CONFIG ||
+ state == NM_DEVICE_STATE_IP_CONFIG ||
+ state == NM_DEVICE_STATE_NEED_AUTH ||
+ state == NM_DEVICE_STATE_ACTIVATED) {
+ new = nm_device_wimax_get_active_nsp (NM_DEVICE_WIMAX (device));
+ }
+
+ old = g_object_get_data (G_OBJECT (device), ACTIVE_NSP_TAG);
+ if (new && (new == old))
+ return new; /* no change */
+
+ if (old) {
+ g_signal_handlers_disconnect_by_func (old, G_CALLBACK (nsp_quality_changed), applet);
+ g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, NULL);
+ }
+
+ if (new) {
+ g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, new);
+
+ /* monitor this NSP's signal strength for updating the applet icon */
+ g_signal_connect (new,
+ "notify::" NM_WIMAX_NSP_SIGNAL_QUALITY,
+ G_CALLBACK (nsp_quality_changed),
+ applet);
+ }
+
+ return new;
+}
+
+static void
+active_nsp_changed_cb (NMDeviceWimax *device,
+ GParamSpec *pspec,
+ NMApplet *applet)
+{
+ NMSettingsConnectionInterface *connection;
+ NMSettingWimax *s_wimax;
+ NMWimaxNsp *new;
+ NMDeviceState state;
+
+ state = nm_device_get_state (NM_DEVICE (device));
+
+ new = update_active_nsp (NM_DEVICE (device), state, applet);
+ if (!new || (state != NM_DEVICE_STATE_ACTIVATED))
+ return;
+
+ connection = applet_get_exported_connection_for_device (NM_DEVICE (device), applet);
+ if (!connection)
+ return;
+
+ s_wimax = (NMSettingWimax *) nm_connection_get_setting (NM_CONNECTION (connection), NM_TYPE_SETTING_WIMAX);
+ if (!s_wimax)
+ return;
+
+ if (g_strcmp0 (nm_wimax_nsp_get_name (new), nm_setting_wimax_get_network_name (s_wimax)) != 0)
+ applet_schedule_update_icon (applet);
+}
+
+static void
+nsp_removed_cb (NMDeviceWimax *device,
+ NMWimaxNsp *nsp,
+ gpointer user_data)
+{
+ NMApplet *applet = NM_APPLET (user_data);
+ NMWimaxNsp *old;
+
+ /* Clear the ACTIVE_NSP_TAG if the active NSP just got removed */
+ old = g_object_get_data (G_OBJECT (device), ACTIVE_NSP_TAG);
+ if (old == nsp) {
+ g_object_set_data (G_OBJECT (device), ACTIVE_NSP_TAG, NULL);
+ applet_schedule_update_icon (applet);
+ }
+}
+
+static void
+wimax_device_added (NMDevice *device, NMApplet *applet)
+{
+ g_signal_connect (device,
+ "notify::" NM_DEVICE_WIMAX_ACTIVE_NSP,
+ G_CALLBACK (active_nsp_changed_cb),
+ applet);
+
+ g_signal_connect (device,
+ "nsp-removed",
+ G_CALLBACK (nsp_removed_cb),
+ applet);
+}
+
+static void
+wimax_device_state_changed (NMDevice *device,
+ NMDeviceState new_state,
+ NMDeviceState old_state,
+ NMDeviceStateReason reason,
+ NMApplet *applet)
+{
+ if (new_state == NM_DEVICE_STATE_ACTIVATED) {
+ NMConnection *connection;
+ NMSettingConnection *s_con = NULL;
+ char *str = NULL;
+
+ connection = applet_find_active_connection_for_device (device, applet, NULL);
+ if (connection) {
+ const char *id;
+
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ id = s_con ? nm_setting_connection_get_id (s_con) : NULL;
+ if (id)
+ str = g_strdup_printf (_("You are now connected to '%s'."), id);
+ }
+
+ applet_do_notify_with_pref (applet,
+ _("Connection Established"),
+ str ? str : _("You are now connected to the WiMAX network."),
+ "nm-device-wwan",
+ PREF_DISABLE_CONNECTED_NOTIFICATIONS);
+ g_free (str);
+ }
+}
+
+static GdkPixbuf *
+wimax_get_icon (NMDevice *device,
+ NMDeviceState state,
+ NMConnection *connection,
+ char **tip,
+ NMApplet *applet)
+{
+ NMSettingConnection *s_con;
+ GdkPixbuf *pixbuf = NULL;
+ const char *id;
+ NMWimaxNsp *nsp;
+ guint32 quality = 0;
+ NMWimaxNspNetworkType nsp_type = NM_WIMAX_NSP_NETWORK_TYPE_UNKNOWN;
+ gboolean roaming;
+
+ id = nm_device_get_iface (NM_DEVICE (device));
+ if (connection) {
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ id = nm_setting_connection_get_id (s_con);
+ }
+
+ nsp = nm_device_wimax_get_active_nsp (NM_DEVICE_WIMAX (device));
+ if (nsp) {
+ quality = nm_wimax_nsp_get_signal_quality (nsp);
+ nsp_type = nm_wimax_nsp_get_network_type (nsp);
+ }
+
+ switch (state) {
+ case NM_DEVICE_STATE_PREPARE:
+ *tip = g_strdup_printf (_("Preparing mobile broadband connection '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_CONFIG:
+ *tip = g_strdup_printf (_("Configuring mobile broadband connection '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_NEED_AUTH:
+ *tip = g_strdup_printf (_("User authentication required for mobile broadband connection '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_IP_CONFIG:
+ *tip = g_strdup_printf (_("Requesting a network address for '%s'..."), id);
+ break;
+ case NM_DEVICE_STATE_ACTIVATED:
+ roaming = (nsp_type == NM_WIMAX_NSP_NETWORK_TYPE_ROAMING_PARTNER);
+ pixbuf = mobile_helper_get_status_pixbuf (quality,
+ TRUE,
+ nsp_type_to_mb_state (nsp_type),
+ MB_TECH_WIMAX,
+ applet);
+ *tip = g_strdup_printf (_("Mobile broadband connection '%s' active: (%d%%%s%s)"),
+ id, quality,
+ roaming ? ", " : "",
+ roaming ? _("roaming") : "");
+ break;
+ default:
+ break;
+ }
+
+ return pixbuf;
+}
+
+static gboolean
+wimax_get_secrets (NMDevice *device,
+ NMSettingsConnectionInterface *connection,
+ NMActiveConnection *active_connection,
+ const char *setting_name,
+ const char **hints,
+ NMANewSecretsRequestedFunc callback,
+ gpointer callback_data,
+ NMApplet *applet,
+ GError **error)
+{
+ g_set_error (error,
+ NM_SETTINGS_INTERFACE_ERROR,
+ NM_SETTINGS_INTERFACE_ERROR_INTERNAL_ERROR,
+ "%s.%d (%s): no WiMAX secrets available.",
+ __FILE__, __LINE__, __func__);
+ return FALSE;
+}
+
+NMADeviceClass *
+applet_device_wimax_get_class (NMApplet *applet)
+{
+ NMADeviceClass *dclass;
+
+ dclass = g_slice_new0 (NMADeviceClass);
+ if (!dclass)
+ return NULL;
+
+ dclass->new_auto_connection = wimax_new_auto_connection;
+ dclass->add_menu_item = wimax_add_menu_item;
+ dclass->device_added = wimax_device_added;
+ dclass->device_state_changed = wimax_device_state_changed;
+ dclass->get_icon = wimax_get_icon;
+ dclass->get_secrets = wimax_get_secrets;
+
+ return dclass;
+}
+
diff --git a/src/applet-device-wimax.h b/src/applet-device-wimax.h
new file mode 100644
index 0000000..185544b
--- /dev/null
+++ b/src/applet-device-wimax.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2011 Red Hat, Inc.
+ */
+
+#ifndef __APPLET_DEVICE_WIMAX_H__
+#define __APPLET_DEVICE_WIMAX_H__
+
+#include <gtk/gtk.h>
+
+#include "applet.h"
+
+NMADeviceClass *applet_device_wimax_get_class (NMApplet *applet);
+
+#endif /* __APPLET_DEVICE_WIMAX_H__ */
diff --git a/src/applet.c b/src/applet.c
index 15bb94f..cdf5a63 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright (C) 2004 - 2010 Red Hat, Inc.
+ * Copyright (C) 2004 - 2011 Red Hat, Inc.
* Copyright (C) 2005 - 2008 Novell, Inc.
*
* This applet used the GNOME Wireless Applet as a skeleton to build from.
@@ -45,6 +45,7 @@
#include <nm-gsm-device.h>
#include <nm-cdma-device.h>
#include <nm-device-bt.h>
+#include <nm-device-wimax.h>
#include <nm-utils.h>
#include <nm-connection.h>
#include <nm-vpn-connection.h>
@@ -63,6 +64,7 @@
#include "applet-device-gsm.h"
#include "applet-device-cdma.h"
#include "applet-device-bt.h"
+#include "applet-device-wimax.h"
#include "applet-dialogs.h"
#include "vpn-password-dialog.h"
#include "applet-dbus-manager.h"
@@ -261,6 +263,8 @@ get_device_class (NMDevice *device, NMApplet *applet)
return applet->cdma_class;
else if (NM_IS_DEVICE_BT (device))
return applet->bt_class;
+ else if (NM_IS_DEVICE_WIMAX (device))
+ return applet->wimax_class;
else
g_message ("%s: Unknown device type '%s'", __func__, G_OBJECT_TYPE_NAME (device));
return NULL;
@@ -3111,6 +3115,9 @@ constructor (GType type,
applet->bt_class = applet_device_bt_get_class (applet);
g_assert (applet->bt_class);
+ applet->wimax_class = applet_device_wimax_get_class (applet);
+ g_assert (applet->wimax_class);
+
foo_client_setup (applet);
/* timeout to update connection timestamps every 5 minutes */
@@ -3147,6 +3154,9 @@ static void finalize (GObject *object)
g_slice_free (NMADeviceClass, applet->wired_class);
g_slice_free (NMADeviceClass, applet->wifi_class);
g_slice_free (NMADeviceClass, applet->gsm_class);
+ g_slice_free (NMADeviceClass, applet->cdma_class);
+ g_slice_free (NMADeviceClass, applet->bt_class);
+ g_slice_free (NMADeviceClass, applet->wimax_class);
if (applet->update_icon_id)
g_source_remove (applet->update_icon_id);
diff --git a/src/applet.h b/src/applet.h
index f300650..236ced9 100644
--- a/src/applet.h
+++ b/src/applet.h
@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
- * Copyright (C) 2004 - 2010 Red Hat, Inc.
+ * Copyright (C) 2004 - 2011 Red Hat, Inc.
* Copyright (C) 2005 - 2008 Novell, Inc.
*/
@@ -101,6 +101,7 @@ typedef struct
NMADeviceClass *gsm_class;
NMADeviceClass *cdma_class;
NMADeviceClass *bt_class;
+ NMADeviceClass *wimax_class;
/* Data model elements */
guint update_icon_id;
diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c
index b758ca7..c4357e8 100644
--- a/src/mb-menu-item.c
+++ b/src/mb-menu-item.c
@@ -70,6 +70,8 @@ get_tech_name (guint32 tech)
return _("HSUPA");
case MB_TECH_HSPA:
return _("HSPA");
+ case MB_TECH_WIMAX:
+ return _("WiMAX");
default:
break;
}
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
index 5901c48..bd3e7ea 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -70,11 +70,13 @@ mobile_helper_get_status_pixbuf (guint32 quality,
GDK_INTERP_BILINEAR, 255);
} else {
tmp = mobile_helper_get_tech_icon (access_tech, applet);
- gdk_pixbuf_composite (tmp, pixbuf, 0, 0,
- gdk_pixbuf_get_width (tmp),
- gdk_pixbuf_get_height (tmp),
- 0, 0, 1.0, 1.0,
- GDK_INTERP_BILINEAR, 255);
+ if (tmp) {
+ gdk_pixbuf_composite (tmp, pixbuf, 0, 0,
+ gdk_pixbuf_get_width (tmp),
+ gdk_pixbuf_get_height (tmp),
+ 0, 0, 1.0, 1.0,
+ GDK_INTERP_BILINEAR, 255);
+ }
}
return pixbuf;
@@ -115,6 +117,7 @@ mobile_helper_get_tech_icon (guint32 tech, NMApplet *applet)
case MB_TECH_HSUPA:
case MB_TECH_HSPA:
return nma_icon_check_and_load ("nm-tech-hspa", &applet->mb_tech_hspa_icon, applet);
+ case MB_TECH_WIMAX:
default:
return NULL;
}
diff --git a/src/mobile-helpers.h b/src/mobile-helpers.h
index fc21328..9461fde 100644
--- a/src/mobile-helpers.h
+++ b/src/mobile-helpers.h
@@ -47,6 +47,7 @@ enum {
MB_TECH_HSDPA,
MB_TECH_HSUPA,
MB_TECH_HSPA,
+ MB_TECH_WIMAX,
};
GdkPixbuf *mobile_helper_get_status_pixbuf (guint32 quality,
diff --git a/src/utils/utils.c b/src/utils/utils.c
index de99a2a..eccaab3 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -30,6 +30,7 @@
#include <nm-device-bt.h>
#include <nm-gsm-device.h>
#include <nm-cdma-device.h>
+#include <nm-device-wimax.h>
#include <nm-access-point.h>
#include <nm-setting-connection.h>
@@ -41,6 +42,7 @@
#include <nm-setting-cdma.h>
#include <nm-setting-pppoe.h>
#include <nm-setting-bluetooth.h>
+#include <nm-setting-wimax.h>
#include <nm-utils.h>
#include "utils.h"
@@ -538,6 +540,46 @@ connection_valid_for_bt (NMConnection *connection,
return addr_match;
}
+static gboolean
+connection_valid_for_wimax (NMConnection *connection,
+ NMSettingConnection *s_con,
+ NMDevice *device,
+ gpointer specific_object)
+{
+ NMDeviceWimax *wimax = NM_DEVICE_WIMAX (device);
+ NMSettingWimax *s_wimax;
+ const char *str_mac;
+ struct ether_addr *bin_mac;
+ const char *connection_type;
+ const GByteArray *setting_mac;
+
+ connection_type = nm_setting_connection_get_connection_type (s_con);
+ if (strcmp (connection_type, NM_SETTING_WIMAX_SETTING_NAME))
+ return FALSE;
+
+ s_wimax = (NMSettingWimax *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIMAX);
+ if (!s_wimax)
+ return FALSE;
+
+ if (s_wimax) {
+ /* Match MAC address */
+ setting_mac = nm_setting_wimax_get_mac_address (s_wimax);
+ if (!setting_mac)
+ return TRUE;
+
+ str_mac = nm_device_wimax_get_hw_address (wimax);
+ g_return_val_if_fail (str_mac != NULL, FALSE);
+
+ bin_mac = ether_aton (str_mac);
+ g_return_val_if_fail (bin_mac != NULL, FALSE);
+
+ if (memcmp (bin_mac->ether_addr_octet, setting_mac->data, ETH_ALEN))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gboolean
utils_connection_valid_for_device (NMConnection *connection,
NMDevice *device,
@@ -562,6 +604,8 @@ utils_connection_valid_for_device (NMConnection *connection,
return connection_valid_for_cdma (connection, s_con, device, specific_object);
else if (NM_IS_DEVICE_BT (device))
return connection_valid_for_bt (connection, s_con, device, specific_object);
+ else if (NM_IS_DEVICE_WIMAX (device))
+ return connection_valid_for_wimax (connection, s_con, device, specific_object);
else
g_warning ("Unknown device type '%s'", g_type_name (G_OBJECT_TYPE(device)));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]