Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_contact_list.py @ 491:203755bbe0fe
massive refactoring from camelCase -> snake_case. See backend commit log for more details
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:44:32 +0200 |
parents | 3c9ba4a694ef |
children |
comparison
equal
deleted
inserted
replaced
490:962d17c4078c | 491:203755bbe0fe |
---|---|
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(_("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 contact_add(self, contact_jid): |
60 """Actually add the contact | 60 """Actually add the contact |
61 | 61 |
62 @param contact_jid(unicode): jid of the contact to add | 62 @param contact_jid(unicode): jid of the contact to add |
63 """ | 63 """ |
64 self.hide() | 64 self.hide() |
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(str(contact_jid), | 70 G.host.bridge.contact_add(str(contact_jid), |
71 self.profile, | 71 self.profile, |
72 callback=lambda: G.host.addNote( | 72 callback=lambda: G.host.add_note( |
73 _("contact request"), | 73 _("contact request"), |
74 _("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=_("can't add contact"), | 77 title=_("can't add contact"), |
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(str(self.contact_item.jid.bare), | 91 G.host.bridge.contact_del(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.add_note( |
94 _("contact removed"), | 94 _("contact removed"), |
95 _("{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=_("can't remove contact"), | 98 title=_("can't remove contact"), |
103 | 103 |
104 def do_item_action(self, touch): | 104 def do_item_action(self, touch): |
105 assert self.profile | 105 assert self.profile |
106 # XXX: for now clicking on an item launch the corresponding Chat widget | 106 # XXX: for now clicking on an item launch the corresponding Chat widget |
107 # behaviour should change in the future | 107 # behaviour should change in the future |
108 G.host.doAction('chat', jid.JID(self.jid), [self.profile]) | 108 G.host.do_action('chat', jid.JID(self.jid), [self.profile]) |
109 | 109 |
110 def getMenuChoices(self): | 110 def get_menu_choices(self): |
111 choices = [] | 111 choices = [] |
112 choices.append(dict(text=_('delete'), | 112 choices.append(dict(text=_('delete'), |
113 index=len(choices)+1, | 113 index=len(choices)+1, |
114 callback=self.main_wid.removeContact)) | 114 callback=self.main_wid.remove_contact)) |
115 return choices | 115 return choices |
116 | 116 |
117 | 117 |
118 class ContactList(QuickContactList, cagou_widget.CagouWidget, FilterBehavior, | 118 class ContactList(QuickContactList, cagou_widget.CagouWidget, FilterBehavior, |
119 TouchMenuBehavior): | 119 TouchMenuBehavior): |
124 def __init__(self, host, target, profiles): | 124 def __init__(self, host, target, profiles): |
125 QuickContactList.__init__(self, G.host, profiles) | 125 QuickContactList.__init__(self, G.host, profiles) |
126 cagou_widget.CagouWidget.__init__(self) | 126 cagou_widget.CagouWidget.__init__(self) |
127 FilterBehavior.__init__(self) | 127 FilterBehavior.__init__(self) |
128 self._wid_map = {} # (profile, bare_jid) to widget map | 128 self._wid_map = {} # (profile, bare_jid) to widget map |
129 self.postInit() | 129 self.post_init() |
130 if len(self.profiles) != 1: | 130 if len(self.profiles) != 1: |
131 raise NotImplementedError('multi profiles is not implemented yet') | 131 raise NotImplementedError('multi profiles is not implemented yet') |
132 self.update(profile=next(iter(self.profiles))) | 132 self.update(profile=next(iter(self.profiles))) |
133 | 133 |
134 def addContactMenu(self): | 134 def add_contact_menu(self): |
135 """Show the "add a contact" menu""" | 135 """Show the "add a contact" menu""" |
136 # FIXME: for now we add contact to the first profile we find | 136 # FIXME: for now we add contact to the first profile we find |
137 profile = next(iter(self.profiles)) | 137 profile = next(iter(self.profiles)) |
138 AddContactMenu(profile=profile).show() | 138 AddContactMenu(profile=profile).show() |
139 | 139 |
140 def removeContact(self, menu_label): | 140 def remove_contact(self, menu_label): |
141 item = self.menu_item | 141 item = self.menu_item |
142 self.clear_menu() | 142 self.clear_menu() |
143 DelContactMenu(contact_item=item).show() | 143 DelContactMenu(contact_item=item).show() |
144 | 144 |
145 def onHeaderInputComplete(self, wid, text): | 145 def on_header_wid_input_complete(self, wid, text): |
146 self.do_filter(self.layout, | 146 self.do_filter(self.layout, |
147 text, | 147 text, |
148 lambda c: c.jid, | 148 lambda c: c.jid, |
149 width_cb=lambda c: c.base_width, | 149 width_cb=lambda c: c.base_width, |
150 height_cb=lambda c: c.minimum_height, | 150 height_cb=lambda c: c.minimum_height, |
151 ) | 151 ) |
152 | 152 |
153 def _addContactItem(self, bare_jid, profile): | 153 def _add_contact_item(self, bare_jid, profile): |
154 """Create a new CLContactItem instance, and add it | 154 """Create a new CLContactItem instance, and add it |
155 | 155 |
156 item will be added in a sorted position | 156 item will be added in a sorted position |
157 @param bare_jid(jid.JID): entity bare JID | 157 @param bare_jid(jid.JID): entity bare JID |
158 @param profile(unicode): profile where the contact is | 158 @param profile(unicode): profile where the contact is |
159 """ | 159 """ |
160 data = G.host.contact_lists[profile].getItem(bare_jid) | 160 data = G.host.contact_lists[profile].get_item(bare_jid) |
161 wid = CLContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self) | 161 wid = CLContactItem(profile=profile, data=data, jid=bare_jid, main_wid=self) |
162 child_jids = [c.jid for c in reversed(self.layout.children)] | 162 child_jids = [c.jid for c in reversed(self.layout.children)] |
163 idx = bisect.bisect_right(child_jids, bare_jid) | 163 idx = bisect.bisect_right(child_jids, bare_jid) |
164 self.layout.add_widget(wid, -idx) | 164 self.layout.add_widget(wid, -idx) |
165 self._wid_map[(profile, bare_jid)] = wid | 165 self._wid_map[(profile, bare_jid)] = wid |
180 self._wid_map[(profile, bare_jid)] = wid | 180 self._wid_map[(profile, bare_jid)] = wid |
181 elif type_ == C.UPDATE_MODIFY: | 181 elif type_ == C.UPDATE_MODIFY: |
182 for entity in entities: | 182 for entity in entities: |
183 entity_bare = entity.bare | 183 entity_bare = entity.bare |
184 wid = self._wid_map[(profile, entity_bare)] | 184 wid = self._wid_map[(profile, entity_bare)] |
185 wid.data = G.host.contact_lists[profile].getItem(entity_bare) | 185 wid.data = G.host.contact_lists[profile].get_item(entity_bare) |
186 elif type_ == C.UPDATE_ADD: | 186 elif type_ == C.UPDATE_ADD: |
187 for entity in entities: | 187 for entity in entities: |
188 self._addContactItem(entity.bare, profile) | 188 self._add_contact_item(entity.bare, profile) |
189 elif type_ == C.UPDATE_DELETE: | 189 elif type_ == C.UPDATE_DELETE: |
190 for entity in entities: | 190 for entity in entities: |
191 try: | 191 try: |
192 self.layout.remove_widget(self._wid_map.pop((profile, entity.bare))) | 192 self.layout.remove_widget(self._wid_map.pop((profile, entity.bare))) |
193 except KeyError: | 193 except KeyError: |