File indexing completed on 2025-01-19 03:59:30
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-05-16 0007 * Description : fingerprints generator 0008 * 0009 * SPDX-FileCopyrightText: 2018 by Mario Frank <mario dot frank at uni minus potsdam dot de> 0010 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * SPDX-FileCopyrightText: 2012 by Andi Clemens <andi dot clemens at gmail dot com> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "fingerprintsgenerator.h" 0018 0019 // Qt includes 0020 0021 #include <QApplication> 0022 #include <QString> 0023 #include <QIcon> 0024 0025 // KDE includes 0026 0027 #include <kconfiggroup.h> 0028 #include <klocalizedstring.h> 0029 #include <ksharedconfig.h> 0030 0031 // Local includes 0032 0033 #include "dimg.h" 0034 #include "coredb.h" 0035 #include "albummanager.h" 0036 #include "coredbaccess.h" 0037 #include "maintenancethread.h" 0038 0039 namespace Digikam 0040 { 0041 0042 class Q_DECL_HIDDEN FingerPrintsGenerator::Private 0043 { 0044 public: 0045 0046 explicit Private() 0047 : rebuildAll(true), 0048 thread(nullptr) 0049 { 0050 } 0051 0052 bool rebuildAll; 0053 0054 AlbumList albumList; 0055 0056 MaintenanceThread* thread; 0057 }; 0058 0059 FingerPrintsGenerator::FingerPrintsGenerator(const bool rebuildAll, const AlbumList& list, ProgressItem* const parent) 0060 : MaintenanceTool(QLatin1String("FingerPrintsGenerator"), parent), 0061 d(new Private) 0062 { 0063 d->albumList = list; 0064 d->rebuildAll = rebuildAll; 0065 d->thread = new MaintenanceThread(this); 0066 0067 connect(d->thread, SIGNAL(signalCompleted()), 0068 this, SLOT(slotDone())); 0069 0070 connect(d->thread, SIGNAL(signalAdvance(QImage)), 0071 this, SLOT(slotAdvance(QImage))); 0072 } 0073 0074 FingerPrintsGenerator::~FingerPrintsGenerator() 0075 { 0076 delete d; 0077 } 0078 0079 void FingerPrintsGenerator::setUseMultiCoreCPU(bool b) 0080 { 0081 d->thread->setUseMultiCore(b); 0082 } 0083 0084 void FingerPrintsGenerator::slotCancel() 0085 { 0086 d->thread->cancel(); 0087 MaintenanceTool::slotCancel(); 0088 } 0089 0090 void FingerPrintsGenerator::slotStart() 0091 { 0092 MaintenanceTool::slotStart(); 0093 0094 setLabel(i18n("Finger-prints")); 0095 0096 ProgressManager::addProgressItem(this); 0097 0098 QApplication::setOverrideCursor(Qt::WaitCursor); 0099 0100 if (d->albumList.isEmpty()) 0101 { 0102 d->albumList = AlbumManager::instance()->allPAlbums(); 0103 } 0104 0105 // Get all item IDs from albums. 0106 0107 QList<qlonglong> itemIds; 0108 0109 for (AlbumList::ConstIterator it = d->albumList.constBegin() ; 0110 !canceled() && (it != d->albumList.constEnd()) ; ++it) 0111 { 0112 if ((*it)->type() == Album::PHYSICAL) 0113 { 0114 Q_FOREACH (const qlonglong& id, CoreDbAccess().db()->getItemIDsInAlbum((*it)->id())) 0115 { 0116 if (!itemIds.contains(id)) 0117 { 0118 itemIds << id; 0119 } 0120 } 0121 } 0122 else if ((*it)->type() == Album::TAG) 0123 { 0124 Q_FOREACH (const qlonglong& id, CoreDbAccess().db()->getItemIDsInTag((*it)->id())) 0125 { 0126 if (!itemIds.contains(id)) 0127 { 0128 itemIds << id; 0129 } 0130 } 0131 } 0132 } 0133 0134 QApplication::restoreOverrideCursor(); 0135 0136 if (itemIds.isEmpty()) 0137 { 0138 slotDone(); 0139 return; 0140 } 0141 0142 setTotalItems(itemIds.count()); 0143 0144 d->thread->generateFingerprints(itemIds, d->rebuildAll); 0145 d->thread->start(); 0146 } 0147 0148 void FingerPrintsGenerator::slotAdvance(const QImage& img) 0149 { 0150 setThumbnail(QIcon(QPixmap::fromImage(img))); 0151 advance(1); 0152 } 0153 0154 void FingerPrintsGenerator::slotDone() 0155 { 0156 // Switch on scanned for finger-prints flag on digiKam config file. 0157 KSharedConfig::openConfig()->group(QLatin1String("General Settings")).writeEntry(QLatin1String("Finger Prints Generator First Run"), true); 0158 0159 MaintenanceTool::slotDone(); 0160 } 0161 0162 } // namespace Digikam 0163 0164 #include "moc_fingerprintsgenerator.cpp"