File indexing completed on 2024-05-05 04:49:15

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
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 DYNAMICSERVICEQUERYMAKER_H
0018 #define DYNAMICSERVICEQUERYMAKER_H
0019 
0020 #include "core/meta/forward_declarations.h"
0021 #include "core/collections/QueryMaker.h"
0022 #include "ServiceCollection.h"
0023 #include "amarok_export.h"
0024 
0025 #include <kio/jobclasses.h>
0026 
0027 namespace ThreadWeaver
0028 {
0029 }
0030 
0031 namespace Collections {
0032 
0033 /**
0034 A base class for implementing custom querymakers that fetch data from an external source.
0035 Basically just stubs out the stuff that not every dynamic querymaker will need
0036 
0037     @author
0038 */
0039 class AMAROK_EXPORT DynamicServiceQueryMaker : public QueryMaker
0040 {
0041 Q_OBJECT
0042 public:
0043     DynamicServiceQueryMaker( );
0044     ~DynamicServiceQueryMaker() override {}
0045 
0046     //this is the stuff that must be implemented
0047     void run() override = 0;
0048     void abortQuery() override = 0;
0049 
0050     //below here is the stuf that each dynamic querymaker will most likely only need
0051     //Some of, hence they are all stubbed out:
0052 
0053     QueryMaker* setQueryType( QueryType type ) override { Q_UNUSED( type); return this; }
0054 
0055     QueryMaker* addReturnValue ( qint64 value ) override;
0056     QueryMaker* addReturnFunction( ReturnFunction function, qint64 value ) override;
0057     QueryMaker* orderBy ( qint64 value, bool descending = false ) override;
0058 
0059     QueryMaker* addMatch ( const Meta::TrackPtr &track ) override;
0060     QueryMaker* addMatch ( const Meta::ArtistPtr &artist, ArtistMatchBehaviour behaviour = TrackArtists ) override;
0061     QueryMaker* addMatch ( const Meta::AlbumPtr &album ) override;
0062     QueryMaker* addMatch ( const Meta::GenrePtr &genre ) override;
0063     QueryMaker* addMatch ( const Meta::ComposerPtr &composer ) override;
0064     QueryMaker* addMatch ( const Meta::YearPtr &year ) override;
0065     QueryMaker* addMatch ( const Meta::LabelPtr &label ) override;
0066 
0067     QueryMaker* addFilter ( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ) override;
0068     QueryMaker* excludeFilter ( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ) override;
0069 
0070     QueryMaker* addNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override;
0071     QueryMaker* excludeNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override;
0072 
0073     QueryMaker* limitMaxResultSize ( int size ) override;
0074 
0075     QueryMaker* beginAnd() override { return this; }
0076     QueryMaker* beginOr() override { return this; }
0077     QueryMaker* endAndOr() override { return this; }
0078 
0079     static Meta::AlbumList matchAlbums( ServiceCollection *coll, const Meta::ArtistPtr &artist );
0080 };
0081 
0082 } //namespace Collections
0083 
0084 #endif