if we have avatar in HD, we get it from there now
This commit is contained in:
parent
89d00ada0d
commit
ee46edcfb8
File diff suppressed because it is too large
Load Diff
58
src/gajim.py
58
src/gajim.py
|
@ -26,6 +26,8 @@ import sys
|
||||||
import pygtk
|
import pygtk
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import common.BeautifulSoup as BeautifulSoup
|
||||||
|
|
||||||
from common import i18n
|
from common import i18n
|
||||||
i18n.init()
|
i18n.init()
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
|
@ -661,7 +663,6 @@ class Interface:
|
||||||
'''vcard holds the vcard data'''
|
'''vcard holds the vcard data'''
|
||||||
jid = vcard['jid']
|
jid = vcard['jid']
|
||||||
resource = vcard['resource']
|
resource = vcard['resource']
|
||||||
self.store_avatar(vcard)
|
|
||||||
|
|
||||||
# vcard window
|
# vcard window
|
||||||
win = None
|
win = None
|
||||||
|
@ -670,7 +671,7 @@ class Interface:
|
||||||
elif self.windows[account]['infos'].has_key(jid + '/' + resource):
|
elif self.windows[account]['infos'].has_key(jid + '/' + resource):
|
||||||
win = self.windows[account]['infos'][jid + '/' + resource]
|
win = self.windows[account]['infos'][jid + '/' + resource]
|
||||||
if win:
|
if win:
|
||||||
win.set_values(vcard) #FIXME: maybe store all vcard data?
|
win.set_values(vcard)
|
||||||
|
|
||||||
# show avatar in chat
|
# show avatar in chat
|
||||||
win = None
|
win = None
|
||||||
|
@ -679,6 +680,7 @@ class Interface:
|
||||||
elif self.windows[account]['chats'].has_key(jid + '/' + resource):
|
elif self.windows[account]['chats'].has_key(jid + '/' + resource):
|
||||||
win = self.windows[account]['chats'][jid + '/' + resource]
|
win = self.windows[account]['chats'][jid + '/' + resource]
|
||||||
if win:
|
if win:
|
||||||
|
# FIXME: this will be removed when we have the thread working
|
||||||
win.show_avatar(jid, resource)
|
win.show_avatar(jid, resource)
|
||||||
if self.remote is not None:
|
if self.remote is not None:
|
||||||
self.remote.raise_signal('VcardInfo', (account, vcard))
|
self.remote.raise_signal('VcardInfo', (account, vcard))
|
||||||
|
@ -943,32 +945,41 @@ class Interface:
|
||||||
def handle_event_vcard_not_published(self, account, array):
|
def handle_event_vcard_not_published(self, account, array):
|
||||||
dialogs.InformationDialog(_('vCard publication failed'), _('There was an error while publishing your personal information, try again later.'))
|
dialogs.InformationDialog(_('vCard publication failed'), _('There was an error while publishing your personal information, try again later.'))
|
||||||
|
|
||||||
def store_avatar(self, vcard):
|
def get_avatar_pixbuf(self, jid):
|
||||||
'''stores avatar per jid so we do not have to ask everytime for vcard'''
|
'''checks if jid has avatar and if that avatar is valid image
|
||||||
jid = vcard['jid']
|
(can be shown)'''
|
||||||
# we assume contact has no avatar
|
if jid not in os.listdir(gajim.VCARDPATH):
|
||||||
self.avatar_pixbufs[jid] = None
|
|
||||||
if not vcard.has_key('PHOTO'):
|
|
||||||
return
|
return
|
||||||
if not isinstance(vcard['PHOTO'], dict):
|
|
||||||
return
|
path_to_file = os.path.join(gajim.VCARDPATH, jid)
|
||||||
img_decoded = None
|
vcard_data = open(path_to_file).read()
|
||||||
if vcard['PHOTO'].has_key('BINVAL'):
|
xmldoc = BeautifulSoup.BeautifulSoup(vcard_data)
|
||||||
try:
|
|
||||||
img_decoded = base64.decodestring(vcard['PHOTO']['BINVAL'])
|
# check for BINVAL
|
||||||
except:
|
if isinstance(xmldoc.vcard.photo.binval, BeautifulSoup.NullType):
|
||||||
pass
|
# no BINVAL, check for EXTVAL
|
||||||
elif vcard['PHOTO'].has_key('EXTVAL'):
|
if isinstance(xmldoc.vcard.photo.extval, BeautifulSoup.NullType):
|
||||||
url = vcard['PHOTO']['EXTVAL']
|
return # no EXTVAL, contact has no avatar in his vcard
|
||||||
|
else:
|
||||||
|
# we have EXTVAL
|
||||||
|
url = xmldoc.vcard.photo.extval
|
||||||
try:
|
try:
|
||||||
fd = urllib.urlopen(url)
|
fd = urllib.urlopen(url)
|
||||||
img_decoded = fd.read()
|
img_decoded = fd.read()
|
||||||
except:
|
except:
|
||||||
pass
|
img_decoded = None
|
||||||
if img_decoded:
|
|
||||||
|
else:
|
||||||
|
# we have BINVAL
|
||||||
|
try:
|
||||||
|
text = xmldoc.vcard.photo.binval.string
|
||||||
|
img_decoded = base64.decodestring(text)
|
||||||
|
except:
|
||||||
|
img_decoded = None
|
||||||
|
|
||||||
|
if img_decoded is not None:
|
||||||
pixbuf = gtkgui_helpers.get_pixbuf_from_data(img_decoded)
|
pixbuf = gtkgui_helpers.get_pixbuf_from_data(img_decoded)
|
||||||
# store avatar for jid
|
return pixbuf
|
||||||
self.avatar_pixbufs[jid] = pixbuf
|
|
||||||
|
|
||||||
def read_sleepy(self):
|
def read_sleepy(self):
|
||||||
'''Check idle status and change that status if needed'''
|
'''Check idle status and change that status if needed'''
|
||||||
|
@ -1286,9 +1297,6 @@ class Interface:
|
||||||
|
|
||||||
self.windows = {'logs': {}}
|
self.windows = {'logs': {}}
|
||||||
|
|
||||||
# keep avatar (pixbuf) per jid
|
|
||||||
self.avatar_pixbufs = {}
|
|
||||||
|
|
||||||
for a in gajim.connections:
|
for a in gajim.connections:
|
||||||
self.windows[a] = {'infos': {}, 'disco': {}, 'chats': {},
|
self.windows[a] = {'infos': {}, 'disco': {}, 'chats': {},
|
||||||
'gc': {}, 'gc_config': {}}
|
'gc': {}, 'gc_config': {}}
|
||||||
|
|
|
@ -285,7 +285,7 @@ def get_abspath_for_script(scriptname, want_type = False):
|
||||||
return path_to_script
|
return path_to_script
|
||||||
|
|
||||||
def get_pixbuf_from_data(file_data):
|
def get_pixbuf_from_data(file_data):
|
||||||
'''wants img data and returns gtk.gdk.Pixbuf'''
|
'''Gets image data and returns gtk.gdk.Pixbuf'''
|
||||||
pixbufloader = gtk.gdk.PixbufLoader()
|
pixbufloader = gtk.gdk.PixbufLoader()
|
||||||
try:
|
try:
|
||||||
pixbufloader.write(file_data)
|
pixbufloader.write(file_data)
|
||||||
|
|
|
@ -131,7 +131,7 @@ class TabbedChatWindow(chat.Chat):
|
||||||
'''we enter the eventbox area so we under conditions add a timeout
|
'''we enter the eventbox area so we under conditions add a timeout
|
||||||
to show a bigger avatar after 0.5 sec'''
|
to show a bigger avatar after 0.5 sec'''
|
||||||
jid = self.get_active_jid()
|
jid = self.get_active_jid()
|
||||||
avatar_pixbuf = gajim.interface.avatar_pixbufs[jid]
|
avatar_pixbuf = gajim.interface.get_avatar_pixbuf(jid)
|
||||||
avatar_w = avatar_pixbuf.get_width()
|
avatar_w = avatar_pixbuf.get_width()
|
||||||
avatar_h = avatar_pixbuf.get_height()
|
avatar_h = avatar_pixbuf.get_height()
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class TabbedChatWindow(chat.Chat):
|
||||||
'''resizes the avatar, if needed, so it has at max half the screen size
|
'''resizes the avatar, if needed, so it has at max half the screen size
|
||||||
and shows it'''
|
and shows it'''
|
||||||
jid = self.get_active_jid()
|
jid = self.get_active_jid()
|
||||||
avatar_pixbuf = gajim.interface.avatar_pixbufs[jid]
|
avatar_pixbuf = gajim.interface.get_avatar_pixbuf(jid)
|
||||||
screen_w = gtk.gdk.screen_width()
|
screen_w = gtk.gdk.screen_width()
|
||||||
screen_h = gtk.gdk.screen_height()
|
screen_h = gtk.gdk.screen_height()
|
||||||
avatar_w = avatar_pixbuf.get_width()
|
avatar_w = avatar_pixbuf.get_width()
|
||||||
|
@ -290,12 +290,11 @@ class TabbedChatWindow(chat.Chat):
|
||||||
if not xml:
|
if not xml:
|
||||||
return
|
return
|
||||||
|
|
||||||
if gajim.interface.avatar_pixbufs[jid] is None:
|
# we assume contact has no avatar
|
||||||
# contact has no avatar
|
|
||||||
scaled_buf = None
|
scaled_buf = None
|
||||||
else:
|
|
||||||
pixbuf = gajim.interface.avatar_pixbufs[jid]
|
|
||||||
|
|
||||||
|
pixbuf = gajim.interface.get_avatar_pixbuf(jid)
|
||||||
|
if pixbuf is not None:
|
||||||
# resize to a width / height for the avatar not to have distortion
|
# resize to a width / height for the avatar not to have distortion
|
||||||
# (keep aspect ratio)
|
# (keep aspect ratio)
|
||||||
ratio = float(pixbuf.get_width()) / float(pixbuf.get_height())
|
ratio = float(pixbuf.get_width()) / float(pixbuf.get_height())
|
||||||
|
@ -438,7 +437,6 @@ class TabbedChatWindow(chat.Chat):
|
||||||
self.childs[contact.jid] = self.xmls[contact.jid].get_widget('chats_vbox')
|
self.childs[contact.jid] = self.xmls[contact.jid].get_widget('chats_vbox')
|
||||||
self.contacts[contact.jid] = contact
|
self.contacts[contact.jid] = contact
|
||||||
|
|
||||||
|
|
||||||
# add MessageTextView to UI
|
# add MessageTextView to UI
|
||||||
message_scrolledwindow = self.xmls[contact.jid].get_widget(
|
message_scrolledwindow = self.xmls[contact.jid].get_widget(
|
||||||
'message_scrolledwindow')
|
'message_scrolledwindow')
|
||||||
|
@ -448,19 +446,13 @@ class TabbedChatWindow(chat.Chat):
|
||||||
self.on_message_textview_mykeypress_event)
|
self.on_message_textview_mykeypress_event)
|
||||||
message_scrolledwindow.add(msg_textview)
|
message_scrolledwindow.add(msg_textview)
|
||||||
|
|
||||||
#FIXME: request in thread or idle and show in roster
|
|
||||||
|
|
||||||
# this is to prove cache code works:
|
|
||||||
# should we ask vcard? (only the first time we should ask)
|
# should we ask vcard? (only the first time we should ask)
|
||||||
if not gajim.interface.avatar_pixbufs.has_key(contact.jid):
|
if contact.jid in os.listdir(gajim.VCARDPATH):
|
||||||
|
# show avatar from HD
|
||||||
|
self.show_avatar(contact.jid, contact.resource)
|
||||||
|
else:
|
||||||
# it's the first time, so we should ask vcard
|
# it's the first time, so we should ask vcard
|
||||||
gajim.connections[self.account].request_vcard(contact.jid)
|
gajim.connections[self.account].request_vcard(contact.jid)
|
||||||
#please do not remove this commented print until I'm done with showing
|
|
||||||
#avatars in roster
|
|
||||||
#print 'REQUESTING VCARD for', contact.jid
|
|
||||||
else:
|
|
||||||
# show avatar from stored place
|
|
||||||
self.show_avatar(contact.jid, contact.resource)
|
|
||||||
|
|
||||||
self.childs[contact.jid].connect('drag_data_received',
|
self.childs[contact.jid].connect('drag_data_received',
|
||||||
self.on_drag_data_received, contact)
|
self.on_drag_data_received, contact)
|
||||||
|
|
Loading…
Reference in New Issue