1 /****************************************************************************************
2  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3  *                                                                                      *
4  * This program is free software; you can redistribute it and/or modify it under        *
5  * the terms of the GNU General Public License as published by the Free Software        *
6  * Foundation; either version 2 of the License, or (at your option) any later           *
7  * version.                                                                             *
8  *                                                                                      *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
11  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
12  *                                                                                      *
13  * You should have received a copy of the GNU General Public License along with         *
14  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
15  ****************************************************************************************/
16 
17 #ifndef AMPACHESERVICECOLLECTION_H
18 #define AMPACHESERVICECOLLECTION_H
19 
20 #include <ServiceCollection.h>
21 #include "AmpacheMeta.h"
22 #include "core/collections/support/TrackForUrlWorker.h"
23 
24 class AmpacheTrackForUrlWorker : public Amarok::TrackForUrlWorker
25 {
26     Q_OBJECT
27     public:
28         AmpacheTrackForUrlWorker( const QUrl &url, const MetaProxy::TrackPtr &track,
29                                   const QUrl &server, const QString &sessionId,
30                                   ServiceBase *service);
31         ~AmpacheTrackForUrlWorker() override;
32         void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = 0) override;
33         void parseTrack( const QString &xml );
34     Q_SIGNALS:
35         void authenticationNeeded();
36     private:
37         MetaProxy::TrackPtr m_proxy;
38         int m_urlTrackId;
39         int m_urlAlbumId;
40         int m_urlArtistId;
41 
42         Meta::AmpacheTrack *m_urlTrack;
43         Meta::AmpacheAlbum *m_urlAlbum;
44         Meta::ServiceArtist *m_urlArtist;
45 
46         QUrl m_server;
47         QString m_sessionId;
48 
49         ServiceBase *m_service;
50 };
51 
52 namespace Collections {
53 
54 /**
55 A collection that dynamically fetches data from a remote location as needed
56 
57 	@author
58 */
59 class AmpacheServiceCollection : public ServiceCollection
60 {
61     Q_OBJECT
62 
63 public:
64     AmpacheServiceCollection( ServiceBase *service, const QUrl &server,
65                               const QString &sessionId );
66 
67     ~AmpacheServiceCollection() override;
68 
69     QueryMaker *queryMaker() override;
70 
71     QString collectionId() const override;
72     QString prettyName() const override;
73 
74     Meta::TrackPtr trackForUrl( const QUrl &url ) override;
75     bool possiblyContainsTrack( const QUrl &url ) const override;
76 
77 Q_SIGNALS:
78     void authenticationNeeded();
79 
80 public Q_SLOTS:
81     void slotAuthenticationNeeded();
82     void slotLookupComplete( const Meta::TrackPtr & );
83 
84 private:
85     QUrl m_server;
86     QString m_sessionId;
87 
88     AmpacheTrackForUrlWorker *m_trackForUrlWorker;
89 };
90 
91 } //namespace Collections
92 
93 #endif
94