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( 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.first(); 00062 if ( d->ensureDataAvailable( msg ) ) 00063 d->emitNotification( msg ); 00064 else 00065 d->pipeline.enqueue( msg ); 00066 } else { 00067 // This is necessary when none of the notifications were accepted / processed 00068 // above, and so there is no one to call changeProcessed() and the ChangeReplay task 00069 // will be stuck forever in the ResourceScheduler. 00070 emit nothingToReplay(); 00071 } 00072 d->saveNotifications(); 00073 } 00074 00075 bool ChangeRecorder::isEmpty() const 00076 { 00077 Q_D( const ChangeRecorder ); 00078 return d->pendingNotifications.isEmpty(); 00079 } 00080 00081 void ChangeRecorder::changeProcessed() 00082 { 00083 Q_D( ChangeRecorder ); 00084 if ( !d->pendingNotifications.isEmpty() ) 00085 d->pendingNotifications.removeFirst(); 00086 d->saveNotifications(); 00087 } 00088 00089 void ChangeRecorder::setChangeRecordingEnabled( bool enable ) 00090 { 00091 Q_D( ChangeRecorder ); 00092 if ( d->enableChangeRecording == enable ) 00093 return; 00094 d->enableChangeRecording = enable; 00095 if ( !enable ) 00096 d->dispatchNotifications(); 00097 } 00098 00099 #include "changerecorder.moc"