InfoBarTunerState 1.1.6: Added SecondInfobar Handling
[enigma2-plugins.git] / infobartunerstate / src / plugin.py
1 #######################################################################
2 #
3 #    InfoBar Tuner State for Enigma-2
4 #    Coded by betonme (c) 2011 <glaserfrank(at)gmail.com>
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=162629
6 #
7 #    This program is free software; you can redistribute it and/or
8 #    modify it under the terms of the GNU General Public License
9 #    as published by the Free Software Foundation; either version 2
10 #    of the License, or (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 General Public License for more details.
16 #
17 #######################################################################
18
19 # for localized messages
20 from . import _
21
22 # Config
23 from Components.config import *
24
25 # Plugin
26 from Plugins.Plugin import PluginDescriptor
27
28 # MessageBox
29 from Screens.MessageBox import MessageBox
30
31 # Plugin internal
32 from IBTSConfiguration import InfoBarTunerStateConfiguration
33 from InfoBarTunerState import InfoBarTunerState, TunerStateInfo
34
35
36 # Contants
37 NAME = _("InfoBarTunerState")
38 IBTSSHOW = _("Show InfoBarTunerState")
39 IBTSSETUP = _("InfoBarTunerState Setup")
40 VERSION = "1.1.6"
41 SUPPORT = "http://bit.ly/ibtsihad"
42 DONATE = "http://bit.ly/ibtspaypal"
43 ABOUT = "\n  " + NAME + " " + VERSION + "\n\n" \
44                                 + _("  (C) 2012 by betonme @ IHAD \n\n") \
45                                 + _("  If You like this plugin and want to support it,\n") \
46                                 + _("  or if just want to say ''thanks'',\n") \
47                                 + _("  feel free to donate via PayPal. \n\n") \
48                                 + _("  Thanks a lot ! \n  PayPal: ") + DONATE + "\n" \
49                                 + _("  SUPPORT: ") + SUPPORT
50
51 # Globals
52 gInfoBarTunerState = None
53
54
55 # Config choices
56 field_choices = [       
57                                                                         ("TypeIcon",                                                            _("Type (Icon)")),
58                                                                         ("TypeText",                                                            _("Type (Text)")),
59                                                                         ("Tuner",                                                                               _("Tuner")),
60                                                                         ("TunerType",                                                           _("Tuner Type")),
61                                                                         ("Number",                                                                      _("Channel Number")),
62                                                                         ("Channel",                                                                     _("Channel Name")),
63                                                                         ("Name",                                                                                _("Name")),
64                                                                         ("TimeLeftDuration",                            _("Time Left / Duration")),
65                                                                         ("TimeLeft",                                                            _("Time Left")),
66                                                                         ("TimeElapsed",                                                 _("Time Elapsed")),
67                                                                         ("Begin",                                                                               _("Begin")),
68                                                                         ("End",                                                                                 _("End")),
69                                                                         ("Duration",                                                            _("Duration")),
70                                                                         ("TimerProgressGraphical",      _("Timer Progress (Graphical)")),  #TODO howto do for file streams
71                                                                         ("TimerProgressText",                           _("Timer Progress (Text)")),  #TODO howto do for file streams
72                                                                         ("TimerDestination",                            _("Destination")),              #TODO howto do for file streams
73                                                                         ("StreamClient",                                                _("Stream Client")),
74                                                                         ("StreamClientPort",                            _("Stream Client with Port")),
75                                                                         ("DestinationStreamClient",     _("Destination / Client")),
76                                                                         #Throughput
77                                                                         #Overall transfer
78                                                                         ("FileSize",                                                            _("File Size")),
79                                                                         ("FreeSpace",                                                           _("Free Space")),
80                                                                         ("None",                                                                                _("None")),
81                                                                 ]
82
83 date_choices = [        
84                                                                         ("%H:%M",                                                       _("HH:MM")),
85                                                                         ("%d.%m %H:%M",                         _("DD.MM HH:MM")),
86                                                                         ("%d.%m. %H:%M",                        _("DD.MM. HH:MM")),
87                                                                         ("%m/%d %H:%M",                         _("MM/DD HH:MM")),
88                                                                         ("%d.%m.%Y %H:%M",              _("DD.MM.YYYY HH:MM")),
89                                                                         ("%Y/%m/%d %H:%M",              _("YYYY/MM/DD HH:MM")),
90                                                                         ("%H:%M %d.%m",                         _("HH:MM DD.MM")),
91                                                                         ("%H:%M %m/%d",                         _("HH:MM MM/DD")),
92                                                                         ("%H:%M %d.%m.%Y",              _("HH:MM DD.MM.YYYY")),
93                                                                         ("%H:%M %Y/%m/%d",              _("HH:MM YYYY/MM/DD")),
94                                                                         ("%a %d.%m. %H:%M",             _("WD DD.MM. HH:MM")),
95                                                                         ("%a, %d.%m. %H:%M",    _("WD, DD.MM. HH:MM")),
96                                                                         ("-    %H:%M",                          _("-    HH:MM")),
97                                                                 ]
98
99 #TODO New Config Show on timer prepare Event
100 event_choices = [       
101                                                                         ("prepare",                                             _("Prepare record")),
102                                                                         ("start",                                                       _("Start record")),
103                                                                         ("end",                                                         _("End record")),
104                                                                         ("startend",                                    _("Start / End record")),
105                                                                         ("preparestartend",             _("Prepare / Start / End record")),
106                                                                 ]
107 #config.infobartunerstate.show_on_events            = ConfigSelection(default = "%H:%M", choices = event_choices)
108
109 # Config options
110 config.infobartunerstate                           = ConfigSubsection()
111
112 config.infobartunerstate.about                     = ConfigNothing()
113 config.infobartunerstate.enabled                   = ConfigEnableDisable(default = True)
114 config.infobartunerstate.extensions_menu_show      = ConfigYesNo(default = True)
115 config.infobartunerstate.extensions_menu_setup     = ConfigYesNo(default = False)
116 #config.infobartunerstate.popup_time               = ConfigSelectionNumber(0, 10, 1, default = 5)
117
118 config.infobartunerstate.show_infobar              = ConfigYesNo(default = True)
119 config.infobartunerstate.show_events               = ConfigYesNo(default = True)                #TODO Show on start, end, start/end
120 config.infobartunerstate.show_streams              = ConfigYesNo(default = True)
121 config.infobartunerstate.show_ontoggle             = ConfigYesNo(default = False)
122 config.infobartunerstate.show_overwrite            = ConfigYesNo(default = False)               # Show with MoviePlayer only is actually not possible
123
124 config.infobartunerstate.time_format_begin         = ConfigSelection(default = "%H:%M", choices = date_choices)
125 config.infobartunerstate.time_format_end           = ConfigSelection(default = "%H:%M", choices = date_choices)
126 config.infobartunerstate.number_pending_records    = ConfigSelectionNumber(0, 10, 1, default = 1)
127 config.infobartunerstate.pending_hours             = ConfigSelectionNumber(0, 1000, 1, default = 0)
128 config.infobartunerstate.number_finished_records   = ConfigSelectionNumber(0, 10, 1, default = 5)
129 config.infobartunerstate.timeout_finished_records  = ConfigSelectionNumber(0, 600, 10, default = 60)
130
131 config.infobartunerstate.fields                    = ConfigSubsection()
132 config.infobartunerstate.fields.a                  = ConfigSelection(default = "TypeIcon", choices = field_choices)
133 config.infobartunerstate.fields.b                  = ConfigSelection(default = "Tuner", choices = field_choices)
134 config.infobartunerstate.fields.c                  = ConfigSelection(default = "Number", choices = field_choices)
135 config.infobartunerstate.fields.d                  = ConfigSelection(default = "Channel", choices = field_choices)
136 config.infobartunerstate.fields.e                  = ConfigSelection(default = "Name", choices = field_choices)
137 config.infobartunerstate.fields.f                  = ConfigSelection(default = "TimerProgressGraphical", choices = field_choices)
138 config.infobartunerstate.fields.g                  = ConfigSelection(default = "TimeLeftDuration", choices = field_choices)
139 config.infobartunerstate.fields.h                  = ConfigSelection(default = "StreamClient", choices = field_choices)
140 config.infobartunerstate.fields.i                  = ConfigSelection(default = "None", choices = field_choices)
141 config.infobartunerstate.fields.j                  = ConfigSelection(default = "None", choices = field_choices)
142
143 config.infobartunerstate.fieldswidth               = ConfigSubsection()
144 config.infobartunerstate.fieldswidth.a             = ConfigSelectionNumber(0, 1000, 1, default = 0)
145 config.infobartunerstate.fieldswidth.b             = ConfigSelectionNumber(0, 1000, 1, default = 0)
146 config.infobartunerstate.fieldswidth.c             = ConfigSelectionNumber(0, 1000, 1, default = 0)
147 config.infobartunerstate.fieldswidth.d             = ConfigSelectionNumber(0, 1000, 1, default = 0)
148 config.infobartunerstate.fieldswidth.e             = ConfigSelectionNumber(0, 1000, 1, default = 0)
149 config.infobartunerstate.fieldswidth.f             = ConfigSelectionNumber(0, 1000, 1, default = 0)
150 config.infobartunerstate.fieldswidth.g             = ConfigSelectionNumber(0, 1000, 1, default = 0)
151 config.infobartunerstate.fieldswidth.h             = ConfigSelectionNumber(0, 1000, 1, default = 0)
152 config.infobartunerstate.fieldswidth.i             = ConfigSelectionNumber(0, 1000, 1, default = 0)
153 config.infobartunerstate.fieldswidth.j             = ConfigSelectionNumber(0, 1000, 1, default = 0)
154
155 config.infobartunerstate.offset_horizontal         = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
156 config.infobartunerstate.offset_vertical           = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
157 config.infobartunerstate.offset_padding            = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
158 config.infobartunerstate.offset_spacing            = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
159 config.infobartunerstate.offset_rightside          = ConfigSelectionNumber(-1000, 1000, 1, default = 0)
160 config.infobartunerstate.placeholder_pogressbar    = ConfigYesNo(default = True)
161 config.infobartunerstate.variable_field_width      = ConfigYesNo(default = True)
162 #MAYBE provide different sorting types / options
163 config.infobartunerstate.list_goesup               = ConfigYesNo(default = False)
164 config.infobartunerstate.infobar_timeout           = ConfigSelectionNumber(0, 100, 1, default = 0)
165
166 config.infobartunerstate.background_transparency   = ConfigYesNo(default = False)
167
168
169 #######################################################
170 # Plugin main function
171 def Plugins(**kwargs):
172         descriptors = []
173         
174         if config.infobartunerstate.enabled.value:
175                 # SessionStart
176                 descriptors.append( PluginDescriptor(where = PluginDescriptor.WHERE_SESSIONSTART, fnc = start, needsRestart = False) )
177                 if config.infobartunerstate.extensions_menu_show.value:
178                         descriptors.append( PluginDescriptor(name = IBTSSHOW, description = IBTSSHOW, where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = show, needsRestart = False) )
179                 if config.infobartunerstate.extensions_menu_setup.value:
180                         descriptors.append( PluginDescriptor(name = IBTSSETUP, description = IBTSSETUP, where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc = setup, needsRestart = False) )
181         
182         descriptors.append( PluginDescriptor(name = NAME, description = NAME + " " +_("configuration"), where = PluginDescriptor.WHERE_PLUGINMENU, fnc = setup, needsRestart = False, icon = "plugin.png") )
183
184         return descriptors
185
186
187 #######################################################
188 # Plugin # Plugin configuration
189 def setup(session, **kwargs):
190         print "InfoBarTunerState setup"
191         #TODO config
192         # Overwrite Skin Position
193         # Show Live TV Tuners PiP LiveStream FileStream
194         # alltime permanent display, needs an dynamic update service
195         # Always display at least Nothing running
196         # show free tuner with dvb-type
197         # Used disk size
198         # Event popup timeout
199         # Feldbreitenbegrenzung fuer Namen ...
200         # Streaming amount of data
201         # Display next x timers also if deactivated
202         try:
203                 session.open(InfoBarTunerStateConfiguration)
204         except Exception, e:
205                 print "InfoBarTunerStateMenu exception " + str(e)
206
207
208 #######################################################
209 # Sessionstart
210 def start(reason, **kwargs):
211         print "InfoBarTunerState start"
212         if reason == 0: # start
213                 if kwargs.has_key("session"):
214                         if config.infobartunerstate.enabled.value:
215                                 global gInfoBarTunerState
216                                 session = kwargs["session"]
217                                 try:
218                                         gInfoBarTunerState = InfoBarTunerState(session)
219                                 except Exception, e:
220                                         print "InfoBarTunerState start exception " + str(e)
221         # Do not cleanup on session shutdown, it will break the movie player integration
222
223
224 #######################################################
225 # Extension Menu
226 def show(session, **kwargs):
227         print "InfoBarTunerState show"
228         if gInfoBarTunerState:
229                 try:
230                         gInfoBarTunerState.show(True, forceshow=True)
231                 except Exception, e:
232                         print "InfoBarTunerState show exception " + str(e)
233         else:
234                 # No InfoBarTunerState Instance running
235                 print "InfoBarTunerState disabled"
236                 session.open(MessageBox, _("InfoBarTunerState is disabled"), MessageBox.TYPE_INFO, 3)
237