a lot of code clean-ups, remove song info screen

This commit is contained in:
unK
2008-09-09 16:49:22 +02:00
parent cad4d36807
commit 0e1e3c6342
16 changed files with 604 additions and 500 deletions

View File

@@ -18,8 +18,8 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <algorithm>
#include "helpers.h"
#include "settings.h"
extern MPDConnection *Mpd;
@@ -27,21 +27,14 @@ extern ncmpcpp_config Config;
extern Menu<Song> *mPlaylist;
extern Menu<Item> *mBrowser;
extern Menu<string> *mTagEditor;
extern Menu<string> *mSearcher;
extern Menu<Song> *mPlaylistEditor;
extern Window *wFooter;
extern NcmpcppScreen current_screen;
extern Song edited_song;
extern Song searched_song;
extern int block_statusbar_update_delay;
extern int lock_statusbar_delay;
extern int browsed_dir_scroll_begin;
extern time_t block_delay;
extern time_t time_of_statusbar_lock;
extern string browsed_dir;
@@ -50,9 +43,9 @@ extern bool block_progressbar_update;
extern bool block_statusbar_update;
extern bool search_case_sensitive;
extern bool search_mode_match;
extern bool search_match_to_pattern;
extern bool redraw_me;
extern bool redraw_screen;
extern string EMPTY_TAG;
extern string UNKNOWN_ARTIST;
@@ -61,8 +54,6 @@ extern string UNKNOWN_ALBUM;
bool CaseInsensitiveSorting::operator()(string a, string b)
{
//a = Window::OmitBBCodes(a);
//b = Window::OmitBBCodes(b);
transform(a.begin(), a.end(), a.begin(), tolower);
transform(b.begin(), b.end(), b.begin(), tolower);
return a < b;
@@ -132,25 +123,6 @@ void UpdateSongList(Menu<Song> *menu)
menu->Refresh();
}
void UpdateFoundList(const SongList &v)
{
int i = search_engine_static_option;
bool bold = 0;
for (SongList::const_iterator it = v.begin(); it != v.end(); it++, i++)
{
for (int j = 0; j < mPlaylist->Size(); j++)
{
if (mPlaylist->at(j).GetHash() == (*it)->GetHash())
{
bold = 1;
break;
}
}
mSearcher->BoldOption(i, bold);
bold = 0;
}
}
string DisplayKeys(int *key, int size)
{
bool backspace = 1;
@@ -225,33 +197,6 @@ void WindowTitle(const string &status)
printf("\033]0;%s\7",status.c_str());
}
string FindSharedDir(Menu<Song> *menu)
{
SongList list;
for (int i = 0; i < menu->Size(); i++)
list.push_back(&menu->at(i));
return FindSharedDir(list);
}
string FindSharedDir(const SongList &v)
{
string result;
if (!v.empty())
{
result = v.front()->GetFile();
for (SongList::const_iterator it = v.begin()+1; it != v.end(); it++)
{
int i = 1;
while (result.substr(0, i) == (*it)->GetFile().substr(0, i))
i++;
result = result.substr(0, i);
}
int slash = result.find_last_of("/");
result = slash != string::npos ? result.substr(0, slash) : "/";
}
return result;
}
string TotalPlaylistLength()
{
const int MINUTE = 60;
@@ -305,31 +250,6 @@ string TotalPlaylistLength()
return result;
}
string DisplayTag(const Song &s, void *data)
{
switch (static_cast<Menu<string> *>(data)->GetChoice())
{
case 0:
return s.GetTitle();
case 1:
return s.GetArtist();
case 2:
return s.GetAlbum();
case 3:
return s.GetYear();
case 4:
return s.GetTrack();
case 5:
return s.GetGenre();
case 6:
return s.GetComment();
case 8:
return s.GetShortFilename();
default:
return "";
}
}
string DisplayItem(const Item &item, void *)
{
switch (item.type)
@@ -773,158 +693,12 @@ string DisplaySong(const Song &s, void *s_template)
return result;
}
void PrepareSearchEngine(Song &s)
{
s.Clear();
mSearcher->Clear();
mSearcher->Reset();
mSearcher->AddOption("[.b]Filename:[/b] " + s.GetShortFilename());
mSearcher->AddOption("[.b]Title:[/b] " + s.GetTitle());
mSearcher->AddOption("[.b]Artist:[/b] " + s.GetArtist());
mSearcher->AddOption("[.b]Album:[/b] " + s.GetAlbum());
mSearcher->AddOption("[.b]Year:[/b] " + s.GetYear());
mSearcher->AddOption("[.b]Track:[/b] " + s.GetTrack());
mSearcher->AddOption("[.b]Genre:[/b] " + s.GetGenre());
mSearcher->AddOption("[.b]Comment:[/b] " + s.GetComment());
mSearcher->AddSeparator();
mSearcher->AddOption("[.b]Search mode:[/b] " + (search_mode_match ? search_mode_one : search_mode_two));
mSearcher->AddOption("[.b]Case sensitive:[/b] " + (string)(search_case_sensitive ? "Yes" : "No"));
mSearcher->AddSeparator();
mSearcher->AddOption("Search");
mSearcher->AddOption("Reset");
}
void Search(SongList &result, Song &s)
{
FreeSongList(result);
if (s.Empty())
return;
SongList list;
Mpd->GetDirectoryRecursive("/", list);
bool found = 1;
s.GetEmptyFields(1);
if (!search_case_sensitive)
{
string t;
t = s.GetShortFilename();
transform(t.begin(), t.end(), t.begin(), tolower);
s.SetShortFilename(t);
t = s.GetTitle();
transform(t.begin(), t.end(), t.begin(), tolower);
s.SetTitle(t);
t = s.GetArtist();
transform(t.begin(), t.end(), t.begin(), tolower);
s.SetArtist(t);
t = s.GetAlbum();
transform(t.begin(), t.end(), t.begin(), tolower);
s.SetAlbum(t);
t = s.GetGenre();
transform(t.begin(), t.end(), t.begin(), tolower);
s.SetGenre(t);
t = s.GetComment();
transform(t.begin(), t.end(), t.begin(), tolower);
s.SetComment(t);
}
for (SongList::const_iterator it = list.begin(); it != list.end(); it++)
{
Song copy = **it;
if (!search_case_sensitive)
{
string t;
t = copy.GetShortFilename();
transform(t.begin(), t.end(), t.begin(), tolower);
copy.SetShortFilename(t);
t = copy.GetTitle();
transform(t.begin(), t.end(), t.begin(), tolower);
copy.SetTitle(t);
t = copy.GetArtist();
transform(t.begin(), t.end(), t.begin(), tolower);
copy.SetArtist(t);
t = copy.GetAlbum();
transform(t.begin(), t.end(), t.begin(), tolower);
copy.SetAlbum(t);
t = copy.GetGenre();
transform(t.begin(), t.end(), t.begin(), tolower);
copy.SetGenre(t);
t = copy.GetComment();
transform(t.begin(), t.end(), t.begin(), tolower);
copy.SetComment(t);
}
if (search_mode_match)
{
if (found && !s.GetShortFilename().empty())
found = copy.GetShortFilename().find(s.GetShortFilename()) != string::npos;
if (found && !s.GetTitle().empty())
found = copy.GetTitle().find(s.GetTitle()) != string::npos;
if (found && !s.GetArtist().empty())
found = copy.GetArtist().find(s.GetArtist()) != string::npos;
if (found && !s.GetAlbum().empty())
found = copy.GetAlbum().find(s.GetAlbum()) != string::npos;
if (found && !s.GetYear().empty())
found = StrToInt(copy.GetYear()) == StrToInt(s.GetYear()) && StrToInt(s.GetYear());
if (found && !s.GetTrack().empty())
found = StrToInt(copy.GetTrack()) == StrToInt(s.GetTrack()) && StrToInt(s.GetTrack());
if (found && !s.GetGenre().empty())
found = copy.GetGenre().find(s.GetGenre()) != string::npos;
if (found && !s.GetComment().empty())
found = copy.GetComment().find(s.GetComment()) != string::npos;
}
else
{
if (found && !s.GetShortFilename().empty())
found = copy.GetShortFilename() == s.GetShortFilename();
if (found && !s.GetTitle().empty())
found = copy.GetTitle() == s.GetTitle();
if (found && !s.GetArtist().empty())
found = copy.GetArtist() == s.GetArtist();
if (found && !s.GetAlbum().empty())
found = copy.GetAlbum() == s.GetAlbum();
if (found && !s.GetYear().empty())
found = StrToInt(copy.GetYear()) == StrToInt(s.GetYear()) && StrToInt(s.GetYear());
if (found && !s.GetTrack().empty())
found = StrToInt(copy.GetTrack()) == StrToInt(s.GetTrack()) && StrToInt(s.GetTrack());
if (found && !s.GetGenre().empty())
found = copy.GetGenre() == s.GetGenre();
if (found && !s.GetComment().empty())
found = copy.GetComment() == s.GetComment();
}
if (found)
{
Song *ss = new Song(**it);
result.push_back(ss);
}
found = 1;
}
FreeSongList(list);
s.GetEmptyFields(0);
}
void ShowMessage(const string &message, int delay)
{
if (messages_allowed)
{
block_delay = time(NULL);
block_statusbar_update_delay = delay;
time_of_statusbar_lock = time(NULL);
lock_statusbar_delay = delay;
if (Config.statusbar_visibility)
block_statusbar_update = 1;
else
@@ -935,83 +709,6 @@ void ShowMessage(const string &message, int delay)
}
}
#ifdef HAVE_TAGLIB_H
bool WriteTags(Song &s)
{
string path_to_file = Config.mpd_music_dir + "/" + s.GetFile();
TagLib::FileRef f(path_to_file.c_str());
if (!f.isNull())
{
s.GetEmptyFields(1);
f.tag()->setTitle(TO_WSTRING(s.GetTitle()));
f.tag()->setArtist(TO_WSTRING(s.GetArtist()));
f.tag()->setAlbum(TO_WSTRING(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()));
s.GetEmptyFields(0);
f.save();
return true;
}
else
return false;
}
#endif // HAVE_TAGLIB_H
bool GetSongInfo(Song &s)
{
string path_to_file = Config.mpd_music_dir + "/" + s.GetFile();
# ifdef HAVE_TAGLIB_H
TagLib::FileRef f(path_to_file.c_str());
if (f.isNull())
return false;
s.SetComment(f.tag()->comment().to8Bit(UNICODE));
# endif
mTagEditor->Clear();
mTagEditor->Reset();
mTagEditor->AddStaticOption("[.b][.white]Song name: [/white][.green][/b]" + s.GetShortFilename() + "[/green]");
mTagEditor->AddStaticOption("[.b][.white]Location in DB: [/white][.green][/b]" + s.GetDirectory() + "[/green]");
mTagEditor->AddStaticOption("");
mTagEditor->AddStaticOption("[.b][.white]Length: [/white][.green][/b]" + s.GetLength() + "[/green]");
# ifdef HAVE_TAGLIB_H
mTagEditor->AddStaticOption("[.b][.white]Bitrate: [/white][.green][/b]" + IntoStr(f.audioProperties()->bitrate()) + " kbps[/green]");
mTagEditor->AddStaticOption("[.b][.white]Sample rate: [/white][.green][/b]" + IntoStr(f.audioProperties()->sampleRate()) + " Hz[/green]");
mTagEditor->AddStaticOption("[.b][.white]Channels: [/white][.green][/b]" + (string)(f.audioProperties()->channels() == 1 ? "Mono" : "Stereo") + "[/green]");
# endif
mTagEditor->AddSeparator();
# ifdef HAVE_TAGLIB_H
mTagEditor->AddOption("[.b]Title:[/b] " + s.GetTitle());
mTagEditor->AddOption("[.b]Artist:[/b] " + s.GetArtist());
mTagEditor->AddOption("[.b]Album:[/b] " + s.GetAlbum());
mTagEditor->AddOption("[.b]Year:[/b] " + s.GetYear());
mTagEditor->AddOption("[.b]Track:[/b] " + s.GetTrack());
mTagEditor->AddOption("[.b]Genre:[/b] " + s.GetGenre());
mTagEditor->AddOption("[.b]Comment:[/b] " + s.GetComment());
mTagEditor->AddSeparator();
mTagEditor->AddOption("Save");
mTagEditor->AddOption("Cancel");
# else
mTagEditor->AddStaticOption("[.b]Title:[/b] " + s.GetTitle());
mTagEditor->AddStaticOption("[.b]Artist:[/b] " + s.GetArtist());
mTagEditor->AddStaticOption("[.b]Album:[/b] " + s.GetAlbum());
mTagEditor->AddStaticOption("[.b]Year:[/b] " + s.GetYear());
mTagEditor->AddStaticOption("[.b]Track:[/b] " + s.GetTrack());
mTagEditor->AddStaticOption("[.b]Genre:[/b] " + s.GetGenre());
mTagEditor->AddStaticOption("[.b]Comment:[/b] " + s.GetComment());
mTagEditor->AddSeparator();
mTagEditor->AddOption("Back");
# endif
edited_song = s;
return true;
}
void GetDirectory(string dir, string subdir)
{
int highlightme = -1;