Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_misc_welcome.py @ 4071:4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 02 Jun 2023 11:49:51 +0200 |
parents | sat/plugins/plugin_misc_welcome.py@524856bd7b19 |
children |
comparison
equal
deleted
inserted
replaced
4070:d10748475025 | 4071:4b842c1fb686 |
---|---|
1 #!/usr/bin/env python3 | |
2 | |
3 | |
4 # SAT plugin for file tansfer | |
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 from libervia.backend.core.i18n import _, D_ | |
21 from libervia.backend.core.constants import Const as C | |
22 from libervia.backend.core.log import getLogger | |
23 | |
24 log = getLogger(__name__) | |
25 from libervia.backend.tools import xml_tools | |
26 | |
27 | |
28 PLUGIN_INFO = { | |
29 C.PI_NAME: "Welcome", | |
30 C.PI_IMPORT_NAME: "WELCOME", | |
31 C.PI_TYPE: C.PLUG_TYPE_MISC, | |
32 C.PI_MAIN: "Welcome", | |
33 C.PI_HANDLER: "no", | |
34 C.PI_DESCRIPTION: _( | |
35 """Plugin which manage welcome message and things to to on first connection.""" | |
36 ), | |
37 } | |
38 | |
39 | |
40 WELCOME_PARAM_CATEGORY = "General" | |
41 WELCOME_PARAM_NAME = "welcome" | |
42 WELCOME_PARAM_LABEL = D_("Display welcome message") | |
43 WELCOME_MSG_TITLE = D_("Welcome to Libervia/Salut à Toi") | |
44 # XXX: this message is mainly targetting libervia new users for now | |
45 # (i.e.: it may look weird on other frontends) | |
46 WELCOME_MSG = D_( | |
47 """Welcome to a free (as in freedom) network! | |
48 | |
49 If you have any trouble, or you want to help us for the bug hunting, you can contact us in real time chat by using the “Help / Official chat room” menu. | |
50 | |
51 To use Libervia, you'll need to add contacts, either people you know, or people you discover by using the “Contacts / Search directory” menu. | |
52 | |
53 We hope that you'll enjoy using this project. | |
54 | |
55 The Libervia/Salut à Toi Team | |
56 """ | |
57 ) | |
58 | |
59 | |
60 PARAMS = """ | |
61 <params> | |
62 <individual> | |
63 <category name="{category}"> | |
64 <param name="{name}" label="{label}" type="bool" /> | |
65 </category> | |
66 </individual> | |
67 </params> | |
68 """.format( | |
69 category=WELCOME_PARAM_CATEGORY, name=WELCOME_PARAM_NAME, label=WELCOME_PARAM_LABEL | |
70 ) | |
71 | |
72 | |
73 class Welcome(object): | |
74 def __init__(self, host): | |
75 log.info(_("plugin Welcome initialization")) | |
76 self.host = host | |
77 host.memory.update_params(PARAMS) | |
78 | |
79 def profile_connected(self, client): | |
80 # XXX: if you wan to try first_start again, you'll have to remove manually | |
81 # the welcome value from your profile params in sat.db | |
82 welcome = self.host.memory.params.param_get_a( | |
83 WELCOME_PARAM_NAME, | |
84 WELCOME_PARAM_CATEGORY, | |
85 use_default=False, | |
86 profile_key=client.profile, | |
87 ) | |
88 if welcome is None: | |
89 first_start = True | |
90 welcome = True | |
91 else: | |
92 first_start = False | |
93 | |
94 if welcome: | |
95 xmlui = xml_tools.note(WELCOME_MSG, WELCOME_MSG_TITLE) | |
96 self.host.action_new({"xmlui": xmlui.toXml()}, profile=client.profile) | |
97 self.host.memory.param_set( | |
98 WELCOME_PARAM_NAME, | |
99 C.BOOL_FALSE, | |
100 WELCOME_PARAM_CATEGORY, | |
101 profile_key=client.profile, | |
102 ) | |
103 | |
104 self.host.trigger.point("WELCOME", first_start, welcome, client.profile) |