shorten long names in messages displayed in statusbar

This commit is contained in:
Andrzej Rybczak
2009-10-10 18:37:53 +02:00
parent 89aa68c698
commit 833f608d60
8 changed files with 77 additions and 36 deletions

View File

@@ -480,9 +480,15 @@ void Browser::ClearDirectory(const std::string &path) const
if (S_ISDIR(file_stat.st_mode)) if (S_ISDIR(file_stat.st_mode))
ClearDirectory(full_path); ClearDirectory(full_path);
if (remove(full_path.c_str()) == 0) if (remove(full_path.c_str()) == 0)
ShowMessage("Deleting \"%s\"...", full_path.c_str()); {
static const char msg[] = "Deleting \"%s\"...";
ShowMessage(msg, Shorten(TO_WSTRING(full_path), COLS-static_strlen(msg)).c_str());
}
else else
ShowMessage("Couldn't remove \"%s\": %s", full_path.c_str(), strerror(errno)); {
static const char msg[] = "Couldn't remove \"%s\": %s";
ShowMessage(msg, Shorten(TO_WSTRING(full_path), COLS-static_strlen(msg)-25).c_str(), strerror(errno));
}
} }
closedir(dir); closedir(dir);
} }

View File

@@ -174,6 +174,18 @@ MPD::Song::SetFunction IntoSetFunction(mpd_tag_type tag)
} }
#endif // HAVE_TAGLIB_H #endif // HAVE_TAGLIB_H
std::string Shorten(const std::basic_string<my_char_t> &s, size_t max_length)
{
if (s.length() <= max_length)
return TO_STRING(s);
if (max_length < 2)
return "";
std::basic_string<my_char_t> result(s, 0, max_length/2-1);
result += U("..");
result += s.substr(s.length()-max_length/2+1);
return TO_STRING(result);
}
void EscapeUnallowedChars(std::string &s) void EscapeUnallowedChars(std::string &s)
{ {
static const std::string unallowed_chars = "\"*/:<>?\\|"; static const std::string unallowed_chars = "\"*/:<>?\\|";

View File

@@ -56,6 +56,8 @@ mpd_tag_type IntoTagItem(char);
MPD::Song::SetFunction IntoSetFunction(mpd_tag_type); MPD::Song::SetFunction IntoSetFunction(mpd_tag_type);
#endif // HAVE_TAGLIB_H #endif // HAVE_TAGLIB_H
std::string Shorten(const std::basic_string<my_char_t> &s, size_t max_length);
void EscapeUnallowedChars(std::string &); void EscapeUnallowedChars(std::string &);
void EscapeHtml(std::string &s); void EscapeHtml(std::string &s);

View File

@@ -317,11 +317,11 @@ void Connection::Move(const std::string &path, int from, int to) const
mpd_response_finish(itsConnection); mpd_response_finish(itsConnection);
} }
void Connection::Rename(const std::string &from, const std::string &to) const bool Connection::Rename(const std::string &from, const std::string &to) const
{ {
if (!itsConnection) if (!itsConnection)
return; return false;
(isCommandsListEnabled ? mpd_send_rename : mpd_run_rename)(itsConnection, from.c_str(), to.c_str()); return (isCommandsListEnabled ? mpd_send_rename : mpd_run_rename)(itsConnection, from.c_str(), to.c_str());
} }
void Connection::GetPlaylistChanges(unsigned version, SongList &v) const void Connection::GetPlaylistChanges(unsigned version, SongList &v) const
@@ -527,11 +527,11 @@ bool Connection::CommitCommandsList()
return !CheckForErrors(); return !CheckForErrors();
} }
void Connection::DeletePlaylist(const std::string &name) const bool Connection::DeletePlaylist(const std::string &name) const
{ {
if (!itsConnection) if (!itsConnection)
return; return false;
(isCommandsListEnabled ? mpd_send_rm : mpd_run_rm)(itsConnection, name.c_str()); return (isCommandsListEnabled ? mpd_send_rm : mpd_run_rm)(itsConnection, name.c_str());
} }
bool Connection::SavePlaylist(const std::string &name) const bool Connection::SavePlaylist(const std::string &name) const

