Mercurial > libervia-desktop-kivy
annotate src/cagou/plugins/plugin_wid_contact_list.py @ 22:74117b733bac
plugin chat: first draft:
- only one 2 one display is handled for now
- own messages are displayed in blue, other ones in gray
- by default we display our own jid (for now)
- to change target, contact in contact widget can be clicked, or a jid can be entered in header input
- disco is called on jid entered in header, if it's a conference a MUCJoin will be called (not implemented yet), else a new chat widget with the jid replace the current one
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 08 Aug 2016 01:07:43 +0200 |
parents | 5c9feaa060a5 |
children | d09bd16dbbe2 |
rev | line source |
---|---|
9 | 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__) | |
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 | |
29 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
|
30 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
|
31 from cagou.core import image |
16
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
32 from cagou import G |
9 | 33 |
34 | |
14 | 35 PLUGIN_INFO = { |
36 "name": _(u"contacts"), | |
37 "main": "ContactList", | |
38 "description": _(u"list of contacts"), | |
39 } | |
40 | |
41 | |
9 | 42 class Avatar(image.Image): |
43 pass | |
44 | |
45 | |
46 class ContactItem(BoxLayout): | |
47 data = properties.DictProperty() | |
48 jid = properties.StringProperty('') | |
49 | |
50 def __init__(self, **kwargs): | |
51 BoxLayout.__init__(self, **kwargs) | |
52 | |
22 | 53 def on_touch_down(self, touch): |
54 if self.collide_point(*touch.pos): | |
55 # XXX: for now clicking on an item launch the corresponding Chat widget | |
56 # behaviour should change in the future | |
57 try: | |
58 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method | |
59 # in host | |
60 plg_infos = [p for p in G.host.getPluggedWidgets() if 'chat' in p['import_name']][0] | |
61 except IndexError: | |
62 log.warning(u"No plugin widget found to display chat") | |
63 else: | |
64 factory = plg_infos['factory'] | |
65 G.host.switchWidget(self, factory(plg_infos, jid.JID(self.jid), profiles=iter(G.host.profiles))) | |
66 | |
67 | |
9 | 68 |
15
56838ad5c84b
files reorganisation, cagou is now launched with python2 cagou.py in src/
Goffi <goffi@goffi.org>
parents:
14
diff
changeset
|
69 class ContactList(QuickContactList, cagou_widget.CagouWidget): |
9 | 70 |
71 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
|
72 QuickContactList.__init__(self, G.host, profiles) |
ba14b596b90e
host can now be get as a global value:
Goffi <goffi@goffi.org>
parents:
15
diff
changeset
|
73 cagou_widget.CagouWidget.__init__(self) |
9 | 74 self.adapter = ListAdapter(data={}, |
75 cls=ContactItem, | |
76 args_converter=self.contactDataConverter, | |
77 selection_mode='multiple', | |
78 allow_empty_selection=True, | |
79 ) | |
80 self.add_widget(ListView(adapter=self.adapter)) | |
17
5c9feaa060a5
contact list: added call to the new postInit method
Goffi <goffi@goffi.org>
parents:
16
diff
changeset
|
81 self.postInit() |
9 | 82 self.update() |
83 | |
84 def contactDataConverter(self, idx, bare_jid): | |
85 return {"jid": bare_jid, "data": self._items_cache[bare_jid]} | |
86 | |
87 def update(self, entities=None, type_=None, profile=None): | |
88 log.info("update: %s %s %s" % (entities, type_, profile)) | |
89 # FIXME: for now we update on each event | |
90 # if entities is None and type_ is None: | |
91 self._items_cache = self.items | |
92 self.adapter.data = self.items_sorted | |
93 |