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

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2008 Casey Link <unnamedrambler@gmail.com>                             *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef MP3TUNESSERVICEQUERYMAKER_H
0019 #define MP3TUNESSERVICEQUERYMAKER_H
0020 
0021 #include "DynamicServiceQueryMaker.h"
0022 
0023 //#include "Mp3TunesMeta.h"
0024 #include "Mp3tunesLocker.h"
0025 #include "Mp3tunesServiceCollection.h"
0026 #include "Mp3tunesWorkers.h"
0027 
0028 #include <kio/jobclasses.h>
0029 
0030 namespace ThreadWeaver
0031 {
0032     class Job;
0033 }
0034 
0035 namespace Collections {
0036 
0037 /**
0038 A query maker for fetching external data
0039 
0040     @author
0041 */
0042 class Mp3tunesServiceQueryMaker : public DynamicServiceQueryMaker
0043 {
0044 Q_OBJECT
0045 public:
0046     Mp3tunesServiceQueryMaker( Mp3tunesServiceCollection * collection, const QString &sessionId );
0047     Mp3tunesServiceQueryMaker( Mp3tunesLocker * locker, const QString &sessionId, Mp3tunesServiceCollection * collection );
0048     ~Mp3tunesServiceQueryMaker();
0049 
0050     virtual void run();
0051 
0052    // virtual void runQuery();
0053     virtual void abortQuery();
0054 
0055     virtual QueryMaker* setQueryType( QueryType type );
0056 
0057     using DynamicServiceQueryMaker::addMatch;
0058     virtual QueryMaker* addMatch ( const Meta::ArtistPtr &artist );
0059     virtual QueryMaker* addMatch ( const Meta::AlbumPtr &album );
0060 
0061     virtual QueryMaker* addFilter( qint64 value, const QString &filter, bool matchBegin = false, bool matchEnd = false );
0062 
0063     virtual int validFilterMask();
0064 
0065     //Methods "borrowed" from MemoryQueryMaker
0066     void handleResult();
0067     void handleResult( const Meta::TrackList &tracks );
0068     void handleResult( const Meta::ArtistList &artists );
0069     void handleResult( const Meta::AlbumList &albums );
0070 
0071     void fetchArtists();
0072     void fetchAlbums();
0073     void fetchTracks();
0074 
0075 protected:
0076     template<class PointerType, class ListType>
0077     void emitProperResult( const ListType& list );
0078 
0079     Mp3tunesServiceCollection * m_collection;
0080     Mp3tunesLocker * m_locker;
0081     KIO::StoredTransferJob * m_storedTransferJob;
0082 
0083     class Private;
0084     Private * const d;
0085 
0086     QString m_sessionId;
0087     QString m_parentAlbumId;
0088     QString m_parentArtistId;
0089 
0090     QString m_artistFilter;
0091     QString m_albumFilter;
0092     QString m_trackFilter;
0093     int m_filterType;
0094 
0095 public Q_SLOTS:
0096 
0097     void artistDownloadComplete( QList<Mp3tunesLockerArtist> artists );
0098     void albumDownloadComplete( QList<Mp3tunesLockerAlbum> albums );
0099     void trackDownloadComplete( QList<Mp3tunesLockerTrack> tracks );
0100 
0101 };
0102 
0103 } //namespace Collections
0104 
0105 #endif