24 #include <tqvaluevector.h>
27 #include <tdelocale.h>
28 #include <kstaticdeleter.h>
30 #include "progressmanager.h"
35 unsigned int KPIM::ProgressManager::uID = 42;
37 ProgressItem::ProgressItem(
38 ProgressItem* parent,
const TQString&
id,
39 const TQString& label,
const TQString& status,
bool canBeCanceled,
41 :mId( id ), mLabel( label ), mStatus( status ), mParent( parent ),
42 mCanBeCanceled( canBeCanceled ), mProgress( 0 ), mTotal( 0 ),
43 mCompleted( 0 ), mWaitingForKids( false ), mCanceled( false ),
44 mUsesCrypto( usesCrypto ), mUsesBusyIndicator( false )
47 ProgressItem::~ProgressItem()
51 void ProgressItem::setComplete()
55 if ( mChildren.isEmpty() ) {
58 emit progressItemCompleted(
this );
60 parent()->removeChild(
this );
63 mWaitingForKids =
true;
67 void ProgressItem::addChild( ProgressItem *kiddo )
69 mChildren.replace( kiddo,
true );
72 void ProgressItem::removeChild( ProgressItem *kiddo )
74 mChildren.remove( kiddo );
76 if ( mChildren.count() == 0 && mWaitingForKids ) {
77 emit progressItemCompleted(
this );
82 void ProgressItem::cancel()
84 if ( mCanceled || !mCanBeCanceled )
return;
85 kdDebug(5300) <<
"ProgressItem::cancel() - " << label() << endl;
88 TQValueList<ProgressItem*> kids = mChildren.keys();
89 TQValueList<ProgressItem*>::Iterator it( kids.begin() );
90 TQValueList<ProgressItem*>::Iterator end( kids.end() );
91 for ( ; it != end; it++ ) {
92 ProgressItem *kid = *it;
93 if ( kid->canBeCanceled() )
96 setStatus( i18n(
"Aborting..." ) );
97 emit progressItemCanceled(
this );
101 void ProgressItem::setProgress(
unsigned int v )
105 emit progressItemProgress(
this, mProgress );
108 void ProgressItem::setLabel(
const TQString& v )
111 emit progressItemLabel(
this, mLabel );
114 void ProgressItem::setStatus(
const TQString& v )
117 emit progressItemStatus(
this, mStatus );
120 void ProgressItem::setUsesCrypto(
bool v )
123 emit progressItemUsesCrypto(
this, v );
126 void ProgressItem::setUsesBusyIndicator(
bool useBusyIndicator )
128 mUsesBusyIndicator = useBusyIndicator;
129 emit progressItemUsesBusyIndicator(
this, useBusyIndicator );
134 ProgressManager::ProgressManager() :TQObject() {
138 ProgressManager::~ProgressManager() { mInstance = 0; }
139 static KStaticDeleter<ProgressManager> progressManagerDeleter;
149 ProgressItem* ProgressManager::createProgressItemImpl(
150 ProgressItem* parent,
const TQString&
id,
151 const TQString &label,
const TQString &status,
152 bool cancellable,
bool usesCrypto )
155 if ( !mTransactions[
id ] ) {
156 t =
new ProgressItem ( parent,
id, label, status, cancellable, usesCrypto );
157 mTransactions.insert(
id, t );
159 ProgressItem *p = mTransactions[ parent->id() ];
165 connect ( t, TQ_SIGNAL( progressItemCompleted(KPIM::ProgressItem*) ),
166 this, TQ_SLOT( slotTransactionCompleted(KPIM::ProgressItem*) ) );
167 connect ( t, TQ_SIGNAL( progressItemProgress(KPIM::ProgressItem*,
unsigned int) ),
168 this, TQ_SIGNAL( progressItemProgress(KPIM::ProgressItem*,
unsigned int) ) );
169 connect ( t, TQ_SIGNAL( progressItemAdded(KPIM::ProgressItem*) ),
170 this, TQ_SIGNAL( progressItemAdded(KPIM::ProgressItem*) ) );
171 connect ( t, TQ_SIGNAL( progressItemCanceled(KPIM::ProgressItem*) ),
172 this, TQ_SIGNAL( progressItemCanceled(KPIM::ProgressItem*) ) );
173 connect ( t, TQ_SIGNAL( progressItemStatus(KPIM::ProgressItem*,
const TQString&) ),
174 this, TQ_SIGNAL( progressItemStatus(KPIM::ProgressItem*,
const TQString&) ) );
175 connect ( t, TQ_SIGNAL( progressItemLabel(KPIM::ProgressItem*,
const TQString&) ),
176 this, TQ_SIGNAL( progressItemLabel(KPIM::ProgressItem*,
const TQString&) ) );
177 connect ( t, TQ_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*,
bool) ),
178 this, TQ_SIGNAL( progressItemUsesCrypto(KPIM::ProgressItem*,
bool) ) );
179 connect ( t, TQ_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*,
bool) ),
180 this, TQ_SIGNAL( progressItemUsesBusyIndicator(KPIM::ProgressItem*,
bool) ) );
182 emit progressItemAdded( t );
185 t = mTransactions[id];
190 ProgressItem* ProgressManager::createProgressItemImpl(
191 const TQString& parent,
const TQString &
id,
192 const TQString &label,
const TQString& status,
193 bool canBeCanceled,
bool usesCrypto )
195 ProgressItem * p = mTransactions[parent];
196 return createProgressItemImpl( p,
id, label, status, canBeCanceled, usesCrypto );
199 void ProgressManager::emitShowProgressDialogImpl()
201 emit showProgressDialog();
207 void ProgressManager::slotTransactionCompleted( ProgressItem *item )
209 mTransactions.remove( item->id() );
210 emit progressItemCompleted( item );
213 void ProgressManager::slotStandardCancelHandler( ProgressItem *item )
218 ProgressItem* ProgressManager::singleItem()
const
220 ProgressItem *item = 0;
221 TQDictIterator< ProgressItem > it( mTransactions );
222 for ( ; it.current(); ++it ) {
225 if ( (*it)->usesBusyIndicator() )
228 if ( !(*it)->parent() ) {
238 void ProgressManager::slotAbortAll()
240 TQDictIterator< ProgressItem > it( mTransactions );
241 for ( ; it.current(); ++it ) {
242 it.current()->cancel();
248 #include "progressmanager.moc"
The ProgressManager singleton keeps track of all ongoing transactions and notifies observers (progres...
TDEPIM classes for drag and drop of mails.