Mercurial > libervia-web
comparison src/browser/libervia_main.py @ 637:7113d40533d6 frontends_multi_profiles
merged souliane changes
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 23 Feb 2015 18:47:27 +0100 |
parents | 86ae737da6f3 66a547539185 |
children | 3e4826948eef |
comparison
equal
deleted
inserted
replaced
636:86ae737da6f3 | 637:7113d40533d6 |
---|---|
58 # FIXME: import plugin dynamically | 58 # FIXME: import plugin dynamically |
59 from sat_browser import plugin_sec_otr | 59 from sat_browser import plugin_sec_otr |
60 except ImportError: | 60 except ImportError: |
61 pass | 61 pass |
62 | 62 |
63 unicode = lambda s: str(s) | 63 |
64 unicode = str # FIXME: pyjamas workaround | |
65 | |
64 | 66 |
65 MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories | 67 MAX_MBLOG_CACHE = 500 # Max microblog entries kept in memories |
66 | 68 |
67 # Set to true to not create a new LiberviaWidget when a similar one | 69 # Set to true to not create a new LiberviaWidget when a similar one |
68 # already exist (i.e. a chat panel with the same target). Instead | 70 # already exist (i.e. a chat panel with the same target). Instead |
78 self.bridge_signals = json.BridgeSignals(self) | 80 self.bridge_signals = json.BridgeSignals(self) |
79 QuickApp.__init__(self, json.BridgeCall) | 81 QuickApp.__init__(self, json.BridgeCall) |
80 self.uni_box = None # FIXME: to be removed | 82 self.uni_box = None # FIXME: to be removed |
81 self.status_panel = HTML('<br />') | 83 self.status_panel = HTML('<br />') |
82 self.panel = panels.MainPanel(self) | 84 self.panel = panels.MainPanel(self) |
83 self.discuss_panel = self.panel.discuss_panel | |
84 self.tab_panel = self.panel.tab_panel | 85 self.tab_panel = self.panel.tab_panel |
85 self.tab_panel.addTabListener(self) | 86 self.tab_panel.addTabListener(self) |
86 self._register_box = None | 87 self._register_box = None |
87 RootPanel().add(self.panel) | 88 RootPanel().add(self.panel) |
88 | 89 |
211 | 212 |
212 @param jid_ (jid.JID): JID of the contact | 213 @param jid_ (jid.JID): JID of the contact |
213 @return: the URL to the avatar (str) | 214 @return: the URL to the avatar (str) |
214 """ | 215 """ |
215 assert isinstance(jid_, jid.JID) | 216 assert isinstance(jid_, jid.JID) |
216 avatar_hash = self.contact_lists[C.PROF_KEY_NONE].getCache(jid_, 'avatar') | 217 contact_list = self.contact_list # pyjamas issue: need a temporary variable to call a property's method |
218 avatar_hash = contact_list.getCache(jid_, 'avatar') | |
217 if avatar_hash is None: | 219 if avatar_hash is None: |
218 # we have no value for avatar_hash, so we request the vcard | 220 # we have no value for avatar_hash, so we request the vcard |
219 self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE) | 221 self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE) |
220 if not avatar_hash: | 222 if not avatar_hash: |
221 return C.DEFAULT_AVATAR_URL | 223 return C.DEFAULT_AVATAR_URL |
236 """Refresh the general display.""" | 238 """Refresh the general display.""" |
237 self.panel.refresh() | 239 self.panel.refresh() |
238 for lib_wid in self.libervia_widgets: | 240 for lib_wid in self.libervia_widgets: |
239 lib_wid.refresh() | 241 lib_wid.refresh() |
240 self.resize() | 242 self.resize() |
241 | |
242 def addTab(self, label, wid=None, select=False): | |
243 """Create a new tab and eventually add a widget to it. | |
244 | |
245 @param label (unicode): label of the tab | |
246 @param wid (LiberviaWidget): optional widget to add | |
247 @param select (bool): True to select the added tab | |
248 @return: WidgetsPanel | |
249 """ | |
250 widgets_panel = base_widget.WidgetsPanel(self) | |
251 self.tab_panel.add(widgets_panel, label) | |
252 tab_index = self.tab_panel.getWidgetCount() - 1 | |
253 if wid is not None: | |
254 self.addWidget(wid, tab_index) | |
255 if select: | |
256 self.tab_panel.selectTab(tab_index) | |
257 if wid is not None: | |
258 self.setSelected(wid) | |
259 return widgets_panel | |
260 | 243 |
261 def addWidget(self, wid, tab_index=None): | 244 def addWidget(self, wid, tab_index=None): |
262 """ Add a widget at the bottom of the current or specified tab | 245 """ Add a widget at the bottom of the current or specified tab |
263 | 246 |
264 @param wid: LiberviaWidget to add | 247 @param wid: LiberviaWidget to add |
374 if hasattr(plugin, 'profileConnected'): | 357 if hasattr(plugin, 'profileConnected'): |
375 plugin.profileConnected() | 358 plugin.profileConnected() |
376 | 359 |
377 def addContactList(self, dummy): | 360 def addContactList(self, dummy): |
378 contact_list = ContactList(self) | 361 contact_list = ContactList(self) |
379 self.contact_lists[C.PROF_KEY_NONE] = contact_list | |
380 self.panel.addContactList(contact_list) | 362 self.panel.addContactList(contact_list) |
381 return contact_list | 363 return contact_list |
382 | 364 |
383 def newWidget(self, widget): | 365 def newWidget(self, widget): |
384 log.debug("newWidget: {}".format(widget)) | 366 log.debug("newWidget: {}".format(widget)) |
609 | 591 |
610 if new_tab: | 592 if new_tab: |
611 kwargs['on_new_widget'] = None | 593 kwargs['on_new_widget'] = None |
612 kwargs['on_existing_widget'] = C.WIDGET_RECREATE | 594 kwargs['on_existing_widget'] = C.WIDGET_RECREATE |
613 wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) | 595 wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) |
614 self.addTab(new_tab, wid) | 596 self.tab_panel.addWidgetsTab(new_tab) |
597 self.addWidget(wid) | |
615 return wid | 598 return wid |
616 | 599 |
617 kwargs['on_existing_widget'] = C.WIDGET_RAISE | 600 kwargs['on_existing_widget'] = C.WIDGET_RAISE |
618 try: | 601 try: |
619 wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) | 602 wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs) |
842 #The user want to subscribe to our presence | 825 #The user want to subscribe to our presence |
843 _dialog = None | 826 _dialog = None |
844 msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_tools.html_sanitize(entity)) | 827 msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_tools.html_sanitize(entity)) |
845 | 828 |
846 def ok_cb(ignore): | 829 def ok_cb(ignore): |
847 self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups()) | 830 self.bridge.call('subscription', None, "subscribed", entity) |
831 self.bridge.updateContact(entity, '', _dialog.getSelectedGroups()) | |
848 | 832 |
849 def cancel_cb(ignore): | 833 def cancel_cb(ignore): |
850 self.bridge.call('subscription', None, "unsubscribed", entity, '', '') | 834 self.bridge.call('subscription', None, "unsubscribed", entity, '', '') |
851 | 835 |
852 _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], "Add", ok_cb, cancel_cb) | 836 _dialog = dialog.GroupSelector([msg], self.contact_panel.getGroups(), [], "Add", ok_cb, cancel_cb) |
968 """ | 952 """ |
969 if not hasattr(self, "warning_popup"): | 953 if not hasattr(self, "warning_popup"): |
970 self.warning_popup = panels.WarningPopup() | 954 self.warning_popup = panels.WarningPopup() |
971 self.warning_popup.showWarning(type_, msg) | 955 self.warning_popup.showWarning(type_, msg) |
972 | 956 |
957 def showDialog(self, message, title="", type_="info", answer_cb=None, answer_data=None): | |
958 if type_ == 'info': | |
959 popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb) | |
960 elif type_ == 'error': | |
961 popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb) | |
962 elif type_ == 'yes/no': | |
963 popup = dialog.ConfirmDialog(lambda answer: answer_cb(answer, answer_data), | |
964 text=unicode(message), title=unicode(title)) | |
965 popup.cancel_button.setText(_("No")) | |
966 else: | |
967 popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb) | |
968 log.error(_('unmanaged dialog type: %s'), type_) | |
969 popup.show() | |
970 | |
973 | 971 |
974 if __name__ == '__main__': | 972 if __name__ == '__main__': |
975 app = SatWebFrontend() | 973 app = SatWebFrontend() |
976 app.onModuleLoad() | 974 app.onModuleLoad() |