diff --git a/doc/ncmpcpp_keys b/doc/ncmpcpp_keys index 4221ef52..d725ab36 100644 --- a/doc/ncmpcpp_keys +++ b/doc/ncmpcpp_keys @@ -51,6 +51,8 @@ # #key_playlist_editor = '6' 270 # +#key_album_tag_editor = '7' 271 +# #key_stop = 's' # #key_pause = 'P' diff --git a/doc/ncmpcpprc b/doc/ncmpcpprc index 56a3fd3e..9f8d84b1 100644 --- a/doc/ncmpcpprc +++ b/doc/ncmpcpprc @@ -62,18 +62,22 @@ # #song_list_format = "{[.green](%l)[/green] }{%a - }{%t}|{[.white]%f[/white]}" # -#song_status_format = "{(%l) }{%a - }{%t}|{%f}" -# -#song_window_title_format = "{%a - }{%t}|{%f}" -# #song_library_format = "{%n - }{%t}|{%f}" # +#tag_editor_album_format = "{(%y) }%b" +# #browser_playlist_prefix = "[.red]playlist[/red] " # #selected_item_prefix = "[.magenta]" # #selected_item_suffix = "[/magenta]" # +## colors are not supported for below veriables +# +#song_status_format = "{(%l) }{%a - }{%t}|{%f}" +# +#song_window_title_format = "{%a - }{%t}|{%f}" +# ##### columns settings ##### ## ## syntax of song columns list format is "column column etc." diff --git a/src/helpers.cpp b/src/helpers.cpp index bcf0c0f0..c6930632 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -59,6 +59,38 @@ extern string UNKNOWN_ARTIST; extern string UNKNOWN_TITLE; extern string UNKNOWN_ALBUM; +bool CaseInsensitiveSorting::operator()(string a, string b) +{ + //a = Window::OmitBBCodes(a); + //b = Window::OmitBBCodes(b); + transform(a.begin(), a.end(), a.begin(), tolower); + transform(b.begin(), b.end(), b.begin(), tolower); + return a < b; +} + +bool CaseInsensitiveSorting::operator()(Song *sa, Song *sb) +{ + string a = sa->GetShortFilename(); + string b = sb->GetShortFilename(); + transform(a.begin(), a.end(), a.begin(), tolower); + transform(b.begin(), b.end(), b.begin(), tolower); + return a < b; +} + +bool CaseInsensitiveSorting::operator()(const Item &a, const Item &b) +{ + if (a.type == b.type) + { + string sa = a.type == itSong ? a.song->GetShortFilename() : a.name; + string sb = b.type == itSong ? b.song->GetShortFilename() : b.name; + transform(sa.begin(), sa.end(), sa.begin(), tolower); + transform(sb.begin(), sb.end(), sb.begin(), tolower); + return sa < sb; + } + else + return a.type < b.type; +} + void UpdateItemList(Menu *menu) { bool bold = 0; @@ -981,20 +1013,6 @@ bool GetSongInfo(Song &s) return true; } -bool SortDirectory(const Item &a, const Item &b) -{ - if (a.type == b.type) - { - string sa = a.type == itSong ? a.song->GetShortFilename() : a.name; - string sb = b.type == itSong ? b.song->GetShortFilename() : b.name; - transform(sa.begin(), sa.end(), sa.begin(), tolower); - transform(sb.begin(), sb.end(), sb.begin(), tolower); - return sa < sb; - } - else - return a.type < b.type; -} - void GetDirectory(string dir, string subdir) { int highlightme = -1; @@ -1016,7 +1034,7 @@ void GetDirectory(string dir, string subdir) ItemList list; Mpd->GetDirectory(dir, list); - sort(list.begin(), list.end(), SortDirectory); + sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (ItemList::iterator it = list.begin(); it != list.end(); it++) { diff --git a/src/helpers.h b/src/helpers.h index 66bd0641..a8113974 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -30,15 +30,12 @@ extern ncmpcpp_config Config; -class CaseInsensitiveComparison +class CaseInsensitiveSorting { public: - bool operator()(string a, string b) - { - transform(a.begin(), a.end(), a.begin(), tolower); - transform(b.begin(), b.end(), b.begin(), tolower); - return a < b; - } + bool operator()(string, string); + bool operator()(Song *, Song *); + bool operator()(const Item &, const Item &); }; void UpdateItemList(Menu *); @@ -59,7 +56,6 @@ string DisplayColumns(string); string DisplaySongInColumns(const Song &, void *); string DisplaySong(const Song &, void * = &Config.song_list_format); void ShowMessage(const string &, int = Config.message_delay_time); -bool SortDirectory(const Item &a, const Item &b); void GetDirectory(string, string = "/"); #ifdef HAVE_TAGLIB_H bool WriteTags(Song &); diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 7477bfbe..8db0446c 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -74,8 +74,8 @@ ncmpcpp_config Config; ncmpcpp_keys Key; SongList vSearched; -std::map vLibAlbums; -std::map vEditorAlbums; +std::map vLibAlbums; +std::map vEditorAlbums; vector vFoundPositions; int found_pos = 0; @@ -504,7 +504,7 @@ int main(int argc, char *argv[]) mLibAlbums->Clear(0); mLibSongs->Clear(0); Mpd->GetArtists(list); - sort(list.begin(), list.end(), CaseInsensitiveComparison()); + sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (TagList::const_iterator it = list.begin(); it != list.end(); it++) mLibArtists->AddOption(*it); mLibArtists->Window::Clear(); @@ -673,17 +673,7 @@ int main(int argc, char *argv[]) Mpd->StartSearch(1); Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, *it); Mpd->CommitSearch(l); - for (SongList::const_iterator j = l.begin(); j != l.end(); j++) - { - if ((*j)->GetYear() != EMPTY_TAG) - { - vEditorAlbums["(" + (*j)->GetYear() + ") " + *it] = *it; - written = 1; - break; - } - } - if (!written) - vEditorAlbums[*it] = *it; + vEditorAlbums[DisplaySong(*l[0], &Config.tag_editor_album_format)] = *it; FreeSongList(l); } for (std::map::const_iterator it = vEditorAlbums.begin(); it != vEditorAlbums.end(); it++) @@ -699,6 +689,7 @@ int main(int argc, char *argv[]) Mpd->StartSearch(1); Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, vEditorAlbums[mEditorAlbums->GetOption()]); Mpd->CommitSearch(list); + sort(list.begin(), list.end(), CaseInsensitiveSorting()); for (SongList::iterator it = list.begin(); it != list.end(); it++) mEditorTags->AddOption(**it); FreeSongList(list); @@ -1330,7 +1321,8 @@ int main(int argc, char *argv[]) case csAlbumEditor: { void (Song::*set)(const string &) = 0; - switch (mEditorTagTypes->GetRealChoice()) + int id = mEditorTagTypes->GetRealChoice(); + switch (id) { case 0: set = &Song::SetTitle; @@ -1346,6 +1338,29 @@ int main(int argc, char *argv[]) break; case 4: set = &Song::SetTrack; + if (wCurrent == mEditorTagTypes) + { + LOCK_STATUSBAR; + wFooter->WriteXY(0, Config.statusbar_visibility, "Number tracks? [y/n] ", 1); + curs_set(1); + int in = 0; + do + { + TraceMpdStatus(); + wFooter->ReadKey(in); + } + while (in != 'y' && in != 'n'); + if (in == 'y') + { + for (int i = 0; i < mEditorTags->Size(); i++) + mEditorTags->at(i).SetTrack(i+1); + ShowMessage("Tracks numbered!"); + } + else + ShowMessage("Aborted!"); + curs_set(0); + UNLOCK_STATUSBAR; + } break; case 5: set = &Song::SetGenre; @@ -1354,9 +1369,11 @@ int main(int argc, char *argv[]) set = &Song::SetComment; break; case 8: // reset + { mEditorTags->Clear(0); ShowMessage("Changes reset"); continue; + } case 9: // save { bool success = 1; @@ -1387,7 +1404,7 @@ int main(int argc, char *argv[]) default: break; } - if (wCurrent == mEditorTagTypes && set != NULL) + if (wCurrent == mEditorTagTypes && id != 0 && id != 4 && set != NULL) { LOCK_STATUSBAR; wFooter->WriteXY(0, Config.statusbar_visibility, "[.b]" + mEditorTagTypes->GetOption() + "[/b]: ", 1); @@ -1395,9 +1412,8 @@ int main(int argc, char *argv[]) string new_tag = wFooter->GetString(mEditorTags->GetOption()); mEditorTags->at(mEditorTags->GetChoice()).GetEmptyFields(0); UNLOCK_STATUSBAR; - if (!new_tag.empty()) - for (int i = 0; i < mEditorTags->Size(); i++) - (mEditorTags->at(i).*set)(new_tag); + for (int i = 0; i < mEditorTags->Size(); i++) + (mEditorTags->at(i).*set)(new_tag); } else if (wCurrent == mEditorTags && set != NULL) { @@ -2801,6 +2817,7 @@ int main(int argc, char *argv[]) mEditorTagTypes->AddSeparator(); mEditorTagTypes->AddOption("Reset"); mEditorTagTypes->AddOption("Save"); + } wCurrent = mEditorAlbums; diff --git a/src/settings.cpp b/src/settings.cpp index b4bbb0b1..075335aa 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -152,6 +152,7 @@ void DefaultConfiguration(ncmpcpp_config &conf) conf.song_status_format = "{(%l) }{%a - }{%t}|{%f}"; conf.song_window_title_format = "{%a - }{%t}|{%f}"; conf.song_library_format = "{%n - }{%t}|{%f}"; + conf.tag_editor_album_format = "{(%y) }%b"; conf.browser_playlist_prefix = "[.red](playlist)[/red] "; conf.selected_item_prefix = "[.magenta]"; conf.selected_item_suffix = "[/magenta]"; @@ -324,6 +325,8 @@ void ReadKeys(ncmpcpp_keys &keys) GetKeys(*it, keys.MediaLibrary); else if (it->find("key_playlist_editor ") != string::npos) GetKeys(*it, keys.PlaylistEditor); + else if (it->find("key_album_tag_editor ") != string::npos) + GetKeys(*it, keys.AlbumEditor); else if (it->find("key_stop ") != string::npos) GetKeys(*it, keys.Stop); else if (it->find("key_pause ") != string::npos) @@ -469,6 +472,11 @@ void ReadConfiguration(ncmpcpp_config &conf) if (!v.empty()) conf.song_library_format = v; } + else if (it->find("tag_editor_album_format") != string::npos) + { + if (!v.empty()) + conf.tag_editor_album_format = v; + } else if (it->find("browser_playlist_prefix") != string::npos) { if (!v.empty()) diff --git a/src/settings.h b/src/settings.h index 3fb4e9cb..d1ea7a6e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -96,6 +96,7 @@ struct ncmpcpp_config string song_status_format; string song_window_title_format; string song_library_format; + string tag_editor_album_format; string browser_playlist_prefix; string selected_item_prefix; diff --git a/src/song.h b/src/song.h index ba8f65e7..dd75affa 100644 --- a/src/song.h +++ b/src/song.h @@ -68,7 +68,9 @@ class Song void SetTitle(const string &str) { itsTitle = str; } void SetAlbum(const string &str) { itsAlbum = str; } void SetTrack(const string &str) { itsTrack = str.empty() ? "" : IntoStr(StrToInt(str)); } + void SetTrack(int track) { itsTrack = IntoStr(track); } void SetYear(const string &str) { itsYear = str.empty() ? "" : IntoStr(StrToInt(str)); } + void SetYear(int year) { itsYear = IntoStr(year); } void SetGenre(const string &str) { itsGenre = str; } void SetComment(const string &str) { itsComment = str; } void SetPosition(int pos) { itsPosition = pos; } diff --git a/src/window.cpp b/src/window.cpp index ece64916..37e0a663 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -433,6 +433,9 @@ string Window::GetString(const string &base, unsigned int length) const do { + mvwprintw(itsWindow, y, minx, "%ls",tmp.c_str()); + wclrtoeol(itsWindow); + if (itsGetStringHelper) itsGetStringHelper(); wmove(itsWindow,y,x); @@ -465,7 +468,7 @@ string Window::GetString(const string &base, unsigned int length) const if ((maxx-x) < 1) break; tmp.erase(tmp.end()-(maxx-x)); wmove(itsWindow,y,x); // for backspace - wdelch(itsWindow); + //wdelch(itsWindow); maxx--; break; } @@ -494,7 +497,7 @@ string Window::GetString(const string &base, unsigned int length) const else tmp.insert(tmp.end()-(maxx-x),wc_in); - winsstr(itsWindow, tmp_in.c_str()); + //winsstr(itsWindow, tmp_in.c_str()); tmp_in.clear(); x++;