[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: [Amarok] save last.fm credentials in KWallet, rather than i
From:       Maximilian Kossick <maximilian.kossick () googlemail ! com>
Date:       2009-08-22 9:26:06
Message-ID: c3d78d90908220226p74f4b586j4b43548f3cf1ca94 () mail ! gmail ! com
[Download RAW message or body]

This is broken on OS X. Amarok now asks me for my last.fm
username/password on each startup

On Sat, Aug 22, 2009 at 6:45 AM, Leo Franchi<lfranchi@kde.org> wrote:
> commit de46538288b61412c6362999e3da74a7866a9eb3
> Author:     Leo Franchi <lfranchi@kde.org>
> AuthorDate: Sat Aug 22 00:40:39 2009 -0700
> Commit:     Leo Franchi <lfranchi@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 );
> 
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic