Skip to content

Commit

Permalink
Better integration of scan command
Browse files Browse the repository at this point in the history
  • Loading branch information
dragotin committed May 22, 2020
1 parent 8ba367b commit 7a69024
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,15 @@ void Dialog::slotFromScanner()

connect(_scanner, &Executor::finished, this, &Dialog::slotScanFinished);
startLengthyOperation();
if (!_scanner->scan(false)) {
if (!_scanner->scan()) {
slotScanFinished(false);
} else {
updateInfoText(ProcessStatus::Scanning);
}

}

void Dialog::slotScanFinished(bool success)
void Dialog::slotScanFinished(int exitCode)
{
// get the result file name from the creator object.
QString resultFile;
Expand All @@ -356,12 +356,12 @@ void Dialog::slotScanFinished(bool success)
delete _scanner;
_scanner = nullptr;
}
if (success) {
if (exitCode == 0) {
_model.addImageFile(resultFile);
}
endLengthyOperation();

if (_model.rowCount() && success)
if (_model.rowCount() && exitCode == 0)
updateInfoText(ProcessStatus::ImageScanned, resultFile);
else
updateInfoText(ProcessStatus::ScanFailed);
Expand Down
2 changes: 1 addition & 1 deletion src/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private slots:
void slotFromScanner();
void slotButtonClicked(QAbstractButton *button);
void pdfCreatorFinished(bool success);
void slotScanFinished(bool success);
void slotScanFinished(int exitCode);
void slotListViewSize(QSize s);

void startLengthyOperation();
Expand Down
36 changes: 22 additions & 14 deletions src/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ Executor::Executor(QObject *parent)

}

Executor::~Executor()
{
if (_process != nullptr) {
if (_process->state() == QProcess::Running) {
_process->kill();
qDebug() << "KILLED the process!";
}
delete _process;
}
}

QString Executor::outputFile()
{
return _outputFile;
Expand Down Expand Up @@ -63,42 +74,39 @@ void Executor::buildPdf(const QStringList& files)
_process = new QProcess;
connect(_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &Executor::slotFinished);

_process->start("convert", args);
} else {
slotFinished(-3, QProcess::ExitStatus::NormalExit);
}
}

bool Executor::scan(bool colorMode)
bool Executor::scan()
{
QTemporaryDir dir;
dir.setAutoRemove(false);

_outputFile = dir.filePath("scan.png");
QProcess *process = new QProcess;
_process = new QProcess;
_process->setStandardOutputFile(_outputFile);

QString cmd = _cmd;
qDebug() << "Starting" << _cmd;

cmd.append(" -o ");
cmd.append(_outputFile);

qDebug() << "Starting" << cmd;

connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
connect(_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
this, &Executor::slotFinished);

process->start(cmd);
_process->start(_cmd);

return true;
}


void Executor::slotFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
emit finished(exitCode >= 0); // FIXME

delete _process;
_process = nullptr;
if (_process) {
qDebug() << "stderr output: " << _process->readAllStandardError();
}
emit finished(exitCode); // FIXME
}


Expand Down
3 changes: 2 additions & 1 deletion src/executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class Executor : public QObject
Q_OBJECT
public:
explicit Executor(QObject *parent = nullptr);
~Executor();

void buildPdf(const QStringList& files);
bool scan(bool colorMode);
bool scan();

void setOutputFile(const QString& fileName);
QString outputFile();
Expand Down

0 comments on commit 7a69024

Please sign in to comment.