[gnome-control-center] Network: show a padlock for 'secure' access points



commit 759dbfd328453286c80245e6ad62d7929dc2fcd9
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Mar 25 17:40:17 2011 -0400

    Network: show a padlock for 'secure' access points
    
    This patch adds a trivial GtkCellRendererPixbuf subclass and
    uses it to show a padlock icon for access points which have some
    kind of security.

 panels/network/Makefile.am                    |    2 +
 panels/network/cc-network-panel.c             |   44 ++++++++
 panels/network/network.ui                     |    2 +
 panels/network/panel-cell-renderer-security.c |  145 +++++++++++++++++++++++++
 panels/network/panel-cell-renderer-security.h |   69 ++++++++++++
 5 files changed, 262 insertions(+), 0 deletions(-)
---
diff --git a/panels/network/Makefile.am b/panels/network/Makefile.am
index 67394c1..5eec1eb 100644
--- a/panels/network/Makefile.am
+++ b/panels/network/Makefile.am
@@ -24,6 +24,8 @@ libnetwork_la_SOURCES =					\
 	net-vpn.h					\
 	panel-cell-renderer-mode.c			\
 	panel-cell-renderer-mode.h			\
+	panel-cell-renderer-security.c			\
+	panel-cell-renderer-security.h			\
 	panel-cell-renderer-signal.c			\
 	panel-cell-renderer-signal.h			\
 	cc-network-panel.c				\
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 78b3c87..f1c3023 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -47,6 +47,7 @@
 #include "panel-common.h"
 #include "panel-cell-renderer-mode.h"
 #include "panel-cell-renderer-signal.h"
+#include "panel-cell-renderer-security.h"
 
 G_DEFINE_DYNAMIC_TYPE (CcNetworkPanel, cc_network_panel, CC_TYPE_PANEL)
 
@@ -77,6 +78,7 @@ enum {
         PANEL_WIRELESS_COLUMN_SORT,
         PANEL_WIRELESS_COLUMN_STRENGTH,
         PANEL_WIRELESS_COLUMN_MODE,
+        PANEL_WIRELESS_COLUMN_SECURITY,
         PANEL_WIRELESS_COLUMN_LAST
 };
 
@@ -680,6 +682,36 @@ panel_set_widget_heading (CcNetworkPanel *panel,
         g_free (label_id);
 }
 
+static guint
+get_access_point_security (NMAccessPoint *ap)
+{
+        NM80211ApFlags flags;
+        NM80211ApSecurityFlags wpa_flags;
+        NM80211ApSecurityFlags rsn_flags;
+        guint type;
+
+        flags = nm_access_point_get_flags (ap);
+        wpa_flags = nm_access_point_get_wpa_flags (ap);
+        rsn_flags = nm_access_point_get_rsn_flags (ap);
+
+        if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) &&
+            wpa_flags == NM_802_11_AP_SEC_NONE &&
+            rsn_flags == NM_802_11_AP_SEC_NONE)
+                type = NM_AP_SEC_NONE;
+        else if ((flags & NM_802_11_AP_FLAGS_PRIVACY) &&
+                 wpa_flags == NM_802_11_AP_SEC_NONE &&
+                 rsn_flags == NM_802_11_AP_SEC_NONE)
+                type = NM_AP_SEC_WEP;
+        else if (!(flags & NM_802_11_AP_FLAGS_PRIVACY) &&
+                 wpa_flags != NM_802_11_AP_SEC_NONE &&
+                 rsn_flags != NM_802_11_AP_SEC_NONE)
+                type = NM_AP_SEC_WPA;
+        else
+                type = NM_AP_SEC_WPA2;
+
+        return type;
+}
+
 static void
 add_access_point (CcNetworkPanel *panel, NMAccessPoint *ap, NMAccessPoint *active)
 {
@@ -708,6 +740,7 @@ add_access_point (CcNetworkPanel *panel, NMAccessPoint *ap, NMAccessPoint *activ
                             PANEL_WIRELESS_COLUMN_SORT, ssid_text,
                             PANEL_WIRELESS_COLUMN_STRENGTH, nm_access_point_get_strength (ap),
                             PANEL_WIRELESS_COLUMN_MODE, nm_access_point_get_mode (ap),
+                            PANEL_WIRELESS_COLUMN_SECURITY, get_access_point_security (ap),
                             -1);
 
         /* is this what we're on already? */
@@ -2162,6 +2195,7 @@ cc_network_panel_init (CcNetworkPanel *panel)
                           panel);
 
         renderer = panel_cell_renderer_mode_new ();
