File indexing completed on 2025-01-05 03:53:48
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2012-01-24 0007 * Description : album parser progress indicator 0008 * 0009 * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2019-2020 by Minh Nghia Duong <minhnghiaduong997 at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "albumparser.h" 0017 0018 // Qt includes 0019 0020 #include <QTimer> 0021 #include <QApplication> 0022 #include <QIcon> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "album.h" 0031 #include "albummanager.h" 0032 #include "iteminfoalbumsjob.h" 0033 #include "applicationsettings.h" 0034 0035 namespace Digikam 0036 { 0037 0038 class Q_DECL_HIDDEN AlbumParser::Private 0039 { 0040 public: 0041 0042 explicit Private() 0043 : cancel(false), 0044 album(nullptr) 0045 { 0046 } 0047 0048 bool cancel; 0049 ItemInfoList infoList; 0050 Album* album; 0051 }; 0052 0053 AlbumParser::AlbumParser(const ItemInfoList& infoList) 0054 : ProgressItem(nullptr, QLatin1String("AlbumParser"), QString(), QString(), true, true), 0055 d(new Private) 0056 { 0057 d->infoList = infoList; 0058 0059 ProgressManager::addProgressItem(this); 0060 } 0061 0062 AlbumParser::AlbumParser(Album* const album) 0063 : ProgressItem(nullptr, QLatin1String("AlbumParser"), QString(), QString(), true, true), 0064 d(new Private) 0065 { 0066 d->album = album; 0067 0068 ProgressManager::addProgressItem(this); 0069 } 0070 0071 AlbumParser::~AlbumParser() 0072 { 0073 delete d; 0074 } 0075 0076 void AlbumParser::run() 0077 { 0078 QTimer::singleShot(500, this, SLOT(slotRun())); 0079 } 0080 0081 void AlbumParser::slotRun() 0082 { 0083 connect(this, SIGNAL(progressItemCanceled(ProgressItem*)), 0084 this, SLOT(slotCancel())); 0085 0086 setLabel(i18n("Scanning albums")); 0087 setThumbnail(QIcon::fromTheme(QLatin1String("digikam"))); 0088 0089 if (d->album) 0090 { 0091 AlbumList albumList; 0092 albumList.append(d->album); 0093 AlbumIterator it(d->album); 0094 0095 while (it.current()) 0096 { 0097 albumList.append(*it); 0098 ++it; 0099 } 0100 0101 ItemInfoAlbumsJob* const job = new ItemInfoAlbumsJob; 0102 0103 connect(job, SIGNAL(signalCompleted(ItemInfoList)), 0104 this, SLOT(slotParseItemInfoList(ItemInfoList))); 0105 0106 job->allItemsFromAlbums(albumList); 0107 } 0108 else 0109 { 0110 slotParseItemInfoList(d->infoList); 0111 } 0112 } 0113 0114 void AlbumParser::slotParseItemInfoList(const ItemInfoList& list) 0115 { 0116 setTotalItems(list.count()); 0117 0118 int i = 0; 0119 0120 QList<QUrl> imageList; 0121 0122 for (ItemInfoList::const_iterator it = list.constBegin() ; 0123 !d->cancel && (it != list.constEnd()) ; 0124 ++it) 0125 { 0126 ItemInfo info = *it; 0127 imageList.append(info.fileUrl()); 0128 0129 advance(i++); 0130 qApp->processEvents(); 0131 } 0132 0133 if (!d->cancel) 0134 { 0135 Q_EMIT signalComplete(imageList); 0136 } 0137 0138 setComplete(); 0139 } 0140 0141 void AlbumParser::slotCancel() 0142 { 0143 d->cancel = true; 0144 } 0145 0146 } // namespace Digikam 0147 0148 #include "moc_albumparser.cpp"