File indexing completed on 2024-05-19 04:50:17

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) version 3 or        *
0007  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0008  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0009  * version 3 of the license.                                                            *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018  
0019 #include "MagnatuneConfig.h"
0020 #include "MagnatuneMeta.h"
0021 #include "core/support/Amarok.h"
0022 
0023 #include <KConfigGroup>
0024 
0025 MagnatuneConfig::MagnatuneConfig()
0026 {
0027     load();
0028 }
0029 
0030 
0031 MagnatuneConfig::~MagnatuneConfig()
0032 {
0033 }
0034 
0035 void
0036 MagnatuneConfig::load()
0037 {
0038     m_hasChanged = false;
0039 
0040 //     qDebug() << "load";
0041 
0042     KConfigGroup config = Amarok::config( QStringLiteral("Service_Magnatune") );
0043 
0044     m_isMember = config.readEntry( "isMember", false );
0045 
0046     m_autoUpdate = config.readEntry( "autoUpdateDatabase", false );
0047 
0048     m_membershipType = config.readEntry( "membershipType", -1 );
0049 
0050     if( m_membershipType == -1 )
0051     {
0052         //try to read the old style string version if that is present and valid.
0053         const QString oldMEmbershipType = config.readEntry( "membershipType", QString() ).toLower();
0054         if( oldMEmbershipType == QLatin1String("stream") )
0055             m_membershipType = MagnatuneConfig::STREAM;
0056         else if ( oldMEmbershipType == QLatin1String("download") )
0057             m_membershipType = MagnatuneConfig::DOWNLOAD;
0058         else
0059             m_membershipType = MagnatuneConfig::DOWNLOAD;
0060             //default to download for now.   
0061     }
0062 
0063     m_username = config.readEntry( "username", QString() );
0064     m_password = config.readEntry( "password", QString() );
0065     m_email = config.readEntry( "email", QString() );
0066 
0067 
0068     qulonglong defaultLong = 0;
0069     m_lastUpdateTimestamp = config.readEntry( "lastUpdate", defaultLong );
0070 
0071     const QString streamTypeString = config.readEntry( "streamType", QString() );
0072    
0073 
0074     //make ogg the default
0075     if ( streamTypeString == QLatin1String("mp3") )
0076         m_streamType = MagnatuneMetaFactory::MP3;
0077     else if (  streamTypeString == QLatin1String("lofi_mp3") )
0078         m_streamType = MagnatuneMetaFactory::LOFI;
0079     else 
0080         m_streamType = MagnatuneMetaFactory::OGG;
0081     
0082 }
0083 
0084 void
0085 MagnatuneConfig::save()
0086 {
0087     qDebug() << "save";
0088     if ( m_hasChanged ) {
0089         KConfigGroup config = Amarok::config( QStringLiteral("Service_Magnatune") );
0090 
0091         config.writeEntry( "isMember", m_isMember );
0092         config.writeEntry( "autoUpdateDatabase", m_autoUpdate );
0093         config.writeEntry( "membershipType", m_membershipType );
0094         config.writeEntry( "username", m_username );
0095         config.writeEntry( "password", m_password );
0096         config.writeEntry( "lastUpdate", QVariant( m_lastUpdateTimestamp ) );
0097         config.writeEntry( "email", m_email );
0098         
0099         QString streamTypeString;
0100         if ( m_streamType == MagnatuneMetaFactory::MP3 )
0101             streamTypeString = QStringLiteral("mp3");
0102         else if ( m_streamType == MagnatuneMetaFactory::LOFI )
0103             streamTypeString = QStringLiteral("lofi_mp3");
0104         else
0105             streamTypeString = QStringLiteral("ogg");
0106 
0107         config.writeEntry( "streamType", streamTypeString );
0108 
0109     }
0110 }
0111 
0112 bool
0113 MagnatuneConfig::isMember()
0114 {
0115     return m_isMember;
0116 }
0117 
0118 void
0119 MagnatuneConfig::setIsMember( bool isMember )
0120 {
0121     m_hasChanged = true;
0122     m_isMember = isMember;
0123 }
0124 
0125 bool
0126 MagnatuneConfig::autoUpdateDatabase()
0127 {
0128     return m_autoUpdate;
0129 }
0130 
0131 void
0132 MagnatuneConfig::setAutoUpdateDatabase( bool value )
0133 {
0134     m_hasChanged = true;
0135     m_autoUpdate = value;
0136 }
0137 
0138 int
0139 MagnatuneConfig::membershipType()
0140 {
0141     return m_membershipType;
0142 }
0143 
0144 void
0145 MagnatuneConfig::setMembershipType( int membershipType )
0146 {
0147     m_hasChanged = true;
0148     m_membershipType = membershipType;
0149 }
0150 
0151 QString
0152 MagnatuneConfig::membershipPrefix()
0153 {
0154     QString prefix;
0155     if( m_membershipType == MagnatuneConfig::STREAM )
0156         prefix = QStringLiteral("stream");
0157     else
0158         prefix = QStringLiteral("download");
0159 
0160     return prefix;
0161 }
0162 
0163 QString
0164 MagnatuneConfig::username() const
0165 {
0166     return m_username;
0167 }
0168 
0169 QString
0170 MagnatuneConfig::password() const
0171 {
0172     return m_password;
0173 }
0174 
0175 void
0176 MagnatuneConfig::setUsername( const QString &username )
0177 {
0178     m_hasChanged = true;
0179     m_username = username;
0180 }
0181 
0182 void
0183 MagnatuneConfig::setPassword( const QString &password )
0184 {
0185     m_hasChanged = true;
0186     m_password = password;
0187 }
0188 
0189 
0190 int
0191 MagnatuneConfig::streamType() const
0192 {
0193     return m_streamType;
0194 }
0195 
0196 
0197 void
0198 MagnatuneConfig::setStreamType( int theValue )
0199 {
0200     m_streamType = theValue;
0201 }
0202 
0203 
0204 qulonglong
0205 MagnatuneConfig::lastUpdateTimestamp() const
0206 {
0207     return m_lastUpdateTimestamp;
0208 }
0209 
0210 void
0211 MagnatuneConfig::setLastUpdateTimestamp( qulonglong timestamp )
0212 {
0213     m_hasChanged = true;
0214     m_lastUpdateTimestamp = timestamp;
0215 }
0216 
0217 QString
0218 MagnatuneConfig::email() const
0219 {
0220     return m_email;
0221 }
0222 
0223 void
0224 MagnatuneConfig::setEmail( const QString &email )
0225 {
0226     m_email = email;
0227     m_hasChanged = true;
0228 }
0229