2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.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/>.
|
|
|
|
*/
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
#ifndef INTERNETMODEL_H
|
|
|
|
#define INTERNETMODEL_H
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "core/song.h"
|
2011-11-24 23:42:22 +01:00
|
|
|
#include "library/librarymodel.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "playlist/playlistitem.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 16:13:38 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2011-07-23 20:34:41 +02:00
|
|
|
class CoverProviders;
|
2010-06-23 15:21:30 +02:00
|
|
|
class Database;
|
2011-09-24 15:44:23 +02:00
|
|
|
class GlobalSearch;
|
2010-05-09 17:51:04 +02:00
|
|
|
class MergedProxyModel;
|
2011-04-28 17:10:28 +02:00
|
|
|
class PlayerInterface;
|
2011-07-15 15:27:50 +02:00
|
|
|
class InternetService;
|
2010-06-09 00:56:31 +02:00
|
|
|
class SettingsDialog;
|
2010-06-23 15:21:30 +02:00
|
|
|
class TaskManager;
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2010-12-18 18:28:02 +01:00
|
|
|
#ifdef HAVE_LIBLASTFM
|
2014-02-07 16:34:20 +01:00
|
|
|
class LastFMService;
|
2010-12-18 18:28:02 +01:00
|
|
|
#endif
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
class InternetModel : public QStandardItemModel {
|
2009-12-26 22:35:45 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2014-02-10 16:03:54 +01:00
|
|
|
InternetModel(Application* app, QObject* parent = nullptr);
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2011-01-09 19:27:41 +01:00
|
|
|
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
|
2011-04-27 00:06:58 +02:00
|
|
|
// PlayBehaviour is set to PlayBehaviour_UseSongLoader.
|
2011-01-09 19:27:41 +01:00
|
|
|
Role_Url,
|
|
|
|
|
2011-04-27 00:06:58 +02:00
|
|
|
// The metadata used in the item that is added to the playlist if the
|
|
|
|
// PlayBehaviour is set to PlayBehaviour_SingleItem. Ignored otherwise.
|
|
|
|
Role_SongMetadata,
|
2011-01-09 19:27:41 +01:00
|
|
|
|
|
|
|
// 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
|
2011-07-15 15:27:50 +02:00
|
|
|
// a pointer to an InternetService. Services should not set this field
|
2011-01-09 19:27:41 +01:00
|
|
|
// themselves.
|
|
|
|
Role_Service,
|
2011-04-26 15:42:58 +02:00
|
|
|
|
2011-10-30 23:59:43 +01:00
|
|
|
// Setting this to true means that the item can be changed by user action
|
|
|
|
// (e.g. changing remote playlists)
|
|
|
|
Role_CanBeModified,
|
2011-11-24 23:42:22 +01:00
|
|
|
RoleCount,
|
|
|
|
Role_IsDivider = LibraryModel::Role_IsDivider,
|
2011-01-09 19:27:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
Type_Service = 1,
|
2012-06-27 21:19:30 +02:00
|
|
|
Type_Track,
|
2011-10-15 18:17:00 +02:00
|
|
|
Type_UserPlaylist,
|
2011-11-29 13:57:35 +01:00
|
|
|
Type_SmartPlaylist,
|
2011-01-09 19:27:41 +01:00
|
|
|
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,
|
2011-04-29 13:24:58 +02:00
|
|
|
|
2012-07-29 01:35:05 +02:00
|
|
|
// 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,
|
|
|
|
|
2011-04-29 13:24:58 +02:00
|
|
|
// This item might not represent a song - the service's ItemDoubleClicked()
|
|
|
|
// slot will get called instead to do some custom action.
|
|
|
|
PlayBehaviour_DoubleClickAction,
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
2014-10-15 20:44:09 +02:00
|
|
|
struct ServiceItem {
|
2014-10-15 20:55:24 +02:00
|
|
|
QStandardItem* item;
|
2014-10-15 20:44:09 +02:00
|
|
|
bool shown;
|
|
|
|
};
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
// Needs to be static for InternetPlaylistItem::restore
|
|
|
|
static InternetService* ServiceByName(const QString& name);
|
2014-10-15 20:44:09 +02:00
|
|
|
static const char* kSettingsGroup;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
template <typename T>
|
2010-05-28 01:34:05 +02:00
|
|
|
static T* Service() {
|
2011-01-02 15:49:55 +01:00
|
|
|
return static_cast<T*>(ServiceByName(T::kServiceName));
|
2010-05-28 01:34:05 +02:00
|
|
|
}
|
|
|
|
|
2011-01-12 21:18:17 +01:00
|
|
|
// 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.
|
2011-07-15 15:27:50 +02:00
|
|
|
void AddService(InternetService* service);
|
|
|
|
void RemoveService(InternetService* service);
|
2014-10-15 20:44:09 +02:00
|
|
|
void HideService(InternetService* service);
|
|
|
|
void ShowService(InternetService* service);
|
|
|
|
// Add or remove the services according to the setting file
|
|
|
|
void UpdateServices();
|
2011-01-12 21:18:17 +01:00
|
|
|
|
|
|
|
// Returns the service that is a parent of this item. Works by walking up
|
|
|
|
// the tree until it finds an item with Role_Service set.
|
2011-07-15 15:27:50 +02:00
|
|
|
InternetService* ServiceForItem(const QStandardItem* item) const;
|
|
|
|
InternetService* ServiceForIndex(const QModelIndex& index) const;
|
2011-01-09 19:27:41 +01:00
|
|
|
|
2011-01-12 21:18:17 +01:00
|
|
|
// Returns true if the given item has a PlayBehaviour other than None.
|
2011-01-09 19:27:41 +01:00
|
|
|
bool IsPlayable(const QModelIndex& index) const;
|
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
// QAbstractItemModel
|
2009-12-26 22:35:45 +01:00
|
|
|
Qt::ItemFlags flags(const QModelIndex& index) const;
|
|
|
|
QStringList mimeTypes() const;
|
|
|
|
QMimeData* mimeData(const QModelIndexList& indexes) const;
|
2014-02-07 16:34:20 +01:00
|
|
|
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row,
|
|
|
|
int column, const QModelIndex& parent);
|
2011-01-09 19:27:41 +01:00
|
|
|
bool hasChildren(const QModelIndex& parent) const;
|
|
|
|
int rowCount(const QModelIndex& parent) const;
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2012-03-11 15:44:43 +01:00
|
|
|
void ShowContextMenu(const QModelIndexList& selected_merged_model_indexes,
|
|
|
|
const QModelIndex& current_merged_model_index,
|
2010-05-09 19:53:27 +02:00
|
|
|
const QPoint& global_pos);
|
2010-02-03 19:32:48 +01:00
|
|
|
void ReloadSettings();
|
2009-12-30 00:01:07 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app() const { return app_; }
|
2010-05-09 17:51:04 +02:00
|
|
|
MergedProxyModel* merged_model() const { return merged_model_; }
|
|
|
|
|
2012-03-11 15:44:43 +01:00
|
|
|
const QModelIndex& current_index() const { return current_index_; }
|
|
|
|
const QModelIndexList& selected_indexes() const { return selected_indexes_; }
|
2014-10-15 20:44:09 +02:00
|
|
|
const QMap<InternetService*, ServiceItem> shown_services() const {
|
|
|
|
return shown_services_;
|
|
|
|
}
|
2012-03-11 15:44:43 +01:00
|
|
|
|
2011-01-02 15:49:55 +01: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 16:13:38 +01:00
|
|
|
|
2011-01-10 23:26:13 +01:00
|
|
|
void AddToPlaylist(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
|
|
|
private slots:
|
2012-10-15 23:02:13 +02:00
|
|
|
void ServiceDeleted();
|
2009-12-26 16:13:38 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2014-10-15 20:44:09 +02:00
|
|
|
QMap<InternetService*, ServiceItem> shown_services_;
|
|
|
|
|
2011-07-15 15:27:50 +02:00
|
|
|
static QMap<QString, InternetService*>* sServices;
|
2012-02-12 14:41:50 +01:00
|
|
|
|
|
|
|
Application* app_;
|
2010-05-09 17:51:04 +02:00
|
|
|
MergedProxyModel* merged_model_;
|
2012-03-11 15:44:43 +01:00
|
|
|
|
|
|
|
// Set when a context menu is requested, can be accessed by context menu
|
|
|
|
// actions to do things to the current item.
|
|
|
|
QModelIndexList selected_indexes_;
|
|
|
|
QModelIndex current_index_;
|
2009-12-26 16:13:38 +01:00
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // INTERNETMODEL_H
|