[gnome-control-center] network: add a cell renderer for displaying the AP signal strength
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] network: add a cell renderer for displaying the AP signal strength
- Date: Wed, 15 Dec 2010 19:25:43 +0000 (UTC)
commit 6b49a205877515b0f64315cfaac2a5ed483b8def
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 15 19:19:21 2010 +0000
network: add a cell renderer for displaying the AP signal strength
panels/network/Makefile.am | 2 +
panels/network/panel-cell-renderer-signal.c | 155 +++++++++++++++++++++++++++
panels/network/panel-cell-renderer-signal.h | 60 ++++++++++
3 files changed, 217 insertions(+), 0 deletions(-)
---
diff --git a/panels/network/Makefile.am b/panels/network/Makefile.am
index e93a71a..f0d7deb 100644
--- a/panels/network/Makefile.am
+++ b/panels/network/Makefile.am
@@ -13,6 +13,8 @@ libnetwork_la_SOURCES = \
network-module.c \
panel-cell-renderer-mode.c \
panel-cell-renderer-mode.h \
+ panel-cell-renderer-signal.c \
+ panel-cell-renderer-signal.h \
cc-network-panel.c \
cc-network-panel.h
diff --git a/panels/network/panel-cell-renderer-signal.c b/panels/network/panel-cell-renderer-signal.c
new file mode 100644
index 0000000..23b1df1
--- /dev/null
+++ b/panels/network/panel-cell-renderer-signal.c
@@ -0,0 +1,155 @@
+/* -*- Signal: C; tab-width: 8; indent-tabs-signal: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "panel-cell-renderer-signal.h"
+
+enum {
+ PROP_0,
+ PROP_SIGNAL,
+ PROP_LAST
+};
+
+G_DEFINE_TYPE (PanelCellRendererSignal, panel_cell_renderer_signal, GTK_TYPE_CELL_RENDERER_PIXBUF)
+
+static gpointer parent_class = NULL;
+
+/**
+ * panel_cell_renderer_signal_get_property:
+ **/
+static void
+panel_cell_renderer_signal_get_property (GObject *object, guint param_id,
+ GValue *value, GParamSpec *pspec)
+{
+ PanelCellRendererSignal *renderer = PANEL_CELL_RENDERER_SIGNAL (object);
+
+ switch (param_id) {
+ case PROP_SIGNAL:
+ g_value_set_uint (value, renderer->signal);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+/**
+ * panel_cell_renderer_set_name:
+ **/
+static void
+panel_cell_renderer_set_name (PanelCellRendererSignal *renderer)
+{
+ const gchar *icon_name = NULL;
+ GIcon *icon;
+
+ if (renderer->signal < 20)
+ icon_name = "network-wireless-signal-none-symbolic";
+ else if (renderer->signal < 40)
+ icon_name = "network-wireless-signal-weak-symbolic";
+ else if (renderer->signal < 50)
+ icon_name = "network-wireless-signal-ok-symbolic";
+ else if (renderer->signal < 80)
+ icon_name = "network-wireless-signal-good-symbolic";
+ else
+ icon_name = "network-wireless-signal-excellent-symbolic";
+
+ icon = g_themed_icon_new_with_default_fallbacks (icon_name);
+ g_object_set (renderer, "gicon", icon, NULL);
+ g_object_unref (icon);
+}
+
+/**
+ * panel_cell_renderer_signal_set_property:
+ **/
+static void
+panel_cell_renderer_signal_set_property (GObject *object, guint param_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ PanelCellRendererSignal *renderer = PANEL_CELL_RENDERER_SIGNAL (object);
+
+ switch (param_id) {
+ case PROP_SIGNAL:
+ renderer->signal = g_value_get_uint (value);
+ panel_cell_renderer_set_name (renderer);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+}
+
+/**
+ * panel_cell_renderer_finalize:
+ **/
+static void
+panel_cell_renderer_finalize (GObject *object)
+{
+ PanelCellRendererSignal *renderer;
+ renderer = PANEL_CELL_RENDERER_SIGNAL (object);
+ g_free (renderer->icon_name);
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+/**
+ * panel_cell_renderer_signal_class_init:
+ **/
+static void
+panel_cell_renderer_signal_class_init (PanelCellRendererSignalClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ object_class->finalize = panel_cell_renderer_finalize;
+
+ parent_class = g_type_class_peek_parent (class);
+
+ object_class->get_property = panel_cell_renderer_signal_get_property;
+ object_class->set_property = panel_cell_renderer_signal_set_property;
+
+ g_object_class_install_property (object_class, PROP_SIGNAL,
+ g_param_spec_uint ("signal", NULL,
+ NULL,
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE));
+}
+
+/**
+ * panel_cell_renderer_signal_init:
+ **/
+static void
+panel_cell_renderer_signal_init (PanelCellRendererSignal *renderer)
+{
+ renderer->signal = 0;
+ renderer->icon_name = NULL;
+}
+
+/**
+ * panel_cell_renderer_signal_new:
+ **/
+GtkCellRenderer *
+panel_cell_renderer_signal_new (void)
+{
+ return g_object_new (PANEL_TYPE_CELL_RENDERER_SIGNAL, NULL);
+}
+
diff --git a/panels/network/panel-cell-renderer-signal.h b/panels/network/panel-cell-renderer-signal.h
new file mode 100644
index 0000000..f63d10d
--- /dev/null
+++ b/panels/network/panel-cell-renderer-signal.h
@@ -0,0 +1,60 @@
+/* -*- Signal: C; tab-width: 8; indent-tabs-signal: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * 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.
+ */
+
+#ifndef PANEL_CELL_RENDERER_SIGNAL_H
+#define PANEL_CELL_RENDERER_SIGNAL_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+#include "panel-common.h"
+
+#define PANEL_TYPE_CELL_RENDERER_SIGNAL (panel_cell_renderer_signal_get_type())
+#define PANEL_CELL_RENDERER_SIGNAL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PANEL_TYPE_CELL_RENDERER_SIGNAL, PanelCellRendererSignal))
+#define PANEL_CELL_RENDERER_SIGNAL_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), PANEL_TYPE_CELL_RENDERER_SIGNAL, PanelCellRendererSignalClass))
+#define PANEL_IS_CELL_RENDERER_SIGNAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PANEL_TYPE_CELL_RENDERER_SIGNAL))
+#define PANEL_IS_CELL_RENDERER_SIGNAL_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), PANEL_TYPE_CELL_RENDERER_SIGNAL))
+#define PANEL_CELL_RENDERER_SIGNAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_CELL_RENDERER_SIGNAL, PanelCellRendererSignalClass))
+
+G_BEGIN_DECLS
+
+typedef struct _PanelCellRendererSignal PanelCellRendererSignal;
+typedef struct _PanelCellRendererSignalClass PanelCellRendererSignalClass;
+
+struct _PanelCellRendererSignal
+{
+ GtkCellRendererPixbuf parent;
+ guint signal;
+ gchar *icon_name;
+};
+
+struct _PanelCellRendererSignalClass
+{
+ GtkCellRendererPixbufClass parent_class;
+};
+
+GType panel_cell_renderer_signal_get_type (void);
+GtkCellRenderer *panel_cell_renderer_signal_new (void);
+
+G_END_DECLS
+
+#endif /* PANEL_CELL_RENDERER_SIGNAL_H */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]