14#include <QApplication>
23#include <QJsonDocument>
30#include <QStandardPaths>
41 themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
49void DownloadItemWidget::setupUI()
51 auto* mainLayout =
new QHBoxLayout(
this);
52 mainLayout->setContentsMargins(8, 8, 8, 8);
53 mainLayout->setSpacing(12);
56 coverLabel_ =
new QLabel(
this);
57 coverLabel_->setFixedSize(48, 48);
58 coverLabel_->setAlignment(Qt::AlignCenter);
59 coverLabel_->setText(
"\u25B6");
60 coverLabel_->setStyleSheet(
"font-size: 24px;");
61 mainLayout->addWidget(coverLabel_);
64 auto* infoLayout =
new QVBoxLayout();
65 infoLayout->setSpacing(4);
67 nameLabel_ =
new QLabel(gameName_,
this);
68 nameLabel_->setStyleSheet(
"font-weight: bold; font-size: 13px;");
69 infoLayout->addWidget(nameLabel_);
71 statusLabel_ =
new QLabel(
"Downloading...",
this);
72 statusLabel_->setStyleSheet(
74 infoLayout->addWidget(statusLabel_);
76 mainLayout->addLayout(infoLayout, 1);
79 auto* progressLayout =
new QVBoxLayout();
80 progressLayout->setSpacing(2);
82 progressBar_ =
new QProgressBar(
this);
83 progressBar_->setRange(0, 1000);
84 progressBar_->setValue(0);
85 progressBar_->setFixedWidth(200);
86 progressBar_->setTextVisible(
false);
87 progressLayout->addWidget(progressBar_);
89 auto* progressInfoLayout =
new QHBoxLayout();
90 progressInfoLayout->setSpacing(8);
92 progressTextLabel_ =
new QLabel(
"0%",
this);
93 progressTextLabel_->setStyleSheet(
"font-size: 11px;");
94 progressInfoLayout->addWidget(progressTextLabel_);
96 speedLabel_ =
new QLabel(
"0 B/s",
this);
97 speedLabel_->setStyleSheet(
99 progressInfoLayout->addWidget(speedLabel_);
101 etaLabel_ =
new QLabel(
"",
this);
102 etaLabel_->setStyleSheet(
104 progressInfoLayout->addWidget(etaLabel_);
106 progressInfoLayout->addStretch();
107 progressLayout->addLayout(progressInfoLayout);
109 mainLayout->addLayout(progressLayout);
112 auto* queueLayout =
new QVBoxLayout();
113 queueLayout->setSpacing(2);
115 moveUpBtn_ =
new QPushButton(
"▲",
this);
116 moveUpBtn_->setFixedSize(24, 24);
117 moveUpBtn_->setToolTip(
"Move up in queue");
118 connect(moveUpBtn_, &QPushButton::clicked,
this, [
this]() { emit
moveUpRequested(appId_); });
119 queueLayout->addWidget(moveUpBtn_);
121 moveDownBtn_ =
new QPushButton(
"▼",
this);
122 moveDownBtn_->setFixedSize(24, 24);
123 moveDownBtn_->setToolTip(
"Move down in queue");
124 connect(moveDownBtn_, &QPushButton::clicked,
this,
126 queueLayout->addWidget(moveDownBtn_);
128 mainLayout->addLayout(queueLayout);
131 auto* actionLayout =
new QVBoxLayout();
132 actionLayout->setSpacing(4);
134 pauseResumeBtn_ =
new QPushButton(
"⏸",
this);
135 pauseResumeBtn_->setFixedSize(32, 32);
136 pauseResumeBtn_->setToolTip(
"Pause download");
137 connect(pauseResumeBtn_, &QPushButton::clicked,
this,
145 actionLayout->addWidget(pauseResumeBtn_);
147 cancelBtn_ =
new QPushButton(
"✕",
this);
148 cancelBtn_->setFixedSize(32, 32);
149 cancelBtn_->setToolTip(
"Cancel download");
150 connect(cancelBtn_, &QPushButton::clicked,
this, [
this]() { emit
cancelRequested(appId_); });
151 actionLayout->addWidget(cancelBtn_);
153 mainLayout->addLayout(actionLayout);
158 progressBar_->setValue(
static_cast<int>(progress * 1000));
159 QString progressText = QString(
"%1% - %2 / %3")
160 .arg(
static_cast<int>(progress * 100))
161 .arg(formatBytes(bytesDownloaded))
162 .arg(formatBytes(totalBytes));
163 progressTextLabel_->setText(progressText);
166 if (lastSpeed_ > 0 && totalBytes > bytesDownloaded)
168 uint64_t remaining = totalBytes - bytesDownloaded;
169 etaLabel_->setText(formatETA(remaining, lastSpeed_));
175 lastSpeed_ = bytesPerSec;
176 speedLabel_->setText(formatSpeed(bytesPerSec));
181 statusLabel_->setText(status);
188 statusLabel_->setText(
"Downloading...");
189 moveUpBtn_->setEnabled(
false);
190 moveDownBtn_->setEnabled(
true);
194 statusLabel_->setText(QString(
"Queued (#%1)").arg(position));
195 moveUpBtn_->setEnabled(position > 1);
196 moveDownBtn_->setEnabled(
true);
205 pauseResumeBtn_->setText(
"▶");
206 pauseResumeBtn_->setToolTip(
"Resume download");
207 statusLabel_->setText(
"Paused");
211 pauseResumeBtn_->setText(
"⏸");
212 pauseResumeBtn_->setToolTip(
"Pause download");
221 QString borderColor = c.
border.name();
223 QString accentColor = c.
accent.name();
225 setStyleSheet(QString(R
"(
227 background-color: %1;
228 border: 1px solid %2;
235 background-color: %2;
240 QProgressBar::chunk {
241 background-color: %4;
245 .arg(bgColor, borderColor, textColor, accentColor));
248QString DownloadItemWidget::formatBytes(uint64_t bytes) const
251 return QString(
"%1 B").arg(bytes);
252 if (bytes < 1024 * 1024)
253 return QString(
"%1 KB").arg(bytes / 1024);
254 if (bytes < 1024ULL * 1024 * 1024)
255 return QString(
"%1 MB").arg(bytes / (1024 * 1024));
256 double gb =
static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0);
257 return QString(
"%1 GB").arg(gb, 0,
'f', 1);
260QString DownloadItemWidget::formatSpeed(
double bytesPerSec)
const
262 if (bytesPerSec < 1024)
263 return QString(
"%1 B/s").arg(
static_cast<int>(bytesPerSec));
264 if (bytesPerSec < 1024 * 1024)
265 return QString(
"%1 KB/s").arg(bytesPerSec / 1024, 0,
'f', 1);
266 return QString(
"%1 MB/s").arg(bytesPerSec / (1024 * 1024), 0,
'f', 1);
269QString DownloadItemWidget::formatETA(uint64_t remaining,
double speed)
const
274 int seconds =
static_cast<int>(
static_cast<double>(remaining) / speed);
276 return QString(
"%1s").arg(seconds);
278 return QString(
"%1m %2s").arg(seconds / 60).arg(seconds % 60);
279 return QString(
"%1h %2m").arg(seconds / 3600).arg((seconds % 3600) / 60);
287 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
289 auto* layout =
new QHBoxLayout(
this);
290 layout->setContentsMargins(12, 8, 12, 8);
291 layout->setSpacing(24);
294 auto* activeLayout =
new QVBoxLayout();
295 auto* activeLabel =
new QLabel(
"Active",
this);
296 activeLabel->setStyleSheet(
297 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
298 activeCountLabel_ =
new QLabel(
"0",
this);
299 activeCountLabel_->setStyleSheet(
"font-size: 18px; font-weight: bold;");
300 activeLayout->addWidget(activeLabel);
301 activeLayout->addWidget(activeCountLabel_);
302 layout->addLayout(activeLayout);
305 auto* queuedLayout =
new QVBoxLayout();
306 auto* queuedLabel =
new QLabel(
"Queued",
this);
307 queuedLabel->setStyleSheet(
308 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
309 queuedCountLabel_ =
new QLabel(
"0",
this);
310 queuedCountLabel_->setStyleSheet(
"font-size: 18px; font-weight: bold;");
311 queuedLayout->addWidget(queuedLabel);
312 queuedLayout->addWidget(queuedCountLabel_);
313 layout->addLayout(queuedLayout);
315 layout->addStretch();
318 auto* speedLayout =
new QVBoxLayout();
319 auto* speedTitleLabel =
new QLabel(
"Speed",
this);
320 speedTitleLabel->setStyleSheet(
321 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
322 speedLabel_ =
new QLabel(
"0 B/s",
this);
323 speedLabel_->setStyleSheet(
"font-size: 14px; font-weight: bold;");
324 speedLayout->addWidget(speedTitleLabel);
325 speedLayout->addWidget(speedLabel_);
326 layout->addLayout(speedLayout);
329 auto* remainingLayout =
new QVBoxLayout();
330 auto* remainingTitleLabel =
new QLabel(
"Remaining",
this);
331 remainingTitleLabel->setStyleSheet(
332 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
333 remainingLabel_ =
new QLabel(
"0 B",
this);
334 remainingLabel_->setStyleSheet(
"font-size: 14px;");
335 remainingLayout->addWidget(remainingTitleLabel);
336 remainingLayout->addWidget(remainingLabel_);
337 layout->addLayout(remainingLayout);
340 auto* etaLayout =
new QVBoxLayout();
341 auto* etaTitleLabel =
new QLabel(
"ETA",
this);
342 etaTitleLabel->setStyleSheet(
343 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
344 etaLabel_ =
new QLabel(
"--",
this);
345 etaLabel_->setStyleSheet(
"font-size: 14px;");
346 etaLayout->addWidget(etaTitleLabel);
347 etaLayout->addWidget(etaLabel_);
348 layout->addLayout(etaLayout);
355 activeCountLabel_->setText(QString::number(count));
360 queuedCountLabel_->setText(QString::number(count));
365 if (bytesPerSec < 1024)
366 speedLabel_->setText(QString(
"%1 B/s").arg(
static_cast<int>(bytesPerSec)));
367 else if (bytesPerSec < 1024 * 1024)
368 speedLabel_->setText(QString(
"%1 KB/s").arg(bytesPerSec / 1024, 0,
'f', 1));
370 speedLabel_->setText(QString(
"%1 MB/s").arg(bytesPerSec / (1024 * 1024), 0,
'f', 1));
376 remainingLabel_->setText(QString(
"%1 B").arg(bytes));
377 else if (bytes < 1024 * 1024)
378 remainingLabel_->setText(QString(
"%1 KB").arg(bytes / 1024));
379 else if (bytes < 1024ULL * 1024 * 1024)
380 remainingLabel_->setText(QString(
"%1 MB").arg(bytes / (1024 * 1024)));
383 double gb =
static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0);
384 remainingLabel_->setText(QString(
"%1 GB").arg(gb, 0,
'f', 1));
392 etaLabel_->setText(
"--");
396 etaLabel_->setText(QString(
"%1s").arg(seconds));
397 else if (seconds < 3600)
398 etaLabel_->setText(QString(
"%1m %2s").arg(seconds / 60).arg(seconds % 60));
400 etaLabel_->setText(QString(
"%1h %2m").arg(seconds / 3600).arg((seconds % 3600) / 60));
408 QString borderColor = c.
border.name();
410 setStyleSheet(QString(R
"(
411 DownloadStatsWidget {
412 background-color: %1;
413 border: 1px solid %2;
417 .arg(bgColor, borderColor));
425 : QWidget(parent), themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
427 auto* layout =
new QVBoxLayout(
this);
428 layout->setContentsMargins(0, 0, 0, 0);
429 layout->setSpacing(8);
431 limitCheckbox_ =
new QCheckBox(
"Limit download bandwidth",
this);
432 connect(limitCheckbox_, &QCheckBox::toggled,
this, &BandwidthControlWidget::onLimitToggled);
433 layout->addWidget(limitCheckbox_);
435 auto* sliderLayout =
new QHBoxLayout();
436 sliderLayout->setSpacing(8);
438 limitSlider_ =
new QSlider(Qt::Horizontal,
this);
439 limitSlider_->setRange(1, 100);
440 limitSlider_->setValue(10);
441 limitSlider_->setEnabled(
false);
442 connect(limitSlider_, &QSlider::valueChanged,
this,
443 &BandwidthControlWidget::onLimitValueChanged);
444 sliderLayout->addWidget(limitSlider_, 1);
446 limitSpinbox_ =
new QSpinBox(
this);
447 limitSpinbox_->setRange(1, 100);
448 limitSpinbox_->setValue(10);
449 limitSpinbox_->setSuffix(
" MB/s");
450 limitSpinbox_->setEnabled(
false);
451 connect(limitSpinbox_, QOverload<int>::of(&QSpinBox::valueChanged), limitSlider_,
453 sliderLayout->addWidget(limitSpinbox_);
455 layout->addLayout(sliderLayout);
457 limitLabel_ =
new QLabel(
"Steam will use unlimited bandwidth",
this);
458 limitLabel_->setStyleSheet(
459 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
460 layout->addWidget(limitLabel_);
467 return limitCheckbox_->isChecked();
472 return limitSpinbox_->value();
475void BandwidthControlWidget::onLimitToggled(
bool checked)
477 limitSlider_->setEnabled(checked);
478 limitSpinbox_->setEnabled(checked);
482 limitLabel_->setText(
483 QString(
"Steam will download at max %1 MB/s").arg(limitSpinbox_->value()));
487 limitLabel_->setText(
"Steam will use unlimited bandwidth");
493void BandwidthControlWidget::onLimitValueChanged(
int value)
495 limitSpinbox_->blockSignals(
true);
496 limitSpinbox_->setValue(value);
497 limitSpinbox_->blockSignals(
false);
499 if (limitCheckbox_->isChecked())
501 limitLabel_->setText(QString(
"Steam will download at max %1 MB/s").arg(value));
518 : QDialog(parent), downloadMonitor_(downloadMonitor), libraryController_(libraryController),
519 themeManager_(themeManager ? themeManager : &
ThemeManager::instance())
521 setWindowTitle(
"Download Queue Manager");
522 setMinimumSize(700, 500);
533 refreshTimer_ =
new QTimer(
this);
534 connect(refreshTimer_, &QTimer::timeout,
this, &DownloadQueueDialog::onRefresh);
535 refreshTimer_->start(2000);
548 QDialog::showEvent(event);
552 refreshTimer_->start(3000);
559 QDialog::hideEvent(event);
563 refreshTimer_->stop();
567void DownloadQueueDialog::setupUI()
569 auto* mainLayout =
new QVBoxLayout(
this);
570 mainLayout->setContentsMargins(16, 16, 16, 16);
571 mainLayout->setSpacing(12);
574 tabWidget_ =
new QTabWidget(
this);
575 mainLayout->addWidget(tabWidget_);
578 activeTab_ =
new QWidget(
this);
579 setupActiveTab(activeTab_);
580 tabWidget_->addTab(activeTab_,
"Active Downloads");
583 updatesTab_ =
new QWidget(
this);
584 setupUpdatesTab(updatesTab_);
585 tabWidget_->addTab(updatesTab_,
"Updates Available");
588 historyTab_ =
new QWidget(
this);
589 setupHistoryTab(historyTab_);
590 tabWidget_->addTab(historyTab_,
"History");
593 settingsTab_ =
new QWidget(
this);
594 setupSettingsTab(settingsTab_);
595 tabWidget_->addTab(settingsTab_,
"Settings");
598 auto* buttonLayout =
new QHBoxLayout();
599 buttonLayout->addStretch();
600 auto* closeBtn =
new QPushButton(
"Close",
this);
601 connect(closeBtn, &QPushButton::clicked,
this, &QDialog::accept);
602 buttonLayout->addWidget(closeBtn);
603 mainLayout->addLayout(buttonLayout);
606void DownloadQueueDialog::setupActiveTab(QWidget* tab)
608 auto* layout =
new QVBoxLayout(tab);
609 layout->setContentsMargins(0, 8, 0, 0);
610 layout->setSpacing(12);
613 statsWidget_ =
new DownloadStatsWidget(
this, themeManager_);
614 layout->addWidget(statsWidget_);
617 const ThemeColors& c = themeManager_->colors();
618 activeEmptyLabel_ =
new QLabel(
"No active downloads.\nSteam manages all game downloads.",
this);
619 activeEmptyLabel_->setAlignment(Qt::AlignCenter);
620 activeEmptyLabel_->setStyleSheet(
621 QString(
"color: %1; font-size: 12px; padding: 40px;").arg(c.
textSecondary.name()));
622 layout->addWidget(activeEmptyLabel_);
625 downloadList_ =
new QListWidget(
this);
626 downloadList_->setSpacing(4);
627 downloadList_->setSelectionMode(QAbstractItemView::NoSelection);
628 layout->addWidget(downloadList_, 1);
631 auto* controlLayout =
new QHBoxLayout();
632 controlLayout->setSpacing(8);
634 pauseAllBtn_ =
new QPushButton(
"Pause All",
this);
635 pauseAllBtn_->setIcon(QIcon::fromTheme(
"media-playback-pause"));
636 connect(pauseAllBtn_, &QPushButton::clicked,
this, &DownloadQueueDialog::onPauseAll);
637 controlLayout->addWidget(pauseAllBtn_);
639 resumeAllBtn_ =
new QPushButton(
"Resume All",
this);
640 resumeAllBtn_->setIcon(QIcon::fromTheme(
"media-playback-start"));
641 connect(resumeAllBtn_, &QPushButton::clicked,
this, &DownloadQueueDialog::onResumeAll);
642 controlLayout->addWidget(resumeAllBtn_);
644 controlLayout->addStretch();
646 refreshBtn_ =
new QPushButton(
"Refresh",
this);
647 refreshBtn_->setIcon(QIcon::fromTheme(
"view-refresh"));
648 connect(refreshBtn_, &QPushButton::clicked,
this, &DownloadQueueDialog::onRefresh);
649 controlLayout->addWidget(refreshBtn_);
651 layout->addLayout(controlLayout);
654void DownloadQueueDialog::setupUpdatesTab(QWidget* tab)
656 const ThemeColors& c = themeManager_->colors();
658 auto* layout =
new QVBoxLayout(tab);
659 layout->setContentsMargins(0, 8, 0, 0);
660 layout->setSpacing(12);
663 auto* updatesInfoLabel =
new QLabel(
664 "Updates are managed by Steam. Click Update to open Steam for the selected game.",
this);
665 updatesInfoLabel->setStyleSheet(
666 QString(
"font-size: 11px; color: %1; padding: 4px 8px;").arg(c.
textSecondary.name()));
667 updatesInfoLabel->setWordWrap(
true);
668 layout->addWidget(updatesInfoLabel);
671 updatesCountLabel_ =
new QLabel(
"Checking for updates...",
this);
672 updatesCountLabel_->setStyleSheet(
673 QString(
"font-size: 13px; font-weight: bold; color: %1; padding: 8px;")
675 layout->addWidget(updatesCountLabel_);
678 updatesList_ =
new QListWidget(
this);
679 updatesList_->setSpacing(4);
680 updatesList_->setSelectionMode(QAbstractItemView::NoSelection);
681 updatesList_->setStyleSheet(
682 QString(
"QListWidget { background-color: %1; border: 1px solid %2; border-radius: 6px; }"
683 "QListWidget::item { background-color: transparent; border-bottom: 1px solid %2; "
685 "QListWidget::item:last-child { border-bottom: none; }")
687 layout->addWidget(updatesList_, 1);
690 auto* controlLayout =
new QHBoxLayout();
691 controlLayout->setSpacing(8);
693 updateAllBtn_ =
new QPushButton(
"Update All via Steam",
this);
694 updateAllBtn_->setObjectName(
"steamUpdateAllBtn");
695 updateAllBtn_->setStyleSheet(
697 "#steamUpdateAllBtn { background-color: %1; color: %2; padding: 10px 20px; "
698 "border-radius: 4px; font-weight: bold; border: 1px solid %3; }"
699 "#steamUpdateAllBtn:hover { background-color: %4; color: %5; border-color: %4; }"
700 "#steamUpdateAllBtn:disabled { background-color: %1; color: %6; border-color: %3; }")
703 connect(updateAllBtn_, &QPushButton::clicked,
this,
707 for (
int i = 0; i < updatesList_->count(); ++i)
709 QListWidgetItem* item = updatesList_->item(i);
710 uint32_t appId = item->data(Qt::UserRole).toUInt();
714 QProcess::startDetached(
"steam",
715 {QString(
"steam://install/%1").arg(appId)});
719 controlLayout->addWidget(updateAllBtn_);
721 controlLayout->addStretch();
723 auto* refreshUpdatesBtn =
new QPushButton(
"Refresh",
this);
724 refreshUpdatesBtn->setIcon(QIcon::fromTheme(
"view-refresh"));
725 connect(refreshUpdatesBtn, &QPushButton::clicked,
this,
726 &DownloadQueueDialog::updateUpdatesList);
727 controlLayout->addWidget(refreshUpdatesBtn);
729 layout->addLayout(controlLayout);
735void DownloadQueueDialog::updateUpdatesList()
737 if (!updatesList_ || !libraryController_)
740 const ThemeColors& c = themeManager_->colors();
742 updatesList_->clear();
746 auto games = libraryController_->getFilteredGames();
747 for (
const auto* game : games)
749 if (!game || game->source !=
GameSource::Steam || game->metadata.steamAppId <= 0)
761 auto* itemWidget =
new QWidget(updatesList_);
762 auto* itemLayout =
new QHBoxLayout(itemWidget);
763 itemLayout->setContentsMargins(8, 4, 8, 4);
764 itemLayout->setSpacing(12);
767 auto* nameLabel =
new QLabel(QString::fromStdString(game->name), itemWidget);
768 nameLabel->setStyleSheet(
769 QString(
"font-weight: bold; color: %1;").arg(c.
textPrimary.name()));
770 itemLayout->addWidget(nameLabel, 1);
773 if (game->metadata.steamBytesToDownload > 0)
776 new QLabel(formatBytes(game->metadata.steamBytesToDownload), itemWidget);
777 sizeLabel->setStyleSheet(QString(
"color: %1;").arg(c.
textSecondary.name()));
778 itemLayout->addWidget(sizeLabel);
782 auto* updateBtn =
new QPushButton(
"Update via Steam", itemWidget);
783 updateBtn->setObjectName(
"steamUpdateBtn");
784 updateBtn->setStyleSheet(
786 "#steamUpdateBtn { background-color: %1; color: %2; padding: 4px 12px; "
787 "border-radius: 3px; border: 1px solid %3; }"
788 "#steamUpdateBtn:hover { background-color: %4; color: %5; border-color: %4; }")
791 uint32_t appId =
static_cast<uint32_t
>(game->metadata.steamAppId);
792 connect(updateBtn, &QPushButton::clicked,
this,
796 QProcess::startDetached(
"steam",
797 {QString(
"steam://install/%1").arg(appId)});
799 itemLayout->addWidget(updateBtn);
802 auto* item =
new QListWidgetItem(updatesList_);
803 item->setData(Qt::UserRole, appId);
804 item->setSizeHint(itemWidget->sizeHint());
805 updatesList_->setItemWidget(item, itemWidget);
810 if (updateCount == 0)
812 updatesCountLabel_->setText(
"✓ All games are up to date");
813 updatesCountLabel_->setStyleSheet(
814 QString(
"font-size: 13px; font-weight: bold; color: %1; padding: 8px;")
816 updateAllBtn_->setEnabled(
false);
820 updatesCountLabel_->setText(QString(
"⬆ %1 game%2 %3 updates available")
822 .arg(updateCount == 1 ?
"" :
"s")
823 .arg(updateCount == 1 ?
"has" :
"have"));
824 updatesCountLabel_->setStyleSheet(
825 QString(
"font-size: 13px; font-weight: bold; color: %1; padding: 8px;")
827 updateAllBtn_->setEnabled(
true);
831 if (tabWidget_ && updatesTab_)
833 int tabIndex = tabWidget_->indexOf(updatesTab_);
837 tabWidget_->setTabText(tabIndex,
838 QString(
"Updates Available (%1)").arg(updateCount));
840 tabWidget_->setTabText(tabIndex,
"Updates Available");
845void DownloadQueueDialog::setupHistoryTab(QWidget* tab)
847 auto* layout =
new QVBoxLayout(tab);
848 layout->setContentsMargins(0, 8, 0, 0);
849 layout->setSpacing(12);
852 historyStatsLabel_ =
new QLabel(
"No download history",
this);
853 historyStatsLabel_->setStyleSheet(
854 "font-size: 12px; color: " + themeManager_->colors().textSecondary.name() +
";");
855 layout->addWidget(historyStatsLabel_);
858 historyList_ =
new QListWidget(
this);
859 historyList_->setSpacing(2);
860 layout->addWidget(historyList_, 1);
863 auto* buttonLayout =
new QHBoxLayout();
864 buttonLayout->addStretch();
865 clearHistoryBtn_ =
new QPushButton(
"Clear History",
this);
866 connect(clearHistoryBtn_, &QPushButton::clicked,
this, &DownloadQueueDialog::onClearCompleted);
867 buttonLayout->addWidget(clearHistoryBtn_);
868 layout->addLayout(buttonLayout);
871void DownloadQueueDialog::setupSettingsTab(QWidget* tab)
873 auto* layout =
new QVBoxLayout(tab);
874 layout->setContentsMargins(0, 8, 0, 0);
875 layout->setSpacing(16);
878 auto* bandwidthGroup =
new QGroupBox(
"Steam Bandwidth Preference",
this);
879 auto* bandwidthLayout =
new QVBoxLayout(bandwidthGroup);
880 bandwidthWidget_ =
new BandwidthControlWidget(
this, themeManager_);
882 &DownloadQueueDialog::onBandwidthLimitChanged);
883 bandwidthLayout->addWidget(bandwidthWidget_);
884 layout->addWidget(bandwidthGroup);
887 auto* behaviorGroup =
new QGroupBox(
"Behavior",
this);
888 auto* behaviorLayout =
new QVBoxLayout(behaviorGroup);
890 autoStartCheckbox_ =
new QCheckBox(
"Auto-start downloads when Steam is running",
this);
891 autoStartCheckbox_->setChecked(
true);
892 behaviorLayout->addWidget(autoStartCheckbox_);
894 notifyCompleteCheckbox_ =
new QCheckBox(
"Show notification when downloads complete",
this);
895 notifyCompleteCheckbox_->setChecked(
true);
896 behaviorLayout->addWidget(notifyCompleteCheckbox_);
898 layout->addWidget(behaviorGroup);
901 auto* infoLabel =
new QLabel(
902 "Note: Bandwidth is controlled by Steam. This sets a preference that "
903 "Steam may apply. Queue priority changes are managed through Steam's download queue.",
905 infoLabel->setStyleSheet(
906 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() +
";");
907 infoLabel->setWordWrap(
true);
908 layout->addWidget(infoLabel);
910 layout->addStretch();
913void DownloadQueueDialog::updateDownloadList()
919 std::set<uint32_t> existingAppIds;
920 for (
int i = 0; i < downloadList_->count(); ++i)
922 auto* item = downloadList_->item(i);
923 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
925 existingAppIds.insert(widget->appId());
930 for (uint32_t appId : downloadingGames)
932 if (existingAppIds.find(appId) == existingAppIds.end())
935 QString gameName = QString(
"App %1").arg(appId);
936 if (libraryController_)
939 auto allGames = libraryController_->getFilteredGames();
940 for (
const auto* game : allGames)
943 static_cast<uint32_t
>(game->metadata.steamAppId) == appId)
945 gameName = QString::fromStdString(game->name);
951 addDownloadItem(appId, gameName, position);
957 for (uint32_t appId : existingAppIds)
959 if (std::find(downloadingGames.begin(), downloadingGames.end(), appId) ==
960 downloadingGames.end())
962 removeDownloadItem(appId);
967 for (
int i = 0; i < downloadList_->count(); ++i)
969 auto* item = downloadList_->item(i);
970 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
975 if (progress.bytesToDownload > 0)
977 widget->setProgress(progress.overallProgress, progress.bytesDownloaded,
978 progress.bytesToDownload);
979 widget->setSpeed(progress.downloadSpeedBytesPerSec);
980 widget->setStatus(QString::fromStdString(progress.stateDescription));
981 widget->setQueuePosition(i);
986 if (activeEmptyLabel_)
988 bool hasDownloads = downloadList_->count() > 0;
989 activeEmptyLabel_->setVisible(!hasDownloads);
990 downloadList_->setVisible(hasDownloads);
994void DownloadQueueDialog::updateStats()
998 int activeCount = downloadingGames.empty() ? 0 : 1;
1000 downloadingGames.size() > 1 ?
static_cast<int>(downloadingGames.size()) - 1 : 0;
1002 double totalSpeed = 0.0;
1003 uint64_t totalRemaining = 0;
1005 for (uint32_t appId : downloadingGames)
1008 totalSpeed += progress.downloadSpeedBytesPerSec;
1009 if (progress.bytesToDownload > progress.bytesDownloaded)
1010 totalRemaining += progress.bytesToDownload - progress.bytesDownloaded;
1013 statsWidget_->setActiveCount(activeCount);
1014 statsWidget_->setQueuedCount(queuedCount);
1015 statsWidget_->setTotalSpeed(totalSpeed);
1016 statsWidget_->setTotalRemaining(totalRemaining);
1018 if (totalSpeed > 0 && totalRemaining > 0)
1020 int eta =
static_cast<int>(
static_cast<double>(totalRemaining) / totalSpeed);
1021 statsWidget_->setEstimatedTime(eta);
1025 statsWidget_->setEstimatedTime(0);
1029 bool hasDownloads = !downloadingGames.empty();
1030 pauseAllBtn_->setEnabled(hasDownloads && !allPaused_);
1031 resumeAllBtn_->setEnabled(hasDownloads && allPaused_);
1034void DownloadQueueDialog::addDownloadItem(uint32_t appId,
const QString& gameName,
1037 auto* widget =
new DownloadItemWidget(appId, gameName,
this, themeManager_);
1038 widget->setQueuePosition(queuePosition);
1042 &DownloadQueueDialog::onPauseRequested);
1044 &DownloadQueueDialog::onResumeRequested);
1046 &DownloadQueueDialog::onCancelRequested);
1048 &DownloadQueueDialog::onMoveUpRequested);
1050 &DownloadQueueDialog::onMoveDownRequested);
1052 &DownloadQueueDialog::onOpenInSteamRequested);
1054 auto* item =
new QListWidgetItem(downloadList_);
1055 item->setSizeHint(QSize(0, 80));
1056 downloadList_->addItem(item);
1057 downloadList_->setItemWidget(item, widget);
1060void DownloadQueueDialog::removeDownloadItem(uint32_t appId)
1062 for (
int i = 0; i < downloadList_->count(); ++i)
1064 auto* item = downloadList_->item(i);
1065 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1066 if (widget && widget->appId() == appId)
1070 if (progress.isComplete)
1072 addToHistory(appId, widget->gameName(), progress.bytesToDownload, 0,
1076 delete downloadList_->takeItem(i);
1084 for (
int i = 0; i < downloadList_->count(); ++i)
1086 auto* item = downloadList_->item(i);
1087 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1088 if (widget && widget->appId() == appId)
1094void DownloadQueueDialog::loadHistory()
1096 QString historyPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
1097 "/download_history.json";
1099 QFile file(historyPath);
1100 if (!file.open(QIODevice::ReadOnly))
1103 QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
1107 downloadHistory_.clear();
1108 for (
const QJsonValue val : doc.array())
1110 QJsonObject obj = val.toObject();
1111 DownloadHistoryItem item;
1112 item.
appId =
static_cast<uint32_t
>(obj[
"appId"].toInt());
1113 item.
gameName = obj[
"gameName"].toString();
1114 item.
totalBytes = obj[
"totalBytes"].toVariant().toULongLong();
1115 item.
completedAt = QDateTime::fromString(obj[
"completedAt"].toString(), Qt::ISODate);
1118 item.
wasUpdate = obj[
"wasUpdate"].toBool();
1119 downloadHistory_.push_back(item);
1123 historyList_->clear();
1124 for (
const auto& item : downloadHistory_)
1126 QString text = QString(
"%1 - %2 (%3)")
1129 .arg(item.
completedAt.toString(
"yyyy-MM-dd hh:mm"));
1130 historyList_->addItem(text);
1134 if (!downloadHistory_.empty())
1136 uint64_t totalBytes = 0;
1137 for (
const auto& item : downloadHistory_)
1140 historyStatsLabel_->setText(QString(
"%1 downloads, %2 total")
1141 .arg(downloadHistory_.size())
1142 .arg(formatBytes(totalBytes)));
1146void DownloadQueueDialog::saveHistory()
1148 QString dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
1149 QDir().mkpath(dataPath);
1151 QString historyPath = dataPath +
"/download_history.json";
1154 for (
const auto& item : downloadHistory_)
1157 obj[
"appId"] =
static_cast<int>(item.
appId);
1159 obj[
"totalBytes"] =
static_cast<qint64
>(item.
totalBytes);
1160 obj[
"completedAt"] = item.
completedAt.toString(Qt::ISODate);
1167 QFile file(historyPath);
1168 if (file.open(QIODevice::WriteOnly))
1170 file.write(QJsonDocument(arr).toJson(QJsonDocument::Compact));
1174void DownloadQueueDialog::addToHistory(uint32_t appId,
const QString& gameName, uint64_t bytes,
1175 int duration,
bool wasUpdate)
1177 DownloadHistoryItem item;
1183 item.
averageSpeed = duration > 0 ?
static_cast<double>(bytes) / duration : 0;
1186 downloadHistory_.insert(downloadHistory_.begin(), item);
1189 if (downloadHistory_.size() > 100)
1190 downloadHistory_.resize(100);
1193 QString text = QString(
"%1 - %2 (%3)")
1195 .arg(formatBytes(bytes))
1196 .arg(item.
completedAt.toString(
"yyyy-MM-dd hh:mm"));
1197 historyList_->insertItem(0, text);
1200 uint64_t totalBytes = 0;
1201 for (
const auto& h : downloadHistory_)
1202 totalBytes += h.totalBytes;
1204 historyStatsLabel_->setText(QString(
"%1 downloads, %2 total")
1205 .arg(downloadHistory_.size())
1206 .arg(formatBytes(totalBytes)));
1209QString DownloadQueueDialog::formatBytes(uint64_t bytes)
const
1212 return QString(
"%1 B").arg(bytes);
1213 if (bytes < 1024 * 1024)
1214 return QString(
"%1 KB").arg(bytes / 1024);
1215 if (bytes < 1024ULL * 1024 * 1024)
1216 return QString(
"%1 MB").arg(bytes / (1024 * 1024));
1217 double gb =
static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0);
1218 return QString(
"%1 GB").arg(gb, 0,
'f', 2);
1221QString DownloadQueueDialog::formatDuration(
int seconds)
const
1224 return QString(
"%1s").arg(seconds);
1226 return QString(
"%1m %2s").arg(seconds / 60).arg(seconds % 60);
1227 return QString(
"%1h %2m").arg(seconds / 3600).arg((seconds % 3600) / 60);
1232void DownloadQueueDialog::onRefresh()
1234 updateDownloadList();
1238void DownloadQueueDialog::onPauseAll()
1241 QProcess::startDetached(
"steam", {
"steam://pausedownloads"});
1245 for (
int i = 0; i < downloadList_->count(); ++i)
1247 auto* item = downloadList_->item(i);
1248 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1250 widget->setPaused(
true);
1253 pauseAllBtn_->setEnabled(
false);
1254 resumeAllBtn_->setEnabled(
true);
1257void DownloadQueueDialog::onResumeAll()
1259 QProcess::startDetached(
"steam", {
"steam://resumedownloads"});
1263 for (
int i = 0; i < downloadList_->count(); ++i)
1265 auto* item = downloadList_->item(i);
1266 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1268 widget->setPaused(
false);
1271 pauseAllBtn_->setEnabled(
true);
1272 resumeAllBtn_->setEnabled(
false);
1275void DownloadQueueDialog::onClearCompleted()
1277 downloadHistory_.clear();
1278 historyList_->clear();
1279 historyStatsLabel_->setText(
"No download history");
1283void DownloadQueueDialog::onPauseRequested(uint32_t appId)
1286 QProcess::startDetached(
"steam", {QString(
"steam://pausedownload/%1").arg(appId)});
1288 if (
auto* widget = findDownloadItem(appId))
1289 widget->setPaused(
true);
1294void DownloadQueueDialog::onResumeRequested(uint32_t appId)
1296 QProcess::startDetached(
"steam", {QString(
"steam://resumedownload/%1").arg(appId)});
1298 if (
auto* widget = findDownloadItem(appId))
1299 widget->setPaused(
false);
1304void DownloadQueueDialog::onCancelRequested(uint32_t appId)
1306 auto* widget = findDownloadItem(appId);
1307 QString gameName = widget ? widget->gameName() : QString(
"App %1").arg(appId);
1309 auto result = QMessageBox::question(
1310 this,
"Cancel Download",
1311 QString(
"Are you sure you want to cancel the download for %1?").arg(gameName),
1312 QMessageBox::Yes | QMessageBox::No);
1314 if (result == QMessageBox::Yes)
1317 QProcess::startDetached(
"steam", {QString(
"steam://uninstall/%1").arg(appId)});
1322void DownloadQueueDialog::onMoveUpRequested(uint32_t )
1326 QProcess::startDetached(
"steam", {
"steam://nav/downloads"});
1330void DownloadQueueDialog::onMoveDownRequested(uint32_t )
1332 QProcess::startDetached(
"steam", {
"steam://nav/downloads"});
1335void DownloadQueueDialog::onOpenInSteamRequested(uint32_t appId)
1337 QProcess::startDetached(
"steam", {QString(
"steam://nav/games/details/%1").arg(appId)});
1340void DownloadQueueDialog::onBandwidthLimitChanged(
bool enabled,
int mbps)
1348void DownloadQueueDialog::onDownloadProgress(uint32_t appId,
double progress,
const QString& status)
1350 if (
auto* widget = findDownloadItem(appId))
1353 widget->setProgress(progress, progressInfo.bytesDownloaded, progressInfo.bytesToDownload);
1354 widget->setSpeed(progressInfo.downloadSpeedBytesPerSec);
1355 widget->setStatus(status);
1359void DownloadQueueDialog::onDownloadComplete(uint32_t appId)
1361 removeDownloadItem(appId);
1365void DownloadQueueDialog::applyTheme()
1367 const ThemeColors& c = themeManager_->colors();
1372 QString borderColor = c.
border.name();
1374 setStyleSheet(QString(R
"(
1375 DownloadQueueDialog {
1376 background-color: %1;
1380 background-color: %1;
1381 border: 1px solid %4;
1385 background-color: %3;
1388 border: 1px solid %4;
1389 border-bottom: none;
1390 border-top-left-radius: 6px;
1391 border-top-right-radius: 6px;
1393 QTabBar::tab:selected {
1394 background-color: %1;
1397 background-color: %1;
1398 border: 1px solid %4;
1402 background-color: transparent;
1406 background-color: %3;
1408 border: 1px solid %4;
1413 background-color: %4;
1415 QPushButton:disabled {
1420 border: 1px solid %4;
1426 subcontrol-origin: margin;
1433 QSlider::groove:horizontal {
1438 QSlider::handle:horizontal {
1445 background-color: %3;
1447 border: 1px solid %4;
1452 .arg(bgColor, textColor, surfaceColor, borderColor));
1456 statsWidget_->applyTheme();
1458 for (
int i = 0; i < downloadList_->count(); ++i)
1460 auto* item = downloadList_->item(i);
1461 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1463 widget->applyTheme();
void showEvent(QShowEvent *event) override
void downloadResumed(uint32_t appId)
void hideEvent(QHideEvent *event) override
void downloadPaused(uint32_t appId)
void downloadCancelled(uint32_t appId)
~DownloadQueueDialog() override
DownloadQueueDialog(SteamDownloadMonitor *downloadMonitor, core::GameLibraryController *libraryController, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
Monitors Steam download/install progress for games.
static std::vector< uint32_t > getDownloadingGames()
Get list of all games currently downloading.
static SteamDownloadProgress readGameState(uint32_t appId)
Read current state of a game directly from its appmanifest.
void themeChanged()
Emitted when theme or accent color changes.
const ThemeColors & colors() const
Get effective colors (with accent customization applied).
@ Steam
Steam store/platform.
bool needsUpdate(uint32_t flags)
Check if a game needs an update.