[recipes] Hook up an action to the system notification



commit 30a234f15519371e446d2911a4985af7264cc714
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Feb 23 23:05:50 2017 -0500

    Hook up an action to the system notification
    
    This lets us get back to the recipe and continue cooking
    from the step where the timer expired.

 src/gr-app.c          |   20 ++++++++++++++++++++
 src/gr-cooking-page.c |    8 ++++++++
 src/gr-cooking-page.h |    2 ++
 src/gr-cooking-view.c |   43 +++++++++++++++++++++++++++++++------------
 src/gr-cooking-view.h |    2 ++
 src/gr-window.c       |   10 ++++++++++
 src/gr-window.h       |    3 +++
 7 files changed, 76 insertions(+), 12 deletions(-)
---
diff --git a/src/gr-app.c b/src/gr-app.c
index 80a5181..9711d5a 100644
--- a/src/gr-app.c
+++ b/src/gr-app.c
@@ -66,6 +66,25 @@ gr_app_activate (GApplication *app)
 }
 
 static void
+timer_expired (GSimpleAction *action,
+               GVariant      *parameter,
+               gpointer       application)
+{
+        GrApp *app = GR_APP (application);
+        GtkWindow *win;
+        const char *id;
+        int step;
+        g_autoptr(GrRecipe) recipe = NULL;
+
+        g_variant_get (parameter, "(&si)", &id, &step);
+
+        gr_app_activate (G_APPLICATION (app));
+        win = gtk_application_get_active_window (GTK_APPLICATION (app));
+        recipe = gr_recipe_store_get_recipe (app->store, id);
+        gr_window_timer_expired (GR_WINDOW (win), recipe, step);
+}
+
+static void
 chef_information_activated (GSimpleAction *action,
                             GVariant      *parameter,
                             gpointer       app)
