get rid of 'using namespace NCurses' directive

This commit is contained in:
Andrzej Rybczak
2012-09-02 15:37:42 +02:00
parent 6f59a175ec
commit d47cad1d50
58 changed files with 607 additions and 613 deletions

View File

@@ -29,6 +29,7 @@
#include "display.h" #include "display.h"
#include "global.h" #include "global.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "helpers.h"
#include "utility/comparators.h" #include "utility/comparators.h"
#include "browser.h" #include "browser.h"
@@ -50,6 +51,12 @@
#include "tiny_tag_editor.h" #include "tiny_tag_editor.h"
#include "visualizer.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; using Global::myScreen;
bool Action::OriginalStatusbarVisibility; bool Action::OriginalStatusbarVisibility;
@@ -64,7 +71,7 @@ size_t Action::FooterStartY;
std::map<ActionType, Action *> Action::Actions; std::map<ActionType, Action *> Action::Actions;
Action::Key Action::NoOp = Action::Key(ERR, ctNCurses); Action::Key Action::NoOp = Action::Key(ERR, ctNCurses);
Action::Key Action::ReadKey(Window &w) Action::Key Action::ReadKey(NC::Window &w)
{ {
std::string tmp; std::string tmp;
int input; int input;
@@ -98,7 +105,7 @@ void Action::ValidateScreenSize()
if (COLS < 20 || MainHeight < 3) if (COLS < 20 || MainHeight < 3)
{ {
DestroyScreen(); NC::DestroyScreen();
std::cout << "Screen is too small!\n"; std::cout << "Screen is too small!\n";
exit(1); exit(1);
} }
@@ -252,7 +259,7 @@ void Action::Seek()
time_t t = time(0); time_t t = time(0);
int old_timeout = wFooter->GetTimeout(); int old_timeout = wFooter->GetTimeout();
wFooter->SetTimeout(ncmpcpp_window_timeout); wFooter->SetTimeout(500);
SeekingInProgress = true; SeekingInProgress = true;
while (true) while (true)
@@ -289,7 +296,7 @@ void Action::Seek()
else else
break; break;
*wFooter << fmtBold; *wFooter << NC::fmtBold;
std::string tracklength; std::string tracklength;
if (Config.new_design) if (Config.new_design)
{ {
@@ -302,7 +309,7 @@ void Action::Seek()
tracklength = MPD::Song::ShowTime(songpos); tracklength = MPD::Song::ShowTime(songpos);
tracklength += "/"; tracklength += "/";
tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
*wHeader << XY(0, 0) << tracklength << " "; *wHeader << NC::XY(0, 0) << tracklength << " ";
wHeader->Refresh(); wHeader->Refresh();
} }
else else
@@ -318,9 +325,9 @@ void Action::Seek()
tracklength += "/"; tracklength += "/";
tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime()); tracklength += MPD::Song::ShowTime(Mpd.GetTotalTime());
tracklength += "]"; 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()); DrawProgressbar(songpos, Mpd.GetTotalTime());
wFooter->Refresh(); wFooter->Refresh();
} }
@@ -415,7 +422,7 @@ bool Action::AskYesNoQuestion(const std::string &question, void (*callback)())
using Global::wFooter; using Global::wFooter;
LockStatusbar(); LockStatusbar();
Statusbar() << question << " [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "]"; Statusbar() << question << " [" << NC::fmtBold << 'y' << NC::fmtBoldEnd << '/' << NC::fmtBold << 'n' << NC::fmtBoldEnd << "]";
wFooter->Refresh(); wFooter->Refresh();
int answer = 0; int answer = 0;
do do
@@ -491,13 +498,13 @@ void MouseEvent::Run()
void ScrollUp::Run() void ScrollUp::Run()
{ {
myScreen->Scroll(wUp); myScreen->Scroll(NC::wUp);
ListsChangeFinisher(); ListsChangeFinisher();
} }
void ScrollDown::Run() void ScrollDown::Run()
{ {
myScreen->Scroll(wDown); myScreen->Scroll(NC::wDown);
ListsChangeFinisher(); ListsChangeFinisher();
} }
@@ -583,25 +590,25 @@ void ScrollDownAlbum::Run()
void PageUp::Run() void PageUp::Run()
{ {
myScreen->Scroll(wPageUp); myScreen->Scroll(NC::wPageUp);
ListsChangeFinisher(); ListsChangeFinisher();
} }
void PageDown::Run() void PageDown::Run()
{ {
myScreen->Scroll(wPageDown); myScreen->Scroll(NC::wPageDown);
ListsChangeFinisher(); ListsChangeFinisher();
} }
void MoveHome::Run() void MoveHome::Run()
{ {
myScreen->Scroll(wHome); myScreen->Scroll(NC::wHome);
ListsChangeFinisher(); ListsChangeFinisher();
} }
void MoveEnd::Run() void MoveEnd::Run()
{ {
myScreen->Scroll(wEnd); myScreen->Scroll(NC::wEnd);
ListsChangeFinisher(); ListsChangeFinisher();
} }
@@ -1416,7 +1423,7 @@ void EditLibraryTag::Run()
if (!isMPDMusicDirSet()) if (!isMPDMusicDirSet())
return; return;
LockStatusbar(); 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()); std::string new_tag = wFooter->GetString(myLibrary->Tags->Current().value());
UnlockStatusbar(); UnlockStatusbar();
if (!new_tag.empty() && new_tag != myLibrary->Tags->Current().value()) if (!new_tag.empty() && new_tag != myLibrary->Tags->Current().value())
@@ -1469,7 +1476,7 @@ void EditLibraryAlbum::Run()
if (!isMPDMusicDirSet()) if (!isMPDMusicDirSet())
return; return;
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Album: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "Album: " << NC::fmtBoldEnd;
std::string new_album = wFooter->GetString(myLibrary->Albums->Current().value().Album); std::string new_album = wFooter->GetString(myLibrary->Albums->Current().value().Album);
UnlockStatusbar(); UnlockStatusbar();
if (!new_album.empty() && new_album != myLibrary->Albums->Current().value().Album) 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; std::string old_dir = myBrowser->Main()->Current().value().name;
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd;
std::string new_dir = wFooter->GetString(old_dir); std::string new_dir = wFooter->GetString(old_dir);
UnlockStatusbar(); UnlockStatusbar();
if (!new_dir.empty() && new_dir != old_dir) if (!new_dir.empty() && new_dir != old_dir)
@@ -1563,7 +1570,7 @@ void EditDirectoryName::Run()
{ {
std::string old_dir = myTagEditor->Dirs->Current().value().first; std::string old_dir = myTagEditor->Dirs->Current().value().first;
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "Directory: " << NC::fmtBoldEnd;
std::string new_dir = wFooter->GetString(old_dir); std::string new_dir = wFooter->GetString(old_dir);
UnlockStatusbar(); UnlockStatusbar();
if (!new_dir.empty() && new_dir != old_dir) if (!new_dir.empty() && new_dir != old_dir)
@@ -1605,7 +1612,7 @@ void EditPlaylistName::Run()
else else
old_name = myBrowser->Main()->Current().value().name; old_name = myBrowser->Main()->Current().value().name;
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "Playlist: " << NC::fmtBoldEnd;
std::string new_name = wFooter->GetString(old_name); std::string new_name = wFooter->GetString(old_name);
UnlockStatusbar(); UnlockStatusbar();
if (!new_name.empty() && new_name != old_name) if (!new_name.empty() && new_name != old_name)
@@ -2005,7 +2012,7 @@ void ApplyFilter::Run()
assert(f); assert(f);
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Apply filter: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "Apply filter: " << NC::fmtBoldEnd;
wFooter->SetGetStringHelper(std::bind(StatusbarApplyFilterImmediately, f, _1)); wFooter->SetGetStringHelper(std::bind(StatusbarApplyFilterImmediately, f, _1));
wFooter->GetString(f->currentFilter()); wFooter->GetString(f->currentFilter());
wFooter->SetGetStringHelper(StatusbarGetStringHelper); wFooter->SetGetStringHelper(StatusbarGetStringHelper);
@@ -2060,9 +2067,9 @@ void Find::Run()
UnlockStatusbar(); UnlockStatusbar();
ShowMessage("Searching..."); ShowMessage("Searching...");
Screen<Scrollpad> *s = static_cast<Screen<Scrollpad> *>(myScreen); Screen<NC::Scrollpad> *s = static_cast<Screen<NC::Scrollpad> *>(myScreen);
s->Main()->RemoveFormatting(); 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(); s->Main()->Flush();
} }
@@ -2131,7 +2138,7 @@ void ToggleReplayGainMode::Run()
} }
LockStatusbar(); 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(); wFooter->Refresh();
int answer = 0; int answer = 0;
do do
@@ -2175,7 +2182,7 @@ void AddRandomItems::Run()
using Global::wFooter; using Global::wFooter;
LockStatusbar(); 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(); wFooter->Refresh();
int answer = 0; int answer = 0;
do do
@@ -2238,7 +2245,7 @@ void ToggleLibraryTagType::Run()
using Global::wFooter; using Global::wFooter;
LockStatusbar(); 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(); wFooter->Refresh();
int answer = 0; int answer = 0;
do do

View File

@@ -23,7 +23,7 @@
#include <map> #include <map>
#include <string> #include <string>
#include "ncmpcpp.h" #include "window.h"
enum ActionType enum ActionType
{ {
@@ -102,7 +102,7 @@ struct Action
return false; return false;
} }
static Key ReadKey(Window &w); static Key ReadKey(NC::Window &w);
static void ValidateScreenSize(); static void ValidateScreenSize();
static void SetResizeFlags(); static void SetResizeFlags();

View File

@@ -35,6 +35,8 @@
#include "tag_editor.h" #include "tag_editor.h"
#include "utility/comparators.h" #include "utility/comparators.h"
using namespace std::placeholders;
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
using Global::myScreen; using Global::myScreen;
@@ -58,7 +60,7 @@ bool BrowserEntryMatcher(const Regex &rx, const MPD::Item &item, bool filter);
void Browser::Init() void Browser::Init()
{ {
w = new Menu<MPD::Item>(0, MainStartY, COLS, MainHeight, Config.columns_in_browser && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, brNone); w = new NC::Menu<MPD::Item>(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->HighlightColor(Config.main_highlight_color);
w->CyclicScrolling(Config.use_cyclic_scrolling); w->CyclicScrolling(Config.use_cyclic_scrolling);
w->CenteredCursor(Config.centered_cursor); w->CenteredCursor(Config.centered_cursor);
@@ -172,7 +174,7 @@ void Browser::SpacePressed()
{ {
i = w->Choice(); i = w->Choice();
w->at(i).setSelected(!w->at(i).isSelected()); w->at(i).setSelected(!w->at(i).isSelected());
w->Scroll(wDown); w->Scroll(NC::wDown);
return; return;
} }
@@ -219,7 +221,7 @@ void Browser::SpacePressed()
break; break;
} }
} }
w->Scroll(wDown); w->Scroll(NC::wDown);
} }
void Browser::MouseButtonPressed(MEVENT me) void Browser::MouseButtonPressed(MEVENT me)
@@ -242,7 +244,7 @@ void Browser::MouseButtonPressed(MEVENT me)
size_t pos = w->Choice(); size_t pos = w->Choice();
SpacePressed(); SpacePressed();
if (pos < w->Size()-1) if (pos < w->Size()-1)
w->Scroll(wUp); w->Scroll(NC::wUp);
} }
break; break;
case itPlaylist: case itPlaylist:
@@ -252,7 +254,7 @@ void Browser::MouseButtonPressed(MEVENT me)
size_t pos = w->Choice(); size_t pos = w->Choice();
SpacePressed(); SpacePressed();
if (pos < w->Size()-1) if (pos < w->Size()-1)
w->Scroll(wUp); w->Scroll(NC::wUp);
} }
else else
EnterPressed(); EnterPressed();
@@ -260,7 +262,7 @@ void Browser::MouseButtonPressed(MEVENT me)
} }
} }
else else
Screen< Menu<MPD::Item> >::MouseButtonPressed(me); Screen< NC::Menu<MPD::Item> >::MouseButtonPressed(me);
} }
/***********************************************************************/ /***********************************************************************/

View File

