[gnome-software: 38/110] gs-update-list: Subclass GtkWidget




commit ea00a6543f28dba406c5d29998e51c48ec3f7d21
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Mon Aug 23 10:41:49 2021 -0300

    gs-update-list: Subclass GtkWidget
    
    Same case of the previous commit. This requres adding a new public
    function to remove all listbox widgets.

 src/gs-update-dialog.c  | 12 ++++-------
 src/gs-update-dialog.ui |  1 -
 src/gs-update-list.c    | 57 ++++++++++++++++++++++++++++++++++++++++++++-----
 src/gs-update-list.h    |  5 +++--
 4 files changed, 59 insertions(+), 16 deletions(-)
---
diff --git a/src/gs-update-dialog.c b/src/gs-update-dialog.c
index 24af1ae14..45a2ed3b1 100644
--- a/src/gs-update-dialog.c
+++ b/src/gs-update-dialog.c
@@ -56,14 +56,10 @@ deck_child_transition_cb (AdwDeck *deck, GParamSpec *pspec, GsUpdateDialog *dial
 }
 
 static void
-installed_updates_row_activated_cb (GtkListBox *list_box,
-                                   GtkListBoxRow *row,
+installed_updates_row_activated_cb (GsUpdateList *update_list,
+                                   GsApp *app,
                                    GsUpdateDialog *dialog)
 {
-       GsApp *app;
-
-       app = gs_app_row_get_app (GS_APP_ROW (row));
-
        gs_update_dialog_show_update_details (dialog, app);
 }
 
@@ -126,7 +122,7 @@ get_installed_updates_cb (GsPluginLoader *plugin_loader,
 
        gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "installed-updates-list");
 
-       gs_widget_remove_all (dialog->list_box_installed_updates, (GsRemoveFunc) gtk_list_box_remove);
+       gs_update_list_remove_all (GS_UPDATE_LIST (dialog->list_box_installed_updates));
        for (i = 0; i < gs_app_list_length (list); i++) {
                gs_update_list_add_app (GS_UPDATE_LIST (dialog->list_box_installed_updates),
                                        gs_app_list_index (list, i));
@@ -338,7 +334,7 @@ gs_update_dialog_init (GsUpdateDialog *dialog)
 
        dialog->cancellable = g_cancellable_new ();
 
-       g_signal_connect (GTK_LIST_BOX (dialog->list_box_installed_updates), "row-activated",
+       g_signal_connect (dialog->list_box_installed_updates, "show-update",
                          G_CALLBACK (installed_updates_row_activated_cb), dialog);
 
        g_signal_connect_after (dialog, "show", G_CALLBACK (unset_focus), NULL);
diff --git a/src/gs-update-dialog.ui b/src/gs-update-dialog.ui
index 995cb507d..a5ad8badf 100644
--- a/src/gs-update-dialog.ui
+++ b/src/gs-update-dialog.ui
@@ -82,7 +82,6 @@
                         <child>
                           <object class="GsUpdateList" id="list_box_installed_updates">
                             <property name="visible">True</property>
-                            <property name="selection_mode">none</property>
                             <style>
                               <class name="content" />
                             </style>
diff --git a/src/gs-update-list.c b/src/gs-update-list.c
index c0d319da1..ac0a03df6 100644
--- a/src/gs-update-list.c
+++ b/src/gs-update-list.c
@@ -21,9 +21,26 @@ typedef struct
        GtkSizeGroup            *sizegroup_image;
        GtkSizeGroup            *sizegroup_name;
        GtkSizeGroup            *sizegroup_desc;
+       GtkListBox              *listbox;
 } GsUpdateListPrivate;
 
-G_DEFINE_TYPE_WITH_PRIVATE (GsUpdateList, gs_update_list, GTK_TYPE_LIST_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (GsUpdateList, gs_update_list, GTK_TYPE_WIDGET)
+
+enum {
+       SIGNAL_SHOW_UPDATE,
+};
+
+static guint signals [SIGNAL_SHOW_UPDATE + 1] = { 0 };
+
+static void
+installed_updates_row_activated_cb (GtkListBox    *list_box,
+                                    GtkListBoxRow *row,
+                                    GsUpdateList  *self)
+{
+       GsApp *app = gs_app_row_get_app (GS_APP_ROW (row));
+
+       g_signal_emit (self, signals[SIGNAL_SHOW_UPDATE], 0, app);
+}
 
 static void
 gs_update_list_app_state_notify_cb (GsApp *app, GParamSpec *pspec, gpointer user_data)
@@ -44,7 +61,7 @@ gs_update_list_add_app (GsUpdateList *update_list, GsApp *app)
        gs_app_row_set_show_description (GS_APP_ROW (app_row), FALSE);
        gs_app_row_set_show_update (GS_APP_ROW (app_row), FALSE);
        gs_app_row_set_show_buttons (GS_APP_ROW (app_row), FALSE);
-       gtk_list_box_insert (GTK_LIST_BOX (update_list), app_row, -1);
+       gtk_list_box_insert (priv->listbox, app_row, -1);
        gs_app_row_set_size_groups (GS_APP_ROW (app_row),
                                    priv->sizegroup_image,
                                    priv->sizegroup_name,
@@ -73,6 +90,11 @@ gs_update_list_dispose (GObject *object)
        GsUpdateList *update_list = GS_UPDATE_LIST (object);
        GsUpdateListPrivate *priv = gs_update_list_get_instance_private (update_list);
 
+       if (priv->listbox != NULL) {
+               gtk_widget_unparent (GTK_WIDGET (priv->listbox));
+               priv->listbox = NULL;
+       }
+
        g_clear_object (&priv->sizegroup_image);
        g_clear_object (&priv->sizegroup_name);
        g_clear_object (&priv->sizegroup_desc);
@@ -88,16 +110,30 @@ gs_update_list_init (GsUpdateList *update_list)
        priv->sizegroup_name = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
        priv->sizegroup_desc = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
 
-       gtk_list_box_set_sort_func (GTK_LIST_BOX (update_list),
-                                   list_sort_func,
-                                   update_list, NULL);
+       priv->listbox = GTK_LIST_BOX (gtk_list_box_new ());
+       gtk_list_box_set_selection_mode (priv->listbox, GTK_SELECTION_NONE);
+       gtk_widget_set_parent (GTK_WIDGET (priv->listbox), GTK_WIDGET (update_list));
+       gtk_list_box_set_sort_func (priv->listbox, list_sort_func, update_list, NULL);
+
+       g_signal_connect (priv->listbox, "row-activated",
+                         G_CALLBACK (installed_updates_row_activated_cb), update_list);
 }
 
 static void
 gs_update_list_class_init (GsUpdateListClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
        object_class->dispose = gs_update_list_dispose;
+
+       signals [SIGNAL_SHOW_UPDATE] =
+               g_signal_new ("show-update",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             0, NULL, NULL, g_cclosure_marshal_VOID__OBJECT,
+                             G_TYPE_NONE, 1, GS_TYPE_APP);
+
+       gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
 }
 
 GtkWidget *
@@ -107,3 +143,14 @@ gs_update_list_new (void)
        update_list = g_object_new (GS_TYPE_UPDATE_LIST, NULL);
        return GTK_WIDGET (update_list);
 }
+
+void
+gs_update_list_remove_all (GsUpdateList *update_list)
+{
+       GsUpdateListPrivate *priv;
+
+       g_return_if_fail (GS_IS_UPDATE_LIST (update_list));
+
+       priv = gs_update_list_get_instance_private (update_list);
+       gs_widget_remove_all (GTK_WIDGET (priv->listbox), (GsRemoveFunc) gtk_list_box_remove);
+}
diff --git a/src/gs-update-list.h b/src/gs-update-list.h
index 731b41224..eda8c4912 100644
--- a/src/gs-update-list.h
+++ b/src/gs-update-list.h
@@ -17,14 +17,15 @@ G_BEGIN_DECLS
 
 #define GS_TYPE_UPDATE_LIST (gs_update_list_get_type ())
 
-G_DECLARE_DERIVABLE_TYPE (GsUpdateList, gs_update_list, GS, UPDATE_LIST, GtkListBox)
+G_DECLARE_DERIVABLE_TYPE (GsUpdateList, gs_update_list, GS, UPDATE_LIST, GtkWidget)
 
 struct _GsUpdateListClass
 {
-       GtkListBoxClass          parent_class;
+       GtkWidgetClass           parent_class;
 };
 
 GtkWidget      *gs_update_list_new                     (void);
+void            gs_update_list_remove_all              (GsUpdateList   *update_list);
 void            gs_update_list_add_app                 (GsUpdateList   *update_list,
                                                         GsApp          *app);
 


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