[gnome-software/wip/jrocha/category-redesign: 3/4] Use a source label when needed in the category view



commit fcb913ebc8ab131c936c4f46843d6d7ea3c0fc16
Author: Joaquim Rocha <jrocha endlessm com>
Date:   Tue Aug 29 17:34:23 2017 +0200

    Use a source label when needed in the category view
    
    If two tiles in the category view represent the same app but coming from
    different sources, then we should add that distinction to the user.
    
    For that, this patch adds a new "origin label" to the popular tile
    that's used in the category view. This label is only visible if the
    mentioned distinction is needed (set to it).

 src/gs-category-page.c |    8 +++++++-
 src/gs-popular-tile.c  |   21 +++++++++++++++++++++
 src/gs-popular-tile.h  |    2 ++
 src/gs-popular-tile.ui |   17 +++++++++++++++++
 4 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/src/gs-category-page.c b/src/gs-category-page.c
index acab5a3..3298ed5 100644
--- a/src/gs-category-page.c
+++ b/src/gs-category-page.c
@@ -149,6 +149,10 @@ gs_category_page_get_apps_cb (GObject *source_object,
        for (i = 0; i < gs_app_list_length (list); i++) {
                app = gs_app_list_index (list, i);
                tile = gs_popular_tile_new (app);
+               if (!gs_app_has_quirk (app, AS_APP_QUIRK_PROVENANCE) ||
+                   gs_utils_list_has_app_fuzzy (list, app))
+                       gs_popular_tile_show_source (GS_POPULAR_TILE (tile), TRUE);
+
                g_signal_connect (tile, "clicked",
                                  G_CALLBACK (app_tile_clicked), self);
                gtk_container_add (GTK_CONTAINER (self->category_detail_box), tile);
@@ -337,7 +341,9 @@ gs_category_page_reload (GsPage *page)
                                         "category", self->subcategory,
                                         "failure-flags", GS_PLUGIN_FAILURE_FLAGS_USE_EVENTS,
                                         "refine-flags", GS_PLUGIN_REFINE_FLAGS_REQUIRE_ICON |
-                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING,
+                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_RATING |
+                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_ORIGIN_HOSTNAME |
+                                                        GS_PLUGIN_REFINE_FLAGS_REQUIRE_PROVENANCE,
                                         NULL);
        gs_plugin_loader_job_process_async (self->plugin_loader,
                                            plugin_job,
diff --git a/src/gs-popular-tile.c b/src/gs-popular-tile.c
index 2b6b30b..c184b6f 100644
--- a/src/gs-popular-tile.c
+++ b/src/gs-popular-tile.c
@@ -38,6 +38,7 @@ struct _GsPopularTile
        GtkWidget       *eventbox;
        GtkWidget       *stack;
        GtkWidget       *stars;
+       GtkWidget       *label_origin;
 };
 
 G_DEFINE_TYPE (GsPopularTile, gs_popular_tile, GS_TYPE_APP_TILE)
@@ -179,6 +180,7 @@ gs_popular_tile_class_init (GsPopularTileClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsPopularTile, eventbox);
        gtk_widget_class_bind_template_child (widget_class, GsPopularTile, stack);
        gtk_widget_class_bind_template_child (widget_class, GsPopularTile, stars);
+       gtk_widget_class_bind_template_child (widget_class, GsPopularTile, label_origin);
 }
 
 GtkWidget *
@@ -193,4 +195,23 @@ gs_popular_tile_new (GsApp *app)
        return GTK_WIDGET (tile);
 }
 
+void
+gs_popular_tile_show_source (GsPopularTile *tile, gboolean show_source)
+{
+       if (show_source) {
+               const gchar *hostname = gs_app_get_origin_hostname (tile->app);
+               if (hostname != NULL) {
+                       /* TRANSLATORS: this refers to where the app came from */
+                       g_autofree gchar *source_text = g_strdup_printf ("%s: %s", _("Source"),
+                                                                        hostname);
+                       gtk_label_set_label (GTK_LABEL (tile->label_origin), source_text);
+               } else {
+                       /* if the hostname is not valid then we hide the source */
+                       show_source = FALSE;
+               }
+       }
+
+       gtk_widget_set_visible (tile->label_origin, show_source);
+}
+
 /* vim: set noexpandtab: */
diff --git a/src/gs-popular-tile.h b/src/gs-popular-tile.h
index 3ed2566..433722a 100644
--- a/src/gs-popular-tile.h
+++ b/src/gs-popular-tile.h
@@ -31,6 +31,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (GsPopularTile, gs_popular_tile, GS, POPULAR_TILE, GsAppTile)
 
 GtkWidget      *gs_popular_tile_new                    (GsApp          *app);
+void            gs_popular_tile_show_source            (GsPopularTile  *tile,
+                                                        gboolean        show_source);
 
 G_END_DECLS
 
diff --git a/src/gs-popular-tile.ui b/src/gs-popular-tile.ui
index 2236467..0cd4a20 100644
--- a/src/gs-popular-tile.ui
+++ b/src/gs-popular-tile.ui
@@ -105,6 +105,23 @@
                         <property name="fill">True</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkLabel" id="label_origin">
+                        <property name="visible">False</property>
+                        <property name="xalign">0.5</property>
+                        <property name="yalign">1.0</property>
+                        <property name="halign">start</property>
+                        <property name="ellipsize">end</property>
+                        <style>
+                          <class name="app-row-origin-text"/>
+                          <class name="dim-label"/>
+                        </style>
+                      </object>
+                      <packing>
+                        <property name="expand">True</property>
+                        <property name="fill">True</property>
+                      </packing>
+                    </child>
                   </object>
                 </child>
               </object>


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