1 /***************************************************************************
2 * Copyright (C) 2008-2014 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_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"
29 #include "song_list.h"
31 struct MediaLibrary
: Screen
<NC::Window
*>, HasColumns
, HasSongs
, Searchable
, Tabbable
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 void setSearchConstraint(const std::string
&constraint
) OVERRIDE
;
54 virtual void clearConstraint() OVERRIDE
;
55 virtual bool find(SearchDirection direction
, bool wrap
, bool skip_current
) OVERRIDE
;
57 // HasSongs implementation
58 virtual bool itemAvailable() OVERRIDE
;
59 virtual bool addItemToPlaylist(bool play
) OVERRIDE
;
60 virtual std::vector
<MPD::Song
> getSelectedSongs() OVERRIDE
;
62 // HasColumns implementation
63 virtual bool previousColumnAvailable() OVERRIDE
;
64 virtual void previousColumn() OVERRIDE
;
66 virtual bool nextColumnAvailable() OVERRIDE
;
67 virtual void nextColumn() OVERRIDE
;
71 void toggleColumnsMode();
73 void LocateSong(const MPD::Song
&);
74 void toggleSortMode();
76 void requestTagsUpdate() { m_tags_update_request
= true; }
77 void requestAlbumsUpdate() { m_albums_update_request
= true; }
78 void requestSongsUpdate() { m_songs_update_request
= true; }
82 PrimaryTag() : m_mtime(0) { }
83 PrimaryTag(std::string tag_
, time_t mtime_
)
84 : m_tag(std::move(tag_
)), m_mtime(mtime_
) { }
86 const std::string
&tag() const { return m_tag
; }
87 time_t mtime() const { return m_mtime
; }
96 Album(std::string tag_
, std::string album_
, std::string date_
, time_t mtime_
)
97 : m_tag(std::move(tag_
)), m_album(std::move(album_
))
98 , m_date(std::move(date_
)), m_mtime(mtime_
) { }
100 const std::string
&tag() const { return m_tag
; }
101 const std::string
&album() const { return m_album
; }
102 const std::string
&date() const { return m_date
; }
103 time_t mtime() const { return m_mtime
; }
114 AlbumEntry() : m_all_tracks_entry(false), m_album("", "", "", 0) { }
115 AlbumEntry(Album album_
) : m_all_tracks_entry(false), m_album(album_
) { }
117 const Album
&entry() const { return m_album
; }
118 bool isAllTracksEntry() const { return m_all_tracks_entry
; }
120 static AlbumEntry
mkAllTracksEntry(std::string tag
) {
121 auto result
= AlbumEntry(Album(tag
, "", "", 0));
122 result
.m_all_tracks_entry
= true;
127 bool m_all_tracks_entry
;
131 NC::Menu
<PrimaryTag
> Tags
;
132 NC::Menu
<AlbumEntry
> Albums
;
136 bool m_tags_update_request
;
137 bool m_albums_update_request
;
138 bool m_songs_update_request
;
140 boost::posix_time::ptime m_timer
;
142 const int m_window_timeout
;
143 const boost::posix_time::time_duration m_fetching_delay
;
145 Regex::Filter
<PrimaryTag
> m_tags_search_predicate
;
146 Regex::ItemFilter
<AlbumEntry
> m_albums_search_predicate
;
147 Regex::Filter
<MPD::Song
> m_songs_search_predicate
;
151 extern MediaLibrary
*myLibrary
;
153 #endif // NCMPCPP_MEDIA_LIBRARY_H