~ubuntu-branches/ubuntu/quantal/kdepim/quantal

« back to all changes in this revision

Viewing changes to libkdepim/agentprogressmonitor.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:51 UTC
  • mto: This revision was merged to the branch mainline in revision 193.
  • Revision ID: package-import@ubuntu.com-20111215141751-bmhdpiwl23wd9w26
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    void abort();
43
43
    void instanceProgressChanged( const AgentInstance &instance );
44
44
    void instanceStatusChanged( const AgentInstance &instance );
45
 
 
 
45
    void instanceRemoved( const Akonadi::AgentInstance& instance );
 
46
    void instanceNameChanged( const Akonadi::AgentInstance& instance );
46
47
    AgentProgressMonitor *const q;
47
48
    AgentInstance agent;
48
49
    QWeakPointer<ProgressItem> const item;
53
54
  agent.abortCurrentTask();
54
55
}
55
56
 
 
57
 
 
58
void AgentProgressMonitor::Private::instanceRemoved( const Akonadi::AgentInstance& instance )
 
59
{
 
60
  if ( !item.data() )
 
61
    return;
 
62
  item.data()->disconnect( q ); // avoid abort call
 
63
  item.data()->cancel();
 
64
  if( item.data() )
 
65
    item.data()->setComplete();
 
66
}
 
67
 
56
68
void AgentProgressMonitor::Private::instanceProgressChanged( const AgentInstance &instance )
57
69
{
58
70
  if ( !item.data() )
59
71
    return;
60
72
 
61
73
  if ( agent == instance ) {
 
74
    //Why ? agent = instance if agent == instance.
62
75
    agent = instance;
63
 
    if ( agent.progress() >= 0 ) {
64
 
      item.data()->setProgress( agent.progress() );
 
76
    const int progress = agent.progress();
 
77
    if ( progress >= 0 ) {
 
78
      item.data()->setProgress( progress );
65
79
    }
66
80
  }
67
81
}
72
86
    return;
73
87
 
74
88
  if ( agent == instance ) {
 
89
    //Why ? agent = instance if agent == instance.
75
90
    agent = instance;
76
91
    item.data()->setStatus( agent.statusMessage() );
77
92
    switch ( agent.status() ) {
78
93
      case AgentInstance::Idle:
79
 
        if( item.data() )             
 
94
        if( item.data() )
80
95
          item.data()->setComplete();
81
96
        break;
82
97
      case AgentInstance::Running:
83
98
        break;
84
 
      case AgentInstance::Broken: 
 
99
      case AgentInstance::Broken:
85
100
        item.data()->disconnect( q ); // avoid abort call
86
101
        item.data()->cancel();
87
102
        if( item.data() )
93
108
  }
94
109
}
95
110
 
 
111
void AgentProgressMonitor::Private::instanceNameChanged( const Akonadi::AgentInstance& instance )
 
112
{
 
113
  if ( !item.data() )
 
114
    return;
 
115
  item.data()->setLabel(instance.name());
 
116
}
 
117
 
96
118
 
97
119
 
98
120
AgentProgressMonitor::AgentProgressMonitor( const AgentInstance &agent,
104
126
      this, SLOT(instanceProgressChanged(Akonadi::AgentInstance)) );
105
127
  connect( AgentManager::self(), SIGNAL(instanceStatusChanged(Akonadi::AgentInstance)),
106
128
      this, SLOT(instanceStatusChanged(Akonadi::AgentInstance)) );
107
 
  // TODO connect to instanceError, instanceNameChanged, instanceWarning, instanceOnline,
108
 
  // instanceRemoved?  and do what?
 
129
  connect( Akonadi::AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)),
 
130
           this, SLOT(instanceRemoved(Akonadi::AgentInstance)) );
 
131
  connect( Akonadi::AgentManager::self(), SIGNAL(instanceNameChanged(Akonadi::AgentInstance)),
 
132
           this, SLOT(instanceNameChanged(Akonadi::AgentInstance)) );
 
133
  // TODO connect to instanceError, instanceWarning, instanceOnline ?
 
134
  // and do what?
109
135
 
110
136
  connect( item, SIGNAL(progressItemCanceled(KPIM::ProgressItem*)),
111
137
      this, SLOT(abort()) );
112
138
 
113
 
  // TODO what about usesCrypto?
114
 
 
115
139
  // TODO handle offline case
116
140
}
117
141