From c02990fff755b9c764c581465f09890c140a6e99 Mon Sep 17 00:00:00 2001 From: hrobeers Date: Thu, 14 Jan 2016 18:36:44 +0100 Subject: [PATCH] server url commandline option --- LICENSE.BSD | 2 +- src/app/main.cpp | 15 +++++++++++++-- src/app/mainwindow.cpp | 5 +++-- src/app/mainwindow.h | 4 +++- src/app/runinteractive.hpp | 4 ++-- src/version_autogen.h | 4 ++-- src/web/exportdialog.cpp | 4 ++-- src/web/exportdialog.hpp | 2 +- src/web/stlexport.cpp | 15 ++++++++------- src/web/stlexport.hpp | 4 +++- 10 files changed, 38 insertions(+), 21 deletions(-) diff --git a/LICENSE.BSD b/LICENSE.BSD index a99c6f2..ae7e854 100644 --- a/LICENSE.BSD +++ b/LICENSE.BSD @@ -1,6 +1,6 @@ /**************************************************************************** - Copyright (c) 2015, Hans Robeers + Copyright (c) 2016, Hans Robeers All rights reserved. BSD 2-Clause License diff --git a/src/app/main.cpp b/src/app/main.cpp index 98060f1..c589412 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -55,7 +55,12 @@ int main(int argc, char *argv[]) parser.addHelpOption(); parser.addVersionOption(); - parser.addPositionalArgument("file", QApplication::tr("File to open.")); + QCommandLineOption serverUrl(QStringLiteral("server-url"), + QApplication::tr("Base URL of the finFoil server."), + QStringLiteral("URL")); + parser.addOption(serverUrl); + + parser.addPositionalArgument(QStringLiteral("file"), QApplication::tr("File to open.")); // Process the actual command line arguments given by the user parser.process(app); @@ -66,7 +71,13 @@ int main(int argc, char *argv[]) if (!args.isEmpty()) filePath = args.first(); - return runInteractive(app, filePath); + QUrl baseUrl; + if (parser.isSet(serverUrl)) + baseUrl = QUrl::fromUserInput(parser.value(serverUrl)); + if (!baseUrl.isValid()) + baseUrl = QStringLiteral("http://finfoil.io/s"); + + return runInteractive(app, baseUrl, filePath); } catch (std::exception &ex) { diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 967530b..9d44dc7 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -43,9 +43,10 @@ using namespace foileditors; using namespace foillogic; using namespace jenson; -MainWindow::MainWindow(const hrlib::Version version, QWidget *parent) : +MainWindow::MainWindow(const QUrl &baseUrl, const hrlib::Version version, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), + _baseUrl(baseUrl), _version(version), _dirty(false) { @@ -191,7 +192,7 @@ void MainWindow::loadThickness() void MainWindow::stlExport() { - web::ExportDialog* exp = new web::ExportDialog(_fin.get(), &_version, this); + web::ExportDialog* exp = new web::ExportDialog(_fin.get(), _baseUrl, _version, this); exp->show(); } diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 4a480d9..2080be2 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -28,6 +28,7 @@ #include #include +#include #include "jenson.h" #include "version.h" @@ -40,7 +41,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(const hrlib::Version version, QWidget *parent = 0); + explicit MainWindow(const QUrl &baseUrl, const hrlib::Version version, QWidget *parent = 0); ~MainWindow(); bool saveFile(const QString &path); @@ -70,6 +71,7 @@ private slots: void setClean(); private: + const QUrl _baseUrl; const hrlib::Version _version; Ui::MainWindow *ui; diff --git a/src/app/runinteractive.hpp b/src/app/runinteractive.hpp index 56e5235..705c485 100644 --- a/src/app/runinteractive.hpp +++ b/src/app/runinteractive.hpp @@ -29,12 +29,12 @@ QTextStream out(stdout); #endif -int runInteractive(QApplication &app, const QString &filePath) +int runInteractive(QApplication &app, const QUrl &baseUrl, const QString &filePath) { out << "Starting finFoil " << version.toString() << endl << "git-hash " << version.commit() << endl; - MainWindow w(version); + MainWindow w(baseUrl, version); w.show(); diff --git a/src/version_autogen.h b/src/version_autogen.h index c2cc535..e7302ea 100644 --- a/src/version_autogen.h +++ b/src/version_autogen.h @@ -11,7 +11,7 @@ #define MINOR_VERSION 1 #define REVISION 0 -#define BUILD_NUMBER 466 -#define COMMIT_HASH "4e732d589fdfcbfa742528741d05fcb91d2e05f1" +#define BUILD_NUMBER 469 +#define COMMIT_HASH "6edb93580a4bc21b163e12ae35e0226808d218ab" #endif // VERSION_AUTOGEN_H diff --git a/src/web/exportdialog.cpp b/src/web/exportdialog.cpp index dcf8647..3151b2e 100644 --- a/src/web/exportdialog.cpp +++ b/src/web/exportdialog.cpp @@ -29,11 +29,11 @@ using namespace web; -ExportDialog::ExportDialog(const foillogic::Foil *toExport, const hrlib::Version *version, QWidget *parent) : +ExportDialog::ExportDialog(const foillogic::Foil *toExport, const QUrl &baseUrl, const hrlib::Version &version, QWidget *parent) : QDialog(parent), _ui(new Ui::ExportDialog), _toExport(toExport), - _stlExport(new StlExport(version)), + _stlExport(new StlExport(baseUrl, version)), _msgReply(nullptr), _postFoilReply(nullptr) { _ui->setupUi(this); diff --git a/src/web/exportdialog.hpp b/src/web/exportdialog.hpp index 08f6328..7e456e3 100644 --- a/src/web/exportdialog.hpp +++ b/src/web/exportdialog.hpp @@ -38,7 +38,7 @@ namespace web { Q_OBJECT public: - explicit ExportDialog(const foillogic::Foil *toExport, const hrlib::Version *version, QWidget *parent = 0); + explicit ExportDialog(const foillogic::Foil *toExport, const QUrl &baseUrl, const hrlib::Version &version, QWidget *parent = 0); ~ExportDialog(); private: diff --git a/src/web/stlexport.cpp b/src/web/stlexport.cpp index 99426c5..1d17a95 100644 --- a/src/web/stlexport.cpp +++ b/src/web/stlexport.cpp @@ -39,16 +39,17 @@ using namespace foillogic; using namespace jenson; using namespace hrlib; -StlExport::StlExport(const Version *version, QObject *parent) : +StlExport::StlExport(const QUrl &baseUrl, const Version &version, QObject *parent) : QObject(parent), _manager(new QNetworkAccessManager()), _fileName("finfoil"), // TODO use real fileName if possible - _messageName("finfoil") + _messageName("finfoil"), + _baseUrl(baseUrl) { QString versionSuffix = "_v"; - versionSuffix.append(QString::number(version->Major())); + versionSuffix.append(QString::number(version.Major())); versionSuffix.append("."); - versionSuffix.append(QString::number(version->Minor())); + versionSuffix.append(QString::number(version.Minor())); _fileName.append(versionSuffix); _fileName.append(".foil"); @@ -59,7 +60,7 @@ StlExport::StlExport(const Version *version, QObject *parent) : QNetworkReply* StlExport::getMessage() { - QUrl url("http://127.0.0.1:4000/messages/" + _messageName); + QUrl url(_baseUrl.toString(QUrl::StripTrailingSlash) + "/messages/" + _messageName); QNetworkRequest request(url); connect(_manager.get(), &QNetworkAccessManager::finished, this, &StlExport::finished); @@ -69,7 +70,7 @@ QNetworkReply* StlExport::getMessage() QNetworkReply* StlExport::generateSTL(const Foil *foil) { - QUrl url("http://127.0.0.1:4000/stl/" + _fileName); + QUrl url(_baseUrl.toString(QUrl::StripTrailingSlash) + "/stl/" + _fileName); QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/foil"); @@ -87,7 +88,7 @@ QNetworkReply* StlExport::generateSTL(const Foil *foil) QNetworkReply *StlExport::getSTL(const QByteArray &stlReply) { - QUrl url("http://127.0.0.1:4000/" + QString::fromUtf8(stlReply)); + QUrl url(_baseUrl.toString(QUrl::StripTrailingSlash) + QString::fromUtf8(stlReply)); QNetworkRequest request(url); connect(_manager.get(), &QNetworkAccessManager::finished, this, &StlExport::finished); diff --git a/src/web/stlexport.hpp b/src/web/stlexport.hpp index 34c7cfa..4ba4b34 100644 --- a/src/web/stlexport.hpp +++ b/src/web/stlexport.hpp @@ -30,6 +30,7 @@ namespace hrlib { class Version; } #include #include +#include namespace web { @@ -38,7 +39,7 @@ namespace web Q_OBJECT public: - explicit StlExport(const hrlib::Version *version, QObject *parent = 0); + explicit StlExport(const QUrl &baseUrl, const hrlib::Version &version, QObject *parent = 0); QNetworkReply* getMessage(); QNetworkReply* generateSTL(const foillogic::Foil *foil); @@ -54,6 +55,7 @@ namespace web private: std::unique_ptr _manager; QString _fileName, _messageName; + QUrl _baseUrl; }; }