annotate cagou/plugins/plugin_wid_contact_list.py @ 221:e1a385a791cc

plugin contact list: implemented contact addition
author Goffi <goffi@goffi.org>
date Tue, 26 Jun 2018 07:36:11 +0200
parents 9faccd140119
children 9e5f9f0cee48
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
126
cd99f70ea592 global file reorganisation:
Goffi <goffi@goffi.org>
parents: 110
diff changeset
5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org)
9
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__)
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
23 from cagou.core.constants import Const as C
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
24 from sat.core.i18n import _
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat_frontends.quick_frontend.quick_contact_list import QuickContactList
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
26 from sat_frontends.tools import jid
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.boxlayout import BoxLayout
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
28 from kivy.uix.behaviors import ButtonBehavior
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
29 from cagou.core.utils import FilterBehavior
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
30 from cagou.core.menu import SideMenu
110
34dfe0e32064 contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents: 90
diff changeset
31 from kivy.metrics import dp
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 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
33 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
34 from cagou.core import image
16
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
35 from cagou import G
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
36 from functools import partial
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
37 import bisect
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
38 import re
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
41 PLUGIN_INFO = {
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
42 "name": _(u"contacts"),
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
43 "main": "ContactList",
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
44 "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
45 "icon_medium": u"{media}/icons/muchoslava/png/contact_list_no_border_blue_44.png"
14
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
46 }
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
47
21a432afd06d plugin system, first draft:
Goffi <goffi@goffi.org>
parents: 10
diff changeset
48
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
49 class AddContactMenu(SideMenu):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
50 profile = properties.StringProperty()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
51 instructions = properties.StringProperty(_(u"Please enter new contact JID"))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
52 size_hint_close = (1, 0)
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
53 size_hint_open = (1, 0.5)
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
54
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
55 def __init__(self, **kwargs):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
56 super(AddContactMenu, self).__init__(**kwargs)
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
57 if self.profile is None:
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
58 log.warning(_(u"profile not set in AddContactMenu"))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
59 self.profile = next(iter(G.host.profiles))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
60
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
61 def addContact(self, contact_jid):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
62 """Actually add the contact
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
63
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
64 @param contact_jid(unicode): jid of the contact to add
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
65 """
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
66 contact_jid = contact_jid.strip()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
67 # FIXME: trivial jid verification
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
68 if not contact_jid or not re.match(r"[^@ ]+@[^@ ]+", contact_jid):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
69 return
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
70 contact_jid = jid.JID(contact_jid).bare
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
71 G.host.bridge.addContact(contact_jid,
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
72 self.profile,
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
73 callback=lambda: G.host.addNote(
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
74 _(u"contact request"),
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
75 _(u"a contact request has been sent to {contact_jid}").format(
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
76 contact_jid=contact_jid)),
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
77 errback=partial(G.host.errback,
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
78 title=_(u"can't add contact"),
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
79 message=_(u"error while trying to add contact: {msg}")))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
80 self.hide()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
81
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
82
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 class Avatar(image.Image):
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 pass
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
87 class ContactItem(ButtonBehavior, BoxLayout):
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
88 base_width = dp(150)
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
89 profile = properties.StringProperty()
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 data = properties.DictProperty()
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 jid = properties.StringProperty('')
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def __init__(self, **kwargs):
50
c45d6e9ec731 contact list: fixed contact list display
Goffi <goffi@goffi.org>
parents: 39
diff changeset
94 super(ContactItem, self).__init__(**kwargs)
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
96 def on_release(self):
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
97 assert self.profile
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
98 # XXX: for now clicking on an item launch the corresponding Chat widget
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
99 # behaviour should change in the future
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
100 try:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
101 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
102 # in host
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
103 plg_infos = [p for p in G.host.getPluggedWidgets()
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
104 if 'chat' in p['import_name']][0]
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
105 except IndexError:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
106 log.warning(u"No plugin widget found to display chat")
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
107 else:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
108 factory = plg_infos['factory']
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
109 G.host.switchWidget(self, factory(plg_infos,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
110 jid.JID(self.jid),
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
111 profiles=[self.profile]))
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
112
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents: 17
diff changeset
113
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
114 class ContactList(QuickContactList, cagou_widget.CagouWidget, FilterBehavior):
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
115 float_layout = properties.ObjectProperty()
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
116 layout = properties.ObjectProperty()
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 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
119 QuickContactList.__init__(self, G.host, profiles)
ba14b596b90e host can now be get as a global value:
Goffi <goffi@goffi.org>
parents: 15
diff changeset
120 cagou_widget.CagouWidget.__init__(self)
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
121 FilterBehavior.__init__(self)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
122 self._wid_map = {} # (profile, bare_jid) to widget map
17
5c9feaa060a5 contact list: added call to the new postInit method
Goffi <goffi@goffi.org>
parents: 16
diff changeset
123 self.postInit()
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
124 if len(self.profiles) != 1:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
125 raise NotImplementedError('multi profiles is not implemented yet')
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
126 self.update(profile=next(iter(self.profiles)))
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
128 def addContactMenu(self):
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
129 """Show the "add a contact" menu"""
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
130 # FIXME: for now we add contact to the first profile we find
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
131 profile = next(iter(self.profiles))
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
132 AddContactMenu(profile=profile).show()
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
133
110
34dfe0e32064 contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents: 90
diff changeset
134 def onHeaderInputComplete(self, wid, text):
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
135 self.do_filter(self.layout.children,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
136 text,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
137 lambda c: c.jid,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
138 width_cb=lambda c: c.base_width,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
139 height_cb=lambda c: c.minimum_height,
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
140 )
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
141
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
142 def _addContactItem(self, bare_jid, profile):
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
143 """Create a new ContactItem instance, and add it
110
34dfe0e32064 contact list: text entered in header input do filtering in shown contacts
Goffi <goffi@goffi.org>
parents: 90
diff changeset
144
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
145 item will be added in a sorted position
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
146 @param bare_jid(jid.JID): entity bare JID
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
147 @param profile(unicode): profile where the contact is
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
148 """
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
149 data = G.host.contact_lists[profile].getItem(bare_jid)
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
150 wid = ContactItem(profile=profile, data=data, jid=bare_jid)
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
151 child_jids = [c.jid for c in reversed(self.layout.children)]
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
152 idx = bisect.bisect_right(child_jids, bare_jid)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
153 self.layout.add_widget(wid, -idx)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
154 self._wid_map[(profile, bare_jid)] = wid
9
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155
7b0a53d2afd3 contact list: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 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
157 log.debug("update: %s %s %s" % (entities, type_, profile))
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
158 if type_ == None or type_ == C.UPDATE_STRUCTURE:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
159 log.debug("full contact list update")
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
160 self.layout.clear_widgets()
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
161 for bare_jid, data in self.items_sorted.iteritems():
221
e1a385a791cc plugin contact list: implemented contact addition
Goffi <goffi@goffi.org>
parents: 219
diff changeset
162 wid = ContactItem(profile=profile, data=data, jid=bare_jid)
219
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
163 self.layout.add_widget(wid)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
164 self._wid_map[(profile, bare_jid)] = wid
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
165 elif type_ == C.UPDATE_MODIFY:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
166 for entity in entities:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
167 entity_bare = entity.bare
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
168 wid = self._wid_map[(profile, entity_bare)]
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
169 wid.data = G.host.contact_lists[profile].getItem(entity_bare)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
170 elif type_ == C.UPDATE_ADD:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
171 for entity in entities:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
172 self._addContactItem(entity.bare, profile)
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
173 elif type_ == C.UPDATE_DELETE:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
174 for entity in entities:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
175 try:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
176 self.layout.remove_widget(self._wid_map.pop((profile, entity.bare)))
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
177 except KeyError:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
178 log.debug("entity not found: {entity}".format(entity=entity.bare))
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
179 else:
9faccd140119 plugin contact list: refactoring:
Goffi <goffi@goffi.org>
parents: 180
diff changeset
180 log.debug("update type not handled: {update_type}".format(update_type=type_))