Commit 893757e1 authored by Johannes Schwab's avatar Johannes Schwab

client: accept file as command line argument

parent 4e9c1298
......@@ -25,6 +25,7 @@
#include <QVariant>
#include <QLocale>
#include <cassert>
#include <QDir>
#ifdef Q_OS_ANDROID
#include "Jni.h"
......@@ -407,13 +408,9 @@ void Backend::shareRecipe(Recipe *recipe) {
}
#else
bool Backend::importRecipeFromFile(const QString &path) {
#ifdef Q_OS_WIN
//Remove "file:///" from beginning
QFile f(path.right(path.size() - 8));
#else
//Remove "file://" from beginning
QFile f(path.right(path.size() - 7));
#endif
const QString resolvedPath = QUrl::fromUserInput(path, QDir::currentPath(), QUrl::AssumeLocalFile).toLocalFile();
qDebug() << "Importing recipe from file" << resolvedPath;
QFile f(resolvedPath);
if (!f.open(QFile::ReadOnly | QFile::Text)) return false;
QTextStream stream(&f);
try {
......@@ -427,13 +424,8 @@ bool Backend::importRecipeFromFile(const QString &path) {
}
bool Backend::saveRecipeToFile(Recipe *recipe, const QString &path) {
#ifdef Q_OS_WIN
//Remove "file:///" from beginning
QFile f(path.right(path.size() - 8));
#else
//Remove "file://" from beginning
QFile f(path.right(path.size() - 7));
#endif
const QString resolvedPath = QUrl::fromUserInput(path, QDir::currentPath(), QUrl::AssumeLocalFile).toLocalFile();
QFile f(resolvedPath);
if (!f.open(QFile::WriteOnly | QFile::Text | QFile::Truncate)) return false;
QTextStream stream(&f);
stream << recipe->toXML();
......
......@@ -22,19 +22,20 @@
#include <InternalError.h>
#include <cstring>
#include <QPixmap>
#include <QBuffer>
#include <QVariant>
#include <QDir>
#include <QPainter>
#include <QPixmap>
#include <QSvgRenderer>
#include <QTextStream>
#include <QXmlSimpleReader>
#include <QXmlDefaultHandler>
#include <QVariant>
#include <QXmlAttributes>
#include <QXmlDefaultHandler>
#include <QXmlSimpleReader>
#include <QtEndian>
#include <cassert>
#include <QSvgRenderer>
#include <QPainter>
#include <array>
#include <cassert>
#include <cstring>
Recipe::Recipe(const QByteArray &id, const QList<Ingredient*> ingredients)
:
......@@ -240,13 +241,8 @@ void Recipe::setImage(const QString &imageSrc) {
image = imageSrc;
} else {
qDebug() << "Opening image" << imageSrc;
#ifdef Q_OS_WIN
//Remove "file:///" from beginning
QImage i(imageSrc.right(imageSrc.size() - 8));
#else
//Remove "file://" from beginning
QImage i(imageSrc.right(imageSrc.size() - 7));
#endif
const QString resolvedPath = QUrl::fromUserInput(imageSrc, QDir::currentPath(), QUrl::AssumeLocalFile).toLocalFile();
QImage i(resolvedPath);
//If you are changing size here, change it in java helper class too.
i = i.scaledToHeight(120, Qt::SmoothTransformation);
QByteArray imageData;
......
......@@ -66,7 +66,9 @@ int main(int argc, char **argv) {
QCommandLineParser parser;
parser.addHelpOption();
parser.addVersionOption();
parser.addPositionalArgument("file", QObject::tr("recipe to import"));
parser.process(app);
const QStringList args = parser.positionalArguments();
#endif
#ifdef Q_OS_ANDROID
......@@ -122,6 +124,7 @@ int main(int argc, char **argv) {
QtAndroid::hideSplashScreen();
#else
engine.load(QUrl("qrc:/qml/MainWindowDesktop.qml"));
if (!args.empty()) backend.importRecipeFromFile(args.at(0));
#endif
return app.exec();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment