changeset 5295eaad5f00 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=5295eaad5f00 description: Small cleanups for avatar save. Also fixes #5461.
* set default file type for avatars centrally * remove client side decision logic determing if a avatar loookup shall happen for a groupchat contact or for a normal contact * remove unused method (this one was triggering the traceback in #5461)
diffstat:
src/chat_control.py | 40 +++++++++++----------------------------- src/common/contacts.py | 8 -------- src/groupchat_control.py | 6 +++--- src/gtkgui_helpers.py | 45 +++++++++++++++++++++++---------------------- src/profile_window.py | 6 +++--- src/roster_window.py | 5 ++--- src/vcard.py | 6 ++---- 7 files changed, 44 insertions(+), 72 deletions(-)
diffs (297 lines):
diff -r cf87e39bc43c -r 5295eaad5f00 src/chat_control.py --- a/src/chat_control.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/chat_control.py Sun Nov 29 23:06:49 2009 +0100 @@ -1351,7 +1351,7 @@ # per jid self.show_bigger_avatar_timeout_id = None self.bigger_avatar_window = None - self.show_avatar(self.contact.resource) + self.show_avatar()
# chatstate timers and state self.reset_kbd_mouse_timeout_vars() @@ -1601,11 +1601,7 @@ bigger avatar after 0.5 sec """ jid = self.contact.jid - is_fake = False - if self.type_id == message_control.TYPE_PM: - is_fake = True - avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid, - is_fake) + avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) if avatar_pixbuf in ('ask', None): return avatar_w = avatar_pixbuf.get_width() @@ -1638,8 +1634,7 @@ menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) id_ = menuitem.connect('activate', gtkgui_helpers.on_avatar_save_as_menuitem_activate, - self.contact.jid, self.account, self.contact.get_shown_name() + \ - '.jpeg') + self.contact.jid, self.account, self.contact.get_shown_name()) self.handlers[id_] = menuitem menu.append(menuitem) menu.show_all() @@ -2403,24 +2398,12 @@ # Re-show the small avatar self.show_avatar()
- def show_avatar(self, resource = None): + def show_avatar(self): if not gajim.config.get('show_avatar_in_chat'): return - - is_fake = False - if self.TYPE_ID == message_control.TYPE_PM: - is_fake = True - jid_with_resource = self.contact.jid # fake jid - else: - jid_with_resource = self.contact.jid - if resource: - jid_with_resource += '/' + resource - - # we assume contact has no avatar - scaled_pixbuf = None - - pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource, - is_fake) + + jid_with_resource = self.contact.get_full_jid() + pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid_with_resource) if pixbuf == 'ask': # we don't have the vcard if self.TYPE_ID == message_control.TYPE_PM: @@ -2436,8 +2419,10 @@ else: gajim.connections[self.account].request_vcard(jid_with_resource) return - if pixbuf is not None: + elif pixbuf: scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'chat') + else: + scaled_pixbuf = None
image = self.xml.get_widget('avatar_image') image.set_from_pixbuf(scaled_pixbuf) @@ -2629,11 +2614,8 @@ if not small_avatar.window: # Tab has been closed since we hovered the avatar return - is_fake = False - if self.type_id == message_control.TYPE_PM: - is_fake = True avatar_pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache( - self.contact.jid, is_fake) + self.contact.jid) if avatar_pixbuf in ('ask', None): return # Hide the small avatar diff -r cf87e39bc43c -r 5295eaad5f00 src/common/contacts.py --- a/src/common/contacts.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/common/contacts.py Sun Nov 29 23:06:49 2009 +0100 @@ -373,14 +373,6 @@ nbr_total += 1 return nbr_online, nbr_total
- def is_pm_from_jid(self, account, jid): - """ - Return True if the given jid is a private message jid - """ - if jid in self._contacts[account]: - return False - return True - def __getattr__(self, attr_name): # Only called if self has no attr_name if hasattr(self._metacontact_manager, attr_name): diff -r cf87e39bc43c -r 5295eaad5f00 src/groupchat_control.py --- a/src/groupchat_control.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/groupchat_control.py Sun Nov 29 23:06:49 2009 +0100 @@ -1171,8 +1171,8 @@ iter_ = self.get_contact_iter(nick) if not iter_: return - pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(self.room_jid + \ - '/' + nick, True) + fake_jid = self.room_jid + '/' + nick + pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid) if pixbuf in ('ask', None): scaled_pixbuf = None else: @@ -1514,7 +1514,7 @@ if gajim.config.get('ask_avatars_on_startup') and \ not server.startswith('irc'): fake_jid = self.room_jid + '/' + nick - pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid, True) + pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(fake_jid) if pixbuf == 'ask': if j: fjid = j diff -r cf87e39bc43c -r 5295eaad5f00 src/gtkgui_helpers.py --- a/src/gtkgui_helpers.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/gtkgui_helpers.py Sun Nov 29 23:06:49 2009 +0100 @@ -30,6 +30,7 @@ import xml.sax.saxutils import gtk import gtk.glade +import glib import gobject import pango import os @@ -593,7 +594,7 @@ scaled_buf = pixbuf.scale_simple(w, h, gtk.gdk.INTERP_HYPER) return scaled_buf
-def get_avatar_pixbuf_from_cache(fjid, is_fake_jid = False, use_local = True): +def get_avatar_pixbuf_from_cache(fjid, use_local=True): """ Check if jid has cached avatar and if that avatar is valid image (can be shown) @@ -607,9 +608,15 @@ gajim.jid_is_transport(jid): # don't show avatar for the transport itself return None + + room, nick = gajim.get_room_and_nick_from_fjid(jid) + if any(room in gajim.contacts.get_gc_list(acc) for acc in gajim.connections): + is_groupchat_contact = True + else: + is_groupchat_contact = False
puny_jid = helpers.sanitize_filename(jid) - if is_fake_jid: + if is_groupchat_contact: puny_nick = helpers.sanitize_filename(nick) path = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid, @@ -631,7 +638,7 @@ return 'ask'
vcard_dict = gajim.connections.values()[0].get_cached_vcard(fjid, - is_fake_jid) + is_groupchat_contact) if not vcard_dict: # This can happen if cached vcard is too old return 'ask' if 'PHOTO' not in vcard_dict: @@ -831,39 +838,33 @@ def destroy_widget(widget): widget.destroy()
-def on_avatar_save_as_menuitem_activate(widget, jid, account, -default_name = ''): +def on_avatar_save_as_menuitem_activate(widget, jid, account, default_name=''): def on_continue(response, file_path): if response < 0: return - # Get pixbuf - pixbuf = None - is_fake = False - if account and gajim.contacts.is_pm_from_jid(account, jid): - is_fake = True - pixbuf = get_avatar_pixbuf_from_cache(jid, is_fake, False) - ext = file_path.split('.')[-1] - type_ = '' - if not ext: + pixbuf = get_avatar_pixbuf_from_cache(jid) + path, extension = os.path.splitext(file_path) + if not extension: # Silently save as Jpeg image + image_format = 'jpeg' file_path += '.jpeg' - type_ = 'jpeg' - elif ext == 'jpg': - type_ = 'jpeg' + elif extension == 'jpg': + image_format = 'jpeg' else: - type_ = ext + image_format = extension[1:] # remove leading dot
# Save image try: - pixbuf.save(file_path, type_) - except Exception: + pixbuf.save(file_path, image_format) + except glib.GError: if os.path.exists(file_path): os.remove(file_path) new_file_path = '.'.join(file_path.split('.')[:-1]) + '.jpeg' def on_ok(file_path, pixbuf): pixbuf.save(file_path, 'jpeg') dialogs.ConfirmationDialog(_('Extension not supported'), - _('Image cannot be saved in %(type)s format. Save as %(new_filename)s?') % {'type': type_, 'new_filename': new_file_path}, + _('Image cannot be saved in %(type)s format. Save as %(new_filename)s?' + ) % {'type': image_format, 'new_filename': new_file_path}, on_response_ok = (on_ok, new_file_path, pixbuf)) else: dialog.destroy() @@ -905,7 +906,7 @@ current_folder=gajim.config.get('last_save_dir'), on_response_ok=on_ok, on_response_cancel=on_cancel)
- dialog.set_current_name(default_name) + dialog.set_current_name(default_name + '.jpeg') dialog.connect('delete-event', lambda widget, event: on_cancel(widget))
diff -r cf87e39bc43c -r 5295eaad5f00 src/profile_window.py --- a/src/profile_window.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/profile_window.py Sun Nov 29 23:06:49 2009 +0100 @@ -183,14 +183,14 @@
# Try to get pixbuf pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(self.jid, - use_local = False) + use_local=False)
- if pixbuf: + if pixbuf not in (None, 'ask'): nick = gajim.config.get_per('accounts', self.account, 'name') menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) menuitem.connect('activate', gtkgui_helpers.on_avatar_save_as_menuitem_activate, - self.jid, None, nick + '.jpeg') + self.jid, self.account, nick) menu.append(menuitem) # show clear menuitem = gtk.ImageMenuItem(gtk.STOCK_CLEAR) diff -r cf87e39bc43c -r 5295eaad5f00 src/roster_window.py --- a/src/roster_window.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/roster_window.py Sun Nov 29 23:06:49 2009 +0100 @@ -1295,10 +1295,9 @@ iters = self._get_contact_iter(jid, account, model=self.model) if not iters or not gajim.config.get('show_avatars_in_roster'): return - jid = self.model[iters[0]][C_JID] - jid = jid.decode('utf-8') + jid = self.model[iters[0]][C_JID].decode('utf-8') pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid) - if pixbuf is None or pixbuf == 'ask': + if pixbuf in (None, 'ask'): scaled_pixbuf = None else: scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'roster') diff -r cf87e39bc43c -r 5295eaad5f00 src/vcard.py --- a/src/vcard.py Sun Nov 29 21:06:26 2009 +0100 +++ b/src/vcard.py Sun Nov 29 23:06:49 2009 +0100 @@ -164,8 +164,7 @@ menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) menuitem.connect('activate', gtkgui_helpers.on_avatar_save_as_menuitem_activate, - self.contact.jid, self.account, self.contact.get_shown_name() + - '.jpeg') + self.contact.jid, self.account, self.contact.get_shown_name()) menu.append(menuitem) menu.connect('selection-done', lambda w:w.destroy()) # show the menu @@ -480,8 +479,7 @@ menuitem = gtk.ImageMenuItem(gtk.STOCK_SAVE_AS) menuitem.connect('activate', gtkgui_helpers.on_avatar_save_as_menuitem_activate, - self.contact.jid, self.account, self.contact.get_shown_name() + - '.jpeg') + self.contact.jid, self.account, self.contact.get_shown_name()) menu.append(menuitem) menu.connect('selection-done', lambda w:w.destroy()) # show the menu