annotate browser_side/dialog.py @ 32:6b8da70b0799

browser_side: contactsChooser now discard MUC rooms
author Goffi <goffi@goffi.org>
date Sat, 14 May 2011 00:58:11 +0200
parents 824516b247e6
children 305e81c7a32c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
3
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
7
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
12
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
17
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
21
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from pyjamas.ui.VerticalPanel import VerticalPanel
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.HorizontalPanel import HorizontalPanel
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pyjamas.ui.DialogBox import DialogBox
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.ListBox import ListBox
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.Button import Button
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
27
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
28 class ContactsChooser(DialogBox):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
29
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
30 def __init__(self, host, callback, nb_contact=None, text='Please select contacts'):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
31 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
32 ContactsChooser allow to select one or several connected contacts
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
33 @param host: SatWebFrontend instance
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
34 @param callback: method to call when contacts have been choosed
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
35 @param nb_contact: number of contacts that have to be selected, None for no limit
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
36 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.host = host
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.callback = callback
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.nb_contact = nb_contact
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
40 DialogBox.__init__(self, centered=True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
41
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
42 content = VerticalPanel()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
43 content.setWidth('100%')
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.contacts_list = ListBox()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.contacts_list.setVisibleItemCount(10)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.contacts_list.setMultipleSelect(True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.contacts_list.setWidth("100%")
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
48 self.contacts_list.setStyleName('contactsChooser')
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.contacts_list.addChangeListener(self.onChange)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
50 content.add(self.contacts_list)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
51 button_panel = HorizontalPanel()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.choose_button = Button("Choose", self.onChoose)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.choose_button.setEnabled(False)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
54 button_panel.add(self.choose_button)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
55 button_panel.add(Button("Cancel", self.onCancel))
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
56 content.add(button_panel)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.setHTML(text)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.setWidget(content)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
59
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def onChange(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
61 if self.nb_contact:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
62 if len(self.contacts_list.getSelectedValues()) == self.nb_contact:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.choose_button.setEnabled(True)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
64 else:
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.choose_button.setEnabled(False)
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
66
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def getContacts(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
68 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
69 Actually ask to choose the contacts
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
70 """
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.contacts_list.clear()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
72 for contact in self.host.contact_panel.getConnected():
32
6b8da70b0799 browser_side: contactsChooser now discard MUC rooms
Goffi <goffi@goffi.org>
parents: 26
diff changeset
73 if contact not in [room.bare for room in self.host.room_list]:
6b8da70b0799 browser_side: contactsChooser now discard MUC rooms
Goffi <goffi@goffi.org>
parents: 26
diff changeset
74 self.contacts_list.addItem(contact)
26
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.show()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
76
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def onChoose(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.hide()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.callback(self.contacts_list.getSelectedValues())
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
80
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def onCancel(self):
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.hide()
824516b247e6 browser side: added ContactsChooser dialog
Goffi <goffi@goffi.org>
parents:
diff changeset
83