Merge lp:~sil/photobomb/publish-via-gwibber-upload into lp:photobomb

Proposed by Stuart Langridge
Status: Needs review
Proposed branch: lp:~sil/photobomb/publish-via-gwibber-upload
Merge into: lp:photobomb
Diff against target: 61 lines (+41/-3)
1 file modified
bin/photobomb (+41/-3)
To merge this branch: bzr merge lp:~sil/photobomb/publish-via-gwibber-upload
Reviewer Review Type Date Requested Status
Rick Spencer Pending
Review via email: mp+70232@code.launchpad.net

Description of the change

Publish files via Gwibber's Upload API, if it exists. This will use the user's preferred image publishing location, rather than having a separate one in photobomb, and it offloads all the hard work onto Gwibber.

Testing: make sure you have a newish gwibber (kenvandine's PPA has it for natty). Set your default image uploader to something other than imgur (not sure whether there is gwibber UI for this yet, or what the default in gwibber is, but I think it's yfrog). The image uploader service (if there's not gwibber UI for this) is set in dconf-editor, in /org/gwibber/preferences/image-uploader: you can set it to "ubuntuone" to use U1. Use the Micro Blog menu entry in photobomb to tweet about an image; the URL you get in the gwibber posting widget should be a URL from your chosen posting service, not imgur.

Testing, part 2: with an older gwibber, try using the Micro Blog entry: it should fall back to imgur exactly as it did before, thus not breaking older versions or people's expectations.

To post a comment you must log in.

Unmerged revisions

149. By Stuart Langridge

Use gwibber's Uploader API to publish images from photobomb, conditionally if it exists.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/photobomb'
2--- bin/photobomb 2011-07-09 15:09:02 +0000
3+++ bin/photobomb 2011-08-02 23:14:28 +0000
4@@ -39,6 +39,7 @@
5 import pycurl
6 import xml.dom.minidom
7 import Image
8+import dbus
9
10 # Check if we are working in the source tree or from the installed
11 # package and mangle the python path accordingly
12@@ -1052,9 +1053,46 @@
13 def micro_blog(self, widget, data=None):
14 if not os.path.exists(self.__temp_dir):
15 os.makedirs(self.__temp_dir)
16- temp_file = os.path.join(self.__temp_dir,"temp.png")
17- self.__create_image(temp_file)
18-
19+ self.__temp_file = os.path.join(self.__temp_dir,"temp.png")
20+ self.__create_image(self.__temp_file)
21+
22+ # first, let's try uploading with Gwibber, because that contains the
23+ # user's preferred place to publish images.
24+ try:
25+ uploader = dbus.SessionBus().get_object("com.Gwibber.Uploader",
26+ "/com/gwibber/Uploaderx")
27+ except dbus.exceptions.DBusException:
28+ # there's no gwibber uploader. So, fall back on the old imgur way.
29+ self._upload_with_imgur(self.__temp_file)
30+ else:
31+ self._u1_upload_complete_signal = uploader.connect_to_signal(
32+ "UploadComplete", self._u1_upload_complete_handler,
33+ dbus_interface="com.Gwibber.Uploader")
34+ self._u1_upload_failed_signal = uploader.connect_to_signal(
35+ "UploadFailed", self._u1_upload_failed_handler,
36+ dbus_interface="com.Gwibber.Uploader")
37+ try:
38+ uploader.Upload(self.__temp_file, dbus_interface="com.Gwibber.Uploader")
39+ except dbus.exceptions.DBusException:
40+ # gwibber uploader signature is wrong. So, fall back on the old imgur way.
41+ self._u1_upload_complete_signal.remove()
42+ self._u1_upload_failed_signal.remove()
43+ self._upload_with_imgur(self.__temp_file)
44+
45+ def _u1_upload_complete_handler(self, path, url):
46+ if self.__temp_file == path:
47+ self._u1_upload_complete_signal.remove()
48+ self._u1_upload_failed_signal.remove()
49+ gwib_win = MicroblogDialog.MicroblogDialog(url, self)
50+ response = gwib_win.show()
51+
52+ def _u1_upload_failed_handler(self, path, message):
53+ if self.__temp_file == path:
54+ self._u1_upload_complete_signal.remove()
55+ self._u1_upload_failed_signal.remove()
56+ quickly.prompts.error("Photobomb Error","Image upload failed\n\n" + str(message))
57+
58+ def _upload_with_imgur(self, temp_file):
59 c = pycurl.Curl()
60 values = [("key", self.__imgur_api_key),("image",(c.FORM_FILE,temp_file))]
61 c.setopt(c.URL, self.__imgur_url)

Subscribers

People subscribed via source and target branches

to all changes: