convert filenames to current locale if needed / some implementation improvements

This commit is contained in:
Andrzej Rybczak
2009-01-15 20:34:35 +01:00
parent 8226b9b4a2
commit 24c308dac8
9 changed files with 66 additions and 79 deletions

View File

@@ -127,6 +127,13 @@ void utf_to_locale(std::string &s)
str_pool_put(tmp); str_pool_put(tmp);
} }
std::string utf_to_locale_cpy(const std::string &s)
{
std::string result = s;
utf_to_locale(result);
return result;
}
void locale_to_utf(std::string &s) void locale_to_utf(std::string &s)
{ {
if (s.empty() || !locale_charset || !has_non_ascii_chars(s)) if (s.empty() || !locale_charset || !has_non_ascii_chars(s))
@@ -137,6 +144,13 @@ void locale_to_utf(std::string &s)
str_pool_put(tmp); str_pool_put(tmp);
} }
std::string locale_to_utf_cpy(const std::string &s)
{
std::string result = s;
locale_to_utf(result);
return result;
}
void str_pool_utf_to_locale(char *&s) void str_pool_utf_to_locale(char *&s)
{ {
if (!has_non_ascii_chars(s)) if (!has_non_ascii_chars(s))

View File

@@ -25,15 +25,18 @@
#include <config.h> #include <config.h>
#endif #endif
#if !defined(_UTF8) && defined(HAVE_ICONV_H)
#include <string> #include <string>
#if !defined(_UTF8) && defined(HAVE_ICONV_H)
void init_current_locale(); void init_current_locale();
void utf_to_locale(std::string &); void utf_to_locale(std::string &);
void locale_to_utf(std::string &); void locale_to_utf(std::string &);
std::string utf_to_locale_cpy(const std::string &s);
std::string locale_to_utf_cpy(const std::string &s);
void str_pool_utf_to_locale(char *&); void str_pool_utf_to_locale(char *&);
void str_pool_locale_to_utf(char *&); void str_pool_locale_to_utf(char *&);
@@ -44,6 +47,9 @@ void str_pool_locale_to_utf(char *&);
#define utf_to_locale(x); #define utf_to_locale(x);
#define locale_to_utf(x); #define locale_to_utf(x);
#define utf_to_locale_cpy(x) (x)
#define locale_to_utf_cpy(x) (x)
#define str_pool_utf_to_locale(x); #define str_pool_utf_to_locale(x);
#define str_pool_locale_to_utf(x); #define str_pool_locale_to_utf(x);

View File

@@ -533,7 +533,7 @@ void DisplaySongInColumns(const Song &s, void *s_template, Menu<Song> *menu)
void DisplaySong(const Song &s, void *data, Menu<Song> *menu) void DisplaySong(const Song &s, void *data, Menu<Song> *menu)
{ {
const_cast<Song *>(&s)->LocalizeTags(); const_cast<Song *>(&s)->Localize();
const string &song_template = data ? *static_cast<string *>(data) : ""; const string &song_template = data ? *static_cast<string *>(data) : "";
basic_buffer<my_char_t> buf; basic_buffer<my_char_t> buf;

View File

@@ -18,6 +18,7 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include "charset.h"
#include "mpdpp.h" #include "mpdpp.h"
using namespace MPD; using namespace MPD;
@@ -482,7 +483,7 @@ int Connection::AddSong(const string &path)
int Connection::AddSong(const Song &s) int Connection::AddSong(const Song &s)
{ {
return !s.Empty() ? (s.IsFromDB() ? AddSong(s.GetFile()) : AddSong("file://" + string(s.GetFile()))) : -1; return !s.Empty() ? (s.IsFromDB() ? (AddSong(s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile())) : AddSong("file://" + (s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile()))) : -1;
} }
void Connection::QueueAddSong(const string &path) void Connection::QueueAddSong(const string &path)
@@ -499,7 +500,7 @@ void Connection::QueueAddSong(const string &path)
void Connection::QueueAddSong(const Song &s) void Connection::QueueAddSong(const Song &s)
{ {
if (!s.Empty()) if (!s.Empty())
QueueAddSong(s.GetFile()); QueueAddSong(s.Localized() ? locale_to_utf_cpy(s.GetFile()) : s.GetFile());
} }
void Connection::QueueAddToPlaylist(const string &playlist, const string &path) void Connection::QueueAddToPlaylist(const string &playlist, const string &path)

View File

@@ -527,7 +527,7 @@ int main(int argc, char *argv[])
if (!l.empty() && !l[0]->GetAlbum().empty()) if (!l.empty() && !l[0]->GetAlbum().empty())
{ {
utf_to_locale(*it); utf_to_locale(*it);
l[0]->LocalizeTags(); l[0]->Localize();
maplist[l[0]->toString(Config.media_lib_album_format)] = *it; maplist[l[0]->toString(Config.media_lib_album_format)] = *it;
} }
FreeSongList(l); FreeSongList(l);
@@ -556,9 +556,7 @@ int main(int argc, char *argv[])
mLibAlbums->Refresh(); mLibAlbums->Refresh();
mLibSongs->Clear(0); mLibSongs->Clear(0);
Mpd->StartSearch(1); Mpd->StartSearch(1);
locale_to_utf(mLibArtists->Current()); Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(mLibArtists->Current()));
Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->Current());
utf_to_locale(mLibArtists->Current());
Mpd->CommitSearch(list); Mpd->CommitSearch(list);
} }
else else
@@ -566,9 +564,7 @@ int main(int argc, char *argv[])
mLibSongs->Clear(0); mLibSongs->Clear(0);
Mpd->StartSearch(1); Mpd->StartSearch(1);
Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->Current()); Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->Current());
locale_to_utf(mLibAlbums->Current().second); Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, locale_to_utf_cpy(mLibAlbums->Current().second));
Mpd->AddSearch(MPD_TAG_ITEM_ALBUM, mLibAlbums->Current().second);
utf_to_locale(mLibAlbums->Current().second);
Mpd->CommitSearch(list); Mpd->CommitSearch(list);
} }
sort(list.begin(), list.end(), SortSongsByTrack); sort(list.begin(), list.end(), SortSongsByTrack);
@@ -615,9 +611,7 @@ int main(int argc, char *argv[])
{ {
mPlaylistEditor->Reset(); mPlaylistEditor->Reset();
SongList list; SongList list;
locale_to_utf(mPlaylistList->Current()); Mpd->GetPlaylistContent(locale_to_utf_cpy(mPlaylistList->Current()), list);
Mpd->GetPlaylistContent(mPlaylistList->Current(), list);
utf_to_locale(mPlaylistList->Current());
if (!list.empty()) if (!list.empty())
mPlaylistEditor->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)")); mPlaylistEditor->SetTitle("Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)"));
else else
@@ -679,7 +673,7 @@ int main(int argc, char *argv[])
Mpd->CommitSearch(l); Mpd->CommitSearch(l);
if (!l.empty()) if (!l.empty())
{ {
l[0]->LocalizeTags(); l[0]->Localize();
maplist[l[0]->toString(Config.tag_editor_album_format)] = *it; maplist[l[0]->toString(Config.tag_editor_album_format)] = *it;
} }
FreeSongList(l); FreeSongList(l);
@@ -730,7 +724,7 @@ int main(int argc, char *argv[])
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (SongList::iterator it = list.begin(); it != list.end(); it++) for (SongList::iterator it = list.begin(); it != list.end(); it++)
{ {
(*it)->LocalizeTags(); (*it)->Localize();
mEditorTags->AddOption(**it); mEditorTags->AddOption(**it);
} }
} }
@@ -740,7 +734,7 @@ int main(int argc, char *argv[])
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (SongList::const_iterator it = list.begin(); it != list.end(); it++) for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
{ {
(*it)->LocalizeTags(); (*it)->Localize();
mEditorTags->AddOption(**it); mEditorTags->AddOption(**it);
} }
} }
@@ -1034,9 +1028,7 @@ int main(int argc, char *argv[])
case itPlaylist: case itPlaylist:
{ {
SongList list; SongList list;
string playlist_real_name = item.name; Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
locale_to_utf(playlist_real_name);
Mpd->GetPlaylistContent(playlist_real_name, 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())
@@ -1156,7 +1148,7 @@ int main(int argc, char *argv[])
ShowMessage("Tags updated!"); ShowMessage("Tags updated!");
if (s.IsFromDB()) if (s.IsFromDB())
{ {
Mpd->UpdateDirectory(s.GetDirectory()); Mpd->UpdateDirectory(locale_to_utf_cpy(s.GetDirectory()));
if (prev_screen == csSearcher) if (prev_screen == csSearcher)
*mSearcher->Current().second = s; *mSearcher->Current().second = s;
} }
@@ -1355,10 +1347,8 @@ int main(int argc, char *argv[])
if (!mLibArtists->Empty() && wCurrent == mLibArtists) if (!mLibArtists->Empty() && wCurrent == mLibArtists)
{ {
string tag = mLibArtists->Current();
locale_to_utf(tag);
Mpd->StartSearch(1); Mpd->StartSearch(1);
Mpd->AddSearch(Config.media_lib_primary_tag, tag); Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(mLibArtists->Current()));
Mpd->CommitSearch(list); Mpd->CommitSearch(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);
@@ -1465,9 +1455,7 @@ int main(int argc, char *argv[])
if (wCurrent == mPlaylistList && !mPlaylistList->Empty()) if (wCurrent == mPlaylistList && !mPlaylistList->Empty())
{ {
string playlist = mPlaylistList->Current(); Mpd->GetPlaylistContent(locale_to_utf_cpy(mPlaylistList->Current()), list);
locale_to_utf(playlist);
Mpd->GetPlaylistContent(playlist, 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())
@@ -1776,11 +1764,8 @@ int main(int argc, char *argv[])
if (browsed_dir != "/" && !mBrowser->Choice()) if (browsed_dir != "/" && !mBrowser->Choice())
continue; // do not let add parent dir. continue; // do not let add parent dir.
string real_dir_name = item.name;
locale_to_utf(real_dir_name);
SongList list; SongList list;
Mpd->GetDirectoryRecursive(real_dir_name, list); Mpd->GetDirectoryRecursive(locale_to_utf_cpy(item.name), 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);
@@ -1827,9 +1812,7 @@ int main(int argc, char *argv[])
case itPlaylist: case itPlaylist:
{ {
SongList list; SongList list;
string playlist_real_name = item.name; Mpd->GetPlaylistContent(locale_to_utf_cpy(item.name), list);
locale_to_utf(playlist_real_name);
Mpd->GetPlaylistContent(playlist_real_name, 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())
@@ -2067,9 +2050,7 @@ int main(int argc, char *argv[])
while (in != 'y' && in != 'n'); while (in != 'y' && in != 'n');
if (in == 'y') if (in == 'y')
{ {
locale_to_utf(name); Mpd->DeletePlaylist(locale_to_utf_cpy(name));
Mpd->DeletePlaylist(name);
utf_to_locale(name);
ShowMessage("Playlist %s deleted!", name.c_str()); ShowMessage("Playlist %s deleted!", name.c_str());
if (!Config.local_browser) if (!Config.local_browser)
GetDirectory("/"); GetDirectory("/");
@@ -2549,16 +2530,14 @@ int main(int argc, char *argv[])
SongList list; SongList list;
ShowMessage("Updating tags..."); ShowMessage("Updating tags...");
Mpd->StartSearch(1); Mpd->StartSearch(1);
locale_to_utf(mLibArtists->Current()); Mpd->AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(mLibArtists->Current()));
Mpd->AddSearch(Config.media_lib_primary_tag, mLibArtists->Current());
utf_to_locale(mLibArtists->Current());
Mpd->CommitSearch(list); Mpd->CommitSearch(list);
SongSetFunction set = IntoSetFunction(Config.media_lib_primary_tag); SongSetFunction set = IntoSetFunction(Config.media_lib_primary_tag);
if (!set) if (!set)
continue; continue;
for (SongList::iterator it = list.begin(); it != list.end(); it++) for (SongList::iterator it = list.begin(); it != list.end(); it++)
{ {
(*it)->LocalizeTags(); (*it)->Localize();
((*it)->*set)(new_tag); ((*it)->*set)(new_tag);
ShowMessage("Updating tags in '%s'...", (*it)->GetName().c_str()); ShowMessage("Updating tags in '%s'...", (*it)->GetName().c_str());
string path = Config.mpd_music_dir + (*it)->GetFile(); string path = Config.mpd_music_dir + (*it)->GetFile();
@@ -2589,7 +2568,7 @@ int main(int argc, char *argv[])
ShowMessage("Updating tags..."); ShowMessage("Updating tags...");
for (size_t i = 0; i < mLibSongs->Size(); i++) for (size_t i = 0; i < mLibSongs->Size(); i++)
{ {
(*mLibSongs)[i].LocalizeTags(); (*mLibSongs)[i].Localize();
ShowMessage("Updating tags in '%s'...", (*mLibSongs)[i].GetName().c_str()); ShowMessage("Updating tags in '%s'...", (*mLibSongs)[i].GetName().c_str());
string path = Config.mpd_music_dir + (*mLibSongs)[i].GetFile(); string path = Config.mpd_music_dir + (*mLibSongs)[i].GetFile();
TagLib::FileRef f(path.c_str()); TagLib::FileRef f(path.c_str());
@@ -2673,18 +2652,14 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (!new_dir.empty() && new_dir != old_dir) if (!new_dir.empty() && new_dir != old_dir)
{ {
locale_to_utf(old_dir); string full_old_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + locale_to_utf_cpy(old_dir);
locale_to_utf(new_dir); string full_new_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + locale_to_utf_cpy(new_dir);
string full_old_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + old_dir;
string full_new_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + new_dir;
if (rename(full_old_dir.c_str(), full_new_dir.c_str()) == 0) if (rename(full_old_dir.c_str(), full_new_dir.c_str()) == 0)
{ {
Mpd->UpdateDirectory(editor_browsed_dir); Mpd->UpdateDirectory(editor_browsed_dir);
} }
else else
{ {
utf_to_locale(old_dir);
utf_to_locale(new_dir);
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());
} }
} }
@@ -2700,19 +2675,15 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (!new_dir.empty() && new_dir != old_dir) if (!new_dir.empty() && new_dir != old_dir)
{ {
locale_to_utf(old_dir);
locale_to_utf(new_dir);
string full_old_dir; string full_old_dir;
if (!Config.local_browser) if (!Config.local_browser)
full_old_dir += Config.mpd_music_dir; full_old_dir += Config.mpd_music_dir;
full_old_dir += old_dir; full_old_dir += locale_to_utf_cpy(old_dir);
string full_new_dir; string full_new_dir;
if (!Config.local_browser) if (!Config.local_browser)
full_new_dir += Config.mpd_music_dir; full_new_dir += Config.mpd_music_dir;
full_new_dir += new_dir; full_new_dir += locale_to_utf_cpy(new_dir);
int rename_result = rename(full_old_dir.c_str(), full_new_dir.c_str()); int rename_result = rename(full_old_dir.c_str(), full_new_dir.c_str());
utf_to_locale(old_dir);
utf_to_locale(new_dir);
if (rename_result == 0) if (rename_result == 0)
{ {
ShowMessage("'%s' renamed to '%s'", old_dir.c_str(), new_dir.c_str()); ShowMessage("'%s' renamed to '%s'", old_dir.c_str(), new_dir.c_str());
@@ -2733,11 +2704,7 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (!new_name.empty() && new_name != old_name) if (!new_name.empty() && new_name != old_name)
{ {
locale_to_utf(old_name); Mpd->Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name));
locale_to_utf(new_name);
Mpd->Rename(old_name, new_name);
utf_to_locale(old_name);
utf_to_locale(new_name);
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)
GetDirectory("/"); GetDirectory("/");
@@ -2782,10 +2749,8 @@ int main(int argc, char *argv[])
Config.local_browser = !s->IsFromDB(); Config.local_browser = !s->IsFromDB();
string option = s->toString(Config.song_status_format); string option = s->toString(Config.song_status_format);
string localed_dir = s->GetDirectory();
locale_to_utf(option); locale_to_utf(option);
utf_to_locale(localed_dir); GetDirectory(s->GetDirectory());
GetDirectory(localed_dir);
for (size_t i = 0; i < mBrowser->Size(); i++) for (size_t i = 0; i < mBrowser->Size(); i++)
{ {
if (mBrowser->at(i).type == itSong && option == mBrowser->at(i).song->toString(Config.song_status_format)) if (mBrowser->at(i).type == itSong && option == mBrowser->at(i).song->toString(Config.song_status_format))

View File

@@ -75,11 +75,13 @@ string Song::GetLength() const
return ShowTime(itsSong->time); return ShowTime(itsSong->time);
} }
void Song::LocalizeTags() void Song::Localize()
{ {
# if !defined(_UTF8) && defined(HAVE_ICONV_H) # if !defined(_UTF8) && defined(HAVE_ICONV_H)
if (isLocalised) if (isLocalised)
return; return;
str_pool_utf_to_locale(itsSong->file);
__Count_Last_Slash_Position();
str_pool_utf_to_locale(itsSong->artist); str_pool_utf_to_locale(itsSong->artist);
str_pool_utf_to_locale(itsSong->title); str_pool_utf_to_locale(itsSong->title);
str_pool_utf_to_locale(itsSong->album); str_pool_utf_to_locale(itsSong->album);
@@ -95,11 +97,13 @@ void Song::LocalizeTags()
# endif // !_UTF8 && HAVE_ICONV_H # endif // !_UTF8 && HAVE_ICONV_H
} }
void Song::DelocalizeTags() /*void Song::Delocalize()
{ {
# if !defined(_UTF8) && defined(HAVE_ICONV_H) # if !defined(_UTF8) && defined(HAVE_ICONV_H)
if (!isLocalised) if (!isLocalised)
return; return;
str_pool_locale_to_utf(itsSong->file);
__Count_Last_Slash_Position();
str_pool_locale_to_utf(itsSong->artist); str_pool_locale_to_utf(itsSong->artist);
str_pool_locale_to_utf(itsSong->title); str_pool_locale_to_utf(itsSong->title);
str_pool_locale_to_utf(itsSong->album); str_pool_locale_to_utf(itsSong->album);
@@ -113,7 +117,7 @@ void Song::DelocalizeTags()
str_pool_locale_to_utf(itsSong->comment); str_pool_locale_to_utf(itsSong->comment);
isLocalised = 0; isLocalised = 0;
# endif // !_UTF8 && HAVE_ICONV_H # endif // !_UTF8 && HAVE_ICONV_H
} }*/
void Song::Clear() void Song::Clear()
{ {

View File

@@ -82,12 +82,13 @@ class Song
void CopyPtr(bool copy) { copyPtr = copy; } void CopyPtr(bool copy) { copyPtr = copy; }
//void GetEmptyFields(bool get) { itsGetEmptyFields = get; } //void GetEmptyFields(bool get) { itsGetEmptyFields = get; }
void LocalizeTags(); void Localize();
void DelocalizeTags(); //void Delocalize();
void Clear(); void Clear();
bool Empty() const; bool Empty() const;
bool IsFromDB() const; bool IsFromDB() const;
bool IsStream() const { return isStream; } bool IsStream() const { return isStream; }
bool Localized() const { return isLocalised; }
Song & operator=(const Song &); Song & operator=(const Song &);
bool operator==(const Song &) const; bool operator==(const Song &) const;

View File

@@ -341,9 +341,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
if (s.GetTotalLength() && elapsed == s.GetTotalLength()-1) if (s.GetTotalLength() && elapsed == s.GetTotalLength()-1)
repeat_one_allowed = 1; repeat_one_allowed = 1;
string song_str = s.toString(Config.song_window_title_format); WindowTitle(utf_to_locale_cpy(s.toString(Config.song_window_title_format)));
utf_to_locale(song_str);
WindowTitle(song_str);
if (!block_statusbar_update && Config.statusbar_visibility) if (!block_statusbar_update && Config.statusbar_visibility)
{ {
@@ -364,9 +362,7 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *)
} }
wFooter->WriteXY(0, 1, 1, "%s", player_state.c_str()); wFooter->WriteXY(0, 1, 1, "%s", player_state.c_str());
wFooter->Bold(0); wFooter->Bold(0);
song_str = s.toString(Config.song_status_format); Scroller(*wFooter, utf_to_locale_cpy(s.toString(Config.song_status_format)), wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin);
utf_to_locale(song_str);
Scroller(*wFooter, song_str, wFooter->GetWidth()-player_state.length()-tracklength.length(), playing_song_scroll_begin);
wFooter->Bold(1); wFooter->Bold(1);
wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 1, "%s", tracklength.c_str()); wFooter->WriteXY(wFooter->GetWidth()-tracklength.length(), 1, 1, "%s", tracklength.c_str());

View File

@@ -28,6 +28,7 @@
#include "textidentificationframe.h" #include "textidentificationframe.h"
#include "mpegfile.h" #include "mpegfile.h"
#include "charset.h"
#include "helpers.h" #include "helpers.h"
#include "status_checker.h" #include "status_checker.h"
@@ -323,6 +324,7 @@ bool GetSongTags(Song &s)
if (s.IsFromDB()) if (s.IsFromDB())
path_to_file += Config.mpd_music_dir; path_to_file += Config.mpd_music_dir;
path_to_file += s.GetFile(); path_to_file += s.GetFile();
locale_to_utf(path_to_file);
TagLib::FileRef f(path_to_file.c_str()); TagLib::FileRef f(path_to_file.c_str());
if (f.isNull()) if (f.isNull())
@@ -384,6 +386,7 @@ bool WriteTags(Song &s)
if (file_is_from_db) if (file_is_from_db)
path_to_file += Config.mpd_music_dir; path_to_file += Config.mpd_music_dir;
path_to_file += s.GetFile(); path_to_file += s.GetFile();
locale_to_utf(path_to_file);
FileRef f(path_to_file.c_str()); FileRef f(path_to_file.c_str());
if (!f.isNull()) if (!f.isNull())
{ {
@@ -423,15 +426,12 @@ bool WriteTags(Song &s)
} }
if (!s.GetNewName().empty()) if (!s.GetNewName().empty())
{ {
string old_name;
if (file_is_from_db)
old_name += Config.mpd_music_dir;
old_name += s.GetFile();
string new_name; string new_name;
if (file_is_from_db) if (file_is_from_db)
new_name += Config.mpd_music_dir; new_name += Config.mpd_music_dir;
new_name += s.GetDirectory() + "/" + s.GetNewName(); new_name += s.GetDirectory() + "/" + s.GetNewName();
if (rename(old_name.c_str(), new_name.c_str()) == 0 && !file_is_from_db) locale_to_utf(new_name);
if (rename(path_to_file.c_str(), new_name.c_str()) == 0 && !file_is_from_db)
{ {
if (wPrev == mPlaylist) if (wPrev == mPlaylist)
{ {