2010-10-25 01:46:05 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SMARTPLAYLISTSEARCHTERM_H
|
|
|
|
#define SMARTPLAYLISTSEARCHTERM_H
|
|
|
|
|
|
|
|
#include <QDataStream>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
namespace smart_playlists {
|
|
|
|
|
|
|
|
class SearchTerm {
|
2010-10-25 01:46:05 +02:00
|
|
|
public:
|
|
|
|
// These values are persisted, so add to the end of the enum only
|
|
|
|
enum Field {
|
|
|
|
Field_Title = 0,
|
|
|
|
Field_Artist,
|
|
|
|
Field_Album,
|
|
|
|
Field_AlbumArtist,
|
|
|
|
Field_Composer,
|
|
|
|
Field_Length,
|
|
|
|
Field_Track,
|
|
|
|
Field_Disc,
|
|
|
|
Field_Year,
|
|
|
|
Field_Genre,
|
|
|
|
Field_BPM,
|
|
|
|
Field_Bitrate,
|
|
|
|
Field_Samplerate,
|
|
|
|
Field_Filesize,
|
|
|
|
Field_DateCreated,
|
|
|
|
Field_DateModified,
|
|
|
|
Field_Rating,
|
2010-11-17 21:21:04 +01:00
|
|
|
Field_Score,
|
2010-10-25 01:46:05 +02:00
|
|
|
Field_PlayCount,
|
|
|
|
Field_SkipCount,
|
|
|
|
Field_LastPlayed,
|
|
|
|
Field_Comment,
|
2010-12-15 16:50:22 +01:00
|
|
|
Field_Filepath,
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
FieldCount
|
|
|
|
};
|
|
|
|
|
|
|
|
// These values are persisted, so add to the end of the enum only
|
|
|
|
enum Operator {
|
|
|
|
// For text
|
|
|
|
Op_Contains = 0,
|
2012-12-10 09:10:24 +01:00
|
|
|
Op_NotContains = 1,
|
|
|
|
Op_StartsWith = 2,
|
|
|
|
Op_EndsWith = 3,
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
// For numbers
|
2012-12-10 09:10:24 +01:00
|
|
|
Op_GreaterThan = 4,
|
|
|
|
Op_LessThan = 5,
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
// For everything
|
2012-12-10 09:10:24 +01:00
|
|
|
Op_Equals = 6,
|
|
|
|
Op_NotEquals = 9,
|
2011-04-24 19:52:16 +02:00
|
|
|
|
|
|
|
// For numeric dates (e.g. in the last X days)
|
2012-12-10 09:10:24 +01:00
|
|
|
Op_NumericDate = 7,
|
2011-04-24 19:52:16 +02:00
|
|
|
// For relative dates
|
2012-12-10 09:10:24 +01:00
|
|
|
Op_RelativeDate = 8,
|
2011-05-04 20:47:48 +02:00
|
|
|
|
|
|
|
// For numeric dates (e.g. not in the last X days)
|
2012-12-10 09:10:24 +01:00
|
|
|
Op_NumericDateNot = 10,
|
2010-10-25 01:46:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
Type_Text,
|
|
|
|
Type_Date,
|
|
|
|
Type_Time,
|
|
|
|
Type_Number,
|
|
|
|
Type_Rating,
|
2012-12-10 09:37:38 +01:00
|
|
|
|
|
|
|
Type_Invalid
|
2010-10-25 01:46:05 +02:00
|
|
|
};
|
|
|
|
|
2011-04-24 19:52:16 +02:00
|
|
|
// These values are persisted, so add to the end of the enum only
|
|
|
|
enum DateType {
|
|
|
|
Date_Hour = 0,
|
|
|
|
Date_Day,
|
|
|
|
Date_Week,
|
|
|
|
Date_Month,
|
|
|
|
Date_Year,
|
|
|
|
};
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
SearchTerm();
|
|
|
|
SearchTerm(Field field, Operator op, const QVariant& value);
|
2010-11-17 21:21:04 +01:00
|
|
|
|
2010-10-25 01:46:05 +02:00
|
|
|
Field field_;
|
|
|
|
Operator operator_;
|
|
|
|
QVariant value_;
|
2011-04-24 19:52:16 +02:00
|
|
|
DateType date_;
|
|
|
|
// For relative dates, we need a second parameter, might be useful somewhere else
|
|
|
|
QVariant second_value_;
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
QString ToSql() const;
|
2010-10-29 20:41:49 +02:00
|
|
|
bool is_valid() const;
|
2010-11-20 13:20:26 +01:00
|
|
|
bool operator ==(const SearchTerm& other) const;
|
|
|
|
bool operator !=(const SearchTerm& other) const { return !(*this == other); }
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
static Type TypeOf(Field field);
|
|
|
|
static QList<Operator> OperatorsForType(Type type);
|
|
|
|
static QString OperatorText(Type type, Operator op);
|
|
|
|
static QString FieldName(Field field);
|
|
|
|
static QString FieldColumnName(Field field);
|
2010-11-01 21:24:44 +01:00
|
|
|
static QString FieldSortOrderText(Type type, bool ascending);
|
2011-04-24 19:52:16 +02:00
|
|
|
static QString DateName(DateType date, bool forQuery);
|
2010-10-25 01:46:05 +02:00
|
|
|
};
|
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
typedef QList<SearchTerm::Operator> OperatorList;
|
|
|
|
|
|
|
|
} // namespace
|
2010-10-25 01:46:05 +02:00
|
|
|
|
2010-11-18 21:19:33 +01:00
|
|
|
QDataStream& operator <<(QDataStream& s, const smart_playlists::SearchTerm& term);
|
|
|
|
QDataStream& operator >>(QDataStream& s, smart_playlists::SearchTerm& term);
|
2010-10-25 01:46:05 +02:00
|
|
|
|
|
|
|
#endif // SMARTPLAYLISTSEARCHTERM_H
|