@@ -22,11 +22,9 @@
#define _BROWSER_H #define _BROWSER_H
#include "interfaces.h" #include "interfaces.h"
#include "ncmpcpp.h"
#include "regex_filter.h"
#include "screen.h" #include "screen.h"
class Browser : public Screen< Menu<MPD::Item> >, public Filterable, public HasSongs, public Searchable class Browser : public Screen< NC::Menu<MPD::Item> >, public Filterable, public HasSongs, public Searchable
{ {
public: public:
Browser() : itsBrowseLocally(0), itsScrollBeginning(0), itsBrowsedDir("/") { } Browser() : itsBrowseLocally(0), itsScrollBeginning(0), itsBrowsedDir("/") { }
@@ -59,7 +57,7 @@ class Browser : public Screen< Menu<MPD::Item> >, public Filterable, public HasS
virtual void removeSelection(); virtual void removeSelection();
virtual MPD::SongList getSelectedSongs(); virtual MPD::SongList getSelectedSongs();
virtual List *GetList() { return w; } virtual NC::List *GetList() { return w; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -54,8 +54,8 @@ void Clock::Init()
{ {
Width = Config.clock_display_seconds ? 60 : 40; Width = Config.clock_display_seconds ? 60 : 40;
itsPane = new Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); itsPane = new NC::Window(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
w = new Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, Border(Config.main_color)); w = new NC::Window((COLS-Width)/2, (MainHeight-Height)/2+MainStartY, Width, Height-1, "", Config.main_color, NC::Border(Config.main_color));
isInitialized = 1; isInitialized = 1;
} }
@@ -160,7 +160,7 @@ void Clock::Update()
next[k] = 0; next[k] = 0;
for (int s = 1; s >= 0; --s) for (int s = 1; s >= 0; --s)
{ {
*w << (s ? fmtReverse : fmtReverseEnd); *w << (s ? NC::fmtReverse : NC::fmtReverseEnd);
for (int i = 0; i < 6; ++i) for (int i = 0; i < 6; ++i)
{ {
long a = (newer[i] ^ older[i]) & (s ? newer : older)[i]; long a = (newer[i] ^ older[i]) & (s ? newer : older)[i];

View File

@@ -30,7 +30,7 @@
#include "window.h" #include "window.h"
#include "screen.h" #include "screen.h"
class Clock : public Screen<Window> class Clock : public Screen<NC::Window>
{ {
public: public:
virtual void Resize(); virtual void Resize();
@@ -39,7 +39,7 @@ class Clock : public Screen<Window>
virtual std::basic_string<my_char_t> Title(); virtual std::basic_string<my_char_t> Title();
virtual void Update(); virtual void Update();
virtual void Scroll(Where) { } virtual void Scroll(NC::Where) { }
virtual void EnterPressed() { } virtual void EnterPressed() { }
virtual void SpacePressed() { } virtual void SpacePressed() { }
@@ -48,7 +48,7 @@ class Clock : public Screen<Window>
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }
@@ -57,7 +57,7 @@ class Clock : public Screen<Window>
virtual bool isLockable() { return false; } virtual bool isLockable() { return false; }
private: private:
Window *itsPane; NC::Window *itsPane;
static void Prepare(); static void Prepare();
static void Set(int, int); static void Set(int, int);

View File

@@ -73,7 +73,7 @@ const my_char_t *toColumnName(char c)
} }
template <typename T> template <typename T>
void setProperties(Menu<T> &menu, const MPD::Song &s, HasSongs &screen, bool &separate_albums, void setProperties(NC::Menu<T> &menu, const MPD::Song &s, HasSongs &screen, bool &separate_albums,
bool &is_now_playing, bool &is_selected, bool &discard_colors) bool &is_now_playing, bool &is_selected, bool &discard_colors)
{ {
separate_albums = false; separate_albums = false;
@@ -84,7 +84,7 @@ void setProperties(Menu<T> &menu, const MPD::Song &s, HasSongs &screen, bool &se
separate_albums = true; separate_albums = true;
} }
if (separate_albums) if (separate_albums)
menu << fmtUnderline; menu << NC::fmtUnderline;
int song_pos = menu.isFiltered() ? s.getPosition() : menu.DrawnPosition(); int song_pos = menu.isFiltered() ? s.getPosition() : menu.DrawnPosition();
is_now_playing = static_cast<void *>(&menu) == myPlaylist->Items is_now_playing = static_cast<void *>(&menu) == myPlaylist->Items
@@ -94,7 +94,7 @@ void setProperties(Menu<T> &menu, const MPD::Song &s, HasSongs &screen, bool &se
} }
template <typename T> template <typename T>
void showSongs(Menu<T> &menu, const MPD::Song &s, HasSongs &screen, const std::string &format) void showSongs(NC::Menu<T> &menu, const MPD::Song &s, HasSongs &screen, const std::string &format)
{ {
bool separate_albums, is_now_playing, is_selected, discard_colors; bool separate_albums, is_now_playing, is_selected, discard_colors;
setProperties(menu, s, screen, 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<T> &menu, const MPD::Song &s, HasSongs &screen, const std::s
else if (isdigit(*it)) // color else if (isdigit(*it)) // color
{ {
if (!discard_colors) if (!discard_colors)
menu << Color(*it-'0'); menu << NC::Color(*it-'0');
} }
else if (*it == 'R') // right align else if (*it == 'R') // right align
{ {
basic_buffer<my_char_t> buf; NC::basic_buffer<my_char_t> buf;
buf << U(" "); buf << U(" ");
String2Buffer(TO_WSTRING(line.substr(it-line.begin()+1)), buf); String2Buffer(TO_WSTRING(line.substr(it-line.begin()+1)), buf);
if (discard_colors) if (discard_colors)
buf.RemoveFormatting(); buf.RemoveFormatting();
if (is_now_playing) if (is_now_playing)
buf << Config.now_playing_suffix; 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) if (separate_albums)
menu << fmtUnderlineEnd; menu << NC::fmtUnderlineEnd;
return; return;
} }
else // not a color nor right align, just a random character else // not a color nor right align, just a random character
@@ -144,11 +144,11 @@ void showSongs(Menu<T> &menu, const MPD::Song &s, HasSongs &screen, const std::s
if (is_now_playing) if (is_now_playing)
menu << Config.now_playing_suffix; menu << Config.now_playing_suffix;
if (separate_albums) if (separate_albums)
menu << fmtUnderlineEnd; menu << NC::fmtUnderlineEnd;
} }
template <typename T> template <typename T>
void showSongsInColumns(Menu<T> &menu, const MPD::Song &s, HasSongs &screen) void showSongsInColumns(NC::Menu<T> &menu, const MPD::Song &s, HasSongs &screen)
{ {
if (Config.columns.empty()) if (Config.columns.empty())
return; return;
@@ -219,16 +219,16 @@ void showSongsInColumns(Menu<T> &menu, const MPD::Song &s, HasSongs &screen)
} }
if (tag.empty() && it->display_empty_tag) if (tag.empty() && it->display_empty_tag)
tag = TO_WSTRING(Config.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; menu << it->color;
int x_off = 0; int x_off = 0;
// if column uses right alignment, calculate proper offset. // if column uses right alignment, calculate proper offset.
// otherwise just assume offset is 0, ie. we start from the left. // otherwise just assume offset is 0, ie. we start from the left.
if (it->right_alignment) 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); whline(menu.Raw(), KEY_SPACE, width);
menu.GotoXY(x + x_off, y); menu.GotoXY(x + x_off, y);
@@ -241,8 +241,8 @@ void showSongsInColumns(Menu<T> &menu, const MPD::Song &s, HasSongs &screen)
remained_width -= width+1; remained_width -= width+1;
} }
if (!discard_colors && it->color != clDefault) if (!discard_colors && it->color != NC::clDefault)
menu << clEnd; menu << NC::clEnd;
} }
// here comes the shitty part, second chapter. here we apply // here comes the shitty part, second chapter. here we apply
@@ -261,7 +261,7 @@ void showSongsInColumns(Menu<T> &menu, const MPD::Song &s, HasSongs &screen)
menu.GotoXY(menu.GetWidth() - Config.selected_item_suffix_length, y); menu.GotoXY(menu.GetWidth() - Config.selected_item_suffix_length, y);
if (separate_albums) if (separate_albums)
menu << fmtUnderlineEnd; menu << NC::fmtUnderlineEnd;
} }
} }
@@ -308,9 +308,9 @@ std::string Display::Columns(size_t list_width)
} }
else else
name = it->name; 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) if (it->right_alignment)
{ {
result += std::string(x_off, KEY_SPACE); result += std::string(x_off, KEY_SPACE);
@@ -333,17 +333,17 @@ std::string Display::Columns(size_t list_width)
return result; return result;
} }
void Display::SongsInColumns(Menu<MPD::Song> &menu, HasSongs &screen) void Display::SongsInColumns(NC::Menu<MPD::Song> &menu, HasSongs &screen)
{ {
showSongsInColumns(menu, menu.Drawn().value(), screen); showSongsInColumns(menu, menu.Drawn().value(), screen);
} }
void Display::Songs(Menu<MPD::Song> &menu, HasSongs &screen, const std::string &format) void Display::Songs(NC::Menu<MPD::Song> &menu, HasSongs &screen, const std::string &format)
{ {
showSongs(menu, menu.Drawn().value(), screen, format); showSongs(menu, menu.Drawn().value(), screen, format);
} }
void Display::Tags(Menu<MPD::MutableSong> &menu) void Display::Tags(NC::Menu<MPD::MutableSong> &menu)
{ {
const MPD::MutableSong &s = menu.Drawn().value(); const MPD::MutableSong &s = menu.Drawn().value();
size_t i = myTagEditor->TagTypes->Choice(); size_t i = myTagEditor->TagTypes->Choice();
@@ -356,16 +356,16 @@ void Display::Tags(Menu<MPD::MutableSong> &menu)
if (s.getNewURI().empty()) if (s.getNewURI().empty())
menu << s.getName(); menu << s.getName();
else 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<MPD::Output> &menu)
{ {
menu << menu.Drawn().value().name(); menu << menu.Drawn().value().name();
} }
void Display::Items(Menu<MPD::Item> &menu) void Display::Items(NC::Menu<MPD::Item> &menu)
{ {
const MPD::Item &item = menu.Drawn().value(); const MPD::Item &item = menu.Drawn().value();
switch (item.type) switch (item.type)
@@ -385,7 +385,7 @@ void Display::Items(Menu<MPD::Item> &menu)
} }
} }
void Display::SearchEngine(Menu<SEItem> &menu) void Display::SearchEngine(NC::Menu<SEItem> &menu)
{ {
const SEItem &si = menu.Drawn().value(); const SEItem &si = menu.Drawn().value();
if (si.isSong()) if (si.isSong())

View File

@@ -22,9 +22,7 @@
#define _DISPLAY_H #define _DISPLAY_H
#include "interfaces.h" #include "interfaces.h"
#include "ncmpcpp.h"
#include "menu.h" #include "menu.h"
#include "mpdpp.h"
#include "mutable_song.h" #include "mutable_song.h"
#include "search_engine.h" #include "search_engine.h"
@@ -32,27 +30,27 @@ namespace Display
{ {
std::string Columns(size_t); std::string Columns(size_t);
template <typename T> void Default(Menu<T> &menu) template <typename T> void Default(NC::Menu<T> &menu)
{ {
menu << menu.Drawn().value(); menu << menu.Drawn().value();
} }
template <typename A, typename B> void Pair(Menu< std::pair<A, B> > &menu) template <typename A, typename B> void Pair(NC::Menu< std::pair<A, B> > &menu)
{ {
menu << menu.Drawn().value().first; menu << menu.Drawn().value().first;
} }
void SongsInColumns(Menu<MPD::Song> &menu, HasSongs &screen); void SongsInColumns(NC::Menu<MPD::Song> &menu, HasSongs &screen);
void Songs(Menu<MPD::Song> &menu, HasSongs &screen, const std::string &format); void Songs(NC::Menu<MPD::Song> &menu, HasSongs &screen, const std::string &format);
void Tags(Menu<MPD::MutableSong> &menu); void Tags(NC::Menu<MPD::MutableSong> &menu);
void Outputs(Menu<MPD::Output> &menu); void Outputs(NC::Menu<MPD::Output> &menu);
void SearchEngine(Menu<SEItem> &menu); void SearchEngine(NC::Menu<SEItem> &menu);
void Items(Menu<MPD::Item> &menu); void Items(NC::Menu<MPD::Item> &menu);
} }
#endif #endif

View File

@@ -23,7 +23,6 @@
#include <sys/time.h> #include <sys/time.h>
#include "ncmpcpp.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "screen.h" #include "screen.h"
@@ -45,10 +44,10 @@ namespace Global
extern BasicScreen *myInactiveScreen; extern BasicScreen *myInactiveScreen;
// header window (above main window) // header window (above main window)
extern Window *wHeader; extern NC::Window *wHeader;
// footer window (below main window) // footer window (below main window)
extern Window *wFooter; extern NC::Window *wFooter;
// Y coordinate of top of main window // Y coordinate of top of main window
extern size_t MainStartY; extern size_t MainStartY;

View File

@@ -22,8 +22,8 @@
#include "global.h" #include "global.h"
#include "help.h" #include "help.h"
#include "scrollpad.h"
#include "settings.h" #include "settings.h"
#include "tag_editor.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -88,11 +88,13 @@ std::string keyToString(const Action::Key &key, bool *print_backspace)
return result; return result;
} }
} }
void Help::Init() 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(); GetKeybindings();
w->Flush(); w->Flush();
isInitialized = 1; isInitialized = 1;
@@ -154,8 +156,8 @@ std::string Help::DisplayKeys(const ActionType at)
void Help::Section(const char *type, const char *title) void Help::Section(const char *type, const char *title)
{ {
*w << U("\n ") << fmtBold << TO_WSTRING(type) << U(" - "); *w << U("\n ") << NC::fmtBold << TO_WSTRING(type) << U(" - ");
*w << TO_WSTRING(title) << fmtBoldEnd << '\n' << '\n'; *w << TO_WSTRING(title) << NC::fmtBoldEnd << '\n' << '\n';
} }
void Help::KeyDesc(const ActionType at, const char *desc) 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) 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() void Help::GetKeybindings()

View File

