game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
download_queue_dialog.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// ==============================================================================
3// download_queue_dialog.cpp
4// ==============================================================================
5// Download Queue Manager Dialog - Implementation
6// ==============================================================================
7
11#include "models/game.h"
12#include "theme_manager.h"
13
14#include <QApplication>
15#include <QCheckBox>
16#include <QDateTime>
17#include <QDir>
18#include <QFile>
19#include <QGroupBox>
20#include <QHBoxLayout>
21#include <QHeaderView>
22#include <QJsonArray>
23#include <QJsonDocument>
24#include <QJsonObject>
25#include <QMessageBox>
26#include <QProcess>
27#include <QScrollArea>
28#include <QSlider>
29#include <QSpinBox>
30#include <QStandardPaths>
31#include <QUrl>
32#include <QVBoxLayout>
33
34// ==============================================================================
35// DownloadItemWidget Implementation
36// ==============================================================================
37
38DownloadItemWidget::DownloadItemWidget(uint32_t appId, const QString& gameName, QWidget* parent,
39 ThemeManager* themeManager)
40 : QWidget(parent), appId_(appId), gameName_(gameName),
41 themeManager_(themeManager ? themeManager : &ThemeManager::instance())
42{
43 setupUI();
44 applyTheme();
45}
46
48
49void DownloadItemWidget::setupUI()
50{
51 auto* mainLayout = new QHBoxLayout(this);
52 mainLayout->setContentsMargins(8, 8, 8, 8);
53 mainLayout->setSpacing(12);
54
55 // Cover art placeholder (small)
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_);
62
63 // Info column
64 auto* infoLayout = new QVBoxLayout();
65 infoLayout->setSpacing(4);
66
67 nameLabel_ = new QLabel(gameName_, this);
68 nameLabel_->setStyleSheet("font-weight: bold; font-size: 13px;");
69 infoLayout->addWidget(nameLabel_);
70
71 statusLabel_ = new QLabel("Downloading...", this);
72 statusLabel_->setStyleSheet(
73 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() + ";");
74 infoLayout->addWidget(statusLabel_);
75
76 mainLayout->addLayout(infoLayout, 1);
77
78 // Progress column
79 auto* progressLayout = new QVBoxLayout();
80 progressLayout->setSpacing(2);
81
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_);
88
89 auto* progressInfoLayout = new QHBoxLayout();
90 progressInfoLayout->setSpacing(8);
91
92 progressTextLabel_ = new QLabel("0%", this);
93 progressTextLabel_->setStyleSheet("font-size: 11px;");
94 progressInfoLayout->addWidget(progressTextLabel_);
95
96 speedLabel_ = new QLabel("0 B/s", this);
97 speedLabel_->setStyleSheet(
98 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() + ";");
99 progressInfoLayout->addWidget(speedLabel_);
100
101 etaLabel_ = new QLabel("", this);
102 etaLabel_->setStyleSheet(
103 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() + ";");
104 progressInfoLayout->addWidget(etaLabel_);
105
106 progressInfoLayout->addStretch();
107 progressLayout->addLayout(progressInfoLayout);
108
109 mainLayout->addLayout(progressLayout);
110
111 // Queue position controls
112 auto* queueLayout = new QVBoxLayout();
113 queueLayout->setSpacing(2);
114
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_);
120
121 moveDownBtn_ = new QPushButton("▼", this);
122 moveDownBtn_->setFixedSize(24, 24);
123 moveDownBtn_->setToolTip("Move down in queue");
124 connect(moveDownBtn_, &QPushButton::clicked, this,
125 [this]() { emit moveDownRequested(appId_); });
126 queueLayout->addWidget(moveDownBtn_);
127
128 mainLayout->addLayout(queueLayout);
129
130 // Action buttons
131 auto* actionLayout = new QVBoxLayout();
132 actionLayout->setSpacing(4);
133
134 pauseResumeBtn_ = new QPushButton("⏸", this);
135 pauseResumeBtn_->setFixedSize(32, 32);
136 pauseResumeBtn_->setToolTip("Pause download");
137 connect(pauseResumeBtn_, &QPushButton::clicked, this,
138 [this]()
139 {
140 if (isPaused_)
141 emit resumeRequested(appId_);
142 else
143 emit pauseRequested(appId_);
144 });
145 actionLayout->addWidget(pauseResumeBtn_);
146
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_);
152
153 mainLayout->addLayout(actionLayout);
154}
155
156void DownloadItemWidget::setProgress(double progress, uint64_t bytesDownloaded, uint64_t totalBytes)
157{
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);
164
165 // Update ETA if we have speed
166 if (lastSpeed_ > 0 && totalBytes > bytesDownloaded)
167 {
168 uint64_t remaining = totalBytes - bytesDownloaded;
169 etaLabel_->setText(formatETA(remaining, lastSpeed_));
170 }
171}
172
173void DownloadItemWidget::setSpeed(double bytesPerSec)
174{
175 lastSpeed_ = bytesPerSec;
176 speedLabel_->setText(formatSpeed(bytesPerSec));
177}
178
179void DownloadItemWidget::setStatus(const QString& status)
180{
181 statusLabel_->setText(status);
182}
183
185{
186 if (position == 0)
187 {
188 statusLabel_->setText("Downloading...");
189 moveUpBtn_->setEnabled(false);
190 moveDownBtn_->setEnabled(true);
191 }
192 else
193 {
194 statusLabel_->setText(QString("Queued (#%1)").arg(position));
195 moveUpBtn_->setEnabled(position > 1);
196 moveDownBtn_->setEnabled(true);
197 }
198}
199
201{
202 isPaused_ = paused;
203 if (paused)
204 {
205 pauseResumeBtn_->setText("▶");
206 pauseResumeBtn_->setToolTip("Resume download");
207 statusLabel_->setText("Paused");
208 }
209 else
210 {
211 pauseResumeBtn_->setText("⏸");
212 pauseResumeBtn_->setToolTip("Pause download");
213 }
214}
215
217{
218 const ThemeColors& c = themeManager_->colors();
219
220 QString bgColor = c.cardBackground.name();
221 QString borderColor = c.border.name();
222 QString textColor = c.textPrimary.name();
223 QString accentColor = c.accent.name();
224
225 setStyleSheet(QString(R"(
226 DownloadItemWidget {
227 background-color: %1;
228 border: 1px solid %2;
229 border-radius: 6px;
230 }
231 QLabel {
232 color: %3;
233 }
234 QProgressBar {
235 background-color: %2;
236 border: none;
237 border-radius: 3px;
238 height: 6px;
239 }
240 QProgressBar::chunk {
241 background-color: %4;
242 border-radius: 3px;
243 }
244 )")
245 .arg(bgColor, borderColor, textColor, accentColor));
246}
247
248QString DownloadItemWidget::formatBytes(uint64_t bytes) const
249{
250 if (bytes < 1024)
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);
258}
259
260QString DownloadItemWidget::formatSpeed(double bytesPerSec) const
261{
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);
268
269QString DownloadItemWidget::formatETA(uint64_t remaining, double speed) const
270{
271 if (speed <= 0)
272 return "";
273
274 int seconds = static_cast<int>(static_cast<double>(remaining) / speed);
275 if (seconds < 60)
276 return QString("%1s").arg(seconds);
277 if (seconds < 3600)
278 return QString("%1m %2s").arg(seconds / 60).arg(seconds % 60);
279 return QString("%1h %2m").arg(seconds / 3600).arg((seconds % 3600) / 60);
280}
281
282// ==============================================================================
283// DownloadStatsWidget Implementation
284// ==============================================================================
285
286DownloadStatsWidget::DownloadStatsWidget(QWidget* parent, ThemeManager* themeManager)
287 : QWidget(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
288{
289 auto* layout = new QHBoxLayout(this);
290 layout->setContentsMargins(12, 8, 12, 8);
291 layout->setSpacing(24);
292
293 // Active downloads
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);
303
304 // Queued downloads
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);
314
315 layout->addStretch();
316
317 // Download speed
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);
327
328 // Remaining
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);
338
339 // ETA
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);
349
350 applyTheme();
351}
352
355 activeCountLabel_->setText(QString::number(count));
356}
357
359{
360 queuedCountLabel_->setText(QString::number(count));
361}
362
363void DownloadStatsWidget::setTotalSpeed(double bytesPerSec)
364{
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));
369 else
370 speedLabel_->setText(QString("%1 MB/s").arg(bytesPerSec / (1024 * 1024), 0, 'f', 1));
371}
372
374{
375 if (bytes < 1024)
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)));
381 else
382 {
383 double gb = static_cast<double>(bytes) / (1024.0 * 1024.0 * 1024.0);
384 remainingLabel_->setText(QString("%1 GB").arg(gb, 0, 'f', 1));
385 }
386}
387
389{
390 if (seconds <= 0)
391 {
392 etaLabel_->setText("--");
393 return;
394 }
395 if (seconds < 60)
396 etaLabel_->setText(QString("%1s").arg(seconds));
397 else if (seconds < 3600)
398 etaLabel_->setText(QString("%1m %2s").arg(seconds / 60).arg(seconds % 60));
399 else
400 etaLabel_->setText(QString("%1h %2m").arg(seconds / 3600).arg((seconds % 3600) / 60));
401}
402
404{
405 const ThemeColors& c = themeManager_->colors();
406
407 QString bgColor = c.cardBackground.name();
408 QString borderColor = c.border.name();
409
410 setStyleSheet(QString(R"(
411 DownloadStatsWidget {
412 background-color: %1;
413 border: 1px solid %2;
414 border-radius: 6px;
415 }
416 )")
417 .arg(bgColor, borderColor));
418}
419
420// ==============================================================================
421// BandwidthControlWidget Implementation
422// ==============================================================================
423
425 : QWidget(parent), themeManager_(themeManager ? themeManager : &ThemeManager::instance())
426{
427 auto* layout = new QVBoxLayout(this);
428 layout->setContentsMargins(0, 0, 0, 0);
429 layout->setSpacing(8);
430
431 limitCheckbox_ = new QCheckBox("Limit download bandwidth", this);
432 connect(limitCheckbox_, &QCheckBox::toggled, this, &BandwidthControlWidget::onLimitToggled);
433 layout->addWidget(limitCheckbox_);
434
435 auto* sliderLayout = new QHBoxLayout();
436 sliderLayout->setSpacing(8);
437
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_,
452 &QSlider::setValue);
453 sliderLayout->addWidget(limitSpinbox_);
454
455 layout->addLayout(sliderLayout);
456
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_);
461
462 applyTheme();
463}
464
466{
467 return limitCheckbox_->isChecked();
468}
469
471{
472 return limitSpinbox_->value();
473}
474
475void BandwidthControlWidget::onLimitToggled(bool checked)
476{
477 limitSlider_->setEnabled(checked);
478 limitSpinbox_->setEnabled(checked);
479
480 if (checked)
482 limitLabel_->setText(
483 QString("Steam will download at max %1 MB/s").arg(limitSpinbox_->value()));
484 }
485 else
486 {
487 limitLabel_->setText("Steam will use unlimited bandwidth");
488 }
489
490 emit limitChanged(checked, limitSpinbox_->value());
491}
492
493void BandwidthControlWidget::onLimitValueChanged(int value)
494{
495 limitSpinbox_->blockSignals(true);
496 limitSpinbox_->setValue(value);
497 limitSpinbox_->blockSignals(false);
498
499 if (limitCheckbox_->isChecked())
500 {
501 limitLabel_->setText(QString("Steam will download at max %1 MB/s").arg(value));
502 emit limitChanged(true, value);
503 }
504}
505
507{
508 // Uses parent theming
509}
510
511// ==============================================================================
512// DownloadQueueDialog Implementation
513// ==============================================================================
514
516 core::GameLibraryController* libraryController,
517 QWidget* parent, ThemeManager* themeManager)
518 : QDialog(parent), downloadMonitor_(downloadMonitor), libraryController_(libraryController),
519 themeManager_(themeManager ? themeManager : &ThemeManager::instance())
520{
521 setWindowTitle("Download Queue Manager");
522 setMinimumSize(700, 500);
523 resize(800, 600);
524
525 setupUI();
526 loadHistory();
527 applyTheme();
528
529 // Connect to theme changes
530 connect(themeManager_, &ThemeManager::themeChanged, this, &DownloadQueueDialog::applyTheme);
531
532 // Set up refresh timer
533 refreshTimer_ = new QTimer(this);
534 connect(refreshTimer_, &QTimer::timeout, this, &DownloadQueueDialog::onRefresh);
535 refreshTimer_->start(2000); // Refresh every 2 seconds
536
537 // Initial refresh
538 onRefresh();
539}
540
542{
543 saveHistory();
544}
545
546void DownloadQueueDialog::showEvent(QShowEvent* event)
547{
548 QDialog::showEvent(event);
549 // Start timer when dialog becomes visible
550 if (refreshTimer_)
551 {
552 refreshTimer_->start(3000); // Match download monitor poll interval
553 }
554 onRefresh(); // Immediate refresh on show
555}
556
557void DownloadQueueDialog::hideEvent(QHideEvent* event)
558{
559 QDialog::hideEvent(event);
560 // Stop timer when dialog is hidden to save CPU
561 if (refreshTimer_)
562 {
563 refreshTimer_->stop();
564 }
565}
566
567void DownloadQueueDialog::setupUI()
568{
569 auto* mainLayout = new QVBoxLayout(this);
570 mainLayout->setContentsMargins(16, 16, 16, 16);
571 mainLayout->setSpacing(12);
572
573 // Tab widget
574 tabWidget_ = new QTabWidget(this);
575 mainLayout->addWidget(tabWidget_);
576
577 // Active downloads tab
578 activeTab_ = new QWidget(this);
579 setupActiveTab(activeTab_);
580 tabWidget_->addTab(activeTab_, "Active Downloads");
581
582 // Updates available tab
583 updatesTab_ = new QWidget(this);
584 setupUpdatesTab(updatesTab_);
585 tabWidget_->addTab(updatesTab_, "Updates Available");
586
587 // History tab
588 historyTab_ = new QWidget(this);
589 setupHistoryTab(historyTab_);
590 tabWidget_->addTab(historyTab_, "History");
591
592 // Settings tab
593 settingsTab_ = new QWidget(this);
594 setupSettingsTab(settingsTab_);
595 tabWidget_->addTab(settingsTab_, "Settings");
596
597 // Close button
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);
604}
605
606void DownloadQueueDialog::setupActiveTab(QWidget* tab)
607{
608 auto* layout = new QVBoxLayout(tab);
609 layout->setContentsMargins(0, 8, 0, 0);
610 layout->setSpacing(12);
611
612 // Stats widget
613 statsWidget_ = new DownloadStatsWidget(this, themeManager_);
614 layout->addWidget(statsWidget_);
615
616 // Empty state label (shown when no active downloads)
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_);
623
624 // Download list
625 downloadList_ = new QListWidget(this);
626 downloadList_->setSpacing(4);
627 downloadList_->setSelectionMode(QAbstractItemView::NoSelection);
628 layout->addWidget(downloadList_, 1);
629
630 // Control buttons
631 auto* controlLayout = new QHBoxLayout();
632 controlLayout->setSpacing(8);
633
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_);
638
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_);
643
644 controlLayout->addStretch();
645
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_);
650
651 layout->addLayout(controlLayout);
652}
653
654void DownloadQueueDialog::setupUpdatesTab(QWidget* tab)
655{
656 const ThemeColors& c = themeManager_->colors();
657
658 auto* layout = new QVBoxLayout(tab);
659 layout->setContentsMargins(0, 8, 0, 0);
660 layout->setSpacing(12);
661
662 // Info label explaining Steam manages updates
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);
669
670 // Updates count label
671 updatesCountLabel_ = new QLabel("Checking for updates...", this);
672 updatesCountLabel_->setStyleSheet(
673 QString("font-size: 13px; font-weight: bold; color: %1; padding: 8px;")
674 .arg(c.textPrimary.name()));
675 layout->addWidget(updatesCountLabel_);
676
677 // Updates list
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; "
684 "padding: 8px; }"
685 "QListWidget::item:last-child { border-bottom: none; }")
686 .arg(c.cardBackground.name(), c.border.name()));
687 layout->addWidget(updatesList_, 1);
688
689 // Control buttons
690 auto* controlLayout = new QHBoxLayout();
691 controlLayout->setSpacing(8);
692
693 updateAllBtn_ = new QPushButton("Update All via Steam", this);
694 updateAllBtn_->setObjectName("steamUpdateAllBtn");
695 updateAllBtn_->setStyleSheet(
696 QString(
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; }")
701 .arg(c.inputBackground.name(), c.textPrimary.name(), c.border.name(), c.accent.name(),
702 c.textOnAccent.name(), c.textMuted.name()));
703 connect(updateAllBtn_, &QPushButton::clicked, this,
704 [this]()
705 {
706 // Trigger updates for all games in the list
707 for (int i = 0; i < updatesList_->count(); ++i)
708 {
709 QListWidgetItem* item = updatesList_->item(i);
710 uint32_t appId = item->data(Qt::UserRole).toUInt();
711 if (appId > 0)
712 {
713 // Use steam://install/ to download/update without auto-launching
714 QProcess::startDetached("steam",
715 {QString("steam://install/%1").arg(appId)});
716 }
717 }
718 });
719 controlLayout->addWidget(updateAllBtn_);
720
721 controlLayout->addStretch();
722
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);
728
729 layout->addLayout(controlLayout);
730
731 // Initial update
732 updateUpdatesList();
733}
734
735void DownloadQueueDialog::updateUpdatesList()
736{
737 if (!updatesList_ || !libraryController_)
738 return;
739
740 const ThemeColors& c = themeManager_->colors();
741
742 updatesList_->clear();
743 int updateCount = 0;
744
745 // Get all games and check for updates
746 auto games = libraryController_->getFilteredGames();
747 for (const auto* game : games)
748 {
749 if (!game || game->source != GameSource::Steam || game->metadata.steamAppId <= 0)
750 continue;
751
752 // Read current state from appmanifest
753 auto progress =
754 SteamDownloadMonitor::readGameState(static_cast<uint32_t>(game->metadata.steamAppId));
755
756 if (SteamStateFlags::needsUpdate(progress.stateFlags))
757 {
758 updateCount++;
759
760 // Create list item
761 auto* itemWidget = new QWidget(updatesList_);
762 auto* itemLayout = new QHBoxLayout(itemWidget);
763 itemLayout->setContentsMargins(8, 4, 8, 4);
764 itemLayout->setSpacing(12);
765
766 // Game name
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);
771
772 // Update size (if known)
773 if (game->metadata.steamBytesToDownload > 0)
774 {
775 auto* sizeLabel =
776 new QLabel(formatBytes(game->metadata.steamBytesToDownload), itemWidget);
777 sizeLabel->setStyleSheet(QString("color: %1;").arg(c.textSecondary.name()));
778 itemLayout->addWidget(sizeLabel);
779 }
780
781 // Update button — outlined style, opens Steam
782 auto* updateBtn = new QPushButton("Update via Steam", itemWidget);
783 updateBtn->setObjectName("steamUpdateBtn");
784 updateBtn->setStyleSheet(
785 QString(
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; }")
789 .arg(c.inputBackground.name(), c.textPrimary.name(), c.border.name(),
790 c.accent.name(), c.textOnAccent.name()));
791 uint32_t appId = static_cast<uint32_t>(game->metadata.steamAppId);
792 connect(updateBtn, &QPushButton::clicked, this,
793 [appId]()
794 {
795 // Use steam://install/ to download/update without auto-launching
796 QProcess::startDetached("steam",
797 {QString("steam://install/%1").arg(appId)});
798 });
799 itemLayout->addWidget(updateBtn);
800
801 // Add to list
802 auto* item = new QListWidgetItem(updatesList_);
803 item->setData(Qt::UserRole, appId);
804 item->setSizeHint(itemWidget->sizeHint());
805 updatesList_->setItemWidget(item, itemWidget);
806 }
807 }
808
809 // Update count label
810 if (updateCount == 0)
811 {
812 updatesCountLabel_->setText("✓ All games are up to date");
813 updatesCountLabel_->setStyleSheet(
814 QString("font-size: 13px; font-weight: bold; color: %1; padding: 8px;")
815 .arg(c.success.name()));
816 updateAllBtn_->setEnabled(false);
817 }
818 else
819 {
820 updatesCountLabel_->setText(QString("⬆ %1 game%2 %3 updates available")
821 .arg(updateCount)
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;")
826 .arg(c.warning.name()));
827 updateAllBtn_->setEnabled(true);
828 }
829
830 // Update tab title with count
831 if (tabWidget_ && updatesTab_)
832 {
833 int tabIndex = tabWidget_->indexOf(updatesTab_);
834 if (tabIndex >= 0)
835 {
836 if (updateCount > 0)
837 tabWidget_->setTabText(tabIndex,
838 QString("Updates Available (%1)").arg(updateCount));
839 else
840 tabWidget_->setTabText(tabIndex, "Updates Available");
841 }
842 }
843}
844
845void DownloadQueueDialog::setupHistoryTab(QWidget* tab)
846{
847 auto* layout = new QVBoxLayout(tab);
848 layout->setContentsMargins(0, 8, 0, 0);
849 layout->setSpacing(12);
850
851 // History stats
852 historyStatsLabel_ = new QLabel("No download history", this);
853 historyStatsLabel_->setStyleSheet(
854 "font-size: 12px; color: " + themeManager_->colors().textSecondary.name() + ";");
855 layout->addWidget(historyStatsLabel_);
856
857 // History list
858 historyList_ = new QListWidget(this);
859 historyList_->setSpacing(2);
860 layout->addWidget(historyList_, 1);
861
862 // Clear button
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);
869}
870
871void DownloadQueueDialog::setupSettingsTab(QWidget* tab)
872{
873 auto* layout = new QVBoxLayout(tab);
874 layout->setContentsMargins(0, 8, 0, 0);
875 layout->setSpacing(16);
876
877 // Bandwidth control group
878 auto* bandwidthGroup = new QGroupBox("Steam Bandwidth Preference", this);
879 auto* bandwidthLayout = new QVBoxLayout(bandwidthGroup);
880 bandwidthWidget_ = new BandwidthControlWidget(this, themeManager_);
881 connect(bandwidthWidget_, &BandwidthControlWidget::limitChanged, this,
882 &DownloadQueueDialog::onBandwidthLimitChanged);
883 bandwidthLayout->addWidget(bandwidthWidget_);
884 layout->addWidget(bandwidthGroup);
885
886 // Behavior group
887 auto* behaviorGroup = new QGroupBox("Behavior", this);
888 auto* behaviorLayout = new QVBoxLayout(behaviorGroup);
889
890 autoStartCheckbox_ = new QCheckBox("Auto-start downloads when Steam is running", this);
891 autoStartCheckbox_->setChecked(true);
892 behaviorLayout->addWidget(autoStartCheckbox_);
893
894 notifyCompleteCheckbox_ = new QCheckBox("Show notification when downloads complete", this);
895 notifyCompleteCheckbox_->setChecked(true);
896 behaviorLayout->addWidget(notifyCompleteCheckbox_);
897
898 layout->addWidget(behaviorGroup);
899
900 // Info label
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.",
904 this);
905 infoLabel->setStyleSheet(
906 "font-size: 11px; color: " + themeManager_->colors().textSecondary.name() + ";");
907 infoLabel->setWordWrap(true);
908 layout->addWidget(infoLabel);
909
910 layout->addStretch();
911}
912
913void DownloadQueueDialog::updateDownloadList()
914{
915 // Get currently downloading games from Steam
916 std::vector<uint32_t> downloadingGames = SteamDownloadMonitor::getDownloadingGames();
917
918 // Track existing items
919 std::set<uint32_t> existingAppIds;
920 for (int i = 0; i < downloadList_->count(); ++i)
921 {
922 auto* item = downloadList_->item(i);
923 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
924 if (widget)
925 existingAppIds.insert(widget->appId());
926 }
927
928 // Add new downloads
929 int position = 0;
930 for (uint32_t appId : downloadingGames)
931 {
932 if (existingAppIds.find(appId) == existingAppIds.end())
933 {
934 // Get game name from library or Steam
935 QString gameName = QString("App %1").arg(appId);
936 if (libraryController_)
937 {
938 // Find game by Steam App ID
939 auto allGames = libraryController_->getFilteredGames();
940 for (const auto* game : allGames)
941 {
942 if (game && game->source == GameSource::Steam &&
943 static_cast<uint32_t>(game->metadata.steamAppId) == appId)
944 {
945 gameName = QString::fromStdString(game->name);
946 break;
947 }
948 }
949 }
950
951 addDownloadItem(appId, gameName, position);
952 }
953 position++;
954 }
955
956 // Remove completed downloads
957 for (uint32_t appId : existingAppIds)
958 {
959 if (std::find(downloadingGames.begin(), downloadingGames.end(), appId) ==
960 downloadingGames.end())
961 {
962 removeDownloadItem(appId);
963 }
964 }
965
966 // Update progress for all items
967 for (int i = 0; i < downloadList_->count(); ++i)
968 {
969 auto* item = downloadList_->item(i);
970 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
971 if (!widget)
972 continue;
973
974 auto progress = SteamDownloadMonitor::readGameState(widget->appId());
975 if (progress.bytesToDownload > 0)
976 {
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);
982 }
983 }
984
985 // Toggle empty state label
986 if (activeEmptyLabel_)
987 {
988 bool hasDownloads = downloadList_->count() > 0;
989 activeEmptyLabel_->setVisible(!hasDownloads);
990 downloadList_->setVisible(hasDownloads);
991 }
992}
993
994void DownloadQueueDialog::updateStats()
995{
996 std::vector<uint32_t> downloadingGames = SteamDownloadMonitor::getDownloadingGames();
997
998 int activeCount = downloadingGames.empty() ? 0 : 1;
999 int queuedCount =
1000 downloadingGames.size() > 1 ? static_cast<int>(downloadingGames.size()) - 1 : 0;
1001
1002 double totalSpeed = 0.0;
1003 uint64_t totalRemaining = 0;
1004
1005 for (uint32_t appId : downloadingGames)
1006 {
1007 auto progress = SteamDownloadMonitor::readGameState(appId);
1008 totalSpeed += progress.downloadSpeedBytesPerSec;
1009 if (progress.bytesToDownload > progress.bytesDownloaded)
1010 totalRemaining += progress.bytesToDownload - progress.bytesDownloaded;
1011 }
1012
1013 statsWidget_->setActiveCount(activeCount);
1014 statsWidget_->setQueuedCount(queuedCount);
1015 statsWidget_->setTotalSpeed(totalSpeed);
1016 statsWidget_->setTotalRemaining(totalRemaining);
1017
1018 if (totalSpeed > 0 && totalRemaining > 0)
1019 {
1020 int eta = static_cast<int>(static_cast<double>(totalRemaining) / totalSpeed);
1021 statsWidget_->setEstimatedTime(eta);
1022 }
1023 else
1024 {
1025 statsWidget_->setEstimatedTime(0);
1026 }
1027
1028 // Update button states
1029 bool hasDownloads = !downloadingGames.empty();
1030 pauseAllBtn_->setEnabled(hasDownloads && !allPaused_);
1031 resumeAllBtn_->setEnabled(hasDownloads && allPaused_);
1032}
1033
1034void DownloadQueueDialog::addDownloadItem(uint32_t appId, const QString& gameName,
1035 int queuePosition)
1036{
1037 auto* widget = new DownloadItemWidget(appId, gameName, this, themeManager_);
1038 widget->setQueuePosition(queuePosition);
1039
1040 // Connect signals
1041 connect(widget, &DownloadItemWidget::pauseRequested, this,
1042 &DownloadQueueDialog::onPauseRequested);
1043 connect(widget, &DownloadItemWidget::resumeRequested, this,
1044 &DownloadQueueDialog::onResumeRequested);
1045 connect(widget, &DownloadItemWidget::cancelRequested, this,
1046 &DownloadQueueDialog::onCancelRequested);
1047 connect(widget, &DownloadItemWidget::moveUpRequested, this,
1048 &DownloadQueueDialog::onMoveUpRequested);
1049 connect(widget, &DownloadItemWidget::moveDownRequested, this,
1050 &DownloadQueueDialog::onMoveDownRequested);
1051 connect(widget, &DownloadItemWidget::openInSteamRequested, this,
1052 &DownloadQueueDialog::onOpenInSteamRequested);
1053
1054 auto* item = new QListWidgetItem(downloadList_);
1055 item->setSizeHint(QSize(0, 80));
1056 downloadList_->addItem(item);
1057 downloadList_->setItemWidget(item, widget);
1058}
1059
1060void DownloadQueueDialog::removeDownloadItem(uint32_t appId)
1061{
1062 for (int i = 0; i < downloadList_->count(); ++i)
1063 {
1064 auto* item = downloadList_->item(i);
1065 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1066 if (widget && widget->appId() == appId)
1067 {
1068 // Add to history before removing
1069 auto progress = SteamDownloadMonitor::readGameState(appId);
1070 if (progress.isComplete)
1071 {
1072 addToHistory(appId, widget->gameName(), progress.bytesToDownload, 0,
1073 false); // TODO: track duration
1074 }
1075
1076 delete downloadList_->takeItem(i);
1077 break;
1078 }
1079 }
1080}
1081
1082DownloadItemWidget* DownloadQueueDialog::findDownloadItem(uint32_t appId)
1083{
1084 for (int i = 0; i < downloadList_->count(); ++i)
1085 {
1086 auto* item = downloadList_->item(i);
1087 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1088 if (widget && widget->appId() == appId)
1089 return widget;
1090 }
1091 return nullptr;
1092}
1093
1094void DownloadQueueDialog::loadHistory()
1095{
1096 QString historyPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) +
1097 "/download_history.json";
1098
1099 QFile file(historyPath);
1100 if (!file.open(QIODevice::ReadOnly))
1101 return;
1102
1103 QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
1104 if (!doc.isArray())
1105 return;
1106
1107 downloadHistory_.clear();
1108 for (const QJsonValue val : doc.array())
1109 {
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);
1116 item.durationSeconds = obj["duration"].toInt();
1117 item.averageSpeed = obj["avgSpeed"].toDouble();
1118 item.wasUpdate = obj["wasUpdate"].toBool();
1119 downloadHistory_.push_back(item);
1120 }
1121
1122 // Update history UI
1123 historyList_->clear();
1124 for (const auto& item : downloadHistory_)
1125 {
1126 QString text = QString("%1 - %2 (%3)")
1127 .arg(item.gameName)
1128 .arg(formatBytes(item.totalBytes))
1129 .arg(item.completedAt.toString("yyyy-MM-dd hh:mm"));
1130 historyList_->addItem(text);
1131 }
1132
1133 // Update stats
1134 if (!downloadHistory_.empty())
1135 {
1136 uint64_t totalBytes = 0;
1137 for (const auto& item : downloadHistory_)
1138 totalBytes += item.totalBytes;
1139
1140 historyStatsLabel_->setText(QString("%1 downloads, %2 total")
1141 .arg(downloadHistory_.size())
1142 .arg(formatBytes(totalBytes)));
1143 }
1144}
1145
1146void DownloadQueueDialog::saveHistory()
1147{
1148 QString dataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
1149 QDir().mkpath(dataPath);
1150
1151 QString historyPath = dataPath + "/download_history.json";
1152
1153 QJsonArray arr;
1154 for (const auto& item : downloadHistory_)
1155 {
1156 QJsonObject obj;
1157 obj["appId"] = static_cast<int>(item.appId);
1158 obj["gameName"] = item.gameName;
1159 obj["totalBytes"] = static_cast<qint64>(item.totalBytes);
1160 obj["completedAt"] = item.completedAt.toString(Qt::ISODate);
1161 obj["duration"] = item.durationSeconds;
1162 obj["avgSpeed"] = item.averageSpeed;
1163 obj["wasUpdate"] = item.wasUpdate;
1164 arr.append(obj);
1165 }
1166
1167 QFile file(historyPath);
1168 if (file.open(QIODevice::WriteOnly))
1169 {
1170 file.write(QJsonDocument(arr).toJson(QJsonDocument::Compact));
1171 }
1172}
1173
1174void DownloadQueueDialog::addToHistory(uint32_t appId, const QString& gameName, uint64_t bytes,
1175 int duration, bool wasUpdate)
1176{
1177 DownloadHistoryItem item;
1178 item.appId = appId;
1179 item.gameName = gameName;
1180 item.totalBytes = bytes;
1181 item.completedAt = QDateTime::currentDateTime();
1182 item.durationSeconds = duration;
1183 item.averageSpeed = duration > 0 ? static_cast<double>(bytes) / duration : 0;
1184 item.wasUpdate = wasUpdate;
1185
1186 downloadHistory_.insert(downloadHistory_.begin(), item);
1187
1188 // Keep only last 100 items
1189 if (downloadHistory_.size() > 100)
1190 downloadHistory_.resize(100);
1191
1192 // Update history list
1193 QString text = QString("%1 - %2 (%3)")
1194 .arg(gameName)
1195 .arg(formatBytes(bytes))
1196 .arg(item.completedAt.toString("yyyy-MM-dd hh:mm"));
1197 historyList_->insertItem(0, text);
1198
1199 // Update stats
1200 uint64_t totalBytes = 0;
1201 for (const auto& h : downloadHistory_)
1202 totalBytes += h.totalBytes;
1203
1204 historyStatsLabel_->setText(QString("%1 downloads, %2 total")
1205 .arg(downloadHistory_.size())
1206 .arg(formatBytes(totalBytes)));
1207}
1208
1209QString DownloadQueueDialog::formatBytes(uint64_t bytes) const
1210{
1211 if (bytes < 1024)
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);
1219}
1220
1221QString DownloadQueueDialog::formatDuration(int seconds) const
1222{
1223 if (seconds < 60)
1224 return QString("%1s").arg(seconds);
1225 if (seconds < 3600)
1226 return QString("%1m %2s").arg(seconds / 60).arg(seconds % 60);
1227 return QString("%1h %2m").arg(seconds / 3600).arg((seconds % 3600) / 60);
1228}
1229
1230// Slots
1231
1232void DownloadQueueDialog::onRefresh()
1233{
1234 updateDownloadList();
1235 updateStats();
1236}
1237
1238void DownloadQueueDialog::onPauseAll()
1239{
1240 // Steam doesn't have a direct API for this, so we use steam:// protocol
1241 QProcess::startDetached("steam", {"steam://pausedownloads"});
1242 allPaused_ = true;
1243
1244 // Update UI
1245 for (int i = 0; i < downloadList_->count(); ++i)
1246 {
1247 auto* item = downloadList_->item(i);
1248 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1249 if (widget)
1250 widget->setPaused(true);
1251 }
1252
1253 pauseAllBtn_->setEnabled(false);
1254 resumeAllBtn_->setEnabled(true);
1255}
1256
1257void DownloadQueueDialog::onResumeAll()
1258{
1259 QProcess::startDetached("steam", {"steam://resumedownloads"});
1260 allPaused_ = false;
1261
1262 // Update UI
1263 for (int i = 0; i < downloadList_->count(); ++i)
1264 {
1265 auto* item = downloadList_->item(i);
1266 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1267 if (widget)
1268 widget->setPaused(false);
1269 }
1270
1271 pauseAllBtn_->setEnabled(true);
1272 resumeAllBtn_->setEnabled(false);
1273}
1274
1275void DownloadQueueDialog::onClearCompleted()
1276{
1277 downloadHistory_.clear();
1278 historyList_->clear();
1279 historyStatsLabel_->setText("No download history");
1280 saveHistory();
1281}
1282
1283void DownloadQueueDialog::onPauseRequested(uint32_t appId)
1284{
1285 // Use Steam protocol to pause specific download
1286 QProcess::startDetached("steam", {QString("steam://pausedownload/%1").arg(appId)});
1287
1288 if (auto* widget = findDownloadItem(appId))
1289 widget->setPaused(true);
1290
1291 emit downloadPaused(appId);
1292}
1293
1294void DownloadQueueDialog::onResumeRequested(uint32_t appId)
1295{
1296 QProcess::startDetached("steam", {QString("steam://resumedownload/%1").arg(appId)});
1297
1298 if (auto* widget = findDownloadItem(appId))
1299 widget->setPaused(false);
1300
1301 emit downloadResumed(appId);
1302}
1303
1304void DownloadQueueDialog::onCancelRequested(uint32_t appId)
1305{
1306 auto* widget = findDownloadItem(appId);
1307 QString gameName = widget ? widget->gameName() : QString("App %1").arg(appId);
1308
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);
1313
1314 if (result == QMessageBox::Yes)
1315 {
1316 // Open Steam uninstall dialog for the partial download
1317 QProcess::startDetached("steam", {QString("steam://uninstall/%1").arg(appId)});
1318 emit downloadCancelled(appId);
1319 }
1320}
1321
1322void DownloadQueueDialog::onMoveUpRequested(uint32_t /*appId*/)
1323{
1324 // Steam uses steam://changepriority/<appid>/<priority>
1325 // where priority 0 = highest
1326 QProcess::startDetached("steam", {"steam://nav/downloads"}); // Open downloads page
1327 // Note: Direct queue manipulation isn't well-supported via steam:// protocol
1328}
1329
1330void DownloadQueueDialog::onMoveDownRequested(uint32_t /*appId*/)
1331{
1332 QProcess::startDetached("steam", {"steam://nav/downloads"});
1333}
1334
1335void DownloadQueueDialog::onOpenInSteamRequested(uint32_t appId)
1336{
1337 QProcess::startDetached("steam", {QString("steam://nav/games/details/%1").arg(appId)});
1338}
1339
1340void DownloadQueueDialog::onBandwidthLimitChanged(bool enabled, int mbps)
1341{
1342 // Note: Bandwidth limiting would require modifying Steam's registry/config
1343 // This is informational - user would need to set it in Steam settings
1344 Q_UNUSED(enabled)
1345 Q_UNUSED(mbps)
1346}
1347
1348void DownloadQueueDialog::onDownloadProgress(uint32_t appId, double progress, const QString& status)
1349{
1350 if (auto* widget = findDownloadItem(appId))
1351 {
1352 auto progressInfo = SteamDownloadMonitor::readGameState(appId);
1353 widget->setProgress(progress, progressInfo.bytesDownloaded, progressInfo.bytesToDownload);
1354 widget->setSpeed(progressInfo.downloadSpeedBytesPerSec);
1355 widget->setStatus(status);
1356 }
1357}
1358
1359void DownloadQueueDialog::onDownloadComplete(uint32_t appId)
1360{
1361 removeDownloadItem(appId);
1362 updateStats();
1363}
1364
1365void DownloadQueueDialog::applyTheme()
1366{
1367 const ThemeColors& c = themeManager_->colors();
1368
1369 QString bgColor = c.windowBackground.name();
1370 QString textColor = c.textPrimary.name();
1371 QString surfaceColor = c.cardBackground.name();
1372 QString borderColor = c.border.name();
1373
1374 setStyleSheet(QString(R"(
1375 DownloadQueueDialog {
1376 background-color: %1;
1377 color: %2;
1378 }
1379 QTabWidget::pane {
1380 background-color: %1;
1381 border: 1px solid %4;
1382 border-radius: 6px;
1383 }
1384 QTabBar::tab {
1385 background-color: %3;
1386 color: %2;
1387 padding: 8px 16px;
1388 border: 1px solid %4;
1389 border-bottom: none;
1390 border-top-left-radius: 6px;
1391 border-top-right-radius: 6px;
1392 }
1393 QTabBar::tab:selected {
1394 background-color: %1;
1395 }
1396 QListWidget {
1397 background-color: %1;
1398 border: 1px solid %4;
1399 border-radius: 6px;
1400 }
1401 QListWidget::item {
1402 background-color: transparent;
1403 border: none;
1404 }
1405 QPushButton {
1406 background-color: %3;
1407 color: %2;
1408 border: 1px solid %4;
1409 border-radius: 4px;
1410 padding: 6px 12px;
1411 }
1412 QPushButton:hover {
1413 background-color: %4;
1414 }
1415 QPushButton:disabled {
1416 opacity: 0.5;
1417 }
1418 QGroupBox {
1419 color: %2;
1420 border: 1px solid %4;
1421 border-radius: 6px;
1422 margin-top: 12px;
1423 padding-top: 8px;
1424 }
1425 QGroupBox::title {
1426 subcontrol-origin: margin;
1427 left: 10px;
1428 padding: 0 5px;
1429 }
1430 QCheckBox {
1431 color: %2;
1432 }
1433 QSlider::groove:horizontal {
1434 background: %4;
1435 height: 6px;
1436 border-radius: 3px;
1437 }
1438 QSlider::handle:horizontal {
1439 background: %2;
1440 width: 16px;
1441 margin: -5px 0;
1442 border-radius: 8px;
1443 }
1444 QSpinBox {
1445 background-color: %3;
1446 color: %2;
1447 border: 1px solid %4;
1448 border-radius: 4px;
1449 padding: 4px;
1450 }
1451 )")
1452 .arg(bgColor, textColor, surfaceColor, borderColor));
1453
1454 // Apply theme to child widgets
1455 if (statsWidget_)
1456 statsWidget_->applyTheme();
1457
1458 for (int i = 0; i < downloadList_->count(); ++i)
1459 {
1460 auto* item = downloadList_->item(i);
1461 auto* widget = qobject_cast<DownloadItemWidget*>(downloadList_->itemWidget(item));
1462 if (widget)
1463 widget->applyTheme();
1464 }
1465}
void limitChanged(bool enabled, int mbps)
BandwidthControlWidget(QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void setStatus(const QString &status)
void pauseRequested(uint32_t appId)
DownloadItemWidget(uint32_t appId, const QString &gameName, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void cancelRequested(uint32_t appId)
void setQueuePosition(int position)
~DownloadItemWidget() override
void moveUpRequested(uint32_t appId)
void setSpeed(double bytesPerSec)
void resumeRequested(uint32_t appId)
void moveDownRequested(uint32_t appId)
void openInSteamRequested(uint32_t appId)
void setProgress(double progress, uint64_t bytesDownloaded, uint64_t totalBytes)
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(SteamDownloadMonitor *downloadMonitor, core::GameLibraryController *libraryController, QWidget *parent=nullptr, ThemeManager *themeManager=nullptr)
void setTotalRemaining(uint64_t bytes)
void setEstimatedTime(int seconds)
void setTotalSpeed(double bytesPerSec)
DownloadStatsWidget(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.
Definition game.h:41
bool needsUpdate(uint32_t flags)
Check if a game needs an update.
QColor inputBackground
QColor cardBackground
QColor textSecondary
QColor textPrimary
QColor windowBackground
QColor textMuted
QColor textOnAccent