Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_contact_list.py @ 219:9faccd140119
plugin contact list: refactoring:
- contacts are now displayed in a grid
- they can be filtered thanks to FilterBehaviour
- use the new update system of QuickContactList
- a new "add a contact" button is visible, but not implemented yet.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Jun 2018 22:26:15 +0200 |
parents | 0ddd2b20cc6b |
children | e1a385a791cc |
rev | line source |
---|---|
9 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
126 | 5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org) |
9 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 from sat.core import log as logging | |
22 log = logging.getLogger(__name__) | |
219 | 23 from cagou.core.constants import Const as C |
14 | 24 from sat.core.i18n import _ |
9 | 25 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList |
22 | 26 from sat_frontends.tools import jid |
9 | 27 from kivy.uix.boxlayout import BoxLayout |
219 | 28 from kivy.uix.behaviors import ButtonBehavior |
29 from cagou.core.utils import FilterBehavior | |
110
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
30 from kivy.metrics import dp |
9 | 31 from kivy import properties |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
32 from cagou.core import cagou_widget |
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
33 from cagou.core import image |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
34 from cagou import G |
219 | 35 import bisect |
9 | 36 |
37 | |
14 | 38 PLUGIN_INFO = { |
39 "name": _(u"contacts"), | |
40 "main": "ContactList", | |
41 "description": _(u"list of contacts"), | |
180
0ddd2b20cc6b
plugins chat, contact_list, settings, widget_selector: changed icons theme
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
42 "icon_medium": u"{media}/icons/muchoslava/png/contact_list_no_border_blue_44.png" |
14 | 43 } |
44 | |
45 | |
9 | 46 class Avatar(image.Image): |
47 pass | |
48 | |
49 | |
219 | 50 class ContactItem(ButtonBehavior, BoxLayout): |
51 base_width = dp(150) | |
9 | 52 data = properties.DictProperty() |
53 jid = properties.StringProperty('') | |
54 | |
55 def __init__(self, **kwargs): | |
50
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
56 super(ContactItem, self).__init__(**kwargs) |
9 | 57 |
219 | 58 def on_release(self): |
59 # XXX: for now clicking on an item launch the corresponding Chat widget | |
60 # behaviour should change in the future | |
61 try: | |
62 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method | |
63 # in host | |
64 plg_infos = [p for p in G.host.getPluggedWidgets() | |
65 if 'chat' in p['import_name']][0] | |
66 except IndexError: | |
67 log.warning(u"No plugin widget found to display chat") | |
68 else: | |
69 factory = plg_infos['factory'] | |
70 G.host.switchWidget(self, factory(plg_infos, | |
71 jid.JID(self.jid), | |
72 profiles=iter(G.host.profiles))) | |
22 | 73 |
74 | |
219 | 75 class ContactList(QuickContactList, cagou_widget.CagouWidget, FilterBehavior): |
76 float_layout = properties.ObjectProperty() | |
77 layout = properties.ObjectProperty() | |
9 | 78 |
79 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
|
80 QuickContactList.__init__(self, G.host, profiles) |
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
81 cagou_widget.CagouWidget.__init__(self) |
219 | 82 FilterBehavior.__init__(self) |
83 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
|
84 self.postInit() |
219 | 85 if len(self.profiles) != 1: |
86 raise NotImplementedError('multi profiles is not implemented yet') | |
87 self.update(profile=next(iter(self.profiles))) | |
9 | 88 |
110
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
89 def onHeaderInputComplete(self, wid, text): |
219 | 90 self.do_filter(self.layout.children, |
91 text, | |
92 lambda c: c.jid, | |
93 width_cb=lambda c: c.base_width, | |
94 height_cb=lambda c: c.minimum_height, | |
95 ) | |
96 | |
97 def _addContactItem(self, bare_jid, profile): | |
98 """Create a new ContactItem 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
|
99 |
219 | 100 item will be added in a sorted position |
101 @param bare_jid(jid.JID): entity bare JID | |
102 @param profile(unicode): profile where the contact is | |
103 """ | |
104 data = G.host.contact_lists[profile].getItem(bare_jid) | |
105 wid = ContactItem(data=data, jid=bare_jid) | |
106 child_jids = [c.jid for c in reversed(self.layout.children)] | |
107 idx = bisect.bisect_right(child_jids, bare_jid) | |
108 self.layout.add_widget(wid, -idx) | |
109 self._wid_map[(profile, bare_jid)] = wid | |
9 | 110 |
111 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
|
112 log.debug("update: %s %s %s" % (entities, type_, profile)) |
219 | 113 if type_ == None or type_ == C.UPDATE_STRUCTURE: |
114 log.debug("full contact list update") | |
115 self.layout.clear_widgets() | |
116 for bare_jid, data in self.items_sorted.iteritems(): | |
117 wid = ContactItem(data=data, jid=bare_jid) | |
118 self.layout.add_widget(wid) | |
119 self._wid_map[(profile, bare_jid)] = wid | |
120 elif type_ == C.UPDATE_MODIFY: | |
121 for entity in entities: | |
122 entity_bare = entity.bare | |
123 wid = self._wid_map[(profile, entity_bare)] | |
124 wid.data = G.host.contact_lists[profile].getItem(entity_bare) | |
125 elif type_ == C.UPDATE_ADD: | |
126 for entity in entities: | |
127 self._addContactItem(entity.bare, profile) | |
128 elif type_ == C.UPDATE_DELETE: | |
129 for entity in entities: | |
130 try: | |
131 self.layout.remove_widget(self._wid_map.pop((profile, entity.bare))) | |
132 except KeyError: | |
133 log.debug("entity not found: {entity}".format(entity=entity.bare)) | |
134 else: | |
135 log.debug("update type not handled: {update_type}".format(update_type=type_)) |