Skip to content

Commit

Permalink
server url commandline option
Browse files Browse the repository at this point in the history
  • Loading branch information
hrobeers committed Jan 14, 2016
1 parent 6edb935 commit c02990f
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion LICENSE.BSD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/****************************************************************************

Copyright (c) 2015, Hans Robeers
Copyright (c) 2016, Hans Robeers
All rights reserved.

BSD 2-Clause License
Expand Down
15 changes: 13 additions & 2 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down
5 changes: 3 additions & 2 deletions src/app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion src/app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include <QMainWindow>
#include <QFileInfo>
#include <QUrl>
#include "jenson.h"
#include "version.h"

Expand All @@ -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);
Expand Down Expand Up @@ -70,6 +71,7 @@ private slots:
void setClean();

private:
const QUrl _baseUrl;
const hrlib::Version _version;
Ui::MainWindow *ui;

Expand Down
4 changes: 2 additions & 2 deletions src/app/runinteractive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/version_autogen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/web/exportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/web/exportdialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 8 additions & 7 deletions src/web/stlexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/web/stlexport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace hrlib { class Version; }

#include <QObject>
#include <memory>
#include <QUrl>

namespace web
{
Expand All @@ -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);
Expand All @@ -54,6 +55,7 @@ namespace web
private:
std::unique_ptr<QNetworkAccessManager> _manager;
QString _fileName, _messageName;
QUrl _baseUrl;
};
}

Expand Down

0 comments on commit c02990f

Please sign in to comment.