diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bcb704366cb5e333a626c18c308c7e0448a8e69f (patch) | |
tree | f0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kopete/libkopete/kopetetask.cpp | |
download | tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kopete/libkopete/kopetetask.cpp')
-rw-r--r-- | kopete/libkopete/kopetetask.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/kopete/libkopete/kopetetask.cpp b/kopete/libkopete/kopetetask.cpp new file mode 100644 index 00000000..b7484116 --- /dev/null +++ b/kopete/libkopete/kopetetask.cpp @@ -0,0 +1,108 @@ +/* + kopetetask.cpp - Kopete Task + + Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk> + Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org> + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include "kopetetask.h" + +#include <klocale.h> + +#include <qptrlist.h> + +namespace Kopete +{ + +class Task::Private +{ +public: + Private() + : result( ResultFailed ) + { + errorMessage = i18n( "The operation has not finished yet" ); + } + + Task::Result result; + QString errorMessage; + QPtrList<Task> subtasks; +}; + +Task::Task() + : d( new Private ) +{ +} + +Task::~Task() +{ + delete d; +} + +bool Task::succeeded() const +{ + return d->result == ResultSucceeded; +} + +const QString &Task::errorString() const +{ + return d->errorMessage; +} + +void Task::abort( int flags ) +{ + int childFlags = flags & ~AbortEmitResult; + for ( Task *task = d->subtasks.first(); task; task = d->subtasks.next() ) + task->abort( childFlags ); + + if ( flags & AbortEmitResult ) + emitResult( ResultFailed, i18n( "Aborted" ) ); + else + delete this; +} + +void Task::addSubtask( Task *task ) +{ + d->subtasks.append( task ); + connect( task, SIGNAL( result( Kopete::Task* ) ), + this, SLOT( slotResult( Kopete::Task* ) ) ); + connect( task, SIGNAL( statusMessage( Kopete::Task*, const QString & ) ), + this, SIGNAL( statusMessage( Kopete::Task*, const QString & ) ) ); +} + +void Task::removeSubtask( Task *task, RemoveSubtaskIfLast actionIfLast ) +{ + disconnect( task, SIGNAL( result( Kopete::Task* ) ), + this, SLOT( slotResult( Kopete::Task* ) ) ); + disconnect( task, SIGNAL( statusMessage( Kopete::Task*, const QString & ) ), + this, SIGNAL( statusMessage( Kopete::Task*, const QString & ) ) ); + d->subtasks.remove( task ); + if ( d->subtasks.isEmpty() && actionIfLast == IfLastEmitResult ) + emitResult( task->succeeded() ? ResultSucceeded : ResultFailed, task->errorString() ); +} + +void Task::emitResult( Result res, const QString &errorMessage ) +{ + d->result = res; + d->errorMessage = errorMessage; + emit result( this ); + delete this; +} + +void Task::slotResult( Kopete::Task *task ) +{ + removeSubtask( task ); +} + +} + +#include "kopetetask.moc" +// vim: set noet ts=4 sts=4 sw=4: |