Add convert function to script
This commit is contained in:
+2
-2
@@ -25,9 +25,9 @@ QStringList scanDirectories(const QStringList &paths)
|
|||||||
std::function<void(const QString &path)> scanDirectory = [&](const QString &path)
|
std::function<void(const QString &path)> scanDirectory = [&](const QString &path)
|
||||||
{
|
{
|
||||||
QFileInfo info(path);
|
QFileInfo info(path);
|
||||||
if(info.isDir() && !scannedDirs.contains(info.canonicalPath()))
|
if(info.isDir() && !scannedDirs.contains(info.canonicalFilePath()))
|
||||||
{
|
{
|
||||||
scannedDirs.append(info.canonicalPath());
|
scannedDirs.append(info.canonicalFilePath());
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
QStringList entries = dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
QStringList entries = dir.entryList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||||
for(QString &entry : entries)
|
for(QString &entry : entries)
|
||||||
|
|||||||
@@ -601,6 +601,8 @@ void ConvertRunable::run()
|
|||||||
ImageInfoData imageinfo;
|
ImageInfoData imageinfo;
|
||||||
std::shared_ptr<RawImage> rawimage;
|
std::shared_ptr<RawImage> rawimage;
|
||||||
loadImage(m_infile, imageinfo, rawimage);
|
loadImage(m_infile, imageinfo, rawimage);
|
||||||
|
QFileInfo info(m_outfile);
|
||||||
|
info.dir().mkpath(".");
|
||||||
|
|
||||||
if(rawimage)
|
if(rawimage)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "loadrunable.h"
|
#include "loadrunable.h"
|
||||||
#include "rawimage.h"
|
#include "rawimage.h"
|
||||||
|
#include "loadrunable.h"
|
||||||
|
|
||||||
namespace Script
|
namespace Script
|
||||||
{
|
{
|
||||||
@@ -11,6 +12,7 @@ namespace Script
|
|||||||
ScriptEngine::ScriptEngine(QObject *parent) : QObject(parent)
|
ScriptEngine::ScriptEngine(QObject *parent) : QObject(parent)
|
||||||
, _jsEngine(new QJSEngine(this))
|
, _jsEngine(new QJSEngine(this))
|
||||||
, _database(new Database(this))
|
, _database(new Database(this))
|
||||||
|
, _pool(new QThreadPool(this))
|
||||||
{
|
{
|
||||||
QJSValue engine = _jsEngine->newQObject(this);
|
QJSValue engine = _jsEngine->newQObject(this);
|
||||||
_jsEngine->globalObject().setProperty("engine", engine);
|
_jsEngine->globalObject().setProperty("engine", engine);
|
||||||
@@ -64,6 +66,24 @@ bool ScriptEngine::isMarked(const File *file) const
|
|||||||
return _database->isMarked(file->absoluteFilePath());
|
return _database->isMarked(file->absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptEngine::convert(File *file, QString &outpath, QJSValue ¶ms)
|
||||||
|
{
|
||||||
|
QString format = params.toString();
|
||||||
|
QString path;
|
||||||
|
QDir dir(_outputDir);
|
||||||
|
QFileInfo info(outpath);
|
||||||
|
QString suffix = info.suffix();
|
||||||
|
if(info.isAbsolute())
|
||||||
|
path = info.absolutePath();
|
||||||
|
else
|
||||||
|
path = dir.absoluteFilePath(outpath);
|
||||||
|
|
||||||
|
info.setFile(path);
|
||||||
|
//qDebug() << info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower();
|
||||||
|
_pool->start(new ConvertRunable(file->absoluteFilePath(), info.absolutePath() + "/" + info.completeBaseName() + "." + format.toLower(), format));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
QJSValue ScriptEngine::newObject()
|
QJSValue ScriptEngine::newObject()
|
||||||
{
|
{
|
||||||
return _jsEngine->newObject();
|
return _jsEngine->newObject();
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QJSEngine>
|
#include <QJSEngine>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QThreadPool>
|
||||||
#include "database.h"
|
#include "database.h"
|
||||||
|
|
||||||
namespace Script
|
namespace Script
|
||||||
@@ -17,6 +18,7 @@ class ScriptEngine : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QJSEngine *_jsEngine;
|
QJSEngine *_jsEngine;
|
||||||
Database *_database;
|
Database *_database;
|
||||||
|
QThreadPool *_pool;
|
||||||
QString _scriptPath;
|
QString _scriptPath;
|
||||||
QString _outputDir;
|
QString _outputDir;
|
||||||
QStringList _paths;
|
QStringList _paths;
|
||||||
@@ -31,6 +33,7 @@ public:
|
|||||||
Q_INVOKABLE void mark(File *file);
|
Q_INVOKABLE void mark(File *file);
|
||||||
Q_INVOKABLE void unmark(File *file);
|
Q_INVOKABLE void unmark(File *file);
|
||||||
Q_INVOKABLE bool isMarked(const File *file) const;
|
Q_INVOKABLE bool isMarked(const File *file) const;
|
||||||
|
Q_INVOKABLE bool convert(File *file, QString &outpath, QJSValue ¶ms);
|
||||||
QJSValue newObject();
|
QJSValue newObject();
|
||||||
public slots:
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
|
|||||||
Reference in New Issue
Block a user