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

akonadi

changerecorder.cpp
00001 /*
00002     Copyright (c) 2007 Volker Krause <vkrause@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 "changerecorder.h"
00021 #include "changerecorder_p.h"
00022 
00023 #include <kdebug.h>
00024 #include <QtCore/QSettings>
00025 
00026 using namespace Akonadi;
00027 
00028 ChangeRecorder::ChangeRecorder( QObject * parent ) :
00029     Monitor( new ChangeRecorderPrivate( 0, this ), parent )
00030 {
00031 }
00032 
00033 ChangeRecorder::ChangeRecorder( ChangeRecorderPrivate *privateclass, QObject * parent ) :
00034     Monitor( privateclass, parent )
00035 {
00036 }
00037 
00038 ChangeRecorder::~ChangeRecorder()
00039 {
00040   Q_D( ChangeRecorder );
00041   d->saveNotifications();
00042 }
00043 
00044 void ChangeRecorder::setConfig(QSettings * settings)
00045 {
00046   Q_D( ChangeRecorder );
00047   if ( settings ) {
00048     d->settings = settings;
00049     Q_ASSERT( d->pendingNotifications.isEmpty() );
00050     d->loadNotifications();
00051   } else if ( d->settings ) {
00052     d->saveNotifications();
00053     d->settings = settings;
00054   }
00055 }
00056 
00057 void ChangeRecorder::replayNext()
00058 {
00059   Q_D( ChangeRecorder );
00060   if ( !d->pendingNotifications.isEmpty() ) {
00061     const NotificationMessage msg = d->pendingNotifications.head();
00062     // TODO kDebug() << msg;
00063     if ( d->ensureDataAvailable( msg ) )
00064       d->emitNotification( msg );
00065     else if ( !d->translateAndCompress( d->pipeline, msg ) ) {
00066       // In the case of a move where both source and destination are
00067       // ignored, we ignore the message and process the next one.
00068       d->pendingNotifications.dequeue();
00069       return replayNext();
00070     }
00071   } else {
00072     // This is necessary when none of the notifications were accepted / processed
00073     // above, and so there is no one to call changeProcessed() and the ChangeReplay task
00074     // will be stuck forever in the ResourceScheduler.
00075     emit nothingToReplay();
00076   }
00077   d->saveNotifications();
00078 }
00079 
00080 bool ChangeRecorder::isEmpty() const
00081 {
00082   Q_D( const ChangeRecorder );
00083   return d->pendingNotifications.isEmpty();
00084 }
00085 
00086 void ChangeRecorder::changeProcessed()
00087 {
00088   Q_D( ChangeRecorder );
00089   if ( !d->pendingNotifications.isEmpty() )
00090     d->pendingNotifications.dequeue();
00091 
00092   // SLOW! After loading 8000 notifications and processing one, we save back the 7999 remaining
00093   // ones, and then process the next one etc.
00094   // Testcase: mark 8000 emails as read.
00095   // TODO: Reserve 4 bytes at the beginning of the file, for the number of the next change
00096   // that must be processed. In the loading code, skip everything until that number.
00097   // Do a full-save only once the notifications list is empty (or only once in a while).
00098   d->saveNotifications();
00099 }
00100 
00101 void ChangeRecorder::setChangeRecordingEnabled( bool enable )
00102 {
00103   Q_D( ChangeRecorder );
00104   if ( d->enableChangeRecording == enable )
00105     return;
00106   d->enableChangeRecording = enable;
00107   if ( !enable )
00108     d->dispatchNotifications();
00109 }
00110 
00111 QString Akonadi::ChangeRecorder::dumpNotificationListToString() const
00112 {
00113   Q_D( const ChangeRecorder );
00114   return d->dumpNotificationListToString();
00115 }
00116 
00117 #include "changerecorder.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:52:52 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.8.3 API Reference

Skip menu "kdepimlibs-4.8.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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