Added possibility to search for rapidshare.com files.
[enigma2-plugins.git] / rsdownloader / src / RSMain.py
1 ##
2 ## RS Downloader
3 ## by AliAbdul
4 ##
5 from Components.ActionMap import ActionMap
6 from Components.MenuList import MenuList
7 from os import path as os_path
8 from RS import rapidshare
9 from RSConfig import RSConfig, config
10 from RSDownloadBrowser import RSDownloadBrowser
11 from RSListBrowser import RSListBrowser
12 from RSProgress import RSProgress
13 from RSSearch import RSSearch
14 from Screens.Console import Console
15 from Screens.MessageBox import MessageBox
16 from Screens.Screen import Screen
17 from Tools.Directories import fileExists
18
19 if fileExists("/usr/lib/enigma2/python/Screens/LTKeyBoard.pyc"):
20         from Screens.LTKeyBoard import LTKeyBoard
21         LT = True
22 else:
23         from Components.Input import Input
24         from Screens.InputBox import InputBox
25         LT = False
26
27 ##############################################################################
28
29 class RSMain(Screen):
30         skin = """
31                 <screen position="200,165" size="320,270" title="RS Downloader">
32                         <widget name="list" position="10,10" size="300,250" />
33                 </screen>"""
34
35         def __init__(self, session, args = None):
36                 Screen.__init__(self, session)
37                 self.session = session
38                 
39                 self["list"] = MenuList([
40                         _("Start downloading..."),
41                         _("Show lists..."),
42                         _("Show downloads..."),
43                         _("Show progress..."),
44                         _("Edit configs..."),
45                         _("Show status..."),
46                         _("Show log..."),
47                         _("Delete log..."),
48                         _("Use search-engine..."),
49                         _("Show info...")])
50                 
51                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.okClicked, "cancel": self.close}, -1)
52
53         def okClicked(self):
54                 selected = self["list"].getCurrent()
55                 if selected is not None:
56                         if selected == (_("Start downloading...")):
57                                 if not rapidshare.downloading:
58                                         ret = rapidshare.startDownloading()
59                                         if ret:
60                                                 self.session.open(MessageBox, _("Started downloading..."), MessageBox.TYPE_INFO)
61                                         else:
62                                                 self.session.open(MessageBox, _("Could not start downloading!"), MessageBox.TYPE_ERROR)
63                                 else:
64                                         self.session.open(MessageBox, _("Already downloading!"), MessageBox.TYPE_ERROR)
65                         
66                         elif selected == (_("Show lists...")):
67                                 path = config.plugins.RSDownloader.lists_directory.value
68                                 if os_path.exists(path):
69                                         self.session.open(RSListBrowser, path)
70                                 else:
71                                         self.session.open(MessageBox, (_("Couldn't find the directory %s!") % path), MessageBox.TYPE_ERROR)
72                         
73                         elif selected == (_("Show downloads...")):
74                                 path = config.plugins.RSDownloader.downloads_directory.value
75                                 if os_path.exists(path):
76                                         self.session.open(RSDownloadBrowser, path)
77                                 else:
78                                         self.session.open(MessageBox, (_("Couldn't find the directory %s!") % path), MessageBox.TYPE_ERROR)
79                         
80                         elif selected == (_("Show progress...")):
81                                 self.session.open(RSProgress)
82                         
83                         elif selected == (_("Edit configs...")):
84                                 self.session.open(RSConfig)
85                         
86                         elif selected == (_("Show status...")):
87                                 if rapidshare.downloading:
88                                         self.session.open(MessageBox, (_("Downloading %s.") % rapidshare.downloading_file), MessageBox.TYPE_INFO)
89                                 else:
90                                         self.session.open(MessageBox, _("Stopped!"), MessageBox.TYPE_INFO)
91                         
92                         elif selected == (_("Show log...")):
93                                 self.session.open(Console, "RS Downloader", ["cat /tmp/rapidshare.log"])
94                         
95                         elif selected == (_("Delete log...")):
96                                 self.session.open(Console, "RS Downloader", ["rm -f /tmp/rapidshare.log"])
97                         
98                         elif selected == (_("Use search-engine...")):
99                                 title = _("Search http://rapidshare-search-engine.com for:")
100                                 if LT:
101                                         self.session.openWithCallback(self.searchCallback, LTKeyBoard, title=title)
102                                 else:
103                                         self.session.openWithCallback(self.searchCallback, InputBox, title=title, text="", maxSize=False, type=Input.TEXT)
104                         
105                         elif selected == (_("Show info...")):
106                                 self.session.open(MessageBox, (_("RS Downloader\nby AliAbdul\n\nThis plugin allows you to download files from rapidshare in the background.")), MessageBox.TYPE_INFO)
107
108         def searchCallback(self, callback):
109                 if callback is not None and callback != "":
110                         self.session.open(RSSearch, callback)
111