[network-manager-applet] cdma: add current signal strength menu's device description item
- From: Dan Williams <dcbw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] cdma: add current signal strength menu's device description item
- Date: Sun, 28 Feb 2010 20:09:03 +0000 (UTC)
commit 5d285b79fa63e1172708845c03fe6f9d49ea3b16
Author: Dan Williams <dcbw redhat com>
Date: Sun Feb 28 12:05:03 2010 -0800
cdma: add current signal strength menu's device description item
src/Makefile.am | 2 +
src/applet-device-cdma.c | 133 +++++++++++++-----------
src/mb-menu-item.c | 253 ++++++++++++++++++++++++++++++++++++++++++++++
src/mb-menu-item.h | 79 ++++++++++++++
4 files changed, 406 insertions(+), 61 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 6bd7b04..b970a71 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -41,6 +41,8 @@ nm_applet_SOURCES = \
applet-device-wifi.c \
ap-menu-item.h \
ap-menu-item.c \
+ mb-menu-item.h \
+ mb-menu-item.c \
applet-device-gsm.h \
applet-device-gsm.c \
applet-device-cdma.h \
diff --git a/src/applet-device-cdma.c b/src/applet-device-cdma.c
index d0ea99f..8df8847 100644
--- a/src/applet-device-cdma.c
+++ b/src/applet-device-cdma.c
@@ -42,6 +42,7 @@
#include "applet-dialogs.h"
#include "nma-marshal.h"
#include "nmn-mobile-providers.h"
+#include "mb-menu-item.h"
typedef struct {
NMApplet *applet;
@@ -253,61 +254,27 @@ typedef struct {
guint32 poll_id;
} CdmaDeviceInfo;
-static char *
-get_cdma_desc (NMDevice *device, CdmaDeviceInfo *info)
+static guint32
+state_for_info (CdmaDeviceInfo *info, guint32 *out_tech)
{
- NMDeviceState state;
- char *desc = NULL;
-
- state = nm_device_get_state (device);
- if (state <= NM_DEVICE_STATE_UNAVAILABLE)
- return NULL;
+ guint32 state = MB_STATE_UNKNOWN;
if (info->evdo_state) {
- switch (info->evdo_state) {
- default:
- case 1: /* REGISTERED */
- case 2: /* HOME */
- if (info->provider_name)
- desc = g_strdup_printf (_("%s EVDO"), info->provider_name);
- else {
- if (info->evdo_state == 2)
- desc = g_strdup (_("Home Network (EVDO)"));
- else
- desc = g_strdup (_("Registered (EVDO)"));
- }
- break;
- case 3: /* ROAMING */
- if (info->provider_name)
- desc = g_strdup_printf (_("%s (EVDO roaming)"), info->provider_name);
- else
- desc = g_strdup (_("Roaming Network (EVDO)"));
- break;
- }
+ *out_tech = MB_TECH_EVDO_REVA;
+ if (info->evdo_state == 1 || info->evdo_state == 2)
+ state = MB_STATE_HOME;
+ else if (info->evdo_state == 3)
+ state = MB_STATE_ROAMING;
} else if (info->cdma1x_state) {
- switch (info->cdma1x_state) {
- default:
- case 1: /* REGISTERED */
- case 2: /* HOME */
- if (info->provider_name)
- desc = g_strdup_printf (_("%s CDMA"), info->provider_name);
- else {
- if (info->evdo_state == 2)
- desc = g_strdup (_("Home Network (CDMA)"));
- else
- desc = g_strdup (_("Registered (CDMA)"));
- }
- break;
- case 3: /* ROAMING */
- if (info->provider_name)
- desc = g_strdup_printf (_("%s (CDMA roaming)"), info->provider_name);
- else
- desc = g_strdup (_("Roaming Network (CDMA)"));
- break;
- }
+ *out_tech = MB_TECH_1XRTT;
+ if (info->cdma1x_state == 1 || info->cdma1x_state == 2)
+ state = MB_STATE_HOME;
+ else if (info->cdma1x_state == 3)
+ state = MB_STATE_ROAMING;
+ } else {
+ *out_tech = MB_TECH_1XRTT;
}
-
- return desc;
+ return state;
}
static void
@@ -320,7 +287,7 @@ cdma_add_menu_item (NMDevice *device,
CdmaDeviceInfo *info;
char *text;
GtkWidget *item;
- GSList *connections, *all;
+ GSList *connections, *all, *iter;
GtkWidget *label;
char *bold_text;
@@ -356,18 +323,62 @@ cdma_add_menu_item (NMDevice *device,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
- if (g_slist_length (connections))
- add_connection_items (device, connections, active, ADD_ACTIVE, menu, applet);
+ /* Add the active connection */
+ item = NULL;
+ for (iter = connections; iter; iter = g_slist_next (iter)) {
+ NMConnection *connection = NM_CONNECTION (iter->data);
+ NMSettingConnection *s_con;
+ guint32 tech = MB_TECH_1XRTT;
+ guint32 mb_state;
+ CdmaMenuItemInfo *menu_info;
+
+ if (connection != active)
+ continue;
+
+ s_con = (NMSettingConnection *) nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION);
+ g_assert (s_con);
+
+ mb_state = state_for_info (info, &tech);
+
+ item = nm_mb_menu_item_new (nm_setting_connection_get_id (s_con),
+ info->quality_valid ? info->quality : 0,
+ info->provider_name,
+ tech,
+ mb_state,
+ applet);
+
+ menu_info = g_slice_new0 (CdmaMenuItemInfo);
+ menu_info->applet = applet;
+ menu_info->device = g_object_ref (G_OBJECT (device));
+ menu_info->connection = g_object_ref (connection);
+
+ g_signal_connect_data (item, "activate",
+ G_CALLBACK (cdma_menu_item_activate),
+ menu_info,
+ (GClosureNotify) cdma_menu_item_info_destroy, 0);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ break;
+ }
/* Notify user of unmanaged or unavailable device */
- item = nma_menu_device_get_menu_item (device, applet, NULL);
- if (item) {
- text = get_cdma_desc (device, info);
- if (text)
- gtk_menu_item_set_label (GTK_MENU_ITEM (item), text);
- g_free (text);
+ if (nm_device_get_state (device) > NM_DEVICE_STATE_DISCONNECTED) {
+ item = nma_menu_device_get_menu_item (device, applet, NULL);
+ if (item) {
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+ }
+ } else {
+ guint32 tech = MB_TECH_1XRTT;
+ guint32 mb_state;
+
+ mb_state = state_for_info (info, &tech);
+ item = nm_mb_menu_item_new (NULL,
+ info->quality_valid ? info->quality : 0,
+ info->provider_name,
+ tech,
+ mb_state,
+ applet);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show (item);
}
if (!nma_menu_device_check_unusable (device)) {
@@ -893,7 +904,7 @@ cdma_device_added (NMDevice *device, NMApplet *applet)
G_CALLBACK (signal_quality_changed_cb), info, NULL);
/* periodically poll for signal quality and registration state */
- info->poll_id = g_timeout_add_seconds (5, cdma_poll_cb, info);
+ info->poll_id = g_timeout_add_seconds (10, cdma_poll_cb, info);
if (!info->nopoll)
cdma_poll_cb (info);
diff --git a/src/mb-menu-item.c b/src/mb-menu-item.c
new file mode 100644
index 0000000..10d05f0
--- /dev/null
+++ b/src/mb-menu-item.c
@@ -0,0 +1,253 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* ap-menu-item.c - Class to represent a Wifi access point
+ *
+ * Jonathan Blandford <jrb redhat com>
+ * 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.
+ *
+ * Copyright (C) 2005 - 2010 Red Hat, Inc.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <glib/gi18n.h>
+#include <string.h>
+
+#include "mb-menu-item.h"
+#include "utils.h"
+
+G_DEFINE_TYPE (NMMbMenuItem, nm_mb_menu_item, GTK_TYPE_IMAGE_MENU_ITEM);
+
+#define NM_MB_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MB_MENU_ITEM, NMMbMenuItemPrivate))
+
+typedef struct {
+ GtkWidget *desc;
+ char *desc_string;
+ GtkWidget *strength;
+ guint32 int_strength;
+ GtkWidget *detail;
+ GtkWidget *hbox;
+
+ gboolean destroyed;
+} NMMbMenuItemPrivate;
+
+static const char *
+get_tech_name (guint32 tech)
+{
+ switch (tech) {
+ case MB_TECH_1XRTT:
+ return _("CDMA");
+ break;
+ case MB_TECH_EVDO_REV0:
+ case MB_TECH_EVDO_REVA:
+ return _("EVDO");
+ break;
+ case MB_TECH_GSM:
+ return _("GSM");
+ break;
+ case MB_TECH_GPRS:
+ return _("GPRS");
+ break;
+ case MB_TECH_EDGE:
+ return _("EDGE");
+ break;
+ case MB_TECH_UMTS:
+ return _("UMTS");
+ break;
+ case MB_TECH_HSDPA:
+ return _("HSDPA");
+ break;
+ case MB_TECH_HSUPA:
+ return _("HSUPA");
+ break;
+ case MB_TECH_HSPA:
+ return _("HSPA");
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+ return NULL;
+}
+
+GtkWidget *
+nm_mb_menu_item_new (const char *connection_name,
+ guint32 strength,
+ const char *provider,
+ guint32 technology,
+ guint32 state,
+ NMApplet *applet)
+{
+ NMMbMenuItem *item;
+ NMMbMenuItemPrivate *priv;
+ const char *tech_name;
+ GdkPixbuf *icon = NULL, *pixbuf;
+
+ g_return_val_if_fail (technology != MB_TECH_UNKNOWN, NULL);
+
+ item = g_object_new (NM_TYPE_MB_MENU_ITEM, NULL);
+ if (!item)
+ return NULL;
+
+ priv = NM_MB_MENU_ITEM_GET_PRIVATE (item);
+ priv->int_strength = strength;
+
+ /* Construct the description string */
+ tech_name = get_tech_name (technology);
+ switch (state) {
+ default:
+ case MB_STATE_IDLE:
+ if (connection_name)
+ priv->desc_string = g_strdup (connection_name);
+ else
+ priv->desc_string = g_strdup (_("not registered"));
+ break;
+ case MB_STATE_HOME:
+ if (connection_name) {
+ if (provider)
+ priv->desc_string = g_strdup_printf ("%s (%s %s)", connection_name, provider, tech_name);
+ else
+ priv->desc_string = g_strdup_printf ("%s (%s)", connection_name, tech_name);
+ } else {
+ if (provider)
+ priv->desc_string = g_strdup_printf ("%s %s", provider, tech_name);
+ else
+ priv->desc_string = g_strdup_printf (_("Home network (%s)"), tech_name);
+ }
+ break;
+ case MB_STATE_SEARCHING:
+ if (connection_name)
+ priv->desc_string = g_strdup (connection_name);
+ else
+ priv->desc_string = g_strdup (_("searching"));
+ break;
+ case MB_STATE_DENIED:
+ priv->desc_string = g_strdup (_("registration denied"));
+ break;
+ case MB_STATE_ROAMING:
+ if (connection_name)
+ priv->desc_string = g_strdup_printf (_("%s (roaming %s)"), connection_name, tech_name);
+ else {
+ if (provider)
+ priv->desc_string = g_strdup_printf (_("%s (%s roaming)"), provider, tech_name);
+ else
+ priv->desc_string = g_strdup_printf (_("Roaming network (%s)"), tech_name);
+ }
+ break;
+ }
+
+ /* Assume a connection name means the label should be active */
+ if (connection_name) {
+ char *markup;
+
+ gtk_label_set_use_markup (GTK_LABEL (priv->desc), TRUE);
+ markup = g_markup_printf_escaped ("<b>%s</b>", priv->desc_string);
+ gtk_label_set_markup (GTK_LABEL (priv->desc), markup);
+ g_free (markup);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), TRUE);
+ } else {
+ gtk_label_set_use_markup (GTK_LABEL (priv->desc), FALSE);
+ gtk_label_set_text (GTK_LABEL (priv->desc), priv->desc_string);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
+ }
+
+ /* And the strength icon, if applicable */
+ if (strength) {
+ if (strength > 80)
+ icon = nma_icon_check_and_load ("nm-signal-100", &applet->wireless_100_icon, applet);
+ else if (strength > 55)
+ icon = nma_icon_check_and_load ("nm-signal-75", &applet->wireless_75_icon, applet);
+ else if (strength > 30)
+ icon = nma_icon_check_and_load ("nm-signal-50", &applet->wireless_50_icon, applet);
+ else if (strength > 5)
+ icon = nma_icon_check_and_load ("nm-signal-25", &applet->wireless_25_icon, applet);
+ else
+ icon = nma_icon_check_and_load ("nm-signal-00", &applet->wireless_00_icon, applet);
+
+ pixbuf = gdk_pixbuf_copy (icon);
+
+#if 0
+ /* Composite technology icon here */
+ if (item->is_encrypted) {
+ top = nma_icon_check_and_load ("nm-secure-lock", &applet->secure_lock_icon, applet);
+ gdk_pixbuf_composite (top, pixbuf, 0, 0, gdk_pixbuf_get_width (top),
+ gdk_pixbuf_get_height (top),
+ 0, 0, 1.0, 1.0,
+ GDK_INTERP_NEAREST, 255);
+ }
+#endif
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (priv->strength), pixbuf);
+ g_object_unref (pixbuf);
+ }
+
+ return GTK_WIDGET (item);
+}
+
+/*******************************************************/
+
+static void
+nm_mb_menu_item_init (NMMbMenuItem *self)
+{
+ NMMbMenuItemPrivate *priv = NM_MB_MENU_ITEM_GET_PRIVATE (self);
+
+ priv->hbox = gtk_hbox_new (FALSE, 6);
+ priv->desc = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (priv->desc), 0.0, 0.5);
+
+ gtk_container_add (GTK_CONTAINER (self), priv->hbox);
+ gtk_box_pack_start (GTK_BOX (priv->hbox), priv->desc, TRUE, TRUE, 0);
+
+ priv->strength = gtk_image_new ();
+ gtk_box_pack_end (GTK_BOX (priv->hbox), priv->strength, FALSE, TRUE, 0);
+
+ gtk_widget_show (priv->desc);
+ gtk_widget_show (priv->strength);
+ gtk_widget_show (priv->hbox);
+}
+
+static void
+dispose (GObject *object)
+{
+ NMMbMenuItem *self = NM_MB_MENU_ITEM (object);
+ NMMbMenuItemPrivate *priv = NM_MB_MENU_ITEM_GET_PRIVATE (self);
+
+ if (priv->destroyed) {
+ G_OBJECT_CLASS (nm_mb_menu_item_parent_class)->dispose (object);
+ return;
+ }
+ priv->destroyed = TRUE;
+
+ gtk_widget_destroy (priv->desc);
+ gtk_widget_destroy (priv->strength);
+ gtk_widget_destroy (priv->hbox);
+
+ G_OBJECT_CLASS (nm_mb_menu_item_parent_class)->dispose (object);
+}
+
+static void
+nm_mb_menu_item_class_init (NMMbMenuItemClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (NMMbMenuItemPrivate));
+
+ /* virtual methods */
+ object_class->dispose = dispose;
+}
+
diff --git a/src/mb-menu-item.h b/src/mb-menu-item.h
new file mode 100644
index 0000000..e320954
--- /dev/null
+++ b/src/mb-menu-item.h
@@ -0,0 +1,79 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* ap-menu-item.h - Class to represent a Wifi access point
+ *
+ * Jonathan Blandford <jrb redhat com>
+ * 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.
+ *
+ * Copyright (C) 2005 - 2010 Red Hat, Inc.
+ */
+
+#ifndef _MB_MENU_ITEM_H_
+#define _MB_MENU_ITEM_H_
+
+#include <gtk/gtk.h>
+#include "applet.h"
+
+#define NM_TYPE_MB_MENU_ITEM (nm_mb_menu_item_get_type ())
+#define NM_MB_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_MB_MENU_ITEM, NMMbMenuItem))
+#define NM_MB_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_MB_MENU_ITEM, NMMbMenuItemClass))
+#define NM_IS_MB_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_MB_MENU_ITEM))
+#define NM_IS_MB_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_MB_MENU_ITEM))
+#define NM_MB_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_MB_MENU_ITEM, NMMbMenuItemClass))
+
+enum {
+ MB_STATE_UNKNOWN = 0,
+ MB_STATE_IDLE,
+ MB_STATE_HOME,
+ MB_STATE_SEARCHING,
+ MB_STATE_DENIED,
+ MB_STATE_ROAMING
+};
+
+enum {
+ MB_TECH_UNKNOWN = 0,
+ MB_TECH_1XRTT,
+ MB_TECH_EVDO_REV0,
+ MB_TECH_EVDO_REVA,
+ MB_TECH_GSM,
+ MB_TECH_GPRS,
+ MB_TECH_EDGE,
+ MB_TECH_UMTS,
+ MB_TECH_HSDPA,
+ MB_TECH_HSUPA,
+ MB_TECH_HSPA,
+};
+
+typedef struct {
+ GtkImageMenuItem image_item;
+} NMMbMenuItem;
+
+typedef struct {
+ GtkImageMenuItemClass parent_class;
+} NMMbMenuItemClass;
+
+
+GType nm_mb_menu_item_get_type (void) G_GNUC_CONST;
+
+GtkWidget *nm_mb_menu_item_new (const char *connection_name,
+ guint32 strength,
+ const char *provider,
+ guint32 technology,
+ guint32 state,
+ NMApplet *applet);
+
+#endif /* _MB_MENU_ITEM_H_ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]