File indexing completed on 2024-05-19 04:49:18

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Maximilian Kossick <maximilian.kossick@googlemail.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 #ifndef MEMORYQUERYMAKERINTERNAL_H
0018 #define MEMORYQUERYMAKERINTERNAL_H
0019 
0020 #include "core/collections/QueryMaker.h"
0021 #include "core/meta/forward_declarations.h"
0022 
0023 #include <QObject>
0024 #include <QWeakPointer>
0025 
0026 class CustomReturnFunction;
0027 class CustomReturnValue;
0028 class MemoryFilter;
0029 class MemoryMatcher;
0030 
0031 namespace Collections {
0032 
0033 class MemoryCollection;
0034 
0035 /**
0036   * A helper class for MemoryQueryMaker
0037   * This class will run in a dedicated thread. It exists so the actual MemoryQueryMaker
0038   * can be safely deleted in the original thread while the query is still running.
0039   * All relevant information is passed from MemoryQueryMaker to MemoryQueryMakerInternal
0040   * using the provided setter methods.
0041   */
0042 class MemoryQueryMakerInternal : public QObject
0043 {
0044     Q_OBJECT
0045 public:
0046     /**
0047       * Creates a new MemoryQueryMakerInternal that will query collection.
0048       * This class will run in a dedicated thread. It exists so the actual MemoryQueryMaker
0049       * can be safely deleted in the original thread while the query is still running.
0050       * @param collection the MemoryCollection instance that the query should be run on.
0051       */
0052     explicit MemoryQueryMakerInternal( const QWeakPointer<Collections::MemoryCollection> &collection );
0053     ~MemoryQueryMakerInternal() override;
0054 
0055 
0056     void runQuery();
0057     void handleResult();
0058     void handleResult( const Meta::TrackList &tracks );
0059 
0060     void setMatchers( MemoryMatcher *matchers );
0061     void setFilters( MemoryFilter *filters );
0062     void setMaxSize( int maxSize );
0063     void setReturnAsDataPtrs( bool returnAsDataPtrs );
0064     void setType( QueryMaker::QueryType );
0065     void setCustomReturnFunctions( const QList<CustomReturnFunction*> &functions );
0066     void setCustomReturnValues( const QList<CustomReturnValue*> &values );
0067     void setAlbumQueryMode( Collections::QueryMaker::AlbumQueryMode mode ) { m_albumQueryMode = mode; }
0068     void setOrderDescending( bool orderDescending ) { m_orderDescending = orderDescending; }
0069     void setOrderByNumberField( bool orderByNumberField ) { m_orderByNumberField = orderByNumberField; }
0070     void setOrderByField( qint64 orderByField ) { m_orderByField = orderByField; }
0071     void setCollectionId( const QString &collectionId ) { m_collectionId = collectionId; }
0072     void setLabelQueryMode( Collections::QueryMaker::LabelQueryMode mode ) { m_labelQueryMode = mode; }
0073 
0074 Q_SIGNALS:
0075     void newTracksReady( Meta::TrackList );
0076     void newArtistsReady( Meta::ArtistList );
0077     void newAlbumsReady( Meta::AlbumList );
0078     void newGenresReady( Meta::GenreList );
0079     void newComposersReady( Meta::ComposerList );
0080     void newYearsReady( Meta::YearList );
0081     void newResultReady( QStringList );
0082     void newLabelsReady( Meta::LabelList );
0083     void newDataReady( Meta::DataList );
0084 
0085 private:
0086     QWeakPointer<Collections::MemoryCollection> m_collection;
0087     MemoryMatcher *m_matchers;
0088     MemoryFilter *m_filters;
0089     int m_maxSize;
0090     bool m_returnAsDataPtrs;
0091     Collections::QueryMaker::QueryType m_type;
0092     Collections::QueryMaker::AlbumQueryMode m_albumQueryMode;
0093     Collections::QueryMaker::LabelQueryMode m_labelQueryMode;
0094     bool m_orderDescending;
0095     bool m_orderByNumberField;
0096     qint64 m_orderByField;
0097     QString m_collectionId;
0098     QList<CustomReturnFunction*> m_returnFunctions;
0099     QList<CustomReturnValue*> m_returnValues;
0100 };
0101 
0102 } //namespace Collections
0103 
0104 #endif