[MerlinSkinThemes] - add config option to disable rebuild on boot
[enigma2-plugins.git] / automaticvolumeadjustment / src / AutomaticVolumeAdjustmentConfig.py
1 # -*- coding: utf-8 -*-
2 #
3 #  AutomaticVolumeAdjustment E2
4 #
5 #  $Id$
6 #
7 #  Coded by Dr.Best (c) 2010
8 #  Support: www.dreambox-tools.info
9 #
10 #  This plugin is licensed under the Creative Commons 
11 #  Attribution-NonCommercial-ShareAlike 3.0 Unported 
12 #  License. To view a copy of this license, visit
13 #  http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
14 #  Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
15 #
16 #  Alternatively, this plugin may be distributed and executed on hardware which
17 #  is licensed by Dream Property GmbH.
18
19 #  This plugin is NOT free software. It is open source, you are allowed to
20 #  modify it (if you keep the license), but it may not be commercially 
21 #  distributed other than under the conditions noted above.
22 #
23 from Components.config import ConfigSubsection, ConfigText, \
24         config, ConfigInteger, Config, ConfigSubList, ConfigDirectory, NoSave, ConfigYesNo, ConfigSelectionNumber, ConfigSelection
25 from os import path as os_path, open as os_open, close as os_close, O_RDWR as os_O_RDWR, O_CREAT  as os_O_CREAT 
26 from pickle import load as pickle_load, dump as pickle_dump
27 from enigma import eEnv
28
29 CONFIG_FILE_VOLUME = eEnv.resolve('${libdir}/enigma2/python/Plugins/SystemPlugins/AutomaticVolumeAdjustment/config_volume')
30
31 def getVolumeDict():
32         if os_path.exists(CONFIG_FILE_VOLUME):
33                 pkl_file = open(CONFIG_FILE_VOLUME, 'rb')
34                 if pkl_file:
35                         volumedict = pickle_load(pkl_file)
36                         pkl_file.close()
37                         return volumedict
38         return {}
39
40 def saveVolumeDict(dict):
41         pkl_file = open(CONFIG_FILE_VOLUME, 'wb')
42         if pkl_file:
43                 pickle_dump(dict, pkl_file)
44                 pkl_file.close()
45
46 class AutomaticVolumeAdjustmentConfig():
47         def __init__(self):
48                 self.CONFIG_FILE = eEnv.resolve('${libdir}/enigma2/python/Plugins/SystemPlugins/AutomaticVolumeAdjustment/config')
49                 # load config file
50                 self.loadConfigFile()
51
52         # load config file and initialize 
53         def loadConfigFile(self):
54                 print "[AutomaticVolumeAdjustmentConfig] Loading config file..."
55                 self.config = Config()
56                 if not os_path.exists(self.CONFIG_FILE):
57                         try:
58                                 fd = os_open( self.CONFIG_FILE, os_O_RDWR|os_O_CREAT)
59                                 os_close( fd )
60                         except Exception, e:
61                                 print "Error: ", e
62                 try:
63                         self.config.loadFromFile(self.CONFIG_FILE)
64                 except Exception, e:
65                         print "Error: ", e
66                 self.config.entriescount =  ConfigInteger(0)
67                 self.config.Entries = ConfigSubList()
68                 self.config.enable = ConfigYesNo(default = False)
69                 self.config.modus = ConfigSelection(choices = [("0", _("Automatic volume adjust")), ("1", _("Remember service volume value"))], default = "0")
70                 self.config.adustvalue = ConfigSelectionNumber(-50, 50, 5, default = 25)
71                 self.config.mpeg_max_volume = ConfigSelectionNumber(10, 100, 5, default = 100)
72                 self.config.show_volumebar = ConfigYesNo(default = False)
73                 self.initConfig()
74
75         def initConfig(self):
76                 count = self.config.entriescount.value
77                 if count != 0:
78                         i = 0
79                         while i < count:
80                                 self.initEntryConfig()
81                                 i += 1
82                 print "[AutomaticVolumeAdjustmentConfig] Loaded %s entries from config file..." % count
83
84         def initEntryConfig(self):
85                 self.config.Entries.append(ConfigSubsection())
86                 i = len(self.config.Entries) - 1
87                 self.config.Entries[i].servicereference = ConfigText(default = "")
88                 self.config.Entries[i].name = NoSave(ConfigDirectory(default = _("Press OK to select a service")))
89                 self.config.Entries[i].adjustvalue = ConfigSelectionNumber(-50, 50, 5, default = 25)
90                 return self.config.Entries[i]
91         
92         def remove(self, configItem):
93                 self.config.entriescount.value = self.config.entriescount.value - 1
94                 self.config.entriescount.save()
95                 self.config.Entries.remove(configItem)
96                 self.config.Entries.save()
97                 self.save()
98         
99         def save(self):
100                 print "[AutomaticVolumeAdjustmentConfig] saving config file..."
101                 self.config.saveToFile(self.CONFIG_FILE)