core, frontends: refactoring to base Libervia on QuickFrontend (big mixed commit):
/!\ not finished, everything is still instable !
- bridge: DBus bridge has been modified to allow blocking call to be called in the same way as asynchronous calls
- bridge: calls with a callback and no errback are now possible, default errback log the error
- constants: removed hack to manage presence without OrderedDict, as an OrderedDict like class has been implemented in Libervia
- core: getLastResource has been removed and replaced by getMainResource (there is a global better management of resources)
- various style improvments: use of constants when possible, fixed variable overlaps, import of module instead of direct class import
- frontends: printInfo and printMessage methods in (Quick)Chat are more generic (use of extra instead of timestamp)
- frontends: bridge creation and option parsing (command line arguments) are now specified by the frontend in QuickApp __init__
- frontends: ProfileManager manage a more complete plug sequence (some stuff formerly manage in contact_list have moved to ProfileManager)
- quick_frontend (quick_widgets): QuickWidgetsManager is now iterable (all widgets are then returned), or can return an iterator on a specific class (return all widgets of this class) with getWidgets
- frontends: tools.jid can now be used in Pyjamas, with some care
- frontends (XMLUI): profile is now managed
- core (memory): big improvment on entities cache management (and specially resource management)
- core (params/exceptions): added PermissionError
- various fixes and improvments, check diff for more details
This commit is contained in:
parent
f45e55388f
commit
8ce5c1862b
3 changed files with 1125 additions and 452 deletions
|
|
@ -30,7 +30,7 @@ from sat_frontends.primitivus.constants import Const as C
|
|||
from sat_frontends.primitivus.keys import action_key_map as a_key
|
||||
from sat_frontends.primitivus.widget import PrimitivusWidget
|
||||
import time
|
||||
from sat_frontends.tools.jid import JID
|
||||
from sat_frontends.tools import jid
|
||||
|
||||
|
||||
class ChatText(urwid.FlowWidget):
|
||||
|
|
@ -83,7 +83,7 @@ class ChatText(urwid.FlowWidget):
|
|||
|
||||
class Chat(PrimitivusWidget, QuickChat):
|
||||
|
||||
def __init__(self, host, target, type_='one2one', profiles=None):
|
||||
def __init__(self, host, target, type_=C.CHAT_ONE2ONE, profiles=None):
|
||||
QuickChat.__init__(self, host, target, type_, profiles=profiles)
|
||||
self.content = urwid.SimpleListWalker([])
|
||||
self.text_list = urwid.ListBox(self.content)
|
||||
|
|
@ -93,10 +93,10 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
self.pile = urwid.Pile([self.chat_colums])
|
||||
PrimitivusWidget.__init__(self, self.pile, self.target)
|
||||
|
||||
# we must adapt the behavious with the type
|
||||
if type_ == 'one2one':
|
||||
# we must adapt the behaviour with the type
|
||||
if type_ == C.CHAT_ONE2ONE:
|
||||
self.historyPrint(profile=self.profile)
|
||||
elif type_ == 'group':
|
||||
elif type_ == C.CHAT_GROUP:
|
||||
if len(self.chat_colums.contents) == 1:
|
||||
present_widget = self._buildPresentList()
|
||||
self.present_panel = sat_widgets.VerticalSeparator(present_widget)
|
||||
|
|
@ -110,7 +110,7 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
|
||||
def keypress(self, size, key):
|
||||
if key == a_key['OCCUPANTS_HIDE']: #user wants to (un)hide the presents panel
|
||||
if self.type == 'group':
|
||||
if self.type == C.CHAT_GROUP:
|
||||
widgets = [widget for (widget, options) in self.chat_colums.contents]
|
||||
if self.present_panel in widgets:
|
||||
self._removePresentPanel()
|
||||
|
|
@ -140,11 +140,11 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
def getMenu(self):
|
||||
"""Return Menu bar"""
|
||||
menu = sat_widgets.Menu(self.host.loop)
|
||||
if self.type == 'group':
|
||||
if self.type == C.CHAT_GROUP:
|
||||
self.host.addMenus(menu, C.MENU_ROOM, {'room_jid': self.target.bare})
|
||||
game = _("Game")
|
||||
menu.addMenu(game, "Tarot", self.onTarotRequest)
|
||||
elif self.type == 'one2one':
|
||||
elif self.type == C.CHAT_ONE2ONE:
|
||||
self.host.addMenus(menu, C.MENU_SINGLE, {'jid': self.target})
|
||||
menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest)
|
||||
return menu
|
||||
|
|
@ -170,13 +170,13 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
self.title_dynamic = '({})'.format(state)
|
||||
|
||||
def _presentClicked(self, list_wid, clicked_wid):
|
||||
assert self.type == 'group'
|
||||
assert self.type == C.CHAT_GROUP
|
||||
nick = clicked_wid.getValue().value
|
||||
if nick == self.getUserNick():
|
||||
#We ignore clicks on our own nick
|
||||
return
|
||||
contact_list = self.host.contact_lists[self.profile]
|
||||
full_jid = JID("%s/%s" % (self.target.bare, nick))
|
||||
full_jid = jid.JID("%s/%s" % (self.target.bare, nick))
|
||||
|
||||
#we have a click on a nick, we need to create the widget if it doesn't exists
|
||||
self.getOrCreatePrivateWidget(full_jid)
|
||||
|
|
@ -258,10 +258,16 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
def onPrivateCreated(self, widget):
|
||||
self.host.contact_lists[widget.profile].specialResourceVisible(widget.target)
|
||||
|
||||
def printMessage(self, from_jid, msg, profile, timestamp=None):
|
||||
assert isinstance(from_jid, JID)
|
||||
def printMessage(self, from_jid, msg, extra=None, profile=C.PROF_KEY_NONE):
|
||||
assert isinstance(from_jid, jid.JID)
|
||||
if extra is None:
|
||||
extra = {}
|
||||
try:
|
||||
jid, nick, mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp)
|
||||
timestamp = float(extra['timestamp'])
|
||||
except KeyError:
|
||||
timestamp=None
|
||||
try:
|
||||
nick, mymess = QuickChat.printMessage(self, from_jid, msg, extra, profile)
|
||||
except TypeError:
|
||||
# None is returned, the message is managed
|
||||
return
|
||||
|
|
@ -291,7 +297,7 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
# all messages and not only with the messages coming from the history.
|
||||
self._notify(from_jid, msg)
|
||||
|
||||
def printInfo(self, msg, type_='normal', timestamp=None):
|
||||
def printInfo(self, msg, type_='normal', extra=None):
|
||||
"""Print general info
|
||||
@param msg: message to print
|
||||
@type_: one of:
|
||||
|
|
@ -299,6 +305,12 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist"
|
||||
@param timestamp (float): number of seconds since epoch
|
||||
"""
|
||||
if extra is None:
|
||||
extra = {}
|
||||
try:
|
||||
timestamp = float(extra['timestamp'])
|
||||
except KeyError:
|
||||
timestamp=None
|
||||
_widget = ChatText(self, timestamp, None, False, msg, is_info=True)
|
||||
self.content.append(_widget)
|
||||
self._notify(msg=msg)
|
||||
|
|
@ -316,7 +328,7 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
self.text_list.focus_position = len(self.content) - 1
|
||||
self.host.redraw()
|
||||
if not self.host.x_notify.hasFocus():
|
||||
if self.type == "one2one":
|
||||
if self.type == C.CHAT_ONE2ONE:
|
||||
self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid)
|
||||
elif self.getUserNick().lower() in msg.lower():
|
||||
self.host.x_notify.sendNotification(_("Primitivus: %(user)s mentioned you in room '%(room)s'") % {'user': from_jid, 'room': self.target})
|
||||
|
|
@ -356,9 +368,9 @@ class Chat(PrimitivusWidget, QuickChat):
|
|||
self.host.showDialog(_(u"File has a unicode error in its name, it's not yet managed by SàT"), title=_("Can't send file"), type_="error")
|
||||
return
|
||||
#FIXME: check last_resource: what if self.target.resource exists ?
|
||||
last_resource = self.host.bridge.getLastResource(unicode(self.target.bare), self.profile)
|
||||
last_resource = self.host.bridge.getMainResource(unicode(self.target.bare), self.profile)
|
||||
if last_resource:
|
||||
full_jid = JID("%s/%s" % (self.target.bare, last_resource))
|
||||
full_jid = jid.JID("%s/%s" % (self.target.bare, last_resource))
|
||||
else:
|
||||
full_jid = self.target
|
||||
progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.profile)
|
||||
|
|
|
|||
|
|
@ -148,6 +148,10 @@ class ContactList(PrimitivusWidget, QuickContactList):
|
|||
self.update()
|
||||
self._emit('click', entity)
|
||||
|
||||
def updatePresence(self, entity, show, priority, statuses):
|
||||
super(ContactList, self).updatePresence(entity, show, priority, statuses)
|
||||
self.update()
|
||||
|
||||
# Methods to build the widget
|
||||
|
||||
def _buildEntityWidget(self, entity, keys=None, use_bare_jid=False, with_alert=True, with_show_attr=True, markup_prepend=None, markup_append = None):
|
||||
|
|
|
|||
|
|
@ -27,8 +27,9 @@ log = logging.getLogger(__name__)
|
|||
import urwid
|
||||
from urwid_satext import sat_widgets
|
||||
from urwid_satext.files_management import FileDialog
|
||||
from sat_frontends.bridge.DBus import DBusBridgeFrontend
|
||||
from sat_frontends.quick_frontend.quick_app import QuickApp
|
||||
from sat_frontends.quick_frontend.quick_utils import getNewPath
|
||||
from sat_frontends.quick_frontend import quick_utils
|
||||
from sat_frontends.quick_frontend import quick_chat
|
||||
from sat_frontends.primitivus.profile_manager import ProfileManager
|
||||
from sat_frontends.primitivus.contact_list import ContactList
|
||||
|
|
@ -277,14 +278,14 @@ class PrimitivusTopWidget(sat_widgets.FocusPile):
|
|||
class PrimitivusApp(QuickApp, InputHistory):
|
||||
|
||||
def __init__(self):
|
||||
QuickApp.__init__(self)
|
||||
QuickApp.__init__(self, create_bridge=DBusBridgeFrontend, check_options=quick_utils.check_options)
|
||||
|
||||
## main loop setup ##
|
||||
self.main_widget = ProfileManager(self)
|
||||
self.loop = urwid.MainLoop(self.main_widget, C.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
|
||||
|
||||
|
||||
##misc setup##
|
||||
self._visible_widgets = set()
|
||||
self.notif_bar = sat_widgets.NotificationBar()
|
||||
urwid.connect_signal(self.notif_bar, 'change', self.onNotification)
|
||||
|
||||
|
|
@ -297,6 +298,10 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
# we already manage exit with a_key['APP_QUIT'], so we don't want C-c
|
||||
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
||||
|
||||
@property
|
||||
def visible_widgets(self):
|
||||
return self._visible_widgets
|
||||
|
||||
@property
|
||||
def mode(self):
|
||||
return self.editBar.mode
|
||||
|
|
@ -496,14 +501,14 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
self.redraw()
|
||||
|
||||
def newWidget(self, widget):
|
||||
self.selectWidget(widget)
|
||||
|
||||
def selectWidget(self, widget):
|
||||
"""Display a widget if possible,
|
||||
|
||||
else add it in the notification bar queue
|
||||
@param widget: BoxWidget
|
||||
"""
|
||||
self.selectWidget(widget)
|
||||
|
||||
def selectWidget(self, widget):
|
||||
assert len(self.center_part.widget_list)<=2
|
||||
wid_idx = len(self.center_part.widget_list)-1
|
||||
self.center_part.widget_list[wid_idx] = widget
|
||||
|
|
@ -512,7 +517,7 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
except KeyError:
|
||||
log.debug("No menu to delete")
|
||||
self.selected_widget = widget
|
||||
self.visible_widgets = set([widget]) # XXX: we can only have one widget visible at the time for now
|
||||
self._visible_widgets = set([widget]) # XXX: we can only have one widget visible at the time for now
|
||||
for contact_list in self.contact_lists.itervalues():
|
||||
contact_list.unselectAll()
|
||||
|
||||
|
|
@ -642,7 +647,7 @@ class PrimitivusApp(QuickApp, InputHistory):
|
|||
|
||||
def dir_selected_cb(path):
|
||||
dest_path = join(path, data['filename'])
|
||||
answer_data["dest_path"] = getNewPath(dest_path)
|
||||
answer_data["dest_path"] = quick_utils.getNewPath(dest_path)
|
||||
self.addProgress(confirmation_id, dest_path)
|
||||
accept_cb(None)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue