[network-manager-applet/lr/ui-improvements: 11/20] editor: the connection list overhaul



commit 54d758d39d72f96001a79aee0b0a7b3f90ce51fd
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Jun 23 20:37:21 2017 +0200

    editor: the connection list overhaul
    
    Turn it into a GtkWindow, remove the extra buttons and use the GtkButtonBar for
    actions. This saves some space.

 src/connection-editor/main.c                |    2 -
 src/connection-editor/nm-connection-list.c  |  129 +++++++++++++--------------
 src/connection-editor/nm-connection-list.h  |    7 +-
 src/connection-editor/nm-connection-list.ui |  127 +++++++++++----------------
 4 files changed, 118 insertions(+), 147 deletions(-)
---
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c
index 7a71d5b..02490e4 100644
--- a/src/connection-editor/main.c
+++ b/src/connection-editor/main.c
@@ -396,8 +396,6 @@ out:
        g_clear_error (&error);
        if (opt_ctx)
                g_option_context_free (opt_ctx);
-       if (list)
-               gtk_widget_destroy (GTK_WIDGET (list));
        g_clear_object (&bus);
        return ret;
 }
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 602024f..8a77e93 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -3,6 +3,7 @@
  *
  * Rodrigo Moya <rodrigo gnome-db org>
  * Dan Williams <dcbw redhat com>
+ * Lubomir Rintel <lkundrak v3 sk>
  *
  * 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
@@ -31,7 +32,7 @@
 #include "ce-page.h"
 #include "nm-connection-editor.h"
 #include "nm-connection-list.h"
-#include "ce-polkit-button.h"
+#include "ce-polkit.h"
 #include "connection-helpers.h"
 
 extern gboolean nm_ce_keep_above;
@@ -45,7 +46,9 @@ enum {
 static guint list_signals[LIST_LAST_SIGNAL] = { 0 };
 
 struct _NMConnectionListPrivate {
-       GtkWidget *connection_button_box;
+       GtkWidget *connection_add;
+       GtkWidget *connection_del;
+       GtkWidget *connection_edit;
        GtkTreeView *connection_list;
        GtkTreeModel *model;
        GtkTreeModelFilter *filter;
@@ -61,7 +64,7 @@ struct _NMConnectionListPrivate {
                                            NM_TYPE_CONNECTION_LIST, \
                                            NMConnectionListPrivate))
 
-G_DEFINE_TYPE_WITH_CODE (NMConnectionList, nm_connection_list, GTK_TYPE_DIALOG,
+G_DEFINE_TYPE_WITH_CODE (NMConnectionList, nm_connection_list, GTK_TYPE_WINDOW,
                          G_ADD_PRIVATE (NMConnectionList))
 
 #define COL_ID         0
@@ -414,28 +417,35 @@ delete_clicked (GtkButton *button, gpointer user_data)
 }
 
 static void
-pk_button_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
+selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
 {
-       CEPolkitButton *button = user_data;
-       NMConnectionList *list = g_object_get_data (G_OBJECT (button), "NMConnectionList");
+       NMConnectionList *list = user_data;
        NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        GtkTreeIter iter;
        GtkTreeModel *model;
-       NMRemoteConnection *connection;
+       NMRemoteConnection *connection = NULL;
        NMSettingConnection *s_con;
        gboolean sensitive = FALSE;
 
-       if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+       if (gtk_tree_selection_get_selected (selection, &model, &iter))
                connection = get_active_connection (priv->connection_list);
-               if (connection) {
-                       s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
-                       g_assert (s_con);
 
-                       sensitive = !nm_setting_connection_get_read_only (s_con);
-               }
-       }
+       if (connection) {
+               s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
+               g_assert (s_con);
 
-       ce_polkit_button_set_validation_error (button, sensitive ? NULL : _("Connection cannot be modified"));
+               sensitive = !nm_setting_connection_get_read_only (s_con);
+
+               ce_polkit_set_widget_validation_error (priv->connection_edit,
+                                                      sensitive ? NULL : _("Connection cannot be modified"));
+               ce_polkit_set_widget_validation_error (priv->connection_del,
+                                                      sensitive ? NULL : _("Connection cannot be deleted"));
+       } else {
+               ce_polkit_set_widget_validation_error (priv->connection_edit,
+                                                      _("Select a connection to edit"));
+               ce_polkit_set_widget_validation_error (priv->connection_del,
+                                                      _("Select a connection to delete"));
+       }
 }
 
 static void
