Skip to content

The only downloader you need. 下载器的集大成者。

refactor(cards): 优化任务状态信息显示逻辑

XiaoYouChR8c2ba85692ec
diff --git a/app/view/components/cards.py b/app/view/components/cards.py
index a0700fb9..a278caff 100644
--- a/app/view/components/cards.py
+++ b/app/view/components/cards.py
@@ -243,7 +243,7 @@ class UniversalTaskCard(TaskCard):
super().__init__(task, parent)
self.setFixedHeight(60)
self.task = task
- self.cardStatus = self.task.status
+ self.cardStatus: TaskStatus = self.task.status
self.hBoxLayout = QHBoxLayout(self)
self.iconLabel = ImageLabel(self)
@@ -311,6 +311,15 @@ class UniversalTaskCard(TaskCard):
self.infoLabel.setText(text)
self.infoLabel.show()
+ def statusInfoText(self) -> str | None:
+ if self.task.status == TaskStatus.COMPLETED:
+ return self.tr("任务已经完成")
+ if self.task.status == TaskStatus.PAUSED:
+ return self.tr("任务已经暂停")
+ if self.task.status == TaskStatus.WAITING:
+ return self.tr("任务正在等待")
+ return None
+
def _renderTaskState(self):
division = len(self.task.stages)
progress = 0
@@ -351,18 +360,18 @@ class UniversalTaskCard(TaskCard):
self.progressBar.hide()
else:
self.progressBar.stop()
- self.showStatusInfo(self.tr("任务已经完成"))
+ self.showStatusInfo(self.statusInfoText() or "")
elif self.task.status == TaskStatus.FAILED:
self.progressBar.error()
self.onTaskFailed()
elif self.task.status == TaskStatus.PAUSED:
self.progressBar.setError(False)
self.progressBar.pause()
- self.showStatusInfo(self.tr("任务已经暂停"))
+ self.showStatusInfo(self.statusInfoText() or "")
else:
self.progressBar.setError(False)
self.progressBar.pause()
- self.showStatusInfo(self.tr("任务正在等待"))
+ self.showStatusInfo(self.statusInfoText() or "")
self.refreshToggleButton()
diff --git a/features/ftp_pack/cards.py b/features/ftp_pack/cards.py
index fc20b837..75d8ddb2 100644
--- a/features/ftp_pack/cards.py
+++ b/features/ftp_pack/cards.py
@@ -500,6 +500,19 @@ class FtpTaskCard(UniversalTaskCard):
return
openFolder(str(target.parent))
+ def statusInfoText(self) -> str | None:
+ if self.task.status == TaskStatus.PAUSED:
+ return super().statusInfoText()
+
+ if self.task.status in {TaskStatus.WAITING, TaskStatus.COMPLETED}:
+ if self.task.totalFileCount > 1 or self.task.isDirectorySource:
+ return self.tr("{0}/{1} 个文件").format(
+ self.task.selectedFileCount,
+ self.task.totalFileCount,
+ )
+
+ return super().statusInfoText()
+
def _renderTaskState(self):
super()._renderTaskState()
@@ -520,15 +533,6 @@ class FtpTaskCard(UniversalTaskCard):
elif self.task.fileSize > 0:
self.leftTimeLabel.setText("--")
- if self.task.status in {TaskStatus.WAITING, TaskStatus.PAUSED, TaskStatus.COMPLETED}:
- if self.task.totalFileCount > 1 or self.task.isDirectorySource:
- self.showStatusInfo(
- self.tr("{0}/{1} 个文件").format(
- self.task.selectedFileCount,
- self.task.totalFileCount,
- )
- )
-
def _onSelectFilesClicked(self):
if self.task.status == TaskStatus.RUNNING:
return