Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_contact_list.py @ 209:5e92bc937778
install (buildozer): added READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions for file sharing
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 May 2018 12:06:52 +0200 |
parents | 0ddd2b20cc6b |
children | 9faccd140119 |
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__) | |
14 | 23 from sat.core.i18n import _ |
9 | 24 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList |
22 | 25 from sat_frontends.tools import jid |
9 | 26 from kivy.uix.boxlayout import BoxLayout |
27 from kivy.uix.listview import ListView | |
28 from kivy.adapters.listadapter import ListAdapter | |
110
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
29 from kivy.metrics import dp |
9 | 30 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
|
31 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
|
32 from cagou.core import image |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
33 from cagou import G |
9 | 34 |
35 | |
14 | 36 PLUGIN_INFO = { |
37 "name": _(u"contacts"), | |
38 "main": "ContactList", | |
39 "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
|
40 "icon_medium": u"{media}/icons/muchoslava/png/contact_list_no_border_blue_44.png" |
14 | 41 } |
42 | |
43 | |
9 | 44 class Avatar(image.Image): |
45 pass | |
46 | |
47 | |
48 class ContactItem(BoxLayout): | |
49 data = properties.DictProperty() | |
50 jid = properties.StringProperty('') | |
51 | |
52 def __init__(self, **kwargs): | |
50
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
53 super(ContactItem, self).__init__(**kwargs) |
9 | 54 |
22 | 55 def on_touch_down(self, touch): |
56 if self.collide_point(*touch.pos): | |
57 # XXX: for now clicking on an item launch the corresponding Chat widget | |
58 # behaviour should change in the future | |
59 try: | |
60 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method | |
61 # in host | |
62 plg_infos = [p for p in G.host.getPluggedWidgets() if 'chat' in p['import_name']][0] | |
63 except IndexError: | |
64 log.warning(u"No plugin widget found to display chat") | |
65 else: | |
66 factory = plg_infos['factory'] | |
67 G.host.switchWidget(self, factory(plg_infos, jid.JID(self.jid), profiles=iter(G.host.profiles))) | |
68 | |
69 | |
50
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
70 class ContactListView(ListView): |
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
71 pass |
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
72 |
9 | 73 |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
74 class ContactList(QuickContactList, cagou_widget.CagouWidget): |
9 | 75 |
76 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
|
77 QuickContactList.__init__(self, G.host, profiles) |
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
78 cagou_widget.CagouWidget.__init__(self) |
9 | 79 self.adapter = ListAdapter(data={}, |
80 cls=ContactItem, | |
81 args_converter=self.contactDataConverter, | |
82 selection_mode='multiple', | |
83 allow_empty_selection=True, | |
84 ) | |
50
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
85 self.add_widget(ContactListView(adapter=self.adapter)) |
17
5c9feaa060a5
contact list: added call to the new postInit method
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
86 self.postInit() |
9 | 87 self.update() |
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): |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
90 # FIXME: this is implementation dependent, need to be done properly |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
91 items = self.children[0].children[0].children[0].children |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
92 |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
93 for item in items: |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
94 if text not in item.ids.jid_label.text: |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
95 item.height = 0 |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
96 item.opacity = 0 |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
97 else: |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
98 item.height = dp(50) |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
99 item.opacity = 1 |
34dfe0e32064
contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents:
90
diff
changeset
|
100 |
9 | 101 def contactDataConverter(self, idx, bare_jid): |
102 return {"jid": bare_jid, "data": self._items_cache[bare_jid]} | |
103 | |
104 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
|
105 log.debug("update: %s %s %s" % (entities, type_, profile)) |
9 | 106 # FIXME: for now we update on each event |
107 # if entities is None and type_ is None: | |
50
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
108 self._items_cache = self.items_sorted |
c45d6e9ec731
contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents:
39
diff
changeset
|
109 self.adapter.data = self.items_sorted.keys() |
9 | 110 |