1 /***************************************************************************
2 * Copyright (C) 2008-2014 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 NCMPCPP_SEARCH_ENGINE_H
22 #define NCMPCPP_SEARCH_ENGINE_H
26 #include "interfaces.h"
30 struct SearchEngine
: Screen
<NC::Menu
<struct SEItem
>>, Filterable
, HasSongs
, Searchable
, Tabbable
34 // Screen< NC::Menu<SEItem> > implementation
35 virtual void resize() OVERRIDE
;
36 virtual void switchTo() OVERRIDE
;
38 virtual std::wstring
title() OVERRIDE
;
39 virtual ScreenType
type() OVERRIDE
{ return ScreenType::SearchEngine
; }
41 virtual void update() OVERRIDE
{ }
43 virtual void enterPressed() OVERRIDE
;
44 virtual void spacePressed() OVERRIDE
;
45 virtual void mouseButtonPressed(MEVENT me
) OVERRIDE
;
47 virtual bool isMergable() OVERRIDE
{ return true; }
49 // Filterable implementation
50 virtual bool allowsFiltering() OVERRIDE
;
51 virtual std::string
currentFilter() OVERRIDE
;
52 virtual void applyFilter(const std::string
&filter
) OVERRIDE
;
54 // Searchable implementation
55 virtual bool allowsSearching() OVERRIDE
;
56 virtual bool search(const std::string
&constraint
) OVERRIDE
;
57 virtual void nextFound(bool wrap
) OVERRIDE
;
58 virtual void prevFound(bool wrap
) OVERRIDE
;
60 // HasSongs implementation
61 virtual ProxySongList
proxySongList() OVERRIDE
;
63 virtual bool allowsSelection() OVERRIDE
;
64 virtual void reverseSelection() OVERRIDE
;
65 virtual MPD::SongList
getSelectedSongs() OVERRIDE
;
70 static size_t StaticOptions
;
71 static size_t SearchButton
;
72 static size_t ResetButton
;
75 virtual bool isLockable() OVERRIDE
{ return true; }
81 const char **SearchMode
;
83 static const char *SearchModes
[];
85 static const size_t ConstraintsNumber
= 11;
86 static const char *ConstraintsNames
[];
87 std::string itsConstraints
[ConstraintsNumber
];
89 static bool MatchToPattern
;
94 SEItem() : m_is_song(false), m_buffer(0) { }
95 SEItem(NC::Buffer
*buf
) : m_is_song(false), m_buffer(buf
) { }
96 SEItem(const MPD::Song
&s
) : m_is_song(true), m_song(s
) { }
97 SEItem(const SEItem
&ei
) { *this = ei
; }
103 NC::Buffer
&mkBuffer() {
106 m_buffer
= new NC::Buffer();
110 bool isSong() const { return m_is_song
; }
112 NC::Buffer
&buffer() { assert(!m_is_song
&& m_buffer
); return *m_buffer
; }
113 MPD::Song
&song() { assert(m_is_song
); return m_song
; }
115 const NC::Buffer
&buffer() const { assert(!m_is_song
&& m_buffer
); return *m_buffer
; }
116 const MPD::Song
&song() const { assert(m_is_song
); return m_song
; }
118 SEItem
&operator=(const SEItem
&se
) {
121 m_is_song
= se
.m_is_song
;
124 else if (se
.m_buffer
)
125 m_buffer
= new NC::Buffer(*se
.m_buffer
);
134 NC::Buffer
*m_buffer
;
138 extern SearchEngine
*mySearcher
;
140 #endif // NCMPCPP_SEARCH_ENGINE_H