new:
[vuplus_dvbapp-plugin] / 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 Multimedia 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
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
27 class AutomaticVolumeAdjustmentConfig():
28         def __init__(self):
29                 self.CONFIG_FILE = '/usr/lib/enigma2/python/Plugins/SystemPlugins/AutomaticVolumeAdjustment/config'
30                 # load config file
31                 self.loadConfigFile()
32
33         # load config file and initialize 
34         def loadConfigFile(self):
35                 print "[AutomaticVolumeAdjustmentConfig] Loading config file..."
36                 self.config = Config()
37                 if not os_path.exists(self.CONFIG_FILE):
38                         fd = os_open( self.CONFIG_FILE, os_O_RDWR|os_O_CREAT)
39                         os_close( fd )
40                 self.config.loadFromFile(self.CONFIG_FILE)
41                 self.config.entriescount =  ConfigInteger(0)
42                 self.config.Entries = ConfigSubList()
43                 self.config.enable = ConfigYesNo(default = False)
44                 self.config.adustvalue = ConfigInteger(default=25, limits=(0,50))
45                 self.config.mpeg_max_volume = ConfigInteger(default=100, limits=(10,100))
46                 self.config.show_volumebar = ConfigYesNo(default = False)
47                 self.initConfig()
48
49         def initConfig(self):
50                 count = self.config.entriescount.value
51                 if count != 0:
52                         i = 0
53                         while i < count:
54                                 self.initEntryConfig()
55                                 i += 1
56                 print "[AutomaticVolumeAdjustmentConfig] Loaded %s entries from config file..." % count
57
58         def initEntryConfig(self):
59                 self.config.Entries.append(ConfigSubsection())
60                 i = len(self.config.Entries) - 1
61                 self.config.Entries[i].servicereference = ConfigText(default = "")
62                 self.config.Entries[i].name = NoSave(ConfigDirectory(default = _("Press OK to select a service")))
63                 self.config.Entries[i].adjustvalue = ConfigInteger(default=25, limits=(5,50))
64                 return self.config.Entries[i]
65         
66         def remove(self, configItem):
67                 self.config.entriescount.value = self.config.entriescount.value - 1
68                 self.config.entriescount.save()
69                 self.config.Entries.remove(configItem)
70                 self.config.Entries.save()
71                 self.save()
72         
73         def save(self):
74                 print "[AutomaticVolumeAdjustmentConfig] saving config file..."
75                 self.config.saveToFile(self.CONFIG_FILE)