annotate src/plugins/plugin_misc_welcome.py @ 1701:23560a1cd397

plugin welcome: first draft this plugin display a welcome message on first connection (or if General/Welcome param is set to True), and have a trigger point if other plugins want to do action on first connection (like adding entities to roster).
author Goffi <goffi@goffi.org>
date Sun, 29 Nov 2015 22:57:11 +0100
parents
children 280890460822
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1701
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
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
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org)
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
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 log = getLogger(__name__)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.tools import xml_tools
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25
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 PLUGIN_INFO = {
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 "name": "Welcome",
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 "import_name": "WELCOME",
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 "type": C.PLUG_TYPE_MISC,
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 "main": "Welcome",
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 "handler": "no",
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 "description": _("""Plugin which manage welcome message and things to to on first connection.""")
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 }
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 WELCOME_PARAM_CATEGORY = "General"
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 WELCOME_PARAM_NAME = "welcome"
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 WELCOME_PARAM_LABEL = D_(u"Display welcome message")
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40 WELCOME_MSG_TITLE = D_(u"Welcome to Libervia/Salut à Toi")
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 # XXX: this message is mainly targetting libervia new users for now
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 # (i.e.: it may look weird on other frontends)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43 WELCOME_MSG = D_(u"""Welcome to a free (as in freedom) network!
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 The use Libervia, you'll need to add contacts, either people you know, or people you discover by using the “Service/Search directory” menu.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 We hope that you'll enjoy using this project.
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 The Libervia/Salut à Toi Team
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
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 PARAMS = """
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 <params>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 <individual>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 <category name="{category}">
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 <param name="{name}" label="{label}" type="bool" />
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 </category>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 </individual>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 </params>
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 """.format(category=WELCOME_PARAM_CATEGORY, name=WELCOME_PARAM_NAME, label=WELCOME_PARAM_LABEL)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 class Welcome(object):
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def __init__(self, host):
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 log.info(_("plugin Welcome initialization"))
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.host = host
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 host.memory.updateParams(PARAMS)
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 def profileConnected(self, profile):
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 # 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
75 # the welcome value from your profile params in sat.db
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 welcome = self.host.memory.params.getParamA(WELCOME_PARAM_NAME, WELCOME_PARAM_CATEGORY, use_default=False, profile_key=profile)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 if welcome is None:
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 first_start = True
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79 welcome = True
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80 else:
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 first_start = False
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 if welcome:
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 xmlui = xml_tools.note(WELCOME_MSG, WELCOME_MSG_TITLE)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.host.actionNew({'xmlui': xmlui.toXml()}, profile=profile)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 self.host.memory.setParam(WELCOME_PARAM_NAME, C.BOOL_FALSE, WELCOME_PARAM_CATEGORY, profile_key=profile)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.host.trigger.point("WELCOME", first_start, welcome, profile)
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
89
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
90
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92
23560a1cd397 plugin welcome: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93