diff 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
line wrap: on
line diff
--- a/src/browser/libervia_main.py	Mon Feb 23 18:44:58 2015 +0100
+++ b/src/browser/libervia_main.py	Mon Feb 23 18:47:27 2015 +0100
@@ -60,7 +60,9 @@
 except ImportError:
     pass
 
-unicode = lambda s: str(s)
+
+unicode = str  # FIXME: pyjamas workaround
+
 
 MAX_MBLOG_CACHE = 500  # Max microblog entries kept in memories
 
@@ -80,7 +82,6 @@
         self.uni_box = None # FIXME: to be removed
         self.status_panel = HTML('<br />')
         self.panel = panels.MainPanel(self)
-        self.discuss_panel = self.panel.discuss_panel
         self.tab_panel = self.panel.tab_panel
         self.tab_panel.addTabListener(self)
         self._register_box = None
@@ -213,7 +214,8 @@
         @return: the URL to the avatar (str)
         """
         assert isinstance(jid_, jid.JID)
-        avatar_hash = self.contact_lists[C.PROF_KEY_NONE].getCache(jid_, 'avatar')
+        contact_list = self.contact_list  # pyjamas issue: need a temporary variable to call a property's method
+        avatar_hash = contact_list.getCache(jid_, 'avatar')
         if avatar_hash is None:
             # we have no value for avatar_hash, so we request the vcard
             self.bridge.getCard(unicode(jid_), profile=C.PROF_KEY_NONE)
@@ -239,25 +241,6 @@
             lib_wid.refresh()
         self.resize()
 
-    def addTab(self, label, wid=None, select=False):
-        """Create a new tab and eventually add a widget to it.
-
-        @param label (unicode): label of the tab
-        @param wid (LiberviaWidget): optional widget to add
-        @param select (bool): True to select the added tab
-        @return: WidgetsPanel
-        """
-        widgets_panel = base_widget.WidgetsPanel(self)
-        self.tab_panel.add(widgets_panel, label)
-        tab_index = self.tab_panel.getWidgetCount() - 1
-        if wid is not None:
-            self.addWidget(wid, tab_index)
-        if select:
-            self.tab_panel.selectTab(tab_index)
-            if wid is not None:
-                self.setSelected(wid)
-        return widgets_panel
-
     def addWidget(self, wid, tab_index=None):
         """ Add a widget at the bottom of the current or specified tab
 
@@ -376,7 +359,6 @@
 
     def addContactList(self, dummy):
         contact_list = ContactList(self)
-        self.contact_lists[C.PROF_KEY_NONE] = contact_list
         self.panel.addContactList(contact_list)
         return contact_list
 
@@ -611,7 +593,8 @@
             kwargs['on_new_widget'] = None
             kwargs['on_existing_widget'] = C.WIDGET_RECREATE
             wid = self.widgets.getOrCreateWidget(class_, target, *args, **kwargs)
-            self.addTab(new_tab, wid)
+            self.tab_panel.addWidgetsTab(new_tab)
+            self.addWidget(wid)
             return wid
 
         kwargs['on_existing_widget'] = C.WIDGET_RAISE
@@ -844,7 +827,8 @@
             msg = HTML('The contact <b>%s</b> want to add you in his/her contact list, do you accept ?' % html_tools.html_sanitize(entity))
 
             def ok_cb(ignore):
-                self.bridge.call('subscription', None, "subscribed", entity, '', _dialog.getSelectedGroups())
+                self.bridge.call('subscription', None, "subscribed", entity)
+                self.bridge.updateContact(entity, '', _dialog.getSelectedGroups())
 
             def cancel_cb(ignore):
                 self.bridge.call('subscription', None, "unsubscribed", entity, '', '')
@@ -970,6 +954,20 @@
             self.warning_popup = panels.WarningPopup()
         self.warning_popup.showWarning(type_, msg)
 
+    def showDialog(self, message, title="", type_="info", answer_cb=None, answer_data=None):
+        if type_ == 'info':
+            popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb)
+        elif type_ == 'error':
+            popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb)
+        elif type_ == 'yes/no':
+            popup = dialog.ConfirmDialog(lambda answer: answer_cb(answer, answer_data),
+                                         text=unicode(message), title=unicode(title))
+            popup.cancel_button.setText(_("No"))
+        else:
+            popup = dialog.InfoDialog(unicode(title), unicode(message), callback=answer_cb)
+            log.error(_('unmanaged dialog type: %s'), type_)
+        popup.show()
+
 
 if __name__ == '__main__':
     app = SatWebFrontend()