1 /***************************************************************************
2  *   Copyright (C) 2008-2021 by Andrzej Rybczak                            *
3  *   andrzej@rybczak.net                                                   *
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  ***************************************************************************/
20 
21 #ifndef NCMPCPP_PLAYLIST_EDITOR_H
22 #define NCMPCPP_PLAYLIST_EDITOR_H
23 
24 #include <boost/date_time/posix_time/posix_time_types.hpp>
25 
26 #include "interfaces.h"
27 #include "regex_filter.h"
28 #include "screens/screen.h"
29 #include "song_list.h"
30 
31 struct PlaylistEditor: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
32 {
33 	PlaylistEditor();
34 
35 	virtual void switchTo() override;
36 	virtual void resize() override;
37 
38 	virtual std::wstring title() override;
typePlaylistEditor39 	virtual ScreenType type() override { return ScreenType::PlaylistEditor; }
40 
41 	virtual void refresh() override;
42 	virtual void update() override;
43 
44 	virtual int windowTimeout() override;
45 
46 	virtual void mouseButtonPressed(MEVENT me) override;
47 
isLockablePlaylistEditor48 	virtual bool isLockable() override { return true; }
isMergablePlaylistEditor49 	virtual bool isMergable() override { return true; }
50 
51 	// Searchable implementation
52 	virtual bool allowsSearching() override;
53 	virtual const std::string &searchConstraint() override;
54 	virtual void setSearchConstraint(const std::string &constraint) override;
55 	virtual void clearSearchConstraint() override;
56 	virtual bool search(SearchDirection direction, bool wrap, bool skip_current) override;
57 
58 	// Filterable implementation
59 	virtual bool allowsFiltering() override;
60 	virtual std::string currentFilter() override;
61 	virtual void applyFilter(const std::string &filter) override;
62 
63 	// HasSongs implementation
64 	virtual bool itemAvailable() override;
65 	virtual bool addItemToPlaylist(bool play) override;
66 	virtual std::vector<MPD::Song> getSelectedSongs() override;
67 
68 	// HasColumns implementation
69 	virtual bool previousColumnAvailable() override;
70 	virtual void previousColumn() override;
71 
72 	virtual bool nextColumnAvailable() override;
73 	virtual void nextColumn() override;
74 
75 	// private members
76 	void updateTimer();
77 
requestPlaylistsUpdatePlaylistEditor78 	void requestPlaylistsUpdate() { m_playlists_update_requested = true; }
requestContentUpdatePlaylistEditor79 	void requestContentUpdate() { m_content_update_requested = true; }
80 
81 	void locatePlaylist(const MPD::Playlist &playlist);
82 	void locateSong(const MPD::Song &s);
83 
84 	NC::Menu<MPD::Playlist> Playlists;
85 	SongMenu Content;
86 
87 private:
88 	bool m_playlists_update_requested;
89 	bool m_content_update_requested;
90 
91 	boost::posix_time::ptime m_timer;
92 
93 	const int m_window_timeout;
94 	const boost::posix_time::time_duration m_fetching_delay;
95 
96 	Regex::Filter<MPD::Playlist> m_playlists_search_predicate;
97 	Regex::Filter<MPD::Song> m_content_search_predicate;
98 };
99 
100 extern PlaylistEditor *myPlaylistEditor;
101 
102 #endif // NCMPCPP_PLAYLIST_EDITOR_H
103 
104