@@ -21,10 +21,10 @@
#ifndef _HELP_H #ifndef _HELP_H
#define _HELP_H #define _HELP_H
#include "ncmpcpp.h" #include "actions.h"
#include "screen.h" #include "screen.h"
class Help : public Screen<Scrollpad> class Help : public Screen<NC::Scrollpad>
{ {
public: public:
virtual void Resize(); virtual void Resize();
@@ -38,7 +38,7 @@ class Help : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -282,22 +282,10 @@ std::string Timestamp(time_t t)
return result; return result;
} }
void UpdateSongList(Menu<MPD::Song> *menu) void UpdateSongList(NC::Menu<MPD::Song> *menu)
{ {
bool bold = 0; for (auto it = menu->Begin(); it != menu->End(); ++it)
for (size_t i = 0; i < menu->Size(); ++i) it->setSelected(myPlaylist->checkForSong(it->value()));
{
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;
}
menu->Refresh(); menu->Refresh();
} }
@@ -307,14 +295,14 @@ std::basic_string<my_char_t> Scroller(const std::basic_string<my_char_t> &str, s
if (!Config.header_text_scrolling) if (!Config.header_text_scrolling)
return s; return s;
std::basic_string<my_char_t> result; std::basic_string<my_char_t> result;
size_t len = Window::Length(s); size_t len = NC::Window::Length(s);
if (len > width) if (len > width)
{ {
s += U(" ** "); s += U(" ** ");
len = 0; len = 0;
std::basic_string<my_char_t>::const_iterator b = s.begin(), e = s.end(); auto b = s.begin(), e = s.end();
for (std::basic_string<my_char_t>::const_iterator it = b+pos; it < e && len < width; ++it) for (auto it = b+pos; it < e && len < width; ++it)
{ {
if ((len += wcwidth(*it)) > width) if ((len += wcwidth(*it)) > width)
break; break;

View File

@@ -21,11 +21,17 @@
#ifndef _HELPERS_H #ifndef _HELPERS_H
#define _HELPERS_H #define _HELPERS_H
#include "interfaces.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "ncmpcpp.h" #include "screen.h"
#include "settings.h" #include "settings.h"
#include "status.h" #include "status.h"
inline HasSongs *hasSongs(BasicScreen *screen)
{
return dynamic_cast<HasSongs *>(screen);
}
template <typename Iterator> void removeSelectionHelper(Iterator first, Iterator last) template <typename Iterator> void removeSelectionHelper(Iterator first, Iterator last)
{ {
for (; first != last; ++first) for (; first != last; ++first)
@@ -51,7 +57,7 @@ template <typename Iterator> std::string getSharedDirectory(Iterator first, Iter
return result; return result;
} }
template <typename T> void withUnfilteredMenu(Menu<T> &menu, std::function<void()> action) template <typename T> void withUnfilteredMenu(NC::Menu<T> &menu, std::function<void()> action)
{ {
bool is_filtered = menu.isFiltered(); bool is_filtered = menu.isFiltered();
menu.ShowAll(); menu.ShowAll();
@@ -65,17 +71,17 @@ void ParseArgv(int, char **);
template <typename T> struct StringConverter { template <typename T> struct StringConverter {
const char *operator()(const char *s) { return s; } const char *operator()(const char *s) { return s; }
}; };
template <> struct StringConverter< basic_buffer<wchar_t> > { template <> struct StringConverter< NC::basic_buffer<wchar_t> > {
std::wstring operator()(const char *s) { return ToWString(s); } std::wstring operator()(const char *s) { return ToWString(s); }
}; };
template <> struct StringConverter<Scrollpad> { template <> struct StringConverter<NC::Scrollpad> {
std::basic_string<my_char_t> operator()(const char *s) { return TO_WSTRING(s); } std::basic_string<my_char_t> operator()(const char *s) { return TO_WSTRING(s); }
}; };
template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_buffer<C> &buf) template <typename C> void String2Buffer(const std::basic_string<C> &s, NC::basic_buffer<C> &buf)
{ {
StringConverter< basic_buffer<C> > cnv; StringConverter< NC::basic_buffer<C> > cnv;
for (typename std::basic_string<C>::const_iterator it = s.begin(); it != s.end(); ++it) for (auto it = s.begin(); it != s.end(); ++it)
{ {
if (*it == '$') if (*it == '$')
{ {
@@ -86,23 +92,23 @@ template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_bu
} }
else if (isdigit(*it)) else if (isdigit(*it))
{ {
buf << Color(*it-'0'); buf << NC::Color(*it-'0');
} }
else else
{ {
switch (*it) switch (*it)
{ {
case 'b': case 'b':
buf << fmtBold; buf << NC::fmtBold;
break; break;
case 'u': case 'u':
buf << fmtUnderline; buf << NC::fmtUnderline;
break; break;
case 'a': case 'a':
buf << fmtAltCharset; buf << NC::fmtAltCharset;
break; break;
case 'r': case 'r':
buf << fmtReverse; buf << NC::fmtReverse;
break; break;
case '/': case '/':
if (++it == s.end()) if (++it == s.end())
@@ -113,16 +119,16 @@ template <typename C> void String2Buffer(const std::basic_string<C> &s, basic_bu
switch (*it) switch (*it)
{ {
case 'b': case 'b':
buf << fmtBoldEnd; buf << NC::fmtBoldEnd;
break; break;
case 'u': case 'u':
buf << fmtUnderlineEnd; buf << NC::fmtUnderlineEnd;
break; break;
case 'a': case 'a':
buf << fmtAltCharsetEnd; buf << NC::fmtAltCharsetEnd;
break; break;
case 'r': case 'r':
buf << fmtReverseEnd; buf << NC::fmtReverseEnd;
break; break;
default: default:
buf << '$' << *--it; buf << '$' << *--it;
@@ -195,14 +201,14 @@ template <typename T> void ShowTime(T &buf, size_t length, bool short_names)
template <typename T> void ShowTag(T &buf, const std::string &tag) template <typename T> void ShowTag(T &buf, const std::string &tag)
{ {
if (tag.empty()) if (tag.empty())
buf << Config.empty_tags_color << Config.empty_tag << clEnd; buf << Config.empty_tags_color << Config.empty_tag << NC::clEnd;
else else
buf << tag; buf << tag;
} }
std::string Timestamp(time_t t); std::string Timestamp(time_t t);
void UpdateSongList(Menu<MPD::Song> *); void UpdateSongList(NC::Menu<MPD::Song> *);
std::basic_string<my_char_t> Scroller(const std::basic_string<my_char_t> &str, size_t &pos, size_t width); std::basic_string<my_char_t> Scroller(const std::basic_string<my_char_t> &str, size_t &pos, size_t width);

View File

@@ -34,6 +34,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include "helpers.h"
#include "charset.h" #include "charset.h"
#include "global.h" #include "global.h"
@@ -44,7 +45,7 @@ Lastfm *myLastfm = new Lastfm;
void Lastfm::Init() 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; isInitialized = 1;
} }
@@ -190,7 +191,7 @@ void Lastfm::Download()
itsService->colorizeOutput(*w); itsService->colorizeOutput(*w);
} }
else else
*w << clRed << result.second << clEnd; *w << NC::clRed << result.second << NC::clEnd;
isReadyToTake = 1; isReadyToTake = 1;
} }

View File

@@ -33,7 +33,7 @@
#include "lastfm_service.h" #include "lastfm_service.h"
#include "screen.h" #include "screen.h"
class Lastfm : public Screen<Scrollpad> class Lastfm : public Screen<NC::Scrollpad>
{ {
public: public:
Lastfm() : isReadyToTake(0), isDownloadInProgress(0) { } Lastfm() : isReadyToTake(0), isDownloadInProgress(0) { }
@@ -50,7 +50,7 @@ class Lastfm : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -102,10 +102,10 @@ bool ArtistInfo::checkArgs(const Args &args)
return args.find("artist") != args.end(); 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(NC::fmtBold, U("\n\nSimilar artists:\n"), NC::fmtBoldEnd, false);
w.SetFormatting(Config.color2, U("\n * "), clEnd, true); w.SetFormatting(Config.color2, U("\n * "), NC::clEnd, true);
// below is used so format won't be removed using RemoveFormatting() by accident. // below is used so format won't be removed using RemoveFormatting() by accident.
w.ForgetFormatting(); w.ForgetFormatting();
} }

View File

@@ -41,7 +41,7 @@ struct LastfmService
virtual Result fetch(Args &args); virtual Result fetch(Args &args);
virtual bool checkArgs(const Args &args) = 0; virtual bool checkArgs(const Args &args) = 0;
virtual void colorizeOutput(NCurses::Scrollpad &w) = 0; virtual void colorizeOutput(NC::Scrollpad &w) = 0;
protected: protected:
virtual bool actionFailed(const std::string &data); virtual bool actionFailed(const std::string &data);
@@ -60,7 +60,7 @@ struct ArtistInfo : public LastfmService
virtual const char *name() { return "Artist info"; } virtual const char *name() { return "Artist info"; }
virtual bool checkArgs(const Args &args); virtual bool checkArgs(const Args &args);
virtual void colorizeOutput(NCurses::Scrollpad &w); virtual void colorizeOutput(NC::Scrollpad &w);
protected: protected:
virtual bool parse(std::string &data); virtual bool parse(std::string &data);

View File

@@ -30,6 +30,7 @@
#include "helpers.h" #include "helpers.h"
#include "lyrics.h" #include "lyrics.h"
#include "playlist.h" #include "playlist.h"
#include "scrollpad.h"
#include "settings.h" #include "settings.h"
#include "song.h" #include "song.h"
@@ -49,7 +50,7 @@ Lyrics *myLyrics = new Lyrics;
void Lyrics::Init() 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; isInitialized = 1;
} }
@@ -254,10 +255,10 @@ void *Lyrics::Download()
bool fetcher_defined = itsFetcher && *itsFetcher; bool fetcher_defined = itsFetcher && *itsFetcher;
for (LyricsFetcher **plugin = fetcher_defined ? itsFetcher : lyricsPlugins; *plugin != 0; ++plugin) 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); result = (*plugin)->fetch(artist, title);
if (result.first == false) if (result.first == false)
*w << clRed << TO_WSTRING(result.second) << clEnd << '\n'; *w << NC::clRed << TO_WSTRING(result.second) << NC::clEnd << '\n';
else else
break; break;
if (fetcher_defined) if (fetcher_defined)

View File

@@ -24,12 +24,11 @@
#include <pthread.h> #include <pthread.h>
#include <queue> #include <queue>
#include "ncmpcpp.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "screen.h" #include "screen.h"
#include "lyrics_fetcher.h" #include "lyrics_fetcher.h"
class Lyrics : public Screen<Scrollpad> class Lyrics : public Screen<NC::Scrollpad>
{ {
public: public:
Lyrics() : ReloadNP(0), Lyrics() : ReloadNP(0),
@@ -50,7 +49,7 @@ class Lyrics : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -34,6 +34,8 @@
#include "utility/comparators.h" #include "utility/comparators.h"
#include "utility/type_conversions.h" #include "utility/type_conversions.h"
using namespace std::placeholders;
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
using Global::myScreen; using Global::myScreen;
@@ -62,11 +64,11 @@ std::string AlbumToString(const SearchConstraints &sc);
std::string SongToString(const MPD::Song &s); std::string SongToString(const MPD::Song &s);
bool TagEntryMatcher(const Regex &rx, const std::string &tag); bool TagEntryMatcher(const Regex &rx, const std::string &tag);
bool AlbumEntryMatcher(const Regex &rx, const Menu<SearchConstraints>::Item &item, bool filter); bool AlbumEntryMatcher(const Regex &rx, const NC::Menu<SearchConstraints>::Item &item, bool filter);
bool SongEntryMatcher(const Regex &rx, const MPD::Song &s); bool SongEntryMatcher(const Regex &rx, const MPD::Song &s);
void DisplayAlbums(Menu<SearchConstraints> &menu); void DisplayAlbums(NC::Menu<SearchConstraints> &menu);
void DisplayPrimaryTags(Menu<std::string> &menu); void DisplayPrimaryTags(NC::Menu<std::string> &menu);
bool SortSongsByTrack(const MPD::Song &a, const MPD::Song &b); bool SortSongsByTrack(const MPD::Song &a, const MPD::Song &b);
bool SortAllTracks(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; itsRightColWidth = COLS-COLS/3*2-1;
itsRightColStartX = itsLeftColWidth+itsMiddleColWidth+2; itsRightColStartX = itsLeftColWidth+itsMiddleColWidth+2;
Tags = new Menu<std::string>(0, MainStartY, itsLeftColWidth, MainHeight, Config.titles_visibility ? tagTypeToString(Config.media_lib_primary_tag) + "s" : "", Config.main_color, brNone); Tags = new NC::Menu<std::string>(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->HighlightColor(Config.active_column_color);
Tags->CyclicScrolling(Config.use_cyclic_scrolling); Tags->CyclicScrolling(Config.use_cyclic_scrolling);
Tags->CenteredCursor(Config.centered_cursor); Tags->CenteredCursor(Config.centered_cursor);
@@ -91,7 +93,7 @@ void MediaLibrary::Init()
Tags->SetSelectSuffix(Config.selected_item_suffix); Tags->SetSelectSuffix(Config.selected_item_suffix);
Tags->setItemDisplayer(DisplayPrimaryTags); Tags->setItemDisplayer(DisplayPrimaryTags);
Albums = new Menu<SearchConstraints>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, brNone); Albums = new NC::Menu<SearchConstraints>(itsMiddleColStartX, MainStartY, itsMiddleColWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, NC::brNone);
Albums->HighlightColor(Config.main_highlight_color); Albums->HighlightColor(Config.main_highlight_color);
Albums->CyclicScrolling(Config.use_cyclic_scrolling); Albums->CyclicScrolling(Config.use_cyclic_scrolling);
Albums->CenteredCursor(Config.centered_cursor); Albums->CenteredCursor(Config.centered_cursor);
@@ -99,7 +101,7 @@ void MediaLibrary::Init()
Albums->SetSelectSuffix(Config.selected_item_suffix); Albums->SetSelectSuffix(Config.selected_item_suffix);
Albums->setItemDisplayer(DisplayAlbums); Albums->setItemDisplayer(DisplayAlbums);
Songs = new Menu<MPD::Song>(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, Config.titles_visibility ? "Songs" : "", Config.main_color, brNone); Songs = new NC::Menu<MPD::Song>(itsRightColStartX, MainStartY, itsRightColWidth, MainHeight, Config.titles_visibility ? "Songs" : "", Config.main_color, NC::brNone);
Songs->HighlightColor(Config.main_highlight_color); Songs->HighlightColor(Config.main_highlight_color);
Songs->CyclicScrolling(Config.use_cyclic_scrolling); Songs->CyclicScrolling(Config.use_cyclic_scrolling);
Songs->CenteredCursor(Config.centered_cursor); Songs->CenteredCursor(Config.centered_cursor);
@@ -152,7 +154,7 @@ void MediaLibrary::Refresh()
Songs->Display(); Songs->Display();
if (Albums->Empty()) if (Albums->Empty())
{ {
*Albums << XY(0, 0) << "No albums found."; *Albums << NC::XY(0, 0) << "No albums found.";
Albums->Window::Refresh(); Albums->Window::Refresh();
} }
} }
@@ -267,7 +269,7 @@ void MediaLibrary::Update()
else if (hasTwoColumns && Albums->ReallyEmpty()) else if (hasTwoColumns && Albums->ReallyEmpty())
{ {
Songs->Clear(); Songs->Clear();
*Albums << XY(0, 0) << "Fetching albums..."; *Albums << NC::XY(0, 0) << "Fetching albums...";
Albums->Window::Refresh(); Albums->Window::Refresh();
Mpd.BlockIdle(true); Mpd.BlockIdle(true);
auto artists = Mpd.GetList(Config.media_lib_primary_tag); auto artists = Mpd.GetList(Config.media_lib_primary_tag);
@@ -359,7 +361,7 @@ void MediaLibrary::SpacePressed()
size_t i = Songs->Choice(); size_t i = Songs->Choice();
Songs->at(i).setSelected(!Songs->at(i).isSelected()); Songs->at(i).setSelected(!Songs->at(i).isSelected());
} }
w->Scroll(wDown); w->Scroll(NC::wDown);
} }
else else
AddToPlaylist(0); AddToPlaylist(0);
@@ -382,11 +384,11 @@ void MediaLibrary::MouseButtonPressed(MEVENT me)
size_t pos = Tags->Choice(); size_t pos = Tags->Choice();
SpacePressed(); SpacePressed();
if (pos < Tags->Size()-1) if (pos < Tags->Size()-1)
Tags->Scroll(wUp); Tags->Scroll(NC::wUp);
} }
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
Albums->Clear(); Albums->Clear();
Songs->Clear(); Songs->Clear();
} }
@@ -402,11 +404,11 @@ void MediaLibrary::MouseButtonPressed(MEVENT me)
size_t pos = Albums->Choice(); size_t pos = Albums->Choice();
SpacePressed(); SpacePressed();
if (pos < Albums->Size()-1) if (pos < Albums->Size()-1)
Albums->Scroll(wUp); Albums->Scroll(NC::wUp);
} }
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
Songs->Clear(); Songs->Clear();
} }
else if (!Songs->Empty() && Songs->hasCoords(me.x, me.y)) else if (!Songs->Empty() && Songs->hasCoords(me.x, me.y))
@@ -424,17 +426,17 @@ void MediaLibrary::MouseButtonPressed(MEVENT me)
size_t pos = Songs->Choice(); size_t pos = Songs->Choice();
SpacePressed(); SpacePressed();
if (pos < Songs->Size()-1) if (pos < Songs->Size()-1)
Songs->Scroll(wUp); Songs->Scroll(NC::wUp);
} }
else else
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
} }
List *MediaLibrary::GetList() NC::List *MediaLibrary::GetList()
{ {
if (w == Tags) if (w == Tags)
return Tags; return Tags;
@@ -841,7 +843,7 @@ void MediaLibrary::AddToPlaylist(bool add_n_play)
if (!add_n_play) if (!add_n_play)
{ {
w->Scroll(wDown); w->Scroll(NC::wDown);
if (w == Tags) if (w == Tags)
{ {
Albums->Clear(); Albums->Clear();
@@ -881,14 +883,12 @@ std::string SongToString(const MPD::Song &s)
return s.toString(Config.song_library_format); return s.toString(Config.song_library_format);
} }
/***********************************************************************/
bool TagEntryMatcher(const Regex &rx, const std::string &tag) bool TagEntryMatcher(const Regex &rx, const std::string &tag)
{ {
return rx.match(tag); return rx.match(tag);
} }
bool AlbumEntryMatcher(const Regex &rx, const Menu<SearchConstraints>::Item &item, bool filter) bool AlbumEntryMatcher(const Regex &rx, const NC::Menu<SearchConstraints>::Item &item, bool filter)
{ {
if (item.isSeparator() || item.value().Date == AllTracksMarker) if (item.isSeparator() || item.value().Date == AllTracksMarker)
return filter; return filter;
@@ -902,12 +902,12 @@ bool SongEntryMatcher(const Regex &rx, const MPD::Song &s)
/***********************************************************************/ /***********************************************************************/
void DisplayAlbums(Menu<SearchConstraints> &menu) void DisplayAlbums(NC::Menu<SearchConstraints> &menu)
{ {
menu << AlbumToString(menu.Drawn().value()); menu << AlbumToString(menu.Drawn().value());
} }
void DisplayPrimaryTags(Menu<std::string> &menu) void DisplayPrimaryTags(NC::Menu<std::string> &menu)
{ {
const std::string &tag = menu.Drawn().value(); const std::string &tag = menu.Drawn().value();
if (tag.empty()) if (tag.empty())

View File

@@ -22,10 +22,9 @@
#define _H_MEDIA_LIBRARY #define _H_MEDIA_LIBRARY
#include "interfaces.h" #include "interfaces.h"
#include "ncmpcpp.h"
#include "screen.h" #include "screen.h"
class MediaLibrary : public Screen<Window>, public Filterable, public HasSongs, public Searchable class MediaLibrary : public Screen<NC::Window>, public Filterable, public HasSongs, public Searchable
{ {
public: public:
virtual void SwitchTo(); virtual void SwitchTo();
@@ -59,7 +58,7 @@ class MediaLibrary : public Screen<Window>, public Filterable, public HasSongs,
virtual void removeSelection(); virtual void removeSelection();
virtual MPD::SongList getSelectedSongs(); virtual MPD::SongList getSelectedSongs();
virtual List *GetList(); virtual NC::List *GetList();
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }
@@ -84,9 +83,9 @@ class MediaLibrary : public Screen<Window>, public Filterable, public HasSongs,
std::string Date; std::string Date;
}; };
Menu<std::string> *Tags; NC::Menu<std::string> *Tags;
Menu<SearchConstraints> *Albums; NC::Menu<SearchConstraints> *Albums;
Menu<MPD::Song> *Songs; NC::Menu<MPD::Song> *Songs;
protected: protected:
virtual void Init(); virtual void Init();

View File

@@ -31,7 +31,7 @@
#include "strbuffer.h" #include "strbuffer.h"
#include "window.h" #include "window.h"
namespace NCurses { namespace NC {
/// List class is an interface for Menu class /// List class is an interface for Menu class
struct List struct List

View File

@@ -73,7 +73,6 @@ namespace MPD
}; };
typedef std::vector<Item> ItemList; typedef std::vector<Item> ItemList;
typedef std::vector<Song> SongList;
typedef std::vector<std::string> StringList; typedef std::vector<std::string> StringList;
typedef std::vector<Output> OutputList; typedef std::vector<Output> OutputList;

View File

@@ -29,7 +29,6 @@
#include <stdexcept> #include <stdexcept>
#include "mpdpp.h" #include "mpdpp.h"
#include "ncmpcpp.h"
#include "actions.h" #include "actions.h"
#include "browser.h" #include "browser.h"
@@ -67,7 +66,7 @@ namespace
errorlog.close(); errorlog.close();
Mpd.Disconnect(); Mpd.Disconnect();
# ifndef USE_PDCURSES // destroying screen somehow crashes pdcurses # ifndef USE_PDCURSES // destroying screen somehow crashes pdcurses
DestroyScreen(); NC::DestroyScreen();
# endif // USE_PDCURSES # endif // USE_PDCURSES
WindowTitle(""); WindowTitle("");
} }
@@ -135,7 +134,7 @@ int main(int argc, char **argv)
cerr_buffer = std::cerr.rdbuf(); cerr_buffer = std::cerr.rdbuf();
std::cerr.rdbuf(errorlog.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; Action::OriginalStatusbarVisibility = Config.statusbar_visibility;
@@ -148,12 +147,12 @@ int main(int argc, char **argv)
Action::SetWindowsDimensions(); Action::SetWindowsDimensions();
Action::ValidateScreenSize(); 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) if (Config.header_visibility || Config.new_design)
wHeader->Display(); wHeader->Display();
wFooter = new Window(0, Action::FooterStartY, COLS, Action::FooterHeight, "", Config.statusbar_color, brNone); wFooter = new NC::Window(0, Action::FooterStartY, COLS, Action::FooterHeight, "", Config.statusbar_color, NC::brNone);
wFooter->SetTimeout(ncmpcpp_window_timeout); wFooter->SetTimeout(500);
wFooter->SetGetStringHelper(StatusbarGetStringHelper); wFooter->SetGetStringHelper(StatusbarGetStringHelper);
if (Mpd.SupportsIdle()) if (Mpd.SupportsIdle())
wFooter->AddFDCallback(Mpd.GetFD(), StatusbarMPDCallback); wFooter->AddFDCallback(Mpd.GetFD(), StatusbarMPDCallback);
@@ -243,20 +242,20 @@ int main(int argc, char **argv)
if (Config.new_design) if (Config.new_design)
{ {
std::basic_string<my_char_t> title = myScreen->Title(); std::basic_string<my_char_t> title = myScreen->Title();
*wHeader << XY(0, 3) << wclrtoeol; *wHeader << NC::XY(0, 3) << wclrtoeol;
*wHeader << fmtBold << Config.alternative_ui_separator_color; *wHeader << NC::fmtBold << Config.alternative_ui_separator_color;
mvwhline(wHeader->Raw(), 2, 0, 0, COLS); mvwhline(wHeader->Raw(), 2, 0, 0, COLS);
mvwhline(wHeader->Raw(), 4, 0, 0, COLS); mvwhline(wHeader->Raw(), 4, 0, 0, COLS);
*wHeader << XY((COLS-Window::Length(title))/2, 3); *wHeader << NC::XY((COLS-NC::Window::Length(title))/2, 3);
*wHeader << Config.header_color << title << clEnd; *wHeader << Config.header_color << title << NC::clEnd;
*wHeader << clEnd << fmtBoldEnd; *wHeader << NC::clEnd << NC::fmtBoldEnd;
} }
else 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 << Config.volume_color;
*wHeader << XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState; *wHeader << NC::XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState;
*wHeader << clEnd; *wHeader << NC::clEnd;
} }
wHeader->Refresh(); wHeader->Refresh();
RedrawHeader = false; RedrawHeader = false;
@@ -295,10 +294,10 @@ int main(int argc, char **argv)
# ifdef ENABLE_VISUALIZER # ifdef ENABLE_VISUALIZER
// visualizer sets timeout to 40ms, but since only it needs such small // visualizer sets timeout to 40ms, but since only it needs such small
// value, we should restore defalt one after switching to another screen. // 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) && !(myScreen == myVisualizer || myLockedScreen == myVisualizer || myInactiveScreen == myVisualizer)
) )
wFooter->SetTimeout(ncmpcpp_window_timeout); wFooter->SetTimeout(500);
# endif // ENABLE_VISUALIZER # endif // ENABLE_VISUALIZER
} }
return 0; return 0;

