strawberry-audio-player-win.../src/playlist/playlistitem.h

147 lines
5.0 KiB
C
Raw Normal View History

2018-02-27 18:06:05 +01:00
/*
* Strawberry Music Player
* This file was part of Clementine.
* Copyright 2010, David Sansome <me@davidsansome.com>
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, 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:10:03 +02:00
*
2018-02-27 18:06:05 +01:00
*/
#ifndef PLAYLISTITEM_H
#define PLAYLISTITEM_H
#include "config.h"
#include <memory>
#include <QFuture>
#include <QMetaType>
#include <QList>
#include <QMap>
#include <QSet>
#include <QVariant>
#include <QString>
2018-02-27 18:06:05 +01:00
#include <QUrl>
#include <QColor>
2018-02-27 18:06:05 +01:00
#include "core/shared_ptr.h"
2018-02-27 18:06:05 +01:00
#include "core/song.h"
2020-02-08 15:03:11 +01:00
class QAction;
class SqlQuery;
2018-02-27 18:06:05 +01:00
class SqlRow;
using std::enable_shared_from_this;
class PlaylistItem : public enable_shared_from_this<PlaylistItem> {
2018-02-27 18:06:05 +01:00
public:
2021-06-20 19:04:08 +02:00
explicit PlaylistItem(const Song::Source source) : should_skip_(false), source_(source) {}
2018-02-27 18:06:05 +01:00
virtual ~PlaylistItem();
static SharedPtr<PlaylistItem> NewFromSource(const Song::Source source);
static SharedPtr<PlaylistItem> NewFromSong(const Song &song);
2018-02-27 18:06:05 +01:00
2023-02-18 14:09:27 +01:00
enum class Option {
2018-02-27 18:06:05 +01:00
Default = 0x00,
// Disables the "pause" action.
PauseDisabled = 0x01,
// Disables the seek slider.
SeekDisabled = 0x04,
};
2019-09-15 20:27:32 +02:00
Q_DECLARE_FLAGS(Options, Option)
2018-02-27 18:06:05 +01:00
2018-09-08 12:38:02 +02:00
virtual Song::Source source() const { return source_; }
2018-02-27 18:06:05 +01:00
2023-02-18 14:09:27 +01:00
virtual Options options() const { return Option::Default; }
2018-02-27 18:06:05 +01:00
virtual QList<QAction*> actions() { return QList<QAction*>(); }
virtual bool InitFromQuery(const SqlRow &query) = 0;
void BindToQuery(SqlQuery *query) const;
2018-02-27 18:06:05 +01:00
virtual void Reload() {}
QFuture<void> BackgroundReload();
virtual Song Metadata() const = 0;
virtual Song OriginalMetadata() const = 0;
2018-02-27 18:06:05 +01:00
virtual QUrl Url() const = 0;
virtual void SetMetadata(const Song&) {}
2018-02-27 18:06:05 +01:00
void SetTemporaryMetadata(const Song &metadata);
void UpdateTemporaryMetadata(const Song &metadata);
2018-02-27 18:06:05 +01:00
void ClearTemporaryMetadata();
bool HasTemporaryMetadata() const { return temp_metadata_.is_valid(); }
Song StreamMetadata() { return HasTemporaryMetadata() ? temp_metadata_ : Metadata(); }
QUrl StreamUrl() const { return HasTemporaryMetadata() && temp_metadata_.effective_stream_url().isValid() ? temp_metadata_.effective_stream_url() : Url(); }
std::optional<double> effective_ebur128_integrated_loudness_lufs() const { return HasTemporaryMetadata() && temp_metadata_.is_valid() ? temp_metadata_.ebur128_integrated_loudness_lufs() : Metadata().ebur128_integrated_loudness_lufs(); }
qint64 effective_beginning_nanosec() const { return HasTemporaryMetadata() && temp_metadata_.is_valid() && temp_metadata_.beginning_nanosec() != -1 ? temp_metadata_.beginning_nanosec() : Metadata().beginning_nanosec(); }
qint64 effective_end_nanosec() const { return HasTemporaryMetadata() && temp_metadata_.is_valid() && temp_metadata_.end_nanosec() != -1 ? temp_metadata_.end_nanosec() : Metadata().end_nanosec(); }
2018-02-27 18:06:05 +01:00
virtual void SetArtManual(const QUrl &cover_url) = 0;
2018-02-27 18:06:05 +01:00
// Background colors.
2021-06-20 19:04:08 +02:00
void SetBackgroundColor(const short priority, const QColor &color);
bool HasBackgroundColor(const short priority) const;
void RemoveBackgroundColor(const short priority);
2018-02-27 18:06:05 +01:00
QColor GetCurrentBackgroundColor() const;
bool HasCurrentBackgroundColor() const;
// Foreground colors.
2021-06-20 19:04:08 +02:00
void SetForegroundColor(const short priority, const QColor &color);
bool HasForegroundColor(const short priority) const;
void RemoveForegroundColor(const short priority);
2018-02-27 18:06:05 +01:00
QColor GetCurrentForegroundColor() const;
bool HasCurrentForegroundColor() const;
// Convenience function to find out whether this item is from the local collection, as opposed to a device, a file on disk, or a stream.
2022-08-28 02:44:37 +02:00
// Remember that even if this returns true, the collection item might be invalid, so you might want to check that its id is not equal to -1 before actually using it.
2018-02-27 18:06:05 +01:00
virtual bool IsLocalCollectionItem() const { return false; }
2021-06-20 19:04:08 +02:00
void SetShouldSkip(const bool val);
2018-02-27 18:06:05 +01:00
bool GetShouldSkip() const;
protected:
bool should_skip_;
2018-09-08 12:38:02 +02:00
enum DatabaseColumn { Column_CollectionId };
2018-02-27 18:06:05 +01:00
virtual QVariant DatabaseValue(DatabaseColumn) const {
return QVariant(QString());
2018-02-27 18:06:05 +01:00
}
virtual Song DatabaseSongMetadata() const { return Song(); }
2018-09-08 12:38:02 +02:00
Song::Source source_;
2018-02-27 18:06:05 +01:00
Song temp_metadata_;
QMap<short, QColor> background_colors_;
QMap<short, QColor> foreground_colors_;
2021-06-20 19:04:08 +02:00
Q_DISABLE_COPY(PlaylistItem)
2018-02-27 18:06:05 +01:00
};
using PlaylistItemPtr = SharedPtr<PlaylistItem>;
2023-02-18 14:09:27 +01:00
using PlaylistItemPtrList = QList<PlaylistItemPtr>;
2018-02-27 18:06:05 +01:00
Q_DECLARE_METATYPE(PlaylistItemPtr)
2023-02-18 14:09:27 +01:00
Q_DECLARE_METATYPE(PlaylistItemPtrList)
2018-02-27 18:06:05 +01:00
Q_DECLARE_OPERATORS_FOR_FLAGS(PlaylistItem::Options)
#endif // PLAYLISTITEM_H