[network-manager-netbook] Implement the "Sorry, we can't find any networks" message.
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [network-manager-netbook] Implement the "Sorry, we can't find any networks" message.
- Date: Tue, 8 Sep 2009 07:16:34 +0000 (UTC)
commit 7380feeb73be2abdfd21d96db3aae38a6d4ba510
Author: Tambet Ingo <tambet gmail com>
Date: Mon Sep 7 13:53:01 2009 +0300
Implement the "Sorry, we can't find any networks" message.
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/nmn-networks.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/nmn-text-item.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
src/nmn-text-item.h | 44 ++++++++++++++++++++
5 files changed, 262 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9a451a5..d42a2e2 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,6 +1,7 @@
src/nmn-connection-details.c
src/nbtk-gtk-light-switch.c
src/nmn-network-item.c
+src/nmn-networks.c
[type: gettext/glade]src/network-manager-netbook.ui
src/nmn-mobile-providers.c
src/nmn-new-connection.c
diff --git a/src/Makefile.am b/src/Makefile.am
index fd59c11..daa16be 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,6 +54,8 @@ network_manager_netbook_SOURCES = \
nmn-serial-item.h \
nmn-status-icon.c \
nmn-status-icon.h \
+ nmn-text-item.c \
+ nmn-text-item.h \
nmn-wifi-handler.c \
nmn-wifi-handler.h \
nmn-wifi-item.c \
diff --git a/src/nmn-networks.c b/src/nmn-networks.c
index c93b21d..5acbc1a 100644
--- a/src/nmn-networks.c
+++ b/src/nmn-networks.c
@@ -18,6 +18,7 @@
*/
#include <string.h>
+#include <glib/gi18n.h>
#include <NetworkManager.h>
#include <nm-settings.h>
#include <nm-device-ethernet.h>
@@ -31,6 +32,7 @@
#include "nmn-ethernet-handler.h"
#include "nmn-serial-handler.h"
#include "nmn-wifi-handler.h"
+#include "nmn-text-item.h"
#define DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH))
@@ -46,6 +48,7 @@ enum {
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NMN_TYPE_NETWORKS, NmnNetworksPrivate))
typedef struct {
+ GtkWidget *zero_items;
NmnNMData *nm_data;
GSList *handlers;
gboolean populated;
@@ -63,6 +66,96 @@ nmn_networks_new (NmnNMData *nm_data)
NULL));
}
+static const char *
+get_punctuation (guint items_left)
+{
+ if (items_left > 1)
+ return ", ";
+ if (items_left == 1)
+ return _(" and ");
+
+ /* items_left == 0 */
+ return ".";
+}
+
+static char *
+build_no_networks_text (NmnNMData *data)
+{
+ GString *string;
+ gboolean wifi_enabled;
+ gboolean ethernet_enabled;
+ gboolean modem_enabled;
+ guint disabled_count;
+
+ string = g_string_new (_("Sorry, we can't find any networks."));
+ disabled_count = 0;
+
+ wifi_enabled = nmn_nm_data_wifi_get_active (data);
+ if (!wifi_enabled)
+ disabled_count++;
+
+ ethernet_enabled = nmn_nm_data_ethernet_get_active (data);
+ if (!ethernet_enabled)
+ disabled_count++;
+
+ modem_enabled = nmn_nm_data_modems_get_active (data);
+ if (!modem_enabled)
+ disabled_count++;
+
+ if (disabled_count > 0) {
+ g_string_append (string, _(" You could try turning on "));
+
+ if (!wifi_enabled) {
+ g_string_append (string, _("WiFi"));
+ g_string_append (string, get_punctuation (--disabled_count));
+ }
+
+ if (!ethernet_enabled) {
+ g_string_append (string, _("Wired"));
+ g_string_append (string, get_punctuation (--disabled_count));
+ }
+
+ if (!modem_enabled) {
+ g_string_append (string, _("3G"));
+ g_string_append (string, get_punctuation (--disabled_count));
+ }
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+static void
+foobar_changed (NmnNMData *data,
+ gboolean active,
+ gpointer user_data)
+{
+ NmnNetworksPrivate *priv = GET_PRIVATE (user_data);
+
+ if (priv->zero_items) {
+ NmnItem *item = NMN_ITEM (priv->zero_items);
+ char *txt;
+
+ txt = build_no_networks_text (data);
+ nmn_item_set_name (item, txt);
+ g_free (txt);
+ }
+}
+
+static void
+add_no_networks_item (NmnNetworks *self)
+{
+ NmnNetworksPrivate *priv = GET_PRIVATE (self);
+ char *txt;
+
+ g_return_if_fail (priv->zero_items == NULL);
+
+ txt = build_no_networks_text (priv->nm_data);
+ priv->zero_items = nmn_text_item_new (txt);
+ g_free (txt);
+
+ nmn_list_add_item (NMN_LIST (self), NMN_ITEM (priv->zero_items));
+}
+
static void
find_ac_for_item (NmnNetworks *self, NmnNetworkItem *item)
{
@@ -97,6 +190,7 @@ typedef struct {
NMExportedConnection *exported;
NMDevice *device;
GSList *items_to_remove;
+ guint counter;
} RemoveInfo;
static void
@@ -105,6 +199,8 @@ remove_connections_cb (GtkWidget *widget, gpointer data)
NmnNetworkItem *item = NMN_NETWORK_ITEM (widget);
RemoveInfo *info = (RemoveInfo *) data;
+ info->counter++;
+
if ((info->item && (NmnItem *) item == info->item) ||
(info->exported && nmn_network_item_get_connection (item) == info->exported) ||
(info->device && nmn_network_item_get_device (item) == info->device))
@@ -124,6 +220,7 @@ remove_connections (NmnNetworks *self,
info.exported = connection;
info.device = device;
info.items_to_remove = NULL;
+ info.counter = 0;
gtk_container_foreach (GTK_CONTAINER (self), remove_connections_cb, &info);
@@ -132,7 +229,11 @@ remove_connections (NmnNetworks *self,
g_object_unref (info.items_to_remove->data);
info.items_to_remove = g_slist_delete_link (info.items_to_remove, info.items_to_remove);
+ info.counter--;
}
+
+ if (info.counter < 1)
+ add_no_networks_item (self);
}
static void
@@ -148,6 +249,12 @@ item_added (NmnDeviceHandler *handler,
gpointer user_data)
{
NmnNetworks *self = NMN_NETWORKS (user_data);
+ NmnNetworksPrivate *priv = GET_PRIVATE (self);
+
+ if (priv->zero_items) {
+ gtk_container_remove (GTK_CONTAINER (self), priv->zero_items);
+ priv->zero_items = NULL;
+ }
nmn_list_add_item (NMN_LIST (self), item);
g_signal_connect (item, "remove-requested", G_CALLBACK (item_remove_requested), self);
@@ -276,6 +383,12 @@ constructor (GType type,
return NULL;
}
+ g_signal_connect (priv->nm_data, "ethernet-toggled", G_CALLBACK (foobar_changed), object);
+ g_signal_connect (priv->nm_data, "wifi-toggled", G_CALLBACK (foobar_changed), object);
+ g_signal_connect (priv->nm_data, "modems-toggled", G_CALLBACK (foobar_changed), object);
+
+ add_no_networks_item (NMN_NETWORKS (object));
+
return object;
}
diff --git a/src/nmn-text-item.c b/src/nmn-text-item.c
new file mode 100644
index 0000000..192e979
--- /dev/null
+++ b/src/nmn-text-item.c
@@ -0,0 +1,102 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* 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 2009 Novell, Inc.
+ */
+
+#include <glib/gi18n.h>
+#include "nmn-text-item.h"
+#include "nmn-item.h"
+
+static void item_init (NmnItem *item_class);
+
+G_DEFINE_TYPE_EXTENDED (NmnTextItem, nmn_text_item, GTK_TYPE_LABEL, 0,
+ G_IMPLEMENT_INTERFACE (NMN_TYPE_ITEM, item_init))
+
+GtkWidget *
+nmn_text_item_new (const char *text)
+{
+ return GTK_WIDGET (g_object_new (NMN_TYPE_TEXT_ITEM,
+ NMN_ITEM_NAME, text,
+ NULL));
+}
+
+static void
+item_init (NmnItem *item_class)
+{
+}
+
+static void
+nmn_text_item_init (NmnTextItem *self)
+{
+ gtk_misc_set_alignment (GTK_MISC (self), 0.0, 0.5);
+ gtk_misc_set_padding (GTK_MISC (self), 20, 20);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ char *s;
+
+ switch (prop_id) {
+ case NMN_ITEM_PROP_NAME:
+ /* FIXME: This does not belong here */
+ s = g_strdup_printf ("<big><b>%s</b></big>", g_value_get_string (value));
+ gtk_label_set_markup (GTK_LABEL (object), s);
+ g_free (s);
+ g_object_notify (object, NMN_ITEM_NAME);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ switch (prop_id) {
+ case NMN_ITEM_PROP_NAME:
+ g_value_set_string (value, gtk_label_get_text (GTK_LABEL (object)));
+ break;
+ case NMN_ITEM_PROP_PRIORITY:
+ g_value_set_uint (value, 0);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nmn_text_item_class_init (NmnTextItemClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+
+ /* properties */
+ g_object_class_override_property (object_class,
+ NMN_ITEM_PROP_NAME,
+ NMN_ITEM_NAME);
+
+ g_object_class_override_property (object_class,
+ NMN_ITEM_PROP_PRIORITY,
+ NMN_ITEM_PRIORITY);
+}
diff --git a/src/nmn-text-item.h b/src/nmn-text-item.h
new file mode 100644
index 0000000..b7e36e0
--- /dev/null
+++ b/src/nmn-text-item.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
+/* 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 2009 Novell, Inc.
+ */
+
+#ifndef NMN_TEXT_ITEM_H
+#define NMN_TEXT_ITEM_H
+
+#include <gtk/gtk.h>
+
+#define NMN_TYPE_TEXT_ITEM (nmn_text_item_get_type ())
+#define NMN_TEXT_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NMN_TYPE_TEXT_ITEM, NmnTextItem))
+#define NMN_TEXT_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NMN_TYPE_TEXT_ITEM, NmnTextItemClass))
+#define NMN_IS_TEXT_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NMN_TYPE_TEXT_ITEM))
+#define NMN_IS_TEXT_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NMN_TYPE_TEXT_ITEM))
+#define NMN_TEXT_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NMN_TYPE_TEXT_ITEM, NmnTextItemClass))
+
+typedef struct {
+ GtkLabel parent;
+} NmnTextItem;
+
+typedef struct {
+ GtkLabelClass parent;
+} NmnTextItemClass;
+
+GType nmn_text_item_get_type (void);
+
+GtkWidget *nmn_text_item_new (const char *text);
+
+#endif /* NMN_TEXT_ITEM_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]