[recipes] Indicate shared recipes in the 'my recipes' list



commit af0db4e085aea47ac474da447aa9530f198e8237
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jun 27 22:38:44 2017 -0400

    Indicate shared recipes in the 'my recipes' list
    
    This helps with finding recipes that should be shared.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783893

 src/gr-list-page.c    |   29 +++++++++++++++++++++++++++--
 src/gr-list-page.h    |    5 ++++-
 src/gr-recipe-tile.c  |   23 +++++++++++++++++++++++
 src/gr-recipe-tile.h  |    2 ++
 src/gr-recipe-tile.ui |   34 ++++++++++++++++++++++++++++------
 src/gr-window.c       |    4 ++--
 src/recipes.css       |    5 +++++
 7 files changed, 91 insertions(+), 11 deletions(-)
---
diff --git a/src/gr-list-page.c b/src/gr-list-page.c
index f59749c..807aef4 100644
--- a/src/gr-list-page.c
+++ b/src/gr-list-page.c
@@ -61,6 +61,8 @@ struct _GrListPage
         GtkWidget *heading;
         GtkWidget *diet_description;
 
+        gboolean show_shared;
+
         int count;
         GrRecipeSearch *search;
 };
@@ -150,6 +152,7 @@ search_hits_added (GrRecipeSearch *search,
                 GtkWidget *tile;
 
                 tile = gr_recipe_tile_new (recipe);
+                gr_recipe_tile_set_show_shared (GR_RECIPE_TILE (tile), page->show_shared);
                 gtk_widget_show (tile);
                 gtk_container_add (GTK_CONTAINER (page->flow_box), tile);
 
@@ -344,6 +347,8 @@ gr_list_page_populate_from_diet (GrListPage *self,
         char *tmp;
         g_autofree char *term = NULL;
 
+        self->show_shared = FALSE;
+
         clear_data (self);
         self->diet = diet;
 
@@ -367,8 +372,16 @@ gr_list_page_populate_from_diet (GrListPage *self,
 }
 
 void
+gr_list_page_set_show_shared (GrListPage *self,
+                              gboolean    show_shared)
+{
+        self->show_shared = show_shared;
+}
+
+void
 gr_list_page_populate_from_chef (GrListPage *self,
-                                 GrChef     *chef)
+                                 GrChef     *chef,
+                                 gboolean    show_shared)
 {
         GrRecipeStore *store;
         const char *id;
@@ -379,6 +392,8 @@ gr_list_page_populate_from_chef (GrListPage *self,
         char *tmp;
         g_autofree char *term = NULL;
 
+        self->show_shared = show_shared;
+
         g_object_ref (chef);
         clear_data (self);
         self->chef = chef;
@@ -436,6 +451,8 @@ gr_list_page_populate_from_season (GrListPage *self,
         char *tmp;
         g_autofree char *term = NULL;
 
+        self->show_shared = FALSE;
+
         tmp = g_strdup (season);
         clear_data (self);
         self->season = tmp;
@@ -459,6 +476,8 @@ gr_list_page_populate_from_season (GrListPage *self,
 void
 gr_list_page_populate_from_favorites (GrListPage *self)
 {
+        self->show_shared = FALSE;
+
         clear_data (self);
         self->favorites = TRUE;
 
@@ -478,6 +497,8 @@ gr_list_page_populate_from_favorites (GrListPage *self)
 void
 gr_list_page_populate_from_all (GrListPage *self)
 {
+        self->show_shared = FALSE;
+
         clear_data (self);
         self->all = TRUE;
 
@@ -503,6 +524,8 @@ gr_list_page_populate_from_new (GrListPage *self)
         g_autofree char *query = NULL;
         const char *terms[2];
 
+        self->show_shared = FALSE;
+
         clear_data (self);
         self->new = TRUE;
 
@@ -533,6 +556,8 @@ gr_list_page_populate_from_list (GrListPage *self,
         GList *l;
         gboolean empty;
 
+        self->show_shared = FALSE;
+
         store = gr_recipe_store_get ();
 
         recipes = g_list_copy_deep (recipes, (GCopyFunc)g_object_ref, NULL);
@@ -572,7 +597,7 @@ void
 gr_list_page_repopulate (GrListPage *page)
 {
         if (page->chef)
-                gr_list_page_populate_from_chef (page, page->chef);
+                gr_list_page_populate_from_chef (page, page->chef, page->show_shared);
         else if (page->diet)
                 gr_list_page_populate_from_diet (page, page->diet);
         else if (page->favorites)
diff --git a/src/gr-list-page.h b/src/gr-list-page.h
index b696eb0..e88164d 100644
--- a/src/gr-list-page.h
+++ b/src/gr-list-page.h
@@ -35,7 +35,8 @@ GtkWidget      *gr_list_page_new                     (void);
 void            gr_list_page_populate_from_diet      (GrListPage *self,
                                                       GrDiets     diet);
 void            gr_list_page_populate_from_chef      (GrListPage *self,
-                                                      GrChef     *chef);
+                                                      GrChef     *chef,
+                                                      gboolean    show_shared);
 void            gr_list_page_populate_from_season    (GrListPage *self,
                                                       const char *season);
 void            gr_list_page_populate_from_favorites (GrListPage *self);
@@ -45,6 +46,8 @@ void            gr_list_page_populate_from_all       (GrListPage *self);
 void            gr_list_page_populate_from_new       (GrListPage *self);
 void            gr_list_page_clear                   (GrListPage *self);
 void            gr_list_page_repopulate              (GrListPage *self);
+void            gr_list_page_set_show_shared         (GrListPage *self,
+                                                      gboolean    show_shared);
 
 typedef enum {
         SORT_BY_NAME,
diff --git a/src/gr-recipe-tile.c b/src/gr-recipe-tile.c
index d1c6654..10d5a13 100644
--- a/src/gr-recipe-tile.c
+++ b/src/gr-recipe-tile.c
@@ -43,8 +43,10 @@ struct _GrRecipeTile
         GtkWidget *author;
         GtkWidget *image;
         GtkWidget *box;
+        GtkWidget *shared_icon;
 
         GCancellable *cancellable;
+        gboolean show_shared;
 };
 
 G_DEFINE_TYPE (GrRecipeTile, gr_recipe_tile, GTK_TYPE_BUTTON)
@@ -59,6 +61,17 @@ show_details (GrRecipeTile *tile)
 }
 
 static void
+update_shared_icon (GrRecipeTile *tile)
+{
+        if (tile->show_shared && tile->recipe) {
+                gtk_widget_set_visible (tile->shared_icon, gr_recipe_is_contributed (tile->recipe));
+        }
+        else {
+                gtk_widget_hide (tile->shared_icon);
+        }
+}
+
+static void
 recipe_tile_set_recipe (GrRecipeTile *tile,
                         GrRecipe     *recipe)
 {
@@ -142,6 +155,7 @@ gr_recipe_tile_class_init (GrRecipeTileClass *klass)
         gtk_widget_class_bind_template_child (widget_class, GrRecipeTile, author);
         gtk_widget_class_bind_template_child (widget_class, GrRecipeTile, image);
         gtk_widget_class_bind_template_child (widget_class, GrRecipeTile, box);
+        gtk_widget_class_bind_template_child (widget_class, GrRecipeTile, shared_icon);
 
         gtk_widget_class_bind_template_callback (widget_class, show_details);
 }
@@ -175,3 +189,12 @@ gr_recipe_tile_get_recipe (GrRecipeTile *tile)
 {
         return tile->recipe;
 }
+
+void
+gr_recipe_tile_set_show_shared (GrRecipeTile *tile,
+                                gboolean      show_shared)
+{
+        tile->show_shared = show_shared;
+
+        update_shared_icon (tile);
+}
diff --git a/src/gr-recipe-tile.h b/src/gr-recipe-tile.h
index 1278639..b6e7c45 100644
--- a/src/gr-recipe-tile.h
+++ b/src/gr-recipe-tile.h
@@ -33,5 +33,7 @@ G_DECLARE_FINAL_TYPE (GrRecipeTile, gr_recipe_tile, GR, RECIPE_TILE, GtkButton)
 GtkWidget      *gr_recipe_tile_new        (GrRecipe     *recipe);
 GtkWidget      *gr_recipe_tile_new_wide   (GrRecipe     *recipe);
 GrRecipe       *gr_recipe_tile_get_recipe (GrRecipeTile *tile);
+void            gr_recipe_tile_set_show_shared (GrRecipeTile *tile,
+                                                gboolean      show_shared);
 
 G_END_DECLS
diff --git a/src/gr-recipe-tile.ui b/src/gr-recipe-tile.ui
index 45dec2d..e114c9a 100644
--- a/src/gr-recipe-tile.ui
+++ b/src/gr-recipe-tile.ui
@@ -29,17 +29,39 @@
                 <property name="valign">end</property>
                 <property name="orientation">vertical</property>
                 <child>
-                  <object class="GtkLabel" id="label">
+                  <object class="GtkBox">
                     <property name="visible">1</property>
-                    <property name="valign">end</property>
-                    <property name="xalign">0</property>
-                    <property name="ellipsize">end</property>
-                    <property name="width-chars">12</property>
-                    <property name="max-width-chars">12</property>
+                    <property name="halign">fill</property>
+                    <property name="orientation">horizontal</property>
                     <style>
                       <class name="recipe"/>
                       <class name="name"/>
                     </style>
+                    <child>
+                      <object class="GtkLabel" id="label">
+                        <property name="visible">1</property>
+                        <property name="valign">end</property>
+                        <property name="xalign">0</property>
+                        <property name="ellipsize">end</property>
+                        <property name="width-chars">12</property>
+                        <property name="max-width-chars">12</property>
+                        <style>
+                          <class name="recipe"/>
+                          <class name="name"/>
+                        </style>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImage" id="shared_icon">
+                        <property name="icon-name">emblem-shared-symbolic</property>
+                        <property name="icon-size">1</property>
+                        <property name="halign">end</property>
+                        <property name="margin-end">10</property>
+                      </object>
+                      <packing>
+                        <property name="expand">1</property>
+                      </packing>
+                    </child>
                   </object>
                 </child>
                 <child>
diff --git a/src/gr-window.c b/src/gr-window.c
index 89bd3dc..2603a0a 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -1251,7 +1251,7 @@ gr_window_show_chef (GrWindow *window,
 
         save_back_entry (window);
 
-        gr_list_page_populate_from_chef (GR_LIST_PAGE (window->chef_page), chef);
+        gr_list_page_populate_from_chef (GR_LIST_PAGE (window->chef_page), chef,  FALSE);
         title = g_strdup_printf (_("Chefs: %s"), gr_chef_get_fullname (chef));
         configure_window (window, title, "back", "title", "list", "chef");
 }
@@ -1322,7 +1322,7 @@ do_show_mine (GrChef   *chef,
 
         save_back_entry (window);
 
-        gr_list_page_populate_from_chef (GR_LIST_PAGE (window->chef_page), chef);
+        gr_list_page_populate_from_chef (GR_LIST_PAGE (window->chef_page), chef, TRUE);
         configure_window (window, _("My Recipes"), "back", "title", "list", "chef");
 }
 
diff --git a/src/recipes.css b/src/recipes.css
index 67f1838..fd179c3 100644
--- a/src/recipes.css
+++ b/src/recipes.css
@@ -113,6 +113,11 @@ label.chef.name {
   min-height: 64px;
 }
 
+box.recipe.name {
+  background: @theme_base_color;
+  color: @theme_fg_color;
+}
+
 label.recipe.name {
   background: @theme_base_color;
   color: @theme_fg_color;


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