comparison src/contact_list.py @ 9:7b0a53d2afd3

contact list: first draft
author Goffi <goffi@goffi.org>
date Fri, 08 Jul 2016 18:30:30 +0200
parents
children 8b2836b5b6c7
comparison
equal deleted inserted replaced
8:d9095d1dd7ae 9:7b0a53d2afd3
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
5 # Copyright (C) 2016 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_frontends.quick_frontend.quick_contact_list import QuickContactList
24 from kivy.uix.boxlayout import BoxLayout
25 from kivy.uix.listview import ListView
26 from kivy.adapters.listadapter import ListAdapter
27 from kivy import properties
28 import image
29
30
31 class Avatar(image.Image):
32 pass
33
34
35 class ContactItem(BoxLayout):
36 data = properties.DictProperty()
37 jid = properties.StringProperty('')
38
39 def __init__(self, **kwargs):
40 BoxLayout.__init__(self, **kwargs)
41
42
43 class ContactList(QuickContactList, BoxLayout):
44
45 def __init__(self, host, target, profiles):
46 QuickContactList.__init__(self, host, profiles)
47 BoxLayout.__init__(self, orientation="vertical")
48 self.adapter = ListAdapter(data={},
49 cls=ContactItem,
50 args_converter=self.contactDataConverter,
51 selection_mode='multiple',
52 allow_empty_selection=True,
53 )
54 self.add_widget(ListView(adapter=self.adapter))
55 self.update()
56
57 def contactDataConverter(self, idx, bare_jid):
58 return {"jid": bare_jid, "data": self._items_cache[bare_jid]}
59
60 def update(self, entities=None, type_=None, profile=None):
61 log.info("update: %s %s %s" % (entities, type_, profile))
62 # FIXME: for now we update on each event
63 # if entities is None and type_ is None:
64 self._items_cache = self.items
65 self.adapter.data = self.items_sorted
66