Refactoring

This commit is contained in:
Jonas Kvinge
2024-10-22 18:12:33 +02:00
parent dfcf715291
commit 8da2b9cd94
623 changed files with 9071 additions and 5126 deletions

View File

@@ -28,9 +28,8 @@
#include <QPixmapCache>
#include <QRegularExpression>
#include "core/application.h"
#include "core/song.h"
#include "core/simpletreemodel.h"
#include "playlist/playlistmanager.h"
#include "covermanager/albumcoverloader.h"
#include "covermanager/albumcoverloaderresult.h"
#include "radiomodel.h"
@@ -45,12 +44,13 @@ namespace {
constexpr int kTreeIconSize = 22;
}
RadioModel::RadioModel(Application *app, QObject *parent)
RadioModel::RadioModel(const SharedPtr<AlbumCoverLoader> albumcover_loader, const SharedPtr<RadioServices> radio_services, QObject *parent)
: SimpleTreeModel<RadioItem>(new RadioItem(this), parent),
app_(app) {
albumcover_loader_(albumcover_loader),
radio_services_(radio_services) {
if (app_) {
QObject::connect(&*app_->album_cover_loader(), &AlbumCoverLoader::AlbumCoverLoaded, this, &RadioModel::AlbumCoverLoaded);
if (albumcover_loader_) {
QObject::connect(&*albumcover_loader, &AlbumCoverLoader::AlbumCoverLoaded, this, &RadioModel::AlbumCoverLoaded);
}
}
@@ -109,12 +109,12 @@ QVariant RadioModel::data(const RadioItem *item, int role) const {
return QVariant::fromValue(item->source);
break;
case Role_Homepage:{
RadioService *service = app_->radio_services()->ServiceBySource(item->source);
RadioService *service = radio_services_->ServiceBySource(item->source);
if (service) return service->Homepage();
break;
}
case Role_Donate:{
RadioService *service = app_->radio_services()->ServiceBySource(item->source);
RadioService *service = radio_services_->ServiceBySource(item->source);
if (service) return service->Donate();
break;
}
@@ -141,7 +141,7 @@ QMimeData *RadioModel::mimeData(const QModelIndexList &indexes) const {
}
data->setUrls(urls);
data->name_for_new_playlist_ = PlaylistManager::GetNameForNewPlaylist(data->songs);
data->name_for_new_playlist_ = Song::GetNameForNewPlaylist(data->songs);
return data;
@@ -287,7 +287,7 @@ QPixmap RadioModel::ChannelIcon(const QModelIndex &idx) {
if (!songs.isEmpty()) {
Song song = songs.first();
song.set_art_automatic(item->channel.thumbnail_url);
const quint64 id = app_->album_cover_loader()->LoadImageAsync(AlbumCoverLoaderOptions(AlbumCoverLoaderOptions::Option::ScaledImage | AlbumCoverLoaderOptions::Option::PadScaledImage, QSize(kTreeIconSize, kTreeIconSize)), song);
const quint64 id = albumcover_loader_->LoadImageAsync(AlbumCoverLoaderOptions(AlbumCoverLoaderOptions::Option::ScaledImage | AlbumCoverLoaderOptions::Option::PadScaledImage, QSize(kTreeIconSize, kTreeIconSize)), song);
pending_art_[id] = ItemAndCacheKey(item, cache_key);
pending_cache_keys_.insert(cache_key);
}