diff --git a/src/actions.cpp b/src/actions.cpp index 4a585fcd..05622026 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -29,6 +29,7 @@ #include "display.h" #include "global.h" #include "mpdpp.h" +#include "helpers.h" #include "utility/comparators.h" #include "browser.h" @@ -50,6 +51,12 @@ #include "tiny_tag_editor.h" #include "visualizer.h" +#ifdef HAVE_TAGLIB_H +# include "fileref.h" +# include "tag.h" +#endif // HAVE_TAGLIB_H + +using namespace std::placeholders; using Global::myScreen; bool Action::OriginalStatusbarVisibility; @@ -64,7 +71,7 @@ size_t Action::FooterStartY; std::map Action::Actions; Action::Key Action::NoOp = Action::Key(ERR, ctNCurses); -Action::Key Action::ReadKey(Window &w) +Action::Key Action::ReadKey(NC::Window &w) { std::string tmp; int input; @@ -98,7 +105,7 @@ void Action::ValidateScreenSize() if (COLS < 20 || MainHeight < 3) { - DestroyScreen(); + NC::DestroyScreen(); std::cout << "Screen is too small!\n"; exit(1); } @@ -252,7 +259,7 @@ void Action::Seek() time_t t = time(0); int old_timeout = wFooter->GetTimeout(); - wFooter->SetTimeout(ncmpcpp_window_timeout); + wFooter->SetTimeout(500); SeekingInProgress = true; while (true) @@ -289,7 +296,7 @@ void Action::Seek() else break; - *wFooter << fmtBold; + *wFooter << NC::fmtBold; std::string tracklength; if (Config.new_design) { @@ -302,7 +309,7 @@ void Action::Seek() tracklength = MPD::Song::ShowTime(songpos); tracklength += "/"; tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); - *wHeader << XY(0, 0) << tracklength << " "; + *wHeader << NC::XY(0, 0) << tracklength << " "; wHeader->Refresh(); } else @@ -318,9 +325,9 @@ void Action::Seek() tracklength += "/"; tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); tracklength += "]"; - *wFooter << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength; + *wFooter << NC::XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength; } - *wFooter << fmtBoldEnd; + *wFooter << NC::fmtBoldEnd; DrawProgressbar(songpos, Mpd.GetTotalTime()); wFooter->Refresh(); } @@ -415,7 +422,7 @@ bool Action::AskYesNoQuestion(const std::string &question, void (*callback)()) using Global::wFooter; LockStatusbar(); - Statusbar() << question << " [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "]"; + Statusbar() << question << " [" << NC::fmtBold << 'y' << NC::fmtBoldEnd << '/' << NC::fmtBold << 'n' << NC::fmtBoldEnd << "]"; wFooter->Refresh(); int answer = 0; do @@ -491,13 +498,13 @@ void MouseEvent::Run() void ScrollUp::Run() { - myScreen->Scroll(wUp); + myScreen->Scroll(NC::wUp); ListsChangeFinisher(); } void ScrollDown::Run() { - myScreen->Scroll(wDown); + myScreen->Scroll(NC::wDown); ListsChangeFinisher(); } @@ -583,25 +590,25 @@ void ScrollDownAlbum::Run() void PageUp::Run() { - myScreen->Scroll(wPageUp); + myScreen->Scroll(NC::wPageUp); ListsChangeFinisher(); } void PageDown::Run() { - myScreen->Scroll(wPageDown); + myScreen->Scroll(NC::wPageDown); ListsChangeFinisher(); } void MoveHome::Run() { - myScreen->Scroll(wHome); + myScreen->Scroll(NC::wHome); ListsChangeFinisher(); } void MoveEnd::Run() { - myScreen->Scroll(wEnd); + myScreen->Scroll(NC::wEnd); ListsChangeFinisher(); } @@ -1416,7 +1423,7 @@ void EditLibraryTag::Run() if (!isMPDMusicDirSet()) return; LockStatusbar(); - Statusbar() << fmtBold << tagTypeToString(Config.media_lib_primary_tag) << fmtBoldEnd << ": "; + Statusbar() << NC::fmtBold << tagTypeToString(Config.media_lib_primary_tag) << NC::fmtBoldEnd << ": "; std::string new_tag = wFooter->GetString(myLibrary->Tags->Current().value()); UnlockStatusbar(); if (!new_tag.empty() && new_tag != myLibrary->Tags->Current().value()) @@ -1469,7 +1476,7 @@ void EditLibraryAlbum::Run() if (!isMPDMusicDirSet()) return; LockStatusbar(); - Statusbar() << fmtBold << "Album: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "Album: " << NC::fmtBoldEnd; std::string new_album = wFooter->GetString(myLibrary->Albums->Current().value().Album); UnlockStatusbar(); if (!new_album.empty() && new_album != myLibrary->Albums->Current().value().Album) @@ -1529,7 +1536,7 @@ void EditDirectoryName::Run() { std::string old_dir = myBrowser->Main()->Current().value().name; LockStatusbar(); - Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd; std::string new_dir = wFooter->GetString(old_dir); UnlockStatusbar(); if (!new_dir.empty() && new_dir != old_dir) @@ -1563,7 +1570,7 @@ void EditDirectoryName::Run() { std::string old_dir = myTagEditor->Dirs->Current().value().first; LockStatusbar(); - Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd; std::string new_dir = wFooter->GetString(old_dir); UnlockStatusbar(); if (!new_dir.empty() && new_dir != old_dir) @@ -1605,7 +1612,7 @@ void EditPlaylistName::Run() else old_name = myBrowser->Main()->Current().value().name; LockStatusbar(); - Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "Playlist: " << NC::fmtBoldEnd; std::string new_name = wFooter->GetString(old_name); UnlockStatusbar(); if (!new_name.empty() && new_name != old_name) @@ -2005,7 +2012,7 @@ void ApplyFilter::Run() assert(f); LockStatusbar(); - Statusbar() << fmtBold << "Apply filter: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "Apply filter: " << NC::fmtBoldEnd; wFooter->SetGetStringHelper(std::bind(StatusbarApplyFilterImmediately, f, _1)); wFooter->GetString(f->currentFilter()); wFooter->SetGetStringHelper(StatusbarGetStringHelper); @@ -2060,9 +2067,9 @@ void Find::Run() UnlockStatusbar(); ShowMessage("Searching..."); - Screen *s = static_cast *>(myScreen); + Screen *s = static_cast *>(myScreen); s->Main()->RemoveFormatting(); - ShowMessage("%s", findme.empty() || s->Main()->SetFormatting(fmtReverse, TO_WSTRING(findme), fmtReverseEnd, 0) ? "Done!" : "No matching patterns found"); + ShowMessage("%s", findme.empty() || s->Main()->SetFormatting(NC::fmtReverse, TO_WSTRING(findme), NC::fmtReverseEnd, 0) ? "Done!" : "No matching patterns found"); s->Main()->Flush(); } @@ -2131,7 +2138,7 @@ void ToggleReplayGainMode::Run() } LockStatusbar(); - Statusbar() << "Replay gain mode? [" << fmtBold << 'o' << fmtBoldEnd << "ff/" << fmtBold << 't' << fmtBoldEnd << "rack/" << fmtBold << 'a' << fmtBoldEnd << "lbum]"; + Statusbar() << "Replay gain mode? [" << NC::fmtBold << 'o' << NC::fmtBoldEnd << "ff/" << NC::fmtBold << 't' << NC::fmtBoldEnd << "rack/" << NC::fmtBold << 'a' << NC::fmtBoldEnd << "lbum]"; wFooter->Refresh(); int answer = 0; do @@ -2175,7 +2182,7 @@ void AddRandomItems::Run() using Global::wFooter; LockStatusbar(); - Statusbar() << "Add random? [" << fmtBold << 's' << fmtBoldEnd << "ongs/" << fmtBold << 'a' << fmtBoldEnd << "rtists/al" << fmtBold << 'b' << fmtBoldEnd << "ums] "; + Statusbar() << "Add random? [" << NC::fmtBold << 's' << NC::fmtBoldEnd << "ongs/" << NC::fmtBold << 'a' << NC::fmtBoldEnd << "rtists/al" << NC::fmtBold << 'b' << NC::fmtBoldEnd << "ums] "; wFooter->Refresh(); int answer = 0; do @@ -2238,7 +2245,7 @@ void ToggleLibraryTagType::Run() using Global::wFooter; LockStatusbar(); - Statusbar() << "Tag type? [" << fmtBold << 'a' << fmtBoldEnd << "rtist/album" << fmtBold << 'A' << fmtBoldEnd << "rtist/" << fmtBold << 'y' << fmtBoldEnd << "ear/" << fmtBold << 'g' << fmtBoldEnd << "enre/" << fmtBold << 'c' << fmtBoldEnd << "omposer/" << fmtBold << 'p' << fmtBoldEnd << "erformer] "; + Statusbar() << "Tag type? [" << NC::fmtBold << 'a' << NC::fmtBoldEnd << "rtist/album" << NC::fmtBold << 'A' << NC::fmtBoldEnd << "rtist/" << NC::fmtBold << 'y' << NC::fmtBoldEnd << "ear/" << NC::fmtBold << 'g' << NC::fmtBoldEnd << "enre/" << NC::fmtBold << 'c' << NC::fmtBoldEnd << "omposer/" << NC::fmtBold << 'p' << NC::fmtBoldEnd << "erformer] "; wFooter->Refresh(); int answer = 0; do diff --git a/src/actions.h b/src/actions.h index f51878d3..fe46444e 100644 --- a/src/actions.h +++ b/src/actions.h @@ -23,7 +23,7 @@ #include #include -#include "ncmpcpp.h" +#include "window.h" enum ActionType { @@ -102,7 +102,7 @@ struct Action return false; } - static Key ReadKey(Window &w); + static Key ReadKey(NC::Window &w); static void ValidateScreenSize(); static void SetResizeFlags(); diff --git a/src/browser.cpp b/src/browser.cpp index 28b1e054..57224466 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -35,6 +35,8 @@ #include "tag_editor.h" #include "utility/comparators.h" +using namespace std::placeholders; + using Global::MainHeight; using Global::MainStartY; using Global::myScreen; @@ -58,7 +60,7 @@ bool BrowserEntryMatcher(const Regex &rx, const MPD::Item &item, bool filter); void Browser::Init() { - w = new Menu(0, MainStartY, COLS, MainHeight, Config.columns_in_browser && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, brNone); + w = new NC::Menu(0, MainStartY, COLS, MainHeight, Config.columns_in_browser && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::brNone); w->HighlightColor(Config.main_highlight_color); w->CyclicScrolling(Config.use_cyclic_scrolling); w->CenteredCursor(Config.centered_cursor); @@ -172,7 +174,7 @@ void Browser::SpacePressed() { i = w->Choice(); w->at(i).setSelected(!w->at(i).isSelected()); - w->Scroll(wDown); + w->Scroll(NC::wDown); return; } @@ -219,7 +221,7 @@ void Browser::SpacePressed() break; } } - w->Scroll(wDown); + w->Scroll(NC::wDown); } void Browser::MouseButtonPressed(MEVENT me) @@ -242,7 +244,7 @@ void Browser::MouseButtonPressed(MEVENT me) size_t pos = w->Choice(); SpacePressed(); if (pos < w->Size()-1) - w->Scroll(wUp); + w->Scroll(NC::wUp); } break; case itPlaylist: @@ -252,7 +254,7 @@ void Browser::MouseButtonPressed(MEVENT me) size_t pos = w->Choice(); SpacePressed(); if (pos < w->Size()-1) - w->Scroll(wUp); + w->Scroll(NC::wUp); } else EnterPressed(); @@ -260,7 +262,7 @@ void Browser::MouseButtonPressed(MEVENT me) } } else - Screen< Menu >::MouseButtonPressed(me); + Screen< NC::Menu >::MouseButtonPressed(me); } /***********************************************************************/ diff --git a/src/browser.h b/src/browser.h index ac4fba86..69262187 100644 --- a/src/browser.h +++ b/src/browser.h @@ -22,11 +22,9 @@ #define _BROWSER_H #include "interfaces.h" -#include "ncmpcpp.h" -#include "regex_filter.h" #include "screen.h" -class Browser : public Screen< Menu >, public Filterable, public HasSongs, public Searchable +class Browser : public Screen< NC::Menu >, public Filterable, public HasSongs, public Searchable { public: Browser() : itsBrowseLocally(0), itsScrollBeginning(0), itsBrowsedDir("/") { } @@ -59,7 +57,7 @@ class Browser : public Screen< Menu >, public Filterable, public HasS virtual void removeSelection(); virtual MPD::SongList getSelectedSongs(); - virtual List *GetList() { return w; } + virtual NC::List *GetList() { return w; } virtual bool isMergable() { return true; } diff --git a/src/clock.cpp b/src/clock.cpp index a7391fa9..277c2a63 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -54,8 +54,8 @@ void Clock::Init() { Width = Config.clock_display_seconds ? 60 : 40; - itsPane = new Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); - w = new Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, Border(Config.main_color)); + itsPane = new NC::Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); + w = new NC::Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, NC::Border(Config.main_color)); isInitialized = 1; } @@ -160,7 +160,7 @@ void Clock::Update() next[k] = 0; for (int s = 1; s >= 0; --s) { - *w << (s ? fmtReverse : fmtReverseEnd); + *w << (s ? NC::fmtReverse : NC::fmtReverseEnd); for (int i = 0; i < 6; ++i) { long a = (newer[i] ^ older[i]) & (s ? newer : older)[i]; diff --git a/src/clock.h b/src/clock.h index 5c26b7da..008689ba 100644 --- a/src/clock.h +++ b/src/clock.h @@ -30,7 +30,7 @@ #include "window.h" #include "screen.h" -class Clock : public Screen +class Clock : public Screen { public: virtual void Resize(); @@ -39,7 +39,7 @@ class Clock : public Screen virtual std::basic_string Title(); virtual void Update(); - virtual void Scroll(Where) { } + virtual void Scroll(NC::Where) { } virtual void EnterPressed() { } virtual void SpacePressed() { } @@ -48,7 +48,7 @@ class Clock : public Screen virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return true; } @@ -57,7 +57,7 @@ class Clock : public Screen virtual bool isLockable() { return false; } private: - Window *itsPane; + NC::Window *itsPane; static void Prepare(); static void Set(int, int); diff --git a/src/display.cpp b/src/display.cpp index cb17ab66..f60fe8a4 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -73,7 +73,7 @@ const my_char_t *toColumnName(char c) } template -void setProperties(Menu &menu, const MPD::Song &s, HasSongs &screen, bool &separate_albums, +void setProperties(NC::Menu &menu, const MPD::Song &s, HasSongs &screen, bool &separate_albums, bool &is_now_playing, bool &is_selected, bool &discard_colors) { separate_albums = false; @@ -84,7 +84,7 @@ void setProperties(Menu &menu, const MPD::Song &s, HasSongs &screen, bool &se separate_albums = true; } if (separate_albums) - menu << fmtUnderline; + menu << NC::fmtUnderline; int song_pos = menu.isFiltered() ? s.getPosition() : menu.DrawnPosition(); is_now_playing = static_cast(&menu) == myPlaylist->Items @@ -94,7 +94,7 @@ void setProperties(Menu &menu, const MPD::Song &s, HasSongs &screen, bool &se } template -void showSongs(Menu &menu, const MPD::Song &s, HasSongs &screen, const std::string &format) +void showSongs(NC::Menu &menu, const MPD::Song &s, HasSongs &screen, const std::string &format) { bool separate_albums, is_now_playing, is_selected, discard_colors; setProperties(menu, s, screen, separate_albums, is_now_playing, is_selected, discard_colors); @@ -112,20 +112,20 @@ void showSongs(Menu &menu, const MPD::Song &s, HasSongs &screen, const std::s else if (isdigit(*it)) // color { if (!discard_colors) - menu << Color(*it-'0'); + menu << NC::Color(*it-'0'); } else if (*it == 'R') // right align { - basic_buffer buf; + NC::basic_buffer buf; buf << U(" "); String2Buffer(TO_WSTRING(line.substr(it-line.begin()+1)), buf); if (discard_colors) buf.RemoveFormatting(); if (is_now_playing) buf << Config.now_playing_suffix; - menu << XY(menu.GetWidth()-buf.Str().length()-(is_selected ? Config.selected_item_suffix_length : 0), menu.Y()) << buf; + menu << NC::XY(menu.GetWidth()-buf.Str().length()-(is_selected ? Config.selected_item_suffix_length : 0), menu.Y()) << buf; if (separate_albums) - menu << fmtUnderlineEnd; + menu << NC::fmtUnderlineEnd; return; } else // not a color nor right align, just a random character @@ -144,11 +144,11 @@ void showSongs(Menu &menu, const MPD::Song &s, HasSongs &screen, const std::s if (is_now_playing) menu << Config.now_playing_suffix; if (separate_albums) - menu << fmtUnderlineEnd; + menu << NC::fmtUnderlineEnd; } template -void showSongsInColumns(Menu &menu, const MPD::Song &s, HasSongs &screen) +void showSongsInColumns(NC::Menu &menu, const MPD::Song &s, HasSongs &screen) { if (Config.columns.empty()) return; @@ -219,16 +219,16 @@ void showSongsInColumns(Menu &menu, const MPD::Song &s, HasSongs &screen) } if (tag.empty() && it->display_empty_tag) tag = TO_WSTRING(Config.empty_tag); - Window::Cut(tag, width); + NC::Window::Cut(tag, width); - if (!discard_colors && it->color != clDefault) + if (!discard_colors && it->color != NC::clDefault) menu << it->color; int x_off = 0; // if column uses right alignment, calculate proper offset. // otherwise just assume offset is 0, ie. we start from the left. if (it->right_alignment) - x_off = std::max(0, width - int(Window::Length(tag))); + x_off = std::max(0, width - int(NC::Window::Length(tag))); whline(menu.Raw(), KEY_SPACE, width); menu.GotoXY(x + x_off, y); @@ -241,8 +241,8 @@ void showSongsInColumns(Menu &menu, const MPD::Song &s, HasSongs &screen) remained_width -= width+1; } - if (!discard_colors && it->color != clDefault) - menu << clEnd; + if (!discard_colors && it->color != NC::clDefault) + menu << NC::clEnd; } // here comes the shitty part, second chapter. here we apply @@ -261,7 +261,7 @@ void showSongsInColumns(Menu &menu, const MPD::Song &s, HasSongs &screen) menu.GotoXY(menu.GetWidth() - Config.selected_item_suffix_length, y); if (separate_albums) - menu << fmtUnderlineEnd; + menu << NC::fmtUnderlineEnd; } } @@ -308,9 +308,9 @@ std::string Display::Columns(size_t list_width) } else name = it->name; - Window::Cut(name, width); + NC::Window::Cut(name, width); - int x_off = std::max(0, width - int(Window::Length(name))); + int x_off = std::max(0, width - int(NC::Window::Length(name))); if (it->right_alignment) { result += std::string(x_off, KEY_SPACE); @@ -333,17 +333,17 @@ std::string Display::Columns(size_t list_width) return result; } -void Display::SongsInColumns(Menu &menu, HasSongs &screen) +void Display::SongsInColumns(NC::Menu &menu, HasSongs &screen) { showSongsInColumns(menu, menu.Drawn().value(), screen); } -void Display::Songs(Menu &menu, HasSongs &screen, const std::string &format) +void Display::Songs(NC::Menu &menu, HasSongs &screen, const std::string &format) { showSongs(menu, menu.Drawn().value(), screen, format); } -void Display::Tags(Menu &menu) +void Display::Tags(NC::Menu &menu) { const MPD::MutableSong &s = menu.Drawn().value(); size_t i = myTagEditor->TagTypes->Choice(); @@ -356,16 +356,16 @@ void Display::Tags(Menu &menu) if (s.getNewURI().empty()) menu << s.getName(); else - menu << s.getName() << Config.color2 << " -> " << clEnd << s.getNewURI(); + menu << s.getName() << Config.color2 << " -> " << NC::clEnd << s.getNewURI(); } } -void Display::Outputs(Menu< MPD::Output > &menu) +void Display::Outputs(NC::Menu &menu) { menu << menu.Drawn().value().name(); } -void Display::Items(Menu &menu) +void Display::Items(NC::Menu &menu) { const MPD::Item &item = menu.Drawn().value(); switch (item.type) @@ -385,7 +385,7 @@ void Display::Items(Menu &menu) } } -void Display::SearchEngine(Menu &menu) +void Display::SearchEngine(NC::Menu &menu) { const SEItem &si = menu.Drawn().value(); if (si.isSong()) diff --git a/src/display.h b/src/display.h index 83b2976b..459caa85 100644 --- a/src/display.h +++ b/src/display.h @@ -22,9 +22,7 @@ #define _DISPLAY_H #include "interfaces.h" -#include "ncmpcpp.h" #include "menu.h" -#include "mpdpp.h" #include "mutable_song.h" #include "search_engine.h" @@ -32,27 +30,27 @@ namespace Display { std::string Columns(size_t); - template void Default(Menu &menu) + template void Default(NC::Menu &menu) { menu << menu.Drawn().value(); } - template void Pair(Menu< std::pair > &menu) + template void Pair(NC::Menu< std::pair > &menu) { menu << menu.Drawn().value().first; } - void SongsInColumns(Menu &menu, HasSongs &screen); + void SongsInColumns(NC::Menu &menu, HasSongs &screen); - void Songs(Menu &menu, HasSongs &screen, const std::string &format); + void Songs(NC::Menu &menu, HasSongs &screen, const std::string &format); - void Tags(Menu &menu); + void Tags(NC::Menu &menu); - void Outputs(Menu &menu); + void Outputs(NC::Menu &menu); - void SearchEngine(Menu &menu); + void SearchEngine(NC::Menu &menu); - void Items(Menu &menu); + void Items(NC::Menu &menu); } #endif diff --git a/src/global.h b/src/global.h index 6afa184d..37af2246 100644 --- a/src/global.h +++ b/src/global.h @@ -23,7 +23,6 @@ #include -#include "ncmpcpp.h" #include "mpdpp.h" #include "screen.h" @@ -45,10 +44,10 @@ namespace Global extern BasicScreen *myInactiveScreen; // header window (above main window) - extern Window *wHeader; + extern NC::Window *wHeader; // footer window (below main window) - extern Window *wFooter; + extern NC::Window *wFooter; // Y coordinate of top of main window extern size_t MainStartY; diff --git a/src/help.cpp b/src/help.cpp index b0bae533..6bcc6f09 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -22,8 +22,8 @@ #include "global.h" #include "help.h" +#include "scrollpad.h" #include "settings.h" -#include "tag_editor.h" using Global::MainHeight; using Global::MainStartY; @@ -88,11 +88,13 @@ std::string keyToString(const Action::Key &key, bool *print_backspace) return result; } + + } void Help::Init() { - w = new Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); GetKeybindings(); w->Flush(); isInitialized = 1; @@ -154,8 +156,8 @@ std::string Help::DisplayKeys(const ActionType at) void Help::Section(const char *type, const char *title) { - *w << U("\n ") << fmtBold << TO_WSTRING(type) << U(" - "); - *w << TO_WSTRING(title) << fmtBoldEnd << '\n' << '\n'; + *w << U("\n ") << NC::fmtBold << TO_WSTRING(type) << U(" - "); + *w << TO_WSTRING(title) << NC::fmtBoldEnd << '\n' << '\n'; } void Help::KeyDesc(const ActionType at, const char *desc) @@ -172,7 +174,7 @@ void Help::MouseDesc(std::string action, const char *desc, bool indent) void Help::MouseColumn(const char *column) { - *w << fmtBold << U(" ") << TO_WSTRING(column) << U(" column:\n") << fmtBoldEnd; + *w << NC::fmtBold << U(" ") << TO_WSTRING(column) << U(" column:\n") << NC::fmtBoldEnd; } void Help::GetKeybindings() diff --git a/src/help.h b/src/help.h index e9808b0d..dd3982f3 100644 --- a/src/help.h +++ b/src/help.h @@ -21,10 +21,10 @@ #ifndef _HELP_H #define _HELP_H -#include "ncmpcpp.h" +#include "actions.h" #include "screen.h" -class Help : public Screen +class Help : public Screen { public: virtual void Resize(); @@ -38,7 +38,7 @@ class Help : public Screen virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return true; } diff --git a/src/helpers.cpp b/src/helpers.cpp index ce946a92..1eb962eb 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -282,22 +282,10 @@ std::string Timestamp(time_t t) return result; } -void UpdateSongList(Menu *menu) +void UpdateSongList(NC::Menu *menu) { - bool bold = 0; - for (size_t i = 0; i < menu->Size(); ++i) - { - for (size_t j = 0; j < myPlaylist->Items->Size(); ++j) - { - if (myPlaylist->Items->at(j).value().getHash() == menu->at(i).value().getHash()) - { - bold = 1; - break; - } - } - (*menu)[i].setBold(bold); - bold = 0; - } + for (auto it = menu->Begin(); it != menu->End(); ++it) + it->setSelected(myPlaylist->checkForSong(it->value())); menu->Refresh(); } @@ -307,14 +295,14 @@ std::basic_string Scroller(const std::basic_string &str, s if (!Config.header_text_scrolling) return s; std::basic_string result; - size_t len = Window::Length(s); + size_t len = NC::Window::Length(s); if (len > width) { s += U(" ** "); len = 0; - std::basic_string::const_iterator b = s.begin(), e = s.end(); - for (std::basic_string::const_iterator it = b+pos; it < e && len < width; ++it) + auto b = s.begin(), e = s.end(); + for (auto it = b+pos; it < e && len < width; ++it) { if ((len += wcwidth(*it)) > width) break; diff --git a/src/helpers.h b/src/helpers.h index 783b01a5..be3be6e1 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -21,11 +21,17 @@ #ifndef _HELPERS_H #define _HELPERS_H +#include "interfaces.h" #include "mpdpp.h" -#include "ncmpcpp.h" +#include "screen.h" #include "settings.h" #include "status.h" +inline HasSongs *hasSongs(BasicScreen *screen) +{ + return dynamic_cast(screen); +} + template void removeSelectionHelper(Iterator first, Iterator last) { for (; first != last; ++first) @@ -51,7 +57,7 @@ template std::string getSharedDirectory(Iterator first, Iter return result; } -template void withUnfilteredMenu(Menu &menu, std::function action) +template void withUnfilteredMenu(NC::Menu &menu, std::function action) { bool is_filtered = menu.isFiltered(); menu.ShowAll(); @@ -65,17 +71,17 @@ void ParseArgv(int, char **); template struct StringConverter { const char *operator()(const char *s) { return s; } }; -template <> struct StringConverter< basic_buffer > { +template <> struct StringConverter< NC::basic_buffer > { std::wstring operator()(const char *s) { return ToWString(s); } }; -template <> struct StringConverter { +template <> struct StringConverter { std::basic_string operator()(const char *s) { return TO_WSTRING(s); } }; -template void String2Buffer(const std::basic_string &s, basic_buffer &buf) +template void String2Buffer(const std::basic_string &s, NC::basic_buffer &buf) { - StringConverter< basic_buffer > cnv; - for (typename std::basic_string::const_iterator it = s.begin(); it != s.end(); ++it) + StringConverter< NC::basic_buffer > cnv; + for (auto it = s.begin(); it != s.end(); ++it) { if (*it == '$') { @@ -86,23 +92,23 @@ template void String2Buffer(const std::basic_string &s, basic_bu } else if (isdigit(*it)) { - buf << Color(*it-'0'); + buf << NC::Color(*it-'0'); } else { switch (*it) { case 'b': - buf << fmtBold; + buf << NC::fmtBold; break; case 'u': - buf << fmtUnderline; + buf << NC::fmtUnderline; break; case 'a': - buf << fmtAltCharset; + buf << NC::fmtAltCharset; break; case 'r': - buf << fmtReverse; + buf << NC::fmtReverse; break; case '/': if (++it == s.end()) @@ -113,16 +119,16 @@ template void String2Buffer(const std::basic_string &s, basic_bu switch (*it) { case 'b': - buf << fmtBoldEnd; + buf << NC::fmtBoldEnd; break; case 'u': - buf << fmtUnderlineEnd; + buf << NC::fmtUnderlineEnd; break; case 'a': - buf << fmtAltCharsetEnd; + buf << NC::fmtAltCharsetEnd; break; case 'r': - buf << fmtReverseEnd; + buf << NC::fmtReverseEnd; break; default: buf << '$' << *--it; @@ -195,14 +201,14 @@ template void ShowTime(T &buf, size_t length, bool short_names) template void ShowTag(T &buf, const std::string &tag) { if (tag.empty()) - buf << Config.empty_tags_color << Config.empty_tag << clEnd; + buf << Config.empty_tags_color << Config.empty_tag << NC::clEnd; else buf << tag; } std::string Timestamp(time_t t); -void UpdateSongList(Menu *); +void UpdateSongList(NC::Menu *); std::basic_string Scroller(const std::basic_string &str, size_t &pos, size_t width); diff --git a/src/lastfm.cpp b/src/lastfm.cpp index 628dc98d..559be6ae 100644 --- a/src/lastfm.cpp +++ b/src/lastfm.cpp @@ -34,6 +34,7 @@ #include #include +#include "helpers.h" #include "charset.h" #include "global.h" @@ -44,7 +45,7 @@ Lastfm *myLastfm = new Lastfm; void Lastfm::Init() { - w = new Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); isInitialized = 1; } @@ -190,7 +191,7 @@ void Lastfm::Download() itsService->colorizeOutput(*w); } else - *w << clRed << result.second << clEnd; + *w << NC::clRed << result.second << NC::clEnd; isReadyToTake = 1; } diff --git a/src/lastfm.h b/src/lastfm.h index 5725100c..3c5be55b 100644 --- a/src/lastfm.h +++ b/src/lastfm.h @@ -33,7 +33,7 @@ #include "lastfm_service.h" #include "screen.h" -class Lastfm : public Screen +class Lastfm : public Screen { public: Lastfm() : isReadyToTake(0), isDownloadInProgress(0) { } @@ -50,7 +50,7 @@ class Lastfm : public Screen virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return true; } diff --git a/src/lastfm_service.cpp b/src/lastfm_service.cpp index c0f3b32c..60f78c9e 100644 --- a/src/lastfm_service.cpp +++ b/src/lastfm_service.cpp @@ -102,10 +102,10 @@ bool ArtistInfo::checkArgs(const Args &args) return args.find("artist") != args.end(); } -void ArtistInfo::colorizeOutput(NCurses::Scrollpad &w) +void ArtistInfo::colorizeOutput(NC::Scrollpad &w) { - w.SetFormatting(fmtBold, U("\n\nSimilar artists:\n"), fmtBoldEnd, false); - w.SetFormatting(Config.color2, U("\n * "), clEnd, true); + w.SetFormatting(NC::fmtBold, U("\n\nSimilar artists:\n"), NC::fmtBoldEnd, false); + w.SetFormatting(Config.color2, U("\n * "), NC::clEnd, true); // below is used so format won't be removed using RemoveFormatting() by accident. w.ForgetFormatting(); } diff --git a/src/lastfm_service.h b/src/lastfm_service.h index 0b143ad3..d94520d0 100644 --- a/src/lastfm_service.h +++ b/src/lastfm_service.h @@ -41,7 +41,7 @@ struct LastfmService virtual Result fetch(Args &args); virtual bool checkArgs(const Args &args) = 0; - virtual void colorizeOutput(NCurses::Scrollpad &w) = 0; + virtual void colorizeOutput(NC::Scrollpad &w) = 0; protected: virtual bool actionFailed(const std::string &data); @@ -60,7 +60,7 @@ struct ArtistInfo : public LastfmService virtual const char *name() { return "Artist info"; } virtual bool checkArgs(const Args &args); - virtual void colorizeOutput(NCurses::Scrollpad &w); + virtual void colorizeOutput(NC::Scrollpad &w); protected: virtual bool parse(std::string &data); diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 0a021df0..aa88e616 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -30,6 +30,7 @@ #include "helpers.h" #include "lyrics.h" #include "playlist.h" +#include "scrollpad.h" #include "settings.h" #include "song.h" @@ -49,7 +50,7 @@ Lyrics *myLyrics = new Lyrics; void Lyrics::Init() { - w = new Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); isInitialized = 1; } @@ -254,10 +255,10 @@ void *Lyrics::Download() bool fetcher_defined = itsFetcher && *itsFetcher; for (LyricsFetcher **plugin = fetcher_defined ? itsFetcher : lyricsPlugins; *plugin != 0; ++plugin) { - *w << U("Fetching lyrics from ") << fmtBold << TO_WSTRING((*plugin)->name()) << fmtBoldEnd << U("... "); + *w << U("Fetching lyrics from ") << NC::fmtBold << TO_WSTRING((*plugin)->name()) << NC::fmtBoldEnd << U("... "); result = (*plugin)->fetch(artist, title); if (result.first == false) - *w << clRed << TO_WSTRING(result.second) << clEnd << '\n'; + *w << NC::clRed << TO_WSTRING(result.second) << NC::clEnd << '\n'; else break; if (fetcher_defined) diff --git a/src/lyrics.h b/src/lyrics.h index 07c51aa8..e8284ae8 100644 --- a/src/lyrics.h +++ b/src/lyrics.h @@ -24,12 +24,11 @@ #include #include -#include "ncmpcpp.h" #include "mpdpp.h" #include "screen.h" #include "lyrics_fetcher.h" -class Lyrics : public Screen +class Lyrics : public Screen { public: Lyrics() : ReloadNP(0), @@ -50,7 +49,7 @@ class Lyrics : public Screen virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return true; } diff --git a/src/media_library.cpp b/src/media_library.cpp index 97b18f9c..33c4405f 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -34,6 +34,8 @@ #include "utility/comparators.h" #include "utility/type_conversions.h" +using namespace std::placeholders; + using Global::MainHeight; using Global::MainStartY; using Global::myScreen; @@ -62,11 +64,11 @@ std::string AlbumToString(const SearchConstraints &sc); std::string SongToString(const MPD::Song &s); bool TagEntryMatcher(const Regex &rx, const std::string &tag); -bool AlbumEntryMatcher(const Regex &rx, const Menu::Item &item, bool filter); +bool AlbumEntryMatcher(const Regex &rx, const NC::Menu::Item &item, bool filter); bool SongEntryMatcher(const Regex &rx, const MPD::Song &s); -void DisplayAlbums(Menu &menu); -void DisplayPrimaryTags(Menu &menu); +void DisplayAlbums(NC::Menu &menu); +void DisplayPrimaryTags(NC::Menu &menu); bool SortSongsByTrack(const MPD::Song &a, const MPD::Song &b); bool SortAllTracks(const MPD::Song &a, const MPD::Song &b); @@ -83,7 +85,7 @@ void MediaLibrary::Init() itsRightColWidth = COLS-COLS/3*2-1; itsRightColStartX = itsLeftColWidth+itsMiddleColWidth+2; - Tags = new Menu(0, MainStartY, itsLeftColWidth, MainHeight, Config.titles_visibility ? tagTypeToString(Config.media_lib_primary_tag) + "s" : "", Config.main_color, brNone); + Tags = new NC::Menu(0, MainStartY, itsLeftColWidth, MainHeight, Config.titles_visibility ? tagTypeToString(Config.media_lib_primary_tag) + "s" : "", Config.main_color, NC::brNone); Tags->HighlightColor(Config.active_column_color); Tags->CyclicScrolling(Config.use_cyclic_scrolling); Tags->CenteredCursor(Config.centered_cursor); @@ -91,7 +93,7 @@ void MediaLibrary::Init() Tags->SetSelectSuffix(Config.selected_item_suffix); Tags->setItemDisplayer(DisplayPrimaryTags); - Albums = new Menu(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, brNone); + Albums = new NC::Menu(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, NC::brNone); Albums->HighlightColor(Config.main_highlight_color); Albums->CyclicScrolling(Config.use_cyclic_scrolling); Albums->CenteredCursor(Config.centered_cursor); @@ -99,7 +101,7 @@ void MediaLibrary::Init() Albums->SetSelectSuffix(Config.selected_item_suffix); Albums->setItemDisplayer(DisplayAlbums); - Songs = new Menu(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, Config.titles_visibility ? "Songs" : "", Config.main_color, brNone); + Songs = new NC::Menu(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, Config.titles_visibility ? "Songs" : "", Config.main_color, NC::brNone); Songs->HighlightColor(Config.main_highlight_color); Songs->CyclicScrolling(Config.use_cyclic_scrolling); Songs->CenteredCursor(Config.centered_cursor); @@ -152,7 +154,7 @@ void MediaLibrary::Refresh() Songs->Display(); if (Albums->Empty()) { - *Albums << XY(0, 0) << "No albums found."; + *Albums << NC::XY(0, 0) << "No albums found."; Albums->Window::Refresh(); } } @@ -267,7 +269,7 @@ void MediaLibrary::Update() else if (hasTwoColumns && Albums->ReallyEmpty()) { Songs->Clear(); - *Albums << XY(0, 0) << "Fetching albums..."; + *Albums << NC::XY(0, 0) << "Fetching albums..."; Albums->Window::Refresh(); Mpd.BlockIdle(true); auto artists = Mpd.GetList(Config.media_lib_primary_tag); @@ -359,7 +361,7 @@ void MediaLibrary::SpacePressed() size_t i = Songs->Choice(); Songs->at(i).setSelected(!Songs->at(i).isSelected()); } - w->Scroll(wDown); + w->Scroll(NC::wDown); } else AddToPlaylist(0); @@ -382,11 +384,11 @@ void MediaLibrary::MouseButtonPressed(MEVENT me) size_t pos = Tags->Choice(); SpacePressed(); if (pos < Tags->Size()-1) - Tags->Scroll(wUp); + Tags->Scroll(NC::wUp); } } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); Albums->Clear(); Songs->Clear(); } @@ -402,11 +404,11 @@ void MediaLibrary::MouseButtonPressed(MEVENT me) size_t pos = Albums->Choice(); SpacePressed(); if (pos < Albums->Size()-1) - Albums->Scroll(wUp); + Albums->Scroll(NC::wUp); } } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); Songs->Clear(); } else if (!Songs->Empty() && Songs->hasCoords(me.x, me.y)) @@ -424,17 +426,17 @@ void MediaLibrary::MouseButtonPressed(MEVENT me) size_t pos = Songs->Choice(); SpacePressed(); if (pos < Songs->Size()-1) - Songs->Scroll(wUp); + Songs->Scroll(NC::wUp); } else EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } } -List *MediaLibrary::GetList() +NC::List *MediaLibrary::GetList() { if (w == Tags) return Tags; @@ -841,7 +843,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play) if (!add_n_play) { - w->Scroll(wDown); + w->Scroll(NC::wDown); if (w == Tags) { Albums->Clear(); @@ -881,14 +883,12 @@ std::string SongToString(const MPD::Song &s) return s.toString(Config.song_library_format); } -/***********************************************************************/ - bool TagEntryMatcher(const Regex &rx, const std::string &tag) { return rx.match(tag); } -bool AlbumEntryMatcher(const Regex &rx, const Menu::Item &item, bool filter) +bool AlbumEntryMatcher(const Regex &rx, const NC::Menu::Item &item, bool filter) { if (item.isSeparator() || item.value().Date == AllTracksMarker) return filter; @@ -902,12 +902,12 @@ bool SongEntryMatcher(const Regex &rx, const MPD::Song &s) /***********************************************************************/ -void DisplayAlbums(Menu &menu) +void DisplayAlbums(NC::Menu &menu) { menu << AlbumToString(menu.Drawn().value()); } -void DisplayPrimaryTags(Menu &menu) +void DisplayPrimaryTags(NC::Menu &menu) { const std::string &tag = menu.Drawn().value(); if (tag.empty()) diff --git a/src/media_library.h b/src/media_library.h index c6f51634..1afd0b47 100644 --- a/src/media_library.h +++ b/src/media_library.h @@ -22,10 +22,9 @@ #define _H_MEDIA_LIBRARY #include "interfaces.h" -#include "ncmpcpp.h" #include "screen.h" -class MediaLibrary : public Screen, public Filterable, public HasSongs, public Searchable +class MediaLibrary : public Screen, public Filterable, public HasSongs, public Searchable { public: virtual void SwitchTo(); @@ -59,7 +58,7 @@ class MediaLibrary : public Screen, public Filterable, public HasSongs, virtual void removeSelection(); virtual MPD::SongList getSelectedSongs(); - virtual List *GetList(); + virtual NC::List *GetList(); virtual bool isMergable() { return true; } @@ -84,9 +83,9 @@ class MediaLibrary : public Screen, public Filterable, public HasSongs, std::string Date; }; - Menu *Tags; - Menu *Albums; - Menu *Songs; + NC::Menu *Tags; + NC::Menu *Albums; + NC::Menu *Songs; protected: virtual void Init(); diff --git a/src/menu.h b/src/menu.h index a086789a..ed6628a8 100644 --- a/src/menu.h +++ b/src/menu.h @@ -31,7 +31,7 @@ #include "strbuffer.h" #include "window.h" -namespace NCurses { +namespace NC { /// List class is an interface for Menu class struct List diff --git a/src/mpdpp.h b/src/mpdpp.h index 1ce62f39..0bd8278b 100644 --- a/src/mpdpp.h +++ b/src/mpdpp.h @@ -73,7 +73,6 @@ namespace MPD }; typedef std::vector ItemList; - typedef std::vector SongList; typedef std::vector StringList; typedef std::vector OutputList; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 86c65fa6..48448f1e 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -29,7 +29,6 @@ #include #include "mpdpp.h" -#include "ncmpcpp.h" #include "actions.h" #include "browser.h" @@ -67,7 +66,7 @@ namespace errorlog.close(); Mpd.Disconnect(); # ifndef USE_PDCURSES // destroying screen somehow crashes pdcurses - DestroyScreen(); + NC::DestroyScreen(); # endif // USE_PDCURSES WindowTitle(""); } @@ -135,7 +134,7 @@ int main(int argc, char **argv) cerr_buffer = std::cerr.rdbuf(); std::cerr.rdbuf(errorlog.rdbuf()); - InitScreen("ncmpcpp ver. "VERSION, Config.colors_enabled); + NC::InitScreen("ncmpcpp ver. "VERSION, Config.colors_enabled); Action::OriginalStatusbarVisibility = Config.statusbar_visibility; @@ -148,12 +147,12 @@ int main(int argc, char **argv) Action::SetWindowsDimensions(); Action::ValidateScreenSize(); - wHeader = new Window(0, 0, COLS, Action::HeaderHeight, "", Config.header_color, brNone); + wHeader = new NC::Window(0, 0, COLS, Action::HeaderHeight, "", Config.header_color, NC::brNone); if (Config.header_visibility || Config.new_design) wHeader->Display(); - wFooter = new Window(0, Action::FooterStartY, COLS, Action::FooterHeight, "", Config.statusbar_color, brNone); - wFooter->SetTimeout(ncmpcpp_window_timeout); + wFooter = new NC::Window(0, Action::FooterStartY, COLS, Action::FooterHeight, "", Config.statusbar_color, NC::brNone); + wFooter->SetTimeout(500); wFooter->SetGetStringHelper(StatusbarGetStringHelper); if (Mpd.SupportsIdle()) wFooter->AddFDCallback(Mpd.GetFD(), StatusbarMPDCallback); @@ -243,20 +242,20 @@ int main(int argc, char **argv) if (Config.new_design) { std::basic_string title = myScreen->Title(); - *wHeader << XY(0, 3) << wclrtoeol; - *wHeader << fmtBold << Config.alternative_ui_separator_color; + *wHeader << NC::XY(0, 3) << wclrtoeol; + *wHeader << NC::fmtBold << Config.alternative_ui_separator_color; mvwhline(wHeader->Raw(), 2, 0, 0, COLS); mvwhline(wHeader->Raw(), 4, 0, 0, COLS); - *wHeader << XY((COLS-Window::Length(title))/2, 3); - *wHeader << Config.header_color << title << clEnd; - *wHeader << clEnd << fmtBoldEnd; + *wHeader << NC::XY((COLS-NC::Window::Length(title))/2, 3); + *wHeader << Config.header_color << title << NC::clEnd; + *wHeader << NC::clEnd << NC::fmtBoldEnd; } else { - *wHeader << XY(0, 0) << wclrtoeol << fmtBold << myScreen->Title() << fmtBoldEnd; + *wHeader << NC::XY(0, 0) << wclrtoeol << NC::fmtBold << myScreen->Title() << NC::fmtBoldEnd; *wHeader << Config.volume_color; - *wHeader << XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState; - *wHeader << clEnd; + *wHeader << NC::XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState; + *wHeader << NC::clEnd; } wHeader->Refresh(); RedrawHeader = false; @@ -295,10 +294,10 @@ int main(int argc, char **argv) # ifdef ENABLE_VISUALIZER // visualizer sets timeout to 40ms, but since only it needs such small // value, we should restore defalt one after switching to another screen. - if (wFooter->GetTimeout() < ncmpcpp_window_timeout + if (wFooter->GetTimeout() < 500 && !(myScreen == myVisualizer || myLockedScreen == myVisualizer || myInactiveScreen == myVisualizer) ) - wFooter->SetTimeout(ncmpcpp_window_timeout); + wFooter->SetTimeout(500); # endif // ENABLE_VISUALIZER } return 0; diff --git a/src/ncmpcpp.h b/src/ncmpcpp.h deleted file mode 100644 index 61e465da..00000000 --- a/src/ncmpcpp.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008-2012 by Andrzej Rybczak * - * electricityispower@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ - -#ifndef _NCMPCPP_H -#define _NCMPCPP_H - -#include "window.h" -#include "menu.h" -#include "scrollpad.h" - -using namespace NCurses; -using namespace std::placeholders; - -typedef std::pair string_pair; - -const int ncmpcpp_window_timeout = 500; - -#endif - diff --git a/src/outputs.cpp b/src/outputs.cpp index e5a82b4e..de355d15 100644 --- a/src/outputs.cpp +++ b/src/outputs.cpp @@ -24,6 +24,8 @@ #include "display.h" #include "global.h" +#include "settings.h" +#include "status.h" using Global::MainHeight; using Global::MainStartY; @@ -33,7 +35,7 @@ Outputs *myOutputs = new Outputs; void Outputs::Init() { - w = new Menu(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Menu(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); w->CyclicScrolling(Config.use_cyclic_scrolling); w->CenteredCursor(Config.centered_cursor); w->HighlightColor(Config.main_highlight_color); @@ -108,7 +110,7 @@ void Outputs::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen< Menu >::MouseButtonPressed(me); + Screen< NC::Menu >::MouseButtonPressed(me); } void Outputs::FetchList() diff --git a/src/outputs.h b/src/outputs.h index 4e0921ca..501ca88a 100644 --- a/src/outputs.h +++ b/src/outputs.h @@ -21,9 +21,7 @@ #ifndef _OUTPUTS_H #define _OUTPUTS_H -#ifdef HAVE_CONFIG_H -#include -#endif +#include "config.h" #ifdef ENABLE_OUTPUTS @@ -31,7 +29,7 @@ #include "mpdpp.h" #include "screen.h" -class Outputs : public Screen< Menu > +class Outputs : public Screen< NC::Menu > { public: virtual void SwitchTo(); @@ -46,7 +44,7 @@ class Outputs : public Screen< Menu > virtual bool allowsSelection() { return false; } - virtual List *GetList() { return w; } + virtual NC::List *GetList() { return w; } virtual bool isMergable() { return true; } diff --git a/src/playlist.cpp b/src/playlist.cpp index 03da74bf..cedace8f 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -31,6 +31,8 @@ #include "status.h" #include "utility/comparators.h" +using namespace std::placeholders; + using Global::MainHeight; using Global::MainStartY; @@ -41,7 +43,7 @@ bool Playlist::ReloadRemaining = false; namespace {// -Menu< std::pair > *SortDialog = 0; +NC::Menu< std::pair > *SortDialog = 0; size_t SortDialogHeight; const size_t SortOptions = 10; @@ -54,7 +56,7 @@ bool playlistEntryMatcher(const Regex &rx, const MPD::Song &s); void Playlist::Init() { - Items = new Menu(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, brNone); + Items = new NC::Menu(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, NC::brNone); Items->CyclicScrolling(Config.use_cyclic_scrolling); Items->CenteredCursor(Config.centered_cursor); Items->HighlightColor(Config.main_highlight_color); @@ -69,7 +71,7 @@ void Playlist::Init() { SortDialogHeight = std::min(int(MainHeight), 17); - SortDialog = new Menu< std::pair >((COLS-SortDialogWidth)/2, (MainHeight-SortDialogHeight)/2+MainStartY, SortDialogWidth, SortDialogHeight, "Sort songs by...", Config.main_color, Config.window_border); + SortDialog = new NC::Menu< std::pair >((COLS-SortDialogWidth)/2, (MainHeight-SortDialogHeight)/2+MainStartY, SortDialogWidth, SortDialogHeight, "Sort songs by...", Config.main_color, Config.window_border); SortDialog->CyclicScrolling(Config.use_cyclic_scrolling); SortDialog->CenteredCursor(Config.centered_cursor); SortDialog->setItemDisplayer(Display::Pair); @@ -239,7 +241,7 @@ void Playlist::SpacePressed() if (w == Items && !Items->Empty()) { Items->Current().setSelected(!Items->Current().isSelected()); - Items->Scroll(wDown); + Items->Scroll(NC::wDown); } } @@ -254,7 +256,7 @@ void Playlist::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } else if (w == SortDialog && SortDialog->hasCoords(me.x, me.y)) { @@ -265,7 +267,7 @@ void Playlist::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } } @@ -407,7 +409,7 @@ void Playlist::MoveSelectedItems(Movement where) if (pos > 0) { if (Mpd.Move(pos-1, pos)) - Items->Scroll(wUp); + Items->Scroll(NC::wUp); } } break; @@ -439,7 +441,7 @@ void Playlist::MoveSelectedItems(Movement where) if (pos < Items->Size()-1) { if (Mpd.Move(pos, pos+1)) - Items->Scroll(wDown); + Items->Scroll(NC::wDown); } } break; @@ -497,7 +499,7 @@ void Playlist::AdjustSortOrder(Movement where) if (pos > 0 && pos < SortOptions) { SortDialog->Swap(pos, pos-1); - SortDialog->Scroll(wUp); + SortDialog->Scroll(NC::wUp); } break; } @@ -507,7 +509,7 @@ void Playlist::AdjustSortOrder(Movement where) if (pos < SortOptions-1) { SortDialog->Swap(pos, pos+1); - SortDialog->Scroll(wDown); + SortDialog->Scroll(NC::wDown); } break; } diff --git a/src/playlist.h b/src/playlist.h index f9769813..4c65d3a4 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -22,11 +22,10 @@ #define _PLAYLIST_H #include "interfaces.h" -#include "ncmpcpp.h" #include "screen.h" #include "song.h" -class Playlist : public Screen, public Filterable, public HasSongs, public Searchable +class Playlist : public Screen, public Filterable, public HasSongs, public Searchable { public: enum Movement { mUp, mDown }; @@ -62,7 +61,7 @@ class Playlist : public Screen, public Filterable, public HasSongs, publ virtual void removeSelection(); virtual MPD::SongList getSelectedSongs(); - virtual List *GetList() { return w == Items ? Items : 0; } + virtual NC::List *GetList() { return w == Items ? Items : 0; } virtual bool isMergable() { return true; } @@ -92,7 +91,7 @@ class Playlist : public Screen, public Filterable, public HasSongs, publ //static std::string SongToString(const MPD::Song &s); //static std::string SongInColumnsToString(const MPD::Song &s); - Menu< MPD::Song > *Items; + NC::Menu< MPD::Song > *Items; int NowPlaying; diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index 9f42cb4e..e3aa4efb 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -32,6 +32,8 @@ #include "tag_editor.h" #include "utility/comparators.h" +using namespace std::placeholders; + using Global::MainHeight; using Global::MainStartY; @@ -56,7 +58,7 @@ void PlaylistEditor::Init() RightColumnStartX = LeftColumnWidth+1; RightColumnWidth = COLS-LeftColumnWidth-1; - Playlists = new Menu(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, brNone); + Playlists = new NC::Menu(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, NC::brNone); Playlists->HighlightColor(Config.active_column_color); Playlists->CyclicScrolling(Config.use_cyclic_scrolling); Playlists->CenteredCursor(Config.centered_cursor); @@ -64,7 +66,7 @@ void PlaylistEditor::Init() Playlists->SetSelectSuffix(Config.selected_item_suffix); Playlists->setItemDisplayer(Display::Default); - Content = new Menu(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, brNone); + Content = new NC::Menu(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, NC::brNone); Content->HighlightColor(Config.main_highlight_color); Content->CyclicScrolling(Config.use_cyclic_scrolling); Content->CenteredCursor(Config.centered_cursor); @@ -183,7 +185,7 @@ void PlaylistEditor::Update() if (Content->ReallyEmpty()) { - *Content << XY(0, 0) << "Playlist is empty."; + *Content << NC::XY(0, 0) << "Playlist is empty."; Content->Window::Refresh(); } } @@ -227,7 +229,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where) { if (Mpd.Move(Playlists->Current().value(), pos-1, pos)) { - Content->Scroll(wUp); + Content->Scroll(NC::wUp); Content->Swap(pos-1, pos); } } @@ -262,7 +264,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where) { if (Mpd.Move(Playlists->Current().value(), pos, pos+1)) { - Content->Scroll(wDown); + Content->Scroll(NC::wDown); Content->Swap(pos, pos+1); } } @@ -349,7 +351,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play) } if (!add_n_play) - w->Scroll(wDown); + w->Scroll(NC::wDown); } void PlaylistEditor::SpacePressed() @@ -361,7 +363,7 @@ void PlaylistEditor::SpacePressed() if (!Playlists->Empty()) { Playlists->Current().setSelected(!Playlists->Current().isSelected()); - Playlists->Scroll(wDown); + Playlists->Scroll(NC::wDown); } } else if (w == Content) @@ -369,7 +371,7 @@ void PlaylistEditor::SpacePressed() if (!Content->Empty()) { Content->Current().setSelected(!Content->Current().isSelected()); - Content->Scroll(wDown); + Content->Scroll(NC::wDown); } } } @@ -391,11 +393,11 @@ void PlaylistEditor::MouseButtonPressed(MEVENT me) size_t pos = Playlists->Choice(); SpacePressed(); if (pos < Playlists->Size()-1) - Playlists->Scroll(wUp); + Playlists->Scroll(NC::wUp); } } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); Content->Clear(); } else if (!Content->Empty() && Content->hasCoords(me.x, me.y)) @@ -410,13 +412,13 @@ void PlaylistEditor::MouseButtonPressed(MEVENT me) size_t pos = Content->Choice(); SpacePressed(); if (pos < Content->Size()-1) - Content->Scroll(wUp); + Content->Scroll(NC::wUp); } else EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } } @@ -576,7 +578,7 @@ void PlaylistEditor::Locate(const std::string &name) SwitchTo(); } -List *PlaylistEditor::GetList() +NC::List *PlaylistEditor::GetList() { if (w == Playlists) return Playlists; diff --git a/src/playlist_editor.h b/src/playlist_editor.h index ced4c713..256c4f2a 100644 --- a/src/playlist_editor.h +++ b/src/playlist_editor.h @@ -22,9 +22,8 @@ #define _PLAYLIST_EDITOR_H #include "playlist.h" -#include "ncmpcpp.h" -class PlaylistEditor : public Screen, public Filterable, public HasSongs, public Searchable +class PlaylistEditor : public Screen, public Filterable, public HasSongs, public Searchable { public: virtual void SwitchTo(); @@ -60,7 +59,7 @@ class PlaylistEditor : public Screen, public Filterable, public HasSongs virtual void Locate(const std::string &); - virtual List *GetList(); + virtual NC::List *GetList(); virtual bool isMergable() { return true; } @@ -72,8 +71,8 @@ class PlaylistEditor : public Screen, public Filterable, public HasSongs bool isPrevColumnAvailable(); bool PrevColumn(); - Menu *Playlists; - Menu *Content; + NC::Menu *Playlists; + NC::Menu *Content; protected: virtual void Init(); diff --git a/src/regex_filter.h b/src/regex_filter.h index 10a0f686..38829079 100644 --- a/src/regex_filter.h +++ b/src/regex_filter.h @@ -25,8 +25,8 @@ template struct RegexFilter { - typedef NCurses::Menu MenuT; - typedef typename NCurses::Menu::Item Item; + typedef NC::Menu MenuT; + typedef typename NC::Menu::Item Item; typedef std::function FilterFunction; RegexFilter(const std::string ®ex_, int cflags, FilterFunction filter) @@ -56,8 +56,8 @@ private: template struct RegexItemFilter { - typedef NCurses::Menu MenuT; - typedef typename NCurses::Menu::Item Item; + typedef NC::Menu MenuT; + typedef typename NC::Menu::Item Item; typedef std::function FilterFunction; RegexItemFilter(const std::string ®ex_, int cflags, FilterFunction filter) diff --git a/src/screen.cpp b/src/screen.cpp index 47ffc58d..e5d1565b 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -20,24 +20,110 @@ #include -#include "screen.h" #include "global.h" +#include "screen.h" +#include "settings.h" using Global::myScreen; using Global::myLockedScreen; using Global::myInactiveScreen; -namespace +namespace {// + +void DrawScreenSeparator(int x) { - void DrawScreenSeparator(int x) + attron(COLOR_PAIR(Config.main_color)); + mvvline(Global::MainStartY, x, 0, Global::MainHeight); + attroff(COLOR_PAIR(Config.main_color)); + refresh(); +} + +} + +void GenericMouseButtonPressed(NC::Window *w, MEVENT me) +{ + if (me.bstate & BUTTON2_PRESSED) { - attron(COLOR_PAIR(Config.main_color)); - mvvline(Global::MainStartY, x, 0, Global::MainHeight); - attroff(COLOR_PAIR(Config.main_color)); - refresh(); + if (Config.mouse_list_scroll_whole_page) + w->Scroll(NC::wPageDown); + else + for (size_t i = 0; i < Config.lines_scrolled; ++i) + w->Scroll(NC::wDown); + } + else if (me.bstate & BUTTON4_PRESSED) + { + if (Config.mouse_list_scroll_whole_page) + w->Scroll(NC::wPageUp); + else + for (size_t i = 0; i < Config.lines_scrolled; ++i) + w->Scroll(NC::wUp); } } +void ScrollpadMouseButtonPressed(NC::Scrollpad *w, MEVENT me) +{ + if (me.bstate & BUTTON2_PRESSED) + { + for (size_t i = 0; i < Config.lines_scrolled; ++i) + w->Scroll(NC::wDown); + } + else if (me.bstate & BUTTON4_PRESSED) + { + for (size_t i = 0; i < Config.lines_scrolled; ++i) + w->Scroll(NC::wUp); + } +} + +/***********************************************************************/ + +void BasicScreen::GetWindowResizeParams(size_t &x_offset, size_t &width, bool adjust_locked_screen) +{ + width = COLS; + x_offset = 0; + if (myLockedScreen && myInactiveScreen) + { + size_t locked_width = COLS*Config.locked_screen_width_part; + if (myLockedScreen == this) + width = locked_width; + else + { + width = COLS-locked_width-1; + x_offset = locked_width+1; + + if (adjust_locked_screen) + { + myLockedScreen->Resize(); + myLockedScreen->Refresh(); + DrawScreenSeparator(x_offset-1); + } + } + } +} + +bool BasicScreen::Lock() +{ + if (myLockedScreen) + return false; + if (isLockable()) + { + myLockedScreen = this; + return true; + } + else + return false; +} + +void BasicScreen::Unlock() +{ + if (myInactiveScreen && myInactiveScreen != myLockedScreen) + myScreen = myInactiveScreen; + myLockedScreen->SwitchTo(); + myLockedScreen = 0; + myInactiveScreen = 0; +} + +/***********************************************************************/ + void ApplyToVisibleWindows(void (BasicScreen::*f)()) { if (myLockedScreen && myScreen->isMergable()) @@ -85,49 +171,3 @@ bool isVisible(BasicScreen *screen) else return screen == myScreen; } - -void BasicScreen::GetWindowResizeParams(size_t &x_offset, size_t &width, bool adjust_locked_screen) -{ - width = COLS; - x_offset = 0; - if (myLockedScreen && myInactiveScreen) - { - size_t locked_width = COLS*Config.locked_screen_width_part; - if (myLockedScreen == this) - width = locked_width; - else - { - width = COLS-locked_width-1; - x_offset = locked_width+1; - - if (adjust_locked_screen) - { - myLockedScreen->Resize(); - myLockedScreen->Refresh(); - DrawScreenSeparator(x_offset-1); - } - } - } -} - -bool BasicScreen::Lock() -{ - if (myLockedScreen) - return false; - if (isLockable()) - { - myLockedScreen = this; - return true; - } - else - return false; -} - -void BasicScreen::Unlock() -{ - if (myInactiveScreen && myInactiveScreen != myLockedScreen) - myScreen = myInactiveScreen; - myLockedScreen->SwitchTo(); - myLockedScreen = 0; - myInactiveScreen = 0; -} diff --git a/src/screen.h b/src/screen.h index a76bf267..455551a5 100644 --- a/src/screen.h +++ b/src/screen.h @@ -21,16 +21,11 @@ #ifndef _SCREEN_H #define _SCREEN_H -#include "window.h" #include "menu.h" -#include "mpdpp.h" -#include "helpers.h" -#include "settings.h" -#include "status.h" +#include "scrollpad.h" -void ApplyToVisibleWindows(void (BasicScreen::*f)()); -void UpdateInactiveScreen(BasicScreen *); -bool isVisible(BasicScreen *); +void GenericMouseButtonPressed(NC::Window *w, MEVENT me); +void ScrollpadMouseButtonPressed(NC::Scrollpad *w, MEVENT me); /// An interface for various instantiations of Screen template class. Since C++ doesn't like /// comparison of two different instantiations of the same template class we need the most @@ -46,7 +41,7 @@ class BasicScreen virtual ~BasicScreen() { } /// @see Screen::ActiveWindow() - virtual Window *ActiveWindow() = 0; + virtual NC::Window *ActiveWindow() = 0; /// Method used for switching to screen virtual void SwitchTo() = 0; @@ -69,7 +64,7 @@ class BasicScreen virtual void RefreshWindow() = 0; /// @see Screen::Scroll() - virtual void Scroll(Where where) = 0; + virtual void Scroll(NC::Where where) = 0; /// Invoked after Enter was pressed virtual void EnterPressed() = 0; @@ -82,7 +77,7 @@ class BasicScreen /// @return pointer to instantiation of Menu template class /// cast to List if available or null pointer otherwise - virtual List *GetList() = 0; + virtual NC::List *GetList() = 0; /// When this is overwritten with a function returning true, the /// screen will be used in tab switching. @@ -129,6 +124,10 @@ class BasicScreen bool isInitialized; }; +void ApplyToVisibleWindows(void (BasicScreen::*f)()); +void UpdateInactiveScreen(BasicScreen *screen_to_be_set); +bool isVisible(BasicScreen *screen); + /// Class that all screens should derive from. It provides basic interface /// for the screen to be working properly and assumes that we didn't forget /// about anything vital. @@ -143,7 +142,7 @@ template class Screen : public BasicScreen /// it's useful to determine the one that is being /// active /// @return address to window object cast to void * - virtual Window *ActiveWindow(); + virtual NC::Window *ActiveWindow(); /// @return pointer to currently active window WindowType *Main(); @@ -158,7 +157,7 @@ template class Screen : public BasicScreen /// if fancy scrolling feature is disabled, enters the /// loop that holds main loop until user releases the key /// @param where indicates where one wants to scroll - virtual void Scroll(Where where); + virtual void Scroll(NC::Where where); /// Invoked after there was one of mouse buttons pressed /// @param me struct that contains coords of where the click @@ -173,7 +172,7 @@ template class Screen : public BasicScreen WindowType *w; }; -template Window *Screen::ActiveWindow() +template NC::Window *Screen::ActiveWindow() { return w; } @@ -193,46 +192,22 @@ template void Screen::RefreshWindow() w->Display(); } -template void Screen::Scroll(Where where) +template void Screen::Scroll(NC::Where where) { w->Scroll(where); } template void Screen::MouseButtonPressed(MEVENT me) { - if (me.bstate & BUTTON2_PRESSED) - { - if (Config.mouse_list_scroll_whole_page) - Scroll(wPageDown); - else - for (size_t i = 0; i < Config.lines_scrolled; ++i) - Scroll(wDown); - } - else if (me.bstate & BUTTON4_PRESSED) - { - if (Config.mouse_list_scroll_whole_page) - Scroll(wPageUp); - else - for (size_t i = 0; i < Config.lines_scrolled; ++i) - Scroll(wUp); - } + GenericMouseButtonPressed(w, me); } /// Specialization for Screen::MouseButtonPressed, that should /// not scroll whole page, but rather a few lines (the number of them is /// defined in the config) -template <> inline void Screen::MouseButtonPressed(MEVENT me) +template <> inline void Screen::MouseButtonPressed(MEVENT me) { - if (me.bstate & BUTTON2_PRESSED) - { - for (size_t i = 0; i < Config.lines_scrolled; ++i) - Scroll(wDown); - } - else if (me.bstate & BUTTON4_PRESSED) - { - for (size_t i = 0; i < Config.lines_scrolled; ++i) - Scroll(wUp); - } + ScrollpadMouseButtonPressed(w, me); } #endif diff --git a/src/scrollpad.cpp b/src/scrollpad.cpp index e01b3c16..99c2c461 100644 --- a/src/scrollpad.cpp +++ b/src/scrollpad.cpp @@ -22,7 +22,7 @@ #include "scrollpad.h" -using namespace NCurses; +namespace NC {// Scrollpad::Scrollpad(size_t startx, size_t starty, @@ -208,3 +208,4 @@ Scrollpad &Scrollpad::operator<<(const std::string &s) } #endif // _UTF8 +} diff --git a/src/scrollpad.h b/src/scrollpad.h index d3dbd797..92c1182b 100644 --- a/src/scrollpad.h +++ b/src/scrollpad.h @@ -24,7 +24,7 @@ #include "window.h" #include "strbuffer.h" -namespace NCurses +namespace NC { /// Scrollpad is specialized window that can hold large portion of text and /// supports scrolling if the amount of it is bigger than the window area. diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 7adcdf17..70146c17 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -31,6 +31,8 @@ #include "status.h" #include "utility/comparators.h" +using namespace std::placeholders; + using Global::MainHeight; using Global::MainStartY; @@ -66,7 +68,7 @@ namespace pos {// }*/ std::string SEItemToString(const SEItem &ei); -bool SEItemEntryMatcher(const Regex &rx, const Menu::Item &item, bool filter); +bool SEItemEntryMatcher(const Regex &rx, const NC::Menu::Item &item, bool filter); } @@ -99,7 +101,7 @@ size_t SearchEngine::SearchButton = 15; void SearchEngine::Init() { - w = new Menu(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Menu(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); w->HighlightColor(Config.main_highlight_color); w->CyclicScrolling(Config.use_cyclic_scrolling); w->CenteredCursor(Config.centered_cursor); @@ -150,7 +152,7 @@ void SearchEngine::SwitchTo() if (!w->Back().value().isSong()) { - *w << XY(0, 0) << "Updating list..."; + *w << NC::XY(0, 0) << "Updating list..."; UpdateFoundList(); } } @@ -171,23 +173,23 @@ void SearchEngine::EnterPressed() if (option < ConstraintsNumber) { std::string constraint = ConstraintsNames[option]; - Statusbar() << fmtBold << constraint << fmtBoldEnd << ": "; + Statusbar() << NC::fmtBold << constraint << NC::fmtBoldEnd << ": "; itsConstraints[option] = Global::wFooter->GetString(itsConstraints[option]); w->Current().value().buffer().Clear(); constraint.resize(13, ' '); - w->Current().value().buffer() << fmtBold << constraint << fmtBoldEnd << ": "; + w->Current().value().buffer() << NC::fmtBold << constraint << NC::fmtBoldEnd << ": "; ShowTag(w->Current().value().buffer(), itsConstraints[option]); } else if (option == ConstraintsNumber+1) { Config.search_in_db = !Config.search_in_db; - w->Current().value().buffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); + w->Current().value().buffer() << NC::fmtBold << "Search in:" << NC::fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); } else if (option == ConstraintsNumber+2) { if (!*++SearchMode) SearchMode = &SearchModes[0]; - w->Current().value().buffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; + w->Current().value().buffer() << NC::fmtBold << "Search mode:" << NC::fmtBoldEnd << ' ' << *SearchMode; } else if (option == SearchButton) { @@ -204,15 +206,15 @@ void SearchEngine::EnterPressed() found += 3; // don't count options inserted below w->InsertSeparator(ResetButton+1); w->InsertItem(ResetButton+2, SEItem(), 1, 1); - w->at(ResetButton+2).value().mkBuffer() << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << clDefault; + w->at(ResetButton+2).value().mkBuffer() << Config.color1 << "Search results: " << Config.color2 << "Found " << found << (found > 1 ? " songs" : " song") << NC::clDefault; w->InsertSeparator(ResetButton+3); UpdateFoundList(); ShowMessage("Searching finished"); if (Config.block_search_constraints_change) for (size_t i = 0; i < StaticOptions-4; ++i) w->at(i).setInactive(true); - w->Scroll(wDown); - w->Scroll(wDown); + w->Scroll(NC::wDown); + w->Scroll(NC::wDown); } else ShowMessage("No results found"); @@ -239,13 +241,13 @@ void SearchEngine::SpacePressed() if (Config.space_selects) { w->Current().setSelected(!w->Current().isSelected()); - w->Scroll(wDown); + w->Scroll(NC::wDown); return; } bool res = myPlaylist->Add(w->Current().value().song(), w->Current().isBold(), 0); w->Current().setBold(res); - w->Scroll(wDown); + w->Scroll(NC::wDown); } void SearchEngine::MouseButtonPressed(MEVENT me) @@ -266,14 +268,14 @@ void SearchEngine::MouseButtonPressed(MEVENT me) size_t pos = w->Choice(); SpacePressed(); if (pos < w->Size()-1) - w->Scroll(wUp); + w->Scroll(NC::wUp); } else EnterPressed(); } } else - Screen< Menu >::MouseButtonPressed(me); + Screen< NC::Menu >::MouseButtonPressed(me); } /***********************************************************************/ @@ -386,12 +388,12 @@ void SearchEngine::Prepare() { std::string constraint = ConstraintsNames[i]; constraint.resize(13, ' '); - (*w)[i].value().mkBuffer() << fmtBold << constraint << fmtBoldEnd << ": "; + (*w)[i].value().mkBuffer() << NC::fmtBold << constraint << NC::fmtBoldEnd << ": "; ShowTag((*w)[i].value().buffer(), itsConstraints[i]); } - w->at(ConstraintsNumber+1).value().mkBuffer() << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); - w->at(ConstraintsNumber+2).value().mkBuffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; + w->at(ConstraintsNumber+1).value().mkBuffer() << NC::fmtBold << "Search in:" << NC::fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); + w->at(ConstraintsNumber+2).value().mkBuffer() << NC::fmtBold << "Search mode:" << NC::fmtBoldEnd << ' ' << *SearchMode; w->at(SearchButton).value().mkBuffer() << "Search"; w->at(ResetButton).value().mkBuffer() << "Reset"; @@ -615,7 +617,7 @@ std::string SEItemToString(const SEItem &ei) return result; } -bool SEItemEntryMatcher(const Regex &rx, const Menu::Item &item, bool filter) +bool SEItemEntryMatcher(const Regex &rx, const NC::Menu::Item &item, bool filter) { if (item.isSeparator() || !item.value().isSong()) return filter; diff --git a/src/search_engine.h b/src/search_engine.h index a4c3b5af..bdff33ed 100644 --- a/src/search_engine.h +++ b/src/search_engine.h @@ -25,13 +25,12 @@ #include "interfaces.h" #include "mpdpp.h" -#include "ncmpcpp.h" #include "screen.h" struct SEItem { SEItem() : isThisSong(false), itsBuffer(0) { } - SEItem(Buffer *buf) : isThisSong(false), itsBuffer(buf) { } + SEItem(NC::Buffer *buf) : isThisSong(false), itsBuffer(buf) { } SEItem(const MPD::Song &s) : isThisSong(true), itsSong(s) { } SEItem(const SEItem &ei) { *this = ei; } ~SEItem() { @@ -39,19 +38,19 @@ struct SEItem delete itsBuffer; } - Buffer &mkBuffer() { + NC::Buffer &mkBuffer() { assert(!isThisSong); delete itsBuffer; - itsBuffer = new Buffer(); + itsBuffer = new NC::Buffer(); return *itsBuffer; } bool isSong() const { return isThisSong; } - Buffer &buffer() { assert(!isThisSong && itsBuffer); return *itsBuffer; } + NC::Buffer &buffer() { assert(!isThisSong && itsBuffer); return *itsBuffer; } MPD::Song &song() { assert(isThisSong); return itsSong; } - const Buffer &buffer() const { assert(!isThisSong && itsBuffer); return *itsBuffer; } + const NC::Buffer &buffer() const { assert(!isThisSong && itsBuffer); return *itsBuffer; } const MPD::Song &song() const { assert(isThisSong); return itsSong; } SEItem &operator=(const SEItem &se) { @@ -61,7 +60,7 @@ struct SEItem if (se.isThisSong) itsSong = se.itsSong; else if (se.itsBuffer) - itsBuffer = new Buffer(*se.itsBuffer); + itsBuffer = new NC::Buffer(*se.itsBuffer); else itsBuffer = 0; return *this; @@ -70,11 +69,11 @@ struct SEItem private: bool isThisSong; - Buffer *itsBuffer; + NC::Buffer *itsBuffer; MPD::Song itsSong; }; -class SearchEngine : public Screen< Menu >, public Filterable, public HasSongs, public Searchable +class SearchEngine : public Screen< NC::Menu >, public Filterable, public HasSongs, public Searchable { public: virtual void Resize(); @@ -105,7 +104,7 @@ class SearchEngine : public Screen< Menu >, public Filterable, public Ha virtual void removeSelection(); virtual MPD::SongList getSelectedSongs(); - virtual List *GetList() { return w->Size() >= StaticOptions ? w : 0; } + virtual NC::List *GetList() { return w->Size() >= StaticOptions ? w : 0; } virtual bool isMergable() { return true; } diff --git a/src/sel_items_adder.cpp b/src/sel_items_adder.cpp index d83d0aa6..eced1011 100644 --- a/src/sel_items_adder.cpp +++ b/src/sel_items_adder.cpp @@ -27,6 +27,8 @@ #include "playlist.h" #include "playlist_editor.h" #include "sel_items_adder.h" +#include "settings.h" +#include "status.h" #include "utility/comparators.h" using Global::MainHeight; @@ -39,13 +41,13 @@ SelectedItemsAdder *mySelectedItemsAdder = new SelectedItemsAdder; void SelectedItemsAdder::Init() { SetDimensions(); - itsPlaylistSelector = new Menu((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "Add selected item(s) to...", Config.main_color, Config.window_border); + itsPlaylistSelector = new NC::Menu((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "Add selected item(s) to...", Config.main_color, Config.window_border); itsPlaylistSelector->CyclicScrolling(Config.use_cyclic_scrolling); itsPlaylistSelector->CenteredCursor(Config.centered_cursor); itsPlaylistSelector->HighlightColor(Config.main_highlight_color); itsPlaylistSelector->setItemDisplayer(Display::Default); - itsPositionSelector = new Menu((COLS-itsPSWidth)/2, (MainHeight-itsPSHeight)/2+MainStartY, itsPSWidth, itsPSHeight, "Where?", Config.main_color, Config.window_border); + itsPositionSelector = new NC::Menu((COLS-itsPSWidth)/2, (MainHeight-itsPSHeight)/2+MainStartY, itsPSWidth, itsPSHeight, "Where?", Config.main_color, Config.window_border); itsPositionSelector->CyclicScrolling(Config.use_cyclic_scrolling); itsPositionSelector->CenteredCursor(Config.centered_cursor); itsPositionSelector->HighlightColor(Config.main_highlight_color); @@ -259,7 +261,7 @@ void SelectedItemsAdder::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen< Menu >::MouseButtonPressed(me); + Screen< NC::Menu >::MouseButtonPressed(me); } void SelectedItemsAdder::SetDimensions() diff --git a/src/sel_items_adder.h b/src/sel_items_adder.h index a066bd5b..4e37e76d 100644 --- a/src/sel_items_adder.h +++ b/src/sel_items_adder.h @@ -21,10 +21,9 @@ #ifndef _SEL_ITEMS_ADDER_H #define _SEL_ITEMS_ADDER_H -#include "ncmpcpp.h" #include "screen.h" -class SelectedItemsAdder : public Screen< Menu > +class SelectedItemsAdder : public Screen< NC::Menu > { public: SelectedItemsAdder() : itsPSWidth(35), itsPSHeight(11) { } @@ -41,7 +40,7 @@ class SelectedItemsAdder : public Screen< Menu > virtual bool allowsSelection() { return false; } - virtual List *GetList() { return w; } + virtual NC::List *GetList() { return w; } virtual bool isMergable() { return false; } @@ -52,8 +51,8 @@ class SelectedItemsAdder : public Screen< Menu > private: void SetDimensions(); - Menu *itsPlaylistSelector; - Menu *itsPositionSelector; + NC::Menu *itsPlaylistSelector; + NC::Menu *itsPositionSelector; size_t itsPSWidth; size_t itsPSHeight; diff --git a/src/server_info.cpp b/src/server_info.cpp index 3ecae657..3b581ba9 100644 --- a/src/server_info.cpp +++ b/src/server_info.cpp @@ -22,6 +22,7 @@ #include #include "global.h" +#include "helpers.h" #include "server_info.h" using Global::MainHeight; @@ -33,7 +34,7 @@ ServerInfo *myServerInfo = new ServerInfo; void ServerInfo::Init() { SetDimensions(); - w = new Scrollpad((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "MPD server info", Config.main_color, Config.window_border); + w = new NC::Scrollpad((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "MPD server info", Config.main_color, Config.window_border); itsURLHandlers = Mpd.GetURLHandlers(); itsTagTypes = Mpd.GetTagTypes(); @@ -99,26 +100,26 @@ void ServerInfo::Update() Mpd.UpdateStats(); w->Clear(); - *w << fmtBold << U("Version: ") << fmtBoldEnd << U("0.") << Mpd.Version() << U(".*\n"); - *w << fmtBold << U("Uptime: ") << fmtBoldEnd; + *w << NC::fmtBold << U("Version: ") << NC::fmtBoldEnd << U("0.") << Mpd.Version() << U(".*\n"); + *w << NC::fmtBold << U("Uptime: ") << NC::fmtBoldEnd; ShowTime(*w, Mpd.Uptime(), 1); *w << '\n'; - *w << fmtBold << U("Time playing: ") << fmtBoldEnd << MPD::Song::ShowTime(Mpd.PlayTime()) << '\n'; + *w << NC::fmtBold << U("Time playing: ") << NC::fmtBoldEnd << MPD::Song::ShowTime(Mpd.PlayTime()) << '\n'; *w << '\n'; - *w << fmtBold << U("Total playtime: ") << fmtBoldEnd; + *w << NC::fmtBold << U("Total playtime: ") << NC::fmtBoldEnd; ShowTime(*w, Mpd.DBPlayTime(), 1); *w << '\n'; - *w << fmtBold << U("Artist names: ") << fmtBoldEnd << Mpd.NumberOfArtists() << '\n'; - *w << fmtBold << U("Album names: ") << fmtBoldEnd << Mpd.NumberOfAlbums() << '\n'; - *w << fmtBold << U("Songs in database: ") << fmtBoldEnd << Mpd.NumberOfSongs() << '\n'; + *w << NC::fmtBold << U("Artist names: ") << NC::fmtBoldEnd << Mpd.NumberOfArtists() << '\n'; + *w << NC::fmtBold << U("Album names: ") << NC::fmtBoldEnd << Mpd.NumberOfAlbums() << '\n'; + *w << NC::fmtBold << U("Songs in database: ") << NC::fmtBoldEnd << Mpd.NumberOfSongs() << '\n'; *w << '\n'; - *w << fmtBold << U("Last DB update: ") << fmtBoldEnd << Timestamp(Mpd.DBUpdateTime()) << '\n'; + *w << NC::fmtBold << U("Last DB update: ") << NC::fmtBoldEnd << Timestamp(Mpd.DBUpdateTime()) << '\n'; *w << '\n'; - *w << fmtBold << U("URL Handlers:") << fmtBoldEnd; + *w << NC::fmtBold << U("URL Handlers:") << NC::fmtBoldEnd; for (auto it = itsURLHandlers.begin(); it != itsURLHandlers.end(); ++it) *w << (it != itsURLHandlers.begin() ? U(", ") : U(" ")) << *it; *w << U("\n\n"); - *w << fmtBold << U("Tag Types:") << fmtBoldEnd; + *w << NC::fmtBold << U("Tag Types:") << NC::fmtBoldEnd; for (auto it = itsTagTypes.begin(); it != itsTagTypes.end(); ++it) *w << (it != itsTagTypes.begin() ? U(", ") : U(" ")) << *it; diff --git a/src/server_info.h b/src/server_info.h index b65c5f21..298a61a7 100644 --- a/src/server_info.h +++ b/src/server_info.h @@ -23,7 +23,7 @@ #include "screen.h" -class ServerInfo : public Screen +class ServerInfo : public Screen { public: virtual void SwitchTo(); @@ -38,7 +38,7 @@ class ServerInfo : public Screen virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return false; } diff --git a/src/settings.cpp b/src/settings.cpp index 2c6d95e5..18bfb870 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -25,6 +25,7 @@ #else # include #endif // WIN32 +#include #include #include #include @@ -58,33 +59,33 @@ KeyConfiguration Keys; namespace { - NCurses::Color stringToColor(const std::string &color) + NC::Color stringToColor(const std::string &color) { - NCurses::Color result = NCurses::clDefault; + NC::Color result = NC::clDefault; if (color == "black") - result = NCurses::clBlack; + result = NC::clBlack; else if (color == "red") - result = NCurses::clRed; + result = NC::clRed; else if (color == "green") - result = NCurses::clGreen; + result = NC::clGreen; else if (color == "yellow") - result = NCurses::clYellow; + result = NC::clYellow; else if (color == "blue") - result = NCurses::clBlue; + result = NC::clBlue; else if (color == "magenta") - result = NCurses::clMagenta; + result = NC::clMagenta; else if (color == "cyan") - result = NCurses::clCyan; + result = NC::clCyan; else if (color == "white") - result = NCurses::clWhite; + result = NC::clWhite; return result; } - Border stringToBorder(const std::string &border) + NC::Border stringToBorder(const std::string &border) { - return Border(stringToColor(border)); + return NC::Border(stringToColor(border)); } BasicScreen *intToScreen(int n) @@ -308,31 +309,31 @@ void Configuration::SetDefaults() tag_editor_album_format = "{{(%y) }%b}"; new_header_first_line = "{$b$1$aqqu$/a$9 {%t}|{%f} $1$atqq$/a$9$/b}"; new_header_second_line = "{{{$4$b%a$/b$9}{ - $7%b$9}{ ($4%y$9)}}|{%D}}"; - browser_playlist_prefix << clRed << "(playlist)" << clEnd << ' '; + browser_playlist_prefix << NC::clRed << "(playlist)" << NC::clEnd << ' '; progressbar = U("=>\0"); visualizer_chars = U("◆│"); pattern = "%n - %t"; - selected_item_prefix << clMagenta; - selected_item_suffix << clEnd; - now_playing_prefix << fmtBold; - now_playing_suffix << fmtBoldEnd; - color1 = clWhite; - color2 = clGreen; - empty_tags_color = clCyan; - header_color = clDefault; - volume_color = clDefault; - state_line_color = clDefault; - state_flags_color = clDefault; - main_color = clYellow; + selected_item_prefix << NC::clMagenta; + selected_item_suffix << NC::clEnd; + now_playing_prefix << NC::fmtBold; + now_playing_suffix << NC::fmtBoldEnd; + color1 = NC::clWhite; + color2 = NC::clGreen; + empty_tags_color = NC::clCyan; + header_color = NC::clDefault; + volume_color = NC::clDefault; + state_line_color = NC::clDefault; + state_flags_color = NC::clDefault; + main_color = NC::clYellow; main_highlight_color = main_color; - progressbar_color = clDefault; - progressbar_elapsed_color = clDefault; - statusbar_color = clDefault; - alternative_ui_separator_color = clBlack; - active_column_color = clRed; - window_border = brGreen; - active_window_border = brRed; - visualizer_color = clYellow; + progressbar_color = NC::clDefault; + progressbar_elapsed_color = NC::clDefault; + statusbar_color = NC::clDefault; + alternative_ui_separator_color = NC::clBlack; + active_column_color = NC::clRed; + window_border = NC::brGreen; + active_window_border = NC::brRed; + visualizer_color = NC::clYellow; media_lib_primary_tag = MPD_TAG_ARTIST; enable_idle_notifications = true; colors_enabled = true; @@ -567,7 +568,7 @@ void Configuration::Read() // make version without colors if (song_status_format.find("$") != std::string::npos) { - Buffer status_no_colors; + NC::Buffer status_no_colors; String2Buffer(song_status_format, status_no_colors); song_status_format_no_colors = status_no_colors.Str(); } @@ -682,7 +683,7 @@ void Configuration::Read() { selected_item_prefix.Clear(); String2Buffer(v, selected_item_prefix); - selected_item_prefix_length = Window::Length(TO_WSTRING(selected_item_prefix.Str())); + selected_item_prefix_length = NC::Window::Length(TO_WSTRING(selected_item_prefix.Str())); } } else if (name == "selected_item_suffix") @@ -691,7 +692,7 @@ void Configuration::Read() { selected_item_suffix.Clear(); String2Buffer(v, selected_item_suffix); - selected_item_suffix_length = Window::Length(TO_WSTRING(selected_item_suffix.Str())); + selected_item_suffix_length = NC::Window::Length(TO_WSTRING(selected_item_suffix.Str())); } } else if (name == "now_playing_prefix") @@ -700,7 +701,7 @@ void Configuration::Read() { now_playing_prefix.Clear(); String2Buffer(v, now_playing_prefix); - now_playing_prefix_length = Window::Length(TO_WSTRING(now_playing_prefix.Str())); + now_playing_prefix_length = NC::Window::Length(TO_WSTRING(now_playing_prefix.Str())); } } else if (name == "now_playing_suffix") @@ -709,7 +710,7 @@ void Configuration::Read() { now_playing_suffix.Clear(); String2Buffer(TO_WSTRING(v), now_playing_suffix); - now_playing_suffix_length = Window::Length(now_playing_suffix.Str()); + now_playing_suffix_length = NC::Window::Length(now_playing_suffix.Str()); } } else if (name == "color1") @@ -1172,7 +1173,7 @@ void Configuration::GenerateColumns() // generate format for converting tags in columns to string for Playlist::SongInColumnsToString() char tag[] = "{% }|"; song_in_columns_to_string_format = "{"; - for (std::vector::const_iterator it = columns.begin(); it != columns.end(); ++it) + for (auto it = columns.begin(); it != columns.end(); ++it) { for (std::string::const_iterator j = it->type.begin(); j != it->type.end(); ++j) { @@ -1193,7 +1194,7 @@ void Configuration::MakeProperPath(std::string &dir) return; if (dir[0] == '~') dir.replace(0, 1, home_directory); - replace(dir.begin(), dir.end(), '\\', '/'); + std::replace(dir.begin(), dir.end(), '\\', '/'); if (*dir.rbegin() != '/') dir += '/'; } diff --git a/src/settings.h b/src/settings.h index 874272b6..91c3c2f9 100644 --- a/src/settings.h +++ b/src/settings.h @@ -23,11 +23,9 @@ #include #include - #include - #include "actions.h" -#include "ncmpcpp.h" +#include "strbuffer.h" class BasicScreen; // forward declaration for screens sequence @@ -41,7 +39,7 @@ struct Column std::string type; int width; int stretch_limit; - Color color; + NC::Color color; bool fixed; bool right_alignment; bool display_empty_tag; @@ -126,30 +124,30 @@ struct Configuration std::vector columns; - Buffer browser_playlist_prefix; - Buffer selected_item_prefix; - Buffer selected_item_suffix; - Buffer now_playing_prefix; - basic_buffer now_playing_suffix; + NC::Buffer browser_playlist_prefix; + NC::Buffer selected_item_prefix; + NC::Buffer selected_item_suffix; + NC::Buffer now_playing_prefix; + NC::basic_buffer now_playing_suffix; - Color color1; - Color color2; - Color empty_tags_color; - Color header_color; - Color volume_color; - Color state_line_color; - Color state_flags_color; - Color main_color; - Color main_highlight_color; - Color progressbar_color; - Color progressbar_elapsed_color; - Color statusbar_color; - Color alternative_ui_separator_color; - Color active_column_color; - Color visualizer_color; + NC::Color color1; + NC::Color color2; + NC::Color empty_tags_color; + NC::Color header_color; + NC::Color volume_color; + NC::Color state_line_color; + NC::Color state_flags_color; + NC::Color main_color; + NC::Color main_highlight_color; + NC::Color progressbar_color; + NC::Color progressbar_elapsed_color; + NC::Color statusbar_color; + NC::Color alternative_ui_separator_color; + NC::Color active_column_color; + NC::Color visualizer_color; - Border window_border; - Border active_window_border; + NC::Border window_border; + NC::Border active_window_border; mpd_tag_type media_lib_primary_tag; diff --git a/src/song.h b/src/song.h index b23fe584..044de3c7 100644 --- a/src/song.h +++ b/src/song.h @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -85,6 +86,8 @@ struct Song size_t m_hash; }; +typedef std::vector SongList; + } #endif diff --git a/src/song_info.cpp b/src/song_info.cpp index f7f5625b..6ff49097 100644 --- a/src/song_info.cpp +++ b/src/song_info.cpp @@ -19,9 +19,15 @@ ***************************************************************************/ #include "global.h" +#include "helpers.h" #include "song_info.h" #include "tag_editor.h" +#ifdef HAVE_TAGLIB_H +# include "fileref.h" +# include "tag.h" +#endif // HAVE_TAGLIB_H + using Global::MainHeight; using Global::MainStartY; @@ -45,7 +51,7 @@ const SongInfo::Metadata SongInfo::Tags[] = void SongInfo::Init() { - w = new Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Scrollpad(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); isInitialized = 1; } @@ -109,24 +115,24 @@ void SongInfo::PrepareSong(MPD::Song &s) TagLib::FileRef f(path_to_file.c_str()); # endif // HAVE_TAGLIB_H - *w << fmtBold << Config.color1 << U("Filename: ") << fmtBoldEnd << Config.color2 << s.getName() << '\n' << clEnd; - *w << fmtBold << U("Directory: ") << fmtBoldEnd << Config.color2; + *w << NC::fmtBold << Config.color1 << U("Filename: ") << NC::fmtBoldEnd << Config.color2 << s.getName() << '\n' << NC::clEnd; + *w << NC::fmtBold << U("Directory: ") << NC::fmtBoldEnd << Config.color2; ShowTag(*w, s.getDirectory()); - *w << U("\n\n") << clEnd; - *w << fmtBold << U("Length: ") << fmtBoldEnd << Config.color2 << s.getLength() << '\n' << clEnd; + *w << U("\n\n") << NC::clEnd; + *w << NC::fmtBold << U("Length: ") << NC::fmtBoldEnd << Config.color2 << s.getLength() << '\n' << NC::clEnd; # ifdef HAVE_TAGLIB_H if (!f.isNull()) { - *w << fmtBold << U("Bitrate: ") << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << U(" kbps\n") << clEnd; - *w << fmtBold << U("Sample rate: ") << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << U(" Hz\n") << clEnd; - *w << fmtBold << U("Channels: ") << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? U("Mono") : U("Stereo")) << '\n' << clDefault; + *w << NC::fmtBold << U("Bitrate: ") << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << U(" kbps\n") << NC::clEnd; + *w << NC::fmtBold << U("Sample rate: ") << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << U(" Hz\n") << NC::clEnd; + *w << NC::fmtBold << U("Channels: ") << NC::fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? U("Mono") : U("Stereo")) << '\n' << NC::clDefault; } # endif // HAVE_TAGLIB_H - *w << clDefault; + *w << NC::clDefault; for (const Metadata *m = Tags; m->Name; ++m) { - *w << fmtBold << '\n' << TO_WSTRING(m->Name) << U(": ") << fmtBoldEnd; + *w << NC::fmtBold << '\n' << TO_WSTRING(m->Name) << U(": ") << NC::fmtBoldEnd; ShowTag(*w, s.getTags(m->Get)); } } diff --git a/src/song_info.h b/src/song_info.h index ad369850..98c9c648 100644 --- a/src/song_info.h +++ b/src/song_info.h @@ -24,7 +24,7 @@ #include "screen.h" #include "mutable_song.h" -class SongInfo : public Screen +class SongInfo : public Screen { public: struct Metadata @@ -44,7 +44,7 @@ class SongInfo : public Screen virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return true; } diff --git a/src/status.cpp b/src/status.cpp index 51256eb9..39a4de0a 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -346,7 +346,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) myPlaylist->NowPlaying = -1; if (Config.new_design) { - *wHeader << XY(0, 0) << wclrtoeol << XY(0, 1) << wclrtoeol; + *wHeader << NC::XY(0, 0) << wclrtoeol << NC::XY(0, 1) << wclrtoeol; player_state = "[stopped]"; changed.Volume = 1; changed.StatusFlags = 1; @@ -362,20 +362,20 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) } # ifdef ENABLE_VISUALIZER if (myScreen == myVisualizer) - wFooter->SetTimeout(state == MPD::psPlay ? Visualizer::WindowTimeout : ncmpcpp_window_timeout); + wFooter->SetTimeout(state == MPD::psPlay ? Visualizer::WindowTimeout : 500); # endif // ENABLE_VISUALIZER if (Config.new_design) { - *wHeader << XY(0, 1) << fmtBold << player_state << fmtBoldEnd; + *wHeader << NC::XY(0, 1) << NC::fmtBold << player_state << NC::fmtBoldEnd; wHeader->Refresh(); } else if (!block_statusbar_update && Config.statusbar_visibility) { - *wFooter << XY(0, 1); + *wFooter << NC::XY(0, 1); if (player_state.empty()) *wFooter << wclrtoeol; else - *wFooter << fmtBold << player_state << fmtBoldEnd; + *wFooter << NC::fmtBold << player_state << NC::fmtBoldEnd; } } if (changed.SongID) @@ -442,28 +442,28 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) tracklength += " kbps"; } - basic_buffer first, second; + NC::basic_buffer first, second; String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.new_header_first_line, "$"))), first); String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.new_header_second_line, "$"))), second); - size_t first_len = Window::Length(first.Str()); + size_t first_len = NC::Window::Length(first.Str()); size_t first_margin = (std::max(tracklength.length()+1, VolumeState.length()))*2; size_t first_start = first_len < COLS-first_margin ? (COLS-first_len)/2 : tracklength.length()+1; - size_t second_len = Window::Length(second.Str()); + size_t second_len = NC::Window::Length(second.Str()); size_t second_margin = (std::max(player_state.length(), size_t(8))+1)*2; size_t second_start = second_len < COLS-second_margin ? (COLS-second_len)/2 : player_state.length()+1; if (!Global::SeekingInProgress) - *wHeader << XY(0, 0) << wclrtoeol << tracklength; - *wHeader << XY(first_start, 0); + *wHeader << NC::XY(0, 0) << wclrtoeol << tracklength; + *wHeader << NC::XY(first_start, 0); first.Write(*wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, U(" ** ")); - *wHeader << XY(0, 1) << wclrtoeol << fmtBold << player_state << fmtBoldEnd; - *wHeader << XY(second_start, 1); + *wHeader << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd; + *wHeader << NC::XY(second_start, 1); second.Write(*wHeader, second_line_scroll_begin, COLS-player_state.length()-8-2, U(" ** ")); - *wHeader << XY(wHeader->GetWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << clEnd; + *wHeader << NC::XY(wHeader->GetWidth()-VolumeState.length(), 0) << Config.volume_color << VolumeState << NC::clEnd; changed.StatusFlags = 1; } @@ -494,11 +494,11 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) tracklength += MPD::Song::ShowTime(Mpd.GetElapsedTime()); tracklength += "]"; } - basic_buffer np_song; + NC::basic_buffer np_song; String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.song_status_format, "$"))), np_song); - *wFooter << XY(0, 1) << wclrtoeol << fmtBold << player_state << fmtBoldEnd; + *wFooter << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd; np_song.Write(*wFooter, playing_song_scroll_begin, wFooter->GetWidth()-player_state.length()-tracklength.length(), U(" ** ")); - *wFooter << fmtBold << XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength << fmtBoldEnd; + *wFooter << NC::fmtBold << NC::XY(wFooter->GetWidth()-tracklength.length(), 1) << tracklength << NC::fmtBoldEnd; } if (!block_progressbar_update) DrawProgressbar(Mpd.GetElapsedTime(), Mpd.GetTotalTime()); @@ -507,7 +507,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) else { if (!block_statusbar_update && Config.statusbar_visibility) - *wFooter << XY(0, 1) << wclrtoeol; + *wFooter << NC::XY(0, 1) << wclrtoeol; } } @@ -571,12 +571,12 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) switch_state += mpd_crossfade ? mpd_crossfade : '-'; switch_state += mpd_db_updating ? mpd_db_updating : '-'; switch_state += ']'; - *wHeader << XY(COLS-switch_state.length(), 1) << fmtBold << Config.state_flags_color << switch_state << clEnd << fmtBoldEnd; + *wHeader << NC::XY(COLS-switch_state.length(), 1) << NC::fmtBold << Config.state_flags_color << switch_state << NC::clEnd << NC::fmtBoldEnd; if (Config.new_design && !Config.header_visibility) // in this case also draw separator { - *wHeader << fmtBold << clBlack; + *wHeader << NC::fmtBold << NC::clBlack; mvwhline(wHeader->Raw(), 2, 0, 0, COLS); - *wHeader << clEnd << fmtBoldEnd; + *wHeader << NC::clEnd << NC::fmtBoldEnd; } wHeader->Refresh(); } @@ -625,8 +625,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) VolumeState += "%"; } *wHeader << Config.volume_color; - *wHeader << XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState; - *wHeader << clEnd; + *wHeader << NC::XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState; + *wHeader << NC::clEnd; wHeader->Refresh(); } if (changed.Outputs) @@ -642,9 +642,9 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) ApplyToVisibleWindows(&BasicScreen::RefreshWindow); } -Window &Statusbar() +NC::Window &Statusbar() { - *wFooter << XY(0, Config.statusbar_visibility) << wclrtoeol; + *wFooter << NC::XY(0, Config.statusbar_visibility) << wclrtoeol; return *wFooter; } @@ -653,7 +653,7 @@ void DrawProgressbar(unsigned elapsed, unsigned time) unsigned pb_width = wFooter->GetWidth(); unsigned howlong = time ? pb_width*elapsed/time : 0; if (Config.progressbar_boldness) - *wFooter << fmtBold; + *wFooter << NC::fmtBold; *wFooter << Config.progressbar_color; if (Config.progressbar[2] != '\0') { @@ -672,11 +672,11 @@ void DrawProgressbar(unsigned elapsed, unsigned time) *wFooter << Config.progressbar[0]; if (howlong < wFooter->GetWidth()) *wFooter << Config.progressbar[1]; - *wFooter << clEnd; + *wFooter << NC::clEnd; } - *wFooter << clEnd; + *wFooter << NC::clEnd; if (Config.progressbar_boldness) - *wFooter << fmtBoldEnd; + *wFooter << NC::fmtBoldEnd; } void ShowMessage(const char *format, ...) @@ -690,7 +690,7 @@ void ShowMessage(const char *format, ...) else block_progressbar_update = 1; wFooter->GotoXY(0, Config.statusbar_visibility); - *wFooter << fmtBoldEnd; + *wFooter << NC::fmtBoldEnd; va_list list; va_start(list, format); wmove(wFooter->Raw(), Config.statusbar_visibility, 0); diff --git a/src/status.h b/src/status.h index 434a0b9a..42f0e24b 100644 --- a/src/status.h +++ b/src/status.h @@ -23,7 +23,6 @@ #include "interfaces.h" #include "mpdpp.h" -#include "ncmpcpp.h" #ifndef USE_PDCURSES void WindowTitle(const std::string &); @@ -41,7 +40,7 @@ void TraceMpdStatus(); void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *); void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *); -Window &Statusbar(); +NC::Window &Statusbar(); void DrawProgressbar(unsigned elapsed, unsigned time); void ShowMessage(const char *, ...) GNUC_PRINTF(1, 2); diff --git a/src/strbuffer.h b/src/strbuffer.h index fd6c40f6..a1d06c7e 100644 --- a/src/strbuffer.h +++ b/src/strbuffer.h @@ -26,7 +26,7 @@ #include -namespace NCurses { +namespace NC { /// Buffer template class that can store text along with its /// format attributes. The content can be easily printed to @@ -234,8 +234,6 @@ typedef basic_buffer Buffer; /// typedef basic_buffer WBuffer; - - template basic_buffer::basic_buffer(const basic_buffer &b) : itsString(b.itsString), itsFormat(b.itsFormat) { } diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 43309fcd..1450643e 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -32,15 +32,21 @@ #include "mpegfile.h" #include "vorbisfile.h" #include "flacfile.h" +#include "xiphcomment.h" +#include "fileref.h" +#include "tag.h" #include "browser.h" #include "charset.h" #include "display.h" #include "global.h" +#include "helpers.h" #include "song_info.h" #include "playlist.h" #include "utility/comparators.h" +using namespace std::placeholders; + using Global::myScreen; using Global::MainHeight; using Global::MainStartY; @@ -83,8 +89,8 @@ std::string GenerateFilename(const MPD::MutableSong &s, const std::string &patte std::string ParseFilename(MPD::MutableSong &s, std::string mask, bool preview); std::string SongToString(const MPD::MutableSong &s); -bool DirEntryMatcher(const Regex &rx, const string_pair &dir, bool filter); -bool AlbumEntryMatcher(const Regex &rx, const string_pair &dir); +bool DirEntryMatcher(const Regex &rx, const std::pair &dir, bool filter); +bool AlbumEntryMatcher(const Regex &rx, const std::pair &dir); bool SongEntryMatcher(const Regex &rx, const MPD::MutableSong &s); } @@ -94,13 +100,13 @@ void TagEditor::Init() PatternsFile = Config.ncmpcpp_directory + "patterns.list"; SetDimensions(0, COLS); - Albums = new Menu(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, brNone); + Albums = new NC::Menu< std::pair >(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, NC::brNone); Albums->HighlightColor(Config.active_column_color); Albums->CyclicScrolling(Config.use_cyclic_scrolling); Albums->CenteredCursor(Config.centered_cursor); Albums->setItemDisplayer(Display::Pair); - Dirs = new Menu(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Directories" : "", Config.main_color, brNone); + Dirs = new NC::Menu< std::pair >(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Directories" : "", Config.main_color, NC::brNone); Dirs->HighlightColor(Config.active_column_color); Dirs->CyclicScrolling(Config.use_cyclic_scrolling); Dirs->CenteredCursor(Config.centered_cursor); @@ -108,7 +114,7 @@ void TagEditor::Init() LeftColumn = Config.albums_in_tag_editor ? Albums : Dirs; - TagTypes = new Menu(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, Config.titles_visibility ? "Tag types" : "", Config.main_color, brNone); + TagTypes = new NC::Menu(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, Config.titles_visibility ? "Tag types" : "", Config.main_color, NC::brNone); TagTypes->HighlightColor(Config.main_highlight_color); TagTypes->CyclicScrolling(Config.use_cyclic_scrolling); TagTypes->CenteredCursor(Config.centered_cursor); @@ -128,7 +134,7 @@ void TagEditor::Init() TagTypes->AddItem("Reset"); TagTypes->AddItem("Save"); - Tags = new Menu(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Tags" : "", Config.main_color, brNone); + Tags = new NC::Menu(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Tags" : "", Config.main_color, NC::brNone); Tags->HighlightColor(Config.main_highlight_color); Tags->CyclicScrolling(Config.use_cyclic_scrolling); Tags->CenteredCursor(Config.centered_cursor); @@ -136,7 +142,7 @@ void TagEditor::Init() Tags->SetSelectSuffix(Config.selected_item_suffix); Tags->setItemDisplayer(Display::Tags); - FParserDialog = new Menu((COLS-FParserDialogWidth)/2, (MainHeight-FParserDialogHeight)/2+MainStartY, FParserDialogWidth, FParserDialogHeight, "", Config.main_color, Config.window_border); + FParserDialog = new NC::Menu((COLS-FParserDialogWidth)/2, (MainHeight-FParserDialogHeight)/2+MainStartY, FParserDialogWidth, FParserDialogHeight, "", Config.main_color, Config.window_border); FParserDialog->CyclicScrolling(Config.use_cyclic_scrolling); FParserDialog->CenteredCursor(Config.centered_cursor); FParserDialog->setItemDisplayer(Display::Default); @@ -145,14 +151,14 @@ void TagEditor::Init() FParserDialog->AddSeparator(); FParserDialog->AddItem("Cancel"); - FParser = new Menu((COLS-FParserWidth)/2, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthOne, FParserHeight, "_", Config.main_color, Config.active_window_border); + FParser = new NC::Menu((COLS-FParserWidth)/2, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthOne, FParserHeight, "_", Config.main_color, Config.active_window_border); FParser->CyclicScrolling(Config.use_cyclic_scrolling); FParser->CenteredCursor(Config.centered_cursor); FParser->setItemDisplayer(Display::Default); - FParserLegend = new Scrollpad((COLS-FParserWidth)/2+FParserWidthOne, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthTwo, FParserHeight, "Legend", Config.main_color, Config.window_border); + FParserLegend = new NC::Scrollpad((COLS-FParserWidth)/2+FParserWidthOne, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthTwo, FParserHeight, "Legend", Config.main_color, Config.window_border); - FParserPreview = new Scrollpad((COLS-FParserWidth)/2+FParserWidthOne, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthTwo, FParserHeight, "Preview", Config.main_color, Config.window_border); + FParserPreview = new NC::Scrollpad((COLS-FParserWidth)/2+FParserWidthOne, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthTwo, FParserHeight, "Preview", Config.main_color, Config.window_border); w = LeftColumn; isInitialized = 1; @@ -261,7 +267,7 @@ void TagEditor::Update() Tags->Clear(); if (Config.albums_in_tag_editor) { - *Albums << XY(0, 0) << "Fetching albums..."; + *Albums << NC::XY(0, 0) << "Fetching albums..."; Albums->Window::Refresh(); Mpd.BlockIdle(true); // for the same reason as in media library auto albums = Mpd.GetList(MPD_TAG_ALBUM); @@ -382,9 +388,9 @@ void TagEditor::EnterPressed() *FParserLegend << U("%p - performer\n"); *FParserLegend << U("%d - disc\n"); *FParserLegend << U("%C - comment\n\n"); - *FParserLegend << fmtBold << U("Files:\n") << fmtBoldEnd; + *FParserLegend << NC::fmtBold << U("Files:\n") << NC::fmtBoldEnd; for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it) - *FParserLegend << Config.color2 << U(" * ") << clEnd << (*it)->getName() << '\n'; + *FParserLegend << Config.color2 << U(" * ") << NC::clEnd << (*it)->getName() << '\n'; FParserLegend->Flush(); if (!Patterns.empty()) @@ -445,7 +451,7 @@ void TagEditor::EnterPressed() { if (FParserUsePreview) { - *FParserPreview << fmtBold << s.getName() << U(":\n") << fmtBoldEnd; + *FParserPreview << NC::fmtBold << s.getName() << U(":\n") << NC::fmtBoldEnd; *FParserPreview << ParseFilename(s, Config.pattern, FParserUsePreview) << '\n'; } else @@ -465,9 +471,9 @@ void TagEditor::EnterPressed() } if (!FParserUsePreview) s.setNewURI(new_file + extension); - *FParserPreview << file << Config.color2 << U(" -> ") << clEnd; + *FParserPreview << file << Config.color2 << U(" -> ") << NC::clEnd; if (new_file.empty()) - *FParserPreview << Config.empty_tags_color << Config.empty_tag << clEnd; + *FParserPreview << Config.empty_tags_color << Config.empty_tag << NC::clEnd; else *FParserPreview << new_file << extension; *FParserPreview << '\n' << '\n'; @@ -558,7 +564,7 @@ void TagEditor::EnterPressed() if (id > 0 && w == TagTypes) { LockStatusbar(); - Statusbar() << fmtBold << TagTypes->Current().value() << fmtBoldEnd << ": "; + Statusbar() << NC::fmtBold << TagTypes->Current().value() << NC::fmtBoldEnd << ": "; std::string new_tag = wFooter->GetString(Tags->Current().value().getTags(get)); UnlockStatusbar(); for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it) @@ -567,12 +573,12 @@ void TagEditor::EnterPressed() else if (w == Tags) { LockStatusbar(); - Statusbar() << fmtBold << TagTypes->Current().value() << fmtBoldEnd << ": "; + Statusbar() << NC::fmtBold << TagTypes->Current().value() << NC::fmtBoldEnd << ": "; std::string new_tag = wFooter->GetString(Tags->Current().value().getTags(get)); UnlockStatusbar(); if (new_tag != Tags->Current().value().getTags(get)) Tags->Current().value().setTag(set, new_tag); - Tags->Scroll(wDown); + Tags->Scroll(NC::wDown); } } else @@ -597,12 +603,12 @@ void TagEditor::EnterPressed() std::string extension = old_name.substr(last_dot); old_name = old_name.substr(0, last_dot); LockStatusbar(); - Statusbar() << fmtBold << "New filename: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "New filename: " << NC::fmtBoldEnd; std::string new_name = wFooter->GetString(old_name); UnlockStatusbar(); if (!new_name.empty() && new_name != old_name) s.setNewURI(new_name + extension); - Tags->Scroll(wDown); + Tags->Scroll(NC::wDown); } } else if (id == 16) // capitalize first letters @@ -660,7 +666,7 @@ void TagEditor::SpacePressed() if (w == Tags && !Tags->Empty()) { Tags->Current().setSelected(!Tags->Current().isSelected()); - w->Scroll(wDown); + w->Scroll(NC::wDown); return; } if (w != LeftColumn) @@ -686,7 +692,7 @@ void TagEditor::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } } else if (w == FParser || w == FParserHelper) @@ -702,13 +708,13 @@ void TagEditor::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } else if (FParserHelper->hasCoords(me.x, me.y)) { if (w != FParserHelper) NextColumn(); - reinterpret_cast *>(this)->Screen::MouseButtonPressed(me); + ScrollpadMouseButtonPressed(FParserHelper, me); } } else if (!LeftColumn->Empty() && LeftColumn->hasCoords(me.x, me.y)) @@ -727,7 +733,7 @@ void TagEditor::MouseButtonPressed(MEVENT me) SpacePressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); Tags->Clear(); } else if (!TagTypes->Empty() && TagTypes->hasCoords(me.x, me.y)) @@ -744,7 +750,7 @@ void TagEditor::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } else if (!Tags->Empty() && Tags->hasCoords(me.x, me.y)) { @@ -761,7 +767,7 @@ void TagEditor::MouseButtonPressed(MEVENT me) EnterPressed(); } else - Screen::MouseButtonPressed(me); + Screen::MouseButtonPressed(me); } } @@ -771,9 +777,9 @@ std::string TagEditor::currentFilter() { std::string filter; if (w == Dirs) - filter = RegexFilter::currentFilter(*Dirs); + filter = RegexFilter< std::pair >::currentFilter(*Dirs); else if (w == Albums) - filter = RegexFilter::currentFilter(*Albums); + filter = RegexFilter< std::pair >::currentFilter(*Albums); else if (w == Tags) filter = RegexFilter::currentFilter(*Tags); return filter; @@ -785,13 +791,13 @@ void TagEditor::applyFilter(const std::string &filter) { Dirs->ShowAll(); auto fun = std::bind(DirEntryMatcher, _1, _2, true); - auto rx = RegexFilter(filter, Config.regex_type, fun); + auto rx = RegexFilter< std::pair >(filter, Config.regex_type, fun); Dirs->filter(Dirs->Begin(), Dirs->End(), rx); } else if (w == Albums) { Albums->ShowAll(); - auto rx = RegexFilter(filter, Config.regex_type, AlbumEntryMatcher); + auto rx = RegexFilter< std::pair >(filter, Config.regex_type, AlbumEntryMatcher); Albums->filter(Albums->Begin(), Albums->End(), rx); } else if (w == Tags) @@ -810,12 +816,12 @@ bool TagEditor::search(const std::string &constraint) if (w == Dirs) { auto fun = std::bind(DirEntryMatcher, _1, _2, false); - auto rx = RegexFilter(constraint, Config.regex_type, fun); + auto rx = RegexFilter< std::pair >(constraint, Config.regex_type, fun); result = Dirs->search(Dirs->Begin(), Dirs->End(), rx); } else if (w == Albums) { - auto rx = RegexFilter(constraint, Config.regex_type, AlbumEntryMatcher); + auto rx = RegexFilter< std::pair >(constraint, Config.regex_type, AlbumEntryMatcher); result = Albums->search(Albums->Begin(), Albums->End(), rx); } else if (w == Tags) @@ -898,7 +904,7 @@ MPD::SongList TagEditor::getSelectedSongs() /***********************************************************************/ -List *TagEditor::GetList() +NC::List *TagEditor::GetList() { if (w == LeftColumn) return LeftColumn; @@ -1392,14 +1398,14 @@ std::string SongToString(const MPD::MutableSong &s) return result.empty() ? Config.empty_tag : result; } -bool DirEntryMatcher(const Regex &rx, const string_pair &dir, bool filter) +bool DirEntryMatcher(const Regex &rx, const std::pair &dir, bool filter) { if (dir.first == "." || dir.first == "..") return filter; return rx.match(dir.first); } -bool AlbumEntryMatcher(const Regex &rx, const string_pair &dir) +bool AlbumEntryMatcher(const Regex &rx, const std::pair &dir) { return rx.match(dir.first); } diff --git a/src/tag_editor.h b/src/tag_editor.h index af89dff1..56f0b66f 100644 --- a/src/tag_editor.h +++ b/src/tag_editor.h @@ -27,17 +27,13 @@ #include -// taglib headers -#include "xiphcomment.h" -#include "fileref.h" -#include "tag.h" - +#include "interfaces.h" #include "mpdpp.h" #include "mutable_song.h" #include "regex_filter.h" #include "screen.h" -class TagEditor : public Screen, public Filterable, public HasSongs, public Searchable +class TagEditor : public Screen, public Filterable, public HasSongs, public Searchable { public: TagEditor() : FParser(0), FParserHelper(0), FParserLegend(0), FParserPreview(0), itsBrowsedDir("/") { } @@ -73,7 +69,7 @@ class TagEditor : public Screen, public Filterable, public HasSongs, pub virtual void removeSelection(); virtual MPD::SongList getSelectedSongs(); - virtual List *GetList(); + virtual NC::List *GetList(); virtual bool isMergable() { return true; } @@ -84,11 +80,11 @@ class TagEditor : public Screen, public Filterable, public HasSongs, pub void LocateSong(const MPD::Song &s); - Menu *LeftColumn; - Menu *Albums; - Menu *Dirs; - Menu *TagTypes; - Menu *Tags; + NC::Menu< std::pair > *LeftColumn; + NC::Menu< std::pair > *Albums; + NC::Menu< std::pair > *Dirs; + NC::Menu *TagTypes; + NC::Menu *Tags; /// NOTICE: this string is always in utf8, no need to convert it const std::string &CurrentDir() { return itsBrowsedDir; } @@ -104,11 +100,11 @@ class TagEditor : public Screen, public Filterable, public HasSongs, pub void SetDimensions(size_t, size_t); std::vector EditedSongs; - Menu *FParserDialog; - Menu *FParser; - Scrollpad *FParserHelper; - Scrollpad *FParserLegend; - Scrollpad *FParserPreview; + NC::Menu *FParserDialog; + NC::Menu *FParser; + NC::Scrollpad *FParserHelper; + NC::Scrollpad *FParserLegend; + NC::Scrollpad *FParserPreview; bool FParserUsePreview; std::string itsBrowsedDir; diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index 53d574fd..922e510b 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -26,10 +26,12 @@ #include "mpegfile.h" #include "vorbisfile.h" #include "flacfile.h" +#include "fileref.h" #include "browser.h" #include "charset.h" #include "display.h" +#include "helpers.h" #include "global.h" #include "song_info.h" #include "playlist.h" @@ -44,11 +46,11 @@ TinyTagEditor *myTinyTagEditor = new TinyTagEditor; void TinyTagEditor::Init() { - w = new Menu(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); + w = new NC::Menu(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone); w->HighlightColor(Config.main_highlight_color); w->CyclicScrolling(Config.use_cyclic_scrolling); w->CenteredCursor(Config.centered_cursor); - w->setItemDisplayer(Display::Default); + w->setItemDisplayer(Display::Default); isInitialized = 1; } @@ -108,15 +110,15 @@ void TinyTagEditor::EnterPressed() if (option < 19) // separator after comment { size_t pos = option-8; - Statusbar() << fmtBold << SongInfo::Tags[pos].Name << ": " << fmtBoldEnd; + Statusbar() << NC::fmtBold << SongInfo::Tags[pos].Name << ": " << NC::fmtBoldEnd; itsEdited.setTag(SongInfo::Tags[pos].Set, Global::wFooter->GetString(itsEdited.getTags(SongInfo::Tags[pos].Get))); w->at(option).value().Clear(); - w->at(option).value() << fmtBold << SongInfo::Tags[pos].Name << ':' << fmtBoldEnd << ' '; + w->at(option).value() << NC::fmtBold << SongInfo::Tags[pos].Name << ':' << NC::fmtBoldEnd << ' '; ShowTag(w->at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get)); } else if (option == 20) { - Statusbar() << fmtBold << "Filename: " << fmtBoldEnd; + Statusbar() << NC::fmtBold << "Filename: " << NC::fmtBoldEnd; std::string filename = itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI(); size_t dot = filename.rfind("."); std::string extension = filename.substr(dot); @@ -124,7 +126,7 @@ void TinyTagEditor::EnterPressed() std::string new_name = Global::wFooter->GetString(filename); itsEdited.setNewURI(new_name + extension); w->at(option).value().Clear(); - w->at(option).value() << fmtBold << "Filename:" << fmtBoldEnd << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI()); + w->at(option).value() << NC::fmtBold << "Filename:" << NC::fmtBoldEnd << ' ' << (itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI()); } UnlockStatusbar(); @@ -166,7 +168,7 @@ void TinyTagEditor::MouseButtonPressed(MEVENT me) } } else - Screen< Menu >::MouseButtonPressed(me); + Screen< NC::Menu >::MouseButtonPressed(me); } void TinyTagEditor::SetEdited(const MPD::Song &s) @@ -214,23 +216,23 @@ bool TinyTagEditor::getTags() w->Highlight(8); - w->at(0).value() << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << itsEdited.getName() << clEnd; - w->at(1).value() << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2; + w->at(0).value() << NC::fmtBold << Config.color1 << "Song name: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getName() << NC::clEnd; + w->at(1).value() << NC::fmtBold << Config.color1 << "Location in DB: " << NC::fmtBoldEnd << Config.color2; ShowTag(w->at(1).value(), itsEdited.getDirectory()); - w->at(1).value() << clEnd; - w->at(3).value() << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << itsEdited.getLength() << clEnd; - w->at(4).value() << fmtBold << Config.color1 << "Bitrate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << clEnd; - w->at(5).value() << fmtBold << Config.color1 << "Sample rate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << clEnd; - w->at(6).value() << fmtBold << Config.color1 << "Channels: " << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << clDefault; + w->at(1).value() << NC::clEnd; + w->at(3).value() << NC::fmtBold << Config.color1 << "Length: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getLength() << NC::clEnd; + w->at(4).value() << NC::fmtBold << Config.color1 << "Bitrate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << NC::clEnd; + w->at(5).value() << NC::fmtBold << Config.color1 << "Sample rate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << NC::clEnd; + w->at(6).value() << NC::fmtBold << Config.color1 << "Channels: " << NC::fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << NC::clDefault; unsigned pos = 8; for (const SongInfo::Metadata *m = SongInfo::Tags; m->Name; ++m, ++pos) { - w->at(pos).value() << fmtBold << m->Name << ":" << fmtBoldEnd << ' '; + w->at(pos).value() << NC::fmtBold << m->Name << ":" << NC::fmtBoldEnd << ' '; ShowTag(w->at(pos).value(), itsEdited.getTags(m->Get)); } - w->at(20).value() << fmtBold << "Filename:" << fmtBoldEnd << ' ' << itsEdited.getName(); + w->at(20).value() << NC::fmtBold << "Filename:" << NC::fmtBoldEnd << ' ' << itsEdited.getName(); w->at(22).value() << "Save"; w->at(23).value() << "Cancel"; diff --git a/src/tiny_tag_editor.h b/src/tiny_tag_editor.h index be172354..c734646c 100644 --- a/src/tiny_tag_editor.h +++ b/src/tiny_tag_editor.h @@ -31,7 +31,7 @@ #include "mutable_song.h" #include "screen.h" -class TinyTagEditor : public Screen< Menu > +class TinyTagEditor : public Screen< NC::Menu > { public: virtual void Resize(); @@ -45,7 +45,7 @@ class TinyTagEditor : public Screen< Menu > virtual bool allowsSelection() { return false; } - virtual List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool isMergable() { return true; } diff --git a/src/visualizer.cpp b/src/visualizer.cpp index 4124b434..7630c87d 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -22,8 +22,6 @@ #ifdef ENABLE_VISUALIZER -#include "global.h" - #include #include #include @@ -33,6 +31,10 @@ #include #include +#include "global.h" +#include "settings.h" +#include "status.h" + using Global::MainStartY; using Global::MainHeight; @@ -42,7 +44,7 @@ const int Visualizer::WindowTimeout = 1000/25; /* 25 fps */ void Visualizer::Init() { - w = new Window(0, MainStartY, COLS, MainHeight, "", Config.visualizer_color, brNone); + w = new NC::Window(0, MainStartY, COLS, MainHeight, "", Config.visualizer_color, NC::brNone); ResetFD(); itsSamples = Config.visualizer_in_stereo ? 4096 : 2048; @@ -173,7 +175,7 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s point_pos /= samples_per_col; point_pos /= std::numeric_limits::max(); point_pos *= half_height; - *w << XY(i, y_offset+half_height+point_pos) << Config.visualizer_chars[0]; + *w << NC::XY(i, y_offset+half_height+point_pos) << Config.visualizer_chars[0]; if (i && abs(prev_point_pos-point_pos) > 2) { // if gap is too big. intermediate values are needed @@ -181,7 +183,7 @@ void Visualizer::DrawSoundWave(int16_t *buf, ssize_t samples, size_t y_offset, s const int breakpoint = std::max(prev_point_pos, point_pos); const int half = (prev_point_pos+point_pos)/2; for (int k = std::min(prev_point_pos, point_pos)+1; k < breakpoint; k += 2) - *w << XY(i-(k < half), y_offset+half_height+k) << Config.visualizer_chars[0]; + *w << NC::XY(i-(k < half), y_offset+half_height+k) << Config.visualizer_chars[0]; } prev_point_pos = point_pos; } @@ -215,7 +217,7 @@ void Visualizer::DrawFrequencySpectrum(int16_t *buf, ssize_t samples, size_t y_o const size_t start_y = y_offset > 0 ? y_offset : height-bar_height; const size_t stop_y = std::min(bar_height+start_y, w->GetHeight()); for (size_t j = start_y; j < stop_y; ++j) - *w << XY(i, j) << Config.visualizer_chars[1]; + *w << NC::XY(i, j) << Config.visualizer_chars[1]; } } #endif // HAVE_FFTW3_H diff --git a/src/visualizer.h b/src/visualizer.h index 51173825..b8ae9a97 100644 --- a/src/visualizer.h +++ b/src/visualizer.h @@ -21,9 +21,7 @@ #ifndef _VISUALIZER_H #define _VISUALIZER_H -#ifdef HAVE_CONFIG_H -#include -#endif +#include "config.h" #ifdef ENABLE_VISUALIZER @@ -34,7 +32,7 @@ # include #endif -class Visualizer : public Screen +class Visualizer : public Screen { public: virtual void SwitchTo(); @@ -43,14 +41,14 @@ class Visualizer : public Screen virtual std::basic_string Title(); virtual void Update(); - virtual void Scroll(Where) { } + virtual void Scroll(NC::Where) { } virtual void EnterPressed() { } virtual void SpacePressed(); virtual void MouseButtonPressed(MEVENT) { } virtual bool isTabbable() { return true; } - virtual NCurses::List *GetList() { return 0; } + virtual NC::List *GetList() { return 0; } virtual bool allowsSelection() { return false; } diff --git a/src/window.cpp b/src/window.cpp index 1cedaa56..3a62ffae 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -32,9 +32,9 @@ #include "utility/string.h" #include "window.h" -using namespace NCurses; +namespace NC {// -void NCurses::InitScreen(GNUC_UNUSED const char *window_title, bool enable_colors) +void InitScreen(GNUC_UNUSED const char *window_title, bool enable_colors) { const int ColorsTable[] = { @@ -65,7 +65,7 @@ void NCurses::InitScreen(GNUC_UNUSED const char *window_title, bool enable_color curs_set(0); } -void NCurses::DestroyScreen() +void DestroyScreen() { curs_set(1); endwin(); @@ -919,7 +919,7 @@ size_t Window::Length(const std::wstring &ws) # endif // WIN32 } -void Window::Cut (std::wstring &ws, size_t max_len) +void Window::Cut(std::wstring &ws, size_t max_len) { size_t i = 0; int remained_len = max_len; @@ -933,3 +933,5 @@ void Window::Cut (std::wstring &ws, size_t max_len) } } } + +} diff --git a/src/window.h b/src/window.h index ec323f11..d9725cce 100644 --- a/src/window.h +++ b/src/window.h @@ -118,10 +118,10 @@ # define wcwidth(x) int(!iscntrl(x)) #endif -/// NCurses namespace provides set of easy-to-use +/// NC namespace provides set of easy-to-use /// wrappers over original curses library /// -namespace NCurses +namespace NC { /// Colors used by NCurses ///