@@ -444,22 +454,20 @@ connection_double_clicked_cb (GtkTreeView *tree_view,
                               GtkTreeViewColumn *column,
                               gpointer user_data)
 {
-       GtkButton *button = user_data;
-
-       if (ce_polkit_button_get_actionable (CE_POLKIT_BUTTON (button)))
-               gtk_button_clicked (button);
-}
+       NMConnectionList *list = user_data;
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
-static void
-list_response_cb (GtkDialog *dialog, gint response, gpointer user_data)
-{
-       g_signal_emit (NM_CONNECTION_LIST (user_data), list_signals[LIST_DONE], 0, response);
+       if (gtk_widget_get_sensitive (priv->connection_edit))
+               do_edit (list);
 }
 
 static void
 list_close_cb (GtkDialog *dialog, gpointer user_data)
 {
-       gtk_dialog_response (dialog, GTK_RESPONSE_CLOSE);
+       g_signal_emit (NM_CONNECTION_LIST (user_data),
+                      list_signals[LIST_DONE],
+                      0,
+                      GTK_RESPONSE_CLOSE);
 }
 
 static void
@@ -510,10 +518,13 @@ nm_connection_list_class_init (NMConnectionListClass *klass)
                                                     
"/org/freedesktop/network-manager-applet/nm-connection-list.ui");
 
         gtk_widget_class_bind_template_child_private (widget_class, NMConnectionList, connection_list);
-        gtk_widget_class_bind_template_child_private (widget_class, NMConnectionList, connection_button_box);
+        gtk_widget_class_bind_template_child_private (widget_class, NMConnectionList, connection_add);
+        gtk_widget_class_bind_template_child_private (widget_class, NMConnectionList, connection_del);
+        gtk_widget_class_bind_template_child_private (widget_class, NMConnectionList, connection_edit);
 
         gtk_widget_class_bind_template_callback (widget_class, add_clicked);
-        gtk_widget_class_bind_template_callback (widget_class, list_response_cb);
+        gtk_widget_class_bind_template_callback (widget_class, do_edit);
+        gtk_widget_class_bind_template_callback (widget_class, delete_clicked);
         gtk_widget_class_bind_template_callback (widget_class, list_close_cb);
 }
 
