configure: require c++14 compatible compiler
[ncmpcpp.git] / src / media_library.h
blob2d13b66a7dd44bfed0d2eeebac682ce76d3e3ba0
1 /***************************************************************************
2 * Copyright (C) 2008-2014 by Andrzej Rybczak *
3 * electricityispower@gmail.com *
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 ***************************************************************************/
21 #ifndef NCMPCPP_MEDIA_LIBRARY_H
22 #define NCMPCPP_MEDIA_LIBRARY_H
24 #include <boost/date_time/posix_time/posix_time_types.hpp>
26 #include "interfaces.h"
27 #include "regex_filter.h"
28 #include "screen.h"
29 #include "song_list.h"
31 struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Searchable, Tabbable
33 MediaLibrary();
35 virtual void switchTo() override;
36 virtual void resize() override;
38 virtual std::wstring title() override;
39 virtual ScreenType type() override { return ScreenType::MediaLibrary; }
41 virtual void refresh() override;
42 virtual void update() override;
44 virtual int windowTimeout() override;
46 virtual void mouseButtonPressed(MEVENT me) override;
48 virtual bool isLockable() override { return true; }
49 virtual bool isMergable() override { return true; }
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;
58 // Filterable implementation
59 virtual bool allowsFiltering() override;
60 virtual std::string currentFilter() override;
61 virtual void applyFilter(const std::string &filter) override;
63 // HasSongs implementation
64 virtual bool itemAvailable() override;
65 virtual bool addItemToPlaylist(bool play) override;
66 virtual std::vector<MPD::Song> getSelectedSongs() override;
68 // HasColumns implementation
69 virtual bool previousColumnAvailable() override;
70 virtual void previousColumn() override;
72 virtual bool nextColumnAvailable() override;
73 virtual void nextColumn() override;
75 // other members
76 void updateTimer();
77 void toggleColumnsMode();
78 int columns();
79 void locateSong(const MPD::Song &s);
80 void toggleSortMode();
82 void requestTagsUpdate() { m_tags_update_request = true; }
83 void requestAlbumsUpdate() { m_albums_update_request = true; }
84 void requestSongsUpdate() { m_songs_update_request = true; }
86 struct PrimaryTag
88 PrimaryTag() : m_mtime(0) { }
89 PrimaryTag(std::string tag_, time_t mtime_)
90 : m_tag(std::move(tag_)), m_mtime(mtime_) { }
92 const std::string &tag() const { return m_tag; }
93 time_t mtime() const { return m_mtime; }
95 private:
96 std::string m_tag;
97 time_t m_mtime;
100 struct Album
102 Album(std::string tag_, std::string album_, std::string date_, time_t mtime_)
103 : m_tag(std::move(tag_)), m_album(std::move(album_))
104 , m_date(std::move(date_)), m_mtime(mtime_) { }
106 const std::string &tag() const { return m_tag; }
107 const std::string &album() const { return m_album; }
108 const std::string &date() const { return m_date; }
109 time_t mtime() const { return m_mtime; }
111 private:
112 std::string m_tag;
113 std::string m_album;
114 std::string m_date;
115 time_t m_mtime;
118 struct AlbumEntry
120 AlbumEntry() : m_all_tracks_entry(false), m_album("", "", "", 0) { }
121 AlbumEntry(Album album_) : m_all_tracks_entry(false), m_album(album_) { }
123 const Album &entry() const { return m_album; }
124 bool isAllTracksEntry() const { return m_all_tracks_entry; }
126 static AlbumEntry mkAllTracksEntry(std::string tag) {
127 auto result = AlbumEntry(Album(tag, "", "", 0));
128 result.m_all_tracks_entry = true;
129 return result;
132 private:
133 bool m_all_tracks_entry;
134 Album m_album;
137 NC::Menu<PrimaryTag> Tags;
138 NC::Menu<AlbumEntry> Albums;
139 SongMenu Songs;
141 private:
142 bool m_tags_update_request;
143 bool m_albums_update_request;
144 bool m_songs_update_request;
146 boost::posix_time::ptime m_timer;
148 const int m_window_timeout;
149 const boost::posix_time::time_duration m_fetching_delay;
151 Regex::Filter<PrimaryTag> m_tags_search_predicate;
152 Regex::ItemFilter<AlbumEntry> m_albums_search_predicate;
153 Regex::Filter<MPD::Song> m_songs_search_predicate;
157 extern MediaLibrary *myLibrary;
159 #endif // NCMPCPP_MEDIA_LIBRARY_H