• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • progresswidget
progressmanager.h
Go to the documentation of this file.
1 /*
2  progressmanager.h
3 
4  This file is part of libkdepim.
5 
6  Copyright (C) 2004 Till Adam <adam@kde.org>
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #ifndef KDEPIM_PROGRESSMANAGER_H
25 #define KDEPIM_PROGRESSMANAGER_H
26 
27 #include "kdepim_export.h"
28 
29 #include <QObject>
30 #include <QString>
31 #include <QMap>
32 #include <QHash>
33 #include <QWeakPointer>
34 #include <QPointer>
35 namespace Akonadi {
36 class AgentInstance;
37 }
38 
39 namespace KPIM {
40 
41 class ProgressItem;
42 class ProgressManager;
43 typedef QMap<ProgressItem *, bool> ProgressItemMap;
44 
45 class KDEPIM_EXPORT ProgressItem : public QObject
46 {
47  Q_OBJECT
48  friend class ProgressManager;
49 
50 public:
51 
56  const QString &id() const { return mId; }
57 
61  ProgressItem *parent() const { return mParent.data(); }
62 
66  const QString &label() const { return mLabel; }
67 
71  void setLabel( const QString &v );
72 
76  const QString &status() const { return mStatus; }
81  void setStatus( const QString &v );
82 
86  bool canBeCanceled() const { return mCanBeCanceled; }
87 
92  bool usesCrypto() const { return mUsesCrypto; }
93 
99  void setUsesCrypto( bool v );
100 
104  bool usesBusyIndicator() const { return mUsesBusyIndicator; }
105 
111  void setUsesBusyIndicator( bool useBusyIndicator );
112 
116  unsigned int progress() const { return mProgress; }
117 
122  void setProgress( unsigned int v );
123 
131  void setComplete();
132 
137  void reset()
138  {
139  setProgress( 0 );
140  setStatus( QString() );
141  mCompleted = 0;
142  }
143 
144  void cancel();
145 
146  // Often needed values for calculating progress.
147  void setTotalItems( unsigned int v ) { mTotal = v; }
148  unsigned int totalItems() const { return mTotal; }
149  void setCompletedItems( unsigned int v ) { mCompleted = v; }
150  void incCompletedItems( unsigned int v = 1 ) { mCompleted += v; }
151  unsigned int completedItems() const { return mCompleted; }
152 
156  void updateProgress()
157  {
158  setProgress( mTotal? mCompleted * 100 / mTotal : 0 );
159  }
160 
161  void addChild( ProgressItem *kiddo );
162  void removeChild( ProgressItem *kiddo );
163 
164  bool canceled() const { return mCanceled; }
165 
166 Q_SIGNALS:
171  void progressItemAdded( KPIM::ProgressItem * );
172 
178  void progressItemProgress( KPIM::ProgressItem *, unsigned int );
179 
186  void progressItemCompleted( KPIM::ProgressItem * );
187 
198  void progressItemCanceled( KPIM::ProgressItem * );
199 
206  void progressItemStatus( KPIM::ProgressItem *, const QString & );
207 
214  void progressItemLabel( KPIM::ProgressItem *, const QString & );
215 
222  void progressItemUsesCrypto( KPIM::ProgressItem *, bool );
223 
231  void progressItemUsesBusyIndicator( KPIM::ProgressItem *item, bool value );
232 
233 protected:
234  /* Only to be used by our good friend the ProgressManager */
235  ProgressItem( ProgressItem *parent, const QString &id, const QString &label,
236  const QString &status, bool isCancellable, bool usesCrypto );
237  virtual ~ProgressItem();
238 
239 private:
240  QString mId;
241  QString mLabel;
242  QString mStatus;
243  QWeakPointer<ProgressItem>mParent;
244  bool mCanBeCanceled;
245  unsigned int mProgress;
246  ProgressItemMap mChildren;
247  unsigned int mTotal;
248  unsigned int mCompleted;
249  bool mWaitingForKids;
250  bool mCanceled;
251  bool mUsesCrypto;
252  bool mUsesBusyIndicator;
253  bool mCompletedCalled;
254 };
255 
256 struct ProgressManagerPrivate;
257 
278 class KDEPIM_EXPORT ProgressManager : public QObject
279 {
280 
281  Q_OBJECT
282 
283  friend struct ProgressManagerPrivate;
284 
285 public:
286  virtual ~ProgressManager();
287 
291  static ProgressManager *instance();
292 
299  static QString getUniqueID()
300  {
301  return QString::number( ++uID );
302  }
303 
309  static ProgressItem *createProgressItem( const QString &label )
310  {
311  return instance()->createProgressItemImpl( 0, getUniqueID(), label,
312  QString(), true, false );
313  }
314 
329  static ProgressItem *createProgressItem( ProgressItem *parent,
330  const QString &id,
331  const QString &label,
332  const QString &status = QString(),
333  bool canBeCanceled = true,
334  bool usesCrypto = false )
335  {
336  return instance()->createProgressItemImpl( parent, id, label, status,
337  canBeCanceled, usesCrypto );
338  }
339 
344  static ProgressItem *createProgressItem( const QString &parent,
345  const QString &id,
346  const QString &label,
347  const QString &status = QString(),
348  bool canBeCanceled = true,
349  bool usesCrypto = false )
350  {
351  return instance()->createProgressItemImpl( parent, id, label,
352  status, canBeCanceled, usesCrypto );
353  }
354 
358  static ProgressItem *createProgressItem( const QString &id,
359  const QString &label,
360  const QString &status = QString(),
361  bool canBeCanceled = true,
362  bool usesCrypto = false )
363  {
364  return instance()->createProgressItemImpl( 0, id, label, status,
365  canBeCanceled, usesCrypto );
366  }
367 
373  static ProgressItem *createProgressItem( ProgressItem *parent,
374  const Akonadi::AgentInstance &agent,
375  const QString &id,
376  const QString &label,
377  const QString &status = QString(),
378  bool canBeCanceled = true,
379  bool usesCrypto = false )
380  {
381  return instance()->createProgressItemForAgent( parent, agent, id, label,
382  status, canBeCanceled, usesCrypto );
383  }
384 
388  bool isEmpty() const
389  {
390  return mTransactions.isEmpty();
391  }
392 
400  ProgressItem *singleItem() const;
401 
406  static void emitShowProgressDialog()
407  {
408  instance()->emitShowProgressDialogImpl();
409  }
410 
411 Q_SIGNALS:
413  void progressItemAdded( KPIM::ProgressItem * );
415  void progressItemProgress( KPIM::ProgressItem *, unsigned int );
417  void progressItemCompleted( KPIM::ProgressItem * );
419  void progressItemCanceled( KPIM::ProgressItem * );
421  void progressItemStatus( KPIM::ProgressItem *, const QString & );
423  void progressItemLabel( KPIM::ProgressItem *, const QString & );
425  void progressItemUsesCrypto( KPIM::ProgressItem *, bool );
427  void progressItemUsesBusyIndicator( KPIM::ProgressItem*, bool );
428 
433  void showProgressDialog();
434 
435 public Q_SLOTS:
436 
442  void slotStandardCancelHandler( KPIM::ProgressItem *item );
443 
447  void slotAbortAll();
448 
449 private Q_SLOTS:
450  void slotTransactionCompleted( KPIM::ProgressItem *item );
451 
452 private:
453  ProgressManager();
454  // prevent unsolicited copies
455  ProgressManager( const ProgressManager & );
456 
457  virtual ProgressItem *createProgressItemImpl( ProgressItem *parent,
458  const QString &id,
459  const QString &label,
460  const QString &status,
461  bool cancellable,
462  bool usesCrypto );
463  virtual ProgressItem *createProgressItemImpl( const QString &parent,
464  const QString &id,
465  const QString &label,
466  const QString &status,
467  bool cancellable,
468  bool usesCrypto );
469  ProgressItem *createProgressItemForAgent( ProgressItem *parent,
470  const Akonadi::AgentInstance &instance,
471  const QString &id,
472  const QString &label,
473  const QString &status,
474  bool cancellable,
475  bool usesCrypto );
476  void emitShowProgressDialogImpl();
477 
478  QHash< QString, ProgressItem* > mTransactions;
479  static unsigned int uID;
480 };
481 
482 }
483 
484 #endif // __KPIM_PROGRESSMANAGER_H__
KPIM::ProgressItem::canceled
bool canceled() const
Definition: progressmanager.h:164
KPIM::ProgressItem::id
const QString & id() const
Definition: progressmanager.h:56
kdepim_export.h
KPIM::ProgressItemMap
QMap< ProgressItem *, bool > ProgressItemMap
Definition: progressmanager.h:42
KPIM::ProgressItem::totalItems
unsigned int totalItems() const
Definition: progressmanager.h:148
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(const QString &label)
Creates a ProgressItem with a unique id and the given label.
Definition: progressmanager.h:309
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(const QString &parent, const QString &id, const QString &label, const QString &status=QString(), bool canBeCanceled=true, bool usesCrypto=false)
Use this version if you have the id string of the parent and want to add a subjob to it...
Definition: progressmanager.h:344
KPIM::ProgressManager::isEmpty
bool isEmpty() const
Definition: progressmanager.h:388
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(const QString &id, const QString &label, const QString &status=QString(), bool canBeCanceled=true, bool usesCrypto=false)
Version without a parent.
Definition: progressmanager.h:358
KPIM::ProgressItem::updateProgress
void updateProgress()
Recalculate progress according to total/completed items and update.
Definition: progressmanager.h:156
KPIM::ProgressItem::canBeCanceled
bool canBeCanceled() const
Definition: progressmanager.h:86
KPIM::ProgressItem::parent
ProgressItem * parent() const
Definition: progressmanager.h:61
KPIM::ProgressItem::incCompletedItems
void incCompletedItems(unsigned int v=1)
Definition: progressmanager.h:150
QObject
KPIM::ProgressManager::getUniqueID
static QString getUniqueID()
Use this to acquire a unique id number which can be used to discern an operation from all others goin...
Definition: progressmanager.h:299
KPIM::ProgressItem::label
const QString & label() const
Definition: progressmanager.h:66
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(ProgressItem *parent, const Akonadi::AgentInstance &agent, const QString &id, const QString &label, const QString &status=QString(), bool canBeCanceled=true, bool usesCrypto=false)
Version for Akonadi agents.
Definition: progressmanager.h:373
KPIM::ProgressManager
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
Definition: progressmanager.h:278
KPIM::ProgressItem::reset
void reset()
Reset the progress value of this item to 0 and the status string to the empty string.
Definition: progressmanager.h:137
KPIM::ProgressItem::usesBusyIndicator
bool usesBusyIndicator() const
Definition: progressmanager.h:104
KPIM::ProgressItem::usesCrypto
bool usesCrypto() const
Definition: progressmanager.h:92
KPIM::ProgressItem::progress
unsigned int progress() const
Definition: progressmanager.h:116
KPIM::ProgressManager::createProgressItem
static ProgressItem * createProgressItem(ProgressItem *parent, const QString &id, const QString &label, const QString &status=QString(), bool canBeCanceled=true, bool usesCrypto=false)
Creates a new progressItem with the given parent, id, label and initial status.
Definition: progressmanager.h:329
KPIM::ProgressManager::emitShowProgressDialog
static void emitShowProgressDialog()
Ask all listeners to show the progress dialog, because there is something that wants to be shown...
Definition: progressmanager.h:406
KPIM::ProgressItem
Definition: progressmanager.h:45
KPIM::ProgressItem::status
const QString & status() const
Definition: progressmanager.h:76
KPIM::ProgressItem::completedItems
unsigned int completedItems() const
Definition: progressmanager.h:151
KPIM::ProgressItem::setTotalItems
void setTotalItems(unsigned int v)
Definition: progressmanager.h:147
KPIM::ProgressItem::setCompletedItems
void setCompletedItems(unsigned int v)
Definition: progressmanager.h:149
KDEPIM_EXPORT
#define KDEPIM_EXPORT
Definition: kdepim_export.h:35
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal