mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
Ref T195, DBus address selector UI to be used with launcher and core UI
This commit is contained in:
120
src/blackgui/components/dbusserveraddressselector.cpp
Normal file
120
src/blackgui/components/dbusserveraddressselector.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
/* Copyright (C) 2017
|
||||
* 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 "dbusserveraddressselector.h"
|
||||
#include "ui_dbusserveraddressselector.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackmisc/network/networkutils.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
|
||||
#include <QIntValidator>
|
||||
|
||||
using namespace BlackConfig;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CDBusServerAddressSelector::CDBusServerAddressSelector(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CDBusServerAddressSelector)
|
||||
{
|
||||
Q_ASSERT(sGui);
|
||||
ui->setupUi(this);
|
||||
|
||||
// normally no system Bus on Windows
|
||||
if (CBuildConfig::isRunningOnWindowsNtPlatform() && !sGui->isRunningInDeveloperEnvironment())
|
||||
{
|
||||
ui->rb_DBusSystem->setEnabled(false);
|
||||
}
|
||||
|
||||
ui->cb_DBusServerAddress->addItems(CNetworkUtils::getKnownLocalIpV4Addresses());
|
||||
ui->cb_DBusServerAddress->setCurrentIndex(0);
|
||||
this->set(sGui->getCmdDBusAddressValue());
|
||||
|
||||
ui->le_DBusServerPort->setValidator(new QIntValidator(0, 65535, this));
|
||||
connect(ui->rb_DBusP2P, &QRadioButton::released, this, &CDBusServerAddressSelector::radioButtonReleased);
|
||||
connect(ui->rb_DBusSession, &QRadioButton::released, this, &CDBusServerAddressSelector::radioButtonReleased);
|
||||
connect(ui->rb_DBusSystem, &QRadioButton::released, this, &CDBusServerAddressSelector::radioButtonReleased);
|
||||
connect(ui->cb_DBusServerAddress, &QComboBox::currentTextChanged, this, &CDBusServerAddressSelector::p2pAddressChanged);
|
||||
}
|
||||
|
||||
CDBusServerAddressSelector::~CDBusServerAddressSelector()
|
||||
{ }
|
||||
|
||||
QString CDBusServerAddressSelector::getP2PAddress() const
|
||||
{
|
||||
if (!this->isP2P()) { return ""; }
|
||||
return CDBusServer::p2pAddress(
|
||||
ui->cb_DBusServerAddress->currentText() + ":" +
|
||||
ui->le_DBusServerPort->text()
|
||||
);
|
||||
}
|
||||
|
||||
QString CDBusServerAddressSelector::getDBusAddress() const
|
||||
{
|
||||
if (ui->rb_DBusSession->isChecked()) { return CDBusServer::sessionBusAddress(); }
|
||||
if (ui->rb_DBusSystem->isChecked()) { return CDBusServer::systemBusAddress(); }
|
||||
return this->getP2PAddress();
|
||||
}
|
||||
|
||||
QStringList CDBusServerAddressSelector::getDBusCmdLineArgs() const
|
||||
{
|
||||
return QStringList { "--dbus", this->getDBusAddress() };
|
||||
}
|
||||
|
||||
bool CDBusServerAddressSelector::isP2P() const
|
||||
{
|
||||
return ui->rb_DBusP2P->isChecked();
|
||||
}
|
||||
|
||||
void CDBusServerAddressSelector::set(const QString &dBus)
|
||||
{
|
||||
const QString dBusLc = dBus.toLower().trimmed();
|
||||
if (dBusLc.isEmpty() || dBusLc.startsWith("session"))
|
||||
{
|
||||
ui->rb_DBusSession->setChecked(true);
|
||||
}
|
||||
else if (dBusLc.startsWith("sys"))
|
||||
{
|
||||
ui->rb_DBusSystem->setChecked(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->rb_DBusP2P->setChecked(true);
|
||||
QString host, port;
|
||||
CDBusServer::dBusAddressToHostAndPort(dBusLc, host, port);
|
||||
if (!host.isEmpty())
|
||||
{
|
||||
if (ui->cb_DBusServerAddress->findText(host) < 0)
|
||||
{
|
||||
ui->cb_DBusServerAddress->addItem(host);
|
||||
}
|
||||
ui->cb_DBusServerAddress->setCurrentText(host);
|
||||
ui->le_DBusServerPort->setText(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CDBusServerAddressSelector::radioButtonReleased()
|
||||
{
|
||||
const bool p2p = this->isP2P();
|
||||
ui->le_DBusServerPort->setEnabled(p2p);
|
||||
ui->cb_DBusServerAddress->setEnabled(p2p);
|
||||
}
|
||||
|
||||
void CDBusServerAddressSelector::p2pAddressChanged()
|
||||
{
|
||||
// void
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
62
src/blackgui/components/dbusserveraddressselector.h
Normal file
62
src/blackgui/components/dbusserveraddressselector.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* Copyright (C) 2017
|
||||
* 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_COMPONENTS_DBUSSERVERADDRESSSELECTOR_H
|
||||
#define BLACKGUI_COMPONENTS_DBUSSERVERADDRESSSELECTOR_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include <QFrame>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace Ui { class CDBusServerAddressSelector; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
//! Select DBus address such as session P2P, ...
|
||||
class BLACKGUI_EXPORT CDBusServerAddressSelector : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
explicit CDBusServerAddressSelector(QWidget *parent = nullptr);
|
||||
|
||||
//! Dtor
|
||||
virtual ~CDBusServerAddressSelector();
|
||||
|
||||
//! DBus address for P2P or empty
|
||||
QString getP2PAddress() const;
|
||||
|
||||
//! DBus address for all 3 options
|
||||
QString getDBusAddress() const;
|
||||
|
||||
//! Get DBus cmd.line arguments
|
||||
QStringList getDBusCmdLineArgs() const;
|
||||
|
||||
//! P2P DBus address
|
||||
bool isP2P() const;
|
||||
|
||||
//! Set values
|
||||
void set(const QString &dBus);
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDBusServerAddressSelector> ui;
|
||||
|
||||
//! Radio button clicked
|
||||
void radioButtonReleased();
|
||||
|
||||
//! P2P address changed
|
||||
void p2pAddressChanged();
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
#endif // guard
|
||||
116
src/blackgui/components/dbusserveraddressselector.ui
Normal file
116
src/blackgui/components/dbusserveraddressselector.ui
Normal file
@@ -0,0 +1,116 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDBusServerAddressSelector</class>
|
||||
<widget class="QFrame" name="CDBusServerAddressSelector">
|
||||
<property name="windowTitle">
|
||||
<string>Frame</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_DBusSelector">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_DBusSession">
|
||||
<property name="text">
|
||||
<string>DBus session server</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_DBusSystem">
|
||||
<property name="text">
|
||||
<string>DBus system server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_DBusP2P">
|
||||
<property name="text">
|
||||
<string>DBus peer to peer server (P2P)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="fr_DBusServerAddress">
|
||||
<layout class="QGridLayout" name="gl_DBusServerAddressDetails">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="verticalSpacing">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item row="0" column="2">
|
||||
<widget class="QComboBox" name="cb_DBusServerAddress">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_DBusServerAddress">
|
||||
<property name="text">
|
||||
<string>Address:</string>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_DBusServerPort">
|
||||
<property name="text">
|
||||
<string>Port:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QLineEdit" name="le_DBusServerPort">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>45000</string>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user