annotate sat/plugins/plugin_misc_welcome.py @ 3042:964abd07dc03

bridge (dbus): AsyncIO version of D-Bus bridge: The frontends D-Bus bridge has now an AIOBridge version which can be instantiated to use asyncio (the loop must be managed by frontends).
author Goffi <goffi@goffi.org>
date Tue, 01 Oct 2019 22:49:10 +0200
parents ab2696e34d29
children 9d0df638c8b4
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
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin for file tansfer
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from sat.core.i18n import _, D_
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core.constants import Const as C
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 log = getLogger(__name__)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.tools import xml_tools
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
29 C.PI_NAME: "Welcome",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
30 C.PI_IMPORT_NAME: "WELCOME",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
31 C.PI_TYPE: C.PLUG_TYPE_MISC,
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
32 C.PI_MAIN: "Welcome",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
33 C.PI_HANDLER: "no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
34 C.PI_DESCRIPTION: _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 """Plugin which manage welcome message and things to to on first connection."""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
36 ),
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 }
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 WELCOME_PARAM_CATEGORY = "General"
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 WELCOME_PARAM_NAME = "welcome"
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
42 WELCOME_PARAM_LABEL = D_("Display welcome message")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
43 WELCOME_MSG_TITLE = D_("Welcome to Libervia/Salut à Toi")
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 # XXX: this message is mainly targetting libervia new users for now
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 # (i.e.: it may look weird on other frontends)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 WELCOME_MSG = D_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
47 """Welcome to a free (as in freedom) network!
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
1707
94c450972346 primitivus and plugins: renamed a few menus:
souliane <souliane@mailoo.org>
parents: 1703
diff changeset
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.
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
1707
94c450972346 primitivus and plugins: renamed a few menus:
souliane <souliane@mailoo.org>
parents: 1703
diff changeset
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.
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 We hope that you'll enjoy using this project.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 The Libervia/Salut à Toi Team
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 """
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 )
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 PARAMS = """
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 <params>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 <individual>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 <category name="{category}">
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 <param name="{name}" label="{label}" type="bool" />
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 </category>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 </individual>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 </params>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 """.format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 category=WELCOME_PARAM_CATEGORY, name=WELCOME_PARAM_NAME, label=WELCOME_PARAM_LABEL
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 )
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 class Welcome(object):
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 def __init__(self, host):
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 log.info(_("plugin Welcome initialization"))
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 self.host = host
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 host.memory.updateParams(PARAMS)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
79 def profileConnected(self, client):
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 # XXX: if you wan to try first_start again, you'll have to remove manually
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 # the welcome value from your profile params in sat.db
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
82 welcome = self.host.memory.params.getParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 WELCOME_PARAM_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 WELCOME_PARAM_CATEGORY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 use_default=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 profile_key=client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 )
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 if welcome is None:
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89 first_start = True
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90 welcome = True
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91 else:
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 first_start = False
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 if welcome:
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 xmlui = xml_tools.note(WELCOME_MSG, WELCOME_MSG_TITLE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 self.host.actionNew({"xmlui": xmlui.toXml()}, profile=client.profile)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 self.host.memory.setParam(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 WELCOME_PARAM_NAME,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 C.BOOL_FALSE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 WELCOME_PARAM_CATEGORY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 profile_key=client.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 )
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
104 self.host.trigger.point("WELCOME", first_start, welcome, client.profile)