support for dirs/playlists rename in browser
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
##### connection settings #####
|
##### connection settings #####
|
||||||
#
|
#
|
||||||
## set it in order to make tag editor work
|
## set it in order to make tag editor and renaming files work properly
|
||||||
#
|
#
|
||||||
#mpd_music_dir = "/var/lib/mpd/music"
|
#mpd_music_dir = "/var/lib/mpd/music"
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -162,6 +162,19 @@ void WindowTitle(const string &status)
|
|||||||
printf("\033]0;%s\7",status.c_str());
|
printf("\033]0;%s\7",status.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string FindSharedDir(const string &one, const string &two)
|
||||||
|
{
|
||||||
|
if (one == two)
|
||||||
|
return one;
|
||||||
|
string result;
|
||||||
|
int i = 1;
|
||||||
|
while (one.substr(0, i) == two.substr(0, i))
|
||||||
|
i++;
|
||||||
|
result = one.substr(0, i);
|
||||||
|
i = result.find_last_of("/");
|
||||||
|
return i != string::npos ? result.substr(0, i) : "/";
|
||||||
|
}
|
||||||
|
|
||||||
string TotalPlaylistLength()
|
string TotalPlaylistLength()
|
||||||
{
|
{
|
||||||
const int MINUTE = 60;
|
const int MINUTE = 60;
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ bool Keypressed(int, const int *);
|
|||||||
|
|
||||||
void WindowTitle(const string &);
|
void WindowTitle(const string &);
|
||||||
|
|
||||||
|
string FindSharedDir(const string &, const string &);
|
||||||
string TotalPlaylistLength();
|
string TotalPlaylistLength();
|
||||||
string DisplayStringPair(const StringPair &, void *, const Menu<StringPair> *);
|
string DisplayStringPair(const StringPair &, void *, const Menu<StringPair> *);
|
||||||
string DisplayItem(const Item &, void *, const Menu<Item> *);
|
string DisplayItem(const Item &, void *, const Menu<Item> *);
|
||||||
|
|||||||
@@ -2313,35 +2313,79 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (wCurrent == mEditorDirs)
|
else if (wCurrent == mEditorDirs)
|
||||||
{
|
{
|
||||||
|
string old_dir = mEditorDirs->Current().first;
|
||||||
LockStatusbar();
|
LockStatusbar();
|
||||||
wFooter->WriteXY(0, Config.statusbar_visibility, "Directory: ", 1);
|
wFooter->WriteXY(0, Config.statusbar_visibility, "Directory: ", 1);
|
||||||
string new_dir = wFooter->GetString(mEditorDirs->Current().first);
|
string new_dir = wFooter->GetString(old_dir);
|
||||||
UnlockStatusbar();
|
UnlockStatusbar();
|
||||||
if (!new_dir.empty() && new_dir != mEditorDirs->Current().first)
|
if (!new_dir.empty() && new_dir != old_dir)
|
||||||
{
|
{
|
||||||
string old_dir = Config.mpd_music_dir + mEditorDirs->Current().second;
|
string full_old_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + old_dir;
|
||||||
new_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + new_dir;
|
string full_new_dir = Config.mpd_music_dir + editor_browsed_dir + "/" + new_dir;
|
||||||
if (rename(old_dir.c_str(), new_dir.c_str()) == 0)
|
if (rename(full_old_dir.c_str(), full_new_dir.c_str()) == 0)
|
||||||
{
|
{
|
||||||
ShowMessage("'" + mEditorDirs->Current().first + "' renamed to '" + new_dir);
|
|
||||||
Mpd->UpdateDirectory(editor_browsed_dir);
|
Mpd->UpdateDirectory(editor_browsed_dir);
|
||||||
|
ShowMessage("'" + old_dir + "' renamed to '" + new_dir + "'");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ShowMessage("Cannot rename '" + old_dir + "' to '" + new_dir + "'!");
|
ShowMessage("Cannot rename '" + full_old_dir + "' to '" + full_new_dir + "'!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif // HAVE_TAGLIB_H
|
# endif // HAVE_TAGLIB_H
|
||||||
if (wCurrent == mPlaylistList)
|
if (wCurrent == mBrowser && mBrowser->Current().type == itDirectory)
|
||||||
{
|
{
|
||||||
|
string old_dir = mBrowser->Current().name;
|
||||||
|
LockStatusbar();
|
||||||
|
wFooter->WriteXY(0, Config.statusbar_visibility, "[.b]Directory:[/b] ", 1);
|
||||||
|
string new_dir = wFooter->GetString(old_dir);
|
||||||
|
UnlockStatusbar();
|
||||||
|
if (!new_dir.empty() && new_dir != old_dir)
|
||||||
|
{
|
||||||
|
string full_old_dir = Config.mpd_music_dir + old_dir;
|
||||||
|
string full_new_dir = Config.mpd_music_dir + new_dir;
|
||||||
|
if (rename(full_old_dir.c_str(), full_new_dir.c_str()) == 0)
|
||||||
|
{
|
||||||
|
ShowMessage("'" + old_dir + "' renamed to '" + new_dir + "'");
|
||||||
|
Mpd->UpdateDirectory(FindSharedDir(old_dir, new_dir));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ShowMessage("Cannot rename '" + full_old_dir + "' to '" + full_new_dir + "'!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// blah, this key is already reserved for TagEditor. I'll merge this to its screen later.
|
||||||
|
/*else if (wCurrent == mBrowser && mBrowser->Current().type == itSong)
|
||||||
|
{
|
||||||
|
string old_name = mBrowser->Current().song->GetFile();
|
||||||
|
LockStatusbar();
|
||||||
|
wFooter->WriteXY(0, Config.statusbar_visibility, "[.b]Filename:[/b] ", 1);
|
||||||
|
string new_name = wFooter->GetString(old_name);
|
||||||
|
UnlockStatusbar();
|
||||||
|
if (!new_name.empty() && new_name != old_name)
|
||||||
|
{
|
||||||
|
string full_old_name = Config.mpd_music_dir + old_name;
|
||||||
|
string full_new_name = Config.mpd_music_dir + new_name;
|
||||||
|
if (rename(full_old_name.c_str(), full_new_name.c_str()) == 0)
|
||||||
|
{
|
||||||
|
Mpd->UpdateDirectory(FindSharedDir(old_name, new_name));
|
||||||
|
ShowMessage("'" + old_name + "' renamed to '" + new_name + "'");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ShowMessage("Cannot rename '" + old_name + "' to '" + new_name + "'!");
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
else if (wCurrent == mPlaylistList || wCurrent == mBrowser && mBrowser->Current().type == itPlaylist)
|
||||||
|
{
|
||||||
|
string old_name = wCurrent == mPlaylistList ? mPlaylistList->GetOption() : mBrowser->Current().name;
|
||||||
LockStatusbar();
|
LockStatusbar();
|
||||||
wFooter->WriteXY(0, Config.statusbar_visibility, "[.b]Playlist:[/b] ", 1);
|
wFooter->WriteXY(0, Config.statusbar_visibility, "[.b]Playlist:[/b] ", 1);
|
||||||
string new_name = wFooter->GetString(mPlaylistList->GetOption());
|
string new_name = wFooter->GetString(old_name);
|
||||||
UnlockStatusbar();
|
UnlockStatusbar();
|
||||||
if (!new_name.empty() && new_name != mPlaylistList->GetOption())
|
if (!new_name.empty() && new_name != old_name)
|
||||||
{
|
{
|
||||||
Mpd->Rename(mPlaylistList->GetOption(), new_name);
|
Mpd->Rename(old_name, new_name);
|
||||||
ShowMessage("Playlist '" + mPlaylistList->GetOption() + "' renamed to '" + new_name + "'");
|
ShowMessage("Playlist '" + old_name + "' renamed to '" + new_name + "'");
|
||||||
|
GetDirectory("/");
|
||||||
mPlaylistList->Clear(0);
|
mPlaylistList->Clear(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user