File indexing completed on 2024-05-19 04:50:28
0001 /**************************************************************************************** 0002 * Copyright (c) 2012 Matěj Laitl <matej@laitl.cz> * 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 STATSYNCING_COLLECTIONPROVIDER_H 0018 #define STATSYNCING_COLLECTIONPROVIDER_H 0019 0020 #include "core/meta/forward_declarations.h" 0021 #include "statsyncing/Provider.h" 0022 0023 #include <QPointer> 0024 #include <QSemaphore> 0025 0026 namespace Collections { 0027 class Collection; 0028 } 0029 0030 namespace StatSyncing 0031 { 0032 /** 0033 * Provider that has Collections::Collections as a back-end. 0034 */ 0035 class CollectionProvider : public Provider 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 /** 0041 * Construct provider that has @param collection as a back-end. 0042 */ 0043 explicit CollectionProvider( Collections::Collection *collection ); 0044 ~CollectionProvider() override; 0045 0046 QString id() const override; 0047 QString prettyName() const override; 0048 QIcon icon() const override; 0049 qint64 reliableTrackMetaData() const override; 0050 qint64 writableTrackStatsData() const override; 0051 Preference defaultPreference() override; 0052 QSet<QString> artists() override; 0053 TrackList artistTracks( const QString &artistName ) override; 0054 0055 Q_SIGNALS: 0056 /// hacks to create and start QueryMaker in main eventloop 0057 void startArtistSearch(); 0058 void startTrackSearch( const QString &artistName ); 0059 0060 private Q_SLOTS: 0061 /// @see startArtistSearch 0062 void slotStartArtistSearch(); 0063 void slotStartTrackSearch(const QString &artistName ); 0064 0065 void slotNewArtistsReady( Meta::ArtistList list ); 0066 void slotNewTracksReady( Meta::TrackList list ); 0067 void slotQueryDone(); 0068 0069 private: 0070 Q_DISABLE_COPY(CollectionProvider) 0071 0072 /// collection can disappear at any time, use weak pointer to notice it 0073 QPointer<Collections::Collection> m_coll; 0074 QSet<QString> m_foundArtists; 0075 QString m_currentArtistName; 0076 TrackList m_foundTracks; 0077 /** 0078 * Semaphore for the simplified producer-consumer pattern, where 0079 * slotNewResultReady( ArtistList ) along with slotQueryDone() is producer 0080 * and artists() is consumer, or 0081 * slotNewResultReady( TrackList ) along with slotQueryDone() is producer 0082 * and artistTracks() is consumer. 0083 */ 0084 QSemaphore m_queryMakerSemaphore; 0085 }; 0086 0087 } // namespace StatSyncing 0088 0089 #endif // STATSYNCING_COLLECTIONPROVIDER_H