7#include <QRegularExpression>
8#include <QStringBuilder>
10#include "ui_copysettingsandcachescomponent.h"
20using namespace swift::misc::audio;
21using namespace swift::misc::input;
22using namespace swift::misc::network;
23using namespace swift::misc::network::data;
24using namespace swift::misc::network::settings;
26using namespace swift::misc::simulation::settings;
27using namespace swift::core::audio;
28using namespace swift::core::application;
30using namespace swift::gui::settings;
39 this->allCheckBoxesReadOnly();
44 &CCopySettingsAndCachesComponent::onOtherVersionChanged);
51 ui->comp_OtherSwiftVersions->reloadOtherVersionsDeferred(deferMs);
54 void CCopySettingsAndCachesComponent::onOtherVersionChanged(
const CApplicationInfo &info)
56 readOnlyCheckbox(ui->cb_SettingsAudio,
58 readOnlyCheckbox(ui->cb_SettingsAudioInputDevice,
65 readOnlyCheckbox(ui->cb_CacheLastNetworkServer,
67 readOnlyCheckbox(ui->cb_CacheLastVatsimServer,
70 readOnlyCheckbox(ui->cb_SettingsGuiGeneral,
72 readOnlyCheckbox(ui->cb_SettingsDockWidget,
74 readOnlyCheckbox(ui->cb_SettingsViewUpdate,
79 readOnlyCheckbox(ui->cb_SettingsSimulatorP3D,
86 readOnlyCheckbox(ui->cb_SettingsTextMessages,
88 readOnlyCheckbox(ui->cb_SettingsDirectories,
92 info, m_settingsConsolidation.getFilename()));
93 readOnlyCheckbox(ui->cb_SettingsModel,
97 void CCopySettingsAndCachesComponent::initAll()
102 this->initSimulator();
107 void CCopySettingsAndCachesComponent::initAudio()
114 void CCopySettingsAndCachesComponent::initNetwork()
121 void CCopySettingsAndCachesComponent::initUi()
128 void CCopySettingsAndCachesComponent::initSimulator()
135 void CCopySettingsAndCachesComponent::initMisc()
142 void CCopySettingsAndCachesComponent::initModel()
148 int CCopySettingsAndCachesComponent::copy()
150 ui->le_Status->clear();
152 const CApplicationInfo otherVersionInfo = ui->comp_OtherSwiftVersions->selectedOtherVersion();
153 if (otherVersionInfo.
isNull())
158 bool success =
false;
161 ui->le_Status->setText(
"Starting to copy from '" + otherVersionInfo.
toQString(
true) +
"'");
164 if (ui->cb_SettingsAudio->isChecked())
166 const QString joStr =
170 const audio::CSettings audioSettings = audio::CSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
171 if (this->parsingMessage(success, errMsg, m_settingsAudio.getKey()))
173 this->displayStatusMessage(m_settingsAudio.setAndSave(audioSettings),
180 if (ui->cb_SettingsAudioInputDevice->isChecked())
183 otherVersionInfo, m_settingsAudioInputDevice.getFilename());
184 const QString audioInputSettings = json::firstJsonValueAsString(joStr);
185 if (!audioInputSettings.
isEmpty())
187 this->displayStatusMessage(m_settingsAudioInputDevice.setAndSave(audioInputSettings),
193 if (ui->cb_SettingsAudioOutputDevice->isChecked())
196 otherVersionInfo, m_settingsAudioOutputDevice.getFilename());
197 const QString audioOutputSettings = json::firstJsonValueAsString(joStr);
198 if (!audioOutputSettings.
isEmpty())
200 this->displayStatusMessage(m_settingsAudioOutputDevice.setAndSave(audioOutputSettings),
201 audioOutputSettings);
207 if (ui->cb_SettingsDirectories->isChecked())
210 otherVersionInfo, m_settingsDirectories.getFilename());
213 const CDirectories directories = CDirectories::fromJsonNoThrow(joStr,
true, success, errMsg);
214 if (this->parsingMessage(success, errMsg, m_settingsDirectories.getKey()))
216 this->displayStatusMessage(m_settingsDirectories.setAndSave(directories),
224 if (ui->cb_SettingsNetworkTrafficServers->isChecked())
227 otherVersionInfo, m_settingsNetworkServers.getFilename());
230 const CServerList networkServers = CServerList::fromJsonNoThrow(joStr,
true, success, errMsg);
231 if (this->parsingMessage(success, errMsg, m_settingsNetworkServers.getKey()))
233 this->displayStatusMessage(m_settingsNetworkServers.setAndSave(networkServers),
240 if (ui->cb_CacheLastNetworkServer->isChecked())
243 otherVersionInfo, m_cacheLastNetworkServer.getFilename());
246 const CServer server = CServer::fromJsonNoThrow(joStr,
true, success, errMsg);
247 if (this->parsingMessage(success, errMsg, m_cacheLastNetworkServer.getKey()))
249 this->displayStatusMessage(m_cacheLastNetworkServer.set(server), server.
toQString(
true));
255 if (ui->cb_CacheLastVatsimServer->isChecked())
258 otherVersionInfo, m_cacheLastVatsimServer.getFilename());
261 const CServer server = CServer::fromJsonNoThrow(joStr,
true, success, errMsg);
262 if (this->parsingMessage(success, errMsg, m_cacheLastVatsimServer.getKey()))
264 this->displayStatusMessage(m_cacheLastVatsimServer.set(server), server.
toQString(
true));
271 if (ui->cb_SettingsGuiGeneral->isChecked())
274 otherVersionInfo, m_settingsGuiGeneral.getFilename());
277 const CGeneralGuiSettings guiGeneral =
278 CGeneralGuiSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
279 this->displayStatusMessage(m_settingsGuiGeneral.setAndSave(guiGeneral), guiGeneral.
toQString(
true));
284 if (ui->cb_SettingsDockWidget->isChecked())
287 otherVersionInfo, m_settingsDockWidget.getFilename());
290 const CDockWidgetSettings dwSettings =
291 CDockWidgetSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
292 this->displayStatusMessage(m_settingsDockWidget.setAndSave(dwSettings), dwSettings.
toQString(
true));
297 if (ui->cb_SettingsViewUpdate->isChecked())
300 otherVersionInfo, m_settingsViewUpdate.getFilename());
303 const CViewUpdateSettings viewUpdate =
304 CViewUpdateSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
305 this->displayStatusMessage(m_settingsViewUpdate.setAndSave(viewUpdate), viewUpdate.
toQString(
true));
311 if (ui->cb_SettingsEnabledSimulators->isChecked())
314 otherVersionInfo, m_settingsEnabledSimulators.getFilename());
317 const QStringList enabledSims = json::firstJsonValueAsStringList(joStr);
320 this->displayStatusMessage(m_settingsEnabledSimulators.setAndSave(enabledSims),
321 enabledSims.
join(
", "));
327 if (ui->cb_SettingsSimulatorP3D->isChecked())
330 otherVersionInfo, m_settingsSimulatorP3D.getFilename());
333 const CSimulatorSettings settings = CSimulatorSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
334 if (this->parsingMessage(success, errMsg, m_settingsSimulatorP3D.getKey()))
336 this->displayStatusMessage(m_settingsSimulatorP3D.setAndSave(settings), settings.
toQString(
true));
342 if (ui->cb_SettingsSimulatorXPlane->isChecked())
345 otherVersionInfo, m_settingsSimulatorXPlane.getFilename());
348 const CSimulatorSettings settings = CSimulatorSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
349 if (this->parsingMessage(success, errMsg, m_settingsSimulatorXPlane.getKey()))
351 this->displayStatusMessage(m_settingsSimulatorXPlane.setAndSave(settings),
359 if (ui->cb_SettingsModel->isChecked())
361 const QString joStr =
365 const CModelSettings settings = CModelSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
366 if (this->parsingMessage(success, errMsg, m_settingsModel.getKey()))
368 this->displayStatusMessage(m_settingsModel.setAndSave(settings), settings.
toQString(
true));
374 if (ui->cb_SettingsConsolidation->isChecked())
377 otherVersionInfo, m_settingsConsolidation.getFilename());
381 const int consolidation = json::firstJsonValueAsInt(joStr, -1, &ok);
384 this->displayStatusMessage(m_settingsConsolidation.setAndSave(consolidation),
392 if (ui->cb_SettingsActionHotkeys->isChecked())
395 otherVersionInfo, m_settingsActionHotkeys.getFilename());
398 CActionHotkeyList hotkeys = CActionHotkeyList::fromJsonNoThrow(joStr,
true, success, errMsg);
400 if (this->parsingMessage(success, errMsg, m_settingsActionHotkeys.getKey()))
402 this->displayStatusMessage(m_settingsActionHotkeys.setAndSave(hotkeys), hotkeys.
toQString(
true));
408 if (ui->cb_SettingsTextMessages->isChecked())
411 otherVersionInfo, m_settingsTextMessage.getFilename());
414 const CTextMessageSettings settings =
415 CTextMessageSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
416 if (this->parsingMessage(success, errMsg, m_settingsTextMessage.getKey()))
418 this->displayStatusMessage(m_settingsTextMessage.setAndSave(settings), settings.
toQString(
true));
426 const CStatusMessage m = CStatusMessage(
this).validationInfo(u
"Copied %1 settings") << copied;
433 void CCopySettingsAndCachesComponent::selectAll()
435 for (QCheckBox *cb : this->checkBoxes())
437 cb->setChecked(cb->isEnabled());
441 void CCopySettingsAndCachesComponent::deselectAll()
443 for (QCheckBox *cb : this->checkBoxes())
445 cb->setChecked(
false);
451 bool CCopySettingsAndCachesComponent::parsingMessage(
bool success,
const QString &msg,
const QString &value)
457 const CStatusMessage sm(
this, msg);
458 this->displayStatusMessage(sm, value);
462 void CCopySettingsAndCachesComponent::displayStatusMessage(
const CStatusMessage &msg,
const QString &value)
474 ui->le_Status->setText(msg.
getMessage() % u
' ' % value);
482 void CCopySettingsAndCachesComponent::allCheckBoxesReadOnly()
484 for (QCheckBox *cb : checkBoxes())
486 readOnlyCheckbox(cb,
true);
490 void CCopySettingsAndCachesComponent::readOnlyCheckbox(QCheckBox *cb,
bool readOnly)
492 Q_ASSERT_X(cb, Q_FUNC_INFO,
"need checkbox");
502 QString CCopySettingsAndCachesComponent::checkBoxText(
const QString &text,
bool setting)
504 return setting ? QStringLiteral(
"%1 [setting]").arg(text) : QStringLiteral(
"%1 [cache]").arg(text);
510 if (m_copyCachesAndSettings)
512 m_copyCachesAndSettings->reloadOtherVersions(1000);
void processEventsToRefreshGui() const
Allow the GUI to refresh by processing events, call the event loop.
static void checkBoxReadOnly(QCheckBox *checkBox, bool readOnly)
Pseudo readonly state for checkbox.
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
COverlayMessagesFrame(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor.
CCopySettingsAndCachesComponent(QWidget *parent=nullptr)
Ctor.
void reloadOtherVersions(int deferMs=-1)
Reload other versions.
~CCopySettingsAndCachesComponent()
Dtor.
void versionChanged(const swift::misc::CApplicationInfo &info)
Selection changed.
Description of a swift application.
bool isNull() const
Null object.
static bool hasOtherVersionSettingsFile(const swift::misc::CApplicationInfo &info, const QString &mySettingFile)
Has the settings file for the given other version?
static QString otherVersionSettingsFileContent(const swift::misc::CApplicationInfo &info, const QString &mySettingFile)
Setting JSON object as string.
static QString otherVersionCacheFileContent(const swift::misc::CApplicationInfo &info, const QString &myCacheFile)
Cache JSON object as string.
static bool hasOtherVersionCacheFile(const swift::misc::CApplicationInfo &info, const QString &myCacheFile)
Has the cache file for the given other version?
QString getFilename() const
Return the file that is used for persistence for this value.
bool isEmpty() const
Message empty.
QString getFilename() const
Return the file that is used for persistence for this value.
QString getMessage() const
Message.
QString toQString(bool i18n=false) const
Cast as QString.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Core data traits (aka cached values) and classes.
High level reusable GUI components.
Classes related to configuration settings.
Free functions in swift::misc.
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QList< T > findChildren(QAnyStringView name, Qt::FindChildOptions options) const const
QObject * parent() const const
bool isEmpty() const const
QString number(double n, char format, int precision)
QString join(QChar separator) const const
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.
static const QString & humanReadable()
Optional human readable name.