1 /*
2  * Strawberry Music Player
3  * This file was part of Clementine.
4  * Copyright 2010, David Sansome <me@davidsansome.com>
5  *
6  * Strawberry is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Strawberry is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Strawberry.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef SMARTPLAYLISTSEARCH_H
22 #define SMARTPLAYLISTSEARCH_H
23 
24 #include "config.h"
25 
26 #include <QList>
27 #include <QString>
28 #include <QDataStream>
29 
30 #include "playlistgenerator.h"
31 #include "smartplaylistsearchterm.h"
32 
33 class SmartPlaylistSearch {
34 
35  public:
36   typedef QList<SmartPlaylistSearchTerm> TermList;
37 
38   // These values are persisted, so add to the end of the enum only
39   enum SearchType { Type_And = 0, Type_Or, Type_All, };
40 
41   // These values are persisted, so add to the end of the enum only
42   enum SortType { Sort_Random = 0, Sort_FieldAsc, Sort_FieldDesc, };
43 
44   explicit SmartPlaylistSearch();
45   explicit SmartPlaylistSearch(const SearchType type, const TermList &terms, const SortType sort_type, const SmartPlaylistSearchTerm::Field sort_field, const int limit = PlaylistGenerator::kDefaultLimit);
46 
47   bool is_valid() const;
48   bool operator==(const SmartPlaylistSearch &other) const;
49   bool operator!=(const SmartPlaylistSearch &other) const { return !(*this == other); }
50 
51   SearchType search_type_;
52   TermList terms_;
53   SortType sort_type_;
54   SmartPlaylistSearchTerm::Field sort_field_;
55   int limit_;
56 
57   // Not persisted, used to alter the behaviour of the query
58   QList<int> id_not_in_;
59   int first_item_;
60 
61   void Reset();
62   QString ToSql(const QString &songs_table) const;
63 
64 };
65 
66 QDataStream &operator<<(QDataStream &s, const SmartPlaylistSearch &search);
67 QDataStream &operator>>(QDataStream &s, SmartPlaylistSearch &search);
68 
69 #endif  // SMARTPLAYLISTSEARCH_H
70