change namespace Browser into class

This commit is contained in:
Andrzej Rybczak
2009-02-14 00:43:58 +01:00
parent 6e167d67e2
commit 8653232a2a
14 changed files with 248 additions and 217 deletions

View File

@@ -38,21 +38,21 @@ using namespace Global;
using namespace MPD; using namespace MPD;
using std::string; using std::string;
Menu<Item> *Global::mBrowser; Browser *myBrowser = new Browser;
void Browser::Init() void Browser::Init()
{ {
mBrowser = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone); w = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
mBrowser->HighlightColor(Config.main_highlight_color); w->HighlightColor(Config.main_highlight_color);
mBrowser->SetTimeout(ncmpcpp_window_timeout); w->SetTimeout(ncmpcpp_window_timeout);
mBrowser->SetSelectPrefix(&Config.selected_item_prefix); w->SetSelectPrefix(&Config.selected_item_prefix);
mBrowser->SetSelectSuffix(&Config.selected_item_suffix); w->SetSelectSuffix(&Config.selected_item_suffix);
mBrowser->SetItemDisplayer(Display::Items); w->SetItemDisplayer(Display::Items);
} }
void Browser::Resize() void Browser::Resize()
{ {
mBrowser->Resize(COLS, main_height); w->Resize(COLS, main_height);
} }
void Browser::SwitchTo() void Browser::SwitchTo()
@@ -64,8 +64,8 @@ void Browser::SwitchTo()
) )
{ {
CLEAR_FIND_HISTORY; CLEAR_FIND_HISTORY;
mBrowser->Empty() ? GetDirectory(browsed_dir) : UpdateItemList(mBrowser); w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList();
wCurrent = mBrowser; wCurrent = w;
wCurrent->Hide(); wCurrent->Hide();
current_screen = csBrowser; current_screen = csBrowser;
// redraw_screen = 1; // redraw_screen = 1;
@@ -73,28 +73,35 @@ void Browser::SwitchTo()
} }
} }
std::string Browser::Title()
{
string result = "Browse: ";
result += TO_STRING(Scroller(itsBrowsedDir, COLS-volume_state.length(), itsScrollBeginning));
return result;
}
void Browser::EnterPressed() void Browser::EnterPressed()
{ {
if (mBrowser->Empty()) if (w->Empty())
return; return;
const Item &item = mBrowser->Current(); const Item &item = w->Current();
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
{ {
CLEAR_FIND_HISTORY; CLEAR_FIND_HISTORY;
GetDirectory(item.name, browsed_dir); GetDirectory(item.name, itsBrowsedDir);
redraw_header = 1; redraw_header = 1;
break; break;
} }
case itSong: case itSong:
{ {
block_item_list_update = 1; block_item_list_update = 1;
if (Config.ncmpc_like_songs_adding && mBrowser->isBold()) if (Config.ncmpc_like_songs_adding && w->isBold())
{ {
bool found = 0; bool found = 0;
long long hash = mBrowser->Current().song->GetHash(); long long hash = w->Current().song->GetHash();
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++) for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
{ {
if (myPlaylist->Main()->at(i).GetHash() == hash) if (myPlaylist->Main()->at(i).GetHash() == hash)
@@ -113,7 +120,7 @@ void Browser::EnterPressed()
{ {
Mpd->PlayID(id); Mpd->PlayID(id);
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
mBrowser->BoldOption(mBrowser->Choice(), 1); w->BoldOption(w->Choice(), 1);
} }
break; break;
} }
@@ -140,15 +147,15 @@ void Browser::EnterPressed()
void Browser::SpacePressed() void Browser::SpacePressed()
{ {
if (mBrowser->Empty()) if (w->Empty())
return; return;
const Item &item = mBrowser->Current(); const Item &item = w->Current();
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
{ {
if (browsed_dir != "/" && !mBrowser->Choice()) if (itsBrowsedDir != "/" && !w->Choice())
break; // do not let add parent dir. break; // do not let add parent dir.
if (Config.local_browser) if (Config.local_browser)
@@ -175,10 +182,10 @@ void Browser::SpacePressed()
case itSong: case itSong:
{ {
block_item_list_update = 1; block_item_list_update = 1;
if (Config.ncmpc_like_songs_adding && mBrowser->isBold()) if (Config.ncmpc_like_songs_adding && w->isBold())
{ {
block_playlist_update = 1; block_playlist_update = 1;
long long hash = mBrowser->Current().song->GetHash(); long long hash = w->Current().song->GetHash();
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++) for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
{ {
if (myPlaylist->Main()->at(i).GetHash() == hash) if (myPlaylist->Main()->at(i).GetHash() == hash)
@@ -189,7 +196,7 @@ void Browser::SpacePressed()
} }
} }
Mpd->CommitQueue(); Mpd->CommitQueue();
mBrowser->BoldOption(mBrowser->Choice(), 0); w->BoldOption(w->Choice(), 0);
} }
else else
{ {
@@ -197,7 +204,7 @@ void Browser::SpacePressed()
if (Mpd->AddSong(s) != -1) if (Mpd->AddSong(s) != -1)
{ {
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str()); ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
mBrowser->BoldOption(mBrowser->Choice(), 1); w->BoldOption(w->Choice(), 1);
} }
} }
break; break;
@@ -219,7 +226,7 @@ void Browser::SpacePressed()
break; break;
} }
} }
mBrowser->Scroll(wDown); w->Scroll(wDown);
} }
namespace namespace
@@ -282,46 +289,24 @@ namespace
} }
} }
void UpdateItemList(Menu<Item> *menu) void Browser::GetDirectory(string dir, string subdir)
{
bool bold = 0;
for (size_t i = 0; i < menu->Size(); i++)
{
if (menu->at(i).type == itSong)
{
for (size_t j = 0; j < myPlaylist->Main()->Size(); j++)
{
if (myPlaylist->Main()->at(j).GetHash() == menu->at(i).song->GetHash())
{
bold = 1;
break;
}
}
menu->BoldOption(i, bold);
bold = 0;
}
}
menu->Refresh();
}
void GetDirectory(string dir, string subdir)
{ {
if (dir.empty()) if (dir.empty())
dir = "/"; dir = "/";
int highlightme = -1; int highlightme = -1;
browsed_dir_scroll_begin = 0; itsScrollBeginning = 0;
if (browsed_dir != dir) if (itsBrowsedDir != dir)
mBrowser->Reset(); w->Reset();
browsed_dir = dir; itsBrowsedDir = dir;
locale_to_utf(dir); locale_to_utf(dir);
for (size_t i = 0; i < mBrowser->Size(); i++) for (size_t i = 0; i < w->Size(); i++)
if (mBrowser->at(i).type == itSong) if (w->at(i).type == itSong)
delete mBrowser->at(i).song; delete w->at(i).song;
mBrowser->Clear(0); w->Clear(0);
if (dir != "/") if (dir != "/")
{ {
@@ -330,7 +315,7 @@ void GetDirectory(string dir, string subdir)
parent.song = (Song *) 1; // in that way we assume that's really parent dir parent.song = (Song *) 1; // in that way we assume that's really parent dir
parent.name = slash != string::npos ? dir.substr(0, slash) : "/"; parent.name = slash != string::npos ? dir.substr(0, slash) : "/";
parent.type = itDirectory; parent.type = itDirectory;
mBrowser->AddOption(parent); w->AddOption(parent);
} }
ItemList list; ItemList list;
@@ -344,15 +329,15 @@ void GetDirectory(string dir, string subdir)
case itPlaylist: case itPlaylist:
{ {
utf_to_locale(it->name); utf_to_locale(it->name);
mBrowser->AddOption(*it); w->AddOption(*it);
break; break;
} }
case itDirectory: case itDirectory:
{ {
utf_to_locale(it->name); utf_to_locale(it->name);
if (it->name == subdir) if (it->name == subdir)
highlightme = mBrowser->Size(); highlightme = w->Size();
mBrowser->AddOption(*it); w->AddOption(*it);
break; break;
} }
case itSong: case itSong:
@@ -366,14 +351,49 @@ void GetDirectory(string dir, string subdir)
break; break;
} }
} }
mBrowser->AddOption(*it, bold); w->AddOption(*it, bold);
break; break;
} }
} }
} }
if (highlightme >= 0) if (highlightme >= 0)
mBrowser->Highlight(highlightme); w->Highlight(highlightme);
if (current_screen == csBrowser) if (current_screen == csBrowser)
mBrowser->Hide(); w->Hide();
}
void Browser::ChangeBrowseMode()
{
if (Mpd->GetHostname()[0] != '/')
return;
Config.local_browser = !Config.local_browser;
ShowMessage("Browse mode: %s", Config.local_browser ? "Local filesystem" : "MPD music dir");
itsBrowsedDir = Config.local_browser ? home_folder : "/";
w->Reset();
GetDirectory(itsBrowsedDir);
redraw_header = 1;
}
void Browser::UpdateItemList()
{
bool bold = 0;
for (size_t i = 0; i < w->Size(); i++)
{
if (w->at(i).type == itSong)
{
for (size_t j = 0; j < myPlaylist->Main()->Size(); j++)
{
if (myPlaylist->Main()->at(j).GetHash() == w->at(i).song->GetHash())
{
bold = 1;
break;
}
}
w->BoldOption(i, bold);
bold = 0;
}
}
w->Refresh();
} }

View File

@@ -23,20 +23,35 @@
#include "mpdpp.h" #include "mpdpp.h"
#include "ncmpcpp.h" #include "ncmpcpp.h"
#include "screen.h"
namespace Browser class Browser : public Screen< Menu<MPD::Item> >
{ {
void Init(); public:
void Resize(); Browser() : itsScrollBeginning(0), itsBrowsedDir("/") { }
void SwitchTo();
virtual void Init();
virtual void Resize();
virtual void SwitchTo();
virtual std::string Title();
virtual void EnterPressed();
virtual void SpacePressed();
const std::string &CurrentDir() { return itsBrowsedDir; }
void GetDirectory(std::string, std::string = "/");
void ChangeBrowseMode();
void UpdateItemList();
void EnterPressed(); protected:
void SpacePressed(); size_t itsScrollBeginning;
}
std::string itsBrowsedDir;
};
void UpdateItemList(Menu<MPD::Item> *); extern Browser *myBrowser;
void GetDirectory(std::string, std::string = "/");
#endif #endif

View File

@@ -91,61 +91,6 @@ string Display::Columns(string st)
return result; return result;
} }
void Display::TotalPlaylistLength(Window &w)
{
const int MINUTE = 60;
const int HOUR = 60*MINUTE;
const int DAY = 24*HOUR;
const int YEAR = 365*DAY;
int length = 0;
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
length += myPlaylist->Main()->at(i).GetTotalLength();
w << '(' << myPlaylist->Main()->Size() << (myPlaylist->Main()->Size() == 1 ? " item" : " items");
if (length)
{
w << ", length: ";
int years = length/YEAR;
if (years)
{
w << years << (years == 1 ? " year" : " years");
length -= years*YEAR;
if (length)
w << ", ";
}
int days = length/DAY;
if (days)
{
w << days << (days == 1 ? " day" : " days");
length -= days*DAY;
if (length)
w << ", ";
}
int hours = length/HOUR;
if (hours)
{
w << hours << (hours == 1 ? " hour" : " hours");
length -= hours*HOUR;
if (length)
w << ", ";
}
int minutes = length/MINUTE;
if (minutes)
{
w << minutes << (minutes == 1 ? " minute" : " minutes");
length -= minutes*MINUTE;
if (length)
w << ", ";
}
if (length)
w << length << (length == 1 ? " second" : " seconds");
}
w << ')';
w.Refresh();
}
void Display::StringPairs(const string_pair &pair, void *, Menu<string_pair> *menu) void Display::StringPairs(const string_pair &pair, void *, Menu<string_pair> *menu)
{ {
*menu << pair.first; *menu << pair.first;

View File

@@ -34,7 +34,7 @@ namespace Display
*menu << t; *menu << t;
} }
void TotalPlaylistLength(Window &); //void TotalPlaylistLength(Window &);
void StringPairs(const string_pair &, void *, Menu<string_pair> *); void StringPairs(const string_pair &, void *, Menu<string_pair> *);

View File

@@ -36,7 +36,7 @@ namespace Global
extern Window *wPrev; extern Window *wPrev;
// extern Menu<MPD::Song> *myPlaylist->Main(); // extern Menu<MPD::Song> *myPlaylist->Main();
extern Menu<MPD::Item> *mBrowser; // extern Menu<MPD::Item> *myBrowser->Main();
extern Menu< std::pair<Buffer *, MPD::Song *> > *mSearcher; extern Menu< std::pair<Buffer *, MPD::Song *> > *mSearcher;
extern Window *wLibActiveCol; extern Window *wLibActiveCol;
@@ -73,14 +73,14 @@ namespace Global
extern int now_playing; extern int now_playing;
extern int lock_statusbar_delay; extern int lock_statusbar_delay;
extern size_t browsed_dir_scroll_begin; // extern size_t browsed_dir_scroll_begin;
extern size_t main_start_y; extern size_t main_start_y;
extern size_t main_height; extern size_t main_height;
extern size_t lyrics_scroll_begin; extern size_t lyrics_scroll_begin;
extern time_t timer; extern time_t timer;
extern std::string browsed_dir; // extern std::string browsed_dir;
extern std::string editor_browsed_dir; extern std::string editor_browsed_dir;
extern std::string editor_highlighted_dir; extern std::string editor_highlighted_dir;
extern std::string info_title; extern std::string info_title;

View File

@@ -305,8 +305,10 @@ const Buffer &ShowTag(const string &tag)
return result; return result;
} }
void Scroller(Window &w, const string &string, size_t width, size_t &pos) const std::basic_string<my_char_t> &Scroller(const string &string, size_t width, size_t &pos)
{ {
static std::basic_string<my_char_t> result;
result.clear();
std::basic_string<my_char_t> s = TO_WSTRING(string); std::basic_string<my_char_t> s = TO_WSTRING(string);
size_t len; size_t len;
# ifdef _UTF8 # ifdef _UTF8
@@ -331,7 +333,7 @@ void Scroller(Window &w, const string &string, size_t width, size_t &pos)
# else # else
len++; len++;
# endif # endif
w << *it; result += *it;
} }
if (++pos >= s.length()) if (++pos >= s.length())
pos = 0; pos = 0;
@@ -342,11 +344,12 @@ void Scroller(Window &w, const string &string, size_t width, size_t &pos)
# else # else
len++; len++;
# endif # endif
w << *b; result += *b;
} }
} }
else else
w << s; result = s;
return result;
} }
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H

View File

@@ -50,7 +50,7 @@ Window &Statusbar();
const Buffer &ShowTag(const std::string &); const Buffer &ShowTag(const std::string &);
void Scroller(Window &, const std::string &, size_t, size_t &); const std::basic_string<my_char_t> &Scroller(const std::string &, size_t, size_t &);
#ifdef HAVE_CURL_CURL_H #ifdef HAVE_CURL_CURL_H
size_t write_data(char *, size_t, size_t, std::string); size_t write_data(char *, size_t, size_t, std::string);

View File

@@ -28,6 +28,7 @@
# include "helpers.h" # include "helpers.h"
#endif #endif
#include "browser.h"
#include "charset.h" #include "charset.h"
#include "global.h" #include "global.h"
#include "media_library.h" #include "media_library.h"
@@ -94,7 +95,7 @@ void Info::GetSong()
} }
else if ( else if (
(wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty())
|| (wCurrent == mBrowser && mBrowser->Current().type == MPD::itSong) || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong)
|| (wCurrent == mSearcher && !mSearcher->Current().first) || (wCurrent == mSearcher && !mSearcher->Current().first)
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
@@ -111,7 +112,7 @@ void Info::GetSong()
s = &myPlaylist->Main()->at(id); s = &myPlaylist->Main()->at(id);
break; break;
case csBrowser: case csBrowser:
s = mBrowser->at(id).song; s = myBrowser->Main()->at(id).song;
break; break;
case csSearcher: case csSearcher:
s = mSearcher->at(id).second; s = mSearcher->at(id).second;
@@ -181,7 +182,7 @@ void Info::GetArtist()
} }
else if ( else if (
(wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty())
|| (wCurrent == mBrowser && mBrowser->Current().type == MPD::itSong) || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong)
|| (wCurrent == mSearcher && !mSearcher->Current().first) || (wCurrent == mSearcher && !mSearcher->Current().first)
|| (wCurrent == mLibArtists && !mLibArtists->Empty()) || (wCurrent == mLibArtists && !mLibArtists->Empty())
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
@@ -205,7 +206,7 @@ void Info::GetArtist()
*artist = myPlaylist->Main()->at(id).GetArtist(); *artist = myPlaylist->Main()->at(id).GetArtist();
break; break;
case csBrowser: case csBrowser:
*artist = mBrowser->at(id).song->GetArtist(); *artist = myBrowser->Main()->at(id).song->GetArtist();
break; break;
case csSearcher: case csSearcher:
*artist = mSearcher->at(id).second->GetArtist(); *artist = mSearcher->at(id).second->GetArtist();

View File

@@ -21,6 +21,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fstream> #include <fstream>
#include "browser.h"
#include "charset.h" #include "charset.h"
#include "global.h" #include "global.h"
#include "helpers.h" #include "helpers.h"
@@ -107,7 +108,7 @@ void Lyrics::Get()
else if ( else if (
reload_lyrics reload_lyrics
|| (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) || (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty())
|| (wCurrent == mBrowser && mBrowser->Current().type == MPD::itSong) || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong)
|| (wCurrent == mSearcher && !mSearcher->Current().first) || (wCurrent == mSearcher && !mSearcher->Current().first)
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
@@ -143,7 +144,7 @@ void Lyrics::Get()
s = &myPlaylist->Main()->at(id); s = &myPlaylist->Main()->at(id);
break; break;
case csBrowser: case csBrowser:
s = mBrowser->at(id).song; s = myBrowser->Main()->at(id).song;
break; break;
case csSearcher: case csSearcher:
s = mSearcher->at(id).second; s = mSearcher->at(id).second;

View File

@@ -74,14 +74,12 @@ Connection *Global::Mpd;
int Global::now_playing = -1; int Global::now_playing = -1;
int Global::lock_statusbar_delay = -1; int Global::lock_statusbar_delay = -1;
size_t Global::browsed_dir_scroll_begin = 0;
size_t Global::main_start_y; size_t Global::main_start_y;
size_t Global::main_height; size_t Global::main_height;
size_t Global::lyrics_scroll_begin = 0; size_t Global::lyrics_scroll_begin = 0;
time_t Global::timer; time_t Global::timer;
string Global::browsed_dir = "/";
string Global::editor_browsed_dir = "/"; string Global::editor_browsed_dir = "/";
string Global::editor_highlighted_dir; string Global::editor_highlighted_dir;
string Global::info_title; string Global::info_title;
@@ -151,7 +149,7 @@ int main(int argc, char *argv[])
main_height++; main_height++;
myPlaylist->Init(); myPlaylist->Init();
Browser::Init(); myBrowser->Init();
SearchEngine::Init(); SearchEngine::Init();
MediaLibrary::Init(); MediaLibrary::Init();
PlaylistEditor::Init(); PlaylistEditor::Init();
@@ -226,10 +224,10 @@ int main(int argc, char *argv[])
// header stuff // header stuff
gettimeofday(&past, 0); gettimeofday(&past, 0);
const size_t max_allowed_title_length = wHeader ? wHeader->GetWidth()-volume_state.length()-screen_title.length() : 0; const size_t max_allowed_title_length = wHeader ? wHeader->GetWidth()-volume_state.length() : 0;
if (((past.tv_sec == now.tv_sec && past.tv_usec >= now.tv_usec+500000) if (((past.tv_sec == now.tv_sec && past.tv_usec >= now.tv_usec+500000)
|| past.tv_sec > now.tv_sec) || past.tv_sec > now.tv_sec)
&& ((current_screen == csBrowser && browsed_dir.length() > max_allowed_title_length) && ((current_screen == csBrowser && myBrowser->CurrentDir().length() > max_allowed_title_length)
|| current_screen == csLyrics)) || current_screen == csLyrics))
{ {
redraw_header = 1; redraw_header = 1;
@@ -246,7 +244,7 @@ int main(int argc, char *argv[])
screen_title = myPlaylist->Title(); screen_title = myPlaylist->Title();
break; break;
case csBrowser: case csBrowser:
screen_title = "Browse: "; screen_title = myBrowser->Title();
break; break;
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
case csTinyTagEditor: case csTinyTagEditor:
@@ -284,21 +282,11 @@ int main(int argc, char *argv[])
wHeader->WriteXY(0, 0, 1, "%s", screen_title.c_str()); wHeader->WriteXY(0, 0, 1, "%s", screen_title.c_str());
wHeader->Bold(0); wHeader->Bold(0);
if (current_screen == csPlaylist) if (current_screen == csLyrics)
{
Display::TotalPlaylistLength(*wHeader);
}
else if (current_screen == csBrowser)
{
wHeader->Bold(1);
Scroller(*wHeader, browsed_dir, max_allowed_title_length, browsed_dir_scroll_begin);
wHeader->Bold(0);
}
else if (current_screen == csLyrics)
{ {
wHeader->Bold(1); wHeader->Bold(1);
Scroller(*wHeader, lyrics_song.toString("%a - %t"), max_allowed_title_length, lyrics_scroll_begin); *wHeader << Scroller(lyrics_song.toString("%a - %t"), max_allowed_title_length, lyrics_scroll_begin);
wHeader->Bold(0); wHeader->Bold(0);
} }
} }
@@ -520,7 +508,7 @@ int main(int argc, char *argv[])
Help::Resize(); Help::Resize();
myPlaylist->Resize(); myPlaylist->Resize();
Browser::Resize(); myBrowser->Resize();
SearchEngine::Resize(); SearchEngine::Resize();
MediaLibrary::Resize(); MediaLibrary::Resize();
PlaylistEditor::Resize(); PlaylistEditor::Resize();
@@ -570,10 +558,10 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.GoToParentDir)) else if (Keypressed(input, Key.GoToParentDir))
{ {
if (wCurrent == mBrowser && browsed_dir != "/") if (wCurrent == myBrowser->Main() && myBrowser->CurrentDir() != "/")
{ {
mBrowser->Reset(); myBrowser->Main()->Reset();
Browser::EnterPressed(); myBrowser->EnterPressed();
} }
} }
else if (Keypressed(input, Key.Enter)) else if (Keypressed(input, Key.Enter))
@@ -588,7 +576,7 @@ int main(int argc, char *argv[])
} }
case csBrowser: case csBrowser:
{ {
Browser::EnterPressed(); myBrowser->EnterPressed();
break; break;
} }
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
@@ -637,7 +625,7 @@ int main(int argc, char *argv[])
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
|| wCurrent == mEditorTags || wCurrent == mEditorTags
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
|| (wCurrent == mBrowser && ((Menu<Song> *)wCurrent)->Choice() >= (browsed_dir != "/" ? 1 : 0)) || (wCurrent == mSearcher && !mSearcher->Current().first) || (wCurrent == myBrowser->Main() && ((Menu<Song> *)wCurrent)->Choice() >= (myBrowser->CurrentDir() != "/" ? 1 : 0)) || (wCurrent == mSearcher && !mSearcher->Current().first)
|| wCurrent == mLibSongs || wCurrent == mLibSongs
|| wCurrent == mPlaylistEditor) || wCurrent == mPlaylistEditor)
{ {
@@ -653,7 +641,7 @@ int main(int argc, char *argv[])
{ {
if (current_screen == csBrowser) if (current_screen == csBrowser)
{ {
Browser::SpacePressed(); myBrowser->SpacePressed();
} }
else if (current_screen == csSearcher) else if (current_screen == csSearcher)
{ {
@@ -840,8 +828,8 @@ int main(int argc, char *argv[])
else if (current_screen == csBrowser || wCurrent == mPlaylistList) else if (current_screen == csBrowser || wCurrent == mPlaylistList)
{ {
LockStatusbar(); LockStatusbar();
string name = wCurrent == mBrowser ? mBrowser->Current().name : mPlaylistList->Current(); string name = wCurrent == myBrowser->Main() ? myBrowser->Main()->Current().name : mPlaylistList->Current();
if (current_screen != csBrowser || mBrowser->Current().type == itPlaylist) if (current_screen != csBrowser || myBrowser->Main()->Current().type == itPlaylist)
{ {
Statusbar() << "Delete playlist " << name << " ? [y/n] "; Statusbar() << "Delete playlist " << name << " ? [y/n] ";
curs_set(1); curs_set(1);
@@ -857,7 +845,7 @@ int main(int argc, char *argv[])
Mpd->DeletePlaylist(locale_to_utf_cpy(name)); Mpd->DeletePlaylist(locale_to_utf_cpy(name));
ShowMessage("Playlist %s deleted!", name.c_str()); ShowMessage("Playlist %s deleted!", name.c_str());
if (!Config.local_browser) if (!Config.local_browser)
GetDirectory("/"); myBrowser->GetDirectory("/");
} }
else else
ShowMessage("Aborted!"); ShowMessage("Aborted!");
@@ -960,8 +948,8 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
} }
} }
if (!Config.local_browser && browsed_dir == "/" && !mBrowser->Empty()) if (!Config.local_browser && myBrowser->CurrentDir() == "/" && !myBrowser->Main()->Empty())
GetDirectory(browsed_dir); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
else if (Keypressed(input, Key.Stop)) else if (Keypressed(input, Key.Stop))
{ {
@@ -1266,11 +1254,11 @@ int main(int argc, char *argv[])
myPlaylist->Main()->SetItemDisplayerUserData(Config.columns_in_playlist ? &Config.song_columns_list_format : &Config.song_list_format); myPlaylist->Main()->SetItemDisplayerUserData(Config.columns_in_playlist ? &Config.song_columns_list_format : &Config.song_list_format);
myPlaylist->Main()->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : ""); myPlaylist->Main()->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : "");
} }
else if (wCurrent == mBrowser) else if (wCurrent == myBrowser->Main())
{ {
Config.columns_in_browser = !Config.columns_in_browser; Config.columns_in_browser = !Config.columns_in_browser;
ShowMessage("Browser display mode: %s", Config.columns_in_browser ? "Columns" : "Classic"); ShowMessage("Browser display mode: %s", Config.columns_in_browser ? "Columns" : "Classic");
mBrowser->SetTitle(Config.columns_in_browser ? Display::Columns(Config.song_columns_list_format) : ""); myBrowser->Main()->SetTitle(Config.columns_in_browser ? Display::Columns(Config.song_columns_list_format) : "");
} }
else if (wCurrent == mSearcher) else if (wCurrent == mSearcher)
{ {
@@ -1302,7 +1290,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.UpdateDB)) else if (Keypressed(input, Key.UpdateDB))
{ {
if (current_screen == csBrowser) if (current_screen == csBrowser)
Mpd->UpdateDirectory(browsed_dir); Mpd->UpdateDirectory(myBrowser->CurrentDir());
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
else if (current_screen == csTagEditor && !Config.albums_in_tag_editor) else if (current_screen == csTagEditor && !Config.albums_in_tag_editor)
Mpd->UpdateDirectory(editor_browsed_dir); Mpd->UpdateDirectory(editor_browsed_dir);
@@ -1430,7 +1418,7 @@ int main(int argc, char *argv[])
} }
else if ( else if (
(wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty()) (wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty())
|| (wCurrent == mBrowser && mBrowser->Current().type == itSong) || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itSong)
|| (wCurrent == mSearcher && !mSearcher->Current().first) || (wCurrent == mSearcher && !mSearcher->Current().first)
|| (wCurrent == mLibSongs && !mLibSongs->Empty()) || (wCurrent == mLibSongs && !mLibSongs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty()) || (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
@@ -1444,7 +1432,7 @@ int main(int argc, char *argv[])
edited_song = myPlaylist->Main()->at(id); edited_song = myPlaylist->Main()->at(id);
break; break;
case csBrowser: case csBrowser:
edited_song = *mBrowser->at(id).song; edited_song = *myBrowser->Main()->at(id).song;
break; break;
case csSearcher: case csSearcher:
edited_song = *mSearcher->at(id).second; edited_song = *mSearcher->at(id).second;
@@ -1506,9 +1494,9 @@ int main(int argc, char *argv[])
} }
else else
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
if (wCurrent == mBrowser && mBrowser->Current().type == itDirectory) if (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itDirectory)
{ {
string old_dir = mBrowser->Current().name; string old_dir = myBrowser->Main()->Current().name;
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Directory: " << fmtBoldEnd; Statusbar() << fmtBold << "Directory: " << fmtBoldEnd;
string new_dir = wFooter->GetString(old_dir); string new_dir = wFooter->GetString(old_dir);
@@ -1529,15 +1517,15 @@ int main(int argc, char *argv[])
ShowMessage("'%s' renamed to '%s'", old_dir.c_str(), new_dir.c_str()); ShowMessage("'%s' renamed to '%s'", old_dir.c_str(), new_dir.c_str());
if (!Config.local_browser) if (!Config.local_browser)
Mpd->UpdateDirectory(FindSharedDir(old_dir, new_dir)); Mpd->UpdateDirectory(FindSharedDir(old_dir, new_dir));
GetDirectory(browsed_dir); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
else else
ShowMessage("Cannot rename '%s' to '%s'!", old_dir.c_str(), new_dir.c_str()); ShowMessage("Cannot rename '%s' to '%s'!", old_dir.c_str(), new_dir.c_str());
} }
} }
else if (wCurrent == mPlaylistList || (wCurrent == mBrowser && mBrowser->Current().type == itPlaylist)) else if (wCurrent == mPlaylistList || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itPlaylist))
{ {
string old_name = wCurrent == mPlaylistList ? mPlaylistList->Current() : mBrowser->Current().name; string old_name = wCurrent == mPlaylistList ? mPlaylistList->Current() : myBrowser->Main()->Current().name;
LockStatusbar(); LockStatusbar();
Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd; Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd;
string new_name = wFooter->GetString(old_name); string new_name = wFooter->GetString(old_name);
@@ -1547,7 +1535,7 @@ int main(int argc, char *argv[])
Mpd->Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name)); Mpd->Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name));
ShowMessage("Playlist '%s' renamed to '%s'", old_name.c_str(), new_name.c_str()); ShowMessage("Playlist '%s' renamed to '%s'", old_name.c_str(), new_name.c_str());
if (!Config.local_browser) if (!Config.local_browser)
GetDirectory("/"); myBrowser->GetDirectory("/");
mPlaylistList->Clear(0); mPlaylistList->Clear(0);
} }
} }
@@ -1595,16 +1583,16 @@ int main(int argc, char *argv[])
string option = s->toString(Config.song_status_format); string option = s->toString(Config.song_status_format);
locale_to_utf(option); locale_to_utf(option);
GetDirectory(s->GetDirectory()); myBrowser->GetDirectory(s->GetDirectory());
for (size_t i = 0; i < mBrowser->Size(); i++) for (size_t i = 0; i < myBrowser->Main()->Size(); i++)
{ {
if (mBrowser->at(i).type == itSong && option == mBrowser->at(i).song->toString(Config.song_status_format)) if (myBrowser->Main()->at(i).type == itSong && option == myBrowser->Main()->at(i).song->toString(Config.song_status_format))
{ {
mBrowser->Highlight(i); myBrowser->Main()->Highlight(i);
break; break;
} }
} }
Browser::SwitchTo(); myBrowser->SwitchTo();
} }
} }
else if (Keypressed(input, Key.StartSearching)) else if (Keypressed(input, Key.StartSearching))
@@ -1638,7 +1626,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.ReverseSelection)) else if (Keypressed(input, Key.ReverseSelection))
{ {
if (wCurrent == myPlaylist->Main() if (wCurrent == myPlaylist->Main()
|| wCurrent == mBrowser || wCurrent == myBrowser->Main()
|| (wCurrent == mSearcher && !mSearcher->Current().first) || (wCurrent == mSearcher && !mSearcher->Current().first)
|| wCurrent == mLibSongs || wCurrent == mLibSongs
|| wCurrent == mPlaylistEditor || wCurrent == mPlaylistEditor
@@ -1652,7 +1640,7 @@ int main(int argc, char *argv[])
for (size_t i = 0; i < mList->Size(); i++) for (size_t i = 0; i < mList->Size(); i++)
mList->Select(i, !mList->isSelected(i) && !mList->isStatic(i)); mList->Select(i, !mList->isSelected(i) && !mList->isStatic(i));
// hackish shit begins // hackish shit begins
if (wCurrent == mBrowser && browsed_dir != "/") if (wCurrent == myBrowser->Main() && myBrowser->CurrentDir() != "/")
mList->Select(0, 0); // [..] cannot be selected, uhm. mList->Select(0, 0); // [..] cannot be selected, uhm.
if (wCurrent == mSearcher) if (wCurrent == mSearcher)
mList->Select(search_engine_reset_button, 0); // 'Reset' cannot be selected, omgplz. mList->Select(search_engine_reset_button, 0); // 'Reset' cannot be selected, omgplz.
@@ -1663,7 +1651,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.DeselectAll)) else if (Keypressed(input, Key.DeselectAll))
{ {
if (wCurrent == myPlaylist->Main() if (wCurrent == myPlaylist->Main()
|| wCurrent == mBrowser || wCurrent == myBrowser->Main()
|| wCurrent == mSearcher || wCurrent == mSearcher
|| wCurrent == mLibSongs || wCurrent == mLibSongs
|| wCurrent == mPlaylistEditor || wCurrent == mPlaylistEditor
@@ -1684,7 +1672,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.AddSelected)) else if (Keypressed(input, Key.AddSelected))
{ {
if (wCurrent != myPlaylist->Main() if (wCurrent != myPlaylist->Main()
&& wCurrent != mBrowser && wCurrent != myBrowser->Main()
&& wCurrent != mSearcher && wCurrent != mSearcher
&& wCurrent != mLibSongs && wCurrent != mLibSongs
&& wCurrent != mPlaylistEditor) && wCurrent != mPlaylistEditor)
@@ -1712,7 +1700,7 @@ int main(int argc, char *argv[])
} }
case csBrowser: case csBrowser:
{ {
const Item &item = mBrowser->at(*it); const Item &item = myBrowser->Main()->at(*it);
switch (item.type) switch (item.type)
{ {
case itDirectory: case itDirectory:
@@ -1863,8 +1851,8 @@ int main(int argc, char *argv[])
if (id != mDialog->Size()-1) if (id != mDialog->Size()-1)
{ {
// refresh playlist's lists // refresh playlist's lists
if (!Config.local_browser && browsed_dir == "/") if (!Config.local_browser && myBrowser->CurrentDir() == "/")
GetDirectory("/"); myBrowser->GetDirectory("/");
mPlaylistList->Clear(0); // make playlist editor update itself mPlaylistList->Clear(0); // make playlist editor update itself
} }
timer = time(NULL); timer = time(NULL);
@@ -1948,17 +1936,17 @@ int main(int argc, char *argv[])
name = myPlaylist->Main()->at(i).toString(Config.song_list_format); name = myPlaylist->Main()->at(i).toString(Config.song_list_format);
break; break;
case csBrowser: case csBrowser:
switch (mBrowser->at(i).type) switch (myBrowser->Main()->at(i).type)
{ {
case itDirectory: case itDirectory:
name = mBrowser->at(i).name; name = myBrowser->Main()->at(i).name;
break; break;
case itSong: case itSong:
name = mBrowser->at(i).song->toString(Config.song_list_format); name = myBrowser->Main()->at(i).song->toString(Config.song_list_format);
break; break;
case itPlaylist: case itPlaylist:
name = Config.browser_playlist_prefix.Str(); name = Config.browser_playlist_prefix.Str();
name += mBrowser->at(i).name; name += myBrowser->Main()->at(i).name;
break; break;
} }
break; break;
@@ -2114,14 +2102,9 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.SwitchTagTypeList)) else if (Keypressed(input, Key.SwitchTagTypeList))
{ {
if (wCurrent == mBrowser && Mpd->GetHostname()[0] == '/') if (wCurrent == myBrowser->Main())
{ {
Config.local_browser = !Config.local_browser; myBrowser->ChangeBrowseMode();
ShowMessage("Browse mode: %s", Config.local_browser ? "Local filesystem" : "MPD music dir");
browsed_dir = Config.local_browser ? home_folder : "/";
mBrowser->Reset();
GetDirectory(browsed_dir);
redraw_header = 1;
} }
else if (wCurrent == mLibArtists) else if (wCurrent == mLibArtists)
{ {
@@ -2172,7 +2155,7 @@ int main(int argc, char *argv[])
else if (Keypressed(input, Key.ScreenSwitcher)) else if (Keypressed(input, Key.ScreenSwitcher))
{ {
if (current_screen == csPlaylist) if (current_screen == csPlaylist)
Browser::SwitchTo(); myBrowser->SwitchTo();
else else
myPlaylist->SwitchTo(); myPlaylist->SwitchTo();
} }
@@ -2182,7 +2165,7 @@ int main(int argc, char *argv[])
} }
else if (Keypressed(input, Key.Browser)) else if (Keypressed(input, Key.Browser))
{ {
Browser::SwitchTo(); myBrowser->SwitchTo();
} }
else if (Keypressed(input, Key.SearchEngine)) else if (Keypressed(input, Key.SearchEngine))
{ {

View File

@@ -62,9 +62,11 @@ void Playlist::Resize()
w->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : ""); w->SetTitle(Config.columns_in_playlist ? Display::Columns(Config.song_columns_list_format) : "");
} }
const char *Playlist::Title() std::string Playlist::Title()
{ {
return "Playlist "; std::string result = "Playlist ";
result += TotalLength();
return result;
} }
void Playlist::SpacePressed() void Playlist::SpacePressed()
@@ -82,3 +84,60 @@ void Playlist::EnterPressed()
Mpd->PlayID(w->Current().GetID()); Mpd->PlayID(w->Current().GetID());
} }
std::string Playlist::TotalLength()
{
std::ostringstream result;
const int MINUTE = 60;
const int HOUR = 60*MINUTE;
const int DAY = 24*HOUR;
const int YEAR = 365*DAY;
int length = 0;
for (size_t i = 0; i < w->Size(); i++)
length += w->at(i).GetTotalLength();
result << '(' << w->Size() << (w->Size() == 1 ? " item" : " items");
if (length)
{
result << ", length: ";
int years = length/YEAR;
if (years)
{
result << years << (years == 1 ? " year" : " years");
length -= years*YEAR;
if (length)
result << ", ";
}
int days = length/DAY;
if (days)
{
result << days << (days == 1 ? " day" : " days");
length -= days*DAY;
if (length)
result << ", ";
}
int hours = length/HOUR;
if (hours)
{
result << hours << (hours == 1 ? " hour" : " hours");
length -= hours*HOUR;
if (length)
result << ", ";
}
int minutes = length/MINUTE;
if (minutes)
{
result << minutes << (minutes == 1 ? " minute" : " minutes");
length -= minutes*MINUTE;
if (length)
result << ", ";
}
if (length)
result << length << (length == 1 ? " second" : " seconds");
}
result << ')';
return result.str();
}

View File

@@ -32,10 +32,13 @@ class Playlist : public Screen< Menu<MPD::Song> >
virtual void SwitchTo(); virtual void SwitchTo();
virtual void Resize(); virtual void Resize();
virtual const char *Title(); virtual std::string Title();
virtual void EnterPressed(); virtual void EnterPressed();
virtual void SpacePressed(); virtual void SpacePressed();
protected:
std::string TotalLength();
}; };
extern Playlist *myPlaylist; extern Playlist *myPlaylist;

View File

@@ -226,7 +226,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
{ {
if (current_screen == csBrowser) if (current_screen == csBrowser)
{ {
UpdateItemList(mBrowser); myBrowser->UpdateItemList();
} }
else if (current_screen == csSearcher) else if (current_screen == csSearcher)
{ {
@@ -244,7 +244,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
} }
if (changed.Database) if (changed.Database)
{ {
GetDirectory(browsed_dir); myBrowser->GetDirectory(myBrowser->CurrentDir());
# ifdef HAVE_TAGLIB_H # ifdef HAVE_TAGLIB_H
mEditorAlbums->Clear(0); mEditorAlbums->Clear(0);
mEditorDirs->Clear(0); mEditorDirs->Clear(0);
@@ -357,7 +357,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
} }
wFooter->WriteXY(0, 1, 1, "%s", player_state.c_str()); wFooter->WriteXY(0, 1, 1, "%s", player_state.c_str());
wFooter->Bold(0); wFooter->Bold(0);
Scroller(*wFooter, utf_to_locale_cpy(s.toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin); *wFooter << Scroller(utf_to_locale_cpy(s.toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin);
wFooter->Bold(1); wFooter->Bold(1);
wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 1, "%s", tracklength.c_str()); wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 1, "%s", tracklength.c_str());

View File

@@ -29,6 +29,7 @@
#include "textidentificationframe.h" #include "textidentificationframe.h"
#include "mpegfile.h" #include "mpegfile.h"
#include "browser.h"
#include "charset.h" #include "charset.h"
#include "display.h" #include "display.h"
#include "global.h" #include "global.h"
@@ -166,8 +167,8 @@ void TinyTagEditor::EnterPressed(Song &s)
{ {
if (wPrev == myPlaylist->Main()) if (wPrev == myPlaylist->Main())
myPlaylist->Main()->Current() = s; myPlaylist->Main()->Current() = s;
else if (wPrev == mBrowser) else if (wPrev == myBrowser->Main())
*mBrowser->Current().song = s; *myBrowser->Main()->Current().song = s;
} }
} }
else else
@@ -972,7 +973,7 @@ bool WriteTags(Song &s)
Mpd->Move(s.GetPosition(), pos); Mpd->Move(s.GetPosition(), pos);
} }
} }
else // only mBrowser else // only myBrowser->Main()
s.SetFile(new_name); s.SetFile(new_name);
} }
} }