kitchensync
profilemanager.cpp
00001 /* 00002 This file is part of KitchenSync. 00003 00004 Copyright (c) 2002 Holger Freyther <zecke@handhelds.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 "profilemanager.h" 00023 00024 using namespace KSync; 00025 00026 ProfileManager::ProfileManager() 00027 { 00028 } 00029 00030 ProfileManager::ProfileManager( const Profile::List &list ) 00031 : mProfiles( list ) 00032 { 00033 } 00034 00035 ProfileManager::~ProfileManager() 00036 { 00037 } 00038 00039 Profile ProfileManager::currentProfile() const 00040 { 00041 return mCurrentProfile; 00042 } 00043 00044 void ProfileManager::setCurrentProfile( const Profile &prof ) 00045 { 00046 mCurrentProfile = prof; 00047 } 00048 00049 Profile::List ProfileManager::profiles() const 00050 { 00051 return mProfiles; 00052 } 00053 00054 void ProfileManager::setProfiles( const Profile::List &list ) 00055 { 00056 mProfiles = list; 00057 mCurrentProfile = Profile(); // invalidate 00058 } 00059 00060 Profile ProfileManager::byName( const QString &name ) 00061 { 00062 Profile prof; 00063 00064 Profile::List::Iterator it; 00065 for ( it = mProfiles.begin(); it != mProfiles.end(); ++it ) { 00066 if ( (*it).name() == name ) { 00067 prof = (*it); 00068 break; 00069 } 00070 } 00071 return prof; 00072 } 00073 00074 Profile::List ProfileManager::byName2( const QString& name ) 00075 { 00076 Profile::List list; 00077 Profile::List::Iterator it; 00078 for ( it = mProfiles.begin(); it != mProfiles.end(); ++it ) { 00079 if ( (*it).name() == name ) 00080 list.append( (*it) ); 00081 } 00082 return list; 00083 } 00084 00085 /* 00086 * Load from KConfig 00087 * there is a Global group for the current Profile ( id ) 00088 * and one Group for each Profile 00089 * 00090 */ 00091 void ProfileManager::load() 00092 { 00093 mProfiles = mProfileConfig.load(); 00094 } 00095 00096 void ProfileManager::save() 00097 { 00098 mProfileConfig.save( mProfiles ); 00099 } 00100 00101 void ProfileManager::addProfile( const Profile &prof ) 00102 { 00103 mProfiles.append( prof ); 00104 } 00105 00106 void ProfileManager::replaceProfile( const Profile &prod ) 00107 { 00108 mProfiles.remove( prod ); 00109 mProfiles.append( prod ); 00110 } 00111 00112 void ProfileManager::removeProfile( const Profile &prof ) 00113 { 00114 mProfiles.remove( prof ); 00115 } 00116 00117 Profile ProfileManager::profile( int i ) const 00118 { 00119 return mProfiles[i]; 00120 } 00121 00122 int ProfileManager::count() const 00123 { 00124 return mProfiles.count(); 00125 }