diff options
author | mkaay <mkaay@mkaay.de> | 2009-12-24 01:28:08 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2009-12-24 01:28:08 +0100 |
commit | ea04c11ce1fb52895449a56e862eff5448ea456a (patch) | |
tree | b0eb5c841b082ee5777ad072d5754a67cff383fc | |
parent | download speed limit (diff) | |
download | pyload-ea04c11ce1fb52895449a56e862eff5448ea456a.tar.xz |
downloads are now aborted correctly, gui: remove downloads, new icons
-rw-r--r-- | module/file_list.py | 6 | ||||
-rw-r--r-- | module/gui/Collector.py | 55 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 20 | ||||
-rw-r--r-- | module/gui/Queue.py | 30 | ||||
-rw-r--r-- | module/gui/connector.py | 20 | ||||
-rwxr-xr-x | module/network/Request.py | 14 | ||||
-rw-r--r-- | module/thread_list.py | 2 | ||||
-rwxr-xr-x | pyLoadGui.py | 11 |
8 files changed, 114 insertions, 44 deletions
diff --git a/module/file_list.py b/module/file_list.py index f156e2c0d..9d7260889 100644 --- a/module/file_list.py +++ b/module/file_list.py @@ -29,6 +29,7 @@ import cPickle import re import module.Plugin from os import sep +from time import sleep class NoSuchElementException(Exception): pass @@ -285,6 +286,9 @@ class File_List(object): packager.file_list.lock.acquire() try: key, n, pypack = packager._getPackageFromID(id) + for pyfile in pypack.files: + pyfile.plugin.req.abort = True + sleep(0.1) del packager.file_list.data[key][n] finally: packager.file_list.lock.release() @@ -296,6 +300,8 @@ class File_List(object): packager.file_list.lock.acquire() try: key, n, pyfile, pypack, pid = packager._getFileFromID(id) + pyfile.plugin.req.abort = True + sleep(0.1) del pypack.files[n] if not pypack.files: packager.removePackage(pid) diff --git a/module/gui/Collector.py b/module/gui/Collector.py index 1d622b006..1f89670ce 100644 --- a/module/gui/Collector.py +++ b/module/gui/Collector.py @@ -58,7 +58,7 @@ class PackageCollector(QThread): child = self.PackageCollectorFile(self, pack) child.setData(info) pack.addChild(fid, child) - #pack.clear(files) + pack.clear(files) self.clear(ids) def addPack(self, pid, newPack): @@ -88,15 +88,14 @@ class PackageCollector(QThread): return None def clear(self, ids): - toremove = [] - for k, pack in enumerate(self.collector): - id = pack.getData()["id"] - if not id in ids: - toremove.append(k) - if not toremove: + clear = False + for pack in self.collector: + if not pack.getData()["id"] in ids: + clear = True + break + if not clear: return self.collector = [] - #self.view.clear() self.view.emit(SIGNAL("clear")) class PackageCollectorPack(): @@ -149,20 +148,15 @@ class PackageCollector(QThread): return self.data def clear(self, ids): - toremove = [] - for k, file in enumerate(self.getChildren()): - id = file.getData()["id"] - if not id in ids: - toremove.append(k) - if not toremove: + clear = False + for file in self.getChildren(): + if not file.getData()["id"] in ids: + clear = True + break + if not clear: return - ppos = self.collector.collector.index(self) - parent = self.collector.view.topLevelItem(ppos) - toremove.sort() - toremove.reverse() - for pos in toremove: - del self.children[k] - parent.takeChild(k) + self.collector.collector = [] + self.collector.view.emit(SIGNAL("clear")) class PackageCollectorFile(): def __init__(self, collector, pack): @@ -237,18 +231,15 @@ class LinkCollector(QThread): return None def clear(self, ids): - toremove = [] - for k, file in enumerate(self.collector): - id = file.getData()["id"] - if not id in ids: - toremove.append(k) - if not toremove: + clear = False + for pack in self.collector: + if not pack.getData()["id"] in ids: + clear = True + break + if not clear: return - toremove.sort() - toremove.reverse() - for pos in toremove: - del self.collector[k] - self.view.takeTopLevelItem(k) + self.collector = [] + self.view.emit(SIGNAL("clear")) class LinkCollectorFile(): def __init__(self, collector): diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index 837125263..53de8cd54 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -147,6 +147,7 @@ class MainWindow(QMainWindow): self.tabs["collector"]["package_view"] = QTreeWidget() self.connect(self.tabs["collector"]["package_view"], SIGNAL("clear"), self.tabs["collector"]["package_view"].clear) self.tabs["collector"]["link_view"] = QTreeWidget() + self.connect(self.tabs["collector"]["link_view"], SIGNAL("clear"), self.tabs["collector"]["link_view"].clear) groupPackage.layout().addWidget(self.tabs["collector"]["package_view"]) groupPackage.layout().addWidget(toQueue) groupLinks.layout().addWidget(self.tabs["collector"]["link_view"]) @@ -164,10 +165,11 @@ class MainWindow(QMainWindow): self.queueContext = QMenu() self.queueContext.buttons = {} self.queueContext.item = (None, None) - self.queueContext.buttons["remove"] = QAction("Remove", self.queueContext) - self.queueContext.buttons["restart"] = QAction("Restart", self.queueContext) + self.queueContext.buttons["remove"] = QAction(QIcon("icons/gui/remove_small.png"), "Remove", self.queueContext) + self.queueContext.buttons["restart"] = QAction(QIcon("icons/gui/refresh_small.png"), "Restart", self.queueContext) self.queueContext.addAction(self.queueContext.buttons["remove"]) self.queueContext.addAction(self.queueContext.buttons["restart"]) + self.connect(self.queueContext.buttons["remove"], SIGNAL("triggered()"), self.slotRemoveDownload) self.connect(self.queueContext.buttons["restart"], SIGNAL("triggered()"), self.slotRestartDownload) def slotToggleStatus(self, status): @@ -279,9 +281,13 @@ class MainWindow(QMainWindow): """ globalPos = self.tabs["queue"]["view"].mapToGlobal(pos) i = self.tabs["queue"]["view"].itemAt(pos) + if not i: + return i.setSelected(True) self.queueContext.item = (i.data(0, Qt.UserRole).toPyObject(), i.parent() == None) - self.queueContext.exec_(globalPos) + menuPos = QCursor.pos() + menuPos.setX(menuPos.x()+2) + self.queueContext.exec_(menuPos) def slotPackageCollectorContextMenu(self, pos): """ @@ -302,4 +308,12 @@ class MainWindow(QMainWindow): id, isTopLevel = self.queueContext.item if not id == None: self.emit(SIGNAL("restartDownload"), id, isTopLevel) + + def slotRemoveDownload(self): + """ + remove download action is triggered + """ + id, isTopLevel = self.queueContext.item + if not id == None: + self.emit(SIGNAL("removeDownload"), id, isTopLevel) diff --git a/module/gui/Queue.py b/module/gui/Queue.py index c9a3e858b..35e1163b9 100644 --- a/module/gui/Queue.py +++ b/module/gui/Queue.py @@ -61,8 +61,10 @@ class Queue(QThread): del d["name"] del d["status"] downloading[did] = d + ids = [] for data in packs: pack = self.getPack(data["id"]) + ids.append(data["id"]) if not pack: pack = self.QueuePack(self) pack.setData(data) @@ -73,12 +75,15 @@ class Queue(QThread): child = pack.getChild(fid) if not child: child = self.QueueFile(self, pack) + info["downloading"] = None try: info["downloading"] = downloading[info["id"]] except: - info["downloading"] = None + pass child.setData(info) pack.addChild(fid, child) + pack.clear(files) + self.clear(ids) def addPack(self, pid, newPack): pos = None @@ -122,6 +127,17 @@ class Queue(QThread): return pack return None + def clear(self, ids): + clear = False + for pack in self.queue: + if not pack.getData()["id"] in ids: + clear = True + break + if not clear: + return + self.queue = [] + self.view.emit(SIGNAL("clear")) + def getWaitingProgress(self, q): locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): @@ -173,7 +189,6 @@ class Queue(QThread): return 0 def getSpeed(self, q): - #locker = QMutexLocker(self.mutex) if isinstance(q, self.QueueFile): data = q.getData() if data["downloading"]: @@ -251,6 +266,17 @@ class Queue(QThread): def getData(self): return self.data + + def clear(self, ids): + clear = False + for file in self.getChildren(): + if not file.getData()["id"] in ids: + clear = True + break + if not clear: + return + self.queue.queue = [] + self.queue.view.emit(SIGNAL("clear")) class QueueFile(): def __init__(self, queue, pack): diff --git a/module/gui/connector.py b/module/gui/connector.py index 75781ebb1..4d3af0d61 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -230,3 +230,23 @@ class connector(QThread): self.proxy.restart_file(fileid) finally: self.mutex.unlock() + + def removePackage(self, packid): + """ + remove a package + """ + self.mutex.lock() + try: + self.proxy.del_packages([packid,]) + finally: + self.mutex.unlock() + + def removeFile(self, fileid): + """ + remove a file + """ + self.mutex.lock() + try: + self.proxy.del_links([fileid,]) + finally: + self.mutex.unlock() diff --git a/module/network/Request.py b/module/network/Request.py index 752c16f04..651553a0f 100755 --- a/module/network/Request.py +++ b/module/network/Request.py @@ -304,7 +304,7 @@ class Request: def writefunc(buf): if self.abort: - raise AbortDownload + return False chunkSize = len(buf) while chunkSize > restLimit() > -1: time.sleep(0.05) @@ -316,8 +316,12 @@ class Request: self.pycurl.setopt(pycurl.WRITEFUNCTION, writefunc) - - self.pycurl.perform() + try: + self.pycurl.perform() + except Exception, e: + code, msg = e + if not code == 23: + raise Exception, e #~ if "..." in file_name: #~ download_folder = dirname(file_name) + sep #~ headers = self.get_header() @@ -438,7 +442,6 @@ class Request: def get_speed(self): try: - #return (self.dl_arrived / ((time.time() if self.dl else self.dl_finished) - self.dl_time)) / 1024 return self.dl_speed except: return 0 @@ -453,7 +456,8 @@ class Request: return (self.dl_size - self.dl_arrived) / 1024 def progress(self, dl_t, dl_d, up_t, up_d): - if self.abort: raise AbortDownload + if self.abort: + return False self.dl_arrived = int(dl_d) self.dl_size = int(dl_t) diff --git a/module/thread_list.py b/module/thread_list.py index 9cdb5fc8f..966157b91 100644 --- a/module/thread_list.py +++ b/module/thread_list.py @@ -267,8 +267,6 @@ class Thread_List(object): for thread in self.parent.py_downloading: thread.plugin.req.speedLimitActive = False return - - print "-----" slowCount = 0 slowSpeed = 0 diff --git a/pyLoadGui.py b/pyLoadGui.py index 997a2f781..d5fb02bc0 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -108,6 +108,7 @@ class main(QObject): self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) self.connect(self.mainWindow, SIGNAL("pushPackageToQueue"), self.slotPushPackageToQueue) self.connect(self.mainWindow, SIGNAL("restartDownload"), self.slotRestartDownload) + self.connect(self.mainWindow, SIGNAL("removeDownload"), self.slotRemoveDownload) def slotShowConnector(self): """ @@ -426,6 +427,16 @@ class main(QObject): else: self.connector.restartFile(id) + def slotRemoveDownload(self, id, isPack): + """ + emitted from main window + remove download + """ + if isPack: + self.connector.removePackage(id) + else: + self.connector.removeFile(id) + class Loop(QThread): """ main loop (not application loop) |