Commit 28dee086 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

[misc] ability to send messages to a group or to several contacts. fixes #1823

parent 1add317c
......@@ -1463,8 +1463,12 @@ class SingleMessageWindow:
self.cancel_button = self.xml.get_widget('cancel_button')
self.close_button = self.xml.get_widget('close_button')
self.message_tv_buffer.connect('changed', self.update_char_counter)
self.to_entry.set_text(to)
if type(to) == type([]):
jid = ', '.join( [i[0].jid + '/' + i[0].resource for i in to])
self.to_entry.set_text(jid)
self.to_entry.set_sensitive(False)
else:
self.to_entry.set_text(to)
if gajim.config.get('use_speller') and HAS_GTK_SPELL and action == 'send':
try:
......@@ -1616,22 +1620,27 @@ class SingleMessageWindow:
ErrorDialog(_('Connection not available'),
_('Please make sure you are connected with "%s".') % self.account)
return
to_whom_jid = self.to_entry.get_text().decode('utf-8')
if self.completion_dict.has_key(to_whom_jid):
to_whom_jid = self.completion_dict[to_whom_jid].jid
subject = self.subject_entry.get_text().decode('utf-8')
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end).decode('utf-8')
if to_whom_jid.find('/announce/') != -1:
gajim.connections[self.account].send_motd(to_whom_jid, subject,
message)
return
if type(self.to) == type([]):
sender_list = [i[0].jid + '/' + i[0].resource for i in self.to]
else:
sender_list = [self.to_entry.get_text().decode('utf-8')]
for to_whom_jid in sender_list:
if self.completion_dict.has_key(to_whom_jid):
to_whom_jid = self.completion_dict[to_whom_jid].jid
subject = self.subject_entry.get_text().decode('utf-8')
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end).decode('utf-8')
if to_whom_jid.find('/announce/') != -1:
gajim.connections[self.account].send_motd(to_whom_jid, subject,
message)
return
# FIXME: allow GPG message some day
gajim.connections[self.account].send_message(to_whom_jid, message,
keyID = None, type = 'normal', subject=subject)
# FIXME: allow GPG message some day
gajim.connections[self.account].send_message(to_whom_jid, message,
keyID = None, type = 'normal', subject=subject)
self.subject_entry.set_text('') # we sent ok, clear the subject
self.message_tv_buffer.set_text('') # we sent ok, clear the textview
......
......@@ -1432,6 +1432,8 @@ class RosterWindow:
contact = None):
if contact is None:
dialogs.SingleMessageWindow(account, action = 'send')
elif type(contact) == type([]):
dialogs.SingleMessageWindow(account, contact, 'send')
else:
jid = contact.jid
if contact.jid == gajim.get_jid_from_account(account):
......@@ -1863,6 +1865,19 @@ class RosterWindow:
edit_groups_item = gtk.MenuItem(_('Edit _Groups'))
menu.append(edit_groups_item)
edit_groups_item.connect('activate', self.on_edit_groups, list_)
account = None
for (contact, current_account) in list_:
# check that we use the same account for every sender
if account is not None and account != current_account:
account = None
break
account = current_account
if account is not None:
send_group_message_item = gtk.MenuItem(_('Send Group M_essage'))
menu.append(send_group_message_item)
send_group_message_item.connect('activate',
self.on_send_single_message_menuitem_activate, account, list_)
# unsensitive if one account is not connected
if one_account_offline:
......@@ -1881,24 +1896,51 @@ class RosterWindow:
path = model.get_path(iter)
group = model[iter][C_JID].decode('utf-8')
account = model[iter][C_ACCOUNT].decode('utf-8')
if group in helpers.special_groups + (_('General'),):
return
menu = gtk.Menu()
if not group in helpers.special_groups + (_('General'),):
rename_item = gtk.ImageMenuItem(_('Re_name'))
# add a special img for rename menuitem
path_to_kbd_input_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
'kbd_input.png')
img = gtk.Image()
img.set_from_file(path_to_kbd_input_img)
rename_item.set_image(img)
menu.append(rename_item)
rename_item.connect('activate', self.on_rename, iter, path)
rename_item = gtk.ImageMenuItem(_('Re_name'))
# add a special img for rename menuitem
path_to_kbd_input_img = os.path.join(gajim.DATA_DIR, 'pixmaps',
'kbd_input.png')
img = gtk.Image()
img.set_from_file(path_to_kbd_input_img)
rename_item.set_image(img)
menu.append(rename_item)
rename_item.connect('activate', self.on_rename, iter, path)
# unsensitive if account is not connected
if gajim.connections[account].connected < 2:
rename_item.set_sensitive(False)
send_group_message_item = gtk.MenuItem(_('Send Group M_essage'))
send_group_message_submenu = gtk.Menu()
send_group_message_item.set_submenu(send_group_message_submenu)
menu.append(send_group_message_item)
group_message_to_all_item = gtk.MenuItem(_('To all users'))
send_group_message_submenu.append(group_message_to_all_item)
group_message_to_all_online_item = gtk.MenuItem(_('To all online users'))
send_group_message_submenu.append(group_message_to_all_online_item)
list_ = [] # list of (jid, account) tuples
list_online = [] # list of (jid, account) tuples
group = model[iter][C_NAME]
for jid in gajim.contacts.get_jid_list(account):
contact = gajim.contacts.get_contact_with_highest_priority(account,
jid)
if group in contact.groups or (contact.groups == [] and group == _('General')):
if contact.show not in ('offline', 'error'):
list_online.append((contact, account))
list_.append((contact, account))
group_message_to_all_online_item.connect('activate',
self.on_send_single_message_menuitem_activate, account, list_online)
group_message_to_all_item.connect('activate',
self.on_send_single_message_menuitem_activate, account, list_)
# unsensitive if account is not connected
if gajim.connections[account].connected < 2:
rename_item.set_sensitive(False)
event_button = gtkgui_helpers.get_possible_button_event(event)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment