summaryrefslogtreecommitdiff
path: root/ZeroTierUI
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2014-01-03 22:14:30 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2014-01-03 22:14:30 -0800
commit67a71868cb5f0bfed14cbaa2100fe03a3998f1c6 (patch)
treeffe2a93b44157e4ded52053dc5a83d784a18801e /ZeroTierUI
parent029f64495c8b931e38fcdea0dd496820e2610fb1 (diff)
downloadinfinitytier-67a71868cb5f0bfed14cbaa2100fe03a3998f1c6.tar.gz
infinitytier-67a71868cb5f0bfed14cbaa2100fe03a3998f1c6.zip
Install dialog in UI.
Diffstat (limited to 'ZeroTierUI')
-rw-r--r--ZeroTierUI/ZeroTierUI.pro9
-rw-r--r--ZeroTierUI/installdialog.cpp83
-rw-r--r--ZeroTierUI/installdialog.h33
-rw-r--r--ZeroTierUI/installdialog.ui131
-rw-r--r--ZeroTierUI/mainwindow.cpp27
-rw-r--r--ZeroTierUI/mainwindow.h7
6 files changed, 271 insertions, 19 deletions
diff --git a/ZeroTierUI/ZeroTierUI.pro b/ZeroTierUI/ZeroTierUI.pro
index 1b735553..6473fdb6 100644
--- a/ZeroTierUI/ZeroTierUI.pro
+++ b/ZeroTierUI/ZeroTierUI.pro
@@ -39,7 +39,8 @@ SOURCES += main.cpp\
../node/Utils.cpp \
../ext/lz4/lz4.c \
../ext/lz4/lz4hc.c \
- networkwidget.cpp
+ networkwidget.cpp \
+ installdialog.cpp
HEADERS += mainwindow.h \
aboutwindow.h \
@@ -88,11 +89,13 @@ HEADERS += mainwindow.h \
../node/UdpSocket.hpp \
../ext/lz4/lz4.h \
../ext/lz4/lz4hc.h \
- networkwidget.h
+ networkwidget.h \
+ installdialog.h
FORMS += mainwindow.ui \
aboutwindow.ui \
- networkwidget.ui
+ networkwidget.ui \
+ installdialog.ui
RESOURCES += \
resources.qrc
diff --git a/ZeroTierUI/installdialog.cpp b/ZeroTierUI/installdialog.cpp
new file mode 100644
index 00000000..ad575770
--- /dev/null
+++ b/ZeroTierUI/installdialog.cpp
@@ -0,0 +1,83 @@
+#include "installdialog.h"
+#include "mainwindow.h"
+#include "ui_installdialog.h"
+
+#include "../node/Defaults.hpp"
+
+#include <QMainWindow>
+#include <QMessageBox>
+#include <QByteArray>
+#include <QSslSocket>
+
+InstallDialog::InstallDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::InstallDialog),
+ nam(new QNetworkAccessManager(this))
+{
+ ui->setupUi(this);
+ QObject::connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(on_networkReply(QNetworkReply*)));
+
+ const char *nfoUrl = ZeroTier::ZT_DEFAULTS.updateLatestNfoURL.c_str();
+ if (!*nfoUrl) {
+ QMessageBox::critical(this,"Download Failed","Download failed: internal error: no update URL configured in build!",QMessageBox::Ok,QMessageBox::NoButton);
+ QApplication::exit(1);
+ return;
+ }
+
+ QNetworkReply *reply = nam->get(QNetworkRequest(QUrl(nfoUrl)));
+ QObject::connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(on_downloadProgress(qint64,qint64)));
+}
+
+InstallDialog::~InstallDialog()
+{
+ delete ui;
+}
+
+void InstallDialog::on_networkReply(QNetworkReply *reply)
+{
+ reply->deleteLater();
+
+ if (reply->error() != QNetworkReply::NoError) {
+ QMessageBox::critical(this,"Download Failed",QString("Download failed: ") + reply->errorString(),QMessageBox::Ok,QMessageBox::NoButton);
+ QApplication::exit(1);
+ return;
+ } else {
+ if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 200) {
+ QByteArray installerData(reply->readAll());
+ installerData.append((char)0);
+ printf("%s\n",installerData.data());
+ } else {
+ QMessageBox::critical(this,"Download Failed",QString("Download failed: HTTP status code ") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString(),QMessageBox::Ok,QMessageBox::NoButton);
+ QApplication::exit(1);
+ return;
+ }
+ }
+}
+
+void InstallDialog::on_InstallDialog_rejected()
+{
+ QApplication::exit();
+}
+
+//((QMainWindow *)this->parent())->setHidden(false);
+
+void InstallDialog::on_cancelButton_clicked()
+{
+ QApplication::exit();
+}
+
+void InstallDialog::on_downloadProgress(qint64 bytesReceived,qint64 bytesTotal)
+{
+ if (bytesTotal <= 0) {
+ ui->progressBar->setValue(0);
+ ui->progressBar->setMinimum(0);
+ ui->progressBar->setMaximum(0);
+ } else {
+ double pct = ((double)bytesReceived / (double)bytesTotal) * 100.0;
+ if (pct > 100.0)
+ pct = 100.0;
+ ui->progressBar->setMinimum(0);
+ ui->progressBar->setMaximum(100);
+ ui->progressBar->setValue((int)pct);
+ }
+}
diff --git a/ZeroTierUI/installdialog.h b/ZeroTierUI/installdialog.h
new file mode 100644
index 00000000..19c7a89a
--- /dev/null
+++ b/ZeroTierUI/installdialog.h
@@ -0,0 +1,33 @@
+#ifndef INSTALLDIALOG_H
+#define INSTALLDIALOG_H
+
+#include <QDialog>
+#include <QNetworkAccessManager>
+#include <QUrl>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+
+namespace Ui {
+class InstallDialog;
+}
+
+class InstallDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit InstallDialog(QWidget *parent = 0);
+ ~InstallDialog();
+
+private slots:
+ void on_networkReply(QNetworkReply *reply);
+ void on_InstallDialog_rejected();
+ void on_cancelButton_clicked();
+ void on_downloadProgress(qint64 bytesReceived,qint64 bytesTotal);
+
+private:
+ Ui::InstallDialog *ui;
+ QNetworkAccessManager *nam;
+};
+
+#endif // INSTALLDIALOG_H
diff --git a/ZeroTierUI/installdialog.ui b/ZeroTierUI/installdialog.ui
new file mode 100644
index 00000000..15a08027
--- /dev/null
+++ b/ZeroTierUI/installdialog.ui
@@ -0,0 +1,131 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>InstallDialog</class>
+ <widget class="QDialog" name="InstallDialog">
+ <property name="windowModality">
+ <enum>Qt::ApplicationModal</enum>
+ </property>
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>547</width>
+ <height>231</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Install ZeroTier One Service</string>
+ </property>
+ <property name="windowIcon">
+ <iconset resource="resources.qrc">
+ <normaloff>:/img/zt1icon.png</normaloff>:/img/zt1icon.png</iconset>
+ </property>
+ <property name="sizeGripEnabled">
+ <bool>true</bool>
+ </property>
+ <property name="modal">
+ <bool>true</bool>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <property name="leftMargin">
+ <number>6</number>
+ </property>
+ <property name="topMargin">
+ <number>6</number>
+ </property>
+ <property name="rightMargin">
+ <number>6</number>
+ </property>
+ <property name="bottomMargin">
+ <number>6</number>
+ </property>
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="font">
+ <font>
+ <pointsize>14</pointsize>
+ </font>
+ </property>
+ <property name="text">
+ <string>Since this is your first time running ZeroTier One on this computer, the virtual Ethernet service must be downloaded and installed.
+
+Please wait while the service downloads, then you will be prompted to enter an administrator password to install it.</string>
+ </property>
+ <property name="textFormat">
+ <enum>Qt::PlainText</enum>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ <property name="margin">
+ <number>10</number>
+ </property>
+ <property name="textInteractionFlags">
+ <set>Qt::NoTextInteraction</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="maximum">
+ <number>0</number>
+ </property>
+ <property name="value">
+ <number>0</number>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QWidget" name="widget" native="true">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
+ <number>0</number>
+ </property>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="cancelButton">
+ <property name="text">
+ <string>Cancel and Exit</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources>
+ <include location="resources.qrc"/>
+ </resources>
+ <connections/>
+</ui>
diff --git a/ZeroTierUI/mainwindow.cpp b/ZeroTierUI/mainwindow.cpp
index b4afcbbb..1c62d015 100644
--- a/ZeroTierUI/mainwindow.cpp
+++ b/ZeroTierUI/mainwindow.cpp
@@ -2,6 +2,7 @@
#include "aboutwindow.h"
#include "networkwidget.h"
#include "ui_mainwindow.h"
+#include "installdialog.h"
#include <string>
#include <map>
@@ -54,16 +55,14 @@ static void handleZTMessage(void *arg,unsigned long id,const char *line)
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
- nam(new QNetworkAccessManager(this))
+ pollServiceTimerId(0)
{
ui->setupUi(this);
- this->startTimer(1000); // poll service every second
+ this->pollServiceTimerId = this->startTimer(1000);
this->setEnabled(false); // gets enabled when updates are received
mainWindow = this;
this->cyclesSinceResponseFromService = 0;
- QObject::connect(nam,SIGNAL(finished(QNetworkReply*)),this,SLOT(on_networkReply(QNetworkReply*)));
-
if (ui->networkListWidget->verticalScrollBar())
ui->networkListWidget->verticalScrollBar()->setSingleStep(8);
@@ -84,11 +83,15 @@ void MainWindow::timerEvent(QTimerEvent *event)
{
event->accept();
+ if (this->isHidden())
+ return;
+
if (!zeroTierClient) {
std::string authToken;
if (!ZeroTier::Utils::readFile(ZeroTier::Node::LocalClient::authTokenDefaultUserPath().c_str(),authToken)) {
#ifdef __APPLE__
- if (QFile::exists("/Library/Application Support/ZeroTier/One/zerotier-one")) {
+ //if (QFile::exists("/Library/Application Support/ZeroTier/One/zerotier-one")) {
+ if (false) {
// Run the little AppleScript hack that asks for admin credentials and
// then installs the auth token file in the current user's home.
QString authHelperPath(QCoreApplication::applicationDirPath() + "/../Resources/helpers/mac/ZeroTier One (Authenticate).app/Contents/MacOS/applet");
@@ -105,11 +108,18 @@ void MainWindow::timerEvent(QTimerEvent *event)
}
QProcess::execute(authHelperPath,QStringList());
} else {
- // Download the latest version and install it
+ // If the service is not installed, download the installer and run it
+ // for the first time.
this->setEnabled(false);
+ InstallDialog *id = new InstallDialog(this);
+ id->setModal(true);
+ id->show();
+ this->setHidden(true);
+ return;
// Run the little AppleScript hack that asks for admin credentials and
// then installs the auth token file in the current user's home.
+ /*
QString installHelperPath(QCoreApplication::applicationDirPath() + "/../Resources/helpers/mac/ZeroTier One (Install).app/Contents/MacOS/applet");
if (!QFile::exists(installHelperPath)) {
QMessageBox::critical(this,"Unable to Locate Helper","Unable to locate install helper, cannot install service.",QMessageBox::Ok,QMessageBox::NoButton);
@@ -117,6 +127,7 @@ void MainWindow::timerEvent(QTimerEvent *event)
return;
}
QProcess::execute(installHelperPath,QStringList());
+ */
}
#endif
@@ -306,7 +317,3 @@ void MainWindow::on_addressButton_clicked()
{
QApplication::clipboard()->setText(this->myAddress);
}
-
-void MainWindow::on_networkReply(QNetworkReply *reply)
-{
-}
diff --git a/ZeroTierUI/mainwindow.h b/ZeroTierUI/mainwindow.h
index d3ec15d8..b34f4dce 100644
--- a/ZeroTierUI/mainwindow.h
+++ b/ZeroTierUI/mainwindow.h
@@ -4,10 +4,6 @@
#include <QMainWindow>
#include <QEvent>
#include <QString>
-#include <QNetworkAccessManager>
-#include <QUrl>
-#include <QNetworkRequest>
-#include <QNetworkReply>
#include <map>
#include <vector>
@@ -55,15 +51,14 @@ private slots:
void on_actionAbout_triggered();
void on_networkIdLineEdit_textChanged(const QString &text);
void on_addressButton_clicked();
- void on_networkReply(QNetworkReply *reply);
private:
Ui::MainWindow *ui;
- QNetworkAccessManager *nam;
QString myAddress;
QString myStatus;
QString myVersion;
+ int pollServiceTimerId;
unsigned int numPeers;
unsigned int cyclesSinceResponseFromService;
std::map< std::string,std::vector<std::string> > networks;