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