Improved version of "Allow to delete data directory from application view"

- split functions into dynamic loading and const versions (loading at startup)
- reload other versions from wizard in case they changed
- some renaming/formatting
This commit is contained in:
Klaus Basan
2018-12-02 04:27:59 +01:00
parent d18c763869
commit 7fc6fcb867
13 changed files with 104 additions and 55 deletions

View File

@@ -419,7 +419,7 @@ namespace BlackGui
void CCopyConfigurationComponent::initOtherSwiftVersions()
{
ui->cb_OtherVersions->clear();
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(true);
const QMap<QString, CApplicationInfo> 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);

View File

@@ -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<BlackMisc::Network::Data::TLastServer> m_lastServer { this }; //!< recently used server (VATSIM, other)
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_modelSetCurrentSimulator { this };
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_modelsCurrentSimulator { this };
BlackMisc::CData<BlackMisc::Simulation::Data::TSimulatorLastSelection> m_modelSetCurrentSimulator { this };
BlackMisc::CData<BlackMisc::Simulation::Data::TModelCacheLastSelection> m_modelsCurrentSimulator { this };
BlackMisc::CData<BlackMisc::Simulation::Data::TLastModel> m_lastAircraftModel { this }; //!< recently used aircraft model
BlackMisc::CData<BlackCore::Data::TLauncherSetup> m_launcherSetup { this };
BlackMisc::CData<BlackCore::Data::TVatsimSetup> m_vatsimSetup { this };
BlackMisc::CData<BlackCore::Data::TLauncherSetup> m_launcherSetup { this };
BlackMisc::CData<BlackCore::Data::TVatsimSetup> m_vatsimSetup { this };
BlackMisc::CData<BlackCore::Data::TVatsimLastServer> m_lastVatsimServer { this }; //!< recently used VATSIM server
};

View File

@@ -46,8 +46,8 @@ namespace BlackGui
void CCopyModelsFromOtherSwiftVersionsComponent::copy()
{
const CSimulatorInfo selectedSimulators = ui->comp_SimulatorSelector->getValue();
const QSet<CSimulatorInfo> sims = selectedSimulators.asSingleSimulatorSet();
if (sims.isEmpty())
const QSet<CSimulatorInfo> 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");

View File

@@ -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::CCopyModelsFromOtherSwiftVersionsComponent> 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;

View File

@@ -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;

View File

@@ -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::CCopySettingsAndCachesComponent> ui;
BlackMisc::CSetting<BlackCore::Audio::TInputDevice> m_settingsAudioInputDevice { this };
BlackMisc::CSetting<BlackCore::Audio::TInputDevice> m_settingsAudioInputDevice { this };
BlackMisc::CSetting<BlackCore::Audio::TOutputDevice> m_settingsAudioOutputDevice { this };
BlackMisc::CSetting<Settings::TGeneralGui> m_settingsGuiGeneral { this };
BlackMisc::CSetting<Settings::TDockWidget> m_settingsDockWidget { this };
BlackMisc::CSetting<Settings::TViewUpdateSettings> m_settingsViewUpdate { this };
BlackMisc::CSetting<Settings::TBackgroundConsolidation> m_settingsConsolidation { this }; //!< consolidation time
BlackMisc::CSetting<Settings::TAtcStationsSettings> m_settingsAtcStations { this };
BlackMisc::CSetting<Settings::TextMessageSettings> m_settingsTextMessage { this };
BlackMisc::CSetting<Settings::TextMessageSettings> m_settingsTextMessage { this };
BlackMisc::CSetting<BlackCore::Application::TEnabledSimulators> m_settingsEnabledSimulators { this };
BlackMisc::CSetting<BlackCore::Application::TActionHotkeys> m_settingsActionHotkeys { this };
BlackMisc::CSetting<BlackCore::Audio::TSettings> m_settingsAudio { this };
@@ -127,7 +130,7 @@ namespace BlackGui
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorFsx> m_settingsSimulatorFsx { this }; //!< FSX settings
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorFs9> m_settingsSimulatorFs9 { this }; //!< FS9 settings
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorP3D> m_settingsSimulatorP3D { this }; //!< P3D settings
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorXP> m_settingsSimulatorXPlane { this }; //!< XP settings
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TSimulatorXP> m_settingsSimulatorXPlane { this }; //!< XP settings
BlackMisc::CSetting<BlackMisc::Simulation::Settings::TModel> m_settingsModel { this }; //!< model setting
BlackMisc::CData<BlackCore::Data::TVatsimLastServer> 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;

View File

@@ -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()

View File

@@ -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::COtherSwiftVersionsComponent> ui;
//! Reload versions
void reloadVersions();
//! Data directory
void openDataDirectory();