Merge branch 'bug_274_disable_fast_winding_for_non_ts'
[enigma2.git] / lib / python / Plugins / SystemPlugins / CleanupWizard / plugin.py
1 from Screens.Screen import Screen
2 from Plugins.Plugin import PluginDescriptor
3 from Components.PluginComponent import plugins
4 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigYesNo, ConfigNumber
5 from Components.ConfigList import ConfigListScreen
6 from Components.ActionMap import ActionMap
7 from Components.Sources.StaticText import StaticText
8 from CleanupWizard import checkFreeSpaceAvailable
9
10 config.plugins.cleanupwizard = ConfigSubsection()
11 config.plugins.cleanupwizard.enable = ConfigYesNo(default = True)
12 config.plugins.cleanupwizard.threshold = ConfigNumber(default = 2048)
13
14 freeSpace = checkFreeSpaceAvailable()
15 print "[CleanupWizard] freeSpaceAvailable-->",freeSpace
16
17 if freeSpace is None:
18         internalMemoryExceeded = 0
19 elif int(freeSpace) <= config.plugins.cleanupwizard.threshold.value:
20         internalMemoryExceeded = 1
21 else:
22         internalMemoryExceeded = 0
23
24 class CleanupWizardConfiguration(Screen, ConfigListScreen):
25
26         skin = """
27                 <screen name="CleanupWizardConfiguration" position="center,center" size="560,440" title="CleanupWizard settings" >
28                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
29                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
30                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
31                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
32                         <widget name="config" zPosition="2" position="5,50" size="550,300" scrollbarMode="showOnDemand" transparent="1" />
33                         <ePixmap pixmap="skin_default/div-h.png" position="0,390" zPosition="10" size="560,2" transparent="1" alphatest="on" />
34                         <widget source="status" render="Label" position="10,400" size="540,40" zPosition="10" font="Regular;20" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/>
35                 </screen>"""
36
37         def __init__(self, session):
38                 Screen.__init__(self, session)
39                 self.session = session
40                 self.EnableEntry = None
41                 self.freeSpaceEntry = None
42                 self.onChangedEntry = [ ]
43                 self.setup_title = _("Cleanup Wizard")
44
45                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
46                 {
47                         "ok": self.keySave,
48                         "cancel": self.keyCancel,
49                         "red": self.keyCancel,
50                         "green": self.keySave,
51                 }, -2)
52
53                 self.list = []
54                 ConfigListScreen.__init__(self, self.list, session = self.session, on_change = self.changedEntry)
55                 self.createSetup()
56
57                 self["key_red"] = StaticText(_("Close"))
58                 self["key_green"] = StaticText(_("Save"))
59                 self["status"] = StaticText()
60                 self.onShown.append(self.setWindowTitle)
61
62         def setWindowTitle(self):
63                 self.setTitle(_("Cleanup Wizard settings"))
64
65         def keyLeft(self):
66                 ConfigListScreen.keyLeft(self)
67                 self.newConfig()
68
69         def keyRight(self):
70                 ConfigListScreen.keyRight(self)
71                 self.newConfig()
72
73         def createSetup(self):
74                 self.list = []
75                 self.EnableEntry = getConfigListEntry(_("Enable Cleanup Wizard?"), config.plugins.cleanupwizard.enable)
76                 self.freeSpaceEntry = getConfigListEntry(_("Warn if free space drops below (kB):"), config.plugins.cleanupwizard.threshold)
77                 self.list.append( self.EnableEntry )
78                 if config.plugins.cleanupwizard.enable.value is True:
79                         self.list.append( self.freeSpaceEntry )
80
81                 self["config"].list = self.list
82                 self["config"].l.setList(self.list)
83                 if not self.selectionChanged in self["config"].onSelectionChanged:
84                         self["config"].onSelectionChanged.append(self.selectionChanged)
85
86         def newConfig(self):
87                 if self["config"].getCurrent() == self.EnableEntry:
88                         self.createSetup()
89
90         def selectionChanged(self):
91                 current = self["config"].getCurrent()
92                 if current == self.EnableEntry:
93                         self["status"].setText(_("Decide if you want to enable or disable the Cleanup Wizard."))
94                 elif current == self.freeSpaceEntry:
95                         self["status"].setText(_("Set available internal memory threshold for the warning."))
96
97         # for summary:
98         def changedEntry(self):
99                 for x in self.onChangedEntry:
100                         x()
101                 self.selectionChanged()
102
103         def getCurrentEntry(self):
104                 return self["config"].getCurrent()[0]
105
106         def getCurrentValue(self):
107                 return str(self["config"].getCurrent()[1].getText())
108
109         def createSummary(self):
110                 from Screens.Setup import SetupSummary
111                 return SetupSummary
112
113
114 def CleanupWizard(*args, **kwargs):
115         from CleanupWizard import CleanupWizard
116         return CleanupWizard(*args, **kwargs)
117
118 def openconfig(session, **kwargs):
119         session.open(CleanupWizardConfiguration)
120
121 def selSetup(menuid, **kwargs):
122         if menuid != "system":
123                 return [ ]
124
125         return [(_("Cleanup Wizard settings") + "...", openconfig, "cleanup_config", 71)]
126
127 def Plugins(**kwargs):
128         list = []
129         list.append(PluginDescriptor(name=_("CleanupWizard"), description=_("Cleanup Wizard settings"),where=PluginDescriptor.WHERE_MENU, fnc=selSetup))
130         if config.plugins.cleanupwizard.enable.value:
131                 if not config.misc.firstrun.value:
132                         if internalMemoryExceeded:
133                                 list.append(PluginDescriptor(name=_("Cleanup Wizard"), where = PluginDescriptor.WHERE_WIZARD, fnc=(1, CleanupWizard)))
134         return list
135