Additional work on batch processing
This commit is contained in:
+11
-1
@@ -5,6 +5,8 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
#include <QMessageBox>
|
||||||
#include "scriptengine.h"
|
#include "scriptengine.h"
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
@@ -170,7 +172,7 @@ void BatchProcessing::runScript()
|
|||||||
if(selectedItems.size())
|
if(selectedItems.size())
|
||||||
{
|
{
|
||||||
_engineThread = new Script::ScriptEngineThread(this);
|
_engineThread = new Script::ScriptEngineThread(this);
|
||||||
connect(_engineThread, &Script::ScriptEngineThread::newMessage, _ui->log, &QTextEdit::append);
|
connect(_engineThread, &Script::ScriptEngineThread::newMessage, this, &BatchProcessing::newMessage);
|
||||||
connect(_engineThread, &Script::ScriptEngineThread::finished, this, &BatchProcessing::scriptFinished);
|
connect(_engineThread, &Script::ScriptEngineThread::finished, this, &BatchProcessing::scriptFinished);
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
for(int i=0; i<_ui->pathsList->count(); i++)
|
for(int i=0; i<_ui->pathsList->count(); i++)
|
||||||
@@ -206,3 +208,11 @@ void BatchProcessing::scriptFinished()
|
|||||||
delete _engineThread;
|
delete _engineThread;
|
||||||
_engineThread = nullptr;
|
_engineThread = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BatchProcessing::newMessage(const QString &message, bool error)
|
||||||
|
{
|
||||||
|
QColor color = _ui->log->textColor();
|
||||||
|
if(error)_ui->log->setTextColor(Qt::red);
|
||||||
|
_ui->log->append(message);
|
||||||
|
if(error)_ui->log->setTextColor(color);
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ public slots:
|
|||||||
void runScript();
|
void runScript();
|
||||||
void stopScript();
|
void stopScript();
|
||||||
void scriptFinished();
|
void scriptFinished();
|
||||||
|
void newMessage(const QString &message, bool error);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BATCHPROCESSING_H
|
#endif // BATCHPROCESSING_H
|
||||||
|
|||||||
+2
-2
@@ -152,11 +152,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
||||||
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
||||||
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
fileMenu->addAction(tr("Export database to CSV"), this, &MainWindow::exportCSV);
|
||||||
fileMenu->addAction(tr("Batch processing"), [this](){
|
/*fileMenu->addAction(tr("Batch processing"), [this](){
|
||||||
BatchProcessing *batchProcessing = new BatchProcessing(this);
|
BatchProcessing *batchProcessing = new BatchProcessing(this);
|
||||||
batchProcessing->exec();
|
batchProcessing->exec();
|
||||||
delete batchProcessing;
|
delete batchProcessing;
|
||||||
}, Qt::Key_B | Qt::CTRL);
|
}, Qt::Key_B | Qt::CTRL);*/
|
||||||
fileMenu->addSeparator();
|
fileMenu->addSeparator();
|
||||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||||
liveModeAction->setCheckable(true);
|
liveModeAction->setCheckable(true);
|
||||||
|
|||||||
+44
-5
@@ -20,7 +20,7 @@ void ScriptEngine::setParams(const QString &scriptPath, const QStringList &paths
|
|||||||
{
|
{
|
||||||
_scriptPath = scriptPath;
|
_scriptPath = scriptPath;
|
||||||
_paths = paths;
|
_paths = paths;
|
||||||
_outputDir = outputDir;
|
_outputDir = outputDir + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::reportError(const QString &message)
|
void ScriptEngine::reportError(const QString &message)
|
||||||
@@ -38,9 +38,14 @@ void ScriptEngine::interrupt()
|
|||||||
_jsEngine->setInterrupted(true);
|
_jsEngine->setInterrupted(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptEngine::logError(const QString &message)
|
||||||
|
{
|
||||||
|
emit newMessage(message, true);
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptEngine::log(const QString &message)
|
void ScriptEngine::log(const QString &message)
|
||||||
{
|
{
|
||||||
emit newMessage(message);
|
emit newMessage(message, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptEngine::mark(File *file)
|
void ScriptEngine::mark(File *file)
|
||||||
@@ -79,7 +84,7 @@ void ScriptEngine::run()
|
|||||||
{
|
{
|
||||||
QString error = result.property("name").toString() + " on line " + result.property("lineNumber").toString() + " : " + result.toString();
|
QString error = result.property("name").toString() + " on line " + result.property("lineNumber").toString() + " : " + result.toString();
|
||||||
error += "\n" + result.property("stack").toString();
|
error += "\n" + result.property("stack").toString();
|
||||||
emit newMessage(error);
|
emit newMessage(error, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit finished();
|
emit finished();
|
||||||
@@ -108,6 +113,26 @@ void File::loadFitsKeywords()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool File::mkpath(const QString &path) const
|
||||||
|
{
|
||||||
|
QFileInfo info(path);
|
||||||
|
if(!info.isRelative())
|
||||||
|
{
|
||||||
|
_engine->logError("Destination path is not relative");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QDir dir(_engine->outputDir());
|
||||||
|
if(dir.mkpath(info.path()))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_engine->logError("Failed to create dir " + info.path());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
File::File(const QString &path, Script::ScriptEngine *engine) :
|
File::File(const QString &path, Script::ScriptEngine *engine) :
|
||||||
_engine(engine),
|
_engine(engine),
|
||||||
_path(path),
|
_path(path),
|
||||||
@@ -173,12 +198,26 @@ bool File::isMarked() const
|
|||||||
|
|
||||||
bool File::copy(const QString &newpath) const
|
bool File::copy(const QString &newpath) const
|
||||||
{
|
{
|
||||||
return QFile::copy(_path, _engine->outputDir() + newpath);
|
if(mkpath(newpath))
|
||||||
|
{
|
||||||
|
if(QFile::copy(_path, _engine->outputDir() + newpath))
|
||||||
|
return true;
|
||||||
|
_engine->logError("Failed copy to " + newpath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::move(const QString &newpath) const
|
bool File::move(const QString &newpath) const
|
||||||
{
|
{
|
||||||
return QFile::rename(_path, _engine->outputDir() + newpath);
|
if(mkpath(newpath))
|
||||||
|
{
|
||||||
|
if(QFile::rename(_path, _engine->outputDir() + newpath))
|
||||||
|
return true;
|
||||||
|
_engine->logError("Failed move to " + newpath);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool File::convertTo(const QString &format)
|
bool File::convertTo(const QString &format)
|
||||||
|
|||||||
+4
-2
@@ -26,6 +26,7 @@ public:
|
|||||||
void reportError(const QString &message);
|
void reportError(const QString &message);
|
||||||
const QString& outputDir() const;
|
const QString& outputDir() const;
|
||||||
void interrupt();
|
void interrupt();
|
||||||
|
void logError(const QString &message);
|
||||||
Q_INVOKABLE void log(const QString &message);
|
Q_INVOKABLE void log(const QString &message);
|
||||||
Q_INVOKABLE void mark(File *file);
|
Q_INVOKABLE void mark(File *file);
|
||||||
Q_INVOKABLE void unmark(File *file);
|
Q_INVOKABLE void unmark(File *file);
|
||||||
@@ -33,7 +34,7 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
signals:
|
signals:
|
||||||
void newMessage(const QString &message);
|
void newMessage(const QString &message, bool error);
|
||||||
void finished();
|
void finished();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ public:
|
|||||||
void start();
|
void start();
|
||||||
void interrupt();
|
void interrupt();
|
||||||
signals:
|
signals:
|
||||||
void newMessage(const QString &message);
|
void newMessage(const QString &message, bool error);
|
||||||
void finished();
|
void finished();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -62,6 +63,7 @@ class File : public QObject
|
|||||||
bool _fitsKeywordsLoaded = false;
|
bool _fitsKeywordsLoaded = false;
|
||||||
QMap<QString, QString> _fitsKeywords;
|
QMap<QString, QString> _fitsKeywords;
|
||||||
void loadFitsKeywords();
|
void loadFitsKeywords();
|
||||||
|
bool mkpath(const QString &path) const;
|
||||||
public:
|
public:
|
||||||
explicit File(const QString &path, ScriptEngine *engine);
|
explicit File(const QString &path, ScriptEngine *engine);
|
||||||
Q_INVOKABLE QString fileName() const;
|
Q_INVOKABLE QString fileName() const;
|
||||||
|
|||||||
Reference in New Issue
Block a user