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