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