From 4d86b2f02fbf4d693136f3698984bcc10016b83d Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 20 Nov 2013 18:29:02 -0500 Subject: UI work... --- ZeroTierUI/mainwindow.cpp | 44 +++- ZeroTierUI/mainwindow.ui | 30 +-- ZeroTierUI/network.cpp | 13 +- ZeroTierUI/network.h | 2 +- ZeroTierUI/network.ui | 532 +++++++++++++++++++++++++++------------------- 5 files changed, 372 insertions(+), 249 deletions(-) diff --git a/ZeroTierUI/mainwindow.cpp b/ZeroTierUI/mainwindow.cpp index c618243a..40a2bf87 100644 --- a/ZeroTierUI/mainwindow.cpp +++ b/ZeroTierUI/mainwindow.cpp @@ -1,9 +1,11 @@ #include "mainwindow.h" #include "aboutwindow.h" +#include "network.h" #include "ui_mainwindow.h" #include #include +#include #include #include @@ -16,6 +18,7 @@ #include #include #include +#include // Globally visible ZeroTier::Node::LocalClient *zeroTierClient = (ZeroTier::Node::LocalClient *)0; @@ -127,11 +130,48 @@ 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(); + std::set networkIds; + // Add/update network widgets in scroll area for(unsigned long i=1;iztMessage.size();++i) { std::vector l(ZeroTier::Node::LocalClient::splitLine(m->ztMessage[i])); + // 200 listnetworks + if ((l.size() == 8)&&(l[2].length() == 16)) { + networkIds.insert(l[2]); + Network *nw = (Network *)0; + for(QObjectList::const_iterator n(ui->networksScrollAreaContentWidget->children().begin());n!=ui->networksScrollAreaContentWidget->children().end();++n) { + Network *n2 = (Network *)*n; + if ((n2)&&(n2->networkId() == l[2])) { + nw = n2; + break; + } + } + if (!nw) { + nw = new Network(ui->networksScrollAreaContentWidget,l[2]); + } + nw->setNetworkName(l[3]); + nw->setStatus(l[4]); + nw->setNetworkType(l[5]); + nw->setNetworkDeviceName(l[6]); + nw->setIps(l[7]); + } } + + // Remove widgets for networks no longer in the list + for(QObjectList::const_iterator n(ui->networksScrollAreaContentWidget->children().begin());n!=ui->networksScrollAreaContentWidget->children().end();++n) { + Network *n2 = (Network *)*n; + if ((n2)&&(!networkIds.count(n2->networkId()))) + n2->deleteLater(); + } + + // Update layout + QVBoxLayout *layout = new QVBoxLayout(); + layout->setSpacing(0); + layout->setMargin(0); + for(QObjectList::const_iterator n(ui->networksScrollAreaContentWidget->children().begin());n!=ui->networksScrollAreaContentWidget->children().end();++n) + layout->addWidget((QWidget *)*n); + delete ui->networksScrollAreaContentWidget->layout(); + ui->networksScrollAreaContentWidget->setLayout(layout); } else if (hdr[1] == "listpeers") { this->numPeers = 0; for(unsigned long i=1;iztMessage.size();++i) { @@ -212,6 +252,8 @@ void MainWindow::on_networkIdLineEdit_textChanged(const QString &text) default: break; } } + if (newText.size() > 16) + newText.truncate(16); ui->networkIdLineEdit->setText(newText); } diff --git a/ZeroTierUI/mainwindow.ui b/ZeroTierUI/mainwindow.ui index 45b8fe63..add117f7 100644 --- a/ZeroTierUI/mainwindow.ui +++ b/ZeroTierUI/mainwindow.ui @@ -45,6 +45,9 @@ + + QFrame::NoFrame + Qt::ScrollBarAlwaysOff @@ -59,27 +62,16 @@ 0 0 - 654 - 236 + 656 + 238 - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - + + + 0 + 0 + + diff --git a/ZeroTierUI/network.cpp b/ZeroTierUI/network.cpp index 1a6a631d..12d02516 100644 --- a/ZeroTierUI/network.cpp +++ b/ZeroTierUI/network.cpp @@ -29,14 +29,14 @@ void Network::setStatus(const std::string &status) ui->statusLabel->setText(QString(status.c_str())); } -void Network::setNetworkName(const std::string &status) +void Network::setNetworkName(const std::string &name) { - ui->nameLabel->setText(QString(status.c_str())); + ui->nameLabel->setText(QString(name.c_str())); } void Network::setNetworkType(const std::string &type) { - ui->networkTypeLabel->setText(QString(status.c_str())); + ui->networkTypeLabel->setText(QString(type.c_str())); if (type == "?") ui->networkTypeLabel->setToolTip("Waiting for configuration..."); else if (type == "public") @@ -69,13 +69,12 @@ void Network::setIps(const std::string &commaSeparatedList) ips = tmp; for(QStringList::iterator i(ips.begin());i!=ips.end();++i) { - if (ui->ipListWidget->findItems(*i).size() == 0) + if (ui->ipListWidget->findItems(*i,Qt::MatchCaseSensitive).size() == 0) ui->ipListWidget->addItem(*i); } - QList inList(ui->ipListWidget->items()); - for(QList::iterator i(inList.begin());i!=inList.end();++i) { - QListWidgetItem *item = *i; + for(int i=0;iipListWidget->count();++i) { + QListWidgetItem *item = ui->ipListWidget->item(i); if (!ips.contains(item->text())) ui->ipListWidget->removeItemWidget(item); } diff --git a/ZeroTierUI/network.h b/ZeroTierUI/network.h index 1048767e..a47915e1 100644 --- a/ZeroTierUI/network.h +++ b/ZeroTierUI/network.h @@ -14,7 +14,7 @@ class Network : public QWidget Q_OBJECT public: - explicit Network(QWidget *parent = 0,const std::string &nwid); + explicit Network(QWidget *parent = 0,const std::string &nwid = std::string()); virtual ~Network(); void setStatus(const std::string &status); diff --git a/ZeroTierUI/network.ui b/ZeroTierUI/network.ui index a9b288a3..c138e7e0 100644 --- a/ZeroTierUI/network.ui +++ b/ZeroTierUI/network.ui @@ -6,12 +6,12 @@ 0 0 - 618 - 108 + 580 + 267 - + 0 0 @@ -19,181 +19,253 @@ Network - - true + + - 6 + 0 - 6 + 0 - 0 + 3 - 6 + 0 - 0 + 3 - - - - QFormLayout::ExpandingFieldsGrow - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - Qt::AlignHCenter|Qt::AlignTop - - + + + QFrame::StyledPanel + + + QFrame::Raised + + + 6 - - 2 - - 0 + 6 - 0 + 6 - 0 + 6 - 0 + 6 - - - - Network ID: - - - Qt::PlainText - - - - - + + - + 0 0 - - - Courier - 13 - 75 - true - - - - Click to Copy to Clipboard - - - border: 0; + + + QFormLayout::ExpandingFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignHCenter|Qt::AlignTop + + + 6 + + + 2 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Network ID: + + + Qt::PlainText + + + + + + + + 0 + 0 + + + + + Courier + 13 + 75 + true + + + + Click to Copy to Clipboard + + + border: 0; padding: 0; margin: 0; text-align: left; - - - 0000000000000000 - - - true - - - - - - - Name: - - - Qt::PlainText - - - - - - - Status: - - - Qt::PlainText - - - - - - - - 0 - 0 - - - - - 75 - true - - - - OK - - - Qt::PlainText - - - - - - - Device: - - - Qt::PlainText - - - - - - - - 75 - true - - - - zt0 - - - Qt::PlainText - + + + 0000000000000000 + + + true + + + + + + + Name: + + + Qt::PlainText + + + + + + + + 75 + true + + + + (name) + + + Qt::PlainText + + + + + + + Type: + + + Qt::PlainText + + + + + + + + 75 + true + + + + public + + + Qt::PlainText + + + + + + + Status: + + + Qt::PlainText + + + + + + + + 0 + 0 + + + + + 75 + true + + + + OK + + + Qt::PlainText + + + + + + + Device: + + + Qt::PlainText + + + + + + + + 75 + true + + + + zt0 + + + Qt::PlainText + + + + - - + + - + 0 0 - - - 100 - 0 - - - + + + 6 + 0 @@ -207,107 +279,125 @@ text-align: left; 0 - - - Qt::Horizontal + + + + false + - - - 40 - 20 - + + IP Addresses - + + Qt::PlainText + + - + + + + 0 + 0 + + + + + 0 + 0 + + - 10 - true + Courier + 12 - - padding: 0; margin: 0; + + QAbstractItemView::NoEditTriggers - - Leave Network + + false - + + QAbstractItemView::SingleSelection + + + QListView::Fixed + + true + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 10 + false + + + + padding: 0.1em; margin:0; + + + Leave Network + + + + + + - - - - - 75 - true - - - - (name) - - - Qt::PlainText - - - - - - - Type: - - - Qt::PlainText - - - - - - - - 75 - true - - - - public - - - Qt::PlainText - - - - - - - - 0 - 0 - - - - - Courier - 10 - - - - false - - - true - - - -- cgit v1.2.3