Example #1
0
	def draw_name_banner(self, contact, chatstate = None):
		'''Draw the fat line at the top of the window that 
		houses the status icon, name, jid, and avatar'''
		# this is the text for the big brown bar
		# some chars need to be escaped..
		jid = contact.jid
		banner_name_label = self.xmls[jid].get_widget('banner_name_label')
		
		name = gtkgui_helpers.escape_for_pango_markup(contact.name)
		
		status = contact.status

		if status is not None:
			banner_name_label.set_ellipsize(pango.ELLIPSIZE_END)
			status = gtkgui_helpers.reduce_chars_newlines(status, 0, 2)

		status = gtkgui_helpers.escape_for_pango_markup(status)

		#FIXME: uncomment me when we support sending messages to specific resource
		# composing full jid
		#fulljid = jid
		#if self.contacts[jid].resource:
		#	fulljid += '/' + self.contacts[jid].resource
		#label_text = '<span weight="heavy" size="x-large">%s</span>\n%s' \
		#	% (name, fulljid)
		
		
		st = gajim.config.get('chat_state_notifications')
		if contact.chatstate and st in ('composing_only', 'all'):
			if contact.show == 'offline':
				chatstate = ''
			elif st == 'all':
				chatstate = helpers.get_uf_chatstate(contact.chatstate)
			else: # 'composing_only'
				if chatstate in ('composing', 'paused'):
					# only print composing, paused
					chatstate = helpers.get_uf_chatstate(contact.chatstate)
				else:
					chatstate = ''
			label_text = \
			'<span weight="heavy" size="x-large">%s</span> %s' % (name, chatstate)
		else:
			label_text = '<span weight="heavy" size="x-large">%s</span>' % name
		
		if status is not None:
			label_text += '\n%s' % status

		# setup the label that holds name and jid
		banner_name_label.set_markup(label_text)
		self.paint_banner(jid)
Example #2
0
    def chat_control_base_draw_banner_called(self, chat_control):
        if not self.config["show_banner_online_msg"]:
            chat_control.banner_status_label.hide()
            chat_control.banner_status_label.set_no_show_all(True)
            status_text = ""
            chat_control.banner_status_label.set_markup(status_text)

        if not self.config["show_banner_image"]:
            if chat_control.TYPE_ID == message_control.TYPE_GC:
                banner_status_img = chat_control.xml.get_object("gc_banner_status_image")
            else:
                banner_status_img = chat_control.xml.get_object("banner_status_image")
            banner_status_img.clear()

        # TODO: part below repeats a lot of code from ChatControl.draw_banner_text()
        # This could be rewritten using re module: getting markup text from
        # banner_name_label and replacing some elements based on plugin config.
        # Would it be faster?
        if self.config["show_banner_resource"] or self.config["banner_small_fonts"]:
            banner_name_label = chat_control.xml.get_object("banner_name_label")
            label_text = banner_name_label.get_label()

            contact = chat_control.contact
            jid = contact.jid

            name = contact.get_shown_name()
            if chat_control.resource:
                name += "/" + chat_control.resource
            elif contact.resource and self.config["show_banner_resource"]:
                name += "/" + contact.resource

            if chat_control.TYPE_ID == message_control.TYPE_PM:
                name = _("%(nickname)s from group chat %(room_name)s") % {
                    "nickname": name,
                    "room_name": chat_control.room_name,
                }
            name = gobject.markup_escape_text(name)

            # We know our contacts nick, but if another contact has the same nick
            # in another account we need to also display the account.
            # except if we are talking to two different resources of the same contact
            acct_info = ""
            for account in gajim.contacts.get_accounts():
                if account == chat_control.account:
                    continue
                if acct_info:  # We already found a contact with same nick
                    break
                for jid in gajim.contacts.get_jid_list(account):
                    other_contact_ = gajim.contacts.get_first_contact_from_jid(account, jid)
                    if other_contact_.get_shown_name() == chat_control.contact.get_shown_name():
                        acct_info = " (%s)" % gobject.markup_escape_text(chat_control.account)
                        break

            font_attrs, font_attrs_small = chat_control.get_font_attrs()
            if self.config["banner_small_fonts"]:
                font_attrs = font_attrs_small

            st = gajim.config.get("displayed_chat_state_notifications")
            cs = contact.chatstate
            if cs and st in ("composing_only", "all"):
                if contact.show == "offline":
                    chatstate = ""
                elif st == "all" or cs == "composing":
                    chatstate = helpers.get_uf_chatstate(cs)
                else:
                    chatstate = ""

                label_text = "<span %s>%s</span><span %s>%s %s</span>" % (
                    font_attrs,
                    name,
                    font_attrs_small,
                    acct_info,
                    chatstate,
                )
            else:
                # weight="heavy" size="x-large"
                label_text = "<span %s>%s</span><span %s>%s</span>" % (font_attrs, name, font_attrs_small, acct_info)

            banner_name_label.set_markup(label_text)
