22 #include <Akonadi/AgentManager>
26 #include <QWeakPointer>
28 using namespace Akonadi;
31 class AgentProgressMonitor::Private
43 void instanceProgressChanged(
const AgentInstance &instance );
44 void instanceStatusChanged(
const AgentInstance &instance );
45 void instanceRemoved(
const Akonadi::AgentInstance& instance );
46 void instanceNameChanged(
const Akonadi::AgentInstance& instance );
49 QWeakPointer<ProgressItem>
const item;
52 void AgentProgressMonitor::Private::abort()
54 agent.abortCurrentTask();
58 void AgentProgressMonitor::Private::instanceRemoved(
const Akonadi::AgentInstance &instance )
66 item.data()->disconnect( q );
67 item.data()->cancel();
69 item.data()->setComplete();
73 void AgentProgressMonitor::Private::instanceProgressChanged(
const AgentInstance &instance )
79 if ( agent == instance ) {
82 const int progress = agent.progress();
83 if ( progress >= 0 ) {
84 item.data()->setProgress( progress );
89 void AgentProgressMonitor::Private::instanceStatusChanged(
const AgentInstance &instance )
94 if ( agent == instance ) {
97 item.data()->setStatus( agent.statusMessage() );
98 switch ( agent.status() ) {
99 case AgentInstance::Idle:
101 item.data()->setComplete();
103 case AgentInstance::Running:
105 case AgentInstance::Broken:
106 item.data()->disconnect( q );
107 item.data()->cancel();
109 item.data()->setComplete();
117 void AgentProgressMonitor::Private::instanceNameChanged(
const Akonadi::AgentInstance& instance )
121 item.data()->setLabel(instance.name());
126 AgentProgressMonitor::AgentProgressMonitor(
const AgentInstance &agent,
129 , d( new Private( this, agent, item ) )
131 connect( AgentManager::self(), SIGNAL(instanceProgressChanged(Akonadi::AgentInstance)),
132 this, SLOT(instanceProgressChanged(Akonadi::AgentInstance)) );
133 connect( AgentManager::self(), SIGNAL(instanceStatusChanged(Akonadi::AgentInstance)),
134 this, SLOT(instanceStatusChanged(Akonadi::AgentInstance)) );
135 connect( Akonadi::AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)),
136 this, SLOT(instanceRemoved(Akonadi::AgentInstance)) );
137 connect( Akonadi::AgentManager::self(), SIGNAL(instanceNameChanged(Akonadi::AgentInstance)),
138 this, SLOT(instanceNameChanged(Akonadi::AgentInstance)) );
143 this, SLOT(abort()) );
153 #include "agentprogressmonitor.moc"