Browse Source

Small code cleanup

Ivan Arkhipov 3 years ago
parent
commit
458a4504da

+ 12 - 17
src/Legacy/legacyapplication.cpp

@@ -26,10 +26,13 @@ LegacyApplication::LegacyApplication() {
 }
 
 LegacyApplication::~LegacyApplication() {
+    patch_managers_thread_->terminate();
+    patch_managers_thread_->wait();
+    delete patch_managers_thread_;
+    delete gui;
 }
 
-bool LegacyApplication::init()
-{
+bool LegacyApplication::init() {
     qt_ntfs_permission_lookup++;
     qDebug() << "Starting initialisation...";
 
@@ -70,36 +73,28 @@ bool LegacyApplication::init()
 
     qDebug() << "Starting GUI initialisation...";
     gui = new MainWindow();
-    connect(this, &LegacyApplication::ErrorStatusChanged, gui, &MainWindow::onErrorStatusChanged);
-    connect(this, &LegacyApplication::SecondsToNextTryToInitChanged, gui, &MainWindow::onSecondsToNextTryToInitChanged);
+//    connect(this, &LegacyApplication::ErrorStatusChanged, gui, &MainWindow::onErrorStatusChanged);
 
     qDebug() << "Starting functional modules initialisation...";
 
     InitModules();
+
+    qDebug() << "Successfully finished the initialization!!!";
     return true;
 }
 
 
-void LegacyApplication::InitModules()
-{
-    if (seconds_after_previous_try_to_init_ + 1 < try_to_init_timeout_) {
-        seconds_after_previous_try_to_init_++;
-        emit SecondsToNextTryToInitChanged(try_to_init_timeout_ - seconds_after_previous_try_to_init_);
-        return;
-    }
-
+void LegacyApplication::InitModules() {
     modules_init_timer_.stop();
-    seconds_after_previous_try_to_init_ = 0;
     AppErrorStatus status = CheckAppPrerequesities();
     emit ErrorStatusChanged(status);
 
     if (status == E_NO_ERRORS) {
-        connect(&PatchDownloader::instance(), &PatchDownloader::finished, &PatchInstaller::instance(), &PatchInstaller::startPatchInstallationChain, Qt::QueuedConnection);
         QMetaObject::invokeMethod(&PatchInstaller::instance(), &PatchInstaller::init, Qt::BlockingQueuedConnection);
         QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::init, Qt::BlockingQueuedConnection);
-        QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::startPatchDownloaderChain, Qt::QueuedConnection);
-    } else {
-        qWarning() << "LegacyApplication: Couldnt init functional modules!";
+        QMetaObject::invokeMethod(&PatchDownloader::instance(), &PatchDownloader::checkForUpdates, Qt::QueuedConnection);
+    } else if (status == E_NO_SERVER_CONNECTION) {
+        qWarning() << "LegacyApplication: Cannot connect to server - restarting in 1 second!";
         modules_init_timer_.start();
     }
 }

+ 0 - 4
src/Legacy/legacyapplication.h

@@ -29,8 +29,6 @@ public:
 signals:
     void ErrorStatusChanged(AppErrorStatus status);
 
-    void SecondsToNextTryToInitChanged(size_t seconds_elapsed);
-
 private slots:
     void InitModules();
 
@@ -40,8 +38,6 @@ private:
     QThread* patch_managers_thread_;
 
     QTimer modules_init_timer_;
-    size_t seconds_after_previous_try_to_init_ = 10; // init value should be equal to try_to_init_timeout_
-    const size_t try_to_init_timeout_ = 10;
 };
 
 #endif // LEGACYAPPLICATION_H

+ 1 - 1
src/Legacy/models/patchdownloader.h

@@ -23,12 +23,12 @@ public:
 private:
     Q_DISABLE_COPY(PatchDownloader)
     PatchDownloader();
-    void checkForUpdates();  // Checks for updates. Returns true, if there are new patch updates
     void downloadDatabases();         // Starts downloading all necessary patches.
     static bool needDownloadDatabase(QString db_name); // Checks if database needs to be downloaded (by checksum comparing)
 
 public slots:
     void init();
+    void checkForUpdates();  // Checks for updates
     void startPatchDownloaderChain();
 
 signals:

+ 9 - 13
src/Legacy/utils.cpp

