Added RS-Downloader plugin
[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 Screens.Console import Console
14 from Screens.MessageBox import MessageBox
15 from Screens.Screen import Screen
16
17 ##############################################################################
18
19 class RSMain(Screen):
20         skin = """
21                 <screen position="200,175" size="320,250" title="RS Downloader">
22                         <widget name="list" position="10,10" size="300,230" />
23                 </screen>"""
24
25         def __init__(self, session, args = None):
26                 Screen.__init__(self, session)
27                 self.session = session
28                 
29                 self["list"] = MenuList([
30                         _("Start downloading..."),
31                         _("Show lists..."),
32                         _("Show downloads..."),
33                         _("Show progress..."),
34                         _("Edit configs..."),
35                         _("Show status..."),
36                         _("Show log..."),
37                         _("Delete log..."),
38                         _("Show info...")])
39                 
40                 self["actions"] = ActionMap(["OkCancelActions"], {"ok": self.okClicked, "cancel": self.close}, -1)
41
42         def okClicked(self):
43                 selected = self["list"].getCurrent()
44                 if selected is not None:
45                         if selected == (_("Start downloading...")):
46                                 if not rapidshare.downloading:
47                                         ret = rapidshare.startDownloading()
48                                         if ret:
49                                                 self.session.open(MessageBox, _("Started downloading..."), MessageBox.TYPE_INFO)
50                                         else:
51                                                 self.session.open(MessageBox, _("Could not start downloading!"), MessageBox.TYPE_ERROR)
52                                 else:
53                                         self.session.open(MessageBox, _("Already downloading!"), MessageBox.TYPE_ERROR)
54                         
55                         elif selected == (_("Show lists...")):
56                                 path = config.plugins.RSDownloader.lists_directory.value
57                                 if os_path.exists(path):
58                                         self.session.open(RSListBrowser, path)
59                                 else:
60                                         self.session.open(MessageBox, (_("Couldn't find the directory %s!") % path), MessageBox.TYPE_ERROR)
61                         
62                         elif selected == (_("Show downloads...")):
63                                 path = config.plugins.RSDownloader.downloads_directory.value
64                                 if os_path.exists(path):
65                                         self.session.open(RSDownloadBrowser, path)
66                                 else:
67                                         self.session.open(MessageBox, (_("Couldn't find the directory %s!") % path), MessageBox.TYPE_ERROR)
68                         
69                         elif selected == (_("Show progress...")):
70                                 self.session.open(RSProgress)
71                         
72                         elif selected == (_("Edit configs...")):
73                                 self.session.open(RSConfig)
74                         
75                         elif selected == (_("Show status...")):
76                                 if rapidshare.downloading:
77                                         self.session.open(MessageBox, (_("Downloading %s.") % rapidshare.downloading_file), MessageBox.TYPE_INFO)
78                                 else:
79                                         self.session.open(MessageBox, _("Stopped!"), MessageBox.TYPE_INFO)
80                         
81                         elif selected == (_("Show log...")):
82                                 self.session.open(Console, "RS Downloader", ["cat /tmp/rapidshare.log"])
83                         
84                         elif selected == (_("Delete log...")):
85                                 self.session.open(Console, "RS Downloader", ["rm -f /tmp/rapidshare.log"])
86                         
87                         elif selected == (_("Show info...")):
88                                 self.session.open(MessageBox, (_("RS Downloader\nby AliAbdul\n\nThis plugin allows you to download files from rapidshare in the background. You can use this plugin only with a rapidshare-account!")), MessageBox.TYPE_INFO)