use proxy in url_preview plugin. Fixes #15
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
[info]
|
[info]
|
||||||
name: Url image preview
|
name: Url image preview
|
||||||
short_name: url_image_preview
|
short_name: url_image_preview
|
||||||
version: 0.2
|
version: 0.3
|
||||||
description: Url image preview in chatbox.
|
description: Url image preview in chatbox.
|
||||||
Based on patch in ticket #5300:
|
Based on patch in ticket #5300:
|
||||||
http://trac.gajim.org/attachment/ticket/5300.
|
http://trac.gajim.org/attachment/ticket/5300.
|
||||||
authors = Denis Fomin <fominde@gmail.com>
|
authors = Denis Fomin <fominde@gmail.com>
|
||||||
|
Yann Leboulanger <asterix@lagaule.org>
|
||||||
homepage = http://trac-plugins.gajim.org/wiki/UrlImagePreviewPlugin
|
homepage = http://trac-plugins.gajim.org/wiki/UrlImagePreviewPlugin
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import os
|
|||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
from common import gajim
|
from common import gajim
|
||||||
|
from common import helpers
|
||||||
from plugins import GajimPlugin
|
from plugins import GajimPlugin
|
||||||
from plugins.helpers import log_calls
|
from plugins.helpers import log_calls
|
||||||
from plugins.gui import GajimPluginConfigDialog
|
from plugins.gui import GajimPluginConfigDialog
|
||||||
@@ -81,36 +82,29 @@ class Base(object):
|
|||||||
buffer_ = self.textview.tv.get_buffer()
|
buffer_ = self.textview.tv.get_buffer()
|
||||||
iter_ = buffer_.get_end_iter()
|
iter_ = buffer_.get_end_iter()
|
||||||
mark = buffer_.create_mark(None, iter_, True)
|
mark = buffer_.create_mark(None, iter_, True)
|
||||||
gajim.thread_interface(self.insert_pic_preview, [mark, special_text,
|
# start downloading image
|
||||||
special_text])
|
gajim.thread_interface(helpers.download_image, [
|
||||||
|
self.textview.account, {'src': url}], self._update_img, [mark])
|
||||||
|
|
||||||
def insert_pic_preview(self, mark, special_text, url):
|
def _update_img(self, (mem, alt), mark):
|
||||||
pixbuf = self.get_pixbuf_from_url( url, self.plugin.config[
|
if mem:
|
||||||
'PREVIEW_SIZE'])
|
try:
|
||||||
if pixbuf:
|
loader = gtk.gdk.PixbufLoader()
|
||||||
# insert image
|
loader.write(mem)
|
||||||
buffer_ = mark.get_buffer()
|
loader.close()
|
||||||
end_iter = buffer_.get_iter_at_mark(mark)
|
pixbuf = loader.get_pixbuf()
|
||||||
anchor = buffer_.create_child_anchor(end_iter)
|
pixbuf.save('qwe.jpg', 'jpeg', {"quality":"100"})
|
||||||
img = TextViewImage(anchor, special_text)
|
pixbuf, w, h = self.get_pixbuf_of_size(pixbuf,
|
||||||
img.set_from_pixbuf(pixbuf)
|
self.plugin.config['PREVIEW_SIZE'])
|
||||||
img.show()
|
buffer_ = mark.get_buffer()
|
||||||
self.textview.tv.add_child_at_anchor(img, anchor)
|
end_iter = buffer_.get_iter_at_mark(mark)
|
||||||
|
anchor = buffer_.create_child_anchor(end_iter)
|
||||||
|
img = TextViewImage(anchor, alt)
|
||||||
def get_pixbuf_from_url(self, url, size):
|
img.set_from_pixbuf(pixbuf)
|
||||||
# download image and resize
|
img.show()
|
||||||
# Returns pixbuf or False if broken image or not connected
|
self.textview.tv.add_child_at_anchor(img, anchor)
|
||||||
try:
|
except Exception:
|
||||||
data = urllib.urlopen(url).read()
|
pass
|
||||||
pix = gtk.gdk.PixbufLoader()
|
|
||||||
pix.write(data)
|
|
||||||
pix.close()
|
|
||||||
pixbuf = pix.get_pixbuf()
|
|
||||||
pixbuf, w, h = self.get_pixbuf_of_size(pixbuf, size)
|
|
||||||
except:
|
|
||||||
return False
|
|
||||||
return pixbuf
|
|
||||||
|
|
||||||
def get_pixbuf_of_size(self, pixbuf, size):
|
def get_pixbuf_of_size(self, pixbuf, size):
|
||||||
# Creates a pixbuf that fits in the specified square of sizexsize
|
# Creates a pixbuf that fits in the specified square of sizexsize
|
||||||
|
|||||||
Reference in New Issue
Block a user