mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-23 14:52:24 +00:00
UI work, add name to listnetworks output in control bus interface.
This commit is contained in:
parent
902c8c38d2
commit
c979a695c5
@ -13,7 +13,7 @@ class AboutWindow : public QDialog
|
||||
|
||||
public:
|
||||
explicit AboutWindow(QWidget *parent = 0);
|
||||
~AboutWindow();
|
||||
virtual ~AboutWindow();
|
||||
|
||||
private slots:
|
||||
void on_uninstallButton_clicked();
|
||||
|
@ -127,6 +127,11 @@ void MainWindow::customEvent(QEvent *event)
|
||||
if (hdr.size() >= 5)
|
||||
this->myVersion = hdr[4].c_str();
|
||||
} else if (hdr[1] == "listnetworks") {
|
||||
const QObjectList &existingNetworks = ui->networksScrollAreaContentWidget->children();
|
||||
|
||||
for(unsigned long i=1;i<m->ztMessage.size();++i) {
|
||||
std::vector<std::string> l(ZeroTier::Node::LocalClient::splitLine(m->ztMessage[i]));
|
||||
}
|
||||
} else if (hdr[1] == "listpeers") {
|
||||
this->numPeers = 0;
|
||||
for(unsigned long i=1;i<m->ztMessage.size();++i) {
|
||||
@ -151,6 +156,18 @@ void MainWindow::customEvent(QEvent *event)
|
||||
|
||||
void MainWindow::on_joinNetworkButton_clicked()
|
||||
{
|
||||
QString toJoin(ui->networkIdLineEdit->text());
|
||||
ui->networkIdLineEdit->setText(QString());
|
||||
|
||||
if (!zeroTierClient) // sanity check
|
||||
return;
|
||||
|
||||
if (toJoin.size() != 16) {
|
||||
QMessageBox::information(this,"Invalid Network ID","The network ID you entered was not valid. Enter a 16-digit hexadecimal network ID, like '8056c2e21c000001'.",QMessageBox::Ok,QMessageBox::NoButton);
|
||||
return;
|
||||
}
|
||||
|
||||
zeroTierClient->send((QString("join ") + toJoin).toStdString());
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAbout_triggered()
|
||||
@ -165,10 +182,6 @@ void MainWindow::on_actionJoin_Network_triggered()
|
||||
on_joinNetworkButton_clicked();
|
||||
}
|
||||
|
||||
void MainWindow::on_actionShow_Detailed_Status_triggered()
|
||||
{
|
||||
}
|
||||
|
||||
void MainWindow::on_networkIdLineEdit_textChanged(const QString &text)
|
||||
{
|
||||
QString newText;
|
||||
|
@ -21,6 +21,8 @@ class MainWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Event used to pass messages from the Node::LocalClient thread to the
|
||||
// main window to update network lists and stats.
|
||||
class ZTMessageEvent : public QEvent
|
||||
{
|
||||
public:
|
||||
@ -44,7 +46,6 @@ private slots:
|
||||
void on_joinNetworkButton_clicked();
|
||||
void on_actionAbout_triggered();
|
||||
void on_actionJoin_Network_triggered();
|
||||
void on_actionShow_Detailed_Status_triggered();
|
||||
void on_networkIdLineEdit_textChanged(const QString &arg1);
|
||||
void on_statusAndAddressButton_clicked();
|
||||
|
||||
|
@ -54,7 +54,7 @@
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<widget class="QWidget" name="networksScrollAreaContentWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -225,7 +225,6 @@
|
||||
<string>File</string>
|
||||
</property>
|
||||
<addaction name="actionJoin_Network"/>
|
||||
<addaction name="actionShow_Detailed_Status"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
@ -242,11 +241,6 @@
|
||||
<string>Join Network</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionShow_Detailed_Status">
|
||||
<property name="text">
|
||||
<string>Show Detailed Status</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionExit">
|
||||
<property name="text">
|
||||
<string>Exit</string>
|
||||
|
@ -1,13 +1,22 @@
|
||||
#include "network.h"
|
||||
#include "mainwindow.h"
|
||||
#include "ui_network.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcess>
|
||||
#include <QList>
|
||||
#include <QMessageBox>
|
||||
|
||||
Network::Network(QWidget *parent) :
|
||||
Network::Network(QWidget *parent,const std::string &nwid) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::Network)
|
||||
ui(new Ui::Network),
|
||||
networkIdStr(nwid)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->networkIdPushButton->setText(QString(nwid.c_str()));
|
||||
}
|
||||
|
||||
Network::~Network()
|
||||
@ -15,8 +24,74 @@ Network::~Network()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void Network::setStatus(const std::string &status)
|
||||
{
|
||||
ui->statusLabel->setText(QString(status.c_str()));
|
||||
}
|
||||
|
||||
void Network::setNetworkName(const std::string &status)
|
||||
{
|
||||
ui->nameLabel->setText(QString(status.c_str()));
|
||||
}
|
||||
|
||||
void Network::setNetworkType(const std::string &type)
|
||||
{
|
||||
ui->networkTypeLabel->setText(QString(status.c_str()));
|
||||
if (type == "?")
|
||||
ui->networkTypeLabel->setToolTip("Waiting for configuration...");
|
||||
else if (type == "public")
|
||||
ui->networkTypeLabel->setToolTip("This network can be joined by anyone.");
|
||||
else if (type == "private")
|
||||
ui->networkTypeLabel->setToolTip("This network is private, only authorized peers can join.");
|
||||
else ui->networkTypeLabel->setToolTip(QString());
|
||||
}
|
||||
|
||||
void Network::setNetworkDeviceName(const std::string &dev)
|
||||
{
|
||||
ui->deviceLabel->setText(QString(dev.c_str()));
|
||||
}
|
||||
|
||||
void Network::setIps(const std::string &commaSeparatedList)
|
||||
{
|
||||
QStringList ips(QString(commaSeparatedList.c_str()).split(QChar(','),QString::SkipEmptyParts));
|
||||
if (commaSeparatedList == "-")
|
||||
ips.clear();
|
||||
|
||||
QStringList tmp;
|
||||
ips.sort();
|
||||
for(QStringList::iterator i(ips.begin());i!=ips.end();++i) {
|
||||
QString ipOnly(*i);
|
||||
int slashIdx = ipOnly.indexOf('/');
|
||||
if (slashIdx > 0)
|
||||
ipOnly.truncate(slashIdx);
|
||||
tmp.append(ipOnly);
|
||||
}
|
||||
ips = tmp;
|
||||
|
||||
for(QStringList::iterator i(ips.begin());i!=ips.end();++i) {
|
||||
if (ui->ipListWidget->findItems(*i).size() == 0)
|
||||
ui->ipListWidget->addItem(*i);
|
||||
}
|
||||
|
||||
QList<QListWidgetItem *> inList(ui->ipListWidget->items());
|
||||
for(QList<QListWidgetItem *>::iterator i(inList.begin());i!=inList.end();++i) {
|
||||
QListWidgetItem *item = *i;
|
||||
if (!ips.contains(item->text()))
|
||||
ui->ipListWidget->removeItemWidget(item);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string &Network::networkId()
|
||||
{
|
||||
return networkIdStr;
|
||||
}
|
||||
|
||||
void Network::on_leaveNetworkButton_clicked()
|
||||
{
|
||||
if (QMessageBox::question(this,"Leave Network?",QString("Are you sure you want to leave network '") + networkIdStr.c_str() + "'?",QMessageBox::No,QMessageBox::Yes) == QMessageBox::Yes) {
|
||||
zeroTierClient->send((QString("leave ") + networkIdStr.c_str()).toStdString());
|
||||
this->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void Network::on_networkIdPushButton_clicked()
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
@ -12,16 +14,24 @@ class Network : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Network(QWidget *parent = 0);
|
||||
~Network();
|
||||
explicit Network(QWidget *parent = 0,const std::string &nwid);
|
||||
virtual ~Network();
|
||||
|
||||
void setStatus(const std::string &status);
|
||||
void setNetworkName(const std::string &name);
|
||||
void setNetworkType(const std::string &type);
|
||||
void setNetworkDeviceName(const std::string &dev);
|
||||
void setIps(const std::string &commaSeparatedList);
|
||||
|
||||
const std::string &networkId();
|
||||
|
||||
private slots:
|
||||
void on_leaveNetworkButton_clicked();
|
||||
|
||||
void on_networkIdPushButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::Network *ui;
|
||||
std::string networkIdStr;
|
||||
};
|
||||
|
||||
#endif // NETWORK_H
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>618</width>
|
||||
<height>93</height>
|
||||
<height>108</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -112,6 +112,16 @@ text-align: left;</string>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Status:</string>
|
||||
@ -121,7 +131,7 @@ text-align: left;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
@ -143,7 +153,7 @@ text-align: left;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<item row="6" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Device:</string>
|
||||
@ -153,7 +163,7 @@ text-align: left;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="deviceLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
@ -169,7 +179,7 @@ text-align: left;</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<item row="7" column="1">
|
||||
<widget class="QWidget" name="leaveNetworkButtonContainerWidget" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
@ -231,6 +241,48 @@ text-align: left;</string>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="nameLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>(name)</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Type:</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="networkTypeLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>public</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>Qt::PlainText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -251,6 +303,9 @@ text-align: left;</string>
|
||||
<property name="showDropIndicator" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -28,6 +28,9 @@
|
||||
#ifndef _ZT_NODE_HPP
|
||||
#define _ZT_NODE_HPP
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
@ -70,6 +73,7 @@ public:
|
||||
*/
|
||||
unsigned long send(const char *command)
|
||||
throw();
|
||||
inline unsigned long send(const std::string &command) throw() { return send(command.c_str()); }
|
||||
|
||||
/**
|
||||
* Split a line of results by space
|
||||
|
@ -200,7 +200,7 @@ std::vector<std::string> NodeConfig::execute(const char *command)
|
||||
_r->topology->eachPeer(_DumpPeerStatistics(r));
|
||||
} else if (cmd[0] == "listnetworks") {
|
||||
Mutex::Lock _l(_networks_m);
|
||||
_P("200 listnetworks <nwid> <status> <type> <dev> <ips>");
|
||||
_P("200 listnetworks <nwid> <name> <status> <type> <dev> <ips>");
|
||||
for(std::map< uint64_t,SharedPtr<Network> >::const_iterator nw(_networks.begin());nw!=_networks.end();++nw) {
|
||||
std::string tmp;
|
||||
std::set<InetAddress> ips(nw->second->tap().ips());
|
||||
@ -211,8 +211,9 @@ std::vector<std::string> NodeConfig::execute(const char *command)
|
||||
}
|
||||
|
||||
SharedPtr<NetworkConfig> nconf(nw->second->config2());
|
||||
_P("200 listnetworks %.16llx %s %s %s %s",
|
||||
_P("200 listnetworks %.16llx %s %s %s %s %s",
|
||||
(unsigned long long)nw->first,
|
||||
((nconf) ? nconf->name().c_str() : "?"),
|
||||
Network::statusString(nw->second->status()),
|
||||
((nconf) ? (nconf->isOpen() ? "public" : "private") : "?"),
|
||||
nw->second->tap().deviceName().c_str(),
|
||||
|
Loading…
Reference in New Issue
Block a user