Exemple #1
0
    def get_path_to_generic_or_avatar(self, generic, jid=None, suffix=None):
        """
        Choose between avatar image and default image

        Returns full path to the avatar image if it exists, otherwise returns full
        path to the image.  generic must be with extension and suffix without
        """
        if jid:
            # we want an avatar
            puny_jid = helpers.sanitize_filename(jid)
            path_to_file = os.path.join(configpaths.get('AVATAR'),
                                        puny_jid) + suffix
            path_to_local_file = path_to_file + '_local'
            for extension in ('.png', '.jpeg'):
                path_to_local_file_full = path_to_local_file + extension
                if os.path.exists(path_to_local_file_full):
                    return path_to_local_file_full
            for extension in ('.png', '.jpeg'):
                path_to_file_full = path_to_file + extension
                if os.path.exists(path_to_file_full):
                    return path_to_file_full
        return os.path.abspath(generic)
Exemple #2
0
    def __init__(self, contact, account, gc_contact=None):
        EventHelper.__init__(self)
        # the contact variable is the jid if vcard is true
        self.xml = get_builder('vcard_information_window.ui')
        self.window = self.xml.get_object('vcard_information_window')
        self.progressbar = self.xml.get_object('progressbar')

        self.contact = contact
        self.account = account
        self.gc_contact = gc_contact
        self.avatar = None

        # Get real jid
        if gc_contact:
            # Don't use real jid if room is (semi-)anonymous
            gc_control = app.interface.msg_win_mgr.get_gc_control(
                gc_contact.room_jid, account)
            if gc_contact.jid and not gc_control.is_anonymous:
                self.real_jid = gc_contact.jid
                self.real_jid_for_vcard = gc_contact.jid
                if gc_contact.resource:
                    self.real_jid += '/' + gc_contact.resource
            else:
                self.real_jid = gc_contact.get_full_jid()
                self.real_jid_for_vcard = self.real_jid
            self.real_resource = gc_contact.name
        else:
            self.real_jid = contact.get_full_jid()
            self.real_resource = contact.resource

        puny_jid = helpers.sanitize_filename(contact.jid)
        local_avatar_basepath = os.path.join(configpaths.get('AVATAR'), puny_jid) + \
                '_local'
        for extension in ('.png', '.jpeg'):
            local_avatar_path = local_avatar_basepath + extension
            if os.path.isfile(local_avatar_path):
                image = self.xml.get_object('custom_avatar_image')
                image.set_from_file(local_avatar_path)
                image.show()
                self.xml.get_object('custom_avatar_label').show()
                break
        self.vcard_arrived = False
        self.os_info_arrived = False
        self.entity_time_arrived = False
        self.time = 0
        self.update_intervall = 100  # Milliseconds
        self.update_progressbar_timeout_id = GLib.timeout_add(
            self.update_intervall, self.update_progressbar)

        self.register_events([
            ('time-result-received', ged.GUI1, self.set_entity_time),
        ])

        self.fill_jabber_page()
        con = app.connections[self.account]
        note = con.get_module('Annotations').get_note(self.contact.jid)
        if note is not None:
            buffer_ = self.xml.get_object('textview_annotation').get_buffer()
            buffer_.set_text(note.data)

        for widget_name in ('URL_label', 'EMAIL_WORK_USERID_label',
                            'EMAIL_HOME_USERID_label'):
            widget = self.xml.get_object(widget_name)
            widget.hide()

        self.xml.connect_signals(self)
        self.xml.get_object('close_button').grab_focus()
        self.window.show_all()