Commit 48b47b54 authored by Gilles Caulier's avatar Gilles Caulier 🗼
Browse files

Maintenance tool : Thumbs Generator now support multi-core CPU

CCBUGS: 289204
parent 0a53da45
......@@ -1265,6 +1265,7 @@ IF(DIGIKAM_CAN_BE_COMPILED)
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/newitemsfinder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/facedetector.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/thumbsgenerator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/thumbstask.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/fingerprintsgenerator.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/maintenancedlg.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utilities/maintenance/maintenancemngr.cpp
......
......@@ -32,6 +32,7 @@
// Local includes
#include "metadatatask.h"
#include "thumbstask.h"
using namespace Solid;
......@@ -86,10 +87,26 @@ void MaintenanceThread::syncMetadata(const ImageInfoList& items, MetadataSynchro
void MaintenanceThread::generateThumbs(const QStringList& paths)
{
// TODO
JobCollection* const collection = new JobCollection();
for(int i=0; i < paths.size(); i++)
{
ThumbsTask* const t = new ThumbsTask();
t->setItem(paths.at(i));
connect(t, SIGNAL(signalFinished(QPixmap)),
this, SIGNAL(signalAdvance(QPixmap)));
connect(this, SIGNAL(signalCanceled()),
t, SLOT(slotCancel()), Qt::QueuedConnection);
collection->addJob(t);
}
appendJob(collection);
}
void MaintenanceThread::generateFingerprints(const QStringList& paths)
void MaintenanceThread::generateFingerprints(const QStringList& /*paths*/)
{
// TODO
}
......
......@@ -33,6 +33,8 @@
#include "metadatasynchronizer.h"
#include "imageinfo.h"
class QPixmap;
using namespace KDcrawIface;
namespace Digikam
......@@ -60,6 +62,7 @@ Q_SIGNALS:
/** Emit when an item have been processed.
*/
void signalAdvance();
void signalAdvance(const QPixmap&);
/** Emit when a items list have been fully processed.
*/
......
......@@ -32,7 +32,6 @@
#include "collectionscanner.h"
#include "metadatahub.h"
#include "imageinfo.h"
namespace Digikam
{
......@@ -83,11 +82,11 @@ void MetadataTask::run()
{
return;
}
if (d->direction == MetadataSynchronizer::WriteFromDatabaseToFile)
{
MetadataHub fileHub;
// read in from database
fileHub.load(d->item);
......
......@@ -45,10 +45,9 @@
#include "albumsettings.h"
#include "databaseaccess.h"
#include "imageinfo.h"
#include "thumbnailloadthread.h"
#include "thumbnailsize.h"
#include "thumbnaildatabaseaccess.h"
#include "thumbnaildb.h"
#include "maintenancethread.h"
#include "config-digikam.h"
namespace Digikam
......@@ -60,17 +59,17 @@ public:
Private() :
rebuildAll(true),
thumbLoadThread(0)
thread(0)
{
}
bool rebuildAll;
bool rebuildAll;
AlbumList albumList;
AlbumList albumList;
QStringList allPicturesPath;
QStringList allPicturesPath;
ThumbnailLoadThread* thumbLoadThread;
MaintenanceThread* thread;
};
ThumbsGenerator::ThumbsGenerator(const bool rebuildAll, const AlbumList& list, ProgressItem* const parent)
......@@ -89,21 +88,30 @@ ThumbsGenerator::ThumbsGenerator(const bool rebuildAll, int albumId, ProgressIte
init(rebuildAll);
}
ThumbsGenerator::~ThumbsGenerator()
{
delete d;
}
void ThumbsGenerator::init(const bool rebuildAll)
{
setLabel(i18n("Thumbs"));
ProgressManager::addProgressItem(this);
d->rebuildAll = rebuildAll;
d->thumbLoadThread = ThumbnailLoadThread::defaultThread();
d->rebuildAll = rebuildAll;
d->thread = new MaintenanceThread(this);
connect(d->thumbLoadThread, SIGNAL(signalThumbnailLoaded(LoadingDescription,QPixmap)),
this, SLOT(slotGotThumbnail(LoadingDescription,QPixmap)));
connect(d->thread, SIGNAL(signalCompleted()),
this, SLOT(slotDone()));
connect(d->thread, SIGNAL(signalAdvance(QPixmap)),
this, SLOT(slotAdvance(QPixmap)));
}
ThumbsGenerator::~ThumbsGenerator()
void ThumbsGenerator::slotCancel()
{
delete d;
d->thread->cancel();
MaintenanceTool::slotCancel();
}
void ThumbsGenerator::slotStart()
......@@ -173,56 +181,16 @@ void ThumbsGenerator::slotStart()
}
setTotalItems(d->allPicturesPath.count());
processOne();
}
void ThumbsGenerator::processOne()
{
if (canceled())
{
slotCancel();
return;
}
if (d->allPicturesPath.isEmpty())
{
slotDone();
return;
}
QString path = d->allPicturesPath.first();
d->thumbLoadThread->deleteThumbnail(path);
d->thumbLoadThread->find(path);
d->thread->setUseMultiCore(true);
d->thread->generateThumbs(d->allPicturesPath);
d->thread->start();
}
void ThumbsGenerator::slotGotThumbnail(const LoadingDescription& desc, const QPixmap& pix)
void ThumbsGenerator::slotAdvance(const QPixmap& pix)
{
if (d->allPicturesPath.isEmpty())
{
return;
}
if (d->allPicturesPath.first() != desc.filePath)
{
return;
}
setThumbnail(pix);
advance(1);
if (!d->allPicturesPath.isEmpty())
{
d->allPicturesPath.removeFirst();
}
if (d->allPicturesPath.isEmpty())
{
slotDone();
}
else
{
processOne();
}
}
} // namespace Digikam
......@@ -36,8 +36,6 @@
namespace Digikam
{
class LoadingDescription;
class ThumbsGenerator : public MaintenanceTool
{
Q_OBJECT
......@@ -56,12 +54,12 @@ public:
private:
void init(const bool rebuildAll);
void processOne();
private Q_SLOTS:
void slotStart();
void slotGotThumbnail(const LoadingDescription&, const QPixmap&);
void slotCancel();
void slotAdvance(const QPixmap&);
private:
......
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2013-08-14
* Description : Thread actions task for thumbs generator.
*
* Copyright (C) 2013 by Gilles Caulier <caulier dot gilles 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 "thumbstask.moc"
// KDE includes
#include <kdebug.h>
#include <threadweaver/ThreadWeaver.h>
// Local includes
#include "thumbnailloadthread.h"
#include "thumbnailsize.h"
namespace Digikam
{
class ThumbsTask::Private
{
public:
Private()
{
cancel = false;
thumbLoadThread = ThumbnailLoadThread::defaultThread();
}
bool cancel;
QString path;
ThumbnailLoadThread* thumbLoadThread;
};
// -------------------------------------------------------
ThumbsTask::ThumbsTask()
: Job(0), d(new Private)
{
connect(d->thumbLoadThread, SIGNAL(signalThumbnailLoaded(LoadingDescription, QPixmap)),
this, SLOT(slotGotThumbnail(LoadingDescription, QPixmap)));
}
ThumbsTask::~ThumbsTask()
{
slotCancel();
delete d;
}
void ThumbsTask::setItem(const QString& path)
{
d->path = path;
}
void ThumbsTask::slotCancel()
{
d->cancel = true;
}
void ThumbsTask::run()
{
if(d->cancel)
{
return;
}
d->thumbLoadThread->deleteThumbnail(d->path);
d->thumbLoadThread->find(d->path);
}
void ThumbsTask::slotGotThumbnail(const LoadingDescription& desc, const QPixmap& pix)
{
if (d->path != desc.filePath)
{
return;
}
emit signalFinished(pix);
}
} // namespace Digikam
/* ============================================================
*
* This file is a part of digiKam project
* http://www.digikam.org
*
* Date : 2013-08-14
* Description : Thread actions task for thumbs generator.
*
* Copyright (C) 2013 by Gilles Caulier <caulier dot gilles 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 THUMBS_TASK_H
#define THUMBS_TASK_H
// Qt includes
#include <QPixmap>
#include <QThread>
// KDE includes
#include <threadweaver/Job.h>
using namespace ThreadWeaver;
namespace Digikam
{
class LoadingDescription;
class ThumbsTask : public Job
{
Q_OBJECT
public:
ThumbsTask();
~ThumbsTask();
void setItem(const QString& path);
Q_SIGNALS:
void signalFinished(const QPixmap&);
public Q_SLOTS:
void slotCancel();
protected:
void run();
private Q_SLOTS:
void slotGotThumbnail(const LoadingDescription&, const QPixmap&);
private:
class Private;
Private* const d;
};
} // namespace Digikam
#endif /* THUMBS_TASK_H */
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