Commit 1360933b authored by nicfit's avatar nicfit
Browse files

Merged in trunk updates, including meta_contacts


Merged revisions 4951,4962-4969 via svnmerge from
svn://svn.gajim.org/gajim/trunk

........
r4951 | nk | 2005-12-30 16:50:36 -0700 (Fri, 30 Dec 2005) | 1 line

fixes in greek transl
........
r4962 | asterix | 2006-01-01 11:41:04 -0700 (Sun, 01 Jan 2006) | 2 lines

merge meta_contacts branch with trunk. Meta contacts are not in gajim yet, but framework is here. We now use gajim.contacts.many_functions() to handle contacts and groupchat_contacts.

........
r4963 | asterix | 2006-01-01 11:43:24 -0700 (Sun, 01 Jan 2006) | 2 lines

correct contacts file

........
r4964 | asterix | 2006-01-01 11:47:26 -0700 (Sun, 01 Jan 2006) | 2 lines

dict.remove() doesn't exists, it's del dict[]

........
r4965 | asterix | 2006-01-01 11:50:15 -0700 (Sun, 01 Jan 2006) | 2 lines

some missing commits from branch

........
r4966 | asterix | 2006-01-01 11:53:30 -0700 (Sun, 01 Jan 2006) | 2 lines

end of gc_contact.nick -> gc_contact.name

........
r4967 | asterix | 2006-01-01 12:05:59 -0700 (Sun, 01 Jan 2006) | 2 lines

new ACE option: send_sha_in_gc_presence that allow to send sha info in groupchat presences

........
r4968 | asterix | 2006-01-01 12:12:36 -0700 (Sun, 01 Jan 2006) | 2 lines

0.9.1-2 in debian that solve the group bug (commit [4924])

........
r4969 | asterix | 2006-01-01 12:31:13 -0700 (Sun, 01 Jan 2006) | 2 lines

typo

