File indexing completed on 2024-05-19 04:50:11

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 AMPACHESERVICEQUERYMAKER_H
0018 #define AMPACHESERVICEQUERYMAKER_H
0019 
0020 #include "DynamicServiceQueryMaker.h"
0021 
0022 #include "AmpacheServiceCollection.h"
0023 #include "AmpacheService.h"
0024 #include "NetworkAccessManagerProxy.h"
0025 
0026 #include <QUrl>
0027 
0028 namespace Collections {
0029 
0030 /** QueryMaker for Ampache
0031     Since Ampache only supports a very limited set of searches
0032     this query maker is very restricted.
0033     E.g. it does not support searches with AND and OR.
0034     TODO: support tags
0035     TODO: think about only using the MemoryQueryMaker
0036 */
0037 class AmpacheServiceQueryMaker : public DynamicServiceQueryMaker
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     AmpacheServiceQueryMaker( AmpacheServiceCollection * collection, const QUrl &server, const QString &sessionId );
0043     ~AmpacheServiceQueryMaker() override;
0044 
0045     void run() override;
0046     void abortQuery() override;
0047 
0048     QueryMaker* setQueryType( QueryType type ) override;
0049 
0050     using DynamicServiceQueryMaker::addMatch;
0051     QueryMaker* addMatch( const Meta::TrackPtr &track ) override;
0052     QueryMaker* addMatch( const Meta::ArtistPtr &artist, ArtistMatchBehaviour behaviour = TrackArtists ) override;
0053     QueryMaker* addMatch( const Meta::AlbumPtr &album ) override;
0054 
0055     QueryMaker* addFilter( qint64 value, const QString &filter, bool matchBegin = false, bool matchEnd = false ) override;
0056     QueryMaker* addNumberFilter( qint64 value, qint64 filter, QueryMaker::NumberComparison compare ) override;
0057 
0058     int validFilterMask() override;
0059     QueryMaker* limitMaxResultSize( int size ) override;
0060 
0061     void fetchArtists();
0062     void fetchAlbums();
0063     void fetchTracks();
0064 
0065 protected:
0066     struct Private;
0067     Private * const d;
0068 
0069 public Q_SLOTS:
0070     void artistDownloadComplete( const QUrl &url, const QByteArray &data, const NetworkAccessManagerProxy::Error &e );
0071     void albumDownloadComplete( const QUrl &url, const QByteArray &data, const NetworkAccessManagerProxy::Error &e );
0072     void trackDownloadComplete( const QUrl &url, const QByteArray &data, const NetworkAccessManagerProxy::Error &e );
0073 
0074 private:
0075     // Disable copy constructor and assignment
0076     AmpacheServiceQueryMaker( const AmpacheServiceQueryMaker& );
0077     AmpacheServiceQueryMaker& operator= ( const AmpacheServiceQueryMaker& );
0078 
0079     /** Gets the url for the ampache requests.
0080         Already adds query items for the dateFilter and the limit.
0081     */
0082     QUrl getRequestUrl( const QString &action = QString() ) const;
0083 
0084     /*
0085     template<class PointerType, class ListType>
0086     void emitProperResult(const ListType& list);
0087     */
0088 };
0089 
0090 } //namespace Collections
0091 
0092 #endif