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