move functions from unnamed namespace to Browser class

This commit is contained in:
Andrzej Rybczak
2009-03-01 00:33:10 +01:00
parent aed227ab5f
commit 27535e133c
2 changed files with 61 additions and 53 deletions

View File

@@ -41,6 +41,14 @@ using std::string;
Browser *myBrowser = new Browser; Browser *myBrowser = new Browser;
const char *Browser::SupportedExtensions[] =
{
"wma", "asf", "rm", "mp1", "mp2", "mp3",
"mp4", "m4a", "flac", "ogg", "wav", "au",
"aiff", "aif", "ac3", "aac", "mpc", "it",
"mod", "s3m", "xm", "wv", 0
};
void Browser::Init() void Browser::Init()
{ {
w = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone); w = new Menu<Item>(0, main_start_y, COLS, main_height, "", Config.main_color, brNone);
@@ -273,40 +281,37 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
} }
} }
namespace bool Browser::hasSupportedExtension(const string &file)
{ {
const char *supported_extensions[] = { "wma", "asf", "rm", "mp1", "mp2", "mp3", "mp4", "m4a", "flac", "ogg", "wav", "au", "aiff", "aif", "ac3", "aac", "mpc", "it", "mod", "s3m", "xm", "wv", 0 };
bool hasSupportedExtension(const string &file)
{
size_t last_dot = file.rfind("."); size_t last_dot = file.rfind(".");
if (last_dot > file.length()) if (last_dot > file.length())
return false; return false;
string ext = file.substr(last_dot+1); string ext = file.substr(last_dot+1);
ToLower(ext); ToLower(ext);
for (int i = 0; supported_extensions[i]; i++) for (int i = 0; SupportedExtensions[i]; i++)
if (strcmp(ext.c_str(), supported_extensions[i]) == 0) if (strcmp(ext.c_str(), SupportedExtensions[i]) == 0)
return true; return true;
return false; return false;
} }
void GetLocalDirectory(const string &dir, ItemList &v) void Browser::GetLocalDirectory(ItemList &v)
{ {
dirent **list; dirent **list;
int n = scandir(dir.c_str(), &list, NULL, alphasort); int n = scandir(itsBrowsedDir.c_str(), &list, NULL, alphasort);
if (n < 0) if (n < 0)
return; return;
struct stat file_stat; struct stat file_stat;
string full_path; string full_path;
for (int i = 2; i < n; i++) for (int i = 2; i < n; i++)
{ {
Item new_item; Item new_item;
full_path = dir; full_path = itsBrowsedDir;
if (dir != "/") if (itsBrowsedDir != "/")
full_path += "/"; full_path += "/";
full_path += list[i]->d_name; full_path += list[i]->d_name;
stat(full_path.c_str(), &file_stat); stat(full_path.c_str(), &file_stat);
@@ -330,7 +335,6 @@ namespace
delete list[i]; delete list[i];
} }
delete list; delete list;
}
} }
void Browser::LocateSong(const MPD::Song &s) void Browser::LocateSong(const MPD::Song &s)
@@ -385,7 +389,7 @@ void Browser::GetDirectory(string dir, string subdir)
} }
ItemList list; ItemList list;
Config.local_browser ? GetLocalDirectory(dir, list) : Mpd->GetDirectory(dir, list); Config.local_browser ? GetLocalDirectory(list) : Mpd->GetDirectory(dir, list);
sort(list.begin(), list.end(), CaseInsensitiveSorting()); sort(list.begin(), list.end(), CaseInsensitiveSorting());
for (ItemList::iterator it = list.begin(); it != list.end(); it++) for (ItemList::iterator it = list.begin(); it != list.end(); it++)

View File

@@ -56,10 +56,14 @@ class Browser : public Screen< Menu<MPD::Item> >
void UpdateItemList(); void UpdateItemList();
protected: protected:
void GetLocalDirectory(MPD::ItemList &);
static bool hasSupportedExtension(const std::string &);
static std::string ItemToString(const MPD::Item &, void *); static std::string ItemToString(const MPD::Item &, void *);
size_t itsScrollBeginning; static const char *SupportedExtensions[];
size_t itsScrollBeginning;
std::string itsBrowsedDir; std::string itsBrowsedDir;
}; };