diff browser_side/panels.py @ 55:d5266c41ca24

Roster list update, contact deletion + some refactoring
author Goffi <goffi@goffi.org>
date Sun, 29 May 2011 02:13:53 +0200
parents f25c4077f6b9
children 5fa710058e2d
line wrap: on
line diff
--- a/browser_side/panels.py	Sat May 28 20:18:14 2011 +0200
+++ b/browser_side/panels.py	Sun May 29 02:13:53 2011 +0200
@@ -79,6 +79,8 @@
 
         menu_contacts = MenuBar(vertical=True)
         menu_contacts.addItem("add contact", MenuCmd(self, "onAddContact"))
+        menu_contacts.addItem("update contact", MenuCmd(self, "onUpdateContact"))
+        menu_contacts.addItem("remove contact", MenuCmd(self, "onRemoveContact"))
 
         menu_group = MenuBar(vertical=True)
         menu_group.addItem("join room", MenuCmd(self, "onJoinRoom"))
@@ -134,6 +136,31 @@
         _dialog.setHTML('<b>Adding contact</b>')
         _dialog.show()
 
+    def onUpdateContact(self):
+        pass
+
+    def onRemoveContact(self):
+        _dialog = None
+        _contacts_list = ListBox()
+       
+        def secondConfirmCb(confirm):
+            if confirm:
+                for contact in _contacts_list.getSelectedValues():
+                    self.host.bridge.call('delContact', None, contact)
+            else:
+                _dialog.show()
+
+        def dialogCb(confirm):
+            if confirm:
+                html_list = ''.join(['<li>%s</li>' % html_sanitize(contact) for contact in _contacts_list.getSelectedValues()])
+                html_body = "Are you sure to remove the following contacts from your contact list ?<ul>%s</ul>" % html_list
+                dialog.ConfirmDialog(secondConfirmCb, html_body).show()
+
+        for contact in self.host.contact_panel.getContacts():
+            _contacts_list.addItem(contact)
+        _dialog = dialog.GenericConfirmDialog([_contacts_list], dialogCb, "Who do you want to remove from your contacts ?")
+        _dialog.show()
+
     #Group menu
     def onJoinRoom(self):
         _dialog = None
@@ -313,6 +340,13 @@
     def addKey(self, key):
         self.getCompletionItems().completions.append(key)
 
+    def removeKey(self, key):
+        try:
+            self.getCompletionItems().completions.remove(key)
+        except KeyError:
+            print "WARNING: trying to remove an unknown key"
+            
+
     def showWarning(self, target_data):
         type, target = target_data
         if type == "PUBLIC":