[gnome-control-center: 11/14] network: Show detailed information about saved wireless connections



commit 1aa2ed94919a9d2e4278dd2e0f2248e6b905d199
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jul 27 11:49:54 2012 +0100

    network: Show detailed information about saved wireless connections

 panels/network/net-device-wifi.c |  109 +++++++++++++++--
 panels/network/network-wifi.ui   |  237 +++++++++++++++++++++++++++++++++++---
 2 files changed, 317 insertions(+), 29 deletions(-)
---
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 7e51f38..7da0488 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -146,9 +146,6 @@ add_access_point (NetDeviceWifi *device_wifi, NMAccessPoint *ap, NMAccessPoint *
         title = g_markup_escape_text (ssid_text, -1);
 
         is_active_ap = active && nm_utils_same_ssid (ssid, nm_access_point_get_ssid (active), TRUE);
-        if (is_active_ap)
-                device_wifi->priv->ssid = g_strdup (ssid_text);
-
         liststore_network = GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
                                             "liststore_network"));
 
@@ -787,11 +784,6 @@ nm_device_wifi_refresh_ui (NetDeviceWifi *device_wifi)
                                          "strength",
                                          str);
 
-        /* setup wireless button */
-        widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder,
-                                                     "button_forget"));
-        gtk_widget_set_visible (widget, active_ap != NULL);
-
         /* only disconnect when connection active */
         widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder,
                                                      "button_disconnect"));
@@ -1542,14 +1534,101 @@ connect_wifi_network (NetDeviceWifi *device_wifi,
 }
 
 static void
+update_saved_last_used (NetDeviceWifi *device_wifi, const gchar *connection_id)
+{
+        gchar *last_used = NULL;
+        GDateTime *now = NULL;
+        GDateTime *then = NULL;
+        gint days;
+        GTimeSpan diff;
+        guint64 timestamp;
+        NMRemoteConnection *connection;
+        NMRemoteSettings *remote_settings;
+        NMSettingConnection *s_con;
+
+        remote_settings = net_object_get_remote_settings (NET_OBJECT (device_wifi));
+        connection = nm_remote_settings_get_connection_by_path (remote_settings, connection_id);
+        if (connection == NULL)
+                goto out;
+        s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+        if (s_con == NULL)
+                goto out;
+        timestamp = nm_setting_connection_get_timestamp (s_con);
+        if (timestamp == 0)
+                goto out;
+
+        /* calculate the amount of time that has elapsed */
+        now = g_date_time_new_now_utc ();
+        then = g_date_time_new_from_unix_utc (timestamp);
+        diff = g_date_time_difference  (now, then);
+        days = diff / G_TIME_SPAN_DAY;
+        last_used = g_strdup_printf (ngettext ("%i day ago", "%i days ago", days), days);
+out:
+        panel_set_device_widget_details (device_wifi->priv->builder,
+                                         "saved_last_used",
+                                         last_used);
+        if (now != NULL)
+                g_date_time_unref (now);
+        if (then != NULL)
+                g_date_time_unref (then);
+        g_free (last_used);
+}
+
+static void
 show_wifi_details (NetDeviceWifi *device_wifi,
                    GtkTreeView *tv,
                    GtkTreePath *path)
 {
         GtkWidget *widget;
+        gboolean ret;
+        gboolean in_range;
+        GtkTreeModel *model;
+        GtkTreeIter iter;
+        gchar *path_str;
+        gchar *id;
+
+        model = gtk_tree_view_get_model (tv);
+        path_str = gtk_tree_path_to_string (path);
+        ret = gtk_tree_model_get_iter_from_string (model, &iter, path_str);
+        if (!ret)
+                goto out;
+
+        /* get parameters about the selected connection */
+        g_free (device_wifi->priv->ssid);
+        gtk_tree_model_get (model, &iter,
+                            COLUMN_ID, &id,
+                            COLUMN_TITLE, &device_wifi->priv->ssid,
+                            COLUMN_AP_IN_RANGE, &in_range,
+                            -1);
+        g_debug ("ssid = %s, in-range = %i",
+                 device_wifi->priv->ssid, in_range);
 
         widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder, "notebook_view"));
-        gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
+        if (in_range) {
+                /* this is automatically key up to date */
+                gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 1);
+                goto out;
+        }
+
+        /* update the last used label */
+        update_saved_last_used (device_wifi, id);
+
+        gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), 4);
+
+        /* set header with SSID */
+        widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder, "label_saved_device"));
+        gtk_label_set_label (GTK_LABEL (widget), device_wifi->priv->ssid);
+
+        /* NM doesn't tell us this yet */
+        panel_set_device_widget_details (device_wifi->priv->builder,
+                                         "saved_security",
+                                         NULL);
+        panel_set_device_widget_details (device_wifi->priv->builder,
+                                         "saved_security_key",
+                                         NULL);
+out:
+        g_free (id);
+        g_free (path_str);
 }
 
 static void
