SeriesPlugin 1.2.8: Fixed multiple timer / movie handling
[enigma2-plugins.git] / seriesplugin / src / SeriesPluginConfiguration.py
1 #######################################################################
2 #
3 #    Series Plugin for Enigma-2
4 #    Coded by betonme (c) 2012 <glaserfrank(at)gmail.com>
5 #    Support: http://www.i-have-a-dreambox.com/wbb2/thread.php?threadid=TBD
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 import os
20
21 # for localized messages
22 from . import _
23
24 # Config
25 from Components.config import *
26 from Components.ConfigList import ConfigListScreen
27 from Components.Sources.StaticText import StaticText
28
29 from Components.ActionMap import ActionMap
30 from Screens.MessageBox import MessageBox
31 from Screens.Screen import Screen
32 from Screens.Setup import SetupSummary
33
34 from Plugins.Plugin import PluginDescriptor
35
36 # Plugin internal
37 from SeriesPlugin import resetInstance, getInstance
38 from SeriesPluginIndependent import startIndependent, stopIndependent
39 from EpisodePatterns import readPatternFile
40 from Logger import splog, Logger
41 from ShowLogScreen import ShowLogScreen
42
43
44 def checkList(cfg):
45         for choices in cfg.choices.choices:
46                 if cfg.value == choices[0]:
47                         return
48         for choices in cfg.choices.choices:
49                 if cfg.default == choices[0]:
50                         cfg.value = cfg.default
51                         return
52         cfg.value = cfg.choices.choices[0][0]
53
54
55 #######################################################
56 # Configuration screen
57 class SeriesPluginConfiguration(ConfigListScreen, Screen, Logger):
58         def __init__(self, session):
59                 Screen.__init__(self, session)
60                 self.skinName = [ "SeriesServiceConfiguration", "Setup" ]
61                 
62                 from plugin import NAME, VERSION
63                 self.setup_title = NAME + " " + _("Configuration") + " " + VERSION
64                 
65                 self.onChangedEntry = [ ]
66                 
67                 # Buttons
68                 self["key_red"] = StaticText(_("Cancel"))
69                 self["key_green"] = StaticText(_("OK"))
70                 self["key_blue"] = StaticText(_("Show Log"))
71                 
72                 # Define Actions
73                 self["actions"] = ActionMap(["SetupActions", "ChannelSelectBaseActions", "ColorActions"],
74                 {
75                         "cancel":               self.keyCancel,
76                         "save":                 self.keySave,
77                         "nextBouquet":  self.pageUp,
78                         "prevBouquet":  self.pageDown,
79                         "blue":                 self.blue,
80                         "ok":                   self.keyOK,
81                         "left":                 self.keyLeft,
82                         "right":                self.keyRight,
83                 }, -2) # higher priority
84                 
85                 stopIndependent()
86                 resetInstance()
87                 self.seriesPlugin = getInstance()
88                 
89                 # Create temporary identifier config elements
90                 identifiers = self.seriesPlugin.modules
91                 identifiers_elapsed = [k for k,v in identifiers.items() if v.knowsElapsed()]
92                 identifiers_today   = [k for k,v in identifiers.items() if v.knowsToday()]
93                 identifiers_future  = [k for k,v in identifiers.items() if v.knowsFuture()]
94                 self.cfg_identifier_elapsed = NoSave( ConfigSelection(choices = identifiers_elapsed, default = config.plugins.seriesplugin.identifier_elapsed.value or identifiers_elapsed[0]) )
95                 self.cfg_identifier_today   = NoSave( ConfigSelection(choices = identifiers_today,   default = config.plugins.seriesplugin.identifier_today.value   or identifiers_today[0]) )
96                 self.cfg_identifier_future  = NoSave( ConfigSelection(choices = identifiers_future,  default = config.plugins.seriesplugin.identifier_future.value  or identifiers_future[0]) )
97                 
98                 # Load patterns
99                 patterns = readPatternFile()
100                 self.cfg_pattern_title       = NoSave( ConfigSelection(choices = patterns, default = config.plugins.seriesplugin.pattern_title.value ) )
101                 self.cfg_pattern_description = NoSave( ConfigSelection(choices = patterns, default = config.plugins.seriesplugin.pattern_description.value ) )
102                 #self.cfg_pattern_record      = NoSave( ConfigSelection(choices = patterns, default = config.plugins.seriesplugin.pattern_record.value ) )
103                 
104                 checkList( self.cfg_pattern_title )
105                 checkList( self.cfg_pattern_description )               
106                 #checkList( self.cfg_pattern_record )
107                 
108                 # Initialize Configuration
109                 self.list = []
110                 self.buildConfig()
111                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
112                 
113                 self.changed()
114                 self.onLayoutFinish.append(self.layoutFinished)
115
116         def layoutFinished(self):
117                 self.setTitle(_(self.setup_title))
118
119         def buildConfig(self):
120                 #    _config list entry
121                 #    _                                                                                   , config element
122                 
123                 self.list.append( getConfigListEntry(  _("Enable SeriesPlugin")                          , config.plugins.seriesplugin.enabled ) )
124                 
125                 if config.plugins.seriesplugin.enabled.value:
126                         self.list.append( getConfigListEntry(  _("Show in info menu")                          , config.plugins.seriesplugin.menu_info ) )
127                         self.list.append( getConfigListEntry(  _("Show in extensions menu")                    , config.plugins.seriesplugin.menu_extensions ) )
128                         self.list.append( getConfigListEntry(  _("Show in epg menu")                           , config.plugins.seriesplugin.menu_epg ) )
129                         self.list.append( getConfigListEntry(  _("Show in channel menu")                       , config.plugins.seriesplugin.menu_channel ) )
130                         self.list.append( getConfigListEntry(  _("Show Info in movie list menu")               , config.plugins.seriesplugin.menu_movie_info ) )
131                         self.list.append( getConfigListEntry(  _("Show Rename in movie list menu")             , config.plugins.seriesplugin.menu_movie_rename ) )
132                         
133                         #if len( config.plugins.seriesplugin.identifier_elapsed.choices ) > 1:
134                         self.list.append( getConfigListEntry(  _("Select identifier for elapsed events")       , self.cfg_identifier_elapsed ) )
135                         #if len( config.plugins.seriesplugin.identifier_today.choices ) > 1:
136                         self.list.append( getConfigListEntry(  _("Select identifier for today events")         , self.cfg_identifier_today ) )
137                         #if len( config.plugins.seriesplugin.identifier_future.choices ) > 1:
138                         self.list.append( getConfigListEntry(  _("Select identifier for future events")        , self.cfg_identifier_future ) )
139                         
140                         #if len( config.plugins.seriesplugin.manager.choices ) > 1:
141 #                       self.list.append( getConfigListEntry(  _("Select manager service")                     , config.plugins.seriesplugin.manager ) )
142                         #if len( config.plugins.seriesplugin.guide.choices ) > 1:
143 #                       self.list.append( getConfigListEntry(  _("Select guide service")                       , config.plugins.seriesplugin.guide ) )
144                         
145                         self.list.append( getConfigListEntry(  _("Episode pattern file")                       , config.plugins.seriesplugin.pattern_file ) )
146                         self.list.append( getConfigListEntry(  _("Record title episode pattern")               , self.cfg_pattern_title ) )
147                         self.list.append( getConfigListEntry(  _("Record description episode pattern")         , self.cfg_pattern_description ) )
148                         #self.list.append( getConfigListEntry(  _("Record description episode pattern")         , self.cfg_pattern_record ) )
149                         
150                         self.list.append( getConfigListEntry(  _("Alternative channel names file")             , config.plugins.seriesplugin.channel_file ) )
151                         self.list.append( getConfigListEntry(  _("Ask for channel matching")                   , config.plugins.seriesplugin.channel_popups ) )
152                         
153                         self.list.append( getConfigListEntry(  _("Rename files")                               , config.plugins.seriesplugin.rename_file ) )
154                         if config.plugins.seriesplugin.rename_file.value:
155                                 self.list.append( getConfigListEntry(  _("Tidy up filename on Rename")             , config.plugins.seriesplugin.tidy_rename ) )
156                         self.list.append( getConfigListEntry(  _("Show warnings after Record renaming")        , config.plugins.seriesplugin.timer_popups ) )
157                         self.list.append( getConfigListEntry(  _("Show success after Record renaming")         , config.plugins.seriesplugin.timer_popups_success ) )
158                         
159                         self.list.append( getConfigListEntry(  _("Max time drift to match episode")            , config.plugins.seriesplugin.max_time_drift ) )
160                         self.list.append( getConfigListEntry(  _("Title search depths")                        , config.plugins.seriesplugin.search_depths ) )
161                         
162                         self.list.append( getConfigListEntry(  _("Skip search during records")                 , config.plugins.seriesplugin.skip_during_records ) )
163                         
164                         self.list.append( getConfigListEntry(  _("AutoTimer independent mode")                 , config.plugins.seriesplugin.autotimer_independent ) )
165                         if config.plugins.seriesplugin.autotimer_independent.value:
166                                 self.list.append( getConfigListEntry(  _("Check timer every x minutes")            , config.plugins.seriesplugin.independent_cycle ) )
167                                 self.list.append( getConfigListEntry(  _("Always retry to find series info")       , config.plugins.seriesplugin.independent_retry ) )
168                         
169                         self.list.append( getConfigListEntry(  _("Check timer list from extension menu")       , config.plugins.seriesplugin.check_timer_list ) )
170
171                         self.list.append( getConfigListEntry(  _("Show warnings after Timer handling")         , config.plugins.seriesplugin.timer_popups ) )
172                         self.list.append( getConfigListEntry(  _("Show success after Timer handling")          , config.plugins.seriesplugin.timer_popups_success ) )
173
174                         self.list.append( getConfigListEntry(  _("Use local caching")                          , config.plugins.seriesplugin.caching ) )
175                         
176                         self.list.append( getConfigListEntry(  _("Allow Google Analytics")                     , config.plugins.seriesplugin.ganalytics ) )
177                         
178                         self.list.append( getConfigListEntry(  _("E2: Composition of the recording filenames") , config.recording.filename_composition ) )
179                         
180                         try:
181                                 self.list.append( getConfigListEntry(  _("AT: Poll automatically")     , config.plugins.autotimer.autopoll ) )
182                                 self.list.append( getConfigListEntry(  _("AT: Startup delay (in min)") , config.plugins.autotimer.delay ) )
183                                 self.list.append( getConfigListEntry(  _("AT: Poll Interval (in h)")   , config.plugins.autotimer.interval ) )
184                                 self.list.append( getConfigListEntry(  _("AT: Timeout (in min)")       , config.plugins.autotimer.timeout ) )
185                         except:
186                                 pass
187                         
188                         self.list.append( getConfigListEntry(  _("Debug: Write Log")                           , config.plugins.seriesplugin.write_log ) )
189                         if config.plugins.seriesplugin.write_log.value:
190                                 self.list.append( getConfigListEntry(  _("Debug: Log file path")                   , config.plugins.seriesplugin.log_file ) )
191                                 self.list.append( getConfigListEntry(  _("Debug: Forum user name")                 , config.plugins.seriesplugin.log_reply_user ) )
192                                 self.list.append( getConfigListEntry(  _("Debug: User mail address")               , config.plugins.seriesplugin.log_reply_mail ) )
193                         
194                         try:
195                                 self.list.append( getConfigListEntry(  _("E2: Enable recording debug (Timer log)")  , config.recording.debug ) )
196                         except:
197                                 pass
198
199         def changeConfig(self):
200                 self.list = []
201                 self.buildConfig()
202                 self["config"].setList(self.list)
203
204         def changed(self):
205                 for x in self.onChangedEntry:
206                         x()
207                 current = self["config"].getCurrent()[1]
208                 if (current == config.plugins.seriesplugin.enabled or 
209                         current == config.plugins.seriesplugin.autotimer_independent or 
210                         current == config.plugins.seriesplugin.write_log or
211                         current == config.plugins.seriesplugin.rename_file):
212                         self.changeConfig()
213
214         # Overwrite ConfigListScreen keySave function
215         def keySave(self):
216                 self.saveAll()
217                 
218                 config.plugins.seriesplugin.identifier_elapsed.value = self.cfg_identifier_elapsed.value
219                 config.plugins.seriesplugin.identifier_today.value   = self.cfg_identifier_today.value
220                 config.plugins.seriesplugin.identifier_future.value  = self.cfg_identifier_future.value
221                 config.plugins.seriesplugin.pattern_title.value       = self.cfg_pattern_title.value
222                 config.plugins.seriesplugin.pattern_description.value = self.cfg_pattern_description.value
223                 #config.plugins.seriesplugin.pattern_record.value      = self.cfg_pattern_record.value
224                 config.plugins.seriesplugin.save()
225                 
226                 from plugin import overwriteAutoTimer, recoverAutoTimer
227                 
228                 if config.plugins.seriesplugin.enabled.value:
229                         overwriteAutoTimer()
230                 else:
231                         recoverAutoTimer()
232                 
233                 # Set new configuration
234                 from plugin import WHERE_EPGMENU, addSeriesPlugin, removeSeriesPlugin, SHOWINFO, RENAMESERIES, CHECKTIMERS, info, extension, channel, movielist_info, movielist_rename, checkTimers
235                 
236                 if config.plugins.seriesplugin.menu_info.value:
237                         addSeriesPlugin(PluginDescriptor.WHERE_EVENTINFO, SHOWINFO, info)
238                 else:
239                         removeSeriesPlugin(PluginDescriptor.WHERE_EVENTINFO, SHOWINFO)
240                 
241                 if config.plugins.seriesplugin.menu_extensions.value:
242                         addSeriesPlugin(PluginDescriptor.WHERE_EXTENSIONSMENU, SHOWINFO)
243                 else:
244                         removeSeriesPlugin(PluginDescriptor.WHERE_EXTENSIONSMENU, SHOWINFO)
245                 
246                 if config.plugins.seriesplugin.menu_epg.value:
247                         addSeriesPlugin(WHERE_EPGMENU, SHOWINFO)
248                 else:
249                         removeSeriesPlugin(WHERE_EPGMENU, SHOWINFO)
250                 
251                 if config.plugins.seriesplugin.menu_channel.value:
252                         addSeriesPlugin(PluginDescriptor.WHERE_CHANNEL_CONTEXT_MENU, SHOWINFO, channel)
253                 else:
254                         removeSeriesPlugin(PluginDescriptor.WHERE_CHANNEL_CONTEXT_MENU, SHOWINFO)
255                 
256                 if config.plugins.seriesplugin.menu_movie_info.value:
257                         addSeriesPlugin(PluginDescriptor.WHERE_MOVIELIST, SHOWINFO, movielist_info)
258                 else:
259                         removeSeriesPlugin(PluginDescriptor.WHERE_MOVIELIST, SHOWINFO)
260                 
261                 if config.plugins.seriesplugin.menu_movie_rename.value:
262                         addSeriesPlugin(PluginDescriptor.WHERE_MOVIELIST, RENAMESERIES, movielist_rename)
263                 else:
264                         removeSeriesPlugin(PluginDescriptor.WHERE_MOVIELIST, RENAMESERIES)
265                 
266                 if config.plugins.seriesplugin.check_timer_list.value:
267                         addSeriesPlugin(PluginDescriptor.WHERE_EXTENSIONSMENU, CHECKTIMERS, checkTimers)
268                 else:
269                         removeSeriesPlugin(PluginDescriptor.WHERE_EXTENSIONSMENU, CHECKTIMERS)
270                 
271                 # To set new module configuration
272                 resetInstance()
273                 
274                 if config.plugins.seriesplugin.autotimer_independent.value:
275                         from SeriesPluginIndependent import startIndependent
276                         startIndependent()
277                         
278                 self.close()
279
280         # Overwrite ConfigListScreen keyCancel function
281         def keyCancel(self):
282                 if self["config"].isChanged():
283                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
284                 else:
285                         self.close()
286
287         # Overwrite Screen close function
288         def close(self):
289                 from plugin import ABOUT
290                 about = ABOUT.format( **{'lookups': config.plugins.seriesplugin.lookup_counter.value} )
291                 self.session.openWithCallback(self.closeConfirm, MessageBox, about, MessageBox.TYPE_INFO)
292
293         def closeConfirm(self, dummy=None):
294                 # Call baseclass function
295                 Screen.close(self)
296         
297         def getCurrentEntry(self):
298                 return self["config"].getCurrent()[0]
299
300         def getCurrentValue(self):
301                 return str(self["config"].getCurrent()[1].getText())
302
303         def createSummary(self):
304                 return SetupSummary
305
306         def pageUp(self):
307                 self["config"].instance.moveSelection(self["config"].instance.pageUp)
308
309         def pageDown(self):
310                 self["config"].instance.moveSelection(self["config"].instance.pageDown)
311
312         def blue(self):
313                 #self.sendLog()
314                 self.session.open(ShowLogScreen, config.plugins.seriesplugin.log_file.value)
315