LocationWidget.ui
NoOfficialHangar.ui
InstallSceneryDialog.ui
+ EditCustomMPServerDialog.ui
)
qt5_add_resources(qrc_sources resources.qrc)
QtFileDialog.hxx
InstallSceneryDialog.hxx
InstallSceneryDialog.cxx
+ EditCustomMPServerDialog.cxx
+ EditCustomMPServerDialog.hxx
${uic_sources}
${qrc_sources})
--- /dev/null
+#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");
+}
\ No newline at end of file
--- /dev/null
+#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
--- /dev/null
+<?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>
#include "AircraftItemDelegate.hxx"
#include "AircraftModel.hxx"
#include "PathsDialog.hxx"
+#include "EditCustomMPServerDialog.hxx"
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
if (status == NoOfficialCatalogMessage) {
return true;
}
-
+
if (!QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent)) {
return false;
}
// startup the HTTP system now since packages needs it
FGHTTPClient* http = globals->add_new_subsystem<FGHTTPClient>();
-
+
// we guard against re-init in the global phase; bind and postinit
// will happen as normal
http->init();
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);
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);
}
m_aircraftModel->scanDirs();
checkOfficialCatalogMessage();
-
+
// re-set scenery dirs
setSceneryPaths();
}
{
// parse the properties
SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
-
-
m_ui->mpServerCombo->clear();
for (int i=0; i<targetnode->nChildren(); ++i) {
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();
}
{
qWarning() << "refreshing MP servers failed:" << QString::fromStdString(m_mpServerRequest->responseReason());
m_mpServerRequest.clear();
+ EditCustomMPServerDialog::addCustomItem(m_ui->mpServerCombo);
+ restoreMPServerSelection();
+}
+
+void QtLauncher::restoreMPServerSelection()
+{
+ 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::onMPServerEdited(QString text)
+void QtLauncher::onMPServerActivated(int index)
{
- // parse as server hostname + optional URL
+ 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)
// apply is used in-app, where we must set properties and trigger
// a reset; setting command line options won't help us.
void onApply();
-
+
void onQuit();
void onDownloadDirChanged();
void onRefreshMPServers();
- void onMPServerEdited(QString text);
+ void onMPServerActivated(int index);
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.