refs #392 Added the "Install XBus" feature

* New "Install XBus" button in the CSimulatorXPlaneConfigWindow
* CSettingsSimulatorComponent cleanup
This commit is contained in:
Michał Garapich
2015-09-13 19:15:32 +02:00
committed by Mathew Sutcliffe
parent 06c17d7d09
commit cf3102333b
10 changed files with 92 additions and 17 deletions

View File

@@ -280,9 +280,7 @@ namespace BlackGui
QString configId = m_plugins->getPluginConfigId(selected->getIdentifier()); QString configId = m_plugins->getPluginConfigId(selected->getIdentifier());
IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId); IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId);
CPluginConfigWindow *window = config->createConfigWindow(); CPluginConfigWindow *window = config->createConfigWindow(qApp->activeWindow());
window->setParent(qApp->activeWindow());
window->setWindowFlags(Qt::Dialog);
window->setAttribute(Qt::WA_DeleteOnClose); window->setAttribute(Qt::WA_DeleteOnClose);
window->show(); window->show();
} }

View File

@@ -32,10 +32,10 @@ namespace BlackGui
public: public:
//! Dtor. //! Dtor.
virtual ~IPluginConfig() = default; virtual ~IPluginConfig() {}
//! Creates a new config window and returns its pointer. //! Creates a new config window and returns its pointer.
virtual CPluginConfigWindow *createConfigWindow() = 0; virtual CPluginConfigWindow *createConfigWindow(QWidget *parent) = 0;
}; };
} }

View File

@@ -1,10 +1,27 @@
#include "pluginconfigwindow.h" #include "pluginconfigwindow.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QStyle>
namespace BlackGui { namespace BlackGui {
CPluginConfigWindow::CPluginConfigWindow() : QWidget(nullptr) CPluginConfigWindow::CPluginConfigWindow(QWidget *parent) : QWidget(parent, Qt::Window)
{ {
} }
void CPluginConfigWindow::showEvent(QShowEvent *event)
{
this->setGeometry(
QStyle::alignedRect(
Qt::LeftToRight,
Qt::AlignCenter,
this->size(),
QDesktopWidget().screenGeometry(qApp->activeWindow())
)
);
Q_UNUSED(event);
}
} }

View File

@@ -22,7 +22,10 @@ namespace BlackGui
Q_OBJECT Q_OBJECT
public: public:
//! No parent //! No parent
explicit CPluginConfigWindow(); explicit CPluginConfigWindow(QWidget *parent);
protected:
virtual void showEvent(QShowEvent *event) override;
}; };
} }

View File

@@ -527,6 +527,7 @@ namespace BlackSimPlugin
} }
else else
{ {
CLogMessage(this).debug() << "Starting XBus on %1" << m_xbusServerSetting.get();
m_conn = CSimulatorXPlane::connectionFromString(m_xbusServerSetting.get()); m_conn = CSimulatorXPlane::connectionFromString(m_xbusServerSetting.get());
m_watcher = new QDBusServiceWatcher(xbusServiceName(), m_conn, QDBusServiceWatcher::WatchForRegistration, this); m_watcher = new QDBusServiceWatcher(xbusServiceName(), m_conn, QDBusServiceWatcher::WatchForRegistration, this);
connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &CSimulatorXPlaneListener::ps_serviceRegistered); connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, &CSimulatorXPlaneListener::ps_serviceRegistered);
@@ -568,7 +569,6 @@ namespace BlackSimPlugin
{ {
// user changed settings, restart the listener // user changed settings, restart the listener
if (m_watcher) { if (m_watcher) {
CLogMessage(this).debug() << "XP: Restarting listener";
stop(); stop();
start(); start();
} }

View File

@@ -11,9 +11,9 @@ namespace BlackSimPlugin
} }
BlackGui::CPluginConfigWindow *CSimulatorXPlaneConfig::createConfigWindow() BlackGui::CPluginConfigWindow *CSimulatorXPlaneConfig::createConfigWindow(QWidget *parent)
{ {
CSimulatorXPlaneConfigWindow* w = new CSimulatorXPlaneConfigWindow(); CSimulatorXPlaneConfigWindow* w = new CSimulatorXPlaneConfigWindow(parent);
return w; return w;
} }
} }

View File

@@ -41,11 +41,14 @@ namespace BlackSimPlugin
//! Ctor //! Ctor
CSimulatorXPlaneConfig(QObject *parent = nullptr); CSimulatorXPlaneConfig(QObject *parent = nullptr);
//! Dtor
virtual ~CSimulatorXPlaneConfig() {}
//! \copydoc BlackGui::IPluginConfig::createConfigWindow() //! \copydoc BlackGui::IPluginConfig::createConfigWindow()
BlackGui::CPluginConfigWindow *createConfigWindow() override; BlackGui::CPluginConfigWindow *createConfigWindow(QWidget *parent) override;
}; };
} }
} }
#endif // SIMULATORXPLANECONFIG_H #endif // guard

