Merge lp:~sil/gwibber/shorten-urls-async-521974 into lp:gwibber

Proposed by Stuart Langridge
Status: Merged
Merged at revision: not available
Proposed branch: lp:~sil/gwibber/shorten-urls-async-521974
Merge into: lp:gwibber
Diff against target: 36 lines (+24/-3)
1 file modified
gwibber/gwui.py (+24/-3)
To merge this branch: bzr merge lp:~sil/gwibber/shorten-urls-async-521974
Reviewer Review Type Date Requested Status
gwibber-committers Pending
Review via email: mp+19309@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stuart Langridge (sil) wrote :

Insert a placeholder character when pasting a URL for shortening, and then asynchronously replace the placeholder character with the shortened URL.

Easier to test if your network connection is being slow, so go and download some films over bittorrent or something and then try pasting a long URL into the post entry and continuing to type while it's fetching the shortened version.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/gwui.py'
2--- gwibber/gwui.py 2010-02-14 03:59:00 +0000
3+++ gwibber/gwui.py 2010-02-15 02:35:24 +0000
4@@ -844,9 +844,30 @@
5 buf = self.get_buffer()
6 buf.stop_emission("insert-text")
7 service = self.model.settings["urlshorter"] or "is.gd"
8- short = self.shortener.Shorten(text, service)
9- buf.insert(iter, short)
10-
11+
12+ def add_shortened(shortened_url):
13+ "Internal add-shortened-url-to-buffer function: a closure"
14+ iter_start = buf.get_iter_at_mark(mark_start)
15+ iter_end = buf.get_iter_at_mark(mark_end)
16+ buf.delete(iter_start, iter_end)
17+ buf.insert(iter_start, shortened_url)
18+ def error_shortened(dbus_exc):
19+ "Internal shortening-url-died function: a closure"
20+ iter = buf.get_iter_at_mark(mark)
21+ buf.insert(iter, text) # shortening failed
22+
23+ # set a mark at iter, so that the callback knows where to insert
24+ mark_start = buf.create_mark(None, iter, True)
25+ # insert a placeholder character
26+ buf.insert(iter, u"\u2328")
27+ # can't just get_insert() because that gets the *named* mark "insert"
28+ # and we want an anonymous mark so it won't get changed later
29+ iter_end = buf.get_iter_at_mark(buf.get_insert())
30+ mark_end = buf.create_mark(None, iter_end, True)
31+ self.shortener.Shorten(text, service,
32+ reply_handler=add_shortened,
33+ error_handler=error_shortened)
34+
35 def set_overlay_text(self, text):
36 self.pango_overlay.set_markup(self.overlay_text % (self.overlay_color, text))
37