+        gtk_cell_renderer_set_padding (renderer, 4, 0);
         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
                                     renderer,
                                     FALSE);
@@ -2169,6 +2203,15 @@ cc_network_panel_init (CcNetworkPanel *panel)
                                         "mode", PANEL_WIRELESS_COLUMN_MODE,
                                         NULL);
 
+        renderer = panel_cell_renderer_security_new ();
+        gtk_cell_renderer_set_padding (renderer, 4, 0);
+        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
+                                    renderer,
+                                    FALSE);
+        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
+                                        "security", PANEL_WIRELESS_COLUMN_SECURITY,
+                                        NULL);
+
         /* sort networks in drop down */
         sortable = GTK_TREE_SORTABLE (gtk_builder_get_object (panel->priv->builder,
                                                               "liststore_wireless_network"));
@@ -2177,6 +2220,7 @@ cc_network_panel_init (CcNetworkPanel *panel)
                                               GTK_SORT_ASCENDING);
 
         renderer = panel_cell_renderer_signal_new ();
+        gtk_cell_renderer_set_padding (renderer, 4, 0);
         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox),
                                     renderer,
                                     FALSE);
diff --git a/panels/network/network.ui b/panels/network/network.ui
index 6e5b153..d79dd44 100644
--- a/panels/network/network.ui
+++ b/panels/network/network.ui
@@ -63,6 +63,8 @@
       <column type="guint"/>
       <!-- column-name mode -->
       <column type="guint"/>
+      <!-- column-name security -->
+      <column type="guint"/>
     </columns>
   </object>
   <object class="GtkWindow" id="window1">
