diff frontends/src/primitivus/primitivus @ 737:378af36155c2

frontends: set and retrieve your own presence and status
author souliane <souliane@mailoo.org>
date Mon, 25 Nov 2013 01:56:07 +0100
parents 6246eb6d64a0
children e867f146d49f
line wrap: on
line diff
--- a/frontends/src/primitivus/primitivus	Sat Nov 23 10:21:40 2013 +0100
+++ b/frontends/src/primitivus/primitivus	Mon Nov 25 01:56:07 2013 +0100
@@ -33,6 +33,7 @@
 from sat_frontends.primitivus.notify import Notify
 from sat_frontends.tools.misc import InputHistory
 from sat_frontends.primitivus.constants import Const
+from sat_frontends.constants import Const as commonConst
 import logging
 from logging import debug, info, error
 from sat.tools.jid  import JID
@@ -119,6 +120,17 @@
         if command == 'quit':
             self.app.onExit()
             raise urwid.ExitMainLoop()
+        elif command == 'presence':
+            self.app.status_bar.onPresenceClick()
+        elif command in ['presence %s' % show for show in commonConst.PRESENCE.keys()]:
+            self.app.status_bar.onChange(user_data=sat_widgets.ClickableText(commonConst.PRESENCE[command[9:]]))
+        elif command == 'status':
+            self.app.status_bar.onStatusClick()
+        elif command.startswith('status '):
+            self.app.status_bar.onChange(user_data=sat_widgets.AdvancedEdit(command[7:]))
+        else:
+            return
+        self.set_edit_text('')
 
     def keypress(self, size, key):
         """Callback when a key is pressed. Send "composing" states
@@ -151,7 +163,7 @@
 
         ## main loop setup ##
         self.main_widget = ProfileManager(self)
-        self.loop = urwid.MainLoop(self.main_widget, const.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
+        self.loop = urwid.MainLoop(self.main_widget, Const.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
 
         ##misc setup##
         self.chat_wins = ChatList(self)
@@ -321,10 +333,10 @@
             #we still have popup to show, we display it
             self.showPopUp(next_popup)
 
-    def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, valign='middle'):
+    def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, align='center', valign='middle'):
         "Show a pop-up window if possible, else put it in queue"
         if not isinstance(self.loop.widget, urwid.Overlay):
-            display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), valign, ('relative', perc_height))
+            display_widget = urwid.Overlay(pop_up_widget, self.main_widget, align, ('relative', perc_width), valign, ('relative', perc_height))
             self.loop.widget = display_widget
             self.redraw()
         else:
@@ -590,7 +602,7 @@
             self.showPopUp(pop_up_widget)
 
     def onAboutRequest(self, menu):
-        self.showPopUp(sat_widgets.Alert(_("About"), const.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
+        self.showPopUp(sat_widgets.Alert(_("About"), Const.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
 
     #MISC CALLBACKS#
 
@@ -627,5 +639,13 @@
         if from_bare in self.chat_wins:
             self.chat_wins[from_bare].updateChatState(state)
 
+    def setStatusOnline(self, online=True, show="", statuses={}):
+        if not online or not show or not statuses:
+            return
+        try:
+            self.status_bar.setPresenceStatus(show, statuses['default'])
+        except (KeyError, TypeError):
+            pass
+
 sat = PrimitivusApp()
 sat.start()