File indexing completed on 2025-01-19 03:53:20
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2004-06-15 0007 * Description : Albums manager interface - Face Album helpers. 0008 * 0009 * SPDX-FileCopyrightText: 2006-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0011 * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> 0012 * 0013 * SPDX-License-Identifier: GPL-2.0-or-later 0014 * 0015 * ============================================================ */ 0016 0017 #include "albummanager_p.h" 0018 0019 namespace Digikam 0020 { 0021 0022 QHash<int, int> AlbumManager::getFaceCount() const 0023 { 0024 return d->fAlbumsCount; 0025 } 0026 0027 QHash<int, int> AlbumManager::getUnconfirmedFaceCount() const 0028 { 0029 return d->uAlbumsCount; 0030 } 0031 0032 void AlbumManager::personItemsCount() 0033 { 0034 if (d->personListJob) 0035 { 0036 disconnect(d->personListJob, nullptr, this, nullptr); 0037 0038 d->personListJob->cancel(); 0039 d->personListJob = nullptr; 0040 } 0041 0042 TagsDBJobInfo jInfo; 0043 jInfo.setFaceFoldersJob(); 0044 0045 d->personListJob = DBJobsManager::instance()->startTagsJobThread(jInfo); 0046 0047 connect(d->personListJob, SIGNAL(finished()), 0048 this, SLOT(slotPeopleJobResult())); 0049 0050 connect(d->personListJob, SIGNAL(faceFoldersData(QMap<QString,QHash<int,int> >)), // krazy:exclude=normalize 0051 this, SLOT(slotPeopleJobData(QMap<QString,QHash<int,int> >))); // krazy:exclude=normalize 0052 } 0053 0054 void AlbumManager::slotPeopleJobResult() 0055 { 0056 if (!d->personListJob) 0057 { 0058 return; 0059 } 0060 0061 if (d->personListJob->hasErrors()) 0062 { 0063 qCWarning(DIGIKAM_GENERAL_LOG) << "Failed to list face tags"; 0064 0065 // Pop-up a message about the error. 0066 0067 DNotificationWrapper(QString(), d->personListJob->errorsList().first(), 0068 nullptr, i18n("digiKam")); 0069 } 0070 0071 d->personListJob = nullptr; 0072 } 0073 0074 void AlbumManager::slotPeopleJobData(const QMap<QString, QHash<int, int> >& facesStatHash) 0075 { 0076 if (facesStatHash.isEmpty()) 0077 { 0078 return; 0079 } 0080 0081 d->uAlbumsCount.clear(); 0082 0083 // I think this is a bug 0084 // Why autodetectedFace have all autodetected tags? 0085 // They should be in autodetectedPerson 0086 0087 if (facesStatHash.contains(ImageTagPropertyName::autodetectedFace())) // autodetectedPerson 0088 { 0089 d->uAlbumsCount = *facesStatHash.find(ImageTagPropertyName::autodetectedFace()); // autodetectedPerson 0090 } 0091 0092 d->fAlbumsCount.clear(); 0093 0094 if (ApplicationSettings::instance()->getShowFolderTreeViewItemsCount()) 0095 { 0096 typedef QHash<int, int> IntIntHash; 0097 0098 Q_FOREACH (const IntIntHash& counts, facesStatHash) 0099 { 0100 QHash<int, int>::const_iterator it; 0101 0102 for (it = counts.begin() ; it != counts.end() ; ++it) 0103 { 0104 d->fAlbumsCount[it.key()] += it.value(); 0105 } 0106 } 0107 } 0108 0109 Q_EMIT signalFaceCountsDirty(d->fAlbumsCount, d->uAlbumsCount, d->toUpdatedFaces); 0110 0111 d->toUpdatedFaces.clear(); 0112 } 0113 0114 } // namespace Digikam