1 /***************************************************************************
2 * Copyright (C) 2008-2016 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"
28 #include "regex_filter.h"
30 #include "song_list.h"
34 SEItem() : m_is_song(false), m_buffer(0) { }
35 SEItem(NC::Buffer
*buf
) : m_is_song(false), m_buffer(buf
) { }
36 SEItem(const MPD::Song
&s
) : m_is_song(true), m_song(s
) { }
37 SEItem(const SEItem
&ei
) { *this = ei
; }
43 NC::Buffer
&mkBuffer() {
46 m_buffer
= new NC::Buffer();
50 bool isSong() const { return m_is_song
; }
52 NC::Buffer
&buffer() { assert(!m_is_song
&& m_buffer
); return *m_buffer
; }
53 MPD::Song
&song() { assert(m_is_song
); return m_song
; }
55 const NC::Buffer
&buffer() const { assert(!m_is_song
&& m_buffer
); return *m_buffer
; }
56 const MPD::Song
&song() const { assert(m_is_song
); return m_song
; }
58 SEItem
&operator=(const SEItem
&se
) {
61 m_is_song
= se
.m_is_song
;
65 m_buffer
= new NC::Buffer(*se
.m_buffer
);
78 struct SearchEngineWindow
: NC::Menu
<SEItem
>, SongList
80 SearchEngineWindow() { }
81 SearchEngineWindow(NC::Menu
<SEItem
> &&base
)
82 : NC::Menu
<SEItem
>(std::move(base
)) { }
84 virtual SongIterator
currentS() override
;
85 virtual ConstSongIterator
currentS() const override
;
86 virtual SongIterator
beginS() override
;
87 virtual ConstSongIterator
beginS() const override
;
88 virtual SongIterator
endS() override
;
89 virtual ConstSongIterator
endS() const override
;
91 virtual std::vector
<MPD::Song
> getSelectedSongs() override
;
94 struct SearchEngine
: Screen
<SearchEngineWindow
>, Filterable
, HasActions
, HasSongs
, Searchable
, Tabbable
98 // Screen<SearchEngineWindow> implementation
99 virtual void resize() override
;
100 virtual void switchTo() override
;
102 virtual std::wstring
title() override
;
103 virtual ScreenType
type() override
{ return ScreenType::SearchEngine
; }
105 virtual void update() override
{ }
107 virtual void mouseButtonPressed(MEVENT me
) override
;
109 virtual bool isLockable() override
{ return true; }
110 virtual bool isMergable() override
{ return true; }
112 // Searchable implementation
113 virtual bool allowsSearching() override
;
114 virtual const std::string
&searchConstraint() override
;
115 virtual void setSearchConstraint(const std::string
&constraint
) override
;
116 virtual void clearSearchConstraint() override
;
117 virtual bool search(SearchDirection direction
, bool wrap
, bool skip_current
) override
;
119 // Filterable implementation
120 virtual bool allowsFiltering() override
;
121 virtual std::string
currentFilter() override
;
122 virtual void applyFilter(const std::string
&filter
) override
;
124 // HasActions implementation
125 virtual bool actionRunnable() override
;
126 virtual void runAction() override
;
128 // HasSongs implementation
129 virtual bool itemAvailable() override
;
130 virtual bool addItemToPlaylist(bool play
) override
;
131 virtual std::vector
<MPD::Song
> getSelectedSongs() override
;
136 static size_t StaticOptions
;
137 static size_t SearchButton
;
138 static size_t ResetButton
;
144 Regex::ItemFilter
<SEItem
> m_search_predicate
;
146 const char **SearchMode
;
148 static const char *SearchModes
[];
150 static const size_t ConstraintsNumber
= 11;
151 static const char *ConstraintsNames
[];
152 std::string itsConstraints
[ConstraintsNumber
];
154 static bool MatchToPattern
;
157 extern SearchEngine
*mySearcher
;
159 #endif // NCMPCPP_SEARCH_ENGINE_H