[gnome-software: 2/7] repos-section: Make it a HdyPreferencesGroup




commit 9c6f75cb7494787932f902928fed406681c9a458
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Jul 30 09:49:55 2021 +0200

    repos-section: Make it a HdyPreferencesGroup
    
    This makes the code simpler.

 src/gs-repos-dialog.c  | 20 ++++++++----------
 src/gs-repos-section.c | 55 +++++++++-----------------------------------------
 src/gs-repos-section.h |  6 +++---
 3 files changed, 20 insertions(+), 61 deletions(-)
---
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index 2a74bfb29..4571baa38 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -349,11 +349,9 @@ add_repo (GsReposDialog *dialog,
                origin_ui = g_strdup (gs_app_get_management_plugin (repo));
        section = g_hash_table_lookup (dialog->sections, origin_ui);
        if (section == NULL) {
-               section = gs_repos_section_new (dialog->plugin_loader, origin_ui);
-               g_object_set (G_OBJECT (section),
-                             "halign", GTK_ALIGN_FILL,
-                             "hexpand", TRUE,
-                             NULL);
+               section = gs_repos_section_new (dialog->plugin_loader);
+               hdy_preferences_group_set_title (HDY_PREFERENCES_GROUP (section),
+                                                origin_ui);
                g_signal_connect_object (section, "remove-clicked",
                                         G_CALLBACK (repo_section_remove_clicked_cb), dialog, 0);
                g_signal_connect_object (section, "switch-clicked",
@@ -384,8 +382,8 @@ repos_dialog_compare_sections_cb (gconstpointer aa,
        if (res != 0)
                return res;
 
-       title_sort_key_a = gs_utils_sort_key (gs_repos_section_get_title (section_a));
-       title_sort_key_b = gs_utils_sort_key (gs_repos_section_get_title (section_b));
+       title_sort_key_a = gs_utils_sort_key (hdy_preferences_group_get_title (HDY_PREFERENCES_GROUP 
(section_a)));
+       title_sort_key_b = gs_utils_sort_key (hdy_preferences_group_get_title (HDY_PREFERENCES_GROUP 
(section_b)));
 
        return g_strcmp0 (title_sort_key_a, title_sort_key_b);
 }
@@ -459,11 +457,9 @@ get_sources_cb (GsPluginLoader *plugin_loader,
                g_autofree gchar *anchor = NULL;
                g_autofree gchar *hint = NULL;
 
-               section = GS_REPOS_SECTION (gs_repos_section_new (dialog->plugin_loader, _("Fedora Third 
Party Repositories")));
-               g_object_set (G_OBJECT (section),
-                             "halign", GTK_ALIGN_FILL,
-                             "hexpand", TRUE,
-                             NULL);
+               section = GS_REPOS_SECTION (gs_repos_section_new (dialog->plugin_loader));
+               hdy_preferences_group_set_title (HDY_PREFERENCES_GROUP (section),
+                                                _("Fedora Third Party Repositories"));
                gs_repos_section_set_sort_key (section, "900");
                g_signal_connect_object (section, "switch-clicked",
                                         G_CALLBACK (repo_section_switch_clicked_cb), dialog, 0);
diff --git a/src/gs-repos-section.c b/src/gs-repos-section.c
index 651024e8f..3bf59ad78 100644
--- a/src/gs-repos-section.c
+++ b/src/gs-repos-section.c
@@ -15,14 +15,14 @@
 
 struct _GsReposSection
 {
-       GtkBox           parent_instance;
-       GtkWidget       *title;
-       GtkListBox      *list;
-       GsPluginLoader  *plugin_loader;
-       gchar           *sort_key;
+       HdyPreferencesGroup      parent_instance;
+       GtkWidget               *title;
+       GtkListBox              *list;
+       GsPluginLoader          *plugin_loader;
+       gchar                   *sort_key;
 };
 
-G_DEFINE_TYPE (GsReposSection, gs_repos_section, GTK_TYPE_BOX)
+G_DEFINE_TYPE (GsReposSection, gs_repos_section, HDY_TYPE_PREFERENCES_GROUP)
 
 enum {
        SIGNAL_REMOVE_CLICKED,
@@ -113,34 +113,10 @@ static void
 gs_repos_section_init (GsReposSection *self)
 {
        GtkStyleContext *style_context;
-       PangoAttrList *attrs;
-
-       attrs = pango_attr_list_new ();
-       pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
-
-       self->title = gtk_label_new ("");
-       g_object_set (G_OBJECT (self->title),
-                     "visible", TRUE,
-                     "halign", GTK_ALIGN_START,
-                     "valign", GTK_ALIGN_CENTER,
-                     "xalign", 0.0,
-                     "yalign", 0.5,
-                     "attributes", attrs,
-                     NULL);
-
-       pango_attr_list_unref (attrs);
-
-       gtk_box_pack_start (GTK_BOX (self), self->title, FALSE, FALSE, 0);
 
        self->list = GTK_LIST_BOX (gtk_list_box_new ());
        g_object_set (G_OBJECT (self->list),
                      "visible", TRUE,
-                     "halign", GTK_ALIGN_FILL,
-                     "hexpand", TRUE,
-                     "valign", GTK_ALIGN_CENTER,
-                     "vexpand", TRUE,
-                     "margin-top", 4,
-                     "margin-bottom", 4,
                      "selection-mode", GTK_SELECTION_NONE,
                      NULL);
        gtk_list_box_set_sort_func (self->list, _list_sort_func, self, NULL);
@@ -148,26 +124,21 @@ gs_repos_section_init (GsReposSection *self)
        style_context = gtk_widget_get_style_context (GTK_WIDGET (self->list));
        gtk_style_context_add_class (style_context, "content");
 
-       gtk_box_pack_start (GTK_BOX (self), GTK_WIDGET (self->list), TRUE, TRUE, 0);
+       gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET (self->list));
 
        g_signal_connect (self->list, "row-activated",
                          G_CALLBACK (gs_repos_section_row_activated_cb), self);
 }
 
 GtkWidget *
-gs_repos_section_new (GsPluginLoader *plugin_loader,
-                     const gchar *title)
+gs_repos_section_new (GsPluginLoader *plugin_loader)
 {
        GsReposSection *self;
 
        g_return_val_if_fail (GS_IS_PLUGIN_LOADER (plugin_loader), NULL);
 
-       self = g_object_new (GS_TYPE_REPOS_SECTION,
-                            "orientation", GTK_ORIENTATION_VERTICAL,
-                            "spacing", 8,
-                            NULL);
+       self = g_object_new (GS_TYPE_REPOS_SECTION, NULL);
 
-       gtk_label_set_text (GTK_LABEL (self->title), title);
        self->plugin_loader = g_object_ref (plugin_loader);
 
        return GTK_WIDGET (self);
@@ -199,14 +170,6 @@ gs_repos_section_add_repo (GsReposSection *self,
        gtk_widget_show (row);
 }
 
-const gchar *
-gs_repos_section_get_title (GsReposSection *self)
-{
-       g_return_val_if_fail (GS_IS_REPOS_SECTION (self), NULL);
-
-       return gtk_label_get_text (GTK_LABEL (self->title));
-}
-
 const gchar *
 gs_repos_section_get_sort_key (GsReposSection *self)
 {
diff --git a/src/gs-repos-section.h b/src/gs-repos-section.h
index 6a8c43004..6e29769c5 100644
--- a/src/gs-repos-section.h
+++ b/src/gs-repos-section.h
@@ -9,6 +9,7 @@
 #pragma once
 
 #include <gtk/gtk.h>
+#include <handy.h>
 
 #include "gnome-software-private.h"
 #include "gs-app.h"
@@ -17,10 +18,9 @@ G_BEGIN_DECLS
 
 #define GS_TYPE_REPOS_SECTION (gs_repos_section_get_type ())
 
-G_DECLARE_FINAL_TYPE (GsReposSection, gs_repos_section, GS, REPOS_SECTION, GtkBox)
+G_DECLARE_FINAL_TYPE (GsReposSection, gs_repos_section, GS, REPOS_SECTION, HdyPreferencesGroup)
 
-GtkWidget      *gs_repos_section_new                   (GsPluginLoader         *plugin_loader,
-                                                        const gchar            *title);
+GtkWidget      *gs_repos_section_new                   (GsPluginLoader         *plugin_loader);
 void            gs_repos_section_add_repo              (GsReposSection         *self,
                                                         GsApp                  *repo);
 const gchar    *gs_repos_section_get_title             (GsReposSection         *self);


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