* 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 return
all_jid = gajim.contacts.get_metacontacts_jids(tag) all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid: for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue
for _jid in all_jid[_account]: for _jid in all_jid[_account]:
c = gajim.contacts.get_first_contact_from_jid(_account, _jid) c = gajim.contacts.get_first_contact_from_jid(_account, _jid)
if not c: if not c:
@ -97,6 +99,8 @@ class EditGroupsDialog:
return return
all_jid = gajim.contacts.get_metacontacts_jids(tag) all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid: for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue
for _jid in all_jid[_account]: for _jid in all_jid[_account]:
contacts = gajim.contacts.get_contact(_account, _jid) contacts = gajim.contacts.get_contact(_account, _jid)
for contact in contacts: for contact in contacts:
@ -112,6 +116,8 @@ class EditGroupsDialog:
return return
all_jid = gajim.contacts.get_metacontacts_jids(tag) all_jid = gajim.contacts.get_metacontacts_jids(tag)
for _account in all_jid: for _account in all_jid:
if not gajim.interface.roster.regroup and _account != self.account:
continue
for _jid in all_jid[_account]: for _jid in all_jid[_account]:
contacts = gajim.contacts.get_contact(_account, _jid) contacts = gajim.contacts.get_contact(_account, _jid)
for contact in contacts: for contact in contacts:
@ -355,7 +361,8 @@ class ChangeStatusMessageDialog:
class AddNewContactWindow: class AddNewContactWindow:
'''Class for 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 self.account = account
if account == None: if account == None:
# fill accounts with active accounts # 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) liststore = gtk.ListStore(str)
self.group_comboboxentry.set_model(liststore) self.group_comboboxentry.set_model(liststore)
group_names = [] group_names = []
i = 0
for acct in accounts: for acct in accounts:
for g in gajim.groups[acct].keys(): for g in gajim.groups[acct].keys():
if g not in helpers.special_groups and g not in group_names: if g not in helpers.special_groups and g not in group_names:
group_names.append(g) group_names.append(g)
self.group_comboboxentry.append_text(g) self.group_comboboxentry.append_text(g)
if group == g:
self.group_comboboxentry.set_active(i)
i += 1
if not jid_agents: if not jid_agents:
# There are no transports, so hide the protocol combobox and label # There are no transports, so hide the protocol combobox and label

View File

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