@@ -727,43 +738,34 @@ static void
 add_connection_buttons (NMConnectionList *self)
 {
        NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
-       GtkWidget *button;
        GtkTreeSelection *selection;
 
+
+       ce_polkit_connect_widget (priv->connection_edit,
+                                 _("Edit the selected connection"),
+                                 _("Authenticate to edit the selected connection"),
+                                 priv->client,
+                                 NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM);
+
+       ce_polkit_connect_widget (priv->connection_del,
+                                 _("Delete the selected connection"),
+                                 _("Authenticate to delete the selected connection"),
+                                 priv->client,
+                                 NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM);
+
        selection = gtk_tree_view_get_selection (priv->connection_list);
 
-       /* Edit */
-       button = ce_polkit_button_new (_("_Edit"),
-                                      _("Edit the selected connection"),
-                                      _("Authenticate to edit the selected connection"),
-                                      "emblem-system-symbolic",
-                                      priv->client,
-                                      NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM);
-       g_object_set_data (G_OBJECT (button), "NMConnectionList", self);
-       gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
-       gtk_box_pack_end (GTK_BOX (priv->connection_button_box), button, TRUE, TRUE, 0);
-
-       g_signal_connect_swapped (button, "clicked", G_CALLBACK (do_edit), self);
-       g_signal_connect (priv->connection_list, "row-activated", G_CALLBACK (connection_double_clicked_cb), 
button);
-       g_signal_connect (selection, "changed", G_CALLBACK (pk_button_selection_changed_cb), button);
-       pk_button_selection_changed_cb (selection, button);
-
-       /* Delete */
-       button = ce_polkit_button_new (_("_Delete"),
-                                      _("Delete the selected connection"),
-                                      _("Authenticate to delete the selected connection"),
-                                      "edit-delete-symbolic",
-                                      priv->client,
-                                      NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM);
-       g_object_set_data (G_OBJECT (button), "NMConnectionList", self);
-       gtk_button_set_use_underline (GTK_BUTTON (button), TRUE);
-       gtk_box_pack_end (GTK_BOX (priv->connection_button_box), button, TRUE, TRUE, 0);
-
-       g_signal_connect (button, "clicked", G_CALLBACK (delete_clicked), self);
-       g_signal_connect (selection, "changed", G_CALLBACK (pk_button_selection_changed_cb), button);
-       pk_button_selection_changed_cb (selection, button);
-
-       gtk_widget_show_all (priv->connection_button_box);
+       g_signal_connect (priv->connection_list,
+                         "row-activated",
+                         G_CALLBACK (connection_double_clicked_cb),
+                         self);
+
+       g_signal_connect (selection,
+                         "changed",
+                         G_CALLBACK (selection_changed_cb),
+                         self);
+
+       selection_changed_cb (selection, self);
 }
 
 static void
@@ -1036,15 +1038,8 @@ nm_connection_list_present (NMConnectionList *list)
                        gtk_tree_path_free (path);
                }
 
-#if 0
-               g_signal_connect (G_OBJECT (priv->dialog), "response",
-                                     G_CALLBACK (list_response_cb), list);
-               g_signal_connect (G_OBJECT (priv->dialog), "close",
-                                     G_CALLBACK (list_close_cb), list);
-#endif
                priv->populated = TRUE;
        }
 
        gtk_window_present (GTK_WINDOW (list));
 }
-
diff --git a/src/connection-editor/nm-connection-list.h b/src/connection-editor/nm-connection-list.h
index e778344..6046e87 100644
--- a/src/connection-editor/nm-connection-list.h
+++ b/src/connection-editor/nm-connection-list.h
@@ -2,6 +2,7 @@
 /* NetworkManager Connection editor -- Connection editor for NetworkManager
  *
  * Rodrigo Moya <rodrigo gnome-db org>
+ * Lubomir Rintel <lkundrak v3 sk>
  *
  * 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
@@ -17,7 +18,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * Copyright 2004 - 2014 Red Hat, Inc.
+ * Copyright 2004 - 2017 Red Hat, Inc.
  */
 
 #ifndef NM_CONNECTION_LIST_H
