[gnome-control-center] network: show the VPN connection state in the panel header



commit 7914025e1f2efe6ecd0d2efaf11b9fd624e695a4
Author: Richard Hughes <richard hughsie com>
Date:   Fri Mar 11 12:56:14 2011 +0000

    network: show the VPN connection state in the panel header

 panels/network/cc-network-panel.c |   24 +++++++++++++++++-
 panels/network/net-object.c       |   25 +++++++++++++++----
 panels/network/net-object.h       |    3 ++
 panels/network/net-vpn.c          |   27 ++++++++++++++++++++
 panels/network/net-vpn.h          |    3 ++
 panels/network/panel-common.c     |   48 +++++++++++++++++++++++++++++++++++++
 panels/network/panel-common.h     |    2 +
 7 files changed, 125 insertions(+), 7 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 463b3c2..785f58d 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -1035,18 +1035,37 @@ nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn)
 {
         GtkWidget *widget;
         const gchar *sub_pane = "vpn";
+        const gchar *status;
         CcNetworkPanelPrivate *priv = panel->priv;
 
-        /* Hide the header: TODO: confirm with designers */
+        /* show the header */
         widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                      "hbox_device_header"));
-        gtk_widget_set_visible (widget, FALSE);
+        gtk_widget_set_visible (widget, TRUE);
 
         /* use proxy note page */
         widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                      "notebook_types"));
         gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 3);
 
