Browse Source

Changed installation label & added progress view for windows taskbar

Ivan Arkhipov 4 years ago
parent
commit
7ad23e67aa

+ 1 - 1
src/Legacy/Legacy.pro

@@ -1,7 +1,7 @@
 include( ../../common.pri )
 include( ../../app.pri )
 
-QT       += core gui network sql
+QT       += core gui network sql winextras
 
 QMAKE_LFLAGS_RELEASE += -static -static-libgcc -static-libstdc++
 

+ 49 - 1
src/Legacy/widgets/mainwindow.cpp

@@ -20,6 +20,7 @@
 #include <QFont>
 #include <QFontDatabase>
 #include <QNetworkAccessManager>
+#include <QWinTaskbarProgress>
 
 #include <ui_statuswidget.h>
 
@@ -78,8 +79,14 @@ MainWindow::MainWindow(QWidget *parent)
     window_height = default_window_height * window_scale_factor / 100;
     resize(window_width, window_height);
 
-    qDebug() << __FUNCTION__ << "Finished main frame initialisation";
     show();
+
+    qDebug() << __FUNCTION__ << "Initializing taskbar icon and progress...";
+    _windows_taskbar_button = new QWinTaskbarButton(this);
+    _windows_taskbar_button->setWindow(windowHandle());
+
+    qDebug() << __FUNCTION__ << "Finished main frame initialisation";
+
 }
 
 MainWindow::~MainWindow()
@@ -268,11 +275,52 @@ void MainWindow::setupWindowBackgroundAndMask(QPixmap background)
 }
 
 
+void MainWindow::onPatchDownloaderStarted() {
+    _windows_taskbar_button->progress()->setVisible(true);
+}
+
+void MainWindow::onPatchDownloaderFinished() {
+    _windows_taskbar_button->progress()->setVisible(false);
+}
+
+void MainWindow::onPatchDownloaderProgressChanged(Downloader::Status status) {
+    int download_percent = status.total_bytes > 0 ? status.downloaded_bytes * 100 / status.total_bytes : 100;
+    _windows_taskbar_button->progress()->setValue(download_percent);
+}
+
+void MainWindow::onPatchInstallerStarted() {
+    _windows_taskbar_button->progress()->setVisible(true);
+}
+
+void MainWindow::onPatchInstallerFinished() {
+    _windows_taskbar_button->progress()->setVisible(false);
+}
+
+void MainWindow::onPatchInstallerProgressChanged(PatchInstaller::Status status) {
+    int install_percent = status.total_parts > 0 ? status.finished_parts * 100 / status.total_parts : 100;
+    _windows_taskbar_button->progress()->setValue(install_percent);
+}
+
+void MainWindow::onPatchInstallerVideoProgressChanged(int finished_videos, int total_videos, Downloader::Status) {
+    int install_percent = total_videos > 0 ? finished_videos * 100 / total_videos : 100;
+    _windows_taskbar_button->progress()->setValue(install_percent);
+}
+
 
 void MainWindow::makeConnections()
 {
     connect(&PatchInstaller::instance(), &PatchInstaller::started, this, [this](){show_warning_on_close = true;});
     connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, [this](){show_warning_on_close = false;});
+
+    connect(&PatchDownloader::instance(), &PatchDownloader::started, this, &MainWindow::onPatchDownloaderStarted);
+    connect(&PatchDownloader::instance(), &PatchDownloader::progressChanged, this, &MainWindow::onPatchDownloaderProgressChanged);
+    connect(&PatchDownloader::instance(), &PatchDownloader::finished, this, &MainWindow::onPatchDownloaderFinished);
+
+    connect(&PatchInstaller::instance(), &PatchInstaller::started, this, &MainWindow::onPatchInstallerStarted);
+    connect(&PatchInstaller::instance(), &PatchInstaller::progressChanged, this, &MainWindow::onPatchInstallerProgressChanged);
+    connect(&PatchInstaller::instance(), &PatchInstaller::finished, this, &MainWindow::onPatchInstallerFinished);
+
+    connect(&PatchInstaller::instance(), &PatchInstaller::videosDownloadProgressChanged, this, &MainWindow::onPatchInstallerVideoProgressChanged);
 }
 
 void MainWindow::setupMenuHoverWidget()

+ 17 - 0
src/Legacy/widgets/mainwindow.h

@@ -12,6 +12,7 @@
 #include <QMutex>
 #include <QMutexLocker>
 #include <QScrollArea>
+#include <QWinTaskbarButton>
 
 #include "statuswidget.h"
 #include "aboutwidget.h"
@@ -67,6 +68,20 @@ private slots:
 
     void setupWindowBackgroundAndMask(QPixmap background);
 
+    void onPatchDownloaderStarted();
+
+    void onPatchDownloaderFinished();
+
+    void onPatchDownloaderProgressChanged(Downloader::Status status);
+
+    void onPatchInstallerStarted();
+
+    void onPatchInstallerFinished();
+
+    void onPatchInstallerProgressChanged(PatchInstaller::Status status);
+
+    void onPatchInstallerVideoProgressChanged(int finished_videos, int total_videos, Downloader::Status status);
+
 private:
     void makeConnections();
 
@@ -87,6 +102,8 @@ private:
 
     Ui::MainWindow *ui = nullptr;
 
+    QWinTaskbarButton* _windows_taskbar_button = nullptr;
+
     MenuEntry* current_active_entry_ = nullptr;
     MenuEntry* current_hovered_entry_ = nullptr;
 

+ 2 - 2
src/Legacy/widgets/statuswidget.cpp

@@ -14,12 +14,12 @@
 #include <QMessageBox>
 #include <QRandomGenerator>
 
+
 StatusWidget::StatusWidget(QWidget *parent)
     : QWidget(parent)
     , ui(new Ui::StatusWidget)
 {
     ui->setupUi(this);
-
     last_statusbar_update_time_.start();
     ui->galadriel_tooltip_example->hide();
     ui->c_progress_bar->setProgress(100);
@@ -308,7 +308,7 @@ void StatusWidget::onPatchInstallerProgressChanged(PatchInstaller::Status status
     double install_percent = status.total_parts > 0 ? double(status.finished_parts) * 100.0 / double(status.total_parts) : 100;
     ui->c_progress_bar->setProgress(install_percent);
     if (last_statusbar_update_time_.elapsed() > 450 || status.finished_parts == 0) {
-        QString text = "Установка русификации: "
+        QString text = "Изменяем файлы игры: "
                      + QString::number(double(status.finished_parts) * 100.0 / double(status.total_parts), 'f', 1)
                      + "%\n(" + QString::number(status.finished_parts)
                      + " фрагментов из " + QString::number(status.total_parts) + ")";

+ 1 - 0
src/Legacy/widgets/statuswidget.h

@@ -100,6 +100,7 @@ private:
 
     QGraphicsOpacityEffect* _components_status_opacity_effect;
     QPropertyAnimation* _components_status_opacity_animation;
+
     bool _need_to_install_patches = false;
     bool _need_to_update = false;
     bool _need_to_repair_game_files = false;