View File

@@ -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<std::string, std::string> string_pair;
const int ncmpcpp_window_timeout = 500;
#endif

View File

@@ -24,6 +24,8 @@
#include "display.h" #include "display.h"
#include "global.h" #include "global.h"
#include "settings.h"
#include "status.h"
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -33,7 +35,7 @@ Outputs *myOutputs = new Outputs;
void Outputs::Init() void Outputs::Init()
{ {
w = new Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); w = new NC::Menu<MPD::Output>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
w->CyclicScrolling(Config.use_cyclic_scrolling); w->CyclicScrolling(Config.use_cyclic_scrolling);
w->CenteredCursor(Config.centered_cursor); w->CenteredCursor(Config.centered_cursor);
w->HighlightColor(Config.main_highlight_color); w->HighlightColor(Config.main_highlight_color);
@@ -108,7 +110,7 @@ void Outputs::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen< Menu<MPD::Output> >::MouseButtonPressed(me); Screen< NC::Menu<MPD::Output> >::MouseButtonPressed(me);
} }
void Outputs::FetchList() void Outputs::FetchList()

View File

@@ -21,9 +21,7 @@
#ifndef _OUTPUTS_H #ifndef _OUTPUTS_H
#define _OUTPUTS_H #define _OUTPUTS_H
#ifdef HAVE_CONFIG_H #include "config.h"
#include <config.h>
#endif
#ifdef ENABLE_OUTPUTS #ifdef ENABLE_OUTPUTS
@@ -31,7 +29,7 @@
#include "mpdpp.h" #include "mpdpp.h"
#include "screen.h" #include "screen.h"
class Outputs : public Screen< Menu<MPD::Output> > class Outputs : public Screen< NC::Menu<MPD::Output> >
{ {
public: public:
virtual void SwitchTo(); virtual void SwitchTo();
@@ -46,7 +44,7 @@ class Outputs : public Screen< Menu<MPD::Output> >
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return w; } virtual NC::List *GetList() { return w; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -31,6 +31,8 @@
#include "status.h" #include "status.h"
#include "utility/comparators.h" #include "utility/comparators.h"
using namespace std::placeholders;
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -41,7 +43,7 @@ bool Playlist::ReloadRemaining = false;
namespace {// namespace {//
Menu< std::pair<std::string, MPD::Song::GetFunction> > *SortDialog = 0; NC::Menu< std::pair<std::string, MPD::Song::GetFunction> > *SortDialog = 0;
size_t SortDialogHeight; size_t SortDialogHeight;
const size_t SortOptions = 10; const size_t SortOptions = 10;
@@ -54,7 +56,7 @@ bool playlistEntryMatcher(const Regex &rx, const MPD::Song &s);
void Playlist::Init() void Playlist::Init()
{ {
Items = new Menu<MPD::Song>(0, MainStartY, COLS, MainHeight, Config.columns_in_playlist && Config.titles_visibility ? Display::Columns(COLS) : "", Config.main_color, brNone); Items = new NC::Menu<MPD::Song>(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->CyclicScrolling(Config.use_cyclic_scrolling);
Items->CenteredCursor(Config.centered_cursor); Items->CenteredCursor(Config.centered_cursor);
Items->HighlightColor(Config.main_highlight_color); Items->HighlightColor(Config.main_highlight_color);
@@ -69,7 +71,7 @@ void Playlist::Init()
{ {
SortDialogHeight = std::min(int(MainHeight), 17); SortDialogHeight = std::min(int(MainHeight), 17);
SortDialog = new Menu< std::pair<std::string, MPD::Song::GetFunction> >((COLS-SortDialogWidth)/2, (MainHeight-SortDialogHeight)/2+MainStartY, SortDialogWidth, SortDialogHeight, "Sort songs by...", Config.main_color, Config.window_border); SortDialog = new NC::Menu< std::pair<std::string, MPD::Song::GetFunction> >((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->CyclicScrolling(Config.use_cyclic_scrolling);
SortDialog->CenteredCursor(Config.centered_cursor); SortDialog->CenteredCursor(Config.centered_cursor);
SortDialog->setItemDisplayer(Display::Pair<std::string, MPD::Song::GetFunction>); SortDialog->setItemDisplayer(Display::Pair<std::string, MPD::Song::GetFunction>);
@@ -239,7 +241,7 @@ void Playlist::SpacePressed()
if (w == Items && !Items->Empty()) if (w == Items && !Items->Empty())
{ {
Items->Current().setSelected(!Items->Current().isSelected()); Items->Current().setSelected(!Items->Current().isSelected());
Items->Scroll(wDown); Items->Scroll(NC::wDown);
} }
} }
@@ -254,7 +256,7 @@ void Playlist::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
else if (w == SortDialog && SortDialog->hasCoords(me.x, me.y)) else if (w == SortDialog && SortDialog->hasCoords(me.x, me.y))
{ {
@@ -265,7 +267,7 @@ void Playlist::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
} }
@@ -407,7 +409,7 @@ void Playlist::MoveSelectedItems(Movement where)
if (pos > 0) if (pos > 0)
{ {
if (Mpd.Move(pos-1, pos)) if (Mpd.Move(pos-1, pos))
Items->Scroll(wUp); Items->Scroll(NC::wUp);
} }
} }
break; break;
@@ -439,7 +441,7 @@ void Playlist::MoveSelectedItems(Movement where)
if (pos < Items->Size()-1) if (pos < Items->Size()-1)
{ {
if (Mpd.Move(pos, pos+1)) if (Mpd.Move(pos, pos+1))
Items->Scroll(wDown); Items->Scroll(NC::wDown);
} }
} }
break; break;
@@ -497,7 +499,7 @@ void Playlist::AdjustSortOrder(Movement where)
if (pos > 0 && pos < SortOptions) if (pos > 0 && pos < SortOptions)
{ {
SortDialog->Swap(pos, pos-1); SortDialog->Swap(pos, pos-1);
SortDialog->Scroll(wUp); SortDialog->Scroll(NC::wUp);
} }
break; break;
} }
@@ -507,7 +509,7 @@ void Playlist::AdjustSortOrder(Movement where)
if (pos < SortOptions-1) if (pos < SortOptions-1)
{ {
SortDialog->Swap(pos, pos+1); SortDialog->Swap(pos, pos+1);
SortDialog->Scroll(wDown); SortDialog->Scroll(NC::wDown);
} }
break; break;
} }

View File

@@ -22,11 +22,10 @@
#define _PLAYLIST_H #define _PLAYLIST_H
#include "interfaces.h" #include "interfaces.h"
#include "ncmpcpp.h"
#include "screen.h" #include "screen.h"
#include "song.h" #include "song.h"
class Playlist : public Screen<Window>, public Filterable, public HasSongs, public Searchable class Playlist : public Screen<NC::Window>, public Filterable, public HasSongs, public Searchable
{ {
public: public:
enum Movement { mUp, mDown }; enum Movement { mUp, mDown };
@@ -62,7 +61,7 @@ class Playlist : public Screen<Window>, public Filterable, public HasSongs, publ
virtual void removeSelection(); virtual void removeSelection();
virtual MPD::SongList getSelectedSongs(); 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; } virtual bool isMergable() { return true; }
@@ -92,7 +91,7 @@ class Playlist : public Screen<Window>, public Filterable, public HasSongs, publ
//static std::string SongToString(const MPD::Song &s); //static std::string SongToString(const MPD::Song &s);
//static std::string SongInColumnsToString(const MPD::Song &s); //static std::string SongInColumnsToString(const MPD::Song &s);
Menu< MPD::Song > *Items; NC::Menu< MPD::Song > *Items;
int NowPlaying; int NowPlaying;

View File

@@ -32,6 +32,8 @@
#include "tag_editor.h" #include "tag_editor.h"
#include "utility/comparators.h" #include "utility/comparators.h"
using namespace std::placeholders;
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -56,7 +58,7 @@ void PlaylistEditor::Init()
RightColumnStartX = LeftColumnWidth+1; RightColumnStartX = LeftColumnWidth+1;
RightColumnWidth = COLS-LeftColumnWidth-1; RightColumnWidth = COLS-LeftColumnWidth-1;
Playlists = new Menu<std::string>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, brNone); Playlists = new NC::Menu<std::string>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Playlists" : "", Config.main_color, NC::brNone);
Playlists->HighlightColor(Config.active_column_color); Playlists->HighlightColor(Config.active_column_color);
Playlists->CyclicScrolling(Config.use_cyclic_scrolling); Playlists->CyclicScrolling(Config.use_cyclic_scrolling);
Playlists->CenteredCursor(Config.centered_cursor); Playlists->CenteredCursor(Config.centered_cursor);
@@ -64,7 +66,7 @@ void PlaylistEditor::Init()
Playlists->SetSelectSuffix(Config.selected_item_suffix); Playlists->SetSelectSuffix(Config.selected_item_suffix);
Playlists->setItemDisplayer(Display::Default<std::string>); Playlists->setItemDisplayer(Display::Default<std::string>);
Content = new Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, brNone); Content = new NC::Menu<MPD::Song>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Playlist content" : "", Config.main_color, NC::brNone);
Content->HighlightColor(Config.main_highlight_color); Content->HighlightColor(Config.main_highlight_color);
Content->CyclicScrolling(Config.use_cyclic_scrolling); Content->CyclicScrolling(Config.use_cyclic_scrolling);
Content->CenteredCursor(Config.centered_cursor); Content->CenteredCursor(Config.centered_cursor);
@@ -183,7 +185,7 @@ void PlaylistEditor::Update()
if (Content->ReallyEmpty()) if (Content->ReallyEmpty())
{ {
*Content << XY(0, 0) << "Playlist is empty."; *Content << NC::XY(0, 0) << "Playlist is empty.";
Content->Window::Refresh(); Content->Window::Refresh();
} }
} }
@@ -227,7 +229,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where)
{ {
if (Mpd.Move(Playlists->Current().value(), pos-1, pos)) if (Mpd.Move(Playlists->Current().value(), pos-1, pos))
{ {
Content->Scroll(wUp); Content->Scroll(NC::wUp);
Content->Swap(pos-1, pos); Content->Swap(pos-1, pos);
} }
} }
@@ -262,7 +264,7 @@ void PlaylistEditor::MoveSelectedItems(Playlist::Movement where)
{ {
if (Mpd.Move(Playlists->Current().value(), pos, pos+1)) if (Mpd.Move(Playlists->Current().value(), pos, pos+1))
{ {
Content->Scroll(wDown); Content->Scroll(NC::wDown);
Content->Swap(pos, pos+1); Content->Swap(pos, pos+1);
} }
} }
@@ -349,7 +351,7 @@ void PlaylistEditor::AddToPlaylist(bool add_n_play)
} }
if (!add_n_play) if (!add_n_play)
w->Scroll(wDown); w->Scroll(NC::wDown);
} }
void PlaylistEditor::SpacePressed() void PlaylistEditor::SpacePressed()
@@ -361,7 +363,7 @@ void PlaylistEditor::SpacePressed()
if (!Playlists->Empty()) if (!Playlists->Empty())
{ {
Playlists->Current().setSelected(!Playlists->Current().isSelected()); Playlists->Current().setSelected(!Playlists->Current().isSelected());
Playlists->Scroll(wDown); Playlists->Scroll(NC::wDown);
} }
} }
else if (w == Content) else if (w == Content)
@@ -369,7 +371,7 @@ void PlaylistEditor::SpacePressed()
if (!Content->Empty()) if (!Content->Empty())
{ {
Content->Current().setSelected(!Content->Current().isSelected()); 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(); size_t pos = Playlists->Choice();
SpacePressed(); SpacePressed();
if (pos < Playlists->Size()-1) if (pos < Playlists->Size()-1)
Playlists->Scroll(wUp); Playlists->Scroll(NC::wUp);
} }
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
Content->Clear(); Content->Clear();
} }
else if (!Content->Empty() && Content->hasCoords(me.x, me.y)) else if (!Content->Empty() && Content->hasCoords(me.x, me.y))
@@ -410,13 +412,13 @@ void PlaylistEditor::MouseButtonPressed(MEVENT me)
size_t pos = Content->Choice(); size_t pos = Content->Choice();
SpacePressed(); SpacePressed();
if (pos < Content->Size()-1) if (pos < Content->Size()-1)
Content->Scroll(wUp); Content->Scroll(NC::wUp);
} }
else else
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
} }
@@ -576,7 +578,7 @@ void PlaylistEditor::Locate(const std::string &name)
SwitchTo(); SwitchTo();
} }
List *PlaylistEditor::GetList() NC::List *PlaylistEditor::GetList()
{ {
if (w == Playlists) if (w == Playlists)
return Playlists; return Playlists;

View File

@@ -22,9 +22,8 @@
#define _PLAYLIST_EDITOR_H #define _PLAYLIST_EDITOR_H
#include "playlist.h" #include "playlist.h"
#include "ncmpcpp.h"
class PlaylistEditor : public Screen<Window>, public Filterable, public HasSongs, public Searchable class PlaylistEditor : public Screen<NC::Window>, public Filterable, public HasSongs, public Searchable
{ {
public: public:
virtual void SwitchTo(); virtual void SwitchTo();
@@ -60,7 +59,7 @@ class PlaylistEditor : public Screen<Window>, public Filterable, public HasSongs
virtual void Locate(const std::string &); virtual void Locate(const std::string &);
virtual List *GetList(); virtual NC::List *GetList();
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }
@@ -72,8 +71,8 @@ class PlaylistEditor : public Screen<Window>, public Filterable, public HasSongs
bool isPrevColumnAvailable(); bool isPrevColumnAvailable();
bool PrevColumn(); bool PrevColumn();
Menu<std::string> *Playlists; NC::Menu<std::string> *Playlists;
Menu<MPD::Song> *Content; NC::Menu<MPD::Song> *Content;
protected: protected:
virtual void Init(); virtual void Init();

View File

@@ -25,8 +25,8 @@
template <typename T> struct RegexFilter template <typename T> struct RegexFilter
{ {
typedef NCurses::Menu<T> MenuT; typedef NC::Menu<T> MenuT;
typedef typename NCurses::Menu<T>::Item Item; typedef typename NC::Menu<T>::Item Item;
typedef std::function<bool(const Regex &, const T &)> FilterFunction; typedef std::function<bool(const Regex &, const T &)> FilterFunction;
RegexFilter(const std::string &regex_, int cflags, FilterFunction filter) RegexFilter(const std::string &regex_, int cflags, FilterFunction filter)
@@ -56,8 +56,8 @@ private:
template <typename T> struct RegexItemFilter template <typename T> struct RegexItemFilter
{ {
typedef NCurses::Menu<T> MenuT; typedef NC::Menu<T> MenuT;
typedef typename NCurses::Menu<T>::Item Item; typedef typename NC::Menu<T>::Item Item;
typedef std::function<bool(const Regex &, const Item &)> FilterFunction; typedef std::function<bool(const Regex &, const Item &)> FilterFunction;
RegexItemFilter(const std::string &regex_, int cflags, FilterFunction filter) RegexItemFilter(const std::string &regex_, int cflags, FilterFunction filter)

View File

@@ -20,24 +20,110 @@
#include <cassert> #include <cassert>
#include "screen.h"
#include "global.h" #include "global.h"
#include "screen.h"
#include "settings.h"
using Global::myScreen; using Global::myScreen;
using Global::myLockedScreen; using Global::myLockedScreen;
using Global::myInactiveScreen; 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)); if (Config.mouse_list_scroll_whole_page)
mvvline(Global::MainStartY, x, 0, Global::MainHeight); w->Scroll(NC::wPageDown);
attroff(COLOR_PAIR(Config.main_color)); else
refresh(); 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)()) void ApplyToVisibleWindows(void (BasicScreen::*f)())
{ {
if (myLockedScreen && myScreen->isMergable()) if (myLockedScreen && myScreen->isMergable())
@@ -85,49 +171,3 @@ bool isVisible(BasicScreen *screen)
else else
return screen == myScreen; 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;
}

View File

@@ -21,16 +21,11 @@
#ifndef _SCREEN_H #ifndef _SCREEN_H
#define _SCREEN_H #define _SCREEN_H
#include "window.h"
#include "menu.h" #include "menu.h"
#include "mpdpp.h" #include "scrollpad.h"
#include "helpers.h"
#include "settings.h"
#include "status.h"
void ApplyToVisibleWindows(void (BasicScreen::*f)()); void GenericMouseButtonPressed(NC::Window *w, MEVENT me);
void UpdateInactiveScreen(BasicScreen *); void ScrollpadMouseButtonPressed(NC::Scrollpad *w, MEVENT me);
bool isVisible(BasicScreen *);
/// An interface for various instantiations of Screen template class. Since C++ doesn't like /// 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 /// comparison of two different instantiations of the same template class we need the most
@@ -46,7 +41,7 @@ class BasicScreen
virtual ~BasicScreen() { } virtual ~BasicScreen() { }
/// @see Screen::ActiveWindow() /// @see Screen::ActiveWindow()
virtual Window *ActiveWindow() = 0; virtual NC::Window *ActiveWindow() = 0;
/// Method used for switching to screen /// Method used for switching to screen
virtual void SwitchTo() = 0; virtual void SwitchTo() = 0;
@@ -69,7 +64,7 @@ class BasicScreen
virtual void RefreshWindow() = 0; virtual void RefreshWindow() = 0;
/// @see Screen::Scroll() /// @see Screen::Scroll()
virtual void Scroll(Where where) = 0; virtual void Scroll(NC::Where where) = 0;
/// Invoked after Enter was pressed /// Invoked after Enter was pressed
virtual void EnterPressed() = 0; virtual void EnterPressed() = 0;
@@ -82,7 +77,7 @@ class BasicScreen
/// @return pointer to instantiation of Menu template class /// @return pointer to instantiation of Menu template class
/// cast to List if available or null pointer otherwise /// 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 /// When this is overwritten with a function returning true, the
/// screen will be used in tab switching. /// screen will be used in tab switching.
@@ -129,6 +124,10 @@ class BasicScreen
bool isInitialized; 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 /// 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 /// for the screen to be working properly and assumes that we didn't forget
/// about anything vital. /// about anything vital.
@@ -143,7 +142,7 @@ template <typename WindowType> class Screen : public BasicScreen
/// it's useful to determine the one that is being /// it's useful to determine the one that is being
/// active /// active
/// @return address to window object cast to void * /// @return address to window object cast to void *
virtual Window *ActiveWindow(); virtual NC::Window *ActiveWindow();
/// @return pointer to currently active window /// @return pointer to currently active window
WindowType *Main(); WindowType *Main();
@@ -158,7 +157,7 @@ template <typename WindowType> class Screen : public BasicScreen
/// if fancy scrolling feature is disabled, enters the /// if fancy scrolling feature is disabled, enters the
/// loop that holds main loop until user releases the key /// loop that holds main loop until user releases the key
/// @param where indicates where one wants to scroll /// @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 /// Invoked after there was one of mouse buttons pressed
/// @param me struct that contains coords of where the click /// @param me struct that contains coords of where the click
@@ -173,7 +172,7 @@ template <typename WindowType> class Screen : public BasicScreen
WindowType *w; WindowType *w;
}; };
template <typename WindowType> Window *Screen<WindowType>::ActiveWindow() template <typename WindowType> NC::Window *Screen<WindowType>::ActiveWindow()
{ {
return w; return w;
} }
@@ -193,46 +192,22 @@ template <typename WindowType> void Screen<WindowType>::RefreshWindow()
w->Display(); w->Display();
} }
template <typename WindowType> void Screen<WindowType>::Scroll(Where where) template <typename WindowType> void Screen<WindowType>::Scroll(NC::Where where)
{ {
w->Scroll(where); w->Scroll(where);
} }
template <typename WindowType> void Screen<WindowType>::MouseButtonPressed(MEVENT me) template <typename WindowType> void Screen<WindowType>::MouseButtonPressed(MEVENT me)
{ {
if (me.bstate & BUTTON2_PRESSED) GenericMouseButtonPressed(w, me);
{
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);
}
} }
/// Specialization for Screen<Scrollpad>::MouseButtonPressed, that should /// Specialization for Screen<Scrollpad>::MouseButtonPressed, that should
/// not scroll whole page, but rather a few lines (the number of them is /// not scroll whole page, but rather a few lines (the number of them is
/// defined in the config) /// defined in the config)
template <> inline void Screen<Scrollpad>::MouseButtonPressed(MEVENT me) template <> inline void Screen<NC::Scrollpad>::MouseButtonPressed(MEVENT me)
{ {
if (me.bstate & BUTTON2_PRESSED) ScrollpadMouseButtonPressed(w, me);
{
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);
}
} }
#endif #endif

