Ver Fonte

UI work...

Adam Ierymenko há 11 anos atrás
pai
commit
bf02c6661a
5 ficheiros alterados com 59 adições e 12 exclusões
  1. 1 0
      Makefile.linux
  2. 1 0
      Makefile.mac
  3. 14 9
      ZeroTierUI/ZeroTierUI.pro
  4. 38 2
      ZeroTierUI/mainwindow.cpp
  5. 5 1
      ZeroTierUI/mainwindow.h

+ 1 - 0
Makefile.linux

@@ -26,6 +26,7 @@ all:	one
 one:	$(OBJS)
 one:	$(OBJS)
 	$(CXX) $(CXXFLAGS) -o zerotier-one main.cpp $(OBJS) $(LIBS)
 	$(CXX) $(CXXFLAGS) -o zerotier-one main.cpp $(OBJS) $(LIBS)
 	$(STRIP) zerotier-one
 	$(STRIP) zerotier-one
+	ln -sf zerotier-one zerotier-cli
 
 
 selftest:	$(OBJS)
 selftest:	$(OBJS)
 	$(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.cpp $(OBJS) $(LIBS)
 	$(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.cpp $(OBJS) $(LIBS)

+ 1 - 0
Makefile.mac

@@ -22,6 +22,7 @@ all: one
 one:	$(OBJS)
 one:	$(OBJS)
 	$(CXX) $(CXXFLAGS) -o zerotier-one main.cpp $(OBJS) $(LIBS)
 	$(CXX) $(CXXFLAGS) -o zerotier-one main.cpp $(OBJS) $(LIBS)
 	$(STRIP) zerotier-one
 	$(STRIP) zerotier-one
+	ln -sf zerotier-one zerotier-cli
 
 
 selftest: $(OBJS)
 selftest: $(OBJS)
 	$(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.cpp $(OBJS) $(LIBS)
 	$(CXX) $(CXXFLAGS) -o zerotier-selftest selftest.cpp $(OBJS) $(LIBS)

+ 14 - 9
ZeroTierUI/ZeroTierUI.pro

@@ -11,20 +11,25 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 TARGET = ZeroTierUI
 TARGET = ZeroTierUI
 TEMPLATE = app
 TEMPLATE = app
 
 
+# ZeroTier One must be built before building this, since it links in the
+# client code and some stuff from Utils to talk to the running service.
+LIBS += ../node/*.o
 
 
 SOURCES += main.cpp\
 SOURCES += main.cpp\
-        mainwindow.cpp \
-    network.cpp \
-    aboutwindow.cpp
+				mainwindow.cpp \
+		network.cpp \
+		aboutwindow.cpp
 
 
 HEADERS  += mainwindow.h \
 HEADERS  += mainwindow.h \
-    network.h \
-    aboutwindow.h \
-    ../node/Node.hpp
+		network.h \
+		aboutwindow.h \
+		../node/Node.hpp \
+		../node/Utils.hpp \
+    ../node/Defaults.hpp
 
 
 FORMS    += mainwindow.ui \
 FORMS    += mainwindow.ui \
-    network.ui \
-    aboutwindow.ui
+		network.ui \
+		aboutwindow.ui
 
 
 RESOURCES += \
 RESOURCES += \
-    resources.qrc
+		resources.qrc

+ 38 - 2
ZeroTierUI/mainwindow.cpp

@@ -5,9 +5,15 @@
 #include <string>
 #include <string>
 #include <map>
 #include <map>
 #include <vector>
 #include <vector>
+#include <stdexcept>
 
 
 #include <QClipboard>
 #include <QClipboard>
 #include <QMutex>
 #include <QMutex>
+#include <QCoreApplication>
+#include <QDir>
+#include <QFile>
+#include <QMessageBox>
+#include <QDebug>
 
 
 static std::map< unsigned long,std::vector<std::string> > ztReplies;
 static std::map< unsigned long,std::vector<std::string> > ztReplies;
 static QMutex ztReplies_m;
 static QMutex ztReplies_m;
@@ -17,7 +23,7 @@ static void handleZTMessage(void *arg,unsigned long id,const char *line)
 	if (*line) {
 	if (*line) {
 		ztReplies[id].push_back(std::string(line));
 		ztReplies[id].push_back(std::string(line));
 		ztReplies_m.unlock();
 		ztReplies_m.unlock();
-	} else {
+	} else { // empty lines conclude transmissions
 		std::vector<std::string> resp(ztReplies[id]);
 		std::vector<std::string> resp(ztReplies[id]);
 		ztReplies.erase(id);
 		ztReplies.erase(id);
 		ztReplies_m.unlock();
 		ztReplies_m.unlock();
@@ -25,13 +31,15 @@ static void handleZTMessage(void *arg,unsigned long id,const char *line)
 }
 }
 
 
 // Globally visible
 // Globally visible
-ZeroTier::Node::LocalClient *zeroTierClient = (ZeroTier::Node::LocalClient *)0;
+ZeroTier::Node::LocalClient *volatile zeroTierClient = (ZeroTier::Node::LocalClient *)0;
 
 
 MainWindow::MainWindow(QWidget *parent) :
 MainWindow::MainWindow(QWidget *parent) :
 	QMainWindow(parent),
 	QMainWindow(parent),
 	ui(new Ui::MainWindow)
 	ui(new Ui::MainWindow)
 {
 {
 	ui->setupUi(this);
 	ui->setupUi(this);
+	this->startTimer(500);
+	this->setEnabled(false); // first timer actually enables controls
 }
 }
 
 
 MainWindow::~MainWindow()
 MainWindow::~MainWindow()
@@ -39,6 +47,34 @@ MainWindow::~MainWindow()
 	delete ui;
 	delete ui;
 }
 }
 
 
+void MainWindow::timerEvent(QTimerEvent *event)
+{
+	QMainWindow::timerEvent(event);
+
+	if (!this->isEnabled())
+		this->setEnabled(true);
+
+	if (!zeroTierClient) {
+		std::string dotAuthFile((QDir::homePath() + QDir::separator() + ".zeroTierOneAuthToken").toStdString());
+		std::string authToken;
+		if (!ZeroTier::Utils::readFile(dotAuthFile.c_str(),authToken)) {
+#ifdef __APPLE__
+			QString authHelperPath(QCoreApplication::applicationDirPath() + "/../Applications/ZeroTier One (Authenticate).app");
+			if (!QFile::exists(authHelperPath)) {
+				// Allow this to also work from the source tree if it's run from there.
+				// This is for debugging purposes but shouldn't harm the live release
+				// in any way.
+				//authHelperPath = QCoreApplication::applicationFilePath() + "/../ZeroTierUI/helpers/mac/ZeroTier One (Authenticate).app";
+				if (!QFile::exists(authHelperPath)) {
+					QMessageBox::critical(this,"Unable to Locate Helper","Unable to locate authorization helper, cannot obtain authentication token.",QMessageBox::Ok,QMessageBox::NoButton);
+					QApplication::exit(1);
+				}
+			}
+#endif
+		}
+	}
+}
+
 void MainWindow::on_joinNetworkButton_clicked()
 void MainWindow::on_joinNetworkButton_clicked()
 {
 {
 }
 }

+ 5 - 1
ZeroTierUI/mainwindow.h

@@ -4,6 +4,7 @@
 #include <QMainWindow>
 #include <QMainWindow>
 
 
 #include "../node/Node.hpp"
 #include "../node/Node.hpp"
+#include "../node/Utils.hpp"
 
 
 namespace Ui {
 namespace Ui {
 class MainWindow;
 class MainWindow;
@@ -11,7 +12,7 @@ class MainWindow;
 
 
 // Globally visible instance of local client for communicating with ZT1
 // Globally visible instance of local client for communicating with ZT1
 // Can be null if not connected, or will point to current
 // Can be null if not connected, or will point to current
-extern ZeroTier::Node::LocalClient *zeroTierClient;
+extern ZeroTier::Node::LocalClient *volatile zeroTierClient;
 
 
 class MainWindow : public QMainWindow
 class MainWindow : public QMainWindow
 {
 {
@@ -21,6 +22,9 @@ public:
 	explicit MainWindow(QWidget *parent = 0);
 	explicit MainWindow(QWidget *parent = 0);
 	~MainWindow();
 	~MainWindow();
 
 
+protected:
+	virtual void timerEvent(QTimerEvent *event);
+
 private slots:
 private slots:
 	void on_joinNetworkButton_clicked();
 	void on_joinNetworkButton_clicked();
 	void on_actionAbout_triggered();
 	void on_actionAbout_triggered();