strawberry-audio-player-win.../src/smartplaylists/smartplaylistsearchterm.h

148 lines
3.7 KiB
C
Raw Permalink Normal View History

/*
* 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>
#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,
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 {
// For text
2023-02-18 14:09:27 +01:00
Contains = 0,
NotContains = 1,
StartsWith = 2,
EndsWith = 3,
// For numbers
2023-02-18 14:09:27 +01:00
GreaterThan = 4,
LessThan = 5,
// For everything
2023-02-18 14:09:27 +01:00
Equals = 6,
NotEquals = 9,
// For numeric dates (e.g. in the last X days)
2023-02-18 14:09:27 +01:00
NumericDate = 7,
// For relative dates
2023-02-18 14:09:27 +01:00
RelativeDate = 8,
// For numeric dates (e.g. not in the last X days)
2023-02-18 14:09:27 +01:00
NumericDateNot = 10,
2023-02-18 14:09:27 +01:00
Empty = 11,
NotEmpty = 12,
// Next value = 13
};
2023-02-18 14:09:27 +01:00
using OperatorList = QList<Operator>;
enum class Type {
Text,
Date,
Time,
Number,
Rating,
Invalid
};
// 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
};
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_;
// 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);
};
QDataStream &operator<<(QDataStream &s, const SmartPlaylistSearchTerm &term);
QDataStream &operator>>(QDataStream &s, SmartPlaylistSearchTerm &term);
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::Field)
2023-02-18 14:09:27 +01:00
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::Operator)
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::OperatorList)
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::Type)
Q_DECLARE_METATYPE(SmartPlaylistSearchTerm::DateType)
2023-02-18 14:09:27 +01:00
#endif // SMARTPLAYLISTSEARCHTERM_H