diff --git a/src/common/gajim.py b/src/common/gajim.py index b73ae7315a27187eac0951814288fc81ca74395d..929947e403aa99c8df4c0e059e95979ea9ddb97a 100644 --- a/src/common/gajim.py +++ b/src/common/gajim.py @@ -61,15 +61,52 @@ sleeper_state = {} # whether we pass auto away / xa or not #'autoxa': autoxa and use sleeper +def get_fjid_from_nick(room_jid, nick): + # fake jid is the jid for a contact in a room + # gaim@conference.jabber.org/nick + fjid = room_jid + '/' + nick + return fjid + +def get_nick_from_jid(jid): + pos = jid.find('@') + return jid[:pos] + +def get_nick_from_fjid(jid): + # fake jid is the jid for a contact in a room + # gaim@conference.jabber.org/nick/nick-continued + return jid.split('/', 1)[1] + def get_contact_instances_from_jid(account, jid): ''' we may have two or more resources on that jid ''' - return contacts[account][jid] + #print contacts + if jid in contacts[account]: + contacts_instances = contacts[account][jid] + return contacts_instances def get_first_contact_instance_from_jid(account, jid): - return contacts[account][jid][0] + if jid in contacts[account]: + contact = contacts[account][jid][0] + else: # it's fake jid + nick = get_nick_from_fjid(jid) + if nick in gc_contacts[room_jid]: + contact = gc_contacts[room_jid][nick] # always only one instance + return contact def get_contact_name_from_jid(account, jid): return contacts[account][jid][0].name def get_jid_without_resource(jid): return jid.split('/')[0] + +def construct_fjid(room_jid, nick): + ''' nick is in utf8 (taken from treeview); room_jid is in unicode''' + return room_jid + '/' + unicode(nick, 'utf-8') + +def get_resource_from_jid(jid): + return jid.split('/', 1)[1] # abc@doremi.org/res/res-continued + '''\ +[15:34:28] <asterix> we should add contact.fake_jid I think +[15:34:46] <asterix> so if we know real jid, it wil be in contact.jid, or we look in contact.fake_jid +[15:32:54] <asterix> they can have resource if we know the real jid +[15:33:07] <asterix> and that resource is in contact.resource +''' diff --git a/src/common/helpers.py b/src/common/helpers.py index c4fab0fcd393734f332b26fa4b589bd520cf68c8..026729b6bb0c41e967603b7c8a1ccc7272853422 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -51,24 +51,6 @@ def get_sorted_keys(adict): keys.sort() return keys -def get_fjid_from_nick(room_jid, nick): - # fake jid is the jid for a contact in a room - # gaim@conference.jabber.org/nick - fjid = room_jid + '/' + nick - return fjid - -def get_nick_from_jid(jid): - pos = jid.find('@') - return jid[:pos] - -def get_nick_from_fjid(jid): - # fake jid is the jid for a contact in a room - # gaim@conference.jabber.org/nick/nick-continued - return jid.split('/', 1)[1] - -def get_resource_from_jid(jid): - return jid.split('/', 1)[1] # abc@doremi.org/res/res-continued - def to_one_line(msg): msg = msg.replace('\\', '\\\\') msg = msg.replace('\n', '\\n') @@ -93,3 +75,16 @@ def from_one_line(msg): # s14 # 'test\ntest\\ntest' return msg + +def get_uf_chatstate(chatstate): + '''removes chatstate jargon and returns user friendly messages''' + if chatstate == 'active': + return _('is paying attention to the conversation') + elif chatstate == 'inactive': + return _('is doing something else') + elif chatstate == 'composing': + return _('is composing a message...') + elif chatstate == 'paused': + return _('paused composing a message...') + elif chatstate == 'gone': + return _('closed the chat window or tab') diff --git a/src/gajim.py b/src/gajim.py index e1714363e87f4feb6e23e3b6c111e45c8db48d0d..e4fa39f573140862231ffd03b3dec09e00e5add4 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -180,7 +180,7 @@ class Interface: def handle_event_roster(self, account, data): #('ROSTER', account, array) - self.roster.mklists(data, account) + self.roster.fill_contacts_and_groups_dicts(data, account) self.roster.draw_roster() if self.remote and self.remote.is_enabled(): self.remote.raise_signal('Roster', (account, data)) diff --git a/src/groupchat_window.py b/src/groupchat_window.py index a4794e2cd59806879c3c119b258a0dd59d6b55cb..5b1fdd7b916baad1e891deaa985245f68e416f32 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -658,7 +658,7 @@ class GroupchatWindow(chat.Chat): def ban(self, widget, room_jid, jid): """ban a user""" # to ban we know the real jid. so jid is not fakejid - nick = helpers.get_nick_from_jid(jid) + nick = gajim.get_nick_from_jid(jid) # ask for reason instance = dialogs.InputDialog(_('Banning %s') % nick, _('You may specify a reason below:')) @@ -704,7 +704,7 @@ class GroupchatWindow(chat.Chat): jid = c.jid fjid = c.jid + '/' + c.resource else: - fjid = room_jid + '/' + nick + fjid = gajim.construct_fjid(room_jid, nick) jid = fjid if self.plugin.windows[self.account]['infos'].has_key(jid): self.plugin.windows[self.account]['infos'][jid].window.present() @@ -723,9 +723,9 @@ class GroupchatWindow(chat.Chat): '''opens a chat window and msg is not None sends private message to a contact in a room''' if nick is None: - nick = model.get_value(iter, 1) + nick = model[iter][1] room_jid = self.get_active_jid() - fjid = room_jid + '/' + nick # 'fake' jid + fjid = gajim.construct_fjid(room_jid, nick) # 'fake' jid if not self.plugin.windows[self.account]['chats'].has_key(fjid): show = self.contacts[room_jid][nick].show u = Contact(jid = fjid, name = nick, groups = ['none'], show = show, @@ -772,7 +772,7 @@ class GroupchatWindow(chat.Chat): def mk_menu(self, room_jid, event, iter): """Make user's popup menu""" model = self.list_treeview[room_jid].get_model() - nick = model.get_value(iter, 1) + nick = model[iter][1] c = self.contacts[room_jid][nick] jid = c.jid target_affiliation = c.affiliation @@ -999,8 +999,8 @@ class GroupchatWindow(chat.Chat): model = widget.get_model() iter = model.get_iter(path) if len(path) == 2: - nick = model.get_value(iter, 1) - fjid = room_jid + '/' + nick + nick = model[iter][1] + fjid = gajim.construct_fjid(room_jid, nick) if not self.plugin.windows[self.account]['chats'].has_key(fjid): show = self.contacts[room_jid][nick].show u = Contact(jid = fjid, name = nick, groups = ['none'], @@ -1019,7 +1019,7 @@ class GroupchatWindow(chat.Chat): model = widget.get_model() iter = model.get_iter(path) - nick = model.get_value(iter, 1) + nick = model[iter][1] if not nick in self.contacts[room_jid]: #it's a group if x < 20: # first cell in 1st column (the arrow SINGLE clicked) if (widget.row_expanded(path)): @@ -1045,8 +1045,8 @@ class GroupchatWindow(chat.Chat): widget.expand_row(path, False) else: # We want to send a private message room_jid = self.get_active_jid() - nick = model.get_value(iter, 1) - fjid = room_jid + '/' + nick + nick = model[iter][1] + fjid = gajim.construct_fjid(room_jid, nick) if not self.plugin.windows[self.account]['chats'].has_key(fjid): show = self.contacts[room_jid][nick].show u = Contact(jid = fjid, name = nick, groups = ['none'], show = show, diff --git a/src/roster_window.py b/src/roster_window.py index 4ac04cad003ea9342210439bda66c208257eb70c..0fa0626a236d1cfc92c55855a4152ba0673b47e8 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -546,7 +546,7 @@ class RosterWindow: for jid in gajim.contacts[acct].keys(): self.add_contact_to_roster(jid, acct) - def mklists(self, array, account): + def fill_contacts_and_groups_dicts(self, array, account): '''fill gajim.contacts and gajim.groups''' if not gajim.contacts.has_key(account): gajim.contacts[account] = {} @@ -575,13 +575,13 @@ class RosterWindow: 'attached_gpg_keys').split() if jid in attached_keys: keyID = attached_keys[attached_keys.index(jid) + 1] - user1 = Contact(jid = ji, name = name, groups = array[jid]['groups'], + contact1 = Contact(jid = ji, name = name, groups = array[jid]['groups'], show = show, status = status, sub = array[jid]['subscription'], ask = array[jid]['ask'], resource = resource, keyID = keyID) # when we draw the roster, we avoid having the same contact - # more than once (eg. we avoid showing it twice with 2 resources) - gajim.contacts[account][ji] = [user1] + # more than once (f.e. we avoid showing it twice when 2 resources) + gajim.contacts[account][ji] = [contact1] for g in array[jid]['groups'] : if g in gajim.groups[account].keys(): continue diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 091843ff0635233b4b97e1ce992c39b293c4ef6e..7dd3ea8be2c3393195fb37fa1db785d192ffd104 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -144,9 +144,9 @@ class TabbedChatWindow(chat.Chat): # % (name, fulljid) if chatstate: + chatstate = helpers.get_uf_chatstate(chatstate) label_text = \ - '<span weight="heavy" size="x-large">%s</span> (chat state: %s)' \ - % (name, chatstate) + '<span weight="heavy" size="x-large">%s</span> %s' % (name, chatstate) else: label_text = '<span weight="heavy" size="x-large">%s</span>' % name