2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2009-2012, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2010, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2011-2012, Arnaud Bienner <arnaud.bienner@gmail.com>
|
|
|
|
Copyright 2011, Tyler Rhodes <tyler.s.rhodes@gmail.com>
|
|
|
|
Copyright 2011, Paweł Bara <keirangtp@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
2010-03-24 00:11:46 +01: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-12-18 23:54:21 +01:00
|
|
|
#ifndef INTERNET_CORE_INTERNETSERVICE_H_
|
|
|
|
#define INTERNET_CORE_INTERNETSERVICE_H_
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2016-02-11 14:45:50 +01:00
|
|
|
#include <QAction>
|
2009-12-26 22:35:45 +01:00
|
|
|
#include <QList>
|
2021-03-18 00:57:12 +01:00
|
|
|
#include <QMenu>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <QObject>
|
2009-12-26 22:35:45 +01:00
|
|
|
#include <QUrl>
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2016-02-11 14:45:50 +01:00
|
|
|
#include "core/lazy.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
|
|
|
#include "playlist/playlistitem.h"
|
2011-11-29 13:57:35 +01:00
|
|
|
#include "smartplaylists/generator.h"
|
2010-08-27 17:42:58 +02:00
|
|
|
#include "ui/settingsdialog.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "widgets/multiloadingindicator.h"
|
2009-12-26 23:15:57 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2011-07-15 15:27:50 +02:00
|
|
|
class InternetModel;
|
2010-05-09 22:18:05 +02:00
|
|
|
class LibraryFilterWidget;
|
2020-02-14 08:50:15 +01:00
|
|
|
class QJsonDocument;
|
|
|
|
class QNetworkReply;
|
2012-06-27 21:19:30 +02:00
|
|
|
class QStandardItem;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
class InternetService : public QObject {
|
2009-12-26 16:13:38 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2011-07-15 15:27:50 +02:00
|
|
|
// Constructs a new internet service with the given name and model. The name
|
2011-02-14 18:00:13 +01:00
|
|
|
// should be user-friendly (like 'DigitallyImported' or 'Last.fm').
|
2012-02-12 14:41:50 +01:00
|
|
|
InternetService(const QString& name, Application* app, InternetModel* model,
|
2014-02-21 17:24:49 +01:00
|
|
|
QObject* parent = nullptr);
|
2011-07-15 15:27:50 +02:00
|
|
|
virtual ~InternetService() {}
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2014-12-27 16:40:13 +01:00
|
|
|
// Convenient method that shows URL in a QMessageBox. Used by several Internet
|
|
|
|
// services
|
|
|
|
static void ShowUrlBox(const QString& title, const QString& url);
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
QString name() const { return name_; }
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetModel* model() const { return model_; }
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2011-01-09 19:27:41 +01:00
|
|
|
virtual QStandardItem* CreateRootItem() = 0;
|
|
|
|
virtual void LazyPopulate(QStandardItem* parent) = 0;
|
2014-12-14 14:35:21 +01:00
|
|
|
virtual bool has_initial_load_settings() const { return false; }
|
|
|
|
virtual void InitialLoadSettings() {}
|
2021-03-18 04:05:42 +01:00
|
|
|
virtual void ShowContextMenu(const QPoint& global_pos);
|
|
|
|
|
2011-11-29 13:57:35 +01:00
|
|
|
// Create a generator for smart playlists
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual smart_playlists::GeneratorPtr CreateGenerator(QStandardItem* item) {
|
|
|
|
return smart_playlists::GeneratorPtr();
|
|
|
|
}
|
2011-10-30 23:59:43 +01:00
|
|
|
// Give the service a chance to do a custom action when data is dropped on it
|
|
|
|
virtual void DropMimeData(const QMimeData* data, const QModelIndex& index) {}
|
2009-12-26 23:59:11 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
virtual PlaylistItem::Options playlistitem_options() const {
|
|
|
|
return PlaylistItem::Default;
|
|
|
|
}
|
|
|
|
// Redefine this function to add service' specific actions to the playlist
|
|
|
|
// item
|
|
|
|
virtual QList<QAction*> playlistitem_actions(const Song& song) {
|
|
|
|
return QList<QAction*>();
|
|
|
|
}
|
2009-12-29 17:12:08 +01:00
|
|
|
|
2014-02-21 17:24:49 +01:00
|
|
|
virtual QWidget* HeaderWidget() const { return nullptr; }
|
2010-05-09 22:18:05 +02:00
|
|
|
|
2010-02-03 19:32:48 +01:00
|
|
|
virtual void ReloadSettings() {}
|
|
|
|
|
2010-03-25 19:38:20 +01:00
|
|
|
virtual QString Icon() { return QString(); }
|
|
|
|
|
2021-07-07 08:07:55 +02:00
|
|
|
virtual bool ConfigRequired() { return false; }
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2009-12-26 22:35:45 +01:00
|
|
|
void StreamError(const QString& message);
|
2009-12-26 23:15:57 +01:00
|
|
|
void StreamMetadataFound(const QUrl& original_url, const Song& song);
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2011-01-10 23:26:13 +01:00
|
|
|
void AddToPlaylistSignal(QMimeData* data);
|
2012-03-11 18:57:15 +01:00
|
|
|
void ScrollToIndex(const QModelIndex& index);
|
2009-12-30 02:41:37 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public slots:
|
2012-06-27 01:21:57 +02:00
|
|
|
virtual void ShowConfig() {}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private slots:
|
2011-02-10 23:24:17 +01:00
|
|
|
void AppendToPlaylist();
|
|
|
|
void ReplacePlaylist();
|
|
|
|
void OpenInNewPlaylist();
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2021-03-18 04:05:42 +01:00
|
|
|
// Called once when context menu is created
|
|
|
|
virtual void PopulateContextMenu(){};
|
|
|
|
// Called every time context menu is shown
|
|
|
|
virtual void UpdateContextMenu(){};
|
|
|
|
|
2011-02-10 23:24:17 +01:00
|
|
|
// Returns all the playlist insertion related QActions (see below).
|
|
|
|
QList<QAction*> GetPlaylistActions();
|
|
|
|
|
|
|
|
// Returns the 'append to playlist' QAction.
|
|
|
|
QAction* GetAppendToPlaylistAction();
|
|
|
|
// Returns the 'replace playlist' QAction.
|
|
|
|
QAction* GetReplacePlaylistAction();
|
|
|
|
// Returns the 'open in new playlist' QAction.
|
|
|
|
QAction* GetOpenInNewPlaylistAction();
|
|
|
|
|
2020-02-14 08:50:15 +01:00
|
|
|
// Check network reply for error, read, then parse. Will display errors if
|
|
|
|
// they occur. Returns a valid QJsonDocument on success, a null document on
|
|
|
|
// failure.
|
|
|
|
QJsonDocument ParseJsonReply(QNetworkReply* reply);
|
|
|
|
|
2011-02-09 19:23:14 +01:00
|
|
|
// Describes how songs should be added to playlist.
|
|
|
|
enum AddMode {
|
|
|
|
// appends songs to the current playlist
|
|
|
|
AddMode_Append,
|
|
|
|
// clears the current playlist and then appends all songs to it
|
|
|
|
AddMode_Replace,
|
|
|
|
// creates a new, empty playlist and then adds all songs to it
|
|
|
|
AddMode_OpenInNew
|
|
|
|
};
|
|
|
|
|
|
|
|
// Adds the 'index' element to playlist using the 'add_mode' mode.
|
|
|
|
void AddItemToPlaylist(const QModelIndex& index, AddMode add_mode);
|
|
|
|
// Adds the 'indexes' elements to playlist using the 'add_mode' mode.
|
|
|
|
void AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode);
|
2011-01-10 23:26:13 +01:00
|
|
|
|
2012-06-27 21:19:30 +02:00
|
|
|
// Convenient function for creating a item representing a song.
|
|
|
|
// Set some common properties (type=track, url, etc.)
|
|
|
|
QStandardItem* CreateSongItem(const Song& song);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
protected:
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
2021-03-18 00:57:12 +01:00
|
|
|
std::unique_ptr<QMenu> context_menu_;
|
2012-02-12 14:41:50 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetModel* model_;
|
2009-12-26 16:13:38 +01:00
|
|
|
QString name_;
|
2011-02-10 23:24:17 +01:00
|
|
|
|
2016-02-11 14:45:50 +01:00
|
|
|
Lazy<QAction> append_to_playlist_;
|
|
|
|
Lazy<QAction> replace_playlist_;
|
|
|
|
Lazy<QAction> open_in_new_playlist_;
|
|
|
|
Lazy<QAction> separator_;
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
2019-11-10 00:30:18 +01:00
|
|
|
Q_DECLARE_METATYPE(InternetService*)
|
2011-01-09 19:27:41 +01:00
|
|
|
|
2014-12-18 23:54:21 +01:00
|
|
|
#endif // INTERNET_CORE_INTERNETSERVICE_H_
|