@@ -143,6 +162,7 @@ search_activated (GSimpleAction *action,
 
 static GActionEntry app_entries[] =
 {
+        { "timer-expired", timer_expired, "(si)", NULL, NULL },
         { "chef-information", chef_information_activated, NULL, NULL, NULL },
         { "about", about_activated, NULL, NULL, NULL },
         { "import", import_activated, NULL, NULL, NULL },
diff --git a/src/gr-cooking-page.c b/src/gr-cooking-page.c
index 2fbb1bc..3826f2f 100644
--- a/src/gr-cooking-page.c
+++ b/src/gr-cooking-page.c
@@ -270,6 +270,14 @@ gr_cooking_page_start_cooking (GrCookingPage *page)
         set_cooking (page, TRUE);
 }
 
+void
+gr_cooking_page_timer_expired (GrCookingPage *page,
+                               int            step)
+{
+        set_cooking (page, TRUE);
+        gr_cooking_view_timer_expired (GR_COOKING_VIEW (page->cooking_view), step);
+}
+
 static void
 show_buttons (GrCookingPage *page)
 {
diff --git a/src/gr-cooking-page.h b/src/gr-cooking-page.h
index 4554d79..7b29757 100644
--- a/src/gr-cooking-page.h
+++ b/src/gr-cooking-page.h
@@ -34,6 +34,8 @@ GrCookingPage *gr_cooking_page_new        (void);
 void           gr_cooking_page_set_recipe (GrCookingPage *page,
                                            GrRecipe      *recipe);
 void           gr_cooking_page_start_cooking (GrCookingPage *page);
+void           gr_cooking_page_timer_expired (GrCookingPage *page,
+                                              int            step);
 
 gboolean       gr_cooking_page_handle_event (GrCookingPage *page,
                                              GdkEvent      *event);
diff --git a/src/gr-cooking-view.c b/src/gr-cooking-view.c
index f3772fe..1f671e7 100644
--- a/src/gr-cooking-view.c
+++ b/src/gr-cooking-view.c
@@ -375,8 +375,8 @@ play_complete_sound (TimerData *td)
 }
 
 static void
-show_complete_notification (GrTimer   *timer,
-                            TimerData *td)
+show_in_app_notification (GrTimer   *timer,
+                          TimerData *td)
 {
         GrCookingView *view = td->view;
         GtkWidget *page;
@@ -392,27 +392,38 @@ show_complete_notification (GrTimer   *timer,
 }
 
 static void
+show_system_notification (GrTimer   *timer,
+                          TimerData *td)
+{
+        GApplication *app = g_application_get_default ();
+        g_autoptr(GNotification) notification = NULL;
+        g_autofree char *body = NULL;
+
+        notification = g_notification_new (_("Timer is up!"));
+
+        body = g_strdup_printf (_("The timer for '%s' has expired."), gr_timer_get_name (timer));
+        g_notification_set_body (notification, body);
+
+        g_notification_set_default_action_and_target (notification, "app.timer-expired",
+                                                      "(si)", td->id, td->num);
+
+        g_application_send_notification (app, "timer", notification);
+}
+
+static void
 timer_complete (GrTimer   *timer,
                 TimerData *td)
 {
         GrCookingView *view = td->view;
 
         if (td->use_system) {
-                GApplication *app = g_application_get_default ();
-                g_autoptr(GNotification) notification = NULL;
-                g_autofree char *body = NULL;
-
-                notification = g_notification_new (_("Timer is up!"));
-
-                body = g_strdup_printf (_("The timer for '%s' (recipe %s) has expired."), gr_timer_get_name 
(timer), td->id);
-                g_notification_set_body (notification, body);
-                g_application_send_notification (app, "timer", notification);
+                show_system_notification (timer, td);
         }
         else {
                 if (view->step == td->num)
                         gtk_stack_set_visible_child_name (GTK_STACK (view->cooking_stack), "complete");
                 else
-                        show_complete_notification (timer, td);
+                        show_in_app_notification (timer, td);
         }
 
         play_complete_sound (td);
@@ -602,6 +613,14 @@ gr_cooking_view_set_step (GrCookingView *view,
 }
 
 void
+gr_cooking_view_timer_expired (GrCookingView *view,
+                               int            step)
+{
+        set_step (view, step);
+        gtk_stack_set_visible_child_name (GTK_STACK (view->cooking_stack), "complete");
+}
+
+void
 gr_cooking_view_start (GrCookingView *view)
 {
         set_step (view, 0);
diff --git a/src/gr-cooking-view.h b/src/gr-cooking-view.h
index b76a7a6..a52f015 100644
--- a/src/gr-cooking-view.h
+++ b/src/gr-cooking-view.h
@@ -46,6 +46,8 @@ void           gr_cooking_view_next_step     (GrCookingView *view);
 void           gr_cooking_view_prev_step     (GrCookingView *view);
 void           gr_cooking_view_set_timer_box (GrCookingView *view,
                                               GtkWidget     *box);
+void           gr_cooking_view_timer_expired (GrCookingView *view,
+                                              int            step);
 
 G_END_DECLS
 
diff --git a/src/gr-window.c b/src/gr-window.c
index 627e92c..d8cac3d 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -327,6 +327,16 @@ start_cooking (GrWindow *window)
         gr_cooking_page_start_cooking (GR_COOKING_PAGE (window->cooking_page));
 }
 
+void
+gr_window_timer_expired (GrWindow *window,
+                         GrRecipe *recipe,
+                         int       step)
+{
+        gr_cooking_page_set_recipe (GR_COOKING_PAGE (window->cooking_page), recipe);
+        gtk_stack_set_visible_child_name (GTK_STACK (window->main_stack), "cooking");
+        gr_cooking_page_timer_expired (GR_COOKING_PAGE (window->cooking_page), step);
+}
+
 static gboolean
 window_keypress_handler (GtkWidget *widget,
                          GdkEvent  *event,
diff --git a/src/gr-window.h b/src/gr-window.h
index e0d895c..1552e8a 100644
--- a/src/gr-window.h
+++ b/src/gr-window.h
@@ -39,6 +39,9 @@ void            gr_window_show_recipe                (GrWindow   *window,
                                                       GrRecipe   *recipe);
 void            gr_window_edit_recipe                (GrWindow   *window,
                                                       GrRecipe   *recipe);
+void            gr_window_timer_expired              (GrWindow   *window,
+                                                      GrRecipe   *recipe,
+                                                      int         step);
 void            gr_window_load_recipe                (GrWindow   *window,
                                                       GFile      *file);
 void            gr_window_show_search                (GrWindow   *window,


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