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; extern Menu<MPD::Song> *mEditorTags;
# endif // HAVE_TAGLIB_H # endif // HAVE_TAGLIB_H
extern Window *wPlaylistEditorActiveCol; // extern Window *wPlaylistEditorActiveCol;
extern Menu<std::string> *mPlaylistList; // extern Menu<std::string> *mPlaylistList;
extern Menu<MPD::Song> *mPlaylistEditor; // extern Menu<MPD::Song> *myPlaylistEditor->Content;
extern Scrollpad *sHelp; extern Scrollpad *sHelp;
extern Scrollpad *sLyrics; extern Scrollpad *sLyrics;

View File

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

View File

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

View File

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

View File

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

View File

@@ -23,22 +23,36 @@
#include "ncmpcpp.h" #include "ncmpcpp.h"
namespace PlaylistEditor class PlaylistEditor : public Screen<Window>
{ {
void Init(); public:
void Resize(); virtual void Init();
void Refresh(); virtual void SwitchTo();
void SwitchTo(); virtual void Resize();
void Update();
void EnterPressed(bool = 1); virtual std::string Title();
inline void SpacePressed();
}
void PlaylistEditor::SpacePressed() virtual void Refresh();
{ virtual void Update();
EnterPressed(0);
} 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 #endif

View File

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

View File

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