Commit d3dccabc authored by Smit Mehta's avatar Smit Mehta
Browse files

Moved all private items from ActionThread to Task and hence stopped sharing...

Moved all private items from ActionThread to Task and hence stopped sharing ActionThread::Private with Task.
Separated ActionThread and Task for better visibility
BUGS:303980
parent b1319988
......@@ -229,6 +229,7 @@ SET(libdngwriter_SRCS
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/plugin )
SET(dngconverter_common_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/plugin/actionthread.cpp
${CMAKE_CURRENT_SOURCE_DIR}/plugin/task.cpp
${CMAKE_CURRENT_SOURCE_DIR}/plugin/batchdialog.cpp
${CMAKE_CURRENT_SOURCE_DIR}/plugin/settingswidget.cpp
${CMAKE_CURRENT_SOURCE_DIR}/plugin/myimagelist.cpp
......
......@@ -8,7 +8,6 @@
*
* Copyright (C) 2012 by Smit Mehta <smit dot meh at gmail dot com>
* Copyright (C) 2008-2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
* Copyright (C) 2012 by Smit Mehta <smit dot meh at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
......@@ -24,19 +23,10 @@
#include "actionthread.moc"
// Qt includes
#include <QFileInfo>
#include <QMutex>
#include <QMutexLocker>
#include <QWaitCondition>
#include <QtDebug>
// KDE includes
#include <threadweaver/ThreadWeaver.h>
#include <threadweaver/JobCollection.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstandarddirs.h>
......@@ -52,7 +42,7 @@
// Local includes
#include "actions.h"
#include "task.h"
#include "kpmetadata.h"
using namespace KDcrawIface;
......@@ -70,124 +60,15 @@ public:
backupOriginalRawFile = false;
compressLossLess = true;
updateFileDate = false;
cancel = false;
previewMode = DNGWriter::MEDIUM;
iface = 0;
PluginLoader* pl = PluginLoader::instance();
if (pl)
{
iface = pl->interface();
}
}
bool backupOriginalRawFile;
bool compressLossLess;
bool updateFileDate;
bool cancel;
int previewMode;
QMutex mutex;
DNGWriter dngProcessor;
Interface* iface;
};
Task::Task(QObject* const parent, const KUrl& fileUrl, const Action& action, ActionThread::Private* const d)
: Job(parent)
{
m_url = fileUrl;
m_action = action;
m_d = d;
}
Task::~Task()
{
}
void Task::run()
{
if (m_d->cancel)
{
return;
}
switch (m_action)
{
case IDENTIFY:
{
// Identify Camera model.
DcrawInfoContainer info;
{
KPFileReadLocker(m_d->iface, m_url.toLocalFile());
KDcraw::rawFileIdentify(info, m_url.toLocalFile());
}
QString identify = i18n("Cannot identify Raw image");
if (info.isDecodable)
{
identify = info.make + QString("-") + info.model;
}
ActionData ad;
ad.action = m_action;
ad.fileUrl = m_url;
ad.message = identify;
ad.result = DNGWriter::PROCESSCOMPLETE;
emit signalFinished(ad);
break;
}
case PROCESS:
{
ActionData ad1;
ad1.action = PROCESS;
ad1.fileUrl = m_url;
ad1.starting = true;
emit signalStarting(ad1);
int ret = DNGWriter::PROCESSCOMPLETE;
QString destPath;
{
KPFileReadLocker(m_d->iface, m_url.toLocalFile());
QFileInfo fi(m_url.toLocalFile());
destPath = fi.absolutePath() + QString("/") + ".kipi-dngconverter-tmp-" +
QString::number(QDateTime::currentDateTime().toTime_t()) + QString(m_url.fileName());
m_d->mutex.lock();
m_d->dngProcessor.reset();
m_d->dngProcessor.setInputFile(m_url.toLocalFile());
m_d->dngProcessor.setOutputFile(destPath);
m_d->dngProcessor.setBackupOriginalRawFile(m_d->backupOriginalRawFile);
m_d->dngProcessor.setCompressLossLess(m_d->compressLossLess);
m_d->dngProcessor.setUpdateFileDate(m_d->updateFileDate);
m_d->dngProcessor.setPreviewMode(m_d->previewMode);
ret = m_d->dngProcessor.convert();
m_d->mutex.unlock();
}
ActionData ad2;
ad2.action = PROCESS;
ad2.fileUrl = m_url;
ad2.destPath = destPath;
ad2.result = ret;
emit signalFinished(ad2);
break;
}
default:
{
kError() << "Unknown action specified";
break;
}
}
}
// ----------------------------------------------------------------------------------------------------------------
ActionThread::ActionThread(QObject* const parent)
: RActionThreadBase(parent), d(new Private)
{
......@@ -240,17 +121,24 @@ void ActionThread::identifyRawFile(const KUrl& url)
void ActionThread::identifyRawFiles(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, IDENTIFY, d);
Task* const t = new Task(this, *it, IDENTIFY);
t->setBackupOriginalRawFile(d->backupOriginalRawFile);
t->setCompressLossLess(d->compressLossLess);
t->setUpdateFileDate(d->updateFileDate);
t->setPreviewMode(d->previewMode);
connect(t, SIGNAL(signalStarting(KIPIDNGConverterPlugin::ActionData)),
this, SIGNAL(signalStarting(KIPIDNGConverterPlugin::ActionData)));
connect(t, SIGNAL(signalFinished(KIPIDNGConverterPlugin::ActionData)),
this, SIGNAL(signalFinished(KIPIDNGConverterPlugin::ActionData)));
connect(this, SIGNAL(signalCancelTask()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
......@@ -260,11 +148,15 @@ void ActionThread::identifyRawFiles(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->setBackupOriginalRawFile(d->backupOriginalRawFile);
t->setCompressLossLess(d->compressLossLess);
t->setUpdateFileDate(d->updateFileDate);
t->setPreviewMode(d->previewMode);
connect(t, SIGNAL(signalStarting(KIPIDNGConverterPlugin::ActionData)),
this, SIGNAL(signalStarting(KIPIDNGConverterPlugin::ActionData)));
......@@ -272,6 +164,9 @@ void ActionThread::processRawFiles(const KUrl::List& urlList)
connect(t, SIGNAL(signalFinished(KIPIDNGConverterPlugin::ActionData)),
this, SIGNAL(signalFinished(KIPIDNGConverterPlugin::ActionData)));
connect(this, SIGNAL(signalCancelTask()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
......@@ -280,7 +175,9 @@ void ActionThread::processRawFiles(const KUrl::List& urlList)
void ActionThread::cancel()
{
d->cancel = true;
if (isRunning())
emit signalCancelTask();
RActionThreadBase::cancel();
}
......
......@@ -24,8 +24,6 @@
#ifndef ACTIONTHREAD_H
#define ACTIONTHREAD_H
// Qt includes
// KDE includes
#include <kurl.h>
......@@ -74,44 +72,17 @@ Q_SIGNALS:
void signalStarting(const KIPIDNGConverterPlugin::ActionData& ad);
void signalFinished(const KIPIDNGConverterPlugin::ActionData& ad);
/** Signal to emit to sub-tasks to cancel processing.
*/
void signalCancelTask();
public:
class Private;
private:
class Private;
Private* const d;
};
// -----------------------------------------------------------------------------------------------------------------------
class Task : public Job
{
Q_OBJECT
public:
Task(QObject* const parent, const KUrl& url, const Action& action, ActionThread::Private* const d);
~Task();
Q_SIGNALS:
void signalStarting(const KIPIDNGConverterPlugin::ActionData& ad);
void signalFinished(const KIPIDNGConverterPlugin::ActionData& ad);
protected:
void run();
private:
KUrl m_url;
Action m_action;
ActionThread::Private* m_d;
};
} // namespace KIPIDNGConverterPlugin
#endif /* ACTIONTHREAD_H */
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.digikam.org
*
* Date : 2012-12-24
* Description : a class to manage plugin actions using threads
*
* Copyright (C) 2012 by Smit Mehta <smit dot meh at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#include "task.moc"
// Qt includes
#include <QFileInfo>
// KDE includes
#include <threadweaver/ThreadWeaver.h>
#include <threadweaver/JobCollection.h>
#include <kdebug.h>
#include <klocale.h>
#include <kstandarddirs.h>
// LibKDcraw includes
#include <libkdcraw/dcrawinfocontainer.h>
#include <libkdcraw/kdcraw.h>
// LibKIPI includes
#include <libkipi/interface.h>
#include <libkipi/pluginloader.h>
// Local includes
#include "actions.h"
#include "kpmetadata.h"
using namespace KDcrawIface;
using namespace KIPIPlugins;
namespace KIPIDNGConverterPlugin
{
class Task::Private
{
public:
Private()
{
backupOriginalRawFile = false;
compressLossLess = true;
updateFileDate = false;
cancel = false;
previewMode = DNGWriter::MEDIUM;
iface = 0;
PluginLoader* pl = PluginLoader::instance();
if (pl)
{
iface = pl->interface();
}
}
bool backupOriginalRawFile;
bool compressLossLess;
bool updateFileDate;
bool cancel;
int previewMode;
KUrl url;
Action action;
DNGWriter dngProcessor;
Interface* iface;
};
Task::Task(QObject* const parent, const KUrl& fileUrl, const Action& action)
: Job(parent), d(new Private)
{
d->url = fileUrl;
d->action = action;
}
Task::~Task()
{
slotCancel();
delete d;
}
void Task::setBackupOriginalRawFile(bool b)
{
d->backupOriginalRawFile = b;
}
void Task::setCompressLossLess(bool b)
{
d->compressLossLess = b;
}
void Task::setUpdateFileDate(bool b)
{
d->updateFileDate = b;
}
void Task::setPreviewMode(int mode)
{
d->previewMode = mode;
}
void Task::run()
{
if (d->cancel)
{
return;
}
kDebug() << d->url;
kDebug() << d->action;
switch (d->action)
{
case IDENTIFY:
{
// Identify Camera model.
DcrawInfoContainer info;
{
KPFileReadLocker(d->iface, d->url.toLocalFile());
KDcraw::rawFileIdentify(info, d->url.toLocalFile());
}
QString identify = i18n("Cannot identify Raw image");
if (info.isDecodable)
{
identify = info.make + QString("-") + info.model;
}
ActionData ad;
ad.action = d->action;
ad.fileUrl = d->url;
ad.message = identify;
ad.result = DNGWriter::PROCESSCOMPLETE;
emit signalFinished(ad);
break;
}
case PROCESS:
{
ActionData ad1;
ad1.action = PROCESS;
ad1.fileUrl = d->url;
ad1.starting = true;
emit signalStarting(ad1);
int ret = DNGWriter::PROCESSCOMPLETE;
QString destPath;
{
KPFileReadLocker(d->iface, d->url.toLocalFile());
QFileInfo fi(d->url.toLocalFile());
destPath = fi.absolutePath() + QString("/") + ".kipi-dngconverter-tmp-" +
QString::number(QDateTime::currentDateTime().toTime_t()) + QString(d->url.fileName());
d->dngProcessor.reset();
d->dngProcessor.setInputFile(d->url.toLocalFile());
d->dngProcessor.setOutputFile(destPath);
d->dngProcessor.setBackupOriginalRawFile(d->backupOriginalRawFile);
d->dngProcessor.setCompressLossLess(d->compressLossLess);
d->dngProcessor.setUpdateFileDate(d->updateFileDate);
d->dngProcessor.setPreviewMode(d->previewMode);
ret = d->dngProcessor.convert();
}
ActionData ad2;
ad2.action = PROCESS;
ad2.fileUrl = d->url;
ad2.destPath = destPath;
ad2.result = ret;
emit signalFinished(ad2);
break;
}
default:
{
kError() << "Unknown action specified";
break;
}
}
}
void Task::slotCancel()
{
d->cancel = true;
d->dngProcessor.cancel();
}
} // namespace KIPIDNGConverterPlugin
/* ============================================================
*
* This file is a part of kipi-plugins project
* http://www.digikam.org
*
* Date : 2012-12-24
* Description : a class to manage plugin actions using threads
*
* Copyright (C) 2012 by Smit Mehta <smit dot meh at gmail dot com>
*
* This program is free software; you can redistribute it
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation;
* either version 2, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* ============================================================ */
#ifndef TASK_H
#define TASK_H
// KDE includes
#include <kurl.h>
#include <threadweaver/Job.h>
// Libkdcraw includes
#include <libkdcraw/ractionthreadbase.h>
// Local includes
#include "settingswidget.h"
#include "actions.h"
using namespace ThreadWeaver;
using namespace KDcrawIface;
namespace KIPIDNGConverterPlugin
{
class Task : public Job
{
Q_OBJECT
public:
Task(QObject* const parent, const KUrl& url, const Action& action);
~Task();
void setBackupOriginalRawFile(bool b);
void setCompressLossLess(bool b);
void setUpdateFileDate(bool b);
void setPreviewMode(int mode);
Q_SIGNALS:
void signalStarting(const KIPIDNGConverterPlugin::ActionData& ad);
void signalFinished(const KIPIDNGConverterPlugin::ActionData& ad);
public Q_SLOTS:
void slotCancel();
protected:
void run();
private:
class Private;
Private* const d;
};
} // namespace KIPIDNGConverterPlugin
#endif /* TASK_H */
\ No newline at end of file
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