Mercurial > libervia-web
annotate src/browser/sat_browser/contact_panel.py @ 736:fe3c2357a8c9
fixes/improve ListManager and contact group manager + better PEP-8 compliance
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 19 Nov 2015 11:41:03 +0100 |
parents | 102bab805ec1 |
children | 76a9c074327b |
rev | line source |
---|---|
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
4 # Libervia: a Salut à Toi frontend |
685 | 5 # Copyright (C) 2011, 2012, 2013, 2014, 2015 Jérôme Poisson <goffi@goffi.org> |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
10 # (at your option) any later version. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
15 # GNU Affero General Public License for more details. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
339
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2067d6241927
fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents:
323
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
20 """ Contacts / jids related panels """ |
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
21 |
226
744426c2b699
browser_side, misc: better PEP8 compliance
souliane <souliane@mailoo.org>
parents:
223
diff
changeset
|
22 import pyjd # this is dummy in pyjs |
439
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
23 from sat.core.log import getLogger |
d52f529a6d42
browser side: use of new log system (first draft):
Goffi <goffi@goffi.org>
parents:
433
diff
changeset
|
24 log = getLogger(__name__) |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
25 from sat_frontends.tools import jid |
449
981ed669d3b3
/!\ reorganize all the file hierarchy, move the code and launching script to src:
souliane <souliane@mailoo.org>
parents:
439
diff
changeset
|
26 |
18
795d144fc1d2
moved panels and menu in a separate file
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from pyjamas.ui.VerticalPanel import VerticalPanel |
323
0b7934e75e76
misc: reorganization of the file panels.py + clean the modules import:
souliane <souliane@mailoo.org>
parents:
322
diff
changeset
|
28 |
648
6d3142b782c3
browser_side: classes reorganisation:
Goffi <goffi@goffi.org>
parents:
647
diff
changeset
|
29 import contact_widget |
433
bbdbee25123a
import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents:
412
diff
changeset
|
30 from constants import Const as C |
20 | 31 |
210
3092f6b1710c
browser side: make the OK button title for group selector configureable + few "cosmetic" changes (PEP 8...)
souliane <souliane@mailoo.org>
parents:
206
diff
changeset
|
32 |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
33 class ContactsPanel(VerticalPanel): |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
34 """ContactList graphic representation |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
35 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
36 Special features like popup menu panel or changing the contact states must be done in a sub-class. |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
37 """ |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
38 |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
39 def __init__(self, host, merge_resources=True, contacts_click=None, |
692
7a9c7b9f6a28
browser_side: use host.default_muc instead of C.DEFAULT_MUC
souliane <souliane@mailoo.org>
parents:
687
diff
changeset
|
40 contacts_style=None, contacts_menus=None, |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
41 contacts_display=C.CONTACT_DEFAULT_DISPLAY): |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
42 """ |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
43 |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
44 @param host (SatWebFrontend): host instance |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
45 @param merge_resources (bool): if True, the entities sharing the same |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
46 bare JID will also share the same contact box. |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
47 @param contacts_click (callable): click callback for the contact boxes |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
48 @param contacts_style (unicode): CSS style name for the contact boxes |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
49 @param contacts_menus (tuple): define the menu types that fit this |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
50 contact panel, with values from the menus type constants. |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
51 @param contacts_display (tuple): prioritize the display methods of the |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
52 contact's label with values in ("jid", "nick", "bare", "resource") |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
53 """ |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
54 VerticalPanel.__init__(self) |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
55 self.host = host |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
56 self.merge_resources = merge_resources |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
57 self._contacts = {} # entity jid to ContactBox map |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
58 self.click_listener = None |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
59 |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
60 if contacts_click is not None: |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
61 self.onClick = contacts_click |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
62 |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
63 self.contacts_style = contacts_style |
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
64 self.contacts_menus = contacts_menus |
660
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
65 self.contacts_display = contacts_display |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
66 |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
67 def _key(self, contact_jid): |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
68 """Return internal key for this contact. |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
69 |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
70 @param contact_jid (jid.JID): contact JID |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
71 @return: jid.JID |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
72 """ |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
73 return contact_jid.bare if self.merge_resources else contact_jid |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
74 |
721
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
75 def getJids(self): |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
76 """Return jids present in the panel |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
77 |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
78 @return (list[jid.JID]): full jids or bare jids if self.merge_resources is True |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
79 """ |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
80 return self.contacts.keys() |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
81 |
102bab805ec1
browser side(xmlui): basic JidsList implementation (read-only) using ContactsPanel, to fix params display
Goffi <goffi@goffi.org>
parents:
695
diff
changeset
|
82 |
684
e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents:
676
diff
changeset
|
83 def clear(self): |
e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents:
676
diff
changeset
|
84 """Clear all contacts.""" |
e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents:
676
diff
changeset
|
85 self._contacts.clear() |
e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents:
676
diff
changeset
|
86 VerticalPanel.clear(self) |
e876f493dccc
browser_side: follow changes made on quick_frontend for chat states and MUC symbols + minor fixes following the refactorisation:
souliane <souliane@mailoo.org>
parents:
676
diff
changeset
|
87 |
660
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
88 def setList(self, jids): |
267761bf7f08
browser side (contact list): ContactPanels is used instead of OccupantsList in MUC:
Goffi <goffi@goffi.org>
parents:
648
diff
changeset
|
89 """set all contacts in the list in one shot. |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
90 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
91 @param jids (list[jid.JID]): jids to display (the order is kept) |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
92 @param name (unicode): optional name of the contact |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
93 """ |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
94 current_jids = [box.jid for box in self.children if isinstance(box, contact_widget.ContactBox)] |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
95 if current_jids == jids: |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
96 # the display doesn't change |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
97 return |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
98 for contact_jid in set(current_jids).difference(jids): |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
99 self.removeContactBox(contact_jid) |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
100 current_index = 0 |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
101 insert_count = 0 |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
102 for contact_jid in jids: |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
103 try: |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
104 if current_jids[current_index] == contact_jid: |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
105 current_index += 1 |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
106 continue |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
107 except IndexError: |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
108 pass |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
109 assert isinstance(contact_jid, jid.JID) |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
110 self.updateContactBox(contact_jid, current_index + insert_count) |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
111 insert_count += 1 |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
112 |
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
113 def getContactBox(self, contact_jid): |
687
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
114 """Get the contact box for the given contact. |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
115 |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
116 @param contact_jid (jid.JID): contact JID |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
117 @return: ContactBox or None |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
118 """ |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
119 try: |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
120 return self._contacts[self._key(contact_jid)] |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
121 except KeyError: |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
122 return None |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
123 |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
124 def updateContactBox(self, contact_jid, index=None): |
687
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
125 """Add a contact or update it if it already exists. |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
126 |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
127 @param contact_jid (jid.JID): contact JID |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
128 @param index (int): insertion index if the contact is added |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
129 @return: ContactBox |
647
e0021d571eef
browser side: moved ContactBox, ContactsPanel, ContactLabeland ContactMenuBar to base_widget/base_panels so they can be reused outside of contact_list module
Goffi <goffi@goffi.org>
parents:
600
diff
changeset
|
130 """ |
687
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
131 box = self.getContactBox(contact_jid) |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
132 if box: |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
133 box.update() |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
134 else: |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
135 entity = contact_jid.bare if self.merge_resources else contact_jid |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
136 box = contact_widget.ContactBox(self.host, entity, |
671
2201ff543a05
browser_side: replace ContactsPanel and ContactBox init "parent" attribute with "host" + menus bound to the avatar can be parameterized
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
137 style_name=self.contacts_style, |
676
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
673
diff
changeset
|
138 display=self.contacts_display, |
849ffb24d5bf
browser side: menus refactorisation:
Goffi <goffi@goffi.org>
parents:
673
diff
changeset
|
139 plugin_menu_context=self.contacts_menus) |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
140 self._contacts[self._key(contact_jid)] = box |
695
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
141 if index: |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
142 VerticalPanel.insert(self, box, index) |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
143 else: |
e86490a7c76e
browser_side: don't rebuild the whole list on contact list update
souliane <souliane@mailoo.org>
parents:
692
diff
changeset
|
144 VerticalPanel.append(self, box) |
687
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
145 return box |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
146 |
687
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
147 def removeContactBox(self, contact_jid): |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
148 """Remove a contact. |
673
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
149 |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
150 @param contact_jid (jid.JID): contact JID |
e489218886d7
browser_side: add attribute "merge_resources" to ContactsPanel to display the MUC occupants + override Chat.replaceUser and Chat.removeUser
souliane <souliane@mailoo.org>
parents:
671
diff
changeset
|
151 """ |
687
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
152 box = self._contacts.pop(self._key(contact_jid), None) |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
153 if box: |
3845a086f0b3
browser_side: update ContactList, Chat, ContactsPanel, ContactBox, ContactLabel to update the display using listeners as it is done in quick_frontend:
souliane <souliane@mailoo.org>
parents:
685
diff
changeset
|
154 VerticalPanel.remove(self, box) |