File indexing completed on 2024-05-19 04:50:10
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "AmpacheConfig.h" 0018 0019 #include "core/support/Amarok.h" 0020 0021 0022 AmpacheConfig::AmpacheConfig() 0023 { 0024 load(); 0025 } 0026 0027 void 0028 AmpacheConfig::load() 0029 { 0030 KConfigGroup config = Amarok::config( "Service_Ampache" ); 0031 0032 int serverIndex = 0; 0033 QString serverEntry = "server" + QString::number( serverIndex ); 0034 0035 while ( config.hasKey( serverEntry ) ) 0036 { 0037 QStringList list = config.readEntry(serverEntry, QStringList() ); 0038 if ( list.isEmpty() ) 0039 continue; 0040 0041 AmpacheServerEntry entry; 0042 entry.name = list.takeFirst(); 0043 entry.url = QUrl( list.takeFirst() ); 0044 entry.username = list.takeFirst(); 0045 entry.password = list.takeFirst(); 0046 entry.addToCollection = false; //FIXME 0047 0048 m_servers.append( entry ); 0049 0050 serverIndex++; 0051 serverEntry = "server" + QString::number( serverIndex ); 0052 } 0053 } 0054 0055 void 0056 AmpacheConfig::save() 0057 { 0058 //delete all entries to make sure the indexes are correct 0059 KConfigGroup config = Amarok::config( "Service_Ampache" ); 0060 0061 int serverIndex = 0; 0062 QString serverEntry = "server" + QString::number( serverIndex ); 0063 0064 while ( config.hasKey ( serverEntry ) ) 0065 { 0066 // kDebug( 14310 ) << "deleting " << serverEntry; 0067 config.deleteEntry( serverEntry ); 0068 serverIndex++; 0069 serverEntry = "server" + QString::number( serverIndex ); 0070 } 0071 0072 for( int i = 0; i < m_servers.size(); i++ ) 0073 { 0074 AmpacheServerEntry entry = m_servers.at( i ); 0075 QStringList list; 0076 0077 list << entry.name; 0078 list << entry.url.url(); 0079 list << entry.username; 0080 list << entry.password; 0081 0082 serverEntry = "server" + QString::number( i ); 0083 // kDebug( 14310 ) << "adding " << serverEntry; 0084 config.writeEntry( serverEntry, list ); 0085 } 0086 } 0087 0088 int 0089 AmpacheConfig::serverCount() const 0090 { 0091 return m_servers.size(); 0092 } 0093 0094 AmpacheServerList 0095 AmpacheConfig::servers() const 0096 { 0097 return m_servers; 0098 } 0099 0100 void 0101 AmpacheConfig::addServer( const AmpacheServerEntry &server ) 0102 { 0103 m_servers.append( server ); 0104 } 0105 0106 void 0107 AmpacheConfig::removeServer( int index ) 0108 { 0109 m_servers.removeAt( index ); 0110 } 0111 0112 void 0113 AmpacheConfig::updateServer( int index, const AmpacheServerEntry & server ) 0114 { 0115 m_servers.removeAt( index ); 0116 m_servers.insert( index, server ); 0117 } 0118