refs #392 Add config window for FSX

* Added plugin_fsx_config subproject
* Removed CSettingsFsxComponent from BlackGui
* Added CSimConnectSettingsComponent
* Add x-plane_install_10.txt path for Windows
This commit is contained in:
Michal Garapich
2015-10-06 19:35:23 +02:00
committed by Mathew Sutcliffe
parent cf3102333b
commit 3781cf2095
21 changed files with 460 additions and 313 deletions

View File

@@ -20,6 +20,7 @@ LIBS += -ldxguid -lole32
SOURCES += *.cpp
HEADERS += *.h
DISTFILES += simulator_fsx.json
DESTDIR = $$DestRoot/bin/plugins/simulator

View File

@@ -2,5 +2,6 @@
"identifier" : "org.swift-project.plugins.simulator.fsx",
"name" : "Flight Simulator X",
"simulator" : "fsx",
"description" : "Microsoft Flight Simulator X (2006)"
"description" : "Microsoft Flight Simulator X (2006)",
"config" : "org.swift-project.plugins.simulator.fsx.config"
}

View File

@@ -0,0 +1,20 @@
load(common_pre)
QT += core widgets dbus
TARGET = simulator_fsx_config
TEMPLATE = lib
CONFIG += plugin shared
CONFIG += blackmisc blackcore blackgui
DEPENDPATH += . $$SourceRoot/src
INCLUDEPATH += . $$SourceRoot/src
SOURCES += *.cpp
HEADERS += *.h
FORMS += *.ui
DISTFILES += simulator_fsx_config.json
DESTDIR = $$BuildRoot/bin/plugins/simulator
load(common_post)

View File

@@ -0,0 +1,166 @@
#include "simconnectsettingscomponent.h"
#include "ui_simconnectsettingscomponent.h"
#include "blackcore/context_application.h"
#include "blackcore/context_simulator.h"
#include "blackmisc/network/networkutils.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/simulation/fsx/fsxsimulatorsetup.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
#include <QFileInfo>
#include <QDesktopServices>
#include <QMessageBox>
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 CSimConnectSettingsComponent::openSimConnectCfgFile()
{
QFileInfo info(CSimConnectUtilities::getLocalSimConnectCfgFilename());
QString path = QDir::toNativeSeparators(info.absolutePath());
QDesktopServices::openUrl(QUrl(QStringLiteral("file:///") % path));
}
void CSimConnectSettingsComponent::deleteSimConnectCfgFile()
{
QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
bool result = getIContextApplication()->removeFile(fileName);
if (result)
{
QMessageBox::information(qApp->activeWindow(), tr("File deleted"),
tr("File %1 deleted successfully.").arg(fileName));
}
checkSimConnectCfgFile();
}
void CSimConnectSettingsComponent::checkSimConnectCfgFile()
{
QString fileName = CSimConnectUtilities::getLocalSimConnectCfgFilename();
if (getIContextApplication()->existsFile(fileName))
{
ui->le_SettingsFsxExistsSimconncetCfg->setText(fileName);
}
else
{
ui->le_SettingsFsxExistsSimconncetCfg->setText("no file");
}
}
void CSimConnectSettingsComponent::testSimConnectConnection()
{
QString address = this->ui->le_SettingsFsxAddress->text().trimmed();
QString port = this->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 (getIContextSimulator())
{
fileName = getIContextSimulator()->getSimulatorSetup().getStringValue(CFsxSimulatorSetup::KeyLocalSimConnectCfgFilename());
}
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 (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));
}
}
}
}

View File

@@ -0,0 +1,65 @@
/* 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>
#include "blackgui/components/enableforruntime.h"
namespace Ui {
class CSimConnectSettingsComponent;
}
namespace BlackSimPlugin
{
namespace Fsx
{
/**
* A component that gathers all SimConnect-related settings.
*/
class CSimConnectSettingsComponent : public QFrame, public BlackGui::Components::CEnableForRuntime
{
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;
};
}
}
#endif // guard

View File

@@ -0,0 +1,246 @@
<?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

@@ -0,0 +1,3 @@
{
"identifier" : "org.swift-project.plugins.simulator.fsx.config"
}

View File

@@ -0,0 +1,19 @@
#include "simulatorfsxconfig.h"
#include "simulatorfsxconfigwindow.h"
namespace BlackSimPlugin
{
namespace Fsx
{
CSimulatorFsxConfig::CSimulatorFsxConfig(QObject *parent) : QObject(parent)
{
}
BlackGui::CPluginConfigWindow *CSimulatorFsxConfig::createConfigWindow(QWidget *parent)
{
return new CSimulatorFsxConfigWindow(parent);
}
}
}

View File

@@ -0,0 +1,43 @@
/* 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_H
#define BLACKSIMPLUGIN_SIMULATOR_FSX_CONFIG_H
#include "blackgui/pluginconfig.h"
#include "blackcore/settingscache.h"
namespace BlackSimPlugin
{
namespace Fsx
{
class CSimulatorFsxConfig : public QObject, public BlackGui::IPluginConfig
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.swift-project.blackgui.pluginconfiginterface" FILE "simulator_fsx_config.json")
Q_INTERFACES(BlackGui::IPluginConfig)
public:
//! Ctor
CSimulatorFsxConfig(QObject *parent = nullptr);
//! Dtor
virtual ~CSimulatorFsxConfig() {}
//! \copydoc BlackGui::IPluginConfig::createConfigWindow()
BlackGui::CPluginConfigWindow *createConfigWindow(QWidget *parent) override;
};
}
}
#endif // guard

View File

@@ -0,0 +1,27 @@
#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()
{
}
}
}

View File

@@ -0,0 +1,48 @@
/* 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

@@ -0,0 +1,46 @@
<?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="frame">
<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>

View File

@@ -1,12 +1,11 @@
include ($$SourceRoot/config.pri)
include ($$SourceRoot/build.pri)
load(common_pre)
QT += core widgets dbus
TARGET = simulator_xplane_config
TEMPLATE = lib
CONFIG += plugin shared
CONFIG += blackmisc blackcore
CONFIG += blackmisc blackcore blackgui
DEPENDPATH += . $$SourceRoot/src
INCLUDEPATH += . $$SourceRoot/src
@@ -17,4 +16,5 @@ FORMS += *.ui
DISTFILES += simulator_xplane_config.json
DESTDIR = $$BuildRoot/bin/plugins/simulator
include ($$SourceRoot/libraries.pri)
load(common_post)

View File

@@ -5,6 +5,8 @@
#include <QStringBuilder>
#include <QFileDialog>
#include <QMessageBox>
#include <QStandardPaths>
#include <QStringBuilder>
using namespace BlackGui;

View File

@@ -14,7 +14,6 @@
#include "simulatorxplaneconfig.h"
#include "blackgui/pluginconfigwindow.h"
#include <QWidget>
#include <QScopedPointer>
namespace Ui {