diff --git a/panels/network/panel-cell-renderer-security.c b/panels/network/panel-cell-renderer-security.c
new file mode 100644
index 0000000..558a1ff
--- /dev/null
+++ b/panels/network/panel-cell-renderer-security.c
@@ -0,0 +1,145 @@
+/* -*- Security: C; tab-width: 8; indent-tabs-security: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 Red Hat, Inc
+ *
+ * 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-security.h"
+
+enum {
+        PROP_0,
+        PROP_SECURITY,
+        PROP_LAST
+};
+
+G_DEFINE_TYPE (PanelCellRendererSecurity, panel_cell_renderer_security, GTK_TYPE_CELL_RENDERER_PIXBUF)
+
+static gpointer parent_class = NULL;
+
+/**
+ * panel_cell_renderer_security_get_property:
+ **/
+static void
+panel_cell_renderer_security_get_property (GObject *object, guint param_id,
+                                       GValue *value, GParamSpec *pspec)
+{
+        PanelCellRendererSecurity *renderer = PANEL_CELL_RENDERER_SECURITY (object);
+
+        switch (param_id) {
+        case PROP_SECURITY:
+                g_value_set_uint (value, renderer->security);
+                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 (PanelCellRendererSecurity *renderer)
+{
+        const gchar *icon_name = NULL;
+
+        if (renderer->security != NM_AP_SEC_UNKNOWN &&
+            renderer->security != NM_AP_SEC_NONE)
+                icon_name = "network-wireless-encrypted-symbolic";
+
+        g_object_set (renderer, "icon-name", icon_name, NULL);
+}
+
+/**
+ * panel_cell_renderer_security_set_property:
+ **/
+static void
+panel_cell_renderer_security_set_property (GObject *object, guint param_id,
+                                       const GValue *value, GParamSpec *pspec)
+{
+        PanelCellRendererSecurity *renderer = PANEL_CELL_RENDERER_SECURITY (object);
+
+        switch (param_id) {
+        case PROP_SECURITY:
+                renderer->security = 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)
+{
+        PanelCellRendererSecurity *renderer;
+        renderer = PANEL_CELL_RENDERER_SECURITY (object);
+        g_free (renderer->icon_name);
+        G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+/**
+ * panel_cell_renderer_security_class_init:
+ **/
+static void
+panel_cell_renderer_security_class_init (PanelCellRendererSecurityClass *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_security_get_property;
+        object_class->set_property = panel_cell_renderer_security_set_property;
+
+        g_object_class_install_property (object_class, PROP_SECURITY,
+                                         g_param_spec_uint ("security", NULL,
+                                                            NULL,
+                                                            0, G_MAXUINT, 0,
+                                                            G_PARAM_READWRITE));
+}
+
+/**
+ * panel_cell_renderer_security_init:
+ **/
+static void
+panel_cell_renderer_security_init (PanelCellRendererSecurity *renderer)
+{
+        renderer->security = 0;
+        renderer->icon_name = NULL;
+}
+
+/**
+ * panel_cell_renderer_security_new:
+ **/
+GtkCellRenderer *
+panel_cell_renderer_security_new (void)
+{
+        return g_object_new (PANEL_TYPE_CELL_RENDERER_SECURITY, NULL);
+}
+
diff --git a/panels/network/panel-cell-renderer-security.h b/panels/network/panel-cell-renderer-security.h
new file mode 100644
index 0000000..e297abe
--- /dev/null
+++ b/panels/network/panel-cell-renderer-security.h
@@ -0,0 +1,69 @@
+/* -*- Security: C; tab-width: 8; indent-tabs-security: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2011 Red Hat, Inc
+ *
+ * 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_SECURITY_H
+#define PANEL_CELL_RENDERER_SECURITY_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+#include "nm-device.h"
+#include "nm-access-point.h"
+
+#define PANEL_TYPE_CELL_RENDERER_SECURITY           (panel_cell_renderer_security_get_type())
+#define PANEL_CELL_RENDERER_SECURITY(obj)           (G_TYPE_CHECK_INSTANCE_CAST((obj), PANEL_TYPE_CELL_RENDERER_SECURITY, PanelCellRendererSecurity))
+#define PANEL_CELL_RENDERER_SECURITY_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST((cls), PANEL_TYPE_CELL_RENDERER_SECURITY, PanelCellRendererSecurityClass))
+#define PANEL_IS_CELL_RENDERER_SECURITY(obj)        (G_TYPE_CHECK_INSTANCE_TYPE((obj), PANEL_TYPE_CELL_RENDERER_SECURITY))
+#define PANEL_IS_CELL_RENDERER_SECURITY_CLASS(cls)  (G_TYPE_CHECK_CLASS_TYPE((cls), PANEL_TYPE_CELL_RENDERER_SECURITY))
+#define PANEL_CELL_RENDERER_SECURITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PANEL_TYPE_CELL_RENDERER_SECURITY, PanelCellRendererSecurityClass))
+
+G_BEGIN_DECLS
+
+typedef struct _PanelCellRendererSecurity           PanelCellRendererSecurity;
+typedef struct _PanelCellRendererSecurityClass      PanelCellRendererSecurityClass;
+
+typedef enum {
+  NM_AP_SEC_UNKNOWN,
+  NM_AP_SEC_NONE,
+  NM_AP_SEC_WEP,
+  NM_AP_SEC_WPA,
+  NM_AP_SEC_WPA2
+} NMAccessPointSecurity;
+
+struct _PanelCellRendererSecurity
+{
+        GtkCellRendererPixbuf    parent;
+        guint                    security;
+        gchar                   *icon_name;
+};
+
+struct _PanelCellRendererSecurityClass
+{
+        GtkCellRendererPixbufClass parent_class;
+};
+
+GType            panel_cell_renderer_security_get_type      (void);
+GtkCellRenderer *panel_cell_renderer_security_new           (void);
+
+G_END_DECLS
+
+#endif /* PANEL_CELL_RENDERER_SECURITY_H */
+



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