summaryrefslogtreecommitdiffstats
path: root/module/gui
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-02-02 22:19:59 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-02-02 22:19:59 +0100
commit99da0e18722d9343a274e9a96376969a469e3a95 (patch)
treeb612118af4ed934c46d46500960b3ec16f2c09a0 /module/gui
parentFixed time compare thanks prophy (diff)
parentmerge (diff)
downloadpyload-99da0e18722d9343a274e9a96376969a469e3a95.tar.xz
merge no2
Diffstat (limited to 'module/gui')
-rw-r--r--module/gui/Collector.py237
-rw-r--r--module/gui/Queue.py135
-rw-r--r--module/gui/connector.py22
3 files changed, 224 insertions, 170 deletions
diff --git a/module/gui/Collector.py b/module/gui/Collector.py
index 0aad5d1ba..ebdbd372d 100644
--- a/module/gui/Collector.py
+++ b/module/gui/Collector.py
@@ -27,7 +27,6 @@ class PackageCollector(QObject):
self.view = view
self.connector = connector
self.collector = []
- self.interval = 2
self.rootItem = self.view.invisibleRootItem()
self.mutex = QMutex()
item = self.PackageCollectorPack(self)
@@ -36,48 +35,82 @@ class PackageCollector(QObject):
item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
self.rootItem.addChild(item)
self.linkCollector = item
- self.pauseIDs = []
- self.updater = self.CollectorUpdater(self.interval)
- self.connect(self.updater, SIGNAL("update()"), self.update)
- class CollectorUpdater(QThread):
- def __init__(self, interval):
- QThread.__init__(self)
- self.interval = interval
- self.running = True
-
- def run(self):
- while self.running:
- self.emit(SIGNAL("update()"))
- self.sleep(self.interval)
-
- def start(self):
- self.updater.start()
-
- def wait(self):
- self.updater.wait()
-
- def stop(self):
- self.updater.running = False
-
- def update(self):
+ def fullReload(self):
locker = QMutexLocker(self.mutex)
+ self.clearAll()
packs = self.connector.getPackageCollector()
- ids = []
for data in packs:
- ids.append(data["id"])
- self.clear(ids)
- for data in packs:
- if data["id"] in self.pauseIDs:
- continue
- ids.append(data["id"])
- pack = self.getPack(data["id"])
- if not pack:
- pack = self.PackageCollectorPack(self)
+ pack = self.PackageCollectorPack(self)
pack.setPackData(data)
+ files = self.connector.getPackageFiles(data["id"])
+ for fid in files:
+ info = self.connector.getLinkInfo(fid)
+ child = self.PackageCollectorFile(self, pack)
+ child.setFileData(info)
+ pack.addPackChild(fid, child)
self.addPack(data["id"], pack)
+
+ def addEvent(self, event):
+ if event[0] == "reload":
+ self.fullReload()
+ elif event[0] == "remove":
+ self.removeEvent(event)
+ elif event[0] == "insert":
+ self.insertEvent(event)
+ elif event[0] == "update":
+ self.updateEvent(event)
+
+ def removeEvent(self, event):
+ if event[2] == "file":
+ for pack in ItemIterator(self.rootItem):
+ for k, child in enumerate(pack.getChildren()):
+ if child.getFileData()["id"] == event[3]:
+ pack.removeChild(child)
+ break
+ else:
+ for k, pack in enumerate(ItemIterator(self.rootItem)):
+ if pack.getPackData()["id"] == event[3]:
+ self.rootItem.removeChild(pack)
+ break
+
+ def insertEvent(self, event):
+ if event[2] == "file":
+ info = self.connector.getLinkInfo(event[3])
+ for pack in ItemIterator(self.rootItem):
+ if pack.getPackData()["id"] == info["package"]:
+ child = self.PackageCollectorFile(self, pack)
+ child.setFileData(info)
+ pack.addPackChild(info["id"], child)
+ break
+ else:
+ data = self.connector.getPackageInfo(event[3])
+ pack = self.PackageCollectorPack(self)
+ pack.setPackData(data)
+ self.addPack(data["id"], pack)
+ files = self.connector.getPackageFiles(data["id"])
+ for fid in files:
+ info = self.connector.getLinkInfo(fid)
+ child = self.PackageCollectorFile(self, pack)
+ child.setFileData(info)
+ pack.addPackChild(fid, child)
+ self.addPack(data["id"], pack)
+
+ def updateEvent(self, event):
+ if event[2] == "file":
+ info = self.connector.getLinkInfo(event[3])
+ if not info:
+ return
+ for pack in ItemIterator(self.rootItem):
+ if pack.getPackData()["id"] == info["package"]:
+ child = pack.getChild(event[3])
+ child.setFileData(info)
+ pack.addPackChild(info["id"], child)
+ else:
+ data = self.connector.getPackageInfo(event[3])
+ pack = self.getPack(event[3])
+ pack.setPackData(data)
files = self.connector.getPackageFiles(data["id"])
- pack.clear(files)
for fid in files:
info = self.connector.getLinkInfo(fid)
child = pack.getChild(fid)
@@ -85,6 +118,7 @@ class PackageCollector(QObject):
child = self.PackageCollectorFile(self, pack)
child.setFileData(info)
pack.addPackChild(fid, child)
+ self.addPack(data["id"], pack)
def addPack(self, pid, newPack):
pos = None
@@ -110,38 +144,10 @@ class PackageCollector(QObject):
return pack
return None
- def clear(self, ids):
- clear = False
- remove = []
+ def clearAll(self):
for k, pack in enumerate(ItemIterator(self.rootItem)):
- if not pack.getPackData()["id"] in ids and not pack.getPackData()["id"] == "fixed":
- clear = True
- remove.append(k)
- if not clear:
- return
- remove.sort()
- remove.reverse()
- for k in remove:
- self.rootItem.takeChild(k)
- for pack in ItemIterator(self.rootItem):
- if pack.getPackData()["id"] == "fixed":
- return
- item = self.PackageCollectorPack(self)
- item.setPackData({"id":"fixed"})
- item.setData(0, Qt.DisplayRole, QVariant("Single Links"))
- item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsSelectable)
- self.rootItem.addChild(item)
- self.linkCollector = item
-
- def pauseItemUpdate(self, pid, pause=True):
- locker = QMutexLocker(self.mutex)
- if pause and not pid in self.pauseIDs:
- self.pauseIDs.append(int(pid))
- else:
- try:
- self.pauseIDs.remove(int(pid))
- except:
- pass
+ if not pack.getPackData()["id"] == "fixed":
+ self.rootItem.removeChild(pack)
class PackageCollectorPack(QTreeWidgetItem):
def __init__(self, collector):
@@ -184,25 +190,6 @@ class PackageCollector(QObject):
if item.getFileData()["id"] == cid:
return item
return None
-
- def clear(self, ids):
- clear = False
- remove = []
- children = []
- for k, file in enumerate(self.getChildren()):
- if not file.getFileData()["id"] in ids:
- remove.append(file.getFileData()["id"])
- if file.getFileData()["id"] in children and not file.getFileData()["id"] in remove:
- remove.append(file.getFileData()["id"])
- continue
- children.append(file.getFileData()["id"])
- if not remove:
- return
- remove.sort()
- remove.reverse()
- parent = self
- for k in remove:
- parent.takeChild(k)
class PackageCollectorFile(QTreeWidgetItem):
def __init__(self, collector, pack):
@@ -226,44 +213,52 @@ class LinkCollector(QObject):
QObject.__init__(self)
self.view = view
self.connector = connector
- self.interval = 2
self.rootItem = root
self.mutex = QMutex()
- self.updater = self.CollectorUpdater(self.interval)
- self.connect(self.updater, SIGNAL("update()"), self.update)
- class CollectorUpdater(QThread):
- def __init__(self, interval):
- QThread.__init__(self)
- self.interval = interval
- self.running = True
-
- def run(self):
- while self.running:
- self.emit(SIGNAL("update()"))
- self.sleep(self.interval)
-
- def start(self):
- self.updater.start()
-
- def wait(self):
- self.updater.wait()
-
- def stop(self):
- self.updater.running = False
-
- def update(self):
+ def fullReload(self):
locker = QMutexLocker(self.mutex)
+ self.clearAll()
ids = self.connector.getLinkCollector()
- self.clear(ids)
for fid in ids:
data = self.connector.getLinkInfo(fid)
- file = self.getFile(fid)
- if not file:
- file = self.LinkCollectorFile(self)
+ file = self.LinkCollectorFile(self)
file.setFileData(data)
self.addFile(fid, file)
+ def addEvent(self, event):
+ if event[0] == "reload":
+ self.fullReload()
+ elif event[0] == "remove":
+ self.removeEvent(event)
+ elif event[0] == "insert":
+ self.insertEvent(event)
+ elif event[0] == "update":
+ self.updateEvent(event)
+
+ def removeEvent(self, event):
+ if event[2] == "file":
+ for k, file in enumerate(ItemIterator(self.rootItem)):
+ if file.getFileData()["id"] == event[3]:
+ self.rootItem.removeChild(file)
+ break
+
+ def insertEvent(self, event):
+ if event[2] == "file":
+ data = self.connector.getLinkInfo(event[3])
+ file = self.LinkCollectorFile(self)
+ file.setFileData(data)
+ self.addFile(event[3], file)
+
+ def updateEvent(self, event):
+ if event[2] == "file":
+ data = self.connector.getLinkInfo(event[3])
+ if not data:
+ return
+ file = getFile(event[3])
+ file.setFileData(data)
+ self.addFile(event[3], file)
+
def addFile(self, pid, newFile):
pos = None
try:
@@ -289,16 +284,10 @@ class LinkCollector(QObject):
return file
return None
- def clear(self, ids):
- clear = False
- for file in ItemIterator(self.rootItem):
- if not file.getFileData()["id"] in ids:
- clear = True
- break
- if not clear:
- return
- self.rootItem.takeChildren()
-
+ def clearAll(self):
+ for k, file in enumerate(ItemIterator(self.rootItem)):
+ self.rootItem.removeChild(file)
+
class LinkCollectorFile(QTreeWidgetItem):
def __init__(self, collector):
QTreeWidgetItem.__init__(self)
diff --git a/module/gui/Queue.py b/module/gui/Queue.py
index 8681d3bb1..bd45e27dc 100644
--- a/module/gui/Queue.py
+++ b/module/gui/Queue.py
@@ -77,28 +77,103 @@ class Queue(QObject):
del d["name"]
del d["status"]
downloading[did] = d
- ids = []
- for data in packs:
- ids.append(data["id"])
- self.clear(ids)
+ for pack in ItemIterator(self.rootItem):
+ for child in pack.getChildren():
+ info = child.getFileData()
+ try:
+ info["downloading"] = downloading[info["id"]]
+ except:
+ info["downloading"] = None
+ child.setFileData(info)
+ pack.addPackChild(info["id"], child)
+ self.addPack(pack.getPackData()["id"], pack)
+
+ def fullReload(self):
+ self.clearAll()
+ packs = self.connector.getPackageQueue()
for data in packs:
- pack = self.getPack(data["id"])
- if not pack:
- pack = self.QueuePack(self)
+ pack = self.QueuePack(self)
pack.setPackData(data)
files = self.connector.getPackageFiles(data["id"])
- pack.clear(files)
+ for fid in files:
+ info = self.connector.getLinkInfo(fid)
+ child = self.QueueFile(self, pack)
+ if not info["status_type"]:
+ info["status_type"] = "queued"
+ child.setFileData(info)
+ pack.addPackChild(fid, child)
self.addPack(data["id"], pack)
+
+ def addEvent(self, event):
+ locker = QMutexLocker(self.mutex)
+ if event[0] == "reload":
+ self.fullReload()
+ elif event[0] == "remove":
+ self.removeEvent(event)
+ elif event[0] == "insert":
+ self.insertEvent(event)
+ elif event[0] == "update":
+ self.updateEvent(event)
+
+ def removeEvent(self, event):
+ if event[2] == "file":
+ for pack in ItemIterator(self.rootItem):
+ for k, child in enumerate(pack.getChildren()):
+ if child.getFileData()["id"] == event[3]:
+ pack.removeChild(child)
+ break
+ else:
+ for k, pack in enumerate(ItemIterator(self.rootItem)):
+ if pack.getPackData()["id"] == event[3]:
+ self.rootItem.removeChild(pack)
+ break
+
+ def insertEvent(self, event):
+ if event[2] == "file":
+ info = self.connector.getLinkInfo(event[3])
+ for pack in ItemIterator(self.rootItem):
+ if pack.getPackData()["id"] == info["package"]:
+ child = self.QueueFile(self, pack)
+ child.setFileData(info)
+ pack.addPackChild(info["id"], child)
+ break
+ else:
+ data = self.connector.getPackageInfo(event[3])
+ pack = self.QueuePack(self)
+ pack.setPackData(data)
+ self.addPack(data["id"], pack)
+ files = self.connector.getPackageFiles(data["id"])
+ for fid in files:
+ info = self.connector.getLinkInfo(fid)
+ child = self.QueueFile(self, pack)
+ if not info["status_type"]:
+ info["status_type"] = "queued"
+ child.setFileData(info)
+ pack.addPackChild(fid, child)
+ self.addPack(data["id"], pack)
+
+ def updateEvent(self, event):
+ if event[2] == "file":
+ info = self.connector.getLinkInfo(event[3])
+ if not info:
+ return
+ for pack in ItemIterator(self.rootItem):
+ if pack.getPackData()["id"] == info["package"]:
+ child = pack.getChild(event[3])
+ if not info["status_type"]:
+ info["status_type"] = "queued"
+ child.setFileData(info)
+ pack.addPackChild(info["id"], child)
+ else:
+ data = self.connector.getPackageInfo(event[3])
+ pack = self.getPack(event[3])
+ pack.setPackData(data)
+ files = self.connector.getPackageFiles(data["id"])
for fid in files:
info = self.connector.getLinkInfo(fid)
child = pack.getChild(fid)
if not child:
child = self.QueueFile(self, pack)
- info["downloading"] = None
- try:
- info["downloading"] = downloading[info["id"]]
- except:
- pass
if not info["status_type"]:
info["status_type"] = "queued"
child.setFileData(info)
@@ -145,19 +220,9 @@ class Queue(QObject):
return pack
return None
- def clear(self, ids):
- clear = False
- remove = []
- for k, pack in enumerate(ItemIterator(self.rootItem)):
- if not pack.getPackData()["id"] in ids:
- clear = True
- remove.append(k)
- if not clear:
- return
- remove.sort()
- remove.reverse()
- for k in remove:
- self.rootItem.takeChild(k)
+ def clearAll(self):
+ for pack in ItemIterator(self.rootItem):
+ self.rootItem.removeChild(pack)
def getWaitingProgress(self, q):
locker = QMutexLocker(self.mutex)
@@ -282,24 +347,6 @@ class Queue(QObject):
if item.getFileData()["id"] == cid:
return item
return None
-
- def clear(self, ids):
- clear = False
- remove = []
- children = []
- for k, file in enumerate(self.getChildren()):
- if not file.getFileData()["id"] in ids:
- remove.append(file.getFileData()["id"])
- if file.getFileData()["id"] in children and not file.getFileData()["id"] in remove:
- remove.append(file.getFileData()["id"])
- continue
- children.append(file.getFileData()["id"])
- if not remove:
- return
- remove.sort()
- remove.reverse()
- for k in remove:
- self.takeChild(k)
class QueueFile(QTreeWidgetItem):
def __init__(self, queue, pack):
diff --git a/module/gui/connector.py b/module/gui/connector.py
index 432999161..b6c383956 100644
--- a/module/gui/connector.py
+++ b/module/gui/connector.py
@@ -19,6 +19,7 @@
SERVER_VERSION = "0.3"
from time import sleep
+from uuid import uuid4 as uuid
from PyQt4.QtCore import *
from PyQt4.QtGui import *
@@ -35,6 +36,7 @@ class connector(QThread):
self.running = True
self.proxy = None
self.addr = None
+ self.connectionID = None
self.errorQueue = []
self.connect(self, SIGNAL("proxy_error"), self._proxyError)
@@ -72,6 +74,7 @@ class connector(QThread):
self.proxy = ServerProxy(addr, allow_none=True)
try:
server_version = self.proxy.get_server_version()
+ self.connectionID = uuid().hex
except:
return False
if not server_version == SERVER_VERSION:
@@ -124,9 +127,12 @@ class connector(QThread):
"""
self.mutex.lock()
try:
- return self.proxy.get_file_info(id)
+ info = self.proxy.get_file_info(id)
+ info["downloading"] = None
+ return info
except Exception, e:
- self.emit(SIGNAL("proxy_error"), "getLinkInfo", e)
+ #self.emit(SIGNAL("proxy_error"), "getLinkInfo", e)
+ return None
finally:
self.mutex.unlock()
@@ -421,4 +427,16 @@ class connector(QThread):
self.emit(SIGNAL("proxy_error"), "setCaptchaResult", e)
finally:
self.mutex.unlock()
+
+ def getEvents(self):
+ """
+ get events
+ """
+ self.mutex.lock()
+ try:
+ return self.proxy.get_events(self.connectionID)
+ except Exception, e:
+ self.emit(SIGNAL("proxy_error"), "getEvents", e)
+ finally:
+ self.mutex.unlock()