........
parent 6036368b
gajim (0.9.1-2) unstable; urgency=low
* fix group bug Closes: #345306
-- Yann Le Boulanger <asterix@lagaule.org> Fri, 30 Dec 2005 13:09:55 +0100
gajim (0.9.1-1) unstable; urgency=low
* new upstream release
......
Index: src/roster_window.py
===================================================================
--- src/roster_window.py (revision 4923)
+++ src/roster_window.py (working copy)
@@ -87,6 +87,8 @@
model = self.tree.get_model()
root = self.get_account_iter(account)
group_iter = model.iter_children(root)
+ # C_NAME column contacts the pango escaped group name
+ name = gtkgui_helpers.escape_for_pango_markup(name)
while group_iter:
group_name = model[group_iter][C_NAME].decode('utf-8')
if name == group_name:
......@@ -548,7 +548,7 @@ msgstr ""
"Συμπληρώστε την ταυτότητα της επαφής προς την οποία\n"
"θέλετε να στείλετε ένα μήνυμα συζήτησης"
#. if offline or connecting
#. if or connecting
#: ../src/dialogs.py:767 ../src/dialogs.py:1145 ../src/dialogs.py:1265
msgid "Connection not available"
msgstr "Σύνδεση μη διαθέσιμη"
......@@ -750,7 +750,7 @@ msgstr "_Συμμετοχή"
#: ../src/disco.py:1202 ../src/gtkgui.glade.h:330 ../src/roster_window.py:1075
msgid "_Edit"
msgstr "Επε_ξεργασία"
msgstr "Ε_πεξεργασία"
#: ../src/disco.py:1241
#, python-format
......@@ -3530,11 +3530,11 @@ msgstr ""
#: ../src/roster_window.py:2636
msgid "Change Status Message..."
msgstr "Αλλαγή Μηνύμαος Κατάστασης..."
msgstr "Αλλαγή Μηνύματος Κατάστασης..."
#: ../src/systray.py:151
msgid "_Change Status Message..."
msgstr "Αλλαγή Μηνύμαος _Κατάστασης..."
msgstr "Αλλαγή Μηνύματος _Κατάστασης..."
#. for chat_with
#. for new_message
......
......@@ -189,7 +189,7 @@ class Chat:
add = _('Group Chat')
elif len(self.xmls) == 1: # just one tab
if self.widget_name == 'tabbed_chat_window':
c = gajim.get_first_contact_instance_from_jid(self.account, jid)
c = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if c is None:
add = ''
else:
......@@ -297,9 +297,9 @@ class Chat:
def get_message_type(self, jid):
if self.widget_name == 'groupchat_window':
return 'gc'
if gajim.contacts[self.account].has_key(jid):
return 'chat'
return 'pm'
if gajim.contacts.is_pm_from_jid(self.account, jid):
return 'pm'
return 'chat'
def get_nth_jid(self, page_number = None):
notebook = self.notebook
......@@ -464,7 +464,7 @@ class Chat:
if self.widget_name == 'tabbed_chat_window':
jid = self.get_active_jid()
c = gajim.get_first_contact_instance_from_jid(self.account, jid)
c = gajim.contacts.get_first_contact_from_jid(self.account, 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.get_first_contact_instance_from_jid(self.account, jid)
c = gajim.contacts.get_first_contact_from_jid(self.account, jid)
if not c.resource:
childs[2].set_sensitive(False)
else:
......
......@@ -170,6 +170,7 @@ class Config:
'roster_window_skip_taskbar': [opt_bool, False],
'use_urgency_hint': [opt_bool, True, _('If True and installed GTK+ and PyGTK versions are at least 2.8, make the window flash (the default behaviour in most Window Managers) when holding pending events.')],
'notification_timeout': [opt_int, 5],
'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')],
}
......
......@@ -2182,7 +2182,8 @@ class Connection:
show = helpers.get_xmpp_show(STATUS_LIST[self.connected])
p = common.xmpp.Presence(to = '%s@%s/%s' % (room, server, nick),
show = show, status = self.status)
p = self.add_sha(p)
if gajim.config.get('send_sha_in_gc_presence'):
p = self.add_sha(p)
t = p.setTag(common.xmpp.NS_MUC + ' x')
if password:
t.setTagData('password', password)
......@@ -2228,7 +2229,8 @@ class Connection:
show = helpers.get_xmpp_show(show)
p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype,
show = show, status = status)
p = self.add_sha(p)
if gajim.config.get('send_sha_in_gc_presence'):
p = self.add_sha(p)
# send instantly so when we go offline, status is sent to gc before we
# disconnect from jabber server
self.connection.send(p)
......
## common/contacts.py
##
## Contributors for this file:
## - Yann Le Boulanger <asterix@lagaule.org>
##
## Copyright (C) 2003-2004 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org>
## Copyright (C) 2005 Yann Le Boulanger <asterix@lagaule.org>
## Vincent Hanquez <tab@snarc.org>
## Nikos Kouremenos <nkour@jabber.org>
## Dimitur Kirov <dkirov@gmail.com>
## Travis Shirk <travis@pobox.com>
## Norman Rasmussen <norman@rasmussen.co.za>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 2 only.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
import common.gajim
class Contact:
'''Information concerning each contact'''
def __init__(self, jid='', name='', groups=[], show='', status='', sub='',
ask='', resource='', priority=5, keyID='', our_chatstate=None,
chatstate=None):
self.jid = jid
self.name = name
self.groups = groups
self.show = show
self.status = status
self.sub = sub
self.ask = ask
self.resource = resource
self.priority = priority
self.keyID = keyID
# please read jep-85 http://www.jabber.org/jeps/jep-0085.html
# we keep track of jep85 support by the peer by three extra states:
# None, False and 'ask'
# None if no info about peer
# False if peer does not support jep85
# 'ask' if we sent the first 'active' chatstate and are waiting for reply
# this holds what WE SEND to contact (our current chatstate)
self.our_chatstate = our_chatstate
# this is contact's chatstate
self.chatstate = chatstate
def get_full_jid(self):
if self.resource:
return self.jid + '/' + self.resource
return self.jid
class GC_Contact:
'''Information concerning each groupchat contact'''
def __init__(self, room_jid='', name='', show='', status='', role='',
affiliation='', jid = ''):
self.room_jid = room_jid
self.name = name
self.show = show
self.status = status
self.role = role
self.affiliation = affiliation
self.jid = jid
def get_full_jid(self):
return self.room_jid + '/' + self.name
class Contacts:
'''Information concerning all contacts and groupchat contacts'''
def __init__(self):
self._contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource
self._gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}}
self._sub_contacts = {} # {acct: {jid1: jid2}} means jid1 is sub of jid2
def change_account_name(self, old_name, new_name):
self._contacts[new_name] = self._contacts[old_name]
self._gc_contacts[new_name] = self._gc_contacts[old_name]
del self._contacts[old_name]
del self._gc_contacts[old_name]
def add_account(self, account):
self._contacts[account] = {}
self._gc_contacts[account] = {}
def get_accounts(self):
return self._contacts.keys()
def remove_account(self, account):
del self._contacts[account]
del self._gc_contacts[account]
def create_contact(self, jid='', name='', groups=[], show='', status='',
sub='', ask='', resource='', priority=5, keyID='', our_chatstate=None,
chatstate=None):
return Contact(jid, name, groups, show, status, sub, ask, resource,
priority, keyID, our_chatstate, chatstate)
def copy_contact(self, contact):
return self.create_contact(jid = contact.jid, name = contact.name,
groups = contact.groups, show = contact.show, status = contact.status,
sub = contact.sub, ask = contact.ask, resource = contact.resource,
priority = contact.priority, keyID = contact.keyID,
our_chatstate = contact.our_chatstate, chatstate = contact.chatstate)
def add_contact(self, account, contact):
# No such account before ?
if not self._contacts.has_key(account):
self._contacts[account] = {contact.jid : [contact]}
return
# No such jid before ?
if not self._contacts[account].has_key(contact.jid):
self._contacts[account][contact.jid] = [contact]
return
# If same JID with same resource already exists, use the new one
for c in self._contacts[account][contact.jid]:
if c.resource == contact.resource:
self.remove_contact(account, c)
break
self._contacts[account][contact.jid].append(contact)
def remove_contact(self, account, contact):
if not self._contacts.has_key(account):
return
if not self._contacts[account].has_key(contact.jid):
return
if contact in self._contacts[account][contact.jid]:
self._contacts[account][contact.jid].remove(contact)
# It was the last resource of this contact ?
if not len(self._contacts[account][contact.jid]):
del self._contacts[account][contact.jid]
def remove_jid(self, account, jid):
'''Removes all contacts for a given jid'''
if not self._contacts.has_key(account):
return
if not self._contacts[account].has_key(jid):
return
del self._contacts[account][jid]
def get_contact(self, account, jid, resource = None):
'''Returns the list of contact instances for this jid (one per resource)
if no resource is given
returns the contact instance for the given resource if it's given
or None if there is not'''
if jid in self._contacts[account]:
contacts = self._contacts[account][jid]
if not resource:
return contacts
for c in contacts:
if c.resource == resource:
return c
return None
def is_subcontact(self, account, contact):
if contact.jid in self._sub_contacts[account]:
return True
def get_contacts_from_jid(self, account, jid):
''' we may have two or more resources on that jid '''
if jid in self._contacts[account]:
contacts_instances = self._contacts[account][jid]
return contacts_instances
return []
def get_highest_prio_contact_from_contacts(self, contacts):
if not contacts:
return None
prim_contact = contacts[0]
for contact in contacts[1:]:
if int(contact.priority) > int(prim_contact.priority):
prim_contact = contact
return prim_contact
def get_contact_with_highest_priority(self, account, jid):
contacts = self.get_contacts_from_jid(account, jid)
return self.get_highest_prio_contact_from_contacts(contacts)
def get_first_contact_from_jid(self, account, jid):
if jid in self._contacts[account]:
return self._contacts[account][jid][0]
else: # it's fake jid
room, nick = common.gajim.get_room_and_nick_from_fjid(jid)
if self._gc_contacts[account].has_key(room) and \
nick in self._gc_contacts[account][room]:
return self._gc_contacts[account][room][nick]
return None
def get_parent_contact(self, account, contact):
'''Returns the parent contact of contact if it's a sub-contact,
else contact'''
if is_subcontact(account, contact):
parrent_jid = self._sub_contacts[account][contact.jid]
return self.get_contact_with_highest_priority(account,
parrent_jid)
return contact
def get_master_contact(self, account, contact):
'''Returns the master contact of contact (parent of parent...) if it's a
sub-contact, else contact'''
while is_subcontact(account, contact):
parrent_jid = self._sub_contacts[account][contact.jid]
contact = self.get_contact_with_highest_priority(account,
parrent_jid)
return contact
def is_pm_from_jid(self, account, jid):
'''Returns True if the given jid is a private message jid'''
if jid in self._contacts[account]:
return False
return True
def is_pm_from_contact(self, account, contact):
'''Returns True if the given contact is a private message contact'''
if isinstance(contact, Contcat):
return False
return True
def get_jid_list(self, account):
return self._contacts[account].keys()
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,
groups = ['none'], show = gc_contact.show, status = gc_contact.status,
sub = 'none')
def create_gc_contact(self, room_jid='', name='', show='', status='',
role='', affiliation='', jid=''):
return GC_Contact(room_jid, name, show, status, role, affiliation, jid)
def add_gc_contact(self, account, gc_contact):
# No such account before ?
if not self._gc_contacts.has_key(account):
self._contacts[account] = {gc_contact.room_jid : {gc_contact.name: \
gc_contact}}
return
# No such room_jid before ?
if not self._gc_contacts[account].has_key(gc_contact.room_jid):
self._gc_contacts[account][gc_contact.room_jid] = {gc_contact.name: \
gc_contact}
return
self._gc_contacts[account][gc_contact.room_jid][gc_contact.name] = \
gc_contact
def remove_gc_contact(self, account, gc_contact):
if not self._gc_contacts.has_key(account):
return
if not self._gc_contacts[account].has_key(gc_contact.room_jid):
return
if not self._gc_contacts[account][gc_contact.room_jid].has_key(
gc_contact.name):
return
del self._gc_contacts[account][gc_contact.room_jid][gc_contact.name]
# It was the last nick in room ?
if not len(self._gc_contacts[account][gc_contact.room_jid]):
del self._gc_contacts[account][gc_contact.room_jid]
def remove_room(self, account, room_jid):
if not self._gc_contacts.has_key(account):
return
if not self._gc_contacts[account].has_key(room_jid):
return
del self._gc_contacts[account][room_jid]
def get_gc_contact(self, account, room_jid, nick):
if not self._gc_contacts.has_key(account):
return
if not self._gc_contacts[account].has_key(room_jid):
return
if not self._gc_contacts[account][room_jid].has_key(nick):
return
del self._gc_contacts[account][room_jid][nick]
def get_gc_list(self, account):
if not self._gc_contacts.has_key(account):
return []
return self._gc_contacts[account].keys()
def get_nick_list(self, account, room_jid):
gc_list = self.get_gc_list(account)
if not room_jid in gc_list:
return []
return self._gc_contacts[account][room_jid].keys()
def get_gc_contact(self, account, room_jid, nick):
nick_list = self.get_nick_list(account, room_jid)
if not nick in nick_list:
return None
return self._gc_contacts[account][room_jid][nick]
......@@ -29,7 +29,7 @@ import logging
import mutex
import config
from contacts import Contacts
interface = None # The actual interface (the gtk one for the moment)
version = '0.10'
......@@ -77,8 +77,7 @@ last_message_time = {} # list of time of the latest incomming message
# {acct1: {jid1: time1, jid2: time2}, }
encrypted_chats = {} # list of encrypted chats {acct1: [jid1, jid2], ..}
contacts = {} # list of contacts {acct: {jid1: [C1, C2]}, } one Contact per resource
gc_contacts = {} # list of contacts that are in gc {acct: {room_jid: {nick: C}}}
contacts = Contacts()
gc_connected = {} # tell if we are connected to the room or not {acct: {room_jid: True}}
gc_passwords = {} # list of the pass required to enter a room {room_jid: password}
......@@ -159,40 +158,9 @@ def get_real_jid_from_fjid(account, fjid):
def get_room_from_fjid(jid):
return get_room_and_nick_from_fjid(jid)[0]
def get_contact_instances_from_jid(account, jid):
''' we may have two or more resources on that jid '''
if jid in contacts[account]:
contacts_instances = contacts[account][jid]
return contacts_instances
def get_first_contact_instance_from_jid(account, jid):
contact = None
if jid in contacts[account]:
contact = contacts[account][jid][0]
else: # it's fake jid
#FIXME: problem see comment in next line
room, nick = \
get_room_and_nick_from_fjid(jid) # if we ban/kick we now real jid
if gc_contacts[account].has_key(room) and \
nick in gc_contacts[account][room]:
contact = gc_contacts[account][room][nick]
return contact
def get_contact_instance_with_highest_priority(account, jid):
contact_instances = contacts[account][jid]
return get_highest_prio_contact_from_contacts(contact_instances)
def get_contact_name_from_jid(account, jid):
return contacts[account][jid][0].name
def get_highest_prio_contact_from_contacts(contacts):
prim_contact = None # primary contact
for contact in contacts:
if prim_contact == None or int(contact.priority) > \
int(prim_contact.priority):
prim_contact = contact
return prim_contact
def get_jid_without_resource(jid):
return jid.split('/')[0]
......
......@@ -43,7 +43,6 @@ try:
except:
HAS_GTK_SPELL = False
from gajim import Contact
from common import helpers
from common import gajim
from common import connection
......@@ -556,7 +555,7 @@ class PreferencesWindow:
# open new tabbed chat windows
for jid in jids:
if kind == 'chats':
c = gajim.get_contact_instance_with_highest_priority(acct, jid)
c = gajim.contacts.get_contact_with_highest_priority(acct, jid)
gajim.interface.roster.new_chat(c, acct)
if kind == 'gc':
gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct)
......@@ -586,7 +585,7 @@ class PreferencesWindow:
# open new tabbed chat windows
for jid in jids:
if kind == 'chats':
c = gajim.get_contact_instance_with_highest_priority(acct, jid)
c = gajim.contacts.get_contact_with_highest_priority(acct, jid)
gajim.interface.roster.new_chat(c, acct)
if kind == 'gc':
gajim.interface.roster.new_room(jid, saved_var[jid]['nick'], acct)
......@@ -1259,8 +1258,6 @@ class AccountModificationWindow:
gajim.allow_notifications[name] = \
gajim.allow_notifications[self.account]
gajim.groups[name] = gajim.groups[self.account]
gajim.contacts[name] = gajim.contacts[self.account]
gajim.gc_contacts[name] = gajim.gc_contacts[self.account]
gajim.gc_connected[name] = gajim.gc_connected[self.account]
gajim.newly_added[name] = gajim.newly_added[self.account]
gajim.to_be_removed[name] = gajim.to_be_removed[self.account]
......@@ -1272,6 +1269,8 @@ class AccountModificationWindow:
gajim.status_before_autoaway[self.account]
gajim.events_for_ui[name] = gajim.events_for_ui[self.account]
gajim.contacts.change_account_name(self.account, name)
#upgrade account variable in opened windows
for kind in ('infos', 'disco', 'chats', 'gc', 'gc_config'):
for j in gajim.interface.instances[name][kind]:
......@@ -1288,8 +1287,6 @@ class AccountModificationWindow:
del gajim.nicks[self.account]
del gajim.allow_notifications[self.account]
del gajim.groups[self.account]
del gajim.contacts[self.account]
del gajim.gc_contacts[self.account]
del gajim.gc_connected[self.account]
del gajim.newly_added[self.account]
del gajim.to_be_removed[self.account]
......@@ -1860,13 +1857,6 @@ class ServiceRegistrationWindow(DataFormWindow):
entry.grab_focus()
table.show_all()
def add_transport_to_roster(self):
user1 = Contact(jid = self.service, name = self.service,
groups = [_('Transports')], show = 'offline', status = 'offline',
sub = 'from')
gajim.contacts[self.account][self.service] = [user1]
gajim.interface.roster.add_contact_to_roster(self.service, self.account)
def on_ok_button_clicked(self, widget):
'''When Ok button is clicked:
send registration info to the core'''
......@@ -1877,7 +1867,8 @@ class ServiceRegistrationWindow(DataFormWindow):
if self.infos.has_key('registered'):
del self.infos['registered']
else:
self.add_transport_to_roster()
gajim.interface.roster.add_transport_to_roster(self.account,
self.service)
gajim.connections[self.account].register_agent(self.service, self.infos)
self.window.destroy()
......@@ -1886,7 +1877,8 @@ class ServiceRegistrationWindow(DataFormWindow):
if self.infos.has_key('registered'):
del self.infos['registered']
else:
self.add_transport_to_roster()
gajim.interface.roster.add_transport_to_roster(self.account,
self.service)
gajim.connections[self.account].register_agent(self.service, self.infos,
True) # True is for is_form
self.window.destroy()
......@@ -2183,8 +2175,7 @@ class RemoveAccountWindow:
del gajim.nicks[self.account]
del gajim.allow_notifications[self.account]
del gajim.groups[self.account]
del gajim.contacts[self.account]
del gajim.gc_contacts[self.account]
gajim.contacts.remove_account(self.account)
del gajim.gc_connected[self.account]
del gajim.to_be_removed[self.account]
del gajim.newly_added[self.account]
......@@ -2724,8 +2715,7 @@ _('You can set advanced account options by pressing Advanced button, or later by
gajim.awaiting_events[self.account] = {}
gajim.connections[self.account].connected = 0
gajim.groups[self.account] = {}
gajim.contacts[self.account] = {}
gajim.gc_contacts[self.account] = {}
gajim.contacts.add_account(self.account)
gajim.gc_connected[self.account] = {}
gajim.newly_added[self.account] = []
gajim.to_be_removed[self.account] = []
......
......@@ -371,8 +371,8 @@ class ConversationTextview(gtk.TextView):
self.on_join_group_chat_menuitem_activate, text)
allow_add = False
if gajim.contacts[self.account].has_key(text):
c = gajim.contacts[self.account][text][0]
c = gajim.contacts.get_first_contact_from_jid(self.account, text)
if c and not gajim.contacts.is_pm_from_contact(self.account, c):
if _('not in the roster') in c.groups:
allow_add = True
else: # he or she's not at all in the account contacts
......
......@@ -43,7 +43,6 @@ except:
from filetransfers_window import FileTransfersWindow
from gajim_themes_window import GajimThemesWindow
from advanced import AdvancedConfigurationWindow