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); }
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_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); }
static void _oauth_service_get_access_token (OAuthService *self, const char *verifier, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GHashTable *data_set; SoupMessage *msg; data_set = g_hash_table_new (g_str_hash, g_str_equal); if (verifier != NULL) g_hash_table_insert (data_set, "oauth_verifier", (gpointer) verifier); oauth_service_add_signature (self, "POST", self->priv->consumer->access_token_url, data_set); msg = soup_form_request_new_from_hash ("POST", self->priv->consumer->access_token_url, data_set); _web_service_send_message (WEB_SERVICE (self), msg, cancellable, callback, user_data, _oauth_service_get_access_token, _oauth_service_get_access_token_ready_cb, self); g_hash_table_destroy (data_set); }
static void _oauth_service_get_access_token_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { OAuthService *self = user_data; GSimpleAsyncResult *result; SoupBuffer *body; result = _web_service_get_result (WEB_SERVICE (self)); if (msg->status_code != 200) { g_simple_async_result_set_error (result, SOUP_HTTP_ERROR, msg->status_code, "%s", soup_status_get_phrase (msg->status_code)); g_simple_async_result_complete_in_idle (result); return; } body = soup_message_body_flatten (msg->response_body); self->priv->consumer->access_token_response (self, msg, body, result); g_simple_async_result_complete_in_idle (result); soup_buffer_free (body); }
static void get_request_token_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { OAuthService *self = user_data; GError *error = NULL; char *url; GtkWidget *dialog; if (! oauth_service_get_request_token_finish (self, result, &error)) { gth_task_completed (GTH_TASK (self), error); return; } url = self->priv->consumer->get_authorization_url (self); dialog = oauth_ask_authorization_dialog_new (url); _gtk_window_resize_to_fit_screen_height (dialog, 1024); _web_service_set_auth_dialog (WEB_SERVICE (self), GTK_DIALOG (dialog)); g_signal_connect (OAUTH_ASK_AUTHORIZATION_DIALOG (dialog), "load-request", G_CALLBACK (ask_authorization_dialog_load_request_cb), self); gtk_widget_show (dialog); g_free (url); }
static void picasa_web_service_get_user_info_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)) { OAuthAccount *account; account = (OAuthAccount *) json_gobject_deserialize (OAUTH_TYPE_ACCOUNT, node); g_object_set (account, "token", self->priv->access_token, "token-secret", self->priv->refresh_token, NULL); g_simple_async_result_set_op_res_gpointer (result, g_object_ref (account), (GDestroyNotify) g_object_unref); _g_object_unref (account); json_node_free (node); } else g_simple_async_result_set_from_error (result, error); g_simple_async_result_complete_in_idle (result); }
static void web_service_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { WebService *self = WEB_SERVICE (object); switch (property_id) { case PROP_SERVICE_NAME: _g_strset (&self->priv->service_name, g_value_get_string (value)); break; case PROP_SERVICE_ADDRESS: _g_strset (&self->priv->service_address, g_value_get_string (value)); break; case PROP_SERVICE_PROTOCOL: _g_strset (&self->priv->service_protocol, g_value_get_string (value)); break; case PROP_ACCOUNT_TYPE: self->priv->account_type = g_value_get_gtype (value); break; case PROP_CANCELLABLE: _g_object_unref (self->priv->cancellable); self->priv->cancellable = g_value_dup_object (value); break; case PROP_BROWSER: self->priv->browser = g_value_get_pointer (value); break; case PROP_DIALOG: self->priv->dialog = g_value_get_pointer (value); break; default: break; } }
static void web_service_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { WebService *self = WEB_SERVICE (object); switch (property_id) { case PROP_SERVICE_NAME: g_value_set_string (value, self->priv->service_name); break; case PROP_SERVICE_ADDRESS: g_value_set_string (value, self->priv->service_address); break; case PROP_SERVICE_PROTOCOL: g_value_set_string (value, self->priv->service_protocol); break; case PROP_ACCOUNT_TYPE: g_value_set_gtype (value, self->priv->account_type); break; case PROP_CANCELLABLE: g_value_set_object (value, self->priv->cancellable); break; case PROP_BROWSER: g_value_set_pointer (value, self->priv->browser); break; case PROP_DIALOG: g_value_set_pointer (value, self->priv->dialog); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void access_token_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { AccessTokenData *data = user_data; PicasaWebService *self = data->service; GError *error = NULL; if (! _picasa_web_service_get_access_token_finish (self, result, &error)) { GSimpleAsyncResult *result; result = g_simple_async_result_new (G_OBJECT (self), data->callback, data->user_data, picasa_web_service_get_user_info); g_simple_async_result_take_error (result, error); g_simple_async_result_complete_in_idle (result); access_token_data_free (data); return; } /* call get_user_info again, now that we have the access token */ picasa_web_service_get_user_info (WEB_SERVICE (self), data->cancellable, data->callback, data->user_data); access_token_data_free (data); }
static void _picasa_web_service_get_access_token (PicasaWebService *self, const char *refresh_token, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GHashTable *data_set; SoupMessage *msg; _g_strset (&self->priv->access_token, NULL); data_set = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (data_set, "refresh_token", (gpointer) refresh_token); g_hash_table_insert (data_set, "client_id", GTHUMB_PICASA_WEB_CLIENT_ID); g_hash_table_insert (data_set, "client_secret", GTHUMB_PICASA_WEB_CLIENT_SECRET); g_hash_table_insert (data_set, "grant_type", "refresh_token"); msg = soup_form_request_new_from_hash ("POST", "https://accounts.google.com/o/oauth2/token", 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_access_token, _picasa_web_service_get_access_token_ready_cb, self); g_hash_table_destroy (data_set); }
static void edit_accounts_button_clicked_cb (GtkButton *button, gpointer user_data) { DialogData *data = user_data; web_service_edit_accounts (WEB_SERVICE (data->service), GTK_WINDOW (data->dialog)); }
static void web_service_constructed (GObject *object) { WebService *self = WEB_SERVICE (object); self->priv->accounts = oauth_accounts_load_from_file (self->priv->service_name, self->priv->account_type); self->priv->account = oauth_accounts_find_default (self->priv->accounts); if (G_OBJECT_CLASS (web_service_parent_class)->constructed != NULL) G_OBJECT_CLASS (web_service_parent_class)->constructed (object); }
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 web_service_cancelled (GthTask *base) { WebService *self = WEB_SERVICE (base); if ((self->priv->session == NULL) || (self->priv->msg == NULL)) return; soup_session_cancel_message (self->priv->session, self->priv->msg, SOUP_STATUS_CANCELLED); }
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 refresh_token_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { PicasaWebService *self = user_data; GError *error = NULL; GtkWidget *dialog; gboolean success; dialog = _web_service_get_auth_dialog (WEB_SERVICE (self)); success = _picasa_web_service_get_refresh_token_finish (self, result, &error); gtk_dialog_response (GTK_DIALOG (dialog), success ? GTK_RESPONSE_OK : GTK_RESPONSE_CANCEL); }
static void get_access_token_ready_cb (GObject *source_object, GAsyncResult *result, gpointer user_data) { OAuthService *self = user_data; GError *error = NULL; GtkWidget *dialog; OAuthAccount *account; dialog = _web_service_get_auth_dialog (WEB_SERVICE (self)); account = _oauth_service_get_access_token_finish (self, result, &error); if (account == NULL) { gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL); gth_task_completed (GTH_TASK (self), error); return; } web_service_set_current_account (WEB_SERVICE (self), account); gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); g_object_unref (account); }
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 web_service_finalize (GObject *object) { WebService *self = WEB_SERVICE (object); _g_object_unref (self->priv->account); _g_object_list_unref (self->priv->accounts); _g_object_unref (self->priv->result); _g_object_unref (self->priv->cancellable); _g_object_unref (self->priv->session); g_free (self->priv->service_protocol); g_free (self->priv->service_address); g_free (self->priv->service_name); G_OBJECT_CLASS (web_service_parent_class)->finalize (object); }
static void _oauth_service_get_request_token_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { OAuthService *self = user_data; GSimpleAsyncResult *result; SoupBuffer *body; GHashTable *values; char *token; char *token_secret; result = _web_service_get_result (WEB_SERVICE (self)); if (msg->status_code != 200) { g_simple_async_result_set_error (result, SOUP_HTTP_ERROR, msg->status_code, "%s", soup_status_get_phrase (msg->status_code)); g_simple_async_result_complete_in_idle (result); return; } body = soup_message_body_flatten (msg->response_body); values = soup_form_decode (body->data); token = g_hash_table_lookup (values, "oauth_token"); token_secret = g_hash_table_lookup (values, "oauth_token_secret"); if ((token != NULL) && (token_secret != NULL)) { oauth_service_set_token (self, token); oauth_service_set_token_secret (self, token_secret); g_simple_async_result_set_op_res_gboolean (result, TRUE); } else { GError *error; error = g_error_new_literal (WEB_SERVICE_ERROR, WEB_SERVICE_ERROR_GENERIC, _("Unknown error")); g_simple_async_result_set_from_error (result, error); } g_simple_async_result_complete_in_idle (result); g_hash_table_destroy (values); soup_buffer_free (body); }
static void picasa_web_service_ask_authorization (WebService *base) { PicasaWebService *self = PICASA_WEB_SERVICE (base); GtkWidget *dialog; _g_strset (&self->priv->refresh_token, NULL); _g_strset (&self->priv->access_token, NULL); dialog = oauth_ask_authorization_dialog_new (picasa_web_service_get_authorization_url (self)); gtk_window_set_default_size (GTK_WINDOW (dialog), 680, 580); _web_service_set_auth_dialog (WEB_SERVICE (self), GTK_DIALOG (dialog)); g_signal_connect (OAUTH_ASK_AUTHORIZATION_DIALOG (dialog), "loaded", G_CALLBACK (ask_authorization_dialog_loaded_cb), self); gtk_widget_show (dialog); }
static void create_album_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { PicasaWebService *self = user_data; GSimpleAsyncResult *result; SoupBuffer *body; DomDocument *doc; GError *error = NULL; result = _web_service_get_result (WEB_SERVICE (self)); if (msg->status_code != 201) { g_simple_async_result_set_error (result, SOUP_HTTP_ERROR, msg->status_code, "%s", soup_status_get_phrase (msg->status_code)); g_simple_async_result_complete_in_idle (result); return; } body = soup_message_body_flatten (msg->response_body); doc = dom_document_new (); if (dom_document_load (doc, body->data, body->length, &error)) { PicasaWebAlbum *album; album = picasa_web_album_new (); dom_domizable_load_from_element (DOM_DOMIZABLE (album), DOM_ELEMENT (doc)->first_child); g_simple_async_result_set_op_res_gpointer (result, album, (GDestroyNotify) g_object_unref); } else { g_simple_async_result_set_from_error (result, error); g_error_free (error); } g_simple_async_result_complete_in_idle (result); g_object_unref (doc); soup_buffer_free (body); }
static void post_photos_done (PicasaWebService *self, GError *error) { GSimpleAsyncResult *result; result = _web_service_get_result (WEB_SERVICE (self)); if (error == NULL) { g_simple_async_result_set_op_res_gboolean (result, TRUE); } else { if (self->priv->post_photos->current != NULL) { GthFileData *file_data = self->priv->post_photos->current->data; char *msg; msg = g_strdup_printf (_("Could not upload '%s': %s"), g_file_info_get_display_name (file_data->info), error->message); g_free (error->message); error->message = msg; } g_simple_async_result_set_from_error (result, error); } g_simple_async_result_complete_in_idle (result); }
void dlg_export_to_picasaweb (GthBrowser *browser, GList *file_list) { DialogData *data; GtkTreeSelection *selection; GList *scan; int n_total; goffset total_size; char *total_size_formatted; char *text; data = g_new0 (DialogData, 1); data->browser = browser; data->settings = g_settings_new (GTHUMB_PICASAWEB_SCHEMA); data->location = gth_file_data_dup (gth_browser_get_location_data (browser)); data->builder = _gtk_builder_new_from_file ("export-to-picasaweb.ui", "picasaweb"); data->dialog = _gtk_builder_get_widget (data->builder, "export_dialog"); data->cancellable = g_cancellable_new (); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("name_treeviewcolumn")); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", ALBUM_NAME_COLUMN, NULL); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", ALBUM_EMBLEM_COLUMN, NULL); } _gtk_window_resize_to_fit_screen_height (data->dialog, 500); data->file_list = NULL; n_total = 0; total_size = 0; for (scan = file_list; scan; scan = scan->next) { GthFileData *file_data = scan->data; const char *mime_type; mime_type = gth_file_data_get_mime_type (file_data); if (g_content_type_equals (mime_type, "image/bmp") || g_content_type_equals (mime_type, "image/gif") || g_content_type_equals (mime_type, "image/jpeg") || g_content_type_equals (mime_type, "image/png")) { total_size += g_file_info_get_size (file_data->info); n_total++; data->file_list = g_list_prepend (data->file_list, g_object_ref (file_data)); } } data->file_list = g_list_reverse (data->file_list); if (data->file_list == NULL) { GError *error; gth_task_dialog (GTH_TASK (data->service), TRUE, NULL); error = g_error_new_literal (GTH_ERROR, GTH_ERROR_GENERIC, _("No valid file selected.")); _gtk_error_dialog_from_gerror_show (GTK_WINDOW (browser), _("Could not export the files"), error); g_clear_error (&error); destroy_dialog (data); return; } total_size_formatted = g_format_size (total_size); text = g_strdup_printf (g_dngettext (NULL, "%d file (%s)", "%d files (%s)", n_total), n_total, total_size_formatted); gtk_label_set_text (GTK_LABEL (GET_WIDGET ("images_info_label")), text); g_free (text); g_free (total_size_formatted); /* Set the widget data */ data->list_view = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NO_SELECTION, FALSE); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->list_view), 112); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->list_view), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->list_view), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->list_view), gth_main_get_sort_type ("file::name")->cmp_func, FALSE); gtk_widget_show (data->list_view); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->list_view, TRUE, TRUE, 0); gth_file_list_set_files (GTH_FILE_LIST (data->list_view), data->file_list); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("album_liststore")), ALBUM_NAME_COLUMN, GTK_SORT_ASCENDING); gtk_widget_set_sensitive (GET_WIDGET ("upload_button"), FALSE); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("resize_checkbutton")), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH) != -1); _gtk_combo_box_add_image_sizes (GTK_COMBO_BOX (GET_WIDGET ("resize_combobox")), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_WIDTH), g_settings_get_int (data->settings, PREF_PICASAWEB_RESIZE_HEIGHT)); /* Set the signals handlers. */ g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (export_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("add_album_button"), "clicked", G_CALLBACK (add_album_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("resize_checkbutton"), "toggled", G_CALLBACK (resize_checkbutton_toggled_cb), data); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (GET_WIDGET ("albums_treeview"))); gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); g_signal_connect (selection, "changed", G_CALLBACK (albums_treeview_selection_changed_cb), data); update_sensitivity (data); data->service = picasa_web_service_new (data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (service_account_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (service_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service)); web_service_autoconnect (WEB_SERVICE (data->service)); }
void dlg_import_from_flickr (FlickrServer *server, GthBrowser *browser) { DialogData *data; GthThumbLoader *thumb_loader; char *title; data = g_new0 (DialogData, 1); data->server = server; data->browser = browser; data->location = gth_file_data_dup (gth_browser_get_location_data (browser)); data->builder = _gtk_builder_new_from_file ("import-from-flickr.ui", "flicker_utils"); data->dialog = _gtk_builder_get_widget (data->builder, "import_dialog"); data->cancellable = g_cancellable_new (); { GtkCellLayout *cell_layout; GtkCellRenderer *renderer; cell_layout = GTK_CELL_LAYOUT (GET_WIDGET ("photoset_combobox")); renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "icon-name", PHOTOSET_ICON_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, TRUE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", PHOTOSET_TITLE_COLUMN, NULL); renderer = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (cell_layout, renderer, FALSE); gtk_cell_layout_set_attributes (cell_layout, renderer, "text", PHOTOSET_N_PHOTOS_COLUMN, NULL); } /* Set the widget data */ data->file_list = gth_file_list_new (gth_grid_view_new (), GTH_FILE_LIST_MODE_NORMAL, FALSE); thumb_loader = gth_file_list_get_thumb_loader (GTH_FILE_LIST (data->file_list)); gth_thumb_loader_set_use_cache (thumb_loader, FALSE); gth_thumb_loader_set_loader_func (thumb_loader, flickr_thumbnail_loader); gth_file_list_set_thumb_size (GTH_FILE_LIST (data->file_list), FLICKR_SIZE_THUMBNAIL); gth_file_list_enable_thumbs (GTH_FILE_LIST (data->file_list), TRUE); gth_file_list_set_ignore_hidden (GTH_FILE_LIST (data->file_list), TRUE); gth_file_list_set_caption (GTH_FILE_LIST (data->file_list), "none"); gth_file_list_set_sort_func (GTH_FILE_LIST (data->file_list), flickr_photo_position_func, FALSE); gth_file_list_clear (GTH_FILE_LIST (data->file_list), _("No album selected")); gtk_widget_show (data->file_list); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("images_box")), data->file_list, TRUE, TRUE, 0); gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (GET_WIDGET ("photoset_liststore")), PHOTOSET_TITLE_COLUMN, GTK_SORT_ASCENDING); gtk_widget_set_sensitive (GET_WIDGET ("download_button"), FALSE); data->preferences_dialog = gth_import_preferences_dialog_new (); gtk_window_set_transient_for (GTK_WINDOW (data->preferences_dialog), GTK_WINDOW (data->dialog)); gtk_box_pack_start (GTK_BOX (GET_WIDGET ("destination_button_box")), gth_import_destination_button_new (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog)), TRUE, TRUE, 0); gtk_widget_show_all (GET_WIDGET ("destination_button_box")); title = g_strdup_printf (_("Import from %s"), data->server->display_name); gtk_window_set_title (GTK_WINDOW (data->dialog), title); g_free (title); _gtk_window_resize_to_fit_screen_height (data->dialog, 500); /* Set the signals handlers. */ g_signal_connect (data->dialog, "destroy", G_CALLBACK (import_dialog_destroy_cb), data); g_signal_connect (data->dialog, "delete-event", G_CALLBACK (gtk_true), NULL); g_signal_connect (data->dialog, "response", G_CALLBACK (import_dialog_response_cb), data); g_signal_connect (GET_WIDGET ("edit_accounts_button"), "clicked", G_CALLBACK (edit_accounts_button_clicked_cb), data); g_signal_connect (GET_WIDGET ("account_combobox"), "changed", G_CALLBACK (account_combobox_changed_cb), data); g_signal_connect (GET_WIDGET ("photoset_combobox"), "changed", G_CALLBACK (photoset_combobox_changed_cb), data); g_signal_connect (gth_file_list_get_view (GTH_FILE_LIST (data->file_list)), "file-selection-changed", G_CALLBACK (file_list_selection_changed_cb), data); update_selection_status (data); gth_import_preferences_dialog_set_event (GTH_IMPORT_PREFERENCES_DIALOG (data->preferences_dialog), ""); data->service = flickr_service_new (server, data->cancellable, GTK_WIDGET (data->browser), data->dialog); g_signal_connect (data->service, "account-ready", G_CALLBACK (authentication_ready_cb), data); g_signal_connect (data->service, "accounts-changed", G_CALLBACK (authentication_accounts_changed_cb), data); data->progress_dialog = gth_progress_dialog_new (GTK_WINDOW (data->browser)); gth_progress_dialog_add_task (GTH_PROGRESS_DIALOG (data->progress_dialog), GTH_TASK (data->service)); web_service_autoconnect (WEB_SERVICE (data->service)); }
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 list_albums_ready_cb (SoupSession *session, SoupMessage *msg, gpointer user_data) { PicasaWebService *self = user_data; GSimpleAsyncResult *result; SoupBuffer *body; DomDocument *doc; GError *error = NULL; result = _web_service_get_result (WEB_SERVICE (self)); if (msg->status_code != 200) { g_simple_async_result_set_error (result, SOUP_HTTP_ERROR, msg->status_code, "%s", soup_status_get_phrase (msg->status_code)); g_simple_async_result_complete_in_idle (result); return; } body = soup_message_body_flatten (msg->response_body); doc = dom_document_new (); if (dom_document_load (doc, body->data, body->length, &error)) { DomElement *feed_node; GList *albums = NULL; feed_node = DOM_ELEMENT (doc)->first_child; while ((feed_node != NULL) && g_strcmp0 (feed_node->tag_name, "feed") != 0) feed_node = feed_node->next_sibling; if (feed_node != NULL) { DomElement *node; PicasaWebAlbum *album; album = NULL; for (node = feed_node->first_child; node != NULL; node = node->next_sibling) { if (g_strcmp0 (node->tag_name, "entry") == 0) { /* read the album data */ if (album != NULL) albums = g_list_prepend (albums, album); album = picasa_web_album_new (); dom_domizable_load_from_element (DOM_DOMIZABLE (album), node); } else if (g_strcmp0 (node->tag_name, "gphoto:quotalimit") == 0) { self->priv->quota_limit = g_ascii_strtoull (dom_element_get_inner_text (node), NULL, 10); } else if (g_strcmp0 (node->tag_name, "gphoto:quotacurrent") == 0) { self->priv->quota_used = g_ascii_strtoull (dom_element_get_inner_text (node), NULL, 10); } } if (album != NULL) albums = g_list_prepend (albums, album); } albums = g_list_reverse (albums); g_simple_async_result_set_op_res_gpointer (result, albums, (GDestroyNotify) _g_object_list_unref); } else { g_simple_async_result_set_from_error (result, error); g_error_free (error); } g_simple_async_result_complete_in_idle (result); g_object_unref (doc); soup_buffer_free (body); }