示例#1
0
 def fill_table_with_accounts(self, accounts):
     iconset = gajim.config.get("iconset")
     if not iconset:
         iconset = "dcraven"
     file_path = os.path.join(gajim.DATA_DIR, "iconsets", iconset, "16x16")
     for acct in accounts:
         message = acct["message"]
         # before reducing the chars we should assure we send unicode, else
         # there are possible pango TBs on 'set_markup'
         if isinstance(message, str):
             message = unicode(message, encoding="utf-8")
         message = gtkgui_helpers.reduce_chars_newlines(message, 50, 1)
         message = gtkgui_helpers.escape_for_pango_markup(message)
         if message:
             self.add_status_row(
                 file_path,
                 acct["show"],
                 '<span weight="bold">'
                 + gtkgui_helpers.escape_for_pango_markup(acct["name"])
                 + "</span>"
                 + " - "
                 + message,
             )
         else:
             self.add_status_row(
                 file_path,
                 acct["show"],
                 '<span weight="bold">' + gtkgui_helpers.escape_for_pango_markup(acct["name"]) + "</span>",
             )
示例#2
0
 def get_status_info(self, resource, priority, show, status):
     str_status = resource + " (" + unicode(priority) + ")"
     if status:
         status = status.strip()
         if status != "":
             # make sure 'status' is unicode before we send to to reduce_chars...
             if isinstance(status, str):
                 status = unicode(status, encoding="utf-8")
             status = gtkgui_helpers.reduce_chars_newlines(status, 0, 1)
             str_status += " - " + status
     return gtkgui_helpers.escape_for_pango_markup(str_status)
示例#3
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)
示例#4
0
    def populate(self, contacts):
        self.create_window()
        self.hbox = gtk.HBox()
        self.hbox.set_homogeneous(False)
        self.hbox.set_spacing(0)
        self.create_table()
        if not contacts or len(contacts) == 0:
            # Tooltip for merged accounts row
            accounts = self.get_accounts_info()
            self.current_row = 0
            self.table.resize(2, 1)
            self.spacer_label = ""
            self.fill_table_with_accounts(accounts)
            self.hbox.add(self.table)
            self.win.add(self.hbox)
            return
            # primary contact
        prim_contact = gajim.get_highest_prio_contact_from_contacts(contacts)

        # try to find the image for the contact status
        icon_name = helpers.get_icon_name_to_show(prim_contact)
        state_file = icon_name.replace(" ", "_")
        transport = gajim.get_transport_name_from_jid(prim_contact.jid)
        if transport:
            file_path = os.path.join(gajim.DATA_DIR, "iconsets", "transports", transport, "16x16")
        else:
            iconset = gajim.config.get("iconset")
            if not iconset:
                iconset = "dcraven"
            file_path = os.path.join(gajim.DATA_DIR, "iconsets", iconset, "16x16")

        files = []
        file_full_path = os.path.join(file_path, state_file)
        files.append(file_full_path + ".png")
        files.append(file_full_path + ".gif")
        self.image.set_from_pixbuf(None)
        for file in files:
            if os.path.exists(file):
                self.image.set_from_file(file)
                break

        info = '<span size="large" weight="bold">' + prim_contact.jid + "</span>"
        info += (
            '\n<span weight="bold">'
            + _("Name: ")
            + "</span>"
            + gtkgui_helpers.escape_for_pango_markup(prim_contact.name)
        )
        if prim_contact.sub:
            info += (
                '\n<span weight="bold">'
                + _("Subscription: ")
                + "</span>"
                + gtkgui_helpers.escape_for_pango_markup(prim_contact.sub)
            )

        if prim_contact.keyID:
            keyID = None
            if len(prim_contact.keyID) == 8:
                keyID = prim_contact.keyID
            elif len(prim_contact.keyID) == 16:
                keyID = prim_contact.keyID[8:]
            if keyID:
                info += (
                    '\n<span weight="bold">'
                    + _("OpenPGP: ")
                    + "</span>"
                    + gtkgui_helpers.escape_for_pango_markup(keyID)
                )

        num_resources = 0
        for contact in contacts:
            if contact.resource:
                num_resources += 1
        if num_resources > 1:
            self.current_row = 1
            self.table.resize(2, 1)
            info += '\n<span weight="bold">' + _("Status: ") + "</span>"
            for contact in contacts:
                if contact.resource:
                    status_line = self.get_status_info(contact.resource, contact.priority, contact.show, contact.status)
                    icon_name = helpers.get_icon_name_to_show(contact)
                    self.add_status_row(file_path, icon_name, status_line)

        else:  # only one resource
            if contact.resource:
                info += (
                    '\n<span weight="bold">'
                    + _("Resource: ")
                    + "</span>"
                    + gtkgui_helpers.escape_for_pango_markup(contact.resource)
                    + " ("
                    + unicode(contact.priority)
                    + ")"
                )
            if contact.show:
                info += '\n<span weight="bold">' + _("Status: ") + "</span>" + helpers.get_uf_show(contact.show)
                if contact.status:
                    status = contact.status.strip()
                    if status != "":
                        # reduce long status
                        # (no more than 130 chars on line and no more than 5 lines)
                        status = gtkgui_helpers.reduce_chars_newlines(status, 130, 5)
                        # escape markup entities.
                        info += " - " + gtkgui_helpers.escape_for_pango_markup(status)

        self.text_label.set_markup(info)
        self.hbox.pack_start(self.image, False, False)
        self.hbox.pack_start(self.table, True, True)
        self.win.add(self.hbox)
