make feature 'display separators between albums' work in all screens

This commit is contained in:
Andrzej Rybczak
2010-07-12 09:14:15 +02:00
parent f627dc854d
commit d962653c76
16 changed files with 62 additions and 22 deletions

View File

@@ -175,7 +175,7 @@ If enabled, time remaining to end of playlist will be shown after playlist's sta
If enabled, total/remaining playlist time displayed in statusbar will be shown using shortened units' names (d:h:m:s instead of days:hours:minutes:seconds).
.TP
.B playlist_separate_albums = yes/no
If enabled, separators will be placed between albums in playlist.
If enabled, separators will be placed between albums.
.TP
.B playlist_display_mode = classic/columns
Default display mode for Playlist.

View File

@@ -57,6 +57,8 @@ const char *Browser::SupportedExtensions[] =
void Browser::Init()
{
static Display::ScreenFormat sf = { this, &Config.song_list_format };
w = new Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.columns_in_browser ? Display::Columns() : "", Config.main_color, brNone);
w->HighlightColor(Config.main_highlight_color);
w->CyclicScrolling(Config.use_cyclic_scrolling);
@@ -64,6 +66,7 @@ void Browser::Init()
w->SetSelectPrefix(&Config.selected_item_prefix);
w->SetSelectSuffix(&Config.selected_item_suffix);
w->SetItemDisplayer(Display::Items);
w->SetItemDisplayerUserData(&sf);
w->SetGetStringFunction(ItemToString);
isInitialized = 1;
}

View File

@@ -40,6 +40,7 @@ class Browser : public Screen< Menu<MPD::Item> >
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong();
virtual MPD::Song *GetSong(size_t pos) { return w->at(pos).type == MPD::itSong ? (*w)[pos].song : 0; }
virtual bool allowsSelection() { return true; }
virtual void ReverseSelection();

View File