@@ -1565,15 +1644,17 @@ arrow_visible (GtkTreeModel *model,
                GtkTreeIter  *iter)
 {
         gboolean active;
+        gboolean ap_is_saved;
         gboolean ret;
         gchar *sort;
 
         gtk_tree_model_get (model, iter,
                             COLUMN_ACTIVE, &active,
+                            COLUMN_AP_IS_SAVED, &ap_is_saved,
                             COLUMN_SORT, &sort,
                             -1);
 
-        if (active || strcmp ("ap:hidden", sort) == 0)
+        if (active || ap_is_saved || strcmp ("ap:hidden", sort) == 0)
                 ret = TRUE;
         else
                 ret = FALSE;
@@ -1844,11 +1925,9 @@ net_device_wifi_init (NetDeviceWifi *device_wifi)
 
         renderer = gtk_cell_renderer_pixbuf_new ();
         gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (column), renderer, FALSE);
-        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (column), renderer,
-                                        "visible", COLUMN_AP_IN_RANGE,
-                                        NULL);
         g_object_set (renderer,
                       "follow-state", TRUE,
+                      "visible", TRUE,
                       NULL);
         gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (column), renderer,
                                             set_arrow_image, device_wifi, NULL);
@@ -1857,6 +1936,10 @@ net_device_wifi_init (NetDeviceWifi *device_wifi)
                                                      "button_back"));
         g_signal_connect_swapped (widget, "clicked",
                                   G_CALLBACK (show_wifi_list), device_wifi);
+        widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder,
+                                                     "button_saved_back"));
+        g_signal_connect_swapped (widget, "clicked",
+                                  G_CALLBACK (show_wifi_list), device_wifi);
 
         /* setup view */
         widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder,
diff --git a/panels/network/network-wifi.ui b/panels/network/network-wifi.ui
index 4168ea2..01ea232 100644
--- a/panels/network/network-wifi.ui
+++ b/panels/network/network-wifi.ui
@@ -607,21 +607,6 @@
                 <property name="can_focus">False</property>
                 <property name="margin_top">12</property>
                 <child>
-                  <object class="GtkButton" id="button_forget">
-                    <property name="label" translatable="yes">_Forget Network</property>
-                    <property name="can_focus">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="halign">start</property>
-                    <property name="valign">end</property>
-                    <property name="use_underline">True</property>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">True</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
                   <object class="GtkButton" id="stop_hotspot_button">
                     <property name="label" translatable="yes">_Stop Hotspot...</property>
                     <property name="can_focus">True</property>
@@ -636,7 +621,7 @@
                   <packing>
                     <property name="expand">False</property>
                     <property name="fill">True</property>
-                    <property name="position">1</property>
+                    <property name="position">0</property>
                   </packing>
                 </child>
                 <child>
@@ -722,6 +707,226 @@
             <property name="tab_fill">False</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkBox" id="box1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkGrid" id="grid1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="valign">start</property>
+                <property name="row_spacing">10</property>
+                <property name="column_spacing">6</property>
+                <child>
+                  <object class="GtkVBox" id="vbox1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="valign">start</property>
+                    <property name="hexpand">True</property>
+                    <property name="spacing">3</property>
+                    <child>
+                      <object class="GtkLabel" id="label_saved_device">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label">SSID HERE</property>
+                        <property name="ellipsize">end</property>
+                        <attributes>
+                          <attribute name="weight" value="bold"/>
+                          <attribute name="scale" value="1.2"/>
+                        </attributes>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkLabel" id="label_saved_status">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="xalign">0</property>
+                        <property name="label" translatable="yes">Out of range</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="heading_saved_security">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Security</property>
+                    <property name="mnemonic_widget">label_saved_security</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="heading_saved_security_key">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Security Key</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">3</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label_saved_security">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label">WPA</property>
+                    <property name="selectable">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">2</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label_saved_security_key">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label">My Secret</property>
+                    <property name="selectable">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">3</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_saved_back">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="halign">start</property>
+                    <property name="valign">center</property>
+                    <property name="hexpand">True</property>
+                    <child>
+                      <object class="GtkArrow" id="arrow2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="arrow_type">left</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="heading_saved_last_used">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">Last used</property>
+                    <property name="mnemonic_widget">label_saved_last_used</property>
+                    <style>
+                      <class name="dim-label"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label_saved_last_used">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">Security</property>
+                    <property name="mnemonic_widget">label_security</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button_forget">
+                <property name="label" translatable="yes">_Forget Network</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="halign">start</property>
+                <property name="valign">end</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="position">4</property>
+          </packing>
+        </child>
+        <child type="tab">
+          <object class="GtkLabel" id="label43">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label">saved-ap</property>
+          </object>
+          <packing>
+            <property name="position">4</property>
+            <property name="tab_fill">False</property>
+          </packing>
+        </child>
       </object>
     </child>
   </object>



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