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



commit abe1a8c7911f6ffd043411533d4e9e2baaa3e1b9
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 |   16 +++++++++++++++-
 src/gr-shopping-list-exporter.h |    2 ++
 src/gr-window.c                 |   10 ++++++++++
 3 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/src/gr-shopping-list-exporter.c b/src/gr-shopping-list-exporter.c
index 3ee258e..6e73867 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
@@ -725,6 +726,9 @@ initialize_export (GrShoppingListExporter *exporter)
        gboolean project_present;
        if (exporter->account_row_selected == exporter->todoist_row) {
                if (!exporter->access_token) {
+                       if (!exporter->account_object) {
+                               get_todoist_account (exporter);
+                       }
                        get_access_token (exporter);
                }
                project_present = get_project_id (exporter);
@@ -740,6 +744,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]