[recipes/favorite-tile: 3/5] Add a new favorites tiles
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/favorite-tile: 3/5] Add a new favorites tiles
- Date: Sat, 7 Jan 2017 12:56:58 +0000 (UTC)
commit ff6e85c7d52acbf852977a8a3eb3e9c3db84c42e
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jan 7 00:19:10 2017 -0500
Add a new favorites tiles
Following Jakub's latest mockup.
src/gr-recipes-page.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++-
src/gr-recipes-page.ui | 39 +++++++++++++++++++++++++++++++++++++
src/recipes.css | 16 +++++++++++++++
3 files changed, 103 insertions(+), 2 deletions(-)
---
diff --git a/src/gr-recipes-page.c b/src/gr-recipes-page.c
index 80c32fc..e5a2e2a 100644
--- a/src/gr-recipes-page.c
+++ b/src/gr-recipes-page.c
@@ -42,11 +42,13 @@ struct _GrRecipesPage
GtkWidget *pick_box;
GtkWidget *diet_box;
GtkWidget *chefs_box;
- GtkWidget *favorites_box;
GtkWidget *categories_expander_image;
GtkWidget *diet_more;
GtkWidget *diet_box2;
GtkWidget *scrolled_win;
+ GtkWidget *favorites_tile;
+ GtkWidget *favorites_list;
+ GtkWidget *favorites_time;
};
G_DEFINE_TYPE (GrRecipesPage, gr_recipes_page, GTK_TYPE_BOX)
@@ -114,6 +116,15 @@ recipes_page_finalize (GObject *object)
}
static void
+favorites_tile_clicked (GrRecipesPage *page)
+{
+ GtkWidget *window;
+
+ window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
+ gr_window_show_favorites (GR_WINDOW (window));
+}
+
+static void
gr_recipes_page_init (GrRecipesPage *page)
{
gtk_widget_set_has_window (GTK_WIDGET (page), FALSE);
@@ -145,9 +156,13 @@ gr_recipes_page_class_init (GrRecipesPageClass *klass)
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GrRecipesPage, diet_box2);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GrRecipesPage, diet_more);
gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GrRecipesPage, scrolled_win);
+ gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GrRecipesPage, favorites_tile);
+ gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GrRecipesPage, favorites_list);
+ gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (klass), GrRecipesPage, favorites_time);
gtk_widget_class_bind_template_callback (widget_class, show_chef_list);
gtk_widget_class_bind_template_callback (widget_class, expander_button_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, favorites_tile_clicked);
}
GtkWidget *
@@ -230,6 +245,12 @@ populate_recipes_from_store (GrRecipesPage *self)
int i;
int todays;
int picks;
+ g_autofree char *fav1 = NULL;
+ g_autofree char *fav2 = NULL;
+ int favorites;
+ char *tmp;
+ GDateTime *change;
+ g_autoptr(GDateTime) now = NULL;
container_remove_all (GTK_CONTAINER (self->today_box));
container_remove_all (GTK_CONTAINER (self->pick_box));
@@ -239,6 +260,7 @@ populate_recipes_from_store (GrRecipesPage *self)
keys = gr_recipe_store_get_recipe_keys (store, &length);
todays = 0;
picks = 0;
+ favorites = 0;
for (i = 0; i < length; i++) {
g_autoptr(GrRecipe) recipe = NULL;
GtkWidget *tile;
@@ -264,8 +286,32 @@ populate_recipes_from_store (GrRecipesPage *self)
picks++;
}
-
+ if (gr_recipe_store_is_favorite (store, recipe)) {
+ if (favorites == 0)
+ fav1 = g_markup_escape_text (gr_recipe_get_name (recipe), -1);
+ else if (favorites == 1)
+ fav2 = g_markup_escape_text (gr_recipe_get_name (recipe), -1);
+ favorites++;
+ }
}
+
+ if (favorites == 1)
+ tmp = g_strdup_printf (_("Cook later: <b>%s</b>"), fav1);
+ else if (favorites == 2)
+ tmp = g_strdup_printf (_("Cook later: <b>%s and %s</b>"), fav1, fav2);
+ else
+ tmp = g_strdup_printf (ngettext ("Cook later: <b>%s, %s and %d other</b>",
+ "Cook later: <b>%s, %s and %d others</b>", favorites - 2),
fav1, fav2, favorites - 2);
+ gtk_label_set_label (GTK_LABEL (self->favorites_list), tmp);
+ g_free (tmp);
+
+ now = g_date_time_new_now_utc ();
+ change = gr_recipe_store_last_favorite_change (store);
+ tmp = format_date_time_difference (now, change);
+ gtk_label_set_label (GTK_LABEL (self->favorites_time), tmp);
+ g_free (tmp);
+
+ gtk_widget_set_visible (self->favorites_tile, favorites > 0);
}
static void
diff --git a/src/gr-recipes-page.ui b/src/gr-recipes-page.ui
index 920dcf7..c824317 100644
--- a/src/gr-recipes-page.ui
+++ b/src/gr-recipes-page.ui
@@ -49,6 +49,45 @@
</object>
</child>
<child>
+ <object class="GtkButton" id="favorites_tile">
+ <property name="visible">1</property>
+ <property name="margin-top">20</property>
+ <signal name="clicked" handler="favorites_tile_clicked" swapped="yes"/>
+ <style>
+ <class name="view"/>
+ <class name="tile"/>
+ <class name="favorites"/>
+ </style>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">1</property>
+ <property name="orientation">horizontal</property>
+ <child>
+ <object class="GtkLabel" id="favorites_list">
+ <property name="visible">1</property>
+ <property name="margin">10</property>
+ <property name="xalign">0</property>
+ <property name="label">Cook later: <b>Bagel, Mixed Salad and 4 other
recipes</b></property>
+ <property name="use-markup">1</property>
+ </object>
+ <packing>
+ <property name="expand">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="favorites_time">
+ <property name="visible">1</property>
+ <property name="margin">10</property>
+ <property name="xalign">1</property>
+ <property name="label">Last edited: 2 hours ago</property>
+ <style> <class name="dim-label"/> </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
<object class="GtkLabel" id="pick_label">
<property name="visible">1</property>
<property name="label" translatable="yes">Editor’s Picks</property>
diff --git a/src/recipes.css b/src/recipes.css
index bfa6604..aad801f 100644
--- a/src/recipes.css
+++ b/src/recipes.css
@@ -53,6 +53,22 @@ image.chef.circular {
border-radius: 0;
}
+.favorites.view.tile {
+ background: @theme_selected_bg_color;
+}
+
+.favorites.view.tile:backdrop {
+ background: @theme_unfocused_selected_bg_color;
+}
+
+.favorites.view.tile label {
+ color: @theme_selected_fg_color;
+}
+
+.favorites.view.tile label:backdrop {
+ color: @theme_unfocused_selected_fg_color;
+}
+
.recipe.view.tile {
color: mix(@theme_base_color,@theme_fg_color,0.1);
background-image:
-gtk-recolor(url('resource:///org/gnome/Recipes/org.gnome.Recipes-symbolic.symbolic.png'));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]