Debian Codegraph @

core/libs/album/engine/albumparser.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2012-01-24
7 * Description : album parser progress indicator
8 *
9 * SPDX-FileCopyrightText: 2012-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * SPDX-FileCopyrightText: 2019-2020 by Minh Nghia Duong <minhnghiaduong997 at gmail dot com>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16 #include "albumparser.h"
17
18 // Qt includes
19
20 #include <QTimer>
21 #include <QApplication>
22 #include <QIcon>
23
24 // KDE includes
25
26 #include <klocalizedstring.h>
27
28 // Local includes
29
30 #include "album.h"
31 #include "albummanager.h"
32 #include "iteminfoalbumsjob.h"
33 #include "applicationsettings.h"
34
35 namespace Digikam
36 {
37
38 class Q_DECL_HIDDEN AlbumParser::Private
39 {
40 public:
41
42 Private() = default;
43
44 bool cancel = false;
45 ItemInfoList infoList;
46 Album* album = nullptr;
47 };
48
49 AlbumParser::AlbumParser(const ItemInfoList& infoList)
50 : ProgressItem(nullptr, QLatin1String("AlbumParser"), QString(), QString(), true, true),
51 d (new Private)
52 {
53 d->infoList = infoList;
54
55 ProgressManager::addProgressItem(this);
56 }
57
58 AlbumParser::AlbumParser(Album* const album)
59 : ProgressItem(nullptr, QLatin1String("AlbumParser"), QString(), QString(), true, true),
60 d (new Private)
61 {
62 d->album = album;
63
64 ProgressManager::addProgressItem(this);
65 }
66
67 AlbumParser::~AlbumParser()
68 {
69 delete d;
70 }
71
72 void AlbumParser::run()
73 {
74 QTimer::singleShot(500, this, SLOT(slotRun()));
75 }
76
77 void AlbumParser::slotRun()
78 {
79 connect(this, SIGNAL(progressItemCanceled(ProgressItem*)),
80 this, SLOT(slotCancel()));
81
82 setLabel(i18n("Scanning albums"));
83 setThumbnail(QIcon::fromTheme(QLatin1String("digikam")));
84
85 if (d->album)
86 {
87 AlbumList albumList;
88 albumList.append(d->album);
89 AlbumIterator it(d->album);
90
91 while (it.current())
92 {
93 albumList.append(*it);
94 ++it;
95 }
96
97 ItemInfoAlbumsJob* const job = new ItemInfoAlbumsJob;
98
99 connect(job, SIGNAL(signalCompleted(ItemInfoList)),
100 this, SLOT(slotParseItemInfoList(ItemInfoList)));
101
102 job->allItemsFromAlbums(albumList);
103 }
104 else
105 {
106 slotParseItemInfoList(d->infoList);
107 }
108 }
109
110 void AlbumParser::slotParseItemInfoList(const ItemInfoList& list)
111 {
112 setTotalItems(list.count());
113
114 int i = 0;
115
116 QList<QUrl> imageList;
117
118 for (ItemInfoList::const_iterator it = list.constBegin() ;
119 !d->cancel && (it != list.constEnd()) ;
120 ++it)
121 {
122 ItemInfo info = *it;
123 imageList.append(info.fileUrl());
124
125 advance(i++);
126 qApp->processEvents();
127 }
128
129 if (!d->cancel)
130 {
131 Q_EMIT signalComplete(imageList);
132 }
133
134 setComplete();
135 }
136
137 void AlbumParser::slotCancel()
138 {
139 d->cancel = true;
140 }
141
142 } // namespace Digikam
143
144 #include "moc_albumparser.cpp"