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

KIMAP Library

  • sources
  • kde-4.12
  • kdepimlibs
  • kimap
idlejob.cpp
1 /*
2  Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
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 "idlejob.h"
21 
22 #include <QtCore/QTimer>
23 #include <KDE/KLocalizedString>
24 
25 #include "job_p.h"
26 #include "message_p.h"
27 #include "session_p.h"
28 
29 namespace KIMAP
30 {
31  class IdleJobPrivate : public JobPrivate
32  {
33  public:
34  IdleJobPrivate( IdleJob *job, Session *session, const QString& name )
35  : JobPrivate( session, name ), q( job ),
36  messageCount( -1 ), recentCount( -1 ),
37  lastMessageCount( -1 ), lastRecentCount( -1 ),
38  originalSocketTimeout( -1 ) { }
39  ~IdleJobPrivate() { }
40 
41  void emitStats()
42  {
43  emitStatsTimer.stop();
44 
45  emit q->mailBoxStats( q, m_session->selectedMailBox(),
46  messageCount, recentCount );
47 
48  lastMessageCount = messageCount;
49  lastRecentCount = recentCount;
50 
51  messageCount = -1;
52  recentCount = -1;
53  }
54 
55  IdleJob * const q;
56 
57  QTimer emitStatsTimer;
58 
59  int messageCount;
60  int recentCount;
61 
62  int lastMessageCount;
63  int lastRecentCount;
64 
65  int originalSocketTimeout;
66  };
67 }
68 
69 using namespace KIMAP;
70 
71 IdleJob::IdleJob( Session *session )
72  : Job( *new IdleJobPrivate( this, session, i18nc( "name of the idle job", "Idle" ) ) )
73 {
74  Q_D( IdleJob );
75  connect( &d->emitStatsTimer, SIGNAL(timeout()),
76  this, SLOT(emitStats()) );
77 }
78 
79 IdleJob::~IdleJob()
80 {
81 }
82 
83 void KIMAP::IdleJob::stop()
84 {
85  Q_D( IdleJob );
86  d->sessionInternal()->setSocketTimeout( d->originalSocketTimeout );
87  d->sessionInternal()->sendData( "DONE" );
88 }
89 
90 void IdleJob::doStart()
91 {
92  Q_D( IdleJob );
93  d->originalSocketTimeout = d->sessionInternal()->socketTimeout();
94  d->sessionInternal()->setSocketTimeout( -1 );
95  d->tags << d->sessionInternal()->sendCommand( "IDLE" );
96 }
97 
98 void IdleJob::handleResponse( const Message &response )
99 {
100  Q_D( IdleJob );
101 
102  // We can predict it'll be handled by handleErrorReplies() so emit
103  // pending signals now (if needed) so that result() will really be
104  // the last emitted signal.
105  if ( !response.content.isEmpty() &&
106  d->tags.size() == 1 &&
107  d->tags.contains( response.content.first().toString() ) &&
108  ( d->messageCount >= 0 || d->recentCount >= 0 ) ) {
109  d->emitStats();
110  }
111 
112  if ( handleErrorReplies( response ) == NotHandled ) {
113  if ( response.content.size() > 0 && response.content[0].toString() == "+" ) {
114  // Got the continuation all is fine
115  return;
116 
117  } else if ( response.content.size() > 2 ) {
118  if ( response.content[2].toString() == "EXISTS" ) {
119  if ( d->messageCount >= 0 ) {
120  d->emitStats();
121  }
122 
123  d->messageCount = response.content[1].toString().toInt();
124  } else if ( response.content[2].toString() == "RECENT" ) {
125  if ( d->recentCount >= 0 ) {
126  d->emitStats();
127  }
128 
129  d->recentCount = response.content[1].toString().toInt();
130  } else if ( response.content[2].toString() == "FETCH" ) {
131  const qint64 uid = response.content[1].toString().toLongLong();
132  Q_EMIT mailBoxMessageFlagsChanged( this, uid );
133  }
134  }
135 
136  if ( d->messageCount>=0 && d->recentCount>=0 ) {
137  d->emitStats();
138  } else if ( d->messageCount>=0 || d->recentCount>=0 ) {
139  d->emitStatsTimer.start( 200 );
140  }
141  }
142 }
143 
144 QString KIMAP::IdleJob::lastMailBox() const
145 {
146  Q_D( const IdleJob );
147  return d->m_session->selectedMailBox();
148 }
149 
150 int KIMAP::IdleJob::lastMessageCount() const
151 {
152  Q_D( const IdleJob );
153  return d->lastMessageCount;
154 }
155 
156 int KIMAP::IdleJob::lastRecentCount() const
157 {
158  Q_D( const IdleJob );
159  return d->lastRecentCount;
160 }
161 
162 #include "moc_idlejob.cpp"
KIMAP::IdleJob
Idles the connection to the IMAP server.
Definition: idlejob.h:63
KIMAP::IdleJob::lastMessageCount
int lastMessageCount() const
The last message count that was reported.
Definition: idlejob.cpp:150
KIMAP::IdleJob::lastRecentCount
int lastRecentCount() const
The last recent message count that was reported.
Definition: idlejob.cpp:156
KIMAP::IdleJob::stop
void stop()
Stops the idle job.
Definition: idlejob.cpp:83
KIMAP::IdleJob::mailBoxMessageFlagsChanged
void mailBoxMessageFlagsChanged(KIMAP::IdleJob *job, qint64 uid)
Signals that the server has notified that the some messages flags have changed.
KIMAP::IdleJob::lastMailBox
QString lastMailBox() const
The last mailbox status that was reported.
Definition: idlejob.cpp:144
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIMAP Library

Skip menu "KIMAP Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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