View File

@@ -22,7 +22,7 @@
#include "scrollpad.h" #include "scrollpad.h"
using namespace NCurses; namespace NC {//
Scrollpad::Scrollpad(size_t startx, Scrollpad::Scrollpad(size_t startx,
size_t starty, size_t starty,
@@ -208,3 +208,4 @@ Scrollpad &Scrollpad::operator<<(const std::string &s)
} }
#endif // _UTF8 #endif // _UTF8
}

View File

@@ -24,7 +24,7 @@
#include "window.h" #include "window.h"
#include "strbuffer.h" #include "strbuffer.h"
namespace NCurses namespace NC
{ {
/// Scrollpad is specialized window that can hold large portion of text and /// 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. /// supports scrolling if the amount of it is bigger than the window area.

View File

@@ -31,6 +31,8 @@
#include "status.h" #include "status.h"
#include "utility/comparators.h" #include "utility/comparators.h"
using namespace std::placeholders;
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -66,7 +68,7 @@ namespace pos {//
}*/ }*/
std::string SEItemToString(const SEItem &ei); std::string SEItemToString(const SEItem &ei);
bool SEItemEntryMatcher(const Regex &rx, const Menu<SEItem>::Item &item, bool filter); bool SEItemEntryMatcher(const Regex &rx, const NC::Menu<SEItem>::Item &item, bool filter);
} }
@@ -99,7 +101,7 @@ size_t SearchEngine::SearchButton = 15;
void SearchEngine::Init() void SearchEngine::Init()
{ {
w = new Menu<SEItem>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); w = new NC::Menu<SEItem>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
w->HighlightColor(Config.main_highlight_color); w->HighlightColor(Config.main_highlight_color);
w->CyclicScrolling(Config.use_cyclic_scrolling); w->CyclicScrolling(Config.use_cyclic_scrolling);
w->CenteredCursor(Config.centered_cursor); w->CenteredCursor(Config.centered_cursor);
@@ -150,7 +152,7 @@ void SearchEngine::SwitchTo()
if (!w->Back().value().isSong()) if (!w->Back().value().isSong())
{ {
*w << XY(0, 0) << "Updating list..."; *w << NC::XY(0, 0) << "Updating list...";
UpdateFoundList(); UpdateFoundList();
} }
} }
@@ -171,23 +173,23 @@ void SearchEngine::EnterPressed()
if (option < ConstraintsNumber) if (option < ConstraintsNumber)
{ {
std::string constraint = ConstraintsNames[option]; std::string constraint = ConstraintsNames[option];
Statusbar() << fmtBold << constraint << fmtBoldEnd << ": "; Statusbar() << NC::fmtBold << constraint << NC::fmtBoldEnd << ": ";
itsConstraints[option] = Global::wFooter->GetString(itsConstraints[option]); itsConstraints[option] = Global::wFooter->GetString(itsConstraints[option]);
w->Current().value().buffer().Clear(); w->Current().value().buffer().Clear();
constraint.resize(13, ' '); 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]); ShowTag(w->Current().value().buffer(), itsConstraints[option]);
} }
else if (option == ConstraintsNumber+1) else if (option == ConstraintsNumber+1)
{ {
Config.search_in_db = !Config.search_in_db; 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) else if (option == ConstraintsNumber+2)
{ {
if (!*++SearchMode) if (!*++SearchMode)
SearchMode = &SearchModes[0]; 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) else if (option == SearchButton)
{ {
@@ -204,15 +206,15 @@ void SearchEngine::EnterPressed()
found += 3; // don't count options inserted below found += 3; // don't count options inserted below
w->InsertSeparator(ResetButton+1); w->InsertSeparator(ResetButton+1);
w->InsertItem(ResetButton+2, SEItem(), 1, 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); w->InsertSeparator(ResetButton+3);
UpdateFoundList(); UpdateFoundList();
ShowMessage("Searching finished"); ShowMessage("Searching finished");
if (Config.block_search_constraints_change) if (Config.block_search_constraints_change)
for (size_t i = 0; i < StaticOptions-4; ++i) for (size_t i = 0; i < StaticOptions-4; ++i)
w->at(i).setInactive(true); w->at(i).setInactive(true);
w->Scroll(wDown); w->Scroll(NC::wDown);
w->Scroll(wDown); w->Scroll(NC::wDown);
} }
else else
ShowMessage("No results found"); ShowMessage("No results found");
@@ -239,13 +241,13 @@ void SearchEngine::SpacePressed()
if (Config.space_selects) if (Config.space_selects)
{ {
w->Current().setSelected(!w->Current().isSelected()); w->Current().setSelected(!w->Current().isSelected());
w->Scroll(wDown); w->Scroll(NC::wDown);
return; return;
} }
bool res = myPlaylist->Add(w->Current().value().song(), w->Current().isBold(), 0); bool res = myPlaylist->Add(w->Current().value().song(), w->Current().isBold(), 0);
w->Current().setBold(res); w->Current().setBold(res);
w->Scroll(wDown); w->Scroll(NC::wDown);
} }
void SearchEngine::MouseButtonPressed(MEVENT me) void SearchEngine::MouseButtonPressed(MEVENT me)
@@ -266,14 +268,14 @@ void SearchEngine::MouseButtonPressed(MEVENT me)
size_t pos = w->Choice(); size_t pos = w->Choice();
SpacePressed(); SpacePressed();
if (pos < w->Size()-1) if (pos < w->Size()-1)
w->Scroll(wUp); w->Scroll(NC::wUp);
} }
else else
EnterPressed(); EnterPressed();
} }
} }
else else
Screen< Menu<SEItem> >::MouseButtonPressed(me); Screen< NC::Menu<SEItem> >::MouseButtonPressed(me);
} }
/***********************************************************************/ /***********************************************************************/
@@ -386,12 +388,12 @@ void SearchEngine::Prepare()
{ {
std::string constraint = ConstraintsNames[i]; std::string constraint = ConstraintsNames[i];
constraint.resize(13, ' '); 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]); 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+1).value().mkBuffer() << NC::fmtBold << "Search in:" << NC::fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist");
w->at(ConstraintsNumber+2).value().mkBuffer() << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << *SearchMode; w->at(ConstraintsNumber+2).value().mkBuffer() << NC::fmtBold << "Search mode:" << NC::fmtBoldEnd << ' ' << *SearchMode;
w->at(SearchButton).value().mkBuffer() << "Search"; w->at(SearchButton).value().mkBuffer() << "Search";
w->at(ResetButton).value().mkBuffer() << "Reset"; w->at(ResetButton).value().mkBuffer() << "Reset";
@@ -615,7 +617,7 @@ std::string SEItemToString(const SEItem &ei)
return result; return result;
} }
bool SEItemEntryMatcher(const Regex &rx, const Menu<SEItem>::Item &item, bool filter) bool SEItemEntryMatcher(const Regex &rx, const NC::Menu<SEItem>::Item &item, bool filter)
{ {
if (item.isSeparator() || !item.value().isSong()) if (item.isSeparator() || !item.value().isSong())
return filter; return filter;

View File

@@ -25,13 +25,12 @@
#include "interfaces.h" #include "interfaces.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "ncmpcpp.h"
#include "screen.h" #include "screen.h"
struct SEItem struct SEItem
{ {
SEItem() : isThisSong(false), itsBuffer(0) { } 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 MPD::Song &s) : isThisSong(true), itsSong(s) { }
SEItem(const SEItem &ei) { *this = ei; } SEItem(const SEItem &ei) { *this = ei; }
~SEItem() { ~SEItem() {
@@ -39,19 +38,19 @@ struct SEItem
delete itsBuffer; delete itsBuffer;
} }
Buffer &mkBuffer() { NC::Buffer &mkBuffer() {
assert(!isThisSong); assert(!isThisSong);
delete itsBuffer; delete itsBuffer;
itsBuffer = new Buffer(); itsBuffer = new NC::Buffer();
return *itsBuffer; return *itsBuffer;
} }
bool isSong() const { return isThisSong; } 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; } 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; } const MPD::Song &song() const { assert(isThisSong); return itsSong; }
SEItem &operator=(const SEItem &se) { SEItem &operator=(const SEItem &se) {
@@ -61,7 +60,7 @@ struct SEItem
if (se.isThisSong) if (se.isThisSong)
itsSong = se.itsSong; itsSong = se.itsSong;
else if (se.itsBuffer) else if (se.itsBuffer)
itsBuffer = new Buffer(*se.itsBuffer); itsBuffer = new NC::Buffer(*se.itsBuffer);
else else
itsBuffer = 0; itsBuffer = 0;
return *this; return *this;
@@ -70,11 +69,11 @@ struct SEItem
private: private:
bool isThisSong; bool isThisSong;
Buffer *itsBuffer; NC::Buffer *itsBuffer;
MPD::Song itsSong; MPD::Song itsSong;
}; };
class SearchEngine : public Screen< Menu<SEItem> >, public Filterable, public HasSongs, public Searchable class SearchEngine : public Screen< NC::Menu<SEItem> >, public Filterable, public HasSongs, public Searchable
{ {
public: public:
virtual void Resize(); virtual void Resize();
@@ -105,7 +104,7 @@ class SearchEngine : public Screen< Menu<SEItem> >, public Filterable, public Ha
virtual void removeSelection(); virtual void removeSelection();
virtual MPD::SongList getSelectedSongs(); 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; } virtual bool isMergable() { return true; }

View File

@@ -27,6 +27,8 @@
#include "playlist.h" #include "playlist.h"
#include "playlist_editor.h" #include "playlist_editor.h"
#include "sel_items_adder.h" #include "sel_items_adder.h"
#include "settings.h"
#include "status.h"
#include "utility/comparators.h" #include "utility/comparators.h"
using Global::MainHeight; using Global::MainHeight;
@@ -39,13 +41,13 @@ SelectedItemsAdder *mySelectedItemsAdder = new SelectedItemsAdder;
void SelectedItemsAdder::Init() void SelectedItemsAdder::Init()
{ {
SetDimensions(); SetDimensions();
itsPlaylistSelector = new Menu<std::string>((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "Add selected item(s) to...", Config.main_color, Config.window_border); itsPlaylistSelector = new NC::Menu<std::string>((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->CyclicScrolling(Config.use_cyclic_scrolling);
itsPlaylistSelector->CenteredCursor(Config.centered_cursor); itsPlaylistSelector->CenteredCursor(Config.centered_cursor);
itsPlaylistSelector->HighlightColor(Config.main_highlight_color); itsPlaylistSelector->HighlightColor(Config.main_highlight_color);
itsPlaylistSelector->setItemDisplayer(Display::Default<std::string>); itsPlaylistSelector->setItemDisplayer(Display::Default<std::string>);
itsPositionSelector = new Menu<std::string>((COLS-itsPSWidth)/2, (MainHeight-itsPSHeight)/2+MainStartY, itsPSWidth, itsPSHeight, "Where?", Config.main_color, Config.window_border); itsPositionSelector = new NC::Menu<std::string>((COLS-itsPSWidth)/2, (MainHeight-itsPSHeight)/2+MainStartY, itsPSWidth, itsPSHeight, "Where?", Config.main_color, Config.window_border);
itsPositionSelector->CyclicScrolling(Config.use_cyclic_scrolling); itsPositionSelector->CyclicScrolling(Config.use_cyclic_scrolling);
itsPositionSelector->CenteredCursor(Config.centered_cursor); itsPositionSelector->CenteredCursor(Config.centered_cursor);
itsPositionSelector->HighlightColor(Config.main_highlight_color); itsPositionSelector->HighlightColor(Config.main_highlight_color);
@@ -259,7 +261,7 @@ void SelectedItemsAdder::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen< Menu<std::string> >::MouseButtonPressed(me); Screen< NC::Menu<std::string> >::MouseButtonPressed(me);
} }
void SelectedItemsAdder::SetDimensions() void SelectedItemsAdder::SetDimensions()

View File

@@ -21,10 +21,9 @@
#ifndef _SEL_ITEMS_ADDER_H #ifndef _SEL_ITEMS_ADDER_H
#define _SEL_ITEMS_ADDER_H #define _SEL_ITEMS_ADDER_H
#include "ncmpcpp.h"
#include "screen.h" #include "screen.h"
class SelectedItemsAdder : public Screen< Menu<std::string> > class SelectedItemsAdder : public Screen< NC::Menu<std::string> >
{ {
public: public:
SelectedItemsAdder() : itsPSWidth(35), itsPSHeight(11) { } SelectedItemsAdder() : itsPSWidth(35), itsPSHeight(11) { }
@@ -41,7 +40,7 @@ class SelectedItemsAdder : public Screen< Menu<std::string> >
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return w; } virtual NC::List *GetList() { return w; }
virtual bool isMergable() { return false; } virtual bool isMergable() { return false; }
@@ -52,8 +51,8 @@ class SelectedItemsAdder : public Screen< Menu<std::string> >
private: private:
void SetDimensions(); void SetDimensions();
Menu<std::string> *itsPlaylistSelector; NC::Menu<std::string> *itsPlaylistSelector;
Menu<std::string> *itsPositionSelector; NC::Menu<std::string> *itsPositionSelector;
size_t itsPSWidth; size_t itsPSWidth;
size_t itsPSHeight; size_t itsPSHeight;

View File

@@ -22,6 +22,7 @@
#include <iomanip> #include <iomanip>
#include "global.h" #include "global.h"
#include "helpers.h"
#include "server_info.h" #include "server_info.h"
using Global::MainHeight; using Global::MainHeight;
@@ -33,7 +34,7 @@ ServerInfo *myServerInfo = new ServerInfo;
void ServerInfo::Init() void ServerInfo::Init()
{ {
SetDimensions(); 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(); itsURLHandlers = Mpd.GetURLHandlers();
itsTagTypes = Mpd.GetTagTypes(); itsTagTypes = Mpd.GetTagTypes();
@@ -99,26 +100,26 @@ void ServerInfo::Update()
Mpd.UpdateStats(); Mpd.UpdateStats();
w->Clear(); w->Clear();
*w << fmtBold << U("Version: ") << fmtBoldEnd << U("0.") << Mpd.Version() << U(".*\n"); *w << NC::fmtBold << U("Version: ") << NC::fmtBoldEnd << U("0.") << Mpd.Version() << U(".*\n");
*w << fmtBold << U("Uptime: ") << fmtBoldEnd; *w << NC::fmtBold << U("Uptime: ") << NC::fmtBoldEnd;
ShowTime(*w, Mpd.Uptime(), 1); ShowTime(*w, Mpd.Uptime(), 1);
*w << '\n'; *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 << '\n';
*w << fmtBold << U("Total playtime: ") << fmtBoldEnd; *w << NC::fmtBold << U("Total playtime: ") << NC::fmtBoldEnd;
ShowTime(*w, Mpd.DBPlayTime(), 1); ShowTime(*w, Mpd.DBPlayTime(), 1);
*w << '\n'; *w << '\n';
*w << fmtBold << U("Artist names: ") << fmtBoldEnd << Mpd.NumberOfArtists() << '\n'; *w << NC::fmtBold << U("Artist names: ") << NC::fmtBoldEnd << Mpd.NumberOfArtists() << '\n';
*w << fmtBold << U("Album names: ") << fmtBoldEnd << Mpd.NumberOfAlbums() << '\n'; *w << NC::fmtBold << U("Album names: ") << NC::fmtBoldEnd << Mpd.NumberOfAlbums() << '\n';
*w << fmtBold << U("Songs in database: ") << fmtBoldEnd << Mpd.NumberOfSongs() << '\n'; *w << NC::fmtBold << U("Songs in database: ") << NC::fmtBoldEnd << Mpd.NumberOfSongs() << '\n';
*w << '\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 << '\n';
*w << fmtBold << U("URL Handlers:") << fmtBoldEnd; *w << NC::fmtBold << U("URL Handlers:") << NC::fmtBoldEnd;
for (auto it = itsURLHandlers.begin(); it != itsURLHandlers.end(); ++it) for (auto it = itsURLHandlers.begin(); it != itsURLHandlers.end(); ++it)
*w << (it != itsURLHandlers.begin() ? U(", ") : U(" ")) << *it; *w << (it != itsURLHandlers.begin() ? U(", ") : U(" ")) << *it;
*w << U("\n\n"); *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) for (auto it = itsTagTypes.begin(); it != itsTagTypes.end(); ++it)
*w << (it != itsTagTypes.begin() ? U(", ") : U(" ")) << *it; *w << (it != itsTagTypes.begin() ? U(", ") : U(" ")) << *it;

View File

@@ -23,7 +23,7 @@
#include "screen.h" #include "screen.h"
class ServerInfo : public Screen<Scrollpad> class ServerInfo : public Screen<NC::Scrollpad>
{ {
public: public:
virtual void SwitchTo(); virtual void SwitchTo();
@@ -38,7 +38,7 @@ class ServerInfo : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return false; } virtual bool isMergable() { return false; }

View File

@@ -25,6 +25,7 @@
#else #else
# include <sys/stat.h> # include <sys/stat.h>
#endif // WIN32 #endif // WIN32
#include <algorithm>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <string> #include <string>
@@ -58,33 +59,33 @@ KeyConfiguration Keys;
namespace 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") if (color == "black")
result = NCurses::clBlack; result = NC::clBlack;
else if (color == "red") else if (color == "red")
result = NCurses::clRed; result = NC::clRed;
else if (color == "green") else if (color == "green")
result = NCurses::clGreen; result = NC::clGreen;
else if (color == "yellow") else if (color == "yellow")
result = NCurses::clYellow; result = NC::clYellow;
else if (color == "blue") else if (color == "blue")
result = NCurses::clBlue; result = NC::clBlue;
else if (color == "magenta") else if (color == "magenta")
result = NCurses::clMagenta; result = NC::clMagenta;
else if (color == "cyan") else if (color == "cyan")
result = NCurses::clCyan; result = NC::clCyan;
else if (color == "white") else if (color == "white")
result = NCurses::clWhite; result = NC::clWhite;
return result; 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) BasicScreen *intToScreen(int n)
@@ -308,31 +309,31 @@ void Configuration::SetDefaults()
tag_editor_album_format = "{{(%y) }%b}"; tag_editor_album_format = "{{(%y) }%b}";
new_header_first_line = "{$b$1$aqqu$/a$9 {%t}|{%f} $1$atqq$/a$9$/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}}"; 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"); progressbar = U("=>\0");
visualizer_chars = U("◆│"); visualizer_chars = U("◆│");
pattern = "%n - %t"; pattern = "%n - %t";
selected_item_prefix << clMagenta; selected_item_prefix << NC::clMagenta;
selected_item_suffix << clEnd; selected_item_suffix << NC::clEnd;
now_playing_prefix << fmtBold; now_playing_prefix << NC::fmtBold;
now_playing_suffix << fmtBoldEnd; now_playing_suffix << NC::fmtBoldEnd;
color1 = clWhite; color1 = NC::clWhite;
color2 = clGreen; color2 = NC::clGreen;
empty_tags_color = clCyan; empty_tags_color = NC::clCyan;
header_color = clDefault; header_color = NC::clDefault;
volume_color = clDefault; volume_color = NC::clDefault;
state_line_color = clDefault; state_line_color = NC::clDefault;
state_flags_color = clDefault; state_flags_color = NC::clDefault;
main_color = clYellow; main_color = NC::clYellow;
main_highlight_color = main_color; main_highlight_color = main_color;
progressbar_color = clDefault; progressbar_color = NC::clDefault;
progressbar_elapsed_color = clDefault; progressbar_elapsed_color = NC::clDefault;
statusbar_color = clDefault; statusbar_color = NC::clDefault;
alternative_ui_separator_color = clBlack; alternative_ui_separator_color = NC::clBlack;
active_column_color = clRed; active_column_color = NC::clRed;
window_border = brGreen; window_border = NC::brGreen;
active_window_border = brRed; active_window_border = NC::brRed;
visualizer_color = clYellow; visualizer_color = NC::clYellow;
media_lib_primary_tag = MPD_TAG_ARTIST; media_lib_primary_tag = MPD_TAG_ARTIST;
enable_idle_notifications = true; enable_idle_notifications = true;
colors_enabled = true; colors_enabled = true;
@@ -567,7 +568,7 @@ void Configuration::Read()
// make version without colors // make version without colors
if (song_status_format.find("$") != std::string::npos) if (song_status_format.find("$") != std::string::npos)
{ {
Buffer status_no_colors; NC::Buffer status_no_colors;
String2Buffer(song_status_format, status_no_colors); String2Buffer(song_status_format, status_no_colors);
song_status_format_no_colors = status_no_colors.Str(); song_status_format_no_colors = status_no_colors.Str();
} }
@@ -682,7 +683,7 @@ void Configuration::Read()
{ {
selected_item_prefix.Clear(); selected_item_prefix.Clear();
String2Buffer(v, selected_item_prefix); 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") else if (name == "selected_item_suffix")
@@ -691,7 +692,7 @@ void Configuration::Read()
{ {
selected_item_suffix.Clear(); selected_item_suffix.Clear();
String2Buffer(v, selected_item_suffix); 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") else if (name == "now_playing_prefix")
@@ -700,7 +701,7 @@ void Configuration::Read()
{ {
now_playing_prefix.Clear(); now_playing_prefix.Clear();
String2Buffer(v, now_playing_prefix); 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") else if (name == "now_playing_suffix")
@@ -709,7 +710,7 @@ void Configuration::Read()
{ {
now_playing_suffix.Clear(); now_playing_suffix.Clear();
String2Buffer(TO_WSTRING(v), now_playing_suffix); 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") else if (name == "color1")
@@ -1172,7 +1173,7 @@ void Configuration::GenerateColumns()
// generate format for converting tags in columns to string for Playlist::SongInColumnsToString() // generate format for converting tags in columns to string for Playlist::SongInColumnsToString()
char tag[] = "{% }|"; char tag[] = "{% }|";
song_in_columns_to_string_format = "{"; song_in_columns_to_string_format = "{";
for (std::vector<Column>::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) 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; return;
if (dir[0] == '~') if (dir[0] == '~')
dir.replace(0, 1, home_directory); dir.replace(0, 1, home_directory);
replace(dir.begin(), dir.end(), '\\', '/'); std::replace(dir.begin(), dir.end(), '\\', '/');
if (*dir.rbegin() != '/') if (*dir.rbegin() != '/')
dir += '/'; dir += '/';
} }

View File

@@ -23,11 +23,9 @@
#include <cassert> #include <cassert>
#include <vector> #include <vector>
#include <mpd/client.h> #include <mpd/client.h>
#include "actions.h" #include "actions.h"
#include "ncmpcpp.h" #include "strbuffer.h"
class BasicScreen; // forward declaration for screens sequence class BasicScreen; // forward declaration for screens sequence
@@ -41,7 +39,7 @@ struct Column
std::string type; std::string type;
int width; int width;
int stretch_limit; int stretch_limit;
Color color; NC::Color color;
bool fixed; bool fixed;
bool right_alignment; bool right_alignment;
bool display_empty_tag; bool display_empty_tag;
@@ -126,30 +124,30 @@ struct Configuration
std::vector<Column> columns; std::vector<Column> columns;
Buffer browser_playlist_prefix; NC::Buffer browser_playlist_prefix;
Buffer selected_item_prefix; NC::Buffer selected_item_prefix;
Buffer selected_item_suffix; NC::Buffer selected_item_suffix;
Buffer now_playing_prefix; NC::Buffer now_playing_prefix;
basic_buffer<my_char_t> now_playing_suffix; NC::basic_buffer<my_char_t> now_playing_suffix;
Color color1; NC::Color color1;
Color color2; NC::Color color2;
Color empty_tags_color; NC::Color empty_tags_color;
Color header_color; NC::Color header_color;
Color volume_color; NC::Color volume_color;
Color state_line_color; NC::Color state_line_color;
Color state_flags_color; NC::Color state_flags_color;
Color main_color; NC::Color main_color;
Color main_highlight_color; NC::Color main_highlight_color;
Color progressbar_color; NC::Color progressbar_color;
Color progressbar_elapsed_color; NC::Color progressbar_elapsed_color;
Color statusbar_color; NC::Color statusbar_color;
Color alternative_ui_separator_color; NC::Color alternative_ui_separator_color;
Color active_column_color; NC::Color active_column_color;
Color visualizer_color; NC::Color visualizer_color;
Border window_border; NC::Border window_border;
Border active_window_border; NC::Border active_window_border;
mpd_tag_type media_lib_primary_tag; mpd_tag_type media_lib_primary_tag;

View File

@@ -24,6 +24,7 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector>
#include <mpd/client.h> #include <mpd/client.h>
@@ -85,6 +86,8 @@ struct Song
size_t m_hash; size_t m_hash;
}; };
typedef std::vector<Song> SongList;
} }
#endif #endif

View File

@@ -19,9 +19,15 @@
***************************************************************************/ ***************************************************************************/
#include "global.h" #include "global.h"
#include "helpers.h"
#include "song_info.h" #include "song_info.h"
#include "tag_editor.h" #include "tag_editor.h"
#ifdef HAVE_TAGLIB_H
# include "fileref.h"
# include "tag.h"
#endif // HAVE_TAGLIB_H
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; using Global::MainStartY;
@@ -45,7 +51,7 @@ const SongInfo::Metadata SongInfo::Tags[] =
void SongInfo::Init() 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; isInitialized = 1;
} }
@@ -109,24 +115,24 @@ void SongInfo::PrepareSong(MPD::Song &s)
TagLib::FileRef f(path_to_file.c_str()); TagLib::FileRef f(path_to_file.c_str());
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
*w << fmtBold << Config.color1 << U("Filename: ") << fmtBoldEnd << Config.color2 << s.getName() << '\n' << clEnd; *w << NC::fmtBold << Config.color1 << U("Filename: ") << NC::fmtBoldEnd << Config.color2 << s.getName() << '\n' << NC::clEnd;
*w << fmtBold << U("Directory: ") << fmtBoldEnd << Config.color2; *w << NC::fmtBold << U("Directory: ") << NC::fmtBoldEnd << Config.color2;
ShowTag(*w, s.getDirectory()); ShowTag(*w, s.getDirectory());
*w << U("\n\n") << clEnd; *w << U("\n\n") << NC::clEnd;
*w << fmtBold << U("Length: ") << fmtBoldEnd << Config.color2 << s.getLength() << '\n' << clEnd; *w << NC::fmtBold << U("Length: ") << NC::fmtBoldEnd << Config.color2 << s.getLength() << '\n' << NC::clEnd;
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
if (!f.isNull()) if (!f.isNull())
{ {
*w << fmtBold << U("Bitrate: ") << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << U(" kbps\n") << clEnd; *w << NC::fmtBold << U("Bitrate: ") << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << U(" kbps\n") << NC::clEnd;
*w << fmtBold << U("Sample rate: ") << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << U(" Hz\n") << clEnd; *w << NC::fmtBold << U("Sample rate: ") << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << U(" Hz\n") << NC::clEnd;
*w << fmtBold << U("Channels: ") << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? U("Mono") : U("Stereo")) << '\n' << clDefault; *w << NC::fmtBold << U("Channels: ") << NC::fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? U("Mono") : U("Stereo")) << '\n' << NC::clDefault;
} }
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
*w << clDefault; *w << NC::clDefault;
for (const Metadata *m = Tags; m->Name; ++m) 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)); ShowTag(*w, s.getTags(m->Get));
} }
} }

