* meta contacts over accounts

* DND a contact to another group asks to add it in this group
Fixes #1515
This commit is contained in:
Yann Leboulanger 2006-06-28 07:27:40 +00:00
parent cb4e46d627
commit 60f9741046
2 changed files with 83 additions and 70 deletions

View File

@ -80,6 +80,8 @@ class EditGroupsDialog:
return
all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue
for _jid in all_jid[_account]:
c = gajim.contacts.get_first_contact_from_jid(_account, _jid)
if not c:
@ -97,6 +99,8 @@ class EditGroupsDialog:
return
all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue
for _jid in all_jid[_account]:
contacts = gajim.contacts.get_contact(_account, _jid)
for contact in contacts:
@ -112,6 +116,8 @@ class EditGroupsDialog:
return
all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue
for _jid in all_jid[_account]:
contacts = gajim.contacts.get_contact(_account, _jid)
for contact in contacts:
@ -355,7 +361,8 @@ class ChangeStatusMessageDialog:
class AddNewContactWindow:
'''Class for AddNewContactWindow'''
def __init__(self, account = None, jid = None, user_nick = None):
def __init__(self, account = None, jid = None, user_nick = None,
group = None):
self.account = account
if account == None:
# fill accounts with active accounts
@ -433,11 +440,15 @@ _('Please fill in the data of the contact you want to add in account %s') %accou
liststore = gtk.ListStore(str)
self.group_comboboxentry.set_model(liststore)
group_names = []
i = 0
for acct in accounts:
for g in gajim.groups[acct].keys():
if g not in helpers.special_groups and g not in group_names:
group_names.append(g)
self.group_comboboxentry.append_text(g)
if group == g:
self.group_comboboxentry.set_active(i)
i += 1
if not jid_agents:
# There are no transports, so hide the protocol combobox and label

View File

