2011-04-28 17:10:28 +02:00
|
|
|
/* This file is part of Clementine.
|
2014-11-02 19:36:21 +01:00
|
|
|
Copyright 2011, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2011, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2012, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2011-04-28 17:10:28 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#ifndef CORE_URLHANDLER_H_
|
|
|
|
#define CORE_URLHANDLER_H_
|
2011-04-28 17:10:28 +02:00
|
|
|
|
2012-01-04 12:50:19 +01:00
|
|
|
#include <QIcon>
|
2011-04-28 17:10:28 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QUrl>
|
|
|
|
|
|
|
|
class UrlHandler : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-11-01 19:26:05 +01:00
|
|
|
explicit UrlHandler(QObject* parent = nullptr);
|
2011-04-28 17:10:28 +02:00
|
|
|
|
|
|
|
// The URL scheme that this handler handles.
|
|
|
|
virtual QString scheme() const = 0;
|
2012-01-04 12:50:19 +01:00
|
|
|
virtual QIcon icon() const;
|
2011-04-28 17:10:28 +02:00
|
|
|
|
2011-07-21 01:22:20 +02:00
|
|
|
// Returned by StartLoading() and LoadNext(), indicates what the player
|
|
|
|
// should do when it wants to load a URL.
|
|
|
|
struct LoadResult {
|
|
|
|
enum Type {
|
|
|
|
// There wasn't a track available, and the player should move on to the
|
|
|
|
// next playlist item.
|
|
|
|
NoMoreTracks,
|
|
|
|
|
|
|
|
// There might be another track available but the handler needs to do some
|
|
|
|
// work (eg. fetching a remote playlist) to find out. AsyncLoadComplete
|
|
|
|
// will be emitted later with the same original_url.
|
|
|
|
WillLoadAsynchronously,
|
|
|
|
|
|
|
|
// There was a track available. Its url is in media_url.
|
|
|
|
TrackAvailable,
|
2021-06-19 07:21:36 +02:00
|
|
|
|
|
|
|
// Failed to resolve URL.
|
|
|
|
Error
|
2011-07-21 01:22:20 +02:00
|
|
|
};
|
|
|
|
|
2021-06-19 07:21:36 +02:00
|
|
|
LoadResult(const QUrl& original_url, Type type,
|
2014-02-07 16:34:20 +01:00
|
|
|
const QUrl& media_url = QUrl(), qint64 length_nanosec_ = -1);
|
2011-07-21 01:22:20 +02:00
|
|
|
|
|
|
|
// The url that the playlist item has in Url().
|
|
|
|
// Might be something unplayable like lastfm://...
|
|
|
|
QUrl original_url_;
|
|
|
|
|
|
|
|
Type type_;
|
|
|
|
|
|
|
|
// The actual url to something that gstreamer can play.
|
|
|
|
QUrl media_url_;
|
2011-10-02 12:05:56 +02:00
|
|
|
|
|
|
|
// Track length, if we are able to get it only now
|
|
|
|
qint64 length_nanosec_;
|
2020-02-20 07:51:22 +01:00
|
|
|
|
|
|
|
// If non-empty, value for an Authorization header.
|
|
|
|
QByteArray auth_header_;
|
2011-07-21 01:22:20 +02:00
|
|
|
};
|
|
|
|
|
2011-04-28 17:10:28 +02:00
|
|
|
// Called by the Player when a song starts loading - gives the handler
|
|
|
|
// a chance to do something clever to get a playable track.
|
2021-06-19 07:21:36 +02:00
|
|
|
virtual LoadResult StartLoading(const QUrl& url) = 0;
|
2011-04-28 17:10:28 +02:00
|
|
|
|
|
|
|
// Called by the player when a song finishes - gives the handler a chance to
|
|
|
|
// get another track to play.
|
2021-06-19 07:21:36 +02:00
|
|
|
virtual LoadResult LoadNext(const QUrl& url) {
|
|
|
|
return LoadResult(url, LoadResult::NoMoreTracks);
|
|
|
|
}
|
2011-04-28 17:10:28 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Functions to be warned when something happen to a track handled by
|
|
|
|
// UrlHandler.
|
2014-11-01 19:26:05 +01:00
|
|
|
virtual void TrackAboutToEnd() {}
|
|
|
|
virtual void TrackSkipped() {}
|
2011-10-02 12:05:56 +02:00
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
signals:
|
2011-07-21 01:22:20 +02:00
|
|
|
void AsyncLoadComplete(const UrlHandler::LoadResult& result);
|
2011-04-28 17:10:28 +02:00
|
|
|
};
|
|
|
|
|
2014-11-01 19:26:05 +01:00
|
|
|
#endif // CORE_URLHANDLER_H_
|