diff --git a/ZeroTierUI/mainwindow.cpp b/ZeroTierUI/mainwindow.cpp index 40a2bf875..e427a6a16 100644 --- a/ZeroTierUI/mainwindow.cpp +++ b/ZeroTierUI/mainwindow.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -130,48 +131,48 @@ void MainWindow::customEvent(QEvent *event) if (hdr.size() >= 5) this->myVersion = hdr[4].c_str(); } else if (hdr[1] == "listnetworks") { - std::set networkIds; - - // Add/update network widgets in scroll area + std::map< std::string,std::vector > byNwid; 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]); - } + if ((l.size() == 8)&&(l[2].length() == 16)) + byNwid[l[2]] = l; + } + + std::map< std::string,std::pair > existingByNwid; + for(int r=0;rnetworkListWidget->count();++r) { + Network *nw = (Network *)ui->networkListWidget->itemWidget(ui->networkListWidget->item(r)); + existingByNwid[nw->networkId()] = std::make_pair(r,nw); + } + + for(std::map< std::string,std::pair >::iterator i(existingByNwid.begin());i!=existingByNwid.end();++i) { + if (byNwid.count(i->first)) { + std::vector &l = byNwid[i->first]; + i->second.second->setNetworkName(l[3]); + i->second.second->setStatus(l[4]); + i->second.second->setNetworkType(l[5]); + i->second.second->setNetworkDeviceName(l[6]); + i->second.second->setIps(l[7]); + } else { + delete ui->networkListWidget->takeItem(i->second.first); + } + } + + for(std::map< std::string,std::vector >::iterator i(byNwid.begin());i!=byNwid.end();++i) { + if (!existingByNwid.count(i->first)) { + std::vector &l = i->second; + Network *nw = new Network((QWidget *)0,i->first); nw->setNetworkName(l[3]); nw->setStatus(l[4]); nw->setNetworkType(l[5]); nw->setNetworkDeviceName(l[6]); nw->setIps(l[7]); + QListWidgetItem *item = new QListWidgetItem(); + item->setSizeHint(nw->sizeHint()); + ui->networkListWidget->addItem(item); + ui->networkListWidget->setItemWidget(item,nw); } } - - // 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) { diff --git a/ZeroTierUI/mainwindow.ui b/ZeroTierUI/mainwindow.ui index add117f78..025ac6cd4 100644 --- a/ZeroTierUI/mainwindow.ui +++ b/ZeroTierUI/mainwindow.ui @@ -35,44 +35,31 @@ 6 - - - - 0 - 0 - - - - - - - QFrame::NoFrame + + + Qt::NoFocus Qt::ScrollBarAlwaysOff - + + false + + + QAbstractItemView::NoEditTriggers + + true - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + + + QAbstractItemView::ScrollPerPixel - - - - 0 - 0 - 656 - 238 - - - - - 0 - 0 - - - diff --git a/ZeroTierUI/network.cpp b/ZeroTierUI/network.cpp index 12d025169..1631c816c 100644 --- a/ZeroTierUI/network.cpp +++ b/ZeroTierUI/network.cpp @@ -17,6 +17,10 @@ Network::Network(QWidget *parent,const std::string &nwid) : { ui->setupUi(this); ui->networkIdPushButton->setText(QString(nwid.c_str())); + QFontMetrics fm(ui->ipListWidget->font()); + int lineHeight = ui->ipListWidget->spacing() + fm.height(); + ui->ipListWidget->setMinimumHeight(lineHeight * 3); + ui->ipListWidget->setMaximumHeight(lineHeight * 3); } Network::~Network() diff --git a/ZeroTierUI/network.ui b/ZeroTierUI/network.ui index c138e7e0c..507bf3351 100644 --- a/ZeroTierUI/network.ui +++ b/ZeroTierUI/network.ui @@ -7,11 +7,11 @@ 0 0 580 - 267 + 253 - + 0 0 @@ -22,249 +22,308 @@ - + - 0 + 6 - 0 + 6 - 3 + 6 - 0 + 6 - 3 + 6 - - - QFrame::StyledPanel + + + + 0 + 0 + - - QFrame::Raised - - - + + + QFormLayout::ExpandingFieldsGrow + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + Qt::AlignHCenter|Qt::AlignTop + + 6 + + 2 + - 6 + 0 - 6 + 0 - 6 + 0 - 6 + 0 + + + + + Network ID: + + + Qt::PlainText + + + + + + + + 0 + 0 + + + + + 75 + true + + + + Click to Copy to Clipboard + + + border: 0; padding: 0; margin: 0; text-align: left; + + + 0000000000000000 + + + true + + + + + + + Name: + + + Qt::PlainText + + + + + + + + 75 + true + + + + ? + + + Qt::PlainText + + + + + + + Type: + + + Qt::PlainText + + + + + + + + 75 + true + + + + ? + + + Qt::PlainText + + + + + + + Status: + + + Qt::PlainText + + + + + + + + 0 + 0 + + + + + 75 + true + + + + ? + + + Qt::PlainText + + + + + + + Device: + + + Qt::PlainText + + + + + + + + 75 + true + + + + ? + + + Qt::PlainText + + + + + + + + + + + 0 + 0 + + + + + 3 + + + QLayout::SetNoConstraint + + + 0 + + + 0 + + + 0 + + + 0 - + + + + false + + + + IP Address Assignments + + + Qt::PlainText + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + Courier + 12 + + + + Qt::NoFocus + + + QAbstractItemView::NoEditTriggers + + + false + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::ScrollPerPixel + + + true + + + + + 0 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 - - - - - - - - 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 0 @@ -279,117 +338,32 @@ text-align: left; 0 - + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + 10 false + + padding: 0.1em; margin:0; + - IP Addresses + Leave Network - - Qt::PlainText - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - Courier - 12 - - - - QAbstractItemView::NoEditTriggers - - - 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 - - - -