2020-09-17 17:50:17 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SMARTPLAYLISTSEARCHTERM_H
|
|
|
|
#define SMARTPLAYLISTSEARCHTERM_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2023-07-12 18:13:02 +02:00
|
|
|
#include <QMetaType>
|
2020-09-17 17:50:17 +02:00
|
|
|
#include <QList>
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QString>
|
|
|
|
|
|
|
|
class SmartPlaylistSearchTerm {
|
|
|
|
public:
|
|
|
|
// These values are persisted, so add to the end of the enum only
|
2023-02-18 14:09:27 +01:00
|
|
|
enum class Field {
|
|
|
|
AlbumArtist = 0,
|
|
|
|
Artist,
|
|
|
|
Album,
|
|
|
|
Title,
|
|
|
|
Track,
|
|
|
|
Disc,
|
|
|
|
Year,
|
|
|
|
OriginalYear,
|
|
|
|
Genre,
|
|
|
|
Composer,
|
|
|
|
Performer,
|
|
|
|
Grouping,
|
|
|
|
Comment,
|
|
|
|
Length,
|
|
|
|
Filepath,
|
|
|
|
Filetype,
|
|
|
|
Filesize,
|
|
|
|
DateCreated,
|
|
|
|
DateModified,
|
|
|
|
PlayCount,
|
|
|
|
SkipCount,
|
|
|
|
LastPlayed,
|
|
|
|
Rating,
|
|
|
|
Samplerate,
|
|
|
|
Bitdepth,
|
|
|
|
Bitrate,
|
2020-09-17 17:50:17 +02:00
|
|
|
FieldCount
|
|
|
|
};
|
|
|
|
|
|
|
|
// These values are persisted, so add to the end of the enum only
|
2023-02-18 14:09:27 +01:00
|
|
|
enum class Operator {
|
2020-09-17 17:50:17 +02:00
|
|
|
// For text
|
2023-02-18 14:09:27 +01:00
|
|
|
Contains = 0,
|
|
|
|
NotContains = 1,
|
|
|
|
StartsWith = 2,
|
|
|
|
EndsWith = 3,
|
2020-09-17 17:50:17 +02:00
|
|
|
|
|
|
|
// For numbers
|
2023-02-18 14:09:27 +01:00
|
|
|
GreaterThan = 4,
|
|
|
|
LessThan = 5,
|
2020-09-17 17:50:17 +02:00
|
|
|
|
|
|
|
// For everything
|
2023-02-18 14:09:27 +01:00
|
|
|
Equals = 6,
|
|
|
|
NotEquals = 9,
|
2020-09-17 17:50:17 +02:00
|
|
|
|
|
|
|
// For numeric dates (e.g. in the last X days)
|
2023-02-18 14:09:27 +01:00
|
|
|
NumericDate = 7,
|
2020-09-17 17:50:17 +02:00
|
|
|
// For relative dates
|
2023-02-18 14:09:27 +01:00
|
|
|
RelativeDate = 8,
|
2020-09-17 17:50:17 +02:00
|
|
|
|
|
|
|
// For numeric dates (e.g. not in the last X days)
|
2023-02-18 14:09:27 +01:00
|
|
|
NumericDateNot = 10,
|
2020-09-17 17:50:17 +02:00
|
|
|
|
2023-02-18 14:09:27 +01:00
|
|
|
Empty = 11,
|
|
|
|
NotEmpty = 12,
|
2020-09-17 17:50:17 +02:00
|
|
|
|
|
|
|
// Next value = 13
|
|
|
|
};
|
2023-02-18 14:09:27 +01:00
|
|
|
using OperatorList = QList<Operator>;
|
|
|
|
|
|
|
|
enum class Type {
|
|
|
|
Text,
|
|
|
|
Date,
|
|
|
|
Time,
|
|
|
|
Number,
|
|
|
|
Rating,
|
|
|
|
Invalid
|
2020-09-17 17:50:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// These values are persisted, so add to the end of the enum only
|
2023-02-18 14:09:27 +01:00
|
|
|
enum class DateType {
|
|
|
|
Hour = 0,
|
|
|
|
Day,
|
|
|
|
Week,
|
|
|
|
Month,
|
|
|
|
Year
|
2020-09-17 17:50:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
explicit SmartPlaylistSearchTerm();
|
|
|
|
explicit SmartPlaylistSearchTerm(const Field field, const Operator op, const QVariant &value);
|
|
|
|
|
|
|
|
Field field_;
|
|
|
|
Operator operator_;
|
|
|
|
QVariant value_;
|
2023-02-18 14:09:27 +01:00
|
|
|
DateType datetype_;
|
2020-09-17 17:50:17 +02:00
|
|
|
// For relative dates, we need a second parameter, might be useful somewhere else
|
|
|
|
QVariant second_value_;
|
|
|
|
|
|
|
|
QString ToSql() const;
|
|
|
|
bool is_valid() const;
|
|
|
|
bool operator==(const SmartPlaylistSearchTerm &other) const;
|
|
|
|
bool operator!=(const SmartPlaylistSearchTerm &other) const { return !(*this == other); }
|
|
|
|
|
|
|
|
static Type TypeOf(const Field field);
|
|
|
|
static QList<Operator> OperatorsForType(const Type type);
|
|
|
|
static QString OperatorText(const Type type, const Operator op);
|
|
|
|
static QString FieldName(const Field field);
|
|
|
|
static QString FieldColumnName(const Field field);
|
|
|
|
static QString FieldSortOrderText(const Type type, const bool ascending);
|
2023-02-18 14:09:27 +01:00
|
|
|
static QString DateName(const DateType datetype, const bool forQuery);
|
2020-09-17 17:50:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
QDataStream &operator<<(QDataStream &s, const SmartPlaylistSearchTerm &term);
|
|
|
|
QDataStream &operator>>(QDataStream &s, SmartPlaylistSearchTerm &term);
|
|
|
|
|
2023-04-07 23:05:07 +02:00
|
|
|
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::Field)
|
2023-02-18 14:09:27 +01:00
|
|
|
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::Operator)
|
|
|
|
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::OperatorList)
|
2023-04-07 23:05:07 +02:00
|
|
|
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::Type)
|
|
|
|
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::DateType)
|
2023-02-18 14:09:27 +01:00
|
|
|
|
2020-09-17 17:50:17 +02:00
|
|
|
#endif // SMARTPLAYLISTSEARCHTERM_H
|