File indexing completed on 2024-05-19 04:50:21
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #include "Mp3tunesConfig.h" 0019 0020 #include "core/support/Amarok.h" 0021 0022 #include <KConfigGroup> 0023 0024 #include <QNetworkInterface> 0025 0026 Mp3tunesConfig::Mp3tunesConfig() 0027 { 0028 m_hasChanged = false; 0029 load(); 0030 } 0031 0032 0033 Mp3tunesConfig::~Mp3tunesConfig() 0034 { 0035 } 0036 0037 void Mp3tunesConfig::load() 0038 { 0039 // kDebug( 14310 ) << "load"; 0040 KConfigGroup config = Amarok::config( "Service_Mp3tunes" ); 0041 m_email = config.readEntry( "email", QString() ); 0042 m_password = config.readEntry( "password", QString() ); 0043 m_identifier = config.readEntry( "identifier", QString() ); 0044 m_pin = config.readEntry( "pin", QString() ); 0045 m_harmonyEmail = config.readEntry( "harmonyEmail", QString() ); 0046 m_partnerToken = config.readEntry( "partnerToken", QString( "4895500420" ) ); 0047 m_harmonyEnabled = config.readEntry( "harmonyEnabled", false ); 0048 0049 if( m_identifier.isEmpty() ) 0050 { 0051 foreach( const QNetworkInterface &iface, QNetworkInterface::allInterfaces() ) 0052 { 0053 QString addr = iface.hardwareAddress(); 0054 if( addr != "00:00:00:00:00:00" ) { 0055 addr.remove( ':' ); 0056 // kDebug( 14310 ) << "Using iface \"" << iface.name() << " addr: " << addr; 0057 setIdentifier( addr + m_partnerToken ); 0058 save(); 0059 break; 0060 } 0061 } 0062 } 0063 } 0064 0065 void Mp3tunesConfig::save() 0066 { 0067 // kDebug( 14310 ) << "save"; 0068 if ( m_hasChanged ) { 0069 KConfigGroup config = Amarok::config( "Service_Mp3tunes" ); 0070 config.writeEntry( "email", m_email ); 0071 config.writeEntry( "password", m_password ); 0072 config.writeEntry( "identifier", m_identifier ); 0073 config.writeEntry( "harmonyEnabled", m_harmonyEnabled ); 0074 config.writeEntry( "partnerToken", m_partnerToken ); 0075 config.writeEntry( "harmonyEmail", m_harmonyEmail ); 0076 config.writeEntry( "pin", m_pin ); 0077 } 0078 } 0079 0080 QString Mp3tunesConfig::email() 0081 { 0082 return m_email; 0083 } 0084 0085 QString Mp3tunesConfig::password() 0086 { 0087 return m_password; 0088 } 0089 0090 QString Mp3tunesConfig::partnerToken() 0091 { 0092 return m_partnerToken; 0093 } 0094 0095 QString Mp3tunesConfig::identifier() 0096 { 0097 return m_identifier; 0098 } 0099 0100 QString Mp3tunesConfig::pin() 0101 { 0102 return m_pin; 0103 } 0104 0105 QString Mp3tunesConfig::harmonyEmail() 0106 { 0107 return m_harmonyEmail; 0108 } 0109 0110 bool Mp3tunesConfig::harmonyEnabled() 0111 { 0112 return m_harmonyEnabled; 0113 } 0114 0115 void Mp3tunesConfig::setHarmonyEnabled( bool enabled ) 0116 { 0117 // kDebug( 14310 ) << "set harmony"; 0118 if ( enabled != m_harmonyEnabled ) { 0119 m_harmonyEnabled = enabled; 0120 m_hasChanged = true; 0121 } 0122 } 0123 0124 void Mp3tunesConfig::setIdentifier( const QString &ident ) 0125 { 0126 // kDebug( 14310 ) << "set hwaddress"; 0127 if ( ident != m_identifier ) { 0128 m_identifier = ident; 0129 m_hasChanged = true; 0130 } 0131 } 0132 0133 void Mp3tunesConfig::setEmail( const QString &email ) 0134 { 0135 // kDebug( 14310 ) << "set email"; 0136 if ( email != m_email ) { 0137 m_email = email; 0138 m_hasChanged = true; 0139 } 0140 } 0141 0142 void Mp3tunesConfig::setPassword( const QString &password ) 0143 { 0144 // kDebug( 14310 ) << "set Password"; 0145 if( password != m_password ) { 0146 m_password = password; 0147 m_hasChanged = true; 0148 } 0149 } 0150 0151 void Mp3tunesConfig::setPartnerToken( const QString &token ) 0152 { 0153 // kDebug( 14310 ) << "set token"; 0154 if( token != m_partnerToken ) { 0155 m_partnerToken = token; 0156 m_hasChanged = true; 0157 } 0158 } 0159 0160 void Mp3tunesConfig::setPin( const QString &pin ) 0161 { 0162 // kDebug( 14310 ) << "set pin"; 0163 if( pin != m_pin ) { 0164 m_pin = pin; 0165 m_hasChanged = true; 0166 } 0167 } 0168 0169 void Mp3tunesConfig::setHarmonyEmail( const QString &harmonyEmail ) 0170 { 0171 // kDebug( 14310 ) << "set harmonyEmail"; 0172 if( harmonyEmail != m_harmonyEmail ) { 0173 m_harmonyEmail = harmonyEmail; 0174 m_hasChanged = true; 0175 } 0176 }