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

@@ -1,190 +0,0 @@
/* Copyright (C) 2013
* 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 "settingsfsxcomponent.h"
#include "ui_settingsfsxcomponent.h"
#include "blackcore/context_simulator.h"
#include "blackcore/context_application.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
#include "blackmisc/network/networkutils.h"
#include "blackmisc/statusmessage.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/simulation/fsx/fsxsimulatorsetup.h"
#include "blackmisc/simulation/fsx/simconnectutilities.h"
#include <QDesktopServices>
#include <QFile>
#include <QDir>
#include <QUrl>
#include <QFileInfo>
using namespace BlackMisc;
using namespace BlackMisc::Simulation::Fsx;
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Components
{
CSettingsFsxComponent::CSettingsFsxComponent(QWidget *parent) :
QFrame(parent), CEnableForRuntime(nullptr, false), ui(new Ui::CSettingsFsxComponent)
{
ui->setupUi(this);
this->connect(this->ui->pb_SettingsFsxTestConnection, &QPushButton::clicked, this, &CSettingsFsxComponent::testSimConnectConnection);
this->connect(this->ui->pb_SettingsFsxSaveSimconnectCfg, &QPushButton::clicked, this, &CSettingsFsxComponent::saveSimConnectCfg);
this->connect(this->ui->pb_SettingsFsxOpenSimconnectCfg, &QPushButton::clicked, this, &CSettingsFsxComponent::simConnectCfgFile);
this->connect(this->ui->pb_SettingsFsxDeleteSimconnectCfg, &QPushButton::clicked, this, &CSettingsFsxComponent::simConnectCfgFile);
this->connect(this->ui->pb_SettingsFsxExistsSimconncetCfg, &QPushButton::clicked, this, &CSettingsFsxComponent::simConnectCfgFile);
}
CSettingsFsxComponent::~CSettingsFsxComponent()
{ }
/*
* SimConnect working?
*/
void CSettingsFsxComponent::testSimConnectConnection()
{
QString address = this->ui->le_SettingsFsxAddress->text().trimmed();
QString port = this->ui->le_SettingsFsxPort->text().trimmed();
if (address.isEmpty() || port.isEmpty())
{
CLogMessage(this).validationWarning("No address or port");
return;
}
if (!CNetworkUtils::isValidIPv4Address(address))
{
CLogMessage(this).validationWarning("IPv4 address invalid");
return;
}
if (!CNetworkUtils::isValidPort(port))
{
CLogMessage(this).validationWarning("Invalid port");
return;
}
int p = port.toInt();
QString msg;
if (!CNetworkUtils::canConnect(address, p, msg))
{
CLogMessage(this).validationWarning(msg);
return;
}
CLogMessage(this).validationInfo("Connected to %1:%2") << address << port;
}
/*
* Save simconnect.cfg
*/
void CSettingsFsxComponent::saveSimConnectCfg()
{
if (!this->getIContextSimulator())
{
CLogMessage(this).validationError("Simulator driver not available");
return;
}
QString address = this->ui->le_SettingsFsxAddress->text().trimmed();
QString port = this->ui->le_SettingsFsxPort->text().trimmed();
if (address.isEmpty() || port.isEmpty())
{
CLogMessage(this).validationError("No address or port");
return;
}
if (!CNetworkUtils::isValidIPv4Address(address))
{
CLogMessage(this).validationError("IPv4 address invalid");
return;
}
if (!CNetworkUtils::isValidPort(port))
{
CLogMessage(this).validationError("Invalid port");
return;
}
int p = port.toInt();
//! \todo filename is only available if driver has been loaded
QString fileName = this->getIContextSimulator()->getSimulatorSetup().getStringValue(CFsxSimulatorSetup::KeyLocalSimConnectCfgFilename());
if (fileName.isEmpty())
{
CLogMessage(this).validationError("Invalid or empty filename empty, driver loaded?");
return;
}
// write either local or remote file
bool localSimulatorObject = this->getIContextSimulator()->isUsingImplementingObject();
bool success = localSimulatorObject ?
BlackMisc::Simulation::Fsx::CSimConnectUtilities::writeSimConnectCfg(fileName, address, p) :
this->getIContextApplication()->writeToFile(fileName, CSimConnectUtilities::simConnectCfg(address, p));
if (success)
{
CLogMessage(this).validationInfo(localSimulatorObject ? "Written local %1" : "Written remote %1") << fileName;
}
else
{
CLogMessage(this).validationError("Cannot write %1") << fileName;
}
this->ui->pb_SettingsFsxExistsSimconncetCfg->click(); // update status
}
/*
* simconnect.cfg: open, delete, exists?
*/
void CSettingsFsxComponent::simConnectCfgFile()
{
if (!this->getIContextSimulator())
{
CLogMessage(this).validationError("Simulator driver not available");
return;
}
QObject *sender = QObject::sender();
if (sender == this->ui->pb_SettingsFsxOpenSimconnectCfg)
{
QFileInfo fi(CSimConnectUtilities::getLocalSimConnectCfgFilename());
QString path = QDir::toNativeSeparators(fi.absolutePath());
QDesktopServices::openUrl(QUrl("file:///" + path));
}
else if (sender == this->ui->pb_SettingsFsxDeleteSimconnectCfg)
{
if (!this->getIContextSimulator()) return;
QString fileName = BlackMisc::Simulation::Fsx::CSimConnectUtilities::getLocalSimConnectCfgFilename();
if (this->getIContextSimulator()->isUsingImplementingObject())
{
QFile f(fileName);
f.remove();
CLogMessage(this).info("Deleted locally %1") << fileName;
}
else
{
this->getIContextApplication()->removeFile(fileName);
CLogMessage(this).info("Deleted remotely %1") << fileName;
}
this->ui->pb_SettingsFsxExistsSimconncetCfg->click(); // update status
}
else if (sender == this->ui->pb_SettingsFsxExistsSimconncetCfg)
{
if (!this->getIContextSimulator()) return;
QString fileName = BlackMisc::Simulation::Fsx::CSimConnectUtilities::getLocalSimConnectCfgFilename();
bool exists = this->getIContextSimulator()->isUsingImplementingObject() ?
QFile::exists(fileName) :
this->getIContextApplication()->existsFile(fileName);
if (exists)
{
this->ui->le_SettingsFsxExistsSimconncetCfg->setText(fileName);
}
else
{
this->ui->le_SettingsFsxExistsSimconncetCfg->setText("no file");
}
}
}
} // ns
} // ns