@@ -36,11 +37,11 @@
 typedef struct _NMConnectionListPrivate NMConnectionListPrivate;
 
 typedef struct {
-       GtkDialog parent;
+       GtkWindow parent;
 } NMConnectionList;
 
 typedef struct {
-       GtkDialogClass parent_class;
+       GtkWindowClass parent_class;
 
        /* Signals */
        void (*done)  (NMConnectionList *list, gint result);
diff --git a/src/connection-editor/nm-connection-list.ui b/src/connection-editor/nm-connection-list.ui
index e345254..2bc3ddc 100644
--- a/src/connection-editor/nm-connection-list.ui
+++ b/src/connection-editor/nm-connection-list.ui
@@ -2,125 +2,102 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <template class="NMConnectionList" parent="GtkDialog">
+  <template class="NMConnectionList" parent="GtkWindow">
     <property name="can_focus">False</property>
-    <property name="border_width">5</property>
     <property name="title" translatable="yes">Network Connections</property>
     <property name="window_position">center</property>
     <property name="default_width">600</property>
     <property name="default_height">400</property>
-    <property name="icon_name">preferences-system-network</property>
-    <property name="type_hint">dialog</property>
-    <signal name="close" handler="list_close_cb" swapped="no"/>
-    <signal name="response" handler="list_response_cb" swapped="no"/>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox2">
+    <property name="gravity">north-east</property>
+    <signal name="destroy" handler="list_close_cb" swapped="no"/>
+    <child>
+      <object class="GtkBox" id="connection_box">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="border_width">6</property>
         <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area2">
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow1">
             <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">never</property>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkButton" id="closebutton1">
-                <property name="label" translatable="yes">_Close</property>
+              <object class="GtkTreeView" id="connection_list">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="receives_default">False</property>
-                <property name="use_underline">True</property>
+                <child internal-child="selection">
+                  <object class="GtkTreeSelection"/>
+                </child>
               </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
             </child>
           </object>
           <packing>
-            <property name="expand">False</property>
+            <property name="expand">True</property>
             <property name="fill">True</property>
-            <property name="pack_type">end</property>
             <property name="position">0</property>
           </packing>
         </child>
         <child>
-          <object class="GtkHBox" id="hbox2">
+          <object class="GtkToolbar" id="connection_toolbar">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="border_width">6</property>
-            <property name="spacing">6</property>
+            <property name="toolbar_style">icons</property>
+            <property name="icon_size">2</property>
             <child>
-              <object class="GtkScrolledWindow" id="scrolledwindow1">
+              <object class="GtkToolButton" id="connection_add">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="hscrollbar_policy">never</property>
-                <property name="shadow_type">in</property>
-                <child>
-                  <object class="GtkTreeView" id="connection_list">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <child internal-child="selection">
-                      <object class="GtkTreeSelection" id="treeview-selection1"/>
-                    </child>
-                  </object>
-                </child>
+                <property name="can_focus">False</property>
+                <property name="tooltip_text" translatable="yes">Add a new connection</property>
+                <property name="label" translatable="yes">_Add</property>
+                <property name="use_underline">True</property>
+                <property name="icon_name">list-add-symbolic</property>
+                <signal name="clicked" handler="add_clicked" swapped="no"/>
               </object>
               <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
               </packing>
             </child>
             <child>
-              <object class="GtkVButtonBox" id="connection_button_box">
+              <object class="GtkToolButton" id="connection_del">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="spacing">6</property>
-                <property name="layout_style">start</property>
-                <child>
-                  <object class="GtkButton" id="connection_add">
-                    <property name="label" translatable="yes">_Add</property>
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="can_default">True</property>
-                    <property name="receives_default">True</property>
-                    <property name="use_underline">True</property>
-                    <signal name="clicked" handler="add_clicked" swapped="no"/>
-                  </object>
-                  <packing>
-                    <property name="expand">False</property>
-                    <property name="fill">False</property>
-                    <property name="position">0</property>
-                  </packing>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
-                <child>
-                  <placeholder/>
-                </child>
+                <property name="label" translatable="yes">_Delete</property>
+                <property name="use_underline">True</property>
+                <property name="icon_name">list-remove-symbolic</property>
+                <signal name="clicked" handler="delete_clicked" swapped="no"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="homogeneous">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkToolButton" id="connection_edit">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="label" translatable="yes">_Edit</property>
+                <property name="use_underline">True</property>
+                <property name="icon_name">emblem-system-symbolic</property>
+                <signal name="clicked" handler="do_edit" swapped="yes"/>
               </object>
               <packing>
                 <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
+                <property name="homogeneous">True</property>
               </packing>
             </child>
+            <style>
+              <class name="inline-toolbar"/>
+            </style>
           </object>
           <packing>
-            <property name="expand">True</property>
+            <property name="expand">False</property>
             <property name="fill">True</property>
             <property name="position">1</property>
           </packing>
         </child>
       </object>
     </child>
-    <action-widgets>
-      <action-widget response="-7">closebutton1</action-widget>
-    </action-widgets>
   </template>
 </interface>


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