add extended virtualkeyboard from epgsearch and prefer it over inputbox,
[enigma2-plugins.git] / ftpbrowser / src / plugin.py
1 #
2 # POC FTP Browser for Enigma2
3 #
4
5 # for localized messages         
6 from . import _
7
8 # Config
9 from Components.config import config, ConfigSet, ConfigSubsection, ConfigText
10
11 config.plugins.ftpbrowser = ConfigSubsection()
12 config.plugins.ftpbrowser.history = ConfigSet(choices = [])
13
14 from FTPBrowser import FTPBrowser
15
16 ftpbrowser = None
17
18 def createSingleton(session):
19         global ftpbrowser
20         if not ftpbrowser:
21                 ftpbrowser = session.instantiateDialog(FTPBrowser)
22                 return False
23         return True
24
25 def main(session, **kwargs):
26         createSingleton(session)
27         session.execDialog(ftpbrowser)
28
29 def filescan_chosen(session, item):
30         if item:
31                 createSingleton(session)
32                 ftpbrowser.connect(item[1])
33                 session.execDialog(ftpbrowser)
34
35 def filescan_open_connected(res, items, session, **kwargs):
36         if res:
37                 ftpbrowser.disconnect()
38                 filescan_open(items, session, **kwargs)
39
40 def filescan_open(items, session, **kwargs):
41         if createSingleton(session) and ftpbrowser.ftpclient:
42                 from Screens.MessageBox import MessageBox
43                 from Tools.BoundFunction import boundFunction
44
45                 session.openWithCallback(
46                         boundFunction(filescan_open_connected, items, session, **kwargs),
47                         MessageBox,
48                         _("There already is an active connection.\nDo you want to abort it?"),
49                         type = MessageBox.TYPE_YESNO
50                 )
51                 return
52
53         Len = len(items)
54         if Len > 1:
55                 from Screens.ChoiceBox import ChoiceBox
56                 from Tools.BoundFunction import boundFunction
57
58                 session.openWithCallback(
59                         boundFunction(filescan_chosen, session),
60                         ChoiceBox,
61                         _("Which server do you want to connect to?"),
62                         [(item, item) for item in items]
63                 )
64         elif Len:
65                 filescan_chosen(items[0])
66
67 def filescan(**kwargs):
68         from Components.Scanner import Scanner, ScanPath
69
70         # Overwrite checkFile to detect remote files
71         class RemoteScanner(Scanner):
72                 def checkFile(self, file):
73                         return file.path.startswith("ftp://")
74
75         return [
76                 RemoteScanner(
77                         mimetypes = None,
78                         paths_to_scan =
79                                 (
80                                         ScanPath(path = "", with_subdirs = False),
81                                 ),
82                         name = "Connect",
83                         description = _("Connect to FTP..."),
84                         openfnc = filescan_open,
85                 ),
86         ]
87
88 def Plugins(**kwargs):
89         from Plugins.Plugin import PluginDescriptor
90
91         return [
92                 PluginDescriptor(
93                         name="FTPBrowser",
94                         description = _("A basic FTP client"),
95                         where = PluginDescriptor.WHERE_PLUGINMENU,
96                         fnc = main
97                 ),
98                 PluginDescriptor(
99                         name = "FTPBrowser",
100                         where = PluginDescriptor.WHERE_FILESCAN,
101                         fnc = filescan
102                 ),
103         ]