kitchensync

synchistory.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002,2003,2004 Holger Freyther <freyther@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 
00022 #include "synchistory.h"
00023 
00024 #include <kconfig.h>
00025 
00026 namespace KSync {
00027 
00040 SyncHistoryMap::SyncHistoryMap( const QString& file )
00041   : mFile( file ), mConf( 0l )
00042 {}
00043 
00044 
00049 SyncHistoryMap::~SyncHistoryMap()
00050 {
00051   delete mConf;
00052 }
00053 
00058 QString SyncHistoryMap::fileName()const
00059 {
00060   return mFile;
00061 }
00062 
00070 void SyncHistoryMap::load()
00071 {
00072   if ( mFile.isEmpty() )
00073     return;
00074 
00075   KConfig* conf = config();
00076   QStringList list = conf->groupList();
00077 
00078   for (QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
00079     conf->setGroup( (*it) );
00080     insert( (*it), conf->readEntry("sum") );
00081   }
00082 }
00083 
00084 
00091 void SyncHistoryMap::save()
00092 {
00093   KConfig* conf = config();
00094 
00095   QStringList groups = conf->groupList();
00096   for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it )
00097     conf->deleteGroup( (*it) );
00098 
00099 
00100   Iterator it;
00101   for ( it = mMap.begin(); it != mMap.end(); ++it ) {
00102     conf->setGroup( it.key() );
00103     conf->writeEntry( "sum", it.data() );
00104   }
00105   conf->sync();
00106 }
00107 
00114 QString SyncHistoryMap::text( const QString& id_key )const
00115 {
00116   return mMap[id_key];
00117 }
00118 
00122 bool SyncHistoryMap::contains( const QString& id_key )const
00123 {
00124   return mMap.contains( id_key );
00125 }
00126 
00134 void SyncHistoryMap::insert( const QString& id_key, const QString& text_data )
00135 {
00136   mMap.insert( id_key, text_data );
00137 }
00138 
00144 void SyncHistoryMap::set( const SyncHistoryMap::Map& map )
00145 {
00146   mMap = map;
00147 }
00148 
00149 
00153 SyncHistoryMap::Map SyncHistoryMap::map()const
00154 {
00155   return mMap;
00156 }
00157 
00162 void SyncHistoryMap::clear()
00163 {
00164   mMap.clear();
00165   KConfig* conf = config();
00166   QStringList groups = conf->groupList();
00167   for (QStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) {
00168     conf->deleteGroup( (*it) );
00169   }
00170 }
00171 
00172 
00176 KConfig* SyncHistoryMap::config()
00177 {
00178   if (!mConf )
00179     mConf = new KConfig( mFile, false, false );
00180 
00181   return mConf;
00182 }
00183 
00184 
00185 }
KDE Home | KDE Accessibility Home | Description of Access Keys