View File

@@ -1,6 +1,10 @@
#include "simulatorxplaneconfigwindow.h" #include "simulatorxplaneconfigwindow.h"
#include "ui_simulatorxplaneconfigwindow.h" #include "ui_simulatorxplaneconfigwindow.h"
#include "blackcore/dbus_server.h" #include "blackcore/dbus_server.h"
#include "blackmisc/simulation/xplane/xplaneutil.h"
#include <QStringBuilder>
#include <QFileDialog>
#include <QMessageBox>
using namespace BlackGui; using namespace BlackGui;
@@ -9,7 +13,8 @@ namespace BlackSimPlugin
namespace XPlane namespace XPlane
{ {
CSimulatorXPlaneConfigWindow::CSimulatorXPlaneConfigWindow() : CSimulatorXPlaneConfigWindow::CSimulatorXPlaneConfigWindow(QWidget *parent) :
CPluginConfigWindow(parent),
ui(new Ui::CSimulatorXPlaneConfigWindow) ui(new Ui::CSimulatorXPlaneConfigWindow)
{ {
ui->setupUi(this); ui->setupUi(this);
@@ -22,6 +27,8 @@ namespace BlackSimPlugin
connect(ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &CSimulatorXPlaneConfigWindow::close); connect(ui->bb_OkCancel, &QDialogButtonBox::rejected, this, &CSimulatorXPlaneConfigWindow::close);
ui->cp_XBusServer->setCurrentText(m_xbusServerSetting.get()); ui->cp_XBusServer->setCurrentText(m_xbusServerSetting.get());
connect(ui->pb_InstallXBus, &QPushButton::clicked, this, &CSimulatorXPlaneConfigWindow::ps_installXBus);
} }
CSimulatorXPlaneConfigWindow::~CSimulatorXPlaneConfigWindow() CSimulatorXPlaneConfigWindow::~CSimulatorXPlaneConfigWindow()
@@ -37,5 +44,32 @@ namespace BlackSimPlugin
} }
} }
void CSimulatorXPlaneConfigWindow::ps_installXBus()
{
QString xPlaneLocation = BlackMisc::Simulation::XPlane::CXPlaneUtil::xplane10Dir();
if (xPlaneLocation.isEmpty())
xPlaneLocation = BlackMisc::Simulation::XPlane::CXPlaneUtil::xplane9Dir();
QString path = QFileDialog::getExistingDirectory(parentWidget(),
tr("Choose your X-Plane install directory"),
xPlaneLocation,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
path.append("/Resources/plugins/xbus/64/");
QDir xbusDir(path);
if (!xbusDir.exists())
{
if (!xbusDir.mkpath("."))
{
return;
}
}
QString origin = QCoreApplication::applicationDirPath() % QStringLiteral("/../xbus/64/lin.xpl");
QString destination = path % "/lin.xpl";
QFile::copy(origin, destination);
QMessageBox::information(this, tr("XBus installed"), tr("You may now launch your X-Plane and start using XBus!"));
}
} }
} }

View File

@@ -34,17 +34,17 @@ namespace BlackSimPlugin
public: public:
//! Ctor. //! Ctor.
CSimulatorXPlaneConfigWindow(); CSimulatorXPlaneConfigWindow(QWidget *parent);
//! Dtor. //! Dtor.
virtual ~CSimulatorXPlaneConfigWindow(); virtual ~CSimulatorXPlaneConfigWindow();
private slots: private slots:
void ps_storeSettings(); void ps_storeSettings();
void ps_installXBus();
private: private:
QScopedPointer<Ui::CSimulatorXPlaneConfigWindow> ui; QScopedPointer<Ui::CSimulatorXPlaneConfigWindow> ui;
BlackCore::CSetting<XBusServer> m_xbusServerSetting { this }; BlackCore::CSetting<XBusServer> m_xbusServerSetting { this };
}; };

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>74</height> <height>136</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -24,7 +24,14 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="3" column="1">
<widget class="QPushButton" name="pb_InstallXBus">
<property name="text">
<string>Install XBus in the X-Plane directory...</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDialogButtonBox" name="bb_OkCancel"> <widget class="QDialogButtonBox" name="bb_OkCancel">
<property name="standardButtons"> <property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
@@ -34,6 +41,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
<resources/> <resources/>