From 9b4eef061fa5345deef4be4f7e370b07d55c10a3 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 18 Jan 2013 18:04:52 +0100 Subject: [PATCH 01/44] Initial commit for scriptable collection. Just a stub. --- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/Collection.h | 3 ++ .../resolvers/ScriptCollection.cpp | 38 ++++++++++++++ src/libtomahawk/resolvers/ScriptCollection.h | 52 +++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 src/libtomahawk/resolvers/ScriptCollection.cpp create mode 100644 src/libtomahawk/resolvers/ScriptCollection.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index cc8d666ee..c3ac2c64c 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -89,6 +89,7 @@ set( libGuiSources ExternalResolverGui.cpp resolvers/ScriptResolver.cpp resolvers/QtScriptResolver.cpp + resolvers/ScriptCollection.cpp utils/ImageRegistry.cpp utils/WidgetDragFilter.cpp diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index f5121f70e..a5d202c7f 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -90,6 +90,9 @@ signals: void changed(); public slots: + //TODO: should be made private and the dbcmd friended + // and can probably be moved into database collection + // it's a slot so the dynamic hookup will work virtual void addTracks( const QList& newitems ) = 0; virtual void removeTracks( const QDir& dir ) = 0; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp new file mode 100644 index 000000000..b30ea41b8 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -0,0 +1,38 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "ScriptCollection.h" + +using namespace Tomahawk; + + +ScriptCollection::ScriptCollection( const source_ptr& source, + const QString& name, + QtScriptResolver* resolver, + QObject* parent ) + : Collection( source, name, parent ) +{ + +} + + +ScriptCollection::~ScriptCollection() +{ + +} diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h new file mode 100644 index 000000000..a2f6d64c5 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -0,0 +1,52 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 SCRIPTCOLLECTION_H +#define SCRIPTCOLLECTION_H + +#include "resolvers/QtScriptResolver.h" +#include "Collection.h" + +#include "Typedefs.h" +#include "DllMacro.h" + + +namespace Tomahawk +{ + +class DLLEXPORT ScriptCollection : public Collection +{ + Q_OBJECT + +public: + explicit ScriptCollection( const source_ptr& source, + const QString& name, + QtScriptResolver* resolver, + QObject* parent = 0 ); + virtual ~ScriptCollection(); + +signals: + +public slots: + +}; + +} //ns + +#endif // SCRIPTCOLLECTION_H From 6138ea160586329a30117d4b31a89425baeac6f8 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 18 Jan 2013 18:28:34 +0100 Subject: [PATCH 02/44] Remove cruft and fix includes. --- src/libtomahawk/Collection.h | 7 ------- src/libtomahawk/accounts/spotify/SpotifyAccount.cpp | 5 +++-- src/libtomahawk/audio/AudioEngine.cpp | 1 + src/libtomahawk/resolvers/ScriptResolver.cpp | 9 +++++---- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index a5d202c7f..ed7b329bc 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -27,7 +27,6 @@ #define TOMAHAWK_COLLECTION_H #include -#include #include #include @@ -90,12 +89,6 @@ signals: void changed(); public slots: - //TODO: should be made private and the dbcmd friended - // and can probably be moved into database collection - // it's a slot so the dynamic hookup will work - virtual void addTracks( const QList& newitems ) = 0; - virtual void removeTracks( const QDir& dir ) = 0; - void setPlaylists( const QList& plists ); void setAutoPlaylists( const QList< Tomahawk::dynplaylist_ptr >& autoplists ); void setStations( const QList< Tomahawk::dynplaylist_ptr >& stations ); diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index 37fb15804..8507eda0f 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -39,12 +39,13 @@ #include "jobview/ErrorStatusMessage.h" #endif -#include #include +#include +#include #include #include #include -#include +#include using namespace Tomahawk; using namespace Accounts; diff --git a/src/libtomahawk/audio/AudioEngine.cpp b/src/libtomahawk/audio/AudioEngine.cpp index 38e9f746b..4981f84c3 100644 --- a/src/libtomahawk/audio/AudioEngine.cpp +++ b/src/libtomahawk/audio/AudioEngine.cpp @@ -40,6 +40,7 @@ #include "playlist/SingleTrackPlaylistInterface.h" #include +#include #include #include diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 1ac8ab6cb..52efdd1ca 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -19,10 +19,6 @@ #include "ScriptResolver.h" -#include -#include -#include - #include "Artist.h" #include "Album.h" #include "Pipeline.h" @@ -32,6 +28,11 @@ #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" +#include +#include +#include +#include + #ifdef Q_OS_WIN #include #endif From 43ae736d612a37017d900af095b8fd102ffbc893 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 20 Jan 2013 15:18:38 +0100 Subject: [PATCH 03/44] Add capabilities support to ScriptResolver and QtScriptResolver. --- data/js/tomahawk.js | 12 ++++++++++++ src/libtomahawk/ExternalResolver.h | 16 ++++++++++++++++ src/libtomahawk/resolvers/QtScriptResolver.cpp | 7 +++++++ src/libtomahawk/resolvers/QtScriptResolver.h | 3 +++ src/libtomahawk/resolvers/ScriptCollection.cpp | 8 ++++++-- src/libtomahawk/resolvers/ScriptCollection.h | 8 +++----- src/libtomahawk/resolvers/ScriptResolver.cpp | 7 +++++++ src/libtomahawk/resolvers/ScriptResolver.h | 12 +++++++----- 8 files changed, 61 insertions(+), 12 deletions(-) diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index 89676f821..7b4e63672 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -79,6 +79,14 @@ Tomahawk.extend = function(object, members) { }; +var TomahawkResolverCapability = { + NullCapability: 0, + Browsable: 1, + PlaylistSync: 2, + AccountFactory: 4 +}; + + // Resolver BaseObject, inherit it to implement your own resolver var TomahawkResolver = { init: function() @@ -125,6 +133,10 @@ var TomahawkResolver = { search: function( qid, searchString ) { return this.resolve( qid, "", "", searchString ); + }, + capabilities: function() + { + return TomahawkResolverCapability.NullCapability; } }; diff --git a/src/libtomahawk/ExternalResolver.h b/src/libtomahawk/ExternalResolver.h index 6a96f8acd..7cebac9aa 100644 --- a/src/libtomahawk/ExternalResolver.h +++ b/src/libtomahawk/ExternalResolver.h @@ -51,6 +51,16 @@ public: FailedToLoad }; + enum Capability + { + NullCapability = 0x0, + Browsable = 0x1, // can be represented in one or more collection tree views + PlaylistSync = 0x2, // can sync playlists + AccountFactory = 0x4 // can configure multiple accounts at the same time + }; + Q_DECLARE_FLAGS( Capabilities, Capability ) + Q_FLAGS( Capabilities ) + ExternalResolver( const QString& filePath ) { m_filePath = filePath; } virtual QString filePath() const { return m_filePath; } @@ -60,6 +70,7 @@ public: virtual void reload() {} // Reloads from file (especially useful to check if file now exists) virtual ErrorState error() const; virtual bool running() const = 0; + virtual Capabilities capabilities() const = 0; public slots: virtual void start() = 0; @@ -67,14 +78,19 @@ public slots: signals: void changed(); // if config widget was added/removed, name changed, etc + void collectionAdded( const Tomahawk::collection_ptr& collection ); + void collectionRemoved( const Tomahawk::collection_ptr& collection ); protected: void setFilePath( const QString& path ) { m_filePath = path; } + QList< Tomahawk::collection_ptr > m_collections; private: QString m_filePath; }; +Q_DECLARE_OPERATORS_FOR_FLAGS( ExternalResolver::Capabilities ) + }; //ns #endif // EXTERNALESOLVER_H diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 23d8ed9cf..a01bc7078 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -334,6 +334,13 @@ QtScriptResolver::init() m_timeout = m.value( "timeout", 25 ).toUInt() * 1000; bool compressed = m.value( "compressed", "false" ).toString() == "true"; + bool ok = 0; + int intCap = m_engine->mainFrame()->evaluateJavaScript( "resolver.capabilities()" ).toInt( &ok ); + if ( !ok ) + m_capabilities = NullCapability; + else + m_capabilities = static_cast< Capabilities >( intCap ); + QByteArray icoData = m.value( "icon" ).toByteArray(); if( compressed ) icoData = qUncompress( QByteArray::fromBase64( icoData ) ); diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index 69e5e947d..1a6a5f596 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -129,6 +129,8 @@ public: virtual ~QtScriptResolver(); static ExternalResolver* factory( const QString& scriptPath ); + virtual Capabilities capabilities() const { return m_capabilities; } + virtual QString name() const { return m_name; } virtual QPixmap icon() const { return m_icon; } virtual unsigned int weight() const { return m_weight; } @@ -171,6 +173,7 @@ private: QString m_name; QPixmap m_icon; unsigned int m_weight, m_timeout; + Capabilities m_capabilities; bool m_ready, m_stopped; ExternalResolver::ErrorState m_error; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index b30ea41b8..73e9752f3 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -19,16 +19,20 @@ #include "ScriptCollection.h" +#include "Source.h" + using namespace Tomahawk; ScriptCollection::ScriptCollection( const source_ptr& source, - const QString& name, QtScriptResolver* resolver, QObject* parent ) - : Collection( source, name, parent ) + : Collection( source, resolver->name(), parent ) { + Q_ASSERT( resolver != 0 ); + qDebug() << Q_FUNC_INFO << resolver->name() << source->friendlyName(); + m_resolver = resolver; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index a2f6d64c5..81ba3baeb 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -36,14 +36,12 @@ class DLLEXPORT ScriptCollection : public Collection public: explicit ScriptCollection( const source_ptr& source, - const QString& name, QtScriptResolver* resolver, QObject* parent = 0 ); virtual ~ScriptCollection(); - -signals: - -public slots: + +private: + QtScriptResolver* m_resolver; }; diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 52efdd1ca..fbaed680a 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -380,6 +380,13 @@ ScriptResolver::doSetup( const QVariantMap& m ) m_timeout = m.value( "timeout", 5 ).toUInt() * 1000; bool compressed = m.value( "compressed", "false" ).toString() == "true"; + bool ok = 0; + int intCap = m.value( "capabilities" ).toInt( &ok ); + if ( !ok ) + m_capabilities = NullCapability; + else + m_capabilities = static_cast< Capabilities >( intCap ); + QByteArray icoData = m.value( "icon" ).toByteArray(); if( compressed ) icoData = qUncompress( QByteArray::fromBase64( icoData ) ); diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index a7594561f..a063b42c4 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -41,11 +41,12 @@ public: virtual ~ScriptResolver(); static ExternalResolver* factory( const QString& exe ); - virtual QString name() const { return m_name; } - virtual QPixmap icon() const { return m_icon; } - virtual unsigned int weight() const { return m_weight; } - virtual unsigned int preference() const { return m_preference; } - virtual unsigned int timeout() const { return m_timeout; } + virtual QString name() const { return m_name; } + virtual QPixmap icon() const { return m_icon; } + virtual unsigned int weight() const { return m_weight; } + virtual unsigned int preference() const { return m_preference; } + virtual unsigned int timeout() const { return m_timeout; } + virtual Capabilities capabilities() const { return m_capabilities; } virtual void setIcon( const QPixmap& icon ); @@ -87,6 +88,7 @@ private: QString m_name; QPixmap m_icon; unsigned int m_weight, m_preference, m_timeout, m_num_restarts; + Capabilities m_capabilities; QPointer< AccountConfigWidget > m_configWidget; quint32 m_msgsize; From c705676ec1cad1043458b9d8de5851123e6d6f31 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 21 Jan 2013 10:29:14 +0100 Subject: [PATCH 04/44] Have browsable resolvers return a collection. --- src/libtomahawk/ExternalResolver.h | 1 + .../resolvers/QtScriptResolver.cpp | 34 +++++++++++++++++++ src/libtomahawk/resolvers/QtScriptResolver.h | 4 +++ .../resolvers/ScriptCollection.cpp | 2 +- src/libtomahawk/resolvers/ScriptCollection.h | 6 ++-- src/libtomahawk/resolvers/ScriptResolver.cpp | 27 +++++++++++++++ src/libtomahawk/resolvers/ScriptResolver.h | 2 ++ 7 files changed, 72 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/ExternalResolver.h b/src/libtomahawk/ExternalResolver.h index 7cebac9aa..a99a2eb43 100644 --- a/src/libtomahawk/ExternalResolver.h +++ b/src/libtomahawk/ExternalResolver.h @@ -71,6 +71,7 @@ public: virtual ErrorState error() const; virtual bool running() const = 0; virtual Capabilities capabilities() const = 0; + virtual QList< Tomahawk::collection_ptr > collections() { return m_collections; } public slots: virtual void start() = 0; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index a01bc7078..2b7efd52f 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,6 +24,7 @@ #include "Album.h" #include "config.h" #include "Pipeline.h" +#include "ScriptCollection.h" #include "SourceList.h" #include "accounts/AccountConfigWidget.h" @@ -368,6 +370,8 @@ QtScriptResolver::init() QVariantMap config = resolverUserConfig(); fillDataInWidgets( config ); + loadCollections(); + qDebug() << "JS" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout << "icon received" << success; m_ready = true; @@ -504,6 +508,13 @@ void QtScriptResolver::stop() { m_stopped = true; + + foreach ( const Tomahawk::collection_ptr& collection, m_collections ) + { + emit collectionRemoved( collection ); + } + m_collections.clear(); + Tomahawk::Pipeline::instance()->removeResolver( this ); emit stopped(); } @@ -634,6 +645,22 @@ QtScriptResolver::fillDataInWidgets( const QVariantMap& data ) } +void +QtScriptResolver::loadCollections() +{ + if ( m_capabilities.testFlag( Browsable ) ) + { + m_collections.clear(); + // at this point we assume that all the tracks browsable through a resolver belong to the local source + Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); + m_collections.append( collection ); + emit collectionAdded( collection ); + + //TODO: implement multiple collections from a resolver + } +} + + QVariantMap QtScriptResolver::resolverSettings() { @@ -654,3 +681,10 @@ QtScriptResolver::resolverInit() return m_engine->mainFrame()->evaluateJavaScript( RESOLVER_LEGACY_CODE "resolver.init();" ).toMap(); } + +QVariantMap +QtScriptResolver::resolverCollections() +{ + return QVariantMap(); //TODO: add a way to distinguish collections +} + diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index 1a6a5f596..a57795099 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -144,6 +145,7 @@ public: virtual void reload(); virtual void setIcon( const QPixmap& icon ) { m_icon = icon; } + public slots: virtual void resolve( const Tomahawk::query_ptr& query ); virtual void stop(); @@ -160,11 +162,13 @@ private: QVariant widgetData( QWidget* widget, const QString& property ); QVariantMap loadDataFromWidgets(); void fillDataInWidgets( const QVariantMap& data ); + void loadCollections(); // encapsulate javascript calls QVariantMap resolverSettings(); QVariantMap resolverUserConfig(); QVariantMap resolverInit(); + QVariantMap resolverCollections(); QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist ); diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 73e9752f3..91131c65f 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -25,7 +25,7 @@ using namespace Tomahawk; ScriptCollection::ScriptCollection( const source_ptr& source, - QtScriptResolver* resolver, + ExternalResolver* resolver, QObject* parent ) : Collection( source, resolver->name(), parent ) { diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 81ba3baeb..949a3ddc4 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -20,7 +20,7 @@ #ifndef SCRIPTCOLLECTION_H #define SCRIPTCOLLECTION_H -#include "resolvers/QtScriptResolver.h" +#include "ExternalResolver.h" #include "Collection.h" #include "Typedefs.h" @@ -36,12 +36,12 @@ class DLLEXPORT ScriptCollection : public Collection public: explicit ScriptCollection( const source_ptr& source, - QtScriptResolver* resolver, + ExternalResolver* resolver, QObject* parent = 0 ); virtual ~ScriptCollection(); private: - QtScriptResolver* m_resolver; + ExternalResolver* m_resolver; }; diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index fbaed680a..dfc1de05f 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,6 +23,7 @@ #include "Artist.h" #include "Album.h" #include "Pipeline.h" +#include "ScriptCollection.h" #include "SourceList.h" #include "accounts/AccountConfigWidget.h" @@ -415,6 +417,8 @@ ScriptResolver::doSetup( const QVariantMap& m ) m_configSent = false; m_num_restarts = 0; + loadCollections(); + if ( !m_stopped ) Tomahawk::Pipeline::instance()->addResolver( this ); @@ -442,6 +446,22 @@ ScriptResolver::setupConfWidget( const QVariantMap& m ) } +void +ScriptResolver::loadCollections() +{ + if ( m_capabilities.testFlag( Browsable ) ) + { + m_collections.clear(); + // at this point we assume that all the tracks browsable through a resolver belong to the local source + Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); + m_collections.append( collection ); + emit collectionAdded( collection ); + + //TODO: implement multiple collections from a resolver + } +} + + void ScriptResolver::startProcess() { @@ -537,5 +557,12 @@ void ScriptResolver::stop() { m_stopped = true; + + foreach ( const Tomahawk::collection_ptr& collection, m_collections ) + { + emit collectionRemoved( collection ); + } + m_collections.clear(); + Tomahawk::Pipeline::instance()->removeResolver( this ); } diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index a063b42c4..36e02d3f5 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -81,6 +82,7 @@ private: void sendMsg( const QByteArray& msg ); void doSetup( const QVariantMap& m ); void setupConfWidget( const QVariantMap& m ); + void loadCollections(); void startProcess(); From e36d9294cce311312b105163e88f067449aebd9a Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 21 Jan 2013 10:59:35 +0100 Subject: [PATCH 05/44] Note to self. --- src/libtomahawk/resolvers/QtScriptResolver.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 2b7efd52f..66e5546b8 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -686,5 +686,9 @@ QVariantMap QtScriptResolver::resolverCollections() { return QVariantMap(); //TODO: add a way to distinguish collections + // the resolver should provide a unique ID string for each collection, and then be queriable + // against this ID. doesn't matter what kind of ID string as long as it's unique. + // Then when there's callbacks from a resolver, it sends source name, collection id + // + data. } From 28e681329e535fec94eb73aa7f66e3802443e657 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 21 Jan 2013 16:47:05 +0100 Subject: [PATCH 06/44] Saner check for db collection. --- src/libtomahawk/Collection.h | 1 + src/libtomahawk/Source.cpp | 8 ++++++-- src/libtomahawk/database/DatabaseCollection.h | 2 ++ src/libtomahawk/resolvers/ScriptCollection.h | 2 ++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index ed7b329bc..1ebdd28f1 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -48,6 +48,7 @@ public: virtual ~Collection(); virtual QString name() const; + virtual QString type() const { return QString(); } virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } virtual void loadAutoPlaylists() { qDebug() << Q_FUNC_INFO; } diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index a98d1c5be..e85135664 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -104,8 +104,12 @@ Source::peerInfos() const collection_ptr Source::collection() const { - if( m_collections.length() ) - return m_collections.first(); + if ( m_collections.length() ) + { + foreach ( const collection_ptr& collection, m_collections ) + if ( collection->type() == "databasecollection" ) + return collection; // We assume only one is a db collection. Now get off my lawn. + } collection_ptr tmp; return tmp; diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index de94bbd6c..9325b122d 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -39,6 +39,8 @@ public: qDebug() << Q_FUNC_INFO; } + virtual QString type() const { return "databasecollection"; } + virtual void loadPlaylists(); virtual void loadAutoPlaylists(); virtual void loadStations(); diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 949a3ddc4..10bbcd14e 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -40,6 +40,8 @@ public: QObject* parent = 0 ); virtual ~ScriptCollection(); + virtual QString type() const { return "scriptcollection"; } + private: ExternalResolver* m_resolver; From a767b7acc010a657cc02ad0f13ede161c4670eca Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 21 Jan 2013 17:34:47 +0100 Subject: [PATCH 07/44] Rename Source::collection() to Source::dbCollection(). --- src/TomahawkWindow.cpp | 6 +++--- .../EchonestCatalogSynchronizer.cpp | 4 ++-- src/libtomahawk/GlobalActionManager.cpp | 2 +- src/libtomahawk/Playlist.cpp | 6 +++--- src/libtomahawk/Source.cpp | 2 +- src/libtomahawk/Source.h | 2 +- src/libtomahawk/ViewManager.cpp | 4 ++-- .../database/DatabaseCommand_AddFiles.cpp | 4 ++-- .../database/DatabaseCommand_AllTracks.cpp | 2 +- .../DatabaseCommand_CreateDynamicPlaylist.cpp | 2 +- .../DatabaseCommand_DeleteDynamicPlaylist.cpp | 6 +++--- .../database/DatabaseCommand_DeleteFiles.cpp | 4 ++-- .../DatabaseCommand_DeletePlaylist.cpp | 4 ++-- .../DatabaseCommand_RenamePlaylist.cpp | 6 +++--- .../database/DatabaseCommand_Resolve.cpp | 4 ++-- ...abaseCommand_SetDynamicPlaylistRevision.cpp | 10 +++++----- .../DatabaseCommand_SetPlaylistRevision.cpp | 2 +- src/libtomahawk/database/DatabaseImpl.cpp | 4 ++-- src/libtomahawk/playlist/AlbumModel.cpp | 4 ++-- .../playlist/RecentlyAddedModel.cpp | 4 ++-- src/libtomahawk/playlist/TreeModel.cpp | 4 ++-- .../playlist/dynamic/DynamicPlaylist.cpp | 14 +++++++------- .../widgets/RecentPlaylistsModel.cpp | 18 +++++++++--------- .../widgets/RecentlyPlayedPlaylistsModel.cpp | 10 +++++----- src/libtomahawk/widgets/WelcomeWidget.cpp | 2 +- .../widgets/infowidgets/SourceInfoWidget.cpp | 4 ++-- src/sourcetree/items/SourceItem.cpp | 14 +++++++------- 27 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index aec607537..0e0948f2c 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -1022,7 +1022,7 @@ TomahawkWindow::createStation() if ( playlistName.isEmpty() || playlistName == title ) { - QList< dynplaylist_ptr > pls = SourceList::instance()->getLocal()->collection()->stations(); + QList< dynplaylist_ptr > pls = SourceList::instance()->getLocal()->dbCollection()->stations(); QStringList titles; foreach ( const playlist_ptr& pl, pls ) titles << pl->title(); @@ -1074,7 +1074,7 @@ TomahawkWindow::playlistCreateDialogFinished( int ret ) { if ( playlistName.isEmpty() ) { - QList< playlist_ptr > pls = SourceList::instance()->getLocal()->collection()->playlists(); + QList< playlist_ptr > pls = SourceList::instance()->getLocal()->dbCollection()->playlists(); QStringList titles; foreach ( const playlist_ptr& pl, pls ) titles << pl->title(); @@ -1096,7 +1096,7 @@ TomahawkWindow::playlistCreateDialogFinished( int ret ) // create Auto Playlist if ( playlistName.isEmpty() ) { - QList< dynplaylist_ptr > pls = SourceList::instance()->getLocal()->collection()->autoPlaylists(); + QList< dynplaylist_ptr > pls = SourceList::instance()->getLocal()->dbCollection()->autoPlaylists(); QStringList titles; foreach ( const dynplaylist_ptr& pl, pls ) titles << pl->title(); diff --git a/src/libtomahawk/EchonestCatalogSynchronizer.cpp b/src/libtomahawk/EchonestCatalogSynchronizer.cpp index d72650f13..066dadc69 100644 --- a/src/libtomahawk/EchonestCatalogSynchronizer.cpp +++ b/src/libtomahawk/EchonestCatalogSynchronizer.cpp @@ -47,8 +47,8 @@ EchonestCatalogSynchronizer::EchonestCatalogSynchronizer( QObject *parent ) qRegisterMetaType >("QList"); connect( TomahawkSettings::instance(), SIGNAL( changed() ), this, SLOT( checkSettingsChanged() ) ); - connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksAdded( QList ) ), this, SLOT( tracksAdded( QList ) ), Qt::QueuedConnection ); - connect( SourceList::instance()->getLocal()->collection().data(), SIGNAL( tracksRemoved( QList ) ), this, SLOT( tracksRemoved( QList ) ), Qt::QueuedConnection ); + connect( SourceList::instance()->getLocal()->dbCollection().data(), SIGNAL( tracksAdded( QList ) ), this, SLOT( tracksAdded( QList ) ), Qt::QueuedConnection ); + connect( SourceList::instance()->getLocal()->dbCollection().data(), SIGNAL( tracksRemoved( QList ) ), this, SLOT( tracksRemoved( QList ) ), Qt::QueuedConnection ); const QByteArray artist = TomahawkSettings::instance()->value( "collection/artistCatalog" ).toByteArray(); const QByteArray song = TomahawkSettings::instance()->value( "collection/songCatalog" ).toByteArray(); diff --git a/src/libtomahawk/GlobalActionManager.cpp b/src/libtomahawk/GlobalActionManager.cpp index a23bf9a63..80a636e78 100644 --- a/src/libtomahawk/GlobalActionManager.cpp +++ b/src/libtomahawk/GlobalActionManager.cpp @@ -1207,7 +1207,7 @@ bool GlobalActionManager::handleBookmarkCommand(const QUrl& url) Pipeline::instance()->resolve( q, true ); // now we add it to the special "bookmarks" playlist, creating it if it doesn't exist. if nothing is playing, start playing the track - QSharedPointer< LocalCollection > col = SourceList::instance()->getLocal()->collection().dynamicCast< LocalCollection >(); + QSharedPointer< LocalCollection > col = SourceList::instance()->getLocal()->dbCollection().dynamicCast< LocalCollection >(); playlist_ptr bookmarkpl = col->bookmarksPlaylist(); if ( bookmarkpl.isNull() ) { diff --git a/src/libtomahawk/Playlist.cpp b/src/libtomahawk/Playlist.cpp index 64a519e55..81e0d1b6b 100644 --- a/src/libtomahawk/Playlist.cpp +++ b/src/libtomahawk/Playlist.cpp @@ -217,7 +217,7 @@ Playlist::load( const QString& guid ) foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() ) { - p = source->collection()->playlist( guid ); + p = source->dbCollection()->playlist( guid ); if ( !p.isNull() ) return p; } @@ -265,7 +265,7 @@ void Playlist::reportCreated( const playlist_ptr& self ) { Q_ASSERT( self.data() == this ); - m_source->collection()->addPlaylist( self ); + m_source->dbCollection()->addPlaylist( self ); } @@ -280,7 +280,7 @@ Playlist::reportDeleted( const Tomahawk::playlist_ptr& self ) } m_deleted = true; - m_source->collection()->deletePlaylist( self ); + m_source->dbCollection()->deletePlaylist( self ); emit deleted( self ); } diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index e85135664..4c9784a72 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -102,7 +102,7 @@ Source::peerInfos() const collection_ptr -Source::collection() const +Source::dbCollection() const { if ( m_collections.length() ) { diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h index f28338243..de83e3116 100644 --- a/src/libtomahawk/Source.h +++ b/src/libtomahawk/Source.h @@ -77,7 +77,7 @@ public: QPixmap avatar( TomahawkUtils::ImageMode style = TomahawkUtils::Original, const QSize& size = QSize() ); #endif - collection_ptr collection() const; + collection_ptr dbCollection() const; void addCollection( const Tomahawk::collection_ptr& c ); void removeCollection( const Tomahawk::collection_ptr& c ); diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index 90c106071..58a303056 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -333,9 +333,9 @@ ViewManager::showSuperCollection() foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() ) { - if ( !m_superCollections.contains( source->collection() ) ) + if ( !m_superCollections.contains( source->dbCollection() ) ) { - m_superCollections.append( source->collection() ); + m_superCollections.append( source->dbCollection() ); // m_superAlbumModel->addCollection( source->collection() ); } } diff --git a/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp b/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp index f8b513ebf..64bd419f1 100644 --- a/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp @@ -57,7 +57,7 @@ DatabaseCommand_AddFiles::postCommitHook() { // make the collection object emit its tracksAdded signal, so the // collection browser will update/fade in etc. - Collection* coll = source()->collection().data(); + Collection* coll = source()->dbCollection().data(); connect( this, SIGNAL( notify( QList ) ), coll, SLOT( setTracks( QList ) ), Qt::QueuedConnection ); @@ -166,5 +166,5 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi ) qDebug() << "Inserted" << added << "tracks to database"; tDebug() << "Committing" << added << "tracks..."; - emit done( m_files, source()->collection() ); + emit done( m_files, source()->dbCollection() ); } diff --git a/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp b/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp index ee887b3d0..9e90d91e3 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp @@ -140,7 +140,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) result->setDiscNumber( query.value( 12 ).toUInt() ); result->setAlbumPos( query.value( 13 ).toUInt() ); result->setScore( 1.0 ); - result->setCollection( s->collection() ); + result->setCollection( s->dbCollection() ); TomahawkSqlQuery attrQuery = dbi->newquery(); QVariantMap attr; diff --git a/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp index 7f90cd9d7..9ab523537 100644 --- a/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_CreateDynamicPlaylist.cpp @@ -102,7 +102,7 @@ void DatabaseCommand_CreateDynamicPlaylist::postCommitHook() { qDebug() << Q_FUNC_INFO; - if ( source().isNull() || source()->collection().isNull() ) + if ( source().isNull() || source()->dbCollection().isNull() ) { qDebug() << "Source has gone offline, not emitting to GUI."; return; diff --git a/src/libtomahawk/database/DatabaseCommand_DeleteDynamicPlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_DeleteDynamicPlaylist.cpp index b2db60005..342b129ba 100644 --- a/src/libtomahawk/database/DatabaseCommand_DeleteDynamicPlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_DeleteDynamicPlaylist.cpp @@ -52,15 +52,15 @@ void DatabaseCommand_DeleteDynamicPlaylist::postCommitHook() { qDebug() << Q_FUNC_INFO << "..reporting..:" << m_playlistguid; - if ( source().isNull() || source()->collection().isNull() ) + if ( source().isNull() || source()->dbCollection().isNull() ) { qDebug() << "Source has gone offline, not emitting to GUI."; return; } // we arent sure which it is, but it can't be more th an one. so try both - dynplaylist_ptr playlist = source()->collection()->autoPlaylist( m_playlistguid ); + dynplaylist_ptr playlist = source()->dbCollection()->autoPlaylist( m_playlistguid ); if( playlist.isNull() ) - playlist = source()->collection()->station( m_playlistguid ); + playlist = source()->dbCollection()->station( m_playlistguid ); tLog( LOGVERBOSE ) << "Just tried to load playlist for deletion:" << m_playlistguid << "Did we get a null one?" << playlist.isNull(); Q_ASSERT( !playlist.isNull() ); diff --git a/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp b/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp index 38e968bbc..bd1d44c14 100644 --- a/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp +++ b/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp @@ -43,7 +43,7 @@ DatabaseCommand_DeleteFiles::postCommitHook() // make the collection object emit its tracksAdded signal, so the // collection browser will update/fade in etc. - Collection* coll = source()->collection().data(); + Collection* coll = source()->dbCollection().data(); connect( this, SIGNAL( notify( QList ) ), coll, SLOT( delTracks( QList ) ), Qt::QueuedConnection ); @@ -136,5 +136,5 @@ DatabaseCommand_DeleteFiles::exec( DatabaseImpl* dbi ) if ( m_idList.count() ) source()->updateIndexWhenSynced(); - emit done( m_idList, source()->collection() ); + emit done( m_idList, source()->dbCollection() ); } diff --git a/src/libtomahawk/database/DatabaseCommand_DeletePlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_DeletePlaylist.cpp index 94fa4a1f7..0e6f34dca 100644 --- a/src/libtomahawk/database/DatabaseCommand_DeletePlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_DeletePlaylist.cpp @@ -53,13 +53,13 @@ void DatabaseCommand_DeletePlaylist::postCommitHook() { qDebug() << Q_FUNC_INFO << "..reporting.."; - if ( source().isNull() || source()->collection().isNull() ) + if ( source().isNull() || source()->dbCollection().isNull() ) { qDebug() << "Source has gone offline, not emitting to GUI."; return; } - playlist_ptr playlist = source()->collection()->playlist( m_playlistguid ); + playlist_ptr playlist = source()->dbCollection()->playlist( m_playlistguid ); Q_ASSERT( !playlist.isNull() ); playlist->reportDeleted( playlist ); diff --git a/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp index 8edc48db8..20ed97ec0 100644 --- a/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp @@ -58,12 +58,12 @@ DatabaseCommand_RenamePlaylist::exec( DatabaseImpl* lib ) void DatabaseCommand_RenamePlaylist::postCommitHook() { - playlist_ptr playlist = source()->collection()->playlist( m_playlistguid ); + playlist_ptr playlist = source()->dbCollection()->playlist( m_playlistguid ); // fallback, check for auto and stations too if( playlist.isNull() ) - playlist = source()->collection()->autoPlaylist( m_playlistguid ); + playlist = source()->dbCollection()->autoPlaylist( m_playlistguid ); if( playlist.isNull() ) - playlist = source()->collection()->station( m_playlistguid ); + playlist = source()->dbCollection()->station( m_playlistguid ); Q_ASSERT( !playlist.isNull() ); diff --git a/src/libtomahawk/database/DatabaseCommand_Resolve.cpp b/src/libtomahawk/database/DatabaseCommand_Resolve.cpp index 72609f60a..6324717da 100644 --- a/src/libtomahawk/database/DatabaseCommand_Resolve.cpp +++ b/src/libtomahawk/database/DatabaseCommand_Resolve.cpp @@ -182,7 +182,7 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib ) } result->setAttributes( attr ); - result->setCollection( s->collection() ); + result->setCollection( s->dbCollection() ); res << result; } @@ -330,7 +330,7 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) } result->setAttributes( attr ); - result->setCollection( s->collection() ); + result->setCollection( s->dbCollection() ); res << result; } diff --git a/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp b/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp index 603b3d29a..659041dc1 100644 --- a/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp +++ b/src/libtomahawk/database/DatabaseCommand_SetDynamicPlaylistRevision.cpp @@ -86,7 +86,7 @@ DatabaseCommand_SetDynamicPlaylistRevision::controlsV() void DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook() { - if ( source().isNull() || source()->collection().isNull() ) + if ( source().isNull() || source()->dbCollection().isNull() ) { tDebug() << "Source has gone offline, not emitting to GUI."; return; @@ -97,13 +97,13 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook() orderedentriesguids << v.toString(); Q_ASSERT( !source().isNull() ); - Q_ASSERT( !source()->collection().isNull() ); + Q_ASSERT( !source()->dbCollection().isNull() ); tLog() << "Postcommitting this playlist:" << playlistguid() << source().isNull(); // private, but we are a friend. will recall itself in its own thread: - dynplaylist_ptr playlist = source()->collection()->autoPlaylist( playlistguid() ); + dynplaylist_ptr playlist = source()->dbCollection()->autoPlaylist( playlistguid() ); if ( playlist.isNull() ) - playlist = source()->collection()->station( playlistguid() ); + playlist = source()->dbCollection()->station( playlistguid() ); // UGH we don't have a sharedptr from DynamicPlaylist+ DynamicPlaylist* rawPl = playlist.data(); @@ -112,7 +112,7 @@ DatabaseCommand_SetDynamicPlaylistRevision::postCommitHook() if ( rawPl == 0 ) { - tLog() <<"Got null playlist with guid:" << playlistguid() << "from source and collection:" << source()->friendlyName() << source()->collection()->name() << "and mode is static?:" << (m_mode == Static); + tLog() <<"Got null playlist with guid:" << playlistguid() << "from source and collection:" << source()->friendlyName() << source()->dbCollection()->name() << "and mode is static?:" << (m_mode == Static); Q_ASSERT( false ); return; } diff --git a/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp b/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp index 052578e4a..33947cdb9 100644 --- a/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp +++ b/src/libtomahawk/database/DatabaseCommand_SetPlaylistRevision.cpp @@ -96,7 +96,7 @@ DatabaseCommand_SetPlaylistRevision::postCommitHook() orderedentriesguids << v.toString(); // private, but we are a friend. will recall itself in its own thread: - playlist_ptr playlist = source()->collection()->playlist( m_playlistguid ); + playlist_ptr playlist = source()->dbCollection()->playlist( m_playlistguid ); if ( playlist.isNull() ) { Q_ASSERT( !playlist.isNull() ); diff --git a/src/libtomahawk/database/DatabaseImpl.cpp b/src/libtomahawk/database/DatabaseImpl.cpp index 9db5da4a3..f8fdf92b2 100644 --- a/src/libtomahawk/database/DatabaseImpl.cpp +++ b/src/libtomahawk/database/DatabaseImpl.cpp @@ -311,7 +311,7 @@ DatabaseImpl::file( int fid ) r->setComposer( composer ); r->setTrack( query.value( 13 ).toString() ); r->setTrackId( query.value( 9 ).toUInt() ); - r->setCollection( s->collection() ); + r->setCollection( s->dbCollection() ); r->setScore( 1.0 ); r->setFileId( fid ); } @@ -713,7 +713,7 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery ) res->setDiscNumber( query.value( 17 ).toUInt() ); res->setRID( uuid() ); res->setTrackId( query.value( 9 ).toUInt() ); - res->setCollection( s->collection() ); + res->setCollection( s->dbCollection() ); res->setYear( query.value( 21 ).toUInt() ); } diff --git a/src/libtomahawk/playlist/AlbumModel.cpp b/src/libtomahawk/playlist/AlbumModel.cpp index 69488c4f1..5f20d2da2 100644 --- a/src/libtomahawk/playlist/AlbumModel.cpp +++ b/src/libtomahawk/playlist/AlbumModel.cpp @@ -71,7 +71,7 @@ AlbumModel::addCollection( const collection_ptr& collection, bool overwrite ) QList sources = SourceList::instance()->sources(); foreach ( const source_ptr& source, sources ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); } } else @@ -236,7 +236,7 @@ AlbumModel::addQueries( const QList& queries ) void AlbumModel::onSourceAdded( const Tomahawk::source_ptr& source ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); } diff --git a/src/libtomahawk/playlist/RecentlyAddedModel.cpp b/src/libtomahawk/playlist/RecentlyAddedModel.cpp index 344232b36..a56429c5d 100644 --- a/src/libtomahawk/playlist/RecentlyAddedModel.cpp +++ b/src/libtomahawk/playlist/RecentlyAddedModel.cpp @@ -54,7 +54,7 @@ RecentlyAddedModel::loadHistory() } startLoading(); - DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_source->collection() ); + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_source->dbCollection() ); cmd->setLimit( m_limit ); cmd->setSortOrder( DatabaseCommand_AllTracks::ModificationTime ); cmd->setSortDescending( true ); @@ -103,7 +103,7 @@ RecentlyAddedModel::setSource( const Tomahawk::source_ptr& source ) void RecentlyAddedModel::onSourceAdded( const Tomahawk::source_ptr& source ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( loadHistory() ) ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( loadHistory() ) ); } diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index ec21f8f4d..24da2b6a5 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -143,7 +143,7 @@ TreeModel::addAllCollections() QList sources = SourceList::instance()->sources(); foreach ( const source_ptr& source, sources ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); } setTitle( tr( "All Artists" ) ); @@ -298,7 +298,7 @@ TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int void TreeModel::onSourceAdded( const Tomahawk::source_ptr& source ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); } diff --git a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp index 4cea498c1..9cda2d8a3 100644 --- a/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp +++ b/src/libtomahawk/playlist/dynamic/DynamicPlaylist.cpp @@ -130,9 +130,9 @@ DynamicPlaylist::load( const QString& guid ) foreach( const Tomahawk::source_ptr& source, SourceList::instance()->sources() ) { - p = source->collection()->autoPlaylist( guid ); + p = source->dbCollection()->autoPlaylist( guid ); if ( p.isNull() ) - p = source->collection()->station( guid ); + p = source->dbCollection()->station( guid ); if ( !p.isNull() ) return p; @@ -323,14 +323,14 @@ DynamicPlaylist::reportCreated( const Tomahawk::dynplaylist_ptr& self ) // qDebug() << Q_FUNC_INFO; Q_ASSERT( self.data() == this ); Q_ASSERT( !author().isNull() ); - Q_ASSERT( !author()->collection().isNull() ); + Q_ASSERT( !author()->dbCollection().isNull() ); // will emit Collection::playlistCreated(...) // qDebug() << "Creating dynplaylist belonging to:" << author().data() << author().isNull(); // qDebug() << "REPORTING DYNAMIC PLAYLIST CREATED:" << this << author()->friendlyName(); if ( self->mode() == Static ) - author()->collection()->addAutoPlaylist( self ); + author()->dbCollection()->addAutoPlaylist( self ); else - author()->collection()->addStation( self ); + author()->dbCollection()->addStation( self ); } @@ -341,9 +341,9 @@ DynamicPlaylist::reportDeleted( const Tomahawk::dynplaylist_ptr& self ) Q_ASSERT( self.data() == this ); // will emit Collection::playlistDeleted(...) if ( self->mode() == Static ) - author()->collection()->deleteAutoPlaylist( self ); + author()->dbCollection()->deleteAutoPlaylist( self ); else - author()->collection()->deleteStation( self ); + author()->dbCollection()->deleteStation( self ); emit deleted( self ); } diff --git a/src/libtomahawk/widgets/RecentPlaylistsModel.cpp b/src/libtomahawk/widgets/RecentPlaylistsModel.cpp index 348add60f..b2a9a86e5 100644 --- a/src/libtomahawk/widgets/RecentPlaylistsModel.cpp +++ b/src/libtomahawk/widgets/RecentPlaylistsModel.cpp @@ -101,11 +101,11 @@ RecentPlaylistsModel::playlistsLoaded( const QListgetLocal(); - playlist_ptr pl = s->collection()->playlist( plPair.second ); + playlist_ptr pl = s->dbCollection()->playlist( plPair.second ); if ( pl.isNull() ) - pl = s->collection()->autoPlaylist( plPair.second ); + pl = s->dbCollection()->autoPlaylist( plPair.second ); if ( pl.isNull() ) - pl = s->collection()->station( plPair.second ); + pl = s->dbCollection()->station( plPair.second ); if ( pl.isNull() ) { @@ -210,12 +210,12 @@ void RecentPlaylistsModel::onSourceAdded( const Tomahawk::source_ptr& source ) { connect( source.data(), SIGNAL( online() ), this, SLOT( sourceOnline() ) ); - connect( source->collection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( refresh() ), Qt::QueuedConnection ); - connect( source->collection().data(), SIGNAL( autoPlaylistsAdded(QList)), SLOT( refresh() ), Qt::QueuedConnection ); - connect( source->collection().data(), SIGNAL( stationsAdded(QList)), SLOT( refresh() ), Qt::QueuedConnection ); - connect( source->collection().data(), SIGNAL( playlistsDeleted( QList ) ), SLOT( onPlaylistsRemoved( QList ) ) ); - connect( source->collection().data(), SIGNAL( autoPlaylistsDeleted(QList) ), SLOT( onDynPlaylistsRemoved( QList ) ) ); - connect( source->collection().data(), SIGNAL( stationsDeleted(QList) ), SLOT( onDynPlaylistsRemoved( QList ) ) ); + connect( source->dbCollection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( refresh() ), Qt::QueuedConnection ); + connect( source->dbCollection().data(), SIGNAL( autoPlaylistsAdded(QList)), SLOT( refresh() ), Qt::QueuedConnection ); + connect( source->dbCollection().data(), SIGNAL( stationsAdded(QList)), SLOT( refresh() ), Qt::QueuedConnection ); + connect( source->dbCollection().data(), SIGNAL( playlistsDeleted( QList ) ), SLOT( onPlaylistsRemoved( QList ) ) ); + connect( source->dbCollection().data(), SIGNAL( autoPlaylistsDeleted(QList) ), SLOT( onDynPlaylistsRemoved( QList ) ) ); + connect( source->dbCollection().data(), SIGNAL( stationsDeleted(QList) ), SLOT( onDynPlaylistsRemoved( QList ) ) ); } diff --git a/src/libtomahawk/widgets/RecentlyPlayedPlaylistsModel.cpp b/src/libtomahawk/widgets/RecentlyPlayedPlaylistsModel.cpp index 0610490d9..3fd1a59be 100644 --- a/src/libtomahawk/widgets/RecentlyPlayedPlaylistsModel.cpp +++ b/src/libtomahawk/widgets/RecentlyPlayedPlaylistsModel.cpp @@ -170,8 +170,8 @@ void RecentlyPlayedPlaylistsModel::onSourceAdded( const Tomahawk::source_ptr& source ) { connect( source.data(), SIGNAL( online() ), this, SLOT( sourceOnline() ) ); - connect( source->collection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( loadFromSettings() ) ); - connect( source->collection().data(), SIGNAL( playlistsDeleted( QList ) ), SLOT( onPlaylistsRemoved( QList ) ) ); + connect( source->dbCollection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( loadFromSettings() ) ); + connect( source->dbCollection().data(), SIGNAL( playlistsDeleted( QList ) ), SLOT( onPlaylistsRemoved( QList ) ) ); } void @@ -224,11 +224,11 @@ RecentlyPlayedPlaylistsModel::plAdded( const QString& plguid, int sId ) if ( source.isNull() ) return; - playlist_ptr pl = source->collection()->playlist( plguid ); + playlist_ptr pl = source->dbCollection()->playlist( plguid ); if ( pl.isNull() ) - pl = source->collection()->autoPlaylist( plguid ); + pl = source->dbCollection()->autoPlaylist( plguid ); if ( pl.isNull() ) - pl = source->collection()->station( plguid ); + pl = source->dbCollection()->station( plguid ); if ( pl.isNull() ) return; diff --git a/src/libtomahawk/widgets/WelcomeWidget.cpp b/src/libtomahawk/widgets/WelcomeWidget.cpp index f33d0d36c..3ded588e4 100644 --- a/src/libtomahawk/widgets/WelcomeWidget.cpp +++ b/src/libtomahawk/widgets/WelcomeWidget.cpp @@ -154,7 +154,7 @@ WelcomeWidget::onSourcesReady() void WelcomeWidget::onSourceAdded( const Tomahawk::source_ptr& source ) { - connect( source->collection().data(), SIGNAL( changed() ), SLOT( updateRecentAdditions() ), Qt::UniqueConnection ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( updateRecentAdditions() ), Qt::UniqueConnection ); } diff --git a/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp index d2879a249..564fbcab0 100644 --- a/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/SourceInfoWidget.cpp @@ -65,7 +65,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* ui->recentAlbumView->proxyModel()->sort( -1 ); onCollectionChanged(); - connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) ); + connect( source->dbCollection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) ); m_title = tr( "New Additions" ); if ( source->isLocal() ) @@ -95,7 +95,7 @@ SourceInfoWidget::onCollectionChanged() void SourceInfoWidget::loadRecentAdditions() { - m_recentAlbumModel->addFilteredCollection( m_source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime, true ); + m_recentAlbumModel->addFilteredCollection( m_source->dbCollection(), 20, DatabaseCommand_AllAlbums::ModificationTime, true ); } diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 470cbea73..30d98243e 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -88,9 +88,9 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw m_recentPlaysItem->setSortValue( -200 ); // create category items if there are playlists to show, or stations to show - QList< playlist_ptr > playlists = source->collection()->playlists(); - QList< dynplaylist_ptr > autoplaylists = source->collection()->autoPlaylists(); - QList< dynplaylist_ptr > stations = source->collection()->stations(); + QList< playlist_ptr > playlists = source->dbCollection()->playlists(); + QList< dynplaylist_ptr > autoplaylists = source->dbCollection()->autoPlaylists(); + QList< dynplaylist_ptr > stations = source->dbCollection()->stations(); if ( !playlists.isEmpty() || !autoplaylists.isEmpty() || source->isLocal() ) { @@ -117,11 +117,11 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); - connect( source->collection().data(), SIGNAL( playlistsAdded( QList ) ), + connect( source->dbCollection().data(), SIGNAL( playlistsAdded( QList ) ), SLOT( onPlaylistsAdded( QList ) ), Qt::QueuedConnection ); - connect( source->collection().data(), SIGNAL( autoPlaylistsAdded( QList< Tomahawk::dynplaylist_ptr > ) ), + connect( source->dbCollection().data(), SIGNAL( autoPlaylistsAdded( QList< Tomahawk::dynplaylist_ptr > ) ), SLOT( onAutoPlaylistsAdded( QList ) ), Qt::QueuedConnection ); - connect( source->collection().data(), SIGNAL( stationsAdded( QList ) ), + connect( source->dbCollection().data(), SIGNAL( stationsAdded( QList ) ), SLOT( onStationsAdded( QList ) ), Qt::QueuedConnection ); if ( m_source->isLocal() ) @@ -503,7 +503,7 @@ SourceItem::collectionClicked() if ( m_source.isNull() ) return 0; - m_collectionPage = ViewManager::instance()->show( m_source->collection() ); + m_collectionPage = ViewManager::instance()->show( m_source->dbCollection() ); return m_collectionPage; } From 35001957085d79429ef56bea96020094f43963b8 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 22 Jan 2013 16:05:34 +0100 Subject: [PATCH 08/44] Added debug UI. --- src/TomahawkWindow.cpp | 2 ++ src/TomahawkWindow.h | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index 0e0948f2c..50ffb4486 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -154,6 +154,8 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) // Window must be fully constructed to toggle fullscreen mode. Queue it up. QTimer::singleShot( 0, this, SLOT( toggleFullscreen() ) ); } + QPushButton* pb = new QPushButton( "debug", this ); + connect( pb, SIGNAL(clicked()),this,SLOT(debug())); } diff --git a/src/TomahawkWindow.h b/src/TomahawkWindow.h index 16517226d..fa4888c1d 100644 --- a/src/TomahawkWindow.h +++ b/src/TomahawkWindow.h @@ -34,7 +34,8 @@ #include #include #include - +#include "SourceList.h" +#include "resolvers/ScriptCollection.h" #ifdef Q_OS_WIN #include #endif @@ -109,6 +110,9 @@ public slots: void fullScreenExited(); private slots: + void debug(){ + SourceList::instance()->getLocal()->addCollection( Tomahawk::collection_ptr( new Tomahawk::Collection( SourceList::instance()->getLocal(), "test" ) ) ); + } void onHistoryBackAvailable( bool avail ); void onHistoryForwardAvailable( bool avail ); From 32780f79a0b16debff46b0e879b4908911b54222 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 22 Jan 2013 16:08:38 +0100 Subject: [PATCH 09/44] Added support for showing multiple collections in a SourceItem. --- src/libtomahawk/Collection.cpp | 7 ++ src/libtomahawk/Collection.h | 1 + src/libtomahawk/Source.cpp | 4 +- src/libtomahawk/Source.h | 5 +- .../resolvers/ScriptCollection.cpp | 7 ++ src/libtomahawk/resolvers/ScriptCollection.h | 1 + src/sourcetree/items/SourceItem.cpp | 70 ++++++++++++++++--- src/sourcetree/items/SourceItem.h | 14 ++-- 8 files changed, 90 insertions(+), 19 deletions(-) diff --git a/src/libtomahawk/Collection.cpp b/src/libtomahawk/Collection.cpp index b10d0b63a..6f08a5389 100644 --- a/src/libtomahawk/Collection.cpp +++ b/src/libtomahawk/Collection.cpp @@ -56,6 +56,13 @@ Collection::name() const } +QString +Collection::prettyName() const +{ + return tr( "Collection" ); +} + + const source_ptr& Collection::source() const { diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index 1ebdd28f1..197e18250 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -48,6 +48,7 @@ public: virtual ~Collection(); virtual QString name() const; + virtual QString prettyName() const; virtual QString type() const { return QString(); } virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 4c9784a72..bcd693117 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -210,7 +210,7 @@ Source::setDbFriendlyName( const QString& dbFriendlyName ) void Source::addCollection( const collection_ptr& c ) { - Q_ASSERT( m_collections.length() == 0 ); // only 1 source supported atm + //Q_ASSERT( m_collections.length() == 0 ); // only 1 source supported atm m_collections.append( c ); emit collectionAdded( c ); } @@ -219,7 +219,7 @@ Source::addCollection( const collection_ptr& c ) void Source::removeCollection( const collection_ptr& c ) { - Q_ASSERT( m_collections.length() == 1 && m_collections.first() == c ); // only 1 source supported atm + //Q_ASSERT( m_collections.length() == 1 && m_collections.first() == c ); // only 1 source supported atm m_collections.removeAll( c ); emit collectionRemoved( c ); } diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h index de83e3116..7878c5c37 100644 --- a/src/libtomahawk/Source.h +++ b/src/libtomahawk/Source.h @@ -78,6 +78,7 @@ public: #endif collection_ptr dbCollection() const; + QList< Tomahawk::collection_ptr > collections() const { return m_collections; } void addCollection( const Tomahawk::collection_ptr& c ); void removeCollection( const Tomahawk::collection_ptr& c ); @@ -105,8 +106,8 @@ signals: void online(); void offline(); - void collectionAdded( const collection_ptr& collection ); - void collectionRemoved( const collection_ptr& collection ); + void collectionAdded( const Tomahawk::collection_ptr& collection ); + void collectionRemoved( const Tomahawk::collection_ptr& collection ); void stats( const QVariantMap& ); diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 91131c65f..e9e062c5c 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -40,3 +40,10 @@ ScriptCollection::~ScriptCollection() { } + + +QString +ScriptCollection::prettyName() const +{ + return QString(); +} diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 10bbcd14e..b4162872f 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -40,6 +40,7 @@ public: QObject* parent = 0 ); virtual ~ScriptCollection(); + virtual QString prettyName() const; virtual QString type() const { return "scriptcollection"; } private: diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 30d98243e..4cf96fcb7 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -52,7 +52,6 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw , m_latchedOn( false ) , m_sourceInfoItem( 0 ) , m_coolPlaylistsItem( 0 ) - , m_collectionPage( 0 ) , m_sourceInfoPage( 0 ) , m_coolPlaylistsPage( 0 ) , m_latestAdditionsPage( 0 ) @@ -64,9 +63,15 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw return; } - m_collectionItem = new GenericPageItem( model(), this, tr( "Collection" ), ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ), //FIXME different icon - boost::bind( &SourceItem::collectionClicked, this ), - boost::bind( &SourceItem::getCollectionPage, this ) ); + connect( source.data(), SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ), + SLOT( onCollectionAdded( Tomahawk::collection_ptr ) ) ); + connect( source.data(), SIGNAL( collectionRemoved( Tomahawk::collection_ptr ) ), + SLOT( onCollectionRemoved( Tomahawk::collection_ptr ) ) ); + + foreach ( const Tomahawk::collection_ptr& collection, source->collections() ) + { + performAddCollectionItem( collection ); + } /* m_sourceInfoItem = new GenericPageItem( model(), this, tr( "New Additions" ), QIcon( RESPATH "images/new-additions.png" ), boost::bind( &SourceItem::sourceInfoClicked, this ), @@ -82,7 +87,6 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw new LovedTracksItem( model(), this ); - m_collectionItem->setSortValue( -350 ); // m_sourceInfoItem->setSortValue( -300 ); m_latestAdditionsItem->setSortValue( -250 ); m_recentPlaysItem->setSortValue( -200 ); @@ -114,6 +118,7 @@ SourceItem::SourceItem( SourcesModel* mdl, SourceTreeItem* parent, const Tomahaw connect( source.data(), SIGNAL( stateChanged() ), SIGNAL( updated() ) ); connect( source.data(), SIGNAL( offline() ), SIGNAL( updated() ) ); connect( source.data(), SIGNAL( online() ), SIGNAL( updated() ) ); + connect( SourceList::instance(), SIGNAL( sourceLatchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOn( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); connect( SourceList::instance(), SIGNAL( sourceLatchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ), SLOT( latchedOff( Tomahawk::source_ptr, Tomahawk::source_ptr ) ) ); @@ -294,6 +299,30 @@ SourceItem::latchModeChanged( Tomahawk::PlaylistModes::LatchMode mode ) } +void +SourceItem::onCollectionAdded( const collection_ptr& collection ) +{ + if ( m_collectionItems.contains( collection ) ) + return; + + beginRowsAdded( model()->rowCount( model()->indexFromItem( this ) ), + model()->rowCount( model()->indexFromItem( this ) ) ); + performAddCollectionItem( collection ); + endRowsAdded(); +} + + +void +SourceItem::onCollectionRemoved( const collection_ptr& collection ) +{ + delete m_collectionPages.value( collection, 0 ); + m_collectionPages.remove( collection ); + + m_collectionItems.value( collection )->deleteLater(); + m_collectionItems.remove( collection ); +} + + void SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplaylist_ptr >& playlists ) { @@ -332,6 +361,25 @@ SourceItem::playlistsAddedInternal( SourceTreeItem* parent, const QList< dynplay } +void +SourceItem::performAddCollectionItem( const collection_ptr& collection ) +{ + GenericPageItem* item = new GenericPageItem( model(), + this, + collection->prettyName(), + ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ), //FIXME different icon + boost::bind( &SourceItem::collectionClicked, this, collection ), + boost::bind( &SourceItem::getCollectionPage, this, collection ) ); + + if ( collection->type() == "databasecollection" ) + item->setSortValue( -350 ); + else + item->setSortValue( -340 ); + + m_collectionItems.insert( collection, item ); +} + + template< typename T > void SourceItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p ) @@ -498,20 +546,20 @@ SourceItem::getSourceInfoPage() const ViewPage* -SourceItem::collectionClicked() +SourceItem::collectionClicked( const Tomahawk::collection_ptr& collection ) { if ( m_source.isNull() ) return 0; - m_collectionPage = ViewManager::instance()->show( m_source->dbCollection() ); - return m_collectionPage; + m_collectionPages[ collection ] = ViewManager::instance()->show( collection ); + return m_collectionPages[ collection ]; } ViewPage* -SourceItem::getCollectionPage() const -{ - return m_collectionPage;; +SourceItem::getCollectionPage( const Tomahawk::collection_ptr& collection ) const +{ + return m_collectionPages[ collection ]; } diff --git a/src/sourcetree/items/SourceItem.h b/src/sourcetree/items/SourceItem.h index 2e9238623..9501bcf76 100644 --- a/src/sourcetree/items/SourceItem.h +++ b/src/sourcetree/items/SourceItem.h @@ -1,6 +1,7 @@ /* * Copyright 2010-2011, Leo Franchi * Copyright 2010-2012, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -69,13 +70,16 @@ private slots: void latchedOff( const Tomahawk::source_ptr&, const Tomahawk::source_ptr& ); void latchModeChanged( Tomahawk::PlaylistModes::LatchMode mode ); + void onCollectionAdded( const Tomahawk::collection_ptr& ); //never call from ctor because of begin/endRowsAdded! + void onCollectionRemoved( const Tomahawk::collection_ptr& ); + void requestExpanding(); Tomahawk::ViewPage* sourceInfoClicked(); Tomahawk::ViewPage* getSourceInfoPage() const; - Tomahawk::ViewPage* collectionClicked(); - Tomahawk::ViewPage* getCollectionPage() const; + Tomahawk::ViewPage* collectionClicked( const Tomahawk::collection_ptr& collection ); + Tomahawk::ViewPage* getCollectionPage( const Tomahawk::collection_ptr& collection ) const; Tomahawk::ViewPage* coolPlaylistsClicked(); Tomahawk::ViewPage* getCoolPlaylistsPage() const; @@ -90,6 +94,7 @@ private: void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists ); template< typename T > void playlistDeletedInternal( SourceTreeItem* parent, const T& playlists ); + void performAddCollectionItem( const Tomahawk::collection_ptr& collection ); Tomahawk::source_ptr m_source; CategoryItem* m_playlists; @@ -98,13 +103,14 @@ private: bool m_latchedOn; Tomahawk::source_ptr m_latchedOnTo; - GenericPageItem* m_collectionItem; + QMap< Tomahawk::collection_ptr, GenericPageItem* > m_collectionItems; + QMap< Tomahawk::collection_ptr, Tomahawk::ViewPage* > m_collectionPages; + GenericPageItem* m_sourceInfoItem; GenericPageItem* m_coolPlaylistsItem; GenericPageItem* m_latestAdditionsItem; GenericPageItem* m_recentPlaysItem; - Tomahawk::ViewPage* m_collectionPage; Tomahawk::ViewPage* m_sourceInfoPage; Tomahawk::ViewPage* m_coolPlaylistsPage; Tomahawk::ViewPage* m_latestAdditionsPage; From df5fa2c55f8c130e2fc529f318ea59976e04e0a1 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 22 Jan 2013 19:54:17 +0100 Subject: [PATCH 10/44] Have SourceList populate the local source with ScriptCollections. --- src/libtomahawk/Pipeline.cpp | 6 ++ src/libtomahawk/SourceList.cpp | 66 +++++++++++++++++++ src/libtomahawk/SourceList.h | 10 +++ .../resolvers/QtScriptResolver.cpp | 1 - .../resolvers/ScriptCollection.cpp | 4 +- src/libtomahawk/resolvers/ScriptCollection.h | 2 + src/sourcetree/items/SourceItem.cpp | 11 +++- 7 files changed, 95 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/Pipeline.cpp b/src/libtomahawk/Pipeline.cpp index dfd7bd07b..88a2f9fc9 100644 --- a/src/libtomahawk/Pipeline.cpp +++ b/src/libtomahawk/Pipeline.cpp @@ -26,6 +26,7 @@ #include "resolvers/ScriptResolver.h" #include "resolvers/QtScriptResolver.h" #include "Source.h" +#include "SourceList.h" #include "utils/Logger.h" @@ -59,6 +60,11 @@ Pipeline::Pipeline( QObject* parent ) m_temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT ); connect( &m_temporaryQueryTimer, SIGNAL( timeout() ), SLOT( onTemporaryQueryTimer() ) ); + + connect( this, SIGNAL( resolverAdded( Tomahawk::Resolver* ) ), + SourceList::instance(), SLOT( onResolverAdded( Tomahawk::Resolver* ) ) ); + connect( this, SIGNAL( resolverRemoved( Tomahawk::Resolver* ) ), + SourceList::instance(), SLOT( onResolverRemoved( Tomahawk::Resolver* ) ) ); } diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index a0204a19e..2d2fd378d 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,8 @@ #include "network/RemoteCollection.h" #include "network/ControlConnection.h" #include "infosystem/InfoSystemCache.h" +#include "ExternalResolver.h" +#include "resolvers/ScriptCollection.h" #include "utils/Logger.h" @@ -259,6 +262,69 @@ SourceList::latchedOff( const source_ptr& to ) emit sourceLatchedOff( source, to ); } + +void +SourceList::onResolverAdded( Resolver* resolver ) +{ + ExternalResolver* r = qobject_cast< ExternalResolver* >( resolver ); + if ( r == 0 ) + return; + + foreach ( const Tomahawk::collection_ptr& collection, r->collections() ) + { + addScriptCollection( collection ); + } + + connect( r, SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ), + this, SLOT( addScriptCollection( Tomahawk::collection_ptr ) ) ); + connect( r, SIGNAL( collectionRemoved(Tomahawk::collection_ptr) ), + this, SLOT( removeScriptCollection( Tomahawk::collection_ptr ) ) ); +} + + +void +SourceList::onResolverRemoved( Resolver* resolver ) +{ + ExternalResolver* r = qobject_cast< ExternalResolver* >( resolver ); + if ( r == 0 ) + return; + + foreach ( const Tomahawk::collection_ptr& collection, m_scriptCollections ) + if ( qobject_cast< ScriptCollection* >( collection.data() )->resolver() == r ) + removeScriptCollection( collection ); + + disconnect( r, SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ), + this, SLOT( addScriptCollection( Tomahawk::collection_ptr ) ) ); + disconnect( r, SIGNAL( collectionRemoved(Tomahawk::collection_ptr) ), + this, SLOT( removeScriptCollection( Tomahawk::collection_ptr ) ) ); +} + + +void +SourceList::addScriptCollection( const collection_ptr& collection ) +{ + m_scriptCollections.append( collection ); + + matchSourceForScriptCollection( collection ); +} + + +void +SourceList::removeScriptCollection( const collection_ptr& collection ) +{ + getLocal()->removeCollection( collection ); + m_scriptCollections.removeAll( collection ); +} + + +void +SourceList::matchSourceForScriptCollection( const collection_ptr& collection ) +{ + //TODO: implement for multi-collection resolvers + getLocal()->addCollection( collection ); +} + + void SourceList::latchedOn( const source_ptr& to ) { diff --git a/src/libtomahawk/SourceList.h b/src/libtomahawk/SourceList.h index 618fa2d90..099adb68e 100644 --- a/src/libtomahawk/SourceList.h +++ b/src/libtomahawk/SourceList.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,6 +60,9 @@ public slots: void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); + void onResolverAdded( Tomahawk::Resolver* resolver ); + void onResolverRemoved( Tomahawk::Resolver* resolver ); + signals: void ready(); @@ -75,12 +79,18 @@ private slots: void latchedOn( const Tomahawk::source_ptr& ); void latchedOff( const Tomahawk::source_ptr& ); + void addScriptCollection( const Tomahawk::collection_ptr& collection ); + void removeScriptCollection( const Tomahawk::collection_ptr& collection ); + private: void add( const Tomahawk::source_ptr& source ); + void matchSourceForScriptCollection( const Tomahawk::collection_ptr& collection ); QMap< QString, Tomahawk::source_ptr > m_sources; QMap< int, QString > m_sources_id2name; + QList< Tomahawk::collection_ptr > m_scriptCollections; + bool m_isReady; Tomahawk::source_ptr m_local; Tomahawk::source_ptr m_dummy; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 66e5546b8..7b66798aa 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -513,7 +513,6 @@ QtScriptResolver::stop() { emit collectionRemoved( collection ); } - m_collections.clear(); Tomahawk::Pipeline::instance()->removeResolver( this ); emit stopped(); diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index e9e062c5c..c1b0ce8d1 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -45,5 +45,7 @@ ScriptCollection::~ScriptCollection() QString ScriptCollection::prettyName() const { - return QString(); + return tr( "%1 Collection", + "Name of a collection based on a resolver, e.g. Subsonic Collection" ) + .arg( m_resolver->name() ); } diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index b4162872f..3e71e54d6 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -43,6 +43,8 @@ public: virtual QString prettyName() const; virtual QString type() const { return "scriptcollection"; } + virtual ExternalResolver* resolver() { return m_resolver; } + private: ExternalResolver* m_resolver; diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 4cf96fcb7..382bb6983 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -315,11 +315,16 @@ SourceItem::onCollectionAdded( const collection_ptr& collection ) void SourceItem::onCollectionRemoved( const collection_ptr& collection ) { - delete m_collectionPages.value( collection, 0 ); - m_collectionPages.remove( collection ); + GenericPageItem* item = m_collectionItems.value( collection ); + int row = model()->indexFromItem( item ).row(); - m_collectionItems.value( collection )->deleteLater(); + beginRowsRemoved( row, row ); + removeChild( item ); + endRowsRemoved(); + + m_collectionPages.remove( collection ); m_collectionItems.remove( collection ); + item->deleteLater(); } From 3ee8555db78d23ae62e6dea656e2be80036cb2d1 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 23 Jan 2013 15:07:06 +0100 Subject: [PATCH 11/44] Use resolver's icon in ScriptCollections. --- src/libtomahawk/Collection.cpp | 8 ++++++++ src/libtomahawk/Collection.h | 3 +++ src/libtomahawk/resolvers/ScriptCollection.cpp | 15 +++++++++++++++ src/libtomahawk/resolvers/ScriptCollection.h | 1 + src/sourcetree/items/SourceItem.cpp | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/Collection.cpp b/src/libtomahawk/Collection.cpp index 6f08a5389..a71c80d96 100644 --- a/src/libtomahawk/Collection.cpp +++ b/src/libtomahawk/Collection.cpp @@ -23,6 +23,7 @@ #include "utils/Logger.h" #include "playlist/PlaylistUpdaterInterface.h" +#include "utils/ImageRegistry.h" #include #include @@ -63,6 +64,13 @@ Collection::prettyName() const } +QIcon +Collection::icon() const +{ + return ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ); +} + + const source_ptr& Collection::source() const { diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index 197e18250..37c40ca18 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -36,6 +36,8 @@ #include "DllMacro.h" +class QIcon; + namespace Tomahawk { @@ -50,6 +52,7 @@ public: virtual QString name() const; virtual QString prettyName() const; virtual QString type() const { return QString(); } + virtual QIcon icon() const; virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } virtual void loadAutoPlaylists() { qDebug() << Q_FUNC_INFO; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index c1b0ce8d1..a1a4abbcf 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -20,6 +20,9 @@ #include "ScriptCollection.h" #include "Source.h" +#include "ExternalResolverGui.h" + +#include using namespace Tomahawk; @@ -49,3 +52,15 @@ ScriptCollection::prettyName() const "Name of a collection based on a resolver, e.g. Subsonic Collection" ) .arg( m_resolver->name() ); } + + +QIcon +ScriptCollection::icon() const +{ + ExternalResolverGui* gResolver = qobject_cast< ExternalResolverGui* >( m_resolver ); + if ( gResolver ) + { + return gResolver->icon(); + } + return QIcon(); +} diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 3e71e54d6..389b6d7a1 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -42,6 +42,7 @@ public: virtual QString prettyName() const; virtual QString type() const { return "scriptcollection"; } + virtual QIcon icon() const; virtual ExternalResolver* resolver() { return m_resolver; } diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 382bb6983..f3519b61e 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -372,7 +372,7 @@ SourceItem::performAddCollectionItem( const collection_ptr& collection ) GenericPageItem* item = new GenericPageItem( model(), this, collection->prettyName(), - ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ), //FIXME different icon + collection->icon(), boost::bind( &SourceItem::collectionClicked, this, collection ), boost::bind( &SourceItem::getCollectionPage, this, collection ) ); From db60026a64809f3da128064c6651d38707eb9a1b Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 23 Jan 2013 18:14:16 +0100 Subject: [PATCH 12/44] How about these? --- src/libtomahawk/Collection.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index 37c40ca18..88e576512 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -75,6 +75,10 @@ public: virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists() { return m_autoplaylists.values(); } virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); } + virtual void artists() = 0; + virtual void albums( const Tomahawk::artist_ptr& artist ) = 0; + virtual void tracks( const Tomahawk::artist_ptr& artist, const Tomahawk::album_ptr& album ) = 0; + const source_ptr& source() const; unsigned int lastmodified() const { return m_lastmodified; } From fb0de1d998456f7c9f7b1da586b411df8bd4c169 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 24 Jan 2013 18:22:55 +0100 Subject: [PATCH 13/44] Remove debug button. --- src/TomahawkWindow.cpp | 2 -- src/TomahawkWindow.h | 5 ----- 2 files changed, 7 deletions(-) diff --git a/src/TomahawkWindow.cpp b/src/TomahawkWindow.cpp index 50ffb4486..0e0948f2c 100644 --- a/src/TomahawkWindow.cpp +++ b/src/TomahawkWindow.cpp @@ -154,8 +154,6 @@ TomahawkWindow::TomahawkWindow( QWidget* parent ) // Window must be fully constructed to toggle fullscreen mode. Queue it up. QTimer::singleShot( 0, this, SLOT( toggleFullscreen() ) ); } - QPushButton* pb = new QPushButton( "debug", this ); - connect( pb, SIGNAL(clicked()),this,SLOT(debug())); } diff --git a/src/TomahawkWindow.h b/src/TomahawkWindow.h index fa4888c1d..f48ae2dd0 100644 --- a/src/TomahawkWindow.h +++ b/src/TomahawkWindow.h @@ -34,8 +34,6 @@ #include #include #include -#include "SourceList.h" -#include "resolvers/ScriptCollection.h" #ifdef Q_OS_WIN #include #endif @@ -110,9 +108,6 @@ public slots: void fullScreenExited(); private slots: - void debug(){ - SourceList::instance()->getLocal()->addCollection( Tomahawk::collection_ptr( new Tomahawk::Collection( SourceList::instance()->getLocal(), "test" ) ) ); - } void onHistoryBackAvailable( bool avail ); void onHistoryForwardAvailable( bool avail ); From 65741c365881f4032d5c9ace4cea1c6ca179bbb3 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 24 Jan 2013 18:29:17 +0100 Subject: [PATCH 14/44] Route (almost) all artists/albums/tracks requests through Collections. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 48 +++++++---- src/libtomahawk/Artist.cpp | 25 ++++-- src/libtomahawk/Artist.h | 3 +- src/libtomahawk/Collection.h | 8 +- .../database/DatabaseCollection.cpp | 80 +++++++++++++++++++ src/libtomahawk/database/DatabaseCollection.h | 9 +++ src/libtomahawk/playlist/TreeModel.cpp | 48 ++++++----- src/libtomahawk/playlist/TreeModel.h | 3 +- .../resolvers/ScriptCollection.cpp | 22 +++++ src/libtomahawk/resolvers/ScriptCollection.h | 4 + 10 files changed, 199 insertions(+), 51 deletions(-) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index 2ecfd8175..8cc30aca7 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -132,14 +133,23 @@ AlbumPlaylistInterface::tracks() const } else if ( m_mode == DatabaseMode && !m_databaseLoaded ) { - DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection ); - cmd->setAlbum( m_album->weakRef() ); - cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); + if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess? + { + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection ); + cmd->setAlbum( m_album->weakRef() ); + cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); + connect( cmd, SIGNAL( tracks( QList, QVariant ) ), + SLOT( onTracksLoaded( QList ) ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); + } + else + { + connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), + SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection ); - connect( cmd, SIGNAL( tracks( QList, QVariant ) ), - SLOT( onTracksLoaded( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); + Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() ); + m_collection->tracks( ap ); + } } } @@ -218,15 +228,23 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) if ( m_queries.isEmpty() && m_mode == Mixed ) { - DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection ); - cmd->setAlbum( m_album->weakRef() ); - //this takes discnumber into account as well - cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); + if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess? + { + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection ); + cmd->setAlbum( m_album->weakRef() ); + cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); + connect( cmd, SIGNAL( tracks( QList, QVariant ) ), + SLOT( onTracksLoaded( QList ) ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); + } + else + { + connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), + SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection ); - connect( cmd, SIGNAL( tracks( QList, QVariant ) ), - SLOT( onTracksLoaded( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); + Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() ); + m_collection->tracks( ap ); + } } else { diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 18306f054..5f8518e3c 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2012, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -165,13 +166,23 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con if ( ( mode == DatabaseMode || mode == Mixed ) && !dbLoaded ) { - DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection, artist ); - cmd->setData( QVariant( collection.isNull() ) ); + if ( collection.isNull() ) + { + DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection, artist ); + cmd->setData( QVariant( collection.isNull() ) ); - connect( cmd, SIGNAL( albums( QList, QVariant ) ), - SLOT( onAlbumsFound( QList, QVariant ) ) ); + connect( cmd, SIGNAL( albums( QList, QVariant ) ), + SLOT( onAlbumsFound( QList, QVariant ) ) ); - Database::instance()->enqueue( QSharedPointer( cmd ) ); + Database::instance()->enqueue( QSharedPointer( cmd ) ); + } + else + { + //collection is *surely* not null + connect( collection.data(), SIGNAL( albumsResult( QList< Tomahawk::album_ptr > ) ), + SLOT( onAlbumsFound( QList ) ), Qt::UniqueConnection ); + collection->albums( artist ); + } } if ( ( mode == InfoSystemMode || mode == Mixed ) && !infoLoaded ) @@ -376,9 +387,9 @@ Artist::playbackCount( const source_ptr& source ) void -Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& data ) +Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& collectionIsNull ) { - if ( data.toBool() ) + if ( collectionIsNull.toBool() ) { m_databaseAlbums << albums; m_albumsLoaded.insert( DatabaseMode, true ); diff --git a/src/libtomahawk/Artist.h b/src/libtomahawk/Artist.h index ab7c0741b..03c2ae1c5 100644 --- a/src/libtomahawk/Artist.h +++ b/src/libtomahawk/Artist.h @@ -89,8 +89,7 @@ signals: void statsLoaded(); private slots: - void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); - void onAlbumsFound( const QList& albums, const QVariant& data ); + void onAlbumsFound( const QList& albums, const QVariant& collectionIsNull = QVariant( false ) ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); void infoSystemFinished( QString target ); diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index 88e576512..b041540c6 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -75,14 +76,19 @@ public: virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists() { return m_autoplaylists.values(); } virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); } + // Async requests. Emit artists/albums/tracksResult in subclasses when finished. virtual void artists() = 0; virtual void albums( const Tomahawk::artist_ptr& artist ) = 0; - virtual void tracks( const Tomahawk::artist_ptr& artist, const Tomahawk::album_ptr& album ) = 0; + virtual void tracks( const Tomahawk::album_ptr& album ) = 0; const source_ptr& source() const; unsigned int lastmodified() const { return m_lastmodified; } signals: + void artistsResult( const QList< Tomahawk::artist_ptr >& artists ); + void albumsResult( const QList< Tomahawk::album_ptr >& albums ); + void tracksResult( const QList< Tomahawk::query_ptr >& queries ); + void tracksAdded( const QList& fileids ); void tracksRemoved( const QList& fileids ); diff --git a/src/libtomahawk/database/DatabaseCollection.cpp b/src/libtomahawk/database/DatabaseCollection.cpp index 5f2624ffe..1bdc518d8 100644 --- a/src/libtomahawk/database/DatabaseCollection.cpp +++ b/src/libtomahawk/database/DatabaseCollection.cpp @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,6 +21,8 @@ #include "DatabaseCollection.h" #include "database/Database.h" +#include "DatabaseCommand_AllArtists.h" +#include "DatabaseCommand_AllAlbums.h" #include "DatabaseCommand_AllTracks.h" #include "DatabaseCommand_AddFiles.h" #include "DatabaseCommand_DeleteFiles.h" @@ -130,6 +133,83 @@ DatabaseCollection::stations() } +void +DatabaseCollection::artists() +{ + //FIXME: assuming there's only one dbcollection per source, and that this is the one + Tomahawk::collection_ptr thisCollection = source()->dbCollection(); + if ( thisCollection->name() != this->name() ) + return; + + DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( thisCollection ); + + connect( cmd, SIGNAL( artists( QList< Tomahawk::artist_ptr > ) ), + SLOT( onArtistsFetched( QList< Tomahawk::artist_ptr > ) ) ); + + Database::instance()->enqueue( QSharedPointer( cmd ) ); +} + + +void +DatabaseCollection::onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists ) +{ + emit artistsResult( artists ); +} + + +void +DatabaseCollection::albums( const Tomahawk::artist_ptr& artist ) +{ + //FIXME: assuming there's only one dbcollection per source, and that this is the one + Tomahawk::collection_ptr thisCollection = source()->dbCollection(); + if ( thisCollection->name() != this->name() ) + return; + + DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( thisCollection, artist ); + + // The QVariant might carry a bool that says whether the dbcmd was executed for a null collection + // but here we know for a fact that the collection is not null, so we'll happily ignore it + connect( cmd, SIGNAL( albums( QList, QVariant ) ), + SLOT( onAlbumsFetched( QList, QVariant ) ) ); + + Database::instance()->enqueue( QSharedPointer( cmd ) ); +} + + +void +DatabaseCollection::onAlbumsFetched( const QList< album_ptr >& albums, const QVariant& data ) +{ + Q_UNUSED( data ); + emit albumsResult( albums ); +} + + +void +DatabaseCollection::tracks( const Tomahawk::album_ptr& album ) +{ + //FIXME: assuming there's only one dbcollection per source, and that this is the one + Tomahawk::collection_ptr thisCollection = source()->dbCollection(); + if ( thisCollection->name() != this->name() ) + return; + + DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( thisCollection ); + cmd->setAlbum( album->weakRef() ); + cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); + + connect( cmd, SIGNAL( tracks( QList, QVariant ) ), + SLOT( onTracksFetched( QList ) ) ); + + Database::instance()->enqueue( QSharedPointer( cmd ) ); +} + + +void +DatabaseCollection::onTracksFetched( const QList< query_ptr >& tracks ) +{ + emit tracksResult( tracks ); +} + + void DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data ) { diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index 9325b122d..9f8d6a688 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -49,11 +50,19 @@ public: virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists(); virtual QList< Tomahawk::dynplaylist_ptr > stations(); + virtual void artists(); + virtual void albums( const Tomahawk::artist_ptr& artist ); + virtual void tracks( const Tomahawk::album_ptr& album ); + public slots: virtual void addTracks( const QList& newitems ); virtual void removeTracks( const QDir& dir ); private slots: + void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists ); + void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums, const QVariant& data ); + void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); + void stationCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); void autoPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); }; diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 24da2b6a5..d8e0a5192 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -3,6 +3,7 @@ * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Jeff Mitchell * Copyright 2012, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -251,12 +252,10 @@ TreeModel::addCollection( const collection_ptr& collection ) startLoading(); m_collection = collection; - DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection ); - connect( cmd, SIGNAL( artists( QList ) ), - SLOT( onArtistsAdded( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); + connect( m_collection.data(), SIGNAL( artistsResult( QList ) ), + SLOT( onArtistsAdded( QList ) ), Qt::UniqueConnection ); + m_collection->artists(); connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); @@ -270,29 +269,28 @@ TreeModel::addCollection( const collection_ptr& collection ) } -void -TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order ) -{ - qDebug() << Q_FUNC_INFO << collection->name() - << collection->source()->id() - << collection->source()->nodeId() - << amount << order; +//void +//TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order ) +//{ +// qDebug() << Q_FUNC_INFO << collection->name() +// << collection->source()->id() +// << collection->source()->nodeId() +// << amount << order; +// DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection ); +// cmd->setLimit( amount ); +// cmd->setSortOrder( order ); +// cmd->setSortDescending( true ); - DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection ); - cmd->setLimit( amount ); - cmd->setSortOrder( order ); - cmd->setSortDescending( true ); +// connect( cmd, SIGNAL( artists( QList, Tomahawk::collection_ptr ) ), +// SLOT( onArtistsAdded( QList, Tomahawk::collection_ptr ) ) ); - connect( cmd, SIGNAL( artists( QList, Tomahawk::collection_ptr ) ), - SLOT( onArtistsAdded( QList, Tomahawk::collection_ptr ) ) ); +// Database::instance()->enqueue( QSharedPointer( cmd ) ); - Database::instance()->enqueue( QSharedPointer( cmd ) ); - - if ( collection->source()->isLocal() ) - setTitle( tr( "My Collection" ) ); - else - setTitle( tr( "Collection of %1" ).arg( collection->source()->friendlyName() ) ); -} +// if ( collection->source()->isLocal() ) +// setTitle( tr( "My Collection" ) ); +// else +// setTitle( tr( "Collection of %1" ).arg( collection->source()->friendlyName() ) ); +//} void diff --git a/src/libtomahawk/playlist/TreeModel.h b/src/libtomahawk/playlist/TreeModel.h index d477370e3..591e908dc 100644 --- a/src/libtomahawk/playlist/TreeModel.h +++ b/src/libtomahawk/playlist/TreeModel.h @@ -53,7 +53,8 @@ public: void addAllCollections(); void addCollection( const Tomahawk::collection_ptr& collection ); - void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order ); + //TODO: Unused, but will be useful for supporting filtered queries. - Teo 1/2013 + //void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order ); void addArtists( const Tomahawk::artist_ptr& artist ); void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent, bool autoRefetch = false ); diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index a1a4abbcf..ad5283565 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -64,3 +64,25 @@ ScriptCollection::icon() const } return QIcon(); } + + +void +ScriptCollection::artists() +{ + //TODO: implement! + emit artistsResult( QList< Tomahawk::artist_ptr >() ); +} + + +void +ScriptCollection::albums( const Tomahawk::artist_ptr& artist ) +{ + emit albumsResult( QList< Tomahawk::album_ptr >() ); +} + + +void +ScriptCollection::tracks( const Tomahawk::album_ptr& album ) +{ + emit tracksResult( QList< Tomahawk::query_ptr >() ); +} diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 389b6d7a1..e8f846837 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -46,6 +46,10 @@ public: virtual ExternalResolver* resolver() { return m_resolver; } + virtual void artists(); + virtual void albums( const Tomahawk::artist_ptr& artist ); + virtual void tracks( const Tomahawk::album_ptr& album ); + private: ExternalResolver* m_resolver; From 3a805cbe673ececbba79605be7676633dfc4f8fa Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 24 Jan 2013 19:31:40 +0100 Subject: [PATCH 15/44] Have collections provide some strings of their own. --- src/libtomahawk/Collection.cpp | 16 +++++++++++++++- src/libtomahawk/Collection.h | 2 ++ src/libtomahawk/ViewManager.cpp | 6 ++---- src/libtomahawk/database/LocalCollection.cpp | 14 ++++++++++++++ src/libtomahawk/database/LocalCollection.h | 3 +++ src/libtomahawk/network/RemoteCollection.cpp | 7 +++++++ src/libtomahawk/network/RemoteCollection.h | 2 ++ src/libtomahawk/playlist/TreeModel.cpp | 5 +---- src/libtomahawk/resolvers/ScriptCollection.cpp | 14 ++++++++++++++ src/libtomahawk/resolvers/ScriptCollection.h | 1 + src/sourcetree/items/SourceItem.cpp | 2 +- 11 files changed, 62 insertions(+), 10 deletions(-) diff --git a/src/libtomahawk/Collection.cpp b/src/libtomahawk/Collection.cpp index a71c80d96..06d4a98bc 100644 --- a/src/libtomahawk/Collection.cpp +++ b/src/libtomahawk/Collection.cpp @@ -64,10 +64,24 @@ Collection::prettyName() const } +QString +Collection::itemName() const +{ + return tr( "Collection" ); +} + + QIcon Collection::icon() const { - return ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ); + return ImageRegistry::instance()->icon( RESPATH "images/collection.svg" ); +} + + +QString +Collection::emptyText() const +{ + return tr( "This collection is empty." ); } diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index b041540c6..b3ed5b07e 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -52,8 +52,10 @@ public: virtual QString name() const; virtual QString prettyName() const; + virtual QString itemName() const; virtual QString type() const { return QString(); } virtual QIcon icon() const; + virtual QString emptyText() const; virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } virtual void loadAutoPlaylists() { qDebug() << Q_FUNC_INFO; } diff --git a/src/libtomahawk/ViewManager.cpp b/src/libtomahawk/ViewManager.cpp index 58a303056..e1a9e2b18 100644 --- a/src/libtomahawk/ViewManager.cpp +++ b/src/libtomahawk/ViewManager.cpp @@ -278,10 +278,8 @@ ViewManager::show( const Tomahawk::collection_ptr& collection ) TreeModel* model = new TreeModel(); view->setTreeModel( model ); - if ( collection && collection->source()->isLocal() ) - view->setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) ); - else - view->setEmptyTip( tr( "This collection is empty." ) ); + if ( !collection.isNull() ) + view->setEmptyTip( collection->emptyText() ); model->addCollection( collection ); diff --git a/src/libtomahawk/database/LocalCollection.cpp b/src/libtomahawk/database/LocalCollection.cpp index 05bc5318d..0448aa5f4 100644 --- a/src/libtomahawk/database/LocalCollection.cpp +++ b/src/libtomahawk/database/LocalCollection.cpp @@ -36,6 +36,20 @@ LocalCollection::LocalCollection( const Tomahawk::source_ptr& source, QObject* p } +QString +LocalCollection::prettyName() const +{ + return tr( "My Collection" ); +} + + +QString +LocalCollection::emptyText() const +{ + return tr( "After you have scanned your music collection you will find your tracks right here." ); +} + + Tomahawk::playlist_ptr LocalCollection::bookmarksPlaylist() { diff --git a/src/libtomahawk/database/LocalCollection.h b/src/libtomahawk/database/LocalCollection.h index 80e212a1d..4d4ae8960 100644 --- a/src/libtomahawk/database/LocalCollection.h +++ b/src/libtomahawk/database/LocalCollection.h @@ -30,6 +30,9 @@ class DLLEXPORT LocalCollection : public DatabaseCollection public: explicit LocalCollection( const Tomahawk::source_ptr& source, QObject* parent = 0 ); + virtual QString prettyName() const; + virtual QString emptyText() const; + // gets the playlist used for storing stuff from the web, if it already exists. if the returned playlist // is invalid ask to create and listen to the signal Tomahawk::playlist_ptr bookmarksPlaylist(); diff --git a/src/libtomahawk/network/RemoteCollection.cpp b/src/libtomahawk/network/RemoteCollection.cpp index ec9af8918..0a0ad7c3f 100644 --- a/src/libtomahawk/network/RemoteCollection.cpp +++ b/src/libtomahawk/network/RemoteCollection.cpp @@ -30,6 +30,13 @@ RemoteCollection::RemoteCollection( source_ptr source, QObject* parent ) } +QString +RemoteCollection::prettyName() const +{ + return tr( "Collection of %1" ).arg( source()->friendlyName() ); +} + + // adding/removing is done by dbsyncconnection, and the dbcmd objects that modify // the database will make us emit the appropriate signals (tracksAdded etc.) void diff --git a/src/libtomahawk/network/RemoteCollection.h b/src/libtomahawk/network/RemoteCollection.h index 8b75c9c93..16ef70f7e 100644 --- a/src/libtomahawk/network/RemoteCollection.h +++ b/src/libtomahawk/network/RemoteCollection.h @@ -37,6 +37,8 @@ public: qDebug() << Q_FUNC_INFO; } + virtual QString prettyName() const; + public slots: virtual void addTracks( const QList& newitems ); virtual void removeTracks( const QDir& dir ); diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index d8e0a5192..2c6ce8cb1 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -262,10 +262,7 @@ TreeModel::addCollection( const collection_ptr& collection ) if ( !collection->source()->avatar().isNull() ) setIcon( collection->source()->avatar( TomahawkUtils::RoundedCorners ) ); - if ( collection->source()->isLocal() ) - setTitle( tr( "My Collection" ) ); - else - setTitle( tr( "Collection of %1" ).arg( collection->source()->friendlyName() ) ); + setTitle( collection->prettyName() ); } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index ad5283565..c57f5b9c7 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -47,6 +47,20 @@ ScriptCollection::~ScriptCollection() QString ScriptCollection::prettyName() const +{ + if ( source()->isLocal() ) + return tr( "My %1 Collection", + "Name of a collection based on a resolver, e.g. My Subsonic Collection" ) + .arg( m_resolver->name() ); + return tr( "%1 Collection of %2", + "Name of a collection based on a resolver, e.g. Subsonic Collection of Some Dude" ) + .arg( m_resolver->name() ) + .arg( source()->friendlyName() ); +} + + +QString +ScriptCollection::itemName() const { return tr( "%1 Collection", "Name of a collection based on a resolver, e.g. Subsonic Collection" ) diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index e8f846837..53b9a6ca2 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -41,6 +41,7 @@ public: virtual ~ScriptCollection(); virtual QString prettyName() const; + virtual QString itemName() const; virtual QString type() const { return "scriptcollection"; } virtual QIcon icon() const; diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index f3519b61e..16f544f74 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -371,7 +371,7 @@ SourceItem::performAddCollectionItem( const collection_ptr& collection ) { GenericPageItem* item = new GenericPageItem( model(), this, - collection->prettyName(), + collection->itemName(), collection->icon(), boost::bind( &SourceItem::collectionClicked, this, collection ), boost::bind( &SourceItem::getCollectionPage, this, collection ) ); From cb7c646c2f730af766f7c9e1ef569b6037d493dd Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 25 Jan 2013 22:54:31 +0100 Subject: [PATCH 16/44] Added artists/albums/tracks support in tomahawk.js --- data/js/tomahawk.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index 7b4e63672..35ce76182 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -137,6 +137,24 @@ var TomahawkResolver = { capabilities: function() { return TomahawkResolverCapability.NullCapability; + }, + artists: function( qid ) + { + return { + qid: qid + }; + }, + albums: function( qid, artist ) + { + return { + qid: qid + }; + }, + tracks: function( qid, artist, album ) + { + return { + qid: qid + }; } }; From ad1e057078dbc238dd81858c92cf1d0f4575f5c8 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 25 Jan 2013 22:58:18 +0100 Subject: [PATCH 17/44] Artists fetching support in scriptcollection. --- src/libtomahawk/ExternalResolver.h | 10 +- .../resolvers/QtScriptResolver.cpp | 102 +++++++++++++++++- src/libtomahawk/resolvers/QtScriptResolver.h | 9 ++ .../resolvers/ScriptCollection.cpp | 26 ++++- src/libtomahawk/resolvers/ScriptCollection.h | 6 +- src/libtomahawk/resolvers/ScriptResolver.cpp | 2 +- src/libtomahawk/resolvers/ScriptResolver.h | 6 ++ 7 files changed, 152 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/ExternalResolver.h b/src/libtomahawk/ExternalResolver.h index a99a2eb43..dc87f5c90 100644 --- a/src/libtomahawk/ExternalResolver.h +++ b/src/libtomahawk/ExternalResolver.h @@ -2,6 +2,7 @@ * * Copyright 2010-2011, Christian Muehlhaeuser * Copyright 2010-2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -71,12 +72,17 @@ public: virtual ErrorState error() const; virtual bool running() const = 0; virtual Capabilities capabilities() const = 0; - virtual QList< Tomahawk::collection_ptr > collections() { return m_collections; } + virtual QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; } public slots: virtual void start() = 0; virtual void stop() = 0; + // For ScriptCollection + virtual void artists( const Tomahawk::collection_ptr& collection ) = 0; + virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) = 0; + virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) = 0; + signals: void changed(); // if config widget was added/removed, name changed, etc void collectionAdded( const Tomahawk::collection_ptr& collection ); @@ -84,7 +90,7 @@ signals: protected: void setFilePath( const QString& path ) { m_filePath = path; } - QList< Tomahawk::collection_ptr > m_collections; + QMap< QString, Tomahawk::collection_ptr > m_collections; private: QString m_filePath; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 7b66798aa..3a2d8c051 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -134,6 +134,37 @@ QtScriptResolverHelper::addTrackResults( const QVariantMap& results ) } +void +QtScriptResolverHelper::addArtistResults( const QVariantMap& results ) +{ + qDebug() << "Resolver reporting artists:" << results; + QList< Tomahawk::artist_ptr > artists = m_resolver->parseArtistVariantList( results.value("artists").toList() ); + + QString qid = results.value("qid").toString(); + + Tomahawk::collection_ptr collection = Tomahawk::collection_ptr(); + foreach ( const Tomahawk::collection_ptr& coll, m_resolver->collections() ) + { + if ( coll->name() == qid ) + { + collection = coll; + } + } + if ( collection.isNull() ) + return; + + tDebug() << Q_FUNC_INFO << "about to push" << artists.count() << "artists"; + foreach( const Tomahawk::artist_ptr& artist, artists) + tDebug() << artist->name(); + QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::artist_ptr >, artists ) ); +} + +void QtScriptResolverHelper::addAlbumResults(const QVariantMap &results) +{ +} + + void QtScriptResolverHelper::setResolverConfig( const QVariantMap& config ) { @@ -389,6 +420,57 @@ QtScriptResolver::start() } +void +QtScriptResolver::artists( const Tomahawk::collection_ptr& collection ) +{ + if ( QThread::currentThread() != thread() ) + { + QMetaObject::invokeMethod( this, "artists", Qt::QueuedConnection, Q_ARG( Tomahawk::collection_ptr, collection ) ); + return; + } + + if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver + !capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections + { + QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::artist_ptr >, QList< Tomahawk::artist_ptr >() ) ); + return; + } + + QString eval = QString( "resolver.artists( '%1' );" ) + .arg( collection->name().replace( "'", "\\'" ) ); + + QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( eval ).toMap(); + if ( m.isEmpty() ) + { + // if the resolver doesn't return anything, async api is used + return; + } + + qDebug() << "Artists JavaScript Result:" << m; + + const QString qid = collection->name(); + const QVariantList reslist = m.value( "artists" ).toList(); + + QList< Tomahawk::artist_ptr > artists = parseArtistVariantList( reslist ); + + QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::artist_ptr >, artists ) ); +} + + +void +QtScriptResolver::albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) +{ +} + + +void +QtScriptResolver::tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) +{ +} + + Tomahawk::ExternalResolver::ErrorState QtScriptResolver::error() const { @@ -503,6 +585,24 @@ QtScriptResolver::parseResultVariantList( const QVariantList& reslist ) return results; } +QList< Tomahawk::artist_ptr > +QtScriptResolver::parseArtistVariantList( const QVariantList& reslist ) +{ + QList< Tomahawk::artist_ptr > results; + + foreach( const QVariant& rv, reslist ) + { + if ( rv.toString().trimmed().isEmpty() ) + continue; + + Tomahawk::artist_ptr ap = Tomahawk::Artist::get( rv.toString(), false ); + + results << ap; + } + + return results; +} + void QtScriptResolver::stop() @@ -652,7 +752,7 @@ QtScriptResolver::loadCollections() m_collections.clear(); // at this point we assume that all the tracks browsable through a resolver belong to the local source Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); - m_collections.append( collection ); + m_collections.insert( collection->name(), collection ); emit collectionAdded( collection ); //TODO: implement multiple collections from a resolver diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index a57795099..02030635d 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -72,6 +72,9 @@ public slots: void addTrackResults( const QVariantMap& results ); + void addArtistResults( const QVariantMap& results ); + void addAlbumResults( const QVariantMap& results ); + private: QString m_scriptPath, m_urlCallback; QVariantMap m_resolverConfig; @@ -151,6 +154,11 @@ public slots: virtual void stop(); virtual void start(); + // For ScriptCollection + virtual void artists( const Tomahawk::collection_ptr& collection ); + virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ); + virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ); + signals: void stopped(); @@ -171,6 +179,7 @@ private: QVariantMap resolverCollections(); QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist ); + QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& reslist ); ScriptEngine* m_engine; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index c57f5b9c7..89200d722 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -30,10 +30,10 @@ using namespace Tomahawk; ScriptCollection::ScriptCollection( const source_ptr& source, ExternalResolver* resolver, QObject* parent ) - : Collection( source, resolver->name(), parent ) + : Collection( source, QString( "scriptcollection:" + resolver->name() + ":" + uuid() ), parent ) { Q_ASSERT( resolver != 0 ); - qDebug() << Q_FUNC_INFO << resolver->name() << source->friendlyName(); + qDebug() << Q_FUNC_INFO << resolver->name() << name(); m_resolver = resolver; } @@ -83,8 +83,7 @@ ScriptCollection::icon() const void ScriptCollection::artists() { - //TODO: implement! - emit artistsResult( QList< Tomahawk::artist_ptr >() ); + m_resolver->artists( m_resolver->collections().value( name() ) ); } @@ -100,3 +99,22 @@ ScriptCollection::tracks( const Tomahawk::album_ptr& album ) { emit tracksResult( QList< Tomahawk::query_ptr >() ); } + + +void +ScriptCollection::onArtistsFetched( const QList& artists ) +{ + emit artistsResult( artists ); +} + + +void +ScriptCollection::onAlbumsFetched( const QList& albums ) +{ +} + + +void +ScriptCollection::onTracksFetched( const QList& tracks ) +{ +} diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 53b9a6ca2..7c4c60ccd 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -51,9 +51,13 @@ public: virtual void albums( const Tomahawk::artist_ptr& artist ); virtual void tracks( const Tomahawk::album_ptr& album ); +private slots: + void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists ); + void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums ); + void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); + private: ExternalResolver* m_resolver; - }; } //ns diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index dfc1de05f..7d805a273 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -454,7 +454,7 @@ ScriptResolver::loadCollections() m_collections.clear(); // at this point we assume that all the tracks browsable through a resolver belong to the local source Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); - m_collections.append( collection ); + m_collections.insert( collection->name(), collection ); emit collectionAdded( collection ); //TODO: implement multiple collections from a resolver diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index 36e02d3f5..3ce59d81b 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -70,6 +70,12 @@ public slots: virtual void resolve( const Tomahawk::query_ptr& query ); virtual void start(); + // TODO: implement. Or not. Not really an issue while Spotify doesn't do browsable personal cloud storage. + virtual void artists( const Tomahawk::collection_ptr& collection ){} + virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) {} + virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) {} + + private slots: void readStderr(); void readStdout(); From 7f73c073be6a015a6d2ecff9a5a200fc788bd0e1 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 26 Jan 2013 00:11:52 +0100 Subject: [PATCH 18/44] Fix collection page icons. --- src/libtomahawk/Collection.cpp | 9 +++++++ src/libtomahawk/Collection.h | 1 + src/libtomahawk/database/LocalCollection.cpp | 1 + src/libtomahawk/playlist/TreeModel.cpp | 3 +-- .../resolvers/ScriptCollection.cpp | 27 +++++++++++++++++++ src/libtomahawk/resolvers/ScriptCollection.h | 1 + 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/Collection.cpp b/src/libtomahawk/Collection.cpp index 06d4a98bc..c0851f7c2 100644 --- a/src/libtomahawk/Collection.cpp +++ b/src/libtomahawk/Collection.cpp @@ -78,6 +78,15 @@ Collection::icon() const } +QPixmap +Collection::bigIcon() const +{ + if ( !source()->avatar().isNull() ) + return source()->avatar( TomahawkUtils::RoundedCorners ); + return TomahawkUtils::defaultPixmap( TomahawkUtils::SuperCollection ); +} + + QString Collection::emptyText() const { diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/Collection.h index b3ed5b07e..4fcba22b8 100644 --- a/src/libtomahawk/Collection.h +++ b/src/libtomahawk/Collection.h @@ -55,6 +55,7 @@ public: virtual QString itemName() const; virtual QString type() const { return QString(); } virtual QIcon icon() const; + virtual QPixmap bigIcon() const; //for the ViewPage header virtual QString emptyText() const; virtual void loadPlaylists() { qDebug() << Q_FUNC_INFO; } diff --git a/src/libtomahawk/database/LocalCollection.cpp b/src/libtomahawk/database/LocalCollection.cpp index 0448aa5f4..2a1d8979e 100644 --- a/src/libtomahawk/database/LocalCollection.cpp +++ b/src/libtomahawk/database/LocalCollection.cpp @@ -23,6 +23,7 @@ #include "SourceList.h" #include #include "utils/Logger.h" +#include "utils/TomahawkUtilsGui.h" #ifndef ENABLE_HEADLESS #include "ViewManager.h" diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index 2c6ce8cb1..ee6d2203d 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -259,8 +259,7 @@ TreeModel::addCollection( const collection_ptr& collection ) connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); - if ( !collection->source()->avatar().isNull() ) - setIcon( collection->source()->avatar( TomahawkUtils::RoundedCorners ) ); + setIcon( collection->bigIcon() ); setTitle( collection->prettyName() ); } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 89200d722..9ce06cca8 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -21,8 +21,10 @@ #include "Source.h" #include "ExternalResolverGui.h" +#include "utils/TomahawkUtilsGui.h" #include +#include using namespace Tomahawk; @@ -80,6 +82,31 @@ ScriptCollection::icon() const } +QPixmap +ScriptCollection::bigIcon() const +{ + QPixmap big = Collection::bigIcon(); + QPixmap base = icon().pixmap( big.size() ); + + if ( !source()->isLocal() ) + { + big = big.scaled( TomahawkUtils::defaultIconSize(), + Qt::KeepAspectRatio, + Qt::SmoothTransformation ); + + QPainter painter( &base ); + painter.drawPixmap( base.width() - big.width(), + base.height() - big.height(), + big.width(), + big.height(), + big ); + painter.end(); + } + + return base; +} + + void ScriptCollection::artists() { diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 7c4c60ccd..00645ac4d 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -44,6 +44,7 @@ public: virtual QString itemName() const; virtual QString type() const { return "scriptcollection"; } virtual QIcon icon() const; + virtual QPixmap bigIcon() const; virtual ExternalResolver* resolver() { return m_resolver; } From 29cdcec3c6d163ce31ab1e882f1226d59afbda72 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 27 Jan 2013 11:01:17 +0100 Subject: [PATCH 19/44] Support albums in scriptcollection. --- .../resolvers/QtScriptResolver.cpp | 89 ++++++++++++++++--- src/libtomahawk/resolvers/QtScriptResolver.h | 2 + .../resolvers/ScriptCollection.cpp | 3 +- 3 files changed, 83 insertions(+), 11 deletions(-) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 3a2d8c051..1c5247ec3 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -138,7 +138,7 @@ void QtScriptResolverHelper::addArtistResults( const QVariantMap& results ) { qDebug() << "Resolver reporting artists:" << results; - QList< Tomahawk::artist_ptr > artists = m_resolver->parseArtistVariantList( results.value("artists").toList() ); + QList< Tomahawk::artist_ptr > artists = m_resolver->parseArtistVariantList( results.value( "artists" ).toList() ); QString qid = results.value("qid").toString(); @@ -160,8 +160,35 @@ QtScriptResolverHelper::addArtistResults( const QVariantMap& results ) Q_ARG( QList< Tomahawk::artist_ptr >, artists ) ); } -void QtScriptResolverHelper::addAlbumResults(const QVariantMap &results) + +void +QtScriptResolverHelper::addAlbumResults( const QVariantMap& results ) { + qDebug() << "Resolver reporting albums:" << results; + QString artistName = results.value( "artist" ).toString(); + if ( artistName.trimmed().isEmpty() ) + return; + Tomahawk::artist_ptr artist = Tomahawk::Artist::get( artistName, false ); + QList< Tomahawk::album_ptr > albums = m_resolver->parseAlbumVariantList( artist, results.value( "albums" ).toList() ); + + QString qid = results.value("qid").toString(); + + Tomahawk::collection_ptr collection = Tomahawk::collection_ptr(); + foreach ( const Tomahawk::collection_ptr& coll, m_resolver->collections() ) + { + if ( coll->name() == qid ) + { + collection = coll; + } + } + if ( collection.isNull() ) + return; + + tDebug() << Q_FUNC_INFO << "about to push" << albums.count() << "albums"; + foreach( const Tomahawk::album_ptr& album, albums) + tDebug() << album->name(); + QMetaObject::invokeMethod( collection.data(), "onAlbumsFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::album_ptr >, albums ) ); } @@ -448,20 +475,43 @@ QtScriptResolver::artists( const Tomahawk::collection_ptr& collection ) } qDebug() << "Artists JavaScript Result:" << m; - - const QString qid = collection->name(); - const QVariantList reslist = m.value( "artists" ).toList(); - - QList< Tomahawk::artist_ptr > artists = parseArtistVariantList( reslist ); - - QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::artist_ptr >, artists ) ); + m_resolverHelper->addArtistResults( m ); } void QtScriptResolver::albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) { + if ( QThread::currentThread() != thread() ) + { + QMetaObject::invokeMethod( this, "albums", Qt::QueuedConnection, + Q_ARG( Tomahawk::collection_ptr, collection ), + Q_ARG( Tomahawk::artist_ptr, artist ) ); + return; + } + + if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver + !capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections + { + QMetaObject::invokeMethod( collection.data(), "onAlbumsFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::album_ptr >, QList< Tomahawk::album_ptr >() ) ); + return; + } + + QString eval = QString( "resolver.albums( '%1', '%2' );" ) + .arg( collection->name().replace( "'", "\\'" ) ) + .arg( artist->name().replace( "'", "\\'" ) ); + + QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( eval ).toMap(); + if ( m.isEmpty() ) + { + // if the resolver doesn't return anything, async api is used + return; + } + + qDebug() << "Albums JavaScript Result:" << m; + + m_resolverHelper->addAlbumResults( m ); } @@ -604,6 +654,25 @@ QtScriptResolver::parseArtistVariantList( const QVariantList& reslist ) } +QList< Tomahawk::album_ptr > +QtScriptResolver::parseAlbumVariantList( const Tomahawk::artist_ptr& artist, const QVariantList& reslist ) +{ + QList< Tomahawk::album_ptr > results; + + foreach( const QVariant& rv, reslist ) + { + if ( rv.toString().trimmed().isEmpty() ) + continue; + + Tomahawk::album_ptr ap = Tomahawk::Album::get( artist, rv.toString(), false ); + + results << ap; + } + + return results; +} + + void QtScriptResolver::stop() { diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index 02030635d..1a7573c1b 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -180,6 +180,8 @@ private: QList< Tomahawk::result_ptr > parseResultVariantList( const QVariantList& reslist ); QList< Tomahawk::artist_ptr > parseArtistVariantList( const QVariantList& reslist ); + QList< Tomahawk::album_ptr > parseAlbumVariantList( const Tomahawk::artist_ptr& artist, + const QVariantList& reslist ); ScriptEngine* m_engine; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 9ce06cca8..2f0aa4142 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -117,7 +117,7 @@ ScriptCollection::artists() void ScriptCollection::albums( const Tomahawk::artist_ptr& artist ) { - emit albumsResult( QList< Tomahawk::album_ptr >() ); + m_resolver->albums( m_resolver->collections().value( name() ), artist ); } @@ -138,6 +138,7 @@ ScriptCollection::onArtistsFetched( const QList& artists ) void ScriptCollection::onAlbumsFetched( const QList& albums ) { + emit albumsResult( albums ); } From 9c5118c49af469a3da2b362c9174ae05dcb6c530 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 27 Jan 2013 19:45:23 +0100 Subject: [PATCH 20/44] Add tracks to ScriptCollection. --- .../resolvers/QtScriptResolver.cpp | 71 +++++++++++++++++++ src/libtomahawk/resolvers/QtScriptResolver.h | 1 + .../resolvers/ScriptCollection.cpp | 3 +- 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 1c5247ec3..da08c9a86 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -192,6 +192,46 @@ QtScriptResolverHelper::addAlbumResults( const QVariantMap& results ) } +void +QtScriptResolverHelper::addAlbumTrackResults( const QVariantMap& results ) +{ + qDebug() << "Resolver reporting album tracks:" << results; + QString artistName = results.value( "artist" ).toString(); + if ( artistName.trimmed().isEmpty() ) + return; + QString albumName = results.value( "album" ).toString(); + if ( albumName.trimmed().isEmpty() ) + return; + + Tomahawk::artist_ptr artist = Tomahawk::Artist::get( artistName, false ); + Tomahawk::album_ptr album = Tomahawk::Album::get( artist, albumName, false ); + + QList< Tomahawk::result_ptr > tracks = m_resolver->parseResultVariantList( results.value("results").toList() ); + + QString qid = results.value("qid").toString(); + + Tomahawk::collection_ptr collection = Tomahawk::collection_ptr(); + foreach ( const Tomahawk::collection_ptr& coll, m_resolver->collections() ) + { + if ( coll->name() == qid ) + { + collection = coll; + } + } + if ( collection.isNull() ) + return; + + QList< Tomahawk::query_ptr > queries; + foreach ( const Tomahawk::result_ptr& result, tracks ) + queries.append( result->toQuery() ); + + tDebug() << Q_FUNC_INFO << "about to push" << tracks.count() << "tracks"; + + QMetaObject::invokeMethod( collection.data(), "onTracksFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::query_ptr >, queries ) ); +} + + void QtScriptResolverHelper::setResolverConfig( const QVariantMap& config ) { @@ -518,6 +558,37 @@ QtScriptResolver::albums( const Tomahawk::collection_ptr& collection, const Toma void QtScriptResolver::tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) { + if ( QThread::currentThread() != thread() ) + { + QMetaObject::invokeMethod( this, "tracks", Qt::QueuedConnection, + Q_ARG( Tomahawk::collection_ptr, collection ), + Q_ARG( Tomahawk::album_ptr, album ) ); + return; + } + + if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver + !capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections + { + QMetaObject::invokeMethod( collection.data(), "onTracksFetched", Qt::QueuedConnection, + Q_ARG( QList< Tomahawk::query_ptr >, QList< Tomahawk::query_ptr >() ) ); + return; + } + + QString eval = QString( "resolver.tracks( '%1', '%2', '%3' );" ) + .arg( collection->name().replace( "'", "\\'" ) ) + .arg( album->artist()->name().replace( "'", "\\'" ) ) + .arg( album->name().replace( "'", "\\'" ) ); + + QVariantMap m = m_engine->mainFrame()->evaluateJavaScript( eval ).toMap(); + if ( m.isEmpty() ) + { + // if the resolver doesn't return anything, async api is used + return; + } + + qDebug() << "Tracks JavaScript Result:" << m; + + m_resolverHelper->addAlbumTrackResults( m ); } diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index 1a7573c1b..659754592 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -74,6 +74,7 @@ public slots: void addArtistResults( const QVariantMap& results ); void addAlbumResults( const QVariantMap& results ); + void addAlbumTrackResults( const QVariantMap& results ); private: QString m_scriptPath, m_urlCallback; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 2f0aa4142..93d7d9fce 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -124,7 +124,7 @@ ScriptCollection::albums( const Tomahawk::artist_ptr& artist ) void ScriptCollection::tracks( const Tomahawk::album_ptr& album ) { - emit tracksResult( QList< Tomahawk::query_ptr >() ); + m_resolver->tracks( m_resolver->collections().value( name() ), album ); } @@ -145,4 +145,5 @@ ScriptCollection::onAlbumsFetched( const QList& albums ) void ScriptCollection::onTracksFetched( const QList& tracks ) { + emit tracksResult( tracks ); } From 4a2fd14d70d6209878a34ac5cfb282ba1fe6b0cb Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 28 Jan 2013 12:35:30 +0100 Subject: [PATCH 21/44] Fix after borked rebase. --- src/libtomahawk/Artist.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libtomahawk/Artist.h b/src/libtomahawk/Artist.h index 03c2ae1c5..0bb5ec001 100644 --- a/src/libtomahawk/Artist.h +++ b/src/libtomahawk/Artist.h @@ -89,6 +89,7 @@ signals: void statsLoaded(); private slots: + void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection ); void onAlbumsFound( const QList& albums, const QVariant& collectionIsNull = QVariant( false ) ); void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); From 4777a64ce7cb4499a114678aa37bce24e7c23974 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 28 Jan 2013 13:29:33 +0100 Subject: [PATCH 22/44] Fixed duplicate tracks. But why do they happen? --- src/libtomahawk/AlbumPlaylistInterface.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index 8cc30aca7..b501d7a1f 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -257,6 +257,10 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) void AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks ) { + if ( !tracks.isEmpty() && + ( tracks.first()->artist() != m_album->artist()->name() || + tracks.first()->album() != m_album->name() ) ) + return; if ( m_collection.isNull() ) { m_databaseLoaded = true; From c6cb208e199672e373710a20772ca7066325a29c Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 28 Jan 2013 19:56:29 +0100 Subject: [PATCH 23/44] Replace stupid fix for track dupes in ScriptCollection with a real one. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 7 +++---- src/libtomahawk/resolvers/ScriptCollection.cpp | 2 ++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index b501d7a1f..2207e94f4 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -257,10 +257,9 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) void AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks ) { - if ( !tracks.isEmpty() && - ( tracks.first()->artist() != m_album->artist()->name() || - tracks.first()->album() != m_album->name() ) ) - return; + disconnect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), + this, SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ) ); + if ( m_collection.isNull() ) { m_databaseLoaded = true; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 93d7d9fce..3a58f0e1e 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -22,6 +22,7 @@ #include "Source.h" #include "ExternalResolverGui.h" #include "utils/TomahawkUtilsGui.h" +#include "utils/Logger.h" #include #include @@ -145,5 +146,6 @@ ScriptCollection::onAlbumsFetched( const QList& albums ) void ScriptCollection::onTracksFetched( const QList& tracks ) { + tDebug() << Q_FUNC_INFO << "About to emit tracksResult"; emit tracksResult( tracks ); } From 1e8767f022df1c1e0fd95e8f9f6d3cbc4c01c540 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 28 Jan 2013 23:01:35 +0100 Subject: [PATCH 24/44] We're pretty sure the results from Subsonic are good. --- src/libtomahawk/resolvers/QtScriptResolver.cpp | 3 +++ src/libtomahawk/resolvers/ScriptCollection.cpp | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index da08c9a86..8db352e25 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -223,7 +223,10 @@ QtScriptResolverHelper::addAlbumTrackResults( const QVariantMap& results ) QList< Tomahawk::query_ptr > queries; foreach ( const Tomahawk::result_ptr& result, tracks ) + { + result->setScore( 1.0 ); queries.append( result->toQuery() ); + } tDebug() << Q_FUNC_INFO << "about to push" << tracks.count() << "tracks"; diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 3a58f0e1e..97693695c 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -146,6 +146,5 @@ ScriptCollection::onAlbumsFetched( const QList& albums ) void ScriptCollection::onTracksFetched( const QList& tracks ) { - tDebug() << Q_FUNC_INFO << "About to emit tracksResult"; emit tracksResult( tracks ); } From 606ecb58658789a982b9d550ac2435fb515aef92 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 1 Feb 2013 10:13:41 +0100 Subject: [PATCH 25/44] Move all resolver-related classes to libtomahawk/resolvers --- src/SettingsDialog.cpp | 4 ++-- src/libtomahawk/CMakeLists.txt | 7 ++++--- src/libtomahawk/Pipeline.cpp | 2 +- src/libtomahawk/Query.cpp | 2 +- src/libtomahawk/Result.cpp | 4 ++-- src/libtomahawk/SourceList.cpp | 2 +- src/libtomahawk/accounts/ResolverAccount.cpp | 4 ++-- src/libtomahawk/database/DatabaseResolver.h | 2 +- src/libtomahawk/{ => resolvers}/ExternalResolver.cpp | 0 src/libtomahawk/{ => resolvers}/ExternalResolver.h | 0 src/libtomahawk/{ => resolvers}/ExternalResolverGui.cpp | 0 src/libtomahawk/{ => resolvers}/ExternalResolverGui.h | 0 src/libtomahawk/{ => resolvers}/Resolver.cpp | 0 src/libtomahawk/{ => resolvers}/Resolver.h | 0 14 files changed, 14 insertions(+), 13 deletions(-) rename src/libtomahawk/{ => resolvers}/ExternalResolver.cpp (100%) rename src/libtomahawk/{ => resolvers}/ExternalResolver.h (100%) rename src/libtomahawk/{ => resolvers}/ExternalResolverGui.cpp (100%) rename src/libtomahawk/{ => resolvers}/ExternalResolverGui.h (100%) rename src/libtomahawk/{ => resolvers}/Resolver.cpp (100%) rename src/libtomahawk/{ => resolvers}/Resolver.h (100%) diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index 3da35d300..c3a1bc0cf 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -33,8 +33,8 @@ #include "TomahawkSettings.h" #include "accounts/DelegateConfigWrapper.h" #include "Pipeline.h" -#include "Resolver.h" -#include "ExternalResolverGui.h" +#include "resolvers/Resolver.h" +#include "resolvers/ExternalResolverGui.h" #include "utils/TomahawkUtilsGui.h" #include "utils/GuiHelpers.h" #include "accounts/AccountDelegate.h" diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index c3ac2c64c..2007be8da 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -86,7 +86,7 @@ set( libGuiSources playlist/dynamic/widgets/CollapsibleControls.cpp playlist/dynamic/widgets/DynamicSetupWidget.cpp - ExternalResolverGui.cpp + resolvers/ExternalResolverGui.cpp resolvers/ScriptResolver.cpp resolvers/QtScriptResolver.cpp resolvers/ScriptCollection.cpp @@ -183,8 +183,6 @@ list(APPEND libSources Playlist.cpp PlaylistPlaylistInterface.cpp MetaPlaylistInterface.cpp - Resolver.cpp - ExternalResolver.cpp Query.cpp Result.cpp Source.cpp @@ -306,6 +304,9 @@ list(APPEND libSources playlist/dynamic/database/DatabaseGenerator.cpp playlist/dynamic/database/DatabaseControl.cpp playlist/dynamic/DynamicControl.cpp + + resolvers/Resolver.cpp + resolvers/ExternalResolver.cpp utils/TomahawkUtils.cpp utils/Logger.cpp diff --git a/src/libtomahawk/Pipeline.cpp b/src/libtomahawk/Pipeline.cpp index 88a2f9fc9..e4e105d34 100644 --- a/src/libtomahawk/Pipeline.cpp +++ b/src/libtomahawk/Pipeline.cpp @@ -22,7 +22,7 @@ #include "FuncTimeout.h" #include "database/Database.h" -#include "ExternalResolver.h" +#include "resolvers/ExternalResolver.h" #include "resolvers/ScriptResolver.h" #include "resolvers/QtScriptResolver.h" #include "Source.h" diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index 62dcc9ee6..28cd4668f 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -31,7 +31,7 @@ #include "Album.h" #include "Collection.h" #include "Pipeline.h" -#include "Resolver.h" +#include "resolvers/Resolver.h" #include "SourceList.h" #include "audio/AudioEngine.h" diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index d4c08e7a6..91bfd0ecf 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -20,7 +20,7 @@ #include "Album.h" #include "Collection.h" -#include "Resolver.h" +#include "resolvers/Resolver.h" #include "Source.h" #include "Pipeline.h" #include "database/Database.h" @@ -31,7 +31,7 @@ #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" -#include "ExternalResolverGui.h" +#include "resolvers/ExternalResolverGui.h" using namespace Tomahawk; diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index 2d2fd378d..91ba0b831 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -25,7 +25,7 @@ #include "network/RemoteCollection.h" #include "network/ControlConnection.h" #include "infosystem/InfoSystemCache.h" -#include "ExternalResolver.h" +#include "resolvers/ExternalResolver.h" #include "resolvers/ScriptCollection.h" #include "utils/Logger.h" diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 184790505..1384cdb63 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -20,8 +20,8 @@ #include "AccountManager.h" #include "AtticaManager.h" -#include "ExternalResolver.h" -#include "ExternalResolverGui.h" +#include "resolvers/ExternalResolver.h" +#include "resolvers/ExternalResolverGui.h" #include "Pipeline.h" #include "TomahawkSettings.h" #include "Source.h" diff --git a/src/libtomahawk/database/DatabaseResolver.h b/src/libtomahawk/database/DatabaseResolver.h index 2a26bbef8..4a120f35d 100644 --- a/src/libtomahawk/database/DatabaseResolver.h +++ b/src/libtomahawk/database/DatabaseResolver.h @@ -19,7 +19,7 @@ #ifndef DATABASERESOLVER_H #define DATABASERESOLVER_H -#include "Resolver.h" +#include "resolvers/Resolver.h" #include "Result.h" #include "Artist.h" #include "Album.h" diff --git a/src/libtomahawk/ExternalResolver.cpp b/src/libtomahawk/resolvers/ExternalResolver.cpp similarity index 100% rename from src/libtomahawk/ExternalResolver.cpp rename to src/libtomahawk/resolvers/ExternalResolver.cpp diff --git a/src/libtomahawk/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h similarity index 100% rename from src/libtomahawk/ExternalResolver.h rename to src/libtomahawk/resolvers/ExternalResolver.h diff --git a/src/libtomahawk/ExternalResolverGui.cpp b/src/libtomahawk/resolvers/ExternalResolverGui.cpp similarity index 100% rename from src/libtomahawk/ExternalResolverGui.cpp rename to src/libtomahawk/resolvers/ExternalResolverGui.cpp diff --git a/src/libtomahawk/ExternalResolverGui.h b/src/libtomahawk/resolvers/ExternalResolverGui.h similarity index 100% rename from src/libtomahawk/ExternalResolverGui.h rename to src/libtomahawk/resolvers/ExternalResolverGui.h diff --git a/src/libtomahawk/Resolver.cpp b/src/libtomahawk/resolvers/Resolver.cpp similarity index 100% rename from src/libtomahawk/Resolver.cpp rename to src/libtomahawk/resolvers/Resolver.cpp diff --git a/src/libtomahawk/Resolver.h b/src/libtomahawk/resolvers/Resolver.h similarity index 100% rename from src/libtomahawk/Resolver.h rename to src/libtomahawk/resolvers/Resolver.h From 0e566bc300b3fc404c61f1d8fcc423f8e3d91cf4 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 1 Feb 2013 12:21:23 +0100 Subject: [PATCH 26/44] Move Collection.{h,cpp} to its own directory. --- src/TomahawkApp.cpp | 2 +- src/TomahawkTrayIcon.cpp | 2 +- src/libtomahawk/Album.h | 2 +- src/libtomahawk/Artist.cpp | 2 +- src/libtomahawk/ArtistPlaylistInterface.cpp | 2 +- src/libtomahawk/CMakeLists.txt | 13 +++++++------ src/libtomahawk/ContextMenu.cpp | 2 +- src/libtomahawk/EchonestCatalogSynchronizer.cpp | 2 +- src/libtomahawk/Query.cpp | 2 +- src/libtomahawk/Result.cpp | 2 +- src/libtomahawk/Source.cpp | 2 +- src/libtomahawk/Source.h | 2 +- src/libtomahawk/ViewManager.h | 2 +- src/libtomahawk/{ => collection}/Collection.cpp | 2 +- src/libtomahawk/{ => collection}/Collection.h | 0 src/libtomahawk/database/DatabaseCollection.h | 2 +- .../database/DatabaseCommand_AddFiles.cpp | 2 +- .../database/DatabaseCommand_AllAlbums.h | 2 +- .../database/DatabaseCommand_AllArtists.h | 2 +- .../database/DatabaseCommand_AllTracks.h | 2 +- .../database/DatabaseCommand_DeleteFiles.cpp | 2 +- .../database/DatabaseCommand_LoadFiles.cpp | 2 +- .../database/DatabaseCommand_LogPlayback.cpp | 2 +- .../database/DatabaseCommand_PlaybackCharts.h | 2 +- .../database/DatabaseCommand_RenamePlaylist.cpp | 2 +- src/libtomahawk/resolvers/ScriptCollection.h | 2 +- src/sourcetree/SourcesModel.cpp | 2 +- 27 files changed, 32 insertions(+), 31 deletions(-) rename src/libtomahawk/{ => collection}/Collection.cpp (99%) rename src/libtomahawk/{ => collection}/Collection.h (100%) diff --git a/src/TomahawkApp.cpp b/src/TomahawkApp.cpp index c5026fad4..c139da39a 100644 --- a/src/TomahawkApp.cpp +++ b/src/TomahawkApp.cpp @@ -26,7 +26,7 @@ #include "AclRegistryImpl.h" #include "Album.h" #include "Artist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "infosystem/InfoSystem.h" #include "infosystem/InfoSystemCache.h" #include "accounts/AccountManager.h" diff --git a/src/TomahawkTrayIcon.cpp b/src/TomahawkTrayIcon.cpp index 592c2c64e..868afbf98 100644 --- a/src/TomahawkTrayIcon.cpp +++ b/src/TomahawkTrayIcon.cpp @@ -25,7 +25,7 @@ #include "TomahawkWindow.h" #include "Query.h" #include "Source.h" -#include "Collection.h" +#include "collection/Collection.h" #include "ActionCollection.h" #include "utils/Logger.h" #include "utils/TomahawkUtilsGui.h" diff --git a/src/libtomahawk/Album.h b/src/libtomahawk/Album.h index 9f2252118..6565b400a 100644 --- a/src/libtomahawk/Album.h +++ b/src/libtomahawk/Album.h @@ -30,7 +30,7 @@ #include "Typedefs.h" #include "PlaylistInterface.h" #include "DllMacro.h" -#include "Collection.h" +#include "collection/Collection.h" #include "infosystem/InfoSystem.h" class IdThreadWorker; diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 5f8518e3c..9a0f9dd25 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -21,7 +21,7 @@ #include "Artist.h" #include "ArtistPlaylistInterface.h" -#include "Collection.h" +#include "collection/Collection.h" #include "database/Database.h" #include "database/DatabaseImpl.h" #include "database/DatabaseCommand_AllAlbums.h" diff --git a/src/libtomahawk/ArtistPlaylistInterface.cpp b/src/libtomahawk/ArtistPlaylistInterface.cpp index f595b8a9c..40a2c744e 100644 --- a/src/libtomahawk/ArtistPlaylistInterface.cpp +++ b/src/libtomahawk/ArtistPlaylistInterface.cpp @@ -20,7 +20,7 @@ #include "ArtistPlaylistInterface.h" #include "Artist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Query.h" #include "database/Database.h" #include "database/DatabaseCommand_AllTracks.h" diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 2007be8da..9f6db902a 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -177,7 +177,6 @@ list(APPEND libSources ArtistPlaylistInterface.cpp Album.cpp AlbumPlaylistInterface.cpp - Collection.cpp CountryUtils.cpp FuncTimeout.cpp Playlist.cpp @@ -207,13 +206,10 @@ list(APPEND libSources accounts/spotify/SpotifyPlaylistUpdater.cpp accounts/spotify/SpotifyInfoPlugin.cpp - sip/SipPlugin.cpp - sip/SipInfo.cpp - sip/PeerInfo.cpp - sip/SipStatusMessage.cpp - audio/AudioEngine.cpp + collection/Collection.cpp + database/Database.cpp database/FuzzyIndex.cpp database/DatabaseCollection.cpp @@ -308,6 +304,11 @@ list(APPEND libSources resolvers/Resolver.cpp resolvers/ExternalResolver.cpp + sip/SipPlugin.cpp + sip/SipInfo.cpp + sip/PeerInfo.cpp + sip/SipStatusMessage.cpp + utils/TomahawkUtils.cpp utils/Logger.cpp utils/Qnr_IoDeviceStream.cpp diff --git a/src/libtomahawk/ContextMenu.cpp b/src/libtomahawk/ContextMenu.cpp index 2cf7bef16..c67a63c51 100644 --- a/src/libtomahawk/ContextMenu.cpp +++ b/src/libtomahawk/ContextMenu.cpp @@ -25,7 +25,7 @@ #include "ViewManager.h" #include "Query.h" #include "Result.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Source.h" #include "Artist.h" #include "Album.h" diff --git a/src/libtomahawk/EchonestCatalogSynchronizer.cpp b/src/libtomahawk/EchonestCatalogSynchronizer.cpp index 066dadc69..720db8fd2 100644 --- a/src/libtomahawk/EchonestCatalogSynchronizer.cpp +++ b/src/libtomahawk/EchonestCatalogSynchronizer.cpp @@ -21,7 +21,7 @@ #include #include -#include "Collection.h" +#include "collection/Collection.h" #include "database/Database.h" #include "database/DatabaseImpl.h" #include "database/DatabaseCommand_GenericSelect.h" diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index 28cd4668f..e38cfd0ab 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -29,7 +29,7 @@ #include "database/DatabaseCommand_SocialAction.h" #include "database/DatabaseCommand_TrackStats.h" #include "Album.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Pipeline.h" #include "resolvers/Resolver.h" #include "SourceList.h" diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index 91bfd0ecf..de9e12be8 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -19,7 +19,7 @@ #include "Result.h" #include "Album.h" -#include "Collection.h" +#include "collection/Collection.h" #include "resolvers/Resolver.h" #include "Source.h" #include "Pipeline.h" diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index bcd693117..4be7dbd6f 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -19,7 +19,7 @@ #include "Source.h" -#include "Collection.h" +#include "collection/Collection.h" #include "SourceList.h" #include "SourcePlaylistInterface.h" diff --git a/src/libtomahawk/Source.h b/src/libtomahawk/Source.h index 7878c5c37..6a78b885b 100644 --- a/src/libtomahawk/Source.h +++ b/src/libtomahawk/Source.h @@ -26,7 +26,7 @@ #include "Typedefs.h" #include "network/DbSyncConnection.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Query.h" #include "utils/TomahawkUtils.h" diff --git a/src/libtomahawk/ViewManager.h b/src/libtomahawk/ViewManager.h index a4379516f..0f95c567e 100644 --- a/src/libtomahawk/ViewManager.h +++ b/src/libtomahawk/ViewManager.h @@ -25,7 +25,7 @@ #include #include "Artist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "PlaylistInterface.h" #include "playlist/QueueView.h" #include "ViewPage.h" diff --git a/src/libtomahawk/Collection.cpp b/src/libtomahawk/collection/Collection.cpp similarity index 99% rename from src/libtomahawk/Collection.cpp rename to src/libtomahawk/collection/Collection.cpp index c0851f7c2..61d93e3bf 100644 --- a/src/libtomahawk/Collection.cpp +++ b/src/libtomahawk/collection/Collection.cpp @@ -17,7 +17,7 @@ * along with Tomahawk. If not, see . */ -#include "Collection.h" +#include "collection/Collection.h" #include "Source.h" diff --git a/src/libtomahawk/Collection.h b/src/libtomahawk/collection/Collection.h similarity index 100% rename from src/libtomahawk/Collection.h rename to src/libtomahawk/collection/Collection.h diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index 9f8d6a688..4634acbfc 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -23,7 +23,7 @@ #include -#include "Collection.h" +#include "collection/Collection.h" #include "Source.h" #include "Typedefs.h" diff --git a/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp b/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp index 64bd419f1..c8fc3c03d 100644 --- a/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AddFiles.cpp @@ -22,7 +22,7 @@ #include "Artist.h" #include "Album.h" -#include "Collection.h" +#include "collection/Collection.h" #include "database/Database.h" #include "DatabaseImpl.h" #include "network/DbSyncConnection.h" diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h index d659699d1..e0bb03b92 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h @@ -24,7 +24,7 @@ #include "Album.h" #include "Artist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Typedefs.h" #include "DatabaseCommand.h" diff --git a/src/libtomahawk/database/DatabaseCommand_AllArtists.h b/src/libtomahawk/database/DatabaseCommand_AllArtists.h index fec4944d8..2d0250bea 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllArtists.h +++ b/src/libtomahawk/database/DatabaseCommand_AllArtists.h @@ -23,7 +23,7 @@ #include #include "Artist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Typedefs.h" #include "DatabaseCommand.h" diff --git a/src/libtomahawk/database/DatabaseCommand_AllTracks.h b/src/libtomahawk/database/DatabaseCommand_AllTracks.h index 4aa8ee056..64247eae1 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllTracks.h +++ b/src/libtomahawk/database/DatabaseCommand_AllTracks.h @@ -23,7 +23,7 @@ #include #include "DatabaseCommand.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Typedefs.h" #include "Query.h" #include "Artist.h" diff --git a/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp b/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp index bd1d44c14..4d72550a0 100644 --- a/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp +++ b/src/libtomahawk/database/DatabaseCommand_DeleteFiles.cpp @@ -23,7 +23,7 @@ #include "Artist.h" #include "Album.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Source.h" #include "database/Database.h" #include "database/DatabaseImpl.h" diff --git a/src/libtomahawk/database/DatabaseCommand_LoadFiles.cpp b/src/libtomahawk/database/DatabaseCommand_LoadFiles.cpp index 24a89ff23..b4084bd15 100644 --- a/src/libtomahawk/database/DatabaseCommand_LoadFiles.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LoadFiles.cpp @@ -19,7 +19,7 @@ #include "DatabaseCommand_LoadFiles.h" #include "DatabaseImpl.h" -#include "Collection.h" +#include "collection/Collection.h" #include "utils/Logger.h" #include "Source.h" diff --git a/src/libtomahawk/database/DatabaseCommand_LogPlayback.cpp b/src/libtomahawk/database/DatabaseCommand_LogPlayback.cpp index a9839b47e..9bba059e6 100644 --- a/src/libtomahawk/database/DatabaseCommand_LogPlayback.cpp +++ b/src/libtomahawk/database/DatabaseCommand_LogPlayback.cpp @@ -21,7 +21,7 @@ #include -#include "Collection.h" +#include "collection/Collection.h" #include "database/Database.h" #include "DatabaseImpl.h" #include "network/Servent.h" diff --git a/src/libtomahawk/database/DatabaseCommand_PlaybackCharts.h b/src/libtomahawk/database/DatabaseCommand_PlaybackCharts.h index b9084f1ef..77cf84f3d 100644 --- a/src/libtomahawk/database/DatabaseCommand_PlaybackCharts.h +++ b/src/libtomahawk/database/DatabaseCommand_PlaybackCharts.h @@ -23,7 +23,7 @@ #include #include "Artist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Typedefs.h" #include "DatabaseCommand.h" diff --git a/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp b/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp index 20ed97ec0..a5985001d 100644 --- a/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp +++ b/src/libtomahawk/database/DatabaseCommand_RenamePlaylist.cpp @@ -21,7 +21,7 @@ #include #include "DatabaseImpl.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Source.h" #include "network/Servent.h" #include "utils/Logger.h" diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 00645ac4d..abf9fd7e3 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -21,7 +21,7 @@ #define SCRIPTCOLLECTION_H #include "ExternalResolver.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Typedefs.h" #include "DllMacro.h" diff --git a/src/sourcetree/SourcesModel.cpp b/src/sourcetree/SourcesModel.cpp index ecb6b4711..7a3ed0325 100644 --- a/src/sourcetree/SourcesModel.cpp +++ b/src/sourcetree/SourcesModel.cpp @@ -33,7 +33,7 @@ #include "sourcetree/items/LovedTracksItem.h" #include "SourceList.h" #include "Playlist.h" -#include "Collection.h" +#include "collection/Collection.h" #include "Source.h" #include "ViewManager.h" #include "GlobalActionManager.h" From 1c3941c16bd243205244541d16014f66c2b9c156 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 1 Feb 2013 19:53:41 +0100 Subject: [PATCH 27/44] Experimenting with ScriptCommands, added ScriptCommand_AllArtists. --- src/libtomahawk/CMakeLists.txt | 6 +- src/libtomahawk/collection/ArtistsRequest.h | 43 ++++++++++++ src/libtomahawk/collection/Collection.h | 4 +- .../database/DatabaseCollection.cpp | 20 ++---- src/libtomahawk/database/DatabaseCollection.h | 3 +- .../database/DatabaseCommand_AllArtists.h | 5 ++ src/libtomahawk/playlist/TreeModel.cpp | 7 +- src/libtomahawk/resolvers/ExternalResolver.h | 27 ++++++-- .../resolvers/QtScriptResolver.cpp | 7 +- .../resolvers/ScriptCollection.cpp | 24 +++---- src/libtomahawk/resolvers/ScriptCollection.h | 4 +- src/libtomahawk/resolvers/ScriptCommand.h | 38 +++++++++++ .../resolvers/ScriptCommandQueue.cpp | 65 ++++++++++++++++++ .../resolvers/ScriptCommandQueue.h | 48 +++++++++++++ .../resolvers/ScriptCommand_AllArtists.cpp | 67 +++++++++++++++++++ .../resolvers/ScriptCommand_AllArtists.h | 53 +++++++++++++++ 16 files changed, 373 insertions(+), 48 deletions(-) create mode 100644 src/libtomahawk/collection/ArtistsRequest.h create mode 100644 src/libtomahawk/resolvers/ScriptCommand.h create mode 100644 src/libtomahawk/resolvers/ScriptCommandQueue.cpp create mode 100644 src/libtomahawk/resolvers/ScriptCommandQueue.h create mode 100644 src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp create mode 100644 src/libtomahawk/resolvers/ScriptCommand_AllArtists.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 9f6db902a..d61dfe23b 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -89,7 +89,6 @@ set( libGuiSources resolvers/ExternalResolverGui.cpp resolvers/ScriptResolver.cpp resolvers/QtScriptResolver.cpp - resolvers/ScriptCollection.cpp utils/ImageRegistry.cpp utils/WidgetDragFilter.cpp @@ -301,8 +300,11 @@ list(APPEND libSources playlist/dynamic/database/DatabaseControl.cpp playlist/dynamic/DynamicControl.cpp - resolvers/Resolver.cpp resolvers/ExternalResolver.cpp + resolvers/Resolver.cpp + resolvers/ScriptCollection.cpp + resolvers/ScriptCommand_AllArtists.cpp + resolvers/ScriptCommandQueue.cpp sip/SipPlugin.cpp sip/SipInfo.cpp diff --git a/src/libtomahawk/collection/ArtistsRequest.h b/src/libtomahawk/collection/ArtistsRequest.h new file mode 100644 index 000000000..db5a32975 --- /dev/null +++ b/src/libtomahawk/collection/ArtistsRequest.h @@ -0,0 +1,43 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 ARTISTSREQUEST_H +#define ARTISTSREQUEST_H + +#include "Typedefs.h" +#include "DllMacro.h" + +#include + +namespace Tomahawk +{ + +class DLLEXPORT ArtistsRequest +{ +public: + virtual ~ArtistsRequest() {} + + virtual void enqueue() = 0; + +protected: //signals + virtual void artists( const QList< Tomahawk::artist_ptr >& ) = 0; +}; + +} //ns + +#endif // ARTISTSREQUEST_H diff --git a/src/libtomahawk/collection/Collection.h b/src/libtomahawk/collection/Collection.h index 4fcba22b8..079bf1acd 100644 --- a/src/libtomahawk/collection/Collection.h +++ b/src/libtomahawk/collection/Collection.h @@ -34,6 +34,7 @@ #include "Typedefs.h" #include "Playlist.h" #include "playlist/dynamic/DynamicPlaylist.h" +#include "collection/ArtistsRequest.h" #include "DllMacro.h" @@ -80,7 +81,7 @@ public: virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); } // Async requests. Emit artists/albums/tracksResult in subclasses when finished. - virtual void artists() = 0; + virtual Tomahawk::ArtistsRequest* requestArtists() = 0; virtual void albums( const Tomahawk::artist_ptr& artist ) = 0; virtual void tracks( const Tomahawk::album_ptr& album ) = 0; @@ -88,7 +89,6 @@ public: unsigned int lastmodified() const { return m_lastmodified; } signals: - void artistsResult( const QList< Tomahawk::artist_ptr >& artists ); void albumsResult( const QList< Tomahawk::album_ptr >& albums ); void tracksResult( const QList< Tomahawk::query_ptr >& queries ); diff --git a/src/libtomahawk/database/DatabaseCollection.cpp b/src/libtomahawk/database/DatabaseCollection.cpp index 1bdc518d8..ce443e928 100644 --- a/src/libtomahawk/database/DatabaseCollection.cpp +++ b/src/libtomahawk/database/DatabaseCollection.cpp @@ -133,27 +133,17 @@ DatabaseCollection::stations() } -void -DatabaseCollection::artists() +Tomahawk::ArtistsRequest* +DatabaseCollection::requestArtists() { //FIXME: assuming there's only one dbcollection per source, and that this is the one Tomahawk::collection_ptr thisCollection = source()->dbCollection(); if ( thisCollection->name() != this->name() ) - return; + return 0; - DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( thisCollection ); + Tomahawk::ArtistsRequest* cmd = new DatabaseCommand_AllArtists( thisCollection ); - connect( cmd, SIGNAL( artists( QList< Tomahawk::artist_ptr > ) ), - SLOT( onArtistsFetched( QList< Tomahawk::artist_ptr > ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); -} - - -void -DatabaseCollection::onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists ) -{ - emit artistsResult( artists ); + return cmd; } diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index 4634acbfc..2fa3a6b49 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -50,7 +50,7 @@ public: virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists(); virtual QList< Tomahawk::dynplaylist_ptr > stations(); - virtual void artists(); + virtual Tomahawk::ArtistsRequest* requestArtists(); virtual void albums( const Tomahawk::artist_ptr& artist ); virtual void tracks( const Tomahawk::album_ptr& album ); @@ -59,7 +59,6 @@ public slots: virtual void removeTracks( const QDir& dir ); private slots: - void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists ); void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums, const QVariant& data ); void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); diff --git a/src/libtomahawk/database/DatabaseCommand_AllArtists.h b/src/libtomahawk/database/DatabaseCommand_AllArtists.h index 2d0250bea..ac778ac4c 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllArtists.h +++ b/src/libtomahawk/database/DatabaseCommand_AllArtists.h @@ -23,13 +23,16 @@ #include #include "Artist.h" +#include "collection/ArtistsRequest.h" #include "collection/Collection.h" #include "Typedefs.h" #include "DatabaseCommand.h" +#include "Database.h" #include "DllMacro.h" class DLLEXPORT DatabaseCommand_AllArtists : public DatabaseCommand + , public Tomahawk::ArtistsRequest { Q_OBJECT public: @@ -47,6 +50,8 @@ public: virtual bool doesMutates() const { return false; } virtual QString commandname() const { return "allartists"; } + virtual void enqueue() { Database::instance()->enqueue( QSharedPointer( this ) ); } + void setLimit( unsigned int amount ) { m_amount = amount; } void setSortOrder( DatabaseCommand_AllArtists::SortOrder order ) { m_sortOrder = order; } void setSortDescending( bool descending ) { m_sortDescending = descending; } diff --git a/src/libtomahawk/playlist/TreeModel.cpp b/src/libtomahawk/playlist/TreeModel.cpp index ee6d2203d..56f6ba7ae 100644 --- a/src/libtomahawk/playlist/TreeModel.cpp +++ b/src/libtomahawk/playlist/TreeModel.cpp @@ -253,9 +253,10 @@ TreeModel::addCollection( const collection_ptr& collection ) m_collection = collection; - connect( m_collection.data(), SIGNAL( artistsResult( QList ) ), - SLOT( onArtistsAdded( QList ) ), Qt::UniqueConnection ); - m_collection->artists(); + Tomahawk::ArtistsRequest* req = m_collection->requestArtists(); + connect( dynamic_cast< QObject* >( req ), SIGNAL( artists( QList< Tomahawk::artist_ptr > ) ), + this, SLOT( onArtistsAdded( QList< Tomahawk::artist_ptr > ) ), Qt::UniqueConnection ); + req->enqueue(); connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); diff --git a/src/libtomahawk/resolvers/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h index dc87f5c90..93468ab67 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.h +++ b/src/libtomahawk/resolvers/ExternalResolver.h @@ -25,6 +25,8 @@ #include "Query.h" #include "DllMacro.h" #include "Resolver.h" +#include "ScriptCommandQueue.h" +#include "ScriptCommand_AllArtists.h" #include @@ -45,6 +47,9 @@ class DLLEXPORT ExternalResolver : public Resolver { Q_OBJECT + friend class ::ScriptCommandQueue; + friend class ::ScriptCommand_AllArtists; + public: enum ErrorState { NoError, @@ -62,7 +67,9 @@ public: Q_DECLARE_FLAGS( Capabilities, Capability ) Q_FLAGS( Capabilities ) - ExternalResolver( const QString& filePath ) { m_filePath = filePath; } + ExternalResolver( const QString& filePath ) + : m_commandQueue( new ScriptCommandQueue( this ) ) + { m_filePath = filePath; } virtual QString filePath() const { return m_filePath; } @@ -74,23 +81,31 @@ public: virtual Capabilities capabilities() const = 0; virtual QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; } + virtual void enqueue( const QSharedPointer< ScriptCommand >& req ) + { m_commandQueue->enqueue( req ); } + public slots: virtual void start() = 0; virtual void stop() = 0; - // For ScriptCollection - virtual void artists( const Tomahawk::collection_ptr& collection ) = 0; - virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) = 0; - virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) = 0; - signals: void changed(); // if config widget was added/removed, name changed, etc void collectionAdded( const Tomahawk::collection_ptr& collection ); void collectionRemoved( const Tomahawk::collection_ptr& collection ); + void artistsFound( const QList< Tomahawk::artist_ptr >& ); + void albumsFound( const QList< Tomahawk::album_ptr >& ); + void tracksFound( const QList< Tomahawk::query_ptr >& ); + protected: void setFilePath( const QString& path ) { m_filePath = path; } QMap< QString, Tomahawk::collection_ptr > m_collections; + ScriptCommandQueue* m_commandQueue; + + // Should only be called by ScriptCommands + virtual void artists( const Tomahawk::collection_ptr& collection ) = 0; + virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) = 0; + virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) = 0; private: QString m_filePath; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 8db352e25..6454594c8 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -156,8 +156,8 @@ QtScriptResolverHelper::addArtistResults( const QVariantMap& results ) tDebug() << Q_FUNC_INFO << "about to push" << artists.count() << "artists"; foreach( const Tomahawk::artist_ptr& artist, artists) tDebug() << artist->name(); - QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::artist_ptr >, artists ) ); + + emit m_resolver->artistsFound( artists ); } @@ -502,8 +502,7 @@ QtScriptResolver::artists( const Tomahawk::collection_ptr& collection ) if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver !capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections { - QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::artist_ptr >, QList< Tomahawk::artist_ptr >() ) ); + emit artistsFound( QList< Tomahawk::artist_ptr >() ); return; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 97693695c..635f5e58a 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -23,6 +23,7 @@ #include "ExternalResolverGui.h" #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" +#include "resolvers/ScriptCommand_AllArtists.h" #include #include @@ -108,31 +109,30 @@ ScriptCollection::bigIcon() const } -void -ScriptCollection::artists() +Tomahawk::ArtistsRequest* +ScriptCollection::requestArtists() { - m_resolver->artists( m_resolver->collections().value( name() ) ); + Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() ); + if ( thisCollection->name() != this->name() ) + return 0; + + Tomahawk::ArtistsRequest* cmd = new ScriptCommand_AllArtists( thisCollection ); + + return cmd; } void ScriptCollection::albums( const Tomahawk::artist_ptr& artist ) { - m_resolver->albums( m_resolver->collections().value( name() ), artist ); + //m_resolver->albums( m_resolver->collections().value( name() ), artist ); } void ScriptCollection::tracks( const Tomahawk::album_ptr& album ) { - m_resolver->tracks( m_resolver->collections().value( name() ), album ); -} - - -void -ScriptCollection::onArtistsFetched( const QList& artists ) -{ - emit artistsResult( artists ); + //m_resolver->tracks( m_resolver->collections().value( name() ), album ); } diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index abf9fd7e3..5a9272b16 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -22,6 +22,7 @@ #include "ExternalResolver.h" #include "collection/Collection.h" +#include "collection/ArtistsRequest.h" #include "Typedefs.h" #include "DllMacro.h" @@ -48,12 +49,11 @@ public: virtual ExternalResolver* resolver() { return m_resolver; } - virtual void artists(); + virtual Tomahawk::ArtistsRequest* requestArtists(); virtual void albums( const Tomahawk::artist_ptr& artist ); virtual void tracks( const Tomahawk::album_ptr& album ); private slots: - void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists ); void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums ); void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); diff --git a/src/libtomahawk/resolvers/ScriptCommand.h b/src/libtomahawk/resolvers/ScriptCommand.h new file mode 100644 index 000000000..13717c825 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand.h @@ -0,0 +1,38 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 SCRIPTCOMMAND_H +#define SCRIPTCOMMAND_H + +#include + +class ScriptCommand : public QObject +{ +public: + explicit ScriptCommand( QObject* parent = 0 ) : QObject( parent ) {} + virtual ~ScriptCommand() {} + +signals: + virtual void done() = 0; + +protected: + friend class ScriptCommandQueue; + virtual void exec() = 0; +}; + +#endif // SCRIPTCOMMAND_H diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp new file mode 100644 index 000000000..edf312bcb --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -0,0 +1,65 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "ScriptCommandQueue.h" + +#include "utils/Closure.h" + +#include + +ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) + : QObject( parent ) + , m_timer( new QTimer( this ) ) +{ + m_timer->setSingleShot( true ); + connect( m_timer, SIGNAL( timeout() ), SLOT( onTimeout() ) ); +} + + +void +ScriptCommandQueue::enqueue( const QSharedPointer< ScriptCommand >& req ) +{ + m_queue.append( req ); + if ( m_queue.count() == 1 ) + nextCommand(); +} + + +void +ScriptCommandQueue::nextCommand() +{ + if ( m_queue.isEmpty() ) + return; + + QSharedPointer< ScriptCommand > req = m_queue.first(); + + NewClosure( req.data(), SIGNAL( done() ), + this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req ); + + req->exec(); +} + + +void +ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req ) +{ + m_queue.removeAll( req ); + req->deleteLater(); + if ( m_queue.count() > 0 ) + nextCommand(); +} diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.h b/src/libtomahawk/resolvers/ScriptCommandQueue.h new file mode 100644 index 000000000..bd7ae2d41 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.h @@ -0,0 +1,48 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 SCRIPTCOMMANDQUEUE_H +#define SCRIPTCOMMANDQUEUE_H + +#include "ScriptCommand.h" + +#include +#include +#include +#include + +class ScriptCommandQueue : public QObject +{ + Q_OBJECT +public: + explicit ScriptCommandQueue( QObject* parent = 0 ); + + void enqueue( const QSharedPointer< ScriptCommand >& req ); + +private slots: + void nextCommand(); + void onCommandDone( const QSharedPointer< ScriptCommand >& req ); + +private: + QQueue< QSharedPointer< ScriptCommand > > m_queue; + QTimer* m_timer; +}; + +Q_DECLARE_METATYPE( QSharedPointer< ScriptCommand > ) + +#endif // SCRIPTCOMMANDQUEUE_H diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp new file mode 100644 index 000000000..c949d672d --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp @@ -0,0 +1,67 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "ScriptCommand_AllArtists.h" + +#include "ExternalResolver.h" +#include "ScriptCollection.h" + +ScriptCommand_AllArtists::ScriptCommand_AllArtists( const Tomahawk::collection_ptr& collection, + QObject* parent ) + : ScriptCommand( parent ) + , m_collection( collection ) +{ +} + + +void +ScriptCommand_AllArtists::enqueue() +{ + Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); + if ( collection == 0 ) + { + emit artists( QList< Tomahawk::artist_ptr >() ); + return; + } + + collection->resolver()->enqueue( QSharedPointer< ScriptCommand >( this ) ); +} + + +void +ScriptCommand_AllArtists::exec() +{ + Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); + if ( collection == 0 ) + { + emit artists( QList< Tomahawk::artist_ptr >() ); + return; + } + + connect( collection->resolver(), SIGNAL( artistsFound( QList< Tomahawk::artist_ptr > ) ), + this, SLOT( onResolverDone( QList< Tomahawk::artist_ptr > ) ) ); + + collection->resolver()->artists( m_collection ); +} + + +void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a ) +{ + emit artists( a ); + emit done(); +} diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h new file mode 100644 index 000000000..051d30001 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h @@ -0,0 +1,53 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 SCRIPTCOMMAND_ALLARTISTS_H +#define SCRIPTCOMMAND_ALLARTISTS_H + +#include "collection/ArtistsRequest.h" +#include "collection/Collection.h" +#include "resolvers/ScriptCommand.h" + +#include + +class ScriptCommand_AllArtists : public ScriptCommand + , public Tomahawk::ArtistsRequest +{ + Q_OBJECT +public: + explicit ScriptCommand_AllArtists( const Tomahawk::collection_ptr& collection, + QObject* parent = 0 ); + virtual ~ScriptCommand_AllArtists() {} + + virtual void enqueue(); + +signals: + void artists( const QList< Tomahawk::artist_ptr >& ); + void done(); + +protected: + virtual void exec(); + +private slots: + void onResolverDone( const QList< Tomahawk::artist_ptr >& ); + +private: + Tomahawk::collection_ptr m_collection; +}; + +#endif // SCRIPTCOMMAND_ALLARTISTS_H From 3da3969ad2d16d09609d04b7d87b3e22d083644b Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 3 Feb 2013 17:57:56 +0100 Subject: [PATCH 28/44] Added timeout support to ScriptCommandQueue. --- src/libtomahawk/resolvers/ScriptCommand.h | 1 + .../resolvers/ScriptCommandQueue.cpp | 26 ++++++++++++++++++- .../resolvers/ScriptCommandQueue.h | 2 ++ .../resolvers/ScriptCommand_AllArtists.cpp | 8 ++++++ .../resolvers/ScriptCommand_AllArtists.h | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/resolvers/ScriptCommand.h b/src/libtomahawk/resolvers/ScriptCommand.h index 13717c825..60ae4db7c 100644 --- a/src/libtomahawk/resolvers/ScriptCommand.h +++ b/src/libtomahawk/resolvers/ScriptCommand.h @@ -33,6 +33,7 @@ signals: protected: friend class ScriptCommandQueue; virtual void exec() = 0; + virtual void reportFailure() = 0; }; #endif // SCRIPTCOMMAND_H diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index edf312bcb..6fb42ccbd 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -27,7 +27,6 @@ ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) , m_timer( new QTimer( this ) ) { m_timer->setSingleShot( true ); - connect( m_timer, SIGNAL( timeout() ), SLOT( onTimeout() ) ); } @@ -51,6 +50,11 @@ ScriptCommandQueue::nextCommand() NewClosure( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req ); + NewClosure( m_timer, SIGNAL( timeout() ), + this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ), req ); + + m_timer->start( 2000 ); + req->exec(); } @@ -58,8 +62,28 @@ ScriptCommandQueue::nextCommand() void ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req ) { + disconnect( this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ) ); + m_timer->stop(); + m_queue.removeAll( req ); req->deleteLater(); + + if ( m_queue.count() > 0 ) + nextCommand(); +} + + +void +ScriptCommandQueue::onTimeout( const QSharedPointer< ScriptCommand >& req ) +{ + disconnect( this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ) ); + + m_timer->stop(); + + m_queue.removeAll( req ); + req->reportFailure(); + req->deleteLater(); + if ( m_queue.count() > 0 ) nextCommand(); } diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.h b/src/libtomahawk/resolvers/ScriptCommandQueue.h index bd7ae2d41..c26aabc95 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.h +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.h @@ -31,12 +31,14 @@ class ScriptCommandQueue : public QObject Q_OBJECT public: explicit ScriptCommandQueue( QObject* parent = 0 ); + virtual ~ScriptCommandQueue() {} void enqueue( const QSharedPointer< ScriptCommand >& req ); private slots: void nextCommand(); void onCommandDone( const QSharedPointer< ScriptCommand >& req ); + void onTimeout( const QSharedPointer< ScriptCommand >& req ); private: QQueue< QSharedPointer< ScriptCommand > > m_queue; diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp index c949d672d..ec90c0a09 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp @@ -60,6 +60,14 @@ ScriptCommand_AllArtists::exec() } +void +ScriptCommand_AllArtists::reportFailure() +{ + emit artists( QList< Tomahawk::artist_ptr >() ); + emit done(); +} + + void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a ) { emit artists( a ); diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h index 051d30001..d5adcb755 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h @@ -42,6 +42,7 @@ signals: protected: virtual void exec(); + virtual void reportFailure(); private slots: void onResolverDone( const QList< Tomahawk::artist_ptr >& ); From 48c56e81f78a534df69df3c2d613d0ab7d1aefce Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 3 Feb 2013 20:01:25 +0100 Subject: [PATCH 29/44] Added ScriptCommand_AllAlbums. --- src/libtomahawk/Artist.cpp | 14 ++- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/collection/AlbumsRequest.h | 43 ++++++++++ src/libtomahawk/collection/Collection.h | 3 +- .../database/DatabaseCollection.cpp | 23 ++--- src/libtomahawk/database/DatabaseCollection.h | 3 +- .../database/DatabaseCommand_AllAlbums.cpp | 5 +- .../database/DatabaseCommand_AllAlbums.h | 11 ++- .../database/DatabaseCommand_AllArtists.h | 1 + src/libtomahawk/resolvers/ExternalResolver.h | 2 + .../resolvers/QtScriptResolver.cpp | 7 +- .../resolvers/ScriptCollection.cpp | 20 ++--- src/libtomahawk/resolvers/ScriptCollection.h | 4 +- .../resolvers/ScriptCommandQueue.cpp | 6 +- .../resolvers/ScriptCommand_AllAlbums.cpp | 86 +++++++++++++++++++ .../resolvers/ScriptCommand_AllAlbums.h | 54 ++++++++++++ .../resolvers/ScriptCommand_AllArtists.cpp | 2 +- .../resolvers/ScriptCommand_AllArtists.h | 2 - 18 files changed, 237 insertions(+), 50 deletions(-) create mode 100644 src/libtomahawk/collection/AlbumsRequest.h create mode 100644 src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp create mode 100644 src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 9a0f9dd25..9e34a7512 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -178,10 +178,16 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con } else { - //collection is *surely* not null - connect( collection.data(), SIGNAL( albumsResult( QList< Tomahawk::album_ptr > ) ), - SLOT( onAlbumsFound( QList ) ), Qt::UniqueConnection ); - collection->albums( artist ); + //collection is *surely* not null, and might be a ScriptCollection + Tomahawk::AlbumsRequest* cmd = collection->requestAlbums( artist ); + + // There is also a signal albums( QList, QVariant ). + // The QVariant might carry a bool that says whether the dbcmd was executed for a null collection + // but here we know for a fact that the collection is not null, so we'll happily ignore it + connect( dynamic_cast< QObject* >( cmd ), SIGNAL( albums( QList ) ), + this, SLOT( onAlbumsFound( QList ) ) ); + + cmd->enqueue(); } } diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index d61dfe23b..c309b87ed 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -304,6 +304,7 @@ list(APPEND libSources resolvers/Resolver.cpp resolvers/ScriptCollection.cpp resolvers/ScriptCommand_AllArtists.cpp + resolvers/ScriptCommand_AllAlbums.cpp resolvers/ScriptCommandQueue.cpp sip/SipPlugin.cpp diff --git a/src/libtomahawk/collection/AlbumsRequest.h b/src/libtomahawk/collection/AlbumsRequest.h new file mode 100644 index 000000000..af3771135 --- /dev/null +++ b/src/libtomahawk/collection/AlbumsRequest.h @@ -0,0 +1,43 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 ALBUMSREQUEST_H +#define ALBUMSREQUEST_H + +#include "Typedefs.h" +#include "DllMacro.h" + +#include + +namespace Tomahawk +{ + +class DLLEXPORT AlbumsRequest +{ +public: + virtual ~AlbumsRequest() {} + + virtual void enqueue() = 0; + +protected: //signals + virtual void albums( const QList< Tomahawk::album_ptr >& ) = 0; +}; + +} //ns + +#endif // ALBUMSREQUEST_H diff --git a/src/libtomahawk/collection/Collection.h b/src/libtomahawk/collection/Collection.h index 079bf1acd..d90e6c639 100644 --- a/src/libtomahawk/collection/Collection.h +++ b/src/libtomahawk/collection/Collection.h @@ -35,6 +35,7 @@ #include "Playlist.h" #include "playlist/dynamic/DynamicPlaylist.h" #include "collection/ArtistsRequest.h" +#include "collection/AlbumsRequest.h" #include "DllMacro.h" @@ -82,7 +83,7 @@ public: // Async requests. Emit artists/albums/tracksResult in subclasses when finished. virtual Tomahawk::ArtistsRequest* requestArtists() = 0; - virtual void albums( const Tomahawk::artist_ptr& artist ) = 0; + virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ) = 0; virtual void tracks( const Tomahawk::album_ptr& album ) = 0; const source_ptr& source() const; diff --git a/src/libtomahawk/database/DatabaseCollection.cpp b/src/libtomahawk/database/DatabaseCollection.cpp index ce443e928..fb787d033 100644 --- a/src/libtomahawk/database/DatabaseCollection.cpp +++ b/src/libtomahawk/database/DatabaseCollection.cpp @@ -147,30 +147,17 @@ DatabaseCollection::requestArtists() } -void -DatabaseCollection::albums( const Tomahawk::artist_ptr& artist ) +Tomahawk::AlbumsRequest* +DatabaseCollection::requestAlbums( const Tomahawk::artist_ptr& artist ) { //FIXME: assuming there's only one dbcollection per source, and that this is the one Tomahawk::collection_ptr thisCollection = source()->dbCollection(); if ( thisCollection->name() != this->name() ) - return; + return 0; - DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( thisCollection, artist ); + Tomahawk::AlbumsRequest* cmd = new DatabaseCommand_AllAlbums( thisCollection, artist ); - // The QVariant might carry a bool that says whether the dbcmd was executed for a null collection - // but here we know for a fact that the collection is not null, so we'll happily ignore it - connect( cmd, SIGNAL( albums( QList, QVariant ) ), - SLOT( onAlbumsFetched( QList, QVariant ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); -} - - -void -DatabaseCollection::onAlbumsFetched( const QList< album_ptr >& albums, const QVariant& data ) -{ - Q_UNUSED( data ); - emit albumsResult( albums ); + return cmd; } diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index 2fa3a6b49..efa60c6a7 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -51,7 +51,7 @@ public: virtual QList< Tomahawk::dynplaylist_ptr > stations(); virtual Tomahawk::ArtistsRequest* requestArtists(); - virtual void albums( const Tomahawk::artist_ptr& artist ); + virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ); virtual void tracks( const Tomahawk::album_ptr& album ); public slots: @@ -59,7 +59,6 @@ public slots: virtual void removeTracks( const QDir& dir ); private slots: - void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums, const QVariant& data ); void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); void stationCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp b/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp index cfc7c9165..7077383ff 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp @@ -34,7 +34,8 @@ DatabaseCommand_AllAlbums::DatabaseCommand_AllAlbums( const Tomahawk::collection , m_amount( 0 ) , m_sortOrder( DatabaseCommand_AllAlbums::None ) , m_sortDescending( false ) -{} +{ +} DatabaseCommand_AllAlbums::~DatabaseCommand_AllAlbums() @@ -114,6 +115,7 @@ DatabaseCommand_AllAlbums::execForArtist( DatabaseImpl* dbi ) } emit albums( al, data() ); + emit albums( al ); emit done(); } @@ -162,6 +164,7 @@ DatabaseCommand_AllAlbums::execForCollection( DatabaseImpl* dbi ) } emit albums( al, data() ); + emit albums( al ); emit done(); } diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h index e0bb03b92..b015b207b 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,12 +26,15 @@ #include "Album.h" #include "Artist.h" #include "collection/Collection.h" +#include "collection/AlbumsRequest.h" #include "Typedefs.h" #include "DatabaseCommand.h" +#include "Database.h" #include "DllMacro.h" class DLLEXPORT DatabaseCommand_AllAlbums : public DatabaseCommand + , public Tomahawk::AlbumsRequest { Q_OBJECT public: @@ -39,7 +43,9 @@ public: ModificationTime = 1 }; - explicit DatabaseCommand_AllAlbums( const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr(), const Tomahawk::artist_ptr& artist = Tomahawk::artist_ptr(), QObject* parent = 0 ); + explicit DatabaseCommand_AllAlbums( const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr(), + const Tomahawk::artist_ptr& artist = Tomahawk::artist_ptr(), + QObject* parent = 0 ); virtual ~DatabaseCommand_AllAlbums(); virtual void exec( DatabaseImpl* ); @@ -47,6 +53,8 @@ public: virtual bool doesMutates() const { return false; } virtual QString commandname() const { return "allalbums"; } + virtual void enqueue() { Database::instance()->enqueue( QSharedPointer( this ) ); } + Tomahawk::collection_ptr collection() const { return m_collection; } void execForCollection( DatabaseImpl* ); @@ -60,6 +68,7 @@ public: signals: void albums( const QList&, const QVariant& data ); + void albums( const QList& ); void done(); private: diff --git a/src/libtomahawk/database/DatabaseCommand_AllArtists.h b/src/libtomahawk/database/DatabaseCommand_AllArtists.h index ac778ac4c..d9d45f4a5 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllArtists.h +++ b/src/libtomahawk/database/DatabaseCommand_AllArtists.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libtomahawk/resolvers/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h index 93468ab67..73ca4c84f 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.h +++ b/src/libtomahawk/resolvers/ExternalResolver.h @@ -27,6 +27,7 @@ #include "Resolver.h" #include "ScriptCommandQueue.h" #include "ScriptCommand_AllArtists.h" +#include "ScriptCommand_AllAlbums.h" #include @@ -49,6 +50,7 @@ Q_OBJECT friend class ::ScriptCommandQueue; friend class ::ScriptCommand_AllArtists; + friend class ::ScriptCommand_AllAlbums; public: enum ErrorState { diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 6454594c8..f62e440f5 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -187,8 +187,8 @@ QtScriptResolverHelper::addAlbumResults( const QVariantMap& results ) tDebug() << Q_FUNC_INFO << "about to push" << albums.count() << "albums"; foreach( const Tomahawk::album_ptr& album, albums) tDebug() << album->name(); - QMetaObject::invokeMethod( collection.data(), "onAlbumsFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::album_ptr >, albums ) ); + + emit m_resolver->albumsFound( albums ); } @@ -535,8 +535,7 @@ QtScriptResolver::albums( const Tomahawk::collection_ptr& collection, const Toma if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver !capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections { - QMetaObject::invokeMethod( collection.data(), "onAlbumsFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::album_ptr >, QList< Tomahawk::album_ptr >() ) ); + emit albumsFound( QList< Tomahawk::album_ptr >() ); return; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 635f5e58a..b200bac48 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -24,6 +24,7 @@ #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" #include "resolvers/ScriptCommand_AllArtists.h" +#include "resolvers/ScriptCommand_AllAlbums.h" #include #include @@ -122,10 +123,16 @@ ScriptCollection::requestArtists() } -void -ScriptCollection::albums( const Tomahawk::artist_ptr& artist ) +Tomahawk::AlbumsRequest* +ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist ) { - //m_resolver->albums( m_resolver->collections().value( name() ), artist ); + Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() ); + if ( thisCollection->name() != this->name() ) + return 0; + + Tomahawk::AlbumsRequest* cmd = new ScriptCommand_AllAlbums( thisCollection, artist ); + + return cmd; } @@ -136,13 +143,6 @@ ScriptCollection::tracks( const Tomahawk::album_ptr& album ) } -void -ScriptCollection::onAlbumsFetched( const QList& albums ) -{ - emit albumsResult( albums ); -} - - void ScriptCollection::onTracksFetched( const QList& tracks ) { diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 5a9272b16..66ab60f6b 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -23,6 +23,7 @@ #include "ExternalResolver.h" #include "collection/Collection.h" #include "collection/ArtistsRequest.h" +#include "collection/AlbumsRequest.h" #include "Typedefs.h" #include "DllMacro.h" @@ -50,11 +51,10 @@ public: virtual ExternalResolver* resolver() { return m_resolver; } virtual Tomahawk::ArtistsRequest* requestArtists(); - virtual void albums( const Tomahawk::artist_ptr& artist ); + virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ); virtual void tracks( const Tomahawk::album_ptr& album ); private slots: - void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums ); void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); private: diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index 6fb42ccbd..ce4662145 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -53,7 +53,7 @@ ScriptCommandQueue::nextCommand() NewClosure( m_timer, SIGNAL( timeout() ), this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ), req ); - m_timer->start( 2000 ); + m_timer->start( 5000 ); req->exec(); } @@ -66,7 +66,6 @@ ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req ) m_timer->stop(); m_queue.removeAll( req ); - req->deleteLater(); if ( m_queue.count() > 0 ) nextCommand(); @@ -80,9 +79,8 @@ ScriptCommandQueue::onTimeout( const QSharedPointer< ScriptCommand >& req ) m_timer->stop(); - m_queue.removeAll( req ); req->reportFailure(); - req->deleteLater(); + m_queue.removeAll( req ); if ( m_queue.count() > 0 ) nextCommand(); diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp new file mode 100644 index 000000000..94fa3c0f8 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp @@ -0,0 +1,86 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "ScriptCommand_AllAlbums.h" + +#include "ExternalResolver.h" +#include "ScriptCollection.h" + +#include "utils/Logger.h" + +ScriptCommand_AllAlbums::ScriptCommand_AllAlbums( const Tomahawk::collection_ptr& collection, + const Tomahawk::artist_ptr& artist, + QObject* parent ) + : ScriptCommand( parent ) + , m_collection( collection ) + , m_artist( artist ) +{ +} + + +void +ScriptCommand_AllAlbums::enqueue() +{ + Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); + if ( collection == 0 ) + { + emit albums( QList< Tomahawk::album_ptr >() ); + return; + } + + collection->resolver()->enqueue( QSharedPointer< ScriptCommand >( this ) ); +} + + +void +ScriptCommand_AllAlbums::exec() +{ + Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); + if ( collection == 0 ) + { + reportFailure(); + return; + } + + if ( m_artist.isNull() ) + { + reportFailure(); + return; + } + + connect( collection->resolver(), SIGNAL( albumsFound( QList< Tomahawk::album_ptr > ) ), + this, SLOT( onResolverDone( QList< Tomahawk::album_ptr > ) ) ); + + collection->resolver()->albums( m_collection, m_artist ); +} + + +void +ScriptCommand_AllAlbums::reportFailure() +{ + emit albums( QList< Tomahawk::album_ptr >() ); + emit done(); +} + + +void +ScriptCommand_AllAlbums::onResolverDone( const QList< Tomahawk::album_ptr >& a ) +{ + emit albums( a ); + emit done(); +} diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h new file mode 100644 index 000000000..5742a2c1e --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 SCRIPTCOMMAND_ALLALBUMS_H +#define SCRIPTCOMMAND_ALLALBUMS_H + +#include "collection/AlbumsRequest.h" +#include "collection/Collection.h" +#include "resolvers/ScriptCommand.h" + +class ScriptCommand_AllAlbums : public ScriptCommand + , public Tomahawk::AlbumsRequest +{ + Q_OBJECT +public: + explicit ScriptCommand_AllAlbums( const Tomahawk::collection_ptr& collection, + const Tomahawk::artist_ptr& artist, + QObject* parent = 0 ); + virtual ~ScriptCommand_AllAlbums() {} + + virtual void enqueue(); + +signals: + void albums( const QList< Tomahawk::album_ptr >& ); + void done(); + +protected: + virtual void exec(); + virtual void reportFailure(); + +private slots: + void onResolverDone( const QList< Tomahawk::album_ptr >& ); + +private: + Tomahawk::collection_ptr m_collection; + Tomahawk::artist_ptr m_artist; +}; + +#endif // SCRIPTCOMMAND_ALLALBUMS_H diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp index ec90c0a09..6c9553040 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp @@ -35,7 +35,7 @@ ScriptCommand_AllArtists::enqueue() Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); if ( collection == 0 ) { - emit artists( QList< Tomahawk::artist_ptr >() ); + reportFailure(); return; } diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h index d5adcb755..3193a72a2 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h @@ -23,8 +23,6 @@ #include "collection/Collection.h" #include "resolvers/ScriptCommand.h" -#include - class ScriptCommand_AllArtists : public ScriptCommand , public Tomahawk::ArtistsRequest { From 6c5ad05d2747c12c3e0c90a20ffba1b3ddf6b928 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 3 Feb 2013 23:17:08 +0100 Subject: [PATCH 30/44] Added ScriptCommand_AllTracks. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 24 +++--- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/collection/Collection.h | 6 +- src/libtomahawk/collection/TracksRequest.h | 43 ++++++++++ .../database/DatabaseCollection.cpp | 18 +--- src/libtomahawk/database/DatabaseCollection.h | 4 +- .../database/DatabaseCommand_AllTracks.cpp | 1 + .../database/DatabaseCommand_AllTracks.h | 6 ++ src/libtomahawk/resolvers/ExternalResolver.h | 2 + .../resolvers/QtScriptResolver.cpp | 6 +- .../resolvers/ScriptCollection.cpp | 16 ++-- src/libtomahawk/resolvers/ScriptCollection.h | 5 +- .../resolvers/ScriptCommand_AllTracks.cpp | 84 +++++++++++++++++++ .../resolvers/ScriptCommand_AllTracks.h | 54 ++++++++++++ 14 files changed, 222 insertions(+), 48 deletions(-) create mode 100644 src/libtomahawk/collection/TracksRequest.h create mode 100644 src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp create mode 100644 src/libtomahawk/resolvers/ScriptCommand_AllTracks.h diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index 2207e94f4..1d5d84fd7 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -21,6 +21,7 @@ #include "AlbumPlaylistInterface.h" #include "Artist.h" +#include "collection/TracksRequest.h" #include "database/Database.h" #include "database/DatabaseImpl.h" #include "database/DatabaseCommand_AllTracks.h" @@ -144,11 +145,13 @@ AlbumPlaylistInterface::tracks() const } else { - connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), - SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection ); - Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() ); - m_collection->tracks( ap ); + + Tomahawk::TracksRequest* cmd = m_collection->requestTracks( ap ); + connect( dynamic_cast< QObject* >( cmd ), SIGNAL( tracks( QList ) ), + this, SLOT( onTracksLoaded( QList ) ) ); + + cmd->enqueue(); } } } @@ -239,11 +242,13 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) } else { - connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), - SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection ); - Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() ); - m_collection->tracks( ap ); + + Tomahawk::TracksRequest* cmd = m_collection->requestTracks( ap ); + connect( dynamic_cast< QObject* >( cmd ), SIGNAL( tracks( QList ) ), + this, SLOT( onTracksLoaded( QList ) ) ); + + cmd->enqueue(); } } else @@ -257,9 +262,6 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) void AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks ) { - disconnect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), - this, SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ) ); - if ( m_collection.isNull() ) { m_databaseLoaded = true; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index c309b87ed..0140e9637 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -305,6 +305,7 @@ list(APPEND libSources resolvers/ScriptCollection.cpp resolvers/ScriptCommand_AllArtists.cpp resolvers/ScriptCommand_AllAlbums.cpp + resolvers/ScriptCommand_AllTracks.cpp resolvers/ScriptCommandQueue.cpp sip/SipPlugin.cpp diff --git a/src/libtomahawk/collection/Collection.h b/src/libtomahawk/collection/Collection.h index d90e6c639..2bc58bd94 100644 --- a/src/libtomahawk/collection/Collection.h +++ b/src/libtomahawk/collection/Collection.h @@ -36,6 +36,7 @@ #include "playlist/dynamic/DynamicPlaylist.h" #include "collection/ArtistsRequest.h" #include "collection/AlbumsRequest.h" +#include "collection/TracksRequest.h" #include "DllMacro.h" @@ -84,15 +85,12 @@ public: // Async requests. Emit artists/albums/tracksResult in subclasses when finished. virtual Tomahawk::ArtistsRequest* requestArtists() = 0; virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ) = 0; - virtual void tracks( const Tomahawk::album_ptr& album ) = 0; + virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album ) = 0; const source_ptr& source() const; unsigned int lastmodified() const { return m_lastmodified; } signals: - void albumsResult( const QList< Tomahawk::album_ptr >& albums ); - void tracksResult( const QList< Tomahawk::query_ptr >& queries ); - void tracksAdded( const QList& fileids ); void tracksRemoved( const QList& fileids ); diff --git a/src/libtomahawk/collection/TracksRequest.h b/src/libtomahawk/collection/TracksRequest.h new file mode 100644 index 000000000..34de43878 --- /dev/null +++ b/src/libtomahawk/collection/TracksRequest.h @@ -0,0 +1,43 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 TRACKSREQUEST_H +#define TRACKSREQUEST_H + +#include "Typedefs.h" +#include "DllMacro.h" + +#include + +namespace Tomahawk +{ + +class DLLEXPORT TracksRequest +{ +public: + virtual ~TracksRequest() {} + + virtual void enqueue() = 0; + +protected: //signals + virtual void tracks( const QList< Tomahawk::query_ptr >& ) = 0; +}; + +} //ns + +#endif // TRACKSREQUEST_H diff --git a/src/libtomahawk/database/DatabaseCollection.cpp b/src/libtomahawk/database/DatabaseCollection.cpp index fb787d033..9df267b00 100644 --- a/src/libtomahawk/database/DatabaseCollection.cpp +++ b/src/libtomahawk/database/DatabaseCollection.cpp @@ -161,29 +161,19 @@ DatabaseCollection::requestAlbums( const Tomahawk::artist_ptr& artist ) } -void -DatabaseCollection::tracks( const Tomahawk::album_ptr& album ) +Tomahawk::TracksRequest* +DatabaseCollection::requestTracks( const Tomahawk::album_ptr& album ) { //FIXME: assuming there's only one dbcollection per source, and that this is the one Tomahawk::collection_ptr thisCollection = source()->dbCollection(); if ( thisCollection->name() != this->name() ) - return; + return 0; DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( thisCollection ); cmd->setAlbum( album->weakRef() ); cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition ); - connect( cmd, SIGNAL( tracks( QList, QVariant ) ), - SLOT( onTracksFetched( QList ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); -} - - -void -DatabaseCollection::onTracksFetched( const QList< query_ptr >& tracks ) -{ - emit tracksResult( tracks ); + return cmd; } diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index efa60c6a7..8ba8865b0 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -52,15 +52,13 @@ public: virtual Tomahawk::ArtistsRequest* requestArtists(); virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ); - virtual void tracks( const Tomahawk::album_ptr& album ); + virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album ); public slots: virtual void addTracks( const QList& newitems ); virtual void removeTracks( const QDir& dir ); private slots: - void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); - void stationCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); void autoPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data ); }; diff --git a/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp b/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp index 9e90d91e3..cf47c7b36 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp @@ -164,5 +164,6 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) } emit tracks( ql, data() ); + emit tracks( ql ); emit done( m_collection ); } diff --git a/src/libtomahawk/database/DatabaseCommand_AllTracks.h b/src/libtomahawk/database/DatabaseCommand_AllTracks.h index 64247eae1..92d43a4ed 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllTracks.h +++ b/src/libtomahawk/database/DatabaseCommand_AllTracks.h @@ -23,7 +23,9 @@ #include #include "DatabaseCommand.h" +#include "Database.h" #include "collection/Collection.h" +#include "collection/TracksRequest.h" #include "Typedefs.h" #include "Query.h" #include "Artist.h" @@ -32,6 +34,7 @@ #include "DllMacro.h" class DLLEXPORT DatabaseCommand_AllTracks : public DatabaseCommand + , public Tomahawk::TracksRequest { Q_OBJECT public: @@ -57,6 +60,8 @@ public: virtual bool doesMutates() const { return false; } virtual QString commandname() const { return "alltracks"; } + virtual void enqueue() { Database::instance()->enqueue( QSharedPointer( this ) ); } + void setArtist( const Tomahawk::artist_ptr& artist ) { m_artist = artist; } void setAlbum( const Tomahawk::album_ptr& album ) { m_album = album; } @@ -66,6 +71,7 @@ public: signals: void tracks( const QList&, const QVariant& data ); + void tracks( const QList& ); void done( const Tomahawk::collection_ptr& ); private: diff --git a/src/libtomahawk/resolvers/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h index 73ca4c84f..bfce61bc3 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.h +++ b/src/libtomahawk/resolvers/ExternalResolver.h @@ -28,6 +28,7 @@ #include "ScriptCommandQueue.h" #include "ScriptCommand_AllArtists.h" #include "ScriptCommand_AllAlbums.h" +#include "ScriptCommand_AllTracks.h" #include @@ -51,6 +52,7 @@ Q_OBJECT friend class ::ScriptCommandQueue; friend class ::ScriptCommand_AllArtists; friend class ::ScriptCommand_AllAlbums; + friend class ::ScriptCommand_AllTracks; public: enum ErrorState { diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index f62e440f5..61d77278a 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -230,8 +230,7 @@ QtScriptResolverHelper::addAlbumTrackResults( const QVariantMap& results ) tDebug() << Q_FUNC_INFO << "about to push" << tracks.count() << "tracks"; - QMetaObject::invokeMethod( collection.data(), "onTracksFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::query_ptr >, queries ) ); + emit m_resolver->tracksFound( queries ); } @@ -570,8 +569,7 @@ QtScriptResolver::tracks( const Tomahawk::collection_ptr& collection, const Toma if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver !capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections { - QMetaObject::invokeMethod( collection.data(), "onTracksFetched", Qt::QueuedConnection, - Q_ARG( QList< Tomahawk::query_ptr >, QList< Tomahawk::query_ptr >() ) ); + emit tracksFound( QList< Tomahawk::query_ptr >() ); return; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index b200bac48..788fd15f2 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -25,6 +25,7 @@ #include "utils/Logger.h" #include "resolvers/ScriptCommand_AllArtists.h" #include "resolvers/ScriptCommand_AllAlbums.h" +#include "resolvers/ScriptCommand_AllTracks.h" #include #include @@ -136,15 +137,14 @@ ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist ) } -void -ScriptCollection::tracks( const Tomahawk::album_ptr& album ) +Tomahawk::TracksRequest* +ScriptCollection::requestTracks( const Tomahawk::album_ptr& album ) { - //m_resolver->tracks( m_resolver->collections().value( name() ), album ); -} + Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() ); + if ( thisCollection->name() != this->name() ) + return 0; + Tomahawk::TracksRequest* cmd = new ScriptCommand_AllTracks( thisCollection, album ); -void -ScriptCollection::onTracksFetched( const QList& tracks ) -{ - emit tracksResult( tracks ); + return cmd; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 66ab60f6b..d53a59e7c 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -52,10 +52,7 @@ public: virtual Tomahawk::ArtistsRequest* requestArtists(); virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ); - virtual void tracks( const Tomahawk::album_ptr& album ); - -private slots: - void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks ); + virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album ); private: ExternalResolver* m_resolver; diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp new file mode 100644 index 000000000..9a4ee43fb --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp @@ -0,0 +1,84 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "ScriptCommand_AllTracks.h" + +#include "ExternalResolver.h" +#include "ScriptCollection.h" + +ScriptCommand_AllTracks::ScriptCommand_AllTracks( const Tomahawk::collection_ptr& collection, + const Tomahawk::album_ptr& album, + QObject* parent ) + : ScriptCommand( parent ) + , m_collection( collection ) + , m_album( album ) +{ +} + + +void +ScriptCommand_AllTracks::enqueue() +{ + Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); + if ( collection == 0 ) + { + emit tracks( QList< Tomahawk::query_ptr >() ); + return; + } + + collection->resolver()->enqueue( QSharedPointer< ScriptCommand >( this ) ); +} + + +void +ScriptCommand_AllTracks::exec() +{ + Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() ); + if ( collection == 0 ) + { + reportFailure(); + return; + } + + if ( m_album.isNull() ) + { + reportFailure(); + return; + } + + connect( collection->resolver(), SIGNAL( tracksFound( QList< Tomahawk::query_ptr > ) ), + this, SLOT( onResolverDone( QList< Tomahawk::query_ptr > ) ) ); + + collection->resolver()->tracks( m_collection, m_album ); +} + + +void +ScriptCommand_AllTracks::reportFailure() +{ + emit tracks( QList< Tomahawk::query_ptr >() ); + emit done(); +} + + +void +ScriptCommand_AllTracks::onResolverDone( const QList< Tomahawk::query_ptr >& q ) +{ + emit tracks( q ); + emit done(); +} diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h new file mode 100644 index 000000000..f017b2c8e --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 SCRIPTCOMMAND_ALLTRACKS_H +#define SCRIPTCOMMAND_ALLTRACKS_H + +#include "collection/TracksRequest.h" +#include "collection/Collection.h" +#include "resolvers/ScriptCommand.h" + +class ScriptCommand_AllTracks : public ScriptCommand + , public Tomahawk::TracksRequest +{ + Q_OBJECT +public: + explicit ScriptCommand_AllTracks( const Tomahawk::collection_ptr& collection, + const Tomahawk::album_ptr& album, + QObject *parent = 0 ); + virtual ~ScriptCommand_AllTracks() {} + + virtual void enqueue(); + +signals: + void tracks( const QList< Tomahawk::query_ptr >& ); + void done(); + +protected: + virtual void exec(); + virtual void reportFailure(); + +private slots: + void onResolverDone( const QList< Tomahawk::query_ptr >& ); + +private: + Tomahawk::collection_ptr m_collection; + Tomahawk::album_ptr m_album; +}; + +#endif // SCRIPTCOMMAND_ALLTRACKS_H From 05c04d046f70fa610b3ff89cde7f9ac4b7f252e2 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Feb 2013 14:21:37 +0100 Subject: [PATCH 31/44] Do not report the same tracks multiple times. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 7 +++++-- src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index 1d5d84fd7..8597dadbf 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -149,7 +149,7 @@ AlbumPlaylistInterface::tracks() const Tomahawk::TracksRequest* cmd = m_collection->requestTracks( ap ); connect( dynamic_cast< QObject* >( cmd ), SIGNAL( tracks( QList ) ), - this, SLOT( onTracksLoaded( QList ) ) ); + this, SLOT( onTracksLoaded( QList ) ), Qt::UniqueConnection ); cmd->enqueue(); } @@ -246,7 +246,7 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) Tomahawk::TracksRequest* cmd = m_collection->requestTracks( ap ); connect( dynamic_cast< QObject* >( cmd ), SIGNAL( tracks( QList ) ), - this, SLOT( onTracksLoaded( QList ) ) ); + this, SLOT( onTracksLoaded( QList ) ), Qt::UniqueConnection ); cmd->enqueue(); } @@ -262,6 +262,9 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) void AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks ) { +// disconnect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), +// this, SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ) ); + if ( m_collection.isNull() ) { m_databaseLoaded = true; diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp index 9a4ee43fb..480fa1065 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp @@ -73,6 +73,8 @@ ScriptCommand_AllTracks::reportFailure() { emit tracks( QList< Tomahawk::query_ptr >() ); emit done(); + disconnect(); + sender()->disconnect( this ); } @@ -81,4 +83,7 @@ ScriptCommand_AllTracks::onResolverDone( const QList< Tomahawk::query_ptr >& q ) { emit tracks( q ); emit done(); + disconnect(); + sender()->disconnect( this ); + //FIXME: find a way to delete this object when its job is done } From 7ad402bb754d68efeaf57861f45a65866a2dcac8 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Feb 2013 16:34:09 +0100 Subject: [PATCH 32/44] Fix typo. --- src/libtomahawk/utils/Closure.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/utils/Closure.h b/src/libtomahawk/utils/Closure.h index de47502bc..7e1cdf53b 100644 --- a/src/libtomahawk/utils/Closure.h +++ b/src/libtomahawk/utils/Closure.h @@ -74,7 +74,7 @@ class DLLEXPORT Closure : public QObject, boost::noncopyable { * If you don't this Closure to act on a signal, but just act like * a closure in that it saves some args and delivers them on demand later * - * Only call this is you passed a null QObject* as a sender! Otherwise you + * Only call this if you passed a null QObject* as a sender! Otherwise you * might delete your object twice :) */ void forceInvoke(); From c9e773071684f90bd01a02b48eed978c539537c2 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Feb 2013 16:51:30 +0100 Subject: [PATCH 33/44] Make sure we eliminate all references to finished ScriptCommands. --- .../resolvers/ScriptCommandQueue.cpp | 31 ++++++++++++------- .../resolvers/ScriptCommandQueue.h | 4 +-- .../resolvers/ScriptCommand_AllTracks.cpp | 4 --- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index ce4662145..06b9e19f8 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -18,8 +18,6 @@ #include "ScriptCommandQueue.h" -#include "utils/Closure.h" - #include ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) @@ -47,11 +45,11 @@ ScriptCommandQueue::nextCommand() QSharedPointer< ScriptCommand > req = m_queue.first(); - NewClosure( req.data(), SIGNAL( done() ), - this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req ); + connect( req.data(), SIGNAL( done() ), + this, SLOT( onCommandDone() ) ); - NewClosure( m_timer, SIGNAL( timeout() ), - this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ), req ); + connect( m_timer, SIGNAL( timeout() ), + this, SLOT( onTimeout() ) ); m_timer->start( 5000 ); @@ -60,28 +58,39 @@ ScriptCommandQueue::nextCommand() void -ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req ) +ScriptCommandQueue::onCommandDone() { - disconnect( this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ) ); m_timer->stop(); + const QSharedPointer< ScriptCommand > req = m_queue.first(); + m_queue.removeAll( req ); + disconnect( req.data(), SIGNAL( done() ), + this, SLOT( onCommandDone() ) ); + disconnect( m_timer, SIGNAL( timeout() ), + this, SLOT( onTimeout() ) ); + if ( m_queue.count() > 0 ) nextCommand(); } void -ScriptCommandQueue::onTimeout( const QSharedPointer< ScriptCommand >& req ) +ScriptCommandQueue::onTimeout() { - disconnect( this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ) ); - m_timer->stop(); + const QSharedPointer< ScriptCommand > req = m_queue.first(); + req->reportFailure(); m_queue.removeAll( req ); + disconnect( req.data(), SIGNAL( done() ), + this, SLOT( onCommandDone() ) ); + disconnect( m_timer, SIGNAL( timeout() ), + this, SLOT( onTimeout() ) ); + if ( m_queue.count() > 0 ) nextCommand(); } diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.h b/src/libtomahawk/resolvers/ScriptCommandQueue.h index c26aabc95..a233ccf44 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.h +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.h @@ -37,8 +37,8 @@ public: private slots: void nextCommand(); - void onCommandDone( const QSharedPointer< ScriptCommand >& req ); - void onTimeout( const QSharedPointer< ScriptCommand >& req ); + void onCommandDone(); + void onTimeout(); private: QQueue< QSharedPointer< ScriptCommand > > m_queue; diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp index 480fa1065..c218fdc6b 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp @@ -73,8 +73,6 @@ ScriptCommand_AllTracks::reportFailure() { emit tracks( QList< Tomahawk::query_ptr >() ); emit done(); - disconnect(); - sender()->disconnect( this ); } @@ -83,7 +81,5 @@ ScriptCommand_AllTracks::onResolverDone( const QList< Tomahawk::query_ptr >& q ) { emit tracks( q ); emit done(); - disconnect(); - sender()->disconnect( this ); //FIXME: find a way to delete this object when its job is done } From 4aa8436b76145c301ee7403a5602c18c1becd4b0 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Feb 2013 16:59:01 +0100 Subject: [PATCH 34/44] Obsolete comment is obsolete. --- src/libtomahawk/resolvers/ScriptCommandQueue.cpp | 1 - src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index 06b9e19f8..06e4b8d0a 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -47,7 +47,6 @@ ScriptCommandQueue::nextCommand() connect( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone() ) ); - connect( m_timer, SIGNAL( timeout() ), this, SLOT( onTimeout() ) ); diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp index c218fdc6b..9a4ee43fb 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp @@ -81,5 +81,4 @@ ScriptCommand_AllTracks::onResolverDone( const QList< Tomahawk::query_ptr >& q ) { emit tracks( q ); emit done(); - //FIXME: find a way to delete this object when its job is done } From 90774b48f413bbe224b0f7e7440bc00e3145b284 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Feb 2013 17:48:34 +0100 Subject: [PATCH 35/44] Make thread safe (I think). --- src/libtomahawk/resolvers/ScriptCommandQueue.cpp | 11 +++++++++-- src/libtomahawk/resolvers/ScriptCommandQueue.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index 06e4b8d0a..7100c8dd5 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -19,6 +19,7 @@ #include "ScriptCommandQueue.h" #include +#include ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) : QObject( parent ) @@ -31,7 +32,10 @@ ScriptCommandQueue::ScriptCommandQueue( QObject* parent ) void ScriptCommandQueue::enqueue( const QSharedPointer< ScriptCommand >& req ) { + QMutexLocker locker( &m_mutex ); m_queue.append( req ); + locker.unlock(); + if ( m_queue.count() == 1 ) nextCommand(); } @@ -61,9 +65,10 @@ ScriptCommandQueue::onCommandDone() { m_timer->stop(); + QMutexLocker locker( &m_mutex ); const QSharedPointer< ScriptCommand > req = m_queue.first(); - m_queue.removeAll( req ); + locker.unlock(); disconnect( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone() ) ); @@ -80,10 +85,12 @@ ScriptCommandQueue::onTimeout() { m_timer->stop(); + QMutexLocker locker( &m_mutex ); const QSharedPointer< ScriptCommand > req = m_queue.first(); + m_queue.removeAll( req ); + locker.unlock(); req->reportFailure(); - m_queue.removeAll( req ); disconnect( req.data(), SIGNAL( done() ), this, SLOT( onCommandDone() ) ); diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.h b/src/libtomahawk/resolvers/ScriptCommandQueue.h index a233ccf44..aa137ab82 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.h +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.h @@ -25,6 +25,7 @@ #include #include #include +#include class ScriptCommandQueue : public QObject { @@ -43,6 +44,7 @@ private slots: private: QQueue< QSharedPointer< ScriptCommand > > m_queue; QTimer* m_timer; + QMutex m_mutex; }; Q_DECLARE_METATYPE( QSharedPointer< ScriptCommand > ) From ec4fe9babe3cd21408a5455383c4dd7339965239 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 4 Feb 2013 22:59:25 +0100 Subject: [PATCH 36/44] Don't fail on timeout. --- src/libtomahawk/resolvers/ScriptCommandQueue.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index 7100c8dd5..d503b2755 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -63,6 +63,9 @@ ScriptCommandQueue::nextCommand() void ScriptCommandQueue::onCommandDone() { + if ( m_queue.isEmpty() || !m_timer->isActive() ) //the timeout already happened or some other weird thing + return; //nothing to do here + m_timer->stop(); QMutexLocker locker( &m_mutex ); From cc577f9e4b07ea4c58756fb236adb0b3b4bad2dd Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 5 Feb 2013 18:02:02 +0100 Subject: [PATCH 37/44] Type enum in Collection.h to make domme happy :) --- src/libtomahawk/Source.cpp | 2 +- src/libtomahawk/collection/Collection.h | 9 ++++++++- src/libtomahawk/database/DatabaseCollection.h | 2 +- src/libtomahawk/resolvers/ScriptCollection.h | 2 +- src/sourcetree/items/SourceItem.cpp | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/Source.cpp b/src/libtomahawk/Source.cpp index 4be7dbd6f..c3336723b 100644 --- a/src/libtomahawk/Source.cpp +++ b/src/libtomahawk/Source.cpp @@ -107,7 +107,7 @@ Source::dbCollection() const if ( m_collections.length() ) { foreach ( const collection_ptr& collection, m_collections ) - if ( collection->type() == "databasecollection" ) + if ( collection->backendType() == Collection::DatabaseCollectionType ) return collection; // We assume only one is a db collection. Now get off my lawn. } diff --git a/src/libtomahawk/collection/Collection.h b/src/libtomahawk/collection/Collection.h index 2bc58bd94..dc5cae784 100644 --- a/src/libtomahawk/collection/Collection.h +++ b/src/libtomahawk/collection/Collection.h @@ -53,10 +53,17 @@ public: Collection( const source_ptr& source, const QString& name, QObject* parent = 0 ); virtual ~Collection(); + enum BackendType + { + NullCollectionType = 0, + DatabaseCollectionType, //talks to a database, incl. LocalCollection + ScriptCollectionType //performs operations through a resolver + }; + virtual QString name() const; virtual QString prettyName() const; virtual QString itemName() const; - virtual QString type() const { return QString(); } + virtual BackendType backendType() const { return NullCollectionType; } virtual QIcon icon() const; virtual QPixmap bigIcon() const; //for the ViewPage header virtual QString emptyText() const; diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index 8ba8865b0..a292ba475 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -40,7 +40,7 @@ public: qDebug() << Q_FUNC_INFO; } - virtual QString type() const { return "databasecollection"; } + virtual BackendType backendType() const { return DatabaseCollectionType; } virtual void loadPlaylists(); virtual void loadAutoPlaylists(); diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index d53a59e7c..556439db6 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -44,7 +44,7 @@ public: virtual QString prettyName() const; virtual QString itemName() const; - virtual QString type() const { return "scriptcollection"; } + virtual BackendType backendType() const { return ScriptCollectionType; } virtual QIcon icon() const; virtual QPixmap bigIcon() const; diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 16f544f74..59c99c52d 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -376,7 +376,7 @@ SourceItem::performAddCollectionItem( const collection_ptr& collection ) boost::bind( &SourceItem::collectionClicked, this, collection ), boost::bind( &SourceItem::getCollectionPage, this, collection ) ); - if ( collection->type() == "databasecollection" ) + if ( collection->backendType() == Collection::DatabaseCollectionType ) item->setSortValue( -350 ); else item->setSortValue( -340 ); From 91c866c701ca27b9953efd022f04eeb378496879 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 5 Feb 2013 18:06:21 +0100 Subject: [PATCH 38/44] Remove unused code. --- src/libtomahawk/resolvers/ScriptResolver.cpp | 18 ------------------ src/libtomahawk/resolvers/ScriptResolver.h | 1 - 2 files changed, 19 deletions(-) diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 7d805a273..1df21ba09 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -417,8 +417,6 @@ ScriptResolver::doSetup( const QVariantMap& m ) m_configSent = false; m_num_restarts = 0; - loadCollections(); - if ( !m_stopped ) Tomahawk::Pipeline::instance()->addResolver( this ); @@ -446,22 +444,6 @@ ScriptResolver::setupConfWidget( const QVariantMap& m ) } -void -ScriptResolver::loadCollections() -{ - if ( m_capabilities.testFlag( Browsable ) ) - { - m_collections.clear(); - // at this point we assume that all the tracks browsable through a resolver belong to the local source - Tomahawk::collection_ptr collection( new Tomahawk::ScriptCollection( SourceList::instance()->getLocal(), this ) ); - m_collections.insert( collection->name(), collection ); - emit collectionAdded( collection ); - - //TODO: implement multiple collections from a resolver - } -} - - void ScriptResolver::startProcess() { diff --git a/src/libtomahawk/resolvers/ScriptResolver.h b/src/libtomahawk/resolvers/ScriptResolver.h index 3ce59d81b..14372a669 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.h +++ b/src/libtomahawk/resolvers/ScriptResolver.h @@ -88,7 +88,6 @@ private: void sendMsg( const QByteArray& msg ); void doSetup( const QVariantMap& m ); void setupConfWidget( const QVariantMap& m ); - void loadCollections(); void startProcess(); From 9a8f2e33069daef1db5b1eaff1a02a32ff9391ca Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 5 Feb 2013 18:32:29 +0100 Subject: [PATCH 39/44] Remove commented-out code. --- src/libtomahawk/AlbumPlaylistInterface.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libtomahawk/AlbumPlaylistInterface.cpp b/src/libtomahawk/AlbumPlaylistInterface.cpp index 8597dadbf..6459925f5 100644 --- a/src/libtomahawk/AlbumPlaylistInterface.cpp +++ b/src/libtomahawk/AlbumPlaylistInterface.cpp @@ -262,9 +262,6 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId ) void AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks ) { -// disconnect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ), -// this, SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ) ); - if ( m_collection.isNull() ) { m_databaseLoaded = true; From fffb00693a06bfcc022a31ca2c7991e73d2e2c99 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 6 Feb 2013 16:46:51 +0100 Subject: [PATCH 40/44] Allow some more time for slow slow Ampache. --- src/libtomahawk/resolvers/ScriptCommandQueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index d503b2755..2663c87e8 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -54,7 +54,7 @@ ScriptCommandQueue::nextCommand() connect( m_timer, SIGNAL( timeout() ), this, SLOT( onTimeout() ) ); - m_timer->start( 5000 ); + m_timer->start( 10000 ); req->exec(); } From 68d3dd663186cd0c637a7ce57ea28c0ded6b8861 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 6 Feb 2013 17:05:15 +0100 Subject: [PATCH 41/44] Synchronous responses are for n00bs, only allow async. --- src/libtomahawk/resolvers/QtScriptResolver.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 61d77278a..b0679be4f 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -515,8 +515,9 @@ QtScriptResolver::artists( const Tomahawk::collection_ptr& collection ) return; } - qDebug() << "Artists JavaScript Result:" << m; - m_resolverHelper->addArtistResults( m ); + QString errorMessage = tr( "Script Resolver Warning: API call %1 returned data sychronously." ).arg( eval ); + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( errorMessage ) ); + tDebug() << errorMessage << m; } @@ -549,9 +550,9 @@ QtScriptResolver::albums( const Tomahawk::collection_ptr& collection, const Toma return; } - qDebug() << "Albums JavaScript Result:" << m; - - m_resolverHelper->addAlbumResults( m ); + QString errorMessage = tr( "Script Resolver Warning: API call %1 returned data sychronously." ).arg( eval ); + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( errorMessage ) ); + tDebug() << errorMessage << m; } @@ -585,9 +586,9 @@ QtScriptResolver::tracks( const Tomahawk::collection_ptr& collection, const Toma return; } - qDebug() << "Tracks JavaScript Result:" << m; - - m_resolverHelper->addAlbumTrackResults( m ); + QString errorMessage = tr( "Script Resolver Warning: API call %1 returned data sychronously." ).arg( eval ); + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( errorMessage ) ); + tDebug() << errorMessage << m; } From 81af9b0e78ac084016e730436f328f6cf76a3d12 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 6 Feb 2013 18:10:21 +0100 Subject: [PATCH 42/44] Style fix. --- src/libtomahawk/database/DatabaseCommand_AllAlbums.h | 3 +-- src/libtomahawk/database/DatabaseCommand_AllArtists.h | 3 +-- src/libtomahawk/database/DatabaseCommand_AllTracks.h | 3 +-- src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h | 3 +-- src/libtomahawk/resolvers/ScriptCommand_AllArtists.h | 3 +-- src/libtomahawk/resolvers/ScriptCommand_AllTracks.h | 3 +-- 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h index b015b207b..a435c0683 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h @@ -33,8 +33,7 @@ #include "DllMacro.h" -class DLLEXPORT DatabaseCommand_AllAlbums : public DatabaseCommand - , public Tomahawk::AlbumsRequest +class DLLEXPORT DatabaseCommand_AllAlbums : public DatabaseCommand, public Tomahawk::AlbumsRequest { Q_OBJECT public: diff --git a/src/libtomahawk/database/DatabaseCommand_AllArtists.h b/src/libtomahawk/database/DatabaseCommand_AllArtists.h index d9d45f4a5..d8129945b 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllArtists.h +++ b/src/libtomahawk/database/DatabaseCommand_AllArtists.h @@ -32,8 +32,7 @@ #include "DllMacro.h" -class DLLEXPORT DatabaseCommand_AllArtists : public DatabaseCommand - , public Tomahawk::ArtistsRequest +class DLLEXPORT DatabaseCommand_AllArtists : public DatabaseCommand, public Tomahawk::ArtistsRequest { Q_OBJECT public: diff --git a/src/libtomahawk/database/DatabaseCommand_AllTracks.h b/src/libtomahawk/database/DatabaseCommand_AllTracks.h index 92d43a4ed..eec71fa08 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllTracks.h +++ b/src/libtomahawk/database/DatabaseCommand_AllTracks.h @@ -33,8 +33,7 @@ #include "DllMacro.h" -class DLLEXPORT DatabaseCommand_AllTracks : public DatabaseCommand - , public Tomahawk::TracksRequest +class DLLEXPORT DatabaseCommand_AllTracks : public DatabaseCommand, public Tomahawk::TracksRequest { Q_OBJECT public: diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h index 5742a2c1e..d1e144552 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h @@ -23,8 +23,7 @@ #include "collection/Collection.h" #include "resolvers/ScriptCommand.h" -class ScriptCommand_AllAlbums : public ScriptCommand - , public Tomahawk::AlbumsRequest +class ScriptCommand_AllAlbums : public ScriptCommand, public Tomahawk::AlbumsRequest { Q_OBJECT public: diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h index 3193a72a2..1bfb0c83f 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h @@ -23,8 +23,7 @@ #include "collection/Collection.h" #include "resolvers/ScriptCommand.h" -class ScriptCommand_AllArtists : public ScriptCommand - , public Tomahawk::ArtistsRequest +class ScriptCommand_AllArtists : public ScriptCommand, public Tomahawk::ArtistsRequest { Q_OBJECT public: diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h index f017b2c8e..18126cedc 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllTracks.h @@ -23,8 +23,7 @@ #include "collection/Collection.h" #include "resolvers/ScriptCommand.h" -class ScriptCommand_AllTracks : public ScriptCommand - , public Tomahawk::TracksRequest +class ScriptCommand_AllTracks : public ScriptCommand, public Tomahawk::TracksRequest { Q_OBJECT public: From a4a0cb771f39bc83e9d0d8de7702f4e57a6e6478 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 6 Feb 2013 18:27:54 +0100 Subject: [PATCH 43/44] No implementations in headers. --- src/libtomahawk/CMakeLists.txt | 3 +++ src/libtomahawk/collection/AlbumsRequest.cpp | 23 ++++++++++++++++++ src/libtomahawk/collection/AlbumsRequest.h | 2 +- src/libtomahawk/collection/ArtistsRequest.cpp | 24 +++++++++++++++++++ src/libtomahawk/collection/ArtistsRequest.h | 2 +- src/libtomahawk/collection/TracksRequest.cpp | 23 ++++++++++++++++++ src/libtomahawk/collection/TracksRequest.h | 2 +- 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/libtomahawk/collection/AlbumsRequest.cpp create mode 100644 src/libtomahawk/collection/ArtistsRequest.cpp create mode 100644 src/libtomahawk/collection/TracksRequest.cpp diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 0140e9637..18fa35ed0 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -208,6 +208,9 @@ list(APPEND libSources audio/AudioEngine.cpp collection/Collection.cpp + collection/ArtistsRequest.cpp + collection/AlbumsRequest.cpp + collection/TracksRequest.cpp database/Database.cpp database/FuzzyIndex.cpp diff --git a/src/libtomahawk/collection/AlbumsRequest.cpp b/src/libtomahawk/collection/AlbumsRequest.cpp new file mode 100644 index 000000000..8fc5d3dbd --- /dev/null +++ b/src/libtomahawk/collection/AlbumsRequest.cpp @@ -0,0 +1,23 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "AlbumsRequest.h" + +Tomahawk::AlbumsRequest::~AlbumsRequest() +{} diff --git a/src/libtomahawk/collection/AlbumsRequest.h b/src/libtomahawk/collection/AlbumsRequest.h index af3771135..0bb457867 100644 --- a/src/libtomahawk/collection/AlbumsRequest.h +++ b/src/libtomahawk/collection/AlbumsRequest.h @@ -30,7 +30,7 @@ namespace Tomahawk class DLLEXPORT AlbumsRequest { public: - virtual ~AlbumsRequest() {} + virtual ~AlbumsRequest(); virtual void enqueue() = 0; diff --git a/src/libtomahawk/collection/ArtistsRequest.cpp b/src/libtomahawk/collection/ArtistsRequest.cpp new file mode 100644 index 000000000..59d46c001 --- /dev/null +++ b/src/libtomahawk/collection/ArtistsRequest.cpp @@ -0,0 +1,24 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "ArtistsRequest.h" + +Tomahawk::ArtistsRequest::~ArtistsRequest() +{} + diff --git a/src/libtomahawk/collection/ArtistsRequest.h b/src/libtomahawk/collection/ArtistsRequest.h index db5a32975..49c2de750 100644 --- a/src/libtomahawk/collection/ArtistsRequest.h +++ b/src/libtomahawk/collection/ArtistsRequest.h @@ -30,7 +30,7 @@ namespace Tomahawk class DLLEXPORT ArtistsRequest { public: - virtual ~ArtistsRequest() {} + virtual ~ArtistsRequest(); virtual void enqueue() = 0; diff --git a/src/libtomahawk/collection/TracksRequest.cpp b/src/libtomahawk/collection/TracksRequest.cpp new file mode 100644 index 000000000..042e693d5 --- /dev/null +++ b/src/libtomahawk/collection/TracksRequest.cpp @@ -0,0 +1,23 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 "TracksRequest.h" + +Tomahawk::TracksRequest::~TracksRequest() +{} diff --git a/src/libtomahawk/collection/TracksRequest.h b/src/libtomahawk/collection/TracksRequest.h index 34de43878..cc92ad034 100644 --- a/src/libtomahawk/collection/TracksRequest.h +++ b/src/libtomahawk/collection/TracksRequest.h @@ -30,7 +30,7 @@ namespace Tomahawk class DLLEXPORT TracksRequest { public: - virtual ~TracksRequest() {} + virtual ~TracksRequest(); virtual void enqueue() = 0; From 0077ca5c8d4706e40eaa3112b3eafa257d2461d6 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 7 Feb 2013 20:35:09 +0100 Subject: [PATCH 44/44] Instead of getting statically defined capabilities at resolver startup, have resolvers report their actual capabilities as soon as they know for sure they have them. --- data/js/tomahawk.js | 4 --- .../resolvers/QtScriptResolver.cpp | 32 +++++++++++++------ src/libtomahawk/resolvers/QtScriptResolver.h | 3 ++ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index 35ce76182..3fa8d7d9b 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -134,10 +134,6 @@ var TomahawkResolver = { { return this.resolve( qid, "", "", searchString ); }, - capabilities: function() - { - return TomahawkResolverCapability.NullCapability; - }, artists: function( qid ) { return { diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index b0679be4f..50a8fc530 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -234,6 +234,21 @@ QtScriptResolverHelper::addAlbumTrackResults( const QVariantMap& results ) } +void +QtScriptResolverHelper::reportCapabilities( const QVariant& v ) +{ + bool ok = 0; + int intCap = v.toInt( &ok ); + Tomahawk::ExternalResolver::Capabilities capabilities; + if ( !ok ) + capabilities = Tomahawk::ExternalResolver::NullCapability; + else + capabilities = static_cast< Tomahawk::ExternalResolver::Capabilities >( intCap ); + + m_resolver->onCapabilitiesChanged( capabilities ); +} + + void QtScriptResolverHelper::setResolverConfig( const QVariantMap& config ) { @@ -436,13 +451,6 @@ QtScriptResolver::init() m_timeout = m.value( "timeout", 25 ).toUInt() * 1000; bool compressed = m.value( "compressed", "false" ).toString() == "true"; - bool ok = 0; - int intCap = m_engine->mainFrame()->evaluateJavaScript( "resolver.capabilities()" ).toInt( &ok ); - if ( !ok ) - m_capabilities = NullCapability; - else - m_capabilities = static_cast< Capabilities >( intCap ); - QByteArray icoData = m.value( "icon" ).toByteArray(); if( compressed ) icoData = qUncompress( QByteArray::fromBase64( icoData ) ); @@ -470,8 +478,6 @@ QtScriptResolver::init() QVariantMap config = resolverUserConfig(); fillDataInWidgets( config ); - loadCollections(); - qDebug() << "JS" << filePath() << "READY," << "name" << m_name << "weight" << m_weight << "timeout" << m_timeout << "icon received" << success; m_ready = true; @@ -884,6 +890,14 @@ QtScriptResolver::fillDataInWidgets( const QVariantMap& data ) } +void +QtScriptResolver::onCapabilitiesChanged( Tomahawk::ExternalResolver::Capabilities capabilities ) +{ + m_capabilities = capabilities; + loadCollections(); +} + + void QtScriptResolver::loadCollections() { diff --git a/src/libtomahawk/resolvers/QtScriptResolver.h b/src/libtomahawk/resolvers/QtScriptResolver.h index 659754592..9ec07c72e 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.h +++ b/src/libtomahawk/resolvers/QtScriptResolver.h @@ -76,6 +76,8 @@ public slots: void addAlbumResults( const QVariantMap& results ); void addAlbumTrackResults( const QVariantMap& results ); + void reportCapabilities( const QVariant& capabilities ); + private: QString m_scriptPath, m_urlCallback; QVariantMap m_resolverConfig; @@ -171,6 +173,7 @@ private: QVariant widgetData( QWidget* widget, const QString& property ); QVariantMap loadDataFromWidgets(); void fillDataInWidgets( const QVariantMap& data ); + void onCapabilitiesChanged( Capabilities capabilities ); void loadCollections(); // encapsulate javascript calls