| 1 |
/* |
| 2 |
* mptFileType.h |
| 3 |
* ------------- |
| 4 |
* Purpose: |
| 5 |
* Notes : Currently none. |
| 6 |
* Authors: OpenMPT Devs |
| 7 |
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details. |
| 8 |
*/ |
| 9 |
|
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include "openmpt/all/BuildSettings.hpp" |
| 14 |
|
| 15 |
#include "mpt/base/alloc.hpp" |
| 16 |
#include "mpt/base/namespace.hpp" |
| 17 |
#include "mpt/string/types.hpp" |
| 18 |
|
| 19 |
#include "openmpt/base/FlagSet.hpp" |
| 20 |
|
| 21 |
#include <vector> |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
OPENMPT_NAMESPACE_BEGIN |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#if defined(MODPLUG_TRACKER) |
| 30 |
|
| 31 |
enum FileTypeFormat |
| 32 |
{ |
| 33 |
FileTypeFormatNone = 0 , // do not show extensions after description, i.e. "Foo Files" |
| 34 |
FileTypeFormatShowExtensions = 1<<0, // show extensions after descripten, i.e. "Foo Files (*.foo,*.bar)" |
| 35 |
}; |
| 36 |
MPT_DECLARE_ENUM(FileTypeFormat) |
| 37 |
|
| 38 |
class FileType |
| 39 |
{ |
| 40 |
private: |
| 41 |
mpt::ustring m_ShortName; // "flac", "mod" (lowercase) |
| 42 |
mpt::ustring m_Description; // "FastTracker 2 Module" |
| 43 |
std::vector<std::string> m_MimeTypes; // "audio/ogg" (in ASCII) |
| 44 |
std::vector<mpt::PathString> m_Extensions; // "mod", "xm" (lowercase) |
| 45 |
std::vector<mpt::PathString> m_Prefixes; // "mod" for "mod.*" |
| 46 |
public: |
| 47 |
FileType() { } |
| 48 |
FileType(const std::vector<FileType> &group) |
| 49 |
{ |
| 50 |
for(const auto &type : group) |
| 51 |
{ |
| 52 |
mpt::append(m_MimeTypes, type.m_MimeTypes); |
| 53 |
mpt::append(m_Extensions, type.m_Extensions); |
| 54 |
mpt::append(m_Prefixes, type.m_Prefixes); |
| 55 |
} |
| 56 |
} |
| 57 |
static FileType Any() |
| 58 |
{ |
| 59 |
return FileType().ShortName(U_("*")).Description(U_("All Files")).AddExtension(P_("*")); |
| 60 |
} |
| 61 |
public: |
| 62 |
FileType& ShortName(const mpt::ustring &shortName) { m_ShortName = shortName; return *this; } |
| 63 |
FileType& Description(const mpt::ustring &description) { m_Description = description; return *this; } |
| 64 |
FileType& MimeTypes(const std::vector<std::string> &mimeTypes) { m_MimeTypes = mimeTypes; return *this; } |
| 65 |
FileType& Extensions(const std::vector<mpt::PathString> &extensions) { m_Extensions = extensions; return *this; } |
| 66 |
FileType& Prefixes(const std::vector<mpt::PathString> &prefixes) { m_Prefixes = prefixes; return *this; } |
| 67 |
FileType& AddMimeType(const std::string &mimeType) { m_MimeTypes.push_back(mimeType); return *this; } |
| 68 |
FileType& AddExtension(const mpt::PathString &extension) { m_Extensions.push_back(extension); return *this; } |
| 69 |
FileType& AddPrefix(const mpt::PathString &prefix) { m_Prefixes.push_back(prefix); return *this; } |
| 70 |
public: |
| 71 |
mpt::ustring GetShortName() const { return m_ShortName; } |
| 72 |
mpt::ustring GetDescription() const { return m_Description; } |
| 73 |
std::vector<std::string> GetMimeTypes() const { return m_MimeTypes; } |
| 74 |
std::vector<mpt::PathString> GetExtensions() const { return m_Extensions; } |
| 75 |
std::vector<mpt::PathString> GetPrefixes() const { return m_Prefixes; } |
| 76 |
public: |
| 77 |
mpt::PathString AsFilterString(FlagSet<FileTypeFormat> format = FileTypeFormatNone) const; |
| 78 |
mpt::PathString AsFilterOnlyString() const; |
| 79 |
}; // class FileType |
| 80 |
|
| 81 |
|
| 82 |
// "Ogg Vorbis|*.ogg;*.oga|" // FileTypeFormatNone |
| 83 |
// "Ogg Vorbis (*.ogg,*.oga)|*.ogg;*.oga|" // FileTypeFormatShowExtensions |
| 84 |
mpt::PathString ToFilterString(const FileType &fileType, FlagSet<FileTypeFormat> format = FileTypeFormatNone); |
| 85 |
mpt::PathString ToFilterString(const std::vector<FileType> &fileTypes, FlagSet<FileTypeFormat> format = FileTypeFormatNone); |
| 86 |
|
| 87 |
// "*.ogg;*.oga" / ";*.ogg;*.oga" |
| 88 |
mpt::PathString ToFilterOnlyString(const FileType &fileType, bool prependSemicolonWhenNotEmpty = false); |
| 89 |
mpt::PathString ToFilterOnlyString(const std::vector<FileType> &fileTypes, bool prependSemicolonWhenNotEmpty = false); |
| 90 |
|
| 91 |
#endif // MODPLUG_TRACKER |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
OPENMPT_NAMESPACE_END |