1 /**************************************************************************************** 2 * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.com> * 3 * * 4 * This program is free software; you can redistribute it and/or modify it under * 5 * the terms of the GNU General Public License as published by the Free Software * 6 * Foundation; either version 2 of the License, or (at your option) any later * 7 * version. * 8 * * 9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 11 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 12 * * 13 * You should have received a copy of the GNU General Public License along with * 14 * this program. If not, see <http://www.gnu.org/licenses/>. * 15 ****************************************************************************************/ 16 17 #ifndef MEMORYQUERYMAKERINTERNAL_H 18 #define MEMORYQUERYMAKERINTERNAL_H 19 20 #include "core/collections/QueryMaker.h" 21 #include "core/meta/forward_declarations.h" 22 23 #include <QObject> 24 #include <QWeakPointer> 25 26 class CustomReturnFunction; 27 class CustomReturnValue; 28 class MemoryFilter; 29 class MemoryMatcher; 30 31 namespace Collections { 32 33 class MemoryCollection; 34 35 /** 36 * A helper class for MemoryQueryMaker 37 * This class will run in a dedicated thread. It exists so the actual MemoryQueryMaker 38 * can be safely deleted in the original thread while the query is still running. 39 * All relevant information is passed from MemoryQueryMaker to MemoryQueryMakerInternal 40 * using the provided setter methods. 41 */ 42 class MemoryQueryMakerInternal : public QObject 43 { 44 Q_OBJECT 45 public: 46 /** 47 * Creates a new MemoryQueryMakerInternal that will query collection. 48 * This class will run in a dedicated thread. It exists so the actual MemoryQueryMaker 49 * can be safely deleted in the original thread while the query is still running. 50 * @param collection the MemoryCollection instance that the query should be run on. 51 */ 52 explicit MemoryQueryMakerInternal( const QWeakPointer<Collections::MemoryCollection> &collection ); 53 ~MemoryQueryMakerInternal() override; 54 55 56 void runQuery(); 57 void handleResult(); 58 void handleResult( const Meta::TrackList &tracks ); 59 60 void setMatchers( MemoryMatcher *matchers ); 61 void setFilters( MemoryFilter *filters ); 62 void setMaxSize( int maxSize ); 63 void setReturnAsDataPtrs( bool returnAsDataPtrs ); 64 void setType( QueryMaker::QueryType ); 65 void setCustomReturnFunctions( const QList<CustomReturnFunction*> &functions ); 66 void setCustomReturnValues( const QList<CustomReturnValue*> &values ); setAlbumQueryMode(Collections::QueryMaker::AlbumQueryMode mode)67 void setAlbumQueryMode( Collections::QueryMaker::AlbumQueryMode mode ) { m_albumQueryMode = mode; } setOrderDescending(bool orderDescending)68 void setOrderDescending( bool orderDescending ) { m_orderDescending = orderDescending; } setOrderByNumberField(bool orderByNumberField)69 void setOrderByNumberField( bool orderByNumberField ) { m_orderByNumberField = orderByNumberField; } setOrderByField(qint64 orderByField)70 void setOrderByField( qint64 orderByField ) { m_orderByField = orderByField; } setCollectionId(const QString & collectionId)71 void setCollectionId( const QString &collectionId ) { m_collectionId = collectionId; } setLabelQueryMode(Collections::QueryMaker::LabelQueryMode mode)72 void setLabelQueryMode( Collections::QueryMaker::LabelQueryMode mode ) { m_labelQueryMode = mode; } 73 74 Q_SIGNALS: 75 void newTracksReady( Meta::TrackList ); 76 void newArtistsReady( Meta::ArtistList ); 77 void newAlbumsReady( Meta::AlbumList ); 78 void newGenresReady( Meta::GenreList ); 79 void newComposersReady( Meta::ComposerList ); 80 void newYearsReady( Meta::YearList ); 81 void newResultReady( QStringList ); 82 void newLabelsReady( Meta::LabelList ); 83 void newDataReady( Meta::DataList ); 84 85 private: 86 QWeakPointer<Collections::MemoryCollection> m_collection; 87 MemoryMatcher *m_matchers; 88 MemoryFilter *m_filters; 89 int m_maxSize; 90 bool m_returnAsDataPtrs; 91 Collections::QueryMaker::QueryType m_type; 92 Collections::QueryMaker::AlbumQueryMode m_albumQueryMode; 93 Collections::QueryMaker::LabelQueryMode m_labelQueryMode; 94 bool m_orderDescending; 95 bool m_orderByNumberField; 96 qint64 m_orderByField; 97 QString m_collectionId; 98 QList<CustomReturnFunction*> m_returnFunctions; 99 QList<CustomReturnValue*> m_returnValues; 100 }; 101 102 } //namespace Collections 103 104 #endif 105