From f563b7da40b2e2ba1c1e2e641f8ed2b37960f264 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Tue, 16 Jun 2020 15:23:30 -0700 Subject: [PATCH] Add DbPlaylistItem base class to LibraryPlaylistItem This will be used to move items from non-library databases away from the LibraryPlaylistItem class. --- src/CMakeLists.txt | 2 ++ src/library/libraryplaylistitem.cpp | 20 ++------------ src/library/libraryplaylistitem.h | 15 ++--------- src/playlist/dbplaylistitem.cpp | 42 +++++++++++++++++++++++++++++ src/playlist/dbplaylistitem.h | 42 +++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 31 deletions(-) create mode 100644 src/playlist/dbplaylistitem.cpp create mode 100644 src/playlist/dbplaylistitem.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e5c9977c9..c65725ce9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -221,6 +221,7 @@ set(SOURCES networkremote/songsender.cpp networkremote/zeroconf.cpp + playlist/dbplaylistitem.cpp playlist/dynamicplaylistcontrols.cpp playlist/playlist.cpp playlist/playlistbackend.cpp @@ -521,6 +522,7 @@ set(HEADERS networkremote/remoteclient.h networkremote/songsender.h + playlist/dbplaylistitem.h playlist/dynamicplaylistcontrols.h playlist/playlist.h playlist/playlistbackend.h diff --git a/src/library/libraryplaylistitem.cpp b/src/library/libraryplaylistitem.cpp index d05e21d0b..d30cb04fe 100644 --- a/src/library/libraryplaylistitem.cpp +++ b/src/library/libraryplaylistitem.cpp @@ -21,12 +21,10 @@ #include LibraryPlaylistItem::LibraryPlaylistItem(const QString& type) - : PlaylistItem(type) {} + : DbPlaylistItem(type) {} LibraryPlaylistItem::LibraryPlaylistItem(const Song& song) - : PlaylistItem("Library"), song_(song) {} - -QUrl LibraryPlaylistItem::Url() const { return song_.url(); } + : DbPlaylistItem("Library", song) {} void LibraryPlaylistItem::Reload() { TagReaderClient::Instance()->ReadFileBlocking(song_.url().toLocalFile(), @@ -39,17 +37,3 @@ bool LibraryPlaylistItem::InitFromQuery(const SqlRow& query) { return song_.is_valid(); } - -QVariant LibraryPlaylistItem::DatabaseValue(DatabaseColumn column) const { - switch (column) { - case Column_LibraryId: - return song_.id(); - default: - return PlaylistItem::DatabaseValue(column); - } -} - -Song LibraryPlaylistItem::Metadata() const { - if (HasTemporaryMetadata()) return temp_metadata_; - return song_; -} diff --git a/src/library/libraryplaylistitem.h b/src/library/libraryplaylistitem.h index dbfd08850..bbd15d2af 100644 --- a/src/library/libraryplaylistitem.h +++ b/src/library/libraryplaylistitem.h @@ -19,9 +19,9 @@ #define LIBRARYPLAYLISTITEM_H #include "core/song.h" -#include "playlist/playlistitem.h" +#include "playlist/dbplaylistitem.h" -class LibraryPlaylistItem : public PlaylistItem { +class LibraryPlaylistItem : public DbPlaylistItem { public: LibraryPlaylistItem(const QString& type); LibraryPlaylistItem(const Song& song); @@ -29,18 +29,7 @@ class LibraryPlaylistItem : public PlaylistItem { bool InitFromQuery(const SqlRow& query); void Reload(); - Song Metadata() const; - void SetMetadata(const Song& song) { song_ = song; } - - QUrl Url() const; - bool IsLocalLibraryItem() const { return true; } - - protected: - QVariant DatabaseValue(DatabaseColumn column) const; - - protected: - Song song_; }; #endif // LIBRARYPLAYLISTITEM_H diff --git a/src/playlist/dbplaylistitem.cpp b/src/playlist/dbplaylistitem.cpp new file mode 100644 index 000000000..a746a88ae --- /dev/null +++ b/src/playlist/dbplaylistitem.cpp @@ -0,0 +1,42 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + Copyright 2020, Jim Broadus + + 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 . +*/ + +#include "dbplaylistitem.h" +#include "core/tagreaderclient.h" + +DbPlaylistItem::DbPlaylistItem(const QString& type) + : PlaylistItem(type) {} + +DbPlaylistItem::DbPlaylistItem(const QString& type, const Song& song) + : PlaylistItem(type), song_(song) {} + +QUrl DbPlaylistItem::Url() const { return song_.url(); } + +QVariant DbPlaylistItem::DatabaseValue(DatabaseColumn column) const { + switch (column) { + case Column_LibraryId: + return song_.id(); + default: + return PlaylistItem::DatabaseValue(column); + } +} + +Song DbPlaylistItem::Metadata() const { + if (HasTemporaryMetadata()) return temp_metadata_; + return song_; +} diff --git a/src/playlist/dbplaylistitem.h b/src/playlist/dbplaylistitem.h new file mode 100644 index 000000000..3096f93f4 --- /dev/null +++ b/src/playlist/dbplaylistitem.h @@ -0,0 +1,42 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + Copyright 2020, Jim Broadus + + 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 . +*/ + +#ifndef DBPLAYLISTITEM_H +#define DBPLAYLISTITEM_H + +#include "core/song.h" +#include "playlist/playlistitem.h" + +class DbPlaylistItem : public PlaylistItem { + public: + DbPlaylistItem(const QString& type); + DbPlaylistItem(const QString& type, const Song& song); + + Song Metadata() const; + void SetMetadata(const Song& song) { song_ = song; } + + QUrl Url() const; + + protected: + QVariant DatabaseValue(DatabaseColumn column) const; + + protected: + Song song_; +}; + +#endif // DBPLAYLISTITEM_H