File indexing completed on 2025-01-05 04:26:06

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Andrew Coder <andrew.coder@gmail.com>                             *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 
0018 #ifndef PLAYDAR_QUERYMAKER_H
0019 #define PLAYDAR_QUERYMAKER_H
0020 
0021 #include "PlaydarMeta.h"
0022 #include "PlaydarCollection.h"
0023 
0024 #include "support/Controller.h"
0025 #include "support/Query.h"
0026 #include "support/QMFunctionTypes.h"
0027 
0028 #include "core/meta/forward_declarations.h"
0029 #include "core/meta/support/MetaConstants.h"
0030 #include "core/collections/QueryMaker.h"
0031 
0032 #include <QMap>
0033 #include <QStack>
0034 
0035 namespace Collections
0036 {
0037     
0038     class PlaydarQueryMaker : public QueryMaker
0039     {
0040         Q_OBJECT
0041         
0042         public:
0043             explicit PlaydarQueryMaker( PlaydarCollection *collection );
0044             ~PlaydarQueryMaker() override;
0045 
0046             void run() override;
0047             void abortQuery() override;
0048 
0049             QueryMaker* setQueryType( QueryType type ) override;
0050             QueryMaker* addReturnValue( qint64 value ) override;
0051             QueryMaker* addReturnFunction( ReturnFunction function, qint64 value ) override;
0052             QueryMaker* orderBy( qint64 value, bool descending = false ) override;
0053 
0054             QueryMaker* addMatch( const Meta::TrackPtr &track ) override;
0055             QueryMaker* addMatch( const Meta::ArtistPtr &artist, ArtistMatchBehaviour behaviour = TrackArtists ) override;
0056             QueryMaker* addMatch( const Meta::AlbumPtr &album ) override;
0057             QueryMaker* addMatch( const Meta::ComposerPtr &composer ) override;
0058             QueryMaker* addMatch( const Meta::GenrePtr &genre ) override;
0059             QueryMaker* addMatch( const Meta::YearPtr &year ) override;
0060             QueryMaker* addMatch( const Meta::LabelPtr &label ) override;
0061 
0062             QueryMaker* addFilter( qint64 value, const QString &filter, bool matchBegin = false, bool matchEnd = false ) override;
0063             QueryMaker* excludeFilter( qint64 value, const QString &filter, bool matchBegin = false, bool matchEnd = false ) override;
0064             
0065             QueryMaker* addNumberFilter( qint64 value, qint64 filter, NumberComparison compare ) override;
0066             QueryMaker* excludeNumberFilter( qint64 value, qint64 filter, NumberComparison compare ) override;
0067             
0068             QueryMaker* limitMaxResultSize( int size ) override;
0069             
0070             QueryMaker* setAlbumQueryMode( AlbumQueryMode mode ) override;
0071             
0072             QueryMaker* setLabelQueryMode( LabelQueryMode mode ) override;
0073             
0074             QueryMaker* beginAnd() override;
0075             QueryMaker* beginOr() override;
0076             QueryMaker* endAndOr() override;
0077             QueryMaker* setAutoDelete( bool autoDelete );
0078             
0079             int validFilterMask() override;
0080 
0081         Q_SIGNALS:
0082             void newTracksReady( const Meta::TrackList& );
0083             void newArtistsReady( const Meta::ArtistList& );
0084             void newAlbumsReady( const Meta::AlbumList& );
0085             void newGenresReady( const Meta::GenreList& );
0086             void newComposersReady(const  Meta::ComposerList& );
0087             void newYearsReady( const Meta::YearList& );
0088             void newResultReady( const QStringList &);
0089             void newLabelsReady( const Meta::LabelList& );
0090 
0091             void queryDone();
0092 
0093             void playdarError( Playdar::Controller::ErrorState );
0094         
0095         private Q_SLOTS:
0096             void slotPlaydarError( Playdar::Controller::ErrorState error );
0097             void collectQuery( Playdar::Query *query );
0098             void collectResult( Meta::PlaydarTrackPtr track );
0099             void aQueryEnded( Playdar::Query *query, const Meta::PlaydarTrackList &trackList );
0100             void memoryQueryDone();
0101             
0102         private:
0103             QueryType m_queryType;
0104             bool m_autoDelete;
0105             int m_activeQueryCount;
0106             bool m_memoryQueryIsRunning;
0107             bool m_collectionUpdated;
0108             QList< CurriedQMFunction* > m_queryMakerFunctions;
0109             
0110             typedef QMap< qint64, QString > FilterMap;
0111             FilterMap m_filterMap;
0112             
0113             QPointer< PlaydarCollection > m_collection;
0114             QPointer< QueryMaker > m_memoryQueryMaker;
0115             
0116             QPointer< Playdar::Controller > m_controller;
0117             
0118             void runMemoryQueryAgain();
0119     };
0120 
0121     
0122 
0123 }
0124 
0125 #endif