@@ -92,18 +92,17 @@ bool checkSingleAppInstance() {
 }
 
 AppErrorStatus CheckAppPrerequesities() {
-    size_t status = E_NO_ERRORS;
     QString game_folder_path = Settings::getValue("Lotro/game_path").toString();
     QString locale_prefix = Settings::getValue("Lotro/original_locale").toString();
 
     // Checking LotroLauncher.exe availability
     QFileInfo lotro_launcher_exe(game_folder_path + "/LotroLauncher.exe");
     if (!lotro_launcher_exe.exists()) {
-        status |= E_WRONG_GAME_FOLDER;
+        return E_WRONG_GAME_FOLDER;
     } else {
         if (!QFile::setPermissions(lotro_launcher_exe.absoluteFilePath(),
                 QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ExeUser)) {
-            status |= E_WRONG_FILE_PERMISSIONS;
+            return E_WRONG_FILE_PERMISSIONS;
         }
     }
 
@@ -115,43 +114,40 @@ AppErrorStatus CheckAppPrerequesities() {
     QFileInfo client_general_file(client_general_filepath);
 
     if (!client_general_file.exists() || !client_local_file.exists()) {
-        status |= E_DAT_FILES_MISSING;
+        return E_DAT_FILES_MISSING;
     } else {
         if (!QFile::setPermissions(client_general_filepath,
                                    QFileDevice::ReadUser |
                                    QFileDevice::WriteUser |
                                    QFileDevice::ExeUser)) {
-            status |= E_WRONG_FILE_PERMISSIONS;
-            status |= E_CANNOT_ACCESS_DAT_FILES;
+            return E_WRONG_FILE_PERMISSIONS;
         }
 
         if (!QFile::setPermissions(client_local_filepath,
                                    QFileDevice::ReadUser |
                                    QFileDevice::WriteUser |
                                    QFileDevice::ExeUser)) {
-            status |= E_WRONG_FILE_PERMISSIONS;
-            status |= E_CANNOT_ACCESS_DAT_FILES;
+            return E_WRONG_FILE_PERMISSIONS;
         }
 
         LOTRO_DAT::DatFile file(0);
         if (!file.Init(client_local_file.absoluteFilePath().toStdString())) {
-            status |= E_DAT_FILE_INCORRECT;
+            return E_DAT_FILE_INCORRECT;
         } else {
             file.Deinit();
         }
         if (!file.Init(client_general_file.absoluteFilePath().toStdString())) {
-            status |= E_DAT_FILE_INCORRECT;
+            return E_DAT_FILE_INCORRECT;
         } else {
             file.Deinit();
         }
     }
 
     if (!checkInternetConnection(QUrl(Settings::getValue("Network/patch_updates_url").toString()))) {
-        status |= E_NO_SERVER_CONNECTION;
+        return E_NO_SERVER_CONNECTION;
     }
 
-    qDebug() << "LegacyApplication: StatusCheck: " << AppErrorStatus(status);
-    return AppErrorStatus(status);
+    return E_NO_ERRORS;
 }
 
 QDebug operator<<(QDebug dbg, const AppErrorStatus &status)

+ 3 - 37
src/Legacy/widgets/mainwindow.cpp

@@ -33,7 +33,6 @@ MainWindow::MainWindow(QWidget *parent)
     , current_active_entry_(nullptr)
     , current_hovered_entry_(nullptr)
     , status_widget_(nullptr)
-    , settings_widget_(nullptr)
     , help_widget_(nullptr)
     , about_widget_(nullptr)
     , choose_locale_dialog_(nullptr)
@@ -49,20 +48,13 @@ MainWindow::MainWindow(QWidget *parent)
 
     qDebug() << __FUNCTION__ << "Initialising main frame...";
     status_widget_ = new StatusWidget(this);
-    settings_widget_ = new SettingsWidget(this);
     help_widget_ = new HelpWidget(this);
     about_widget_ = new AboutWidget(this);
 
     ui->content_layout->addWidget(status_widget_);
-    ui->content_layout->addWidget(settings_widget_);
     ui->content_layout->addWidget(help_widget_);
     ui->content_layout->addWidget(about_widget_);
 
-    // Adding patch update triggers on settings state changes
-//    connect(settings_widget_, &SettingsWidget::SettingsChanged, legacy_patches_, &PatchList::stopAutoUpdate);
-//    connect(settings_widget_, &SettingsWidget::SettingsReset, legacy_patches_, &PatchList::startAutoUpdate);
-//    connect(settings_widget_, &SettingsWidget::SettingsApplied, legacy_patches_, &PatchList::initialize);
-
 
     hideAllContentWidgets();
     status_widget_->show();
@@ -236,17 +228,9 @@ void MainWindow::on_menuentry_2_clicked()
 {
     current_active_entry_ = ui->menuentry_2;
     hideAllContentWidgets();
-//    settings_widget_->show();
     help_widget_->show();
 }
 
-void MainWindow::on_menuentry_3_clicked()
-{
-//    current_active_entry_ = ui->menuentry_3;
-//    hideAllContentWidgets();
-//    help_widget_->show();
-}
-
 void MainWindow::on_menuentry_4_clicked()
 {
     current_active_entry_ = ui->menuentry_4;
@@ -298,7 +282,6 @@ void MainWindow::setupMenuHoverWidget()
 
     connect(ui->menuentry_1, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
     connect(ui->menuentry_2, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
-//    connect(ui->menuentry_3, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
     connect(ui->menuentry_4, &MenuEntry::entryIsHovered, this, &MainWindow::onHoverMenuentry);
 
     current_active_entry_ = ui->menuentry_1;
@@ -326,7 +309,6 @@ void MainWindow::moveMenuHoverWidget(MenuEntry *target)
 
     ui->menuentry_1->raise();
     ui->menuentry_2->raise();
-//    ui->menuentry_3->raise();
     ui->menuentry_4->raise();
 }
 
@@ -344,7 +326,6 @@ void MainWindow::checkMenuIsHovered()
 void MainWindow::hideAllContentWidgets()
 {
     status_widget_->hide();
-    settings_widget_->hide();
     help_widget_->hide();
     about_widget_->hide();
 }
@@ -353,7 +334,6 @@ void MainWindow::updateFontSizes()
 {
     ui->menuentry_1->setFont(trajan_9pt);
     ui->menuentry_2->setFont(trajan_9pt);
-//    ui->menuentry_3->setFont(trajan_10pt);
     ui->menuentry_4->setFont(trajan_9pt);
 }
 
@@ -377,21 +357,6 @@ void MainWindow::closeEvent(QCloseEvent *event)
     event->ignore();
 }
 
-void MainWindow::showChooseVersionDialog()
-{
-//    QGraphicsBlurEffect *effect = new QGraphicsBlurEffect();
-//    effect->setBlurRadius(10);
-//    effect->setBlurHints(QGraphicsBlurEffect::QualityHint);
-//    ui->content_area->setGraphicsEffect(effect);
-    choose_locale_dialog_->show();
-}
-
-void MainWindow::hideChooseVersionDialog()
-{
-//    ui->content_area->setGraphicsEffect(nullptr);
-    choose_locale_dialog_->hide();
-}
-
 void MainWindow::onErrorStatusChanged(AppErrorStatus status)
 {
     // TODO: Settings widget
@@ -410,8 +375,9 @@ void MainWindow::on_minimizeButton_clicked()
 
 void MainWindow::setEventFilterRecursive(QObject *widget)
 {
-    if (!widget)
+    if (!widget) {
         return;
+    }
 
     widget->installEventFilter(this);
 
@@ -420,7 +386,7 @@ void MainWindow::setEventFilterRecursive(QObject *widget)
     }
 }
 
-bool MainWindow::eventFilter(QObject *watched, QEvent *event)
+bool MainWindow::eventFilter(QObject *, QEvent *event)
 {
     if (event->type() == QEvent::MouseButtonPress) {
         mousePressEvent((QMouseEvent*)(event));

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

@@ -41,9 +41,6 @@ protected:
     virtual void closeEvent(QCloseEvent *event) override;
 
 public slots:
-    void showChooseVersionDialog();
-    void hideChooseVersionDialog();
-
     void onErrorStatusChanged(AppErrorStatus status);
     void onSecondsToNextTryToInitChanged(size_t seconds_elapsed);
 
@@ -66,8 +63,6 @@ private slots:
 
     void on_menuentry_2_clicked();
 
-    void on_menuentry_3_clicked();
-
     void on_menuentry_4_clicked();
 
     void onHoverMenuentry(MenuEntry* hovered_entry);
@@ -106,7 +101,6 @@ private:
     MenuEntry* current_hovered_entry_;
 
     StatusWidget *status_widget_;
-    SettingsWidget *settings_widget_;
     HelpWidget *help_widget_;
     AboutWidget *about_widget_;
 

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

@@ -340,8 +340,6 @@ void StatusWidget::onPatchInstallerVideoProgressChanged(int finished_videos, int
 
 void StatusWidget::on_game_button_clicked()
 {
-    MainWindow* window = qobject_cast<MainWindow*>(parentWidget()->parentWidget()->parentWidget());
-    window->showChooseVersionDialog();
 }
 
 void StatusWidget::createTooltipMessageWidget(QString tooltip_id)