[recipes/todoist: 2/3] Todoist row only shows up if there is account



commit 5af638d203403cf3d56c6dd980b2c9c26035f1a3
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date:   Sat Jul 1 20:34:45 2017 +0530

    Todoist row only shows up if there is account

 src/gr-ingredients-exporter.c |   62 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/src/gr-ingredients-exporter.c b/src/gr-ingredients-exporter.c
index 5add85c..76a328d 100644
--- a/src/gr-ingredients-exporter.c
+++ b/src/gr-ingredients-exporter.c
@@ -16,12 +16,14 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
+#define GOA_API_IS_SUBJECT_TO_CHANGE
 
 #include "config.h"
 
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
+ #include <goa/goa.h>
 
 #include "gr-ingredients-exporter.h"
 
@@ -29,6 +31,8 @@
 {
         GObject parent_instance;
         GtkWindow *window;
+
+        GtkWidget *todoist_row;
 };
 
 
@@ -47,6 +51,8 @@ static void
 gr_ingredients_exporter_class_init (GrIngredientsExporterClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
 
         object_class->finalize = gr_ingredients_exporter_finalize;
 }
@@ -73,10 +79,60 @@ show_export_dialog (GrIngredientsExporter *exporter)
 {
         g_autoptr(GtkBuilder) builder = NULL;
         GtkWidget *dialog;
-        //GtkWidget *list;
 
-        builder = gtk_builder_new_from_resource ("/org/gnome/Recipes/ingredients-exporter-dialog.ui");
+
+                builder = gtk_builder_new_from_resource 
("/org/gnome/Recipes/ingredients-exporter-dialog.ui");
         dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dialog"));
+        exporter->todoist_row = GTK_WIDGET (gtk_builder_get_object (builder, "todoist_row"));
+
+
+        GoaClient *client;
+           GList *accounts, *l;
+           GoaAccount *account;
+           GError *error;
+
+           client = goa_client_new_sync (NULL, &error);
+           
+  if (!client) {
+    g_error ("Could not create GoaClient: %s", error->message);
+    return 1;
+  }
+
+  accounts = goa_client_get_accounts (client);
+  for (l = accounts; l != NULL; l = l->next) {
+    GoaOAuth2Based *oauth2 = NULL;
+
+    account = goa_object_get_account (GOA_OBJECT (l->data));
+    if (strcmp (goa_account_get_provider_name (account), "Todoist"))
+    {
+       gtk_widget_set_visible (exporter->todoist_row, TRUE);
+    }
+    g_print ("%s at %s (%s)\n",
+             goa_account_get_presentation_identity (account),
+             goa_account_get_provider_name (account),
+             goa_account_get_provider_type (account));
+    oauth2 = goa_object_get_oauth2_based (GOA_OBJECT (l->data));
+    if (oauth2) {
+      gchar *access_token;
+      if (goa_oauth2_based_call_get_access_token_sync (oauth2,
+                                                       &access_token,
+                                                       NULL,
+                                                       NULL,
+                                                       NULL)) {
+        g_print ("\tAccessToken: %s\n", access_token);
+        g_free (access_token);
+      }
+      g_print ("\tClientId: %s\n\tClientSecret: %s\n",
+               goa_oauth2_based_get_client_id (oauth2),
+               goa_oauth2_based_get_client_secret (oauth2));
+    }
+    g_clear_object (&oauth2);
+  }
+
+        //GtkWidget *list;
+
+
+        //gtk_widget_set_visible (exporter->todoist_row, TRUE);
 
         gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (exporter->window));
         gtk_widget_show (dialog);
@@ -85,6 +141,6 @@ show_export_dialog (GrIngredientsExporter *exporter)
 void
 gr_ingredients_exporter_export (GrIngredientsExporter *exporter)
 {
-
+        // check_todoist_present(exporter);
         show_export_dialog (exporter);
 }


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