View File

@@ -24,7 +24,7 @@
#include "screen.h" #include "screen.h"
#include "mutable_song.h" #include "mutable_song.h"
class SongInfo : public Screen<Scrollpad> class SongInfo : public Screen<NC::Scrollpad>
{ {
public: public:
struct Metadata struct Metadata
@@ -44,7 +44,7 @@ class SongInfo : public Screen<Scrollpad>
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -346,7 +346,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
myPlaylist->NowPlaying = -1; myPlaylist->NowPlaying = -1;
if (Config.new_design) 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]"; player_state = "[stopped]";
changed.Volume = 1; changed.Volume = 1;
changed.StatusFlags = 1; changed.StatusFlags = 1;
@@ -362,20 +362,20 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
} }
# ifdef ENABLE_VISUALIZER # ifdef ENABLE_VISUALIZER
if (myScreen == myVisualizer) if (myScreen == myVisualizer)
wFooter->SetTimeout(state == MPD::psPlay ? Visualizer::WindowTimeout : ncmpcpp_window_timeout); wFooter->SetTimeout(state == MPD::psPlay ? Visualizer::WindowTimeout : 500);
# endif // ENABLE_VISUALIZER # endif // ENABLE_VISUALIZER
if (Config.new_design) 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(); wHeader->Refresh();
} }
else if (!block_statusbar_update && Config.statusbar_visibility) else if (!block_statusbar_update && Config.statusbar_visibility)
{ {
*wFooter << XY(0, 1); *wFooter << NC::XY(0, 1);
if (player_state.empty()) if (player_state.empty())
*wFooter << wclrtoeol; *wFooter << wclrtoeol;
else else
*wFooter << fmtBold << player_state << fmtBoldEnd; *wFooter << NC::fmtBold << player_state << NC::fmtBoldEnd;
} }
} }
if (changed.SongID) if (changed.SongID)
@@ -442,28 +442,28 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
tracklength += " kbps"; tracklength += " kbps";
} }
basic_buffer<my_char_t> first, second; NC::basic_buffer<my_char_t> 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_first_line, "$"))), first);
String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.new_header_second_line, "$"))), second); 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_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 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_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; size_t second_start = second_len < COLS-second_margin ? (COLS-second_len)/2 : player_state.length()+1;
if (!Global::SeekingInProgress) if (!Global::SeekingInProgress)
*wHeader << XY(0, 0) << wclrtoeol << tracklength; *wHeader << NC::XY(0, 0) << wclrtoeol << tracklength;
*wHeader << XY(first_start, 0); *wHeader << NC::XY(first_start, 0);
first.Write(*wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, U(" ** ")); first.Write(*wHeader, first_line_scroll_begin, COLS-tracklength.length()-VolumeState.length()-1, U(" ** "));
*wHeader << XY(0, 1) << wclrtoeol << fmtBold << player_state << fmtBoldEnd; *wHeader << NC::XY(0, 1) << wclrtoeol << NC::fmtBold << player_state << NC::fmtBoldEnd;
*wHeader << XY(second_start, 1); *wHeader << NC::XY(second_start, 1);
second.Write(*wHeader, second_line_scroll_begin, COLS-player_state.length()-8-2, U(" ** ")); 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; changed.StatusFlags = 1;
} }
@@ -494,11 +494,11 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
tracklength += MPD::Song::ShowTime(Mpd.GetElapsedTime()); tracklength += MPD::Song::ShowTime(Mpd.GetElapsedTime());
tracklength += "]"; tracklength += "]";
} }
basic_buffer<my_char_t> np_song; NC::basic_buffer<my_char_t> np_song;
String2Buffer(TO_WSTRING(utf_to_locale_cpy(np.toString(Config.song_status_format, "$"))), 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(" ** ")); 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) if (!block_progressbar_update)
DrawProgressbar(Mpd.GetElapsedTime(), Mpd.GetTotalTime()); DrawProgressbar(Mpd.GetElapsedTime(), Mpd.GetTotalTime());
@@ -507,7 +507,7 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
else else
{ {
if (!block_statusbar_update && Config.statusbar_visibility) 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_crossfade ? mpd_crossfade : '-';
switch_state += mpd_db_updating ? mpd_db_updating : '-'; switch_state += mpd_db_updating ? mpd_db_updating : '-';
switch_state += ']'; 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 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); mvwhline(wHeader->Raw(), 2, 0, 0, COLS);
*wHeader << clEnd << fmtBoldEnd; *wHeader << NC::clEnd << NC::fmtBoldEnd;
} }
wHeader->Refresh(); wHeader->Refresh();
} }
@@ -625,8 +625,8 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
VolumeState += "%"; VolumeState += "%";
} }
*wHeader << Config.volume_color; *wHeader << Config.volume_color;
*wHeader << XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState; *wHeader << NC::XY(wHeader->GetWidth()-VolumeState.length(), 0) << VolumeState;
*wHeader << clEnd; *wHeader << NC::clEnd;
wHeader->Refresh(); wHeader->Refresh();
} }
if (changed.Outputs) if (changed.Outputs)
@@ -642,9 +642,9 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
ApplyToVisibleWindows(&BasicScreen::RefreshWindow); 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; return *wFooter;
} }
@@ -653,7 +653,7 @@ void DrawProgressbar(unsigned elapsed, unsigned time)
unsigned pb_width = wFooter->GetWidth(); unsigned pb_width = wFooter->GetWidth();
unsigned howlong = time ? pb_width*elapsed/time : 0; unsigned howlong = time ? pb_width*elapsed/time : 0;
if (Config.progressbar_boldness) if (Config.progressbar_boldness)
*wFooter << fmtBold; *wFooter << NC::fmtBold;
*wFooter << Config.progressbar_color; *wFooter << Config.progressbar_color;
if (Config.progressbar[2] != '\0') if (Config.progressbar[2] != '\0')
{ {
@@ -672,11 +672,11 @@ void DrawProgressbar(unsigned elapsed, unsigned time)
*wFooter << Config.progressbar[0]; *wFooter << Config.progressbar[0];
if (howlong < wFooter->GetWidth()) if (howlong < wFooter->GetWidth())
*wFooter << Config.progressbar[1]; *wFooter << Config.progressbar[1];
*wFooter << clEnd; *wFooter << NC::clEnd;
} }
*wFooter << clEnd; *wFooter << NC::clEnd;
if (Config.progressbar_boldness) if (Config.progressbar_boldness)
*wFooter << fmtBoldEnd; *wFooter << NC::fmtBoldEnd;
} }
void ShowMessage(const char *format, ...) void ShowMessage(const char *format, ...)
@@ -690,7 +690,7 @@ void ShowMessage(const char *format, ...)
else else
block_progressbar_update = 1; block_progressbar_update = 1;
wFooter->GotoXY(0, Config.statusbar_visibility); wFooter->GotoXY(0, Config.statusbar_visibility);
*wFooter << fmtBoldEnd; *wFooter << NC::fmtBoldEnd;
va_list list; va_list list;
va_start(list, format); va_start(list, format);
wmove(wFooter->Raw(), Config.statusbar_visibility, 0); wmove(wFooter->Raw(), Config.statusbar_visibility, 0);

