diff --git a/CMakeLists.txt b/CMakeLists.txt index 6caa2c004..dd6cd7787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}") set(kmailprivate_LIB_SRCS kmagentmanager.cpp + kmagentinstance.cpp foldercollectionmonitor.cpp readablecollectionproxymodel.cpp folderselectiontreeview.cpp diff --git a/kmagentinstance.cpp b/kmagentinstance.cpp new file mode 100644 index 000000000..db3ae6a0a --- /dev/null +++ b/kmagentinstance.cpp @@ -0,0 +1,60 @@ +/* + This file is part of KMail, the KDE mail client. + Copyright (c) 2009 Montel Laurent + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "kmagentinstance.h" +#include +#include +#include +#include "progressmanager.h" +using KPIM::ProgressItem; +using KPIM::ProgressManager; + +KMAgentInstance::KMAgentInstance( QObject *parent, const Akonadi::AgentInstance & inst ) + :QObject( parent ), mAgentInstance( inst ), mProgressItem( 0 ) +{ + qDebug()<<" KMAgentInstance::KMAgentInstance"; +} + +KMAgentInstance::~KMAgentInstance() +{ + qDebug()<<" KMAgentInstance::~KMAgentInstance"; +} + +void KMAgentInstance::progressChanged(int progress) +{ + if ( !mProgressItem ) { + mProgressItem = ProgressManager::createProgressItem ("MailCheck"+mAgentInstance.name(),i18n("Preparing transmission from \"%1\"...", mAgentInstance.name() ) ); + connect( mProgressItem, SIGNAL( progressItemCanceled( KPIM::ProgressItem* ) ), this, SLOT( slotCanceled() ) ) ; + } + mProgressItem->setProgress( progress ); + if ( progress == 100 ) { + mProgressItem->setComplete(); + mProgressItem = 0; + } + qDebug()<<" progress changed :"<reset(); + mProgressItem = 0; +} + +#include "kmagentinstance.moc" + diff --git a/kmagentinstance.h b/kmagentinstance.h new file mode 100644 index 000000000..a9ac2b2b8 --- /dev/null +++ b/kmagentinstance.h @@ -0,0 +1,50 @@ +/* + This file is part of KMail, the KDE mail client. + Copyright (c) 2009 Montel Laurent + + KMail is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. + + KMail is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef KMAGENTINSTANCE_H +#define KMAGENTINSTANCE_H + +#include +#include +namespace KPIM { + class ProgressItem; +} + +using KPIM::ProgressItem; + +class KMAgentInstance : public QObject +{ + Q_OBJECT +public: + explicit KMAgentInstance( QObject *, const Akonadi::AgentInstance & ); + ~KMAgentInstance(); + + void progressChanged( int ); + +protected slots: + void slotCanceled(); + +private: + Akonadi::AgentInstance mAgentInstance; + ProgressItem *mProgressItem; + +}; + + +#endif /* KMAGENTINSTANCE_H */ + diff --git a/kmagentmanager.cpp b/kmagentmanager.cpp index 2d9d9c7ef..929a4047b 100644 --- a/kmagentmanager.cpp +++ b/kmagentmanager.cpp @@ -19,6 +19,7 @@ #include "kmagentmanager.h" #include #include +#include "kmagentinstance.h" KMAgentManager::KMAgentManager( QObject *parent ) : QObject( parent ) @@ -27,6 +28,17 @@ KMAgentManager::KMAgentManager( QObject *parent ) init(); } +KMAgentManager::~KMAgentManager() +{ + qDebug()<<" KMAgentManager::~KMAgentManager"; + QMapIterator i(lstAgentInstance); + while (i.hasNext()) { + i.next(); + delete i.value(); + } + lstAgentInstance.clear(); +} + void KMAgentManager::init() { Akonadi::AgentInstance::List lst = mAgentManager->instances(); @@ -34,10 +46,15 @@ void KMAgentManager::init() { if ( type.type().mimeTypes().contains( "message/rfc822" ) ) { mListInstance << type; + KMAgentInstance *agent = new KMAgentInstance( this, type ); + lstAgentInstance.insert( type.identifier(), agent ); + } } connect( mAgentManager, SIGNAL( instanceAdded( const Akonadi::AgentInstance & ) ), this, SLOT( slotInstanceAdded( const Akonadi::AgentInstance& ) ) ); connect( mAgentManager, SIGNAL( instanceRemoved( const Akonadi::AgentInstance & ) ), this, SLOT( slotInstanceRemoved( const Akonadi::AgentInstance& ) ) ); + + connect( mAgentManager, SIGNAL( instanceProgressChanged( const Akonadi::AgentInstance & ) ), this, SLOT( slotInstanceProgressChanged( const Akonadi::AgentInstance& ) ) ); } Akonadi::AgentInstance::List KMAgentManager::instanceList() const @@ -55,18 +72,31 @@ bool KMAgentManager::isEmpty() const return mListInstance.isEmpty(); } +void KMAgentManager::slotInstanceProgressChanged( const Akonadi::AgentInstance & instance ) +{ + qDebug()<<" slotInstanceProgressChanged"; + if ( lstAgentInstance.contains( instance.identifier() ) ) { + lstAgentInstance.value( instance.identifier() )->progressChanged(instance.progress()); + } +} + void KMAgentManager::slotInstanceAdded( const Akonadi::AgentInstance & instance) { qDebug()<<" KMAgentManager::slotInstanceAdded :"< +#include #include #include +class KMAgentInstance; + class KMAgentManager : public QObject { Q_OBJECT public: - KMAgentManager( QObject *parent ); + explicit KMAgentManager( QObject *parent ); + ~KMAgentManager(); bool isEmpty() const; Akonadi::AgentInstance::List instanceList() const; Akonadi::AgentInstance instance( const QString & ); protected slots: - void slotInstanceAdded( const Akonadi::AgentInstance & ); - void slotInstanceRemoved( const Akonadi::AgentInstance & ); - + void slotInstanceAdded( const Akonadi::AgentInstance &); + void slotInstanceRemoved( const Akonadi::AgentInstance &); + void slotInstanceProgressChanged( const Akonadi::AgentInstance &); private: void init(); + QMap lstAgentInstance; Akonadi::AgentInstance::List mListInstance; Akonadi::AgentManager * mAgentManager; };