mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Fix for GitHub issue #30
This commit is contained in:
parent
434a2f7071
commit
fe6b7f477c
4 changed files with 53 additions and 37 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
|
#include <QEventLoop>
|
||||||
|
|
||||||
// Globally visible
|
// Globally visible
|
||||||
ZeroTier::Node::LocalClient *zeroTierClient = (ZeroTier::Node::LocalClient *)0;
|
ZeroTier::Node::LocalClient *zeroTierClient = (ZeroTier::Node::LocalClient *)0;
|
||||||
|
@ -76,7 +77,7 @@ MainWindow::~MainWindow()
|
||||||
|
|
||||||
void MainWindow::timerEvent(QTimerEvent *event)
|
void MainWindow::timerEvent(QTimerEvent *event)
|
||||||
{
|
{
|
||||||
QMainWindow::timerEvent(event);
|
event->accept();
|
||||||
|
|
||||||
if (!zeroTierClient) {
|
if (!zeroTierClient) {
|
||||||
std::string dotAuthFile((QDir::homePath() + QDir::separator() + ".zeroTierOneAuthToken").toStdString());
|
std::string dotAuthFile((QDir::homePath() + QDir::separator() + ".zeroTierOneAuthToken").toStdString());
|
||||||
|
@ -123,7 +124,6 @@ void MainWindow::timerEvent(QTimerEvent *event)
|
||||||
void MainWindow::customEvent(QEvent *event)
|
void MainWindow::customEvent(QEvent *event)
|
||||||
{
|
{
|
||||||
ZTMessageEvent *m = (ZTMessageEvent *)event; // only one custom event type so far
|
ZTMessageEvent *m = (ZTMessageEvent *)event; // only one custom event type so far
|
||||||
|
|
||||||
if (m->ztMessage.size() == 0)
|
if (m->ztMessage.size() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -143,46 +143,57 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
if (hdr.size() >= 5)
|
if (hdr.size() >= 5)
|
||||||
this->myVersion = hdr[4].c_str();
|
this->myVersion = hdr[4].c_str();
|
||||||
} else if (hdr[1] == "listnetworks") {
|
} else if (hdr[1] == "listnetworks") {
|
||||||
std::map< std::string,std::vector<std::string> > byNwid;
|
std::map< std::string,std::vector<std::string> > newNetworks;
|
||||||
for(unsigned long i=1;i<m->ztMessage.size();++i) {
|
for(unsigned long i=1;i<m->ztMessage.size();++i) {
|
||||||
std::vector<std::string> l(ZeroTier::Node::LocalClient::splitLine(m->ztMessage[i]));
|
std::vector<std::string> l(ZeroTier::Node::LocalClient::splitLine(m->ztMessage[i]));
|
||||||
// 200 listnetworks <nwid> <name> <status> <config age> <type> <dev> <ips>
|
// 200 listnetworks <nwid> <name> <status> <config age> <type> <dev> <ips>
|
||||||
if ((l.size() == 9)&&(l[2].length() == 16))
|
if ((l.size() == 9)&&(l[2].length() == 16))
|
||||||
byNwid[l[2]] = l;
|
newNetworks[l[2]] = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map< std::string,std::pair<int,NetworkWidget *> > existingByNwid;
|
if (newNetworks != networks) {
|
||||||
for(int r=0;r<ui->networkListWidget->count();++r) {
|
networks = newNetworks;
|
||||||
NetworkWidget *nw = (NetworkWidget *)ui->networkListWidget->itemWidget(ui->networkListWidget->item(r));
|
|
||||||
existingByNwid[nw->networkId()] = std::make_pair(r,nw);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(std::map< std::string,std::pair<int,NetworkWidget *> >::iterator i(existingByNwid.begin());i!=existingByNwid.end();++i) {
|
for (bool removed=true;removed;) {
|
||||||
if (byNwid.count(i->first)) {
|
removed = false;
|
||||||
std::vector<std::string> &l = byNwid[i->first];
|
for(int r=0;r<ui->networkListWidget->count();++r) {
|
||||||
i->second.second->setNetworkName(l[3]);
|
NetworkWidget *nw = (NetworkWidget *)ui->networkListWidget->itemWidget(ui->networkListWidget->item(r));
|
||||||
i->second.second->setStatus(l[4],l[5]);
|
if (!networks.count(nw->networkId())) {
|
||||||
i->second.second->setNetworkType(l[6]);
|
ui->networkListWidget->setVisible(false); // HACK to prevent an occasional crash here, discovered through hours of shotgun debugging... :P
|
||||||
i->second.second->setNetworkDeviceName(l[7]);
|
delete ui->networkListWidget->takeItem(r);
|
||||||
i->second.second->setIps(l[8]);
|
removed = true;
|
||||||
} else {
|
break;
|
||||||
delete ui->networkListWidget->takeItem(i->second.first);
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
ui->networkListWidget->setVisible(true);
|
||||||
|
std::set<std::string> alreadyDisplayed;
|
||||||
for(std::map< std::string,std::vector<std::string> >::iterator i(byNwid.begin());i!=byNwid.end();++i) {
|
for(int r=0;r<ui->networkListWidget->count();++r) {
|
||||||
if (!existingByNwid.count(i->first)) {
|
NetworkWidget *nw = (NetworkWidget *)ui->networkListWidget->itemWidget(ui->networkListWidget->item(r));
|
||||||
std::vector<std::string> &l = i->second;
|
if (networks.count(nw->networkId()) > 0) {
|
||||||
NetworkWidget *nw = new NetworkWidget((QWidget *)0,i->first);
|
alreadyDisplayed.insert(nw->networkId());
|
||||||
nw->setNetworkName(l[3]);
|
std::vector<std::string> &l = networks[nw->networkId()];
|
||||||
nw->setStatus(l[4],l[5]);
|
nw->setNetworkName(l[3]);
|
||||||
nw->setNetworkType(l[6]);
|
nw->setStatus(l[4],l[5]);
|
||||||
nw->setNetworkDeviceName(l[7]);
|
nw->setNetworkType(l[6]);
|
||||||
nw->setIps(l[8]);
|
nw->setNetworkDeviceName(l[7]);
|
||||||
QListWidgetItem *item = new QListWidgetItem();
|
nw->setIps(l[8]);
|
||||||
item->setSizeHint(nw->sizeHint());
|
}
|
||||||
ui->networkListWidget->addItem(item);
|
}
|
||||||
ui->networkListWidget->setItemWidget(item,nw);
|
for(std::map< std::string,std::vector<std::string> >::iterator nwdata(networks.begin());nwdata!=networks.end();++nwdata) {
|
||||||
|
if (alreadyDisplayed.count(nwdata->first) == 0) {
|
||||||
|
std::vector<std::string> &l = nwdata->second;
|
||||||
|
NetworkWidget *nw = new NetworkWidget((QWidget *)0,nwdata->first);
|
||||||
|
nw->setNetworkName(l[3]);
|
||||||
|
nw->setStatus(l[4],l[5]);
|
||||||
|
nw->setNetworkType(l[6]);
|
||||||
|
nw->setNetworkDeviceName(l[7]);
|
||||||
|
nw->setIps(l[8]);
|
||||||
|
QListWidgetItem *item = new QListWidgetItem();
|
||||||
|
item->setSizeHint(nw->sizeHint());
|
||||||
|
ui->networkListWidget->addItem(item);
|
||||||
|
ui->networkListWidget->setItemWidget(item,nw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (hdr[1] == "listpeers") {
|
} else if (hdr[1] == "listpeers") {
|
||||||
|
@ -196,7 +207,7 @@ void MainWindow::customEvent(QEvent *event)
|
||||||
|
|
||||||
if (this->myAddress.size())
|
if (this->myAddress.size())
|
||||||
ui->addressButton->setText(this->myAddress);
|
ui->addressButton->setText(this->myAddress);
|
||||||
else ui->addressButton->setText("??????????");
|
else ui->addressButton->setText(" ");
|
||||||
|
|
||||||
QString st(this->myStatus);
|
QString st(this->myStatus);
|
||||||
st += ", v";
|
st += ", v";
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "../node/Node.hpp"
|
#include "../node/Node.hpp"
|
||||||
#include "../node/Utils.hpp"
|
#include "../node/Utils.hpp"
|
||||||
|
|
||||||
|
@ -56,6 +60,7 @@ private:
|
||||||
QString myVersion;
|
QString myVersion;
|
||||||
unsigned int numPeers;
|
unsigned int numPeers;
|
||||||
unsigned int cyclesSinceResponseFromService;
|
unsigned int cyclesSinceResponseFromService;
|
||||||
|
std::map< std::string,std::vector<std::string> > networks;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -135,7 +135,7 @@ QPushButton:pressed {
|
||||||
s</string>
|
s</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>##########</string>
|
<string> </string>
|
||||||
</property>
|
</property>
|
||||||
<property name="flat">
|
<property name="flat">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|
|
@ -106,8 +106,8 @@ const std::string &NetworkWidget::networkId()
|
||||||
void NetworkWidget::on_leaveNetworkButton_clicked()
|
void NetworkWidget::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) {
|
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);
|
this->setEnabled(false);
|
||||||
|
zeroTierClient->send((QString("leave ") + networkIdStr.c_str()).toStdString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue