local browser: properly check if file extension is supported
This commit is contained in:
@@ -47,13 +47,7 @@ using MPD::itPlaylist;
|
||||
|
||||
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
|
||||
};
|
||||
std::set<std::string> Browser::SupportedExtensions;
|
||||
|
||||
void Browser::Init()
|
||||
{
|
||||
@@ -68,6 +62,10 @@ void Browser::Init()
|
||||
w->SetItemDisplayer(Display::Items);
|
||||
w->SetItemDisplayerUserData(&sf);
|
||||
w->SetGetStringFunction(ItemToString);
|
||||
|
||||
if (SupportedExtensions.empty())
|
||||
Mpd.GetSupportedExtensions(SupportedExtensions);
|
||||
|
||||
isInitialized = 1;
|
||||
}
|
||||
|
||||
@@ -330,11 +328,7 @@ bool Browser::hasSupportedExtension(const std::string &file)
|
||||
|
||||
std::string ext = file.substr(last_dot+1);
|
||||
ToLower(ext);
|
||||
for (int i = 0; SupportedExtensions[i]; ++i)
|
||||
if (strcmp(ext.c_str(), SupportedExtensions[i]) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
return SupportedExtensions.find(ext) != SupportedExtensions.end();
|
||||
}
|
||||
|
||||
void Browser::LocateSong(const MPD::Song &s)
|
||||
|
||||
@@ -73,7 +73,7 @@ class Browser : public Screen< Menu<MPD::Item> >
|
||||
static bool hasSupportedExtension(const std::string &);
|
||||
static std::string ItemToString(const MPD::Item &, void *);
|
||||
|
||||
static const char *SupportedExtensions[];
|
||||
static std::set<std::string> SupportedExtensions;
|
||||
|
||||
bool itsBrowseLocally;
|
||||
size_t itsScrollBeginning;
|
||||
|
||||
@@ -682,6 +682,24 @@ void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
|
||||
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)
|
||||
{
|
||||
if (!itsConnection)
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef _MPDPP_H
|
||||
#define _MPDPP_H
|
||||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include <mpd/client.h>
|
||||
@@ -162,6 +163,8 @@ namespace MPD
|
||||
Song GetSong(const std::string &);
|
||||
void GetPlaylistContent(const std::string &, SongList &);
|
||||
|
||||
void GetSupportedExtensions(std::set<std::string> &);
|
||||
|
||||
void SetRepeat(bool);
|
||||
void SetRandom(bool);
|
||||
void SetSingle(bool);
|
||||
|
||||
Reference in New Issue
Block a user