comparison cagou/plugins/plugin_wid_contact_list.py @ 126:cd99f70ea592

global file reorganisation: - follow common convention by puttin cagou in "cagou" instead of "src/cagou" - added VERSION in cagou with current version - updated dates - moved main executable in /bin - moved buildozer files in root directory - temporary moved platform to assets/platform
author Goffi <goffi@goffi.org>
date Thu, 05 Apr 2018 17:11:21 +0200
parents src/cagou/plugins/plugin_wid_contact_list.py@34dfe0e32064
children 0ddd2b20cc6b
comparison
equal deleted inserted replaced
125:b6e6afb0dc46 126:cd99f70ea592
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org)
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__)
23 from sat.core.i18n import _
24 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
25 from sat_frontends.tools import jid
26 from kivy.uix.boxlayout import BoxLayout
27 from kivy.uix.listview import ListView
28 from kivy.adapters.listadapter import ListAdapter
29 from kivy.metrics import dp
30 from kivy import properties
31 from cagou.core import cagou_widget
32 from cagou.core import image
33 from cagou import G
34
35
36 PLUGIN_INFO = {
37 "name": _(u"contacts"),
38 "main": "ContactList",
39 "description": _(u"list of contacts"),
40 "icon_small": u"{media}/icons/muchoslava/png/contact_list_new_32.png",
41 "icon_medium": u"{media}/icons/muchoslava/png/contact_list_new_44.png"
42 }
43
44
45 class Avatar(image.Image):
46 pass
47
48
49 class ContactItem(BoxLayout):
50 data = properties.DictProperty()
51 jid = properties.StringProperty('')
52
53 def __init__(self, **kwargs):
54 super(ContactItem, self).__init__(**kwargs)
55
56 def on_touch_down(self, touch):
57 if self.collide_point(*touch.pos):
58 # XXX: for now clicking on an item launch the corresponding Chat widget
59 # behaviour should change in the future
60 try:
61 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method
62 # in host
63 plg_infos = [p for p in G.host.getPluggedWidgets() if 'chat' in p['import_name']][0]
64 except IndexError:
65 log.warning(u"No plugin widget found to display chat")
66 else:
67 factory = plg_infos['factory']
68 G.host.switchWidget(self, factory(plg_infos, jid.JID(self.jid), profiles=iter(G.host.profiles)))
69
70
71 class ContactListView(ListView):
72 pass
73
74
75 class ContactList(QuickContactList, cagou_widget.CagouWidget):
76
77 def __init__(self, host, target, profiles):
78 QuickContactList.__init__(self, G.host, profiles)
79 cagou_widget.CagouWidget.__init__(self)
80 self.adapter = ListAdapter(data={},
81 cls=ContactItem,
82 args_converter=self.contactDataConverter,
83 selection_mode='multiple',
84 allow_empty_selection=True,
85 )
86 self.add_widget(ContactListView(adapter=self.adapter))
87 self.postInit()
88 self.update()
89
90 def onHeaderInputComplete(self, wid, text):
91 # FIXME: this is implementation dependent, need to be done properly
92 items = self.children[0].children[0].children[0].children
93
94 for item in items:
95 if text not in item.ids.jid_label.text:
96 item.height = 0
97 item.opacity = 0
98 else:
99 item.height = dp(50)
100 item.opacity = 1
101
102 def contactDataConverter(self, idx, bare_jid):
103 return {"jid": bare_jid, "data": self._items_cache[bare_jid]}
104
105 def update(self, entities=None, type_=None, profile=None):
106 log.debug("update: %s %s %s" % (entities, type_, profile))
107 # FIXME: for now we update on each event
108 # if entities is None and type_ is None:
109 self._items_cache = self.items_sorted
110 self.adapter.data = self.items_sorted.keys()
111