whitespace cleanup,
[enigma2-plugins.git] / networkbrowser / src / MountManager.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 Screens.MessageBox import MessageBox\r
6 from Screens.VirtualKeyBoard import VirtualKeyBoard\r
7 from Components.Label import Label\r
8 from Components.Pixmap import Pixmap\r
9 from Components.ActionMap import ActionMap\r
10 from Components.Network import iNetwork\r
11 from Components.Sources.List import List\r
12 from Tools.LoadPixmap import LoadPixmap\r
13 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE\r
14 from os import path as os_path\r
15 \r
16 from MountView import AutoMountView\r
17 from MountEdit import AutoMountEdit\r
18 from AutoMount import iAutoMount, AutoMount\r
19 from UserManager import UserManager\r
20 \r
21 class AutoMountManager(Screen):\r
22         skin = """\r
23                 <screen name="AutoMountManager" position="90,140" size="560,350" title="AutoMountManager">\r
24                         <widget source="config" render="Listbox" position="10,10" size="540,220" scrollbarMode="showOnDemand" >\r
25                                 <convert type="TemplatedMultiContent">\r
26                                         {"template": [\r
27                                                         MultiContentEntryText(pos = (0, 3), size = (480, 25), font=0, flags = RT_HALIGN_LEFT, text = 0), # index 2 is the Menu Titel\r
28                                                         MultiContentEntryText(pos = (10, 29), size = (480, 17), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 3 is the Description\r
29                                                         MultiContentEntryPixmapAlphaTest(pos = (500, 1), size = (48, 48), png = 3), # index 4 is the pixmap\r
30                                                 ],\r
31                                         "fonts": [gFont("Regular", 20),gFont("Regular", 14)],\r
32                                         "itemHeight": 50\r
33                                         }\r
34                                 </convert>\r
35                         </widget>\r
36                         <widget name="introduction" position="90,260" size="300,20" zPosition="10" font="Regular;21" halign="center" transparent="1" />\r
37                         <widget name="ButtonRedtext" position="410,305" size="140,21" zPosition="10" font="Regular;21" transparent="1" />\r
38                         <widget name="ButtonRed" pixmap="skin_default/buttons/button_red.png" position="390,305" zPosition="10" size="15,16" transparent="1" alphatest="on" />\r
39                         <ePixmap pixmap="skin_default/bottombar.png" position="10,250" size="540,120" zPosition="1" transparent="1" alphatest="on" />\r
40                 </screen>"""\r
41         def __init__(self, session, iface ,plugin_path):\r
42                 self.skin_path = plugin_path\r
43                 self.session = session\r
44                 self.hostname = None\r
45                 self.restartLanRef = None\r
46                 Screen.__init__(self, session)\r
47                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions"],\r
48                 {\r
49                         "ok": self.keyOK,\r
50                         "back": self.exit,\r
51                         "cancel": self.exit,\r
52                         "red": self.exit,\r
53                 })\r
54                 self["ButtonRed"] = Pixmap()\r
55                 self["ButtonRedtext"] = Label(_("Close"))\r
56                 self["introduction"] = Label(_("Press OK to select."))\r
57 \r
58                 self.list = []\r
59                 self["config"] = List(self.list)\r
60                 self.updateList()\r
61                 self.onClose.append(self.cleanup)\r
62                 self.onShown.append(self.setWindowTitle)\r
63 \r
64         def setWindowTitle(self):\r
65                 self.setTitle(_("MountManager"))\r
66 \r
67         def cleanup(self):\r
68                 iNetwork.stopRestartConsole()\r
69                 iNetwork.stopGetInterfacesConsole()\r
70 \r
71         def updateList(self):\r
72                 self.list = []\r
73                 okpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkBrowser/icons/ok.png"))\r
74                 self.list.append((_("Add new network mount point"),"add", _("Add a new NFS or CIFS mount point to your Dreambox."), okpng ))\r
75                 self.list.append((_("Mountpoints management"),"view", _("View, edit or delete mountpoints on your Dreambox."), okpng ))\r
76                 self.list.append((_("User management"),"user", _("View, edit or delete usernames and passwords for your network."), okpng))\r
77                 self.list.append((_("Change hostname"),"hostname", _("Change the hostname of your Dreambox."), okpng))\r
78                 self["config"].setList(self.list)\r
79 \r
80         def exit(self):\r
81                 self.close()\r
82 \r
83         def keyOK(self, returnValue = None):\r
84                 if returnValue == None:\r
85                         returnValue = self["config"].getCurrent()[1]\r
86                         if returnValue is "add":\r
87                                 self.addMount()\r
88                         elif returnValue is "view":\r
89                                 self.viewMounts()\r
90                         elif returnValue is "user":\r
91                                 self.userEdit()\r
92                         elif returnValue is "hostname":\r
93                                 self.hostEdit()\r
94 \r
95         def addMount(self):\r
96                 self.session.open(AutoMountEdit, self.skin_path)\r
97 \r
98         def viewMounts(self):\r
99                 self.session.open(AutoMountView, self.skin_path)\r
100 \r
101         def userEdit(self):\r
102                 self.session.open(UserManager, self.skin_path)\r
103 \r
104         def hostEdit(self):\r
105                 if os_path.exists("/etc/hostname"):\r
106                         fp = open('/etc/hostname', 'r')\r
107                         self.hostname = fp.read()\r
108                         fp.close()\r
109                         self.session.openWithCallback(self.hostnameCallback, VirtualKeyBoard, title = (_("Enter new hostname for your Dreambox")), text = self.hostname)\r
110 \r
111         def hostnameCallback(self, callback = None):\r
112                 if callback is not None and len(callback):\r
113                         fp = open('/etc/hostname', 'w+')\r
114                         fp.write(callback)\r
115                         fp.close()\r
116                         self.restartLan()\r
117 \r
118         def restartLan(self):\r
119                 iNetwork.restartNetwork(self.restartLanDataAvail)\r
120                 self.restartLanRef = self.session.openWithCallback(self.restartfinishedCB, MessageBox, _("Please wait while your network is restarting..."), type = MessageBox.TYPE_INFO, enable_input = False)\r
121 \r
122         def restartLanDataAvail(self, data):\r
123                 if data is True:\r
124                         iNetwork.getInterfaces(self.getInterfacesDataAvail)\r
125 \r
126         def getInterfacesDataAvail(self, data):\r
127                 if data is True:\r
128                         if self.restartLanRef.execing:\r
129                                 self.restartLanRef.close(True)\r
130 \r
131         def restartfinishedCB(self,data):\r
132                 if data is True:\r
133                         self.session.open(MessageBox, _("Finished restarting your network"), type = MessageBox.TYPE_INFO, timeout = 10, default = False)\r
134 \r