From 4478b66c2456cb0d67c3bc8f1f0939fc118f39b0 Mon Sep 17 00:00:00 2001 From: Robert Honz Date: Mon, 1 Apr 2024 12:44:41 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Able=20to=20remove=20single=20items?= =?UTF-8?q?=20from=20download=20queue.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tidal_dl_ng/gui.py | 25 ++++++++++++++++++++----- tidal_dl_ng/ui/main.py | 26 +++++++++++++------------- tidal_dl_ng/ui/main.ui | 8 ++++---- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/tidal_dl_ng/gui.py b/tidal_dl_ng/gui.py index 116aca8..cf568ca 100644 --- a/tidal_dl_ng/gui.py +++ b/tidal_dl_ng/gui.py @@ -326,7 +326,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): items: [QtWidgets.QTreeWidgetItem] = self.tr_lists_user.selectedItems() if len(items) == 0: - logger_gui.error("Please select a row first.") + logger_gui.error("Please select a mix or playlist first.") else: item = items[0] @@ -507,8 +507,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): self.pb_download.clicked.connect(lambda: self.thread_it(self.on_download_results)) self.pb_download_list.clicked.connect(lambda: self.thread_it(self.on_download_list_media)) self.pb_reload_user_lists.clicked.connect(lambda: self.thread_it(self.tidal_user_lists)) - self.pb_clear_all.clicked.connect(self.on_clear_all) - self.pb_clear_finished.clicked.connect(self.on_clear_finished) + self.pb_queue_download_clear_all.clicked.connect(self.on_queue_download_clear_all) + self.pb_queue_download_clear_finished.clicked.connect(self.on_queue_download_clear_finished) + self.pb_queue_download_remove.clicked.connect(self.on_queue_download_remove) self.l_search.returnPressed.connect( lambda: self.search_populate_results(self.l_search.text(), self.cb_search_type.currentData()) ) @@ -643,12 +644,12 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): # Execute self.threadpool.start(worker) - def on_clear_all(self): + def on_queue_download_clear_all(self): self.on_clear_queue_download( f"[{QueueDownloadStatus.Waiting.value}{QueueDownloadStatus.Finished.value}{QueueDownloadStatus.Failed.value}]" ) - def on_clear_finished(self): + def on_queue_download_clear_finished(self): self.on_clear_queue_download(f"[{QueueDownloadStatus.Finished.value}]") def on_clear_queue_download(self, regex: str): @@ -659,6 +660,20 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow): for item in items: self.tr_queue_download.takeTopLevelItem(self.tr_queue_download.indexOfTopLevelItem(item)) + def on_queue_download_remove(self): + items: [QtWidgets.QTreeWidgetItem | None] = self.tr_queue_download.selectedItems() + + if len(items) == 0: + logger_gui.error("Please select an item from the queue first.") + else: + for item in items: + status: str = item.text(0) + + if status is not QueueDownloadStatus.Downloading.value: + self.tr_queue_download.takeTopLevelItem(self.tr_queue_download.indexOfTopLevelItem(item)) + else: + logger_gui.info("Cannot remove a currently downloading item from queue.") + # TODO: Must happen in main thread. Do not thread this. def on_download_results(self) -> None: items: [QtWidgets.QTreeWidgetItem | None] = self.tr_results.selectedItems() diff --git a/tidal_dl_ng/ui/main.py b/tidal_dl_ng/ui/main.py index 035f732..00565ee 100644 --- a/tidal_dl_ng/ui/main.py +++ b/tidal_dl_ng/ui/main.py @@ -445,23 +445,23 @@ class Ui_MainWindow: self.lv_queue_download.addWidget(self.tr_queue_download) - self.pb_queue_download_item_remove = QPushButton(self.w_central) - self.pb_queue_download_item_remove.setObjectName("pb_queue_download_item_remove") - self.pb_queue_download_item_remove.setEnabled(False) + self.pb_queue_download_remove = QPushButton(self.w_central) + self.pb_queue_download_remove.setObjectName("pb_queue_download_remove") + self.pb_queue_download_remove.setEnabled(True) - self.lv_queue_download.addWidget(self.pb_queue_download_item_remove) + self.lv_queue_download.addWidget(self.pb_queue_download_remove) self.horizontalLayout_3 = QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") - self.pb_clear_finished = QPushButton(self.w_central) - self.pb_clear_finished.setObjectName("pb_clear_finished") + self.pb_queue_download_clear_finished = QPushButton(self.w_central) + self.pb_queue_download_clear_finished.setObjectName("pb_queue_download_clear_finished") - self.horizontalLayout_3.addWidget(self.pb_clear_finished) + self.horizontalLayout_3.addWidget(self.pb_queue_download_clear_finished) - self.pb_clear_all = QPushButton(self.w_central) - self.pb_clear_all.setObjectName("pb_clear_all") + self.pb_queue_download_clear_all = QPushButton(self.w_central) + self.pb_queue_download_clear_all.setObjectName("pb_queue_download_clear_all") - self.horizontalLayout_3.addWidget(self.pb_clear_all) + self.horizontalLayout_3.addWidget(self.pb_queue_download_clear_all) self.lv_queue_download.addLayout(self.horizontalLayout_3) @@ -581,9 +581,9 @@ class Ui_MainWindow: ___qtreewidgetitem5.setText(3, QCoreApplication.translate("MainWindow", "Type", None)) ___qtreewidgetitem5.setText(2, QCoreApplication.translate("MainWindow", "Name", None)) ___qtreewidgetitem5.setText(1, QCoreApplication.translate("MainWindow", "obj", None)) - self.pb_queue_download_item_remove.setText(QCoreApplication.translate("MainWindow", "Remove", None)) - self.pb_clear_finished.setText(QCoreApplication.translate("MainWindow", "Clear Finished", None)) - self.pb_clear_all.setText(QCoreApplication.translate("MainWindow", "Clear All", None)) + self.pb_queue_download_remove.setText(QCoreApplication.translate("MainWindow", "Remove", None)) + self.pb_queue_download_clear_finished.setText(QCoreApplication.translate("MainWindow", "Clear Finished", None)) + self.pb_queue_download_clear_all.setText(QCoreApplication.translate("MainWindow", "Clear All", None)) self.m_file.setTitle(QCoreApplication.translate("MainWindow", "File", None)) self.m_help.setTitle(QCoreApplication.translate("MainWindow", "Help", None)) diff --git a/tidal_dl_ng/ui/main.ui b/tidal_dl_ng/ui/main.ui index 6a30e81..f7aafc6 100644 --- a/tidal_dl_ng/ui/main.ui +++ b/tidal_dl_ng/ui/main.ui @@ -656,9 +656,9 @@ - + - false + true Remove @@ -668,14 +668,14 @@ - + Clear Finished - + Clear All