[gnome-control-center] network: Fix updating VPN info when edited



commit e04d0bb7875cbb7bf472e59e709235e50fed8f46
Author: JiÅÃ KlimeÅ <jklimes redhat com>
Date:   Fri Jul 22 12:12:31 2011 +0200

    network: Fix updating VPN info when edited
    
    - Updating VPN info
    - Removing 'setting' private member from NetVpn object, because settings are
      replaced when connection is updated (libnm-glib/nm-remote-connection.c).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657303
    https://bugzilla.redhat.com/show_bug.cgi?id=723489

 panels/network/cc-network-panel.c |   43 +++++++++++++++++++++++++++++++++++-
 panels/network/net-vpn.c          |   15 +++---------
 2 files changed, 45 insertions(+), 13 deletions(-)
---
diff --git a/panels/network/cc-network-panel.c b/panels/network/cc-network-panel.c
index 49aaf19..8277b4c 100644
--- a/panels/network/cc-network-panel.c
+++ b/panels/network/cc-network-panel.c
@@ -87,6 +87,7 @@ enum {
 
 static void     refresh_ui      (CcNetworkPanel *panel);
 static NetObject *find_in_model_by_id (CcNetworkPanel *panel, const gchar *id);
+static gboolean find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter);
 
 static void
 cc_network_panel_get_property (GObject    *object,
@@ -1876,6 +1877,9 @@ nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn)
         const gchar *path;
         const gchar *apath;
         NMVPNConnectionState state;
+        gchar *title;
+        GtkListStore *liststore_devices;
+        GtkTreeIter iter;
 
         sw = GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                  "device_vpn_off_switch"));
@@ -1898,10 +1902,23 @@ nm_device_refresh_vpn_ui (CcNetworkPanel *panel, NetVpn *vpn)
                                       "network-vpn",
                                       GTK_ICON_SIZE_DIALOG);
 
-        /* use title */
+        /* update title */
         widget = GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                      "label_vpn_device"));
-        gtk_label_set_label (GTK_LABEL (widget), net_object_get_title (NET_OBJECT (vpn)));
+        title = g_strdup_printf (_("%s VPN"), nm_connection_get_id (net_vpn_get_connection (vpn)));
+        net_object_set_title (NET_OBJECT (vpn), title);
+        gtk_label_set_label (GTK_LABEL (widget), title);
+
+        /* update list store title */
+        liststore_devices = GTK_LIST_STORE (gtk_builder_get_object (panel->priv->builder,
+                                                                    "liststore_devices"));
+        if (find_model_iter_by_object (GTK_TREE_MODEL (liststore_devices), NET_OBJECT (vpn), &iter)) {
+                gtk_list_store_set (liststore_devices,
+                                    &iter,
+                                    PANEL_DEVICES_COLUMN_TITLE, title,
+                                    -1);
+        }
+        g_free (title);
 
         /* use status */
         state = net_vpn_get_state (vpn);
@@ -2207,6 +2224,28 @@ out:
         return object;
 }
 
+static gboolean
+find_model_iter_by_object (GtkTreeModel *model, const NetObject *object, GtkTreeIter *iter)
+{
+        gboolean valid;
+        NetObject *object_tmp;
+
+        /* find iter in model according to the passed object */
+        valid = gtk_tree_model_get_iter_first (model, iter);
+        while (valid) {
+                gtk_tree_model_get (model, iter,
+                                    PANEL_DEVICES_COLUMN_OBJECT, &object_tmp,
+                                    -1);
+                if (object_tmp != NULL)
+                        g_object_unref (object_tmp);
+                if (object_tmp == object)
+                        return TRUE;
+                valid = gtk_tree_model_iter_next (model, iter);
+        }
+
+        return FALSE;
+}
+
 static void
 panel_add_vpn_device (CcNetworkPanel *panel, NMConnection *connection)
 {
diff --git a/panels/network/net-vpn.c b/panels/network/net-vpn.c
index f930ef3..250fb39 100644
--- a/panels/network/net-vpn.c
+++ b/panels/network/net-vpn.c
@@ -32,7 +32,6 @@
 
 struct _NetVpnPrivate
 {
-        NMSettingVPN            *setting;
         NMConnection            *connection;
         gboolean                 valid;
 };
@@ -59,10 +58,7 @@ static void
 connection_removed_cb (NMConnection *connection,
                        NetVpn *vpn)
 {
-        if (vpn->priv->setting == NULL)
-                return;
         net_object_emit_removed (NET_OBJECT (vpn));
-        vpn->priv->setting = NULL;
 }
 
 void
@@ -93,7 +89,6 @@ net_vpn_set_connection (NetVpn *vpn, NMConnection *connection)
                                   G_CALLBACK (connection_vpn_state_changed_cb),
                                   vpn);
         }
-        priv->setting = NM_SETTING_VPN (g_object_ref (nm_connection_get_setting_by_name (connection, "vpn")));
 }
 
 NMConnection *
@@ -115,28 +110,28 @@ const gchar *
 net_vpn_get_gateway (NetVpn *vpn)
 {
         NetVpnPrivate *priv = vpn->priv;
-        return nm_setting_vpn_get_data_item (priv->setting, "IPSec gateway");
+        return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), "IPSec gateway");
 }
 
 const gchar *
 net_vpn_get_id (NetVpn *vpn)
 {
         NetVpnPrivate *priv = vpn->priv;
-        return nm_setting_vpn_get_data_item (priv->setting, "IPSec ID");
+        return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), "IPSec ID");
 }
 
 const gchar *
 net_vpn_get_username (NetVpn *vpn)
 {
         NetVpnPrivate *priv = vpn->priv;
-        return nm_setting_vpn_get_data_item (priv->setting, "Xauth username");
+        return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), "Xauth username");
 }
 
 const gchar *
 net_vpn_get_password (NetVpn *vpn)
 {
         NetVpnPrivate *priv = vpn->priv;
-        return nm_setting_vpn_get_data_item (priv->setting, "Xauth password");
+        return nm_setting_vpn_get_data_item (nm_connection_get_setting_vpn (priv->connection), "Xauth password");
 }
 
 static void
@@ -146,8 +141,6 @@ net_vpn_finalize (GObject *object)
         NetVpnPrivate *priv = vpn->priv;
 
         g_object_unref (priv->connection);
-        if (priv->setting != NULL)
-                g_object_unref (priv->setting);
 
         G_OBJECT_CLASS (net_vpn_parent_class)->finalize (object);
 }



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