Custom MP server support.
This commit is contained in:
parent
2eb5e6f0f4
commit
d800c49cb9
6 changed files with 236 additions and 17 deletions
|
@ -78,6 +78,7 @@ if (HAVE_QT)
|
|||
LocationWidget.ui
|
||||
NoOfficialHangar.ui
|
||||
InstallSceneryDialog.ui
|
||||
EditCustomMPServerDialog.ui
|
||||
)
|
||||
qt5_add_resources(qrc_sources resources.qrc)
|
||||
|
||||
|
@ -113,6 +114,8 @@ if (HAVE_QT)
|
|||
QtFileDialog.hxx
|
||||
InstallSceneryDialog.hxx
|
||||
InstallSceneryDialog.cxx
|
||||
EditCustomMPServerDialog.cxx
|
||||
EditCustomMPServerDialog.hxx
|
||||
${uic_sources}
|
||||
${qrc_sources})
|
||||
|
||||
|
|
48
src/GUI/EditCustomMPServerDialog.cxx
Normal file
48
src/GUI/EditCustomMPServerDialog.cxx
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "EditCustomMPServerDialog.hxx"
|
||||
#include "ui_EditCustomMPServerDialog.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QComboBox>
|
||||
|
||||
#include "Main/fg_props.hxx"
|
||||
|
||||
EditCustomMPServerDialog::EditCustomMPServerDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::EditCustomMPServerDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
QSettings settings;
|
||||
ui->mpServer->setText(settings.value("mp-custom-host").toString());
|
||||
ui->port->setText(settings.value("mp-custom-port").toString());
|
||||
}
|
||||
|
||||
EditCustomMPServerDialog::~EditCustomMPServerDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
QString EditCustomMPServerDialog::hostname() const
|
||||
{
|
||||
return ui->mpServer->text();
|
||||
}
|
||||
|
||||
void EditCustomMPServerDialog::accept()
|
||||
{
|
||||
QSettings settings;
|
||||
settings.setValue("mp-custom-host", ui->mpServer->text());
|
||||
settings.setValue("mp-custom-port", ui->port->text());
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void EditCustomMPServerDialog::addCustomItem(QComboBox* combo)
|
||||
{
|
||||
QSettings settings;
|
||||
QString customMPHost = settings.value("mp-custom-host").toString();
|
||||
|
||||
if (customMPHost.isEmpty()) {
|
||||
combo->addItem(tr("Custom server..."), "custom");
|
||||
return;
|
||||
}
|
||||
|
||||
combo->addItem(tr("Custom - %1").arg(customMPHost), "custom");
|
||||
}
|
29
src/GUI/EditCustomMPServerDialog.hxx
Normal file
29
src/GUI/EditCustomMPServerDialog.hxx
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef EDITCUSTOMMPSERVERDIALOG_HXX
|
||||
#define EDITCUSTOMMPSERVERDIALOG_HXX
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
namespace Ui {
|
||||
class EditCustomMPServerDialog;
|
||||
}
|
||||
|
||||
class QComboBox;
|
||||
|
||||
class EditCustomMPServerDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditCustomMPServerDialog(QWidget *parent = 0);
|
||||
~EditCustomMPServerDialog();
|
||||
|
||||
QString hostname() const;
|
||||
|
||||
virtual void accept();
|
||||
|
||||
static void addCustomItem(QComboBox* combo);
|
||||
private:
|
||||
Ui::EditCustomMPServerDialog *ui;
|
||||
};
|
||||
|
||||
#endif // EDITCUSTOMMPSERVERDIALOG_HXX
|
114
src/GUI/EditCustomMPServerDialog.ui
Normal file
114
src/GUI/EditCustomMPServerDialog.ui
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditCustomMPServerDialog</class>
|
||||
<widget class="QDialog" name="EditCustomMPServerDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>369</width>
|
||||
<height>172</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Enter custom server</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout" columnstretch="1,1">
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Enter the host name and optional port of the multi-player server you wish to connect to.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Server:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="mpServer">
|
||||
<property name="placeholderText">
|
||||
<string>flightgear.example.com</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="port">
|
||||
<property name="text">
|
||||
<string>5000</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>5000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>EditCustomMPServerDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>EditCustomMPServerDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -65,6 +65,7 @@
|
|||
#include "AircraftItemDelegate.hxx"
|
||||
#include "AircraftModel.hxx"
|
||||
#include "PathsDialog.hxx"
|
||||
#include "EditCustomMPServerDialog.hxx"
|
||||
|
||||
#include <Main/globals.hxx>
|
||||
#include <Main/fg_props.hxx>
|
||||
|
@ -577,6 +578,9 @@ QtLauncher::QtLauncher() :
|
|||
this, &QtLauncher::onToggleTerrasync);
|
||||
updateSettingsSummary();
|
||||
|
||||
connect(m_ui->mpServerCombo, SIGNAL(activated(int)),
|
||||
this, SLOT(onMPServerActivated(int)));
|
||||
|
||||
m_aircraftModel = new AircraftItemModel(this);
|
||||
m_aircraftProxy->setSourceModel(m_aircraftModel);
|
||||
|
||||
|
@ -846,8 +850,15 @@ void QtLauncher::onRun()
|
|||
if (m_ui->mpBox->isChecked()) {
|
||||
opt->addOption("callsign", m_ui->mpCallsign->text().toStdString());
|
||||
QString host = m_ui->mpServerCombo->currentData().toString();
|
||||
int port = 5000;
|
||||
if (host == "custom") {
|
||||
QSettings settings;
|
||||
host = settings.value("mp-custom-host").toString();
|
||||
port = settings.value("mp-custom-port").toInt();
|
||||
} else {
|
||||
port = findMPServerPort(host.toStdString());
|
||||
}
|
||||
globals->get_props()->setStringValue("/sim/multiplay/txhost", host.toStdString());
|
||||
int port = findMPServerPort(host.toStdString());
|
||||
globals->get_props()->setIntValue("/sim/multiplay/txport", port);
|
||||
}
|
||||
|
||||
|
@ -1302,8 +1313,6 @@ void QtLauncher::onRefreshMPServersDone(simgear::HTTP::Request*)
|
|||
{
|
||||
// parse the properties
|
||||
SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
|
||||
|
||||
|
||||
m_ui->mpServerCombo->clear();
|
||||
|
||||
for (int i=0; i<targetnode->nChildren(); ++i) {
|
||||
|
@ -1318,13 +1327,8 @@ void QtLauncher::onRefreshMPServersDone(simgear::HTTP::Request*)
|
|||
m_ui->mpServerCombo->addItem(tr("%1 - %2").arg(name,loc), host);
|
||||
}
|
||||
|
||||
if (m_doRestoreMPServer) {
|
||||
QSettings settings;
|
||||
int index = m_ui->mpServerCombo->findData(settings.value("mp-server"));
|
||||
if (index >= 0) {
|
||||
m_ui->mpServerCombo->setCurrentIndex(index);
|
||||
}
|
||||
}
|
||||
EditCustomMPServerDialog::addCustomItem(m_ui->mpServerCombo);
|
||||
restoreMPServerSelection();
|
||||
|
||||
m_mpServerRequest.clear();
|
||||
}
|
||||
|
@ -1333,11 +1337,31 @@ void QtLauncher::onRefreshMPServersFailed(simgear::HTTP::Request*)
|
|||
{
|
||||
qWarning() << "refreshing MP servers failed:" << QString::fromStdString(m_mpServerRequest->responseReason());
|
||||
m_mpServerRequest.clear();
|
||||
EditCustomMPServerDialog::addCustomItem(m_ui->mpServerCombo);
|
||||
restoreMPServerSelection();
|
||||
}
|
||||
|
||||
void QtLauncher::onMPServerEdited(QString text)
|
||||
void QtLauncher::restoreMPServerSelection()
|
||||
{
|
||||
// parse as server hostname + optional URL
|
||||
if (m_doRestoreMPServer) {
|
||||
QSettings settings;
|
||||
int index = m_ui->mpServerCombo->findData(settings.value("mp-server"));
|
||||
if (index >= 0) {
|
||||
m_ui->mpServerCombo->setCurrentIndex(index);
|
||||
}
|
||||
m_doRestoreMPServer = false;
|
||||
}
|
||||
}
|
||||
|
||||
void QtLauncher::onMPServerActivated(int index)
|
||||
{
|
||||
if (m_ui->mpServerCombo->itemData(index) == "custom") {
|
||||
EditCustomMPServerDialog dlg(this);
|
||||
dlg.exec();
|
||||
if (dlg.result() == QDialog::Accepted) {
|
||||
m_ui->mpServerCombo->setItemText(index, tr("Custom - %1").arg(dlg.hostname()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int QtLauncher::findMPServerPort(const std::string& host)
|
||||
|
|
|
@ -99,7 +99,7 @@ private slots:
|
|||
void onDownloadDirChanged();
|
||||
|
||||
void onRefreshMPServers();
|
||||
void onMPServerEdited(QString text);
|
||||
void onMPServerActivated(int index);
|
||||
|
||||
|
||||
private:
|
||||
|
@ -127,6 +127,7 @@ private:
|
|||
void onRefreshMPServersDone(simgear::HTTP::Request*);
|
||||
void onRefreshMPServersFailed(simgear::HTTP::Request*);
|
||||
int findMPServerPort(const std::string& host);
|
||||
void restoreMPServerSelection();
|
||||
|
||||
// need to wait after a model reset before restoring selection and
|
||||
// scrolling, to give the view time it seems.
|
||||
|
|
Loading…
Reference in a new issue