annotate src/cagou/plugins/plugin_wid_contact_list.py @ 97:5d2289127bb7

menu (upload): better menu using dedicated widget: upload menu now use a decicated widget instead of context menu. The menu take half the size of the main window, and show each upload option as an icon. Use can select upload or P2P sending, and a short text message explains how the file will be transmitted.
author Goffi <goffi@goffi.org>
date Thu, 29 Dec 2016 23:47:07 +0100
parents 9a6121722669
children 34dfe0e32064
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core import log as logging
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = logging.getLogger(__name__)
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
23 from sat.core.i18n import _
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
25 from sat_frontends.tools import jid
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from kivy.uix.boxlayout import BoxLayout
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.listview import ListView
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from kivy.adapters.listadapter import ListAdapter
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
35 PLUGIN_INFO = {
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
36 "name": _(u"contacts"),
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
37 "main": "ContactList",
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
38 "description": _(u"list of contacts"),
90
9a6121722669 chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents: 50
diff changeset
39 "icon_small": u"{media}/icons/muchoslava/png/contact_list_new_32.png",
9a6121722669 chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents: 50
diff changeset
40 "icon_medium": u"{media}/icons/muchoslava/png/contact_list_new_44.png"
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
41 }
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
42
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
43
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 class Avatar(image.Image):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 pass
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 class ContactItem(BoxLayout):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 data = properties.DictProperty()
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 jid = properties.StringProperty('')
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
55 def on_touch_down(self, touch):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
56 if self.collide_point(*touch.pos):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
57 # XXX: for now clicking on an item launch the corresponding Chat widget
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
58 # behaviour should change in the future
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
59 try:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
60 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
61 # in host
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
62 plg_infos = [p for p in G.host.getPluggedWidgets() if 'chat' in p['import_name']][0]
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
63 except IndexError:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
64 log.warning(u"No plugin widget found to display chat")
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
65 else:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
66 factory = plg_infos['factory']
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
67 G.host.switchWidget(self, factory(plg_infos, jid.JID(self.jid), profiles=iter(G.host.profiles)))
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
68
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 self.adapter = ListAdapter(data={},
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 cls=ContactItem,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 args_converter=self.contactDataConverter,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 selection_mode='multiple',
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 allow_empty_selection=True,
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 self.update()
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 def contactDataConverter(self, idx, bare_jid):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 return {"jid": bare_jid, "data": self._items_cache[bare_jid]}
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 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
93 log.debug("update: %s %s %s" % (entities, type_, profile))
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 # FIXME: for now we update on each event
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 # if entities is None and type_ is None:
50
c45d6e9ec731 contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents: 39
diff changeset
96 self._items_cache = self.items_sorted
c45d6e9ec731 contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents: 39
diff changeset
97 self.adapter.data = self.items_sorted.keys()
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98