View File

@@ -1,54 +0,0 @@
/* Copyright (C) 2013
* 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 BLACKGUI_SETTINGSFSXCOMPONENT_H
#define BLACKGUI_SETTINGSFSXCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackgui/components/enableforruntime.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CSettingsFsxComponent; }
namespace BlackGui
{
namespace Components
{
//! Settings for FSX
class BLACKGUI_EXPORT CSettingsFsxComponent : public QFrame, public CEnableForRuntime
{
Q_OBJECT
public:
//! Constructor
explicit CSettingsFsxComponent(QWidget *parent = nullptr);
//! Destructor
~CSettingsFsxComponent();
private slots:
//! Test the SIM connect connectivity
void testSimConnectConnection();
//! Save a simconnect.cfg file for FSX
void saveSimConnectCfg();
//! simConnect.cfg: open, exists? delete
void simConnectCfgFile();
private:
QScopedPointer<Ui::CSettingsFsxComponent> ui;
};
}
}
#endif // guard

View File

@@ -1,277 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CSettingsFsxComponent</class>
<widget class="QFrame" name="CSettingsFsxComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>317</width>
<height>141</height>
</rect>
</property>
<property name="windowTitle">
<string>FSX SimConnect Settings</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_SettingsFsxComponent">
<property name="spacing">
<number>0</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="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>
<tabstops>
<tabstop>le_SettingsFsxAddress</tabstop>
<tabstop>le_SettingsFsxPort</tabstop>
<tabstop>le_SettingsFsxExistsSimconncetCfg</tabstop>
<tabstop>pb_SettingsFsxExistsSimconncetCfg</tabstop>
<tabstop>pb_SettingsFsxOpenSimconnectCfg</tabstop>
<tabstop>pb_SettingsFsxDeleteSimconnectCfg</tabstop>
<tabstop>pb_SettingsFsxSaveSimconnectCfg</tabstop>
<tabstop>pb_SettingsFsxTestConnection</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -228,10 +228,6 @@ namespace BlackGui
void CSettingsSimulatorComponent::ps_simulatorPluginChanged(const CSimulatorPluginInfo &info)
{
// disable / enable driver specific GUI parts
bool hasFsxDriver = this->getIContextSimulator()->getAvailableSimulatorPlugins().supportsSimulator(QStringLiteral("fsx"));
this->ui->comp_SettingsSimulatorFsx->setVisible(hasFsxDriver);
// I intentionally to not set the selected plugin combobox here
// as this would cause undesired rountrips
@@ -281,6 +277,7 @@ namespace BlackGui
QString configId = m_plugins->getPluginConfigId(selected->getIdentifier());
IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId);
CPluginConfigWindow *window = config->createConfigWindow(qApp->activeWindow());
CEnableForRuntime::setRuntimeForComponents(getRuntime(), window);
window->setAttribute(Qt::WA_DeleteOnClose);
window->show();
}

View File

@@ -22,7 +22,7 @@
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="vl_SettingsSimulatorComponent" stretch="0,0,1">
<layout class="QVBoxLayout" name="vl_SettingsSimulatorComponent" stretch="0,1">
<property name="leftMargin">
<number>2</number>
</property>
@@ -366,16 +366,6 @@
</layout>
</widget>
</item>
<item>
<widget class="BlackGui::Components::CSettingsFsxComponent" name="comp_SettingsSimulatorFsx">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="vs_SettingsSimulator">
<property name="orientation">
@@ -395,12 +385,6 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CSettingsFsxComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/settingsfsxcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::CLedWidget</class>
<extends>QWidget</extends>

View File

@@ -52,11 +52,6 @@ namespace BlackGui
pw->layout()->addWidget(cb);
QPushButton *details = new QPushButton("?");
m_detailsButtonMapper->setMapping(details, identifier);
connect(details, &QPushButton::clicked, m_detailsButtonMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
pw->layout()->addWidget(details);
if (hasConfig) {
QPushButton *config = new QPushButton("...");
m_configButtonMapper->setMapping(config, identifier);
@@ -64,6 +59,11 @@ namespace BlackGui
pw->layout()->addWidget(config);
}
QPushButton *details = new QPushButton("?");
m_detailsButtonMapper->setMapping(details, identifier);
connect(details, &QPushButton::clicked, m_detailsButtonMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
pw->layout()->addWidget(details);
layout->setStretch(0, 1);
layout->setStretch(1, 0);
layout->setStretch(2, 0);