fix selection and bsod
[enigma2-plugins.git] / 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.Label import Label
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
14
15 class UserManager(Screen):
16         skin = """
17                 <screen name="UserManager" position="90,140" size="560,350" title="UserManager">
18                         <widget source="config" render="Listbox" position="10,10" size="540,220" scrollbarMode="showOnDemand">
19                                 <convert type="TemplatedMultiContent">
20                                         {"template": [
21                                                         MultiContentEntryText(pos = (80, 5), size = (400, 50), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 0 is the name
22                                                         MultiContentEntryPixmapAlphaTest(pos = (0, 0), size = (48, 48), png = 3), # index 4 is the status pixmap
23                                                 ],
24                                         "fonts": [gFont("Regular", 40)],
25                                         "itemHeight": 50
26                                         }
27                                 </convert>
28                         </widget>
29                         <widget name="introduction" position="50,270" size="500,20" zPosition="10" font="Regular;21" halign="center" transparent="1" />
30                         <widget name="ButtonRedtext" position="410,305" size="140,21" zPosition="10" font="Regular;21" transparent="1" />
31                         <widget name="ButtonRed" pixmap="skin_default/buttons/button_red.png" position="390,305" zPosition="10" size="15,16" transparent="1" alphatest="on" />
32                         <ePixmap pixmap="skin_default/buttons/button_yellow.png" position="30,305" zPosition="10" size="15,16" transparent="1" alphatest="on" />
33                         <widget name="deletetext" position="50,305" size="350,21" zPosition="10" font="Regular;21" transparent="1" />
34                         <ePixmap pixmap="skin_default/bottombar.png" position="10,250" size="540,120" zPosition="1" transparent="1" alphatest="on" />
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                 self["ButtonRed"] = Pixmap()
50                 self["ButtonRedtext"] = Label(_("Close"))
51                 self["introduction"] = Label(_("Press OK to edit selected settings."))
52                 self["deletetext"] = Label(_("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