[network-manager-applet/lr/ui-improvements: 9/18] editor: turn NMConnectionList into a widget template



commit e3fe45a4447aaba7fed188b564a139d3fe3421ce
Author: Lubomir Rintel <lkundrak v3 sk>
Date:   Fri Jun 23 20:29:18 2017 +0200

    editor: turn NMConnectionList into a widget template
    
    Make NMConnectionList subclass GtkDialog via a widget template instead of
    composing one with GtkBuilder. This reduces the number of objects and at the
    same time gives us opportunity to set construct-only properties at object
    creation time.

 src/connection-editor/ce.gresource.xml        |    1 +
 src/connection-editor/main.c                  |    3 +-
 src/connection-editor/nm-connection-editor.ui |  118 ----------
 src/connection-editor/nm-connection-list.c    |  290 ++++++++++++++-----------
 src/connection-editor/nm-connection-list.h    |   21 +--
 src/connection-editor/nm-connection-list.ui   |  126 +++++++++++
 6 files changed, 294 insertions(+), 265 deletions(-)
---
diff --git a/src/connection-editor/ce.gresource.xml b/src/connection-editor/ce.gresource.xml
index 8533ed9..d0965dc 100644
--- a/src/connection-editor/ce.gresource.xml
+++ b/src/connection-editor/ce.gresource.xml
@@ -2,6 +2,7 @@
 <gresources>
        <gresource prefix="/org/freedesktop/network-manager-applet">
                <file preprocess="xml-stripblanks">nm-connection-editor.ui</file>
+               <file preprocess="xml-stripblanks">nm-connection-list.ui</file>
                <file preprocess="xml-stripblanks">ce-ip4-routes.ui</file>
                <file preprocess="xml-stripblanks">ce-ip6-routes.ui</file>
                <file preprocess="xml-stripblanks">ce-new-connection.ui</file>
diff --git a/src/connection-editor/main.c b/src/connection-editor/main.c
index a942369..7a71d5b 100644
--- a/src/connection-editor/main.c
+++ b/src/connection-editor/main.c
@@ -396,7 +396,8 @@ out:
        g_clear_error (&error);
        if (opt_ctx)
                g_option_context_free (opt_ctx);
-       g_clear_object (&list);
+       if (list)
+               gtk_widget_destroy (GTK_WIDGET (list));
        g_clear_object (&bus);
        return ret;
 }
diff --git a/src/connection-editor/nm-connection-editor.ui b/src/connection-editor/nm-connection-editor.ui
index ecb2488..209da9e 100644
--- a/src/connection-editor/nm-connection-editor.ui
+++ b/src/connection-editor/nm-connection-editor.ui
@@ -2,124 +2,6 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <object class="GtkDialog" id="NMConnectionList">
-    <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>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox2">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="dialog-action_area2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="closebutton1">
-                <property name="label" translatable="yes">_Close</property>
-                <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>
-              </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="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkHBox" id="hbox2">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="border_width">6</property>
-            <property name="spacing">6</property>
-            <child>
-              <object class="GtkScrolledWindow" id="scrolledwindow1">
-                <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>
-              </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkVButtonBox" id="connection_button_box">
-                <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>
-                  </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>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">True</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>
-  </object>
   <object class="GtkWindow" id="nm-connection-editor">
     <property name="can_focus">False</property>
     <property name="window_position">center</property>
diff --git a/src/connection-editor/nm-connection-list.c b/src/connection-editor/nm-connection-list.c
index 36936e7..b47b03e 100644
--- a/src/connection-editor/nm-connection-list.c
+++ b/src/connection-editor/nm-connection-list.c
@@ -36,8 +36,6 @@
 
 extern gboolean nm_ce_keep_above;
 
-G_DEFINE_TYPE (NMConnectionList, nm_connection_list, G_TYPE_OBJECT)
-
 enum {
        LIST_DONE,
        EDITING_DONE,
@@ -46,6 +44,26 @@ enum {
 
 static guint list_signals[LIST_LAST_SIGNAL] = { 0 };
 
+struct _NMConnectionListPrivate {
+       GtkWidget *connection_button_box;
+       GtkTreeView *connection_list;
+       GtkTreeModel *model;
+       GtkTreeModelFilter *filter;
+       GtkTreeSortable *sortable;
+       GType displayed_type;
+
+       NMClient *client;
+
+       gboolean populated;
+};
+
+#define NM_CONNECTION_LIST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+                                           NM_TYPE_CONNECTION_LIST, \
+                                           NMConnectionListPrivate))
+
+G_DEFINE_TYPE_WITH_CODE (NMConnectionList, nm_connection_list, GTK_TYPE_DIALOG,
+                         G_ADD_PRIVATE (NMConnectionList))
+
 #define COL_ID         0
 #define COL_LAST_USED  1
 #define COL_TIMESTAMP  2
