From 6a6f5dba7a787ba8f9d60a007e0737e25065254b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Fri, 24 Feb 2012 16:53:33 +0100 Subject: [PATCH 1/7] Beginning of a bad spotifyAccount --- src/libtomahawk/CMakeLists.txt | 3 +- src/libtomahawk/accounts/SpotifyAccount.cpp | 93 ++++++++++++++++++++ src/libtomahawk/accounts/SpotifyAccount.h | 67 ++++++++++++++ src/libtomahawk/resolvers/scriptresolver.cpp | 25 +++++- src/libtomahawk/resolvers/scriptresolver.h | 3 +- 5 files changed, 188 insertions(+), 3 deletions(-) create mode 100644 src/libtomahawk/accounts/SpotifyAccount.cpp create mode 100644 src/libtomahawk/accounts/SpotifyAccount.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 3ddce4215..9aa842e64 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -310,6 +310,7 @@ set( libSources accounts/ResolverAccount.cpp accounts/LastFmAccount.cpp accounts/LastFmConfig.cpp + accounts/SpotifyAccount.cpp sip/SipPlugin.cpp sip/SipHandler.cpp @@ -454,7 +455,7 @@ set( libHeaders accounts/ResolverAccount.h accounts/LastFmAccount.h accounts/LastFmConfig.h - + accounts/SpotifyAccount.h EchonestCatalogSynchronizer.h sip/SipPlugin.h diff --git a/src/libtomahawk/accounts/SpotifyAccount.cpp b/src/libtomahawk/accounts/SpotifyAccount.cpp new file mode 100644 index 000000000..b806a3de5 --- /dev/null +++ b/src/libtomahawk/accounts/SpotifyAccount.cpp @@ -0,0 +1,93 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "SpotifyAccount.h" +#include "playlist.h" +#include "utils/tomahawkutils.h" +#include "PlaylistUpdaterInterface.h" +#include "sourcelist.h" + +using namespace Tomahawk; +using namespace Accounts; + +SpotifyResolverAccount::SpotifyResolverAccount() +{ + qDebug() << Q_FUNC_INFO; +} +SpotifyResolverAccount::~SpotifyResolverAccount() +{ + qDebug() << Q_FUNC_INFO; +} + +void +SpotifyResolverAccount::addPlaylist(const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks) +{ + Sync sync; + sync.id_ = qid; + int index = m_syncPlaylists.indexOf( sync ); + + if( !m_syncPlaylists.contains( sync ) ) + { + qDebug() << Q_FUNC_INFO << "Adding playlist to sync" << qid; + playlist_ptr pl; + pl = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), + uuid(), + title, + QString(), + QString(), + false, + tracks ); + sync.playlist = pl; + sync.uuid = pl->guid(); + m_syncPlaylists.append( sync ); + } + else{ + + qDebug() << Q_FUNC_INFO << "Found playlist"; + + if( index != -1 && !tracks.isEmpty()) + { + + qDebug() << Q_FUNC_INFO << "Got pl" << m_syncPlaylists[ index ].playlist->guid(); + + QList< query_ptr > currTracks; + foreach ( const plentry_ptr ple, m_syncPlaylists[ index ].playlist->entries() ) + currTracks << ple->query(); + + qDebug() << Q_FUNC_INFO << "tracks" << currTracks; + + QList< query_ptr > mergedTracks = TomahawkUtils::mergePlaylistChanges( currTracks, tracks ); + + QList el = m_syncPlaylists[ index ].playlist->entriesFromQueries( mergedTracks, true ); + m_syncPlaylists[ index ].playlist->createNewRevision( uuid(), m_syncPlaylists[ index ].playlist->currentrevision(), el ); + + } + } + + +} + + + +bool operator==(SpotifyResolverAccount::Sync one, SpotifyResolverAccount::Sync two) +{ + if(one.id_ == two.id_) + return true; + return false; +} + diff --git a/src/libtomahawk/accounts/SpotifyAccount.h b/src/libtomahawk/accounts/SpotifyAccount.h new file mode 100644 index 000000000..db27dffd8 --- /dev/null +++ b/src/libtomahawk/accounts/SpotifyAccount.h @@ -0,0 +1,67 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef SpotifyAccount_H +#define SpotifyAccount_H + +#include "playlist.h" +#include "utils/tomahawkutils.h" +#include "sourcelist.h" +#include "ResolverAccount.h" +class QTimer; + +namespace Tomahawk { + +class ExternalResolverGui; + +namespace Accounts { + +class SpotifyResolverAccount : public QObject // : public AccountFactory +{ + Q_OBJECT +public: + SpotifyResolverAccount(); + virtual ~SpotifyResolverAccount(); + + /*virtual Account* createAccount(const QString& accountId = QString()); + virtual QString description() const { return tr( "Play and sync your playlists with Spotify" ); } + virtual QString factoryId() const { return "spotifyaccount"; } + virtual QString prettyName() const { return "Spotify"; } + + virtual AccountTypes types() const { return AccountTypes( ResolverType ); } + virtual bool allowUserCreation() const { return false; } + virtual QPixmap icon() const { return m_icon; } + virtual bool isUnique() const { return true; } + */ + void addPlaylist(const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks); + struct Sync { + QString id_; + QString uuid; + Tomahawk::playlist_ptr playlist; + }; + +private: + QList m_syncPlaylists; + int m_sCount; + +}; +} + +} + +#endif // SpotifyAccount_H diff --git a/src/libtomahawk/resolvers/scriptresolver.cpp b/src/libtomahawk/resolvers/scriptresolver.cpp index 9fd1b96cc..5f5fb2193 100644 --- a/src/libtomahawk/resolvers/scriptresolver.cpp +++ b/src/libtomahawk/resolvers/scriptresolver.cpp @@ -55,6 +55,7 @@ ScriptResolver::ScriptResolver( const QString& exe ) // set the name to the binary, if we launch properly we'll get the name the resolver reports m_name = QFileInfo( filePath() ).baseName(); + m_account = new Tomahawk::Accounts::SpotifyResolverAccount(); } @@ -228,7 +229,7 @@ ScriptResolver::handleMsg( const QByteArray& msg ) return; } - if ( msgtype == "results" ) + else if ( msgtype == "results" ) { const QString qid = m.value( "qid" ).toString(); QList< Tomahawk::result_ptr > results; @@ -265,6 +266,28 @@ ScriptResolver::handleMsg( const QByteArray& msg ) Tomahawk::Pipeline::instance()->reportResults( qid, results ); } + else if ( msgtype == "playlist" ) + { + + QList< Tomahawk::query_ptr > tracks; + const QString qid = m.value( "qid" ).toString(); + const QString title = m.value( "identifier" ).toString(); + const QVariantList reslist = m.value( "playlist" ).toList(); + + if( !reslist.isEmpty() ) + { + foreach( const QVariant& rv, reslist ) + { + QVariantMap m = rv.toMap(); + qDebug() << "Found playlist result:" << m; + Tomahawk::query_ptr q = Tomahawk::Query::get( m.value( "artist" ).toString() , m.value( "track" ).toString() , QString(), uuid(), false ); + tracks << q; + } + + if(m_account) + m_account->addPlaylist( qid, title, tracks); + } + } } diff --git a/src/libtomahawk/resolvers/scriptresolver.h b/src/libtomahawk/resolvers/scriptresolver.h index f8e94b0ff..037a29376 100644 --- a/src/libtomahawk/resolvers/scriptresolver.h +++ b/src/libtomahawk/resolvers/scriptresolver.h @@ -27,7 +27,7 @@ #include "query.h" #include "ExternalResolverGui.h" - +#include "accounts/SpotifyAccount.h" #include "dllmacro.h" class QWidget; @@ -90,6 +90,7 @@ private: QJson::Parser m_parser; QJson::Serializer m_serializer; + Tomahawk::Accounts::SpotifyResolverAccount *m_account; }; #endif // SCRIPTRESOLVER_H From 970b3e79a99552ec2cd789bf11256211c50dd5e7 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 21:49:50 -0500 Subject: [PATCH 2/7] Properly load spotify account --- src/libtomahawk/accounts/Account.h | 4 +++ src/libtomahawk/accounts/AccountManager.cpp | 30 ++++++++++++++++++++ src/libtomahawk/accounts/AccountManager.h | 16 +++++++++++ src/libtomahawk/accounts/ResolverAccount.cpp | 7 +++++ src/libtomahawk/accounts/ResolverAccount.h | 4 +++ src/libtomahawk/accounts/SpotifyAccount.cpp | 23 +++++++++++++++ src/libtomahawk/accounts/SpotifyAccount.h | 4 +++ src/settingsdialog.cpp | 3 +- 8 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 73a7dedee..93fcda654 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -180,6 +180,10 @@ public: virtual AccountTypes types() const = 0; virtual Account* createAccount( const QString& accountId = QString() ) = 0; + + /// If this resolver type accepts this path on disk (For general and special resolver accounts) + virtual bool acceptsPath( const QString& path ) const { return false; } + virtual Account* createFromPath( const QString& path ) { return 0; } }; }; diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index ae0b96f99..df8177bac 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -22,6 +22,7 @@ #include "sourcelist.h" #include "ResolverAccount.h" #include "LastFmAccount.h" +#include "SpotifyAccount.h" #include #include @@ -59,9 +60,14 @@ AccountManager::AccountManager( QObject *parent ) // We include the resolver factory manually, not in a plugin ResolverAccountFactory* f = new ResolverAccountFactory(); m_accountFactories[ f->factoryId() ] = f; + registerAccountFactoryForFilesystem( f ); LastFmAccountFactory* l = new LastFmAccountFactory(); m_accountFactories[ l->factoryId() ] = l; + + SpotifyAccountFactory* s = new SpotifyAccountFactory; + m_accountFactories[ s->factoryId() ] = s; + registerAccountFactoryForFilesystem( s ); } @@ -331,6 +337,30 @@ AccountManager::removeAccount( Account* account ) } +Account* +AccountManager::accountFromPath( const QString& accountPath ) +{ + foreach ( AccountFactory* factory, m_factoriesForFilesytem ) + { + if ( factory->acceptsPath( accountPath ) ) + { + return factory->createFromPath( accountPath ); + } + } + + Q_ASSERT_X( false, "Shouldn't have had no account factory accepting a path.. at least ResolverAccount!!", ""); + return 0; +} + + +void +AccountManager::registerAccountFactoryForFilesystem( AccountFactory* factory ) +{ + m_factoriesForFilesytem.prepend( factory ); +} + + + void AccountManager::hookupAccount( Account* account ) const { diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 969edd27f..acec261d9 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -61,6 +61,21 @@ public: QList< Account* > accounts() const { return m_accounts; }; QList< Account* > accounts( Tomahawk::Accounts::AccountType type ) const { return m_accountsByAccountType[ type ]; } + /** + * Returns a new Account for a certain path on disk. This will go through all on-disk resolver account providers + * to find the most specific account that matches this. + * + * The fallback is ResolverAccount, which handles our generic external script resolvers. + */ + Account* accountFromPath( const QString& path ); + + /** + * Registers an account factory as being able to "handle" resolvers on disk. When accountFromPath is called + * AccountManager will go through all registered account factories in order until it finds one that can handle the path. + * This is searched in LIFO order. + */ + void registerAccountFactoryForFilesystem( AccountFactory* factory ); + public slots: void connectAll(); void disconnectAll(); @@ -97,6 +112,7 @@ private: QHash< AccountType, QList< Account* > > m_accountsByAccountType; QHash< QString, AccountFactory* > m_accountFactories; + QList< AccountFactory* > m_factoriesForFilesytem; static AccountManager* s_instance; }; diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 95acbe284..76efe47fd 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -45,6 +45,13 @@ ResolverAccountFactory::createAccount( const QString& accountId ) } +Account* +ResolverAccountFactory::createFromPath( const QString& path ) +{ + return createFromPath( path, false ); +} + + Account* ResolverAccountFactory::createFromPath( const QString& path, bool isAttica ) { diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index e02a7bfe1..db33f157d 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -44,6 +44,10 @@ public: // Used to create a new resolver from a script on disk, either chosen by // the user, or installed from synchrotron + virtual bool acceptsPath( const QString& path ) const { return true; } // This is the catch-all filesystem account + virtual Account* createFromPath( const QString& path ); + + // Internal use static Account* createFromPath( const QString& path, bool isAttica ); }; diff --git a/src/libtomahawk/accounts/SpotifyAccount.cpp b/src/libtomahawk/accounts/SpotifyAccount.cpp index e9b1dc8f1..24a52c081 100644 --- a/src/libtomahawk/accounts/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/SpotifyAccount.cpp @@ -35,6 +35,22 @@ SpotifyAccountFactory::createAccount( const QString& accountId ) return new SpotifyAccount( accountId ); } + +bool +SpotifyAccountFactory::acceptsPath( const QString& path ) const +{ + QFileInfo info( path ); + return info.baseName().startsWith( "spotify_" ); +} + + +Account* +SpotifyAccountFactory::createFromPath( const QString& path ) +{ + return new SpotifyAccount( generateId( "spotifyaccount" ), path ); +} + + QPixmap SpotifyAccountFactory::icon() const { @@ -52,6 +68,13 @@ SpotifyAccount::SpotifyAccount( const QString& accountId ) } +SpotifyAccount::SpotifyAccount( const QString& accountId, const QString& path ) + : ResolverAccount( accountId, path ) +{ + +} + + QPixmap SpotifyAccount::icon() const { diff --git a/src/libtomahawk/accounts/SpotifyAccount.h b/src/libtomahawk/accounts/SpotifyAccount.h index 687315a96..67bd97883 100644 --- a/src/libtomahawk/accounts/SpotifyAccount.h +++ b/src/libtomahawk/accounts/SpotifyAccount.h @@ -44,6 +44,9 @@ public: virtual QString factoryId() const { return "spotifyaccount"; } virtual QString prettyName() const { return "Spotify"; } + virtual bool acceptsPath( const QString& path ) const; + virtual Account* createFromPath( const QString& path ); + virtual AccountTypes types() const { return AccountTypes( ResolverType ); } virtual bool allowUserCreation() const { return false; } virtual QPixmap icon() const; @@ -56,6 +59,7 @@ class SpotifyAccount : public ResolverAccount Q_OBJECT public: SpotifyAccount( const QString& accountId ); + SpotifyAccount( const QString& accountId, const QString& path ); virtual ~SpotifyAccount() {} virtual QPixmap icon() const; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 62e03e36f..66f3acdb4 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -396,7 +396,8 @@ SettingsDialog::installFromFile() if( !resolver.isEmpty() ) { - Account* acct = ResolverAccountFactory::createFromPath( resolver, false ); + Account* acct = AccountManager::instance()->accountFromPath( resolver ); + AccountManager::instance()->addAccount( acct ); TomahawkSettings::instance()->addAccount( acct->accountId() ); AccountManager::instance()->enableAccount( acct ); From 2d1a036b3d277470b31ae35e2e9809248dc891eb Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 22:36:35 -0500 Subject: [PATCH 3/7] Use virtual method for factory name --- src/libtomahawk/AtticaManager.cpp | 2 +- src/libtomahawk/accounts/Account.h | 4 ++-- src/libtomahawk/accounts/AccountModel.cpp | 1 - src/libtomahawk/accounts/AccountModelNode.h | 1 + src/libtomahawk/accounts/ResolverAccount.cpp | 8 ++++---- src/libtomahawk/accounts/ResolverAccount.h | 2 +- src/libtomahawk/accounts/SpotifyAccount.cpp | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libtomahawk/AtticaManager.cpp b/src/libtomahawk/AtticaManager.cpp index 2ecbc6fe3..7d87459e2 100644 --- a/src/libtomahawk/AtticaManager.cpp +++ b/src/libtomahawk/AtticaManager.cpp @@ -456,7 +456,7 @@ AtticaManager::payloadFetched() if ( reply->property( "createAccount" ).toBool() ) { // Do the install / add to tomahawk - Tomahawk::Accounts::Account* resolver = Tomahawk::Accounts::ResolverAccountFactory::createFromPath( resolverPath, true ); + Tomahawk::Accounts::Account* resolver = Tomahawk::Accounts::ResolverAccountFactory::createFromPath( resolverPath, "resolveraccount", true ); Tomahawk::Accounts::AccountManager::instance()->addAccount( resolver ); TomahawkSettings::instance()->addAccount( resolver->accountId() ); } diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 93fcda654..f2e297241 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -182,8 +182,8 @@ public: virtual Account* createAccount( const QString& accountId = QString() ) = 0; /// If this resolver type accepts this path on disk (For general and special resolver accounts) - virtual bool acceptsPath( const QString& path ) const { return false; } - virtual Account* createFromPath( const QString& path ) { return 0; } + virtual bool acceptsPath( const QString& ) const { return false; } + virtual Account* createFromPath( const QString& ) { return 0; } }; }; diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 9c8b78f80..6a7b43b0c 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -597,7 +597,6 @@ void AccountModel::accountStateChanged( Account* account , Account::ConnectionState ) { // Find the factory this belongs up, and update - AccountFactory* factory = AccountManager::instance()->factoryForAccount( account ); for ( int i = 0; i < m_accounts.size(); i++ ) { AccountModelNode* n = m_accounts.at( i ); diff --git a/src/libtomahawk/accounts/AccountModelNode.h b/src/libtomahawk/accounts/AccountModelNode.h index fd6d2c933..28a3a5625 100644 --- a/src/libtomahawk/accounts/AccountModelNode.h +++ b/src/libtomahawk/accounts/AccountModelNode.h @@ -118,6 +118,7 @@ struct AccountModelNode { { init(); resolverAccount = ra; + factory = AccountManager::instance()->factoryForAccount( ra ); } explicit AccountModelNode( Account* account ) : type( CustomAccountType ) diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 76efe47fd..801477fd2 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -48,21 +48,21 @@ ResolverAccountFactory::createAccount( const QString& accountId ) Account* ResolverAccountFactory::createFromPath( const QString& path ) { - return createFromPath( path, false ); + return createFromPath( path, factoryId(), false ); } Account* -ResolverAccountFactory::createFromPath( const QString& path, bool isAttica ) +ResolverAccountFactory::createFromPath( const QString& path, const QString& factory, bool isAttica ) { qDebug() << "Creating ResolverAccount from path:" << path << "is attica" << isAttica; if ( isAttica ) { QFileInfo info( path ); - return new AtticaResolverAccount( generateId( "resolveraccount" ), path, info.baseName() ); + return new AtticaResolverAccount( generateId( factory ), path, info.baseName() ); } else - return new ResolverAccount( generateId( "resolveraccount" ), path ); + return new ResolverAccount( generateId( factory ), path ); } diff --git a/src/libtomahawk/accounts/ResolverAccount.h b/src/libtomahawk/accounts/ResolverAccount.h index db33f157d..59b8ef162 100644 --- a/src/libtomahawk/accounts/ResolverAccount.h +++ b/src/libtomahawk/accounts/ResolverAccount.h @@ -48,7 +48,7 @@ public: virtual Account* createFromPath( const QString& path ); // Internal use - static Account* createFromPath( const QString& path, bool isAttica ); + static Account* createFromPath( const QString& path, const QString& factoryId, bool isAttica ); }; /** diff --git a/src/libtomahawk/accounts/SpotifyAccount.cpp b/src/libtomahawk/accounts/SpotifyAccount.cpp index 24a52c081..b0567019e 100644 --- a/src/libtomahawk/accounts/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/SpotifyAccount.cpp @@ -47,7 +47,7 @@ SpotifyAccountFactory::acceptsPath( const QString& path ) const Account* SpotifyAccountFactory::createFromPath( const QString& path ) { - return new SpotifyAccount( generateId( "spotifyaccount" ), path ); + return new SpotifyAccount( generateId( factoryId() ), path ); } From 1aeb5ed80777214a81628347e0d6e01698f32f5d Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 22:36:53 -0500 Subject: [PATCH 4/7] Don't re-sync on deletion as then deleting an account never removes it from the config file --- src/libtomahawk/accounts/Account.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 208cc7bac..7450a96a4 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -58,7 +58,6 @@ Account::Account( const QString& accountId ) Account::~Account() { - sync(); } From 6dbcac58a45d851e2def26d2f8377f8a3acc77a1 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 22:37:25 -0500 Subject: [PATCH 5/7] Show description from factory for manual resolvers --- src/libtomahawk/accounts/AccountModel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index 6a7b43b0c..b76e327d1 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -311,7 +311,7 @@ AccountModel::data( const QModelIndex& index, int role ) const case Qt::DecorationRole: return acct->icon(); case DescriptionRole: - return node->type == AccountModelNode::ManualResolverType ? QString() : node->factory->description(); + return node->factory ? node->factory->description() : QString(); case Qt::CheckStateRole: return acct->enabled() ? Qt::Checked : Qt::Unchecked; case AccountData: From 66e67fdd4e966d37542b325f869c147f02e52fb0 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 22:37:39 -0500 Subject: [PATCH 6/7] Fix crash when accounts were loaded before attica was fetched --- src/libtomahawk/accounts/LastFmAccount.cpp | 15 +++++++++++++++ src/libtomahawk/accounts/LastFmAccount.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/libtomahawk/accounts/LastFmAccount.cpp b/src/libtomahawk/accounts/LastFmAccount.cpp index fb4c97ec4..6de62718c 100644 --- a/src/libtomahawk/accounts/LastFmAccount.cpp +++ b/src/libtomahawk/accounts/LastFmAccount.cpp @@ -83,6 +83,13 @@ LastFmAccount::~LastFmAccount() void LastFmAccount::authenticate() { + if ( !AtticaManager::instance()->resolversLoaded() ) + { + // If we're still waiting to load, wait for the attica resolvers to come down the pipe + connect( AtticaManager::instance(), SIGNAL(resolversLoaded(Attica::Content::List)), this, SLOT( atticaLoaded( Attica::Content::List ) ), Qt::UniqueConnection ); + return; + } + const Attica::Content res = AtticaManager::instance()->resolverForId( "lastfm" ); const AtticaManager::ResolverState state = AtticaManager::instance()->resolverState( res ); @@ -104,6 +111,14 @@ LastFmAccount::authenticate() } +void +LastFmAccount::atticaLoaded( Attica::Content::List ) +{ + disconnect( AtticaManager::instance(), SIGNAL( resolversLoaded( Attica::Content::List ) ), this, SLOT( atticaLoaded( Attica::Content::List ) ) ); + authenticate(); +} + + void LastFmAccount::deauthenticate() { diff --git a/src/libtomahawk/accounts/LastFmAccount.h b/src/libtomahawk/accounts/LastFmAccount.h index 3e7aaf651..7988c37d6 100644 --- a/src/libtomahawk/accounts/LastFmAccount.h +++ b/src/libtomahawk/accounts/LastFmAccount.h @@ -94,6 +94,8 @@ public: Attica::Content atticaContent() const; private slots: + void atticaLoaded( Attica::Content::List ); + void resolverInstalled( const QString& resolverId ); void resolverChanged(); From 57490a68f00c5481ee515f941f3b0ebf2c0ebef4 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 9 Mar 2012 22:41:01 -0500 Subject: [PATCH 7/7] Cleanup --- src/libtomahawk/resolvers/scriptresolver.cpp | 2 +- src/libtomahawk/resolvers/scriptresolver.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libtomahawk/resolvers/scriptresolver.cpp b/src/libtomahawk/resolvers/scriptresolver.cpp index a70ed5746..bc72bb1f1 100644 --- a/src/libtomahawk/resolvers/scriptresolver.cpp +++ b/src/libtomahawk/resolvers/scriptresolver.cpp @@ -306,7 +306,7 @@ ScriptResolver::cmdExited( int code, QProcess::ExitStatus status ) return; } - if ( m_num_restarts < 0 ) + if ( m_num_restarts < 10 ) { m_num_restarts++; tLog() << "*** Restart num" << m_num_restarts; diff --git a/src/libtomahawk/resolvers/scriptresolver.h b/src/libtomahawk/resolvers/scriptresolver.h index 56fbff8d4..ffe4e5ae5 100644 --- a/src/libtomahawk/resolvers/scriptresolver.h +++ b/src/libtomahawk/resolvers/scriptresolver.h @@ -28,7 +28,6 @@ #include "query.h" #include "ExternalResolverGui.h" -#include "accounts/SpotifyAccount.h" #include "dllmacro.h" class QWidget;