[recipes/todoist] Making a async call using RestProxyCall
- From: Ekta Nandwani <ektan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes/todoist] Making a async call using RestProxyCall
- Date: Tue, 11 Jul 2017 15:08:22 +0000 (UTC)
commit 48b1a363bd1a6695da98db4f455822e0fd62ff3a
Author: Ekta Nandwani <mailnandwaniekta gmail com>
Date: Tue Jul 11 20:37:36 2017 +0530
Making a async call using RestProxyCall
meson.build | 1 +
src/gr-ingredients-exporter.c | 91 +++++++++++++++++++++++++-----------
src/ingredients-exporter-dialog.ui | 1 +
3 files changed, 66 insertions(+), 27 deletions(-)
---
diff --git a/meson.build b/meson.build
index ed3d7ca..ee3df9c 100644
--- a/meson.build
+++ b/meson.build
@@ -83,6 +83,7 @@ deps = [ dependency('gtk+-3.0', version : '>=3.22'),
dependency('gmodule-export-2.0'),
dependency('libsoup-2.4'),
dependency('goa-1.0'),
+ dependency('rest-0.7'),
autoar_dep,
gspell_dep,
canberra_dep,
diff --git a/src/gr-ingredients-exporter.c b/src/gr-ingredients-exporter.c
index 1cfbf7c..03cdd2a 100644
--- a/src/gr-ingredients-exporter.c
+++ b/src/gr-ingredients-exporter.c
@@ -25,6 +25,7 @@
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <goa/goa.h>
+#include <rest/oauth2-proxy.h>
#include "gr-ingredients-exporter.h"
@@ -33,6 +34,8 @@
GObject parent_instance;
GtkWindow *window;
+ GoaObject *account_object;
+
GtkWidget *export_button;
GtkWidget *cancel_button;
GtkWidget *back_button;
@@ -42,6 +45,9 @@
GtkWidget *dialog_stack;
GtkWidget *header_start_stack;
GtkWidget *header;
+ GtkWidget *providers_list;
+ GtkWidget *accounts_list;
+ GtkWidget *account_row_selected;
};
@@ -104,11 +110,50 @@ switch_dialog_contents (GrIngredientsExporter *exporter)
//gtk_widget_set_visible (exporter->accounts_box, FALSE);
}
+static void
+do_something_here (RestProxyCall *call, GError *error, GObject *obj, GrIngredientsExporter *exporter)
+{
+ g_print("call made\n");
+}
static void
-export_shopping_list (GtkLabel *label, const char *uri, GrIngredientsExporter *exporter)
+export_shopping_list (GrIngredientsExporter *exporter)
{
- g_print ("export_shopping_list\n");
+ GoaOAuth2Based *oauth2 = NULL;
+ gchar *access_token;
+ GError *error;
+ RestProxy *proxy;
+ RestProxyCall *call;
+ //GtkWidget *account_label;
+
+ error = NULL;
+ oauth2 = goa_object_get_oauth2_based (GOA_OBJECT (exporter->account_object));
+
+ if (!goa_oauth2_based_call_get_access_token_sync (oauth2, &access_token, NULL, NULL, &error))
+ {
+ g_print("access token not found!");
+ }
+
+ if (exporter->todoist_row == exporter->account_row_selected)
+ {
+ g_print ("export the list here\n");
+ }
+ //account_label = gtk_bin_get_child (GTK_BIN (exporter->account_row_selected));
+
+ proxy = rest_proxy_new ("https://todoist.com/API/v7/sync", FALSE);
+ call = rest_proxy_new_call (proxy);
+ rest_proxy_call_set_method (call, "POST");
+ rest_proxy_call_add_header (call, "content-type", "application/x-www-form-urlencoded");
+ rest_proxy_call_add_param (call, "token", access_token);
+ rest_proxy_call_add_param (call, "resource_types", "[\"all\"]");
+ if (!rest_proxy_call_async (call, (RestProxyCallAsyncCallback) do_something_here, NULL,
+ exporter,
+ &error))
+ {
+ g_print("calling async failed\n");
+ }
+
+
}
static void
@@ -117,6 +162,14 @@ cancel_export (GrIngredientsExporter *exporter)
g_print ("cancel_export\n");
}
+static GtkWidget *
+get_selected_account (GtkListBox *list, GrIngredientsExporter *exporter)
+{
+ g_print("get_selected_account\n");
+
+ exporter->account_row_selected = GTK_WIDGET (gtk_list_box_get_selected_row (list));
+}
+
static void
show_export_dialog (GrIngredientsExporter *exporter)
@@ -139,11 +192,14 @@ show_export_dialog (GrIngredientsExporter *exporter)
exporter->dialog_stack = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stack"));
exporter->header_start_stack = GTK_WIDGET (gtk_builder_get_object (builder, "header_start_stack"));
exporter->header = GTK_WIDGET (gtk_builder_get_object (builder, "header"));
+ exporter->providers_list = GTK_WIDGET (gtk_builder_get_object (builder, "providers_list"));
+ exporter->accounts_list = GTK_WIDGET (gtk_builder_get_object (builder, "accounts_list"));
g_signal_connect_swapped (add_service, "activate-link", G_CALLBACK (switch_dialog_contents),
exporter);
g_signal_connect_swapped (exporter->back_button, "clicked", G_CALLBACK (switch_dialog_contents),
exporter);
- g_signal_connect (exporter->export_button, "clicked", G_CALLBACK (export_shopping_list), exporter);
+ g_signal_connect_swapped (exporter->export_button, "clicked", G_CALLBACK (export_shopping_list),
exporter);
g_signal_connect (exporter->cancel_button, "clicked", G_CALLBACK (cancel_export), exporter);
+ g_signal_connect (exporter->accounts_list, "selected-rows-changed", G_CALLBACK
(get_selected_account), exporter);
@@ -163,35 +219,16 @@ show_export_dialog (GrIngredientsExporter *exporter)
accounts = goa_client_get_accounts (client);
for (l = accounts; l != NULL; l = l->next)
{
- GoaOAuth2Based *oauth2 = NULL;
+ const gchar *provider_type;
account = goa_object_get_account (GOA_OBJECT (l->data));
- if (strcmp (goa_account_get_provider_name (account), "Todoist"))
+ provider_type = goa_account_get_provider_type (account);
+ if (strcmp (provider_type, "todoist"))
{
gtk_widget_set_visible (exporter->todoist_row, TRUE);
+ exporter->account_object = GOA_OBJECT(l->data);
}
- 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);
+ g_object_unref (account);
}
//GtkWidget *list;
diff --git a/src/ingredients-exporter-dialog.ui b/src/ingredients-exporter-dialog.ui
index 775a2ad..cb50332 100644
--- a/src/ingredients-exporter-dialog.ui
+++ b/src/ingredients-exporter-dialog.ui
@@ -171,6 +171,7 @@
<object class="GtkListBox" id="providers_list">
<property name="selection_mode">single</property>
<property name="visible">1</property>
+ <signal name="selected-rows-changed" handler="row_changed"/>
<style>
<class name="frame"/>
</style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]