| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2004-06-15 |
| 7 |
* Description : Albums manager interface - Face Album helpers. |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2006-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 10 |
* SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> |
| 11 |
* SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com> |
| 12 |
* |
| 13 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 14 |
* |
| 15 |
* ============================================================ */ |
| 16 |
|
| 17 |
#include "albummanager_p.h" |
| 18 |
|
| 19 |
namespace Digikam |
| 20 |
{ |
| 21 |
|
| 22 |
QHash<int, int> AlbumManager::getFaceCount() const |
| 23 |
{ |
| 24 |
return d->fAlbumsCount; |
| 25 |
} |
| 26 |
|
| 27 |
QHash<int, int> AlbumManager::getUnconfirmedFaceCount() const |
| 28 |
{ |
| 29 |
return d->uAlbumsCount; |
| 30 |
} |
| 31 |
|
| 32 |
void AlbumManager::personItemsCount() |
| 33 |
{ |
| 34 |
if (d->personListJob) |
| 35 |
{ |
| 36 |
disconnect(d->personListJob, nullptr, |
| 37 |
this, nullptr); |
| 38 |
|
| 39 |
d->personListJob->cancel(); |
| 40 |
d->personListJob = nullptr; |
| 41 |
} |
| 42 |
|
| 43 |
TagsDBJobInfo jInfo; |
| 44 |
jInfo.setFaceFoldersJob(); |
| 45 |
|
| 46 |
d->personListJob = DBJobsManager::instance()->startTagsJobThread(jInfo); |
| 47 |
|
| 48 |
connect(d->personListJob, SIGNAL(signalFinished()), |
| 49 |
this, SLOT(slotPeopleJobResult())); |
| 50 |
|
| 51 |
connect(d->personListJob, SIGNAL(faceFoldersData(QMap<QString,QHash<int,int> >)), // krazy:exclude=normalize |
| 52 |
this, SLOT(slotPeopleJobData(QMap<QString,QHash<int,int> >))); // krazy:exclude=normalize |
| 53 |
} |
| 54 |
|
| 55 |
void AlbumManager::slotPeopleJobResult() |
| 56 |
{ |
| 57 |
if (!d->personListJob) |
| 58 |
{ |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
if (d->personListJob->hasErrors()) |
| 63 |
{ |
| 64 |
qCWarning(DIGIKAM_GENERAL_LOG) << "Failed to list face tags"; |
| 65 |
|
| 66 |
// Pop-up a message about the error. |
| 67 |
|
| 68 |
DNotificationWrapper(QString(), d->personListJob->errorsList().first(), |
| 69 |
nullptr, i18n("digiKam")); |
| 70 |
} |
| 71 |
|
| 72 |
d->personListJob = nullptr; |
| 73 |
} |
| 74 |
|
| 75 |
void AlbumManager::slotPeopleJobData(const QMap<QString, QHash<int, int> >& facesStatHash) |
| 76 |
{ |
| 77 |
if (facesStatHash.isEmpty()) |
| 78 |
{ |
| 79 |
return; |
| 80 |
} |
| 81 |
|
| 82 |
d->uAlbumsCount.clear(); |
| 83 |
|
| 84 |
// I think this is a bug |
| 85 |
// Why autodetectedFace have all autodetected tags? |
| 86 |
// They should be in autodetectedPerson |
| 87 |
|
| 88 |
if (facesStatHash.contains(ImageTagPropertyName::autodetectedFace())) // autodetectedPerson |
| 89 |
{ |
| 90 |
d->uAlbumsCount = *facesStatHash.find(ImageTagPropertyName::autodetectedFace()); // autodetectedPerson |
| 91 |
} |
| 92 |
|
| 93 |
d->fAlbumsCount.clear(); |
| 94 |
|
| 95 |
if (ApplicationSettings::instance()->getShowFolderTreeViewItemsCount()) |
| 96 |
{ |
| 97 |
typedef QHash<int, int> IntIntHash; |
| 98 |
|
| 99 |
for (const IntIntHash& counts : std::as_const(facesStatHash)) |
| 100 |
{ |
| 101 |
QHash<int, int>::const_iterator it; |
| 102 |
|
| 103 |
for (it = counts.begin() ; it != counts.end() ; ++it) |
| 104 |
{ |
| 105 |
d->fAlbumsCount[it.key()] += it.value(); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
Q_EMIT signalFaceCountsDirty(d->fAlbumsCount, d->uAlbumsCount, d->toUpdatedFaces); |
| 111 |
|
| 112 |
d->toUpdatedFaces.clear(); |
| 113 |
} |
| 114 |
|
| 115 |
} // namespace Digikam |