+        /* set VPN icon */
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                                     "image_device"));
+        gtk_image_set_from_icon_name (GTK_IMAGE (widget),
+                                      "network-workgroup",
+                                      GTK_ICON_SIZE_DIALOG);
+
+        /* use title */
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                                     "label_device"));
+        gtk_label_set_label (GTK_LABEL (widget), net_object_get_title (NET_OBJECT (vpn)));
+
+        /* use status */
+        widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
+                                                     "label_status"));
+        status = panel_vpn_state_to_localized_string (net_vpn_get_state (vpn));
+        gtk_label_set_label (GTK_LABEL (widget), status);
+
         /* gateway */
         panel_set_widget_data (panel,
                                sub_pane,
@@ -1264,6 +1283,7 @@ panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
         title_markup = g_strdup_printf ("<span size=\"large\">%s</span>",
                                         title);
 
+        net_object_set_title (NET_OBJECT (net_vpn), title);
         gtk_list_store_append (liststore_devices, &iter);
         gtk_list_store_set (liststore_devices,
                             &iter,
diff --git a/panels/network/net-object.c b/panels/network/net-object.c
index dd32cac..d8c34be 100644
--- a/panels/network/net-object.c
+++ b/panels/network/net-object.c
@@ -30,7 +30,7 @@
 
 struct _NetObjectPrivate
 {
-        guint                            dummy;
+        gchar                           *title;
 };
 
 enum {
@@ -49,13 +49,28 @@ net_object_emit_changed (NetObject *object)
         g_signal_emit (object, signals[SIGNAL_CHANGED], 0);
 }
 
+const gchar *
+net_object_get_title (NetObject *object)
+{
+        NetObjectPrivate *priv = object->priv;
+        return priv->title;
+}
+
+void
+net_object_set_title (NetObject *object, const gchar *title)
+{
+        NetObjectPrivate *priv = object->priv;
+        priv->title = g_strdup (title);
+}
+
 static void
 net_object_finalize (GObject *object)
 {
-#if 0
-        NetObject *object = NET_OBJECT (object);
-        NetObjectPrivate *priv = object->priv;
-#endif
+        NetObject *nm_object = NET_OBJECT (object);
+        NetObjectPrivate *priv = nm_object->priv;
+
+        g_free (priv->title);
+
         G_OBJECT_CLASS (net_object_parent_class)->finalize (object);
 }
 
diff --git a/panels/network/net-object.h b/panels/network/net-object.h
index 98c0c9c..360c70c 100644
--- a/panels/network/net-object.h
+++ b/panels/network/net-object.h
@@ -51,6 +51,9 @@ struct _NetObjectClass
 
 GType            net_object_get_type                    (void);
 NetObject       *net_object_new                         (void);
+const gchar     *net_object_get_title                   (NetObject      *object);
+void             net_object_set_title                   (NetObject      *object,
+                                                         const gchar    *title);
 void             net_object_emit_changed                (NetObject      *object);
 
 G_END_DECLS
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index 8238367..9ccd818 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -32,10 +32,20 @@
 struct _NetVpnPrivate
 {
         NMSettingVPN            *setting;
+        NMConnection            *connection;
 };
 
 G_DEFINE_TYPE (NetVpn, net_vpn, NET_TYPE_OBJECT)
 
+static void
+connection_state_changed_cb (NMVPNConnection *connection,
+                             NMVPNConnectionState state,
+                             NMVPNConnectionStateReason reason,
+                             NetVpn *vpn)
+{
+        net_object_emit_changed (NET_OBJECT (vpn));
+}
+
 void
 net_vpn_set_connection (NetVpn *vpn, NMConnection *connection)
 {
@@ -49,9 +59,25 @@ net_vpn_set_connection (NetVpn *vpn, NMConnection *connection)
          * key=IPSec ID, value=rh-vpn
          * key=Xauth username, value=rhughes
          */
+        priv->connection = g_object_ref (connection);
+        if (NM_IS_VPN_CONNECTION (priv->connection)) {
+                g_signal_connect (priv->connection,
+                                  NM_VPN_CONNECTION_VPN_STATE,
+                                  G_CALLBACK (connection_state_changed_cb),
+                                  vpn);
+        }
         priv->setting = NM_SETTING_VPN (nm_connection_get_setting_by_name (connection, "vpn"));
 }
 
+NMVPNConnectionState
+net_vpn_get_state (NetVpn *vpn)
+{
+        NetVpnPrivate *priv = vpn->priv;
+        if (!NM_IS_VPN_CONNECTION (priv->connection))
+                return NM_VPN_CONNECTION_STATE_DISCONNECTED;
+        return nm_vpn_connection_get_vpn_state (NM_VPN_CONNECTION (priv->connection));
+}
+
 const gchar *
 net_vpn_get_gateway (NetVpn *vpn)
 {
@@ -86,6 +112,7 @@ net_vpn_finalize (GObject *object)
         NetVpn *vpn = NET_VPN (object);
         NetVpnPrivate *priv = vpn->priv;
 
+        g_object_unref (priv->connection);
         g_object_unref (priv->setting);
 
         G_OBJECT_CLASS (net_vpn_parent_class)->finalize (object);
diff --git a/panels/network/net-vpn.h b/panels/network/net-vpn.h
index c50507d..d409aa4 100644
--- a/panels/network/net-vpn.h
+++ b/panels/network/net-vpn.h
@@ -24,8 +24,10 @@
 
 #include <glib-object.h>
 
+#include "NetworkManagerVPN.h"
 #include "net-object.h"
 #include "nm-connection.h"
+#include "nm-vpn-connection.h"
 
 G_BEGIN_DECLS
 
@@ -59,6 +61,7 @@ const gchar     *net_vpn_get_gateway            (NetVpn         *vpn);
 const gchar     *net_vpn_get_id                 (NetVpn         *vpn);
 const gchar     *net_vpn_get_username           (NetVpn         *vpn);
 const gchar     *net_vpn_get_password           (NetVpn         *vpn);
+NMVPNConnectionState net_vpn_get_state          (NetVpn         *vpn);
 
 G_END_DECLS
 
diff --git a/panels/network/panel-common.c b/panels/network/panel-common.c
index b07189b..1820a4a 100644
--- a/panels/network/panel-common.c
+++ b/panels/network/panel-common.c
@@ -227,3 +227,51 @@ panel_device_state_to_localized_string (NMDeviceState type)
         }
         return value;
 }
+
+/**
+ * panel_vpn_state_to_localized_string:
+ **/
+const gchar *
+panel_vpn_state_to_localized_string (NMVPNConnectionState type)
+{
+        const gchar *value = NULL;
+        switch (type) {
+        case NM_DEVICE_STATE_UNKNOWN:
+                /* TRANSLATORS: VPN status */
+                value = _("Status unknown");
+                break;
+        case NM_VPN_CONNECTION_STATE_PREPARE:
+                /* TRANSLATORS: VPN status */
+                value = _("Preparing");
+                break;
+        case NM_VPN_CONNECTION_STATE_NEED_AUTH:
+                /* TRANSLATORS: VPN status */
+                value = _("Authenticating");
+                break;
+        case NM_VPN_CONNECTION_STATE_CONNECT:
+                /* TRANSLATORS: VPN status */
+                value = _("Connecting");
+                break;
+        case NM_VPN_CONNECTION_STATE_IP_CONFIG_GET:
+                /* TRANSLATORS: VPN status */
+                value = _("Getting network address");
+                break;
+        case NM_VPN_CONNECTION_STATE_ACTIVATED:
+                /* TRANSLATORS: VPN status */
+                value = _("Active");
+                break;
+        case NM_VPN_CONNECTION_STATE_FAILED:
+                /* TRANSLATORS: VPN status */
+                value = _("Failed");
+                break;
+        case NM_VPN_CONNECTION_STATE_DISCONNECTED:
+                /* TRANSLATORS: VPN status */
+                value = _("Disconnected");
+                break;
+        default:
+                /* TRANSLATORS: VPN status */
+                value = _("Status unknown (missing)");
+                break;
+        }
+        return value;
+}
diff --git a/panels/network/panel-common.h b/panels/network/panel-common.h
index dd0eb08..b2ee678 100644
--- a/panels/network/panel-common.h
+++ b/panels/network/panel-common.h
@@ -24,6 +24,7 @@
 
 #include <glib-object.h>
 #include <NetworkManager.h>
+#include <NetworkManagerVPN.h>
 #include <nm-device.h>
 
 G_BEGIN_DECLS
@@ -33,6 +34,7 @@ const gchar     *panel_device_to_localized_string          (NMDevice *device);
 const gchar     *panel_device_to_sortable_string           (NMDevice *device);
 const gchar     *panel_ap_mode_to_localized_string              (NM80211Mode mode);
 const gchar     *panel_device_state_to_localized_string         (NMDeviceState type);
+const gchar     *panel_vpn_state_to_localized_string         (NMVPNConnectionState type);
 
 G_END_DECLS
 



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