digiKam
fileactionimageinfolist.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2012-02-05
7  * Description : file action manager task list
8  *
9  * Copyright (C) 2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_FILE_ACTION_IMAGE_INFO_LIST_H
25 #define DIGIKAM_FILE_ACTION_IMAGE_INFO_LIST_H
26 
27 // Qt includes
28 
29 #include <QAtomicPointer>
30 #include <QList>
31 #include <QExplicitlySharedDataPointer>
32 #include <QDebug>
33 
34 // Local includes
35 
36 #include "iteminfo.h"
37 #include "progressmanager.h"
38 
39 namespace Digikam
40 {
41 
43 {
44 public:
45 
47  virtual ~FileActionProgressItemCreator() = default;
48  virtual ProgressItem* createProgressItem(const QString& action) const = 0;
49  virtual void addProgressItem(ProgressItem* const item) = 0;
50 
51 private:
52 
53  Q_DISABLE_COPY(FileActionProgressItemCreator)
54 };
55 
56 // -------------------------------------------------------------------------------------------------------------------
57 
58 class TwoProgressItemsContainer : public QSharedData
59 {
60 protected:
61 
62  QAtomicPointer<ProgressItem> firstItem;
63  QAtomicPointer<ProgressItem> secondItem;
64 
65 protected:
66 
67  // Note: It is currently not safe to schedule after the framework had a chance to
68  // advance all already scheduled items. For this, we'd need to add a mechanism (flag to block completion?)
69 
70  void scheduleOnProgressItem(QAtomicPointer<ProgressItem>& ptr, int total,
71  const QString& action, FileActionProgressItemCreator* const creator);
72  void advance(QAtomicPointer<ProgressItem>& ptr, int n);
73 };
74 
75 // -------------------------------------------------------------------------------------------------------------------
76 
78 {
79  Q_OBJECT
80 
81 public:
82 
84  void schedulingForDB(int numberOfInfos, const QString& action, FileActionProgressItemCreator* const creator);
85  void dbProcessed(int numberOfInfos);
86  void dbFinished();
87  void schedulingForWrite(int numberOfInfos, const QString& action, FileActionProgressItemCreator* const creator);
88  void written(int numberOfInfos);
89  void finishedWriting();
90 
91 Q_SIGNALS:
92 
94 
95 private:
96 
97  // Disable
98  explicit FileActionProgressItemContainer(QObject*);
99 };
100 
101 // -------------------------------------------------------------------------------------------------------------------
102 
103 class FileActionItemInfoList : public QList<ItemInfo>
104 {
105 public:
106 
108  {
109  }
110 
112  : QList (copy),
113  container(copy.container)
114  {
115  }
116 
118  {
119  }
120 
121 public:
122 
123  static FileActionItemInfoList create(const QList<ItemInfo>& list);
126 
128  {
129  return container.data();
130  }
131 
133  void schedulingForDB(int numberOfInfos,
134  const QString& action,
135  FileActionProgressItemCreator* const creator)
136  {
137  progress()->schedulingForDB(numberOfInfos, action, creator);
138  }
139 
140  void schedulingForDB(const QString& action,
141  FileActionProgressItemCreator* const creator)
142  {
143  schedulingForDB(size(), action, creator);
144  }
145 
147  void dbProcessedOne() const { dbProcessed(1); }
148  void dbProcessed(int numberOfInfos) const { progress()->dbProcessed(numberOfInfos); }
149  void dbFinished() const { progress()->dbFinished(); }
150 
152  void schedulingForWrite(int numberOfInfos,
153  const QString& action,
154  FileActionProgressItemCreator* const creator) const
155  {
156  progress()->schedulingForWrite(numberOfInfos, action, creator);
157  }
158 
159  void schedulingForWrite(const QString& action,
160  FileActionProgressItemCreator* const creator) const
161  {
162  schedulingForWrite(size(), action, creator);
163  }
164 
166  void writtenToOne() const { written(1); }
167  void written(int numberOfInfos) const { progress()->written(numberOfInfos); }
168  void finishedWriting() const { progress()->finishedWriting(); }
169 
170 public:
171 
172  QExplicitlySharedDataPointer<FileActionProgressItemContainer> container;
173 
174 private:
175 
176  explicit FileActionItemInfoList(const QList<ItemInfo>& list)
177  : QList<ItemInfo>(list)
178  {
179  }
180 };
181 
182 } // namespace Digikam
183 
184 Q_DECLARE_METATYPE(Digikam::FileActionItemInfoList)
185 
186 #endif // DIGIKAM_FILE_ACTION_IMAGE_INFO_LIST_H
Definition: fileactionimageinfolist.h:104
void schedulingForWrite(int numberOfInfos, const QString &action, FileActionProgressItemCreator *const creator) const
db worker calls this before sending to file worker
Definition: fileactionimageinfolist.h:152
void schedulingForDB(const QString &action, FileActionProgressItemCreator *const creator)
Definition: fileactionimageinfolist.h:140
FileActionProgressItemContainer * progress() const
Definition: fileactionimageinfolist.h:127
FileActionItemInfoList()
Definition: fileactionimageinfolist.h:107
void finishedWriting() const
Definition: fileactionimageinfolist.h:168
FileActionItemInfoList(const FileActionItemInfoList &copy)
Definition: fileactionimageinfolist.h:111
void schedulingForWrite(const QString &action, FileActionProgressItemCreator *const creator) const
Definition: fileactionimageinfolist.h:159
QExplicitlySharedDataPointer< FileActionProgressItemContainer > container
Definition: fileactionimageinfolist.h:172
static FileActionItemInfoList create(const QList< ItemInfo > &list)
Definition: fileactionimageinfolist.cpp:123
void dbProcessedOne() const
db worker progress info
Definition: fileactionimageinfolist.h:147
void writtenToOne() const
file worker calls this when finished
Definition: fileactionimageinfolist.h:166
void dbFinished() const
Definition: fileactionimageinfolist.h:149
void written(int numberOfInfos) const
Definition: fileactionimageinfolist.h:167
~FileActionItemInfoList()
Definition: fileactionimageinfolist.h:117
static FileActionItemInfoList continueTask(const QList< ItemInfo > &list, FileActionProgressItemContainer *const container)
Definition: fileactionimageinfolist.cpp:132
void schedulingForDB(int numberOfInfos, const QString &action, FileActionProgressItemCreator *const creator)
before sending to db worker
Definition: fileactionimageinfolist.h:133
void dbProcessed(int numberOfInfos) const
Definition: fileactionimageinfolist.h:148
Definition: fileactionimageinfolist.h:78
FileActionProgressItemContainer()
Definition: fileactionimageinfolist.cpp:78
void schedulingForDB(int numberOfInfos, const QString &action, FileActionProgressItemCreator *const creator)
Definition: fileactionimageinfolist.cpp:82
void dbProcessed(int numberOfInfos)
Definition: fileactionimageinfolist.cpp:89
void dbFinished()
Definition: fileactionimageinfolist.cpp:94
void schedulingForWrite(int numberOfInfos, const QString &action, FileActionProgressItemCreator *const creator)
Definition: fileactionimageinfolist.cpp:101
void written(int numberOfInfos)
Definition: fileactionimageinfolist.cpp:111
void finishedWriting()
Definition: fileactionimageinfolist.cpp:116
Definition: fileactionimageinfolist.h:43
virtual ~FileActionProgressItemCreator()=default
virtual ProgressItem * createProgressItem(const QString &action) const =0
virtual void addProgressItem(ProgressItem *const item)=0
Definition: iteminfo.h:78
Definition: progressmanager.h:45
Definition: fileactionimageinfolist.h:59
QAtomicPointer< ProgressItem > secondItem
Definition: fileactionimageinfolist.h:63
void advance(QAtomicPointer< ProgressItem > &ptr, int n)
Definition: fileactionimageinfolist.cpp:65
void scheduleOnProgressItem(QAtomicPointer< ProgressItem > &ptr, int total, const QString &action, FileActionProgressItemCreator *const creator)
Definition: fileactionimageinfolist.cpp:38
QAtomicPointer< ProgressItem > firstItem
Definition: fileactionimageinfolist.h:62
Definition: piwigotalker.h:48
Definition: datefolderview.cpp:43