change namespace PlaylistEditor into class

This commit is contained in:
Andrzej Rybczak
2009-02-14 18:11:31 +01:00
parent 5a06f2a4fc
commit 7148762b0c
8 changed files with 224 additions and 195 deletions

View File

@@ -54,9 +54,9 @@ namespace Global
extern Menu<MPD::Song> *mEditorTags;
# endif // HAVE_TAGLIB_H
extern Window *wPlaylistEditorActiveCol;
extern Menu<std::string> *mPlaylistList;
extern Menu<MPD::Song> *mPlaylistEditor;
// extern Window *wPlaylistEditorActiveCol;
// extern Menu<std::string> *mPlaylistList;
// extern Menu<MPD::Song> *myPlaylistEditor->Content;
extern Scrollpad *sHelp;
extern Scrollpad *sLyrics;

View File

@@ -85,7 +85,7 @@ void Info::GetSong()
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Refresh();
myPlaylistEditor->Refresh();
}
# ifdef HAVE_TAGLIB_H
else if (current_screen == csTagEditor)
@@ -99,7 +99,7 @@ void Info::GetSong()
|| (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong)
|| (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|| (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
# ifdef HAVE_TAGLIB_H
|| (wCurrent == mEditorTags && !mEditorTags->Empty())
# endif // HAVE_TAGLIB_H
@@ -122,7 +122,7 @@ void Info::GetSong()
s = &myLibrary->Songs->at(id);
break;
case csPlaylistEditor:
s = &mPlaylistEditor->at(id);
s = &myPlaylistEditor->Content->at(id);
break;
# ifdef HAVE_TAGLIB_H
case csTagEditor:
@@ -172,7 +172,7 @@ void Info::GetArtist()
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Refresh();
myPlaylistEditor->Refresh();
}
# ifdef HAVE_TAGLIB_H
else if (current_screen == csTagEditor)
@@ -187,7 +187,7 @@ void Info::GetArtist()
|| (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| (wCurrent == myLibrary->Artists && !myLibrary->Artists->Empty())
|| (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|| (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
# ifdef HAVE_TAGLIB_H
|| (wCurrent == mEditorTags && !mEditorTags->Empty())
# endif // HAVE_TAGLIB_H
@@ -216,7 +216,7 @@ void Info::GetArtist()
*artist = myLibrary->Artists->at(id);
break;
case csPlaylistEditor:
*artist = mPlaylistEditor->at(id).GetArtist();
*artist = myPlaylistEditor->Content->at(id).GetArtist();
break;
# ifdef HAVE_TAGLIB_H
case csTagEditor:

View File

@@ -97,7 +97,7 @@ void Lyrics::Get()
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Refresh();
myPlaylistEditor->Refresh();
}
# ifdef HAVE_TAGLIB_H
else if (current_screen == csTagEditor)
@@ -112,7 +112,7 @@ void Lyrics::Get()
|| (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == MPD::itSong)
|| (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|| (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
# ifdef HAVE_TAGLIB_H
|| (wCurrent == mEditorTags && !mEditorTags->Empty())
# endif // HAVE_TAGLIB_H
@@ -154,7 +154,7 @@ void Lyrics::Get()
s = &myLibrary->Songs->at(id);
break;
case csPlaylistEditor:
s = &mPlaylistEditor->at(id);
s = &myPlaylistEditor->Content->at(id);
break;
# ifdef HAVE_TAGLIB_H
case csTagEditor:

View File

@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
myBrowser->Init();
mySearcher->Init();
myLibrary->Init();
PlaylistEditor::Init();
myPlaylistEditor->Init();
# ifdef HAVE_TAGLIB_H
TinyTagEditor::Init();
@@ -264,7 +264,7 @@ int main(int argc, char *argv[])
screen_title = "Lyrics: ";
break;
case csPlaylistEditor:
screen_title = "Playlist editor";
screen_title = myPlaylistEditor->Title();
break;
# ifdef ENABLE_CLOCK
case csClock:
@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Update();
myPlaylistEditor->Update();
}
else
# ifdef HAVE_TAGLIB_H
@@ -383,9 +383,9 @@ int main(int argc, char *argv[])
{
myLibrary->Songs->Clear(0);
}
else if (wCurrent == mPlaylistList)
else if (wCurrent == myPlaylistEditor->List)
{
mPlaylistEditor->Clear(0);
myPlaylistEditor->Content->Clear(0);
}
# ifdef HAVE_TAGLIB_H
else if (wCurrent == mEditorLeftCol)
@@ -413,7 +413,7 @@ int main(int argc, char *argv[])
{
if (!Config.fancy_scrolling
&& (wCurrent == myLibrary->Artists
|| wCurrent == mPlaylistList
|| wCurrent == myPlaylistEditor->List
# ifdef HAVE_TAGLIB_H
|| wCurrent == mEditorLeftCol
# endif // HAVE_TAGLIB_H
@@ -441,7 +441,7 @@ int main(int argc, char *argv[])
{
if (!Config.fancy_scrolling
&& (wCurrent == myLibrary->Artists
|| wCurrent == mPlaylistList
|| wCurrent == myPlaylistEditor->List
# ifdef HAVE_TAGLIB_H
|| wCurrent == mEditorLeftCol
# endif // HAVE_TAGLIB_H
@@ -510,7 +510,7 @@ int main(int argc, char *argv[])
myBrowser->Resize();
mySearcher->Resize();
myLibrary->Resize();
PlaylistEditor::Resize();
myPlaylistEditor->Resize();
Info::Resize();
Lyrics::Resize();
@@ -543,7 +543,7 @@ int main(int argc, char *argv[])
# endif // HAVE_TAGLIB_H
if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Refresh();
myPlaylistEditor->Refresh();
}
header_update_status = 1;
PlayerState mpd_state = Mpd->GetState();
@@ -597,7 +597,7 @@ int main(int argc, char *argv[])
}
case csPlaylistEditor:
{
PlaylistEditor::EnterPressed();
myPlaylistEditor->EnterPressed();
break;
}
# ifdef HAVE_TAGLIB_H
@@ -626,7 +626,7 @@ int main(int argc, char *argv[])
# endif // HAVE_TAGLIB_H
|| (wCurrent == myBrowser->Main() && ((Menu<Song> *)wCurrent)->Choice() >= (myBrowser->CurrentDir() != "/" ? 1 : 0)) || (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| wCurrent == myLibrary->Songs
|| wCurrent == mPlaylistEditor)
|| wCurrent == myPlaylistEditor->Content)
{
List *mList = (Menu<Song> *)wCurrent;
if (mList->Empty())
@@ -652,7 +652,7 @@ int main(int argc, char *argv[])
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::SpacePressed();
myPlaylistEditor->SpacePressed();
}
# ifdef HAVE_TAGLIB_H
else if (wCurrent == mEditorLeftCol)
@@ -680,14 +680,7 @@ int main(int argc, char *argv[])
}
else if (current_screen == csPlaylistEditor && input == Key.VolumeUp[0])
{
if (wCurrent == mPlaylistList)
{
CLEAR_FIND_HISTORY;
mPlaylistList->HighlightColor(Config.main_highlight_color);
wCurrent->Refresh();
wCurrent = wPlaylistEditorActiveCol = mPlaylistEditor;
mPlaylistEditor->HighlightColor(Config.active_column_color);
}
myPlaylistEditor->NextColumn();
}
# ifdef HAVE_TAGLIB_H
else if (current_screen == csTagEditor && input == Key.VolumeUp[0])
@@ -720,14 +713,7 @@ int main(int argc, char *argv[])
}
else if (current_screen == csPlaylistEditor && input == Key.VolumeDown[0])
{
if (wCurrent == mPlaylistEditor)
{
CLEAR_FIND_HISTORY;
mPlaylistEditor->HighlightColor(Config.main_highlight_color);
wCurrent->Refresh();
wCurrent = wPlaylistEditorActiveCol = mPlaylistList;
mPlaylistList->HighlightColor(Config.active_column_color);
}
myPlaylistEditor->PrevColumn();
}
# ifdef HAVE_TAGLIB_H
else if (current_screen == csTagEditor && input == Key.VolumeDown[0])
@@ -790,10 +776,10 @@ int main(int argc, char *argv[])
}
Mpd->CommitQueue();
}
else if (current_screen == csBrowser || wCurrent == mPlaylistList)
else if (current_screen == csBrowser || wCurrent == myPlaylistEditor->List)
{
LockStatusbar();
string name = wCurrent == myBrowser->Main() ? myBrowser->Main()->Current().name : mPlaylistList->Current();
string name = wCurrent == myBrowser->Main() ? myBrowser->Main()->Current().name : myPlaylistEditor->List->Current();
if (current_screen != csBrowser || myBrowser->Main()->Current().type == itPlaylist)
{
Statusbar() << "Delete playlist " << name << " ? [y/n] ";
@@ -815,41 +801,41 @@ int main(int argc, char *argv[])
else
ShowMessage("Aborted!");
curs_set(0);
mPlaylistList->Clear(0); // make playlists list update itself
myPlaylistEditor->List->Clear(0); // make playlists list update itself
}
UnlockStatusbar();
}
else if (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
else if (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
{
if (mPlaylistEditor->hasSelected())
if (myPlaylistEditor->Content->hasSelected())
{
vector<size_t> list;
mPlaylistEditor->GetSelected(list);
locale_to_utf(mPlaylistList->Current());
myPlaylistEditor->Content->GetSelected(list);
locale_to_utf(myPlaylistEditor->List->Current());
for (vector<size_t>::const_reverse_iterator it = list.rbegin(); it != ((const vector<size_t> &)list).rend(); it++)
{
Mpd->QueueDeleteFromPlaylist(mPlaylistList->Current(), *it);
mPlaylistEditor->DeleteOption(*it);
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->List->Current(), *it);
myPlaylistEditor->Content->DeleteOption(*it);
}
utf_to_locale(mPlaylistList->Current());
ShowMessage("Selected items deleted from playlist '%s'!", mPlaylistList->Current().c_str());
utf_to_locale(myPlaylistEditor->List->Current());
ShowMessage("Selected items deleted from playlist '%s'!", myPlaylistEditor->List->Current().c_str());
// redraw_screen = 1;
}
else
{
mPlaylistEditor->SetTimeout(50);
locale_to_utf(mPlaylistList->Current());
while (!mPlaylistEditor->Empty() && Keypressed(input, Key.Delete))
myPlaylistEditor->Content->SetTimeout(50);
locale_to_utf(myPlaylistEditor->List->Current());
while (!myPlaylistEditor->Content->Empty() && Keypressed(input, Key.Delete))
{
TraceMpdStatus();
timer = time(NULL);
Mpd->QueueDeleteFromPlaylist(mPlaylistList->Current(), mPlaylistEditor->Choice());
mPlaylistEditor->DeleteOption(mPlaylistEditor->Choice());
mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input);
Mpd->QueueDeleteFromPlaylist(myPlaylistEditor->List->Current(), myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->DeleteOption(myPlaylistEditor->Content->Choice());
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
utf_to_locale(mPlaylistList->Current());
mPlaylistEditor->SetTimeout(ncmpcpp_window_timeout);
utf_to_locale(myPlaylistEditor->List->Current());
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
Mpd->CommitQueue();
}
@@ -884,7 +870,7 @@ int main(int argc, char *argv[])
if (Mpd->SavePlaylist(real_playlist_name))
{
ShowMessage("Playlist saved as: %s", playlist_name.c_str());
mPlaylistList->Clear(0); // make playlist's list update itself
myPlaylistEditor->List->Clear(0); // make playlist's list update itself
}
else
{
@@ -909,7 +895,7 @@ int main(int argc, char *argv[])
else
ShowMessage("Aborted!");
curs_set(0);
mPlaylistList->Clear(0); // make playlist's list update itself
myPlaylistEditor->List->Clear(0); // make playlist's list update itself
UnlockStatusbar();
}
}
@@ -975,13 +961,13 @@ int main(int argc, char *argv[])
}
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
}
else if (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
else if (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
{
mPlaylistEditor->SetTimeout(50);
if (mPlaylistEditor->hasSelected())
myPlaylistEditor->Content->SetTimeout(50);
if (myPlaylistEditor->Content->hasSelected())
{
vector<size_t> list;
mPlaylistEditor->GetSelected(list);
myPlaylistEditor->Content->GetSelected(list);
vector<size_t> origs(list);
@@ -992,35 +978,35 @@ int main(int argc, char *argv[])
for (vector<size_t>::iterator it = list.begin(); it != list.end(); it++)
{
(*it)--;
mPlaylistEditor->Swap(*it, (*it)+1);
myPlaylistEditor->Content->Swap(*it, (*it)+1);
}
mPlaylistEditor->Highlight(list[(list.size()-1)/2]);
mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input);
myPlaylistEditor->Content->Highlight(list[(list.size()-1)/2]);
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
for (size_t i = 0; i < list.size(); i++)
if (origs[i] != list[i])
Mpd->QueueMove(mPlaylistList->Current(), origs[i], list[i]);
Mpd->QueueMove(myPlaylistEditor->List->Current(), origs[i], list[i]);
Mpd->CommitQueue();
}
else
{
size_t from, to;
from = to = mPlaylistEditor->Choice();
from = to = myPlaylistEditor->Content->Choice();
while (Keypressed(input, Key.MvSongUp) && to > 0)
{
TraceMpdStatus();
timer = time(NULL);
to--;
mPlaylistEditor->Swap(to, to+1);
mPlaylistEditor->Scroll(wUp);
mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input);
myPlaylistEditor->Content->Swap(to, to+1);
myPlaylistEditor->Content->Scroll(wUp);
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
if (from != to)
Mpd->Move(mPlaylistList->Current(), from, to);
Mpd->Move(myPlaylistEditor->List->Current(), from, to);
}
mPlaylistEditor->SetTimeout(ncmpcpp_window_timeout);
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
}
else if (Keypressed(input, Key.MvSongDown))
@@ -1079,52 +1065,52 @@ int main(int argc, char *argv[])
myPlaylist->Main()->SetTimeout(ncmpcpp_window_timeout);
}
else if (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
else if (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
{
mPlaylistEditor->SetTimeout(50);
if (mPlaylistEditor->hasSelected())
myPlaylistEditor->Content->SetTimeout(50);
if (myPlaylistEditor->Content->hasSelected())
{
vector<size_t> list;
mPlaylistEditor->GetSelected(list);
myPlaylistEditor->Content->GetSelected(list);
vector<size_t> origs(list);
while (Keypressed(input, Key.MvSongDown) && list.back() < mPlaylistEditor->Size()-1)
while (Keypressed(input, Key.MvSongDown) && list.back() < myPlaylistEditor->Content->Size()-1)
{
TraceMpdStatus();
timer = time(NULL);
for (vector<size_t>::reverse_iterator it = list.rbegin(); it != list.rend(); it++)
{
(*it)++;
mPlaylistEditor->Swap(*it, (*it)-1);
myPlaylistEditor->Content->Swap(*it, (*it)-1);
}
mPlaylistEditor->Highlight(list[(list.size()-1)/2]);
mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input);
myPlaylistEditor->Content->Highlight(list[(list.size()-1)/2]);
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
for (int i = list.size()-1; i >= 0; i--)
if (origs[i] != list[i])
Mpd->QueueMove(mPlaylistList->Current(), origs[i], list[i]);
Mpd->QueueMove(myPlaylistEditor->List->Current(), origs[i], list[i]);
Mpd->CommitQueue();
}
else
{
size_t from, to;
from = to = mPlaylistEditor->Choice();
while (Keypressed(input, Key.MvSongDown) && to < mPlaylistEditor->Size()-1)
from = to = myPlaylistEditor->Content->Choice();
while (Keypressed(input, Key.MvSongDown) && to < myPlaylistEditor->Content->Size()-1)
{
TraceMpdStatus();
timer = time(NULL);
to++;
mPlaylistEditor->Swap(to, to-1);
mPlaylistEditor->Scroll(wDown);
mPlaylistEditor->Refresh();
mPlaylistEditor->ReadKey(input);
myPlaylistEditor->Content->Swap(to, to-1);
myPlaylistEditor->Content->Scroll(wDown);
myPlaylistEditor->Content->Refresh();
myPlaylistEditor->Content->ReadKey(input);
}
if (from != to)
Mpd->Move(mPlaylistList->Current(), from, to);
Mpd->Move(myPlaylistEditor->List->Current(), from, to);
}
mPlaylistEditor->SetTimeout(ncmpcpp_window_timeout);
myPlaylistEditor->Content->SetTimeout(ncmpcpp_window_timeout);
}
}
else if (Keypressed(input, Key.Add))
@@ -1386,7 +1372,7 @@ int main(int argc, char *argv[])
|| (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itSong)
|| (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|| (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
|| (wCurrent == mEditorTags && !mEditorTags->Empty()))
{
List *mList = reinterpret_cast<Menu<Song> *>(wCurrent);
@@ -1406,7 +1392,7 @@ int main(int argc, char *argv[])
edited_song = myLibrary->Songs->at(id);
break;
case csPlaylistEditor:
edited_song = mPlaylistEditor->at(id);
edited_song = myPlaylistEditor->Content->at(id);
break;
case csTagEditor:
edited_song = mEditorTags->at(id);
@@ -1488,9 +1474,9 @@ int main(int argc, char *argv[])
ShowMessage("Cannot rename '%s' to '%s'!", old_dir.c_str(), new_dir.c_str());
}
}
else if (wCurrent == mPlaylistList || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itPlaylist))
else if (wCurrent == myPlaylistEditor->List || (wCurrent == myBrowser->Main() && myBrowser->Main()->Current().type == itPlaylist))
{
string old_name = wCurrent == mPlaylistList ? mPlaylistList->Current() : myBrowser->Main()->Current().name;
string old_name = wCurrent == myPlaylistEditor->List ? myPlaylistEditor->List->Current() : myBrowser->Main()->Current().name;
LockStatusbar();
Statusbar() << fmtBold << "Playlist: " << fmtBoldEnd;
string new_name = wFooter->GetString(old_name);
@@ -1501,7 +1487,7 @@ int main(int argc, char *argv[])
ShowMessage("Playlist '%s' renamed to '%s'", old_name.c_str(), new_name.c_str());
if (!Config.local_browser)
myBrowser->GetDirectory("/");
mPlaylistList->Clear(0);
myPlaylistEditor->List->Clear(0);
}
}
}
@@ -1510,7 +1496,7 @@ int main(int argc, char *argv[])
if ((wCurrent == myPlaylist->Main() && !myPlaylist->Main()->Empty())
|| (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| (wCurrent == myLibrary->Songs && !myLibrary->Songs->Empty())
|| (wCurrent == mPlaylistEditor && !mPlaylistEditor->Empty())
|| (wCurrent == myPlaylistEditor->Content && !myPlaylistEditor->Content->Empty())
# ifdef HAVE_TAGLIB_H
|| (wCurrent == mEditorTags && !mEditorTags->Empty())
# endif // HAVE_TAGLIB_H
@@ -1530,7 +1516,7 @@ int main(int argc, char *argv[])
s = &myLibrary->Songs->at(id);
break;
case csPlaylistEditor:
s = &mPlaylistEditor->at(id);
s = &myPlaylistEditor->Content->at(id);
break;
# ifdef HAVE_TAGLIB_H
case csTagEditor:
@@ -1594,7 +1580,7 @@ int main(int argc, char *argv[])
|| wCurrent == myBrowser->Main()
|| (wCurrent == mySearcher->Main() && !mySearcher->Main()->Current().first)
|| wCurrent == myLibrary->Songs
|| wCurrent == mPlaylistEditor
|| wCurrent == myPlaylistEditor->Content
# ifdef HAVE_TAGLIB_H
|| wCurrent == mEditorTags
# endif // HAVE_TAGLIB_H
@@ -1619,7 +1605,7 @@ int main(int argc, char *argv[])
|| wCurrent == myBrowser->Main()
|| wCurrent == mySearcher->Main()
|| wCurrent == myLibrary->Songs
|| wCurrent == mPlaylistEditor
|| wCurrent == myPlaylistEditor->Content
# ifdef HAVE_TAGLIB_H
|| wCurrent == mEditorTags
# endif // HAVE_TAGLIB_H
@@ -1640,7 +1626,7 @@ int main(int argc, char *argv[])
&& wCurrent != myBrowser->Main()
&& wCurrent != mySearcher->Main()
&& wCurrent != myLibrary->Songs
&& wCurrent != mPlaylistEditor)
&& wCurrent != myPlaylistEditor->Content)
continue;
List *mList = reinterpret_cast<Menu<Song> *>(wCurrent);
@@ -1701,7 +1687,7 @@ int main(int argc, char *argv[])
}
case csPlaylistEditor:
{
Song *s = new Song(mPlaylistEditor->at(*it));
Song *s = new Song(myPlaylistEditor->Content->at(*it));
result.push_back(s);
break;
}
@@ -1770,7 +1756,7 @@ int main(int argc, char *argv[])
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Refresh();
myPlaylistEditor->Refresh();
}
else
wCurrent->Refresh();
@@ -1818,7 +1804,7 @@ int main(int argc, char *argv[])
// refresh playlist's lists
if (!Config.local_browser && myBrowser->CurrentDir() == "/")
myBrowser->GetDirectory("/");
mPlaylistList->Clear(0); // make playlist editor update itself
myPlaylistEditor->List->Clear(0); // make playlist editor update itself
}
timer = time(NULL);
delete mDialog;
@@ -1927,10 +1913,10 @@ int main(int argc, char *argv[])
name = myLibrary->Songs->at(i).toString(Config.song_library_format);
break;
case csPlaylistEditor:
if (wCurrent == mPlaylistList)
name = mPlaylistList->at(i);
if (wCurrent == myPlaylistEditor->List)
name = myPlaylistEditor->List->at(i);
else
name = mPlaylistEditor->at(i).toString(Config.song_list_format);
name = myPlaylistEditor->Content->at(i).toString(Config.song_list_format);
break;
# ifdef HAVE_TAGLIB_H
case csTagEditor:
@@ -2142,7 +2128,7 @@ int main(int argc, char *argv[])
}
else if (Keypressed(input, Key.PlaylistEditor))
{
PlaylistEditor::SwitchTo();
myPlaylistEditor->SwitchTo();
}
# ifdef HAVE_TAGLIB_H
else if (Keypressed(input, Key.TagEditor))

