File indexing completed on 2025-01-05 04:25:51
0001 /* 0002 * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #ifndef AGGREGATEQUERYMAKER_H 0020 #define AGGREGATEQUERYMAKER_H 0021 0022 #include "core/collections/QueryMaker.h" 0023 #include "core/collections/Collection.h" 0024 #include "core-impl/collections/aggregate/AggregateMeta.h" 0025 0026 #include <QList> 0027 #include <QMutex> 0028 #include <QSet> 0029 0030 #include "AmarokSharedPointer.h" 0031 0032 class CustomReturnFunction; 0033 class CustomReturnValue; 0034 0035 namespace Collections 0036 { 0037 0038 class AMAROK_EXPORT AggregateQueryMaker : public QueryMaker 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 AggregateQueryMaker( Collections::AggregateCollection *collection, const QList<QueryMaker*> &queryMakers ); 0044 ~AggregateQueryMaker() override; 0045 0046 void run() override; 0047 void abortQuery() override; 0048 0049 QueryMaker* setQueryType( QueryType type ) override; 0050 0051 QueryMaker* addReturnValue( qint64 value) override; 0052 QueryMaker* addReturnFunction( ReturnFunction function, qint64 value ) override; 0053 QueryMaker* orderBy( qint64 value, bool descending = false ) override; 0054 0055 QueryMaker* addMatch( const Meta::TrackPtr &track ) override; 0056 QueryMaker* addMatch( const Meta::ArtistPtr &artist, ArtistMatchBehaviour behaviour = TrackArtists ) override; 0057 QueryMaker* addMatch( const Meta::AlbumPtr &album ) override; 0058 QueryMaker* addMatch( const Meta::ComposerPtr &composer ) override; 0059 QueryMaker* addMatch( const Meta::GenrePtr &genre ) override; 0060 QueryMaker* addMatch( const Meta::YearPtr &year ) override; 0061 QueryMaker* addMatch( const Meta::LabelPtr &label ) override; 0062 0063 QueryMaker* addFilter( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ) override; 0064 QueryMaker* excludeFilter( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ) override; 0065 0066 QueryMaker* addNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override; 0067 QueryMaker* excludeNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override; 0068 0069 QueryMaker* limitMaxResultSize( int size ) override; 0070 0071 QueryMaker* beginAnd() override; 0072 QueryMaker* beginOr() override; 0073 QueryMaker* endAndOr() override; 0074 0075 QueryMaker* setAlbumQueryMode( AlbumQueryMode mode ) override; 0076 QueryMaker* setLabelQueryMode( LabelQueryMode mode ) override; 0077 0078 private: 0079 void handleResult(); 0080 0081 private Q_SLOTS: 0082 void slotQueryDone(); 0083 void slotNewTracksReady( const Meta::TrackList &tracks ); 0084 void slotNewArtistsReady( const Meta::ArtistList &artists ); 0085 void slotNewAlbumsReady( const Meta::AlbumList &albums ); 0086 void slotNewGenresReady( const Meta::GenreList &genres ); 0087 void slotNewComposersReady( const Meta::ComposerList &composers ); 0088 void slotNewYearsReady( const Meta::YearList &years ); 0089 void slotNewLabelsReady( const Meta::LabelList &labels ); 0090 0091 private: 0092 AggregateCollection *m_collection; 0093 QList<QueryMaker*> m_builders; 0094 int m_queryDoneCount; 0095 bool m_returnDataPointers; 0096 int m_maxResultSize; 0097 QueryType m_queryType; 0098 bool m_orderDescending; 0099 qint64 m_orderField; 0100 bool m_orderByNumberField; 0101 QMutex m_queryDoneCountMutex; 0102 // store AggregateCollection meta stuff using AmarokSharedPointer, 0103 // otherwise AggregateCollection might delete it (as soon as it gets garbage collection) 0104 QSet<AmarokSharedPointer<Meta::AggregateTrack> > m_tracks; 0105 QSet<AmarokSharedPointer<Meta::AggregateArtist> > m_artists; 0106 QSet<AmarokSharedPointer<Meta::AggregateAlbum> > m_albums; 0107 QSet<AmarokSharedPointer<Meta::AggregateGenre> > m_genres; 0108 QSet<AmarokSharedPointer<Meta::AggregateComposer> > m_composers; 0109 QSet<AmarokSharedPointer<Meta::AggreagateYear> > m_years; 0110 QSet<AmarokSharedPointer<Meta::AggregateLabel> > m_labels; 0111 QList<CustomReturnFunction*> m_returnFunctions; 0112 QList<CustomReturnValue*> m_returnValues; 0113 }; 0114 0115 } 0116 0117 #endif /* AGGREGATEQUERYMAKER_H */