local browser: properly check if file extension is supported

This commit is contained in:
Andrzej Rybczak
2012-01-15 13:23:07 +01:00
parent b058fdce30
commit 57511bb941
4 changed files with 28 additions and 13 deletions

View File

@@ -47,13 +47,7 @@ using MPD::itPlaylist;
Browser *myBrowser = new Browser; Browser *myBrowser = new Browser;
const char *Browser::SupportedExtensions[] = std::set<std::string> 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()
{ {
@@ -68,6 +62,10 @@ void Browser::Init()
w->SetItemDisplayer(Display::Items); w->SetItemDisplayer(Display::Items);
w->SetItemDisplayerUserData(&sf); w->SetItemDisplayerUserData(&sf);
w->SetGetStringFunction(ItemToString); w->SetGetStringFunction(ItemToString);
if (SupportedExtensions.empty())
Mpd.GetSupportedExtensions(SupportedExtensions);
isInitialized = 1; isInitialized = 1;
} }
@@ -330,11 +328,7 @@ bool Browser::hasSupportedExtension(const std::string &file)
std::string ext = file.substr(last_dot+1); std::string ext = file.substr(last_dot+1);
ToLower(ext); ToLower(ext);
for (int i = 0; SupportedExtensions[i]; ++i) return SupportedExtensions.find(ext) != SupportedExtensions.end();
if (strcmp(ext.c_str(), SupportedExtensions[i]) == 0)
return true;
return false;
} }
void Browser::LocateSong(const MPD::Song &s) void Browser::LocateSong(const MPD::Song &s)

View File

@@ -73,7 +73,7 @@ class Browser : public Screen< Menu<MPD::Item> >
static bool hasSupportedExtension(const std::string &); static bool hasSupportedExtension(const std::string &);
static std::string ItemToString(const MPD::Item &, void *); static std::string ItemToString(const MPD::Item &, void *);
static const char *SupportedExtensions[]; static std::set<std::string> SupportedExtensions;
bool itsBrowseLocally; bool itsBrowseLocally;
size_t itsScrollBeginning; size_t itsScrollBeginning;

View File

@@ -682,6 +682,24 @@ void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
GoIdle(); GoIdle();
} }
void MPD::Connection::GetSupportedExtensions(std::set<std::string> &acc)
{
if (!itsConnection)
return;
assert(!isCommandsListEnabled);
GoBusy();
mpd_send_command(itsConnection, "decoders", NULL);
if (mpd_pair *pair = mpd_recv_pair_named(itsConnection, "suffix"))
{
acc.insert(pair->value);
mpd_return_pair(itsConnection, pair);
}
mpd_response_finish(itsConnection);
GoIdle();
}
void MPD::Connection::SetRepeat(bool mode) void MPD::Connection::SetRepeat(bool mode)
{ {
if (!itsConnection) if (!itsConnection)

View File

@@ -21,6 +21,7 @@
#ifndef _MPDPP_H #ifndef _MPDPP_H
#define _MPDPP_H #define _MPDPP_H
#include <set>
#include <vector> #include <vector>
#include <mpd/client.h> #include <mpd/client.h>
@@ -162,6 +163,8 @@ namespace MPD
Song GetSong(const std::string &); Song GetSong(const std::string &);
void GetPlaylistContent(const std::string &, SongList &); void GetPlaylistContent(const std::string &, SongList &);
void GetSupportedExtensions(std::set<std::string> &);
void SetRepeat(bool); void SetRepeat(bool);
void SetRandom(bool); void SetRandom(bool);
void SetSingle(bool); void SetSingle(bool);