Skip to content

Commit

Permalink
better filetype handling in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ahigerd committed Aug 31, 2023
1 parent cc77fb5 commit cc9b9cf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
11 changes: 10 additions & 1 deletion gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ void MainWindow::openFile()
return;
}
QStringList filters;
auto exts = m_plugin->extensions();
if (exts.size() > 1) {
QString allExts;
for (const auto& pair : m_plugin->extensions()) {
QString ext = QString::fromStdString(pair.first);
allExts += QStringLiteral(" *.%1").arg(ext);
}
filters << tr("All supported formats (%1)").arg(allExts.trimmed());
}
for (const auto& pair : m_plugin->extensions()) {
QString desc = QString::fromStdString(pair.second);
if (!desc.contains("(")) {
Expand Down Expand Up @@ -127,7 +136,7 @@ void MainWindow::openFile(const QString& path, bool doAcquire, bool autoPlay)
}
{
auto stream = m_plugin->context()->openFile(stdFilename);
if (!m_plugin->isPlayable(stdFilename, *stream)) {
if (!m_plugin->isPlayable(stdFilename, *stream, true)) {
// TODO: error
m_plugin->unload();
ctx = nullptr;
Expand Down
13 changes: 8 additions & 5 deletions src/plugin/baseplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct TagsM3UMixin {
#ifdef BUILD_DUMMY_PLUGIN
struct DummyPluginInfo : public TagsM3UMixin {
S2WPLUGIN_STATIC_FIELDS
static bool isPlayable(std::istream& file) {
static bool isPlayable(S2WContext* s2w, const std::string& filename, std::istream& file, bool ignoreExtension = false) {
return false;
}
static double length(S2WContext* s2w, const std::string& filename, std::istream& file) {
Expand Down Expand Up @@ -84,7 +84,7 @@ class S2WPluginBase {
virtual const std::string& pluginName() const = 0;
virtual const ConstPairList& extensions() const = 0;
virtual const std::string& about() const = 0;
virtual bool isPlayable(const std::string& filename, std::istream& file) const = 0;
virtual bool isPlayable(const std::string& filename, std::istream& file, bool ignoreExtension = false) const = 0;
virtual double length(const std::string& filename, std::istream& file) const = 0;
virtual int sampleRate(const std::string& filename, std::istream& file) const = 0; // of unloaded track

Expand All @@ -101,6 +101,9 @@ class S2WPluginBase {

template <typename Info, typename U = int> struct GetSubsongs {
static std::vector<std::string> getSubsongsImpl(S2WContext* s2w, const std::string& filename, std::istream& file) {
(void)s2w;
(void)filename;
(void)file;
return std::vector<std::string>();
}
};
Expand All @@ -127,14 +130,14 @@ class S2WPlugin : public S2WPluginBase, public PluginInfo {
static std::string message = Info::about + seq2wavCopyright();
return message;
}
virtual bool isPlayable(const std::string& filename, std::istream& file) const {
virtual bool isPlayable(const std::string& filename, std::istream& file, bool ignoreExtension = false) const {
try {
if (!matchExtension(filename)) {
if (!ignoreExtension && !matchExtension(filename)) {
return false;
}
file.clear();
file.seekg(0);
return Info::isPlayable(file);
return Info::isPlayable(s2w, filename, file);
} catch (...) {
return false;
}
Expand Down

0 comments on commit cc9b9cf

Please sign in to comment.