View File

@@ -23,7 +23,6 @@
#include "interfaces.h" #include "interfaces.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "ncmpcpp.h"
#ifndef USE_PDCURSES #ifndef USE_PDCURSES
void WindowTitle(const std::string &); void WindowTitle(const std::string &);
@@ -41,7 +40,7 @@ void TraceMpdStatus();
void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *); void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *);
void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *); void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *);
Window &Statusbar(); NC::Window &Statusbar();
void DrawProgressbar(unsigned elapsed, unsigned time); void DrawProgressbar(unsigned elapsed, unsigned time);
void ShowMessage(const char *, ...) GNUC_PRINTF(1, 2); void ShowMessage(const char *, ...) GNUC_PRINTF(1, 2);

View File

@@ -26,7 +26,7 @@
#include <list> #include <list>
namespace NCurses { namespace NC {
/// Buffer template class that can store text along with its /// Buffer template class that can store text along with its
/// format attributes. The content can be easily printed to /// format attributes. The content can be easily printed to
@@ -234,8 +234,6 @@ typedef basic_buffer<char> Buffer;
/// ///
typedef basic_buffer<wchar_t> WBuffer; typedef basic_buffer<wchar_t> WBuffer;
template <typename C> basic_buffer<C>::basic_buffer(const basic_buffer &b) template <typename C> basic_buffer<C>::basic_buffer(const basic_buffer &b)
: itsString(b.itsString), itsFormat(b.itsFormat) { } : itsString(b.itsString), itsFormat(b.itsFormat) { }

View File

@@ -32,15 +32,21 @@
#include "mpegfile.h" #include "mpegfile.h"
#include "vorbisfile.h" #include "vorbisfile.h"
#include "flacfile.h" #include "flacfile.h"
#include "xiphcomment.h"
#include "fileref.h"
#include "tag.h"
#include "browser.h" #include "browser.h"
#include "charset.h" #include "charset.h"
#include "display.h" #include "display.h"
#include "global.h" #include "global.h"
#include "helpers.h"
#include "song_info.h" #include "song_info.h"
#include "playlist.h" #include "playlist.h"
#include "utility/comparators.h" #include "utility/comparators.h"
using namespace std::placeholders;
using Global::myScreen; using Global::myScreen;
using Global::MainHeight; using Global::MainHeight;
using Global::MainStartY; 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 ParseFilename(MPD::MutableSong &s, std::string mask, bool preview);
std::string SongToString(const MPD::MutableSong &s); std::string SongToString(const MPD::MutableSong &s);
bool DirEntryMatcher(const Regex &rx, const string_pair &dir, bool filter); bool DirEntryMatcher(const Regex &rx, const std::pair<std::string, std::string> &dir, bool filter);
bool AlbumEntryMatcher(const Regex &rx, const string_pair &dir); bool AlbumEntryMatcher(const Regex &rx, const std::pair<std::string, std::string> &dir);
bool SongEntryMatcher(const Regex &rx, const MPD::MutableSong &s); bool SongEntryMatcher(const Regex &rx, const MPD::MutableSong &s);
} }
@@ -94,13 +100,13 @@ void TagEditor::Init()
PatternsFile = Config.ncmpcpp_directory + "patterns.list"; PatternsFile = Config.ncmpcpp_directory + "patterns.list";
SetDimensions(0, COLS); SetDimensions(0, COLS);
Albums = new Menu<string_pair>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, brNone); Albums = new NC::Menu< std::pair<std::string, std::string> >(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Albums" : "", Config.main_color, NC::brNone);
Albums->HighlightColor(Config.active_column_color); Albums->HighlightColor(Config.active_column_color);
Albums->CyclicScrolling(Config.use_cyclic_scrolling); Albums->CyclicScrolling(Config.use_cyclic_scrolling);
Albums->CenteredCursor(Config.centered_cursor); Albums->CenteredCursor(Config.centered_cursor);
Albums->setItemDisplayer(Display::Pair<std::string, std::string>); Albums->setItemDisplayer(Display::Pair<std::string, std::string>);
Dirs = new Menu<string_pair>(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Directories" : "", Config.main_color, brNone); Dirs = new NC::Menu< std::pair<std::string, std::string> >(0, MainStartY, LeftColumnWidth, MainHeight, Config.titles_visibility ? "Directories" : "", Config.main_color, NC::brNone);
Dirs->HighlightColor(Config.active_column_color); Dirs->HighlightColor(Config.active_column_color);
Dirs->CyclicScrolling(Config.use_cyclic_scrolling); Dirs->CyclicScrolling(Config.use_cyclic_scrolling);
Dirs->CenteredCursor(Config.centered_cursor); Dirs->CenteredCursor(Config.centered_cursor);
@@ -108,7 +114,7 @@ void TagEditor::Init()
LeftColumn = Config.albums_in_tag_editor ? Albums : Dirs; LeftColumn = Config.albums_in_tag_editor ? Albums : Dirs;
TagTypes = new Menu<std::string>(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, Config.titles_visibility ? "Tag types" : "", Config.main_color, brNone); TagTypes = new NC::Menu<std::string>(MiddleColumnStartX, MainStartY, MiddleColumnWidth, MainHeight, Config.titles_visibility ? "Tag types" : "", Config.main_color, NC::brNone);
TagTypes->HighlightColor(Config.main_highlight_color); TagTypes->HighlightColor(Config.main_highlight_color);
TagTypes->CyclicScrolling(Config.use_cyclic_scrolling); TagTypes->CyclicScrolling(Config.use_cyclic_scrolling);
TagTypes->CenteredCursor(Config.centered_cursor); TagTypes->CenteredCursor(Config.centered_cursor);
@@ -128,7 +134,7 @@ void TagEditor::Init()
TagTypes->AddItem("Reset"); TagTypes->AddItem("Reset");
TagTypes->AddItem("Save"); TagTypes->AddItem("Save");
Tags = new Menu<MPD::MutableSong>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Tags" : "", Config.main_color, brNone); Tags = new NC::Menu<MPD::MutableSong>(RightColumnStartX, MainStartY, RightColumnWidth, MainHeight, Config.titles_visibility ? "Tags" : "", Config.main_color, NC::brNone);
Tags->HighlightColor(Config.main_highlight_color); Tags->HighlightColor(Config.main_highlight_color);
Tags->CyclicScrolling(Config.use_cyclic_scrolling); Tags->CyclicScrolling(Config.use_cyclic_scrolling);
Tags->CenteredCursor(Config.centered_cursor); Tags->CenteredCursor(Config.centered_cursor);
@@ -136,7 +142,7 @@ void TagEditor::Init()
Tags->SetSelectSuffix(Config.selected_item_suffix); Tags->SetSelectSuffix(Config.selected_item_suffix);
Tags->setItemDisplayer(Display::Tags); Tags->setItemDisplayer(Display::Tags);
FParserDialog = new Menu<std::string>((COLS-FParserDialogWidth)/2, (MainHeight-FParserDialogHeight)/2+MainStartY, FParserDialogWidth, FParserDialogHeight, "", Config.main_color, Config.window_border); FParserDialog = new NC::Menu<std::string>((COLS-FParserDialogWidth)/2, (MainHeight-FParserDialogHeight)/2+MainStartY, FParserDialogWidth, FParserDialogHeight, "", Config.main_color, Config.window_border);
FParserDialog->CyclicScrolling(Config.use_cyclic_scrolling); FParserDialog->CyclicScrolling(Config.use_cyclic_scrolling);
FParserDialog->CenteredCursor(Config.centered_cursor); FParserDialog->CenteredCursor(Config.centered_cursor);
FParserDialog->setItemDisplayer(Display::Default<std::string>); FParserDialog->setItemDisplayer(Display::Default<std::string>);
@@ -145,14 +151,14 @@ void TagEditor::Init()
FParserDialog->AddSeparator(); FParserDialog->AddSeparator();
FParserDialog->AddItem("Cancel"); FParserDialog->AddItem("Cancel");
FParser = new Menu<std::string>((COLS-FParserWidth)/2, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthOne, FParserHeight, "_", Config.main_color, Config.active_window_border); FParser = new NC::Menu<std::string>((COLS-FParserWidth)/2, (MainHeight-FParserHeight)/2+MainStartY, FParserWidthOne, FParserHeight, "_", Config.main_color, Config.active_window_border);
FParser->CyclicScrolling(Config.use_cyclic_scrolling); FParser->CyclicScrolling(Config.use_cyclic_scrolling);
FParser->CenteredCursor(Config.centered_cursor); FParser->CenteredCursor(Config.centered_cursor);
FParser->setItemDisplayer(Display::Default<std::string>); FParser->setItemDisplayer(Display::Default<std::string>);
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; w = LeftColumn;
isInitialized = 1; isInitialized = 1;
@@ -261,7 +267,7 @@ void TagEditor::Update()
Tags->Clear(); Tags->Clear();
if (Config.albums_in_tag_editor) if (Config.albums_in_tag_editor)
{ {
*Albums << XY(0, 0) << "Fetching albums..."; *Albums << NC::XY(0, 0) << "Fetching albums...";
Albums->Window::Refresh(); Albums->Window::Refresh();
Mpd.BlockIdle(true); // for the same reason as in media library Mpd.BlockIdle(true); // for the same reason as in media library
auto albums = Mpd.GetList(MPD_TAG_ALBUM); auto albums = Mpd.GetList(MPD_TAG_ALBUM);
@@ -382,9 +388,9 @@ void TagEditor::EnterPressed()
*FParserLegend << U("%p - performer\n"); *FParserLegend << U("%p - performer\n");
*FParserLegend << U("%d - disc\n"); *FParserLegend << U("%d - disc\n");
*FParserLegend << U("%C - comment\n\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) 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(); FParserLegend->Flush();
if (!Patterns.empty()) if (!Patterns.empty())
@@ -445,7 +451,7 @@ void TagEditor::EnterPressed()
{ {
if (FParserUsePreview) 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'; *FParserPreview << ParseFilename(s, Config.pattern, FParserUsePreview) << '\n';
} }
else else
@@ -465,9 +471,9 @@ void TagEditor::EnterPressed()
} }
if (!FParserUsePreview) if (!FParserUsePreview)
s.setNewURI(new_file + extension); s.setNewURI(new_file + extension);
*FParserPreview << file << Config.color2 << U(" -> ") << clEnd; *FParserPreview << file << Config.color2 << U(" -> ") << NC::clEnd;
if (new_file.empty()) if (new_file.empty())
*FParserPreview << Config.empty_tags_color << Config.empty_tag << clEnd; *FParserPreview << Config.empty_tags_color << Config.empty_tag << NC::clEnd;
else else
*FParserPreview << new_file << extension; *FParserPreview << new_file << extension;
*FParserPreview << '\n' << '\n'; *FParserPreview << '\n' << '\n';
@@ -558,7 +564,7 @@ void TagEditor::EnterPressed()
if (id > 0 && w == TagTypes) if (id > 0 && w == TagTypes)
{ {
LockStatusbar(); 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)); std::string new_tag = wFooter->GetString(Tags->Current().value().getTags(get));
UnlockStatusbar(); UnlockStatusbar();
for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it) for (auto it = EditedSongs.begin(); it != EditedSongs.end(); ++it)
@@ -567,12 +573,12 @@ void TagEditor::EnterPressed()
else if (w == Tags) else if (w == Tags)
{ {
LockStatusbar(); 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)); std::string new_tag = wFooter->GetString(Tags->Current().value().getTags(get));
UnlockStatusbar(); UnlockStatusbar();
if (new_tag != Tags->Current().value().getTags(get)) if (new_tag != Tags->Current().value().getTags(get))
Tags->Current().value().setTag(set, new_tag); Tags->Current().value().setTag(set, new_tag);
Tags->Scroll(wDown); Tags->Scroll(NC::wDown);
} }
} }
else else
@@ -597,12 +603,12 @@ void TagEditor::EnterPressed()
std::string extension = old_name.substr(last_dot); std::string extension = old_name.substr(last_dot);
old_name = old_name.substr(0, last_dot); old_name = old_name.substr(0, last_dot);
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "New filename: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "New filename: " << NC::fmtBoldEnd;
std::string new_name = wFooter->GetString(old_name); std::string new_name = wFooter->GetString(old_name);
UnlockStatusbar(); UnlockStatusbar();
if (!new_name.empty() && new_name != old_name) if (!new_name.empty() && new_name != old_name)
s.setNewURI(new_name + extension); s.setNewURI(new_name + extension);
Tags->Scroll(wDown); Tags->Scroll(NC::wDown);
} }
} }
else if (id == 16) // capitalize first letters else if (id == 16) // capitalize first letters
@@ -660,7 +666,7 @@ void TagEditor::SpacePressed()
if (w == Tags && !Tags->Empty()) if (w == Tags && !Tags->Empty())
{ {
Tags->Current().setSelected(!Tags->Current().isSelected()); Tags->Current().setSelected(!Tags->Current().isSelected());
w->Scroll(wDown); w->Scroll(NC::wDown);
return; return;
} }
if (w != LeftColumn) if (w != LeftColumn)
@@ -686,7 +692,7 @@ void TagEditor::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
} }
else if (w == FParser || w == FParserHelper) else if (w == FParser || w == FParserHelper)
@@ -702,13 +708,13 @@ void TagEditor::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
else if (FParserHelper->hasCoords(me.x, me.y)) else if (FParserHelper->hasCoords(me.x, me.y))
{ {
if (w != FParserHelper) if (w != FParserHelper)
NextColumn(); NextColumn();
reinterpret_cast<Screen<Scrollpad> *>(this)->Screen<Scrollpad>::MouseButtonPressed(me); ScrollpadMouseButtonPressed(FParserHelper, me);
} }
} }
else if (!LeftColumn->Empty() && LeftColumn->hasCoords(me.x, me.y)) else if (!LeftColumn->Empty() && LeftColumn->hasCoords(me.x, me.y))
@@ -727,7 +733,7 @@ void TagEditor::MouseButtonPressed(MEVENT me)
SpacePressed(); SpacePressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
Tags->Clear(); Tags->Clear();
} }
else if (!TagTypes->Empty() && TagTypes->hasCoords(me.x, me.y)) else if (!TagTypes->Empty() && TagTypes->hasCoords(me.x, me.y))
@@ -744,7 +750,7 @@ void TagEditor::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
else if (!Tags->Empty() && Tags->hasCoords(me.x, me.y)) else if (!Tags->Empty() && Tags->hasCoords(me.x, me.y))
{ {
@@ -761,7 +767,7 @@ void TagEditor::MouseButtonPressed(MEVENT me)
EnterPressed(); EnterPressed();
} }
else else
Screen<Window>::MouseButtonPressed(me); Screen<NC::Window>::MouseButtonPressed(me);
} }
} }
@@ -771,9 +777,9 @@ std::string TagEditor::currentFilter()
{ {
std::string filter; std::string filter;
if (w == Dirs) if (w == Dirs)
filter = RegexFilter<string_pair>::currentFilter(*Dirs); filter = RegexFilter< std::pair<std::string, std::string> >::currentFilter(*Dirs);
else if (w == Albums) else if (w == Albums)
filter = RegexFilter<string_pair>::currentFilter(*Albums); filter = RegexFilter< std::pair<std::string, std::string> >::currentFilter(*Albums);
else if (w == Tags) else if (w == Tags)
filter = RegexFilter<MPD::MutableSong>::currentFilter(*Tags); filter = RegexFilter<MPD::MutableSong>::currentFilter(*Tags);
return filter; return filter;
@@ -785,13 +791,13 @@ void TagEditor::applyFilter(const std::string &filter)
{ {
Dirs->ShowAll(); Dirs->ShowAll();
auto fun = std::bind(DirEntryMatcher, _1, _2, true); auto fun = std::bind(DirEntryMatcher, _1, _2, true);
auto rx = RegexFilter<string_pair>(filter, Config.regex_type, fun); auto rx = RegexFilter< std::pair<std::string, std::string> >(filter, Config.regex_type, fun);
Dirs->filter(Dirs->Begin(), Dirs->End(), rx); Dirs->filter(Dirs->Begin(), Dirs->End(), rx);
} }
else if (w == Albums) else if (w == Albums)
{ {
Albums->ShowAll(); Albums->ShowAll();
auto rx = RegexFilter<string_pair>(filter, Config.regex_type, AlbumEntryMatcher); auto rx = RegexFilter< std::pair<std::string, std::string> >(filter, Config.regex_type, AlbumEntryMatcher);
Albums->filter(Albums->Begin(), Albums->End(), rx); Albums->filter(Albums->Begin(), Albums->End(), rx);
} }
else if (w == Tags) else if (w == Tags)
@@ -810,12 +816,12 @@ bool TagEditor::search(const std::string &constraint)
if (w == Dirs) if (w == Dirs)
{ {
auto fun = std::bind(DirEntryMatcher, _1, _2, false); auto fun = std::bind(DirEntryMatcher, _1, _2, false);
auto rx = RegexFilter<string_pair>(constraint, Config.regex_type, fun); auto rx = RegexFilter< std::pair<std::string, std::string> >(constraint, Config.regex_type, fun);
result = Dirs->search(Dirs->Begin(), Dirs->End(), rx); result = Dirs->search(Dirs->Begin(), Dirs->End(), rx);
} }
else if (w == Albums) else if (w == Albums)
{ {
auto rx = RegexFilter<string_pair>(constraint, Config.regex_type, AlbumEntryMatcher); auto rx = RegexFilter< std::pair<std::string, std::string> >(constraint, Config.regex_type, AlbumEntryMatcher);
result = Albums->search(Albums->Begin(), Albums->End(), rx); result = Albums->search(Albums->Begin(), Albums->End(), rx);
} }
else if (w == Tags) else if (w == Tags)
@@ -898,7 +904,7 @@ MPD::SongList TagEditor::getSelectedSongs()
/***********************************************************************/ /***********************************************************************/
List *TagEditor::GetList() NC::List *TagEditor::GetList()
{ {
if (w == LeftColumn) if (w == LeftColumn)
return LeftColumn; return LeftColumn;
@@ -1392,14 +1398,14 @@ std::string SongToString(const MPD::MutableSong &s)
return result.empty() ? Config.empty_tag : result; 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<std::string, std::string> &dir, bool filter)
{ {
if (dir.first == "." || dir.first == "..") if (dir.first == "." || dir.first == "..")
return filter; return filter;
return rx.match(dir.first); return rx.match(dir.first);
} }
bool AlbumEntryMatcher(const Regex &rx, const string_pair &dir) bool AlbumEntryMatcher(const Regex &rx, const std::pair<std::string, std::string> &dir)
{ {
return rx.match(dir.first); return rx.match(dir.first);
} }

View File

@@ -27,17 +27,13 @@
#include <list> #include <list>
// taglib headers #include "interfaces.h"
#include "xiphcomment.h"
#include "fileref.h"
#include "tag.h"
#include "mpdpp.h" #include "mpdpp.h"
#include "mutable_song.h" #include "mutable_song.h"
#include "regex_filter.h" #include "regex_filter.h"
#include "screen.h" #include "screen.h"
class TagEditor : public Screen<Window>, public Filterable, public HasSongs, public Searchable class TagEditor : public Screen<NC::Window>, public Filterable, public HasSongs, public Searchable
{ {
public: public:
TagEditor() : FParser(0), FParserHelper(0), FParserLegend(0), FParserPreview(0), itsBrowsedDir("/") { } TagEditor() : FParser(0), FParserHelper(0), FParserLegend(0), FParserPreview(0), itsBrowsedDir("/") { }
@@ -73,7 +69,7 @@ class TagEditor : public Screen<Window>, public Filterable, public HasSongs, pub
virtual void removeSelection(); virtual void removeSelection();
virtual MPD::SongList getSelectedSongs(); virtual MPD::SongList getSelectedSongs();
virtual List *GetList(); virtual NC::List *GetList();
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }
@@ -84,11 +80,11 @@ class TagEditor : public Screen<Window>, public Filterable, public HasSongs, pub
void LocateSong(const MPD::Song &s); void LocateSong(const MPD::Song &s);
Menu<string_pair> *LeftColumn; NC::Menu< std::pair<std::string, std::string> > *LeftColumn;
Menu<string_pair> *Albums; NC::Menu< std::pair<std::string, std::string> > *Albums;
Menu<string_pair> *Dirs; NC::Menu< std::pair<std::string, std::string> > *Dirs;
Menu<std::string> *TagTypes; NC::Menu<std::string> *TagTypes;
Menu<MPD::MutableSong> *Tags; NC::Menu<MPD::MutableSong> *Tags;
/// NOTICE: this string is always in utf8, no need to convert it /// NOTICE: this string is always in utf8, no need to convert it
const std::string &CurrentDir() { return itsBrowsedDir; } const std::string &CurrentDir() { return itsBrowsedDir; }
@@ -104,11 +100,11 @@ class TagEditor : public Screen<Window>, public Filterable, public HasSongs, pub
void SetDimensions(size_t, size_t); void SetDimensions(size_t, size_t);
std::vector<MPD::MutableSong *> EditedSongs; std::vector<MPD::MutableSong *> EditedSongs;
Menu<std::string> *FParserDialog; NC::Menu<std::string> *FParserDialog;
Menu<std::string> *FParser; NC::Menu<std::string> *FParser;
Scrollpad *FParserHelper; NC::Scrollpad *FParserHelper;
Scrollpad *FParserLegend; NC::Scrollpad *FParserLegend;
Scrollpad *FParserPreview; NC::Scrollpad *FParserPreview;
bool FParserUsePreview; bool FParserUsePreview;
std::string itsBrowsedDir; std::string itsBrowsedDir;

View File

@@ -26,10 +26,12 @@
#include "mpegfile.h" #include "mpegfile.h"
#include "vorbisfile.h" #include "vorbisfile.h"
#include "flacfile.h" #include "flacfile.h"
#include "fileref.h"
#include "browser.h" #include "browser.h"
#include "charset.h" #include "charset.h"
#include "display.h" #include "display.h"
#include "helpers.h"
#include "global.h" #include "global.h"
#include "song_info.h" #include "song_info.h"
#include "playlist.h" #include "playlist.h"
@@ -44,11 +46,11 @@ TinyTagEditor *myTinyTagEditor = new TinyTagEditor;
void TinyTagEditor::Init() void TinyTagEditor::Init()
{ {
w = new Menu<Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, brNone); w = new NC::Menu<NC::Buffer>(0, MainStartY, COLS, MainHeight, "", Config.main_color, NC::brNone);
w->HighlightColor(Config.main_highlight_color); w->HighlightColor(Config.main_highlight_color);
w->CyclicScrolling(Config.use_cyclic_scrolling); w->CyclicScrolling(Config.use_cyclic_scrolling);
w->CenteredCursor(Config.centered_cursor); w->CenteredCursor(Config.centered_cursor);
w->setItemDisplayer(Display::Default<Buffer>); w->setItemDisplayer(Display::Default<NC::Buffer>);
isInitialized = 1; isInitialized = 1;
} }
@@ -108,15 +110,15 @@ void TinyTagEditor::EnterPressed()
if (option < 19) // separator after comment if (option < 19) // separator after comment
{ {
size_t pos = option-8; 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))); itsEdited.setTag(SongInfo::Tags[pos].Set, Global::wFooter->GetString(itsEdited.getTags(SongInfo::Tags[pos].Get)));
w->at(option).value().Clear(); 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)); ShowTag(w->at(option).value(), itsEdited.getTags(SongInfo::Tags[pos].Get));
} }
else if (option == 20) else if (option == 20)
{ {
Statusbar() << fmtBold << "Filename: " << fmtBoldEnd; Statusbar() << NC::fmtBold << "Filename: " << NC::fmtBoldEnd;
std::string filename = itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI(); std::string filename = itsEdited.getNewURI().empty() ? itsEdited.getName() : itsEdited.getNewURI();
size_t dot = filename.rfind("."); size_t dot = filename.rfind(".");
std::string extension = filename.substr(dot); std::string extension = filename.substr(dot);
@@ -124,7 +126,7 @@ void TinyTagEditor::EnterPressed()
std::string new_name = Global::wFooter->GetString(filename); std::string new_name = Global::wFooter->GetString(filename);
itsEdited.setNewURI(new_name + extension); itsEdited.setNewURI(new_name + extension);
w->at(option).value().Clear(); 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(); UnlockStatusbar();
@@ -166,7 +168,7 @@ void TinyTagEditor::MouseButtonPressed(MEVENT me)
} }
} }
else else
Screen< Menu<Buffer> >::MouseButtonPressed(me); Screen< NC::Menu<NC::Buffer> >::MouseButtonPressed(me);
} }
void TinyTagEditor::SetEdited(const MPD::Song &s) void TinyTagEditor::SetEdited(const MPD::Song &s)
@@ -214,23 +216,23 @@ bool TinyTagEditor::getTags()
w->Highlight(8); w->Highlight(8);
w->at(0).value() << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << itsEdited.getName() << clEnd; w->at(0).value() << NC::fmtBold << Config.color1 << "Song name: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getName() << NC::clEnd;
w->at(1).value() << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2; w->at(1).value() << NC::fmtBold << Config.color1 << "Location in DB: " << NC::fmtBoldEnd << Config.color2;
ShowTag(w->at(1).value(), itsEdited.getDirectory()); ShowTag(w->at(1).value(), itsEdited.getDirectory());
w->at(1).value() << clEnd; w->at(1).value() << NC::clEnd;
w->at(3).value() << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << itsEdited.getLength() << clEnd; w->at(3).value() << NC::fmtBold << Config.color1 << "Length: " << NC::fmtBoldEnd << Config.color2 << itsEdited.getLength() << NC::clEnd;
w->at(4).value() << fmtBold << Config.color1 << "Bitrate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << clEnd; w->at(4).value() << NC::fmtBold << Config.color1 << "Bitrate: " << NC::fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << NC::clEnd;
w->at(5).value() << fmtBold << Config.color1 << "Sample rate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << 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() << fmtBold << Config.color1 << "Channels: " << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << clDefault; w->at(6).value() << NC::fmtBold << Config.color1 << "Channels: " << NC::fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << NC::clDefault;
unsigned pos = 8; unsigned pos = 8;
for (const SongInfo::Metadata *m = SongInfo::Tags; m->Name; ++m, ++pos) 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)); 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(22).value() << "Save";
w->at(23).value() << "Cancel"; w->at(23).value() << "Cancel";

