EPGRefreshConfiguration.py: show last refresh date/time on info pressed
[vuplus_dvbapp-plugin] / networkbrowser / src / UserManager.py
1 # -*- coding: utf-8 -*-
2 # for localized messages
3 #from __init__ import _
4 from Screens.Screen import Screen
5 from Components.Sources.StaticText import StaticText
6 from Components.Pixmap import Pixmap
7 from Components.ActionMap import ActionMap
8 from Components.Sources.List import List
9
10 from Tools.LoadPixmap import LoadPixmap
11 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
12 from UserDialog import UserDialog
13 from os import unlink, listdir, path as os_path
14
15 class UserManager(Screen):
16         skin = """
17                 <screen name="UserManager" position="center,center" size="560,400" title="UserManager">
18                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
19                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
20                         <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" />
21                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
22                         <widget source="config" render="Listbox" position="5,50" size="540,220" scrollbarMode="showOnDemand">
23                                 <convert type="TemplatedMultiContent">
24                                         {"template": [
25                                                         MultiContentEntryText(pos = (80, 5), size = (400, 50), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
26                                                         MultiContentEntryPixmapAlphaTest(pos = (0, 0), size = (48, 48), png = 3), # index 4 is the status pixmap
27                                                 ],
28                                         "fonts": [gFont("Regular", 40)],
29                                         "itemHeight": 50
30                                         }
31                                 </convert>
32                         </widget>
33                         <ePixmap pixmap="skin_default/div-h.png" position="0,360" zPosition="1" size="560,2" />
34                         <widget source="introduction" render="Label" position="10,370" size="540,21" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1"/>
35                 </screen>"""
36
37         def __init__(self, session, plugin_path):
38                 self.skin_path = plugin_path
39                 self.session = session
40                 Screen.__init__(self, session)
41                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions"],
42                 {
43                         "ok": self.keyOK,
44                         "back": self.exit,
45                         "cancel": self.exit,
46                         "red": self.exit,
47                         "yellow": self.delete,
48                 })
49
50                 self["key_red"] = StaticText(_("Close"))
51                 self["introduction"] = StaticText(_("Press OK to edit selected settings."))
52                 self["key_yellow"] = StaticText(_("Delete"))
53
54                 self.list = []
55                 self["config"] = List(self.list)
56                 self.updateList()
57                 self.onShown.append(self.setWindowTitle)
58
59         def setWindowTitle(self):
60                 self.setTitle(_("Usermanager"))
61
62         def updateList(self):
63                 self.list = []
64                 for file in listdir('/etc/enigma2'):
65                         if file.endswith('.cache'):
66                                 if file == 'networkbrowser.cache':
67                                         continue
68                                 else:
69                                         hostpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkBrowser/icons/host.png"))
70                                         self.list.append(( file[:-6],'edit',file,hostpng ))
71                 self["config"].setList(self.list)
72
73         def exit(self):
74                 self.close()
75
76         def keyOK(self, returnValue = None):
77                 cur = self["config"].getCurrent()
78                 if cur:
79                         returnValue = cur[1]
80                         hostinfo = cur[0]
81                         if returnValue is "edit":
82                                 self.session.open(UserDialog, self.skin_path,hostinfo)
83
84         def delete(self, returnValue = None):
85                 cur = self["config"].getCurrent()
86                 if cur:
87                         returnValue = cur[2]
88                         cachefile = '/etc/enigma2/' + returnValue.strip()
89                         if os_path.exists(cachefile):
90                                 unlink(cachefile)
91                                 self.updateList()
92