[recipes] Allow sharing the shopping list



commit 2103afa043705a9c7d40a7ffbc44d774ef8cea21
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 10 15:54:48 2017 -0500

    Allow sharing the shopping list

 src/gr-shopping-page.c  |   40 ++++++++++++++++++++++++++++++++++++++++
 src/gr-shopping-page.ui |    4 +++-
 2 files changed, 43 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-shopping-page.c b/src/gr-shopping-page.c
index df165bf..07cfc3f 100644
--- a/src/gr-shopping-page.c
+++ b/src/gr-shopping-page.c
@@ -33,6 +33,9 @@
 #include "gr-window.h"
 #include "gr-number.h"
 #include "gr-shopping-list-printer.h"
+#include "gr-shopping-list-formatter.h"
+#include "gr-mail.h"
+
 
 struct _GrShoppingPage
 {
@@ -658,6 +661,42 @@ print_list (GrShoppingPage *page)
 }
 
 static void
+share_list (GrShoppingPage *page)
+{
+        GList *recipes, *items;
+        g_autofree char *text = NULL;
+        g_autoptr(GError) error = NULL;
+
+        recipes = get_recipes (page);
+        items = get_ingredients (page);
+
+        text = gr_shopping_list_format (recipes, items);
+        if (!gr_send_mail (NULL, _("Shopping List"), text, NULL, &error)) {
+                GtkWidget *window;
+                GtkWidget *error_dialog;
+
+                g_message ("Sharing the shopping list failed: %s", error->message);
+
+                window = gtk_widget_get_ancestor (GTK_WIDGET (page), GTK_TYPE_APPLICATION_WINDOW);
+                error_dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+                                                       GTK_DIALOG_MODAL |
+                                                       GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                       GTK_MESSAGE_ERROR,
+                                                       GTK_BUTTONS_CLOSE,
+                                                       _("Could not share shopping list"));
+                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (error_dialog),
+                                                          _("There was an error sending the shopping "
+                                                            "list by e-mail.\n"));
+                g_signal_connect (error_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+                gtk_widget_show (error_dialog);
+
+        }
+
+        g_list_free_full (recipes, g_object_unref);
+        g_list_free_full (items, item_free);
+}
+
+static void
 gr_shopping_page_init (GrShoppingPage *page)
 {
         gtk_widget_set_has_window (GTK_WIDGET (page), FALSE);
@@ -742,6 +781,7 @@ gr_shopping_page_class_init (GrShoppingPageClass *klass)
 
         gtk_widget_class_bind_template_callback (widget_class, clear_list);
         gtk_widget_class_bind_template_callback (widget_class, print_list);
+        gtk_widget_class_bind_template_callback (widget_class, share_list);
         gtk_widget_class_bind_template_callback (widget_class, selected_rows_changed);
         gtk_widget_class_bind_template_callback (widget_class, removed_row_activated);
 }
diff --git a/src/gr-shopping-page.ui b/src/gr-shopping-page.ui
index 6b1b581..70dde4a 100644
--- a/src/gr-shopping-page.ui
+++ b/src/gr-shopping-page.ui
@@ -140,8 +140,10 @@
         </child>
         <child>
           <object class="GtkButton">
+            <property name="visible">1</property>
             <property name="use-underline">1</property>
-            <property name="label" translatable="yes">E_xport</property>
+            <property name="label" translatable="yes">_Share</property>
+            <signal name="clicked" handler="share_list" swapped="yes"/>
           </object>
           <packing>
             <property name="pack-type">end</property>


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