comparison cagou/plugins/plugin_wid_contact_list.py @ 312:772c170b47a9

Python3 port: /!\ Cagou now runs with Python 3.6+ Port has been done in the same way as for backend (check backend commit b2d067339de3 message for details).
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:14:22 +0200
parents 1b835bcfa663
children e2b51663d8b8
comparison
equal deleted inserted replaced
311:a0d978d3ce84 312:772c170b47a9
36 import bisect 36 import bisect
37 import re 37 import re
38 38
39 39
40 PLUGIN_INFO = { 40 PLUGIN_INFO = {
41 "name": _(u"contacts"), 41 "name": _("contacts"),
42 "main": "ContactList", 42 "main": "ContactList",
43 "description": _(u"list of contacts"), 43 "description": _("list of contacts"),
44 "icon_medium": u"{media}/icons/muchoslava/png/contact_list_no_border_blue_44.png" 44 "icon_medium": "{media}/icons/muchoslava/png/contact_list_no_border_blue_44.png"
45 } 45 }
46 46
47 47
48 class AddContactMenu(SideMenu): 48 class AddContactMenu(SideMenu):
49 profile = properties.StringProperty() 49 profile = properties.StringProperty()
51 size_hint_open = (1, 0.5) 51 size_hint_open = (1, 0.5)
52 52
53 def __init__(self, **kwargs): 53 def __init__(self, **kwargs):
54 super(AddContactMenu, self).__init__(**kwargs) 54 super(AddContactMenu, self).__init__(**kwargs)
55 if self.profile is None: 55 if self.profile is None:
56 log.warning(_(u"profile not set in AddContactMenu")) 56 log.warning(_("profile not set in AddContactMenu"))
57 self.profile = next(iter(G.host.profiles)) 57 self.profile = next(iter(G.host.profiles))
58 58
59 def addContact(self, contact_jid): 59 def addContact(self, contact_jid):
60 """Actually add the contact 60 """Actually add the contact
61 61
65 contact_jid = contact_jid.strip() 65 contact_jid = contact_jid.strip()
66 # FIXME: trivial jid verification 66 # FIXME: trivial jid verification
67 if not contact_jid or not re.match(r"[^@ ]+@[^@ ]+", contact_jid): 67 if not contact_jid or not re.match(r"[^@ ]+@[^@ ]+", contact_jid):
68 return 68 return
69 contact_jid = jid.JID(contact_jid).bare 69 contact_jid = jid.JID(contact_jid).bare
70 G.host.bridge.addContact(unicode(contact_jid), 70 G.host.bridge.addContact(str(contact_jid),
71 self.profile, 71 self.profile,
72 callback=lambda: G.host.addNote( 72 callback=lambda: G.host.addNote(
73 _(u"contact request"), 73 _("contact request"),
74 _(u"a contact request has been sent to {contact_jid}").format( 74 _("a contact request has been sent to {contact_jid}").format(
75 contact_jid=contact_jid)), 75 contact_jid=contact_jid)),
76 errback=partial(G.host.errback, 76 errback=partial(G.host.errback,
77 title=_(u"can't add contact"), 77 title=_("can't add contact"),
78 message=_(u"error while trying to add contact: {msg}"))) 78 message=_("error while trying to add contact: {msg}")))
79 79
80 80
81 class DelContactMenu(SideMenu): 81 class DelContactMenu(SideMenu):
82 size_hint_close = (1, 0) 82 size_hint_close = (1, 0)
83 size_hint_open = (1, 0.5) 83 size_hint_open = (1, 0.5)
86 self.contact_item = contact_item 86 self.contact_item = contact_item
87 super(DelContactMenu, self).__init__(**kwargs) 87 super(DelContactMenu, self).__init__(**kwargs)
88 88
89 def do_delete_contact(self): 89 def do_delete_contact(self):
90 self.hide() 90 self.hide()
91 G.host.bridge.delContact(unicode(self.contact_item.jid.bare), 91 G.host.bridge.delContact(str(self.contact_item.jid.bare),
92 self.contact_item.profile, 92 self.contact_item.profile,
93 callback=lambda: G.host.addNote( 93 callback=lambda: G.host.addNote(
94 _(u"contact removed"), 94 _("contact removed"),
95 _(u"{contact_jid} has been removed from your contacts list").format( 95 _("{contact_jid} has been removed from your contacts list").format(
96 contact_jid=self.contact_item.jid.bare)), 96 contact_jid=self.contact_item.jid.bare)),
97 errback=partial(G.host.errback, 97 errback=partial(G.host.errback,
98 title=_(u"can't remove contact"), 98 title=_("can't remove contact"),
99 message=_(u"error while trying to remove contact: {msg}"))) 99 message=_("error while trying to remove contact: {msg}")))
100 100
101 101
102 102
103 class Avatar(image.Image): 103 class Avatar(image.Image):
104 pass 104 pass
115 115
116 def do_item_action(self, touch): 116 def do_item_action(self, touch):
117 assert self.profile 117 assert self.profile
118 # XXX: for now clicking on an item launch the corresponding Chat widget 118 # XXX: for now clicking on an item launch the corresponding Chat widget
119 # behaviour should change in the future 119 # behaviour should change in the future
120 G.host.doAction(u'chat', jid.JID(self.jid), [self.profile]) 120 G.host.doAction('chat', jid.JID(self.jid), [self.profile])
121 121
122 def getMenuChoices(self): 122 def getMenuChoices(self):
123 choices = [] 123 choices = []
124 choices.append(dict(text=_(u'delete'), 124 choices.append(dict(text=_('delete'),
125 index=len(choices)+1, 125 index=len(choices)+1,
126 callback=self.main_wid.removeContact)) 126 callback=self.main_wid.removeContact))
127 return choices 127 return choices
128 128
129 129
178 def update(self, entities=None, type_=None, profile=None): 178 def update(self, entities=None, type_=None, profile=None):
179 log.debug("update: %s %s %s" % (entities, type_, profile)) 179 log.debug("update: %s %s %s" % (entities, type_, profile))
180 if type_ == None or type_ == C.UPDATE_STRUCTURE: 180 if type_ == None or type_ == C.UPDATE_STRUCTURE:
181 log.debug("full contact list update") 181 log.debug("full contact list update")
182 self.layout.clear_widgets() 182 self.layout.clear_widgets()
183 for bare_jid, data in self.items_sorted.iteritems(): 183 for bare_jid, data in self.items_sorted.items():
184 wid = ContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self) 184 wid = ContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self)
185 self.layout.add_widget(wid) 185 self.layout.add_widget(wid)
186 self._wid_map[(profile, bare_jid)] = wid 186 self._wid_map[(profile, bare_jid)] = wid
187 elif type_ == C.UPDATE_MODIFY: 187 elif type_ == C.UPDATE_MODIFY:
188 for entity in entities: 188 for entity in entities: