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 AMPACHESERVICECOLLECTION_H
0018 #define AMPACHESERVICECOLLECTION_H
0019 
0020 #include <ServiceCollection.h>
0021 #include "AmpacheMeta.h"
0022 #include "core/collections/support/TrackForUrlWorker.h"
0023 
0024 class AmpacheTrackForUrlWorker : public Amarok::TrackForUrlWorker
0025 {
0026     Q_OBJECT
0027     public:
0028         AmpacheTrackForUrlWorker( const QUrl &url, const MetaProxy::TrackPtr &track,
0029                                   const QUrl &server, const QString &sessionId,
0030                                   ServiceBase *service);
0031         ~AmpacheTrackForUrlWorker() override;
0032         void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = nullptr) override;
0033         void parseTrack( const QString &xml );
0034     Q_SIGNALS:
0035         void authenticationNeeded();
0036     private:
0037         MetaProxy::TrackPtr m_proxy;
0038         int m_urlTrackId;
0039         int m_urlAlbumId;
0040         int m_urlArtistId;
0041 
0042         Meta::AmpacheTrack *m_urlTrack;
0043         Meta::AmpacheAlbum *m_urlAlbum;
0044         Meta::ServiceArtist *m_urlArtist;
0045 
0046         QUrl m_server;
0047         QString m_sessionId;
0048 
0049         ServiceBase *m_service;
0050 };
0051 
0052 namespace Collections {
0053 
0054 /**
0055 A collection that dynamically fetches data from a remote location as needed
0056 
0057     @author
0058 */
0059 class AmpacheServiceCollection : public ServiceCollection
0060 {
0061     Q_OBJECT
0062 
0063 public:
0064     AmpacheServiceCollection( ServiceBase *service, const QUrl &server,
0065                               const QString &sessionId );
0066 
0067     ~AmpacheServiceCollection() override;
0068 
0069     QueryMaker *queryMaker() override;
0070 
0071     QString collectionId() const override;
0072     QString prettyName() const override;
0073 
0074     Meta::TrackPtr trackForUrl( const QUrl &url ) override;
0075     bool possiblyContainsTrack( const QUrl &url ) const override;
0076 
0077 Q_SIGNALS:
0078     void authenticationNeeded();
0079 
0080 public Q_SLOTS:
0081     void slotAuthenticationNeeded();
0082     void slotLookupComplete( const Meta::TrackPtr & );
0083 
0084 private:
0085     QUrl m_server;
0086     QString m_sessionId;
0087 
0088     AmpacheTrackForUrlWorker *m_trackForUrlWorker;
0089 };
0090 
0091 } //namespace Collections
0092 
0093 #endif