summaryrefslogtreecommitdiffstats
path: root/module/gui
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-02-01 18:54:19 +0100
committerGravatar mkaay <mkaay@mkaay.de> 2010-02-01 18:54:19 +0100
commit5d04894e73a52e69968cb4a4bfd9a581cd2fb86c (patch)
tree648c782dd85d3905f1162b4914a87262f92487be /module/gui
parentclean + strip (diff)
downloadpyload-5d04894e73a52e69968cb4a4bfd9a581cd2fb86c.tar.xz
new update system for remote clients
Diffstat (limited to 'module/gui')
-rw-r--r--module/gui/Collector.py230
-rw-r--r--module/gui/Queue.py132
-rw-r--r--module/gui/connector.py19
3 files changed, 213 insertions, 168 deletions
diff --git a/module/gui/Collector.py b/module/gui/Collector.py
index 0aad5d1ba..c0754aa42 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,80 @@ 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.takeChild(k)
+ break
+ else:
+ for k, pack in enumerate(ItemIterator(self.rootItem)):
+ if pack.getPackData()["id"] == event[3]:
+ self.rootItem.takeChild(k)
+ 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])
+ 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 +116,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 +142,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.takeChild(k)
class PackageCollectorPack(QTreeWidgetItem):
def __init__(self, collector):
@@ -184,25 +188,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 +211,50 @@ 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.takeChild(k)
+ 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])
+ file = getFile(event[3])
+ file.setFileData(data)
+ self.addFile(event[3], file)
+
def addFile(self, pid, newFile):
pos = None
try:
@@ -289,16 +280,9 @@ 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
+ def clearAll(self):
self.rootItem.takeChildren()
-
+
class LinkCollectorFile(QTreeWidgetItem):
def __init__(self, collector):
QTreeWidgetItem.__init__(self)
diff --git a/module/gui/Queue.py b/module/gui/Queue.py
index 8681d3bb1..9659137ec 100644
--- a/module/gui/Queue.py
+++ b/module/gui/Queue.py
@@ -77,28 +77,101 @@ 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):
+ locker = QMutexLocker(self.mutex)
+ 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):
+ 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.takeChild(k)
+ break
+ else:
+ for k, pack in enumerate(ItemIterator(self.rootItem)):
+ if pack.getPackData()["id"] == event[3]:
+ self.rootItem.takeChild(k)
+ 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])
+ 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 +218,8 @@ 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):
+ self.rootItem.takeChildren()
def getWaitingProgress(self, q):
locker = QMutexLocker(self.mutex)
@@ -282,24 +344,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..3146ecf5b 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,7 +127,9 @@ 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)
finally:
@@ -421,4 +426,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()