1 /***************************************************************************
2 * Copyright (C) 2008-2012 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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. *
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. *
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
26 #include "interfaces.h"
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
; }
41 NC::Buffer
&mkBuffer() {
44 itsBuffer
= new NC::Buffer();
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
) {
59 isThisSong
= se
.isThisSong
;
62 else if (se
.itsBuffer
)
63 itsBuffer
= new NC::Buffer(*se
.itsBuffer
);
72 NC::Buffer
*itsBuffer
;
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
;
113 static size_t StaticOptions
;
114 static size_t SearchButton
;
115 static size_t ResetButton
;
118 virtual void init() OVERRIDE
;
119 virtual bool isLockable() OVERRIDE
{ return true; }
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
;