7 #include <QRegularExpression>
8 #include <QStringBuilder>
10 #include "ui_copysettingsandcachescomponent.h"
20 using namespace swift::misc::audio;
21 using namespace swift::misc::input;
22 using namespace swift::misc::network;
23 using namespace swift::misc::network::data;
24 using namespace swift::misc::network::settings;
26 using namespace swift::misc::simulation::settings;
27 using namespace swift::core::audio;
28 using namespace swift::core::application;
30 using namespace swift::gui::settings;
34 CCopySettingsAndCachesComponent::CCopySettingsAndCachesComponent(QWidget *parent)
39 this->allCheckBoxesReadOnly();
40 connect(ui->pb_SelectAll, &QPushButton::clicked,
this, &CCopySettingsAndCachesComponent::selectAll);
41 connect(ui->pb_DeselectAll, &QPushButton::clicked,
this, &CCopySettingsAndCachesComponent::deselectAll);
42 connect(ui->pb_Copy, &QPushButton::clicked,
this, &CCopySettingsAndCachesComponent::copy);
44 &CCopySettingsAndCachesComponent::onOtherVersionChanged);
51 ui->comp_OtherSwiftVersions->reloadOtherVersionsDeferred(deferMs);
54 void CCopySettingsAndCachesComponent::onOtherVersionChanged(
const CApplicationInfo &info)
56 readOnlyCheckbox(ui->cb_SettingsAudio,
57 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsAudio.
getFilename()));
58 readOnlyCheckbox(ui->cb_SettingsAudioInputDevice,
59 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsAudio.
getFilename()));
60 readOnlyCheckbox(ui->cb_SettingsAudioOutputDevice, !CCacheSettingsUtils::hasOtherVersionSettingsFile(
63 readOnlyCheckbox(ui->cb_SettingsNetworkTrafficServers, !CCacheSettingsUtils::hasOtherVersionSettingsFile(
65 readOnlyCheckbox(ui->cb_CacheLastNetworkServer,
66 !CCacheSettingsUtils::hasOtherVersionCacheFile(info, m_cacheLastNetworkServer.
getFilename()));
67 readOnlyCheckbox(ui->cb_CacheLastVatsimServer,
68 !CCacheSettingsUtils::hasOtherVersionCacheFile(info, m_cacheLastVatsimServer.
getFilename()));
70 readOnlyCheckbox(ui->cb_SettingsGuiGeneral,
71 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsGuiGeneral.getFilename()));
72 readOnlyCheckbox(ui->cb_SettingsDockWidget,
73 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsDockWidget.getFilename()));
74 readOnlyCheckbox(ui->cb_SettingsViewUpdate,
75 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsViewUpdate.getFilename()));
77 readOnlyCheckbox(ui->cb_SettingsEnabledSimulators, !CCacheSettingsUtils::hasOtherVersionSettingsFile(
79 readOnlyCheckbox(ui->cb_SettingsSimulatorFSX,
80 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsSimulatorFsx.
getFilename()));
81 readOnlyCheckbox(ui->cb_SettingsSimulatorP3D,
82 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsSimulatorP3D.
getFilename()));
83 readOnlyCheckbox(ui->cb_SettingsSimulatorXPlane, !CCacheSettingsUtils::hasOtherVersionSettingsFile(
86 readOnlyCheckbox(ui->cb_SettingsActionHotkeys, !CCacheSettingsUtils::hasOtherVersionSettingsFile(
88 readOnlyCheckbox(ui->cb_SettingsTextMessages,
89 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsTextMessage.getFilename()));
90 readOnlyCheckbox(ui->cb_SettingsDirectories,
91 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsDirectories.
getFilename()));
93 readOnlyCheckbox(ui->cb_SettingsConsolidation, !CCacheSettingsUtils::hasOtherVersionSettingsFile(
94 info, m_settingsConsolidation.getFilename()));
95 readOnlyCheckbox(ui->cb_SettingsModel,
96 !CCacheSettingsUtils::hasOtherVersionSettingsFile(info, m_settingsModel.
getFilename()));
99 void CCopySettingsAndCachesComponent::initAll()
104 this->initSimulator();
109 void CCopySettingsAndCachesComponent::initAudio()
111 ui->cb_SettingsAudio->setText(checkBoxText(TSettings::humanReadable(),
true));
112 ui->cb_SettingsAudioInputDevice->setText(checkBoxText(TInputDevice::humanReadable(),
true));
113 ui->cb_SettingsAudioOutputDevice->setText(checkBoxText(TOutputDevice::humanReadable(),
true));
116 void CCopySettingsAndCachesComponent::initNetwork()
118 ui->cb_SettingsNetworkTrafficServers->setText(checkBoxText(TTrafficServers::humanReadable(),
true));
119 ui->cb_CacheLastNetworkServer->setText(checkBoxText(TLastServer::humanReadable(),
false));
120 ui->cb_CacheLastVatsimServer->setText(checkBoxText(TVatsimLastServer::humanReadable(),
false));
123 void CCopySettingsAndCachesComponent::initUi()
125 ui->cb_SettingsGuiGeneral->setText(checkBoxText(TGeneralGui::humanReadable(),
true));
126 ui->cb_SettingsDockWidget->setText(checkBoxText(TDockWidget::humanReadable(),
true));
127 ui->cb_SettingsViewUpdate->setText(checkBoxText(TViewUpdateSettings::humanReadable(),
true));
130 void CCopySettingsAndCachesComponent::initSimulator()
132 ui->cb_SettingsEnabledSimulators->setText(checkBoxText(TEnabledSimulators::humanReadable(),
true));
133 ui->cb_SettingsSimulatorFSX->setText(checkBoxText(TSimulatorFsx::humanReadable(),
true));
134 ui->cb_SettingsSimulatorP3D->setText(checkBoxText(TSimulatorP3D::humanReadable(),
true));
135 ui->cb_SettingsSimulatorXPlane->setText(checkBoxText(TSimulatorXP::humanReadable(),
true));
138 void CCopySettingsAndCachesComponent::initMisc()
140 ui->cb_SettingsActionHotkeys->setText(checkBoxText(TActionHotkeys::humanReadable(),
true));
141 ui->cb_SettingsTextMessages->setText(checkBoxText(TextMessageSettings::humanReadable(),
true));
142 ui->cb_SettingsDirectories->setText(checkBoxText(TDirectorySettings::humanReadable(),
true));
145 void CCopySettingsAndCachesComponent::initModel()
147 ui->cb_SettingsModel->setText(checkBoxText(TModel::humanReadable(),
true));
148 ui->cb_SettingsConsolidation->setText(checkBoxText(TBackgroundConsolidation::humanReadable(),
true));
151 int CCopySettingsAndCachesComponent::copy()
153 ui->le_Status->clear();
155 const CApplicationInfo otherVersionInfo = ui->comp_OtherSwiftVersions->selectedOtherVersion();
156 if (otherVersionInfo.
isNull()) {
return 0; }
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 =
167 CCacheSettingsUtils::otherVersionSettingsFileContent(otherVersionInfo, m_settingsAudio.
getFilename());
168 if (!joStr.isEmpty())
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())
182 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
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())
195 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
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())
209 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
210 otherVersionInfo, m_settingsDirectories.
getFilename());
211 if (!joStr.isEmpty())
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())
226 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
227 otherVersionInfo, m_settingsNetworkServers.
getFilename());
228 if (!joStr.isEmpty())
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())
242 const QString joStr = CCacheSettingsUtils::otherVersionCacheFileContent(
243 otherVersionInfo, m_cacheLastNetworkServer.
getFilename());
244 if (!joStr.isEmpty())
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())
257 const QString joStr = CCacheSettingsUtils::otherVersionCacheFileContent(
258 otherVersionInfo, m_cacheLastVatsimServer.
getFilename());
259 if (!joStr.isEmpty())
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())
273 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
274 otherVersionInfo, m_settingsGuiGeneral.getFilename());
275 if (!joStr.isEmpty())
278 CGeneralGuiSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
279 this->displayStatusMessage(m_settingsGuiGeneral.setAndSave(guiGeneral), guiGeneral.
toQString(
true));
284 if (ui->cb_SettingsDockWidget->isChecked())
286 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
287 otherVersionInfo, m_settingsDockWidget.getFilename());
288 if (!joStr.isEmpty())
291 CDockWidgetSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
292 this->displayStatusMessage(m_settingsDockWidget.setAndSave(dwSettings), dwSettings.
toQString(
true));
297 if (ui->cb_SettingsViewUpdate->isChecked())
299 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
300 otherVersionInfo, m_settingsViewUpdate.getFilename());
301 if (!joStr.isEmpty())
304 CViewUpdateSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
305 this->displayStatusMessage(m_settingsViewUpdate.setAndSave(viewUpdate), viewUpdate.
toQString(
true));
311 if (ui->cb_SettingsEnabledSimulators->isChecked())
313 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
314 otherVersionInfo, m_settingsEnabledSimulators.
getFilename());
315 if (!joStr.isEmpty())
317 const QStringList enabledSims = json::firstJsonValueAsStringList(joStr);
318 if (!enabledSims.isEmpty())
320 this->displayStatusMessage(m_settingsEnabledSimulators.
setAndSave(enabledSims),
321 enabledSims.join(
", "));
327 if (ui->cb_SettingsSimulatorFSX->isChecked())
329 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
330 otherVersionInfo, m_settingsSimulatorFsx.
getFilename());
331 if (!joStr.isEmpty())
333 const CSimulatorSettings settings = CSimulatorSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
334 if (this->parsingMessage(success, errMsg, m_settingsSimulatorFsx.
getKey()))
336 this->displayStatusMessage(m_settingsSimulatorFsx.
setAndSave(settings), settings.
toQString(
true));
342 if (ui->cb_SettingsSimulatorP3D->isChecked())
344 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
345 otherVersionInfo, m_settingsSimulatorP3D.
getFilename());
346 if (!joStr.isEmpty())
348 const CSimulatorSettings settings = CSimulatorSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
349 if (this->parsingMessage(success, errMsg, m_settingsSimulatorP3D.
getKey()))
351 this->displayStatusMessage(m_settingsSimulatorP3D.
setAndSave(settings), settings.
toQString(
true));
357 if (ui->cb_SettingsSimulatorXPlane->isChecked())
359 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
360 otherVersionInfo, m_settingsSimulatorXPlane.
getFilename());
361 if (!joStr.isEmpty())
363 const CSimulatorSettings settings = CSimulatorSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
364 if (this->parsingMessage(success, errMsg, m_settingsSimulatorXPlane.
getKey()))
366 this->displayStatusMessage(m_settingsSimulatorXPlane.
setAndSave(settings),
374 if (ui->cb_SettingsModel->isChecked())
376 const QString joStr =
377 CCacheSettingsUtils::otherVersionSettingsFileContent(otherVersionInfo, m_settingsModel.
getFilename());
378 if (!joStr.isEmpty())
380 const CModelSettings settings = CModelSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
381 if (this->parsingMessage(success, errMsg, m_settingsModel.
getKey()))
383 this->displayStatusMessage(m_settingsModel.
setAndSave(settings), settings.
toQString(
true));
389 if (ui->cb_SettingsConsolidation->isChecked())
391 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
392 otherVersionInfo, m_settingsConsolidation.getFilename());
393 if (!joStr.isEmpty())
396 const int consolidation = json::firstJsonValueAsInt(joStr, -1, &ok);
399 this->displayStatusMessage(m_settingsConsolidation.setAndSave(consolidation),
400 QString::number(consolidation));
407 if (ui->cb_SettingsActionHotkeys->isChecked())
409 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
410 otherVersionInfo, m_settingsActionHotkeys.
getFilename());
411 if (!joStr.isEmpty())
413 CActionHotkeyList hotkeys = CActionHotkeyList::fromJsonNoThrow(joStr,
true, success, errMsg);
415 if (this->parsingMessage(success, errMsg, m_settingsActionHotkeys.
getKey()))
417 this->displayStatusMessage(m_settingsActionHotkeys.
setAndSave(hotkeys), hotkeys.
toQString(
true));
423 if (ui->cb_SettingsTextMessages->isChecked())
425 const QString joStr = CCacheSettingsUtils::otherVersionSettingsFileContent(
426 otherVersionInfo, m_settingsTextMessage.getFilename());
427 if (!joStr.isEmpty())
430 CTextMessageSettings::fromJsonNoThrow(joStr,
true, success, errMsg);
431 if (this->parsingMessage(success, errMsg, m_settingsTextMessage.getKey()))
433 this->displayStatusMessage(m_settingsTextMessage.setAndSave(settings), settings.
toQString(
true));
448 void CCopySettingsAndCachesComponent::selectAll()
450 for (QCheckBox *cb : this->checkBoxes()) { cb->setChecked(cb->isEnabled()); }
453 void CCopySettingsAndCachesComponent::deselectAll()
455 for (QCheckBox *cb : this->checkBoxes()) { cb->setChecked(
false); }
458 QList<QCheckBox *> CCopySettingsAndCachesComponent::checkBoxes()
const {
return this->findChildren<QCheckBox *>(); }
460 bool CCopySettingsAndCachesComponent::parsingMessage(
bool success,
const QString &msg,
const QString &value)
462 if (success) {
return true; }
464 this->displayStatusMessage(sm, value);
468 void CCopySettingsAndCachesComponent::displayStatusMessage(
const CStatusMessage &msg,
const QString &value)
471 if (value.isEmpty()) { ui->le_Status->setText(msg.
getMessage()); }
472 else { ui->le_Status->setText(msg.
getMessage() % u
' ' % value); }
476 void CCopySettingsAndCachesComponent::allCheckBoxesReadOnly()
478 for (QCheckBox *cb : checkBoxes()) { readOnlyCheckbox(cb,
true); }
481 void CCopySettingsAndCachesComponent::readOnlyCheckbox(QCheckBox *cb,
bool readOnly)
483 Q_ASSERT_X(cb, Q_FUNC_INFO,
"need checkbox");
485 if (readOnly) { cb->setChecked(
false); }
486 cb->setEnabled(!readOnly);
490 QString CCopySettingsAndCachesComponent::checkBoxText(
const QString &text,
bool setting)
492 return setting ? QStringLiteral(
"%1 [setting]").arg(text) : QStringLiteral(
"%1 [cache]").arg(text);
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))
HTML message.
Using this class provides a QFrame with the overlay functionality already integrated.
Copy settings and caches.
void reloadOtherVersions(int deferMs=-1)
Reload other versions.
virtual ~CCopySettingsAndCachesComponent()
Dtor.
virtual void initializePage()
virtual bool validatePage()
void versionChanged(const swift::misc::CApplicationInfo &info)
Selection changed.
Settings about view update rates.
Description of a swift application.
bool isNull() const
Null object.
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
const QString & getKey() const
Get the key string of this value.
CStatusMessage set(const typename Trait::type &value, qint64 timestamp=0)
Write a new value. Must be called from the thread in which the owner lives.
QString getFilename() const
Return the file that is used for persistence for this value.
Directories (swift data directories)
bool isEmpty() const
Message empty.
Derived & validationInfo(const char16_t(&format)[N])
Set the severity to info, providing a format string, and adding the validation category.
QString getFilename() const
Return the file that is used for persistence for this value.
Streamable status message, e.g.
QString getMessage() const
Message.
Value object encapsulating information of audio related settings.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating information of a server.
Value object encapsulating a list of servers.
Settings for simulator Driver independent parts (such as directories), also used in model loaders.
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.