def populate(self, contact): if not contact: return self.create_window() hbox = gtk.HBox() if contact.jid.strip() != "": info = '<span size="large" weight="bold">' + contact.jid + "</span>" else: info = '<span size="large" weight="bold">' + contact.name + "</span>" info += '\n<span weight="bold">' + _("Role: ") + "</span>" + helpers.get_uf_role(contact.role) info += '\n<span weight="bold">' + _("Affiliation: ") + "</span>" + contact.affiliation.capitalize() info += '\n<span weight="bold">' + _("Status: ") + "</span>" + helpers.get_uf_show(contact.show) if contact.status: status = contact.status.strip() if status != "": # escape markup entities info += " - " + gtkgui_helpers.escape_for_pango_markup(status) if contact.resource.strip() != "": info += ( '\n<span weight="bold">' + _("Resource: ") + "</span>" + gtkgui_helpers.escape_for_pango_markup(contact.resource) ) self.text_label.set_markup(info) hbox.add(self.text_label) self.win.add(hbox)
def add_transfer(self, account, contact, file_props): ''' add new transfer to FT window and show the FT window ''' self.on_transfers_list_leave_notify_event(None) if file_props is None: return file_props['elapsed-time'] = 0 self.files_props[file_props['type']][file_props['sid']] = file_props iter = self.model.append() text_labels = '<b>' + _('Name: ') + '</b>\n' if file_props['type'] == 'r': text_labels += '<b>' + _('Sender: ') + '</b>' else: text_labels += '<b>' + _('Recipient: ') + '</b>' if file_props['type'] == 'r': (file_path, file_name) = os.path.split(file_props['file-name']) else: file_name = file_props['name'] text_props = gtkgui_helpers.escape_for_pango_markup(file_name) + '\n' text_props += gtkgui_helpers.escape_for_pango_markup(contact.name) self.model.set(iter, 1, text_labels, 2, text_props, C_SID, file_props['type'] + file_props['sid']) self.set_progress(file_props['type'], file_props['sid'], 0, iter) if file_props.has_key('started') and file_props['started'] is False: status = 'waiting' elif file_props['type'] == 'r': status = 'download' else: status = 'upload' file_props['tt_account'] = account self.set_status(file_props['type'], file_props['sid'], status) self.set_cleanup_sensitivity() self.window.show_all()
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>", )
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)
def show_stopped(self, jid, file_props): self.window.present() self.window.window.focus() if file_props['type'] == 'r': file_name = os.path.basename(file_props['file-name']) else: file_name = file_props['name'] sectext = '\t' + _('Filename: %s') % \ gtkgui_helpers.escape_for_pango_markup(file_name) sectext += '\n\t' + _('Sender: %s') % \ gtkgui_helpers.escape_for_pango_markup(jid) dialogs.ErrorDialog(_('File transfer stopped by the contact of the other side'), \ sectext).get_response() self.tree.get_selection().unselect_all()
def show_completed(self, jid, file_props): ''' show a dialog saying that file (file_props) has been transferred''' self.window.present() self.window.window.focus() if file_props['type'] == 'r': # file path is used below in 'Save in' (file_path, file_name) = os.path.split(file_props['file-name']) else: file_name = file_props['name'] sectext = '\t' + _('Filename: %s') % \ gtkgui_helpers.escape_for_pango_markup(file_name) sectext += '\n\t' + _('Size: %s') % \ helpers.convert_bytes(file_props['size']) if file_props['type'] == 'r': jid = unicode(file_props['sender']).split('/')[0] sender_name = gajim.get_first_contact_instance_from_jid( file_props['tt_account'], jid).name sender = gtkgui_helpers.escape_for_pango_markup(sender_name) else: #You is a reply of who sent a file sender = _('You') sectext += '\n\t' +_('Sender: %s') % sender sectext += '\n\t' +_('Recipient: ') if file_props['type'] == 's': jid = unicode(file_props['receiver']).split('/')[0] receiver_name = gajim.get_first_contact_instance_from_jid( file_props['tt_account'], jid).name recipient = gtkgui_helpers.escape_for_pango_markup(receiver_name) else: #You is a reply of who received a file recipient = _('You') sectext += recipient if file_props['type'] == 'r': sectext += '\n\t' +_('Saved in: %s') % \ gtkgui_helpers.escape_for_pango_markup(file_path) dialog = dialogs.HigDialog(None, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, _('File transfer completed'), sectext) if file_props['type'] == 'r': dialog.add_buttons(_('_Open Containing Folder'), gtk.RESPONSE_ACCEPT) dialog.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK) dialog.show_all() response = dialog.run() dialog.destroy() if response == gtk.RESPONSE_ACCEPT: if not file_props.has_key('file-name'): return (path, file) = os.path.split(file_props['file-name']) if os.path.exists(path) and os.path.isdir(path): helpers.launch_file_manager(path) self.tree.get_selection().unselect_all()
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)
def populate(self, file_props): self.create_window() self.hbox = gtk.HBox() text = "<b>" + _("Name: ") + "</b>" name = file_props["name"] if file_props["type"] == "r": (file_path, file_name) = os.path.split(file_props["file-name"]) else: file_name = file_props["name"] text += gtkgui_helpers.escape_for_pango_markup(file_name) text += "\n<b>" + _("Type: ") + "</b>" if file_props["type"] == "r": text += _("Download") else: text += _("Upload") if file_props["type"] == "r": text += "\n<b>" + _("Sender: ") + "</b>" sender = unicode(file_props["sender"]).split("/")[0] name = gajim.get_first_contact_instance_from_jid(file_props["tt_account"], sender).name else: text += "\n<b>" + _("Recipient: ") + "</b>" receiver = file_props["receiver"] if hasattr(receiver, "name"): receiver = receiver.name receiver = receiver.split("/")[0] if receiver.find("@") == -1: name = receiver else: name = gajim.get_first_contact_instance_from_jid(file_props["tt_account"], receiver).name text += gtkgui_helpers.escape_for_pango_markup(name) text += "\n<b>" + _("Size: ") + "</b>" text += helpers.convert_bytes(file_props["size"]) text += "\n<b>" + _("Transferred: ") + "</b>" transfered_len = 0 if file_props.has_key("received-len"): transfered_len = file_props["received-len"] text += helpers.convert_bytes(transfered_len) text += "\n<b>" + _("Status: ") + "</b>" status = "" if not file_props.has_key("started") or not file_props["started"]: status = _("Not started") elif file_props.has_key("connected"): if file_props.has_key("stopped") and file_props["stopped"] == True: status = _("Stopped") elif file_props["completed"]: status = _("Completed") elif file_props["connected"] == False: if file_props["completed"]: status = _("Completed") else: if file_props.has_key("paused") and file_props["paused"] == True: status = _("Paused") elif file_props.has_key("stalled") and file_props["stalled"] == True: # stalled is not paused. it is like 'frozen' it stopped alone status = _("Stalled") else: status = _("Transferring") else: status = _("Not started") text += status self.text_label.set_markup(text) self.hbox.add(self.text_label) self.win.add(self.hbox)
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)
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)