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_SEL_ITEMS_ADDER_H
22 #define NCMPCPP_SEL_ITEMS_ADDER_H
23 
24 #include "runnable_item.h"
25 #include "interfaces.h"
26 #include "regex_filter.h"
27 #include "screens/screen.h"
28 #include "song.h"
29 
30 struct SelectedItemsAdder: Screen<NC::Menu<RunnableItem<std::string, void()>> *>, HasActions, Searchable, Tabbable
31 {
32 	typedef SelectedItemsAdder Self;
33 	typedef typename std::remove_pointer<WindowType>::type Component;
34 	typedef Component::Item::Type Entry;
35 
36 	SelectedItemsAdder();
37 
38 	virtual void switchTo() override;
39 	virtual void resize() override;
40 	virtual void refresh() override;
41 
42 	virtual std::wstring title() override;
typeSelectedItemsAdder43 	virtual ScreenType type() override { return ScreenType::SelectedItemsAdder; }
44 
updateSelectedItemsAdder45 	virtual void update() override { }
46 
47 	virtual void mouseButtonPressed(MEVENT me) override;
48 
isLockableSelectedItemsAdder49 	virtual bool isLockable() override { return false; }
isMergableSelectedItemsAdder50 	virtual bool isMergable() override { return false; }
51 
52 	// HasActions implementation
53 	virtual bool actionRunnable() override;
54 	virtual void runAction() override;
55 
56 	// Searchable implementation
57 	virtual bool allowsSearching() override;
58 	virtual const std::string &searchConstraint() override;
59 	virtual void setSearchConstraint(const std::string &constraint) override;
60 	virtual void clearSearchConstraint() override;
61 	virtual bool search(SearchDirection direction, bool wrap, bool skip_current) override;
62 
63 private:
64 	void populatePlaylistSelector(BaseScreen *screen);
65 
66 	void addToCurrentPlaylist();
67 	void addToNewPlaylist() const;
68 	void addToExistingPlaylist(const std::string &playlist) const;
69 	void addAtTheEndOfPlaylist() const;
70 	void addAtTheBeginningOfPlaylist() const;
71 	void addAfterCurrentSong() const;
72 	void addAfterCurrentAlbum() const;
73 	void addAfterHighlightedSong() const;
74 	void cancel();
75 	void exitSuccessfully(bool success) const;
76 
77 	void setDimensions();
78 
79 	size_t m_playlist_selector_width;
80 	size_t m_playlist_selector_height;
81 
82 	size_t m_position_selector_width;
83 	size_t m_position_selector_height;
84 
85 	Component m_playlist_selector;
86 	Component m_position_selector;
87 
88 	std::vector<MPD::Song> m_selected_items;
89 
90 	Regex::ItemFilter<Entry> m_search_predicate;
91 };
92 
93 extern SelectedItemsAdder *mySelectedItemsAdder;
94 
95 #endif // NCMPCPP_SEL_ITEMS_ADDER_H
96 
97