diff --git a/src/chat.py b/src/chat.py index 0b784b390..c66ed1f4a 100644 --- a/src/chat.py +++ b/src/chat.py @@ -464,7 +464,7 @@ class Chat: if self.widget_name == 'tabbed_chat_window': jid = self.get_active_jid() - c = gajim.contacts.get_first_contact_from_jid(self.account, jid) + c = self.contacts[jid] if _('not in the roster') in c.groups: # for add_to_roster_menuitem childs[5].show() childs[5].set_no_show_all(False) @@ -502,7 +502,7 @@ class Chat: childs[3].set_active(isactive) childs[3].set_property('sensitive', issensitive) # If we don't have resource, we can't do file transfert - c = gajim.contacts.get_first_contact_from_jid(self.account, jid) + c = self.contacts[jid] if not c.resource: childs[2].set_sensitive(False) else: diff --git a/src/chat_control.py b/src/chat_control.py index 53017968b..2e393d7f8 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1179,6 +1179,9 @@ class ChatControl(ChatControlBase): self.send_chatstate('inactive', self.contact) def show_avatar(self, resource = None): + if not gajim.config.get('show_avatar_in_chat'): + return + jid = self.contact.jid jid_with_resource = jid if resource: diff --git a/src/common/config.py b/src/common/config.py index e88928db6..4231a2fce 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -186,6 +186,7 @@ class Config: 'send_sha_in_gc_presence': [opt_bool, True, _('Jabberd1.4 does not like sha info when one join a password protected room. Turn this option to False to stop sending sha info in groupchat presences')], 'one_message_window': [opt_str, 'never', _('Controls the window where new messages are placed.\n\'always\' - All messages are sent to a single window.\n\'never\' - All messages get their own window.\n\'peracct\' - Messages for each account are sent to a specific window.\n\'pertype\' - Each message type (e.g., chats vs. groupchats) are sent to a specific window. Note, changing this option requires restarting Gajim before the changes will take effect')], + 'show_avatar_in_chat': [opt_bool, True, _('If False, you will no longer see the avatar in the chat window')], } __options_per_key = { diff --git a/src/common/connection.py b/src/common/connection.py index 3dd3e65f0..331234073 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -531,7 +531,7 @@ class Connection: self.dispatch('ERROR_ANSWER', ('', jid_stripped, errmsg, errcode)) - if avatar_sha: + if avatar_sha and ptype != 'error': if self.vcard_shas.has_key(jid_stripped): if avatar_sha != self.vcard_shas[jid_stripped]: # avatar has been updated diff --git a/src/common/contacts.py b/src/common/contacts.py index c76b391a4..a3bca6f85 100644 --- a/src/common/contacts.py +++ b/src/common/contacts.py @@ -122,12 +122,16 @@ class Contacts: if not self._contacts[account].has_key(contact.jid): self._contacts[account][contact.jid] = [contact] return + contacts = self._contacts[account][contact.jid] + # We had only one that was offline, remove it + if len(contacts) == 1 and contacts[0].show == 'offline': + self.remove_contact(account, contacts[0]) # If same JID with same resource already exists, use the new one - for c in self._contacts[account][contact.jid]: + for c in contacts: if c.resource == contact.resource: self.remove_contact(account, c) break - self._contacts[account][contact.jid].append(contact) + contacts.append(contact) def remove_contact(self, account, contact): if not self._contacts.has_key(account): @@ -223,7 +227,13 @@ class Contacts: def contact_from_gc_contact(self, gc_contact): '''Create a Contact instance from a GC_Contact instance''' - return Contact(jid = gc_contact.get_full_jid(), name = gc_contact.name, + if gc_contact.jid: + jid = gc_contact.jid + resource = gc_contact.resource + else: + jid = gc_contact.get_full_jid() + resource = '' + return Contact(jid = jid, resource = resource, name = gc_contact.name, groups = ['none'], show = gc_contact.show, status = gc_contact.status, sub = 'none') diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 3b197fe7a..1815062ff 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -330,10 +330,7 @@ class GroupchatControl(ChatControlBase): gajim.interface.systray.add_jid(fjid, self.account, 'pm') self.parent_win.show_title() else: - gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) - c = gajim.contacts.contact_from_gc_contact(gc_c) - print "creating PM chat" - gajim.interface.roster.new_chat(c, self.account, private_chat = True) + self._start_private_message(nick) # Scroll to line self.list_treeview.expand_row(path[0:1], False) self.list_treeview.scroll_to_cell(path) @@ -577,21 +574,9 @@ class GroupchatControl(ChatControlBase): nick = model[iter][C_NICK].decode('utf-8') fjid = gajim.construct_fjid(self.room_jid, nick) # 'fake' jid - chat_win = gajim.interface.msg_win_mgr.get_window(fjid) - if not chat_win: - gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) - c = gajim.contacts.contact_from_gc_contact(gc_c) - print "creating PM chat" - gajim.interface.roster.new_chat(c, self.account, private_chat = True) - chat_win = gajim.interface.msg_win_mgr.get_window(fjid) - chat_control = chat_win.get_control(fjid) - - #make active here in case we need to send a message - chat_win.set_active_tab(fjid) - + self._start_private_message(nick) if msg: chat_control.send_message(msg) - chat_win.window.present() def draw_contact(self, nick, selected=False, focus=False): iter = self.get_contact_iter(nick) @@ -1333,7 +1318,9 @@ class GroupchatControl(ChatControlBase): menu.show_all() def _start_private_message(self, nick): - nick_jid = gajim.construct_fjid(self.room_jid, nick) + gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) + c = gajim.contacts.contact_from_gc_contact(gc_c) + nick_jid = c.jid win = gajim.interface.msg_win_mgr.get_window(nick_jid) if not win: @@ -1355,7 +1342,7 @@ class GroupchatControl(ChatControlBase): widget.expand_row(path, False) else: # We want to send a private message nick = model[iter][C_NICK].decode('utf-8') - win = self._start_private_message(nick) + self._start_private_message(nick) def on_list_treeview_button_press_event(self, widget, event): '''popup user's group's or agent menu''' @@ -1385,17 +1372,7 @@ class GroupchatControl(ChatControlBase): iter = model.get_iter(path) if len(path) == 2: nick = model[iter][C_NICK].decode('utf-8') - fjid = gajim.construct_fjid(self.room_jid, nick) - win = gajim.interface.msg_win_mgr.get_window(fjid) - if not win: - gc_c = gajim.contacts.get_gc_contact(self.account, self.room_jid, - nick) - c = gajim.contacts.contact_from_gc_contact(gc_c) - gajim.interface.roster.new_chat(c, self.account, - private_chat = True) - win = gajim.interface.msg_win_mgr.get_window(fjid) - win.set_active_tab(fjid) - win.window.present() + self._start_private_message(nick) return True elif event.button == 1: # left click @@ -1526,13 +1503,18 @@ class GroupchatControl(ChatControlBase): def on_info(self, widget, ck): '''Call vcard_information_window class to display user's information''' c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick) - jid = c.get_full_jid() - if gajim.interface.instances[self.account]['infos'].has_key(jid): - gajim.interface.instances[self.account]['infos'][jid].window.present() +# jid = c.get_full_jid() +# if gajim.interface.instances[self.account]['infos'].has_key(jid): +# gajim.interface.instances[self.account]['infos'][jid].window.present() + # we create a Contact instance + c2 = gajim.contacts.contact_from_gc_contact(c) + if gajim.interface.instances[self.account]['infos'].has_key(c2.jid): + gajim.interface.instances[self.account]['infos'][c2.jid].window.present() else: - # we create a Contact instance - c2 = gajim.contacts.contact_from_gc_contact(c) - gajim.interface.instances[self.account]['infos'][jid] = \ +# # we create a Contact instance +# c2 = gajim.contacts.contact_from_gc_contact(c) +# gajim.interface.instances[self.account]['infos'][jid] = \ + gajim.interface.instances[self.account]['infos'][c2.jid] = \ vcard.VcardWindow(c2, self.account, False) def on_history(self, widget, ck): diff --git a/src/groupchat_window.py b/src/groupchat_window.py index a572317bb..80bd4c81f 100644 --- a/src/groupchat_window.py +++ b/src/groupchat_window.py @@ -1162,13 +1162,12 @@ current room topic.') % command, room_jid) def on_info(self, widget, room_jid, nick): '''Call vcard_information_window class to display user's information''' c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) - jid = c.get_full_jid() - if gajim.interface.instances[self.account]['infos'].has_key(jid): - gajim.interface.instances[self.account]['infos'][jid].window.present() + # we create a Contact instance + c2 = gajim.contacts.contact_from_gc_contact(c) + if gajim.interface.instances[self.account]['infos'].has_key(c2.jid): + gajim.interface.instances[self.account]['infos'][c2.jid].window.present() else: - # we create a Contact instance - c2 = gajim.contacts.contact_from_gc_contact(c) - gajim.interface.instances[self.account]['infos'][jid] = \ + gajim.interface.instances[self.account]['infos'][c2.jid] = \ vcard.VcardWindow(c2, self.account, False) def on_history(self, widget, room_jid, nick): @@ -1676,14 +1675,13 @@ current room topic.') % command, room_jid) else: # We want to send a private message room_jid = self.get_active_jid() nick = model[iter][C_NICK].decode('utf-8') - jid = gajim.construct_fjid(room_jid, nick) - # FIXME - if not gajim.interface.instances[self.account]['chats'].has_key(jid): - gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) - c = gajim.contacts.contact_from_gc_contact(gc_c) + gc_c = gajim.contacts.get_gc_contact(self.account, room_jid, nick) + c = gajim.contacts.contact_from_gc_contact(gc_c) + if not gajim.interface.instances[self.account]['chats'].has_key(c.jid): gajim.interface.roster.new_chat(c, self.account) - gajim.interface.instances[self.account]['chats'][jid].set_active_tab(jid) - gajim.interface.instances[self.account]['chats'][jid].window.present() + gajim.interface.instances[self.account]['chats'][c.jid].set_active_tab( + c.jid) + gajim.interface.instances[self.account]['chats'][c.jid].window.present() def on_list_treeview_row_expanded(self, widget, iter, path): '''When a row is expanded: change the icon of the arrow''' diff --git a/src/roster_window.py b/src/roster_window.py index c1f840bb6..b0c5c7bc2 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -457,33 +457,34 @@ class RosterWindow: self.new_message_menuitem_handler_id) self.new_message_menuitem_handler_id = None - #remove the existing submenus + # remove the existing submenus add_new_contact_menuitem.remove_submenu() service_disco_menuitem.remove_submenu() join_gc_menuitem.remove_submenu() new_message_menuitem.remove_submenu() advanced_menuitem.remove_submenu() - #remove the existing accelerator + # remove the existing accelerator if self.have_new_message_accel: ag = gtk.accel_groups_from_object(self.window)[0] new_message_menuitem.remove_accelerator(ag, gtk.keysyms.n, gtk.gdk.CONTROL_MASK) self.have_new_message_accel = False - #join gc + # join gc sub_menu = gtk.Menu() join_gc_menuitem.set_submenu(sub_menu) at_least_one_account_connected = False multiple_accounts = len(gajim.connections) >= 2 #FIXME: stop using bool var here for account in gajim.connections: - if gajim.connections[account].connected <= 1: #if offline or connecting + if gajim.connections[account].connected <= 1: # if offline or connecting continue if not at_least_one_account_connected: at_least_one_account_connected = True if multiple_accounts: label = gtk.Label() label.set_markup('' + account.upper() +'') + label.set_use_underline(False) item = gtk.MenuItem() item.add(label) item.connect('state-changed', self.on_bm_header_changed_state) @@ -494,7 +495,7 @@ class RosterWindow: sub_menu.append(item) for bookmark in gajim.connections[account].bookmarks: - item = gtk.MenuItem(bookmark['name']) + item = gtk.MenuItem(bookmark['name'], False) # Do not use underline item.connect('activate', self.on_bookmark_menuitem_activate, account, bookmark) sub_menu.append(item) @@ -519,7 +520,7 @@ class RosterWindow: if gajim.connections[account].connected <= 1: #if offline or connecting continue - item = gtk.MenuItem(_('to %s account') % account) + item = gtk.MenuItem(_('to %s account') % account, False) sub_menu.append(item) item.connect('activate', self.on_add_new_contact, account) add_new_contact_menuitem.set_submenu(sub_menu) @@ -531,7 +532,7 @@ class RosterWindow: if gajim.connections[account].connected <= 1: #if offline or connecting continue - item = gtk.MenuItem(_('using %s account') % account) + item = gtk.MenuItem(_('using %s account') % account, False) sub_menu.append(item) item.connect('activate', self.on_service_disco_menuitem_activate, account) @@ -545,7 +546,7 @@ class RosterWindow: if gajim.connections[account].connected <= 1: #if offline or connecting continue - item = gtk.MenuItem(_('using account %s') % account) + item = gtk.MenuItem(_('using account %s') % account, False) sub_menu.append(item) item.connect('activate', self.on_new_message_menuitem_activate, account) @@ -556,7 +557,7 @@ class RosterWindow: #Advanced Actions sub_menu = gtk.Menu() for account in gajim.connections: - item = gtk.MenuItem(_('for account %s') % account) + item = gtk.MenuItem(_('for account %s') % account, False) sub_menu.append(item) advanced_menuitem_menu = self.get_and_connect_advanced_menuitem_menu( account) diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 4e2765760..800f61cd8 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -301,6 +301,8 @@ class TabbedChatWindow(chat.Chat): def show_avatar(self, jid, resource): # Get the XML instance + if not gajim.config.get('show_avatar_in_chat'): + return jid_with_resource = jid if resource: jid_with_resource += '/' + resource