示例#5
0
    def populate(self, data):
        self.create_window()
        self.create_table()
        self.hbox = gtk.HBox()
        self.table.set_property("column-spacing", 1)
        text, single_line = "", ""

        unread_chat = gajim.interface.roster.nb_unread
        unread_single_chat = 0
        unread_gc = 0
        unread_pm = 0

        accounts = self.get_accounts_info()

        for acct in gajim.connections:
            # we count unread chat/pm messages
            chat_wins = gajim.interface.instances[acct]["chats"]
            for jid in chat_wins:
                if jid != "tabbed":
                    if gajim.contacts[acct].has_key(jid):
                        unread_chat += chat_wins[jid].nb_unread[jid]
                    else:
                        unread_pm += chat_wins[jid].nb_unread[jid]
                        # we count unread gc/pm messages
            gc_wins = gajim.interface.instances[acct]["gc"]
            for jid in gc_wins:
                if jid != "tabbed":
                    pm_msgs = gc_wins[jid].get_specific_unread(jid)
                    unread_gc += gc_wins[jid].nb_unread[jid]
                    unread_gc -= pm_msgs
                    unread_pm += pm_msgs

        if unread_chat or unread_single_chat or unread_gc or unread_pm:
            text = ""
            if unread_chat:
                text += i18n.ngettext(
                    "Gajim - %d unread message", "Gajim - %d unread messages", unread_chat, unread_chat, unread_chat
                )
                text += "\n"
            if unread_single_chat:
                text += i18n.ngettext(
                    "Gajim - %d unread single message",
                    "Gajim - %d unread single messages",
                    unread_single_chat,
                    unread_single_chat,
                    unread_single_chat,
                )
                text += "\n"
            if unread_gc:
                text += i18n.ngettext(
                    "Gajim - %d unread group chat message",
                    "Gajim - %d unread group chat messages",
                    unread_gc,
                    unread_gc,
                    unread_gc,
                )
                text += "\n"
            if unread_pm:
                text += i18n.ngettext(
                    "Gajim - %d unread private message",
                    "Gajim - %d unread private messages",
                    unread_pm,
                    unread_pm,
                    unread_pm,
                )
                text += "\n"
            text = text[:-1]  # remove latest \n
        elif len(accounts) > 1:
            text = _("Gajim")
            self.current_row = 1
            self.table.resize(2, 1)
            self.fill_table_with_accounts(accounts)

        elif len(accounts) == 1:
            message = accounts[0]["status_line"]
            message = gtkgui_helpers.reduce_chars_newlines(message, 50, 1)
            message = gtkgui_helpers.escape_for_pango_markup(message)
            text = _("Gajim - %s") % message
        else:
            text = _("Gajim - %s") % helpers.get_uf_show("offline")
        self.text_label.set_markup(text)
        self.hbox.add(self.table)
        self.win.add(self.hbox)