File indexing completed on 2025-01-19 03:53:19
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 - Collection 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 bool AlbumManager::handleCollectionStatusChange(const CollectionLocation& location, int oldStatus) 0023 { 0024 enum Action 0025 { 0026 Add, 0027 Remove, 0028 DoNothing 0029 }; 0030 Action action = DoNothing; 0031 0032 switch (oldStatus) 0033 { 0034 case CollectionLocation::LocationNull: 0035 case CollectionLocation::LocationHidden: 0036 case CollectionLocation::LocationUnavailable: 0037 { 0038 switch (location.status()) 0039 { 0040 case CollectionLocation::LocationNull: // not possible 0041 { 0042 break; 0043 } 0044 0045 case CollectionLocation::LocationHidden: 0046 { 0047 action = Remove; 0048 break; 0049 } 0050 0051 case CollectionLocation::LocationAvailable: 0052 { 0053 action = Add; 0054 break; 0055 } 0056 0057 case CollectionLocation::LocationUnavailable: 0058 { 0059 if (d->showOnlyAvailableAlbums) 0060 { 0061 action = Remove; 0062 } 0063 else 0064 { 0065 action = Add; 0066 } 0067 0068 break; 0069 } 0070 0071 case CollectionLocation::LocationDeleted: 0072 { 0073 action = Remove; 0074 break; 0075 } 0076 } 0077 0078 break; 0079 } 0080 case CollectionLocation::LocationAvailable: 0081 { 0082 switch (location.status()) 0083 { 0084 case CollectionLocation::LocationNull: 0085 case CollectionLocation::LocationHidden: 0086 case CollectionLocation::LocationDeleted: 0087 { 0088 action = Remove; 0089 break; 0090 } 0091 0092 case CollectionLocation::LocationUnavailable: 0093 { 0094 if (d->showOnlyAvailableAlbums) 0095 { 0096 action = Remove; 0097 } 0098 0099 break; 0100 } 0101 0102 case CollectionLocation::LocationAvailable: // not possible 0103 { 0104 break; 0105 } 0106 } 0107 0108 break; 0109 } 0110 0111 case CollectionLocation::LocationDeleted: // not possible 0112 { 0113 break; 0114 } 0115 } 0116 0117 if ((action == Add) && !d->albumRootAlbumHash.value(location.id())) 0118 { 0119 // This is the only place where album root albums are added 0120 0121 addAlbumRoot(location); 0122 return true; 0123 } 0124 else if (action == Remove && d->albumRootAlbumHash.value(location.id())) 0125 { 0126 removeAlbumRoot(location); 0127 return true; 0128 } 0129 0130 return false; 0131 } 0132 0133 void AlbumManager::addAlbumRoot(const CollectionLocation& location) 0134 { 0135 PAlbum* album = d->albumRootAlbumHash.value(location.id()); 0136 0137 if (!album) 0138 { 0139 // Create a PAlbum for the Album Root. 0140 0141 QString label = d->labelForAlbumRootAlbum(location); 0142 album = new PAlbum(location.id(), label); 0143 0144 qCDebug(DIGIKAM_GENERAL_LOG) << "Added root album called: " << album->title(); 0145 0146 // insert album root created into hash 0147 0148 d->albumRootAlbumHash.insert(location.id(), album); 0149 } 0150 } 0151 0152 void AlbumManager::removeAlbumRoot(const CollectionLocation& location) 0153 { 0154 // retrieve and remove from hash 0155 0156 PAlbum* const album = d->albumRootAlbumHash.take(location.id()); 0157 0158 if (album) 0159 { 0160 // delete album and all its children 0161 0162 removePAlbum(album); 0163 } 0164 } 0165 0166 void AlbumManager::slotCollectionLocationStatusChanged(const CollectionLocation& location, int oldStatus) 0167 { 0168 // not before initialization 0169 0170 if (!d->rootPAlbum) 0171 { 0172 return; 0173 } 0174 0175 if (handleCollectionStatusChange(location, oldStatus)) 0176 { 0177 // a change occurred. Possibly albums have appeared or disappeared 0178 0179 if (!d->scanPAlbumsTimer->isActive()) 0180 { 0181 d->scanPAlbumsTimer->start(); 0182 } 0183 } 0184 } 0185 0186 void AlbumManager::slotCollectionLocationPropertiesChanged(const CollectionLocation& location) 0187 { 0188 PAlbum* const album = d->albumRootAlbumHash.value(location.id()); 0189 0190 if (album) 0191 { 0192 QString newLabel = d->labelForAlbumRootAlbum(location); 0193 0194 if (album->title() != newLabel) 0195 { 0196 album->setTitle(newLabel); 0197 Q_EMIT signalAlbumRenamed(album); 0198 } 0199 } 0200 } 0201 0202 void AlbumManager::slotCollectionImageChange(const CollectionImageChangeset& changeset) 0203 { 0204 if (!d->rootDAlbum) 0205 { 0206 return; 0207 } 0208 0209 switch (changeset.operation()) 0210 { 0211 case CollectionImageChangeset::Added: 0212 case CollectionImageChangeset::Deleted: 0213 case CollectionImageChangeset::Removed: 0214 case CollectionImageChangeset::RemovedAll: 0215 { 0216 if (!d->albumItemCountTimer->isActive()) 0217 { 0218 d->albumItemCountTimer->start(); 0219 } 0220 0221 if (!d->scanDAlbumsTimer->isActive()) 0222 { 0223 d->scanDAlbumsTimer->start(); 0224 } 0225 0226 break; 0227 } 0228 0229 default: 0230 { 0231 break; 0232 } 0233 } 0234 } 0235 0236 } // namespace Digikam