Fix some wrong locale path definitions and disable own locale handling inside Network...
[enigma2-plugins.git] / networkbrowser / src / MountView.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 Components.Sources.StaticText import StaticText
7 from Components.ActionMap import ActionMap
8 from Components.Network import iNetwork
9 from Components.Sources.List import List
10 from Tools.LoadPixmap import LoadPixmap
11 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
12 from AutoMount import iAutoMount, AutoMount
13 from MountEdit import AutoMountEdit
14
15 class AutoMountView(Screen):
16         skin = """
17                 <screen name="AutoMountView" position="90,140" size="560,350" title="MountView">
18                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
19                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
20                         <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" />
21                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
22                         <widget source="legend1" render="Label" position="0,50" zPosition="1" size="130,40" font="Regular;18" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
23                         <widget source="legend2" render="Label" position="130,50" zPosition="1" size="310,40" font="Regular;18" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
24                         <widget source="legend3" render="Label" position="410,50" zPosition="1" size="100,40" font="Regular;18" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
25                         <ePixmap pixmap="skin_default/div-h.png" position="0,90" zPosition="2" size="560,2" />
26                         <widget source="config" render="Listbox" position="5,100" size="555,200" scrollbarMode="showOnDemand">
27                                 <convert type="TemplatedMultiContent">
28                                         {"template": [
29                                                         MultiContentEntryPixmapAlphaTest(pos = (15, 1), size = (48, 48), png = 0), # index 0 is the isMounted pixmap
30                                                         MultiContentEntryText(pos = (100, 3), size = (200, 25), font=0, flags = RT_HALIGN_LEFT, text = 1), # index 1 is the sharename
31                                                         MultiContentEntryText(pos = (290, 5), size = (150, 17), font=1, flags = RT_HALIGN_LEFT, text = 2), # index 2 is the IPdescription
32                                                         MultiContentEntryText(pos = (100, 29), size = (350, 17), font=1, flags = RT_HALIGN_LEFT, text = 3), # index 3 is the DIRdescription
33                                                         MultiContentEntryPixmapAlphaTest(pos = (450, 9), size = (48, 48), png = 4), # index 4 is the activepng pixmap
34                                                         MultiContentEntryPixmapAlphaTest(pos = (480, 1), size = (48, 48), png = 5), # index 4 is the mounttype pixmap
35                                                 ],
36                                         "fonts": [gFont("Regular", 20),gFont("Regular", 14)],
37                                         "itemHeight": 50
38                                         }
39                                 </convert>
40                         </widget>
41                         <ePixmap pixmap="skin_default/div-h.png" position="0,310" zPosition="1" size="560,2" />
42                         <widget source="introduction" render="Label" position="110,320" size="300,20" zPosition="10" font="Regular;21" halign="center" valign="center" backgroundColor="#25062748" transparent="1" />
43                 </screen>"""
44
45         def __init__(self, session, plugin_path):
46                 self.skin_path = plugin_path
47                 self.session = session
48                 Screen.__init__(self, session)
49                 self.mounts = None
50                 self.applyConfigRef = None
51                 self["shortcuts"] = ActionMap(["ShortcutActions", "WizardActions"],
52                 {
53                         "ok": self.keyOK,
54                         "back": self.exit,
55                         "cancel": self.exit,
56                         "red": self.exit,
57                         "yellow": self.delete,
58                 })
59                 self["legend1"] = StaticText(_("Mounted/\nUnmounted"))
60                 self["legend2"] = StaticText(_("Mount informations"))
61                 self["legend3"] = StaticText(_("Active/\nInactive"))
62                 self["introduction"] = StaticText(_("Press OK to edit the settings."))
63                 self["key_red"] = StaticText(_("Close"))
64                 self["key_yellow"] = StaticText(_("Delete mount"))
65
66                 self.list = []
67                 self["config"] = List(self.list)
68                 self.showMountsList()
69
70         def showMountsList(self):
71                 self.list = []
72                 self.mounts = iAutoMount.getMountsList()
73                 for sharename in self.mounts.keys():
74                         mountentry = iAutoMount.automounts[sharename]
75                         self.list.append(self.buildMountViewItem(mountentry))
76                 self["config"].setList(self.list)
77
78         def buildMountViewItem(self, entry):
79                 if entry["isMounted"] is True:
80                         isMountedpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkBrowser/icons/ok.png"))
81                 if entry["isMounted"] is False:
82                         isMountedpng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkBrowser/icons/cancel.png"))
83                 sharename = entry["sharename"]
84                 IPdescription = _("IP:") + " " + str(entry["ip"])
85                 DIRdescription = _("Dir:") + " " + str(entry["sharedir"])
86                 if entry["active"] == 'True' or entry["active"] == True:
87                         activepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_on.png"))
88                 if entry["active"] == 'False' or entry["active"] == False:
89                         activepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_SKIN_IMAGE, "skin_default/icons/lock_error.png"))
90                 if entry["mounttype"] == 'nfs':
91                         mounttypepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkBrowser/icons/i-nfs.png"))
92                 if entry["mounttype"] == 'cifs':
93                         mounttypepng = LoadPixmap(cached=True, path=resolveFilename(SCOPE_PLUGINS, "SystemPlugins/NetworkBrowser/icons/i-smb.png"))
94                 return((isMountedpng, sharename, IPdescription, DIRdescription, activepng, mounttypepng))
95
96         def exit(self):
97                 self.close()
98
99         def keyOK(self, returnValue = None):
100                 cur = self["config"].getCurrent()
101                 if cur:
102                         returnValue = cur[1]
103                         self.session.openWithCallback(self.MountEditClosed, AutoMountEdit, self.skin_path, iAutoMount.automounts[returnValue])
104
105         def MountEditClosed(self, returnValue = None):
106                 if returnValue == None:
107                         self.showMountsList()
108
109         def delete(self, returnValue = None):
110                 cur = self["config"].getCurrent()
111                 if cur:
112                         returnValue = cur[1]
113                         self.applyConfigRef = self.session.openWithCallback(self.applyConfigfinishedCB, MessageBox, _("Please wait while removing your network mount..."), type = MessageBox.TYPE_INFO, enable_input = False)
114                         iAutoMount.removeMount(returnValue,self.removeDataAvail)
115
116         def removeDataAvail(self, data):
117                 if data is True:
118                         iAutoMount.writeMountsConfig()
119                         iAutoMount.getAutoMountPoints(self.deleteDataAvail)
120
121         def deleteDataAvail(self, data):
122                 if data is True:
123                         if self.applyConfigRef.execing:
124                                 self.applyConfigRef.close(True)
125
126         def applyConfigfinishedCB(self,data):
127                 if data is True:
128                         self.session.openWithCallback(self.ConfigfinishedCB, MessageBox, _("Your network mount has been removed."), type = MessageBox.TYPE_INFO, timeout = 10)
129
130         def ConfigfinishedCB(self,data):
131                 if data is not None:
132                         if data is True:
133                                 self.showMountsList()
134