comparison sat/plugins/plugin_misc_welcome.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _, D_ 20 from sat.core.i18n import _, D_
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core.log import getLogger 22 from sat.core.log import getLogger
23
23 log = getLogger(__name__) 24 log = getLogger(__name__)
24 from sat.tools import xml_tools 25 from sat.tools import xml_tools
25 26
26 27
27 PLUGIN_INFO = { 28 PLUGIN_INFO = {
28 C.PI_NAME: "Welcome", 29 C.PI_NAME: "Welcome",
29 C.PI_IMPORT_NAME: "WELCOME", 30 C.PI_IMPORT_NAME: "WELCOME",
30 C.PI_TYPE: C.PLUG_TYPE_MISC, 31 C.PI_TYPE: C.PLUG_TYPE_MISC,
31 C.PI_MAIN: "Welcome", 32 C.PI_MAIN: "Welcome",
32 C.PI_HANDLER: "no", 33 C.PI_HANDLER: "no",
33 C.PI_DESCRIPTION: _("""Plugin which manage welcome message and things to to on first connection.""") 34 C.PI_DESCRIPTION: _(
35 """Plugin which manage welcome message and things to to on first connection."""
36 ),
34 } 37 }
35 38
36 39
37 WELCOME_PARAM_CATEGORY = "General" 40 WELCOME_PARAM_CATEGORY = "General"
38 WELCOME_PARAM_NAME = "welcome" 41 WELCOME_PARAM_NAME = "welcome"
39 WELCOME_PARAM_LABEL = D_(u"Display welcome message") 42 WELCOME_PARAM_LABEL = D_(u"Display welcome message")
40 WELCOME_MSG_TITLE = D_(u"Welcome to Libervia/Salut à Toi") 43 WELCOME_MSG_TITLE = D_(u"Welcome to Libervia/Salut à Toi")
41 # XXX: this message is mainly targetting libervia new users for now 44 # XXX: this message is mainly targetting libervia new users for now
42 # (i.e.: it may look weird on other frontends) 45 # (i.e.: it may look weird on other frontends)
43 WELCOME_MSG = D_(u"""Welcome to a free (as in freedom) network! 46 WELCOME_MSG = D_(
47 u"""Welcome to a free (as in freedom) network!
44 48
45 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. 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.
46 50
47 To use Libervia, you'll need to add contacts, either people you know, or people you discover by using the “Contacts / Search directory” menu. 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.
48 52
49 We hope that you'll enjoy using this project. 53 We hope that you'll enjoy using this project.
50 54
51 The Libervia/Salut à Toi Team 55 The Libervia/Salut à Toi Team
52 """) 56 """
57 )
53 58
54 59
55 PARAMS = """ 60 PARAMS = """
56 <params> 61 <params>
57 <individual> 62 <individual>
58 <category name="{category}"> 63 <category name="{category}">
59 <param name="{name}" label="{label}" type="bool" /> 64 <param name="{name}" label="{label}" type="bool" />
60 </category> 65 </category>
61 </individual> 66 </individual>
62 </params> 67 </params>
63 """.format(category=WELCOME_PARAM_CATEGORY, name=WELCOME_PARAM_NAME, label=WELCOME_PARAM_LABEL) 68 """.format(
69 category=WELCOME_PARAM_CATEGORY, name=WELCOME_PARAM_NAME, label=WELCOME_PARAM_LABEL
70 )
64 71
65 72
66 class Welcome(object): 73 class Welcome(object):
67
68 def __init__(self, host): 74 def __init__(self, host):
69 log.info(_("plugin Welcome initialization")) 75 log.info(_("plugin Welcome initialization"))
70 self.host = host 76 self.host = host
71 host.memory.updateParams(PARAMS) 77 host.memory.updateParams(PARAMS)
72 78
73 def profileConnected(self, client): 79 def profileConnected(self, client):
74 # XXX: if you wan to try first_start again, you'll have to remove manually 80 # XXX: if you wan to try first_start again, you'll have to remove manually
75 # the welcome value from your profile params in sat.db 81 # the welcome value from your profile params in sat.db
76 welcome = self.host.memory.params.getParamA(WELCOME_PARAM_NAME, WELCOME_PARAM_CATEGORY, use_default=False, profile_key=client.profile) 82 welcome = self.host.memory.params.getParamA(
83 WELCOME_PARAM_NAME,
84 WELCOME_PARAM_CATEGORY,
85 use_default=False,
86 profile_key=client.profile,
87 )
77 if welcome is None: 88 if welcome is None:
78 first_start = True 89 first_start = True
79 welcome = True 90 welcome = True
80 else: 91 else:
81 first_start = False 92 first_start = False
82 93
83 if welcome: 94 if welcome:
84 xmlui = xml_tools.note(WELCOME_MSG, WELCOME_MSG_TITLE) 95 xmlui = xml_tools.note(WELCOME_MSG, WELCOME_MSG_TITLE)
85 self.host.actionNew({'xmlui': xmlui.toXml()}, profile=client.profile) 96 self.host.actionNew({"xmlui": xmlui.toXml()}, profile=client.profile)
86 self.host.memory.setParam(WELCOME_PARAM_NAME, C.BOOL_FALSE, WELCOME_PARAM_CATEGORY, profile_key=client.profile) 97 self.host.memory.setParam(
98 WELCOME_PARAM_NAME,
99 C.BOOL_FALSE,
100 WELCOME_PARAM_CATEGORY,
101 profile_key=client.profile,
102 )
87 103
88 self.host.trigger.point("WELCOME", first_start, welcome, client.profile) 104 self.host.trigger.point("WELCOME", first_start, welcome, client.profile)
89
90
91
92
93