syncee.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qregexp.h>
00024
00025 #include <kdebug.h>
00026 #include <ksimpleconfig.h>
00027 #include <kstandarddirs.h>
00028
00029 #include "syncee.h"
00030
00031 using namespace KSync;
00032
00033 Syncee::Syncee( uint size )
00034 : mStatusLog( 0 ), mSupport( size )
00035 {
00036 mSyncMode = MetaLess;
00037 mFirstSync = false;
00038 mSupport.fill( true );
00039
00040 }
00041
00042 Syncee::~Syncee()
00043 {
00044 delete mStatusLog;
00045 }
00046
00047 void Syncee::setIdentifier( const QString &identifier )
00048 {
00049 mIdentifier = identifier;
00050 }
00051
00052 bool Syncee::isValid()
00053 {
00054 return !identifier().isEmpty();
00055 }
00056
00057 SyncEntry *Syncee::findEntry( const QString &id )
00058 {
00059
00060
00061 SyncEntry *entry = firstEntry();
00062 while ( entry ) {
00063 if ( entry->id() == id ) return entry;
00064 entry = nextEntry();
00065 }
00066
00067 return 0;
00068 }
00069
00070 void Syncee::replaceEntry( SyncEntry *oldEntry, SyncEntry *newEntry )
00071 {
00072 removeEntry( oldEntry );
00073 addEntry( newEntry );
00074 }
00075
00076 bool Syncee::hasChanged( SyncEntry *entry )
00077 {
00078
00079 if ( entry->timestamp().isEmpty() ) return true;
00080 if ( !mStatusLog ) return true;
00081
00082 mStatusLog->setGroup( entry->id() );
00083 QString timestamp = mStatusLog->readEntry( "Timestamp" );
00084
00085 return ( timestamp != entry->timestamp() );
00086 }
00087
00088 bool Syncee::loadLog()
00089 {
00090 if ( !isValid() ) {
00091 kdDebug() << "Syncee::loadLog(): Unable to load Sync log, identifier is "
00092 "empty." << endl;
00093 return false;
00094 }
00095
00096 delete mStatusLog;
00097
00098 QString logFile = locateLocal( "appdata", statusLogName() );
00099
00100 mStatusLog = new KSimpleConfig( logFile );
00101
00102 kdDebug() << "Syncee::loadLog() " << logFile << endl;
00103
00104 return true;
00105 }
00106
00107 bool Syncee::saveLog()
00108 {
00109 if ( !mStatusLog ) return false;
00110 for ( SyncEntry *entry = firstEntry(); entry; entry = nextEntry() ) {
00111 mStatusLog->setGroup( entry->id() );
00112 mStatusLog->writeEntry( "Name",entry->name() );
00113 mStatusLog->writeEntry( "Timestamp",entry->timestamp() );
00114 }
00115
00116 mStatusLog->sync();
00117
00118 return true;
00119 }
00120
00121 QString Syncee::statusLogName()
00122 {
00123 QString name = type();
00124
00125 name += "-" + identifier();
00126
00127 name.replace(QRegExp("/"),"_");
00128 name.replace(QRegExp(":"),"_");
00129
00130 name += ".syncee";
00131
00132 return name;
00133 }
00134
00135 int Syncee::modificationState( SyncEntry *entry ) const
00136 {
00137 return entry->state();
00138 }
00139
00140 int Syncee::syncMode() const
00141 {
00142 return mSyncMode;
00143 }
00144
00145 void Syncee::setSyncMode( int mode )
00146 {
00147 mSyncMode = mode;
00148 }
00149
00150 bool Syncee::firstSync() const
00151 {
00152 return mFirstSync;
00153 }
00154
00155 void Syncee::setFirstSync( bool first )
00156 {
00157 mFirstSync = first;
00158 }
00159
00160 void Syncee::insertId( const QString &type,
00161 const QString &konnectorId,
00162 const QString &kdeId )
00163 {
00164 QMap<QString, Kontainer::ValueList>::Iterator it;
00165 it = mMaps.find( type );
00166 if ( it == mMaps.end() ) {
00167 Kontainer::ValueList list;
00168 list.append( Kontainer(konnectorId, kdeId) );
00169 mMaps.replace( type, list);
00170 } else {
00171 it.data().append(Kontainer( konnectorId, kdeId) );
00172 }
00173 }
00174
00175 Kontainer::ValueList Syncee::ids( const QString &type ) const
00176 {
00177 Kontainer::ValueList id;
00178 QMap<QString, Kontainer::ValueList >::ConstIterator it;
00179 it = mMaps.find( type );
00180 if ( it != mMaps.end() ) id = it.data();
00181 return id;
00182 }
00183
00184 QMap<QString, Kontainer::ValueList> Syncee::ids() const
00185 {
00186 return mMaps;
00187 }
00188
00189 bool Syncee::trustIdsOnFirstSync() const
00190 {
00191 return false;
00192 }
00193
00194 QString Syncee::newId() const
00195 {
00196 return QString::null;
00197 }
00198
00199 void Syncee::setSupports( const QBitArray& ar )
00200 {
00201 mSupport = ar;
00202 mSupport.detach();
00203 kdDebug(5230) << "setSupports count is " << ar.size() << endl;
00204 }
00205
00206 QBitArray Syncee::bitArray() const
00207 {
00208 return mSupport;
00209 }
00210
00211 bool Syncee::isSupported( uint attr ) const
00212 {
00213 if ( attr >= mSupport.size() ) return false;
00214 return mSupport.testBit( attr );
00215 }
00216
00217 void Syncee::setSource( const QString& str )
00218 {
00219 mName = str;
00220 }
00221
00222 QString Syncee::source() const
00223 {
00224 return mName;
00225 }
This file is part of the documentation for kitchensync Library Version 3.3.2.