kitchensync
syncee.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 00005 Copyright (c) 2002,2004 Holger Hans Peter Freyther <freyther@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #include "syncee.h" 00024 #include "merger.h" 00025 00026 #include <kdebug.h> 00027 #include <ksimpleconfig.h> 00028 #include <kstandarddirs.h> 00029 00030 #include <qregexp.h> 00031 00032 00033 00034 00035 using namespace KSync; 00036 00037 Syncee::Syncee( Merger* merger ) 00038 : mMerger( merger ) 00039 {} 00040 00041 Syncee::~Syncee() 00042 { 00043 } 00044 00045 QString Syncee::identifier()const { 00046 return mIdentifier; 00047 } 00048 00049 void Syncee::setIdentifier( const QString &identifier ) 00050 { 00051 mIdentifier = identifier; 00052 } 00053 00054 bool Syncee::isValid() 00055 { 00056 return !identifier().isEmpty(); 00057 } 00058 00059 SyncEntry *Syncee::findEntry( const QString &id ) 00060 { 00061 00062 SyncEntry *entry = firstEntry(); 00063 while ( entry ) { 00064 if ( entry->id() == id ) return entry; 00065 entry = nextEntry(); 00066 } 00067 00068 return 0; 00069 } 00070 00071 void Syncee::replaceEntry( SyncEntry *oldEntry, SyncEntry *newEntry ) 00072 { 00073 removeEntry( oldEntry ); 00074 addEntry( newEntry ); 00075 00076 /* no risk no fun */ 00077 delete oldEntry; 00078 } 00079 00080 00081 int Syncee::modificationState( SyncEntry *entry ) const 00082 { 00083 return entry->state(); 00084 } 00085 00086 SyncEntry::PtrList Syncee::added() { 00087 return find( SyncEntry::Added ); 00088 } 00089 00090 SyncEntry::PtrList Syncee::modified() { 00091 return find( SyncEntry::Modified ); 00092 } 00093 00094 SyncEntry::PtrList Syncee::removed() { 00095 return find( SyncEntry::Removed ); 00096 } 00097 00098 void Syncee::insertId( const QString &type, 00099 const QString &konnectorId, 00100 const QString &kdeId ) 00101 { 00102 QMap<QString, Kontainer::ValueList>::Iterator it; 00103 it = mMaps.find( type ); 00104 if ( it == mMaps.end() ) { // not inserted yet anything 00105 Kontainer::ValueList list; 00106 list.append( Kontainer(konnectorId, kdeId) ); 00107 mMaps.replace( type, list); 00108 } else { 00109 it.data().append(Kontainer( konnectorId, kdeId) ); 00110 } 00111 } 00112 00113 Kontainer::ValueList Syncee::ids( const QString &type ) const 00114 { 00115 Kontainer::ValueList id; 00116 QMap<QString, Kontainer::ValueList >::ConstIterator it; 00117 it = mMaps.find( type ); 00118 if ( it != mMaps.end() ) id = it.data(); 00119 return id; 00120 } 00121 00122 QMap<QString, Kontainer::ValueList> Syncee::ids() const 00123 { 00124 return mMaps; 00125 } 00126 00127 bool Syncee::trustIdsOnFirstSync() const 00128 { 00129 return false; 00130 } 00131 00132 QString Syncee::generateNewId() const 00133 { 00134 return QString::null; 00135 } 00136 00137 Merger* Syncee::merger()const 00138 { 00139 return mMerger; 00140 } 00141 00142 void Syncee::setMerger( Merger *merger ) 00143 { 00144 mMerger = merger; 00145 } 00146 00147 void Syncee::setTitle( const QString& str ) 00148 { 00149 mTitle = str; 00150 } 00151 00152 QString Syncee::title() const 00153 { 00154 return mTitle; 00155 } 00156 00157 00158 void Syncee::setType(const QString& type ) 00159 { 00160 mType = type; 00161 } 00162 00163 QString Syncee::type()const 00164 { 00165 return mType; 00166 } 00167 00168 SyncEntry::PtrList Syncee::find( int state ) 00169 { 00170 QPtrList<SyncEntry> found; 00171 SyncEntry* entry; 00172 for ( entry = firstEntry(); entry != 0; entry = nextEntry() ) 00173 if ( entry->state() == state ) 00174 found.append( entry ); 00175 00176 00177 return found; 00178 } 00179 00180 00181