View File

@@ -162,13 +162,13 @@ namespace MPD
void StartCommandsList(); void StartCommandsList();
bool CommitCommandsList(); bool CommitCommandsList();
void DeletePlaylist(const std::string &) const; bool DeletePlaylist(const std::string &) const;
bool SavePlaylist(const std::string &) const; bool SavePlaylist(const std::string &) const;
void ClearPlaylist(const std::string &) const; void ClearPlaylist(const std::string &) const;
void AddToPlaylist(const std::string &, const Song &) const; void AddToPlaylist(const std::string &, const Song &) const;
void AddToPlaylist(const std::string &, const std::string &) const; void AddToPlaylist(const std::string &, const std::string &) const;
void Move(const std::string &, int, int) const; void Move(const std::string &, int, int) const;
void Rename(const std::string &, const std::string &) const; bool Rename(const std::string &, const std::string &) const;
void StartSearch(bool) const; void StartSearch(bool) const;
void StartFieldSearch(mpd_tag_type); void StartFieldSearch(mpd_tag_type);

View File

@@ -595,7 +595,7 @@ int main(int argc, char *argv[])
{ {
std::string name = myScreen == myBrowser ? myBrowser->Main()->Current().name : myPlaylistEditor->Playlists->Current(); std::string name = myScreen == myBrowser ? myBrowser->Main()->Current().name : myPlaylistEditor->Playlists->Current();
LockStatusbar(); LockStatusbar();
Statusbar() << "Delete playlist \"" << name << "\" ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] "; Statusbar() << "Delete playlist \"" << Shorten(TO_WSTRING(name), COLS-28) << "\" ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "]";
wFooter->Refresh(); wFooter->Refresh();
input = 0; input = 0;
do do
@@ -607,10 +607,13 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (input == 'y') if (input == 'y')
{ {
Mpd.DeletePlaylist(locale_to_utf_cpy(name)); if (Mpd.DeletePlaylist(locale_to_utf_cpy(name)))
ShowMessage("Playlist \"%s\" deleted!", name.c_str()); {
if (myBrowser->Main() && !myBrowser->isLocal() && myBrowser->CurrentDir() == "/") static const char msg[] = "Playlist \"%s\" deleted!";
myBrowser->GetDirectory("/"); ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)).c_str());
if (myBrowser->Main() && !myBrowser->isLocal() && myBrowser->CurrentDir() == "/")
myBrowser->GetDirectory("/");
}
} }
else else
ShowMessage("Aborted!"); ShowMessage("Aborted!");
@@ -640,7 +643,7 @@ int main(int argc, char *argv[])
std::string name = item.type == itSong ? item.song->GetName() : item.name; std::string name = item.type == itSong ? item.song->GetName() : item.name;
LockStatusbar(); LockStatusbar();
Statusbar() << "Delete " << (item.type == itSong ? "file" : "directory") << " \"" << name << "\" ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] "; Statusbar() << "Delete " << (item.type == itSong ? "file" : "directory") << " \"" << Shorten(TO_WSTRING(name), COLS-30) << "\" ? [" << fmtBold << 'y' << fmtBoldEnd << '/' << fmtBold << 'n' << fmtBoldEnd << "] ";
wFooter->Refresh(); wFooter->Refresh();
input = 0; input = 0;
do do
@@ -662,14 +665,18 @@ int main(int argc, char *argv[])
if (remove(path.c_str()) == 0) if (remove(path.c_str()) == 0)
{ {
ShowMessage("\"%s\" has been successfuly deleted!", name.c_str()); static const char msg[] = "\"%s\" deleted!";
ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)).c_str());
if (!myBrowser->isLocal()) if (!myBrowser->isLocal())
Mpd.UpdateDirectory(myBrowser->CurrentDir()); Mpd.UpdateDirectory(myBrowser->CurrentDir());
else else
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
else else
ShowMessage("Couldn't remove \"%s\": %s", name.c_str(), strerror(errno)); {
static const char msg[] = "Couldn't remove \"%s\": %s";
ShowMessage(msg, Shorten(TO_WSTRING(name), COLS-static_strlen(msg)-25).c_str(), strerror(errno));
}
} }
else else
ShowMessage("Aborted!"); ShowMessage("Aborted!");
@@ -1375,7 +1382,8 @@ int main(int argc, char *argv[])
std::string path = Config.mpd_music_dir + (*it)->GetFile(); std::string path = Config.mpd_music_dir + (*it)->GetFile();
if (!TagEditor::WriteTags(**it)) if (!TagEditor::WriteTags(**it))
{ {
ShowMessage("Error updating tags in \"%s\"!", (*it)->GetFile().c_str()); static const char msg[] = "Error while updating tags in \"%s\"!";
ShowMessage(msg, Shorten(TO_WSTRING((*it)->GetFile()), COLS-static_strlen(msg)).c_str());
success = 0; success = 0;
break; break;
} }
@@ -1406,14 +1414,16 @@ int main(int argc, char *argv[])
TagLib::FileRef f(locale_to_utf_cpy(path).c_str()); TagLib::FileRef f(locale_to_utf_cpy(path).c_str());
if (f.isNull()) if (f.isNull())
{ {
ShowMessage("Error opening file \"%s\"!", (*myLibrary->Songs)[i].GetFile().c_str()); static const char msg[] = "Error while opening file \"%s\"!";
ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].GetFile()), COLS-static_strlen(msg)).c_str());
success = 0; success = 0;
break; break;
} }
f.tag()->setAlbum(ToWString(new_album)); f.tag()->setAlbum(ToWString(new_album));
if (!f.save()) if (!f.save())
{ {
ShowMessage("Error writing tags in \"%s\"!", (*myLibrary->Songs)[i].GetFile().c_str()); static const char msg[] = "Error while writing tags in \"%s\"!";
ShowMessage(msg, Shorten(TO_WSTRING((*myLibrary->Songs)[i].GetFile()), COLS-static_strlen(msg)).c_str());
success = 0; success = 0;
break; break;
} }
@@ -1438,11 +1448,14 @@ int main(int argc, char *argv[])
std::string full_new_dir = Config.mpd_music_dir + myTagEditor->CurrentDir() + "/" + locale_to_utf_cpy(new_dir); std::string full_new_dir = Config.mpd_music_dir + myTagEditor->CurrentDir() + "/" + locale_to_utf_cpy(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)
{ {
static const char msg[] = "Directory renamed to \"%s\"";
ShowMessage(msg, Shorten(TO_WSTRING(new_dir), COLS-static_strlen(msg)).c_str());
Mpd.UpdateDirectory(myTagEditor->CurrentDir()); Mpd.UpdateDirectory(myTagEditor->CurrentDir());
} }
else else
{ {
ShowMessage("Cannot rename \"%s\" to \"%s\"!", old_dir.c_str(), new_dir.c_str()); static const char msg[] = "Couldn't rename \"%s\": %s";
ShowMessage(msg, Shorten(TO_WSTRING(old_dir), COLS-static_strlen(msg)-25).c_str(), strerror(errno));
} }
} }
} }
@@ -1472,13 +1485,17 @@ int main(int argc, char *argv[])
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());
if (rename_result == 0) if (rename_result == 0)
{ {
ShowMessage("\"%s\" renamed to \"%s\"", old_dir.c_str(), new_dir.c_str()); static const char msg[] = "Directory renamed to \"%s\"";
ShowMessage(msg, Shorten(TO_WSTRING(new_dir), COLS-static_strlen(msg)).c_str());
if (!myBrowser->isLocal()) if (!myBrowser->isLocal())
Mpd.UpdateDirectory(locale_to_utf_cpy(FindSharedDir(old_dir, new_dir))); Mpd.UpdateDirectory(locale_to_utf_cpy(FindSharedDir(old_dir, new_dir)));
myBrowser->GetDirectory(myBrowser->CurrentDir()); myBrowser->GetDirectory(myBrowser->CurrentDir());
} }
else else
ShowMessage("Cannot rename \"%s\" to \"%s\"!", old_dir.c_str(), new_dir.c_str()); {
static const char msg[] = "Couldn't rename \"%s\": %s";
ShowMessage(msg, Shorten(TO_WSTRING(old_dir), COLS-static_strlen(msg)-25).c_str(), strerror(errno));
}
} }
} }
else if (myScreen->ActiveWindow() == myPlaylistEditor->Playlists || (myScreen == myBrowser && myBrowser->Main()->Current().type == itPlaylist)) else if (myScreen->ActiveWindow() == myPlaylistEditor->Playlists || (myScreen == myBrowser && myBrowser->Main()->Current().type == itPlaylist))
@@ -1490,12 +1507,15 @@ int main(int argc, char *argv[])
UnlockStatusbar(); UnlockStatusbar();
if (!new_name.empty() && new_name != old_name) if (!new_name.empty() && new_name != old_name)
{ {
Mpd.Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name)); if (Mpd.Rename(locale_to_utf_cpy(old_name), locale_to_utf_cpy(new_name)))
ShowMessage("Playlist \"%s\" renamed to \"%s\"", old_name.c_str(), new_name.c_str()); {
if (myBrowser->Main() && !myBrowser->isLocal()) static const char msg[] = "Playlist renamed to \"%s\"";
myBrowser->GetDirectory("/"); ShowMessage(msg, Shorten(TO_WSTRING(new_name), COLS-static_strlen(msg)).c_str());
if (myPlaylistEditor->Main()) if (myBrowser->Main() && !myBrowser->isLocal())
myPlaylistEditor->Playlists->Clear(0); myBrowser->GetDirectory("/");
if (myPlaylistEditor->Main())
myPlaylistEditor->Playlists->Clear(0);
}
} }
} }
} }

