/* * Strawberry Music Player * Copyright 2021, Jonas Kvinge * * 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 . * */ #ifndef RADIOMODEL_H #define RADIOMODEL_H #include #include #include #include #include #include #include #include #include #include #include "core/song.h" #include "core/simpletreemodel.h" #include "covermanager/albumcoverloaderresult.h" #include "radioitem.h" #include "radiochannel.h" class QMimeData; class Application; class Database; class RadioModel : public SimpleTreeModel { Q_OBJECT public: explicit RadioModel(Application *app, QObject *parent = nullptr); ~RadioModel() override; enum Role { Role_Type = Qt::UserRole + 1, Role_SortText, Role_Source, Role_Url, Role_Homepage, Role_Donate, RoleCount }; // QAbstractItemModel Qt::ItemFlags flags(const QModelIndex &idx) const override; QVariant data(const QModelIndex &idx, int role) const override; QStringList mimeTypes() const override; QMimeData *mimeData(const QModelIndexList &indexes) const override; QVariant data(const RadioItem *item, int role) const; void Reset(); void AddChannels(const RadioChannelList &channels); private: bool IsPlayable(const QModelIndex &idx) const; bool CompareItems(const RadioItem *a, const RadioItem *b) const; void GetChildSongs(RadioItem *item, QList *urls, SongList *songs) const; SongList GetChildSongs(const QModelIndexList &indexes) const; SongList GetChildSongs(const QModelIndex &idx) const; QString ChannelIconPixmapCacheKey(const QModelIndex &idx) const; QPixmap ServiceIcon(const QModelIndex &idx) const; QPixmap ServiceIcon(RadioItem *item) const; QPixmap ChannelIcon(const QModelIndex &idx); QString SortText(QString text); private slots: void AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result); private: static const int kTreeIconSize; using ItemAndCacheKey = QPair; Application *app_; QMap container_nodes_; QList items_; QMap pending_art_; QSet pending_cache_keys_; }; #endif // RADIOMODEL_H