annotate libervia/backend/stdui/ui_contact_list.py @ 4288:f46891f2c9cb

plugin XEP-0166: handle `content-add` action + expose `get_transport`: - `content-add` is now handled at this plugin level (implementation needs to be done in apps and transports plugins). - `get_transport` is now exposed. rel 447
author Goffi <goffi@goffi.org>
date Mon, 29 Jul 2024 03:30:58 +0200
parents 4b842c1fb686
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3254
diff changeset
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
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
20 from libervia.backend.core.i18n import _, D_
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.constants import Const as C
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
22 from libervia.backend.tools import xml_tools
987
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
32 self.__add_id = host.register_callback(self._add_contact, with_data=True)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
33 self.__update_id = host.register_callback(self._update_contact, with_data=True)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
34 self.__confirm_delete_id = host.register_callback(
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
35 self._get_confirm_remove_xmlui, with_data=True
2624
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
38 host.import_menu(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 (D_("Contacts"), D_("Add contact")),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
40 self._get_add_dialog_xmlui,
2624
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 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
44 host.import_menu(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 (D_("Contacts"), D_("Update contact")),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
46 self._get_update_dialog_xmlui,
2624
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 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
50 host.import_menu(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 (D_("Contacts"), D_("Remove contact")),
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
52 self._get_remove_dialog_xmlui,
2624
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:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
59 self.default_host = self.host.plugins["MISC-ACCOUNT"].account_domain_new_get()
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
63 def contacts_get(self, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
69 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
70 ret = [contact.full() for contact in client.roster.get_jids()]
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
74 def get_groups(self, new_groups=None, profile=C.PROF_KEY_NONE):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
81 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
82 ret = client.roster.get_groups()
987
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
87 def get_groups_of_contact(self, user_jid_s, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
94 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
95 return client.roster.get_item(jid.JID(user_jid_s)).groups
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff changeset
96
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 def get_groups_of_all_contacts(self, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
105 client = self.host.get_client(profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
106 return {item.jid.userhost(): item.groups for item in client.roster.get_items()}
987
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125 def get_dialog_xmlui(self, options, data, profile):
987
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(
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
144 xml_tools.form_escape("contact_jid"), "@%s" % self.default_host
2624
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:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
148 contacts = self.contacts_get(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])
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
150 elts = self._data2elts(self.get_groups_of_all_contacts(profile))
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
151 list_.set_internal_callback(
2624
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:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
163 selected_groups = self.get_groups_of_contact(contacts[0], profile)
987
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
166 groups = self.get_groups(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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
171 adv_list = form_ui.change_container("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"))
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
175 button.set_internal_callback("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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
181 def _get_add_dialog_xmlui(self, data, profile):
987
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 }
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
193 return self.get_dialog_xmlui(options, {}, profile)
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff changeset
194
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
195 def _get_update_dialog_xmlui(self, data, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
202 if not self.contacts_get(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 }
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
212 return self.get_dialog_xmlui(options, {}, profile)
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff changeset
213
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
214 def _get_remove_dialog_xmlui(self, data, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
221 if not self.contacts_get(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 )
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
231 form_ui.addList("contact_jid", options=self.contacts_get(profile))
2624
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
234 def _get_confirm_remove_xmlui(self, data, profile):
987
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 {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
243 contact = data[xml_tools.form_escape("contact_jid")]
2624
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")):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
247 self._delete_contact(jid.JID(contact), profile)
2071
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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
250 delete_id = self.host.register_callback(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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
257 def _add_contact(self, data, profile):
987
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 {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
266 contact_jid_s = data[xml_tools.form_escape("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):
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
270 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.on_form_submitted)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
271 data["selected_groups"] = data[xml_tools.form_escape("groups_list")].split(
2624
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 }
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
280 return self.get_dialog_xmlui(options, data, profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
281 self.host.contact_add(contact_jid, profile_key=profile)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
282 return self._update_contact(data, profile) # after adding, updating
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff changeset
283
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
284 def _update_contact(self, data, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
291 client = self.host.get_client(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 {}
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
294 contact_jid = jid.JID(data[xml_tools.form_escape("contact_jid")])
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
295 # TODO: replace '\t' by a constant (see tools.xmlui.XMLUI.on_form_submitted)
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
296 groups = data[xml_tools.form_escape("groups_list")].split("\t")
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
297 self.host.contact_update(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
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
300 def _delete_contact(self, contact_jid, profile):
987
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 """
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
307 self.host.contact_del(contact_jid, profile_key=profile)
987
3a96920c07b7 core, frontends: unify the roster management UIs in sat/stdui/ui_contact_list.py
souliane <souliane@mailoo.org>
parents:
diff changeset
308 return {}