diff --git a/src/blackgui/components/copyconfigurationcomponent.cpp b/src/blackgui/components/copyconfigurationcomponent.cpp index c1343f199..6eb9fe917 100644 --- a/src/blackgui/components/copyconfigurationcomponent.cpp +++ b/src/blackgui/components/copyconfigurationcomponent.cpp @@ -419,7 +419,7 @@ namespace BlackGui void CCopyConfigurationComponent::initOtherSwiftVersions() { ui->cb_OtherVersions->clear(); - const QMap otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(true); + const QMap otherVersions = CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion(); for (const QString &directory : otherVersions.keys()) { const CApplicationInfo info(otherVersions.value(directory)); @@ -445,8 +445,8 @@ namespace BlackGui void CCopyConfigurationComponent::setWidths() { const int w = this->width(); - const int wCb = 0.45 * w; - const int wView = 0.4 * w; + const int wCb = qRound(0.45 * w); + const int wView = qRound(0.4 * w); ui->cb_OtherVersions->setMaximumWidth(wCb); ui->tv_Destination->setMinimumWidth(wView); ui->tv_Source->setMinimumWidth(wView); diff --git a/src/blackgui/components/copyconfigurationcomponent.h b/src/blackgui/components/copyconfigurationcomponent.h index 4aae1dbdd..aa3f88345 100644 --- a/src/blackgui/components/copyconfigurationcomponent.h +++ b/src/blackgui/components/copyconfigurationcomponent.h @@ -122,9 +122,9 @@ namespace BlackGui QStringList m_otherVersionDirs; QString m_initializedSourceDir; QString m_initializedDestinationDir; - bool m_logCopiedFiles = true; - bool m_nameFilterDisables = false; //!< name filter disables or hides - bool m_withBootstrapFile = false; + bool m_logCopiedFiles = true; + bool m_nameFilterDisables = false; //!< name filter disables or hides + bool m_withBootstrapFile = false; bool m_hasOtherSwiftVersions = false; // caches will be explicitly initialized in initCaches @@ -135,11 +135,11 @@ namespace BlackGui // those caches do not harm if they exists default initialized //! \fixme this is a workaround, as it creates files on disk even if those are not copied. It was much nicer if the cache would init themself if the file appears BlackMisc::CData m_lastServer { this }; //!< recently used server (VATSIM, other) - BlackMisc::CData m_modelSetCurrentSimulator { this }; - BlackMisc::CData m_modelsCurrentSimulator { this }; + BlackMisc::CData m_modelSetCurrentSimulator { this }; + BlackMisc::CData m_modelsCurrentSimulator { this }; BlackMisc::CData m_lastAircraftModel { this }; //!< recently used aircraft model - BlackMisc::CData m_launcherSetup { this }; - BlackMisc::CData m_vatsimSetup { this }; + BlackMisc::CData m_launcherSetup { this }; + BlackMisc::CData m_vatsimSetup { this }; BlackMisc::CData m_lastVatsimServer { this }; //!< recently used VATSIM server }; diff --git a/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp b/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp index 57ccc8daa..0e047379a 100644 --- a/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp +++ b/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp @@ -46,8 +46,8 @@ namespace BlackGui void CCopyModelsFromOtherSwiftVersionsComponent::copy() { const CSimulatorInfo selectedSimulators = ui->comp_SimulatorSelector->getValue(); - const QSet sims = selectedSimulators.asSingleSimulatorSet(); - if (sims.isEmpty()) + const QSet simulators = selectedSimulators.asSingleSimulatorSet(); + if (simulators.isEmpty()) { static const CStatusMessage m = CStatusMessage(this).validationError("No simulators selected"); this->showOverlayMessage(m); @@ -73,22 +73,22 @@ namespace BlackGui int sets = 0; int caches = 0; const CApplicationInfo otherVersion = ui->comp_OtherSwiftVersions->selectedOtherVersion(); - for (const CSimulatorInfo &sim : sims) + for (const CSimulatorInfo &simulator : simulators) { if (set) { // inits current version cache - m_modelSetCaches.synchronizeCache(sim); + m_modelSetCaches.synchronizeCache(simulator); // get file name CAircraftModelList otherSet; - const QString thisVersionModelSetFile = m_modelSetCaches.getFilename(sim); - if (this->readDataFile(thisVersionModelSetFile, otherSet, otherVersion, sim) && !otherSet.isEmpty()) + const QString thisVersionModelSetFile = m_modelSetCaches.getFilename(simulator); + if (this->readDataFile(thisVersionModelSetFile, otherSet, otherVersion, simulator) && !otherSet.isEmpty()) { CApplication::processEventsFor(250); - if (this->confirmOverride(QString("Override model set for '%1'").arg(sim.toQString()))) + if (this->confirmOverride(QString("Override model set for '%1'").arg(simulator.toQString()))) { - m_modelSetCaches.setModelsForSimulator(otherSet, sim); + m_modelSetCaches.setModelsForSimulator(otherSet, simulator); } } sets++; @@ -97,17 +97,17 @@ namespace BlackGui if (cache) { // inits current version cache - m_modelCaches.synchronizeCache(sim); + m_modelCaches.synchronizeCache(simulator); // get file name CAircraftModelList otherCache; - const QString thisVersionModelCacheFile = m_modelCaches.getFilename(sim); - if (this->readDataFile(thisVersionModelCacheFile, otherCache, otherVersion, sim) && !otherCache.isEmpty()) + const QString thisVersionModelCacheFile = m_modelCaches.getFilename(simulator); + if (this->readDataFile(thisVersionModelCacheFile, otherCache, otherVersion, simulator) && !otherCache.isEmpty()) { CApplication::processEventsFor(250); - if (this->confirmOverride(QString("Override model cache for '%1'").arg(sim.toQString()))) + if (this->confirmOverride(QString("Override model cache for '%1'").arg(simulator.toQString()))) { - m_modelCaches.setModelsForSimulator(otherCache, sim); + m_modelCaches.setModelsForSimulator(otherCache, simulator); } } caches++; @@ -186,6 +186,17 @@ namespace BlackGui ui->comp_SimulatorSelector->setValue(setSims); } + void CCopyModelsFromOtherSwiftVersionsComponent::reloadOtherVersions() + { + ui->comp_OtherSwiftVersions->reloadOtherVersions(); + } + + void CCopyModelsFromOtherSwiftVersionsWizardPage::initializePage() + { + // force reload as the other version could be changed + if (m_copyModels) { m_copyModels->reloadOtherVersions(); } + } + bool CCopyModelsFromOtherSwiftVersionsWizardPage::validatePage() { Q_ASSERT_X(m_copyModels, Q_FUNC_INFO, "Missing widget"); diff --git a/src/blackgui/components/copymodelsfromotherswiftversionscomponent.h b/src/blackgui/components/copymodelsfromotherswiftversionscomponent.h index c45a4f6ca..bf5f5a2f2 100644 --- a/src/blackgui/components/copymodelsfromotherswiftversionscomponent.h +++ b/src/blackgui/components/copymodelsfromotherswiftversionscomponent.h @@ -38,6 +38,9 @@ namespace BlackGui //! Dtor virtual ~CCopyModelsFromOtherSwiftVersionsComponent(); + //! Reload other versions + void reloadOtherVersions(); + private: //! Copy as per UI settings void copy(); @@ -54,7 +57,7 @@ namespace BlackGui QScopedPointer ui; // caches will be explicitly initialized in copy - BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; + BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this }; }; @@ -70,6 +73,9 @@ namespace BlackGui //! Set config void setConfigComponent(CCopyModelsFromOtherSwiftVersionsComponent *config) { m_copyModels = config; } + //! \copydoc QWizardPage::initializePage + virtual void initializePage() override; + //! \copydoc QWizardPage::validatePage virtual bool validatePage() override; diff --git a/src/blackgui/components/copysettingsandcachescomponent.cpp b/src/blackgui/components/copysettingsandcachescomponent.cpp index 37f230327..a1d6844b4 100644 --- a/src/blackgui/components/copysettingsandcachescomponent.cpp +++ b/src/blackgui/components/copysettingsandcachescomponent.cpp @@ -53,6 +53,11 @@ namespace BlackGui CCopySettingsAndCachesComponent::~CCopySettingsAndCachesComponent() { } + void CCopySettingsAndCachesComponent::reloadOtherVersions() + { + ui->comp_OtherSwiftVersions->reloadOtherVersions(); + } + void CCopySettingsAndCachesComponent::onOtherVersionChanged(const CApplicationInfo &info) { readOnlyCheckbox(ui->cb_SettingsAudio, !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsAudio.getFilename())); @@ -396,7 +401,7 @@ namespace BlackGui if (copied > 0) { const CStatusMessage m = CStatusMessage(this).validationInfo("Copied %1 settings") << copied; - this->showOverlayMessage(m); + this->showOverlayHTMLMessage(m); } return copied; @@ -469,6 +474,12 @@ namespace BlackGui return setting ? s.arg(text) : c.arg(text); } + void CCopySettingsAndCachesWizardPage::initializePage() + { + // re-init other versions + if (m_copyCachesAndSettings) { m_copyCachesAndSettings->reloadOtherVersions(); } + } + bool CCopySettingsAndCachesWizardPage::validatePage() { return true; diff --git a/src/blackgui/components/copysettingsandcachescomponent.h b/src/blackgui/components/copysettingsandcachescomponent.h index 38c7c89d0..977f6b951 100644 --- a/src/blackgui/components/copysettingsandcachescomponent.h +++ b/src/blackgui/components/copysettingsandcachescomponent.h @@ -57,6 +57,9 @@ namespace BlackGui //! Dtor virtual ~CCopySettingsAndCachesComponent(); + //! Reload other versions + void reloadOtherVersions(); + private: //! Other version has been changed void onOtherVersionChanged(const BlackMisc::CApplicationInfo &info); @@ -111,14 +114,14 @@ namespace BlackGui QScopedPointer ui; - BlackMisc::CSetting m_settingsAudioInputDevice { this }; + BlackMisc::CSetting m_settingsAudioInputDevice { this }; BlackMisc::CSetting m_settingsAudioOutputDevice { this }; BlackMisc::CSetting m_settingsGuiGeneral { this }; BlackMisc::CSetting m_settingsDockWidget { this }; BlackMisc::CSetting m_settingsViewUpdate { this }; BlackMisc::CSetting m_settingsConsolidation { this }; //!< consolidation time BlackMisc::CSetting m_settingsAtcStations { this }; - BlackMisc::CSetting m_settingsTextMessage { this }; + BlackMisc::CSetting m_settingsTextMessage { this }; BlackMisc::CSetting m_settingsEnabledSimulators { this }; BlackMisc::CSetting m_settingsActionHotkeys { this }; BlackMisc::CSetting m_settingsAudio { this }; @@ -127,7 +130,7 @@ namespace BlackGui BlackMisc::CSetting m_settingsSimulatorFsx { this }; //!< FSX settings BlackMisc::CSetting m_settingsSimulatorFs9 { this }; //!< FS9 settings BlackMisc::CSetting m_settingsSimulatorP3D { this }; //!< P3D settings - BlackMisc::CSetting m_settingsSimulatorXPlane { this }; //!< XP settings + BlackMisc::CSetting m_settingsSimulatorXPlane { this }; //!< XP settings BlackMisc::CSetting m_settingsModel { this }; //!< model setting BlackMisc::CData m_cacheLastVatsimServer { this }; //!< recently used VATSIM server @@ -151,6 +154,9 @@ namespace BlackGui //! Set config void setConfigComponent(CCopySettingsAndCachesComponent *config) { m_copyCachesAndSettings = config; } + //! \copydoc QWizardPage::initializePage + virtual void initializePage() override; + //! \copydoc QWizardPage::validatePage virtual bool validatePage() override; diff --git a/src/blackgui/components/otherswiftversionscomponent.cpp b/src/blackgui/components/otherswiftversionscomponent.cpp index 7df9080ae..bdb29fdde 100644 --- a/src/blackgui/components/otherswiftversionscomponent.cpp +++ b/src/blackgui/components/otherswiftversionscomponent.cpp @@ -36,7 +36,7 @@ namespace BlackGui connect(ui->tb_DataDir, &QToolButton::clicked, this, &COtherSwiftVersionsComponent::openDataDirectory); connect(ui->tvp_ApplicationInfo, &CApplicationInfoView::objectSelected, this, &COtherSwiftVersionsComponent::onObjectSelected); - connect(ui->tvp_ApplicationInfo, &CApplicationInfoView::requestUpdate, this, &COtherSwiftVersionsComponent::reloadVersions); + connect(ui->tvp_ApplicationInfo, &CApplicationInfoView::requestUpdate, this, &COtherSwiftVersionsComponent::reloadOtherVersions); } COtherSwiftVersionsComponent::~COtherSwiftVersionsComponent() @@ -53,9 +53,9 @@ namespace BlackGui return ui->tvp_ApplicationInfo->selectedObject(); } - void COtherSwiftVersionsComponent::reloadVersions() + void COtherSwiftVersionsComponent::reloadOtherVersions() { - ui->tvp_ApplicationInfo->otherSwiftVersionsFromDataDirectories(); + ui->tvp_ApplicationInfo->otherSwiftVersionsFromDataDirectories(true); } void COtherSwiftVersionsComponent::openDataDirectory() diff --git a/src/blackgui/components/otherswiftversionscomponent.h b/src/blackgui/components/otherswiftversionscomponent.h index 695c58834..8f8c02940 100644 --- a/src/blackgui/components/otherswiftversionscomponent.h +++ b/src/blackgui/components/otherswiftversionscomponent.h @@ -41,6 +41,9 @@ namespace BlackGui //! Get the selected other version BlackMisc::CApplicationInfo selectedOtherVersion() const; + //! Reload versions + void reloadOtherVersions(); + signals: //! Selection changed void versionChanged(const BlackMisc::CApplicationInfo &info); @@ -48,9 +51,6 @@ namespace BlackGui private: QScopedPointer ui; - //! Reload versions - void reloadVersions(); - //! Data directory void openDataDirectory(); diff --git a/src/blackgui/views/applicationinfoview.cpp b/src/blackgui/views/applicationinfoview.cpp index 766ea32a3..2f1defe98 100644 --- a/src/blackgui/views/applicationinfoview.cpp +++ b/src/blackgui/views/applicationinfoview.cpp @@ -27,9 +27,9 @@ namespace BlackGui this->setCustomMenu(new CApplicationInfoMenu(this)); } - int CApplicationInfoView::otherSwiftVersionsFromDataDirectories() + int CApplicationInfoView::otherSwiftVersionsFromDataDirectories(bool reInit) { - const CApplicationInfoList others = CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories(); + const CApplicationInfoList others = CApplicationInfoList::fromOtherSwiftVersionsFromDataDirectories(reInit); this->updateContainer(others); m_acceptRowSelection = (others.size() > 0); return others.size(); @@ -53,7 +53,7 @@ namespace BlackGui } } if (deletedDirectories.isEmpty()) { return; } - this->otherSwiftVersionsFromDataDirectories(); + this->otherSwiftVersionsFromDataDirectories(true); } void CApplicationInfoMenu::customMenu(CMenuActions &menuActions) diff --git a/src/blackgui/views/applicationinfoview.h b/src/blackgui/views/applicationinfoview.h index daf5774ee..5ab90171a 100644 --- a/src/blackgui/views/applicationinfoview.h +++ b/src/blackgui/views/applicationinfoview.h @@ -31,7 +31,7 @@ namespace BlackGui explicit CApplicationInfoView(QWidget *parent = nullptr); //! BlackMisc::CApplicationInfoList::otherSwiftVersionsFromDataDirectories - int otherSwiftVersionsFromDataDirectories(); + int otherSwiftVersionsFromDataDirectories(bool reInit = false); //! Delete the selected directories void deleteSelectedDataDirectories(); diff --git a/src/blackmisc/applicationinfolist.cpp b/src/blackmisc/applicationinfolist.cpp index 436476df8..b63f846c0 100644 --- a/src/blackmisc/applicationinfolist.cpp +++ b/src/blackmisc/applicationinfolist.cpp @@ -45,7 +45,10 @@ namespace BlackMisc int CApplicationInfoList::otherSwiftVersionsFromDataDirectories(bool reinit) { this->clear(); - const QMap otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(reinit); + const QMap otherVersions = reinit ? + CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion() : + CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(); + for (const QString &directory : otherVersions.keys()) { CApplicationInfo info(otherVersions.value(directory)); diff --git a/src/blackmisc/directoryutils.cpp b/src/blackmisc/directoryutils.cpp index 3aa234fcd..337212af4 100644 --- a/src/blackmisc/directoryutils.cpp +++ b/src/blackmisc/directoryutils.cpp @@ -117,15 +117,17 @@ namespace BlackMisc const QFileInfoList &CDirectoryUtils::applicationDataDirectories() { - static const QFileInfoList fileInfoList([] - { - const QDir swiftAppData(CDirectoryUtils::applicationDataDirectory()); // contains 1..n subdirs - if (!swiftAppData.isReadable()) { return QFileInfoList(); } - return swiftAppData.entryInfoList({}, QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time); - }()); + static QFileInfoList fileInfoList = currentApplicationDataDirectories(); return fileInfoList; } + QFileInfoList CDirectoryUtils::currentApplicationDataDirectories() + { + const QDir swiftAppData(CDirectoryUtils::applicationDataDirectory()); // contains 1..n subdirs + if (!swiftAppData.isReadable()) { return QFileInfoList(); } + return swiftAppData.entryInfoList({}, QDir::Dirs | QDir::NoDotAndDotDot, QDir::Time); + } + int CDirectoryUtils::applicationDataDirectoriesCount() { return CDirectoryUtils::applicationDataDirectories().size(); @@ -144,14 +146,18 @@ namespace BlackMisc return dirs; } - const CDirectoryUtils::FilePerApplication &CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(bool reinit) + const CDirectoryUtils::FilePerApplication &CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion() { - static FilePerApplication dirs; - if (!reinit && !dirs.isEmpty()) { return dirs; } + static const FilePerApplication directories = currentApplicationDataDirectoryMapWithoutCurrentVersion(); + return directories; + } + CDirectoryUtils::FilePerApplication CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion() + { FilePerApplication directories; - for (const QFileInfo &info : CDirectoryUtils::applicationDataDirectories()) + for (const QFileInfo &info : CDirectoryUtils::currentApplicationDataDirectories()) { + // check for myself (the running swift) if (caseInsensitiveStringCompare(info.filePath(), CDirectoryUtils::normalizedApplicationDataDirectory())) { continue; } // the application info will be written by each swift application started @@ -161,6 +167,7 @@ namespace BlackMisc CApplicationInfo appInfo; if (appInfoJson.isEmpty()) { + // no JSON means the app no longer exists const QString exeDir = CDirectoryUtils::decodeNormalizedDirectory(info.filePath()); appInfo.setExecutablePath(exeDir); } @@ -172,13 +179,12 @@ namespace BlackMisc directories.insert(info.filePath(), appInfo); } - dirs = directories; - return dirs; + return directories; } - bool CDirectoryUtils::hasOtherSwiftDataDirectories(bool reinit) + bool CDirectoryUtils::hasOtherSwiftDataDirectories() { - return CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(reinit).size() > 0; + return CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion().size() > 0; } const QString &CDirectoryUtils::normalizedApplicationDataDirectory() diff --git a/src/blackmisc/directoryutils.h b/src/blackmisc/directoryutils.h index 313c09de7..b0fe340f5 100644 --- a/src/blackmisc/directoryutils.h +++ b/src/blackmisc/directoryutils.h @@ -58,14 +58,20 @@ namespace BlackMisc //! number of data directories (including this version) static int applicationDataDirectoriesCount(); + //! swift application data sub directories + static QFileInfoList currentApplicationDataDirectories(); + //! swift application data sub directories static QStringList applicationDataDirectoryList(bool withoutCurrent = false, bool decodedDirName = false); //! swift application data sub directories with info if available - static const FilePerApplication &applicationDataDirectoryMapWithoutCurrentVersion(bool reinit = false); + static const FilePerApplication &applicationDataDirectoryMapWithoutCurrentVersion(); + + //! swift application data sub directories with info if available + static FilePerApplication currentApplicationDataDirectoryMapWithoutCurrentVersion(); //! Other swift data directories - static bool hasOtherSwiftDataDirectories(bool reinit = false); + static bool hasOtherSwiftDataDirectories(); //! Is MacOS application bundle? //! \remark: Means the currently running executable is a MacOS bundle, but not all our executables are bundles on MacOS