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

KIMAP Library

  • 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  }
131  }
132 
133  if ( d->messageCount>=0 && d->recentCount>=0 ) {
134  d->emitStats();
135  } else if ( d->messageCount>=0 || d->recentCount>=0 ) {
136  d->emitStatsTimer.start( 200 );
137  }
138  }
139 }
140 
141 QString KIMAP::IdleJob::lastMailBox() const
142 {
143  Q_D( const IdleJob );
144  return d->m_session->selectedMailBox();
145 }
146 
147 int KIMAP::IdleJob::lastMessageCount() const
148 {
149  Q_D( const IdleJob );
150  return d->lastMessageCount;
151 }
152 
153 int KIMAP::IdleJob::lastRecentCount() const
154 {
155  Q_D( const IdleJob );
156  return d->lastRecentCount;
157 }
158 
159 #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:147
KIMAP::IdleJob::lastRecentCount
int lastRecentCount() const
The last recent message count that was reported.
Definition: idlejob.cpp:153
KIMAP::IdleJob::stop
void stop()
Stops the idle job.
Definition: idlejob.cpp:83
KIMAP::IdleJob::lastMailBox
QString lastMailBox() const
The last mailbox status that was reported.
Definition: idlejob.cpp:141
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Tue Nov 26 2013 09:02:14 by doxygen 1.8.5 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-4.11.3 API Reference

Skip menu "kdepimlibs-4.11.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
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