[recipes/list-new: 12/14] Add API to populate a list page with new recipes



commit bebf40daed3ad0ad6907b82abbd984ee22f3402a
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 24 23:56:58 2017 -0500

    Add API to populate a list page with new recipes
    
    This uses hte just-introduced find-new-recipes query.

 src/gr-list-page.c |   33 +++++++++++++++++++++++++++++++++
 src/gr-list-page.h |    1 +
 2 files changed, 34 insertions(+), 0 deletions(-)
---
diff --git a/src/gr-list-page.c b/src/gr-list-page.c
index 3736c2d..5dbfb29 100644
--- a/src/gr-list-page.c
+++ b/src/gr-list-page.c
@@ -40,6 +40,7 @@ struct _GrListPage
         GrDiets diet;
         gboolean favorites;
         gboolean all;
+        gboolean new;
         char *season;
         GList *recipes;
 
@@ -76,6 +77,7 @@ clear_data (GrListPage *self)
         self->diet = 0;
         self->favorites = FALSE;
         self->all = FALSE;
+        self->new = FALSE;
         g_clear_pointer (&self->season, g_free);
         g_list_free_full (self->recipes, g_object_unref);
         self->recipes = NULL;
@@ -411,6 +413,37 @@ gr_list_page_populate_from_all (GrListPage *self)
 }
 
 void
+gr_list_page_populate_from_new (GrListPage *self)
+{
+        g_autoptr(GDateTime) now = NULL;
+        g_autoptr(GDateTime) time = NULL;
+        g_autofree char *timestamp = NULL;
+        g_autofree char *query = NULL;
+        const char *terms[2];
+
+        clear_data (self);
+        self->new = TRUE;
+
+        gtk_widget_hide (self->chef_grid);
+        gtk_widget_hide (self->heading);
+        gtk_widget_hide (self->diet_description);
+
+        container_remove_all (GTK_CONTAINER (self->flow_box));
+        gtk_label_set_label (GTK_LABEL (self->empty_title), _("No new recipes"));
+        gtk_label_set_label (GTK_LABEL (self->empty_subtitle), _("Sorry about this."));
+
+        gr_recipe_search_stop (self->search);
+        gtk_stack_set_visible_child_name (GTK_STACK (self->list_stack), "list");
+        now = g_date_time_new_now_utc ();
+        time = g_date_time_add_weeks (now, -1);
+        timestamp = date_time_to_string (time);
+        query = g_strconcat ("ct:", timestamp, NULL);
+        terms[0] = (const char*)query;
+        terms[1] = NULL;
+        gr_recipe_search_set_terms (self->search, terms);
+}
+
+void
 gr_list_page_populate_from_list (GrListPage *self,
                                  GList      *recipes)
 {
diff --git a/src/gr-list-page.h b/src/gr-list-page.h
index c20070d..4c33c02 100644
--- a/src/gr-list-page.h
+++ b/src/gr-list-page.h
@@ -42,6 +42,7 @@ void            gr_list_page_populate_from_favorites (GrListPage *self);
 void            gr_list_page_populate_from_list      (GrListPage *self,
                                                       GList      *recipes);
 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);
 


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