[gnome-software/1166-repository-dialog-design-updates] SortKey for sections & changed way of switching states



commit 2b90cdd471ebeff94e82541f619f54c986a8a0bd
Author: Milan Crha <mcrha redhat com>
Date:   Tue Jul 13 12:58:20 2021 +0200

    SortKey for sections & changed way of switching states

 plugins/flatpak/gs-flatpak-utils.c        |  1 +
 plugins/fwupd/gs-plugin-fwupd.c           |  1 +
 plugins/packagekit/gs-plugin-packagekit.c |  1 +
 plugins/rpm-ostree/gs-plugin-rpm-ostree.c |  1 +
 src/gs-repo-row.c                         | 16 ++++++++--------
 src/gs-repos-dialog.c                     | 24 ++++++++++++++----------
 src/gs-repos-section.c                    | 12 ++++++------
 src/gs-repos-section.h                    |  2 +-
 8 files changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/plugins/flatpak/gs-flatpak-utils.c b/plugins/flatpak/gs-flatpak-utils.c
index d57982dc5..f77b97f82 100644
--- a/plugins/flatpak/gs-flatpak-utils.c
+++ b/plugins/flatpak/gs-flatpak-utils.c
@@ -80,6 +80,7 @@ gs_flatpak_app_new_from_remote (FlatpakRemote *xremote,
                         flatpak_remote_get_name (xremote));
        gs_app_set_size_download (app, GS_APP_SIZE_UNKNOWABLE);
 
+       gs_app_set_metadata (app, "GnomeSoftware::SortKey", "100");
        gs_app_set_metadata (app, "GnomeSoftware::InstallationKind",
                is_user ? _("User Installation") : _("System Installation"));
 
diff --git a/plugins/fwupd/gs-plugin-fwupd.c b/plugins/fwupd/gs-plugin-fwupd.c
index 1e90c592c..0278ddc6e 100644
--- a/plugins/fwupd/gs-plugin-fwupd.c
+++ b/plugins/fwupd/gs-plugin-fwupd.c
@@ -1191,6 +1191,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
                                     fwupd_remote_get_id (remote));
                gs_app_set_management_plugin (app, "fwupd");
                gs_app_set_metadata (app, "GnomeSoftware::PackagingFormat", "fwupd");
+               gs_app_set_metadata (app, "GnomeSoftware::SortKey", "800");
                gs_app_set_origin_ui (app, _("Firmware"));
                gs_app_list_add (list, app);
        }
diff --git a/plugins/packagekit/gs-plugin-packagekit.c b/plugins/packagekit/gs-plugin-packagekit.c
index e476cb919..0258b7b4d 100644
--- a/plugins/packagekit/gs-plugin-packagekit.c
+++ b/plugins/packagekit/gs-plugin-packagekit.c
@@ -297,6 +297,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
                                    GS_APP_QUALITY_LOWEST,
                                    pk_repo_detail_get_description (rd));
                gs_plugin_packagekit_set_packaging_format (plugin, app);
