2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2019-09-23 19:17:41 +02:00
|
|
|
* Copyright 2018-2019, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* 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/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2020-02-08 03:40:30 +01:00
|
|
|
#include <memory>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <functional>
|
2018-10-19 20:18:46 +02:00
|
|
|
#include <algorithm>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QtConcurrentRun>
|
2020-02-08 03:40:30 +01:00
|
|
|
#include <QThread>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QMutex>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QFuture>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QDataStream>
|
|
|
|
#include <QMimeData>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QIODevice>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QSet>
|
2019-11-25 22:25:29 +01:00
|
|
|
#include <QMap>
|
2020-02-08 03:40:30 +01:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QByteArray>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QString>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QStringList>
|
|
|
|
#include <QUrl>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QImage>
|
2020-02-08 03:40:30 +01:00
|
|
|
#include <QChar>
|
|
|
|
#include <QRegExp>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QPixmapCache>
|
2020-02-08 03:40:30 +01:00
|
|
|
#include <QNetworkDiskCache>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QSettings>
|
2020-02-07 23:18:18 +01:00
|
|
|
#include <QStandardPaths>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtDebug>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#include "core/application.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "core/closure.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "core/database.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "core/iconloader.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/taskmanager.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "collectionquery.h"
|
|
|
|
#include "collectionbackend.h"
|
|
|
|
#include "collectiondirectorymodel.h"
|
|
|
|
#include "collectionitem.h"
|
|
|
|
#include "collectionmodel.h"
|
|
|
|
#include "sqlrow.h"
|
|
|
|
#include "playlist/playlistmanager.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "playlist/songmimedata.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "covermanager/albumcoverloader.h"
|
2020-04-20 18:03:18 +02:00
|
|
|
#include "covermanager/albumcoverloaderresult.h"
|
2020-02-07 23:18:18 +01:00
|
|
|
#include "settings/collectionsettingspage.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
using std::placeholders::_1;
|
|
|
|
using std::placeholders::_2;
|
|
|
|
|
|
|
|
const char *CollectionModel::kSavedGroupingsSettingsGroup = "SavedGroupings";
|
|
|
|
const int CollectionModel::kPrettyCoverSize = 32;
|
2020-04-29 00:33:38 +02:00
|
|
|
const char *CollectionModel::kPixmapDiskCacheDir = "pixmapcache";
|
2020-02-07 23:18:18 +01:00
|
|
|
|
|
|
|
QNetworkDiskCache *CollectionModel::sIconCache = nullptr;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
static bool IsArtistGroupBy(const CollectionModel::GroupBy by) {
|
|
|
|
return by == CollectionModel::GroupBy_Artist || by == CollectionModel::GroupBy_AlbumArtist;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool IsCompilationArtistNode(const CollectionItem *node) {
|
|
|
|
return node == node->parent->compilation_artist_node_;
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, QObject *parent) :
|
|
|
|
SimpleTreeModel<CollectionItem>(new CollectionItem(this), parent),
|
|
|
|
backend_(backend),
|
|
|
|
app_(app),
|
|
|
|
dir_model_(new CollectionDirectoryModel(backend, this)),
|
|
|
|
show_various_artists_(true),
|
|
|
|
total_song_count_(0),
|
|
|
|
total_artist_count_(0),
|
|
|
|
total_album_count_(0),
|
2018-08-29 21:42:24 +02:00
|
|
|
artist_icon_(IconLoader::Load("folder-sound")),
|
|
|
|
album_icon_(IconLoader::Load("cdcase")),
|
2018-02-27 18:06:05 +01:00
|
|
|
playlists_dir_icon_(IconLoader::Load("folder-sound")),
|
|
|
|
playlist_icon_(IconLoader::Load("albums")),
|
|
|
|
init_task_id_(-1),
|
|
|
|
use_pretty_covers_(false),
|
2020-02-07 23:18:18 +01:00
|
|
|
show_dividers_(true),
|
|
|
|
use_disk_cache_(false) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
root_->lazy_loaded = true;
|
|
|
|
|
2019-05-27 21:10:37 +02:00
|
|
|
group_by_[0] = GroupBy_AlbumArtist;
|
2018-02-27 18:06:05 +01:00
|
|
|
group_by_[1] = GroupBy_Album;
|
|
|
|
group_by_[2] = GroupBy_None;
|
|
|
|
|
|
|
|
cover_loader_options_.desired_height_ = kPrettyCoverSize;
|
|
|
|
cover_loader_options_.pad_output_image_ = true;
|
|
|
|
cover_loader_options_.scale_output_image_ = true;
|
|
|
|
|
2020-04-29 00:33:38 +02:00
|
|
|
if (app_) {
|
2020-04-20 18:03:18 +02:00
|
|
|
connect(app_->album_cover_loader(), SIGNAL(AlbumCoverLoaded(quint64, AlbumCoverLoaderResult)), SLOT(AlbumCoverLoaded(quint64, AlbumCoverLoaderResult)));
|
2020-04-29 00:33:38 +02:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-08-29 21:42:24 +02:00
|
|
|
QIcon nocover = IconLoader::Load("cdcase");
|
2020-05-16 19:17:06 +02:00
|
|
|
if (!nocover.isNull()) {
|
|
|
|
no_cover_icon_ = nocover.pixmap(nocover.availableSizes().last()).scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-05-16 19:17:06 +02:00
|
|
|
if (app_ && !sIconCache) {
|
2020-02-07 23:18:18 +01:00
|
|
|
sIconCache = new QNetworkDiskCache(this);
|
2020-04-29 00:33:38 +02:00
|
|
|
sIconCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" + kPixmapDiskCacheDir);
|
2020-05-16 19:35:25 +02:00
|
|
|
connect(app_, SIGNAL(ClearPixmapDiskCache()), SLOT(ClearDiskCache()));
|
2020-04-29 00:33:38 +02:00
|
|
|
}
|
2020-02-07 23:18:18 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
connect(backend_, SIGNAL(SongsDiscovered(SongList)), SLOT(SongsDiscovered(SongList)));
|
|
|
|
connect(backend_, SIGNAL(SongsDeleted(SongList)), SLOT(SongsDeleted(SongList)));
|
|
|
|
connect(backend_, SIGNAL(DatabaseReset()), SLOT(Reset()));
|
|
|
|
connect(backend_, SIGNAL(TotalSongCountUpdated(int)), SLOT(TotalSongCountUpdatedSlot(int)));
|
|
|
|
connect(backend_, SIGNAL(TotalArtistCountUpdated(int)), SLOT(TotalArtistCountUpdatedSlot(int)));
|
|
|
|
connect(backend_, SIGNAL(TotalAlbumCountUpdated(int)), SLOT(TotalAlbumCountUpdatedSlot(int)));
|
2019-04-19 14:02:28 +02:00
|
|
|
connect(backend_, SIGNAL(SongsStatisticsChanged(SongList)), SLOT(SongsSlightlyChanged(SongList)));
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
backend_->UpdateTotalSongCountAsync();
|
|
|
|
backend_->UpdateTotalArtistCountAsync();
|
|
|
|
backend_->UpdateTotalAlbumCountAsync();
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
ReloadSettings();
|
2019-07-22 19:57:53 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2019-07-24 19:16:51 +02:00
|
|
|
CollectionModel::~CollectionModel() {
|
|
|
|
delete root_;
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::set_pretty_covers(const bool use_pretty_covers) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (use_pretty_covers != use_pretty_covers_) {
|
|
|
|
use_pretty_covers_ = use_pretty_covers;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::set_show_dividers(const bool show_dividers) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (show_dividers != show_dividers_) {
|
|
|
|
show_dividers_ = show_dividers;
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SaveGrouping(QString name) {
|
|
|
|
|
|
|
|
qLog(Debug) << "Model, save to: " << name;
|
|
|
|
|
|
|
|
QByteArray buffer;
|
|
|
|
QDataStream ds(&buffer, QIODevice::WriteOnly);
|
|
|
|
ds << group_by_;
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSavedGroupingsSettingsGroup);
|
|
|
|
s.setValue(name, buffer);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
void CollectionModel::ReloadSettings() {
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
|
|
|
|
s.beginGroup(CollectionSettingsPage::kSettingsGroup);
|
|
|
|
|
|
|
|
use_disk_cache_ = s.value(CollectionSettingsPage::kSettingsDiskCacheEnable, false).toBool();
|
|
|
|
|
2020-04-29 00:33:38 +02:00
|
|
|
QPixmapCache::setCacheLimit(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsCacheSize, CollectionSettingsPage::kSettingsCacheSizeUnit, CollectionSettingsPage::kSettingsCacheSizeDefault) / 1024);
|
2020-02-07 23:18:18 +01:00
|
|
|
|
2020-05-16 19:17:06 +02:00
|
|
|
if (sIconCache) {
|
|
|
|
sIconCache->setMaximumCacheSize(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsDiskCacheSize, CollectionSettingsPage::kSettingsDiskCacheSizeUnit, CollectionSettingsPage::kSettingsDiskCacheSizeDefault));
|
|
|
|
}
|
2020-02-07 23:18:18 +01:00
|
|
|
|
|
|
|
s.endGroup();
|
2020-04-29 00:33:38 +02:00
|
|
|
|
|
|
|
if (!use_disk_cache_) {
|
|
|
|
ClearDiskCache();
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::Init(const bool async) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (async) {
|
|
|
|
// Show a loading indicator in the model.
|
|
|
|
CollectionItem *loading = new CollectionItem(CollectionItem::Type_LoadingIndicator, root_);
|
|
|
|
loading->display_text = tr("Loading...");
|
|
|
|
loading->lazy_loaded = true;
|
|
|
|
beginResetModel();
|
|
|
|
endResetModel();
|
|
|
|
|
|
|
|
// Show a loading indicator in the status bar too.
|
2019-06-28 01:33:22 +02:00
|
|
|
if (app_)
|
|
|
|
init_task_id_ = app_->task_manager()->StartTask(tr("Loading songs"));
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ResetAsync();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SongsDiscovered(const SongList &songs) {
|
|
|
|
|
|
|
|
for (const Song &song : songs) {
|
2018-09-14 23:05:58 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// Sanity check to make sure we don't add songs that are outside the user's filter
|
|
|
|
if (!query_options_.Matches(song)) continue;
|
|
|
|
|
|
|
|
// Hey, we've already got that one!
|
|
|
|
if (song_nodes_.contains(song.id())) continue;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Before we can add each song we need to make sure the required container items already exist in the tree.
|
|
|
|
// These depend on which "group by" settings the user has on the collection.
|
|
|
|
// Eg. if the user grouped by artist and album, we would need to make sure nodes for the song's artist and album were already in the tree.
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Find parent containers in the tree
|
|
|
|
CollectionItem *container = root_;
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
GroupBy type = group_by_[i];
|
|
|
|
if (type == GroupBy_None) break;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Special case: if the song is a compilation and the current GroupBy level is Artists, then we want the Various Artists node :(
|
2018-02-27 18:06:05 +01:00
|
|
|
if (IsArtistGroupBy(type) && song.is_compilation()) {
|
|
|
|
if (container->compilation_artist_node_ == nullptr)
|
|
|
|
CreateCompilationArtistNode(true, container);
|
|
|
|
container = container->compilation_artist_node_;
|
|
|
|
}
|
|
|
|
else {
|
2018-03-10 13:02:56 +01:00
|
|
|
// Otherwise find the proper container at this level based on the item's key
|
2018-02-27 18:06:05 +01:00
|
|
|
QString key;
|
|
|
|
switch (type) {
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_AlbumArtist: key = song.effective_albumartist(); break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist: key = song.artist(); break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Album: key = song.album(); break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Composer: key = song.composer(); break;
|
|
|
|
case GroupBy_Performer: key = song.performer(); break;
|
|
|
|
case GroupBy_Grouping: key = song.grouping(); break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Disc: key = QString::number(song.disc()); break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Genre: key = song.genre(); break;
|
|
|
|
case GroupBy_Year:
|
2018-06-28 01:15:32 +02:00
|
|
|
key = QString::number(qMax(0, song.year()));
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_OriginalYear:
|
|
|
|
key = QString::number(qMax(0, song.effective_originalyear()));
|
|
|
|
break;
|
|
|
|
case GroupBy_YearAlbum:
|
|
|
|
key = PrettyYearAlbum(qMax(0, song.year()), song.album());
|
|
|
|
break;
|
|
|
|
case GroupBy_OriginalYearAlbum:
|
2018-06-28 01:15:32 +02:00
|
|
|
key = PrettyYearAlbum(qMax(0, song.effective_originalyear()), song.album());
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
|
|
|
case GroupBy_FileType:
|
2019-03-30 22:03:33 +01:00
|
|
|
key = QString::number(song.filetype());
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
2018-06-28 01:15:32 +02:00
|
|
|
case GroupBy_Samplerate:
|
2019-03-30 22:03:33 +01:00
|
|
|
key = QString::number(song.samplerate());
|
2018-06-28 01:15:32 +02:00
|
|
|
break;
|
|
|
|
case GroupBy_Bitdepth:
|
2019-03-30 22:03:33 +01:00
|
|
|
key = QString::number(song.bitdepth());
|
|
|
|
break;
|
|
|
|
case GroupBy_Bitrate:
|
|
|
|
key = QString::number(song.bitrate());
|
|
|
|
break;
|
|
|
|
case GroupBy_Format:
|
|
|
|
if (song.samplerate() <= 0) {
|
|
|
|
key = QString::number(song.filetype());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (song.bitdepth() <= 0) {
|
|
|
|
key = QString("%1 (%2)").arg(song.filetype()).arg(QString::number(song.samplerate() / 1000.0, 'G', 5));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
key = QString("%1 (%2/%3)").arg(song.filetype()).arg(QString::number(song.samplerate() / 1000.0, 'G', 5)).arg(song.bitdepth());
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 01:15:32 +02:00
|
|
|
break;
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:
|
|
|
|
key = PrettyAlbumDisc(song.album(), qMax(0, song.disc()));
|
|
|
|
break;
|
|
|
|
case GroupBy_YearAlbumDisc:
|
|
|
|
key = PrettyYearAlbumDisc(qMax(0, song.year()), song.album(), qMax(0, song.disc()));
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_None:
|
|
|
|
qLog(Error) << "GroupBy_None";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does it exist already?
|
|
|
|
if (!container_nodes_[i].contains(key)) {
|
|
|
|
// Create the container
|
|
|
|
container_nodes_[i][key] = ItemFromSong(type, true, i == 0, container, song, i);
|
|
|
|
}
|
|
|
|
container = container_nodes_[i][key];
|
|
|
|
}
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// If we just created the damn thing then we don't need to continue into it any further because it'll get lazy-loaded properly later.
|
2018-02-27 18:06:05 +01:00
|
|
|
if (!container->lazy_loaded) break;
|
|
|
|
}
|
|
|
|
if (!container->lazy_loaded) continue;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// We've gone all the way down to the deepest level and everything was already lazy loaded, so now we have to create the song in the container.
|
2018-02-27 18:06:05 +01:00
|
|
|
song_nodes_[song.id()] = ItemFromSong(GroupBy_None, true, false, container, song, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SongsSlightlyChanged(const SongList &songs) {
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// This is called if there was a minor change to the songs that will not normally require the collection to be restructured.
|
|
|
|
// We can just update our internal cache of Song objects without worrying about resetting the model.
|
2018-02-27 18:06:05 +01:00
|
|
|
for (const Song &song : songs) {
|
|
|
|
if (song_nodes_.contains(song.id())) {
|
|
|
|
song_nodes_[song.id()]->metadata = song;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
CollectionItem *CollectionModel::CreateCompilationArtistNode(const bool signal, CollectionItem *parent) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (signal) beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());
|
|
|
|
|
|
|
|
parent->compilation_artist_node_ = new CollectionItem(CollectionItem::Type_Container, parent);
|
|
|
|
parent->compilation_artist_node_->compilation_artist_node_ = nullptr;
|
|
|
|
parent->compilation_artist_node_->key = tr("Various artists");
|
|
|
|
parent->compilation_artist_node_->sort_text = " various";
|
|
|
|
parent->compilation_artist_node_->container_level = parent->container_level + 1;
|
|
|
|
|
|
|
|
if (signal) endInsertRows();
|
|
|
|
|
|
|
|
return parent->compilation_artist_node_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QString CollectionModel::DividerKey(const GroupBy type, CollectionItem *item) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Items which are to be grouped under the same divider must produce the same divider key. This will only get called for top-level items.
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (item->sort_text.isEmpty()) return QString();
|
|
|
|
|
|
|
|
switch (type) {
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_AlbumArtist:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist:
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Album:
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Composer:
|
|
|
|
case GroupBy_Performer:
|
|
|
|
case GroupBy_Grouping:
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Disc:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Genre:
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Format:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_FileType: {
|
|
|
|
QChar c = item->sort_text[0];
|
2019-03-30 22:03:33 +01:00
|
|
|
if (c.isDigit()) return "0";
|
|
|
|
if (c == ' ') return QString();
|
|
|
|
if (c.decompositionTag() != QChar::NoDecomposition)
|
|
|
|
return QChar(c.decomposition()[0]);
|
|
|
|
return c;
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
case GroupBy_Year:
|
|
|
|
case GroupBy_OriginalYear:
|
|
|
|
return SortTextForNumber(item->sort_text.toInt() / 10 * 10);
|
|
|
|
|
|
|
|
case GroupBy_YearAlbum:
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_YearAlbumDisc:
|
2018-02-27 18:06:05 +01:00
|
|
|
return SortTextForNumber(item->metadata.year());
|
|
|
|
|
|
|
|
case GroupBy_OriginalYearAlbum:
|
|
|
|
return SortTextForNumber(item->metadata.effective_originalyear());
|
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
case GroupBy_Samplerate:
|
|
|
|
return SortTextForNumber(item->metadata.samplerate());
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
case GroupBy_Bitdepth:
|
|
|
|
return SortTextForNumber(item->metadata.bitdepth());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Bitrate:
|
|
|
|
return SortTextForNumber(item->metadata.bitrate());
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_None:
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
qLog(Error) << "Unknown GroupBy type" << type << "for item" << item->display_text;
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QString CollectionModel::DividerDisplayText(const GroupBy type, const QString &key) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Pretty display text for the dividers.
|
|
|
|
|
|
|
|
switch (type) {
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumArtist:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist:
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_Album:
|
|
|
|
case GroupBy_AlbumDisc:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Composer:
|
|
|
|
case GroupBy_Performer:
|
|
|
|
case GroupBy_Disc:
|
|
|
|
case GroupBy_Grouping:
|
|
|
|
case GroupBy_Genre:
|
|
|
|
case GroupBy_FileType:
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Format:
|
2018-02-27 18:06:05 +01:00
|
|
|
if (key == "0") return "0-9";
|
|
|
|
return key.toUpper();
|
|
|
|
|
|
|
|
case GroupBy_YearAlbum:
|
|
|
|
case GroupBy_OriginalYearAlbum:
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_YearAlbumDisc:
|
2018-02-27 18:06:05 +01:00
|
|
|
if (key == "0000") return tr("Unknown");
|
|
|
|
return key.toUpper();
|
|
|
|
|
|
|
|
case GroupBy_Year:
|
|
|
|
case GroupBy_OriginalYear:
|
|
|
|
if (key == "0000") return tr("Unknown");
|
|
|
|
return QString::number(key.toInt()); // To remove leading 0s
|
|
|
|
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Samplerate:
|
2018-02-27 18:06:05 +01:00
|
|
|
if (key == "000") return tr("Unknown");
|
|
|
|
return QString::number(key.toInt()); // To remove leading 0s
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Bitdepth:
|
2018-06-28 01:15:32 +02:00
|
|
|
if (key == "000") return tr("Unknown");
|
|
|
|
return QString::number(key.toInt()); // To remove leading 0s
|
2018-10-02 00:38:52 +02:00
|
|
|
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Bitrate:
|
2018-06-28 01:15:32 +02:00
|
|
|
if (key == "000") return tr("Unknown");
|
|
|
|
return QString::number(key.toInt()); // To remove leading 0s
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
case GroupBy_None:
|
|
|
|
// fallthrough
|
|
|
|
;
|
|
|
|
}
|
|
|
|
qLog(Error) << "Unknown GroupBy type" << type << "for divider key" << key;
|
|
|
|
return QString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SongsDeleted(const SongList &songs) {
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
// Delete the actual song nodes first, keeping track of each parent so we might check to see if they're empty later.
|
2018-02-27 18:06:05 +01:00
|
|
|
QSet<CollectionItem*> parents;
|
|
|
|
for (const Song &song : songs) {
|
|
|
|
if (song_nodes_.contains(song.id())) {
|
|
|
|
CollectionItem *node = song_nodes_[song.id()];
|
|
|
|
|
|
|
|
if (node->parent != root_) parents << node->parent;
|
|
|
|
|
2019-11-26 19:42:05 +01:00
|
|
|
beginRemoveRows(ItemToIndex(node->parent), node->row, node->row);
|
2018-02-27 18:06:05 +01:00
|
|
|
node->parent->Delete(node->row);
|
|
|
|
song_nodes_.remove(song.id());
|
|
|
|
endRemoveRows();
|
2019-11-25 22:25:29 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-05-01 00:41:33 +02:00
|
|
|
// If we get here it means some of the songs we want to delete haven't been lazy-loaded yet.
|
|
|
|
// This is bad, because it would mean that to clean up empty parents we would need to lazy-load them all individually to see if they're empty.
|
|
|
|
// This can take a very long time, so better to just reset the model and be done with it.
|
2018-02-27 18:06:05 +01:00
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now delete empty parents
|
|
|
|
QSet<QString> divider_keys;
|
|
|
|
while (!parents.isEmpty()) {
|
2018-05-01 00:41:33 +02:00
|
|
|
// Since we are going to remove elements from the container, we need a copy to iterate over.
|
|
|
|
// If we iterate over the original, the behavior will be undefined.
|
2018-02-27 18:06:05 +01:00
|
|
|
QSet<CollectionItem*> parents_copy = parents;
|
|
|
|
for (CollectionItem *node : parents_copy) {
|
|
|
|
parents.remove(node);
|
|
|
|
if (node->children.count() != 0) continue;
|
|
|
|
|
|
|
|
// Consider its parent for the next round
|
|
|
|
if (node->parent != root_) parents << node->parent;
|
|
|
|
|
|
|
|
// Maybe consider its divider node
|
|
|
|
if (node->container_level == 0)
|
|
|
|
divider_keys << DividerKey(group_by_[0], node);
|
|
|
|
|
|
|
|
// Special case the Various Artists node
|
|
|
|
if (IsCompilationArtistNode(node))
|
|
|
|
node->parent->compilation_artist_node_ = nullptr;
|
|
|
|
else
|
|
|
|
container_nodes_[node->container_level].remove(node->key);
|
|
|
|
|
2019-11-25 22:25:29 +01:00
|
|
|
// Remove from pixmap cache
|
|
|
|
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node));
|
|
|
|
QPixmapCache::remove(cache_key);
|
2020-05-16 19:17:06 +02:00
|
|
|
if (use_disk_cache_ && sIconCache) sIconCache->remove(QUrl(cache_key));
|
2019-11-25 22:25:29 +01:00
|
|
|
if (pending_cache_keys_.contains(cache_key)) {
|
|
|
|
pending_cache_keys_.remove(cache_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove from pending art loading
|
|
|
|
QMap<quint64, ItemAndCacheKey>::iterator i = pending_art_.begin();
|
|
|
|
while (i != pending_art_.end()) {
|
|
|
|
if (i.value().first == node) {
|
|
|
|
i = pending_art_.erase(i);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// It was empty - delete it
|
|
|
|
beginRemoveRows(ItemToIndex(node->parent), node->row, node->row);
|
|
|
|
node->parent->Delete(node->row);
|
|
|
|
endRemoveRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete empty dividers
|
|
|
|
for (const QString ÷r_key : divider_keys) {
|
|
|
|
if (!divider_nodes_.contains(divider_key)) continue;
|
|
|
|
|
|
|
|
// Look to see if there are any other items still under this divider
|
|
|
|
bool found = false;
|
|
|
|
for (CollectionItem *node : container_nodes_[0].values()) {
|
|
|
|
if (DividerKey(group_by_[0], node) == divider_key) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found) continue;
|
|
|
|
|
|
|
|
// Remove the divider
|
|
|
|
int row = divider_nodes_[divider_key]->row;
|
|
|
|
beginRemoveRows(ItemToIndex(root_), row, row);
|
|
|
|
root_->Delete(row);
|
|
|
|
endRemoveRows();
|
|
|
|
divider_nodes_.remove(divider_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
QString CollectionModel::AlbumIconPixmapCacheKey(const QModelIndex &idx) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QStringList path;
|
2019-07-07 21:14:24 +02:00
|
|
|
QModelIndex idx_copy(idx);
|
|
|
|
while (idx_copy.isValid()) {
|
2019-11-13 21:12:50 +01:00
|
|
|
path.prepend(idx_copy.data().toString());
|
2019-07-07 21:14:24 +02:00
|
|
|
idx_copy = idx_copy.parent();
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
return Song::TextForSource(backend_->Source()) + path.join("/");
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
CollectionItem *item = IndexToItem(idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
if (!item) return no_cover_icon_;
|
|
|
|
|
|
|
|
// Check the cache for a pixmap we already loaded.
|
2019-07-07 21:14:24 +02:00
|
|
|
const QString cache_key = AlbumIconPixmapCacheKey(idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QPixmap cached_pixmap;
|
|
|
|
if (QPixmapCache::find(cache_key, &cached_pixmap)) {
|
|
|
|
return cached_pixmap;
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
// Try to load it from the disk cache
|
2020-05-16 19:17:06 +02:00
|
|
|
if (use_disk_cache_ && sIconCache) {
|
2020-02-07 23:18:18 +01:00
|
|
|
std::unique_ptr<QIODevice> cache(sIconCache->data(QUrl(cache_key)));
|
|
|
|
if (cache) {
|
2020-04-23 21:08:28 +02:00
|
|
|
QImage cached_image;
|
|
|
|
if (cached_image.load(cache.get(), "XPM")) {
|
|
|
|
QPixmapCache::insert(cache_key, QPixmap::fromImage(cached_image));
|
|
|
|
return QPixmap::fromImage(cached_image);
|
2020-02-07 23:18:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
// Maybe we're loading a pixmap already?
|
|
|
|
if (pending_cache_keys_.contains(cache_key)) {
|
|
|
|
return no_cover_icon_;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No art is cached and we're not loading it already. Load art for the first song in the album.
|
2019-07-07 21:14:24 +02:00
|
|
|
SongList songs = GetChildSongs(idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
if (!songs.isEmpty()) {
|
|
|
|
const quint64 id = app_->album_cover_loader()->LoadImageAsync(cover_loader_options_, songs.first());
|
|
|
|
pending_art_[id] = ItemAndCacheKey(item, cache_key);
|
|
|
|
pending_cache_keys_.insert(cache_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return no_cover_icon_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-20 18:03:18 +02:00
|
|
|
void CollectionModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderResult &result) {
|
2019-09-15 20:27:32 +02:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
if (!pending_art_.contains(id)) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ItemAndCacheKey item_and_cache_key = pending_art_.take(id);
|
|
|
|
CollectionItem *item = item_and_cache_key.first;
|
|
|
|
if (!item) return;
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
const QString &cache_key = item_and_cache_key.second;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
pending_cache_keys_.remove(cache_key);
|
|
|
|
|
|
|
|
// Insert this image in the cache.
|
2020-04-20 18:03:18 +02:00
|
|
|
if (result.image_scaled.isNull()) {
|
2018-02-27 18:06:05 +01:00
|
|
|
// Set the no_cover image so we don't continually try to load art.
|
|
|
|
QPixmapCache::insert(cache_key, no_cover_icon_);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
QPixmap image_pixmap;
|
2020-04-20 18:03:18 +02:00
|
|
|
image_pixmap = QPixmap::fromImage(result.image_scaled);
|
2018-02-27 18:06:05 +01:00
|
|
|
QPixmapCache::insert(cache_key, image_pixmap);
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
// If we have a valid cover not already in the disk cache
|
2020-05-16 19:17:06 +02:00
|
|
|
if (use_disk_cache_ && sIconCache) {
|
2020-02-07 23:18:18 +01:00
|
|
|
std::unique_ptr<QIODevice> cached_img(sIconCache->data(QUrl(cache_key)));
|
2020-04-20 18:03:18 +02:00
|
|
|
if (!cached_img && !result.image_scaled.isNull()) {
|
2020-02-07 23:18:18 +01:00
|
|
|
QNetworkCacheMetaData item_metadata;
|
|
|
|
item_metadata.setSaveToDisk(true);
|
|
|
|
item_metadata.setUrl(QUrl(cache_key));
|
2020-04-29 00:33:38 +02:00
|
|
|
QIODevice *cache = sIconCache->prepare(item_metadata);
|
2020-02-07 23:18:18 +01:00
|
|
|
if (cache) {
|
2020-04-20 18:03:18 +02:00
|
|
|
result.image_scaled.save(cache, "XPM");
|
2020-02-07 23:18:18 +01:00
|
|
|
sIconCache->insert(cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
const QModelIndex idx = ItemToIndex(item);
|
2019-07-22 19:57:53 +02:00
|
|
|
if (!idx.isValid()) return;
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
emit dataChanged(idx, idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QVariant CollectionModel::data(const QModelIndex &idx, const int role) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
const CollectionItem *item = IndexToItem(idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Handle a special case for returning album artwork instead of a generic CD icon.
|
|
|
|
// this is here instead of in the other data() function to let us use the
|
|
|
|
// QModelIndex& version of GetChildSongs, which satisfies const-ness, instead
|
|
|
|
// of the CollectionItem *version, which doesn't.
|
|
|
|
if (use_pretty_covers_) {
|
|
|
|
bool is_album_node = false;
|
|
|
|
if (role == Qt::DecorationRole && item->type == CollectionItem::Type_Container) {
|
|
|
|
GroupBy container_type = group_by_[item->container_level];
|
2020-05-06 22:35:55 +02:00
|
|
|
is_album_node = IsAlbumGrouping(container_type);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
if (is_album_node) {
|
|
|
|
// It has const behaviour some of the time - that's ok right?
|
2019-07-07 21:14:24 +02:00
|
|
|
return const_cast<CollectionModel*>(this)->AlbumIcon(idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return data(item, role);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QVariant CollectionModel::data(const CollectionItem *item, const int role) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
GroupBy container_type = item->type == CollectionItem::Type_Container ? group_by_[item->container_level] : GroupBy_None;
|
|
|
|
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole:
|
|
|
|
case Qt::ToolTipRole:
|
|
|
|
return item->DisplayText();
|
|
|
|
|
|
|
|
case Qt::DecorationRole:
|
|
|
|
switch (item->type) {
|
|
|
|
case CollectionItem::Type_PlaylistContainer:
|
|
|
|
return playlists_dir_icon_;
|
|
|
|
case CollectionItem::Type_Container:
|
|
|
|
switch (container_type) {
|
|
|
|
case GroupBy_Album:
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_YearAlbum:
|
|
|
|
case GroupBy_OriginalYearAlbum:
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_YearAlbumDisc:
|
2018-02-27 18:06:05 +01:00
|
|
|
return album_icon_;
|
|
|
|
case GroupBy_Artist:
|
|
|
|
case GroupBy_AlbumArtist:
|
|
|
|
return artist_icon_;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Role_Type:
|
|
|
|
return item->type;
|
|
|
|
|
|
|
|
case Role_IsDivider:
|
|
|
|
return item->type == CollectionItem::Type_Divider;
|
|
|
|
|
|
|
|
case Role_ContainerType:
|
|
|
|
return container_type;
|
|
|
|
|
|
|
|
case Role_Key:
|
|
|
|
return item->key;
|
|
|
|
|
|
|
|
case Role_Artist:
|
|
|
|
return item->metadata.artist();
|
|
|
|
|
|
|
|
case Role_Editable:
|
|
|
|
if (!item->lazy_loaded) {
|
|
|
|
const_cast<CollectionModel*>(this)->LazyPopulate(const_cast<CollectionItem*>(item), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->type == CollectionItem::Type_Container) {
|
2018-03-10 13:02:56 +01:00
|
|
|
// if we have even one non editable item as a child, we ourselves are not available for edit
|
2018-02-27 18:06:05 +01:00
|
|
|
if (!item->children.isEmpty()) {
|
|
|
|
for (CollectionItem *child : item->children) {
|
|
|
|
if (!data(child, role).toBool()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2019-05-30 18:05:07 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-02-27 18:06:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (item->type == CollectionItem::Type_Song) {
|
|
|
|
return item->metadata.IsEditable();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
case Role_SortText:
|
|
|
|
return item->SortText();
|
|
|
|
}
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CollectionModel::HasCompilations(const CollectionQuery &query) {
|
|
|
|
|
|
|
|
CollectionQuery q = query;
|
|
|
|
q.AddCompilationRequirement(true);
|
|
|
|
q.SetLimit(1);
|
|
|
|
|
|
|
|
QMutexLocker l(backend_->db()->Mutex());
|
|
|
|
if (!backend_->ExecQuery(&q)) return false;
|
|
|
|
|
|
|
|
return q.Next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CollectionModel::QueryResult CollectionModel::RunQuery(CollectionItem *parent) {
|
|
|
|
|
|
|
|
QueryResult result;
|
|
|
|
|
|
|
|
// Information about what we want the children to be
|
|
|
|
int child_level = parent == root_ ? 0 : parent->container_level + 1;
|
|
|
|
GroupBy child_type = child_level >= 3 ? GroupBy_None : group_by_[child_level];
|
|
|
|
|
2018-03-10 13:02:56 +01:00
|
|
|
// Initialise the query. child_type says what type of thing we want (artists, songs, etc.)
|
2018-02-27 18:06:05 +01:00
|
|
|
CollectionQuery q(query_options_);
|
|
|
|
InitQuery(child_type, &q);
|
|
|
|
|
|
|
|
// Walk up through the item's parents adding filters as necessary
|
|
|
|
CollectionItem *p = parent;
|
|
|
|
while (p && p->type == CollectionItem::Type_Container) {
|
|
|
|
FilterQuery(group_by_[p->container_level], p, &q);
|
|
|
|
p = p->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Artists GroupBy is special - we don't want compilation albums appearing
|
|
|
|
if (IsArtistGroupBy(child_type)) {
|
|
|
|
// Add the special Various artists node
|
|
|
|
if (show_various_artists_ && HasCompilations(q)) {
|
|
|
|
result.create_va = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't show compilations again outside the Various artists node
|
|
|
|
q.AddCompilationRequirement(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute the query
|
|
|
|
QMutexLocker l(backend_->db()->Mutex());
|
2019-07-25 17:56:28 +02:00
|
|
|
if (backend_->ExecQuery(&q)) {
|
|
|
|
while (q.Next()) {
|
|
|
|
result.rows << SqlRow(q);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
2019-07-24 19:16:51 +02:00
|
|
|
|
|
|
|
if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) {
|
|
|
|
backend_->Close();
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::PostQuery(CollectionItem *parent, const CollectionModel::QueryResult &result, const bool signal) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Information about what we want the children to be
|
|
|
|
int child_level = parent == root_ ? 0 : parent->container_level + 1;
|
|
|
|
GroupBy child_type = child_level >= 3 ? GroupBy_None : group_by_[child_level];
|
|
|
|
|
|
|
|
if (result.create_va) {
|
|
|
|
CreateCompilationArtistNode(signal, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Step through the results
|
|
|
|
for (const SqlRow &row : result.rows) {
|
|
|
|
// Create the item - it will get inserted into the model here
|
|
|
|
CollectionItem *item = ItemFromQuery(child_type, signal, child_level == 0, parent, row, child_level);
|
|
|
|
|
|
|
|
// Save a pointer to it for later
|
|
|
|
if (child_type == GroupBy_None)
|
|
|
|
song_nodes_[item->metadata.id()] = item;
|
|
|
|
else
|
|
|
|
container_nodes_[child_level][item->key] = item;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::LazyPopulate(CollectionItem *parent, const bool signal) {
|
2019-03-30 22:03:33 +01:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
if (parent->lazy_loaded) return;
|
|
|
|
parent->lazy_loaded = true;
|
|
|
|
|
|
|
|
QueryResult result = RunQuery(parent);
|
|
|
|
PostQuery(parent, result, signal);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::ResetAsync() {
|
|
|
|
QFuture<CollectionModel::QueryResult> future = QtConcurrent::run(this, &CollectionModel::RunQuery, root_);
|
|
|
|
NewClosure(future, this, SLOT(ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult>)), future);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::ResetAsyncQueryFinished(QFuture<CollectionModel::QueryResult> future) {
|
|
|
|
|
2019-07-25 17:56:28 +02:00
|
|
|
if (QThread::currentThread() != thread() && QThread::currentThread() != backend_->thread()) {
|
|
|
|
backend_->Close();
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
const struct QueryResult result = future.result();
|
|
|
|
|
|
|
|
BeginReset();
|
|
|
|
root_->lazy_loaded = true;
|
|
|
|
|
|
|
|
PostQuery(root_, result, false);
|
|
|
|
|
|
|
|
if (init_task_id_ != -1) {
|
2019-06-28 01:33:22 +02:00
|
|
|
if (app_)
|
|
|
|
app_->task_manager()->SetTaskFinished(init_task_id_);
|
2018-02-27 18:06:05 +01:00
|
|
|
init_task_id_ = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
endResetModel();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::BeginReset() {
|
|
|
|
|
|
|
|
beginResetModel();
|
|
|
|
delete root_;
|
|
|
|
song_nodes_.clear();
|
|
|
|
container_nodes_[0].clear();
|
|
|
|
container_nodes_[1].clear();
|
|
|
|
container_nodes_[2].clear();
|
|
|
|
divider_nodes_.clear();
|
|
|
|
pending_art_.clear();
|
2019-07-22 19:57:53 +02:00
|
|
|
pending_cache_keys_.clear();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
root_ = new CollectionItem(this);
|
|
|
|
root_->compilation_artist_node_ = nullptr;
|
|
|
|
root_->lazy_loaded = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::Reset() {
|
|
|
|
|
|
|
|
BeginReset();
|
|
|
|
|
|
|
|
// Populate top level
|
|
|
|
LazyPopulate(root_, false);
|
|
|
|
|
|
|
|
endResetModel();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::InitQuery(const GroupBy type, CollectionQuery *q) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Say what type of thing we want to get back from the database.
|
|
|
|
switch (type) {
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_AlbumArtist:
|
|
|
|
q->SetColumnSpec("DISTINCT effective_albumartist");
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist:
|
|
|
|
q->SetColumnSpec("DISTINCT artist");
|
|
|
|
break;
|
|
|
|
case GroupBy_Album:
|
2019-05-30 18:05:07 +02:00
|
|
|
q->SetColumnSpec("DISTINCT album, album_id");
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
|
|
|
case GroupBy_Composer:
|
|
|
|
q->SetColumnSpec("DISTINCT composer");
|
|
|
|
break;
|
|
|
|
case GroupBy_Performer:
|
|
|
|
q->SetColumnSpec("DISTINCT performer");
|
|
|
|
break;
|
|
|
|
case GroupBy_Disc:
|
|
|
|
q->SetColumnSpec("DISTINCT disc");
|
|
|
|
break;
|
|
|
|
case GroupBy_Grouping:
|
|
|
|
q->SetColumnSpec("DISTINCT grouping");
|
|
|
|
break;
|
|
|
|
case GroupBy_YearAlbum:
|
|
|
|
q->SetColumnSpec("DISTINCT year, album, grouping");
|
|
|
|
break;
|
|
|
|
case GroupBy_OriginalYearAlbum:
|
|
|
|
q->SetColumnSpec("DISTINCT year, originalyear, album, grouping");
|
|
|
|
break;
|
|
|
|
case GroupBy_Year:
|
|
|
|
q->SetColumnSpec("DISTINCT year");
|
|
|
|
break;
|
|
|
|
case GroupBy_OriginalYear:
|
|
|
|
q->SetColumnSpec("DISTINCT effective_originalyear");
|
|
|
|
break;
|
|
|
|
case GroupBy_Genre:
|
|
|
|
q->SetColumnSpec("DISTINCT genre");
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_FileType:
|
|
|
|
q->SetColumnSpec("DISTINCT filetype");
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
2018-06-28 01:15:32 +02:00
|
|
|
case GroupBy_Samplerate:
|
|
|
|
q->SetColumnSpec("DISTINCT samplerate");
|
|
|
|
break;
|
|
|
|
case GroupBy_Bitdepth:
|
|
|
|
q->SetColumnSpec("DISTINCT bitdepth");
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Bitrate:
|
|
|
|
q->SetColumnSpec("DISTINCT bitrate");
|
|
|
|
break;
|
|
|
|
case GroupBy_Format:
|
|
|
|
q->SetColumnSpec("DISTINCT filetype, samplerate, bitdepth");
|
|
|
|
break;
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:
|
|
|
|
q->SetColumnSpec("DISTINCT album, disc");
|
|
|
|
break;
|
|
|
|
case GroupBy_YearAlbumDisc:
|
|
|
|
q->SetColumnSpec("DISTINCT year, album, disc");
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_None:
|
|
|
|
q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::FilterQuery(const GroupBy type, CollectionItem *item, CollectionQuery *q) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-03-10 13:02:56 +01:00
|
|
|
// Say how we want the query to be filtered. This is done once for each parent going up the tree.
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
switch (type) {
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_AlbumArtist:
|
|
|
|
if (IsCompilationArtistNode(item))
|
|
|
|
q->AddCompilationRequirement(true);
|
|
|
|
else {
|
|
|
|
// Don't duplicate compilations outside the Various artists node
|
|
|
|
q->AddCompilationRequirement(false);
|
|
|
|
q->AddWhere("effective_albumartist", item->key);
|
|
|
|
}
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist:
|
|
|
|
if (IsCompilationArtistNode(item))
|
|
|
|
q->AddCompilationRequirement(true);
|
|
|
|
else {
|
|
|
|
// Don't duplicate compilations outside the Various artists node
|
|
|
|
q->AddCompilationRequirement(false);
|
|
|
|
q->AddWhere("artist", item->key);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GroupBy_Album:
|
|
|
|
q->AddWhere("album", item->key);
|
2019-05-30 18:05:07 +02:00
|
|
|
q->AddWhere("album_id", item->metadata.album_id());
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
|
|
|
case GroupBy_YearAlbum:
|
|
|
|
q->AddWhere("year", item->metadata.year());
|
|
|
|
q->AddWhere("album", item->metadata.album());
|
|
|
|
q->AddWhere("grouping", item->metadata.grouping());
|
|
|
|
break;
|
|
|
|
case GroupBy_OriginalYearAlbum:
|
|
|
|
q->AddWhere("year", item->metadata.year());
|
|
|
|
q->AddWhere("originalyear", item->metadata.originalyear());
|
|
|
|
q->AddWhere("album", item->metadata.album());
|
|
|
|
q->AddWhere("grouping", item->metadata.grouping());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GroupBy_Year:
|
|
|
|
q->AddWhere("year", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_OriginalYear:
|
|
|
|
q->AddWhere("effective_originalyear", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Composer:
|
|
|
|
q->AddWhere("composer", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Performer:
|
|
|
|
q->AddWhere("performer", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Disc:
|
|
|
|
q->AddWhere("disc", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Grouping:
|
|
|
|
q->AddWhere("grouping", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Genre:
|
|
|
|
q->AddWhere("genre", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_FileType:
|
|
|
|
q->AddWhere("filetype", item->metadata.filetype());
|
|
|
|
break;
|
2018-06-28 01:15:32 +02:00
|
|
|
case GroupBy_Samplerate:
|
|
|
|
q->AddWhere("samplerate", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Bitdepth:
|
|
|
|
q->AddWhere("bitdepth", item->key);
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Bitrate:
|
|
|
|
q->AddWhere("bitrate", item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Format:
|
|
|
|
q->AddWhere("filetype", item->metadata.filetype());
|
|
|
|
q->AddWhere("samplerate", item->metadata.samplerate());
|
|
|
|
q->AddWhere("bitdepth", item->metadata.bitdepth());
|
|
|
|
break;
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:
|
|
|
|
q->AddWhere("album", item->metadata.album());
|
|
|
|
q->AddWhere("disc", item->metadata.disc());
|
|
|
|
break;
|
|
|
|
case GroupBy_YearAlbumDisc:
|
|
|
|
q->AddWhere("year", item->metadata.year());
|
|
|
|
q->AddWhere("album", item->metadata.album());
|
|
|
|
q->AddWhere("disc", item->metadata.disc());
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_None:
|
|
|
|
qLog(Error) << "Unknown GroupBy type" << type << "used in filter";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
CollectionItem *CollectionModel::InitItem(const GroupBy type, const bool signal, CollectionItem *parent, const int container_level) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
CollectionItem::Type item_type = type == GroupBy_None ? CollectionItem::Type_Song : CollectionItem::Type_Container;
|
|
|
|
|
2018-03-10 13:02:56 +01:00
|
|
|
if (signal) beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
// Initialise the item depending on what type it's meant to be
|
|
|
|
CollectionItem *item = new CollectionItem(item_type, parent);
|
|
|
|
item->compilation_artist_node_ = nullptr;
|
|
|
|
item->container_level = container_level;
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
CollectionItem *CollectionModel::ItemFromQuery(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, const SqlRow &row, const int container_level) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
CollectionItem *item = InitItem(type, signal, parent, container_level);
|
|
|
|
|
|
|
|
switch (type) {
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_AlbumArtist:
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist:
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Composer:
|
|
|
|
case GroupBy_Performer:
|
|
|
|
case GroupBy_Grouping:
|
|
|
|
case GroupBy_Genre:
|
2018-02-27 18:06:05 +01:00
|
|
|
item->key = row.value(0).toString();
|
|
|
|
item->display_text = TextOrUnknown(item->key);
|
|
|
|
item->sort_text = SortTextForArtist(item->key);
|
|
|
|
break;
|
|
|
|
|
2019-05-30 18:05:07 +02:00
|
|
|
case GroupBy_Album:
|
|
|
|
item->key = row.value(0).toString();
|
|
|
|
item->display_text = TextOrUnknown(item->key);
|
|
|
|
item->sort_text = SortTextForArtist(item->key);
|
2019-06-20 02:14:44 +02:00
|
|
|
item->metadata.set_album_id(row.value(1).toString());
|
2019-05-30 18:05:07 +02:00
|
|
|
break;
|
|
|
|
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_OriginalYear:{
|
|
|
|
int year = qMax(0, row.value(0).toInt());
|
|
|
|
item->key = QString::number(year);
|
|
|
|
item->sort_text = SortTextForNumber(year) + " ";
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Year:{
|
|
|
|
int year = qMax(0, row.value(0).toInt());
|
|
|
|
item->key = QString::number(year);
|
|
|
|
item->sort_text = SortTextForNumber(year) + " ";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GroupBy_OriginalYearAlbum:{
|
2018-02-27 18:06:05 +01:00
|
|
|
item->metadata.set_year(row.value(0).toInt());
|
|
|
|
item->metadata.set_originalyear(row.value(1).toInt());
|
|
|
|
item->metadata.set_album(row.value(2).toString());
|
|
|
|
item->metadata.set_grouping(row.value(3).toString());
|
2019-03-30 22:03:33 +01:00
|
|
|
int effective_originalyear = qMax(0, item->metadata.effective_originalyear());
|
2018-02-27 18:06:05 +01:00
|
|
|
item->key = PrettyYearAlbum(effective_originalyear, item->metadata.album());
|
|
|
|
item->sort_text = SortTextForNumber(effective_originalyear) + item->metadata.grouping() + item->metadata.album();
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_YearAlbum:{
|
|
|
|
int year = qMax(0, row.value(0).toInt());
|
|
|
|
item->metadata.set_year(row.value(0).toInt());
|
|
|
|
item->metadata.set_album(row.value(1).toString());
|
|
|
|
item->metadata.set_grouping(row.value(2).toString());
|
|
|
|
item->key = PrettyYearAlbum(year, item->metadata.album());
|
|
|
|
item->sort_text = SortTextForNumber(year) + item->metadata.grouping() + item->metadata.album();
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case GroupBy_Format:{
|
|
|
|
item->metadata.set_filetype(Song::FileType(row.value(0).toInt()));
|
|
|
|
item->metadata.set_samplerate(row.value(1).toInt());
|
|
|
|
item->metadata.set_bitdepth(row.value(2).toInt());
|
|
|
|
if (item->metadata.samplerate() <= 0) {
|
|
|
|
item->key = item->metadata.TextForFiletype();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (item->metadata.bitdepth() <= 0) {
|
|
|
|
item->key = QString("%1 (%2)").arg(item->metadata.TextForFiletype()).arg(QString::number(item->metadata.samplerate() / 1000.0, 'G', 5));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item->key = QString("%1 (%2/%3)").arg(item->metadata.TextForFiletype()).arg(QString::number(item->metadata.samplerate() / 1000.0, 'G', 5)).arg(QString::number(item->metadata.bitdepth()));
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Disc:{
|
|
|
|
int disc = row.value(0).toInt();
|
2018-02-27 18:06:05 +01:00
|
|
|
item->key = QString::number(disc);
|
|
|
|
item->sort_text = SortTextForNumber(disc);
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_FileType:
|
|
|
|
item->metadata.set_filetype(Song::FileType(row.value(0).toInt()));
|
|
|
|
item->key = item->metadata.TextForFiletype();
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Samplerate:{
|
|
|
|
int samplerate = qMax(0, row.value(0).toInt());
|
2018-06-28 01:15:32 +02:00
|
|
|
item->key = QString::number(samplerate);
|
|
|
|
item->sort_text = SortTextForNumber(samplerate) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Bitdepth:{
|
|
|
|
int bitdepth = qMax(0, row.value(0).toInt());
|
2018-06-28 01:15:32 +02:00
|
|
|
item->key = QString::number(bitdepth);
|
|
|
|
item->sort_text = SortTextForNumber(bitdepth) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Bitrate:{
|
|
|
|
int bitrate = qMax(0, row.value(0).toInt());
|
|
|
|
item->key = QString::number(bitrate);
|
|
|
|
item->sort_text = SortTextForNumber(bitrate) + " ";
|
|
|
|
break;
|
|
|
|
}
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:{
|
|
|
|
item->metadata.set_album(row.value(0).toString());
|
|
|
|
item->metadata.set_disc(row.value(1).toInt());
|
|
|
|
item->key = PrettyAlbumDisc(item->metadata.album(), item->metadata.disc());
|
|
|
|
int disc = qMax(0, row.value(1).toInt());
|
|
|
|
item->sort_text = item->metadata.album() + SortTextForNumber(disc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GroupBy_YearAlbumDisc:{
|
|
|
|
item->metadata.set_year(row.value(0).toInt());
|
|
|
|
item->metadata.set_album(row.value(1).toString());
|
|
|
|
item->metadata.set_disc(row.value(2).toInt());
|
|
|
|
item->key = PrettyYearAlbumDisc(item->metadata.year(), item->metadata.album(), item->metadata.disc());
|
|
|
|
int year = qMax(0, row.value(0).toInt());
|
|
|
|
int disc = qMax(0, row.value(2).toInt());
|
|
|
|
item->sort_text = SortTextForNumber(year) + item->metadata.album() + SortTextForNumber(disc);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_None:
|
|
|
|
item->metadata.InitFromQuery(row, true);
|
|
|
|
item->key = item->metadata.title();
|
|
|
|
item->display_text = item->metadata.TitleWithCompilationArtist();
|
2020-05-06 22:14:59 +02:00
|
|
|
if (item->container_level == 1 && !IsAlbumGrouping(group_by_[0])) {
|
|
|
|
item->sort_text = SortText(item->metadata.title());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item->sort_text = SortTextForSong(item->metadata);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishItem(type, signal, create_divider, parent, item);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
CollectionItem *CollectionModel::ItemFromSong(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, const Song &s, const int container_level) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
CollectionItem *item = InitItem(type, signal, parent, container_level);
|
|
|
|
|
|
|
|
switch (type) {
|
2019-06-07 22:54:34 +02:00
|
|
|
case GroupBy_AlbumArtist:
|
|
|
|
item->key = s.effective_albumartist();
|
|
|
|
item->display_text = TextOrUnknown(item->key);
|
|
|
|
item->sort_text = SortTextForArtist(item->key);
|
|
|
|
break;
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_Artist:
|
|
|
|
item->key = s.artist();
|
|
|
|
item->display_text = TextOrUnknown(item->key);
|
|
|
|
item->sort_text = SortTextForArtist(item->key);
|
|
|
|
break;
|
2019-06-07 22:54:34 +02:00
|
|
|
case GroupBy_Album:
|
|
|
|
item->key = s.album();
|
|
|
|
item->display_text = TextOrUnknown(item->key);
|
|
|
|
item->sort_text = SortTextForArtist(item->key);
|
|
|
|
item->metadata.set_album_id(s.album_id());
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_YearAlbum:{
|
|
|
|
int year = qMax(0, s.year());
|
2018-02-27 18:06:05 +01:00
|
|
|
item->metadata.set_year(year);
|
|
|
|
item->metadata.set_album(s.album());
|
|
|
|
item->key = PrettyYearAlbum(year, s.album());
|
|
|
|
item->sort_text = SortTextForNumber(year) + s.grouping() + s.album();
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_OriginalYearAlbum:{
|
|
|
|
int year = qMax(0, s.year());
|
|
|
|
int originalyear = qMax(0, s.originalyear());
|
|
|
|
int effective_originalyear = qMax(0, s.effective_originalyear());
|
2018-02-27 18:06:05 +01:00
|
|
|
item->metadata.set_year(year);
|
|
|
|
item->metadata.set_originalyear(originalyear);
|
|
|
|
item->metadata.set_album(s.album());
|
|
|
|
item->key = PrettyYearAlbum(effective_originalyear, s.album());
|
|
|
|
item->sort_text = SortTextForNumber(effective_originalyear) + s.grouping() + s.album();
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Year:{
|
|
|
|
int year = qMax(0, s.year());
|
2018-02-27 18:06:05 +01:00
|
|
|
item->key = QString::number(year);
|
|
|
|
item->sort_text = SortTextForNumber(year) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_OriginalYear:{
|
|
|
|
int year = qMax(0, s.effective_originalyear());
|
2018-02-27 18:06:05 +01:00
|
|
|
item->key = QString::number(year);
|
|
|
|
item->sort_text = SortTextForNumber(year) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
2019-09-16 21:20:12 +02:00
|
|
|
case GroupBy_Composer:
|
|
|
|
if (item->key.isNull()) item->key = s.composer();
|
|
|
|
// fallthrough
|
|
|
|
case GroupBy_Performer:
|
|
|
|
if (item->key.isNull()) item->key = s.performer();
|
|
|
|
// fallthrough
|
|
|
|
case GroupBy_Grouping:
|
|
|
|
if (item->key.isNull()) item->key = s.grouping();
|
|
|
|
// fallthrough
|
|
|
|
case GroupBy_Genre:
|
|
|
|
if (item->key.isNull()) item->key = s.genre();
|
2018-02-27 18:06:05 +01:00
|
|
|
item->display_text = TextOrUnknown(item->key);
|
|
|
|
item->sort_text = SortTextForArtist(item->key);
|
|
|
|
break;
|
|
|
|
case GroupBy_Disc:
|
|
|
|
item->key = QString::number(s.disc());
|
|
|
|
item->sort_text = SortTextForNumber(s.disc());
|
|
|
|
break;
|
|
|
|
case GroupBy_FileType:
|
|
|
|
item->metadata.set_filetype(s.filetype());
|
|
|
|
item->key = s.TextForFiletype();
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
case GroupBy_Bitrate:{
|
|
|
|
int bitrate = qMax(0, s.bitrate());
|
2018-02-27 18:06:05 +01:00
|
|
|
item->key = QString::number(bitrate);
|
|
|
|
item->sort_text = SortTextForNumber(bitrate) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Samplerate:{
|
|
|
|
int samplerate = qMax(0, s.samplerate());
|
2018-06-28 01:15:32 +02:00
|
|
|
item->key = QString::number(samplerate);
|
|
|
|
item->sort_text = SortTextForNumber(samplerate) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Bitdepth:{
|
|
|
|
int bitdepth = qMax(0, s.bitdepth());
|
2018-06-28 01:15:32 +02:00
|
|
|
item->key = QString::number(bitdepth);
|
|
|
|
item->sort_text = SortTextForNumber(bitdepth) + " ";
|
|
|
|
break;
|
2019-03-30 22:03:33 +01:00
|
|
|
}
|
|
|
|
case GroupBy_Format:{
|
|
|
|
item->metadata.set_filetype(s.filetype());
|
|
|
|
item->metadata.set_samplerate(s.samplerate());
|
|
|
|
item->metadata.set_bitdepth(s.bitdepth());
|
|
|
|
if (s.samplerate() <= 0) {
|
|
|
|
item->key = s.TextForFiletype();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (s.bitdepth() <= 0) {
|
|
|
|
item->key = QString("%1 (%2)").arg(s.TextForFiletype()).arg(QString::number(s.samplerate() / 1000.0, 'G', 5));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item->key = QString("%1 (%2/%3)").arg(s.TextForFiletype()).arg(QString::number(s.samplerate() / 1000.0, 'G', 5)).arg(QString::number(s.bitdepth()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2019-08-05 19:17:31 +02:00
|
|
|
case GroupBy_AlbumDisc:{
|
|
|
|
item->metadata.set_album(s.album());
|
|
|
|
item->metadata.set_disc(s.disc());
|
|
|
|
item->key = PrettyAlbumDisc(s.album(), s.disc());
|
|
|
|
int disc = qMax(0, s.disc());
|
|
|
|
item->sort_text = s.album() + SortTextForNumber(disc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GroupBy_YearAlbumDisc:{
|
|
|
|
item->metadata.set_year(s.year());
|
|
|
|
item->metadata.set_album(s.album());
|
|
|
|
item->metadata.set_disc(s.disc());
|
|
|
|
item->key = PrettyYearAlbumDisc(s.year(), s.album(), s.disc());
|
|
|
|
int year = qMax(0, s.year());
|
|
|
|
int disc = qMax(0, s.disc());
|
|
|
|
item->sort_text = SortTextForNumber(year) + s.album() + SortTextForNumber(disc);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
case GroupBy_None:
|
|
|
|
item->metadata = s;
|
|
|
|
item->key = s.title();
|
|
|
|
item->display_text = s.TitleWithCompilationArtist();
|
2020-05-06 22:14:59 +02:00
|
|
|
if (item->container_level == 1 && !IsAlbumGrouping(group_by_[0])) {
|
|
|
|
item->sort_text = SortText(s.title());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
item->sort_text = SortTextForSong(s);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FinishItem(type, signal, create_divider, parent, item);
|
|
|
|
if (s.url().scheme() == "cdda") item->lazy_loaded = true;
|
2018-09-14 23:05:58 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
return item;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::FinishItem(const GroupBy type, const bool signal, const bool create_divider, CollectionItem *parent, CollectionItem *item) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (type == GroupBy_None) item->lazy_loaded = true;
|
|
|
|
|
|
|
|
if (signal) endInsertRows();
|
|
|
|
|
|
|
|
// Create the divider entry if we're supposed to
|
|
|
|
if (create_divider && show_dividers_) {
|
|
|
|
QString divider_key = DividerKey(type, item);
|
|
|
|
item->sort_text.prepend(divider_key);
|
|
|
|
|
|
|
|
if (!divider_key.isEmpty() && !divider_nodes_.contains(divider_key)) {
|
|
|
|
if (signal)
|
|
|
|
beginInsertRows(ItemToIndex(parent), parent->children.count(), parent->children.count());
|
|
|
|
|
|
|
|
CollectionItem *divider = new CollectionItem(CollectionItem::Type_Divider, root_);
|
|
|
|
divider->key = divider_key;
|
|
|
|
divider->display_text = DividerDisplayText(type, divider_key);
|
|
|
|
divider->lazy_loaded = true;
|
|
|
|
|
|
|
|
divider_nodes_[divider_key] = divider;
|
|
|
|
|
|
|
|
if (signal) endInsertRows();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CollectionModel::TextOrUnknown(const QString &text) {
|
|
|
|
|
|
|
|
if (text.isEmpty()) return tr("Unknown");
|
|
|
|
return text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-05 19:17:31 +02:00
|
|
|
QString CollectionModel::PrettyYearAlbum(const int year, const QString &album) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
if (year <= 0) return TextOrUnknown(album);
|
|
|
|
return QString::number(year) + " - " + TextOrUnknown(album);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-08-05 19:17:31 +02:00
|
|
|
QString CollectionModel::PrettyAlbumDisc(const QString &album, const int disc) {
|
|
|
|
|
2019-08-05 23:03:40 +02:00
|
|
|
if (disc <= 0 || album.contains(QRegExp(Song::kAlbumRemoveDisc))) return TextOrUnknown(album);
|
2019-08-05 19:17:31 +02:00
|
|
|
else return TextOrUnknown(album) + " - (Disc " + QString::number(disc) + ")";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CollectionModel::PrettyYearAlbumDisc(const int year, const QString &album, const int disc) {
|
|
|
|
|
|
|
|
QString str;
|
|
|
|
|
|
|
|
if (year <= 0) str = TextOrUnknown(album);
|
|
|
|
else str = QString::number(year) + " - " + TextOrUnknown(album);
|
|
|
|
|
|
|
|
if (!album.contains(QRegExp(Song::kAlbumRemoveDisc)) && disc > 0) str += " - (Disc " + QString::number(disc) + ")";
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
QString CollectionModel::SortText(QString text) {
|
|
|
|
|
|
|
|
if (text.isEmpty()) {
|
|
|
|
text = " unknown";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
text = text.toLower();
|
|
|
|
}
|
|
|
|
text = text.remove(QRegExp("[^\\w ]"));
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CollectionModel::SortTextForArtist(QString artist) {
|
|
|
|
|
|
|
|
artist = SortText(artist);
|
|
|
|
|
2019-07-05 00:13:51 +02:00
|
|
|
for (const auto &i : Song::kArticles) {
|
|
|
|
if (artist.startsWith(i)) {
|
|
|
|
int ilen = i.length();
|
|
|
|
artist = artist.right(artist.length() - ilen) + ", " + i.left(ilen - 1);
|
|
|
|
break;
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return artist;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QString CollectionModel::SortTextForNumber(const int number) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
return QString("%1").arg(number, 4, 10, QChar('0'));
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QString CollectionModel::SortTextForYear(const int year) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QString str = QString::number(year);
|
|
|
|
return QString("0").repeated(qMax(0, 4 - str.length())) + str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
QString CollectionModel::SortTextForBitrate(const int bitrate) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
QString str = QString::number(bitrate);
|
|
|
|
return QString("0").repeated(qMax(0, 3 - str.length())) + str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CollectionModel::SortTextForSong(const Song &song) {
|
|
|
|
|
|
|
|
QString ret = QString::number(qMax(0, song.disc()) * 1000 + qMax(0, song.track()));
|
|
|
|
ret.prepend(QString("0").repeated(6 - ret.length()));
|
|
|
|
ret.append(song.url().toString());
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
Qt::ItemFlags CollectionModel::flags(const QModelIndex &idx) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
switch (IndexToItem(idx)->type) {
|
2018-02-27 18:06:05 +01:00
|
|
|
case CollectionItem::Type_Song:
|
|
|
|
case CollectionItem::Type_Container:
|
|
|
|
return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled;
|
|
|
|
case CollectionItem::Type_Divider:
|
|
|
|
case CollectionItem::Type_Root:
|
|
|
|
case CollectionItem::Type_LoadingIndicator:
|
|
|
|
default:
|
|
|
|
return Qt::ItemIsEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList CollectionModel::mimeTypes() const {
|
|
|
|
return QStringList() << "text/uri-list";
|
|
|
|
}
|
|
|
|
|
|
|
|
QMimeData *CollectionModel::mimeData(const QModelIndexList &indexes) const {
|
|
|
|
|
|
|
|
if (indexes.isEmpty()) return nullptr;
|
|
|
|
|
|
|
|
SongMimeData *data = new SongMimeData;
|
|
|
|
QList<QUrl> urls;
|
|
|
|
QSet<int> song_ids;
|
|
|
|
|
|
|
|
data->backend = backend_;
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
for (const QModelIndex &idx : indexes) {
|
|
|
|
GetChildSongs(IndexToItem(idx), &urls, &data->songs, &song_ids);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data->setUrls(urls);
|
|
|
|
data->name_for_new_playlist_ = PlaylistManager::GetNameForNewPlaylist(data->songs);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CollectionModel::CompareItems(const CollectionItem *a, const CollectionItem *b) const {
|
|
|
|
|
|
|
|
QVariant left(data(a, CollectionModel::Role_SortText));
|
|
|
|
QVariant right(data(b, CollectionModel::Role_SortText));
|
|
|
|
|
|
|
|
if (left.type() == QVariant::Int) return left.toInt() < right.toInt();
|
|
|
|
return left.toString() < right.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-29 00:33:38 +02:00
|
|
|
int CollectionModel::MaximumCacheSize(QSettings *s, const char *size_id, const char *size_unit_id, const int cache_size_default) const {
|
2020-02-07 23:18:18 +01:00
|
|
|
|
2020-04-29 00:33:38 +02:00
|
|
|
int size = s->value(size_id, cache_size_default).toInt();
|
2020-02-07 23:18:18 +01:00
|
|
|
int unit = s->value(size_unit_id, CollectionSettingsPage::CacheSizeUnit::CacheSizeUnit_MB).toInt() + 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
size *= 1024;
|
|
|
|
unit -= 1;
|
|
|
|
} while (unit > 0);
|
|
|
|
|
|
|
|
return size;
|
2020-05-16 19:17:06 +02:00
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
void CollectionModel::GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const {
|
|
|
|
|
|
|
|
switch (item->type) {
|
|
|
|
case CollectionItem::Type_Container: {
|
|
|
|
const_cast<CollectionModel*>(this)->LazyPopulate(item);
|
|
|
|
|
|
|
|
QList<CollectionItem*> children = item->children;
|
2018-10-19 20:18:46 +02:00
|
|
|
std::sort(children.begin(), children.end(), std::bind(&CollectionModel::CompareItems, this, _1, _2));
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
for (CollectionItem *child : children)
|
|
|
|
GetChildSongs(child, urls, songs, song_ids);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case CollectionItem::Type_Song:
|
|
|
|
urls->append(item->metadata.url());
|
|
|
|
if (!song_ids->contains(item->metadata.id())) {
|
|
|
|
songs->append(item->metadata);
|
|
|
|
song_ids->insert(item->metadata.id());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SongList CollectionModel::GetChildSongs(const QModelIndexList &indexes) const {
|
|
|
|
|
|
|
|
QList<QUrl> dontcare;
|
|
|
|
SongList ret;
|
|
|
|
QSet<int> song_ids;
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
for (const QModelIndex &idx : indexes) {
|
|
|
|
GetChildSongs(IndexToItem(idx), &dontcare, &ret, &song_ids);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
SongList CollectionModel::GetChildSongs(const QModelIndex &idx) const {
|
|
|
|
return GetChildSongs(QModelIndexList() << idx);
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::SetFilterAge(const int age) {
|
2018-02-27 18:06:05 +01:00
|
|
|
query_options_.set_max_age(age);
|
|
|
|
ResetAsync();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SetFilterText(const QString &text) {
|
|
|
|
query_options_.set_filter(text);
|
|
|
|
ResetAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SetFilterQueryMode(QueryOptions::QueryMode query_mode) {
|
|
|
|
query_options_.set_query_mode(query_mode);
|
|
|
|
ResetAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CollectionModel::canFetchMore(const QModelIndex &parent) const {
|
|
|
|
|
|
|
|
if (!parent.isValid()) return false;
|
|
|
|
|
|
|
|
CollectionItem *item = IndexToItem(parent);
|
|
|
|
return !item->lazy_loaded;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollectionModel::SetGroupBy(const Grouping &g) {
|
|
|
|
|
|
|
|
group_by_ = g;
|
|
|
|
|
|
|
|
ResetAsync();
|
|
|
|
emit GroupingChanged(g);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
const CollectionModel::GroupBy &CollectionModel::Grouping::operator[](const int i) const {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0: return first;
|
|
|
|
case 1: return second;
|
|
|
|
case 2: return third;
|
|
|
|
}
|
|
|
|
qLog(Error) << "CollectionModel::Grouping[] index out of range" << i;
|
|
|
|
return first;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
CollectionModel::GroupBy &CollectionModel::Grouping::operator[](const int i) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
switch (i) {
|
|
|
|
case 0: return first;
|
|
|
|
case 1: return second;
|
|
|
|
case 2: return third;
|
|
|
|
}
|
|
|
|
qLog(Error) << "CollectionModel::Grouping[] index out of range" << i;
|
|
|
|
|
|
|
|
return first;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::TotalSongCountUpdatedSlot(const int count) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
total_song_count_ = count;
|
|
|
|
emit TotalSongCountUpdated(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::TotalArtistCountUpdatedSlot(const int count) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
total_artist_count_ = count;
|
|
|
|
emit TotalArtistCountUpdated(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-06 22:26:29 +02:00
|
|
|
void CollectionModel::TotalAlbumCountUpdatedSlot(const int count) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
total_album_count_ = count;
|
|
|
|
emit TotalAlbumCountUpdated(count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-02-07 23:18:18 +01:00
|
|
|
void CollectionModel::ClearDiskCache() {
|
2020-05-16 19:17:06 +02:00
|
|
|
if (sIconCache) sIconCache->clear();
|
2020-02-07 23:18:18 +01:00
|
|
|
}
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
QDataStream &operator<<(QDataStream &s, const CollectionModel::Grouping &g) {
|
|
|
|
s << quint32(g.first) << quint32(g.second) << quint32(g.third);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream &operator>>(QDataStream &s, CollectionModel::Grouping &g) {
|
|
|
|
|
|
|
|
quint32 buf;
|
|
|
|
s >> buf;
|
|
|
|
g.first = CollectionModel::GroupBy(buf);
|
|
|
|
s >> buf;
|
|
|
|
g.second = CollectionModel::GroupBy(buf);
|
|
|
|
s >> buf;
|
|
|
|
g.third = CollectionModel::GroupBy(buf);
|
|
|
|
return s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|