core, frontends (menus): MENU_ROOM and MENU_SINGLE are now managed

This commit is contained in:
Goffi 2014-06-26 00:05:20 +02:00
commit 08be0324a6
2 changed files with 66 additions and 44 deletions

View file

@ -132,11 +132,11 @@ class Chat(urwid.WidgetWrap, QuickChat):
"""Return Menu bar"""
menu = sat_widgets.Menu(self.host.loop)
if self.type == 'group':
self.host.addMenus(menu, C.MENU_ROOM, {'room_jid': self.target.bare})
game = _("Game")
muc = _("MUC")
menu.addMenu(game, "Tarot", self.onTarotRequest)
menu.addMenu(muc, _("Configure room"), self.onConfigureRoom)
elif self.type == 'one2one':
self.host.addMenus(menu, C.MENU_SINGLE, {'jid': self.target})
menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest)
return menu
@ -345,6 +345,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
#MENU EVENTS#
def onTarotRequest(self, menu):
# TODO: move this to plugin_misc_tarot with dynamic menu
if len(self.occupants) != 4:
self.host.showPopUp(sat_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp))
else:
@ -358,6 +359,7 @@ class Chat(urwid.WidgetWrap, QuickChat):
self.host.bridge.configureRoom(self.id, self.host.profile, callback=gotUI, errback=configureError)
def onSendFileRequest(self, menu):
# TODO: move this to core with dynamic menus
dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp)
self.host.showPopUp(dialog, 80, 80)

View file

@ -282,6 +282,22 @@ class PrimitivusApp(QuickApp, InputHistory):
except AttributeError:
return input
def addMenus(self, menu, type_, menu_data=None):
"""Add cached menus to instance
@param menu: sat_widgets.Menu instance
@param type_: menu type like is sat.core.sat_main.importMenu
@param menu_data: data to send with these menus
"""
menus = self.profiles[self.profile]['menus'].get(type_,[])
def add_menu_cb(callback_id):
self.launchAction(callback_id, menu_data, profile_key = self.profile)
for id_, path, path_i18n in menus:
if len(path) != 2:
raise NotImplementedError("Menu with a path != 2 are not implemented yet")
menu.addMenu(path_i18n[0], path_i18n[1], lambda dummy,id_=id_: add_menu_cb(id_))
def _buildMenuRoller(self):
menu = sat_widgets.Menu(self.loop)
general = _("General")
@ -296,14 +312,7 @@ class PrimitivusApp(QuickApp, InputHistory):
menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
#additionals menus
#FIXME: do this in a more generic way (in quickapp)
add_menus = self.bridge.getMenus('', C.NO_SECURITY_LIMIT)
def add_menu_cb(callback_id):
self.launchAction(callback_id, None, profile_key = self.profile)
for id_, type_, path, path_i18n in add_menus:
assert(type_=="NORMAL") #TODO: manage other types
if len(path) != 2:
raise NotImplementedError("Menu with a path != 2 are not implemented yet")
menu.addMenu(path_i18n[0], path_i18n[1], lambda menu,id_=id_: add_menu_cb(id_))
self.addMenus(menu, C.MENU_GLOBAL)
menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
return menu_roller