+               gs_app_set_metadata (app, "GnomeSoftware::SortKey", "300");
                gs_app_set_origin_ui (app, _("Packages"));
                gs_app_list_add (list, app);
                g_hash_table_insert (hash,
diff --git a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
index 869615183..0984fedcb 100644
--- a/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
+++ b/plugins/rpm-ostree/gs-plugin-rpm-ostree.c
@@ -2148,6 +2148,7 @@ gs_plugin_add_sources (GsPlugin *plugin,
                gs_app_set_name (app, GS_APP_QUALITY_LOWEST, description);
                gs_app_set_summary (app, GS_APP_QUALITY_LOWEST, description);
 
+               gs_app_set_metadata (app, "GnomeSoftware::SortKey", "200");
                gs_app_set_origin_ui (app, _("Operating System (RPM-OStree)"));
 
                gs_app_list_add (list, app);
diff --git a/src/gs-repo-row.c b/src/gs-repo-row.c
index b534695f2..67927e623 100644
--- a/src/gs-repo-row.c
+++ b/src/gs-repo-row.c
@@ -39,7 +39,7 @@ refresh_ui (GsRepoRow *row)
 {
        GsRepoRowPrivate *priv = gs_repo_row_get_instance_private (row);
        gboolean active = FALSE;
-       gboolean sensitive = TRUE;
+       gboolean busy = priv->busy;
 
        if (priv->repo == NULL) {
                gtk_widget_set_sensitive (priv->disable_switch, FALSE);
@@ -60,11 +60,11 @@ refresh_ui (GsRepoRow *row)
                break;
        case GS_APP_STATE_INSTALLING:
                active = TRUE;
-               sensitive = FALSE;
+               busy = TRUE;
                break;
        case GS_APP_STATE_REMOVING:
                active = FALSE;
-               sensitive = FALSE;
+               busy = TRUE;
                break;
        case GS_APP_STATE_UNAVAILABLE:
                g_signal_handler_unblock (priv->disable_switch, priv->switch_handler_id);
@@ -75,12 +75,12 @@ refresh_ui (GsRepoRow *row)
        }
 
        /* disable main repo */
-       sensitive = sensitive &&
-                   !priv->busy &&
-                   !gs_app_has_quirk (priv->repo, GS_APP_QUIRK_PROVENANCE);
+       gtk_widget_set_sensitive (priv->disable_switch, !gs_app_has_quirk (priv->repo, 
GS_APP_QUIRK_PROVENANCE));
 
-       gtk_switch_set_active (GTK_SWITCH (priv->disable_switch), active);
-       gtk_widget_set_sensitive (priv->disable_switch, sensitive);
+       if (busy)
+               gtk_switch_set_state (GTK_SWITCH (priv->disable_switch), active);
+       else
+               gtk_switch_set_active (GTK_SWITCH (priv->disable_switch), active);
 
        g_signal_handler_unblock (priv->disable_switch, priv->switch_handler_id);
 }
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index eb44eb3a0..932c141d8 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -428,19 +428,23 @@ repos_dialog_compare_sections_cb (gconstpointer aa,
 {
        GsReposSection *section_a = (GsReposSection *) aa;
        GsReposSection *section_b = (GsReposSection *) bb;
-       g_autofree gchar *sort_key_a = NULL;
-       g_autofree gchar *sort_key_b = NULL;
+       const gchar *section_sort_key_a;
+       const gchar *section_sort_key_b;
+       g_autofree gchar *title_sort_key_a = NULL;
+       g_autofree gchar *title_sort_key_b = NULL;
+       gint res;
 
-       /* Place firmware updates at the bottom */
-       if (g_strcmp0 (gs_repos_section_get_packaging_format (section_a), "fwupd") == 0)
-               return 1;
-       if (g_strcmp0 (gs_repos_section_get_packaging_format (section_b), "fwupd") == 0)
-               return -1;
+       section_sort_key_a = gs_repos_section_get_sort_key (section_a);
+       section_sort_key_b = gs_repos_section_get_sort_key (section_b);
 
-       sort_key_a = gs_utils_sort_key (gs_repos_section_get_title (section_a));
-       sort_key_b = gs_utils_sort_key (gs_repos_section_get_title (section_b));
+       res = g_strcmp0 (section_sort_key_a, section_sort_key_b);
+       if (res != 0)
+               return res;
 
-       return g_strcmp0 (sort_key_a, sort_key_b);
+       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));
+
+       return g_strcmp0 (title_sort_key_a, title_sort_key_b);
 }
 
 static void
diff --git a/src/gs-repos-section.c b/src/gs-repos-section.c
index 685a7dc4a..175c1c21e 100644
--- a/src/gs-repos-section.c
+++ b/src/gs-repos-section.c
@@ -18,7 +18,7 @@ struct _GsReposSection
        GtkBox           parent_instance;
        GtkWidget       *title;
        GtkListBox      *list;
-       gchar           *packaging_format;
+       gchar           *sort_key;
 };
 
 G_DEFINE_TYPE (GsReposSection, gs_repos_section, GTK_TYPE_BOX)
@@ -62,7 +62,7 @@ gs_repos_section_finalize (GObject *object)
 {
        GsReposSection *self = GS_REPOS_SECTION (object);
 
-       g_free (self->packaging_format);
+       g_free (self->sort_key);
 
        G_OBJECT_CLASS (gs_repos_section_parent_class)->finalize (object);
 }
@@ -146,8 +146,8 @@ gs_repos_section_add_repo (GsReposSection *self,
        g_return_if_fail (GS_IS_REPOS_SECTION (self));
        g_return_if_fail (GS_IS_APP (repo));
 
-       if (!self->packaging_format)
-               self->packaging_format = gs_app_get_packaging_format (repo);
+       if (!self->sort_key)
+               self->sort_key = g_strdup (gs_app_get_metadata_item (repo, "GnomeSoftware::SortKey"));
 
        row = gs_repo_row_new ();
        gs_repo_row_set_repo (GS_REPO_ROW (row), repo);
@@ -168,9 +168,9 @@ gs_repos_section_get_title (GsReposSection *self)
 }
 
 const gchar *
-gs_repos_section_get_packaging_format (GsReposSection *self)
+gs_repos_section_get_sort_key (GsReposSection *self)
 {
        g_return_val_if_fail (GS_IS_REPOS_SECTION (self), NULL);
 
-       return self->packaging_format;
+       return self->sort_key;
 }
diff --git a/src/gs-repos-section.h b/src/gs-repos-section.h
index 2679017cd..522d90b90 100644
--- a/src/gs-repos-section.h
+++ b/src/gs-repos-section.h
@@ -22,6 +22,6 @@ GtkWidget     *gs_repos_section_new                   (const gchar            *title);
 void            gs_repos_section_add_repo              (GsReposSection         *self,
                                                         GsApp                  *repo);
 const gchar    *gs_repos_section_get_title             (GsReposSection         *self);
-const gchar    *gs_repos_section_get_packaging_format  (GsReposSection         *self);
+const gchar    *gs_repos_section_get_sort_key          (GsReposSection         *self);
 
 G_END_DECLS


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