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_H 22 #define NCMPCPP_PLAYLIST_H 23 24 #include <boost/date_time/posix_time/posix_time_types.hpp> 25 #include <unordered_map> 26 27 #include "interfaces.h" 28 #include "regex_filter.h" 29 #include "screens/screen.h" 30 #include "song.h" 31 #include "song_list.h" 32 33 struct Playlist: Screen<SongMenu>, Filterable, HasSongs, Searchable, Tabbable 34 { 35 Playlist(); 36 37 // Screen<SongMenu> implementation 38 virtual void switchTo() override; 39 virtual void resize() override; 40 41 virtual std::wstring title() override; typePlaylist42 virtual ScreenType type() override { return ScreenType::Playlist; } 43 44 virtual void update() override; 45 46 virtual void mouseButtonPressed(MEVENT me) override; 47 isLockablePlaylist48 virtual bool isLockable() override { return true; } isMergablePlaylist49 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 // other members 69 MPD::Song nowPlayingSong(); 70 71 // Locate song in playlist. 72 void locateSong(const MPD::Song &s); 73 74 void enableHighlighting(); 75 76 void setSelectedItemsPriority(int prio); 77 78 bool checkForSong(const MPD::Song &s); 79 void registerSong(const MPD::Song &s); 80 void unregisterSong(const MPD::Song &s); 81 reloadTotalLengthPlaylist82 void reloadTotalLength() { m_reload_total_length = true; } reloadRemainingPlaylist83 void reloadRemaining() { m_reload_remaining = true; } 84 85 private: 86 std::string getTotalLength(); 87 88 std::string m_stats; 89 90 std::unordered_map<MPD::Song, int, MPD::Song::Hash> m_song_refs; 91 92 size_t m_total_length;; 93 size_t m_remaining_time; 94 size_t m_scroll_begin; 95 96 boost::posix_time::ptime m_timer; 97 98 bool m_reload_total_length; 99 bool m_reload_remaining; 100 101 Regex::Filter<MPD::Song> m_search_predicate; 102 }; 103 104 extern Playlist *myPlaylist; 105 106 #endif // NCMPCPP_PLAYLIST_H 107 108