swift
simconnectsettingscomponent.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QDesktopServices>
7 #include <QDir>
8 #include <QFileDialog>
9 #include <QFileInfo>
10 #include <QMessageBox>
11 #include <QStringBuilder>
12 
13 #include "ui_simconnectsettingscomponent.h"
14 
15 #include "config/buildconfig.h"
18 #include "gui/guiapplication.h"
19 #include "misc/logmessage.h"
22 
23 using namespace swift::config;
24 using namespace swift::misc;
25 using namespace swift::misc::simulation;
26 using namespace swift::misc::simulation::fsx;
27 using namespace swift::misc::network;
28 using namespace swift::gui;
29 
30 namespace swift::simplugin::fsxcommon
31 {
32  CSimConnectSettingsComponent::CSimConnectSettingsComponent(QWidget *parent)
34  {
35  ui->setupUi(this);
36 
37  this->setSimConnectInfo();
38 
39  if (m_p3d64bit)
40  {
41  connect(ui->cb_P3DVersion, &QComboBox::currentTextChanged, this,
42  &CSimConnectSettingsComponent::onP3DVersionChanged);
43  }
44  }
45 
47  {
48  // void
49  }
50 
51  void CSimConnectSettingsComponent::setSimConnectInfo()
52  {
53  if (CBuildConfig::isCompiledWithP3DSupport() && CBuildConfig::buildWordSize() == 64)
54  {
55  ui->pte_SimConnectInfo->setPlainText("Static linking P3Dv4 x64");
56  m_simulator = CSimulatorInfo(CSimulatorInfo::P3D);
57  m_p3d64bit = true;
58 
59  const QString v = m_p3dVersion.get();
60  this->setComboBox(v);
61  }
62 
63  ui->lbl_P3DVersion->setVisible(m_p3d64bit);
64  ui->cb_P3DVersion->setVisible(m_p3d64bit);
65  }
66 
67  void CSimConnectSettingsComponent::setComboBox(const QString &value)
68  {
69  QString v;
70  bool found = false;
71  for (int index = 0; index < ui->cb_P3DVersion->count(); index++)
72  {
73  v = ui->cb_P3DVersion->itemText(index);
74  if (v.contains(value, Qt::CaseInsensitive))
75  {
76  found = true;
77  break;
78  }
79  }
80  ui->cb_P3DVersion->setCurrentText(found ? v : "");
81  }
82 
83  void CSimConnectSettingsComponent::onP3DVersionChanged(const QString &version)
84  {
85  if (m_p3dVersion.get() == version) { return; }
86  const CStatusMessage saveMsg = m_p3dVersion.setAndSave(version);
87  if (saveMsg.isSuccess())
88  {
89  const CStatusMessage m =
90  CStatusMessage(this).info(
91  u"Changed P3D version to '%1'. Requires a new start of swift to become effective!")
92  << version;
93  this->showOverlayMessage(m);
94  }
95  }
96 } // namespace swift::simplugin::fsxcommon
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show single message.
Using this class provides a QFrame with the overlay functionality already integrated.
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.
Definition: valuecache.h:417
T get() const
Get a copy of the current value.
Definition: valuecache.h:408
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Streamable status message, e.g.
bool isSuccess() const
Operation considered successful.
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
A component that gathers all SimConnect related settings.
GUI related classes.
Free functions in swift::misc.
void currentTextChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
CaseInsensitive