Example #3
0
    def chat_control_base_draw_banner_called(self, chat_control):
        if not self.config['show_banner_online_msg']:
            chat_control.banner_status_label.hide()
            chat_control.banner_status_label.set_no_show_all(True)
            status_text = ''
            chat_control.banner_status_label.set_markup(status_text)

        if not self.config['show_banner_image']:
            if chat_control.TYPE_ID == message_control.TYPE_GC:
                banner_status_img = chat_control.xml.get_object(
                    'gc_banner_status_image')
            else:
                banner_status_img = chat_control.xml.get_object(
                    'banner_status_image')
            banner_status_img.clear()

        # TODO: part below repeats a lot of code from ChatControl.draw_banner_text()
        # This could be rewritten using re module: getting markup text from
        # banner_name_label and replacing some elements based on plugin config.
        # Would it be faster?
        if self.config['show_banner_resource'] or self.config['banner_small_fonts']:
            banner_name_label = chat_control.xml.get_object('banner_name_label')
            label_text = banner_name_label.get_label()

            contact = chat_control.contact
            jid = contact.jid

            name = contact.get_shown_name()
            if chat_control.resource:
                name += '/' + chat_control.resource
            elif contact.resource and self.config['show_banner_resource']:
                name += '/' + contact.resource

            if chat_control.TYPE_ID == message_control.TYPE_PM:
                name = _('%(nickname)s from group chat %(room_name)s') %\
                        {'nickname': name, 'room_name': chat_control.room_name}
            name = gobject.markup_escape_text(name)

            # We know our contacts nick, but if another contact has the same nick
            # in another account we need to also display the account.
            # except if we are talking to two different resources of the same contact
            acct_info = ''
            for account in gajim.contacts.get_accounts():
                if account == chat_control.account:
                    continue
                if acct_info: # We already found a contact with same nick
                    break
                for jid in gajim.contacts.get_jid_list(account):
                    other_contact_ = \
                            gajim.contacts.get_first_contact_from_jid(account, jid)
                    if other_contact_.get_shown_name() == chat_control.contact.get_shown_name():
                        acct_info = ' (%s)' % \
                                gobject.markup_escape_text(chat_control.account)
                        break

            font_attrs, font_attrs_small = chat_control.get_font_attrs()
            if self.config['banner_small_fonts']:
                font_attrs = font_attrs_small

            st = gajim.config.get('displayed_chat_state_notifications')
            cs = contact.chatstate
            if cs and st in ('composing_only', 'all'):
                if contact.show == 'offline':
                    chatstate = ''
                elif st == 'all' or cs == 'composing':
                    chatstate = helpers.get_uf_chatstate(cs)
                else:
                    chatstate = ''

                label_text = '<span %s>%s</span><span %s>%s %s</span>' % \
                    (font_attrs, name, font_attrs_small, acct_info, chatstate)
            else:
                # weight="heavy" size="x-large"
                label_text = '<span %s>%s</span><span %s>%s</span>' % \
                    (font_attrs, name, font_attrs_small, acct_info)

            banner_name_label.set_markup(label_text)