Commit 73415c51 authored by Yann Leboulanger's avatar Yann Leboulanger

show bookmarked rooms in invite to menu when possible. Fixes #4455

parent d0ec490b
......@@ -42,6 +42,7 @@ import config
import vcard
import cell_renderer_image
import dataforms_widget
import nbxmpp
from common import gajim
from common import helpers
......@@ -2500,9 +2501,13 @@ class GroupchatControl(ChatControlBase):
muc_icon = gtkgui_helpers.load_icon('muc_active')
if muc_icon:
item.set_image(muc_icon)
if c.jid and c.name != self.nick:
if jid and c.name != self.nick:
bookmarked = False
contact = gajim.contacts.get_contact(self.account, jid, c.resource)
if contact and contact.supports(nbxmpp.NS_CONFERENCE):
bookmarked=True
gui_menu_builder.build_invite_submenu(item, ((c, self.account),),
ignore_rooms=[self.room_jid])
ignore_rooms=[self.room_jid], show_bookmarked=bookmarked)
else:
item.set_sensitive(False)
......
......@@ -26,7 +26,7 @@ import message_control
from common import gajim
from common import helpers
from nbxmpp.protocol import NS_COMMANDS, NS_FILE, NS_MUC, NS_ESESSION
from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER
from nbxmpp.protocol import NS_JINGLE_FILE_TRANSFER, NS_CONFERENCE
def build_resources_submenu(contacts, account, action, room_jid=None,
room_account=None, cap=None):
......@@ -63,7 +63,8 @@ def build_resources_submenu(contacts, account, action, room_jid=None,
return sub_menu
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[]):
def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[],
show_bookmarked=False):
"""
list_ in a list of (contact, account)
"""
......@@ -150,7 +151,9 @@ def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[]):
item = gtk.SeparatorMenuItem() # separator
invite_to_submenu.append(item)
for (room_jid, account) in rooms:
menuitem = gtk.MenuItem(room_jid.split('@')[0])
menuitem = gtk.ImageMenuItem(room_jid.split('@')[0])
muc_active_icon = gtkgui_helpers.load_icon('muc_active')
menuitem.set_image(muc_active_icon)
if len(contact_list) > 1: # several resources
menuitem.set_submenu(build_resources_submenu(
contact_list, account, roster.on_invite_to_room, room_jid,
......@@ -162,9 +165,45 @@ def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[]):
else:
resource = None
menuitem.connect('activate', roster.on_invite_to_room, list_,
room_jid, account, resource)
room_jid, account, resource)
invite_to_submenu.append(menuitem)
if not show_bookmarked:
return
rooms2 = [] # a list of (room_jid, account) tuple
r_jids = [] # list of room jids
for account in connected_accounts:
for room in gajim.connections[account].bookmarks:
r_jid = room['jid']
if r_jid in r_jids:
continue
if r_jid not in gajim.gc_connected[account] or not \
gajim.gc_connected[account][r_jid]:
rooms2.append((r_jid, account))
r_jids.append(r_jid)
if not rooms2:
return
item = gtk.SeparatorMenuItem() # separator
invite_to_submenu.append(item)
for (room_jid, account) in rooms2:
menuitem = gtk.ImageMenuItem(room_jid.split('@')[0])
muc_inactive_icon = gtkgui_helpers.load_icon('muc_inactive')
menuitem.set_image(muc_inactive_icon)
if len(contact_list) > 1: # several resources
menuitem.set_submenu(build_resources_submenu(
contact_list, account, roster.on_invite_to_room, room_jid,
account))
else:
# use resource if it's self contact
if contact.jid == gajim.get_jid_from_account(account):
resource = contact.resource
else:
resource = None
menuitem.connect('activate', roster.on_invite_to_room, list_,
room_jid, account, resource)
invite_to_submenu.append(menuitem)
def get_contact_menu(contact, account, use_multiple_contacts=True,
show_start_chat=True, show_encryption=False, show_buttonbar_items=True,
control=None, gc_contact=None, is_anonymous=True):
......@@ -402,9 +441,16 @@ control=None, gc_contact=None, is_anonymous=True):
# it's a pm and we don't know real JID
invite_menuitem.set_sensitive(False)
else:
build_invite_submenu(invite_menuitem, [(gc_contact, account)])
bookmarked = False
c_ = gajim.contacts.get_contact(account, gc_contact.jid,
gc_contact.resource)
if c_ and c_.supports(nbxmpp.NS_CONFERENCE):
bookmarked=True
build_invite_submenu(invite_menuitem, [(gc_contact, account)],
show_bookmarked=bookmarked)
else:
build_invite_submenu(invite_menuitem, [(contact, account)])
build_invite_submenu(invite_menuitem, [(contact, account)],
show_bookmarked=contact.supports(NS_CONFERENCE))
if gajim.account_is_disconnected(account):
invite_menuitem.set_sensitive(False)
......@@ -651,4 +697,4 @@ def get_transport_menu(contact, account):
menu.connect('selection-done', gtkgui_helpers.destroy_widget)
menu.show_all()
return menu
\ No newline at end of file
return menu
......@@ -70,7 +70,7 @@ from common import dbus_support
if dbus_support.supported:
import dbus
from nbxmpp.protocol import NS_FILE, NS_ROSTERX
from nbxmpp.protocol import NS_FILE, NS_ROSTERX, NS_CONFERENCE
from common.pep import MOODS, ACTIVITIES
#(icon, name, type, jid, account, editable, second pixbuf)
......@@ -5715,9 +5715,10 @@ class RosterWindow:
group = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
list_ = [] # list of (jid, account) tuples
list_online = [] # list of (jid, account) tuples
list_ = [] # list of (contact, account) tuples
list_online = [] # list of (contact, account) tuples
show_bookmarked = True
group = model[titer][C_JID]
for jid in gajim.contacts.get_jid_list(account):
contact = gajim.contacts.get_contact_with_highest_priority(account,
......@@ -5725,6 +5726,9 @@ class RosterWindow:
if group in contact.get_shown_groups():
if contact.show not in ('offline', 'error'):
list_online.append((contact, account))
# Check that all contacts support direct NUC invite
if not contact.supports(NS_CONFERENCE):
show_bookmarked = False
list_.append((contact, account))
menu = gtk.Menu()
......@@ -5768,7 +5772,8 @@ class RosterWindow:
if muc_icon:
invite_menuitem.set_image(muc_icon)
gui_menu_builder.build_invite_submenu(invite_menuitem, list_online)
gui_menu_builder.build_invite_submenu(invite_menuitem, list_online,
show_bookmarked=show_bookmarked)
menu.append(invite_menuitem)
# Send Custom Status
......@@ -5917,6 +5922,12 @@ class RosterWindow:
account = None
break
account = current_account
show_bookmarked = True
for (contact, current_account) in list_:
# Check that all contacts support direct NUC invite
if not contact.supports(NS_CONFERENCE):
show_bookmarked = False
break
if account is not None:
send_group_message_item = gtk.ImageMenuItem(
_('Send Group M_essage'))
......@@ -5932,7 +5943,8 @@ class RosterWindow:
if muc_icon:
invite_item.set_image(muc_icon)
gui_menu_builder.build_invite_submenu(invite_item, list_)
gui_menu_builder.build_invite_submenu(invite_item, list_,
show_bookmarked=show_bookmarked)
menu.append(invite_item)
item = gtk.SeparatorMenuItem() # separator
......
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