<property name="bottomMargin">
<number>8</number>
</property>
- <item row="8" column="0">
+ <item row="9" column="0">
<widget class="QPushButton" name="restoreDefaultsButton">
<property name="text">
<string>Restore Defaults...</string>
</item>
</layout>
</item>
- <item row="7" column="0" colspan="2">
+ <item row="8" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Additional options</string>
</layout>
</widget>
</item>
- <item row="6" column="0">
+ <item row="7" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</spacer>
</item>
+ <item row="6" column="0" colspan="2">
+ <widget class="QGroupBox" name="mpBox">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>100</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Multi-player</string>
+ </property>
+ <property name="checkable">
+ <bool>true</bool>
+ </property>
+ <layout class="QGridLayout" name="gridLayout" columnstretch="1,2,0">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_9">
+ <property name="text">
+ <string>Callsign:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="label_10">
+ <property name="text">
+ <string>Server:</string>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="mpCallsign">
+ <property name="maxLength">
+ <number>10</number>
+ </property>
+ <property name="placeholderText">
+ <string>G-FGFS</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="2">
+ <widget class="QLabel" name="label_11">
+ <property name="text">
+ <string>(Ten characters maximum)</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1" colspan="2">
+ <widget class="QComboBox" name="mpServerCombo"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
</layout>
</widget>
</widget>
#include "PathsDialog.hxx"
#include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
#include <Navaids/NavDataCache.hxx>
#include <Navaids/navrecord.hxx>
#include <Navaids/SHPParser.hxx>
#include <Main/fg_init.hxx>
#include <Viewer/WindowBuilder.hxx>
#include <Network/HTTPClient.hxx>
+#include <Network/RemoteXMLRequest.hxx>
using namespace flightgear;
using namespace simgear::pkg;
QDialog(),
m_ui(NULL),
m_subsystemIdleTimer(NULL),
- m_inAppMode(false)
+ m_inAppMode(false),
+ m_doRestoreMPServer(false)
{
m_ui.reset(new Ui::Launcher);
m_ui->setupUi(this);
checkOfficialCatalogMessage();
restoreSettings();
+
+ onRefreshMPServers();
}
QtLauncher::~QtLauncher()
maybeRestoreAircraftSelection();
m_ui->commandLineArgs->setPlainText(settings.value("additional-args").toString());
+
+ m_ui->mpCallsign->setText(settings.value("mp-callsign").toString());
+ // don't restore MP server here, we do it after a refresh
+ m_doRestoreMPServer = true;
}
void QtLauncher::delayedAircraftModelReset()
settings.setValue("additional-args", m_ui->commandLineArgs->toPlainText());
m_ui->location->saveSettings();
+
+ settings.setValue("mp-callsign", m_ui->mpCallsign->text());
+ settings.setValue("mp-server", m_ui->mpServerCombo->currentData());
}
void QtLauncher::setEnableDisableOptionFromCheckbox(QCheckBox* cbox, QString name) const
m_recentAircraft.pop_back();
}
+ if (m_ui->mpBox->isChecked()) {
+ opt->addOption("callsign", m_ui->mpCallsign->text().toStdString());
+ QString host = m_ui->mpServerCombo->currentData().toString();
+ globals->get_props()->setStringValue("/sim/multiplay/txhost", host.toStdString());
+ int port = findMPServerPort(host.toStdString());
+ globals->get_props()->setIntValue("/sim/multiplay/txport", port);
+ }
+
m_ui->location->setLocationOptions();
// time of day
checkOfficialCatalogMessage();
}
+void QtLauncher::onRefreshMPServers()
+{
+ if (m_mpServerRequest.get()) {
+ return; // in-progress
+ }
+
+ string url(fgGetString("/sim/multiplay/serverlist-url",
+ "http://liveries.flightgear.org/mpstatus/mpservers.xml"));
+
+ if (url.empty()) {
+ SG_LOG(SG_IO, SG_ALERT, "do_multiplayer.refreshserverlist: no URL given");
+ return;
+ }
+
+ SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
+ m_mpServerRequest.reset(new RemoteXMLRequest(url, targetnode));
+ m_mpServerRequest->done(this, &QtLauncher::onRefreshMPServersDone);
+ m_mpServerRequest->fail(this, &QtLauncher::onRefreshMPServersFailed);
+ globals->get_subsystem<FGHTTPClient>()->makeRequest(m_mpServerRequest);
+}
+
+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) {
+ SGPropertyNode* c = targetnode->getChild(i);
+ if (c->getName() != std::string("server")) {
+ continue;
+ }
+
+ QString name = QString::fromStdString(c->getStringValue("name"));
+ QString loc = QString::fromStdString(c->getStringValue("location"));
+ QString host = QString::fromStdString(c->getStringValue("hostname"));
+ 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);
+ }
+ }
+
+ m_mpServerRequest.clear();
+}
+
+void QtLauncher::onRefreshMPServersFailed(simgear::HTTP::Request*)
+{
+ qWarning() << "refreshing MP servers failed:" << QString::fromStdString(m_mpServerRequest->responseReason());
+ m_mpServerRequest.clear();
+}
+
+void QtLauncher::onMPServerEdited(QString text)
+{
+ // parse as server hostname + optional URL
+}
+
+int QtLauncher::findMPServerPort(const std::string& host)
+{
+ SGPropertyNode *targetnode = fgGetNode("/sim/multiplay/server-list", true);
+ for (int i=0; i<targetnode->nChildren(); ++i) {
+ SGPropertyNode* c = targetnode->getChild(i);
+ if (c->getName() != std::string("server")) {
+ continue;
+ }
+
+ if (c->getStringValue("hostname") == host) {
+ return c->getIntValue("port");
+ }
+ }
+
+ return 0;
+}
+
simgear::pkg::PackageRef QtLauncher::packageForAircraftURI(QUrl uri) const
{
if (uri.scheme() != "package") {