kitchensync
synchistory.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 }
|