From 95a6d31e18951d4fc3b123fb991f8e69d7e61f28 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 14 Apr 2017 18:31:23 +0100 Subject: [PATCH] Launcher: update all aircraft UI. Replaces more complex previous attempt, which was also not hooked up properly, ooops. --- src/GUI/CMakeLists.txt | 1 - src/GUI/Launcher.ui | 17 ++++++--- src/GUI/LauncherMainWindow.cxx | 66 +++++++++++++--------------------- src/GUI/LauncherMainWindow.hxx | 3 +- src/GUI/UpdateAllAircraft.ui | 50 -------------------------- 5 files changed, 38 insertions(+), 99 deletions(-) delete mode 100644 src/GUI/UpdateAllAircraft.ui diff --git a/src/GUI/CMakeLists.txt b/src/GUI/CMakeLists.txt index 6fcbbd738..8e1a5878c 100644 --- a/src/GUI/CMakeLists.txt +++ b/src/GUI/CMakeLists.txt @@ -78,7 +78,6 @@ if (HAVE_QT) LocationWidget.ui NoOfficialHangar.ui InstallSceneryDialog.ui - UpdateAllAircraft.ui ) qt5_add_resources(qrc_sources resources.qrc) diff --git a/src/GUI/Launcher.ui b/src/GUI/Launcher.ui index 5b26a07ff..16fc264ff 100644 --- a/src/GUI/Launcher.ui +++ b/src/GUI/Launcher.ui @@ -443,7 +443,7 @@ - + 4 @@ -533,6 +533,13 @@ + + + + <html><head/><body><p>%1 aircraft have updates available, <a href="action:update"><span style=" text-decoration: underline; color:#0000ff;">click here to update</span></a> (Or <a href="action:hide"><span style=" text-decoration: underline; color:#0000ff;">hide this</span></a>)</p></body></html> + + + @@ -570,8 +577,8 @@ 0 0 - 643 - 644 + 90 + 20 @@ -603,8 +610,8 @@ 0 0 - 643 - 644 + 173 + 23 diff --git a/src/GUI/LauncherMainWindow.cxx b/src/GUI/LauncherMainWindow.cxx index 1880db2b3..04f580921 100644 --- a/src/GUI/LauncherMainWindow.cxx +++ b/src/GUI/LauncherMainWindow.cxx @@ -69,26 +69,6 @@ private: Ui::NoOfficialHangarMessage* m_ui; }; -class UpdateAllAircraftMessage : public QWidget -{ - Q_OBJECT -public: - UpdateAllAircraftMessage() : - m_ui(new Ui::UpdateAllAircraftMessage) - { - m_ui->setupUi(this); - // proxy this signal upwards - connect(m_ui->label, &QLabel::linkActivated, this, &UpdateAllAircraftMessage::linkActivated); - connect(m_ui->updateAllButton, &QPushButton::clicked, this, &UpdateAllAircraftMessage::updateAll); - } - -Q_SIGNALS: - void linkActivated(QUrl link); - void updateAll(); -private: - Ui::UpdateAllAircraftMessage* m_ui; -}; - #include "LauncherMainWindow.moc" QQmlPrivate::AutoParentResult launcher_autoParent(QObject* thing, QObject* parent) @@ -195,6 +175,8 @@ LauncherMainWindow::LauncherMainWindow() : m_ui->locationHistory->setIcon(historyIcon); m_aircraftModel = new AircraftItemModel(this); + connect(m_aircraftModel, &AircraftItemModel::packagesNeedUpdating, + this, &LauncherMainWindow::onPackagesNeedUpdate); m_aircraftProxy->setSourceModel(m_aircraftModel); m_aircraftProxy->setFilterCaseSensitivity(Qt::CaseInsensitive); @@ -241,6 +223,9 @@ LauncherMainWindow::LauncherMainWindow() : connect(m_aircraftProxy, &AircraftProxyModel::modelReset, this, &LauncherMainWindow::delayedAircraftModelReset); + connect(m_ui->updateAircraftLabel, &QLabel::linkActivated, + this, &LauncherMainWindow::onUpdateAircraftLink); + QSettings settings; m_aircraftModel->setPaths(settings.value("aircraft-paths").toStringList()); m_aircraftModel->setPackageRoot(globals->packageRoot()); @@ -254,6 +239,7 @@ LauncherMainWindow::LauncherMainWindow() : m_ui->stack->addWidget(m_viewCommandLinePage); checkOfficialCatalogMessage(); + checkUpdateAircraft(); restoreSettings(); updateSettingsSummary(); } @@ -833,14 +819,6 @@ void LauncherMainWindow::updateSelectedAircraft() } } -void LauncherMainWindow::onUpdateAllAircraft() -{ - const PackageList& toBeUpdated = globals->packageRoot()->packagesNeedingUpdate(); - std::for_each(toBeUpdated.begin(), toBeUpdated.end(), [](PackageRef pkg) { - globals->packageRoot()->scheduleToUpdate(pkg->install()); - }); -} - void LauncherMainWindow::onPackagesNeedUpdate(bool yes) { Q_UNUSED(yes); @@ -1034,22 +1012,28 @@ void LauncherMainWindow::onOfficialCatalogMessageLink(QUrl link) void LauncherMainWindow::checkUpdateAircraft() { - if (shouldShowOfficialCatalogMessage()) { - return; // don't interfere - } + const size_t numToUpdate = globals->packageRoot()->packagesNeedingUpdate().size(); + const bool showUpdateMessage = (numToUpdate > 0); - const bool showUpdateMessage = !globals->packageRoot()->packagesNeedingUpdate().empty(); - m_aircraftModel->setMessageWidgetVisible(showUpdateMessage); - if (showUpdateMessage) { - UpdateAllAircraftMessage* messageWidget = new UpdateAllAircraftMessage; - // connect(messageWidget, &UpdateAllAircraftMessage::linkActivated, - // this, &LauncherMainWindow::onMessageLink); - connect(messageWidget, &UpdateAllAircraftMessage::updateAll, this, &LauncherMainWindow::onUpdateAllAircraft); - QModelIndex index = m_aircraftProxy->mapFromSource(m_aircraftModel->messageWidgetIndex()); - m_ui->aircraftList->setIndexWidget(index, messageWidget); - } + static QString originalText = m_ui->updateAircraftLabel->text(); + const QString t = originalText.arg(numToUpdate); + m_ui->updateAircraftLabel->setText(t); + m_ui->updateAircraftLabel->setVisible(showUpdateMessage); } +void LauncherMainWindow::onUpdateAircraftLink(QUrl link) +{ + QString s = link.toString(); + if (s == "action:hide") { + m_ui->updateAircraftLabel->hide(); + } else if (s == "action:update") { + m_ui->updateAircraftLabel->hide(); + const PackageList& toBeUpdated = globals->packageRoot()->packagesNeedingUpdate(); + std::for_each(toBeUpdated.begin(), toBeUpdated.end(), [](PackageRef pkg) { + globals->packageRoot()->scheduleToUpdate(pkg->install()); + }); + } +} simgear::pkg::PackageRef LauncherMainWindow::packageForAircraftURI(QUrl uri) const { diff --git a/src/GUI/LauncherMainWindow.hxx b/src/GUI/LauncherMainWindow.hxx index eff15cb16..4cf254b47 100644 --- a/src/GUI/LauncherMainWindow.hxx +++ b/src/GUI/LauncherMainWindow.hxx @@ -98,8 +98,6 @@ private slots: Q_INVOKABLE void onDownloadDirChanged(); - void onUpdateAllAircraft(); - void onPackagesNeedUpdate(bool yes); void onClickToolboxButton(); @@ -110,6 +108,7 @@ private slots: void onChangeDataDir(); void onSettingsSearchChanged(); + void onUpdateAircraftLink(QUrl link); private: /** diff --git a/src/GUI/UpdateAllAircraft.ui b/src/GUI/UpdateAllAircraft.ui deleted file mode 100644 index c66a22655..000000000 --- a/src/GUI/UpdateAllAircraft.ui +++ /dev/null @@ -1,50 +0,0 @@ - - - UpdateAllAircraftMessage - - - - 0 - 0 - 607 - 44 - - - - Form - - - - :/app-icon-large:/app-icon-large - - - false - - - - - - <html><head/><body><p>%1 aircraft have updates available. (<a href="action:hide"><span style=" text-decoration: underline; color:#0000ff;">Click</span></a> to hide this)</p></body></html> - - - Qt::RichText - - - true - - - - - - - Update all - - - - - - - - - -