[recipes/todoist-3: 9/10] Method do_undo_in_todoist called on click of 'Undo' button in notification resends the shopping list



commit 05a610bf2cc72e11a39b66d3b2f910e57ee19188
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date:   Mon Aug 21 06:05:51 2017 +0530

    Method do_undo_in_todoist called on click of 'Undo' button in notification resends the shopping list to 
Todoist

 src/gr-shopping-list-exporter.c |   20 +++++++++++++++++---
 src/gr-shopping-list-exporter.h |    2 ++
 src/gr-window.c                 |   10 ++++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/src/gr-shopping-list-exporter.c b/src/gr-shopping-list-exporter.c
index 9ba9a63..1d9198c 100644
--- a/src/gr-shopping-list-exporter.c
+++ b/src/gr-shopping-list-exporter.c
@@ -321,7 +321,8 @@ export_shopping_list_callback (RestProxyCall *call,
 
        out:
          g_object_unref (parser);
-         close_dialog (exporter);
+         if (exporter->dialog)
+               close_dialog (exporter);
 }
 
 static void
@@ -727,8 +728,11 @@ initialize_export (GrShoppingListExporter *exporter)
        gboolean project_present;
        if (exporter->account_row_selected == exporter->todoist_row) {
                if (!exporter->access_token) {
-                       get_access_token (exporter);
-               }
+                       if (!exporter->account_object) {
+                                       get_todoist_account(exporter);
+                               }
+                               get_access_token (exporter);
+                       }
                project_present = get_project_id (exporter);
                if (!project_present)
                {
@@ -742,6 +746,16 @@ initialize_export (GrShoppingListExporter *exporter)
        }
 }
 
+void
+do_undo_in_todoist (GrShoppingListExporter *exporter, GList *items)
+{
+       if (!exporter->ingredients)
+               exporter->ingredients = items;
+
+       initialize_export (exporter);
+}
+
+
 static GVariant*
 build_dbus_parameters (const gchar *action,
                        const gchar *arg)
diff --git a/src/gr-shopping-list-exporter.h b/src/gr-shopping-list-exporter.h
index 6fc44b2..76b8923 100644
--- a/src/gr-shopping-list-exporter.h
+++ b/src/gr-shopping-list-exporter.h
@@ -35,4 +35,6 @@ GrShoppingListExporter *gr_shopping_list_exporter_new    (GtkWindow        *wind
 void                                   gr_shopping_list_exporter_export (GrShoppingListExporter *exporter, 
GList *items);
 
 void                                   done_shopping_in_todoist (GrShoppingListExporter *exporter);
+
+void                                   do_undo_in_todoist (GrShoppingListExporter *exporter, GList *items);
 G_END_DECLS
\ No newline at end of file
diff --git a/src/gr-window.c b/src/gr-window.c
index 0520d76..584c27b 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -792,7 +792,9 @@ back_to_shopping (GrWindow *window)
 {
         GrRecipeStore *store;
         GList *l;
+        GList *items;
         int i;
+        GrShoppingListExporter *exporter = NULL;
 
         store = gr_recipe_store_get ();
 
@@ -800,6 +802,14 @@ back_to_shopping (GrWindow *window)
                 ShoppingListEntry *entry = l->data;
                 gr_recipe_store_add_to_shopping (store, entry->recipe, entry->yield);
         }
+        items = get_ingredients (GR_SHOPPING_PAGE (window->shopping_page));
+        if (!exporter) {
+                GtkWidget *shopping_window;
+
+                shopping_window = gtk_widget_get_ancestor (GTK_WIDGET (window->shopping_page), 
GTK_TYPE_APPLICATION_WINDOW);
+                exporter = gr_shopping_list_exporter_new (GTK_WINDOW (shopping_window));
+                do_undo_in_todoist (exporter, items);
+        }
         for (i = 0; window->removed_ingredients && window->removed_ingredients[i]; i++) {
                 gr_recipe_store_remove_shopping_ingredient (store, window->removed_ingredients[i]);
         }


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