View File

@@ -33,56 +33,60 @@ using namespace Global;
using namespace MPD;
using std::string;
Window *Global::wPlaylistEditorActiveCol;
Menu<string> *Global::mPlaylistList;
Menu<Song> *Global::mPlaylistEditor;
//Window *Global::wPlaylistEditorActiveCol;
//Menu<string> *Global::List;
//Menu<Song> *Global::Content;
namespace PlaylistEditor
{
size_t left_col_width;
size_t right_col_startx;
size_t right_col_width;
}
PlaylistEditor *myPlaylistEditor = new PlaylistEditor;
size_t PlaylistEditor::LeftColumnWidth;
size_t PlaylistEditor::RightColumnStartX;
size_t PlaylistEditor::RightColumnWidth;
void PlaylistEditor::Init()
{
left_col_width = COLS/3-1;
right_col_startx = left_col_width+1;
right_col_width = COLS-left_col_width-1;
LeftColumnWidth = COLS/3-1;
RightColumnStartX = LeftColumnWidth+1;
RightColumnWidth = COLS-LeftColumnWidth-1;
mPlaylistList = new Menu<string>(0, main_start_y, left_col_width, main_height, "Playlists", Config.main_color, brNone);
mPlaylistList->HighlightColor(Config.active_column_color);
mPlaylistList->SetTimeout(ncmpcpp_window_timeout);
mPlaylistList->SetItemDisplayer(Display::Generic);
List = new Menu<string>(0, main_start_y, LeftColumnWidth, main_height, "Playlists", Config.main_color, brNone);
List->HighlightColor(Config.active_column_color);
List->SetTimeout(ncmpcpp_window_timeout);
List->SetItemDisplayer(Display::Generic);
mPlaylistEditor = new Menu<Song>(right_col_startx, main_start_y, right_col_width, main_height, "Playlist's content", Config.main_color, brNone);
mPlaylistEditor->HighlightColor(Config.main_highlight_color);
mPlaylistEditor->SetTimeout(ncmpcpp_window_timeout);
mPlaylistEditor->SetSelectPrefix(&Config.selected_item_prefix);
mPlaylistEditor->SetSelectSuffix(&Config.selected_item_suffix);
mPlaylistEditor->SetItemDisplayer(Display::Songs);
mPlaylistEditor->SetItemDisplayerUserData(&Config.song_list_format);
Content = new Menu<Song>(RightColumnStartX, main_start_y, RightColumnWidth, main_height, "Playlist's content", Config.main_color, brNone);
Content->HighlightColor(Config.main_highlight_color);
Content->SetTimeout(ncmpcpp_window_timeout);
Content->SetSelectPrefix(&Config.selected_item_prefix);
Content->SetSelectSuffix(&Config.selected_item_suffix);
Content->SetItemDisplayer(Display::Songs);
Content->SetItemDisplayerUserData(&Config.song_list_format);
wPlaylistEditorActiveCol = mPlaylistList;
w = List;
}
void PlaylistEditor::Resize()
{
left_col_width = COLS/3-1;
right_col_startx = left_col_width+1;
right_col_width = COLS-left_col_width-1;
LeftColumnWidth = COLS/3-1;
RightColumnStartX = LeftColumnWidth+1;
RightColumnWidth = COLS-LeftColumnWidth-1;
mPlaylistList->Resize(left_col_width, main_height);
mPlaylistEditor->Resize(right_col_width, main_height);
List->Resize(LeftColumnWidth, main_height);
Content->Resize(RightColumnWidth, main_height);
mPlaylistEditor->MoveTo(right_col_startx, main_start_y);
Content->MoveTo(RightColumnStartX, main_start_y);
}
std::string PlaylistEditor::Title()
{
return "Playlist editor";
}
void PlaylistEditor::Refresh()
{
mPlaylistList->Display();
mvvline(main_start_y, right_col_startx-1, 0, main_height);
mPlaylistEditor->Display();
List->Display();
mvvline(main_start_y, RightColumnStartX-1, 0, main_height);
Content->Display();
}
void PlaylistEditor::SwitchTo()
@@ -101,39 +105,39 @@ void PlaylistEditor::SwitchTo()
redraw_header = 1;
PlaylistEditor::Refresh();
wCurrent = wPlaylistEditorActiveCol;
wCurrent = w;
current_screen = csPlaylistEditor;
UpdateSongList(mPlaylistEditor);
UpdateSongList(Content);
}
}
void PlaylistEditor::Update()
{
if (mPlaylistList->Empty())
if (List->Empty())
{
mPlaylistEditor->Clear(0);
Content->Clear(0);
TagList list;
Mpd->GetPlaylists(list);
sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (TagList::iterator it = list.begin(); it != list.end(); it++)
{
utf_to_locale(*it);
mPlaylistList->AddOption(*it);
List->AddOption(*it);
}
mPlaylistList->Window::Clear();
mPlaylistList->Refresh();
List->Window::Clear();
List->Refresh();
}
if (!mPlaylistList->Empty() && mPlaylistEditor->Empty())
if (!List->Empty() && Content->Empty())
{
mPlaylistEditor->Reset();
Content->Reset();
SongList list;
Mpd->GetPlaylistContent(locale_to_utf_cpy(mPlaylistList->Current()), list);
Mpd->GetPlaylistContent(locale_to_utf_cpy(List->Current()), list);
if (!list.empty())
mPlaylistEditor->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)"));
Content->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)"));
else
mPlaylistEditor->SetTitle("Playlist's content");
Content->SetTitle("Playlist's content");
bool bold = 0;
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
{
@@ -145,40 +149,64 @@ void PlaylistEditor::Update()
break;
}
}
mPlaylistEditor->AddOption(**it, bold);
Content->AddOption(**it, bold);
bold = 0;
}
FreeSongList(list);
mPlaylistEditor->Window::Clear();
mPlaylistEditor->Display();
Content->Window::Clear();
Content->Display();
}
if (wCurrent == mPlaylistEditor && mPlaylistEditor->Empty())
if (wCurrent == Content && Content->Empty())
{
mPlaylistEditor->HighlightColor(Config.main_highlight_color);
mPlaylistList->HighlightColor(Config.active_column_color);
wCurrent = wPlaylistEditorActiveCol = mPlaylistList;
Content->HighlightColor(Config.main_highlight_color);
List->HighlightColor(Config.active_column_color);
wCurrent = w = List;
}
if (mPlaylistEditor->Empty())
if (Content->Empty())
{
mPlaylistEditor->WriteXY(0, 0, 0, "Playlist is empty.");
mPlaylistEditor->Refresh();
Content->WriteXY(0, 0, 0, "Playlist is empty.");
Content->Refresh();
}
}
void PlaylistEditor::EnterPressed(bool add_n_play)
void PlaylistEditor::NextColumn()
{
if (w == List)
{
CLEAR_FIND_HISTORY;
List->HighlightColor(Config.main_highlight_color);
w->Refresh();
wCurrent = w = Content;
Content->HighlightColor(Config.active_column_color);
}
}
void PlaylistEditor::PrevColumn()
{
if (w == Content)
{
CLEAR_FIND_HISTORY;
Content->HighlightColor(Config.main_highlight_color);
w->Refresh();
wCurrent = w = List;
List->HighlightColor(Config.active_column_color);
}
}
void PlaylistEditor::AddToPlaylist(bool add_n_play)
{
SongList list;
if (wCurrent == mPlaylistList && !mPlaylistList->Empty())
if (wCurrent == List && !List->Empty())
{
Mpd->GetPlaylistContent(locale_to_utf_cpy(mPlaylistList->Current()), list);
Mpd->GetPlaylistContent(locale_to_utf_cpy(List->Current()), list);
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
Mpd->QueueAddSong(**it);
if (Mpd->CommitQueue())
{
ShowMessage("Loading playlist %s...", mPlaylistList->Current().c_str());
ShowMessage("Loading playlist %s...", List->Current().c_str());
Song &s = myPlaylist->Main()->at(myPlaylist->Main()->Size()-list.size());
if (s.GetHash() == list[0]->GetHash())
{
@@ -189,14 +217,14 @@ void PlaylistEditor::EnterPressed(bool add_n_play)
ShowMessage("%s", message_part_of_songs_added);
}
}
else if (wCurrent == mPlaylistEditor)
else if (wCurrent == Content)
{
if (!mPlaylistEditor->Empty())
if (!Content->Empty())
{
block_item_list_update = 1;
if (Config.ncmpc_like_songs_adding && mPlaylistEditor->isBold())
if (Config.ncmpc_like_songs_adding && Content->isBold())
{
long long hash = mPlaylistEditor->Current().GetHash();
long long hash = Content->Current().GetHash();
if (add_n_play)
{
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++)
@@ -221,19 +249,19 @@ void PlaylistEditor::EnterPressed(bool add_n_play)
}
}
Mpd->CommitQueue();
mPlaylistEditor->BoldOption(mPlaylistEditor->Choice(), 0);
Content->BoldOption(Content->Choice(), 0);
}
}
else
{
Song &s = mPlaylistEditor->at(mPlaylistEditor->Choice());
Song &s = Content->at(Content->Choice());
int id = Mpd->AddSong(s);
if (id >= 0)
{
ShowMessage("Added to playlist: %s", s.toString(Config.song_status_format).c_str());
if (add_n_play)
Mpd->PlayID(id);
mPlaylistEditor->BoldOption(mPlaylistEditor->Choice(), 1);
Content->BoldOption(Content->Choice(), 1);
}
}
}

