1 /****************************************************************************************
2  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
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 DYNAMICSERVICEQUERYMAKER_H
18 #define DYNAMICSERVICEQUERYMAKER_H
19 
20 #include "core/meta/forward_declarations.h"
21 #include "core/collections/QueryMaker.h"
22 #include "ServiceCollection.h"
23 #include "amarok_export.h"
24 
25 #include <kio/jobclasses.h>
26 
27 namespace ThreadWeaver
28 {
29 }
30 
31 namespace Collections {
32 
33 /**
34 A base class for implementing custom querymakers that fetch data from an external source.
35 Basically just stubs out the stuff that not every dynamic querymaker will need
36 
37     @author
38 */
39 class AMAROK_EXPORT DynamicServiceQueryMaker : public QueryMaker
40 {
41 Q_OBJECT
42 public:
43     DynamicServiceQueryMaker( );
~DynamicServiceQueryMaker()44     ~DynamicServiceQueryMaker() override {}
45 
46     //this is the stuff that must be implemented
47     void run() override = 0;
48     void abortQuery() override = 0;
49 
50     //below here is the stuf that each dynamic querymaker will most likely only need
51     //Some of, hence they are all stubbed out:
52 
setQueryType(QueryType type)53     QueryMaker* setQueryType( QueryType type ) override { Q_UNUSED( type); return this; }
54 
55     QueryMaker* addReturnValue ( qint64 value ) override;
56     QueryMaker* addReturnFunction( ReturnFunction function, qint64 value ) override;
57     QueryMaker* orderBy ( qint64 value, bool descending = false ) override;
58 
59     QueryMaker* addMatch ( const Meta::TrackPtr &track ) override;
60     QueryMaker* addMatch ( const Meta::ArtistPtr &artist, ArtistMatchBehaviour behaviour = TrackArtists ) override;
61     QueryMaker* addMatch ( const Meta::AlbumPtr &album ) override;
62     QueryMaker* addMatch ( const Meta::GenrePtr &genre ) override;
63     QueryMaker* addMatch ( const Meta::ComposerPtr &composer ) override;
64     QueryMaker* addMatch ( const Meta::YearPtr &year ) override;
65     QueryMaker* addMatch ( const Meta::LabelPtr &label ) override;
66 
67     QueryMaker* addFilter ( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ) override;
68     QueryMaker* excludeFilter ( qint64 value, const QString &filter, bool matchBegin, bool matchEnd ) override;
69 
70     QueryMaker* addNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override;
71     QueryMaker* excludeNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override;
72 
73     QueryMaker* limitMaxResultSize ( int size ) override;
74 
beginAnd()75     QueryMaker* beginAnd() override { return this; }
beginOr()76     QueryMaker* beginOr() override { return this; }
endAndOr()77     QueryMaker* endAndOr() override { return this; }
78 
79     static Meta::AlbumList matchAlbums( ServiceCollection *coll, const Meta::ArtistPtr &artist );
80 };
81 
82 } //namespace Collections
83 
84 #endif
85