From 73c166a0299a337b2d40bbbb1caa6d4513da10cb Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 11 Jan 2009 15:43:12 +0100 Subject: [PATCH] always save and read id3 tags in unicode --- src/helpers.cpp | 2 +- src/ncmpcpp.cpp | 2 +- src/tag_editor.cpp | 38 +++++++++++++++++++------------------- src/window.h | 2 -- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index 143ebbe..4542730 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -764,7 +764,7 @@ void GetInfo(Song &s, Scrollpad &info) path_to_file += s.GetFile(); TagLib::FileRef f(path_to_file.c_str()); if (!f.isNull()) - s.SetComment(f.tag()->comment().to8Bit(UNICODE)); + s.SetComment(f.tag()->comment().to8Bit(1)); # endif // HAVE_TAGLIB_H info << fmtBold << Config.color1 << "Filename: " << fmtBoldEnd << Config.color2 << s.GetName() << "\n" << clEnd; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 4523965..25ade9f 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -2571,7 +2571,7 @@ int main(int argc, char *argv[]) success = 0; break; } - f.tag()->setAlbum(TO_WSTRING(new_album)); + f.tag()->setAlbum(ToWString(new_album)); f.save(); } if (success) diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index e075443..cc6420c 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -274,31 +274,31 @@ void ReadTagsFromFile(mpd_Song *s) TagLib::MPEG::File *mpegf = dynamic_cast(f.file()); - s->artist = !f.tag()->artist().isEmpty() ? str_pool_get(f.tag()->artist().toCString(UNICODE)) : 0; - s->title = !f.tag()->title().isEmpty() ? str_pool_get(f.tag()->title().toCString(UNICODE)) : 0; - s->album = !f.tag()->album().isEmpty() ? str_pool_get(f.tag()->album().toCString(UNICODE)) : 0; + s->artist = !f.tag()->artist().isEmpty() ? str_pool_get(f.tag()->artist().toCString(1)) : 0; + s->title = !f.tag()->title().isEmpty() ? str_pool_get(f.tag()->title().toCString(1)) : 0; + s->album = !f.tag()->album().isEmpty() ? str_pool_get(f.tag()->album().toCString(1)) : 0; s->track = f.tag()->track() ? str_pool_get(IntoStr(f.tag()->track()).c_str()) : 0; s->date = f.tag()->year() ? str_pool_get(IntoStr(f.tag()->year()).c_str()) : 0; - s->genre = !f.tag()->genre().isEmpty() ? str_pool_get(f.tag()->genre().toCString(UNICODE)) : 0; + s->genre = !f.tag()->genre().isEmpty() ? str_pool_get(f.tag()->genre().toCString(1)) : 0; if (mpegf) { s->composer = !mpegf->ID3v2Tag()->frameListMap()["TCOM"].isEmpty() ? (!mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().isEmpty() - ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().toCString(UNICODE)) + ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().toCString(1)) : 0) : 0; s->performer = !mpegf->ID3v2Tag()->frameListMap()["TOPE"].isEmpty() ? (!mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().isEmpty() - ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().toCString(UNICODE)) + ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().toCString(1)) : 0) : 0; s->disc = !mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty() ? (!mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().isEmpty() - ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().toCString(UNICODE)) + ? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().toCString(1)) : 0) : 0; } - s->comment = !f.tag()->comment().isEmpty() ? str_pool_get(f.tag()->comment().toCString(UNICODE)) : 0; + s->comment = !f.tag()->comment().isEmpty() ? str_pool_get(f.tag()->comment().toCString(1)) : 0; s->time = f.audioProperties()->length(); } @@ -312,7 +312,7 @@ bool GetSongTags(Song &s) TagLib::FileRef f(path_to_file.c_str()); if (f.isNull()) return false; - s.SetComment(f.tag()->comment().to8Bit(UNICODE)); + s.SetComment(f.tag()->comment().to8Bit(1)); string ext = s.GetFile(); ext = ext.substr(ext.find_last_of(".")+1); @@ -372,13 +372,13 @@ bool WriteTags(Song &s) FileRef f(path_to_file.c_str()); if (!f.isNull()) { - f.tag()->setTitle(TO_WSTRING(s.GetTitle())); - f.tag()->setArtist(TO_WSTRING(s.GetArtist())); - f.tag()->setAlbum(TO_WSTRING(s.GetAlbum())); + f.tag()->setTitle(ToWString(s.GetTitle())); + f.tag()->setArtist(ToWString(s.GetArtist())); + f.tag()->setAlbum(ToWString(s.GetAlbum())); f.tag()->setYear(StrToInt(s.GetYear())); f.tag()->setTrack(StrToInt(s.GetTrack())); - f.tag()->setGenre(TO_WSTRING(s.GetGenre())); - f.tag()->setComment(TO_WSTRING(s.GetComment())); + f.tag()->setGenre(ToWString(s.GetGenre())); + f.tag()->setComment(ToWString(s.GetComment())); f.save(); string ext = s.GetFile(); @@ -388,16 +388,16 @@ bool WriteTags(Song &s) { MPEG::File file(path_to_file.c_str()); ID3v2::Tag *tag = file.ID3v2Tag(); - String::Type encoding = UNICODE ? String::UTF8 : String::Latin1; + String::Type encoding = String::UTF8; ByteVector Composer("TCOM"); ByteVector Performer("TOPE"); ByteVector Disc("TPOS"); ID3v2::Frame *ComposerFrame = new ID3v2::TextIdentificationFrame(Composer, encoding); ID3v2::Frame *PerformerFrame = new ID3v2::TextIdentificationFrame(Performer, encoding); ID3v2::Frame *DiscFrame = new ID3v2::TextIdentificationFrame(Disc, encoding); - ComposerFrame->setText(TO_WSTRING(s.GetComposer())); - PerformerFrame->setText(TO_WSTRING(s.GetPerformer())); - DiscFrame->setText(TO_WSTRING(s.GetDisc())); + ComposerFrame->setText(ToWString(s.GetComposer())); + PerformerFrame->setText(ToWString(s.GetPerformer())); + DiscFrame->setText(ToWString(s.GetDisc())); tag->removeFrames(Composer); tag->addFrame(ComposerFrame); tag->removeFrames(Performer); @@ -599,7 +599,7 @@ void __deal_with_filenames(SongList &v) int last_dot = file.find_last_of("."); string extension = file.substr(last_dot); basic_buffer new_file; - new_file << TO_WSTRING(GenerateFilename(s, Config.pattern)); + new_file << ToWString(GenerateFilename(s, Config.pattern)); if (new_file.Str().empty()) { if (preview) diff --git a/src/window.h b/src/window.h index 798c93b..7b7df7b 100644 --- a/src/window.h +++ b/src/window.h @@ -34,14 +34,12 @@ #include #ifdef _UTF8 -# define UNICODE 1 # define my_char_t wchar_t # define my_string_t wstring # define UTF_S_FMT "%ls" # define TO_STRING(x) ToString(x) # define TO_WSTRING(x) ToWString(x) #else -# define UNICODE 0 # define my_char_t char # define my_string_t string # define UTF_S_FMT "%s" -- 2.11.4.GIT