View File

@@ -621,7 +621,8 @@ void TagEditor::EnterPressed()
ShowMessage("Writing tags in \"%s\"...", (*it)->GetName().c_str()); ShowMessage("Writing tags in \"%s\"...", (*it)->GetName().c_str());
if (!WriteTags(**it)) if (!WriteTags(**it))
{ {
ShowMessage("Error writing tags in \"%s\"!", (*it)->GetFile().c_str()); static const char msg[] = "Error while writing tags in \"%s\"!";
ShowMessage(msg, Shorten(TO_WSTRING((*it)->GetFile()), COLS-static_strlen(msg)).c_str());
success = 0; success = 0;
break; break;
} }

View File

@@ -65,7 +65,7 @@ void TinyTagEditor::SwitchTo()
{ {
if (itsEdited.isStream()) if (itsEdited.isStream())
{ {
ShowMessage("Cannot edit streams!"); ShowMessage("Streams cannot be edited!");
} }
else if (GetTags()) else if (GetTags())
{ {
@@ -77,11 +77,11 @@ void TinyTagEditor::SwitchTo()
} }
else else
{ {
std::string message = "Cannot read file '"; std::string message = "Couldn't read file \"";
if (itsEdited.isFromDB()) if (itsEdited.isFromDB())
message += Config.mpd_music_dir; message += Config.mpd_music_dir;
message += itsEdited.GetFile(); message += Shorten(TO_WSTRING(itsEdited.GetFile()), COLS-message.length()-3);
message += "'!"; message += "\"!";
ShowMessage("%s", message.c_str()); ShowMessage("%s", message.c_str());
} }
} }
@@ -142,7 +142,7 @@ void TinyTagEditor::EnterPressed()
} }
} }
else else
ShowMessage("Error writing tags!"); ShowMessage("Error while writing tags!");
} }
if (option > 20) if (option > 20)
myOldScreen->SwitchTo(); myOldScreen->SwitchTo();