diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-06-14 20:35:58 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-06-14 20:35:58 +0200 |
commit | d443a3c2509889533ca812c163056bace396b586 (patch) | |
tree | e94ffc0d9c054ca4efb8fb327e18dfac88e15dc7 /plugins/shotwell-publishing/TumblrPublishing.vala | |
parent | bb9797c14470641b082ebf635e2ae3cfd5f27a3b (diff) |
New upstream version 0.32.1upstream/0.32.1
Diffstat (limited to 'plugins/shotwell-publishing/TumblrPublishing.vala')
-rw-r--r-- | plugins/shotwell-publishing/TumblrPublishing.vala | 152 |
1 files changed, 49 insertions, 103 deletions
diff --git a/plugins/shotwell-publishing/TumblrPublishing.vala b/plugins/shotwell-publishing/TumblrPublishing.vala index 7061d6d..c9fed3f 100644 --- a/plugins/shotwell-publishing/TumblrPublishing.vala +++ b/plugins/shotwell-publishing/TumblrPublishing.vala @@ -6,16 +6,7 @@ */ public class TumblrService : Object, Spit.Pluggable, Spit.Publishing.Service { - private const string ICON_FILENAME = "tumblr.png"; - - private static Gdk.Pixbuf[] icon_pixbuf_set = null; - - public TumblrService(GLib.File resource_directory) { - if (icon_pixbuf_set == null) - icon_pixbuf_set = - Resources.load_from_resource(Resources.RESOURCE_PATH + "/" + - ICON_FILENAME); - } + public TumblrService() {} public int get_pluggable_interface(int min_host_interface, int max_host_interface) { return Spit.negotiate_interfaces(min_host_interface, max_host_interface, @@ -23,23 +14,21 @@ public class TumblrService : Object, Spit.Pluggable, Spit.Publishing.Service { } public unowned string get_id() { - return "org.yorba.shotwell.publishing.tumblr"; + return "org.gnome.shotwell.publishing.tumblr"; } public unowned string get_pluggable_name() { return "Tumblr"; } - public void get_info(ref Spit.PluggableInfo info) { + public Spit.PluggableInfo get_info() { + var info = new Spit.PluggableInfo(); + info.authors = "Jeroen Arnoldus"; info.copyright = _("Copyright 2012 BJA Electronics"); - info.translators = Resources.TRANSLATORS; - info.version = _VERSION; - info.website_name = Resources.WEBSITE_NAME; - info.website_url = Resources.WEBSITE_URL; - info.is_license_wordwrapped = false; - info.license = Resources.LICENSE; - info.icons = icon_pixbuf_set; + info.icon_name = "tumblr"; + + return info; } public void activation(bool enabled) { @@ -189,72 +178,47 @@ namespace Publishing.Tumblr { auth_token_secret.get_string(), ""); - do_get_blogs(); + do_get_blogs.begin(); } - private void do_get_blogs() { + private async void do_get_blogs() { debug("ACTION: obtain all blogs of the tumblr user"); UserInfoFetchTransaction txn = new UserInfoFetchTransaction(session); - txn.completed.connect(on_info_request_txn_completed); - txn.network_error.connect(on_info_request_txn_error); try { - txn.execute(); - } catch (Spit.Publishing.PublishingError err) { + yield txn.execute_async(); + if (!is_running()) + return; + + debug("EVENT: user info request transaction completed; response = '%s'", + txn.get_response()); + do_parse_token_info_from_user_request(txn.get_response()); + do_show_publishing_options_pane(); + } catch (Error err) { + session.deauthenticate(); + //invalidate_persistent_session(); + debug("EVENT: user info request transaction caused a network error"); host.post_error(err); } - - } - - private void on_info_request_txn_completed(Publishing.RESTSupport.Transaction txn) { - txn.completed.disconnect(on_info_request_txn_completed); - txn.network_error.disconnect(on_info_request_txn_error); - - if (!is_running()) - return; - - debug("EVENT: user info request transaction completed; response = '%s'", - txn.get_response()); - do_parse_token_info_from_user_request(txn.get_response()); - do_show_publishing_options_pane(); - } - - - private void do_parse_token_info_from_user_request(string response) { + private void do_parse_token_info_from_user_request(string response) throws Error { debug("ACTION: parsing info request response '%s' into list of available blogs", response); - try { - var parser = new Json.Parser(); - parser.load_from_data (response, -1); - var root_object = parser.get_root().get_object(); - this.username = root_object.get_object_member("response").get_object_member("user").get_string_member ("name"); - debug("Got user name: %s",username); - foreach (var blognode in root_object.get_object_member("response").get_object_member("user").get_array_member("blogs").get_elements ()) { - var blog = blognode.get_object (); - string name = blog.get_string_member ("name"); - string url = blog.get_string_member ("url").replace("http://","").replace("https://", "").replace("/",""); - debug("Got blog name: %s and url: %s", name, url); - this.blogs += new BlogEntry(name,url); - } - } catch (Error err) { - host.post_error(err); + + var parser = new Json.Parser(); + parser.load_from_data (response, -1); + var root_object = parser.get_root().get_object(); + this.username = root_object.get_object_member("response").get_object_member("user").get_string_member ("name"); + debug("Got user name: %s",username); + foreach (var blognode in root_object.get_object_member("response").get_object_member("user").get_array_member("blogs").get_elements ()) { + var blog = blognode.get_object (); + string name = blog.get_string_member ("name"); + string url = blog.get_string_member ("url").replace("http://","").replace("https://", "").replace("/",""); + debug("Got blog name: %s and url: %s", name, url); + this.blogs += new BlogEntry(name,url); } } - private void on_info_request_txn_error(Publishing.RESTSupport.Transaction txn, - Spit.Publishing.PublishingError err) { - txn.completed.disconnect(on_info_request_txn_completed); - txn.network_error.disconnect(on_info_request_txn_error); - - if (!is_running()) - return; - - session.deauthenticate(); - //invalidate_persistent_session(); - debug("EVENT: user info request transaction caused a network error"); - host.post_error(err); - } private void do_show_publishing_options_pane() { debug("ACTION: displaying publishing options pane"); @@ -328,7 +292,7 @@ namespace Publishing.Tumblr { Uploader uploader = new Uploader(session, sorted_list.to_array(),blog_url); uploader.upload_complete.connect(on_upload_complete); uploader.upload_error.connect(on_upload_error); - uploader.upload(on_upload_status_updated); + uploader.upload_async.begin(on_upload_status_updated); } private void do_show_success_pane() { @@ -575,22 +539,6 @@ namespace Publishing.Tumblr { internal class UploadTransaction : Publishing.RESTSupport.OAuth1.UploadTransaction { //Workaround for Soup.URI.encode() to support binary data (i.e. string with \0) - private string encode( uint8[] data ){ - var s = new StringBuilder(); - char[] bytes = new char[2]; - bytes[1] = 0; - foreach( var byte in data ) - { - if(byte == 0) { - s.append( "%00" ); - } else { - bytes[0] = (char)byte; - s.append( Soup.URI.encode((string) bytes, ENCODE_RFC_3986_EXTRA) ); - } - } - return s.str; - } - public UploadTransaction(Publishing.RESTSupport.OAuth1.Session session,Spit.Publishing.Publishable publishable, string blog_url) { debug("Init upload transaction"); @@ -598,25 +546,21 @@ namespace Publishing.Tumblr { } - public override void execute() throws Spit.Publishing.PublishingError { + public override async void execute_async() throws Spit.Publishing.PublishingError { string payload; size_t payload_length; try { FileUtils.get_contents(base.publishable.get_serialized_file().get_path(), out payload, out payload_length); - string reqdata = this.encode(payload.data[0:payload_length]); - - - - add_argument("data[0]", reqdata); + add_argument("data64", Base64.encode(payload.data[0:payload_length])); add_argument("type", "photo"); string[] keywords = base.publishable.get_publishing_keywords(); string tags = ""; if (keywords != null) { tags = string.joinv (",", keywords); } - add_argument("tags", Soup.URI.encode(tags, ENCODE_RFC_3986_EXTRA)); + add_argument("tags", tags); } catch (FileError e) { throw new Spit.Publishing.PublishingError.LOCAL_FILE_ERROR( @@ -626,13 +570,15 @@ namespace Publishing.Tumblr { this.authorize(); - Publishing.RESTSupport.Argument[] request_arguments = get_arguments(); - assert(request_arguments.length > 0); - - var request_data = Publishing.RESTSupport.Argument.serialize_list(request_arguments); + var form = new GLib.HashTable<string, string>(GLib.str_hash, GLib.str_equal); + foreach (var arg in get_arguments()) { + form.insert(arg.key, arg.value); + } + assert(form.size() > 0); - Soup.Message outbound_message = new Soup.Message( "POST", get_endpoint_url()); - outbound_message.set_request("application/x-www-form-urlencoded", Soup.MemoryUse.COPY, request_data.data); + var outbound_message = new Soup.Message ("POST", get_endpoint_url()); + var body = new Bytes(Soup.Form.encode_hash(form).data); + outbound_message.set_request_body_from_bytes(Soup.FORM_MIME_TYPE_URLENCODED, body); // TODO: there must be a better way to iterate over a map Gee.MapIterator<string, string> i = base.message_headers.map_iterator(); @@ -641,11 +587,11 @@ namespace Publishing.Tumblr { outbound_message.request_headers.append(i.get_key(), i.get_value()); cont = i.next(); } - set_message(outbound_message); + set_message(outbound_message, body.length); set_is_executed(true); - send(); + yield send_async(); } } |