You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
182 lines
5.5 KiB
182 lines
5.5 KiB
|
12 years ago
|
/*
|
||
|
11 years ago
|
* ZeroTier One - Network Virtualization Everywhere
|
||
|
|
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||
|
12 years ago
|
*
|
||
|
|
* This program is free software: you can redistribute it and/or modify
|
||
|
|
* it under the terms of the GNU General Public License as published by
|
||
|
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
|
* (at your option) any later version.
|
||
|
|
*
|
||
|
|
* This program is distributed in the hope that it will be useful,
|
||
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
* GNU General Public License for more details.
|
||
|
|
*
|
||
|
|
* You should have received a copy of the GNU General Public License
|
||
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
*
|
||
|
|
* --
|
||
|
|
*
|
||
|
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||
|
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||
|
|
*
|
||
|
|
* If you would like to embed ZeroTier into a commercial application or
|
||
|
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||
|
|
* LLC. Start here: http://www.zerotier.com/
|
||
|
|
*/
|
||
|
|
|
||
|
12 years ago
|
#include "networkwidget.h"
|
||
|
13 years ago
|
#include "mainwindow.h"
|
||
|
12 years ago
|
#include "ui_networkwidget.h"
|
||
|
12 years ago
|
#include "onetimedialog.h"
|
||
|
|
#include "main.h"
|
||
|
13 years ago
|
|
||
|
13 years ago
|
#include <QClipboard>
|
||
|
13 years ago
|
#include <QString>
|
||
|
|
#include <QStringList>
|
||
|
|
#include <QCoreApplication>
|
||
|
|
#include <QProcess>
|
||
|
|
#include <QList>
|
||
|
|
#include <QMessageBox>
|
||
|
12 years ago
|
#include <QFont>
|
||
|
|
|
||
|
|
#include "../node/Constants.hpp"
|
||
|
13 years ago
|
|
||
|
12 years ago
|
NetworkWidget::NetworkWidget(QWidget *parent,const std::string &nwid) :
|
||
|
13 years ago
|
QWidget(parent),
|
||
|
12 years ago
|
ui(new Ui::NetworkWidget),
|
||
|
12 years ago
|
networkIdStr(nwid),
|
||
|
|
publicWarningShown(false)
|
||
|
13 years ago
|
{
|
||
|
|
ui->setupUi(this);
|
||
|
12 years ago
|
ui->networkIdButton->setText(QString(nwid.c_str()));
|
||
|
12 years ago
|
|
||
|
13 years ago
|
QFontMetrics fm(ui->ipListWidget->font());
|
||
|
|
int lineHeight = ui->ipListWidget->spacing() + fm.height();
|
||
|
12 years ago
|
ui->ipListWidget->setMinimumHeight(lineHeight * 6);
|
||
|
|
ui->ipListWidget->setMaximumHeight(lineHeight * 6);
|
||
|
12 years ago
|
|
||
|
12 years ago
|
#ifdef __APPLE__
|
||
|
12 years ago
|
QWidgetList widgets = this->findChildren<QWidget*>();
|
||
|
|
foreach(QWidget* widget, widgets)
|
||
|
|
widget->setAttribute(Qt::WA_MacShowFocusRect,false);
|
||
|
12 years ago
|
#endif
|
||
|
|
|
||
|
|
#ifdef __WINDOWS__
|
||
|
|
QWidgetList widgets = this->findChildren<QWidget*>();
|
||
|
|
foreach(QWidget *widget, widgets) {
|
||
|
|
QFont font(widget->font());
|
||
|
|
font.setPointSizeF(font.pointSizeF() * 0.75);
|
||
|
|
widget->setFont(font);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
12 years ago
|
NetworkWidget::~NetworkWidget()
|
||
|
13 years ago
|
{
|
||
|
|
delete ui;
|
||
|
|
}
|
||
|
13 years ago
|
|
||
|
12 years ago
|
void NetworkWidget::setStatus(const std::string &status,const std::string &age)
|
||
|
13 years ago
|
{
|
||
|
|
ui->statusLabel->setText(QString(status.c_str()));
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::setNetworkName(const std::string &name)
|
||
|
13 years ago
|
{
|
||
|
12 years ago
|
if (name == "?") {
|
||
|
12 years ago
|
ui->nameLabel->setText("... waiting ...");
|
||
|
|
ui->nameLabel->setEnabled(false);
|
||
|
12 years ago
|
} else {
|
||
|
|
ui->nameLabel->setText(QString(name.c_str()));
|
||
|
12 years ago
|
ui->nameLabel->setEnabled(true);
|
||
|
12 years ago
|
}
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::setNetworkType(const std::string &type)
|
||
|
13 years ago
|
{
|
||
|
13 years ago
|
ui->networkTypeLabel->setText(QString(type.c_str()));
|
||
|
13 years ago
|
if (type == "?")
|
||
|
12 years ago
|
ui->networkTypeLabel->setStatusTip("Waiting for configuration...");
|
||
|
12 years ago
|
else if (type == "public") {
|
||
|
|
if ((!publicWarningShown)&&(!settings->value("shown_publicWarning",false).toBool())) {
|
||
|
|
publicWarningShown = true;
|
||
|
|
OneTimeDialog *d = new OneTimeDialog(mainWindow,"shown_publicWarning","Security Notice","Security Notice:"ZT_EOL_S""ZT_EOL_S"You have joined a public network. Anyone can join these. We recommend making sure that your system's automatic software updates are enabled and turning off any shared network services that you do not want people to access.");
|
||
|
|
d->setModal(false);
|
||
|
|
d->show();
|
||
|
|
}
|
||
|
12 years ago
|
ui->networkTypeLabel->setStatusTip("This network can be joined by anyone in the world.");
|
||
|
12 years ago
|
} else if (type == "private")
|
||
|
12 years ago
|
ui->networkTypeLabel->setStatusTip("This network is private; only authorized peers can join.");
|
||
|
|
else ui->networkTypeLabel->setStatusTip("Unknown network type.");
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::setNetworkDeviceName(const std::string &dev)
|
||
|
13 years ago
|
{
|
||
|
|
ui->deviceLabel->setText(QString(dev.c_str()));
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::setIps(const std::string &commaSeparatedList)
|
||
|
13 years ago
|
{
|
||
|
|
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) {
|
||
|
13 years ago
|
if (ui->ipListWidget->findItems(*i,Qt::MatchCaseSensitive).size() == 0)
|
||
|
13 years ago
|
ui->ipListWidget->addItem(*i);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
for(int i=0;i<ui->ipListWidget->count();++i) {
|
||
|
|
QListWidgetItem *item = ui->ipListWidget->item(i);
|
||
|
13 years ago
|
if (!ips.contains(item->text()))
|
||
|
|
ui->ipListWidget->removeItemWidget(item);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::setMAC(const std::string &mac)
|
||
|
|
{
|
||
|
|
ui->macLabel->setText(QString(mac.c_str()));
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
const std::string &NetworkWidget::networkId()
|
||
|
13 years ago
|
{
|
||
|
|
return networkIdStr;
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::on_leaveNetworkButton_clicked()
|
||
|
13 years ago
|
{
|
||
|
13 years ago
|
if (QMessageBox::question(this,"Leave Network?",QString("Are you sure you want to leave network '") + networkIdStr.c_str() + "'?",QMessageBox::No,QMessageBox::Yes) == QMessageBox::Yes) {
|
||
|
|
this->setEnabled(false);
|
||
|
12 years ago
|
zeroTierClient->send((QString("leave ") + networkIdStr.c_str()).toStdString());
|
||
|
13 years ago
|
}
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
12 years ago
|
void NetworkWidget::on_networkIdButton_clicked()
|
||
|
13 years ago
|
{
|
||
|
12 years ago
|
QApplication::clipboard()->setText(ui->networkIdButton->text());
|
||
|
13 years ago
|
}
|
||
|
12 years ago
|
|
||
|
12 years ago
|
void NetworkWidget::on_ipListWidget_itemActivated(QListWidgetItem *item)
|
||
|
12 years ago
|
{
|
||
|
12 years ago
|
if (item)
|
||
|
|
QApplication::clipboard()->setText(item->text());
|
||
|
|
}
|
||
|
|
|
||
|
|
void NetworkWidget::on_ipListWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
|
||
|
|
{
|
||
|
|
if (current)
|
||
|
|
QApplication::clipboard()->setText(current->text());
|
||
|
12 years ago
|
}
|