refs #891, FSX using common base class

This commit is contained in:
Klaus Basan
2017-02-28 04:33:34 +01:00
committed by Mathew Sutcliffe
parent 70045c046d
commit 5d8ed66931
16 changed files with 24 additions and 3213 deletions

View File

@@ -12,9 +12,8 @@ INCLUDEPATH += . $$SourceRoot/src
SOURCES += *.cpp
HEADERS += *.h
FORMS += *.ui
DISTFILES += simulatorfsxconfig.json
LIBS += -lsimulatorfsxcommon
DESTDIR = $$DestRoot/bin/plugins/simulator
win32 {

View File

@@ -1,175 +0,0 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simconnectsettingscomponent.h"
#include "ui_simconnectsettingscomponent.h"
#include "blackgui/guiapplication.h"
#include "blackcore/context/contextapplication.h"
#include "blackcore/context/contextsimulator.h"
#include "blackmisc/network/networkutils.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
#include <QFileInfo>
#include <QDesktopServices>
#include <QMessageBox>
#include <QStringBuilder>
#include <QDir>
using namespace BlackMisc;
using namespace BlackMisc::Simulation::Fsx;
using namespace BlackMisc::Network;
namespace BlackSimPlugin
{
namespace Fsx
{
CSimConnectSettingsComponent::CSimConnectSettingsComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CSimConnectSettingsComponent)
{
ui->setupUi(this);
connect(ui->pb_SettingsFsxOpenSimconnectCfg, &QPushButton::clicked, this, &CSimConnectSettingsComponent::openSimConnectCfgFile);
connect(ui->pb_SettingsFsxDeleteSimconnectCfg, &QPushButton::clicked, this, &CSimConnectSettingsComponent::deleteSimConnectCfgFile);
connect(ui->pb_SettingsFsxExistsSimconncetCfg, &QPushButton::clicked, this, &CSimConnectSettingsComponent::checkSimConnectCfgFile);
connect(ui->pb_SettingsFsxSaveSimconnectCfg, &QPushButton::clicked, this, &CSimConnectSettingsComponent::saveSimConnectCfgFile);
connect(ui->pb_SettingsFsxTestConnection, &QPushButton::clicked, this, &CSimConnectSettingsComponent::testSimConnectConnection);
}
CSimConnectSettingsComponent::~CSimConnectSettingsComponent()
{
// void
}
void CSimConnectSettingsComponent::openSimConnectCfgFile()
{
const QFileInfo info(CSimConnectUtilities::getLocalSimConnectCfgFilename());
const QString path = QDir::toNativeSeparators(info.absolutePath());
QDesktopServices::openUrl(QUrl(QStringLiteral("file:///") % path));
}
void CSimConnectSettingsComponent::deleteSimConnectCfgFile()
{
const QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
const bool result = sGui->getIContextApplication()->removeFile(fileName);
if (result)
{
QMessageBox::information(qApp->activeWindow(), tr("File deleted"),
tr("File %1 deleted successfully.").arg(fileName));
}
checkSimConnectCfgFile();
}
void CSimConnectSettingsComponent::checkSimConnectCfgFile()
{
const QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
if (sGui->getIContextApplication()->existsFile(fileName))
{
ui->le_SettingsFsxExistsSimconncetCfg->setText(fileName);
}
else
{
ui->le_SettingsFsxExistsSimconncetCfg->setText("no file");
}
}
void CSimConnectSettingsComponent::testSimConnectConnection()
{
const QString address = ui->le_SettingsFsxAddress->text().trimmed();
const QString port = ui->le_SettingsFsxPort->text().trimmed();
if (address.isEmpty() || port.isEmpty())
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"),
tr("Address and/or port not specified!"));
return;
}
if (!CNetworkUtils::isValidIPv4Address(address))
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"),
tr("Wrong IPv4 address!"));
return;
}
if (!CNetworkUtils::isValidPort(port))
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"),
tr("Invalid port!"));
return;
}
int p = port.toInt();
QString msg;
if (!CNetworkUtils::canConnect(address, p, msg))
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"), msg);
return;
}
QMessageBox::information(qApp->activeWindow(), tr("Connection successful"),
tr("Connected to %1:%2.").arg(address, port));
}
void CSimConnectSettingsComponent::saveSimConnectCfgFile()
{
QString address = ui->le_SettingsFsxAddress->text().trimmed();
QString port = ui->le_SettingsFsxPort->text().trimmed();
if (address.isEmpty() || port.isEmpty())
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"),
tr("Address and/or port not specified!"));
return;
}
if (!CNetworkUtils::isValidIPv4Address(address))
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"),
tr("Wrong IPv4 address!"));
return;
}
if (!CNetworkUtils::isValidPort(port))
{
QMessageBox::warning(qApp->activeWindow(), tr("Connection invalid"),
tr("Invalid port!"));
return;
}
int p = port.toInt();
QString fileName;
if (sGui->getIContextSimulator())
{
const BlackMisc::Simulation::CSimulatorInternals internals(sGui->getIContextSimulator()->getSimulatorInternals());
fileName = internals.getStringValue("fsx/simConnectCfgFilename");
}
if (fileName.isEmpty())
{
fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
}
if (fileName.isEmpty())
{
QMessageBox::warning(qApp->activeWindow(), tr("Failed writing simConnect.cfg"),
tr("No file name specified!"));
return;
}
if (sGui->getIContextApplication()->writeToFile(fileName, CSimConnectUtilities::simConnectCfg(address, p)))
{
QMessageBox::information(qApp->activeWindow(), tr("File saved"),
tr("File %1 saved.").arg(fileName));
checkSimConnectCfgFile();
}
else
{
QMessageBox::warning(qApp->activeWindow(), tr("Failed writing simConnect.cfg"),
tr("Failed writing %1!").arg(fileName));
}
}
} // ns
} // ns

