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  else
63  {
64  const CWinDllUtils::DLLInfo SimConnectInfo = CSimConnectUtilities::simConnectDllInfo();
65  ui->pte_SimConnectInfo->setPlainText(SimConnectInfo.summary());
66  m_simulator = CSimulatorInfo(CSimulatorInfo::FSX);
67  m_p3d64bit = false;
68  }
69 
70  ui->lbl_P3DVersion->setVisible(m_p3d64bit);
71  ui->cb_P3DVersion->setVisible(m_p3d64bit);
72  }
73 
74  void CSimConnectSettingsComponent::setComboBox(const QString &value)
75  {
76  QString v;
77  bool found = false;
78  for (int index = 0; index < ui->cb_P3DVersion->count(); index++)
79  {
80  v = ui->cb_P3DVersion->itemText(index);
81  if (v.contains(value, Qt::CaseInsensitive))
82  {
83  found = true;
84  break;
85  }
86  }
87  ui->cb_P3DVersion->setCurrentText(found ? v : "");
88  }
89 
90  void CSimConnectSettingsComponent::onP3DVersionChanged(const QString &version)
91  {
92  if (m_p3dVersion.get() == version) { return; }
93  const CStatusMessage saveMsg = m_p3dVersion.setAndSave(version);
94  if (saveMsg.isSuccess())
95  {
96  const CStatusMessage m =
97  CStatusMessage(this).info(
98  u"Changed P3D version to '%1'. Requires a new start of swift to become effective!")
99  << version;
100  this->showOverlayMessage(m);
101  }
102  }
103 } // 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.
QString summary() const
Summary.
Definition: windllutils.h:45