@@ -18,6 +18,8 @@
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <cassert>
#include "display.h"
#include "helpers.h"
#include "info.h"
@@ -130,7 +132,7 @@ std::string Display::Columns()
return TO_STRING(result);
}
void Display::SongsInColumns(const MPD::Song &s, void *, Menu<MPD::Song> *menu)
void Display::SongsInColumns(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
{
if (!s.Localized())
const_cast<MPD::Song *>(&s)->Localize();
@@ -142,10 +144,14 @@ void Display::SongsInColumns(const MPD::Song &s, void *, Menu<MPD::Song> *menu)
if (Config.columns.empty())
return;
bool separate_albums = Config.playlist_separate_albums
&& myScreen == myPlaylist
&& menu->CurrentlyDrawedPosition()+1 < myPlaylist->Items->Size()
&& (*myPlaylist->Items)[menu->CurrentlyDrawedPosition()+1].GetAlbum() != s.GetAlbum();
assert(data);
bool separate_albums = false;
if (Config.playlist_separate_albums && menu->CurrentlyDrawedPosition()+1 < menu->Size())
{
MPD::Song *next = static_cast<ScreenFormat *>(data)->screen->GetSong(menu->CurrentlyDrawedPosition()+1);
if (next && next->GetAlbum() != s.GetAlbum())
separate_albums = true;
}
if (separate_albums)
*menu << fmtUnderline;
@@ -300,10 +306,14 @@ void Display::Songs(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
if (is_now_playing)
*menu << Config.now_playing_prefix;
bool separate_albums = Config.playlist_separate_albums
&& myScreen == myPlaylist
&& menu->CurrentlyDrawedPosition()+1 < myPlaylist->Items->Size()
&& (*myPlaylist->Items)[menu->CurrentlyDrawedPosition()+1].GetAlbum() != s.GetAlbum();
assert(data);
bool separate_albums = false;
if (Config.playlist_separate_albums && menu->CurrentlyDrawedPosition()+1 < menu->Size())
{
MPD::Song *next = static_cast<ScreenFormat *>(data)->screen->GetSong(menu->CurrentlyDrawedPosition()+1);
if (next && next->GetAlbum() != s.GetAlbum())
separate_albums = true;
}
if (separate_albums)
{
*menu << fmtUnderline;
@@ -312,7 +322,7 @@ void Display::Songs(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
bool discard_colors = Config.discard_colors_if_item_is_selected && menu->isSelected(menu->CurrentlyDrawedPosition());
std::string line = s.toString(*static_cast<std::string *>(data), "$");
std::string line = s.toString(*static_cast<ScreenFormat *>(data)->format, "$");
for (std::string::const_iterator it = line.begin(); it != line.end(); ++it)
{
if (*it == '$')
@@ -376,7 +386,7 @@ void Display::Tags(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
}
}
void Display::Items(const MPD::Item &item, void *, Menu<MPD::Item> *menu)
void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
{
switch (item.type)
{
@@ -392,9 +402,9 @@ void Display::Items(const MPD::Item &item, void *, Menu<MPD::Item> *menu)
}
case MPD::itSong:
if (!Config.columns_in_browser)
Display::Songs(*item.song, &Config.song_list_format, reinterpret_cast<Menu<MPD::Song> *>(menu));
Display::Songs(*item.song, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
else
Display::SongsInColumns(*item.song, 0, reinterpret_cast<Menu<MPD::Song> *>(menu));
Display::SongsInColumns(*item.song, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
return;
case MPD::itPlaylist:
*menu << Config.browser_playlist_prefix << ExtractTopName(item.name);
@@ -404,14 +414,14 @@ void Display::Items(const MPD::Item &item, void *, Menu<MPD::Item> *menu)
}
}
void Display::SearchEngine(const std::pair<Buffer *, MPD::Song *> &pair, void *, Menu< std::pair<Buffer *, MPD::Song *> > *menu)
void Display::SearchEngine(const std::pair<Buffer *, MPD::Song *> &pair, void *data, Menu< std::pair<Buffer *, MPD::Song *> > *menu)
{
if (pair.second)
{
if (!Config.columns_in_search_engine)
Display::Songs(*pair.second, &Config.song_list_format, reinterpret_cast<Menu<MPD::Song> *>(menu));
Display::Songs(*pair.second, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
else
Display::SongsInColumns(*pair.second, 0, reinterpret_cast<Menu<MPD::Song> *>(menu));
Display::SongsInColumns(*pair.second, data, reinterpret_cast<Menu<MPD::Song> *>(menu));
}
else

View File

@@ -24,9 +24,16 @@
#include "ncmpcpp.h"
#include "menu.h"
#include "mpdpp.h"
#include "screen.h"
namespace Display
{
struct ScreenFormat
{
BasicScreen *screen;
std::string *format;
};
std::string Columns();
template <typename T> void Generic(const T &t, void *, Menu<T> *menu)

View File

@@ -210,7 +210,7 @@ void Help::GetKeybindings()
# endif // HAVE_TAGLIB_H
*w << DisplayKeys(Key.ToggleDisplayMode) << "Toggle display mode\n";
*w << DisplayKeys(Key.ToggleInterface) << "Toggle user interface\n";
*w << DisplayKeys(Key.ToggleSeparatorsInPlaylist) << "Toggle displaying separators between albums in playlist\n";
*w << DisplayKeys(Key.ToggleSeparatorsInPlaylist) << "Toggle displaying separators between albums\n";
*w << DisplayKeys(Key.GoToPosition) << "Go to given position in current song (in % by default)\n";
*w << DisplayKeys(Key.SongInfo) << "Show song info\n";
# ifdef HAVE_CURL_CURL_H

View File

@@ -75,6 +75,8 @@ void MediaLibrary::Init()
Albums->SetGetStringFunction(AlbumToString);
Albums->SetGetStringFunctionUserData(this);
static Display::ScreenFormat sf = { this, &Config.song_library_format };
Songs = new Menu<MPD::Song>(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, "Songs", Config.main_color, brNone);
Songs->HighlightColor(Config.main_highlight_color);
Songs->CyclicScrolling(Config.use_cyclic_scrolling);
@@ -82,7 +84,7 @@ void MediaLibrary::Init()
Songs->SetSelectPrefix(&Config.selected_item_prefix);
Songs->SetSelectSuffix(&Config.selected_item_suffix);
Songs->SetItemDisplayer(Display::Songs);
Songs->SetItemDisplayerUserData(&Config.song_library_format);
Songs->SetItemDisplayerUserData(&sf);
Songs->SetGetStringFunction(SongToString);
w = Artists;

View File

@@ -56,6 +56,7 @@ class MediaLibrary : public Screen<Window>
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong();
virtual MPD::Song *GetSong(size_t pos) { return w == Songs ? &Songs->at(pos) : 0; }
virtual bool allowsSelection() { return true; }
virtual void ReverseSelection();

View File

@@ -47,6 +47,8 @@ Menu< std::pair<std::string, MPD::Song::GetFunction> > *Playlist::SortDialog = 0
void Playlist::Init()
{
static Display::ScreenFormat sf = { this, &Config.song_list_format };
Items = new Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist ? Display::Columns() : "", Config.main_color, brNone);
Items->CyclicScrolling(Config.use_cyclic_scrolling);
Items->CenteredCursor(Config.centered_cursor);
@@ -54,7 +56,7 @@ void Playlist::Init()
Items->SetSelectPrefix(&Config.selected_item_prefix);
Items->SetSelectSuffix(&Config.selected_item_suffix);
Items->SetItemDisplayer(Config.columns_in_playlist ? Display::SongsInColumns : Display::Songs);
Items->SetItemDisplayerUserData(&Config.song_list_format);
Items->SetItemDisplayerUserData(&sf);
Items->SetGetStringFunction(Config.columns_in_playlist ? SongInColumnsToString : SongToString);
Items->SetGetStringFunctionUserData(&Config.song_list_format);
@@ -275,7 +277,7 @@ void Playlist::MouseButtonPressed(MEVENT me)
MPD::Song *Playlist::CurrentSong()
{
return !Items->Empty() ? &Items->Current() : 0;
return w == Items && !Items->Empty() ? &Items->Current() : 0;
}
void Playlist::GetSelectedSongs(MPD::SongList &v)

View File

@@ -45,6 +45,7 @@ class Playlist : public Screen<Window>
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong();
virtual MPD::Song *GetSong(size_t pos) { return w == Items ? &Items->at(pos) : 0; }
virtual bool allowsSelection() { return w == Items; }
virtual void ReverseSelection() { Items->ReverseSelection(); }

View File

@@ -51,6 +51,8 @@ void PlaylistEditor::Init()
Playlists->CenteredCursor(Config.centered_cursor);
Playlists->SetItemDisplayer(Display::Generic);
static Display::ScreenFormat sf = { this, &Config.song_list_format };
Content = new Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, "Playlist's content", Config.main_color, brNone);
Content->HighlightColor(Config.main_highlight_color);
Content->CyclicScrolling(Config.use_cyclic_scrolling);
@@ -58,7 +60,7 @@ void PlaylistEditor::Init()
Content->SetSelectPrefix(&Config.selected_item_prefix);
Content->SetSelectSuffix(&Config.selected_item_suffix);
Content->SetItemDisplayer(Display::Songs);
Content->SetItemDisplayerUserData(&Config.song_list_format);
Content->SetItemDisplayerUserData(&sf);
Content->SetGetStringFunction(Playlist::SongToString);
Content->SetGetStringFunctionUserData(&Config.song_list_format);

View File

@@ -40,6 +40,7 @@ class PlaylistEditor : public Screen<Window>
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong();
virtual MPD::Song *GetSong(size_t pos) { return w == Content ? &Content->at(pos) : 0; }
virtual bool allowsSelection() { return w == Content; }
virtual void ReverseSelection() { Content->ReverseSelection(); }

View File

@@ -96,6 +96,11 @@ class BasicScreen
///
virtual MPD::Song *CurrentSong() { return 0; }
/// @return pointer to song at given position in the screen
/// (if screen is provides one) or null pointer otherwise.
///
virtual MPD::Song *GetSong(GNUC_UNUSED size_t pos) { return 0; }
/// @return true if the screen allows selecting items, false otherwise
///
virtual bool allowsSelection() = 0;

View File

@@ -61,11 +61,14 @@ size_t SearchEngine::SearchButton = 14;
void SearchEngine::Init()
{
static Display::ScreenFormat sf = { this, &Config.song_list_format };
w = new Menu< std::pair<Buffer *, MPD::Song *> >(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone);
w->HighlightColor(Config.main_highlight_color);
w->CyclicScrolling(Config.use_cyclic_scrolling);
w->CenteredCursor(Config.centered_cursor);
w->SetItemDisplayer(Display::SearchEngine);
w->SetItemDisplayerUserData(&sf);
w->SetSelectPrefix(&Config.selected_item_prefix);
w->SetSelectSuffix(&Config.selected_item_suffix);
w->SetGetStringFunction(SearchEngineOptionToString);

View File

@@ -38,6 +38,7 @@ class SearchEngine : public Screen< Menu< std::pair<Buffer *, MPD::Song *> > >
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong();
virtual MPD::Song *GetSong(size_t pos) { return w->at(pos).second; }
virtual bool allowsSelection() { return w->Choice() >= StaticOptions; }
virtual void ReverseSelection() { w->ReverseSelection(StaticOptions); }

View File

@@ -56,6 +56,7 @@ class TagEditor : public Screen<Window>
virtual bool isTabbable() { return true; }
virtual MPD::Song *CurrentSong();
virtual MPD::Song *GetSong(size_t pos) { return w == Tags ? &Tags->at(pos) : 0; }
virtual bool allowsSelection() { return w == Tags; }
virtual void ReverseSelection() { Tags->ReverseSelection(); }