kitchensync

konnectorpairmanager.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2004 Tobias Koenig <tokoe@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 <kstandarddirs.h>
00023 
00024 #include "konnectorpairmanager.h"
00025 
00026 
00027 KonnectorPairManager::KonnectorPairManager( QObject *parent )
00028   : QObject( parent, "KonnectorPairManager" )
00029 {
00030 }
00031 
00032 KonnectorPairManager::~KonnectorPairManager()
00033 {
00034   KonnectorPair::Map::Iterator it;
00035   for ( it = mPairs.begin(); it != mPairs.end(); ++it )
00036     delete it.data();
00037 
00038   mPairs.clear();
00039 }
00040 
00041 void KonnectorPairManager::load()
00042 {
00043   KConfig config( configFile() );
00044 
00045   config.setGroup( "General" );
00046   QStringList pairUids = config.readListEntry( "PairUids" );
00047 
00048   QStringList::ConstIterator it;
00049   for ( it = pairUids.begin(); it != pairUids.end(); ++it ) {
00050     KonnectorPair *pair = new KonnectorPair;
00051     pair->setUid( *it );
00052     pair->load();
00053 
00054     mPairs.insert( pair->uid(), pair );
00055   }
00056 
00057   emit changed();
00058 }
00059 
00060 void KonnectorPairManager::save()
00061 {
00062   KConfig config( configFile() );
00063 
00064   config.setGroup( "General" );
00065   config.writeEntry( "PairUids", mPairs.keys() );
00066 
00067   KonnectorPair::Map::Iterator it;
00068   for ( it = mPairs.begin(); it != mPairs.end(); ++it )
00069     it.data()->save();
00070 }
00071 
00072 void KonnectorPairManager::add( KonnectorPair *pair )
00073 {
00074   mPairs.insert( pair->uid(), pair );
00075 
00076   emit changed();
00077 }
00078 
00079 void KonnectorPairManager::change( KonnectorPair *pair )
00080 {
00081   mPairs.insert( pair->uid(), pair );
00082 
00083   emit changed();
00084 }
00085 
00086 void KonnectorPairManager::remove( const QString &uid )
00087 {
00088   delete mPairs[ uid ];
00089   mPairs.remove( uid );
00090 
00091   emit changed();
00092 }
00093 
00094 KonnectorPair* KonnectorPairManager::pair( const QString &uid ) const
00095 {
00096   return mPairs[ uid ];
00097 }
00098 
00099 KonnectorPair::List KonnectorPairManager::pairs() const
00100 {
00101   return mPairs.values();
00102 }
00103 
00104 QString KonnectorPairManager::configFile() const
00105 {
00106   return locateLocal( "config", "multisynk_konnectorpairsrc" );
00107 }
00108 
00109 #include "konnectorpairmanager.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys