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