• Skip to content
  • Skip to link menu
KDE 4.5 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

KIMAP Library

idlejob.cpp

00001 /*
00002     Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #include "idlejob.h"
00021 
00022 #include <QtCore/QTimer>
00023 #include <KDE/KLocale>
00024 
00025 #include "job_p.h"
00026 #include "message_p.h"
00027 #include "session_p.h"
00028 
00029 namespace KIMAP
00030 {
00031   class IdleJobPrivate : public JobPrivate
00032   {
00033     public:
00034       IdleJobPrivate( IdleJob *job, Session *session, const QString& name )
00035         : JobPrivate( session, name ), q(job),
00036           messageCount( -1 ), recentCount( -1 ),
00037           lastMessageCount( -1 ), lastRecentCount( -1 ),
00038           originalSocketTimeout( -1 ) { }
00039       ~IdleJobPrivate() { }
00040 
00041       IdleJob * const q;
00042 
00043       int messageCount;
00044       int recentCount;
00045 
00046       int lastMessageCount;
00047       int lastRecentCount;
00048 
00049       int originalSocketTimeout;
00050   };
00051 }
00052 
00053 using namespace KIMAP;
00054 
00055 IdleJob::IdleJob( Session *session )
00056   : Job( *new IdleJobPrivate(this, session, i18nc("name of the idle job", "Idle")) )
00057 {
00058 }
00059 
00060 IdleJob::~IdleJob()
00061 {
00062 }
00063 
00064 void KIMAP::IdleJob::stop()
00065 {
00066   Q_D(IdleJob);
00067   d->sessionInternal()->setSocketTimeout( d->originalSocketTimeout );
00068   d->sessionInternal()->sendData( "DONE" );
00069 }
00070 
00071 void IdleJob::doStart()
00072 {
00073   Q_D(IdleJob);
00074   d->originalSocketTimeout = d->sessionInternal()->socketTimeout();
00075   d->sessionInternal()->setSocketTimeout( -1 );
00076   d->tags << d->sessionInternal()->sendCommand( "IDLE" );
00077 }
00078 
00079 void IdleJob::handleResponse( const Message &response )
00080 {
00081   Q_D(IdleJob);
00082 
00083   if (handleErrorReplies(response) == NotHandled ) {
00084     if ( response.content.size() > 0 && response.content[0].toString()=="+" ) {
00085       // Got the continuation all is fine
00086       return;
00087 
00088     } else if ( response.content[2].toString()=="EXISTS" ) {
00089       d->messageCount = response.content[1].toString().toInt();
00090     } else if ( response.content[2].toString()=="RECENT" ) {
00091       d->recentCount = response.content[1].toString().toInt();
00092     }
00093 
00094     if ( d->messageCount>=0 && d->recentCount>=0 ) {
00095       emit mailBoxStats(this, d->m_session->selectedMailBox(),
00096                         d->messageCount, d->recentCount);
00097 
00098       d->lastMessageCount = d->messageCount;
00099       d->lastRecentCount = d->recentCount;
00100 
00101       d->messageCount = -1;
00102       d->recentCount = -1;
00103     }
00104   }
00105 }
00106 
00107 QString KIMAP::IdleJob::lastMailBox() const
00108 {
00109   Q_D(const IdleJob);
00110   return d->m_session->selectedMailBox();
00111 }
00112 
00113 int KIMAP::IdleJob::lastMessageCount() const
00114 {
00115   Q_D(const IdleJob);
00116   return d->lastMessageCount;
00117 }
00118 
00119 int KIMAP::IdleJob::lastRecentCount() const
00120 {
00121   Q_D(const IdleJob);
00122   return d->lastRecentCount;
00123 }
00124 
00125 #include "idlejob.moc"

KIMAP Library

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kblog
  • kcal
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.7.1
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal