00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 Q_D( ChangeRecorder );
00032 d->init();
00033 d->connectToNotificationManager();
00034 }
00035
00036 ChangeRecorder::ChangeRecorder( ChangeRecorderPrivate *privateclass, QObject * parent ) :
00037 Monitor( privateclass, parent )
00038 {
00039 Q_D( ChangeRecorder );
00040 d->init();
00041 d->connectToNotificationManager();
00042 }
00043
00044 ChangeRecorder::~ ChangeRecorder()
00045 {
00046 Q_D( ChangeRecorder );
00047 d->saveNotifications();
00048 }
00049
00050 void ChangeRecorder::setConfig(QSettings * settings)
00051 {
00052 Q_D( ChangeRecorder );
00053 if ( settings ) {
00054 d->settings = settings;
00055 Q_ASSERT( d->pendingNotifications.isEmpty() );
00056 d->loadNotifications();
00057 } else if ( d->settings ) {
00058 d->saveNotifications();
00059 d->settings = settings;
00060 }
00061 }
00062
00063 void ChangeRecorder::replayNext()
00064 {
00065 Q_D( ChangeRecorder );
00066 if ( !d->pendingNotifications.isEmpty() ) {
00067 const NotificationMessage msg = d->pendingNotifications.first();
00068 if ( d->ensureDataAvailable( msg ) )
00069 d->emitNotification( msg );
00070 else
00071 d->pipeline.enqueue( msg );
00072 } else {
00073
00074
00075
00076 emit nothingToReplay();
00077 }
00078 d->saveNotifications();
00079 }
00080
00081 bool ChangeRecorder::isEmpty() const
00082 {
00083 Q_D( const ChangeRecorder );
00084 return d->pendingNotifications.isEmpty();
00085 }
00086
00087 void ChangeRecorder::changeProcessed()
00088 {
00089 Q_D( ChangeRecorder );
00090 if ( !d->pendingNotifications.isEmpty() )
00091 d->pendingNotifications.removeFirst();
00092 d->saveNotifications();
00093 }
00094
00095 void ChangeRecorder::setChangeRecordingEnabled( bool enable )
00096 {
00097 Q_D( ChangeRecorder );
00098 if ( d->enableChangeRecording == enable )
00099 return;
00100 d->enableChangeRecording = enable;
00101 if ( !enable )
00102 d->dispatchNotifications();
00103 }
00104
00105 #include "changerecorder.moc"