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) Returns None if there is no image in vcard/ Returns 'ask' if cached vcard should not be used (user changed his vcard, so we have new sha) or if we don't have the vcard """ jid, nick = gajim.get_room_and_nick_from_fjid(fjid) if gajim.config.get('hide_avatar_of_transport') and\ gajim.jid_is_transport(jid): # don't show avatar for the transport itself return None if any(jid in gajim.contacts.get_gc_list(acc) for acc in \ gajim.contacts.get_accounts()): is_groupchat_contact = True else: is_groupchat_contact = False puny_jid = helpers.sanitize_filename(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, puny_nick) + '_local' else: path = os.path.join(gajim.VCARD_PATH, puny_jid) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid) + \ '_local' if use_local: for extension in ('.png', '.jpeg'): local_avatar_path = local_avatar_basepath + extension if os.path.isfile(local_avatar_path): avatar_file = open(local_avatar_path, 'rb') avatar_data = avatar_file.read() avatar_file.close() return get_pixbuf_from_data(avatar_data) if not os.path.isfile(path): return 'ask' vcard_dict = gajim.connections.values()[0].get_cached_vcard(fjid, is_groupchat_contact) if not vcard_dict: # This can happen if cached vcard is too old return 'ask' if 'PHOTO' not in vcard_dict: return None pixbuf = vcard.get_avatar_pixbuf_encoded_mime(vcard_dict['PHOTO'])[0] return pixbuf
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) Returns None if there is no image in vcard/ Returns 'ask' if cached vcard should not be used (user changed his vcard, so we have new sha) or if we don't have the vcard """ jid, nick = gajim.get_room_and_nick_from_fjid(fjid) if gajim.config.get('hide_avatar_of_transport') and\ gajim.jid_is_transport(jid): # don't show avatar for the transport itself return None if any(jid in gajim.contacts.get_gc_list(acc) for acc in \ gajim.contacts.get_accounts()): is_groupchat_contact = True else: is_groupchat_contact = False puny_jid = helpers.sanitize_filename(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, puny_nick) + '_local' else: path = os.path.join(gajim.VCARD_PATH, puny_jid) local_avatar_basepath = os.path.join(gajim.AVATAR_PATH, puny_jid) + \ '_local' if use_local: for extension in ('.png', '.jpeg'): local_avatar_path = local_avatar_basepath + extension if os.path.isfile(local_avatar_path): avatar_file = open(local_avatar_path, 'rb') avatar_data = avatar_file.read() avatar_file.close() return get_pixbuf_from_data(avatar_data) if not os.path.isfile(path): return 'ask' vcard_dict = list(gajim.connections.values())[0].get_cached_vcard( fjid, is_groupchat_contact) if not vcard_dict: # This can happen if cached vcard is too old return 'ask' if 'PHOTO' not in vcard_dict: return None pixbuf = vcard.get_avatar_pixbuf_encoded_mime(vcard_dict['PHOTO'])[0] return pixbuf
def set_values(self, vcard_): button = self.xml.get_widget('PHOTO_button') image = button.get_image() text_button = self.xml.get_widget('NOPHOTO_button') if not 'PHOTO' in vcard_: # set default image image.set_from_pixbuf(None) button.hide() text_button.show() for i in vcard_.keys(): if i == 'PHOTO': pixbuf, self.avatar_encoded, self.avatar_mime_type = \ vcard.get_avatar_pixbuf_encoded_mime(vcard_[i]) if not pixbuf: image.set_from_pixbuf(None) button.hide() text_button.show() continue pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'vcard') image.set_from_pixbuf(pixbuf) button.show() text_button.hide() continue if i == 'ADR' or i == 'TEL' or i == 'EMAIL': for entry in vcard_[i]: add_on = '_HOME' if 'WORK' in entry: add_on = '_WORK' for j in entry.keys(): self.set_value(i + add_on + '_' + j + '_entry', entry[j]) if isinstance(vcard_[i], dict): for j in vcard_[i].keys(): self.set_value(i + '_' + j + '_entry', vcard_[i][j]) else: if i == 'DESC': self.xml.get_widget('DESC_textview').get_buffer().set_text( vcard_[i], 0) else: self.set_value(i + '_entry', vcard_[i]) if self.update_progressbar_timeout_id is not None: if self.message_id: self.statusbar.remove(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, _('Information received')) self.remove_statusbar_timeout_id = gobject.timeout_add_seconds( 3, self.remove_statusbar, self.message_id) gobject.source_remove(self.update_progressbar_timeout_id) self.progressbar.hide() self.progressbar.set_fraction(0) self.update_progressbar_timeout_id = None
def set_values(self, vcard_): button = self.xml.get_object('PHOTO_button') image = button.get_image() text_button = self.xml.get_object('NOPHOTO_button') if not 'PHOTO' in vcard_: # set default image image.set_from_pixbuf(None) button.hide() text_button.show() for i in vcard_.keys(): if i == 'PHOTO': pixbuf, self.avatar_encoded, self.avatar_mime_type = \ vcard.get_avatar_pixbuf_encoded_mime(vcard_[i]) if not pixbuf: image.set_from_pixbuf(None) button.hide() text_button.show() continue pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'vcard') image.set_from_pixbuf(pixbuf) button.show() text_button.hide() continue if i == 'ADR' or i == 'TEL' or i == 'EMAIL': for entry in vcard_[i]: add_on = '_HOME' if 'WORK' in entry: add_on = '_WORK' for j in entry.keys(): self.set_value(i + add_on + '_' + j + '_entry', entry[j]) if isinstance(vcard_[i], dict): for j in vcard_[i].keys(): self.set_value(i + '_' + j + '_entry', vcard_[i][j]) else: if i == 'DESC': self.xml.get_object('DESC_textview').get_buffer().set_text( vcard_[i], len(vcard[i].encode('utf-8'))) else: self.set_value(i + '_entry', vcard_[i]) if self.update_progressbar_timeout_id is not None: if self.message_id: self.statusbar.remove(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, _('Information received')) self.remove_statusbar_timeout_id = GLib.timeout_add_seconds(3, self.remove_statusbar, self.message_id) GLib.source_remove(self.update_progressbar_timeout_id) self.progressbar.hide() self.progressbar.set_fraction(0) self.update_progressbar_timeout_id = None
def set_values(self, vcard_): button = self.xml.get_widget("PHOTO_button") image = button.get_image() text_button = self.xml.get_widget("NOPHOTO_button") if not "PHOTO" in vcard_: # set default image image.set_from_pixbuf(None) button.hide() text_button.show() for i in vcard_.keys(): if i == "PHOTO": pixbuf, self.avatar_encoded, self.avatar_mime_type = vcard.get_avatar_pixbuf_encoded_mime(vcard_[i]) if not pixbuf: image.set_from_pixbuf(None) button.hide() text_button.show() continue pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, "vcard") image.set_from_pixbuf(pixbuf) button.show() text_button.hide() continue if i == "ADR" or i == "TEL" or i == "EMAIL": for entry in vcard_[i]: add_on = "_HOME" if "WORK" in entry: add_on = "_WORK" for j in entry.keys(): self.set_value(i + add_on + "_" + j + "_entry", entry[j]) if isinstance(vcard_[i], dict): for j in vcard_[i].keys(): self.set_value(i + "_" + j + "_entry", vcard_[i][j]) else: if i == "DESC": self.xml.get_widget("DESC_textview").get_buffer().set_text(vcard_[i], 0) else: self.set_value(i + "_entry", vcard_[i]) if self.update_progressbar_timeout_id is not None: if self.message_id: self.statusbar.remove(self.context_id, self.message_id) self.message_id = self.statusbar.push(self.context_id, _("Information received")) self.remove_statusbar_timeout_id = gobject.timeout_add_seconds(3, self.remove_statusbar, self.message_id) gobject.source_remove(self.update_progressbar_timeout_id) self.progressbar.hide() self.progressbar.set_fraction(0) self.update_progressbar_timeout_id = None
def get_avatar_pixbuf_from_cache(jid): """checks if jid has cached avatar and if that avatar is valid image (can be shown) returns None if there is no image in vcard returns 'ask' if cached vcard should not be used (user changed his vcard, so we have new sha) or if we don't have the vcard""" if gajim.config.get("hide_avatar_of_transport") and gajim.jid_is_transport(jid): # don't show avatar for the transport itself return None if jid not in os.listdir(gajim.VCARDPATH): return "ask" vcard_dict = gajim.connections.values()[0].get_cached_vcard(jid) if not vcard_dict: # This can happen if cached vcard is too old return "ask" if not vcard_dict.has_key("PHOTO"): return None pixbuf = vcard.get_avatar_pixbuf_encoded_mime(vcard_dict["PHOTO"])[0] return pixbuf