Add a kmagentinstance to allow to add a kpim::progressitem

svn path=/branches/work/akonadi-ports/kdepim/; revision=1045645
wilder-work
Laurent Montel 17 years ago
parent 1cd34ad2b0
commit ca67ea9ba2
  1. 1
      CMakeLists.txt
  2. 60
      kmagentinstance.cpp
  3. 50
      kmagentinstance.h
  4. 34
      kmagentmanager.cpp
  5. 13
      kmagentmanager.h

@ -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

@ -0,0 +1,60 @@
/*
This file is part of KMail, the KDE mail client.
Copyright (c) 2009 Montel Laurent <montel@kde.org>
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 <akonadi/agentinstance.h>
#include <QDebug>
#include <KLocale>
#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 :"<<progress;
}
void KMAgentInstance::slotCanceled()
{
mAgentInstance.abortCurrentTask();
mProgressItem->reset();
mProgressItem = 0;
}
#include "kmagentinstance.moc"

@ -0,0 +1,50 @@
/*
This file is part of KMail, the KDE mail client.
Copyright (c) 2009 Montel Laurent <montel@kde.org>
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 <QObject>
#include <akonadi/agentinstance.h>
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 */

@ -19,6 +19,7 @@
#include "kmagentmanager.h"
#include <QDebug>
#include <QStringList>
#include "kmagentinstance.h"
KMAgentManager::KMAgentManager( QObject *parent )
: QObject( parent )
@ -27,6 +28,17 @@ KMAgentManager::KMAgentManager( QObject *parent )
init();
}
KMAgentManager::~KMAgentManager()
{
qDebug()<<" KMAgentManager::~KMAgentManager";
QMapIterator<QString, KMAgentInstance*> 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 :"<<instance.name();
if ( instance.type().mimeTypes().contains( "message/rfc822" ) )
if ( instance.type().mimeTypes().contains( "message/rfc822" ) ) {
mListInstance << instance;
KMAgentInstance *agent = new KMAgentInstance( this, instance );
lstAgentInstance.insert( instance.identifier(), agent );
}
}
void KMAgentManager::slotInstanceRemoved( const Akonadi::AgentInstance &instance )
{
qDebug()<<" KMAgentManager::slotInstanceRemoved :"<<instance.name();
if ( mListInstance.contains( instance ) )
if ( mListInstance.contains( instance ) ) {
mListInstance.removeAll( instance );
lstAgentInstance.remove( instance.identifier() );
}
}
#include "kmagentmanager.moc"

@ -20,26 +20,31 @@
#define KMAGENTMANAGER_H
#include <QObject>
#include <QMap>
#include <akonadi/agentinstance.h>
#include <akonadi/agentmanager.h>
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<QString, KMAgentInstance*> lstAgentInstance;
Akonadi::AgentInstance::List mListInstance;
Akonadi::AgentManager * mAgentManager;
};

Loading…
Cancel
Save