adjust indentation of remaining classes in headers
[ncmpcpp.git] / src / search_engine.h
blob785fcf1cfee6af1419fdb3afaeea7ed3d3d84a6d
1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef _SEARCH_ENGINE_H
22 #define _SEARCH_ENGINE_H
24 #include <cassert>
26 #include "interfaces.h"
27 #include "mpdpp.h"
28 #include "screen.h"
30 struct SEItem
32 SEItem() : isThisSong(false), itsBuffer(0) { }
33 SEItem(NC::Buffer *buf) : isThisSong(false), itsBuffer(buf) { }
34 SEItem(const MPD::Song &s) : isThisSong(true), itsSong(s) { }
35 SEItem(const SEItem &ei) { *this = ei; }
36 ~SEItem() {
37 if (!isThisSong)
38 delete itsBuffer;
41 NC::Buffer &mkBuffer() {
42 assert(!isThisSong);
43 delete itsBuffer;
44 itsBuffer = new NC::Buffer();
45 return *itsBuffer;
48 bool isSong() const { return isThisSong; }
50 NC::Buffer &buffer() { assert(!isThisSong && itsBuffer); return *itsBuffer; }
51 MPD::Song &song() { assert(isThisSong); return itsSong; }
53 const NC::Buffer &buffer() const { assert(!isThisSong && itsBuffer); return *itsBuffer; }
54 const MPD::Song &song() const { assert(isThisSong); return itsSong; }
56 SEItem &operator=(const SEItem &se) {
57 if (this == &se)
58 return *this;
59 isThisSong = se.isThisSong;
60 if (se.isThisSong)
61 itsSong = se.itsSong;
62 else if (se.itsBuffer)
63 itsBuffer = new NC::Buffer(*se.itsBuffer);
64 else
65 itsBuffer = 0;
66 return *this;
69 private:
70 bool isThisSong;
72 NC::Buffer *itsBuffer;
73 MPD::Song itsSong;
76 struct SearchEngine : public Screen< NC::Menu<SEItem> >, public Filterable, public HasSongs, public Searchable
78 // Screen< NC::Menu<SEItem> > implementation
79 virtual void resize() OVERRIDE;
80 virtual void switchTo() OVERRIDE;
82 virtual std::wstring title() OVERRIDE;
84 virtual void update() OVERRIDE { }
86 virtual void enterPressed() OVERRIDE;
87 virtual void spacePressed() OVERRIDE;
88 virtual void mouseButtonPressed(MEVENT me) OVERRIDE;
90 virtual bool isTabbable() OVERRIDE { return true; }
91 virtual bool isMergable() OVERRIDE { return true; }
93 // Filterable implementation
94 virtual bool allowsFiltering() OVERRIDE;
95 virtual std::string currentFilter() OVERRIDE;
96 virtual void applyFilter(const std::string &filter) OVERRIDE;
98 // Searchable implementation
99 virtual bool allowsSearching() OVERRIDE;
100 virtual bool search(const std::string &constraint) OVERRIDE;
101 virtual void nextFound(bool wrap) OVERRIDE;
102 virtual void prevFound(bool wrap) OVERRIDE;
104 // HasSongs implementation
105 virtual std::shared_ptr<ProxySongList> getProxySongList() OVERRIDE;
107 virtual bool allowsSelection() OVERRIDE;
108 virtual void reverseSelection() OVERRIDE;
109 virtual MPD::SongList getSelectedSongs() OVERRIDE;
111 // private members
113 static size_t StaticOptions;
114 static size_t SearchButton;
115 static size_t ResetButton;
117 protected:
118 virtual void init() OVERRIDE;
119 virtual bool isLockable() OVERRIDE { return true; }
121 private:
122 void Prepare();
123 void Search();
124 void reset();
126 const char **SearchMode;
128 static const char *SearchModes[];
130 static const size_t ConstraintsNumber = 11;
131 static const char *ConstraintsNames[];
132 std::string itsConstraints[ConstraintsNumber];
134 static bool MatchToPattern;
137 extern SearchEngine *mySearcher;
139 #endif