• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkdepim

  • sources
  • kde-4.12
  • kdepim
  • libkdepim
  • progresswidget
agentprogressmonitor.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "agentprogressmonitor.h"
21 
22 #include <Akonadi/AgentManager>
23 
24 #include <KDebug>
25 
26 #include <QWeakPointer>
27 
28 using namespace Akonadi;
29 using namespace KPIM;
30 
31 class AgentProgressMonitor::Private
32 {
33 public:
34  Private( AgentProgressMonitor *qq, const AgentInstance &agnt, ProgressItem *itm )
35  : q( qq )
36  , agent( agnt )
37  , item ( itm )
38  {
39  }
40 
41  // slots:
42  void abort();
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 );
47  AgentProgressMonitor *const q;
48  AgentInstance agent;
49  QWeakPointer<ProgressItem> const item;
50 };
51 
52 void AgentProgressMonitor::Private::abort()
53 {
54  agent.abortCurrentTask();
55 }
56 
57 
58 void AgentProgressMonitor::Private::instanceRemoved( const Akonadi::AgentInstance &instance )
59 {
60  Q_UNUSED( instance );
61 
62  if ( !item.data() ) {
63  return;
64  }
65 
66  item.data()->disconnect( q ); // avoid abort call
67  item.data()->cancel();
68  if( item.data() ) {
69  item.data()->setComplete();
70  }
71 }
72 
73 void AgentProgressMonitor::Private::instanceProgressChanged( const AgentInstance &instance )
74 {
75  if ( !item.data() ) {
76  return;
77  }
78 
79  if ( agent == instance ) {
80  //Why ? agent = instance if agent == instance.
81  agent = instance;
82  const int progress = agent.progress();
83  if ( progress >= 0 ) {
84  item.data()->setProgress( progress );
85  }
86  }
87 }
88 
89 void AgentProgressMonitor::Private::instanceStatusChanged( const AgentInstance &instance )
90 {
91  if ( !item.data() )
92  return;
93 
94  if ( agent == instance ) {
95  //Why ? agent = instance if agent == instance.
96  agent = instance;
97  item.data()->setStatus( agent.statusMessage() );
98  switch ( agent.status() ) {
99  case AgentInstance::Idle:
100  if( item.data() )
101  item.data()->setComplete();
102  break;
103  case AgentInstance::Running:
104  break;
105  case AgentInstance::Broken:
106  item.data()->disconnect( q ); // avoid abort call
107  item.data()->cancel();
108  if( item.data() )
109  item.data()->setComplete();
110  break;
111  default:
112  Q_ASSERT( false );
113  }
114  }
115 }
116 
117 void AgentProgressMonitor::Private::instanceNameChanged( const Akonadi::AgentInstance& instance )
118 {
119  if ( !item.data() )
120  return;
121  item.data()->setLabel(instance.name());
122 }
123 
124 
125 
126 AgentProgressMonitor::AgentProgressMonitor( const AgentInstance &agent,
127  ProgressItem *item )
128  : QObject( item )
129  , d( new Private( this, agent, item ) )
130 {
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)) );
139  // TODO connect to instanceError, instanceWarning, instanceOnline ?
140  // and do what?
141 
142  connect( item, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
143  this, SLOT(abort()) );
144 
145  // TODO handle offline case
146 }
147 
148 AgentProgressMonitor::~AgentProgressMonitor()
149 {
150  delete d;
151 }
152 
153 #include "agentprogressmonitor.moc"
QObject
agentprogressmonitor.h
KPIM::AgentProgressMonitor
Definition: agentprogressmonitor.h:36
KPIM::ProgressItem
Definition: progressmanager.h:45
KPIM::AgentProgressMonitor::~AgentProgressMonitor
~AgentProgressMonitor()
Definition: agentprogressmonitor.cpp:148
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:58:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkdepim

Skip menu "libkdepim"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal