Mercurial > libervia-backend
annotate sat/stdui/ui_contact_list.py @ 3971:9b1d74a6b48c
tests (e2e/cli): add tests for JET:
rel 378
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 31 Oct 2022 04:09:38 +0100 |
parents | be6d91572633 |
children | 524856bd7b19 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
3 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
4 # SAT standard user interface for managing contacts |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
6 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
11 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
16 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
19 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
20 from sat.core.i18n import _, D_ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
22 from sat.tools import xml_tools |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
23 from twisted.words.protocols.jabber import jid |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
24 from xml.dom.minidom import Element |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
25 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
26 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
27 class ContactList(object): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
28 """Add, update and remove contacts.""" |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
29 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
30 def __init__(self, host): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
31 self.host = host |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
32 self.__add_id = host.registerCallback(self._addContact, with_data=True) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
33 self.__update_id = host.registerCallback(self._updateContact, with_data=True) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 self.__confirm_delete_id = host.registerCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
35 self._getConfirmRemoveXMLUI, with_data=True |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
36 ) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
37 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
38 host.importMenu( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 (D_("Contacts"), D_("Add contact")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 self._getAddDialogXMLUI, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 security_limit=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 help_string=D_("Add contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 host.importMenu( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 (D_("Contacts"), D_("Update contact")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 self._getUpdateDialogXMLUI, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 security_limit=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 help_string=D_("Update contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 host.importMenu( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 (D_("Contacts"), D_("Remove contact")), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 self._getRemoveDialogXMLUI, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 security_limit=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 help_string=D_("Remove contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 ) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
56 |
2263
90189f312fd3
core (stdui): added a FIXME to not use plugin/default_host in the future
Goffi <goffi@goffi.org>
parents:
2071
diff
changeset
|
57 # FIXME: a plugin should not be used here, and current profile's jid host would be better than installation wise host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 if "MISC-ACCOUNT" in self.host.plugins: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 self.default_host = self.host.plugins["MISC-ACCOUNT"].getNewAccountDomain() |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
60 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 self.default_host = "example.net" |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
62 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
63 def getContacts(self, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
64 """Return a sorted list of the contacts for that profile |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
65 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
66 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
67 @return: list[string] |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
68 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
69 client = self.host.getClient(profile) |
1262
f8a8434dbac7
core: improved roster management + misc:
Goffi <goffi@goffi.org>
parents:
987
diff
changeset
|
70 ret = [contact.full() for contact in client.roster.getJids()] |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
71 ret.sort() |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
72 return ret |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
73 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
74 def getGroups(self, new_groups=None, profile=C.PROF_KEY_NONE): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
75 """Return a sorted list of the groups for that profile |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
76 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
77 @param new_group (list): add these groups to the existing ones |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
78 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
79 @return: list[string] |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
80 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
81 client = self.host.getClient(profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
82 ret = client.roster.getGroups() |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
83 ret.sort() |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
84 ret.extend([group for group in new_groups if group not in ret]) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
85 return ret |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
86 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
87 def getGroupsOfContact(self, user_jid_s, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
88 """Return all the groups of the given contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
89 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
90 @param user_jid_s (string) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
91 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
92 @return: list[string] |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
93 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
94 client = self.host.getClient(profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
95 return client.roster.getItem(jid.JID(user_jid_s)).groups |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
96 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
97 def getGroupsOfAllContacts(self, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
98 """Return a mapping between the contacts and their groups |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
99 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
100 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
101 @return: dict (key: string, value: list[string]): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
102 - key: the JID userhost |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
103 - value: list of groups |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
104 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
105 client = self.host.getClient(profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
106 return {item.jid.userhost(): item.groups for item in client.roster.getItems()} |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
107 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
108 def _data2elts(self, data): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
109 """Convert a contacts data dict to minidom Elements |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
110 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
111 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
112 @return list[Element] |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
113 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
114 elts = [] |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
115 for key in data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 key_elt = Element("jid") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 key_elt.setAttribute("name", key) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
118 for value in data[key]: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 value_elt = Element("group") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 value_elt.setAttribute("name", value) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
121 key_elt.childNodes.append(value_elt) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
122 elts.append(key_elt) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
123 return elts |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
124 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
125 def getDialogXMLUI(self, options, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
126 """Generic method to return the XMLUI dialog for adding or updating a contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
127 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
128 @param options (dict): parameters for the dialog, with the keys: |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
129 - 'id': the menu callback id |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
130 - 'title': deferred localized string |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
131 - 'contact_text': deferred localized string |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
132 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
133 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
134 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
135 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 form_ui = xml_tools.XMLUI("form", title=options["title"], submit_id=options["id"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 if "message" in data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 form_ui.addText(data["message"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 form_ui.addDivider("dash") |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
140 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 form_ui.addText(options["contact_text"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
142 if options["id"] == self.__add_id: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
143 contact = data.get( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 xml_tools.formEscape("contact_jid"), "@%s" % self.default_host |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 form_ui.addString("contact_jid", value=contact) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 elif options["id"] == self.__update_id: |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
148 contacts = self.getContacts(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 list_ = form_ui.addList("contact_jid", options=contacts, selected=contacts[0]) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
150 elts = self._data2elts(self.getGroupsOfAllContacts(profile)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 list_.setInternalCallback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 "groups_of_contact", fields=["contact_jid", "groups_list"], data_elts=elts |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
154 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 form_ui.addDivider("blank") |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
156 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
157 form_ui.addText(_("Select in which groups your contact is:")) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
158 selected_groups = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 if "selected_groups" in data: |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 selected_groups = data["selected_groups"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 elif options["id"] == self.__update_id: |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
162 try: |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
163 selected_groups = self.getGroupsOfContact(contacts[0], profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
164 except IndexError: |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
165 pass |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
166 groups = self.getGroups(selected_groups, profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
167 form_ui.addList( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 "groups_list", options=groups, selected=selected_groups, styles=["multi"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
169 ) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
170 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 adv_list = form_ui.changeContainer("advanced_list", columns=3, selectable="no") |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
172 form_ui.addLabel(D_("Add group")) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
173 form_ui.addString("add_group") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 button = form_ui.addButton("", value=D_("Add")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
175 button.setInternalCallback("move", fields=["add_group", "groups_list"]) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
176 adv_list.end() |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
177 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 form_ui.addDivider("blank") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 return {"xmlui": form_ui.toXml()} |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
180 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
181 def _getAddDialogXMLUI(self, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
182 """Get the dialog for adding contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
183 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
184 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
185 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
186 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
187 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 "id": self.__add_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
190 "title": D_("Add contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
191 "contact_text": D_("New contact identifier (JID):"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
192 } |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
193 return self.getDialogXMLUI(options, {}, profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
194 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
195 def _getUpdateDialogXMLUI(self, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
196 """Get the dialog for updating contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
197 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
198 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
199 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
200 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
201 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
202 if not self.getContacts(profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
203 _dialog = xml_tools.XMLUI("popup", title=D_("Nothing to update")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
204 _dialog.addText(_("Your contact list is empty.")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
205 return {"xmlui": _dialog.toXml()} |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
206 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 "id": self.__update_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 "title": D_("Update contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
210 "contact_text": D_("Which contact do you want to update?"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
211 } |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
212 return self.getDialogXMLUI(options, {}, profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
213 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
214 def _getRemoveDialogXMLUI(self, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
215 """Get the dialog for removing contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
216 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
217 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
218 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
219 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
220 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
221 if not self.getContacts(profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 _dialog = xml_tools.XMLUI("popup", title=D_("Nothing to delete")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
223 _dialog.addText(_("Your contact list is empty.")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 return {"xmlui": _dialog.toXml()} |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
225 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 form_ui = xml_tools.XMLUI( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 "form", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 title=D_("Who do you want to remove from your contacts?"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 submit_id=self.__confirm_delete_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
230 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 form_ui.addList("contact_jid", options=self.getContacts(profile)) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 return {"xmlui": form_ui.toXml()} |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
233 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
234 def _getConfirmRemoveXMLUI(self, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
235 """Get the confirmation dialog for removing contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
236 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
237 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
238 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
239 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
240 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
241 if C.bool(data.get("cancelled", "false")): |
2071
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
242 return {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
243 contact = data[xml_tools.formEscape("contact_jid")] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
244 |
2071
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
245 def delete_cb(data, profile): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
246 if not C.bool(data.get("cancelled", "false")): |
2071
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
247 self._deleteContact(jid.JID(contact), profile) |
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
248 return {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 |
2071
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
250 delete_id = self.host.registerCallback(delete_cb, with_data=True, one_shot=True) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
251 form_ui = xml_tools.XMLUI("form", title=D_("Delete contact"), submit_id=delete_id) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 form_ui.addText( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 D_("Are you sure you want to remove %s from your contact list?") % contact |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 return {"xmlui": form_ui.toXml()} |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
256 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
257 def _addContact(self, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
258 """Add the selected contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
259 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
260 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
261 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
262 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
263 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 if C.bool(data.get("cancelled", "false")): |
2071
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
265 return {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 contact_jid_s = data[xml_tools.formEscape("contact_jid")] |
1714
0b4c1f6ada52
stdui (contact_list): use jid.JID to check the JID instead of an approximative regex
souliane <souliane@mailoo.org>
parents:
1546
diff
changeset
|
267 try: |
0b4c1f6ada52
stdui (contact_list): use jid.JID to check the JID instead of an approximative regex
souliane <souliane@mailoo.org>
parents:
1546
diff
changeset
|
268 contact_jid = jid.JID(contact_jid_s) |
0b4c1f6ada52
stdui (contact_list): use jid.JID to check the JID instead of an approximative regex
souliane <souliane@mailoo.org>
parents:
1546
diff
changeset
|
269 except (RuntimeError, jid.InvalidFormat, AttributeError): |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
270 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 data["selected_groups"] = data[xml_tools.formEscape("groups_list")].split( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 "\t" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 options = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 "id": self.__add_id, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 "title": D_("Add contact"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 "contact_text": D_('Please enter a valid JID (like "contact@%s"):') |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 % self.default_host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 } |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
280 return self.getDialogXMLUI(options, data, profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
281 self.host.addContact(contact_jid, profile_key=profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
282 return self._updateContact(data, profile) # after adding, updating |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
283 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
284 def _updateContact(self, data, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
285 """Update the selected contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
286 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
287 @param data (dict) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
288 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
289 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
290 """ |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
291 client = self.host.getClient(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
292 if C.bool(data.get("cancelled", "false")): |
2071
c2fdee1bd908
core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
293 return {} |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 contact_jid = jid.JID(data[xml_tools.formEscape("contact_jid")]) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
295 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.onFormSubmitted) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
296 groups = data[xml_tools.formEscape("groups_list")].split("\t") |
3254
6cf4bd6972c2
core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
297 self.host.updateContact(client, contact_jid, name="", groups=groups) |
987
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
298 return {} |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
299 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
300 def _deleteContact(self, contact_jid, profile): |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
301 """Delete the selected contact |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
302 |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
303 @param contact_jid (JID) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
304 @param profile: %(doc_profile)s |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
305 @return dict |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
306 """ |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
307 self.host.delContact(contact_jid, profile_key=profile) |
3a96920c07b7
core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff
changeset
|
308 return {} |