From 27687fd2b12914e9960aa78a1d12d620ac049cf7 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 15 Sep 2009 16:36:26 +0000 Subject: [PATCH] pass Buffer/Window to ShowTag() by reference returning new Buffer and passing it to Window by operator<<() was rather bad idea since it required unnecessary copying. --- src/display.cpp | 20 ++++++------ src/helpers.cpp | 10 ------ src/helpers.h | 10 ++++-- src/info.cpp | 48 ++++++++++++++-------------- src/info.h | 1 - src/search_engine.cpp | 69 +++++++++++++++++++++++++++++------------ src/tiny_tag_editor.cpp | 64 +++++++++++++++++++++++++------------- 7 files changed, 133 insertions(+), 89 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index a913ea99..197ca366 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -242,34 +242,34 @@ void Display::Tags(const MPD::Song &s, void *data, Menu *menu) switch (static_cast *>(data)->Choice()) { case 0: - *menu << ShowTag(s.GetTitle()); + ShowTag(*menu, s.GetTitle()); return; case 1: - *menu << ShowTag(s.GetArtist()); + ShowTag(*menu, s.GetArtist()); return; case 2: - *menu << ShowTag(s.GetAlbum()); + ShowTag(*menu, s.GetAlbum()); return; case 3: - *menu << ShowTag(s.GetDate()); + ShowTag(*menu, s.GetDate()); return; case 4: - *menu << ShowTag(s.GetTrack()); + ShowTag(*menu, s.GetTrack()); return; case 5: - *menu << ShowTag(s.GetGenre()); + ShowTag(*menu, s.GetGenre()); return; case 6: - *menu << ShowTag(s.GetComposer()); + ShowTag(*menu, s.GetComposer()); return; case 7: - *menu << ShowTag(s.GetPerformer()); + ShowTag(*menu, s.GetPerformer()); return; case 8: - *menu << ShowTag(s.GetDisc()); + ShowTag(*menu, s.GetDisc()); return; case 9: - *menu << ShowTag(s.GetComment()); + ShowTag(*menu, s.GetComment()); return; case 11: if (s.GetNewName().empty()) diff --git a/src/helpers.cpp b/src/helpers.cpp index e3cc898e..4cbaa9b1 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -367,16 +367,6 @@ std::string ExtractTopDirectory(const std::string &s) return slash != std::string::npos ? s.substr(++slash) : s; } -Buffer ShowTag(const std::string &tag) -{ - Buffer result; - if (tag.empty()) - result << Config.empty_tags_color << Config.empty_tag << clEnd; - else - result << tag; - return result; -} - #ifdef _UTF8 std::basic_string Scroller(const std::string &str, size_t &pos, size_t width) { diff --git a/src/helpers.h b/src/helpers.h index 9f388e9f..0f8a0c21 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -95,6 +95,14 @@ template void String2Buffer(const std::basic_string &s, basic_bu } } +template void ShowTag(T &buf, const std::string &tag) +{ + if (tag.empty()) + buf << Config.empty_tags_color << Config.empty_tag << clEnd; + else + buf << tag; +} + inline bool Keypressed(int in, const int *key) { return in == key[0] || in == key[1]; @@ -113,8 +121,6 @@ std::string GetLineValue(std::string &, char = '"', char = '"', bool = 0); void RemoveTheWord(std::string &s); std::string ExtractTopDirectory(const std::string &); -Buffer ShowTag(const std::string &); - #ifdef _UTF8 std::basic_string Scroller(const std::string &str, size_t &pos, size_t width); #endif // _UTF8 diff --git a/src/info.cpp b/src/info.cpp index 2c18630b..6f984c1e 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -345,7 +345,9 @@ void Info::PrepareSong(MPD::Song &s) # endif // HAVE_TAGLIB_H *w << fmtBold << Config.color1 << "Filename: " << fmtBoldEnd << Config.color2 << s.GetName() << "\n" << clEnd; - *w << fmtBold << "Directory: " << fmtBoldEnd << Config.color2 << ShowTag(s.GetDirectory()) << "\n\n" << clEnd; + *w << fmtBold << "Directory: " << fmtBoldEnd << Config.color2; + ShowTag(*w, s.GetDirectory()); + *w << "\n\n" << clEnd; *w << fmtBold << "Length: " << fmtBoldEnd << Config.color2 << s.GetLength() << "\n" << clEnd; # ifdef HAVE_TAGLIB_H if (!f.isNull()) @@ -357,29 +359,25 @@ void Info::PrepareSong(MPD::Song &s) # endif // HAVE_TAGLIB_H *w << clDefault; - *w << fmtBold << "\nTitle: " << fmtBoldEnd << ShowTag(s.GetTitle()); - *w << fmtBold << "\nArtist: " << fmtBoldEnd << ShowTag(s.GetArtist()); - *w << fmtBold << "\nAlbum: " << fmtBoldEnd << ShowTag(s.GetAlbum()); - *w << fmtBold << "\nYear: " << fmtBoldEnd << ShowTag(s.GetDate()); - *w << fmtBold << "\nTrack: " << fmtBoldEnd << ShowTag(s.GetTrack()); - *w << fmtBold << "\nGenre: " << fmtBoldEnd << ShowTag(s.GetGenre()); - *w << fmtBold << "\nComposer: " << fmtBoldEnd << ShowTag(s.GetComposer()); - *w << fmtBold << "\nPerformer: " << fmtBoldEnd << ShowTag(s.GetPerformer()); - *w << fmtBold << "\nDisc: " << fmtBoldEnd << ShowTag(s.GetDisc()); - *w << fmtBold << "\nComment: " << fmtBoldEnd << ShowTag(s.GetComment()); -} - -basic_buffer Info::ShowTag(const std::string &tag) -{ -# ifdef _UTF8 - WBuffer result; - if (tag.empty()) - result << Config.empty_tags_color << ToWString(Config.empty_tag) << clEnd; - else - result << ToWString(tag); - return result; -# else - return ::ShowTag(tag); -# endif + *w << fmtBold << "\nTitle: " << fmtBoldEnd; + ShowTag(*w, s.GetTitle()); + *w << fmtBold << "\nArtist: " << fmtBoldEnd; + ShowTag(*w, s.GetArtist()); + *w << fmtBold << "\nAlbum: " << fmtBoldEnd; + ShowTag(*w, s.GetAlbum()); + *w << fmtBold << "\nYear: " << fmtBoldEnd; + ShowTag(*w, s.GetDate()); + *w << fmtBold << "\nTrack: " << fmtBoldEnd; + ShowTag(*w, s.GetTrack()); + *w << fmtBold << "\nGenre: " << fmtBoldEnd; + ShowTag(*w, s.GetGenre()); + *w << fmtBold << "\nComposer: " << fmtBoldEnd; + ShowTag(*w, s.GetComposer()); + *w << fmtBold << "\nPerformer: " << fmtBoldEnd; + ShowTag(*w, s.GetPerformer()); + *w << fmtBold << "\nDisc: " << fmtBoldEnd; + ShowTag(*w, s.GetDisc()); + *w << fmtBold << "\nComment: " << fmtBoldEnd; + ShowTag(*w, s.GetComment()); } diff --git a/src/info.h b/src/info.h index a604f0f1..553f37d4 100644 --- a/src/info.h +++ b/src/info.h @@ -58,7 +58,6 @@ class Info : public Screen std::string itsFilenamePath; void PrepareSong(MPD::Song &); - static basic_buffer ShowTag(const std::string &); # ifdef HAVE_CURL_CURL_H static void *PrepareArtist(void *); diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 324a2d0a..1c37529e 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -103,70 +103,80 @@ void SearchEngine::EnterPressed() { Statusbar() << fmtBold << "Any: " << fmtBoldEnd; itsPattern.Any(wFooter->GetString(itsPattern.Any())); - *w->Current().first << fmtBold << "Any: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.Any()); + *w->Current().first << fmtBold << "Any: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.Any()); break; } case 1: { Statusbar() << fmtBold << "Artist: " << fmtBoldEnd; itsPattern.SetArtist(wFooter->GetString(itsPattern.GetArtist())); - *w->Current().first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetArtist()); + *w->Current().first << fmtBold << "Artist: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetArtist()); break; } case 2: { Statusbar() << fmtBold << "Title: " << fmtBoldEnd; itsPattern.SetTitle(wFooter->GetString(itsPattern.GetTitle())); - *w->Current().first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetTitle()); + *w->Current().first << fmtBold << "Title: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetTitle()); break; } case 3: { Statusbar() << fmtBold << "Album: " << fmtBoldEnd; itsPattern.SetAlbum(wFooter->GetString(itsPattern.GetAlbum())); - *w->Current().first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetAlbum()); + *w->Current().first << fmtBold << "Album: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetAlbum()); break; } case 4: { Statusbar() << fmtBold << "Filename: " << fmtBoldEnd; itsPattern.SetFile(wFooter->GetString(itsPattern.GetFile())); - *w->Current().first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetFile()); + *w->Current().first << fmtBold << "Filename: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetFile()); break; } case 5: { Statusbar() << fmtBold << "Composer: " << fmtBoldEnd; itsPattern.SetComposer(wFooter->GetString(itsPattern.GetComposer())); - *w->Current().first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetComposer()); + *w->Current().first << fmtBold << "Composer: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetComposer()); break; } case 6: { Statusbar() << fmtBold << "Performer: " << fmtBoldEnd; itsPattern.SetPerformer(wFooter->GetString(itsPattern.GetPerformer())); - *w->Current().first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetPerformer()); + *w->Current().first << fmtBold << "Performer:" << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetPerformer()); break; } case 7: { Statusbar() << fmtBold << "Genre: " << fmtBoldEnd; itsPattern.SetGenre(wFooter->GetString(itsPattern.GetGenre())); - *w->Current().first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetGenre()); + *w->Current().first << fmtBold << "Genre: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetGenre()); break; } case 8: { Statusbar() << fmtBold << "Year: " << fmtBoldEnd; itsPattern.SetDate(wFooter->GetString(itsPattern.GetDate())); - *w->Current().first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetDate()); + *w->Current().first << fmtBold << "Year: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetDate()); break; } case 9: { Statusbar() << fmtBold << "Comment: " << fmtBoldEnd; itsPattern.SetComment(wFooter->GetString(itsPattern.GetComment())); - *w->Current().first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetComment()); + *w->Current().first << fmtBold << "Comment: " << fmtBoldEnd << ' '; + ShowTag(*w->Current().first, itsPattern.GetComment()); break; } case 11: @@ -344,16 +354,35 @@ void SearchEngine::Prepare() catch (List::InvalidItem) { } } - *w->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.Any()); - *w->at(1).first << fmtBold << "Artist: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetArtist()); - *w->at(2).first << fmtBold << "Title: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetTitle()); - *w->at(3).first << fmtBold << "Album: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetAlbum()); - *w->at(4).first << fmtBold << "Filename: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetName()); - *w->at(5).first << fmtBold << "Composer: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetComposer()); - *w->at(6).first << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetPerformer()); - *w->at(7).first << fmtBold << "Genre: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetGenre()); - *w->at(8).first << fmtBold << "Year: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetDate()); - *w->at(9).first << fmtBold << "Comment: " << fmtBoldEnd << ' ' << ShowTag(itsPattern.GetComment()); + *w->at(0).first << fmtBold << "Any: " << fmtBoldEnd << ' '; + ShowTag(*w->at(0).first, itsPattern.Any()); + + *w->at(1).first << fmtBold << "Artist: " << fmtBoldEnd << ' '; + ShowTag(*w->at(1).first, itsPattern.GetArtist()); + + *w->at(2).first << fmtBold << "Title: " << fmtBoldEnd << ' '; + ShowTag(*w->at(2).first, itsPattern.GetTitle()); + + *w->at(3).first << fmtBold << "Album: " << fmtBoldEnd << ' '; + ShowTag(*w->at(3).first, itsPattern.GetAlbum()); + + *w->at(4).first << fmtBold << "Filename: " << fmtBoldEnd << ' '; + ShowTag(*w->at(4).first, itsPattern.GetName()); + + *w->at(5).first << fmtBold << "Composer: " << fmtBoldEnd << ' '; + ShowTag(*w->at(5).first, itsPattern.GetComposer()); + + *w->at(6).first << fmtBold << "Performer:" << fmtBoldEnd << ' '; + ShowTag(*w->at(6).first, itsPattern.GetPerformer()); + + *w->at(7).first << fmtBold << "Genre: " << fmtBoldEnd << ' '; + ShowTag(*w->at(7).first, itsPattern.GetGenre()); + + *w->at(8).first << fmtBold << "Year: " << fmtBoldEnd << ' '; + ShowTag(*w->at(8).first, itsPattern.GetDate()); + + *w->at(9).first << fmtBold << "Comment: " << fmtBoldEnd << ' '; + ShowTag(*w->at(9).first, itsPattern.GetComment()); *w->at(11).first << fmtBold << "Search in:" << fmtBoldEnd << ' ' << (Config.search_in_db ? "Database" : "Current playlist"); *w->at(12).first << fmtBold << "Search mode:" << fmtBoldEnd << ' ' << (MatchToPattern ? NormalMode : StrictMode); diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index a8acdbee..dc207df1 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -101,70 +101,80 @@ void TinyTagEditor::EnterPressed() { Statusbar() << fmtBold << "Title: " << fmtBoldEnd; s.SetTitle(wFooter->GetString(s.GetTitle())); - w->at(option) << fmtBold << "Title:" << fmtBoldEnd << ' ' << ShowTag(s.GetTitle()); + w->at(option) << fmtBold << "Title:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetTitle()); break; } case 2: { Statusbar() << fmtBold << "Artist: " << fmtBoldEnd; s.SetArtist(wFooter->GetString(s.GetArtist())); - w->at(option) << fmtBold << "Artist:" << fmtBoldEnd << ' ' << ShowTag(s.GetArtist()); + w->at(option) << fmtBold << "Artist:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetArtist()); break; } case 3: { Statusbar() << fmtBold << "Album: " << fmtBoldEnd; s.SetAlbum(wFooter->GetString(s.GetAlbum())); - w->at(option) << fmtBold << "Album:" << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum()); + w->at(option) << fmtBold << "Album:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetAlbum()); break; } case 4: { Statusbar() << fmtBold << "Year: " << fmtBoldEnd; s.SetDate(wFooter->GetString(s.GetDate())); - w->at(option) << fmtBold << "Year:" << fmtBoldEnd << ' ' << ShowTag(s.GetDate()); + w->at(option) << fmtBold << "Year:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetDate()); break; } case 5: { Statusbar() << fmtBold << "Track: " << fmtBoldEnd; s.SetTrack(wFooter->GetString(s.GetTrack())); - w->at(option) << fmtBold << "Track:" << fmtBoldEnd << ' ' << ShowTag(s.GetTrack()); + w->at(option) << fmtBold << "Track:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetTrack()); break; } case 6: { Statusbar() << fmtBold << "Genre: " << fmtBoldEnd; s.SetGenre(wFooter->GetString(s.GetGenre())); - w->at(option) << fmtBold << "Genre:" << fmtBoldEnd << ' ' << ShowTag(s.GetGenre()); + w->at(option) << fmtBold << "Genre:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetGenre()); break; } case 7: { Statusbar() << fmtBold << "Composer: " << fmtBoldEnd; s.SetComposer(wFooter->GetString(s.GetComposer())); - w->at(option) << fmtBold << "Composer:" << fmtBoldEnd << ' ' << ShowTag(s.GetComposer()); + w->at(option) << fmtBold << "Composer:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetComposer()); break; } case 8: { Statusbar() << fmtBold << "Performer: " << fmtBoldEnd; s.SetPerformer(wFooter->GetString(s.GetPerformer())); - w->at(option) << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer()); + w->at(option) << fmtBold << "Performer:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetPerformer()); break; } case 9: { Statusbar() << fmtBold << "Disc: " << fmtBoldEnd; s.SetDisc(wFooter->GetString(s.GetDisc())); - w->at(option) << fmtBold << "Disc:" << fmtBoldEnd << ' ' << ShowTag(s.GetDisc()); + w->at(option) << fmtBold << "Disc:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetDisc()); break; } case 10: { Statusbar() << fmtBold << "Comment: " << fmtBoldEnd; s.SetComment(wFooter->GetString(s.GetComment())); - w->at(option) << fmtBold << "Comment:" << fmtBoldEnd << ' ' << ShowTag(s.GetComment()); + w->at(option) << fmtBold << "Comment:" << fmtBoldEnd << ' '; + ShowTag(w->at(option), s.GetComment()); break; } case 12: @@ -278,22 +288,34 @@ bool TinyTagEditor::GetTags() w->Highlight(8); w->at(0) << fmtBold << Config.color1 << "Song name: " << fmtBoldEnd << Config.color2 << s.GetName() << clEnd; - w->at(1) << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2 << ShowTag(s.GetDirectory()) << clEnd; + w->at(1) << fmtBold << Config.color1 << "Location in DB: " << fmtBoldEnd << Config.color2; + ShowTag(w->at(1), s.GetDirectory()); + w->at(1) << clEnd; w->at(3) << fmtBold << Config.color1 << "Length: " << fmtBoldEnd << Config.color2 << s.GetLength() << clEnd; w->at(4) << fmtBold << Config.color1 << "Bitrate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->bitrate() << " kbps" << clEnd; w->at(5) << fmtBold << Config.color1 << "Sample rate: " << fmtBoldEnd << Config.color2 << f.audioProperties()->sampleRate() << " Hz" << clEnd; w->at(6) << fmtBold << Config.color1 << "Channels: " << fmtBoldEnd << Config.color2 << (f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") << clDefault; - w->at(8) << fmtBold << "Title:" << fmtBoldEnd << ' ' << ShowTag(s.GetTitle()); - w->at(9) << fmtBold << "Artist:" << fmtBoldEnd << ' ' << ShowTag(s.GetArtist()); - w->at(10) << fmtBold << "Album:" << fmtBoldEnd << ' ' << ShowTag(s.GetAlbum()); - w->at(11) << fmtBold << "Year:" << fmtBoldEnd << ' ' << ShowTag(s.GetDate()); - w->at(12) << fmtBold << "Track:" << fmtBoldEnd << ' ' << ShowTag(s.GetTrack()); - w->at(13) << fmtBold << "Genre:" << fmtBoldEnd << ' ' << ShowTag(s.GetGenre()); - w->at(14) << fmtBold << "Composer:" << fmtBoldEnd << ' ' << ShowTag(s.GetComposer()); - w->at(15) << fmtBold << "Performer:" << fmtBoldEnd << ' ' << ShowTag(s.GetPerformer()); - w->at(16) << fmtBold << "Disc:" << fmtBoldEnd << ' ' << ShowTag(s.GetDisc()); - w->at(17) << fmtBold << "Comment:" << fmtBoldEnd << ' ' << ShowTag(s.GetComment()); + w->at(8) << fmtBold << "Title:" << fmtBoldEnd << ' '; + ShowTag(w->at(8), s.GetTitle()); + w->at(9) << fmtBold << "Artist:" << fmtBoldEnd << ' '; + ShowTag(w->at(9), s.GetArtist()); + w->at(10) << fmtBold << "Album:" << fmtBoldEnd << ' '; + ShowTag(w->at(10), s.GetAlbum()); + w->at(11) << fmtBold << "Year:" << fmtBoldEnd << ' '; + ShowTag(w->at(11), s.GetDate()); + w->at(12) << fmtBold << "Track:" << fmtBoldEnd << ' '; + ShowTag(w->at(12), s.GetTrack()); + w->at(13) << fmtBold << "Genre:" << fmtBoldEnd << ' '; + ShowTag(w->at(13), s.GetGenre()); + w->at(14) << fmtBold << "Composer:" << fmtBoldEnd << ' '; + ShowTag(w->at(14), s.GetComposer()); + w->at(15) << fmtBold << "Performer:" << fmtBoldEnd << ' '; + ShowTag(w->at(15), s.GetPerformer()); + w->at(16) << fmtBold << "Disc:" << fmtBoldEnd << ' '; + ShowTag(w->at(16), s.GetDisc()); + w->at(17) << fmtBold << "Comment:" << fmtBoldEnd << ' '; + ShowTag(w->at(17), s.GetComment()); w->at(19) << fmtBold << "Filename:" << fmtBoldEnd << ' ' << s.GetName();