@@ -91,18 +109,19 @@ get_iter_for_connection (NMConnectionList *list,
                          GtkTreeIter *iter)
 {
        GtkTreeIter types_iter;
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
-       if (!gtk_tree_model_get_iter_first (list->model, &types_iter))
+       if (!gtk_tree_model_get_iter_first (priv->model, &types_iter))
                return FALSE;
 
        do {
-               if (!gtk_tree_model_iter_children (list->model, iter, &types_iter))
+               if (!gtk_tree_model_iter_children (priv->model, iter, &types_iter))
                        continue;
 
                do {
                        NMRemoteConnection *candidate = NULL;
 
-                       gtk_tree_model_get (list->model, iter,
+                       gtk_tree_model_get (priv->model, iter,
                                            COL_CONNECTION, &candidate,
                                            -1);
                        if (candidate == connection) {
@@ -110,8 +129,8 @@ get_iter_for_connection (NMConnectionList *list,
                                return TRUE;
                        }
                        g_object_unref (candidate);
-               } while (gtk_tree_model_iter_next (list->model, iter));
-       } while (gtk_tree_model_iter_next (list->model, &types_iter));
+               } while (gtk_tree_model_iter_next (priv->model, iter));
+       } while (gtk_tree_model_iter_next (priv->model, &types_iter));
 
        return FALSE;
 }
