The only downloader you need. 下载器的集大成者。
TypeScript asyncasynciobittorentbtcross-platformdownload-managerdownloaderfluent-designftphttp3magnetpyqtpyside6pythonqtquicreactsoftwarestreaming
添加删除任务对话框 优化文件打开方式
XiaoYouChRac3c7b4b8771
diff --git a/app/common/methods.py b/app/common/methods.pyindex 6b3839e8..7cec1019 100644--- a/app/common/methods.py+++ b/app/common/methods.py@@ -2,10 +2,12 @@ import importlibimport inspectimport osimport sys+from datetime import datetime, timedelta, timezonefrom functools import wrapsfrom time import sleep, localtime-from datetime import datetime, timedelta, timezone+from PySide6.QtCore import QUrl+from PySide6.QtGui import QDesktopServicesfrom PySide6.QtWidgets import QApplicationfrom loguru import logger@@ -125,13 +127,12 @@ def retry(retries: int = 3, delay: float = 0.1, handleFunction: callable = None)def openFile(fileResolve):-- if sys.platform == "win32":- os.startfile(f"{fileResolve}")- elif sys.platform == "darwin": # macOS- os.system(f"open '{fileResolve}'")- else:- os.system(f"xdg-open '{fileResolve}'")+ """+ 打开文件++ :param fileResolve: 文件路径+ """+ QDesktopServices.openUrl(QUrl.fromLocalFile(fileResolve))def getLocalTimeFromGithubApiTime(gmtTimeStr:str):diff --git a/app/components/Ui_TaskCard.py b/app/components/Ui_TaskCard.pyindex 5eefd438..43e90102 100644--- a/app/components/Ui_TaskCard.py+++ b/app/components/Ui_TaskCard.py@@ -12,8 +12,7 @@ from PySide6.QtCore import (QCoreApplication, QMetaObject, QSize, Qt)from PySide6.QtWidgets import (QHBoxLayout, QSizePolicy, QSpacerItem,QVBoxLayout)-from qfluentwidgets import (BodyLabel, PixmapLabel, TitleLabel, ToolButton, RoundMenu, Action,- DropDownToolButton, PrimaryToolButton)+from qfluentwidgets import (BodyLabel, PixmapLabel, TitleLabel, ToolButton, PrimaryToolButton)from qfluentwidgets import FluentIcon as FIF@@ -72,24 +71,10 @@ class Ui_TaskCard(object):self.horizontalLayout.addWidget(self.folderButton)- # self.fileButton = ToolButton(TaskCard)- # self.fileButton.setObjectName(u"folderButton")- # self.fileButton.setMinimumSize(QSize(31, 31))- # self.fileButton.setMaximumSize(QSize(31, 31))- #- # self.horizontalLayout.addWidget(self.fileButton)-- self.Menu = RoundMenu(parent=self)- self.delAction = Action(FIF.DELETE, "删除")- self.completelyDelAction = Action(FIF.CLOSE, "彻底删除")- self.Menu.addAction(self.delAction)- self.Menu.addAction(self.completelyDelAction)-- self.cancelButton = DropDownToolButton(TaskCard)+ self.cancelButton = ToolButton(TaskCard)self.cancelButton.setObjectName(u"cancelButton")- self.cancelButton.setMenu(self.Menu)- self.cancelButton.setMinimumSize(QSize(61, 31))- self.cancelButton.setMaximumSize(QSize(61, 31))+ self.cancelButton.setMinimumSize(QSize(31, 31))+ self.cancelButton.setMaximumSize(QSize(31, 31))self.horizontalLayout.addWidget(self.cancelButton)@@ -131,7 +116,6 @@ class Ui_TaskCard(object):self.pauseButton.setIcon(FIF.PAUSE)self.cancelButton.setIcon(FIF.DELETE)self.folderButton.setIcon(FIF.FOLDER)- # self.fileButton.setIcon(FIF.LIBRARY)self.retranslateUi(TaskCard)@@ -144,6 +128,5 @@ class Ui_TaskCard(object):self.pauseButton.setText("")self.cancelButton.setText("")self.folderButton.setText("")- # self.fileButton.setText("")self.processLabel.setText("")# retranslateUidiff --git a/app/components/del_dialog.py b/app/components/del_dialog.pynew file mode 100644index 00000000..ff1b9a92--- /dev/null+++ b/app/components/del_dialog.py@@ -0,0 +1,9 @@+from qfluentwidgets import CheckBox, MessageBox+++class DelDialog(MessageBox):+ def __init__(self, parent=None):+ super().__init__(title="删除下载任务", content="确定要删除下载任务吗?", parent=parent)++ self.checkBox = CheckBox("彻底删除", self)+ self.textLayout.insertWidget(2, self.checkBox)diff --git a/app/components/task_card.py b/app/components/task_card.pyindex b95adcc8..1a83423d 100644--- a/app/components/task_card.py+++ b/app/components/task_card.py@@ -11,6 +11,7 @@ from qfluentwidgets import FluentIcon as FIFfrom shiboken6.Shiboken import deletefrom .Ui_TaskCard import Ui_TaskCard+from .del_dialog import DelDialogfrom .task_progress_bar import TaskProgressBarfrom ..common.config import cfgfrom ..common.download_task import DownloadTask@@ -102,8 +103,7 @@ class TaskCard(CardWidget, Ui_TaskCard):# 连接信号到槽self.pauseButton.clicked.connect(self.pauseTask)- self.delAction.triggered.connect(lambda: self.cancelTask(False))- self.completelyDelAction.triggered.connect(lambda: self.cancelTask(True))+ self.cancelButton.clicked.connect(self.cancelTask)self.folderButton.clicked.connect(lambda: openFile(path))if self.status == "working":@@ -208,49 +208,56 @@ class TaskCard(CardWidget, Ui_TaskCard):@retry(3, 0.1)- def cancelTask(self, completely: bool = False):- self.pauseButton.setDisabled(True)- self.cancelButton.setDisabled(True)+ def cancelTask(self, surely=False, completely=False):- try:- if self.status == "working":- self.pauseTask()+ if not surely:+ dialog = DelDialog(self.window())+ if dialog.exec():+ completely = dialog.checkBox.isChecked()+ surely = True+ dialog.deleteLater()- if completely:- # 删除文件- try:- Path(f"{self.filePath}/{self.fileName}").unlink()- Path(f"{self.filePath}/{self.fileName}.ghd").unlink()- logger.info(f"self:{self.fileName}, delete file successfully!")+ if surely:+ self.pauseButton.setDisabled(True)+ self.cancelButton.setDisabled(True)- except FileNotFoundError:- pass+ try:+ if self.status == "working":+ self.pauseTask()- except Exception as e:- raise e+ if completely:+ # 删除文件+ try:+ Path(f"{self.filePath}/{self.fileName}").unlink()+ Path(f"{self.filePath}/{self.fileName}.ghd").unlink()+ logger.info(f"self:{self.fileName}, delete file successfully!")- except Exception as e:- logger.warning(f"Task:{self.fileName}, 删除时遇到错误: {e}")+ except FileNotFoundError:+ pass- finally:+ except Exception as e:+ raise e- try:- # 删除记录文件- with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "r", encoding="utf-8") as f:- _ = f.read()+ except Exception as e:+ logger.warning(f"Task:{self.fileName}, 删除时遇到错误: {e}")- _ = _.replace(str({"url": self.url, "fileName": self.fileName, "filePath": str(self.filePath),- "blockNum": self.maxBlockNum, "status": self.status}) + "\n", "")+ finally:+ try:+ # 删除记录文件+ with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "r", encoding="utf-8") as f:+ _ = f.read()- with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "w", encoding="utf-8") as f:- f.write(_)+ _ = _.replace(str({"url": self.url, "fileName": self.fileName, "filePath": str(self.filePath),+ "blockNum": self.maxBlockNum, "status": self.status}) + "\n", "")- finally:+ with open("{}/Ghost Downloader 记录文件".format(cfg.appPath), "w", encoding="utf-8") as f:+ f.write(_)- self.status = "canceled"- # Remove Widget- self.parent().parent().parent().expandLayout.removeWidget(self)- self.hide()+ finally:+ self.status = "canceled"+ # Remove Widget+ self.parent().parent().parent().expandLayout.removeWidget(self)+ self.hide()def __changeInfo(self, content: list):# 理论来说 worker 直增不减 所以ProgressBar不用考虑线程减少的问题diff --git a/app/view/task_interface.py b/app/view/task_interface.pyindex feffb817..44eaafae 100644--- a/app/view/task_interface.py+++ b/app/view/task_interface.py@@ -1,10 +1,10 @@from PySide6.QtCore import Qtfrom PySide6.QtWidgets import QWidget, QFrame, QHBoxLayout, QSpacerItem, QSizePolicyfrom qfluentwidgets import FluentIcon as FIF-from qfluentwidgets import ScrollArea, TitleLabel, PrimaryPushButton, PushButton, ExpandLayout, SplitPushButton, \- RoundMenu, Action, InfoBar, InfoBarPosition+from qfluentwidgets import ScrollArea, TitleLabel, PrimaryPushButton, PushButton, ExpandLayout, InfoBar, InfoBarPositionfrom ..common.signal_bus import signalBus+from ..components.del_dialog import DelDialogfrom ..components.task_card import TaskCard@@ -20,7 +20,6 @@ class TaskInterface(ScrollArea):self.allStartButton.clicked.connect(self.allStartTasks)self.allPauseButton.clicked.connect(self.allPauseTasks)self.allDeleteButton.clicked.connect(self.allCancelTasks)- self.completelyDelAction.triggered.connect(lambda: self.allCancelTasks(True))self.setWidget(self.scrollWidget)self.setWidgetResizable(True)@@ -72,15 +71,9 @@ class TaskInterface(ScrollArea):self.allPauseButton.setIcon(FIF.STOP_WATCH)self.horizontalLayout.addWidget(self.allPauseButton)- self.allDeleteButton = SplitPushButton(self.toolsBar)+ self.allDeleteButton = PushButton(self.toolsBar)self.allDeleteButton.setObjectName(u"allDeleteButton")self.allDeleteButton.setIcon(FIF.DELETE)-- self.Menu = RoundMenu(parent=self)- self.completelyDelAction = Action(FIF.CLOSE, "全部彻底删除")- self.Menu.addAction(self.completelyDelAction)- self.allDeleteButton.setFlyout(self.Menu)-self.horizontalLayout.addWidget(self.allDeleteButton)self.horizontalSpacer = QSpacerItem(447, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)@@ -165,9 +158,15 @@ class TaskInterface(ScrollArea):if card.status == "working":card.pauseTask()- def allCancelTasks(self, completely: bool = False):- for card in self.cards:- if card.status == "canceled":- continue+ def allCancelTasks(self):+ dialog = DelDialog(self.window())+ if dialog.exec():+ completely = dialog.checkBox.isChecked()++ for card in self.cards:+ if card.status == "canceled":+ continue++ card.cancelTask(True, completely)- card.cancelTask(completely)+ dialog.deleteLater()