digiKam
progressmanager.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-01-13
7  * Description : progress manager
8  *
9  * Copyright (C) 2007-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11  * Copyright (C) 2004 by Till Adam <adam at kde dot org>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_PROGRESS_MANAGER_H
27 #define DIGIKAM_PROGRESS_MANAGER_H
28 
29 // Qt includes
30 
31 #include <QObject>
32 #include <QString>
33 #include <QMap>
34 #include <QHash>
35 #include <QPixmap>
36 
37 // Local includes
38 
39 #include "digikam_export.h"
40 
41 namespace Digikam
42 {
43 
44 class DIGIKAM_EXPORT ProgressItem : public QObject
45 {
46  Q_OBJECT
47 
48 public:
49 
50  ProgressItem(ProgressItem* const parent,
51  const QString& id,
52  const QString& label,
53  const QString& status,
54  bool canBeCanceled,
55  bool hasThumb);
56  ~ProgressItem() override;
57 
62  void setShowAtStart(bool showAtStart);
63 
67  bool showAtStart() const;
68 
73  const QString& id() const;
74 
78  ProgressItem* parent() const;
79 
83  const QString& label() const;
84 
88  void setLabel(const QString& v);
89 
93  const QString& status() const;
94 
99  void setStatus(const QString& v);
100 
104  bool canBeCanceled() const;
105 
109  bool usesBusyIndicator() const;
110 
116  void setUsesBusyIndicator(bool useBusyIndicator);
117 
121  bool hasThumbnail() const;
122 
126  void setThumbnail(const QIcon &icon);
127 
131  unsigned int progress() const;
132 
137  void setProgress(unsigned int v);
138 
146  void setComplete();
147 
152  void reset();
153 
154  void cancel();
155  bool canceled() const;
156 
157  // Often needed values for calculating progress.
158  void setTotalItems(unsigned int v);
159  void incTotalItems(unsigned int v = 1);
160  unsigned int totalItems() const;
161  bool setCompletedItems(unsigned int v);
162  bool incCompletedItems(unsigned int v = 1);
163  unsigned int completedItems() const;
164  bool totalCompleted() const;
165 
169  void updateProgress();
170 
176  bool advance(unsigned int v);
177 
178  void addChild(ProgressItem* const kiddo);
179  void removeChild(ProgressItem* const kiddo);
180 
181 Q_SIGNALS:
182 
188 
194  void progressItemProgress(ProgressItem*, unsigned int);
195 
203 
215  void progressItemCanceledById(const QString& id);
216 
223  void progressItemStatus(ProgressItem*, const QString&);
224 
231  void progressItemLabel(ProgressItem*, const QString&);
232 
241 
247  void progressItemThumbnail(ProgressItem* item, const QPixmap& thumb);
248 
249 private:
250 
251  class Private;
252  Private* const d;
253 };
254 
255 // --------------------------------------------------------------------------------------------
256 
277 class DIGIKAM_EXPORT ProgressManager : public QObject
278 {
279  Q_OBJECT
280 
281 public:
282 
286  bool isEmpty() const;
287 
291  ProgressItem* findItembyId(const QString& id) const;
292 
300  ProgressItem* singleItem() const;
301 
305  static ProgressManager* instance();
306 
313  QString getUniqueID();
314 
326  static ProgressItem* createProgressItem(const QString& label,
327  const QString& status = QString(),
328  bool canBeCanceled = true,
329  bool hasThumb = false);
330 
344  static ProgressItem* createProgressItem(ProgressItem* const parent,
345  const QString& id,
346  const QString& label,
347  const QString& status = QString(),
348  bool canBeCanceled = true,
349  bool hasThumb = false);
350 
355  static ProgressItem* createProgressItem(const QString& parent,
356  const QString& id,
357  const QString& label,
358  const QString& status = QString(),
359  bool canBeCanceled = true,
360  bool hasThumb = false);
361 
365  static ProgressItem* createProgressItem(const QString& id,
366  const QString& label,
367  const QString& status = QString(),
368  bool canBeCanceled = true,
369  bool hasThumb = false);
370 
378  static bool addProgressItem(ProgressItem* const t, ProgressItem* const parent = nullptr);
379 
384  static void emitShowProgressView();
385 
386 Q_SIGNALS:
387 
392 
396  void progressItemProgress(ProgressItem*, unsigned int);
397 
402 
407 
411  void progressItemStatus(ProgressItem*, const QString&);
412 
416  void progressItemLabel(ProgressItem*, const QString&);
417 
422 
426  void progressItemThumbnail(ProgressItem*, const QPixmap&);
427 
433 
435 
436 public Q_SLOTS:
437 
443  void slotStandardCancelHandler(ProgressItem* item);
444 
448  void slotAbortAll();
449 
450 private Q_SLOTS:
451 
452  void slotTransactionCompleted(ProgressItem* item);
453  void slotTransactionCompletedDeferred(ProgressItem* item);
454  void slotTransactionViewIsEmpty();
455 
456 private:
457 
458  // Disable
459  ProgressManager();
460  ProgressManager(QObject*);
462  ~ProgressManager() override;
463 
464  void emitShowProgressViewImpl();
465 
466  virtual ProgressItem* createProgressItemImpl(ProgressItem* const parent,
467  const QString& id,
468  const QString& label,
469  const QString& status,
470  bool cancellable,
471  bool hasThumb);
472 
473  virtual ProgressItem* createProgressItemImpl(const QString& parent,
474  const QString& id,
475  const QString& label,
476  const QString& status,
477  bool cancellable,
478  bool hasThumb);
479 
480  virtual void addProgressItemImpl(ProgressItem* const t, ProgressItem* const parent);
481 
482 private:
483 
484  class Private;
485  Private* const d;
486 
487  friend class ProgressManagerCreator;
488 };
489 
490 } // namespace Digikam
491 
492 #endif // DIGIKAM_PROGRESS_MANAGER_H
Definition: progressmanager.h:45
void progressItemUsesBusyIndicator(ProgressItem *item, bool value)
void progressItemCanceled(ProgressItem *)
void progressItemStatus(ProgressItem *, const QString &)
void progressItemCanceledById(const QString &id)
void progressItemAdded(ProgressItem *)
void progressItemThumbnail(ProgressItem *item, const QPixmap &thumb)
void progressItemCompleted(ProgressItem *)
void progressItemProgress(ProgressItem *, unsigned int)
void progressItemLabel(ProgressItem *, const QString &)
Definition: progressmanager.h:278
void progressItemCompleted(ProgressItem *)
void progressItemStatus(ProgressItem *, const QString &)
void progressItemThumbnail(ProgressItem *, const QPixmap &)
void completeTransactionDeferred(ProgressItem *item)
void progressItemProgress(ProgressItem *, unsigned int)
void progressItemUsesBusyIndicator(ProgressItem *, bool)
void progressItemAdded(ProgressItem *)
void progressItemCanceled(ProgressItem *)
void progressItemLabel(ProgressItem *, const QString &)
qulonglong value
Definition: itemviewutilities.cpp:592
Definition: datefolderview.cpp:43