From b65f7f78951450998bc4a85f60ce1350c2ed2a12 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Fri, 24 Jan 2014 23:15:14 -0800 Subject: [PATCH] Qt GUI now builds and runs on Windows. On Windows it can (via its manifest) automatically request admin rights on launch, which plugs it nicely into Windows' admin rights system without requiring file copies and such. --- ZeroTierUI/ZeroTierUI.pro | 174 +++++++++++++++++++------------------- ZeroTierUI/aboutwindow.ui | 2 +- ZeroTierUI/main.cpp | 2 + ZeroTierUI/mainwindow.cpp | 43 ++++++---- ZeroTierUI/mainwindow.ui | 39 +-------- ZeroTierUI/stylesheet.css | 5 ++ 6 files changed, 123 insertions(+), 142 deletions(-) diff --git a/ZeroTierUI/ZeroTierUI.pro b/ZeroTierUI/ZeroTierUI.pro index dd31f27fb..c43876ee8 100644 --- a/ZeroTierUI/ZeroTierUI.pro +++ b/ZeroTierUI/ZeroTierUI.pro @@ -3,105 +3,107 @@ TARGET = "ZeroTier One" TEMPLATE = app win32:RC_FILE = ZeroTierUI.rc +win32:LIBS += winhttp.lib Iphlpapi.lib ws2_32.lib advapi32.lib Shell32.lib Rpcrt4.lib +win32:QMAKE_LFLAGS += /MANIFESTUAC:\"level=\'requireAdministrator\' uiAccess=\'false\'\" mac:ICON = zt1icon.icns mac:QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6 mac:QMAKE_INFO_PLIST = Info.plist mac:LIBS += -framework Cocoa -SOURCES += main.cpp\ - mainwindow.cpp \ - aboutwindow.cpp \ - ../node/C25519.cpp \ - ../node/CertificateOfMembership.cpp \ - ../node/Defaults.cpp \ - ../node/Demarc.cpp \ - ../node/EthernetTap.cpp \ - ../node/HttpClient.cpp \ - ../node/Identity.cpp \ - ../node/InetAddress.cpp \ - ../node/Logger.cpp \ - ../node/Multicaster.cpp \ - ../node/Network.cpp \ - ../node/NetworkConfig.cpp \ - ../node/Node.cpp \ - ../node/NodeConfig.cpp \ - ../node/Packet.cpp \ - ../node/PacketDecoder.cpp \ - ../node/Peer.cpp \ - ../node/Poly1305.cpp \ - ../node/Salsa20.cpp \ - ../node/Service.cpp \ - ../node/SHA512.cpp \ - ../node/SoftwareUpdater.cpp \ - ../node/Switch.cpp \ - ../node/SysEnv.cpp \ - ../node/Topology.cpp \ - ../node/UdpSocket.cpp \ - ../node/Utils.cpp \ - ../ext/lz4/lz4.c \ - ../ext/lz4/lz4hc.c \ - networkwidget.cpp \ - installdialog.cpp \ +SOURCES += main.cpp \ + mainwindow.cpp \ + aboutwindow.cpp \ + ../node/C25519.cpp \ + ../node/CertificateOfMembership.cpp \ + ../node/Defaults.cpp \ + ../node/Demarc.cpp \ + ../node/EthernetTap.cpp \ + ../node/HttpClient.cpp \ + ../node/Identity.cpp \ + ../node/InetAddress.cpp \ + ../node/Logger.cpp \ + ../node/Multicaster.cpp \ + ../node/Network.cpp \ + ../node/NetworkConfig.cpp \ + ../node/Node.cpp \ + ../node/NodeConfig.cpp \ + ../node/Packet.cpp \ + ../node/PacketDecoder.cpp \ + ../node/Peer.cpp \ + ../node/Poly1305.cpp \ + ../node/Salsa20.cpp \ + ../node/Service.cpp \ + ../node/SHA512.cpp \ + ../node/SoftwareUpdater.cpp \ + ../node/Switch.cpp \ + ../node/SysEnv.cpp \ + ../node/Topology.cpp \ + ../node/UdpSocket.cpp \ + ../node/Utils.cpp \ + ../ext/lz4/lz4.c \ + ../ext/lz4/lz4hc.c \ + networkwidget.cpp \ + installdialog.cpp \ licensedialog.cpp HEADERS += mainwindow.h \ - aboutwindow.h \ - ../node/Node.hpp \ - ../node/Utils.hpp \ - ../node/Defaults.hpp \ - ../node/Address.hpp \ - ../node/Array.hpp \ - ../node/AtomicCounter.hpp \ - ../node/BandwidthAccount.hpp \ - ../node/Buffer.hpp \ - ../node/C25519.hpp \ - ../node/CertificateOfMembership.hpp \ - ../node/CMWC4096.hpp \ - ../node/Condition.hpp \ - ../node/Constants.hpp \ - ../node/Demarc.hpp \ - ../node/Dictionary.hpp \ - ../node/EthernetTap.hpp \ - ../node/HttpClient.hpp \ - ../node/Identity.hpp \ - ../node/InetAddress.hpp \ - ../node/Logger.hpp \ - ../node/MAC.hpp \ - ../node/Multicaster.hpp \ - ../node/MulticastGroup.hpp \ - ../node/Mutex.hpp \ - ../node/Network.hpp \ - ../node/NetworkConfig.hpp \ - ../node/NodeConfig.hpp \ - ../node/NonCopyable.hpp \ - ../node/Packet.hpp \ - ../node/PacketDecoder.hpp \ - ../node/Peer.hpp \ - ../node/Poly1305.hpp \ - ../node/RuntimeEnvironment.hpp \ - ../node/Salsa20.hpp \ - ../node/Service.hpp \ - ../node/SHA512.hpp \ - ../node/SharedPtr.hpp \ - ../node/SoftwareUpdater.hpp \ - ../node/Switch.hpp \ - ../node/SysEnv.hpp \ - ../node/Thread.hpp \ - ../node/Topology.hpp \ - ../node/UdpSocket.hpp \ - ../ext/lz4/lz4.h \ - ../ext/lz4/lz4hc.h \ - networkwidget.h \ - installdialog.h \ - mac_doprivileged.h \ + aboutwindow.h \ + ../node/Node.hpp \ + ../node/Utils.hpp \ + ../node/Defaults.hpp \ + ../node/Address.hpp \ + ../node/Array.hpp \ + ../node/AtomicCounter.hpp \ + ../node/BandwidthAccount.hpp \ + ../node/Buffer.hpp \ + ../node/C25519.hpp \ + ../node/CertificateOfMembership.hpp \ + ../node/CMWC4096.hpp \ + ../node/Condition.hpp \ + ../node/Constants.hpp \ + ../node/Demarc.hpp \ + ../node/Dictionary.hpp \ + ../node/EthernetTap.hpp \ + ../node/HttpClient.hpp \ + ../node/Identity.hpp \ + ../node/InetAddress.hpp \ + ../node/Logger.hpp \ + ../node/MAC.hpp \ + ../node/Multicaster.hpp \ + ../node/MulticastGroup.hpp \ + ../node/Mutex.hpp \ + ../node/Network.hpp \ + ../node/NetworkConfig.hpp \ + ../node/NodeConfig.hpp \ + ../node/NonCopyable.hpp \ + ../node/Packet.hpp \ + ../node/PacketDecoder.hpp \ + ../node/Peer.hpp \ + ../node/Poly1305.hpp \ + ../node/RuntimeEnvironment.hpp \ + ../node/Salsa20.hpp \ + ../node/Service.hpp \ + ../node/SHA512.hpp \ + ../node/SharedPtr.hpp \ + ../node/SoftwareUpdater.hpp \ + ../node/Switch.hpp \ + ../node/SysEnv.hpp \ + ../node/Thread.hpp \ + ../node/Topology.hpp \ + ../node/UdpSocket.hpp \ + ../ext/lz4/lz4.h \ + ../ext/lz4/lz4hc.h \ + networkwidget.h \ + installdialog.h \ + mac_doprivileged.h \ licensedialog.h \ main.h FORMS += mainwindow.ui \ - aboutwindow.ui \ - networkwidget.ui \ - installdialog.ui \ + aboutwindow.ui \ + networkwidget.ui \ + installdialog.ui \ licensedialog.ui RESOURCES += \ diff --git a/ZeroTierUI/aboutwindow.ui b/ZeroTierUI/aboutwindow.ui index e32dfca34..568082afb 100644 --- a/ZeroTierUI/aboutwindow.ui +++ b/ZeroTierUI/aboutwindow.ui @@ -134,7 +134,7 @@ QFrame::StyledPanel - QFrame::Raised + QFrame::Sunken diff --git a/ZeroTierUI/main.cpp b/ZeroTierUI/main.cpp index 3255ec9fa..5814849c7 100644 --- a/ZeroTierUI/main.cpp +++ b/ZeroTierUI/main.cpp @@ -59,6 +59,8 @@ int main(int argc, char *argv[]) #ifdef __APPLE__ { + // Put QSettings here because this is one of the writable directories allowed + // in Apple's app store sandbox specs. We might end up in app store someday. QString zt1AppSupport(QDir::homePath() + "/Library/Application Support/ZeroTier/One"); QDir::root().mkpath(zt1AppSupport); settings = new QSettings(zt1AppSupport + "/ui.ini",QSettings::IniFormat); diff --git a/ZeroTierUI/mainwindow.cpp b/ZeroTierUI/mainwindow.cpp index 07df1964e..3e4e96a05 100644 --- a/ZeroTierUI/mainwindow.cpp +++ b/ZeroTierUI/mainwindow.cpp @@ -99,13 +99,19 @@ MainWindow::MainWindow(QWidget *parent) : ui->setupUi(this); if (ui->networkListWidget->verticalScrollBar()) ui->networkListWidget->verticalScrollBar()->setSingleStep(8); + +#ifdef __APPLE__ QWidgetList widgets = this->findChildren(); foreach(QWidget *widget, widgets) widget->setAttribute(Qt::WA_MacShowFocusRect,false); - ui->noNetworksLabel->setText("Connecting to Service..."); // changed when result is received +#endif + + ui->noNetworksLabel->setVisible(true); + ui->noNetworksLabel->setText("Connecting to Service..."); + ui->bottomContainerWidget->setVisible(false); + ui->networkListWidget->setVisible(false); this->pollServiceTimerId = this->startTimer(1000); - this->setEnabled(false); // gets enabled when updates are received this->cyclesSinceResponseFromService = 0; } @@ -173,19 +179,25 @@ void MainWindow::timerEvent(QTimerEvent *event) #endif if (!ZeroTier::Utils::readFile(ZeroTier::Node::LocalClient::authTokenDefaultUserPath().c_str(),authToken)) { - QMessageBox::critical(this,"Cannot Authorize","Unable to authorize this user to administrate ZeroTier One. (Did you enter your password correctly?)",QMessageBox::Ok,QMessageBox::NoButton); - QApplication::exit(1); - return; + if (!ZeroTier::Utils::readFile(ZeroTier::Node::LocalClient::authTokenDefaultSystemPath().c_str(),authToken)) { + QMessageBox::critical(this,"Cannot Authorize","Unable to authorize this user to administrate ZeroTier One. (Did you enter your password correctly?)",QMessageBox::Ok,QMessageBox::NoButton); + QApplication::exit(1); + return; + } } } zeroTierClient = new ZeroTier::Node::LocalClient(authToken.c_str(),0,&handleZTMessage,this); } - // TODO: do something more user-friendly here... or maybe try to restart - // the service? - if (++this->cyclesSinceResponseFromService == 4) - QMessageBox::critical(this,"No Response from Service","The ZeroTier One service does not appear to be running.",QMessageBox::Ok,QMessageBox::NoButton); + if (++this->cyclesSinceResponseFromService >= 4) { + if (this->cyclesSinceResponseFromService == 4) + QMessageBox::warning(this,"Service Not Running","Can't Connect to the ZeroTier One service. Is it running?",QMessageBox::Ok); + ui->noNetworksLabel->setVisible(true); + ui->noNetworksLabel->setText("Connecting to Service..."); + ui->bottomContainerWidget->setVisible(false); + ui->networkListWidget->setVisible(false); + } zeroTierClient->send("info"); zeroTierClient->send("listnetworks"); @@ -281,6 +293,11 @@ void MainWindow::customEvent(QEvent *event) ui->noNetworksLabel->setVisible(true); } else ui->noNetworksLabel->setVisible(false); + if (!ui->bottomContainerWidget->isVisible()) + ui->bottomContainerWidget->setVisible(true); + if (!ui->networkListWidget->isVisible()) + ui->networkListWidget->setVisible(true); + if (this->myAddress.size()) ui->addressButton->setText(this->myAddress); else ui->addressButton->setText(" "); @@ -292,14 +309,6 @@ void MainWindow::customEvent(QEvent *event) st += QString::number(this->numPeers); st += " direct links to peers"; ui->statusLabel->setText(st); - - if (this->myStatus == "ONLINE") { - if (!this->isEnabled()) - this->setEnabled(true); - } else { - if (this->isEnabled()) - this->setEnabled(false); - } } void MainWindow::on_joinNetworkButton_clicked() diff --git a/ZeroTierUI/mainwindow.ui b/ZeroTierUI/mainwindow.ui index ad71f0341..0f686b28b 100644 --- a/ZeroTierUI/mainwindow.ui +++ b/ZeroTierUI/mainwindow.ui @@ -36,43 +36,6 @@ - - - - - - - 0 - 0 - 0 - - - - - - - - - 0 - 0 - 0 - - - - - - - - - 127 - 127 - 127 - - - - - - 16 @@ -267,7 +230,7 @@ 0 0 668 - 22 + 18 diff --git a/ZeroTierUI/stylesheet.css b/ZeroTierUI/stylesheet.css index 706da1fad..3a5795c5d 100644 --- a/ZeroTierUI/stylesheet.css +++ b/ZeroTierUI/stylesheet.css @@ -80,6 +80,11 @@ QLabel.networkName { padding: 0; } +#noNetworksLabel { + background: transparent; + color: #ffffff; +} + #networkListWidget { background: palette(dark); margin: 0 0 2px 0;