annotate cagou/plugins/plugin_wid_contact_list.py @ 445:9b73a1879989

core: fixed doAction when new widget is already existing and visible: when the doAction new widget was existing and visible, the factory was creating a new one, which could result in a consusing situation for the user (share widget's attachment added to an non visible widget for instance).
author Goffi <goffi@goffi.org>
date Wed, 18 Mar 2020 20:26:21 +0100
parents 167c3e198f73
children 3c9ba4a694ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
379
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
1 #!/usr/bin/env python3
1da3c379205b fixed shebangs
Goffi <goffi@goffi.org>
parents: 378
diff changeset
2
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
378
4d660b252487 dates update
Goffi <goffi@goffi.org>
parents: 365
diff changeset
5 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
365
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
21 from functools import partial
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
22 import bisect
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
23 import re
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core import log as logging
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
25 from sat.core.i18n import _
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
27 from sat_frontends.tools import jid
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy import properties
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
29 from cagou import G
365
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
30 from ..core import cagou_widget
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
31 from ..core.constants import Const as C
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
32 from ..core.common import ContactItem
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 387
diff changeset
33 from ..core.behaviors import FilterBehavior, TouchMenuBehavior, TouchMenuItemBehavior
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 387
diff changeset
34 from ..core.menu import SideMenu
365
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
35
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
36
9c6fe392d623 core (widgets_handler): use a StencilView + BoxLayout instead of ScrollView as wrapper:
Goffi <goffi@goffi.org>
parents: 322
diff changeset
37 log = logging.getLogger(__name__)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
40 PLUGIN_INFO = {
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
41 "name": _("contacts"),
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
42 "main": "ContactList",
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
43 "description": _("list of contacts"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
44 "icon_medium": "{media}/icons/muchoslava/png/contact_list_no_border_blue_44.png"
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
45 }
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
46
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
47
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
48 class AddContactMenu(SideMenu):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
49 profile = properties.StringProperty()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
50 size_hint_close = (1, 0)
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
51 size_hint_open = (1, 0.5)
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
52
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
53 def __init__(self, **kwargs):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
54 super(AddContactMenu, self).__init__(**kwargs)
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
55 if self.profile is None:
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
56 log.warning(_("profile not set in AddContactMenu"))
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
57 self.profile = next(iter(G.host.profiles))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
58
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
59 def addContact(self, contact_jid):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
60 """Actually add the contact
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
61
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
62 @param contact_jid(unicode): jid of the contact to add
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
63 """
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
64 self.hide()
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
65 contact_jid = contact_jid.strip()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
66 # FIXME: trivial jid verification
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
67 if not contact_jid or not re.match(r"[^@ ]+@[^@ ]+", contact_jid):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
68 return
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
69 contact_jid = jid.JID(contact_jid).bare
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
70 G.host.bridge.addContact(str(contact_jid),
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
71 self.profile,
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
72 callback=lambda: G.host.addNote(
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
73 _("contact request"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
74 _("a contact request has been sent to {contact_jid}").format(
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
75 contact_jid=contact_jid)),
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
76 errback=partial(G.host.errback,
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
77 title=_("can't add contact"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
78 message=_("error while trying to add contact: {msg}")))
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
79
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
80
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
81 class DelContactMenu(SideMenu):
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
82 size_hint_close = (1, 0)
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
83 size_hint_open = (1, 0.5)
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
84
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
85 def __init__(self, contact_item, **kwargs):
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
86 self.contact_item = contact_item
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
87 super(DelContactMenu, self).__init__(**kwargs)
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
88
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
89 def do_delete_contact(self):
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
90 self.hide()
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
91 G.host.bridge.delContact(str(self.contact_item.jid.bare),
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
92 self.contact_item.profile,
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
93 callback=lambda: G.host.addNote(
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
94 _("contact removed"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
95 _("{contact_jid} has been removed from your contacts list").format(
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
96 contact_jid=self.contact_item.jid.bare)),
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
97 errback=partial(G.host.errback,
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
98 title=_("can't remove contact"),
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
99 message=_("error while trying to remove contact: {msg}")))
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
100
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
101
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 387
diff changeset
102 class CLContactItem(TouchMenuItemBehavior, ContactItem):
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
104 def do_item_action(self, touch):
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
105 assert self.profile
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
106 # XXX: for now clicking on an item launch the corresponding Chat widget
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
107 # behaviour should change in the future
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
108 G.host.doAction('chat', jid.JID(self.jid), [self.profile])
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
109
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
110 def getMenuChoices(self):
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
111 choices = []
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
112 choices.append(dict(text=_('delete'),
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
113 index=len(choices)+1,
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
114 callback=self.main_wid.removeContact))
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
115 return choices
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
116
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
117
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
118 class ContactList(QuickContactList, cagou_widget.CagouWidget, FilterBehavior,
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 387
diff changeset
119 TouchMenuBehavior):
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
120 float_layout = properties.ObjectProperty()
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
121 layout = properties.ObjectProperty()
387
d61bbbac4160 cagou widget: don't add header_input systematically anymore:
Goffi <goffi@goffi.org>
parents: 379
diff changeset
122 use_header_input = True
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124 def __init__(self, host, target, profiles):
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
125 QuickContactList.__init__(self, G.host, profiles)
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
126 cagou_widget.CagouWidget.__init__(self)
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
127 FilterBehavior.__init__(self)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
128 self._wid_map = {} # (profile, bare_jid) to widget map
17
5c9feaa060a5 contact list: added call to the new postInit method
Goffi <goffi@goffi.org>
parents: 16
diff changeset
129 self.postInit()
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
130 if len(self.profiles) != 1:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
131 raise NotImplementedError('multi profiles is not implemented yet')
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
132 self.update(profile=next(iter(self.profiles)))
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
134 def addContactMenu(self):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
135 """Show the "add a contact" menu"""
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
136 # FIXME: for now we add contact to the first profile we find
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
137 profile = next(iter(self.profiles))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
138 AddContactMenu(profile=profile).show()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
139
223
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
140 def removeContact(self, menu_label):
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
141 item = self.menu_item
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
142 self.clear_menu()
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
143 DelContactMenu(contact_item=item).show()
9e5f9f0cee48 plugin contact list: use new TouchMenuBehaviour to implement contact deletion
Goffi <goffi@goffi.org>
parents: 221
diff changeset
144
110
34dfe0e32064 contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents: 90
diff changeset
145 def onHeaderInputComplete(self, wid, text):
404
f7476818f9fb core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents: 387
diff changeset
146 self.do_filter(self.layout,
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
147 text,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
148 lambda c: c.jid,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
149 width_cb=lambda c: c.base_width,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
150 height_cb=lambda c: c.minimum_height,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
151 )
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
152
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
153 def _addContactItem(self, bare_jid, profile):
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
154 """Create a new CLContactItem instance, and add it
110
34dfe0e32064 contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents: 90
diff changeset
155
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
156 item will be added in a sorted position
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
157 @param bare_jid(jid.JID): entity bare JID
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
158 @param profile(unicode): profile where the contact is
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
159 """
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
160 data = G.host.contact_lists[profile].getItem(bare_jid)
322
e2b51663d8b8 core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents: 312
diff changeset
161 wid = CLContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self)
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
162 child_jids = [c.jid for c in reversed(self.layout.children)]
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
163 idx = bisect.bisect_right(child_jids, bare_jid)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
164 self.layout.add_widget(wid, -idx)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
165 self._wid_map[(profile, bare_jid)] = wid
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
166
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 def update(self, entities=None, type_=None, profile=None):
50
c45d6e9ec731 contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents: 39
diff changeset
168 log.debug("update: %s %s %s" % (entities, type_, profile))
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
169 if type_ == None or type_ == C.UPDATE_STRUCTURE:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
170 log.debug("full contact list update")
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
171 self.layout.clear_widgets()
312
772c170b47a9 Python3 port:
Goffi <goffi@goffi.org>
parents: 282
diff changeset
172 for bare_jid, data in self.items_sorted.items():
440
167c3e198f73 contact list: fixed crash on update when profile is not specified
Goffi <goffi@goffi.org>
parents: 404
diff changeset
173 wid = CLContactItem(
167c3e198f73 contact list: fixed crash on update when profile is not specified
Goffi <goffi@goffi.org>
parents: 404
diff changeset
174 profile=data['profile'],
167c3e198f73 contact list: fixed crash on update when profile is not specified
Goffi <goffi@goffi.org>
parents: 404
diff changeset
175 data=data,
167c3e198f73 contact list: fixed crash on update when profile is not specified
Goffi <goffi@goffi.org>
parents: 404
diff changeset
176 jid=bare_jid,
167c3e198f73 contact list: fixed crash on update when profile is not specified
Goffi <goffi@goffi.org>
parents: 404
diff changeset
177 main_wid=self,
167c3e198f73 contact list: fixed crash on update when profile is not specified
Goffi <goffi@goffi.org>
parents: 404
diff changeset
178 )
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
179 self.layout.add_widget(wid)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
180 self._wid_map[(profile, bare_jid)] = wid
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
181 elif type_ == C.UPDATE_MODIFY:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
182 for entity in entities:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
183 entity_bare = entity.bare
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
184 wid = self._wid_map[(profile, entity_bare)]
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
185 wid.data = G.host.contact_lists[profile].getItem(entity_bare)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
186 elif type_ == C.UPDATE_ADD:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
187 for entity in entities:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
188 self._addContactItem(entity.bare, profile)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
189 elif type_ == C.UPDATE_DELETE:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
190 for entity in entities:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
191 try:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
192 self.layout.remove_widget(self._wid_map.pop((profile, entity.bare)))
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
193 except KeyError:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
194 log.debug("entity not found: {entity}".format(entity=entity.bare))
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
195 else:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
196 log.debug("update type not handled: {update_type}".format(update_type=type_))