View File

@@ -23,22 +23,36 @@
#include "ncmpcpp.h"
namespace PlaylistEditor
class PlaylistEditor : public Screen<Window>
{
void Init();
void Resize();
void Refresh();
void SwitchTo();
void Update();
public:
virtual void Init();
virtual void SwitchTo();
virtual void Resize();
void EnterPressed(bool = 1);
inline void SpacePressed();
}
virtual std::string Title();
void PlaylistEditor::SpacePressed()
{
EnterPressed(0);
}
virtual void Refresh();
virtual void Update();
virtual void EnterPressed() { AddToPlaylist(1); }
virtual void SpacePressed() { AddToPlaylist(0); }
void NextColumn();
void PrevColumn();
Menu<std::string> *List;
Menu<MPD::Song> *Content;
protected:
void AddToPlaylist(bool);
static size_t LeftColumnWidth;
static size_t RightColumnStartX;
static size_t RightColumnWidth;
};
extern PlaylistEditor *myPlaylistEditor;
#endif

View File

@@ -27,6 +27,7 @@
#include "helpers.h"
#include "media_library.h"
#include "playlist.h"
#include "playlist_editor.h"
#include "search_engine.h"
#include "settings.h"
#include "status_checker.h"
@@ -237,7 +238,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
}
else if (current_screen == csPlaylistEditor)
{
UpdateSongList(mPlaylistEditor);
UpdateSongList(myPlaylistEditor->Content);
}
}
}
@@ -249,7 +250,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
mEditorDirs->Clear(0);
# endif // HAVE_TAGLIB_H
myLibrary->Artists->Clear(0);
mPlaylistEditor->Clear(0);
myPlaylistEditor->Content->Clear(0);
}
if (changed.PlayerState)
{

View File

@@ -187,7 +187,7 @@ void TinyTagEditor::EnterPressed(Song &s)
}
else if (current_screen == csPlaylistEditor)
{
PlaylistEditor::Refresh();
myPlaylistEditor->Refresh();
}
else if (current_screen == csTagEditor)
{