From 2cc55280147877a88113112ac4c6d115e3e6d117 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 15 Dec 2008 20:29:45 +0100 Subject: [PATCH] improve code formatting --- src/ncmpcpp.cpp | 346 ++++++++++++++++++++++++------------------------ 1 file changed, 175 insertions(+), 171 deletions(-) diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 337ed811..cecb2cce 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -2759,178 +2759,182 @@ int main(int argc, char *argv[]) } else if (Keypressed(input, Key.AddSelected)) { - if (wCurrent == mPlaylist || wCurrent == mBrowser || wCurrent == mSearcher || wCurrent == mLibSongs || wCurrent == mPlaylistEditor) + if (wCurrent != mPlaylist + && wCurrent != mBrowser + && wCurrent != mSearcher + && wCurrent != mLibSongs + && wCurrent != mPlaylistEditor) + continue; + + List *mList = reinterpret_cast *>(wCurrent); + if (!mList->hasSelected()) { - List *mList = reinterpret_cast *>(wCurrent); - if (mList->hasSelected()) - { - vector list; - mList->GetSelected(list); - SongList result; - for (vector::const_iterator it = list.begin(); it != list.end(); it++) - { - switch (current_screen) - { - case csPlaylist: - { - Song *s = new Song(mPlaylist->at(*it)); - result.push_back(s); - break; - } - case csBrowser: - { - const Item &item = mBrowser->at(*it); - switch (item.type) - { - case itDirectory: - { - if (browsed_dir != "/") - Mpd->GetDirectoryRecursive(browsed_dir + "/" + item.name, result); - else - Mpd->GetDirectoryRecursive(item.name, result); - break; - } - case itSong: - { - Song *s = new Song(*item.song); - result.push_back(s); - break; - } - case itPlaylist: - { - Mpd->GetPlaylistContent(item.name, result); - break; - } - } - break; - } - case csSearcher: - { - Song *s = mSearcher->at(*it).second; - result.push_back(s); - break; - } - case csLibrary: - { - Song *s = new Song(mLibSongs->at(*it)); - result.push_back(s); - break; - } - case csPlaylistEditor: - { - Song *s = new Song(mPlaylistEditor->at(*it)); - result.push_back(s); - break; - } - default: - break; - } - } - - size_t dialog_width = COLS*0.8; - size_t dialog_height = LINES*0.6; - Menu *mDialog = new Menu((COLS-dialog_width)/2, (LINES-dialog_height)/2, dialog_width, dialog_height, "Add selected items to...", Config.main_color, Config.window_border); - mDialog->SetTimeout(ncmpcpp_window_timeout); - mDialog->SetItemDisplayer(GenericDisplayer); - - mDialog->AddOption("Current MPD playlist"); - mDialog->AddOption("Create new playlist (m3u file)"); - mDialog->AddSeparator(); - TagList playlists; - Mpd->GetPlaylists(playlists); - for (TagList::const_iterator it = playlists.begin(); it != playlists.end(); it++) - mDialog->AddOption("'" + *it + "' playlist"); - mDialog->AddSeparator(); - mDialog->AddOption("Cancel"); - - mDialog->Display(); - prev_screen = current_screen; - current_screen = csOther; - - while (!Keypressed(input, Key.Enter)) - { - TraceMpdStatus(); - mDialog->Refresh(); - mDialog->ReadKey(input); - - if (Keypressed(input, Key.Up)) - mDialog->Scroll(wUp); - else if (Keypressed(input, Key.Down)) - mDialog->Scroll(wDown); - else if (Keypressed(input, Key.PageUp)) - mDialog->Scroll(wPageUp); - else if (Keypressed(input, Key.PageDown)) - mDialog->Scroll(wPageDown); - else if (Keypressed(input, Key.Home)) - mDialog->Scroll(wHome); - else if (Keypressed(input, Key.End)) - mDialog->Scroll(wEnd); - } - - size_t id = mDialog->Choice(); - - redraw_screen = 1; - if (current_screen == csLibrary) - { - REFRESH_MEDIA_LIBRARY_SCREEN; - } - else if (current_screen == csPlaylistEditor) - { - REFRESH_PLAYLIST_EDITOR_SCREEN; - } - else - wCurrent->Refresh(); - - if (id == 0) - { - for (SongList::const_iterator it = result.begin(); it != result.end(); it++) - Mpd->QueueAddSong(**it); - if (Mpd->CommitQueue()) - { - ShowMessage("Selected items added!"); - Song &s = mPlaylist->at(mPlaylist->Size()-result.size()); - if (s.GetHash() != result[0]->GetHash()) - ShowMessage("%s", message_part_of_songs_added); - } - } - else if (id == 1) - { - LockStatusbar(); - Statusbar() << "Save playlist as: "; - string playlist = wFooter->GetString(); - UnlockStatusbar(); - if (!playlist.empty()) - { - for (SongList::const_iterator it = result.begin(); it != result.end(); it++) - Mpd->QueueAddToPlaylist(playlist, **it); - Mpd->CommitQueue(); - ShowMessage("Selected items added to playlist '%s'!", playlist.c_str()); - } - - } - else if (id > 1 && id < mDialog->Size()-1) - { - for (SongList::const_iterator it = result.begin(); it != result.end(); it++) - Mpd->QueueAddToPlaylist(playlists[id-3], **it); - Mpd->CommitQueue(); - ShowMessage("Selected items added to playlist '%s'!", playlists[id-3].c_str()); - } - - if (id != mDialog->Size()-1) - { - // refresh playlist's lists - if (!Config.local_browser && browsed_dir == "/") - GetDirectory("/"); - mPlaylistList->Clear(0); // make playlist editor update itself - } - current_screen = prev_screen; - timer = time(NULL); - delete mDialog; - FreeSongList(result); - } - else - ShowMessage("No selected items!"); + ShowMessage("No selected items!"); + continue; } + + vector list; + mList->GetSelected(list); + SongList result; + for (vector::const_iterator it = list.begin(); it != list.end(); it++) + { + switch (current_screen) + { + case csPlaylist: + { + Song *s = new Song(mPlaylist->at(*it)); + result.push_back(s); + break; + } + case csBrowser: + { + const Item &item = mBrowser->at(*it); + switch (item.type) + { + case itDirectory: + { + if (browsed_dir != "/") + Mpd->GetDirectoryRecursive(browsed_dir + "/" + item.name, result); + else + Mpd->GetDirectoryRecursive(item.name, result); + break; + } + case itSong: + { + Song *s = new Song(*item.song); + result.push_back(s); + break; + } + case itPlaylist: + { + Mpd->GetPlaylistContent(item.name, result); + break; + } + } + break; + } + case csSearcher: + { + Song *s = mSearcher->at(*it).second; + result.push_back(s); + break; + } + case csLibrary: + { + Song *s = new Song(mLibSongs->at(*it)); + result.push_back(s); + break; + } + case csPlaylistEditor: + { + Song *s = new Song(mPlaylistEditor->at(*it)); + result.push_back(s); + break; + } + default: + break; + } + } + + size_t dialog_width = COLS*0.8; + size_t dialog_height = LINES*0.6; + Menu *mDialog = new Menu((COLS-dialog_width)/2, (LINES-dialog_height)/2, dialog_width, dialog_height, "Add selected items to...", Config.main_color, Config.window_border); + mDialog->SetTimeout(ncmpcpp_window_timeout); + mDialog->SetItemDisplayer(GenericDisplayer); + + mDialog->AddOption("Current MPD playlist"); + mDialog->AddOption("Create new playlist (m3u file)"); + mDialog->AddSeparator(); + TagList playlists; + Mpd->GetPlaylists(playlists); + for (TagList::const_iterator it = playlists.begin(); it != playlists.end(); it++) + mDialog->AddOption("'" + *it + "' playlist"); + mDialog->AddSeparator(); + mDialog->AddOption("Cancel"); + + mDialog->Display(); + prev_screen = current_screen; + current_screen = csOther; + + while (!Keypressed(input, Key.Enter)) + { + TraceMpdStatus(); + mDialog->Refresh(); + mDialog->ReadKey(input); + + if (Keypressed(input, Key.Up)) + mDialog->Scroll(wUp); + else if (Keypressed(input, Key.Down)) + mDialog->Scroll(wDown); + else if (Keypressed(input, Key.PageUp)) + mDialog->Scroll(wPageUp); + else if (Keypressed(input, Key.PageDown)) + mDialog->Scroll(wPageDown); + else if (Keypressed(input, Key.Home)) + mDialog->Scroll(wHome); + else if (Keypressed(input, Key.End)) + mDialog->Scroll(wEnd); + } + + size_t id = mDialog->Choice(); + + redraw_screen = 1; + if (current_screen == csLibrary) + { + REFRESH_MEDIA_LIBRARY_SCREEN; + } + else if (current_screen == csPlaylistEditor) + { + REFRESH_PLAYLIST_EDITOR_SCREEN; + } + else + wCurrent->Refresh(); + + if (id == 0) + { + for (SongList::const_iterator it = result.begin(); it != result.end(); it++) + Mpd->QueueAddSong(**it); + if (Mpd->CommitQueue()) + { + ShowMessage("Selected items added!"); + Song &s = mPlaylist->at(mPlaylist->Size()-result.size()); + if (s.GetHash() != result[0]->GetHash()) + ShowMessage("%s", message_part_of_songs_added); + } + } + else if (id == 1) + { + LockStatusbar(); + Statusbar() << "Save playlist as: "; + string playlist = wFooter->GetString(); + UnlockStatusbar(); + if (!playlist.empty()) + { + for (SongList::const_iterator it = result.begin(); it != result.end(); it++) + Mpd->QueueAddToPlaylist(playlist, **it); + Mpd->CommitQueue(); + ShowMessage("Selected items added to playlist '%s'!", playlist.c_str()); + } + } + else if (id > 1 && id < mDialog->Size()-1) + { + for (SongList::const_iterator it = result.begin(); it != result.end(); it++) + Mpd->QueueAddToPlaylist(playlists[id-3], **it); + Mpd->CommitQueue(); + ShowMessage("Selected items added to playlist '%s'!", playlists[id-3].c_str()); + } + + if (id != mDialog->Size()-1) + { + // refresh playlist's lists + if (!Config.local_browser && browsed_dir == "/") + GetDirectory("/"); + mPlaylistList->Clear(0); // make playlist editor update itself + } + current_screen = prev_screen; + timer = time(NULL); + delete mDialog; + FreeSongList(result); } else if (Keypressed(input, Key.Crop)) { @@ -3109,7 +3113,7 @@ int main(int argc, char *argv[]) } } ShowMessage("Searching finished!"); - + if (Config.wrapped_search ? vFoundPositions.empty() : found_pos < 0) ShowMessage("Unable to find \"%s\"", findme.c_str()); else