Add tidal support
This commit is contained in:
43
src/internet/internetmimedata.h
Normal file
43
src/internet/internetmimedata.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTERNETMIMEDATA_H
|
||||
#define INTERNETMIMEDATA_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QModelIndexList>
|
||||
|
||||
#include "core/mimedata.h"
|
||||
|
||||
class InternetModel;
|
||||
|
||||
class InternetMimeData : public MimeData {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InternetMimeData(const InternetModel *_model) : model(_model) {}
|
||||
|
||||
const InternetModel *model;
|
||||
QModelIndexList indexes;
|
||||
};
|
||||
|
||||
#endif
|
||||
83
src/internet/internetmodel.cpp
Normal file
83
src/internet/internetmodel.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QStandardItemModel>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "internetmodel.h"
|
||||
#include "internetservice.h"
|
||||
#include "tidal/tidalservice.h"
|
||||
|
||||
QMap<QString, InternetService*>* InternetModel::sServices = nullptr;
|
||||
|
||||
InternetModel::InternetModel(Application *app, QObject *parent)
|
||||
: QStandardItemModel(parent),
|
||||
app_(app) {
|
||||
|
||||
if (!sServices) sServices = new QMap<QString, InternetService*>;
|
||||
Q_ASSERT(sServices->isEmpty());
|
||||
AddService(new TidalService(app, this));
|
||||
|
||||
}
|
||||
|
||||
void InternetModel::AddService(InternetService *service) {
|
||||
|
||||
qLog(Debug) << "Adding internet service:" << service->name();
|
||||
sServices->insert(service->name(), service);
|
||||
connect(service, SIGNAL(destroyed()), SLOT(ServiceDeleted()));
|
||||
if (service->has_initial_load_settings()) service->InitialLoadSettings();
|
||||
else service->ReloadSettings();
|
||||
|
||||
}
|
||||
|
||||
void InternetModel::RemoveService(InternetService *service) {
|
||||
|
||||
if (!sServices->contains(service->name())) return;
|
||||
sServices->remove(service->name());
|
||||
disconnect(service, 0, this, 0);
|
||||
|
||||
}
|
||||
|
||||
void InternetModel::ServiceDeleted() {
|
||||
|
||||
InternetService *service = qobject_cast<InternetService*>(sender());
|
||||
if (service) RemoveService(service);
|
||||
|
||||
}
|
||||
|
||||
InternetService *InternetModel::ServiceByName(const QString &name) {
|
||||
|
||||
if (sServices->contains(name)) return sServices->value(name);
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
void InternetModel::ReloadSettings() {
|
||||
for (InternetService *service : sServices->values()) {
|
||||
service->ReloadSettings();
|
||||
}
|
||||
}
|
||||
132
src/internet/internetmodel.h
Normal file
132
src/internet/internetmodel.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTERNETMODEL_H
|
||||
#define INTERNETMODEL_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QObject>
|
||||
#include <QStandardItemModel>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "collection/collectionmodel.h"
|
||||
#include "playlist/playlistitem.h"
|
||||
#include "settings/settingsdialog.h"
|
||||
#include "widgets/multiloadingindicator.h"
|
||||
|
||||
class Application;
|
||||
class InternetService;
|
||||
|
||||
class InternetModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InternetModel(Application* app, QObject *parent = nullptr);
|
||||
|
||||
enum Role {
|
||||
// Services can use this role to distinguish between different types of items that they add.
|
||||
// The root item's type is automatically set to Type_Service,
|
||||
// but apart from that Services are free to define their own values for this field (starting from TypeCount).
|
||||
Role_Type = Qt::UserRole + 1000,
|
||||
|
||||
// If this is not set the item is not playable (ie. it can't be dragged to the playlist).
|
||||
// Otherwise it describes how this item is converted to playlist items.
|
||||
// See the PlayBehaviour enum for more details.
|
||||
Role_PlayBehaviour,
|
||||
|
||||
// The URL of the media for this item. This is required if the PlayBehaviour is set to PlayBehaviour_UseSongLoader.
|
||||
Role_Url,
|
||||
|
||||
// The metadata used in the item that is added to the playlist if the PlayBehaviour is set to PlayBehaviour_SingleItem. Ignored otherwise.
|
||||
Role_SongMetadata,
|
||||
|
||||
// If this is set to true then the model will call the service's LazyPopulate method when this item is expanded.
|
||||
// Use this if your item's children have to be downloaded or fetched remotely.
|
||||
Role_CanLazyLoad,
|
||||
|
||||
// This is automatically set on the root item for a service. It contains a pointer to an InternetService.
|
||||
// Services should not set this field themselves.
|
||||
Role_Service,
|
||||
|
||||
// Setting this to true means that the item can be changed by user action (e.g. changing remote playlists)
|
||||
Role_CanBeModified,
|
||||
RoleCount,
|
||||
Role_IsDivider = CollectionModel::Role_IsDivider,
|
||||
};
|
||||
|
||||
enum Type {
|
||||
Type_Service = 1,
|
||||
Type_Track,
|
||||
Type_UserPlaylist,
|
||||
TypeCount
|
||||
};
|
||||
|
||||
enum PlayBehaviour {
|
||||
// The item can't be played. This is the default.
|
||||
PlayBehaviour_None = 0,
|
||||
|
||||
// This item's URL is passed through the normal song loader.
|
||||
// This supports loading remote playlists, remote files and local files.
|
||||
// This is probably the most sensible behaviour to use if you're just returning normal radio stations.
|
||||
PlayBehaviour_UseSongLoader,
|
||||
|
||||
// This item's URL, Title and Artist are used in the playlist. No special behaviour occurs
|
||||
// The URL is just passed straight to gstreamer when the user starts playing.
|
||||
PlayBehaviour_SingleItem,
|
||||
|
||||
// This item's children have PlayBehaviour_SingleItem set.
|
||||
// This is used when dragging a playlist item for instance, to have all the playlit's items info loaded in the mime data.
|
||||
PlayBehaviour_MultipleItems,
|
||||
|
||||
// This item might not represent a song - the service's ItemDoubleClicked() slot will get called instead to do some custom action.
|
||||
PlayBehaviour_DoubleClickAction,
|
||||
};
|
||||
|
||||
// Needs to be static for InternetPlaylistItem::restore
|
||||
static InternetService *ServiceByName(const QString &name);
|
||||
|
||||
template <typename T>
|
||||
static T *Service() {
|
||||
return static_cast<T*>(ServiceByName(T::kServiceName));
|
||||
}
|
||||
|
||||
// Add and remove services. Ownership is not transferred and the service is not reparented.
|
||||
// If the service is deleted it will be automatically removed from the model.
|
||||
void AddService(InternetService *service);
|
||||
void RemoveService(InternetService *service);
|
||||
void ReloadSettings();
|
||||
|
||||
Application *app() const { return app_; }
|
||||
|
||||
private slots:
|
||||
void ServiceDeleted();
|
||||
|
||||
private:
|
||||
static QMap<QString, InternetService*> *sServices;
|
||||
Application *app_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
106
src/internet/internetplaylistitem.cpp
Normal file
106
src/internet/internetplaylistitem.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSettings>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
#include <QtDebug>
|
||||
|
||||
#include "internetplaylistitem.h"
|
||||
#include "internetservice.h"
|
||||
#include "internetmodel.h"
|
||||
#include "core/settingsprovider.h"
|
||||
#include "collection/sqlrow.h"
|
||||
#include "playlist/playlistbackend.h"
|
||||
|
||||
InternetPlaylistItem::InternetPlaylistItem(const QString &type)
|
||||
: PlaylistItem(type), set_service_icon_(false) {}
|
||||
|
||||
InternetPlaylistItem::InternetPlaylistItem(InternetService *service, const Song &metadata)
|
||||
: PlaylistItem("Internet"),
|
||||
service_name_(service->name()),
|
||||
set_service_icon_(false),
|
||||
metadata_(metadata) {
|
||||
InitMetadata();
|
||||
}
|
||||
|
||||
bool InternetPlaylistItem::InitFromQuery(const SqlRow &query) {
|
||||
|
||||
// The song tables gets joined first, plus one each for the song ROWIDs
|
||||
const int row = (Song::kColumns.count() + 1) * PlaylistBackend::kSongTableJoins;
|
||||
|
||||
service_name_ = query.value(row + 1).toString();
|
||||
|
||||
metadata_.InitFromQuery(query, false, (Song::kColumns.count() + 1) * 1);
|
||||
InitMetadata();
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
InternetService *InternetPlaylistItem::service() const {
|
||||
|
||||
InternetService *ret = InternetModel::ServiceByName(service_name_);
|
||||
|
||||
if (ret && !set_service_icon_) {
|
||||
const_cast<InternetPlaylistItem*>(this)->set_service_icon_ = true;
|
||||
|
||||
QString icon = ret->Icon();
|
||||
if (!icon.isEmpty()) {
|
||||
const_cast<InternetPlaylistItem*>(this)->metadata_.set_art_manual(icon);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
QVariant InternetPlaylistItem::DatabaseValue(DatabaseColumn column) const {
|
||||
switch (column) {
|
||||
case Column_InternetService:
|
||||
return service_name_;
|
||||
default:
|
||||
return PlaylistItem::DatabaseValue(column);
|
||||
}
|
||||
}
|
||||
|
||||
void InternetPlaylistItem::InitMetadata() {
|
||||
|
||||
if (metadata_.title().isEmpty())
|
||||
metadata_.set_title(metadata_.url().toString());
|
||||
metadata_.set_filetype(Song::Type_Stream);
|
||||
metadata_.set_valid(true);
|
||||
|
||||
}
|
||||
|
||||
Song InternetPlaylistItem::Metadata() const {
|
||||
if (!set_service_icon_) {
|
||||
// Get the icon if we don't have it already
|
||||
service();
|
||||
}
|
||||
|
||||
if (HasTemporaryMetadata()) return temp_metadata_;
|
||||
return metadata_;
|
||||
}
|
||||
|
||||
QUrl InternetPlaylistItem::Url() const { return metadata_.url(); }
|
||||
58
src/internet/internetplaylistitem.h
Normal file
58
src/internet/internetplaylistitem.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2010, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTERNETPLAYLISTITEM_H
|
||||
#define INTERNETPLAYLISTITEM_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QVariant>
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlistitem.h"
|
||||
|
||||
class InternetService;
|
||||
|
||||
class InternetPlaylistItem : public PlaylistItem {
|
||||
|
||||
public:
|
||||
explicit InternetPlaylistItem(const QString &type);
|
||||
InternetPlaylistItem(InternetService *service, const Song &metadata);
|
||||
bool InitFromQuery(const SqlRow &query);
|
||||
Song Metadata() const;
|
||||
QUrl Url() const;
|
||||
|
||||
protected:
|
||||
QVariant DatabaseValue(DatabaseColumn) const;
|
||||
Song DatabaseSongMetadata() const { return metadata_; }
|
||||
|
||||
private:
|
||||
void InitMetadata();
|
||||
InternetService *service() const;
|
||||
|
||||
private:
|
||||
QString service_name_;
|
||||
bool set_service_icon_;
|
||||
Song metadata_;
|
||||
};
|
||||
|
||||
#endif
|
||||
32
src/internet/internetservice.cpp
Normal file
32
src/internet/internetservice.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardItem>
|
||||
#include <QVariant>
|
||||
#include <QString>
|
||||
|
||||
#include "core/logging.h"
|
||||
#include "core/mimedata.h"
|
||||
#include "internetmodel.h"
|
||||
#include "internetservice.h"
|
||||
|
||||
InternetService::InternetService(const QString &name, Application *app, InternetModel *model, QObject *parent)
|
||||
: QObject(parent), app_(app), model_(model), name_(name) {
|
||||
}
|
||||
64
src/internet/internetservice.h
Normal file
64
src/internet/internetservice.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTERNETSERVICE_H
|
||||
#define INTERNETSERVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QStandardItem>
|
||||
#include <QAction>
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/song.h"
|
||||
#include "playlist/playlistitem.h"
|
||||
#include "settings/settingsdialog.h"
|
||||
|
||||
class Application;
|
||||
class InternetModel;
|
||||
class CollectionFilterWidget;
|
||||
|
||||
class InternetService : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InternetService(const QString &name, Application *app, InternetModel *model, QObject *parent = nullptr);
|
||||
virtual ~InternetService() {}
|
||||
QString name() const { return name_; }
|
||||
InternetModel *model() const { return model_; }
|
||||
virtual bool has_initial_load_settings() const { return false; }
|
||||
virtual void InitialLoadSettings() {}
|
||||
virtual void ReloadSettings() {}
|
||||
virtual QString Icon() { return QString(); }
|
||||
|
||||
public slots:
|
||||
virtual void ShowConfig() {}
|
||||
|
||||
protected:
|
||||
Application *app_;
|
||||
private:
|
||||
InternetModel *model_;
|
||||
QString name_;
|
||||
|
||||
};
|
||||
Q_DECLARE_METATYPE(InternetService*);
|
||||
|
||||
#endif
|
||||
39
src/internet/internetsongmimedata.h
Normal file
39
src/internet/internetsongmimedata.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Strawberry Music Player
|
||||
* This file was part of Clementine.
|
||||
* Copyright 2011, David Sansome <me@davidsansome.com>
|
||||
*
|
||||
* Strawberry 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.
|
||||
*
|
||||
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef INTERNETSONGMIMEDATA_H
|
||||
#define INTERNETSONGMIMEDATA_H
|
||||
|
||||
#include "core/mimedata.h"
|
||||
#include "core/song.h"
|
||||
|
||||
class InternetService;
|
||||
|
||||
class InternetSongMimeData : public MimeData {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit InternetSongMimeData(InternetService *_service) : service(_service) {}
|
||||
|
||||
InternetService *service;
|
||||
SongList songs;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user