@@ -193,6 +212,7 @@ update_connection_row (NMConnectionList *self,
                        GtkTreeIter *iter,
                        NMRemoteConnection *connection)
 {
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
        NMSettingConnection *s_con;
        char *last_used, *id;
 
@@ -201,7 +221,7 @@ update_connection_row (NMConnectionList *self,
 
        last_used = format_last_used (nm_setting_connection_get_timestamp (s_con));
        id = g_markup_escape_text (nm_setting_connection_get_id (s_con), -1);
-       gtk_tree_store_set (GTK_TREE_STORE (self->model), iter,
+       gtk_tree_store_set (GTK_TREE_STORE (priv->model), iter,
                            COL_ID, id,
                            COL_LAST_USED, last_used,
                            COL_TIMESTAMP, nm_setting_connection_get_timestamp (s_con),
@@ -210,23 +230,24 @@ update_connection_row (NMConnectionList *self,
        g_free (last_used);
        g_free (id);
 
-       gtk_tree_model_filter_refilter (self->filter);
+       gtk_tree_model_filter_refilter (priv->filter);
 }
 
 static void
 delete_slaves_of_connection (NMConnectionList *list, NMConnection *connection)
 {
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        const char *uuid, *iface;
        GtkTreeIter iter, types_iter;
 
-       if (!gtk_tree_model_get_iter_first (list->model, &types_iter))
+       if (!gtk_tree_model_get_iter_first (priv->model, &types_iter))
                return;
 
        uuid = nm_connection_get_uuid (connection);
        iface = nm_connection_get_interface_name (connection);
 
        do {
-               if (!gtk_tree_model_iter_children (list->model, &iter, &types_iter))
+               if (!gtk_tree_model_iter_children (priv->model, &iter, &types_iter))
                        continue;
 
                do {
@@ -234,7 +255,7 @@ delete_slaves_of_connection (NMConnectionList *list, NMConnection *connection)
                        NMSettingConnection *s_con;
                        const char *master;
 
-                       gtk_tree_model_get (list->model, &iter,
+                       gtk_tree_model_get (priv->model, &iter,
                                            COL_CONNECTION, &candidate,
                                            -1);
                        s_con = nm_connection_get_setting_connection (NM_CONNECTION (candidate));
@@ -245,8 +266,8 @@ delete_slaves_of_connection (NMConnectionList *list, NMConnection *connection)
                        }
 
                        g_object_unref (candidate);
-               } while (gtk_tree_model_iter_next (list->model, &iter));
-       } while (gtk_tree_model_iter_next (list->model, &types_iter));
+               } while (gtk_tree_model_iter_next (priv->model, &iter));
+       } while (gtk_tree_model_iter_next (priv->model, &types_iter));
 }
 
 
@@ -271,6 +292,7 @@ really_add_connection (FUNC_TAG_NEW_CONNECTION_RESULT_IMPL,
                        gpointer user_data)
 {
        NMConnectionList *list = user_data;
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        NMConnectionEditor *editor;
 
        if (!connection) {
@@ -285,7 +307,7 @@ really_add_connection (FUNC_TAG_NEW_CONNECTION_RESULT_IMPL,
        if (connection_supports_ip6 (connection) && !nm_connection_get_setting_ip6_config (connection))
                nm_connection_add_setting (connection, nm_setting_ip6_config_new ());
 
-       editor = nm_connection_editor_new (GTK_WINDOW (list->dialog), connection, list->client);
+       editor = nm_connection_editor_new (GTK_WINDOW (list), connection, priv->client);
        if (!editor) {
                g_signal_emit (list, list_signals[EDITING_DONE], 0, 0);
                return;
@@ -304,10 +326,13 @@ add_clicked (GtkButton *button, gpointer user_data)
 void
 nm_connection_list_add (NMConnectionList *list)
 {
+       NMConnectionListPrivate *priv;
+
        g_return_if_fail (NM_IS_CONNECTION_LIST (list));
+       priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
-       new_connection_dialog (GTK_WINDOW (list->dialog),
-                              list->client,
+       new_connection_dialog (GTK_WINDOW (list),
+                              priv->client,
                               NULL,
                               really_add_connection,
                               list);
@@ -333,6 +358,7 @@ edit_done_cb (NMConnectionEditor *editor, GtkResponseType response, gpointer use
 static void
 edit_connection (NMConnectionList *list, NMConnection *connection)
 {
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        NMConnectionEditor *editor;
 
        g_return_if_fail (connection != NULL);
@@ -344,9 +370,9 @@ edit_connection (NMConnectionList *list, NMConnection *connection)
                return;
        }
 
-       editor = nm_connection_editor_new (GTK_WINDOW (list->dialog),
+       editor = nm_connection_editor_new (GTK_WINDOW (list),
                                           NM_CONNECTION (connection),
-                                          list->client);
+                                          priv->client);
        if (editor) {
                g_signal_connect (editor, "done", G_CALLBACK (edit_done_cb), list);
                nm_connection_editor_run (editor);
@@ -356,7 +382,9 @@ edit_connection (NMConnectionList *list, NMConnection *connection)
 static void
 do_edit (NMConnectionList *list)
 {
-       edit_connection (list, NM_CONNECTION (get_active_connection (list->connection_list)));
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
+
+       edit_connection (list, NM_CONNECTION (get_active_connection (priv->connection_list)));
 }
 
 static void
@@ -375,12 +403,13 @@ static void
 delete_clicked (GtkButton *button, gpointer user_data)
 {
        NMConnectionList *list = user_data;
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        NMRemoteConnection *connection;
 
-       connection = get_active_connection (list->connection_list);
+       connection = get_active_connection (priv->connection_list);
        g_return_if_fail (connection != NULL);
 
-       delete_connection (GTK_WINDOW (list->dialog), connection,
+       delete_connection (GTK_WINDOW (list), connection,
                           delete_connection_cb, list);
 }
 
@@ -389,6 +418,7 @@ pk_button_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
 {
        CEPolkitButton *button = user_data;
        NMConnectionList *list = g_object_get_data (G_OBJECT (button), "NMConnectionList");
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        GtkTreeIter iter;
        GtkTreeModel *model;
        NMRemoteConnection *connection;
@@ -396,7 +426,7 @@ pk_button_selection_changed_cb (GtkTreeSelection *selection, gpointer user_data)
        gboolean sensitive = FALSE;
 
        if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
-               connection = get_active_connection (list->connection_list);
+               connection = get_active_connection (priv->connection_list);
                if (connection) {
                        s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
                        g_assert (s_con);
@@ -421,28 +451,32 @@ connection_double_clicked_cb (GtkTreeView *tree_view,
 }
 
 static void
-dialog_response_cb (GtkDialog *dialog, guint response, gpointer user_data)
+list_response_cb (GtkDialog *dialog, gint response, gpointer user_data)
 {
-       gtk_widget_hide (GTK_WIDGET (dialog));
+       g_signal_emit (NM_CONNECTION_LIST (user_data), list_signals[LIST_DONE], 0, response);
+}
+
+static void
+list_close_cb (GtkDialog *dialog, gpointer user_data)
+{
+       gtk_dialog_response (dialog, GTK_RESPONSE_CLOSE);
 }
 
 static void
 nm_connection_list_init (NMConnectionList *list)
 {
+       list->priv = nm_connection_list_get_instance_private (list);
+
+       gtk_widget_init_template (GTK_WIDGET (list));
 }
 
 static void
 dispose (GObject *object)
 {
        NMConnectionList *list = NM_CONNECTION_LIST (object);
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
-       if (list->dialog)
-               gtk_widget_hide (list->dialog);
-
-       if (list->gui)
-               g_object_unref (list->gui);
-       if (list->client)
-               g_object_unref (list->client);
+       g_clear_object (&priv->client);
 
        G_OBJECT_CLASS (nm_connection_list_parent_class)->dispose (object);
 }
@@ -451,6 +485,7 @@ static void
 nm_connection_list_class_init (NMConnectionListClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        /* virtual methods */
        object_class->dispose = dispose;
@@ -471,6 +506,17 @@ nm_connection_list_class_init (NMConnectionListClass *klass)
                              G_STRUCT_OFFSET (NMConnectionListClass, done),
                              NULL, NULL, NULL,
                              G_TYPE_NONE, 1, G_TYPE_INT);
+
+       /* Initialize the widget template */
+        gtk_widget_class_set_template_from_resource (widget_class,
+                                                    
"/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_callback (widget_class, add_clicked);
+        gtk_widget_class_bind_template_callback (widget_class, list_response_cb);
+        gtk_widget_class_bind_template_callback (widget_class, list_close_cb);
 }
 
 static void
@@ -554,6 +600,7 @@ tree_model_visible_func (GtkTreeModel *model,
                          gpointer user_data)
 {
        NMConnectionList *self = user_data;
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
        gs_unref_object NMConnection *connection = NULL;
        NMSettingConnection *s_con;
        const char *master;
@@ -582,7 +629,7 @@ tree_model_visible_func (GtkTreeModel *model,
            && g_strcmp0 (slave_type, NM_SETTING_BRIDGE_SETTING_NAME) != 0)
                return TRUE;
 
-       if (nm_client_get_connection_by_uuid (self->client, master))
+       if (nm_client_get_connection_by_uuid (priv->client, master))
                return FALSE;
        if (nm_connection_editor_get_master (connection))
                return FALSE;
@@ -595,6 +642,7 @@ tree_model_visible_func (GtkTreeModel *model,
 static void
 initialize_treeview (NMConnectionList *self)
 {
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
        GtkCellRenderer *renderer;
        GtkTreeViewColumn *column;
        GtkTreeSelection *selection;
@@ -604,7 +652,7 @@ initialize_treeview (NMConnectionList *self)
        int i;
 
        /* Model */
-       self->model = GTK_TREE_MODEL (gtk_tree_store_new (8, G_TYPE_STRING,
+       priv->model = GTK_TREE_MODEL (gtk_tree_store_new (8, G_TYPE_STRING,
                                                             G_TYPE_STRING,
                                                             G_TYPE_UINT64,
                                                             G_TYPE_OBJECT,
@@ -614,21 +662,21 @@ initialize_treeview (NMConnectionList *self)
                                                             G_TYPE_INT));
 
        /* Filter */
-       self->filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (self->model, NULL));
-       gtk_tree_model_filter_set_visible_func (self->filter,
+       priv->filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (priv->model, NULL));
+       gtk_tree_model_filter_set_visible_func (priv->filter,
                                                tree_model_visible_func,
                                                self, NULL);
 
        /* Sortable */
-       self->sortable = GTK_TREE_SORTABLE (gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL 
(self->filter)));
-       gtk_tree_sortable_set_default_sort_func (self->sortable, NULL, NULL, NULL);
-       gtk_tree_sortable_set_sort_func (self->sortable, COL_TIMESTAMP, timestamp_sort_func,
-                                        self->sortable, NULL);
-       gtk_tree_sortable_set_sort_func (self->sortable, COL_ID, id_sort_func,
-                                        self->sortable, NULL);
-       gtk_tree_sortable_set_sort_column_id (self->sortable, COL_TIMESTAMP, GTK_SORT_ASCENDING);
+       priv->sortable = GTK_TREE_SORTABLE (gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL 
(priv->filter)));
+       gtk_tree_sortable_set_default_sort_func (priv->sortable, NULL, NULL, NULL);
+       gtk_tree_sortable_set_sort_func (priv->sortable, COL_TIMESTAMP, timestamp_sort_func,
+                                        priv->sortable, NULL);
+       gtk_tree_sortable_set_sort_func (priv->sortable, COL_ID, id_sort_func,
+                                        priv->sortable, NULL);
+       gtk_tree_sortable_set_sort_column_id (priv->sortable, COL_TIMESTAMP, GTK_SORT_ASCENDING);
 
-       gtk_tree_view_set_model (self->connection_list, GTK_TREE_MODEL (self->sortable));
+       gtk_tree_view_set_model (priv->connection_list, GTK_TREE_MODEL (priv->sortable));
 
        /* Name column */
        renderer = gtk_cell_renderer_text_new ();
@@ -639,7 +687,7 @@ initialize_treeview (NMConnectionList *self)
        gtk_tree_view_column_set_expand (column, TRUE);
        gtk_tree_view_column_set_sort_column_id (column, COL_ID);
        g_signal_connect (column, "clicked", G_CALLBACK (column_header_clicked_cb), GINT_TO_POINTER (COL_ID));
-       gtk_tree_view_append_column (self->connection_list, column);
+       gtk_tree_view_append_column (priv->connection_list, column);
 
        /* Last Used column */
        renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
@@ -651,10 +699,10 @@ initialize_treeview (NMConnectionList *self)
                                                           NULL);
        gtk_tree_view_column_set_sort_column_id (column, COL_TIMESTAMP);
        g_signal_connect (column, "clicked", G_CALLBACK (column_header_clicked_cb), GINT_TO_POINTER 
(COL_TIMESTAMP));
-       gtk_tree_view_append_column (self->connection_list, column);
+       gtk_tree_view_append_column (priv->connection_list, column);
 
        /* Selection */
-       selection = gtk_tree_view_get_selection (self->connection_list);
+       selection = gtk_tree_view_get_selection (priv->connection_list);
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
 
        /* Fill in connection types */
@@ -665,8 +713,8 @@ initialize_treeview (NMConnectionList *self)
                id = g_strdup_printf ("<b>%s</b>", tmp);
                g_free (tmp);
 
-               gtk_tree_store_append (GTK_TREE_STORE (self->model), &iter, NULL);
-               gtk_tree_store_set (GTK_TREE_STORE (self->model), &iter,
+               gtk_tree_store_append (GTK_TREE_STORE (priv->model), &iter, NULL);
+               gtk_tree_store_set (GTK_TREE_STORE (priv->model), &iter,
                                    COL_ID, id,
                                    COL_GTYPE0, types[i].setting_types[0],
                                    COL_GTYPE1, types[i].setting_types[1],
@@ -680,30 +728,25 @@ initialize_treeview (NMConnectionList *self)
 static void
 add_connection_buttons (NMConnectionList *self)
 {
-       GtkWidget *button, *box;
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
+       GtkWidget *button;
        GtkTreeSelection *selection;
 
-       selection = gtk_tree_view_get_selection (self->connection_list);
-
-       /* Add */
-       button = GTK_WIDGET (gtk_builder_get_object (self->gui, "connection_add"));
-       g_signal_connect (button, "clicked", G_CALLBACK (add_clicked), self);
-
-       box = GTK_WIDGET (gtk_builder_get_object (self->gui, "connection_button_box"));
+       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",
-                                      self->client,
+                                      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 (box), button, TRUE, TRUE, 0);
+       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 (self->connection_list, "row-activated", G_CALLBACK (connection_double_clicked_cb), 
button);
+       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);
 
@@ -712,17 +755,17 @@ add_connection_buttons (NMConnectionList *self)
                                       _("Delete the selected connection"),
                                       _("Authenticate to delete the selected connection"),
                                       "edit-delete-symbolic",
-                                      self->client,
+                                      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 (box), button, TRUE, TRUE, 0);
+       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 (box);
+       gtk_widget_show_all (priv->connection_button_box);
 }
 
 static void
@@ -731,13 +774,14 @@ connection_removed (NMClient *client,
                     gpointer user_data)
 {
        NMConnectionList *self = NM_CONNECTION_LIST (user_data);
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
        GtkTreeIter iter, parent_iter;
 
        if (get_iter_for_connection (self, connection, &iter)) {
-               gtk_tree_model_iter_parent (self->model, &parent_iter, &iter);
-               gtk_tree_store_remove (GTK_TREE_STORE (self->model), &iter);
+               gtk_tree_model_iter_parent (priv->model, &parent_iter, &iter);
+               gtk_tree_store_remove (GTK_TREE_STORE (priv->model), &iter);
        }
-       gtk_tree_model_filter_refilter (self->filter);
+       gtk_tree_model_filter_refilter (priv->filter);
 }
 
 static void
@@ -760,6 +804,7 @@ get_parent_iter_for_connection (NMConnectionList *list,
                                 NMRemoteConnection *connection,
                                 GtkTreeIter *iter)
 {
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
        NMSettingConnection *s_con;
        const char *str_type;
        GType type, row_type0, row_type1, row_type2;
@@ -774,16 +819,16 @@ get_parent_iter_for_connection (NMConnectionList *list,
 
        type = nm_setting_lookup_type (str_type);
 
-       if (gtk_tree_model_get_iter_first (list->model, iter)) {
+       if (gtk_tree_model_get_iter_first (priv->model, iter)) {
                do {
-                       gtk_tree_model_get (list->model, iter,
+                       gtk_tree_model_get (priv->model, iter,
                                            COL_GTYPE0, &row_type0,
                                            COL_GTYPE1, &row_type1,
                                            COL_GTYPE2, &row_type2,
                                            -1);
                        if (row_type0 == type || row_type1 == type || row_type2 == type)
                                return TRUE;
-               } while (gtk_tree_model_iter_next (list->model, iter));
+               } while (gtk_tree_model_iter_next (priv->model, iter));
        }
 
        return FALSE;
@@ -795,6 +840,7 @@ connection_added (NMClient *client,
                   gpointer user_data)
 {
        NMConnectionList *self = NM_CONNECTION_LIST (user_data);
+       NMConnectionListPrivate *priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
        GtkTreeIter parent_iter, iter;
        NMSettingConnection *s_con;
        char *last_used, *id;
@@ -809,8 +855,8 @@ connection_added (NMClient *client,
 
        id = g_markup_escape_text (nm_setting_connection_get_id (s_con), -1);
 
-       gtk_tree_store_append (GTK_TREE_STORE (self->model), &iter, &parent_iter);
-       gtk_tree_store_set (GTK_TREE_STORE (self->model), &iter,
+       gtk_tree_store_append (GTK_TREE_STORE (priv->model), &iter, &parent_iter);
+       gtk_tree_store_set (GTK_TREE_STORE (priv->model), &iter,
                            COL_ID, id,
                            COL_LAST_USED, last_used,
                            COL_TIMESTAMP, nm_setting_connection_get_timestamp (s_con),
@@ -820,81 +866,66 @@ connection_added (NMClient *client,
        g_free (id);
        g_free (last_used);
 
-       if (self->displayed_type) {
+       if (priv->displayed_type) {
                GType added_type0, added_type1, added_type2;
 
-               gtk_tree_model_get (self->model, &parent_iter,
+               gtk_tree_model_get (priv->model, &parent_iter,
                                    COL_GTYPE0, &added_type0,
                                    COL_GTYPE1, &added_type1,
                                    COL_GTYPE2, &added_type2,
                                    -1);
-               if (   added_type0 != self->displayed_type
-                   && added_type1 != self->displayed_type
-                   && added_type2 != self->displayed_type)
+               if (   added_type0 != priv->displayed_type
+                   && added_type1 != priv->displayed_type
+                   && added_type2 != priv->displayed_type)
                        expand = FALSE;
        }
 
        if (expand) {
                GtkTreePath *path, *filtered_path;
 
-               path = gtk_tree_model_get_path (self->model, &parent_iter);
-               filtered_path = gtk_tree_model_filter_convert_child_path_to_path (self->filter, path);
-               gtk_tree_view_expand_row (self->connection_list, filtered_path, FALSE);
+               path = gtk_tree_model_get_path (priv->model, &parent_iter);
+               filtered_path = gtk_tree_model_filter_convert_child_path_to_path (priv->filter, path);
+               gtk_tree_view_expand_row (priv->connection_list, filtered_path, FALSE);
                gtk_tree_path_free (filtered_path);
                gtk_tree_path_free (path);
        }
 
        g_signal_connect (client, NM_CLIENT_CONNECTION_REMOVED, G_CALLBACK (connection_removed), self);
        g_signal_connect (connection, NM_CONNECTION_CHANGED, G_CALLBACK (connection_changed), self);
-       gtk_tree_model_filter_refilter (self->filter);
+       gtk_tree_model_filter_refilter (priv->filter);
 }
 
 NMConnectionList *
 nm_connection_list_new (void)
 {
        NMConnectionList *list;
+       NMConnectionListPrivate *priv;
        GError *error = NULL;
-       const char *objects[] = { "NMConnectionList", NULL };
 
        list = g_object_new (NM_TYPE_CONNECTION_LIST, NULL);
        if (!list)
                return NULL;
 
-       /* load GUI */
-       list->gui = gtk_builder_new ();
-
-       if (!gtk_builder_add_objects_from_resource (list->gui,
-                                                   
"/org/freedesktop/network-manager-applet/nm-connection-editor.ui",
-                                                   (char **) objects,
-                                                   &error)) {
-               g_warning ("Couldn't load builder resource: %s", error->message);
-               g_error_free (error);
-               goto error;
-       }
+       priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
        gtk_window_set_default_icon_name ("preferences-system-network");
 
-       list->client = nm_client_new (NULL, &error);
-       if (!list->client) {
+       priv->client = nm_client_new (NULL, &error);
+       if (!priv->client) {
                g_warning ("Couldn't construct the client instance: %s", error->message);
                g_error_free (error);
                goto error;
        }
-       g_signal_connect (list->client,
+       g_signal_connect (priv->client,
                          NM_CLIENT_CONNECTION_ADDED,
                          G_CALLBACK (connection_added),
                          list);
 
-       list->connection_list = GTK_TREE_VIEW (gtk_builder_get_object (list->gui, "connection_list"));
        initialize_treeview (list);
        add_connection_buttons (list);
 
-       list->dialog = GTK_WIDGET (gtk_builder_get_object (list->gui, "NMConnectionList"));
-       if (!list->dialog)
-               goto error;
        if (nm_ce_keep_above)
-               gtk_window_set_keep_above (GTK_WINDOW (list->dialog), TRUE);
-       g_signal_connect (G_OBJECT (list->dialog), "response", G_CALLBACK (dialog_response_cb), list);
+               gtk_window_set_keep_above (GTK_WINDOW (list), TRUE);
 
        return list;
 
@@ -906,21 +937,26 @@ error:
 void
 nm_connection_list_set_type (NMConnectionList *self, GType ctype)
 {
+       NMConnectionListPrivate *priv;
+
        g_return_if_fail (NM_IS_CONNECTION_LIST (self));
+       priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
 
-       self->displayed_type = ctype;
+       priv->displayed_type = ctype;
 }
 
 void
-nm_connection_list_create (NMConnectionList *self,
+nm_connection_list_create (NMConnectionList *list,
                            GType ctype,
                            const char *detail,
                            const char *import_filename)
 {
+       NMConnectionListPrivate *priv;
        ConnectionTypeData *types;
        int i;
 
-       g_return_if_fail (NM_IS_CONNECTION_LIST (self));
+       g_return_if_fail (NM_IS_CONNECTION_LIST (list));
+       priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
        types = get_connection_type_list ();
        for (i = 0; types[i].name; i++) {
@@ -946,25 +982,27 @@ nm_connection_list_create (NMConnectionList *self,
                        if (!connection)
                                return;
                }
-               new_connection_of_type (GTK_WINDOW (self->dialog),
+               new_connection_of_type (GTK_WINDOW (list),
                                        detail,
                                        NULL,
                                        connection,
-                                       self->client,
+                                       priv->client,
                                        types[i].new_connection_func,
                                        really_add_connection,
-                                       self);
+                                       list);
        }
 }
 
 void
 nm_connection_list_edit (NMConnectionList *self, const gchar *uuid)
 {
+       NMConnectionListPrivate *priv;
        NMConnection *connection;
 
        g_return_if_fail (NM_IS_CONNECTION_LIST (self));
+       priv = NM_CONNECTION_LIST_GET_PRIVATE (self);
 
-       connection = (NMConnection *) nm_client_get_connection_by_uuid (self->client, uuid);
+       connection = (NMConnection *) nm_client_get_connection_by_uuid (priv->client, uuid);
        if (!connection) {
                nm_connection_editor_error (NULL,
                                            _("Error editing connection"),
@@ -975,48 +1013,40 @@ nm_connection_list_edit (NMConnectionList *self, const gchar *uuid)
        edit_connection (self, connection);
 }
 
-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);
-}
-
-static void
-list_close_cb (GtkDialog *dialog, gpointer user_data)
-{
-       gtk_dialog_response (dialog, GTK_RESPONSE_CLOSE);
-}
-
 void
 nm_connection_list_present (NMConnectionList *list)
 {
+       NMConnectionListPrivate *priv;
        const GPtrArray *all_cons;
        GtkTreePath *path;
        GtkTreeIter iter;
        int i;
 
        g_return_if_fail (NM_IS_CONNECTION_LIST (list));
+       priv = NM_CONNECTION_LIST_GET_PRIVATE (list);
 
-       if (!list->populated) {
+       if (!priv->populated) {
                /* Fill the treeview initially */
-               all_cons = nm_client_get_connections (list->client);
+               all_cons = nm_client_get_connections (priv->client);
                for (i = 0; i < all_cons->len; i++)
-                       connection_added (list->client, all_cons->pdata[i], list);
-               if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (list->sortable), &iter)) {
-                       path = gtk_tree_model_get_path (GTK_TREE_MODEL (list->sortable), &iter);
-                       gtk_tree_view_scroll_to_cell (list->connection_list,
+                       connection_added (priv->client, all_cons->pdata[i], list);
+               if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->sortable), &iter)) {
+                       path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->sortable), &iter);
+                       gtk_tree_view_scroll_to_cell (priv->connection_list,
                                                      path, NULL,
                                                      FALSE, 0, 0);
                        gtk_tree_path_free (path);
                }
 
-               g_signal_connect (G_OBJECT (list->dialog), "response",
+#if 0
+               g_signal_connect (G_OBJECT (priv->dialog), "response",
                                      G_CALLBACK (list_response_cb), list);
-               g_signal_connect (G_OBJECT (list->dialog), "close",
+               g_signal_connect (G_OBJECT (priv->dialog), "close",
                                      G_CALLBACK (list_close_cb), list);
-               list->populated = TRUE;
+#endif
+               priv->populated = TRUE;
        }
 
-       gtk_window_present (GTK_WINDOW (list->dialog));
+       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 1db3ec8..9ffe1c7 100644
--- a/src/connection-editor/nm-connection-list.h
+++ b/src/connection-editor/nm-connection-list.h
@@ -33,26 +33,15 @@
 #define NM_IS_CONNECTION_LIST(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CONNECTION_LIST))
 #define NM_CONNECTION_LIST(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CONNECTION_LIST, 
NMConnectionList))
 
-typedef struct {
-       GObject parent;
-
-       /* private data */
-       GtkTreeView *connection_list;
-       GtkTreeModel *model;
-       GtkTreeModelFilter *filter;
-       GtkTreeSortable *sortable;
-       GType displayed_type;
-
-       NMClient *client;
+typedef struct _NMConnectionListPrivate NMConnectionListPrivate;
 
-       GtkBuilder *gui;
-       GtkWidget *dialog;
-
-       gboolean populated;
+typedef struct {
+       GtkDialog parent;
+       NMConnectionListPrivate *priv;
 } NMConnectionList;
 
 typedef struct {
-       GObjectClass parent_class;
+       GtkDialogClass 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
new file mode 100644
index 0000000..e345254
--- /dev/null
+++ b/src/connection-editor/nm-connection-list.ui
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.20.0 -->
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <template class="NMConnectionList" parent="GtkDialog">
+    <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="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="closebutton1">
+                <property name="label" translatable="yes">_Close</property>
+                <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>
+              </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="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHBox" id="hbox2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">6</property>
+            <property name="spacing">6</property>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow1">
+                <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>
+              </object>
+              <packing>
+                <property name="expand">True</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVButtonBox" id="connection_button_box">
+                <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>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</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]