| 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 - Collection 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 |
bool AlbumManager::handleCollectionStatusChange(const CollectionLocation& location, int oldStatus) |
| 23 |
{ |
| 24 |
enum Action |
| 25 |
{ |
| 26 |
Add, |
| 27 |
Remove, |
| 28 |
DoNothing |
| 29 |
}; |
| 30 |
Action action = DoNothing; |
| 31 |
|
| 32 |
switch (oldStatus) |
| 33 |
{ |
| 34 |
case CollectionLocation::LocationNull: |
| 35 |
case CollectionLocation::LocationHidden: |
| 36 |
case CollectionLocation::LocationUnavailable: |
| 37 |
{ |
| 38 |
switch (location.status()) |
| 39 |
{ |
| 40 |
case CollectionLocation::LocationNull: // not possible |
| 41 |
{ |
| 42 |
break; |
| 43 |
} |
| 44 |
|
| 45 |
case CollectionLocation::LocationHidden: |
| 46 |
{ |
| 47 |
action = Remove; |
| 48 |
break; |
| 49 |
} |
| 50 |
|
| 51 |
case CollectionLocation::LocationAvailable: |
| 52 |
{ |
| 53 |
action = Add; |
| 54 |
break; |
| 55 |
} |
| 56 |
|
| 57 |
case CollectionLocation::LocationUnavailable: |
| 58 |
{ |
| 59 |
if (d->showOnlyAvailableAlbums) |
| 60 |
{ |
| 61 |
action = Remove; |
| 62 |
} |
| 63 |
else |
| 64 |
{ |
| 65 |
action = Add; |
| 66 |
} |
| 67 |
|
| 68 |
break; |
| 69 |
} |
| 70 |
|
| 71 |
case CollectionLocation::LocationDeleted: |
| 72 |
{ |
| 73 |
action = Remove; |
| 74 |
break; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
break; |
| 79 |
} |
| 80 |
|
| 81 |
case CollectionLocation::LocationAvailable: |
| 82 |
{ |
| 83 |
switch (location.status()) |
| 84 |
{ |
| 85 |
case CollectionLocation::LocationNull: |
| 86 |
case CollectionLocation::LocationHidden: |
| 87 |
case CollectionLocation::LocationDeleted: |
| 88 |
{ |
| 89 |
action = Remove; |
| 90 |
break; |
| 91 |
} |
| 92 |
|
| 93 |
case CollectionLocation::LocationUnavailable: |
| 94 |
{ |
| 95 |
if (d->showOnlyAvailableAlbums) |
| 96 |
{ |
| 97 |
action = Remove; |
| 98 |
} |
| 99 |
|
| 100 |
break; |
| 101 |
} |
| 102 |
|
| 103 |
case CollectionLocation::LocationAvailable: // not possible |
| 104 |
{ |
| 105 |
break; |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
break; |
| 110 |
} |
| 111 |
|
| 112 |
case CollectionLocation::LocationDeleted: // not possible |
| 113 |
{ |
| 114 |
break; |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
if ((action == Add) && !d->albumRootAlbumHash.value(location.id())) |
| 119 |
{ |
| 120 |
// This is the only place where album root albums are added |
| 121 |
|
| 122 |
addAlbumRoot(location); |
| 123 |
return true; |
| 124 |
} |
| 125 |
else if ((action == Remove) && d->albumRootAlbumHash.value(location.id())) |
| 126 |
{ |
| 127 |
removeAlbumRoot(location); |
| 128 |
return true; |
| 129 |
} |
| 130 |
|
| 131 |
return false; |
| 132 |
} |
| 133 |
|
| 134 |
void AlbumManager::addAlbumRoot(const CollectionLocation& location) |
| 135 |
{ |
| 136 |
PAlbum* album = d->albumRootAlbumHash.value(location.id()); |
| 137 |
|
| 138 |
if (!album) |
| 139 |
{ |
| 140 |
// Create a PAlbum for the Album Root. |
| 141 |
|
| 142 |
QString label = d->labelForAlbumRootAlbum(location); |
| 143 |
album = new PAlbum(location.id(), label); |
| 144 |
|
| 145 |
qCDebug(DIGIKAM_GENERAL_LOG) << "Added root album called: " << album->title(); |
| 146 |
|
| 147 |
// insert album root created into hash |
| 148 |
|
| 149 |
d->albumRootAlbumHash.insert(location.id(), album); |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
void AlbumManager::removeAlbumRoot(const CollectionLocation& location) |
| 154 |
{ |
| 155 |
// retrieve and remove from hash |
| 156 |
|
| 157 |
PAlbum* const album = d->albumRootAlbumHash.take(location.id()); |
| 158 |
|
| 159 |
if (album) |
| 160 |
{ |
| 161 |
// delete album and all its children |
| 162 |
|
| 163 |
removePAlbum(album); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
void AlbumManager::slotCollectionLocationStatusChanged(const CollectionLocation& location, int oldStatus) |
| 168 |
{ |
| 169 |
// not before initialization |
| 170 |
|
| 171 |
if (!d->rootPAlbum) |
| 172 |
{ |
| 173 |
return; |
| 174 |
} |
| 175 |
|
| 176 |
if (handleCollectionStatusChange(location, oldStatus)) |
| 177 |
{ |
| 178 |
// a change occurred. Possibly albums have appeared or disappeared |
| 179 |
|
| 180 |
if (!d->scanPAlbumsTimer->isActive()) |
| 181 |
{ |
| 182 |
d->scanPAlbumsTimer->start(); |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 187 |
void AlbumManager::slotCollectionLocationPropertiesChanged(const CollectionLocation& location) |
| 188 |
{ |
| 189 |
PAlbum* const album = d->albumRootAlbumHash.value(location.id()); |
| 190 |
|
| 191 |
if (album) |
| 192 |
{ |
| 193 |
QString newLabel = d->labelForAlbumRootAlbum(location); |
| 194 |
|
| 195 |
if (album->title() != newLabel) |
| 196 |
{ |
| 197 |
album->setTitle(newLabel); |
| 198 |
|
| 199 |
Q_EMIT signalAlbumRenamed(album); |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
void AlbumManager::slotCollectionImageChange(const CollectionImageChangeset& changeset) |
| 205 |
{ |
| 206 |
if (!d->rootDAlbum) |
| 207 |
{ |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
switch (changeset.operation()) |
| 212 |
{ |
| 213 |
case CollectionImageChangeset::Added: |
| 214 |
case CollectionImageChangeset::Deleted: |
| 215 |
case CollectionImageChangeset::Removed: |
| 216 |
case CollectionImageChangeset::RemovedAll: |
| 217 |
{ |
| 218 |
if (!d->albumItemCountTimer->isActive()) |
| 219 |
{ |
| 220 |
d->albumItemCountTimer->start(); |
| 221 |
} |
| 222 |
|
| 223 |
if (!d->scanDAlbumsTimer->isActive()) |
| 224 |
{ |
| 225 |
d->scanDAlbumsTimer->start(); |
| 226 |
} |
| 227 |
|
| 228 |
break; |
| 229 |
} |
| 230 |
|
| 231 |
default: |
| 232 |
{ |
| 233 |
break; |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
} // namespace Digikam |