Commit 791ce58f authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

To preserve re-entrancy with RawDecodingIface, move all private items from...

To preserve re-entrancy with RawDecodingIface, move all private items from ActionThread to Task. Do not share ActionThread::Private with Task.
Code is very similar than digiKam BQM core, and same fixes must be applied to DNGConverter.
CCBUGS: 303980
CCMAIL: smit.meh@gmail.com
parent 21c7f255
......@@ -343,7 +343,7 @@ void BatchDialog::slotStartStop()
d->progressBar->progressScheduled(i18n("RAW Converter"), true, true);
d->progressBar->progressThumbnailChanged(KIcon("rawconverter").pixmap(22));
d->thread->setRawDecodingSettings(d->decodingSettingsBox->settings(), d->saveSettingsBox->fileFormat());
d->thread->setSettings(d->decodingSettingsBox->settings(), d->saveSettingsBox->fileFormat());
processAll();
}
else
......
......@@ -308,7 +308,7 @@ void SingleDialog::saveSettings()
// 'Preview' dialog button.
void SingleDialog::slotUser1()
{
d->thread->setRawDecodingSettings(d->decodingSettingsBox->settings(), KPSaveSettingsWidget::OUTPUT_PNG);
d->thread->setSettings(d->decodingSettingsBox->settings(), KPSaveSettingsWidget::OUTPUT_PNG);
d->thread->processHalfRawFile(KUrl(d->inputFile));
if (!d->thread->isRunning())
d->thread->start();
......@@ -317,7 +317,7 @@ void SingleDialog::slotUser1()
// 'Convert' dialog button.
void SingleDialog::slotUser2()
{
d->thread->setRawDecodingSettings(d->decodingSettingsBox->settings(), d->saveSettingsBox->fileFormat());
d->thread->setSettings(d->decodingSettingsBox->settings(), d->saveSettingsBox->fileFormat());
d->thread->processRawFile(KUrl(d->inputFile));
if (!d->thread->isRunning())
d->thread->start();
......
......@@ -24,13 +24,6 @@
#include "actionthread.moc"
// Qt includes
#include <QMutex>
#include <QMutexLocker>
#include <QWaitCondition>
#include <QtDebug>
// KDE includes
#include <klocale.h>
......@@ -63,26 +56,11 @@ public:
Private()
{
cancel = false;
iface = 0;
PluginLoader* const pl = PluginLoader::instance();
if (pl)
{
iface = pl->interface();
}
}
bool cancel;
QMutex mutex;
RawDecodingIface dcrawIface;
KPSaveSettingsWidget::OutputFormat outputFormat;
RawDecodingSettings rawDecodingSettings;
Interface* iface;
};
//------------------------------------------------------------
......@@ -93,32 +71,58 @@ public:
Private()
{
dp = 0;
cancel = false;
iface = 0;
PluginLoader* const pl = PluginLoader::instance();
if (pl)
{
iface = pl->interface();
}
}
KUrl url;
Action action;
bool cancel;
KUrl url;
Action action;
ActionThread::Private* dp;
RawDecodingIface dcrawIface;
Interface* iface;
KPSaveSettingsWidget::OutputFormat outputFormat;
RawDecodingSettings rawDecodingSettings;
};
Task::Task(QObject* const parent, const KUrl& fileUrl, const Action& action,
ActionThread::Private* const dp)
Task::Task(QObject* const parent, const KUrl& fileUrl, const Action& action)
: Job(parent), d(new Private)
{
d->url = fileUrl;
d->action = action;
d->dp = dp;
}
Task::~Task()
{
slotCancel();
delete d;
}
void Task::setSettings(const RawDecodingSettings& rawDecodingSettings,
KPSaveSettingsWidget::OutputFormat outputFormat)
{
d->rawDecodingSettings = rawDecodingSettings;
d->outputFormat = outputFormat;
}
void Task::slotCancel()
{
d->cancel = true;
d->dcrawIface.cancel();
}
void Task::run()
{
if (d->dp->cancel)
if (d->cancel)
{
return;
}
......@@ -131,11 +135,12 @@ void Task::run()
// Identify Camera model.
DcrawInfoContainer info;
{
KPFileReadLocker(d->dp->iface, d->url.toLocalFile());
d->dp->dcrawIface.rawFileIdentify(info, d->url.toLocalFile());
KPFileReadLocker(d->iface, d->url.toLocalFile());
d->dcrawIface.rawFileIdentify(info, d->url.toLocalFile());
}
QString identify = i18n("Cannot identify RAW image");
if (info.isDecodable)
{
if (d->action == IDENTIFY)
......@@ -190,8 +195,8 @@ void Task::run()
// Get embedded RAW file thumbnail.
QImage image;
{
KPFileReadLocker(d->dp->iface, d->url.toLocalFile());
d->dp->dcrawIface.loadRawPreview(image, d->url.toLocalFile());
KPFileReadLocker(d->iface, d->url.toLocalFile());
d->dcrawIface.loadRawPreview(image, d->url.toLocalFile());
}
ActionData ad;
......@@ -214,9 +219,9 @@ void Task::run()
QString destPath;
bool result = false;
{
KPFileReadLocker(d->dp->iface, d->url.toLocalFile());
result = d->dp->dcrawIface.decodeHalfRAWImage(d->url.toLocalFile(), destPath,
d->dp->outputFormat, d->dp->rawDecodingSettings);
KPFileReadLocker(d->iface, d->url.toLocalFile());
result = d->dcrawIface.decodeHalfRAWImage(d->url.toLocalFile(), destPath,
d->outputFormat, d->rawDecodingSettings);
}
ActionData ad2;
......@@ -240,9 +245,9 @@ void Task::run()
bool result = false;
{
KPFileReadLocker(d->dp->iface, d->url.toLocalFile());
result = d->dp->dcrawIface.decodeRAWImage(d->url.toLocalFile(), destPath,
d->dp->outputFormat, d->dp->rawDecodingSettings);
KPFileReadLocker(d->iface, d->url.toLocalFile());
result = d->dcrawIface.decodeRAWImage(d->url.toLocalFile(), destPath,
d->outputFormat, d->rawDecodingSettings);
}
ActionData ad2;
......@@ -279,8 +284,8 @@ ActionThread::~ActionThread()
delete d;
}
void ActionThread::setRawDecodingSettings(const RawDecodingSettings& rawDecodingSettings,
KPSaveSettingsWidget::OutputFormat outputFormat)
void ActionThread::setSettings(const RawDecodingSettings& rawDecodingSettings,
KPSaveSettingsWidget::OutputFormat outputFormat)
{
d->rawDecodingSettings = rawDecodingSettings;
d->outputFormat = outputFormat;
......@@ -316,11 +321,12 @@ void ActionThread::thumbRawFile(const KUrl& url)
void ActionThread::identifyRawFiles(const KUrl::List& urlList, bool full)
{
JobCollection* collection = new JobCollection();
JobCollection* const collection = new JobCollection();
for (KUrl::List::const_iterator it = urlList.constBegin(); it != urlList.constEnd(); ++it)
{
Task* t = new Task(this, *it, full ? IDENTIFY_FULL : IDENTIFY, d);
Task* const t = new Task(this, *it, full ? IDENTIFY_FULL : IDENTIFY);
t->setSettings(d->rawDecodingSettings, d->outputFormat);
connect(t, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)));
......@@ -328,6 +334,9 @@ void ActionThread::identifyRawFiles(const KUrl::List& urlList, bool full)
connect(t, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)));
connect(this, SIGNAL(signalCancelTask()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
......@@ -336,11 +345,12 @@ void ActionThread::identifyRawFiles(const KUrl::List& urlList, bool full)
void ActionThread::thumbRawFiles(const KUrl::List& urlList)
{
JobCollection* collection = new JobCollection();
JobCollection* const collection = new JobCollection();
for (KUrl::List::const_iterator it = urlList.constBegin(); it != urlList.constEnd(); ++it)
{
Task* t = new Task(this, *it, THUMBNAIL, d);
Task* const t = new Task(this, *it, THUMBNAIL);
t->setSettings(d->rawDecodingSettings, d->outputFormat);
connect(t, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)));
......@@ -348,6 +358,9 @@ void ActionThread::thumbRawFiles(const KUrl::List& urlList)
connect(t, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)));
connect(this, SIGNAL(signalCancelTask()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
......@@ -356,11 +369,12 @@ void ActionThread::thumbRawFiles(const KUrl::List& urlList)
void ActionThread::processRawFiles(const KUrl::List& urlList)
{
JobCollection* collection = new JobCollection();
JobCollection* const collection = new JobCollection();
for (KUrl::List::const_iterator it = urlList.constBegin(); it != urlList.constEnd(); ++it)
{
Task* t = new Task(this, *it, PROCESS, d);
Task* const t = new Task(this, *it, PROCESS);
t->setSettings(d->rawDecodingSettings, d->outputFormat);
connect(t, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)));
......@@ -368,6 +382,9 @@ void ActionThread::processRawFiles(const KUrl::List& urlList)
connect(t, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)));
connect(this, SIGNAL(signalCancelTask()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
......@@ -376,11 +393,12 @@ void ActionThread::processRawFiles(const KUrl::List& urlList)
void ActionThread::processHalfRawFiles(const KUrl::List& urlList)
{
JobCollection* collection = new JobCollection();
JobCollection* const collection = new JobCollection();
for (KUrl::List::const_iterator it = urlList.constBegin(); it != urlList.constEnd(); ++it)
{
Task* t = new Task(this, *it, PREVIEW, d);
Task* const t = new Task(this, *it, PREVIEW);
t->setSettings(d->rawDecodingSettings, d->outputFormat);
connect(t, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalStarting(KIPIRawConverterPlugin::ActionData)));
......@@ -388,6 +406,9 @@ void ActionThread::processHalfRawFiles(const KUrl::List& urlList)
connect(t, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)),
this, SIGNAL(signalFinished(KIPIRawConverterPlugin::ActionData)));
connect(this, SIGNAL(signalCancelTask()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
......@@ -396,8 +417,9 @@ void ActionThread::processHalfRawFiles(const KUrl::List& urlList)
void ActionThread::cancel()
{
d->dcrawIface.cancel();
d->cancel = true;
if (isRunning())
emit signalCancelTask();
RActionThreadBase::cancel();
}
......
......@@ -63,8 +63,8 @@ public:
ActionThread(QObject* const parent);
~ActionThread();
void setRawDecodingSettings(const RawDecodingSettings& rawDecodingSettings,
KPSaveSettingsWidget::OutputFormat outputFormat);
void setSettings(const RawDecodingSettings& rawDecodingSettings,
KPSaveSettingsWidget::OutputFormat outputFormat);
void identifyRawFile(const KUrl& url, bool full=false);
void identifyRawFiles(const KUrl::List& urlList, bool full=false);
......@@ -85,12 +85,13 @@ Q_SIGNALS:
void signalStarting(const KIPIRawConverterPlugin::ActionData& ad);
void signalFinished(const KIPIRawConverterPlugin::ActionData& ad);
public:
class Private;
/** Signal to emit to sub-tasks to cancel processing.
*/
void signalCancelTask();
private:
class Private;
Private* const d;
};
......@@ -102,14 +103,21 @@ class Task : public Job
public:
Task(QObject* const parent, const KUrl& url, const Action& action, ActionThread::Private* const dp);
Task(QObject* const parent, const KUrl& url, const Action& action);
~Task();
void setSettings(const RawDecodingSettings& rawDecodingSettings,
KPSaveSettingsWidget::OutputFormat outputFormat);
Q_SIGNALS:
void signalStarting(const KIPIRawConverterPlugin::ActionData& ad);
void signalFinished(const KIPIRawConverterPlugin::ActionData& ad);
public Q_SLOTS:
void slotCancel();
protected:
void run();
......
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