File indexing completed on 2024-05-19 04:50:18
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 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 MAGNATUNEDATABASEWORKER_H 0018 #define MAGNATUNEDATABASEWORKER_H 0019 0020 #include "MagnatuneMeta.h" 0021 0022 #include "../ServiceSqlRegistry.h" 0023 0024 #include <ThreadWeaver/Job> 0025 0026 /** 0027 A small helper class to do some simple asynchronous database queries 0028 0029 @author Nikolaj Hald Nielsen <nhn@kde.org> 0030 */ 0031 0032 class MagnatuneDatabaseWorker : public QObject, public ThreadWeaver::Job 0033 { 0034 Q_OBJECT 0035 public: 0036 MagnatuneDatabaseWorker(); 0037 0038 ~MagnatuneDatabaseWorker() override; 0039 0040 void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = nullptr) override; 0041 0042 void fetchMoodMap(); 0043 void fetchTrackswithMood( const QString &mood, int noOfTracks, ServiceSqlRegistry * registry ); 0044 void fetchAlbumBySku( const QString &sku, ServiceSqlRegistry * registry ); 0045 0046 Q_SIGNALS: 0047 /** This signal is emitted when this job is being processed by a thread. */ 0048 void started(ThreadWeaver::JobPointer); 0049 /** This signal is emitted when the job has been finished (no matter if it succeeded or not). */ 0050 void done(ThreadWeaver::JobPointer); 0051 /** This job has failed. 0052 * This signal is emitted when success() returns false after the job is executed. */ 0053 void failed(ThreadWeaver::JobPointer); 0054 0055 void gotMoodMap( const QMap<QString, int> &map ); 0056 void gotMoodyTracks( const Meta::TrackList &tracks ); 0057 void gotAlbumBySku( Meta::MagnatuneAlbum * album ); 0058 0059 private Q_SLOTS: 0060 void completeJob(); 0061 0062 private: 0063 0064 void doFetchMoodMap(); 0065 void doFetchTrackswithMood(); 0066 void doFetchAlbumBySku(); 0067 0068 enum taskType { FETCH_MODS, FETCH_MOODY_TRACKS, ALBUM_BY_SKU }; 0069 0070 int m_task; 0071 0072 QMap<QString, int> m_moodMap; 0073 Meta::TrackList m_moodyTracks; 0074 0075 QString m_mood; 0076 QString m_sku; 0077 int m_noOfTracks; 0078 Meta::MagnatuneAlbum * m_album; 0079 0080 ServiceSqlRegistry * m_registry; 0081 0082 protected: 0083 void defaultBegin(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override; 0084 void defaultEnd(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override; 0085 }; 0086 0087 #endif