@ -237,9 +237,8 @@ class RosterWindow:
if family:
for data in family:
_account = data['account']
#XXX When we support metacontacts from different servers, make
# sure that loop from #1953 is fixed and remove next 2 lines!
if _account != account:
# Metacontacts over different accounts only in merged mode
if _account != account and not self.regroup:
continue
_jid = data['jid']
@ -475,15 +474,18 @@ class RosterWindow:
if icon_name in ('error', 'offline'):
# get the icon from the first child as they are sorted by show
child_jid = model[child_iter][C_JID].decode('utf-8')
child_account = model[child_iter][C_ACCOUNT].decode('utf-8')
child_contact = gajim.contacts.get_contact_with_highest_priority(
account, child_jid)
child_icon_name = helpers.get_icon_name_to_show(child_contact, account)
child_account, child_jid)
child_icon_name = helpers.get_icon_name_to_show(child_contact,
child_account)
if child_icon_name not in ('error', 'not in roster'):
icon_name = child_icon_name
while child_iter:
# a child has awaiting messages ?
child_jid = model[child_iter][C_JID].decode('utf-8')
if gajim.awaiting_events[account].has_key(child_jid):
child_account = model[child_iter][C_ACCOUNT].decode('utf-8')
if gajim.awaiting_events[child_account].has_key(child_jid):
icon_name = 'message'
break
child_iter = model.iter_next(child_iter)
@ -3032,30 +3034,32 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
data = model[iter][C_JID]
selection.set(selection.target, 8, data)
def on_drop_in_contact(self, widget, account, c_source, c_dest,
was_big_brother, context, etime):
def on_drop_in_contact(self, widget, account_source, c_source, account_dest,
c_dest, was_big_brother, context, etime):
# children must take the new tag too, so remember old tag
old_tag = gajim.contacts.get_metacontacts_tag(account, c_source.jid)
old_tag = gajim.contacts.get_metacontacts_tag(account_source,
c_source.jid)
# remove the source row
self.remove_contact(c_source, account)
self.remove_contact(c_source, account_source)
# brother inherite big brother groups
c_source.groups = []
for g in c_dest.groups:
c_source.groups.append(g)
gajim.contacts.add_metacontact(account, c_dest.jid, account, c_source.jid)
gajim.contacts.add_metacontact(account_dest, c_dest.jid, account_source,
c_source.jid)
if was_big_brother:
# add brothers too
all_jid = gajim.contacts.get_metacontacts_jids(old_tag)
for _account in all_jid:
for _jid in all_jid[_account]:
gajim.contacts.add_metacontact(account, c_dest.jid, _account,
_jid)
gajim.contacts.add_metacontact(account_dest, c_dest.jid,
_account, _jid)
_c = gajim.contacts.get_first_contact_from_jid(_account, _jid)
self.remove_contact(_c, _account)
self.add_contact_to_roster(_jid, _account)
self.draw_contact(_jid, _account)
self.add_contact_to_roster(c_source.jid, account)
self.draw_contact(c_dest.jid, account)
self.add_contact_to_roster(c_source.jid, account_source)
self.draw_contact(c_dest.jid, account_dest)
context.finish(True, True, etime)
@ -3104,10 +3108,10 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
iter_dest = model.get_iter(path_dest)
type_dest = model[iter_dest][C_TYPE].decode('utf-8')
jid_dest = model[iter_dest][C_JID].decode('utf-8')
account = model[iter_dest][C_ACCOUNT].decode('utf-8')
account_dest = model[iter_dest][C_ACCOUNT].decode('utf-8')
# if account is not connected, do nothing
if gajim.connections[account].connected < 2:
if gajim.connections[account_dest].connected < 2:
return
if info == self.TARGET_TYPE_URI_LIST:
@ -3116,15 +3120,15 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
return
if type_dest != 'contact':
return
c_dest = gajim.contacts.get_contact_with_highest_priority(account,
c_dest = gajim.contacts.get_contact_with_highest_priority(account_dest,
jid_dest)
uri = data.strip()
uri_splitted = uri.split() # we may have more than one file dropped
for uri in uri_splitted:
path = helpers.get_file_path_from_dnd_dropped_uri(uri)
if os.path.isfile(path): # is it file?
gajim.interface.instances['file_transfers'].send_file(account,
c_dest, path)
gajim.interface.instances['file_transfers'].send_file(
account_dest, c_dest, path)
return
if position == gtk.TREE_VIEW_DROP_BEFORE and len(path_dest) == 2:
@ -3133,18 +3137,10 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
iter_source = treeview.get_selection().get_selected()[1]
path_source = model.get_path(iter_source)
type_source = model[iter_source][C_TYPE]
if type_dest == 'account': # dropped on an account
return
account_source = model[iter_source][C_ACCOUNT].decode('utf-8')
if type_source != 'contact': # source is not a contact
return
source_account = model[iter_source][C_ACCOUNT].decode('utf-8')
disable_meta = False
if account != source_account: # dropped in another account
if self.regroup:
# in merge mode it is ok to change group, but disable meta
account = source_account
disable_meta = True
else:
if type_dest == 'account' and account_source == account_dest:
return
it = iter_source
while model[it][C_TYPE] == 'contact':
@ -3154,36 +3150,47 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
if grp_source in helpers.special_groups:
return
jid_source = data.decode('utf-8')
c_source = gajim.contacts.get_contact_with_highest_priority(account,
jid_source)
# Get destination group
c_source = gajim.contacts.get_contact_with_highest_priority(
account_source, jid_source)
grp_dest = None
if type_dest == 'group':
grp_dest = model[iter_dest][C_JID].decode('utf-8')
if grp_dest in helpers.special_groups:
return
if context.action == gtk.gdk.ACTION_COPY:
self.on_drop_in_group(None, account, c_source, grp_dest, context,
etime)
return
self.on_drop_in_group(None, account, c_source, grp_dest, context,
etime, grp_source)
return
else:
elif type_dest in ('contact', 'agent'):
it = iter_dest
while model[it][C_TYPE] != 'group':
it = model.iter_parent(it)
grp_dest = model[it][C_JID].decode('utf-8')
if (type_dest == 'account' or not self.regroup) and \
account_source != account_dest:
# add contact to this account in that group
dialogs.AddNewContactWindow(account = account_dest, jid = jid_source,
user_nick = c_source.name, group = grp_dest)
return
# Get destination group
if type_dest == 'group':
if grp_dest in helpers.special_groups:
return
if context.action == gtk.gdk.ACTION_COPY:
self.on_drop_in_group(None, account_source, c_source, grp_dest,
context, etime)
return
self.on_drop_in_group(None, account_source, c_source, grp_dest,
context, etime, grp_source)
return
if grp_dest in helpers.special_groups:
return
if jid_source == jid_dest:
if grp_source == grp_dest:
if grp_source == grp_dest and account_source == account_dest:
return
if context.action == gtk.gdk.ACTION_COPY:
self.on_drop_in_group(None, account, c_source, grp_dest, context,
etime)
self.on_drop_in_group(None, account_source, c_source, grp_dest,
context, etime)
return
self.on_drop_in_group(None, account, c_source, grp_dest, context,
etime, grp_source)
self.on_drop_in_group(None, account_source, c_source, grp_dest,
context, etime, grp_source)
return
if grp_source == grp_dest:
# Add meta contact
@ -3192,7 +3199,7 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
# if context.action == gtk.gdk.ACTION_COPY:
# # Keep only MOVE
# return
c_dest = gajim.contacts.get_contact_with_highest_priority(account,
c_dest = gajim.contacts.get_contact_with_highest_priority(account_dest,
jid_dest)
is_big_brother = False
if model.iter_has_child(iter_source):
@ -3200,35 +3207,30 @@ _('If "%s" accepts this request you will know his or her status.') % jid)
if not c_dest:
# c_dest is None if jid_dest doesn't belong to account
return
self.on_drop_in_contact(treeview, account, c_source, c_dest,
is_big_brother, context, etime)
self.on_drop_in_contact(treeview, account_source, c_source,
account_dest, c_dest, is_big_brother, context, etime)
return
# We upgrade only the first user because user2.groups is a pointer to
# user1.groups
if context.action == gtk.gdk.ACTION_COPY:
self.on_drop_in_group(None, account, c_source, grp_dest, context,
etime)
self.on_drop_in_group(None, account_source, c_source, grp_dest,
context, etime)
else:
menu = gtk.Menu()
item = gtk.MenuItem(_('Drop %s in group %s') % (c_source.name,
grp_dest))
item.connect('activate', self.on_drop_in_group, account, c_source,
item.connect('activate', self.on_drop_in_group, account_dest, c_source,
grp_dest, context, etime, grp_source)
menu.append(item)
if not disable_meta:
# source and dest account are the same, enable metacontacts
c_dest = gajim.contacts.get_contact_with_highest_priority(account,
jid_dest)
c_dest = gajim.contacts.get_contact_with_highest_priority(
account_dest, jid_dest)
item = gtk.MenuItem(_('Make %s and %s metacontacts') % (c_source.name,
c_dest.name))
is_big_brother = False
if model.iter_has_child(iter_source):
is_big_brother = True
item.connect('activate', self.on_drop_in_contact, account, c_source,
c_dest, is_big_brother, context, etime)
else: #source and dest account are not the same, disable meta
item = gtk.MenuItem(_('Can\'t create a metacontact with contacts from two different accounts'))
item.set_sensitive(False)
item.connect('activate', self.on_drop_in_contact, account_source,
c_source, account_dest, c_dest, is_big_brother, context, etime)
menu.append(item)