View File

@@ -31,7 +31,7 @@
#include "mutable_song.h" #include "mutable_song.h"
#include "screen.h" #include "screen.h"
class TinyTagEditor : public Screen< Menu<Buffer> > class TinyTagEditor : public Screen< NC::Menu<NC::Buffer> >
{ {
public: public:
virtual void Resize(); virtual void Resize();
@@ -45,7 +45,7 @@ class TinyTagEditor : public Screen< Menu<Buffer> >
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }
virtual List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool isMergable() { return true; } virtual bool isMergable() { return true; }

View File

@@ -22,8 +22,6 @@
#ifdef ENABLE_VISUALIZER #ifdef ENABLE_VISUALIZER
#include "global.h"
#include <cerrno> #include <cerrno>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
@@ -33,6 +31,10 @@
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include "global.h"
#include "settings.h"
#include "status.h"
using Global::MainStartY; using Global::MainStartY;
using Global::MainHeight; using Global::MainHeight;
@@ -42,7 +44,7 @@ const int Visualizer::WindowTimeout = 1000/25; /* 25 fps */
void Visualizer::Init() 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(); ResetFD();
itsSamples = Config.visualizer_in_stereo ? 4096 : 2048; 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 /= samples_per_col;
point_pos /= std::numeric_limits<int16_t>::max(); point_pos /= std::numeric_limits<int16_t>::max();
point_pos *= half_height; 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 (i && abs(prev_point_pos-point_pos) > 2)
{ {
// if gap is too big. intermediate values are needed // 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 breakpoint = std::max(prev_point_pos, point_pos);
const int half = (prev_point_pos+point_pos)/2; const int half = (prev_point_pos+point_pos)/2;
for (int k = std::min(prev_point_pos, point_pos)+1; k < breakpoint; k += 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; 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 start_y = y_offset > 0 ? y_offset : height-bar_height;
const size_t stop_y = std::min(bar_height+start_y, w->GetHeight()); const size_t stop_y = std::min(bar_height+start_y, w->GetHeight());
for (size_t j = start_y; j < stop_y; ++j) 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 #endif // HAVE_FFTW3_H

View File

@@ -21,9 +21,7 @@
#ifndef _VISUALIZER_H #ifndef _VISUALIZER_H
#define _VISUALIZER_H #define _VISUALIZER_H
#ifdef HAVE_CONFIG_H #include "config.h"
#include <config.h>
#endif
#ifdef ENABLE_VISUALIZER #ifdef ENABLE_VISUALIZER
@@ -34,7 +32,7 @@
# include <fftw3.h> # include <fftw3.h>
#endif #endif
class Visualizer : public Screen<Window> class Visualizer : public Screen<NC::Window>
{ {
public: public:
virtual void SwitchTo(); virtual void SwitchTo();
@@ -43,14 +41,14 @@ class Visualizer : public Screen<Window>
virtual std::basic_string<my_char_t> Title(); virtual std::basic_string<my_char_t> Title();
virtual void Update(); virtual void Update();
virtual void Scroll(Where) { } virtual void Scroll(NC::Where) { }
virtual void EnterPressed() { } virtual void EnterPressed() { }
virtual void SpacePressed(); virtual void SpacePressed();
virtual void MouseButtonPressed(MEVENT) { } virtual void MouseButtonPressed(MEVENT) { }
virtual bool isTabbable() { return true; } virtual bool isTabbable() { return true; }
virtual NCurses::List *GetList() { return 0; } virtual NC::List *GetList() { return 0; }
virtual bool allowsSelection() { return false; } virtual bool allowsSelection() { return false; }

View File

@@ -32,9 +32,9 @@
#include "utility/string.h" #include "utility/string.h"
#include "window.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[] = const int ColorsTable[] =
{ {
@@ -65,7 +65,7 @@ void NCurses::InitScreen(GNUC_UNUSED const char *window_title, bool enable_color
curs_set(0); curs_set(0);
} }
void NCurses::DestroyScreen() void DestroyScreen()
{ {
curs_set(1); curs_set(1);
endwin(); endwin();
@@ -919,7 +919,7 @@ size_t Window::Length(const std::wstring &ws)
# endif // WIN32 # 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; size_t i = 0;
int remained_len = max_len; int remained_len = max_len;
@@ -933,3 +933,5 @@ void Window::Cut (std::wstring &ws, size_t max_len)
} }
} }
} }
}

View File

@@ -118,10 +118,10 @@
# define wcwidth(x) int(!iscntrl(x)) # define wcwidth(x) int(!iscntrl(x))
#endif #endif
/// NCurses namespace provides set of easy-to-use /// NC namespace provides set of easy-to-use
/// wrappers over original curses library /// wrappers over original curses library
/// ///
namespace NCurses namespace NC
{ {
/// Colors used by NCurses /// Colors used by NCurses
/// ///