mirror of
https://github.com/strawberrymusicplayer/strawberry
synced 2024-12-18 11:39:31 +01:00
parent
b0966f14e6
commit
bfa9a1eb8a
@ -119,10 +119,11 @@ CollectionModel::CollectionModel(CollectionBackend *backend, Application *app, Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
QIcon nocover = IconLoader::Load("cdcase");
|
QIcon nocover = IconLoader::Load("cdcase");
|
||||||
|
if (!nocover.isNull()) {
|
||||||
no_cover_icon_ = nocover.pixmap(nocover.availableSizes().last()).scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
no_cover_icon_ = nocover.pixmap(nocover.availableSizes().last()).scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
//no_cover_icon_ = QPixmap(":/pictures/noalbumart.png").scaled(kPrettyCoverSize, kPrettyCoverSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
}
|
||||||
|
|
||||||
if (sIconCache == nullptr) {
|
if (app_ && !sIconCache) {
|
||||||
sIconCache = new QNetworkDiskCache(this);
|
sIconCache = new QNetworkDiskCache(this);
|
||||||
sIconCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" + kPixmapDiskCacheDir);
|
sIconCache->setCacheDirectory(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/" + kPixmapDiskCacheDir);
|
||||||
}
|
}
|
||||||
@ -191,7 +192,9 @@ void CollectionModel::ReloadSettings() {
|
|||||||
|
|
||||||
QPixmapCache::setCacheLimit(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsCacheSize, CollectionSettingsPage::kSettingsCacheSizeUnit, CollectionSettingsPage::kSettingsCacheSizeDefault) / 1024);
|
QPixmapCache::setCacheLimit(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsCacheSize, CollectionSettingsPage::kSettingsCacheSizeUnit, CollectionSettingsPage::kSettingsCacheSizeDefault) / 1024);
|
||||||
|
|
||||||
|
if (sIconCache) {
|
||||||
sIconCache->setMaximumCacheSize(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsDiskCacheSize, CollectionSettingsPage::kSettingsDiskCacheSizeUnit, CollectionSettingsPage::kSettingsDiskCacheSizeDefault));
|
sIconCache->setMaximumCacheSize(MaximumCacheSize(&s, CollectionSettingsPage::kSettingsDiskCacheSize, CollectionSettingsPage::kSettingsDiskCacheSizeUnit, CollectionSettingsPage::kSettingsDiskCacheSizeDefault));
|
||||||
|
}
|
||||||
|
|
||||||
s.endGroup();
|
s.endGroup();
|
||||||
|
|
||||||
@ -512,7 +515,7 @@ void CollectionModel::SongsDeleted(const SongList &songs) {
|
|||||||
// Remove from pixmap cache
|
// Remove from pixmap cache
|
||||||
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node));
|
const QString cache_key = AlbumIconPixmapCacheKey(ItemToIndex(node));
|
||||||
QPixmapCache::remove(cache_key);
|
QPixmapCache::remove(cache_key);
|
||||||
if (use_disk_cache_) sIconCache->remove(QUrl(cache_key));
|
if (use_disk_cache_ && sIconCache) sIconCache->remove(QUrl(cache_key));
|
||||||
if (pending_cache_keys_.contains(cache_key)) {
|
if (pending_cache_keys_.contains(cache_key)) {
|
||||||
pending_cache_keys_.remove(cache_key);
|
pending_cache_keys_.remove(cache_key);
|
||||||
}
|
}
|
||||||
@ -587,7 +590,7 @@ QVariant CollectionModel::AlbumIcon(const QModelIndex &idx) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to load it from the disk cache
|
// Try to load it from the disk cache
|
||||||
if (use_disk_cache_) {
|
if (use_disk_cache_ && sIconCache) {
|
||||||
std::unique_ptr<QIODevice> cache(sIconCache->data(QUrl(cache_key)));
|
std::unique_ptr<QIODevice> cache(sIconCache->data(QUrl(cache_key)));
|
||||||
if (cache) {
|
if (cache) {
|
||||||
QImage cached_image;
|
QImage cached_image;
|
||||||
@ -639,7 +642,7 @@ void CollectionModel::AlbumCoverLoaded(const quint64 id, const AlbumCoverLoaderR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we have a valid cover not already in the disk cache
|
// If we have a valid cover not already in the disk cache
|
||||||
if (use_disk_cache_) {
|
if (use_disk_cache_ && sIconCache) {
|
||||||
std::unique_ptr<QIODevice> cached_img(sIconCache->data(QUrl(cache_key)));
|
std::unique_ptr<QIODevice> cached_img(sIconCache->data(QUrl(cache_key)));
|
||||||
if (!cached_img && !result.image_scaled.isNull()) {
|
if (!cached_img && !result.image_scaled.isNull()) {
|
||||||
QNetworkCacheMetaData item_metadata;
|
QNetworkCacheMetaData item_metadata;
|
||||||
@ -1558,6 +1561,7 @@ int CollectionModel::MaximumCacheSize(QSettings *s, const char *size_id, const c
|
|||||||
} while (unit > 0);
|
} while (unit > 0);
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CollectionModel::GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const {
|
void CollectionModel::GetChildSongs(CollectionItem *item, QList<QUrl> *urls, SongList *songs, QSet<int> *song_ids) const {
|
||||||
@ -1688,7 +1692,7 @@ void CollectionModel::TotalAlbumCountUpdatedSlot(const int count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CollectionModel::ClearDiskCache() {
|
void CollectionModel::ClearDiskCache() {
|
||||||
sIconCache->clear();
|
if (sIconCache) sIconCache->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDataStream &operator<<(QDataStream &s, const CollectionModel::Grouping &g) {
|
QDataStream &operator<<(QDataStream &s, const CollectionModel::Grouping &g) {
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QValidator>
|
#include <QValidator>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
#include <QTextDocument>
|
||||||
#include <QTextFormat>
|
#include <QTextFormat>
|
||||||
|
|
||||||
#include "core/arraysize.h"
|
#include "core/arraysize.h"
|
||||||
@ -44,8 +45,6 @@
|
|||||||
|
|
||||||
#include "organiseformat.h"
|
#include "organiseformat.h"
|
||||||
|
|
||||||
class QTextDocument;
|
|
||||||
|
|
||||||
const char *OrganiseFormat::kTagPattern = "\\%([a-zA-Z]*)";
|
const char *OrganiseFormat::kTagPattern = "\\%([a-zA-Z]*)";
|
||||||
const char *OrganiseFormat::kBlockPattern = "\\{([^{}]+)\\}";
|
const char *OrganiseFormat::kBlockPattern = "\\{([^{}]+)\\}";
|
||||||
const QStringList OrganiseFormat::kKnownTags = QStringList() << "title"
|
const QStringList OrganiseFormat::kKnownTags = QStringList() << "title"
|
||||||
@ -145,7 +144,12 @@ QString OrganiseFormat::GetFilenameForSong(const Song &song) const {
|
|||||||
|
|
||||||
QFileInfo info(filename);
|
QFileInfo info(filename);
|
||||||
QString extension = info.suffix();
|
QString extension = info.suffix();
|
||||||
QString filepath = info.path() + "/" + info.completeBaseName();
|
QString filepath;
|
||||||
|
if (!info.path().isEmpty() && info.path() != ".") {
|
||||||
|
filepath.append(info.path());
|
||||||
|
filepath.append("/");
|
||||||
|
}
|
||||||
|
filepath.append(info.completeBaseName());
|
||||||
|
|
||||||
// Fix any parts of the path that start with dots.
|
// Fix any parts of the path that start with dots.
|
||||||
QStringList parts_old = filepath.split("/");
|
QStringList parts_old = filepath.split("/");
|
||||||
|
@ -87,7 +87,6 @@ if(Qt5Test_FOUND AND GTEST_FOUND AND GMOCK_LIBRARY)
|
|||||||
add_test_file(src/song_test.cpp false)
|
add_test_file(src/song_test.cpp false)
|
||||||
add_test_file(src/collectionbackend_test.cpp false)
|
add_test_file(src/collectionbackend_test.cpp false)
|
||||||
add_test_file(src/collectionmodel_test.cpp true)
|
add_test_file(src/collectionmodel_test.cpp true)
|
||||||
add_test_file(src/playlist_test.cpp true)
|
|
||||||
add_test_file(src/songplaylistitem_test.cpp false)
|
add_test_file(src/songplaylistitem_test.cpp false)
|
||||||
add_test_file(src/organiseformat_test.cpp false)
|
add_test_file(src/organiseformat_test.cpp false)
|
||||||
|
|
||||||
|
@ -75,6 +75,8 @@ class CollectionModelTest : public ::testing::Test {
|
|||||||
Song AddSong(const QString& title, const QString& artist, const QString& album, int length) {
|
Song AddSong(const QString& title, const QString& artist, const QString& album, int length) {
|
||||||
Song song;
|
Song song;
|
||||||
song.Init(title, artist, album, length);
|
song.Init(title, artist, album, length);
|
||||||
|
song.set_mtime(0);
|
||||||
|
song.set_ctime(0);
|
||||||
return AddSong(song);
|
return AddSong(song);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,6 +113,8 @@ TEST_F(CollectionModelTest, CompilationAlbums) {
|
|||||||
Song song;
|
Song song;
|
||||||
song.Init("Title", "Artist", "Album", 123);
|
song.Init("Title", "Artist", "Album", 123);
|
||||||
song.set_compilation(true);
|
song.set_compilation(true);
|
||||||
|
song.set_mtime(0);
|
||||||
|
song.set_ctime(0);
|
||||||
|
|
||||||
AddSong(song);
|
AddSong(song);
|
||||||
model_->Init(false);
|
model_->Init(false);
|
||||||
@ -200,6 +204,8 @@ TEST_F(CollectionModelTest, VariousArtistSongs) {
|
|||||||
QString n = QString::number(i+1);
|
QString n = QString::number(i+1);
|
||||||
Song song;
|
Song song;
|
||||||
song.Init("Title " + n, "Artist " + n, "Album", 0);
|
song.Init("Title " + n, "Artist " + n, "Album", 0);
|
||||||
|
song.set_mtime(0);
|
||||||
|
song.set_ctime(0);
|
||||||
songs << song;
|
songs << song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ TEST_F(OrganiseFormatTest, BasicReplace) {
|
|||||||
format_.set_format("%album %albumartist %artist %bitrate %comment %composer %performer %grouping %disc %genre %length %samplerate %bitdepth %title %track %year");
|
format_.set_format("%album %albumartist %artist %bitrate %comment %composer %performer %grouping %disc %genre %length %samplerate %bitdepth %title %track %year");
|
||||||
|
|
||||||
ASSERT_TRUE(format_.IsValid());
|
ASSERT_TRUE(format_.IsValid());
|
||||||
|
|
||||||
EXPECT_EQ("album_albumartist_artist_123_comment_composer_performer_grouping_789_genre_987_654_32_title_321_2010", format_.GetFilenameForSong(song_));
|
EXPECT_EQ("album_albumartist_artist_123_comment_composer_performer_grouping_789_genre_987_654_32_title_321_2010", format_.GetFilenameForSong(song_));
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -135,11 +136,12 @@ TEST_F(OrganiseFormatTest, ReplaceNonAscii) {
|
|||||||
|
|
||||||
format_.set_remove_non_ascii(false);
|
format_.set_remove_non_ascii(false);
|
||||||
EXPECT_EQ(QString::fromUtf8("Röyksopp"), format_.GetFilenameForSong(song_));
|
EXPECT_EQ(QString::fromUtf8("Röyksopp"), format_.GetFilenameForSong(song_));
|
||||||
|
|
||||||
format_.set_remove_non_ascii(true);
|
format_.set_remove_non_ascii(true);
|
||||||
EXPECT_EQ("Royksopp", format_.GetFilenameForSong(song_));
|
EXPECT_EQ("Royksopp", format_.GetFilenameForSong(song_));
|
||||||
|
|
||||||
song_.set_artist(QString::fromUtf8("Владимир Высоцкий"));
|
song_.set_artist(QString::fromUtf8("Владимир Высоцкий"));
|
||||||
EXPECT_EQ("_________________", format_.GetFilenameForSong(song_));
|
EXPECT_EQ("????????_????????", format_.GetFilenameForSong(song_));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,15 +53,15 @@ class PlaylistTest : public ::testing::Test {
|
|||||||
Song metadata;
|
Song metadata;
|
||||||
metadata.Init(title, artist, album, length);
|
metadata.Init(title, artist, album, length);
|
||||||
|
|
||||||
//MockPlaylistItem* ret = new MockPlaylistItem;
|
MockPlaylistItem *ret = new MockPlaylistItem;
|
||||||
//EXPECT_CALL(*ret, Metadata()).WillRepeatedly(Return(metadata));
|
//EXPECT_CALL(*ret, Metadata()).WillRepeatedly(Return(metadata));
|
||||||
|
|
||||||
//return ret;
|
return ret;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<PlaylistItem> MakeMockItemP(const QString& title, const QString& artist = QString(), const QString& album = QString(), int length = 123) const {
|
PlaylistItemPtr MakeMockItemP(const QString& title, const QString& artist = QString(), const QString& album = QString(), int length = 123) const {
|
||||||
return std::shared_ptr<PlaylistItem>(MakeMockItem(title, artist, album, length));
|
return PlaylistItemPtr(MakeMockItem(title, artist, album, length));
|
||||||
}
|
}
|
||||||
|
|
||||||
Playlist playlist_;
|
Playlist playlist_;
|
||||||
@ -76,7 +76,7 @@ TEST_F(PlaylistTest, Basic) {
|
|||||||
TEST_F(PlaylistTest, InsertItems) {
|
TEST_F(PlaylistTest, InsertItems) {
|
||||||
|
|
||||||
MockPlaylistItem* item = MakeMockItem("Title", "Artist", "Album", 123);
|
MockPlaylistItem* item = MakeMockItem("Title", "Artist", "Album", 123);
|
||||||
std::shared_ptr<PlaylistItem> item_ptr(item);
|
PlaylistItemPtr item_ptr(item);
|
||||||
|
|
||||||
// Insert the item
|
// Insert the item
|
||||||
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
EXPECT_EQ(0, playlist_.rowCount(QModelIndex()));
|
||||||
|
Loading…
Reference in New Issue
Block a user