View File

@@ -1,60 +0,0 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMPLUGIN_SIMCONNECT_SETTINGS_COMPONENT_H
#define BLACKSIMPLUGIN_SIMCONNECT_SETTINGS_COMPONENT_H
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CSimConnectSettingsComponent; }
namespace BlackSimPlugin
{
namespace Fsx
{
/*!
* A component that gathers all SimConnect-related settings.
*/
class CSimConnectSettingsComponent : public QFrame
{
Q_OBJECT
public:
//! Ctor
explicit CSimConnectSettingsComponent(QWidget *parent = nullptr);
//! Dtor
~CSimConnectSettingsComponent();
private slots:
//! Open simConnect.cfg using default application
void openSimConnectCfgFile();
//! Delete simConnect.cfg file
void deleteSimConnectCfgFile();
//! Check whether the simConnect.cfg file exists
void checkSimConnectCfgFile();
//! Test the SimConnect connectivity
void testSimConnectConnection();
//! Save a simconnect.cfg file for FSX
void saveSimConnectCfgFile();
private:
QScopedPointer<Ui::CSimConnectSettingsComponent> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -1,246 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSimConnectSettingsComponent</class>
<widget class="QWidget" name="CSimConnectSettingsComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>158</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="gb_FsxSimConnectConfigFile">
<property name="title">
<string>FSX SimConnect config file</string>
</property>
<layout class="QFormLayout" name="fl_Settings">
<property name="leftMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>4</number>
</property>
<property name="bottomMargin">
<number>4</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lbl_SettingsFsxAddress">
<property name="text">
<string>FSX address</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_SettingsFsxAddress">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>127.0.0.1</string>
</property>
<property name="maxLength">
<number>128</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_SettingsFsxPort">
<property name="text">
<string>FSX port</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="le_SettingsFsxPort">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>500</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_SettingsFsxExistsSimconncetCfg">
<property name="toolTip">
<string>is 'SimConnect.cfg' available?</string>
</property>
<property name="text">
<string>.cfg?</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QWidget" name="wi_SettingsFsxExistsSimconncetCfg" native="true">
<layout class="QHBoxLayout" name="hl_SettingsFsxExistsSimconncetCfg">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="le_SettingsFsxExistsSimconncetCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxExistsSimconncetCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>check</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0" colspan="2">
<layout class="QHBoxLayout" name="hl_SettingsSimconnectCfgButtons">
<property name="spacing">
<number>3</number>
</property>
<item>
<widget class="QPushButton" name="pb_SettingsFsxOpenSimconnectCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>open</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxDeleteSimconnectCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>del.</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxSaveSimconnectCfg">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_SettingsFsxTestConnection">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Test connection</string>
</property>
<property name="text">
<string extracomment="Test connection">test</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -1,5 +1,14 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "simulatorfsxconfig.h"
#include "simulatorfsxconfigwindow.h"
#include "../fsxcommon/simulatorfsxconfigwindow.h"
namespace BlackSimPlugin
{
@@ -12,7 +21,7 @@ namespace BlackSimPlugin
BlackGui::CPluginConfigWindow *CSimulatorFsxConfig::createConfigWindow(QWidget *parent)
{
return new CSimulatorFsxConfigWindow(parent);
return new FsxCommon::CSimulatorFsxConfigWindow("P3D", parent);
}
}
}

View File

@@ -1,24 +0,0 @@
#include "simulatorfsxconfigwindow.h"
#include "ui_simulatorfsxconfigwindow.h"
using namespace BlackGui;
namespace BlackSimPlugin
{
namespace Fsx
{
CSimulatorFsxConfigWindow::CSimulatorFsxConfigWindow(QWidget *parent) :
CPluginConfigWindow(parent),
ui(new Ui::CSimulatorFsxConfigWindow)
{
ui->setupUi(this);
connect(ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &QWidget::close);
}
CSimulatorFsxConfigWindow::~CSimulatorFsxConfigWindow()
{
// void
}
}
}

View File

@@ -1,45 +0,0 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKSIMPLUGIN_SIMULATOR_FSX_CONFIG_WINDOW_H
#define BLACKSIMPLUGIN_SIMULATOR_FSX_CONFIG_WINDOW_H
#include "simulatorfsxconfig.h"
#include "blackgui/pluginconfigwindow.h"
#include <QScopedPointer>
namespace Ui { class CSimulatorFsxConfigWindow; }
namespace BlackSimPlugin
{
namespace Fsx
{
/**
* A window the lets user set up the FSX plugin.
*/
class CSimulatorFsxConfigWindow : public BlackGui::CPluginConfigWindow
{
Q_OBJECT
public:
//! Ctor.
CSimulatorFsxConfigWindow(QWidget *parent);
//! Dtor.
virtual ~CSimulatorFsxConfigWindow();
private:
QScopedPointer<Ui::CSimulatorFsxConfigWindow> ui;
};
}
}
#endif // guard

View File

@@ -1,46 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSimulatorFsxConfigWindow</class>
<widget class="QWidget" name="CSimulatorFsxConfigWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>FSX plugin settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="BlackSimPlugin::Fsx::CSimConnectSettingsComponent" name="fr_simConnectSettings">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="bb_OkCancel">
<property name="standardButtons">
<set>QDialogButtonBox::Close</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackSimPlugin::Fsx::CSimConnectSettingsComponent</class>
<extends>QFrame</extends>
<header>simconnectsettingscomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>