[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kipi-plugins] timeadjust: moved private data from actionthread to task,
From: Smit Mehta <smit.meh () gmail ! com>
Date: 2012-12-31 15:34:29
Message-ID: 20121231153429.2BFFDA6091 () git ! kde ! org
[Download RAW message or body]
Git commit 0f612d3076dbb8a9c8575cfc60e9bd724e9a95a7 by Smit Mehta.
Committed on 31/12/2012 at 16:26.
Pushed by smitmehta into branch 'master'.
moved private data from actionthread to task, and hence stopped the sharing of \
private object.\nShifted task to another file for better readibility.
M +1 -0 timeadjust/CMakeLists.txt
M +19 -186 timeadjust/actionthread.cpp
M +2 -28 timeadjust/actionthread.h
C +61 -111 timeadjust/task.cpp [from: timeadjust/actionthread.cpp - 056% \
similarity] C +16 -48 timeadjust/task.h [from: timeadjust/actionthread.h - 054% \
similarity] [License: UNKNOWN] *
The files marked with a * at the end have a non valid license. Please read: \
http://techbase.kde.org/Policies/Licensing_Policy and use the headers which are \
listed at that page.
http://commits.kde.org/kipi-plugins/0f612d3076dbb8a9c8575cfc60e9bd724e9a95a7
diff --git a/timeadjust/CMakeLists.txt b/timeadjust/CMakeLists.txt
index 90a57c3..0b09832 100644
--- a/timeadjust/CMakeLists.txt
+++ b/timeadjust/CMakeLists.txt
@@ -4,6 +4,7 @@ SET(kipiplugin_timeadjust_PART_SRCS plugin_timeadjust.cpp
timeadjustdialog.cpp
clockphotodialog.cpp
actionthread.cpp
+ task.cpp
myimagelist.cpp
settingswidget.cpp
)
diff --git a/timeadjust/actionthread.cpp b/timeadjust/actionthread.cpp
index 18328c9..a00b5e3 100644
--- a/timeadjust/actionthread.cpp
+++ b/timeadjust/actionthread.cpp
@@ -23,15 +23,7 @@
#include "actionthread.moc"
-// C ANSI includes
-
-extern "C"
-{
-#include <unistd.h>
-#include <utime.h>
-}
-
-// Qt includes
+// Qt Includes
#include <QFileInfo>
@@ -40,13 +32,10 @@ extern "C"
#include <threadweaver/ThreadWeaver.h>
#include <threadweaver/JobCollection.h>
#include <kdebug.h>
-#include <kde_file.h>
// Local includes
-#include "kpmetadata.h"
-#include "kpimageinfo.h"
-#include "myimagelist.h"
+#include "task.h"
namespace KIPITimeAdjustPlugin
{
@@ -54,15 +43,6 @@ namespace KIPITimeAdjustPlugin
class ActionThread::Private
{
public:
-
- Private()
- {
- cancel = false;
- }
-
- // To manage items processing.
- bool cancel;
-
// Settings from GUI.
TimeAdjustSettings settings;
@@ -70,166 +50,6 @@ public:
QMap<KUrl, QDateTime> itemsMap;
};
-// ----------------------------------------------------------------------------------------------------
-
-Task::Task(QObject* const parent, const KUrl& url, ActionThread::Private* const d)
- : Job(parent)
-{
- m_url = url;
- m_d = d;
-}
-
-Task::~Task()
-{
-}
-
-void Task::run()
-{
- if (m_d->cancel) return;
-
- QDateTime dt = m_d->itemsMap.value(m_url);
-
- if (!dt.isValid()) return;
-
- emit signalProcessStarted(m_url);
-
- bool metadataChanged = m_d->settings.updEXIFModDate || \
m_d->settings.updEXIFOriDate ||
- m_d->settings.updEXIFDigDate || m_d->settings.updIPTCDate \
||
- m_d->settings.updXMPDate;
-
- int status = MyImageList::NOPROCESS_ERROR;
-
- if (metadataChanged)
- {
- bool ret = true;
-
- KPMetadata meta;
-
- ret &= meta.load(m_url.path());
- if (ret)
- {
- if (meta.canWriteExif(m_url.path()))
- {
- if (m_d->settings.updEXIFModDate)
- {
- ret &= meta.setExifTagString("Exif.Image.DateTime",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- }
-
- if (m_d->settings.updEXIFOriDate)
- {
- ret &= meta.setExifTagString("Exif.Photo.DateTimeOriginal",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- }
-
- if (m_d->settings.updEXIFDigDate)
- {
- ret &= meta.setExifTagString("Exif.Photo.DateTimeDigitized",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- }
- }
- else if (m_d->settings.updEXIFModDate || m_d->settings.updEXIFOriDate || \
m_d->settings.updEXIFDigDate)
- {
- ret = false;
- }
-
- if (m_d->settings.updIPTCDate)
- {
- if (meta.canWriteIptc(m_url.path()))
- {
- ret &= meta.setIptcTagString("Iptc.Application2.DateCreated",
- dt.date().toString(Qt::ISODate));
- ret &= meta.setIptcTagString("Iptc.Application2.TimeCreated",
- dt.time().toString(Qt::ISODate));
- }
- else
- {
- ret = false;
- }
- }
-
- if (m_d->settings.updXMPDate)
- {
- if (meta.supportXmp() && meta.canWriteXmp(m_url.path()))
- {
- ret &= meta.setXmpTagString("Xmp.exif.DateTimeOriginal",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- ret &= meta.setXmpTagString("Xmp.photoshop.DateCreated",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- ret &= meta.setXmpTagString("Xmp.tiff.DateTime",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- ret &= meta.setXmpTagString("Xmp.xmp.CreateDate",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- ret &= meta.setXmpTagString("Xmp.xmp.MetadataDate",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- ret &= meta.setXmpTagString("Xmp.xmp.ModifyDate",
- dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
- }
- else
- {
- ret = false;
- }
- }
-
- ret &= meta.save(m_url.path());
-
- if (!ret)
- {
- kDebug() << "Failed to update metadata in file " << \
m_url.fileName();
- }
- }
- else
- {
- kDebug() << "Failed to load metadata from file " << m_url.fileName();
- }
-
- if (!ret)
- {
- status |= MyImageList::META_TIME_ERROR;
- }
- }
-
- if (m_d->settings.updFileModDate)
- {
- // Since QFileInfo does not support timestamp updates, see Qt suggestion \
#79427 at
- // http://www.qtsoftware.com/developer/task-tracker/index_html?id=79427&method=entry
- // we have to use the utime() system call.
-
- utimbuf times;
- times.actime = QDateTime::currentDateTime().toTime_t();
- times.modtime = dt.toTime_t();
-
- if (utime(QFile::encodeName(m_url.toLocalFile()).constData(), ×) != 0)
- {
- status |= MyImageList::FILE_TIME_ERROR;
- }
- }
-
- if (m_d->settings.updFileName)
- {
- bool ret = true;
- KUrl newUrl = ActionThread::newUrl(m_url, dt);
-
- if (KDE_rename(QFile::encodeName(m_url.toLocalFile()), \
QFile::encodeName(newUrl.toLocalFile())) != 0)
- ret = false;
-
- ret &= KPMetadata::moveSidecar(m_url, newUrl);
-
- if (!ret)
- status |= MyImageList::FILE_NAME_ERROR;
- }
-
- if (m_d->settings.updAppDate)
- {
- KPImageInfo info(m_url);
- QDateTime dt = m_d->itemsMap.value(m_url);
- if (dt.isValid()) info.setDate(dt);
- }
-
- emit signalProcessEnded(m_url, status);
-}
-
-// ----------------------------------------------------------------------------------------------------
ActionThread::ActionThread(QObject* const parent)
: RActionThreadBase(parent), d(new Private)
@@ -238,16 +58,25 @@ ActionThread::ActionThread(QObject* const parent)
ActionThread::~ActionThread()
{
+ // cancel the thread
+ cancel();
+ // wait for the thread to finish
+ wait();
+
+ delete d;
+
}
void ActionThread::setUpdatedDates(const QMap<KUrl, QDateTime>& map)
{
d->itemsMap = map;
- JobCollection* collection = new JobCollection();
+ JobCollection* const collection = new JobCollection();
foreach (const KUrl& url, d->itemsMap.keys())
{
- Task* t = new Task(this, url, d);
+ Task* const t = new Task(this, url);
+ t->setSettings(d->settings);
+ t->setItemsMap(map);
connect(t, SIGNAL(signalProcessStarted(KUrl)),
this, SIGNAL(signalProcessStarted(KUrl)));
@@ -255,6 +84,9 @@ void ActionThread::setUpdatedDates(const QMap<KUrl, QDateTime>& \
map) connect(t, SIGNAL(signalProcessEnded(KUrl, int)),
this, SIGNAL(signalProcessEnded(KUrl, int)));
+ connect(this, SIGNAL(signalCancelTask()),
+ t, SLOT(slotCancel()), Qt::QueuedConnection);
+
collection->addJob(t);
}
@@ -268,10 +100,11 @@ void ActionThread::setSettings(const TimeAdjustSettings& \
settings)
void ActionThread::cancel()
{
- d->cancel = true;
+ if (isRunning())
+ emit signalCancelTask();
+
RActionThreadBase::cancel();
}
-
/** Static public method also called from GUI to update listview information about \
new filename
* computed with timeStamp.
*/
diff --git a/timeadjust/actionthread.h b/timeadjust/actionthread.h
index abe71df..58766f5 100644
--- a/timeadjust/actionthread.h
+++ b/timeadjust/actionthread.h
@@ -70,6 +70,8 @@ Q_SIGNALS:
void signalProcessStarted(const KUrl&);
void signalProcessEnded(const KUrl&, int);
+ void signalCancelTask();
+
public:
class Private;
@@ -78,34 +80,6 @@ private:
Private* const d;
};
-
-// ----------------------------------------------------------------------------------------------------
-
-class Task : public Job
-{
- Q_OBJECT
-
-public:
-
- Task(QObject* const parent, const KUrl& url, ActionThread::Private* const d);
- ~Task();
-
-Q_SIGNALS:
-
- void signalProcessStarted(const KUrl&);
- void signalProcessEnded(const KUrl&, int);
-
-protected:
-
- void run();
-
-private:
-
- QMutex m_mutex;
- KUrl m_url;
- ActionThread::Private* m_d;
-};
-
} // namespace KIPITimeAdjustPlugin
#endif /* ACTION_THREAD_H */
diff --git a/timeadjust/actionthread.cpp b/timeadjust/task.cpp
similarity index 56%
copy from timeadjust/actionthread.cpp
copy to timeadjust/task.cpp
index 18328c9..fc80777 100644
--- a/timeadjust/actionthread.cpp
+++ b/timeadjust/task.cpp
@@ -3,11 +3,10 @@
* This file is a part of kipi-plugins project
* http://www.digikam.org
*
- * Date : 2004-05-16
- * Description : a plugin to set time stamp of picture files.
+ * Date : 2012-12-31
+ * Description : a class to manage plugin actions using threads
*
- * Copyright (C) 2012 by Smit Mehta <smit dot meh at gmail dot com>
- * Copyright (C) 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
@@ -21,7 +20,7 @@
*
* ============================================================ */
-#include "actionthread.moc"
+#include "task.moc"
// C ANSI includes
@@ -47,22 +46,23 @@ extern "C"
#include "kpmetadata.h"
#include "kpimageinfo.h"
#include "myimagelist.h"
+#include "actionthread.h"
namespace KIPITimeAdjustPlugin
{
-
-class ActionThread::Private
+
+class Task::Private
{
public:
Private()
{
- cancel = false;
+ cancel = false;
}
- // To manage items processing.
- bool cancel;
-
+ bool cancel;
+ KUrl url;
+
// Settings from GUI.
TimeAdjustSettings settings;
@@ -70,32 +70,46 @@ public:
QMap<KUrl, QDateTime> itemsMap;
};
-// ----------------------------------------------------------------------------------------------------
-
-Task::Task(QObject* const parent, const KUrl& url, ActionThread::Private* const d)
- : Job(parent)
+Task::Task(QObject* const parent, const KUrl& url)
+ : Job(parent), d(new Private)
{
- m_url = url;
- m_d = d;
+ d->url = url;
}
Task::~Task()
{
+ slotCancel();
+ delete d;
+}
+
+void Task::slotCancel()
+{
+ d->cancel = true;
+}
+
+void Task::setSettings(const TimeAdjustSettings& settings)
+{
+ d->settings = settings;
+}
+
+void Task::setItemsMap(QMap<KUrl, QDateTime> itemsMap)
+{
+ d->itemsMap = itemsMap;
}
void Task::run()
{
- if (m_d->cancel) return;
+ if (d->cancel) return;
- QDateTime dt = m_d->itemsMap.value(m_url);
+ QDateTime dt = d->itemsMap.value(d->url);
if (!dt.isValid()) return;
- emit signalProcessStarted(m_url);
+ emit signalProcessStarted(d->url);
- bool metadataChanged = m_d->settings.updEXIFModDate || \
m_d->settings.updEXIFOriDate ||
- m_d->settings.updEXIFDigDate || m_d->settings.updIPTCDate \
||
- m_d->settings.updXMPDate;
+ bool metadataChanged = d->settings.updEXIFModDate || d->settings.updEXIFOriDate \
|| + d->settings.updEXIFDigDate || d->settings.updIPTCDate \
|| + d->settings.updXMPDate;
int status = MyImageList::NOPROCESS_ERROR;
@@ -105,37 +119,37 @@ void Task::run()
KPMetadata meta;
- ret &= meta.load(m_url.path());
+ ret &= meta.load(d->url.path());
if (ret)
{
- if (meta.canWriteExif(m_url.path()))
+ if (meta.canWriteExif(d->url.path()))
{
- if (m_d->settings.updEXIFModDate)
+ if (d->settings.updEXIFModDate)
{
ret &= meta.setExifTagString("Exif.Image.DateTime",
dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
}
- if (m_d->settings.updEXIFOriDate)
+ if (d->settings.updEXIFOriDate)
{
ret &= meta.setExifTagString("Exif.Photo.DateTimeOriginal",
dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
}
- if (m_d->settings.updEXIFDigDate)
+ if (d->settings.updEXIFDigDate)
{
ret &= meta.setExifTagString("Exif.Photo.DateTimeDigitized",
dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
}
}
- else if (m_d->settings.updEXIFModDate || m_d->settings.updEXIFOriDate || \
m_d->settings.updEXIFDigDate) + else if (d->settings.updEXIFModDate || \
d->settings.updEXIFOriDate || d->settings.updEXIFDigDate) {
ret = false;
}
- if (m_d->settings.updIPTCDate)
+ if (d->settings.updIPTCDate)
{
- if (meta.canWriteIptc(m_url.path()))
+ if (meta.canWriteIptc(d->url.path()))
{
ret &= meta.setIptcTagString("Iptc.Application2.DateCreated",
dt.date().toString(Qt::ISODate));
@@ -148,9 +162,9 @@ void Task::run()
}
}
- if (m_d->settings.updXMPDate)
+ if (d->settings.updXMPDate)
{
- if (meta.supportXmp() && meta.canWriteXmp(m_url.path()))
+ if (meta.supportXmp() && meta.canWriteXmp(d->url.path()))
{
ret &= meta.setXmpTagString("Xmp.exif.DateTimeOriginal",
dt.toString(QString("yyyy:MM:dd hh:mm:ss")).toAscii());
@@ -171,16 +185,16 @@ void Task::run()
}
}
- ret &= meta.save(m_url.path());
+ ret &= meta.save(d->url.path());
if (!ret)
{
- kDebug() << "Failed to update metadata in file " << \
m_url.fileName(); + kDebug() << "Failed to update metadata in file " \
<< d->url.fileName(); }
}
else
{
- kDebug() << "Failed to load metadata from file " << m_url.fileName();
+ kDebug() << "Failed to load metadata from file " << d->url.fileName();
}
if (!ret)
@@ -189,7 +203,7 @@ void Task::run()
}
}
- if (m_d->settings.updFileModDate)
+ if (d->settings.updFileModDate)
{
// Since QFileInfo does not support timestamp updates, see Qt suggestion \
#79427 at
// http://www.qtsoftware.com/developer/task-tracker/index_html?id=79427&method=entry
@@ -199,97 +213,33 @@ void Task::run()
times.actime = QDateTime::currentDateTime().toTime_t();
times.modtime = dt.toTime_t();
- if (utime(QFile::encodeName(m_url.toLocalFile()).constData(), ×) != 0)
+ if (utime(QFile::encodeName(d->url.toLocalFile()).constData(), ×) != 0)
{
status |= MyImageList::FILE_TIME_ERROR;
}
}
- if (m_d->settings.updFileName)
+ if (d->settings.updFileName)
{
bool ret = true;
- KUrl newUrl = ActionThread::newUrl(m_url, dt);
+ KUrl newUrl = ActionThread::newUrl(d->url, dt);
- if (KDE_rename(QFile::encodeName(m_url.toLocalFile()), \
QFile::encodeName(newUrl.toLocalFile())) != 0) + if \
(KDE_rename(QFile::encodeName(d->url.toLocalFile()), \
QFile::encodeName(newUrl.toLocalFile())) != 0) ret = false;
- ret &= KPMetadata::moveSidecar(m_url, newUrl);
+ ret &= KPMetadata::moveSidecar(d->url, newUrl);
if (!ret)
status |= MyImageList::FILE_NAME_ERROR;
}
- if (m_d->settings.updAppDate)
+ if (d->settings.updAppDate)
{
- KPImageInfo info(m_url);
- QDateTime dt = m_d->itemsMap.value(m_url);
+ KPImageInfo info(d->url);
+ QDateTime dt = d->itemsMap.value(d->url);
if (dt.isValid()) info.setDate(dt);
}
- emit signalProcessEnded(m_url, status);
-}
-
-// ----------------------------------------------------------------------------------------------------
-
-ActionThread::ActionThread(QObject* const parent)
- : RActionThreadBase(parent), d(new Private)
-{
-}
-
-ActionThread::~ActionThread()
-{
+ emit signalProcessEnded(d->url, status);
}
-
-void ActionThread::setUpdatedDates(const QMap<KUrl, QDateTime>& map)
-{
- d->itemsMap = map;
- JobCollection* collection = new JobCollection();
-
- foreach (const KUrl& url, d->itemsMap.keys())
- {
- Task* t = new Task(this, url, d);
-
- connect(t, SIGNAL(signalProcessStarted(KUrl)),
- this, SIGNAL(signalProcessStarted(KUrl)));
-
- connect(t, SIGNAL(signalProcessEnded(KUrl, int)),
- this, SIGNAL(signalProcessEnded(KUrl, int)));
-
- collection->addJob(t);
- }
-
- appendJob(collection);
-}
-
-void ActionThread::setSettings(const TimeAdjustSettings& settings)
-{
- d->settings = settings;
-}
-
-void ActionThread::cancel()
-{
- d->cancel = true;
- RActionThreadBase::cancel();
-}
-
-/** Static public method also called from GUI to update listview information about \
new filename
- * computed with timeStamp.
- */
-KUrl ActionThread::newUrl(const KUrl& url, const QDateTime& dt)
-{
- if (!dt.isValid()) return KUrl();
-
- QFileInfo fi(url.path());
-
- QString newFileName = fi.baseName();
- newFileName += '-';
- newFileName += dt.toString(QString("yyyyMMddThhmmss"));
- newFileName += '.';
- newFileName += fi.completeSuffix();
-
- KUrl newUrl = url;
- newUrl.setFileName(newFileName);
- return newUrl;
-}
-
-} // namespace KIPITimeAdjustPlugin
+} // namespace KIPITimeAdjustPlugin
\ No newline at end of file
diff --git a/timeadjust/actionthread.h b/timeadjust/task.h
similarity index 54%
copy from timeadjust/actionthread.h
copy to timeadjust/task.h
index abe71df..5e35f3d 100644
--- a/timeadjust/actionthread.h
+++ b/timeadjust/task.h
@@ -3,11 +3,10 @@
* This file is a part of kipi-plugins project
* http://www.digikam.org
*
- * Date : 2004-05-16
- * Description : a plugin to set time stamp of picture files.
+ * Date : 2012-12-31
+ * Description : a class to manage plugin actions using threads
*
- * Copyright (C) 2012 by Smit Mehta <smit dot meh at gmail dot com>
- * Copyright (C) 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
@@ -21,15 +20,9 @@
*
* ============================================================ */
-#ifndef ACTION_THREAD_H
-#define ACTION_THREAD_H
-// Qt includes
-
-#include <QObject>
-#include <QDateTime>
-#include <QMutex>
-#include <QMap>
+#ifndef TASK_H
+#define TASK_H
// KDE includes
@@ -50,45 +43,17 @@ using namespace ThreadWeaver;
namespace KIPITimeAdjustPlugin
{
-class ActionThread : public RActionThreadBase
-{
- Q_OBJECT
-
-public:
-
- ActionThread(QObject* const parent);
- ~ActionThread();
-
- void setUpdatedDates(const QMap<KUrl, QDateTime>& map);
- void setSettings(const TimeAdjustSettings& settings);
- void cancel();
-
- static KUrl newUrl(const KUrl& url, const QDateTime& dt);
-
-Q_SIGNALS:
-
- void signalProcessStarted(const KUrl&);
- void signalProcessEnded(const KUrl&, int);
-
-public:
-
- class Private;
-
-private:
-
- Private* const d;
-};
-
-// ----------------------------------------------------------------------------------------------------
-
class Task : public Job
{
Q_OBJECT
public:
- Task(QObject* const parent, const KUrl& url, ActionThread::Private* const d);
+ Task(QObject* const parent, const KUrl& url);
~Task();
+
+ void setSettings(const TimeAdjustSettings& settings);
+ void setItemsMap(QMap<KUrl, QDateTime> itemsMap);
Q_SIGNALS:
@@ -99,13 +64,16 @@ protected:
void run();
+public Q_SLOTS:
+
+ void slotCancel();
+
private:
- QMutex m_mutex;
- KUrl m_url;
- ActionThread::Private* m_d;
+ class Private;
+ Private* const d;
};
} // namespace KIPITimeAdjustPlugin
-#endif /* ACTION_THREAD_H */
+#endif /* TASK_H */
\ No newline at end of file
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic