change namespace Browser into class
This commit is contained in:
144
src/browser.cpp
144
src/browser.cpp
@@ -38,21 +38,21 @@ using namespace Global;
|
||||
using namespace MPD;
|
||||
using std::string;
|
||||
|
||||
Menu<Item> *Global::mBrowser;
|
||||
Browser *myBrowser = new Browser;
|
||||
|
||||
void Browser::Init()
|
||||
{
|
||||
mBrowser = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
|
||||
mBrowser->HighlightColor(Config.main_highlight_color);
|
||||
mBrowser->SetTimeout(ncmpcpp_window_timeout);
|
||||
mBrowser->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
mBrowser->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
mBrowser->SetItemDisplayer(Display::Items);
|
||||
w = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
|
||||
w->HighlightColor(Config.main_highlight_color);
|
||||
w->SetTimeout(ncmpcpp_window_timeout);
|
||||
w->SetSelectPrefix(&Config.selected_item_prefix);
|
||||
w->SetSelectSuffix(&Config.selected_item_suffix);
|
||||
w->SetItemDisplayer(Display::Items);
|
||||
}
|
||||
|
||||
void Browser::Resize()
|
||||
{
|
||||
mBrowser->Resize(COLS, main_height);
|
||||
w->Resize(COLS, main_height);
|
||||
}
|
||||
|
||||
void Browser::SwitchTo()
|
||||
@@ -64,8 +64,8 @@ void Browser::SwitchTo()
|
||||
)
|
||||
{
|
||||
CLEAR_FIND_HISTORY;
|
||||
mBrowser->Empty() ? GetDirectory(browsed_dir) : UpdateItemList(mBrowser);
|
||||
wCurrent = mBrowser;
|
||||
w->Empty() ? myBrowser->GetDirectory(itsBrowsedDir) : myBrowser->UpdateItemList();
|
||||
wCurrent = w;
|
||||
wCurrent->Hide();
|
||||
current_screen = csBrowser;
|
||||
// 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()
|
||||
{
|
||||
if (mBrowser->Empty())
|
||||
if (w->Empty())
|
||||
return;
|
||||
|
||||
const Item &item = mBrowser->Current();
|
||||
const Item &item = w->Current();
|
||||
switch (item.type)
|
||||
{
|
||||
case itDirectory:
|
||||
{
|
||||
CLEAR_FIND_HISTORY;
|
||||
GetDirectory(item.name, browsed_dir);
|
||||
GetDirectory(item.name, itsBrowsedDir);
|
||||
redraw_header = 1;
|
||||
break;
|
||||
}
|
||||
case itSong:
|
||||
{
|
||||
block_item_list_update = 1;
|
||||
if (Config.ncmpc_like_songs_adding && mBrowser->isBold())
|
||||
if (Config.ncmpc_like_songs_adding && w->isBold())
|
||||
{
|
||||
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++)
|
||||
{
|
||||
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
||||
@@ -113,7 +120,7 @@ void Browser::EnterPressed()
|
||||
{
|
||||
Mpd->PlayID(id);
|
||||
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
|
||||
mBrowser->BoldOption(mBrowser->Choice(), 1);
|
||||
w->BoldOption(w->Choice(), 1);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -140,15 +147,15 @@ void Browser::EnterPressed()
|
||||
|
||||
void Browser::SpacePressed()
|
||||
{
|
||||
if (mBrowser->Empty())
|
||||
if (w->Empty())
|
||||
return;
|
||||
|
||||
const Item &item = mBrowser->Current();
|
||||
const Item &item = w->Current();
|
||||
switch (item.type)
|
||||
{
|
||||
case itDirectory:
|
||||
{
|
||||
if (browsed_dir != "/" && !mBrowser->Choice())
|
||||
if (itsBrowsedDir != "/" && !w->Choice())
|
||||
break; // do not let add parent dir.
|
||||
|
||||
if (Config.local_browser)
|
||||
@@ -175,10 +182,10 @@ void Browser::SpacePressed()
|
||||
case itSong:
|
||||
{
|
||||
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;
|
||||
long long hash = mBrowser->Current().song->GetHash();
|
||||
long long hash = w->Current().song->GetHash();
|
||||
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
|
||||
{
|
||||
if (myPlaylist->Main()->at(i).GetHash() == hash)
|
||||
@@ -189,7 +196,7 @@ void Browser::SpacePressed()
|
||||
}
|
||||
}
|
||||
Mpd->CommitQueue();
|
||||
mBrowser->BoldOption(mBrowser->Choice(), 0);
|
||||
w->BoldOption(w->Choice(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -197,7 +204,7 @@ void Browser::SpacePressed()
|
||||
if (Mpd->AddSong(s) != -1)
|
||||
{
|
||||
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
|
||||
mBrowser->BoldOption(mBrowser->Choice(), 1);
|
||||
w->BoldOption(w->Choice(), 1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -219,7 +226,7 @@ void Browser::SpacePressed()
|
||||
break;
|
||||
}
|
||||
}
|
||||
mBrowser->Scroll(wDown);
|
||||
w->Scroll(wDown);
|
||||
}
|
||||
|
||||
namespace
|
||||
@@ -282,46 +289,24 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateItemList(Menu<Item> *menu)
|
||||
{
|
||||
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)
|
||||
void Browser::GetDirectory(string dir, string subdir)
|
||||
{
|
||||
if (dir.empty())
|
||||
dir = "/";
|
||||
|
||||
int highlightme = -1;
|
||||
browsed_dir_scroll_begin = 0;
|
||||
if (browsed_dir != dir)
|
||||
mBrowser->Reset();
|
||||
browsed_dir = dir;
|
||||
itsScrollBeginning = 0;
|
||||
if (itsBrowsedDir != dir)
|
||||
w->Reset();
|
||||
itsBrowsedDir = dir;
|
||||
|
||||
locale_to_utf(dir);
|
||||
|
||||
for (size_t i = 0; i < mBrowser->Size(); i++)
|
||||
if (mBrowser->at(i).type == itSong)
|
||||
delete mBrowser->at(i).song;
|
||||
for (size_t i = 0; i < w->Size(); i++)
|
||||
if (w->at(i).type == itSong)
|
||||
delete w->at(i).song;
|
||||
|
||||
mBrowser->Clear(0);
|
||||
w->Clear(0);
|
||||
|
||||
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.name = slash != string::npos ? dir.substr(0, slash) : "/";
|
||||
parent.type = itDirectory;
|
||||
mBrowser->AddOption(parent);
|
||||
w->AddOption(parent);
|
||||
}
|
||||
|
||||
ItemList list;
|
||||
@@ -344,15 +329,15 @@ void GetDirectory(string dir, string subdir)
|
||||
case itPlaylist:
|
||||
{
|
||||
utf_to_locale(it->name);
|
||||
mBrowser->AddOption(*it);
|
||||
w->AddOption(*it);
|
||||
break;
|
||||
}
|
||||
case itDirectory:
|
||||
{
|
||||
utf_to_locale(it->name);
|
||||
if (it->name == subdir)
|
||||
highlightme = mBrowser->Size();
|
||||
mBrowser->AddOption(*it);
|
||||
highlightme = w->Size();
|
||||
w->AddOption(*it);
|
||||
break;
|
||||
}
|
||||
case itSong:
|
||||
@@ -366,14 +351,49 @@ void GetDirectory(string dir, string subdir)
|
||||
break;
|
||||
}
|
||||
}
|
||||
mBrowser->AddOption(*it, bold);
|
||||
w->AddOption(*it, bold);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (highlightme >= 0)
|
||||
mBrowser->Highlight(highlightme);
|
||||
w->Highlight(highlightme);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,20 +23,35 @@
|
||||
|
||||
#include "mpdpp.h"
|
||||
#include "ncmpcpp.h"
|
||||
#include "screen.h"
|
||||
|
||||
namespace Browser
|
||||
class Browser : public Screen< Menu<MPD::Item> >
|
||||
{
|
||||
void Init();
|
||||
void Resize();
|
||||
void SwitchTo();
|
||||
public:
|
||||
Browser() : itsScrollBeginning(0), itsBrowsedDir("/") { }
|
||||
|
||||
void EnterPressed();
|
||||
void SpacePressed();
|
||||
}
|
||||
virtual void Init();
|
||||
virtual void Resize();
|
||||
virtual void SwitchTo();
|
||||
|
||||
void UpdateItemList(Menu<MPD::Item> *);
|
||||
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();
|
||||
|
||||
protected:
|
||||
size_t itsScrollBeginning;
|
||||
|
||||
std::string itsBrowsedDir;
|
||||
};
|
||||
|
||||
extern Browser *myBrowser;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -91,61 +91,6 @@ string Display::Columns(string st)
|
||||
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)
|
||||
{
|
||||
*menu << pair.first;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Display
|
||||
*menu << t;
|
||||
}
|
||||
|
||||
void TotalPlaylistLength(Window &);
|
||||
//void TotalPlaylistLength(Window &);
|
||||
|
||||
void StringPairs(const string_pair &, void *, Menu<string_pair> *);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Global
|
||||
extern Window *wPrev;
|
||||
|
||||
// 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 Window *wLibActiveCol;
|
||||
@@ -73,14 +73,14 @@ namespace Global
|
||||
extern int now_playing;
|
||||
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_height;
|
||||
extern size_t lyrics_scroll_begin;
|
||||
|
||||
extern time_t timer;
|
||||
|
||||
extern std::string browsed_dir;
|
||||
// extern std::string browsed_dir;
|
||||
extern std::string editor_browsed_dir;
|
||||
extern std::string editor_highlighted_dir;
|
||||
extern std::string info_title;
|
||||
|
||||
@@ -305,8 +305,10 @@ const Buffer &ShowTag(const string &tag)
|
||||
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);
|
||||
size_t len;
|
||||
# ifdef _UTF8
|
||||
@@ -331,7 +333,7 @@ void Scroller(Window &w, const string &string, size_t width, size_t &pos)
|
||||
# else
|
||||
len++;
|
||||
# endif
|
||||
w << *it;
|
||||
result += *it;
|
||||
}
|
||||
if (++pos >= s.length())
|
||||
pos = 0;
|
||||
@@ -342,11 +344,12 @@ void Scroller(Window &w, const string &string, size_t width, size_t &pos)
|
||||
# else
|
||||
len++;
|
||||
# endif
|
||||
w << *b;
|
||||
result += *b;
|
||||
}
|
||||
}
|
||||
else
|
||||
w << s;
|
||||
result = s;
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef HAVE_CURL_CURL_H
|
||||
|
||||
@@ -50,7 +50,7 @@ Window &Statusbar();
|
||||
|
||||
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
|
||||
size_t write_data(char *, size_t, size_t, std::string);
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
# include "helpers.h"
|
||||
#endif
|
||||
|
||||
#include "browser.h"
|
||||
#include "charset.h"
|
||||
#include "global.h"
|
||||
#include "media_library.h"
|
||||
@@ -94,7 +95,7 @@ void Info::GetSong()
|
||||
}
|
||||
else if (
|
||||
(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 == mLibSongs && !mLibSongs->Empty())
|
||||
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|
||||
@@ -111,7 +112,7 @@ void Info::GetSong()
|
||||
s = &myPlaylist->Main()->at(id);
|
||||
break;
|
||||
case csBrowser:
|
||||
s = mBrowser->at(id).song;
|
||||
s = myBrowser->Main()->at(id).song;
|
||||
break;
|
||||
case csSearcher:
|
||||
s = mSearcher->at(id).second;
|
||||
@@ -181,7 +182,7 @@ void Info::GetArtist()
|
||||
}
|
||||
else if (
|
||||
(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 == mLibArtists && !mLibArtists->Empty())
|
||||
|| (wCurrent == mLibSongs && !mLibSongs->Empty())
|
||||
@@ -205,7 +206,7 @@ void Info::GetArtist()
|
||||
*artist = myPlaylist->Main()->at(id).GetArtist();
|
||||
break;
|
||||
case csBrowser:
|
||||
*artist = mBrowser->at(id).song->GetArtist();
|
||||
*artist = myBrowser->Main()->at(id).song->GetArtist();
|
||||
break;
|
||||
case csSearcher:
|
||||
*artist = mSearcher->at(id).second->GetArtist();
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
|
||||
#include "browser.h"
|
||||
#include "charset.h"
|
||||
#include "global.h"
|
||||
#include "helpers.h"
|
||||
@@ -107,7 +108,7 @@ void Lyrics::Get()
|
||||
else if (
|
||||
reload_lyrics
|
||||
|| (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 == mLibSongs && !mLibSongs->Empty())
|
||||
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|
||||
@@ -143,7 +144,7 @@ void Lyrics::Get()
|
||||
s = &myPlaylist->Main()->at(id);
|
||||
break;
|
||||
case csBrowser:
|
||||
s = mBrowser->at(id).song;
|
||||
s = myBrowser->Main()->at(id).song;
|
||||
break;
|
||||
case csSearcher:
|
||||
s = mSearcher->at(id).second;
|
||||
|
||||
115
src/ncmpcpp.cpp
115
src/ncmpcpp.cpp
@@ -74,14 +74,12 @@ Connection *Global::Mpd;
|
||||
int Global::now_playing = -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_height;
|
||||
size_t Global::lyrics_scroll_begin = 0;
|
||||
|
||||
time_t Global::timer;
|
||||
|
||||
string Global::browsed_dir = "/";
|
||||
string Global::editor_browsed_dir = "/";
|
||||
string Global::editor_highlighted_dir;
|
||||
string Global::info_title;
|
||||
@@ -151,7 +149,7 @@ int main(int argc, char *argv[])
|
||||
main_height++;
|
||||
|
||||
myPlaylist->Init();
|
||||
Browser::Init();
|
||||
myBrowser->Init();
|
||||
SearchEngine::Init();
|
||||
MediaLibrary::Init();
|
||||
PlaylistEditor::Init();
|
||||
@@ -226,10 +224,10 @@ int main(int argc, char *argv[])
|
||||
|
||||
// header stuff
|
||||
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)
|
||||
|| 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))
|
||||
{
|
||||
redraw_header = 1;
|
||||
@@ -246,7 +244,7 @@ int main(int argc, char *argv[])
|
||||
screen_title = myPlaylist->Title();
|
||||
break;
|
||||
case csBrowser:
|
||||
screen_title = "Browse: ";
|
||||
screen_title = myBrowser->Title();
|
||||
break;
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
case csTinyTagEditor:
|
||||
@@ -284,21 +282,11 @@ int main(int argc, char *argv[])
|
||||
wHeader->WriteXY(0, 0, 1, "%s", screen_title.c_str());
|
||||
wHeader->Bold(0);
|
||||
|
||||
if (current_screen == csPlaylist)
|
||||
{
|
||||
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)
|
||||
if (current_screen == csLyrics)
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -520,7 +508,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
Help::Resize();
|
||||
myPlaylist->Resize();
|
||||
Browser::Resize();
|
||||
myBrowser->Resize();
|
||||
SearchEngine::Resize();
|
||||
MediaLibrary::Resize();
|
||||
PlaylistEditor::Resize();
|
||||
@@ -570,10 +558,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.GoToParentDir))
|
||||
{
|
||||
if (wCurrent == mBrowser && browsed_dir != "/")
|
||||
if (wCurrent == myBrowser->Main() && myBrowser->CurrentDir() != "/")
|
||||
{
|
||||
mBrowser->Reset();
|
||||
Browser::EnterPressed();
|
||||
myBrowser->Main()->Reset();
|
||||
myBrowser->EnterPressed();
|
||||
}
|
||||
}
|
||||
else if (Keypressed(input, Key.Enter))
|
||||
@@ -588,7 +576,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
case csBrowser:
|
||||
{
|
||||
Browser::EnterPressed();
|
||||
myBrowser->EnterPressed();
|
||||
break;
|
||||
}
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
@@ -637,7 +625,7 @@ int main(int argc, char *argv[])
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
|| wCurrent == mEditorTags
|
||||
# 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 == mPlaylistEditor)
|
||||
{
|
||||
@@ -653,7 +641,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (current_screen == csBrowser)
|
||||
{
|
||||
Browser::SpacePressed();
|
||||
myBrowser->SpacePressed();
|
||||
}
|
||||
else if (current_screen == csSearcher)
|
||||
{
|
||||
@@ -840,8 +828,8 @@ int main(int argc, char *argv[])
|
||||
else if (current_screen == csBrowser || wCurrent == mPlaylistList)
|
||||
{
|
||||
LockStatusbar();
|
||||
string name = wCurrent == mBrowser ? mBrowser->Current().name : mPlaylistList->Current();
|
||||
if (current_screen != csBrowser || mBrowser->Current().type == itPlaylist)
|
||||
string name = wCurrent == myBrowser->Main() ? myBrowser->Main()->Current().name : mPlaylistList->Current();
|
||||
if (current_screen != csBrowser || myBrowser->Main()->Current().type == itPlaylist)
|
||||
{
|
||||
Statusbar() << "Delete playlist " << name << " ? [y/n] ";
|
||||
curs_set(1);
|
||||
@@ -857,7 +845,7 @@ int main(int argc, char *argv[])
|
||||
Mpd->DeletePlaylist(locale_to_utf_cpy(name));
|
||||
ShowMessage("Playlist %s deleted!", name.c_str());
|
||||
if (!Config.local_browser)
|
||||
GetDirectory("/");
|
||||
myBrowser->GetDirectory("/");
|
||||
}
|
||||
else
|
||||
ShowMessage("Aborted!");
|
||||
@@ -960,8 +948,8 @@ int main(int argc, char *argv[])
|
||||
UnlockStatusbar();
|
||||
}
|
||||
}
|
||||
if (!Config.local_browser && browsed_dir == "/" && !mBrowser->Empty())
|
||||
GetDirectory(browsed_dir);
|
||||
if (!Config.local_browser && myBrowser->CurrentDir() == "/" && !myBrowser->Main()->Empty())
|
||||
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
||||
}
|
||||
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()->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;
|
||||
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)
|
||||
{
|
||||
@@ -1302,7 +1290,7 @@ int main(int argc, char *argv[])
|
||||
else if (Keypressed(input, Key.UpdateDB))
|
||||
{
|
||||
if (current_screen == csBrowser)
|
||||
Mpd->UpdateDirectory(browsed_dir);
|
||||
Mpd->UpdateDirectory(myBrowser->CurrentDir());
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
else if (current_screen == csTagEditor && !Config.albums_in_tag_editor)
|
||||
Mpd->UpdateDirectory(editor_browsed_dir);
|
||||
@@ -1430,7 +1418,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (
|
||||
(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 == mLibSongs && !mLibSongs->Empty())
|
||||
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|
||||
@@ -1444,7 +1432,7 @@ int main(int argc, char *argv[])
|
||||
edited_song = myPlaylist->Main()->at(id);
|
||||
break;
|
||||
case csBrowser:
|
||||
edited_song = *mBrowser->at(id).song;
|
||||
edited_song = *myBrowser->Main()->at(id).song;
|
||||
break;
|
||||
case csSearcher:
|
||||
edited_song = *mSearcher->at(id).second;
|
||||
@@ -1506,9 +1494,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
# 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();
|
||||
Statusbar() << fmtBold << "Directory: " << fmtBoldEnd;
|
||||
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());
|
||||
if (!Config.local_browser)
|
||||
Mpd->UpdateDirectory(FindSharedDir(old_dir, new_dir));
|
||||
GetDirectory(browsed_dir);
|
||||
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
||||
}
|
||||
else
|
||||
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();
|
||||
Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd;
|
||||
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));
|
||||
ShowMessage("Playlist '%s' renamed to '%s'", old_name.c_str(), new_name.c_str());
|
||||
if (!Config.local_browser)
|
||||
GetDirectory("/");
|
||||
myBrowser->GetDirectory("/");
|
||||
mPlaylistList->Clear(0);
|
||||
}
|
||||
}
|
||||
@@ -1595,16 +1583,16 @@ int main(int argc, char *argv[])
|
||||
|
||||
string option = s->toString(Config.song_status_format);
|
||||
locale_to_utf(option);
|
||||
GetDirectory(s->GetDirectory());
|
||||
for (size_t i = 0; i < mBrowser->Size(); i++)
|
||||
myBrowser->GetDirectory(s->GetDirectory());
|
||||
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;
|
||||
}
|
||||
}
|
||||
Browser::SwitchTo();
|
||||
myBrowser->SwitchTo();
|
||||
}
|
||||
}
|
||||
else if (Keypressed(input, Key.StartSearching))
|
||||
@@ -1638,7 +1626,7 @@ int main(int argc, char *argv[])
|
||||
else if (Keypressed(input, Key.ReverseSelection))
|
||||
{
|
||||
if (wCurrent == myPlaylist->Main()
|
||||
|| wCurrent == mBrowser
|
||||
|| wCurrent == myBrowser->Main()
|
||||
|| (wCurrent == mSearcher && !mSearcher->Current().first)
|
||||
|| wCurrent == mLibSongs
|
||||
|| wCurrent == mPlaylistEditor
|
||||
@@ -1652,7 +1640,7 @@ int main(int argc, char *argv[])
|
||||
for (size_t i = 0; i < mList->Size(); i++)
|
||||
mList->Select(i, !mList->isSelected(i) && !mList->isStatic(i));
|
||||
// hackish shit begins
|
||||
if (wCurrent == mBrowser && browsed_dir != "/")
|
||||
if (wCurrent == myBrowser->Main() && myBrowser->CurrentDir() != "/")
|
||||
mList->Select(0, 0); // [..] cannot be selected, uhm.
|
||||
if (wCurrent == mSearcher)
|
||||
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))
|
||||
{
|
||||
if (wCurrent == myPlaylist->Main()
|
||||
|| wCurrent == mBrowser
|
||||
|| wCurrent == myBrowser->Main()
|
||||
|| wCurrent == mSearcher
|
||||
|| wCurrent == mLibSongs
|
||||
|| wCurrent == mPlaylistEditor
|
||||
@@ -1684,7 +1672,7 @@ int main(int argc, char *argv[])
|
||||
else if (Keypressed(input, Key.AddSelected))
|
||||
{
|
||||
if (wCurrent != myPlaylist->Main()
|
||||
&& wCurrent != mBrowser
|
||||
&& wCurrent != myBrowser->Main()
|
||||
&& wCurrent != mSearcher
|
||||
&& wCurrent != mLibSongs
|
||||
&& wCurrent != mPlaylistEditor)
|
||||
@@ -1712,7 +1700,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
case csBrowser:
|
||||
{
|
||||
const Item &item = mBrowser->at(*it);
|
||||
const Item &item = myBrowser->Main()->at(*it);
|
||||
switch (item.type)
|
||||
{
|
||||
case itDirectory:
|
||||
@@ -1863,8 +1851,8 @@ int main(int argc, char *argv[])
|
||||
if (id != mDialog->Size()-1)
|
||||
{
|
||||
// refresh playlist's lists
|
||||
if (!Config.local_browser && browsed_dir == "/")
|
||||
GetDirectory("/");
|
||||
if (!Config.local_browser && myBrowser->CurrentDir() == "/")
|
||||
myBrowser->GetDirectory("/");
|
||||
mPlaylistList->Clear(0); // make playlist editor update itself
|
||||
}
|
||||
timer = time(NULL);
|
||||
@@ -1948,17 +1936,17 @@ int main(int argc, char *argv[])
|
||||
name = myPlaylist->Main()->at(i).toString(Config.song_list_format);
|
||||
break;
|
||||
case csBrowser:
|
||||
switch (mBrowser->at(i).type)
|
||||
switch (myBrowser->Main()->at(i).type)
|
||||
{
|
||||
case itDirectory:
|
||||
name = mBrowser->at(i).name;
|
||||
name = myBrowser->Main()->at(i).name;
|
||||
break;
|
||||
case itSong:
|
||||
name = mBrowser->at(i).song->toString(Config.song_list_format);
|
||||
name = myBrowser->Main()->at(i).song->toString(Config.song_list_format);
|
||||
break;
|
||||
case itPlaylist:
|
||||
name = Config.browser_playlist_prefix.Str();
|
||||
name += mBrowser->at(i).name;
|
||||
name += myBrowser->Main()->at(i).name;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -2114,14 +2102,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.SwitchTagTypeList))
|
||||
{
|
||||
if (wCurrent == mBrowser && Mpd->GetHostname()[0] == '/')
|
||||
if (wCurrent == myBrowser->Main())
|
||||
{
|
||||
Config.local_browser = !Config.local_browser;
|
||||
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;
|
||||
myBrowser->ChangeBrowseMode();
|
||||
}
|
||||
else if (wCurrent == mLibArtists)
|
||||
{
|
||||
@@ -2172,7 +2155,7 @@ int main(int argc, char *argv[])
|
||||
else if (Keypressed(input, Key.ScreenSwitcher))
|
||||
{
|
||||
if (current_screen == csPlaylist)
|
||||
Browser::SwitchTo();
|
||||
myBrowser->SwitchTo();
|
||||
else
|
||||
myPlaylist->SwitchTo();
|
||||
}
|
||||
@@ -2182,7 +2165,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else if (Keypressed(input, Key.Browser))
|
||||
{
|
||||
Browser::SwitchTo();
|
||||
myBrowser->SwitchTo();
|
||||
}
|
||||
else if (Keypressed(input, Key.SearchEngine))
|
||||
{
|
||||
|
||||
@@ -62,9 +62,11 @@ void Playlist::Resize()
|
||||
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()
|
||||
@@ -82,3 +84,60 @@ void Playlist::EnterPressed()
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,10 +32,13 @@ class Playlist : public Screen< Menu<MPD::Song> >
|
||||
virtual void SwitchTo();
|
||||
virtual void Resize();
|
||||
|
||||
virtual const char *Title();
|
||||
virtual std::string Title();
|
||||
|
||||
virtual void EnterPressed();
|
||||
virtual void SpacePressed();
|
||||
|
||||
protected:
|
||||
std::string TotalLength();
|
||||
};
|
||||
|
||||
extern Playlist *myPlaylist;
|
||||
|
||||
@@ -226,7 +226,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
{
|
||||
if (current_screen == csBrowser)
|
||||
{
|
||||
UpdateItemList(mBrowser);
|
||||
myBrowser->UpdateItemList();
|
||||
}
|
||||
else if (current_screen == csSearcher)
|
||||
{
|
||||
@@ -244,7 +244,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
|
||||
}
|
||||
if (changed.Database)
|
||||
{
|
||||
GetDirectory(browsed_dir);
|
||||
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
||||
# ifdef HAVE_TAGLIB_H
|
||||
mEditorAlbums->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->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->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 1, "%s", tracklength.c_str());
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "textidentificationframe.h"
|
||||
#include "mpegfile.h"
|
||||
|
||||
#include "browser.h"
|
||||
#include "charset.h"
|
||||
#include "display.h"
|
||||
#include "global.h"
|
||||
@@ -166,8 +167,8 @@ void TinyTagEditor::EnterPressed(Song &s)
|
||||
{
|
||||
if (wPrev == myPlaylist->Main())
|
||||
myPlaylist->Main()->Current() = s;
|
||||
else if (wPrev == mBrowser)
|
||||
*mBrowser->Current().song = s;
|
||||
else if (wPrev == myBrowser->Main())
|
||||
*myBrowser->Main()->Current().song = s;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -972,7 +973,7 @@ bool WriteTags(Song &s)
|
||||
Mpd->Move(s.GetPosition(), pos);
|
||||
}
|
||||
}
|
||||
else // only mBrowser
|
||||
else // only myBrowser->Main()
|
||||
s.SetFile(new_name);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user