replaced deprecated ConfigEnableDisable by ConfigOnOff
[enigma2-plugins.git] / pushservice / src / plugin.py
1 #######################################################################\r
2 #\r
3 #    Push Service for Enigma-2\r
4 #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>\r
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=167779\r
6 #\r
7 #    This program is free software; you can redistribute it and/or\r
8 #    modify it under the terms of the GNU General Public License\r
9 #    as published by the Free Software Foundation; either version 2\r
10 #    of the License, or (at your option) any later version.\r
11 #\r
12 #    This program is distributed in the hope that it will be useful,\r
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 #    GNU General Public License for more details.\r
16 #\r
17 #######################################################################\r
18 \r
19 import os, sys, traceback\r
20 \r
21 # Plugin\r
22 from Plugins.Plugin import PluginDescriptor\r
23 \r
24 # Config\r
25 from Components.config import config, ConfigSubsection, ConfigNothing, ConfigOnOff, ConfigText, ConfigClock, ConfigSelectionNumber\r
26 \r
27 # Default encoding\r
28 #from Components.Language import language\r
29 \r
30 # Plugin internal\r
31 from __init__ import _\r
32 from PushService import PushService\r
33 #from ConfigScreen import ConfigScreen\r
34 \r
35 \r
36 # Constants\r
37 NAME = "PushService"\r
38 VERSION = "0.4.0"\r
39 SUPPORT = "http://bit.ly/psihad"\r
40 DONATE = "http://bit.ly/pspaypal"\r
41 ABOUT = "\n  " + NAME + " " + VERSION + "\n\n" \\r
42                                 + _("  (C) 2012 by betonme @ IHAD \n\n") \\r
43                                 + _("  If You like this plugin and want to support it,\n") \\r
44                                 + _("  or if just want to say ''thanks'',\n") \\r
45                                 + _("  feel free to donate via PayPal. \n\n") \\r
46                                 + _("  Thanks a lot ! \n  PayPal: ") + DONATE + "\n" \\r
47                                 + _("  Support: ") + SUPPORT\r
48 \r
49 \r
50 # Globals\r
51 gPushService = None\r
52 \r
53 \r
54 # Config options\r
55 config.pushservice                           = ConfigSubsection()\r
56 \r
57 config.pushservice.about                     = ConfigNothing()\r
58 \r
59 config.pushservice.enable                    = ConfigOnOff(default = True)\r
60 \r
61 config.pushservice.boxname                   = ConfigText(default = "Enigma2", fixed_size = False)\r
62 config.pushservice.xmlpath                   = ConfigText(default = "/etc/enigma2/pushservice.xml", fixed_size = False)\r
63 \r
64 config.pushservice.time                      = ConfigClock(default = 0)\r
65 config.pushservice.period                    = ConfigSelectionNumber(0, 1000, 1, default = 24)\r
66 config.pushservice.runonboot                 = ConfigOnOff(default = True)\r
67 config.pushservice.bootdelay                 = ConfigSelectionNumber(5, 1000, 5, default = 10)\r
68 \r
69 config.pushservice.push_errors               = ConfigOnOff(default = False)\r
70 \r
71 \r
72 #######################################################\r
73 # Plugin configuration\r
74 def setup(session, **kwargs):\r
75         try:\r
76                 ### For testing only\r
77                 import ConfigScreen\r
78                 reload(ConfigScreen)\r
79                 ###\r
80                 session.open(ConfigScreen.ConfigScreen)\r
81         except Exception, e:\r
82                 print _("PushService setup exception ") + str(e)\r
83                 exc_type, exc_value, exc_traceback = sys.exc_info()\r
84                 traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)\r
85 \r
86 \r
87 #######################################################\r
88 # Autostart\r
89 def autostart(reason, **kwargs):\r
90         if reason == 0:  # start\r
91                 if config.pushservice.enable.value:\r
92                         try:\r
93                                 global gPushService\r
94                                 gPushService = PushService()\r
95                                 gPushService.start()\r
96                         except Exception, e:\r
97                                 print _("PushService autostart exception ") + str(e)\r
98                                 exc_type, exc_value, exc_traceback = sys.exc_info()\r
99                                 traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)\r
100 \r
101 \r
102 #######################################################\r
103 # Plugin main function\r
104 def Plugins(**kwargs):\r
105         \r
106         descriptors = []\r
107         \r
108         if config.pushservice.enable.value:\r
109                 # AutoStart\r
110                 descriptors.append( PluginDescriptor(where = PluginDescriptor.WHERE_AUTOSTART, fnc = autostart, needsRestart = False) )\r
111                 \r
112         #TODO icon\r
113         descriptors.append( PluginDescriptor(name = NAME, description = NAME + " " +_("configuration"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = setup, needsRestart = False) ) #icon = "/icon.png"\r
114 \r
115         return descriptors\r