• 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.cpp
Go to the documentation of this file.
1 /*
2  progressmanager.cpp
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 #include "progressmanager.h"
25 
26 #include <KDebug>
27 #include <KLocale>
28 #include <KGlobal>
29 
30 namespace KPIM {
31 
32 unsigned int KPIM::ProgressManager::uID = 42;
33 
34 ProgressItem::ProgressItem( ProgressItem *parent, const QString &id,
35  const QString &label, const QString &status,
36  bool canBeCanceled, bool usesCrypto )
37  : mId( id ), mLabel( label ), mStatus( status ), mParent( parent ),
38  mCanBeCanceled( canBeCanceled ), mProgress( 0 ), mTotal( 0 ),
39  mCompleted( 0 ), mWaitingForKids( false ), mCanceled( false ),
40  mUsesCrypto( usesCrypto ), mUsesBusyIndicator( false ), mCompletedCalled( false )
41 {
42 }
43 
44 ProgressItem::~ProgressItem()
45 {
46 }
47 
48 void ProgressItem::setComplete()
49 {
50  // kDebug() << label();
51  if ( mChildren.isEmpty() ) {
52  if ( mCompletedCalled )
53  return;
54  if ( !mCanceled ) {
55  setProgress( 100 );
56  }
57  mCompletedCalled = true;
58  if ( parent() ) {
59  parent()->removeChild( this );
60  }
61  emit progressItemCompleted( this );
62  } else {
63  mWaitingForKids = true;
64  }
65 }
66 
67 void ProgressItem::addChild( ProgressItem *kiddo )
68 {
69  mChildren.insert( kiddo, true );
70 }
71 
72 void ProgressItem::removeChild( ProgressItem *kiddo )
73 {
74  if ( mChildren.isEmpty() ) {
75  mWaitingForKids = false;
76  return;
77  }
78 
79  if ( mChildren.remove( kiddo ) == 0 ) {
80  // do nothing if the specified item is not in the map
81  return;
82  }
83 
84  // in case we were waiting for the last kid to go away, now is the time
85  if ( mChildren.count() == 0 && mWaitingForKids ) {
86  emit progressItemCompleted( this );
87  }
88 }
89 
90 void ProgressItem::cancel()
91 {
92  if ( mCanceled || !mCanBeCanceled ) {
93  return;
94  }
95 
96  kDebug() << label();
97  mCanceled = true;
98  // Cancel all children.
99  QList<ProgressItem* > kids = mChildren.keys();
100  QList<ProgressItem* >::Iterator it( kids.begin() );
101  QList<ProgressItem* >::Iterator end( kids.end() );
102  for ( ; it != end; it++ ) {
103  ProgressItem *kid = *it;
104  if ( kid->canBeCanceled() ) {
105  kid->cancel();
106  }
107  }
108  setStatus( i18n( "Aborting..." ) );
109  emit progressItemCanceled( this );
110 }
111 
112 void ProgressItem::setProgress( unsigned int v )
113 {
114  mProgress = v;
115  // kDebug() << label() << " :" << v;
116  emit progressItemProgress( this, mProgress );
117 }
118 
119 void ProgressItem::setLabel( const QString &v )
120 {
121  mLabel = v;
122  emit progressItemLabel( this, mLabel );
123 }
124 
125 void ProgressItem::setStatus( const QString &v )
126 {
127  mStatus = v;
128  emit progressItemStatus( this, mStatus );
129 }
130 
131 void ProgressItem::setUsesCrypto( bool v )
132 {
133  mUsesCrypto = v;
134  emit progressItemUsesCrypto( this, v );
135 }
136 
137 void ProgressItem::setUsesBusyIndicator( bool useBusyIndicator )
138 {
139  mUsesBusyIndicator = useBusyIndicator;
140  emit progressItemUsesBusyIndicator( this, useBusyIndicator );
141 }
142 
143 // ======================================
144 
145 struct ProgressManagerPrivate {
146  ProgressManager instance;
147 };
148 
149 K_GLOBAL_STATIC( ProgressManagerPrivate, progressManagerPrivate )
150 
151 ProgressManager::ProgressManager()
152  : QObject()
153 {
154 
155 }
156 
157 ProgressManager::~ProgressManager() {}
158 
159 ProgressManager *ProgressManager::instance()
160 {
161  return progressManagerPrivate.isDestroyed() ? 0 : &progressManagerPrivate->instance ;
162 }
163 
164 ProgressItem *ProgressManager::createProgressItemImpl( ProgressItem *parent,
165  const QString &id,
166  const QString &label,
167  const QString &status,
168  bool cancellable,
169  bool usesCrypto )
170 {
171  ProgressItem *t = 0;
172  if ( !mTransactions.value( id ) ) {
173  t = new ProgressItem ( parent, id, label, status, cancellable, usesCrypto );
174  mTransactions.insert( id, t );
175  if ( parent ) {
176  ProgressItem *p = mTransactions.value( parent->id() );
177  if ( p ) {
178  p->addChild( t );
179  }
180  }
181  // connect all signals
182  connect ( t, SIGNAL(progressItemCompleted(KPIM::ProgressItem*)),
183  this, SLOT(slotTransactionCompleted(KPIM::ProgressItem*)) );
184  connect ( t, SIGNAL(progressItemProgress(KPIM::ProgressItem*,uint)),
185  this, SIGNAL(progressItemProgress(KPIM::ProgressItem*,uint)) );
186  connect ( t, SIGNAL(progressItemAdded(KPIM::ProgressItem*)),
187  this, SIGNAL(progressItemAdded(KPIM::ProgressItem*)) );
188  connect ( t, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
189  this, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)) );
190  connect ( t, SIGNAL(progressItemStatus(KPIM::ProgressItem*,QString)),
191  this, SIGNAL(progressItemStatus(KPIM::ProgressItem*,QString)) );
192  connect ( t, SIGNAL(progressItemLabel(KPIM::ProgressItem*,QString)),
193  this, SIGNAL(progressItemLabel(KPIM::ProgressItem*,QString)) );
194  connect ( t, SIGNAL(progressItemUsesCrypto(KPIM::ProgressItem*,bool)),
195  this, SIGNAL(progressItemUsesCrypto(KPIM::ProgressItem*,bool)) );
196  connect ( t, SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,bool)),
197  this, SIGNAL(progressItemUsesBusyIndicator(KPIM::ProgressItem*,bool)) );
198 
199  emit progressItemAdded( t );
200  } else {
201  // Hm, is this what makes the most sense?
202  t = mTransactions.value( id );
203  }
204  return t;
205 }
206 
207 ProgressItem *ProgressManager::createProgressItemImpl( const QString &parent,
208  const QString &id,
209  const QString &label,
210  const QString &status,
211  bool canBeCanceled,
212  bool usesCrypto )
213 {
214  ProgressItem *p = mTransactions.value( parent );
215  return createProgressItemImpl( p, id, label, status, canBeCanceled, usesCrypto );
216 }
217 
218 void ProgressManager::emitShowProgressDialogImpl()
219 {
220  emit showProgressDialog();
221 }
222 
223 // slots
224 
225 void ProgressManager::slotTransactionCompleted( ProgressItem *item )
226 {
227  mTransactions.remove( item->id() );
228  emit progressItemCompleted( item );
229 }
230 
231 void ProgressManager::slotStandardCancelHandler( ProgressItem *item )
232 {
233  item->setComplete();
234 }
235 
236 ProgressItem *ProgressManager::singleItem() const
237 {
238  ProgressItem *item = 0;
239  QHash< QString, ProgressItem* >::const_iterator it = mTransactions.constBegin();
240  QHash< QString, ProgressItem* >::const_iterator end = mTransactions.constEnd();
241  while ( it != end ) {
242 
243  // No single item for progress possible, as one of them is a busy indicator one.
244  if ( (*it)->usesBusyIndicator() )
245  return 0;
246 
247  if ( !(*it)->parent() ) { // if it's a top level one, only those count
248  if ( item ) {
249  return 0; // we found more than one
250  } else {
251  item = (*it);
252  }
253  }
254  ++it;
255  }
256  return item;
257 }
258 
259 void ProgressManager::slotAbortAll()
260 {
261  QHashIterator<QString, ProgressItem *> it(mTransactions);
262  while (it.hasNext()) {
263  it.next();
264  it.value()->cancel();
265  }
266 
267 }
268 
269 } // namespace
270 
271 #include "progressmanager.moc"
KPIM::ProgressItem::id
const QString & id() const
Definition: progressmanager.h:56
KPIM::ProgressManager::instance
static ProgressManager * instance()
Definition: progressmanager.cpp:159
KPIM::ProgressItem::progressItemUsesCrypto
void progressItemUsesCrypto(KPIM::ProgressItem *, bool)
Emitted when the crypto status of an item changed.
KPIM::ProgressItem::~ProgressItem
virtual ~ProgressItem()
Definition: progressmanager.cpp:44
KPIM::ProgressManager::slotAbortAll
void slotAbortAll()
Aborts all running jobs.
Definition: progressmanager.cpp:259
KPIM::ProgressItem::removeChild
void removeChild(ProgressItem *kiddo)
Definition: progressmanager.cpp:72
KPIM::ProgressItem::progressItemProgress
void progressItemProgress(KPIM::ProgressItem *, unsigned int)
Emitted when the progress value of an item changes.
KPIM::ProgressManager::progressItemCompleted
void progressItemCompleted(KPIM::ProgressItem *)
KPIM::ProgressManager::progressItemProgress
void progressItemProgress(KPIM::ProgressItem *, unsigned int)
KPIM::ProgressManager::progressItemUsesCrypto
void progressItemUsesCrypto(KPIM::ProgressItem *, bool)
KPIM::ProgressItem::progressItemLabel
void progressItemLabel(KPIM::ProgressItem *, const QString &)
Emitted when the label of an item changed.
KPIM::ProgressManager::progressItemStatus
void progressItemStatus(KPIM::ProgressItem *, const QString &)
KPIM::ProgressItem::canBeCanceled
bool canBeCanceled() const
Definition: progressmanager.h:86
KPIM::ProgressItem::parent
ProgressItem * parent() const
Definition: progressmanager.h:61
QObject
KPIM::ProgressManager::progressItemLabel
void progressItemLabel(KPIM::ProgressItem *, const QString &)
KPIM::ProgressItem::label
const QString & label() const
Definition: progressmanager.h:66
KPIM::ProgressItem::setUsesCrypto
void setUsesCrypto(bool v)
Set whether this item uses crypted communication, so listeners can display a nice crypto icon...
Definition: progressmanager.cpp:131
KPIM::ProgressItem::setLabel
void setLabel(const QString &v)
Definition: progressmanager.cpp:119
KPIM::ProgressManager
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
Definition: progressmanager.h:278
KPIM::ProgressItem::setComplete
void setComplete()
Tell the item it has finished.
Definition: progressmanager.cpp:48
progressmanager.h
KPIM::ProgressItem::progressItemUsesBusyIndicator
void progressItemUsesBusyIndicator(KPIM::ProgressItem *item, bool value)
Emitted when the busy indicator state of an item changes.
KPIM::ProgressItem::addChild
void addChild(ProgressItem *kiddo)
Definition: progressmanager.cpp:67
KPIM::ProgressManager::~ProgressManager
virtual ~ProgressManager()
Definition: progressmanager.cpp:157
KPIM::ProgressItem::cancel
void cancel()
Definition: progressmanager.cpp:90
KPIM::ProgressManager::progressItemUsesBusyIndicator
void progressItemUsesBusyIndicator(KPIM::ProgressItem *, bool)
KPIM::ProgressItem::setProgress
void setProgress(unsigned int v)
Set the progress (percentage of completion) value of this item.
Definition: progressmanager.cpp:112
KPIM::ProgressItem::ProgressItem
ProgressItem(ProgressItem *parent, const QString &id, const QString &label, const QString &status, bool isCancellable, bool usesCrypto)
Definition: progressmanager.cpp:34
KPIM::ProgressItem::setUsesBusyIndicator
void setUsesBusyIndicator(bool useBusyIndicator)
Sets whether this item uses a busy indicator instead of real progress for its progress bar...
Definition: progressmanager.cpp:137
KPIM::ProgressItem::progressItemStatus
void progressItemStatus(KPIM::ProgressItem *, const QString &)
Emitted when the status message of an item changed.
KPIM::ProgressManager::slotStandardCancelHandler
void slotStandardCancelHandler(KPIM::ProgressItem *item)
Calls setCompleted() on the item, to make sure it goes away.
Definition: progressmanager.cpp:231
KPIM::ProgressItem
Definition: progressmanager.h:45
KPIM::ProgressItem::progressItemCompleted
void progressItemCompleted(KPIM::ProgressItem *)
Emitted when a progress item was completed.
KPIM::ProgressManager::progressItemAdded
void progressItemAdded(KPIM::ProgressItem *)
KPIM::ProgressItem::progressItemCanceled
void progressItemCanceled(KPIM::ProgressItem *)
Emitted when an item was canceled.
KPIM::ProgressManager::progressItemCanceled
void progressItemCanceled(KPIM::ProgressItem *)
KPIM::ProgressManager::showProgressDialog
void showProgressDialog()
Emitted when an operation requests the listeners to be shown.
KPIM::ProgressManager::singleItem
ProgressItem * singleItem() const
Definition: progressmanager.cpp:236
KPIM::ProgressItem::setStatus
void setStatus(const QString &v)
Set the string to be used for showing this item's current status.
Definition: progressmanager.cpp:125
QList
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