[Amarok] save last.fm credentials in KWallet, rather than i

Orville Bennett illogical1 at gmail.com
Sat Aug 22 15:34:26 CEST 2009


Maximilian Kossick wrote:
> This is broken on OS X. Amarok now asks me for my last.fm
> username/password on each startup
I think if you link the kwallet (kwalletd?) exe to the path it'll work.
It's a wider KDE issue with finding progs in the .apps.

>
> On Sat, Aug 22, 2009 at 6:45 AM, Leo Franchi<lfranchi at kde.org>  wrote:
>> commit de46538288b61412c6362999e3da74a7866a9eb3
>> Author:     Leo Franchi<lfranchi at kde.org>
>> AuthorDate: Sat Aug 22 00:40:39 2009 -0700
>> Commit:     Leo Franchi<lfranchi at kde.org>
>> CommitDate: Sat Aug 22 00:41:47 2009 -0700
>>
>>     save last.fm credentials in KWallet, rather than in plaintext in
>>     amarokrc.
>>
>>     will migrate existing username/pw into KWallet silently and remove the
>>     text entries. we should use kwallet more, services save all sorts of
>>     private info in amarokrc :( it's really easy...
>>
>> diff --git a/src/services/lastfm/LastFmServiceConfig.cpp b/src/services/lastfm/LastFmServiceConfig.cpp
>> index 42781ef..2224944 100644
>> --- a/src/services/lastfm/LastFmServiceConfig.cpp
>> +++ b/src/services/lastfm/LastFmServiceConfig.cpp
>> @@ -19,6 +19,8 @@
>>   #include "LastFmServiceConfig.h"
>>   #include "Debug.h"
>>
>> +#include<KWallet/Wallet>
>> +
>>   LastFmServiceConfig::LastFmServiceConfig()
>>   {
>>      load();
>> @@ -30,8 +32,38 @@ LastFmServiceConfig::load()
>>   {
>>      debug()<<  "load config";
>>      KConfigGroup config = KGlobal::config()->group( configSectionName() );
>> -    m_username = config.readEntry( "username", QString() );
>> -    m_password = config.readEntry( "password", QString() );
>> +    // delete info from kconfig, as a safety measure
>> +
>> +    // check the wallet if it exists
>> +    KWallet::Wallet* wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous );
>> +    if( wallet )
>> +    {
>> +        if( !wallet->hasFolder( "Amarok" ) )
>> +            wallet->createFolder( "Amarok" );
>> +        // do a one-time transfer
>> +        // can remove at some point in the future, post-2.2
>> +        wallet->setFolder( "Amarok" );
>> +        if( config.hasKey( "password" ) )
>> +        {
>> +            wallet->writePassword( "lastfm_password", config.readEntry( "password" ) );
>> +            config.deleteEntry( "password" );
>> +        }
>> +        if( config.hasKey( "username" ) )
>> +        {
>> +            wallet->writeEntry( "lastfm_username", config.readEntry( "username" ).toUtf8() );
>> +            config.deleteEntry( "username" );
>> +        }
>> +
>> +        if( wallet->readPassword( "lastfm_password", m_password )>  0 )
>> +            debug()<<  "Failed to read lastfm password from kwallet!";
>> +        QByteArray rawUsername;
>> +        if( wallet->readEntry( "lastfm_username", rawUsername )>  0 )
>> +            debug()<<  "failed to read last.fm username from kwallet.. :(";
>> +        else
>> +            m_username = QString::fromUtf8( rawUsername );
>> +    }
>> +    delete wallet;
>> +
>>      m_sessionKey = config.readEntry( "sessionKey", QString() );
>>      m_scrobble = config.readEntry( "scrobble", true );
>>      m_fetchSimilar = config.readEntry( "fetchSimilar", true );
>> @@ -41,9 +73,20 @@ LastFmServiceConfig::load()
>>   void LastFmServiceConfig::save()
>>   {
>>      debug()<<  "save config";
>> +
>> +    KWallet::Wallet* wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous );
>> +
>> +    if( wallet )
>> +    {
>> +        wallet->setFolder( "Amarok" );
>> +        if( wallet->writePassword( "lastfm_password", m_password )>  0 )
>> +            debug()<<  "Failed to save last.fm pw to kwallet!";
>> +        if( wallet->writeEntry( "lastfm_username", m_username.toUtf8() )>  0 )
>> +            debug()<<  "Failed to save last.fm username to kwallet!";
>> +    }
>> +    delete wallet;
>> +
>>      KConfigGroup config = KGlobal::config()->group( configSectionName() );
>> -    config.writeEntry( "username", m_username );
>> -    config.writeEntry( "password", m_password );
>>      config.writeEntry( "sessionKey", m_sessionKey );
>>      config.writeEntry( "scrobble", m_scrobble );
>>      config.writeEntry( "fetchSimilar", m_fetchSimilar );
>>
>>
>>
> _______________________________________________
> Amarok-devel mailing list
> Amarok-devel at kde.org
> https://mail.kde.org/mailman/listinfo/amarok-devel



More information about the Amarok-devel mailing list