diff options
author | mkaay <mkaay@mkaay.de> | 2009-12-21 18:52:51 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2009-12-21 18:52:51 +0100 |
commit | 9a435f166b8d70fa2e61351b1d84db77c5b42472 (patch) | |
tree | 0b0fc9193e8666721b880351d9a5a5ac31f78cb8 | |
parent | total progressbar bullshit (diff) | |
parent | merged Wugy (diff) | |
download | pyload-9a435f166b8d70fa2e61351b1d84db77c5b42472.tar.xz |
merged Wugy, 2nd try
-rw-r--r-- | module/config/gui_default.xml | 4 | ||||
-rw-r--r-- | module/gui/Collector.py | 21 | ||||
-rw-r--r-- | module/gui/LinkDock.py | 1 | ||||
-rw-r--r-- | module/gui/MainWindow.py | 31 | ||||
-rw-r--r-- | module/gui/PackageDock.py | 29 | ||||
-rw-r--r-- | module/gui/connector.py | 20 | ||||
-rw-r--r-- | module/web/pyload.db | bin | 44032 -> 44032 bytes | |||
-rwxr-xr-x | pyLoadGui.py | 48 |
8 files changed, 150 insertions, 4 deletions
diff --git a/module/config/gui_default.xml b/module/config/gui_default.xml index af38eda4c..9b6d75936 100644 --- a/module/config/gui_default.xml +++ b/module/config/gui_default.xml @@ -4,4 +4,8 @@ <name>Local</name> </connection> </connections> + <mainWindow> + <state></state> + <geometry></geometry> + </mainWindow> </root> diff --git a/module/gui/Collector.py b/module/gui/Collector.py index 0dbccab1f..28cac097b 100644 --- a/module/gui/Collector.py +++ b/module/gui/Collector.py @@ -102,8 +102,8 @@ class PackageCollector(QThread): except: self.children.append(newChild) pos = self.children.index(newChild) - ppos = self.queue.queue.index(self) - parent = self.queue.view.topLevelItem(ppos) + ppos = self.collector.collector.index(self) + parent = self.collector.view.topLevelItem(ppos) item = parent.child(pos) if not item: item = QTreeWidgetItem() @@ -172,6 +172,7 @@ class LinkCollector(QThread): file = self.LinkCollectorFile(self) file.setData(data) self.addFile(id, file) + self.clear(ids) def addFile(self, pid, newFile): pos = None @@ -192,12 +193,28 @@ class LinkCollector(QThread): self.view.insertTopLevelItem(pos, item) item.setData(0, Qt.DisplayRole, QVariant(newFile.getData()["filename"])) item.setData(0, Qt.UserRole, QVariant(pid)) + flags = Qt.ItemIsSelectable | Qt.ItemIsDragEnabled | Qt.ItemIsEnabled + item.setFlags(flags) def getFile(self, pid): for k, file in enumerate(self.collector): if file.getData()["id"] == pid: return file 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: + return + toremove.sort() + toremove.reverse() + for pos in toremove: + del self.collector[k] + self.view.takeTopLevelItem(k) class LinkCollectorFile(): def __init__(self, collector): diff --git a/module/gui/LinkDock.py b/module/gui/LinkDock.py index 01a0cc193..99429d04b 100644 --- a/module/gui/LinkDock.py +++ b/module/gui/LinkDock.py @@ -22,6 +22,7 @@ from PyQt4.QtGui import * class NewLinkDock(QDockWidget): def __init__(self): QDockWidget.__init__(self, "New Links") + self.setObjectName("New Links Dock") self.widget = NewLinkWindow(self) self.setWidget(self.widget) self.setAllowedAreas(Qt.RightDockWidgetArea|Qt.LeftDockWidgetArea) diff --git a/module/gui/MainWindow.py b/module/gui/MainWindow.py index 6d68f4d7a..4f92f68a9 100644 --- a/module/gui/MainWindow.py +++ b/module/gui/MainWindow.py @@ -33,12 +33,16 @@ class MainWindow(QMainWindow): self.setWindowIcon(QIcon("icons/logo.png")) self.resize(750,500) + #layout version + self.version = 1 + #init docks self.newPackDock = NewPackageDock() self.addDockWidget(Qt.RightDockWidgetArea, self.newPackDock) self.newLinkDock = NewLinkDock() self.addDockWidget(Qt.RightDockWidgetArea, self.newLinkDock) self.connect(self.newLinkDock, SIGNAL("done"), self.slotAddLinks) + self.connect(self.newPackDock, SIGNAL("done"), self.slotAddPackage) #central widget, layout self.masterlayout = QVBoxLayout() @@ -88,7 +92,8 @@ class MainWindow(QMainWindow): self.connect(self.mactions["exit"], SIGNAL("triggered()"), self.close) def init_toolbar(self): - self.toolbar = self.addToolBar("main") + self.toolbar = self.addToolBar("Main Toolbar") + self.toolbar.setObjectName("Main Toolbar") self.toolbar.setIconSize(QSize(40,40)) self.actions["toggle_status"] = self.toolbar.addAction("Toggle Pause/Resume") pricon = QIcon() @@ -156,3 +161,27 @@ class MainWindow(QMainWindow): def slotAddLinks(self, links): self.emit(SIGNAL("addLinks"), links) + + def slotAddPackage(self, name, ids): + self.emit(SIGNAL("addPackage"), name, ids) + + def closeEvent(self, event): + state_raw = self.saveState(self.version) + geo_raw = self.saveGeometry() + + state = str(state_raw.toBase64()) + geo = str(geo_raw.toBase64()) + + self.emit(SIGNAL("saveMainWindow"), state, geo) + event.accept() + + def restoreWindow(self, state, geo): + state = QByteArray(state) + geo = QByteArray(geo) + + state_raw = QByteArray.fromBase64(state) + geo_raw = QByteArray.fromBase64(geo) + + self.restoreState(state_raw, self.version) + self.restoreGeometry(geo_raw) + diff --git a/module/gui/PackageDock.py b/module/gui/PackageDock.py index c97e9d645..b90e3533d 100644 --- a/module/gui/PackageDock.py +++ b/module/gui/PackageDock.py @@ -22,10 +22,23 @@ from PyQt4.QtGui import * class NewPackageDock(QDockWidget): def __init__(self): QDockWidget.__init__(self, "New Package") + self.setObjectName("New Package Dock") self.widget = NewPackageWindow(self) self.setWidget(self.widget) self.setAllowedAreas(Qt.RightDockWidgetArea|Qt.LeftDockWidgetArea) self.hide() + + def slotDone(self): + view = self.widget.view + count = view.topLevelItemCount() + ids = [] + for i in range(count): + item = view.topLevelItem(i) + if item: + ids.append(item.data(0, Qt.UserRole).toInt()[0]) + self.emit(SIGNAL("done"), self.widget.nameInput.text(), ids) + view.clear() + self.hide() class NewPackageWindow(QWidget): def __init__(self, dock): @@ -38,7 +51,19 @@ class NewPackageWindow(QWidget): nameInput = QLineEdit() linksLabel = QLabel("Links in this Package") - linkView = QListWidget() + linkView = QTreeWidget() + linkView.setSelectionBehavior(QAbstractItemView.SelectRows) + linkView.setSelectionMode(QAbstractItemView.SingleSelection) + linkView.setColumnCount(1) + linkView.setHeaderLabels(["Name"]) + linkView.setDragEnabled(True) + linkView.setDragDropMode(QAbstractItemView.DragDrop) + linkView.setDropIndicatorShown(True) + linkView.setAcceptDrops(True) + linkView.setDragDropOverwriteMode(True) + + self.view = linkView + self.nameInput = nameInput save = QPushButton("Create") @@ -47,3 +72,5 @@ class NewPackageWindow(QWidget): layout.addWidget(linksLabel, 1, 0, 1, 2) layout.addWidget(linkView, 2, 0, 1, 2) layout.addWidget(save, 3, 0, 1, 2) + + self.connect(save, SIGNAL("clicked()"), self.dock.slotDone) diff --git a/module/gui/connector.py b/module/gui/connector.py index 32da29bba..e7a151c5e 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -177,3 +177,23 @@ class connector(QThread): self.proxy.unpause_server() finally: self.mutex.unlock() + + def newPackage(self, name): + """ + create a new package and return id + """ + self.mutex.lock() + try: + return self.proxy.new_package(name) + finally: + self.mutex.unlock() + + def addFileToPackage(self, fileid, packid): + """ + add a file from collector to package + """ + self.mutex.lock() + try: + self.proxy.move_file_2_package(fileid, packid) + finally: + self.mutex.unlock() diff --git a/module/web/pyload.db b/module/web/pyload.db Binary files differindex 013c8607d..e5e224850 100644 --- a/module/web/pyload.db +++ b/module/web/pyload.db diff --git a/pyLoadGui.py b/pyLoadGui.py index 6c3bae1dd..a21c27cb9 100755 --- a/pyLoadGui.py +++ b/pyLoadGui.py @@ -61,6 +61,7 @@ class main(QObject): def startMain(self): self.connector.start() sleep(1) + self.restoreMainWindow() self.mainWindow.show() self.initQueue() self.initPackageCollector() @@ -88,7 +89,9 @@ class main(QObject): self.connect(self.pwWindow, SIGNAL("cancel"), self.quit) self.connect(self.mainWindow, SIGNAL("connector"), self.slotShowConnector) self.connect(self.mainWindow, SIGNAL("addLinks"), self.slotAddLinks) + self.connect(self.mainWindow, SIGNAL("addPackage"), self.slotAddPackage) self.connect(self.mainWindow, SIGNAL("setDownloadStatus"), self.slotSetDownloadStatus) + self.connect(self.mainWindow, SIGNAL("saveMainWindow"), self.slotSaveMainWindow) def slotShowConnector(self): self.stopMain() @@ -120,6 +123,19 @@ class main(QObject): view = self.mainWindow.tabs["collector"]["link_view"] view.setColumnCount(1) view.setHeaderLabels(["Name"]) + view.setSelectionBehavior(QAbstractItemView.SelectRows) + view.setSelectionMode(QAbstractItemView.SingleSelection) + def event(klass, event): + event.setDropAction(Qt.CopyAction) + event.accept() + view = event.source() + row = view.currentIndex().row() + view.takeTopLevelItem(row) + view.dropEvent = event + view.setDragEnabled(True) + view.setDragDropMode(QAbstractItemView.DragDrop) + view.setDropIndicatorShown(True) + view.setDragDropOverwriteMode(True) self.linkCollector = LinkCollector(view, self.connector) self.linkCollector.start() @@ -274,6 +290,38 @@ class main(QObject): def slotSetDownloadStatus(self, status): self.connector.setPause(not status) + def slotAddPackage(self, name, ids): + packid = self.connector.newPackage(str(name)) + for fileid in ids: + self.connector.addFileToPackage(fileid, packid) + + def slotSaveMainWindow(self, state, geo): + mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) + if mainWindowNode.isNull(): + raise Exception("null") + stateNode = mainWindowNode.toElement().elementsByTagName("state").item(0) + geoNode = mainWindowNode.toElement().elementsByTagName("geometry").item(0) + newStateNode = self.parser.xml.createTextNode(state) + newGeoNode = self.parser.xml.createTextNode(geo) + + stateNode.removeChild(stateNode.firstChild()) + geoNode.removeChild(geoNode.firstChild()) + stateNode.appendChild(newStateNode) + geoNode.appendChild(newGeoNode) + + self.parser.saveData() + + def restoreMainWindow(self): + mainWindowNode = self.parser.xml.elementsByTagName("mainWindow").item(0) + if mainWindowNode.isNull(): + raise Exception("null") + nodes = self.parser.parseNode(mainWindowNode, "dict") + + state = str(nodes["state"].text()) + geo = str(nodes["geometry"].text()) + + self.mainWindow.restoreWindow(state, geo) + class Loop(QThread): def __init__(self, parent): QThread.__init__(self) |