void picasa_web_service_list_albums (PicasaWebService *self, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { OAuthAccount *account; SoupMessage *msg; char *url; account = web_service_get_current_account (WEB_SERVICE (self)); g_return_if_fail (account != NULL); gth_task_progress (GTH_TASK (self), _("Getting the album list"), NULL, TRUE, 0.0); url = g_strconcat ("https://picasaweb.google.com/data/feed/api/user/", account->id, NULL); msg = soup_message_new ("GET", url); _picasa_web_service_add_headers (self, msg); _web_service_send_message (WEB_SERVICE (self), msg, cancellable, callback, user_data, picasa_web_service_list_albums, list_albums_ready_cb, self); g_free (url); }
static void update_account_list (DialogData *data) { int current_account_idx; OAuthAccount *current_account; int idx; GList *scan; GtkTreeIter iter; gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("account_liststore"))); current_account_idx = 0; current_account = web_service_get_current_account (WEB_SERVICE (data->service)); for (scan = web_service_get_accounts (WEB_SERVICE (data->service)), idx = 0; scan; scan = scan->next, idx++) { OAuthAccount *account = scan->data; if ((current_account != NULL) && (g_strcmp0 (current_account->id, account->id) == 0)) current_account_idx = idx; gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter); gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter, ACCOUNT_DATA_COLUMN, account, ACCOUNT_NAME_COLUMN, account->name, -1); } gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), current_account_idx); }
static void _picasa_web_service_get_access_token_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { PicasaWebService *self = user_data; GSimpleAsyncResult *result; GError *error = NULL; JsonNode *node; result = _web_service_get_result (WEB_SERVICE (self)); if (picasa_web_utils_parse_json_response (msg, &node, &error)) { JsonObject *obj; OAuthAccount *account; obj = json_node_get_object (node); account = web_service_get_current_account (WEB_SERVICE (self)); if (account != NULL) g_object_set (account, "token", json_object_get_string_member (obj, "access_token"), NULL); else _g_strset (&self->priv->access_token, json_object_get_string_member (obj, "access_token")); } else g_simple_async_result_set_from_error (result, error); g_simple_async_result_complete_in_idle (result); }
static void update_account_list (DialogData *data) { int current_account_idx; OAuthAccount *current_account; int idx; GList *scan; GtkTreeIter iter; char *free_space; gtk_list_store_clear (GTK_LIST_STORE (GET_WIDGET ("account_liststore"))); current_account_idx = 0; current_account = web_service_get_current_account (WEB_SERVICE (data->service)); for (scan = web_service_get_accounts (WEB_SERVICE (data->service)), idx = 0; scan; scan = scan->next, idx++) { OAuthAccount *account = scan->data; if (oauth_account_cmp (current_account, account) == 0) current_account_idx = idx; gtk_list_store_append (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter); gtk_list_store_set (GTK_LIST_STORE (GET_WIDGET ("account_liststore")), &iter, ACCOUNT_DATA_COLUMN, account, ACCOUNT_NAME_COLUMN, account->name, -1); } gtk_combo_box_set_active (GTK_COMBO_BOX (GET_WIDGET ("account_combobox")), current_account_idx); free_space = g_format_size (FLICKR_ACCOUNT (current_account)->max_bandwidth - FLICKR_ACCOUNT (current_account)->used_bandwidth); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("free_space_label")), free_space); g_free (free_space); }
static void completed_messagedialog_response_cb (GtkDialog *dialog, int response_id, gpointer user_data) { DialogData *data = user_data; switch (response_id) { case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CLOSE: gtk_widget_destroy (GTK_WIDGET (dialog)); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); break; case _OPEN_IN_BROWSER_RESPONSE: { OAuthAccount *account; GdkScreen *screen; char *url = NULL; GError *error = NULL; account = web_service_get_current_account (WEB_SERVICE (data->service)); screen = gtk_widget_get_screen (GTK_WIDGET (dialog)); gtk_widget_destroy (GTK_WIDGET (dialog)); if (data->album != NULL) { if (data->album->alternate_url != NULL) url = g_strdup (data->album->alternate_url); else url = g_strconcat ("http://picasaweb.google.com/", account->id, "/", data->album->id, NULL); } else url = g_strconcat ("http://picasaweb.google.com/", account->id, NULL); if ((url != NULL) && ! gtk_show_uri (screen, url, 0, &error)) { gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_run (GTK_WINDOW (data->browser), _("Could not connect to the server"), error); g_clear_error (&error); } gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); g_free (url); } break; default: break; } }
static void picasa_web_service_get_user_info (WebService *base, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { PicasaWebService *self = PICASA_WEB_SERVICE (base); OAuthAccount *account; GHashTable *data_set; SoupMessage *msg; account = web_service_get_current_account (WEB_SERVICE (self)); if (account != NULL) { _g_strset (&self->priv->refresh_token, account->token_secret); _g_strset (&self->priv->access_token, account->token); } data_set = g_hash_table_new (g_str_hash, g_str_equal); if (self->priv->access_token != NULL) { msg = soup_form_request_new_from_hash ("GET", "https://www.googleapis.com/oauth2/v2/userinfo", data_set); _picasa_web_service_add_headers (self, msg); _web_service_send_message (WEB_SERVICE (self), msg, cancellable, callback, user_data, picasa_web_service_get_user_info, picasa_web_service_get_user_info_ready_cb, self); } else { /* Get the access token from the refresh token */ AccessTokenData *data; data = g_new0 (AccessTokenData, 1); data->service = self; data->cancellable = _g_object_ref (cancellable); data->callback = callback; data->user_data = user_data; _picasa_web_service_get_access_token (self, self->priv->refresh_token, cancellable, access_token_ready_cb, data); } g_hash_table_destroy (data_set); }
void picasa_web_service_create_album (PicasaWebService *self, PicasaWebAlbum *album, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { OAuthAccount *account; DomDocument *doc; DomElement *entry; char *buffer; gsize len; char *url; SoupMessage *msg; account = web_service_get_current_account (WEB_SERVICE (self)); g_return_if_fail (account != NULL); gth_task_progress (GTH_TASK (self), _("Creating the new album"), NULL, TRUE, 0.0); doc = dom_document_new (); entry = dom_domizable_create_element (DOM_DOMIZABLE (album), doc); dom_element_append_child (DOM_ELEMENT (doc), entry); buffer = dom_document_dump (doc, &len); url = g_strconcat ("https://picasaweb.google.com/data/feed/api/user/", account->id, NULL); msg = soup_message_new ("POST", url); soup_message_set_request (msg, ATOM_ENTRY_MIME_TYPE, SOUP_MEMORY_TAKE, buffer, len); _picasa_web_service_add_headers (self, msg); _web_service_send_message (WEB_SERVICE (self), msg, cancellable, callback, user_data, picasa_web_service_create_album, create_album_ready_cb, self); g_free (url); g_object_unref (doc); }
static void account_combobox_changed_cb (GtkComboBox *widget, gpointer user_data) { DialogData *data = user_data; GtkTreeIter iter; OAuthAccount *account; if (! gtk_combo_box_get_active_iter (widget, &iter)) return; gtk_tree_model_get (gtk_combo_box_get_model (widget), &iter, ACCOUNT_DATA_COLUMN, &account, -1); if (oauth_account_cmp (account, web_service_get_current_account (WEB_SERVICE (data->service))) != 0) web_service_connect (WEB_SERVICE (data->service), account); g_object_unref (account); }
static void post_photo_file_buffer_ready_cb (void **buffer, gsize count, GError *error, gpointer user_data) { PicasaWebService *self = user_data; OAuthAccount *account; GthFileData *file_data; SoupMultipart *multipart; const char *filename; char *value; GObject *metadata; DomDocument *doc; DomElement *entry; char *entry_buffer; gsize entry_len; SoupMessageHeaders *headers; SoupBuffer *body; void *resized_buffer; gsize resized_count; char *url; SoupMessage *msg; if (error != NULL) { post_photos_done (self, error); return; } account = web_service_get_current_account (WEB_SERVICE (self)); file_data = self->priv->post_photos->current->data; multipart = soup_multipart_new ("multipart/related"); /* the metadata part */ doc = dom_document_new (); entry = dom_document_create_element (doc, "entry", "xmlns", "http://www.w3.org/2005/Atom", "xmlns:gphoto", "http://schemas.google.com/photos/2007", "xmlns:media", "http://search.yahoo.com/mrss/", NULL); filename = g_file_info_get_display_name (file_data->info); dom_element_append_child (entry, dom_document_create_element_with_text (doc, filename, "title", NULL)); value = gth_file_data_get_attribute_as_string (file_data, "general::description"); if (value == NULL) value = gth_file_data_get_attribute_as_string (file_data, "general::title"); dom_element_append_child (entry, dom_document_create_element_with_text (doc, value, "summary", NULL)); value = gth_file_data_get_attribute_as_string (file_data, "general::location"); if (value != NULL) dom_element_append_child (entry, dom_document_create_element_with_text (doc, value, "gphoto:location", NULL)); metadata = g_file_info_get_attribute_object (file_data->info, "general::tags"); if (metadata != NULL) value = gth_string_list_join (GTH_STRING_LIST (gth_metadata_get_string_list (GTH_METADATA (metadata))), ", "); if (value != NULL) { DomElement *group; group = dom_document_create_element (doc, "media:group", NULL); dom_element_append_child (group, dom_document_create_element_with_text (doc, value, "media:keywords", NULL)); dom_element_append_child (entry, group); g_free (value); } dom_element_append_child (entry, dom_document_create_element (doc, "category", "scheme", "http://schemas.google.com/g/2005#kind", "term", "http://schemas.google.com/photos/2007#photo", NULL)); dom_element_append_child (DOM_ELEMENT (doc), entry); entry_buffer = dom_document_dump (doc, &entry_len); headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_REQUEST); soup_message_headers_append (headers, "Content-Type", "application/atom+xml"); body = soup_buffer_new (SOUP_MEMORY_TAKE, entry_buffer, entry_len); soup_multipart_append_part (multipart, headers, body); soup_buffer_free (body); soup_message_headers_free (headers); g_object_unref (doc); /* the file part */ if (_g_buffer_resize_image (*buffer, count, file_data, self->priv->post_photos->max_width, self->priv->post_photos->max_height, &resized_buffer, &resized_count, self->priv->post_photos->cancellable, &error)) { body = soup_buffer_new (SOUP_MEMORY_TAKE, resized_buffer, resized_count); } else if (error == NULL) { body = soup_buffer_new (SOUP_MEMORY_TEMPORARY, *buffer, count); } else { soup_multipart_free (multipart); post_photos_done (self, error); return; } soup_multipart_append_form_file (multipart, "file", NULL, gth_file_data_get_mime_type (file_data), body); soup_buffer_free (body); /* send the file */ self->priv->post_photos->wrote_body_data_size = 0; url = g_strconcat ("https://picasaweb.google.com/data/feed/api/user/", account->id, "/albumid/", self->priv->post_photos->album->id, NULL); msg = soup_form_request_new_from_multipart (url, multipart); g_signal_connect (msg, "wrote-body-data", (GCallback) upload_photo_wrote_body_data_cb, self); _picasa_web_service_add_headers (self, msg); _web_service_send_message (WEB_SERVICE (self), msg, self->priv->post_photos->cancellable, self->priv->post_photos->callback, self->priv->post_photos->user_data, picasa_web_service_post_photos, post_photo_ready_cb, self); g_free (url); soup_multipart_free (multipart); }
static void completed_messagedialog_response_cb (GtkDialog *dialog, int response_id, gpointer user_data) { DialogData *data = user_data; switch (response_id) { case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CLOSE: gtk_widget_destroy (GTK_WIDGET (dialog)); gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); break; case _OPEN_IN_BROWSER_RESPONSE: { GdkScreen *screen; OAuthAccount *account; char *url = NULL; GError *error = NULL; screen = gtk_widget_get_screen (GTK_WIDGET (dialog)); gtk_widget_destroy (GTK_WIDGET (dialog)); account = web_service_get_current_account (WEB_SERVICE (data->service)); if (data->photoset == NULL) { GString *ids; GList *scan; ids = g_string_new (""); for (scan = data->photos_ids; scan; scan = scan->next) { if (scan != data->photos_ids) g_string_append (ids, ","); g_string_append (ids, (char *) scan->data); } url = g_strconcat (data->server->url, "/photos/upload/edit/?ids=", ids->str, NULL); g_string_free (ids, TRUE); } else if (data->photoset->url != NULL) url = g_strdup (data->photoset->url); else if (data->photoset->id != NULL) url = g_strconcat (data->server->url, "/photos/", account->id, "/sets/", data->photoset->id, NULL); if ((url != NULL) && ! gtk_show_uri (screen, url, 0, &error)) { if (data->service != NULL) gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); _gtk_error_dialog_from_gerror_run (GTK_WINDOW (data->browser), _("Could not connect to the server"), error); g_clear_error (&error); } gtk_dialog_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_DELETE_EVENT); g_free (url); } break; default: break; } }