enumerating all MIME types (half finished, doesn't work yet)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
4314ec480e
commit
1b986aef6e
@ -190,6 +190,12 @@ public:
|
|||||||
// read in additional file in mime.types format
|
// read in additional file in mime.types format
|
||||||
bool ReadMimeTypes(const wxString& filename);
|
bool ReadMimeTypes(const wxString& filename);
|
||||||
|
|
||||||
|
// enumerate all known file types: the caller is responsible for freeing
|
||||||
|
// both the array and its elements! The previous value of filetypes is lost
|
||||||
|
//
|
||||||
|
// returns the number of retrieved file types
|
||||||
|
size_t EnumAllFileTypes(wxFileType **filetypes);
|
||||||
|
|
||||||
// these functions can be used to provide default values for some of the
|
// these functions can be used to provide default values for some of the
|
||||||
// MIME types inside the program itself (you may also use
|
// MIME types inside the program itself (you may also use
|
||||||
// ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
|
// ReadMailcap(filenameWithDefaultTypes, TRUE /* use as fallback */) to
|
||||||
|
@ -79,6 +79,10 @@
|
|||||||
// to open/print the file (the positional parameters are introduced by %1,
|
// to open/print the file (the positional parameters are introduced by %1,
|
||||||
// %2, ... in these strings, we change them to %s ourselves)
|
// %2, ... in these strings, we change them to %s ourselves)
|
||||||
|
|
||||||
|
// although I don't know of any official documentation which mentions this
|
||||||
|
// location, uses it, so it isn't likely to change
|
||||||
|
static const wxChar *MIME_DATABASE_KEY = wxT("MIME\\Database\\Content Type\\");
|
||||||
|
|
||||||
class wxFileTypeImpl
|
class wxFileTypeImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -134,6 +138,8 @@ public:
|
|||||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||||
|
|
||||||
|
size_t EnumAllFileTypes(wxFileType **filetypes);
|
||||||
|
|
||||||
// this are NOPs under Windows
|
// this are NOPs under Windows
|
||||||
bool ReadMailcap(const wxString& filename, bool fallback = TRUE)
|
bool ReadMailcap(const wxString& filename, bool fallback = TRUE)
|
||||||
{ return TRUE; }
|
{ return TRUE; }
|
||||||
@ -161,6 +167,8 @@ public :
|
|||||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||||
|
|
||||||
|
size_t EnumAllFileTypes(wxFileType **filetypes);
|
||||||
|
|
||||||
// this are NOPs under MacOS
|
// this are NOPs under MacOS
|
||||||
bool ReadMailcap(const wxString& filename, bool fallback = TRUE) { return TRUE; }
|
bool ReadMailcap(const wxString& filename, bool fallback = TRUE) { return TRUE; }
|
||||||
bool ReadMimeTypes(const wxString& filename) { return TRUE; }
|
bool ReadMimeTypes(const wxString& filename) { return TRUE; }
|
||||||
@ -346,6 +354,8 @@ public:
|
|||||||
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
wxFileType *GetFileTypeFromExtension(const wxString& ext);
|
||||||
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
|
||||||
|
|
||||||
|
size_t EnumAllFileTypes(wxFileType **filetypes);
|
||||||
|
|
||||||
bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
|
bool ReadMailcap(const wxString& filename, bool fallback = FALSE);
|
||||||
bool ReadMimeTypes(const wxString& filename);
|
bool ReadMimeTypes(const wxString& filename);
|
||||||
|
|
||||||
@ -644,6 +654,13 @@ void wxMimeTypesManager::AddFallbacks(const wxFileTypeInfo *filetypes)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t wxMimeTypesManager::EnumAllFileTypes(wxFileType **filetypes)
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( filetypes, 0u, _T("bad pointer in EnumAllFileTypes") );
|
||||||
|
|
||||||
|
return m_impl->EnumAllFileTypes(filetypes);
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// real (OS specific) implementation
|
// real (OS specific) implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@ -896,11 +913,7 @@ wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext)
|
|||||||
wxFileType *
|
wxFileType *
|
||||||
wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
|
wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
|
||||||
{
|
{
|
||||||
// HACK I don't know of any official documentation which mentions this
|
wxString strKey = MIME_DATABASE_KEY;
|
||||||
// location, but as a matter of fact IE uses it, so why not we?
|
|
||||||
static const wxChar *szMimeDbase = wxT("MIME\\Database\\Content Type\\");
|
|
||||||
|
|
||||||
wxString strKey = szMimeDbase;
|
|
||||||
strKey << mimeType;
|
strKey << mimeType;
|
||||||
|
|
||||||
// suppress possible error messages
|
// suppress possible error messages
|
||||||
@ -932,8 +945,15 @@ wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined ( __WXMAC__ )
|
size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxFileType **filetypes)
|
||||||
|
{
|
||||||
|
// enumerate all keys under MIME_DATABASE_KEY
|
||||||
|
wxRegKey key(wxRegKey::HKCR, MIME_DATABASE_KEY);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif defined ( __WXMAC__ )
|
||||||
|
|
||||||
bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const
|
bool wxFileTypeImpl::GetCommand(wxString *command, const char *verb) const
|
||||||
{
|
{
|
||||||
@ -948,12 +968,12 @@ bool wxFileTypeImpl::GetExtensions(wxArrayString& extensions)
|
|||||||
|
|
||||||
bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const
|
bool wxFileTypeImpl::GetMimeType(wxString *mimeType) const
|
||||||
{
|
{
|
||||||
if ( m_strFileType.Length() > 0 )
|
if ( m_strFileType.Length() > 0 )
|
||||||
{
|
{
|
||||||
*mimeType = m_strFileType ;
|
*mimeType = m_strFileType ;
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -972,73 +992,74 @@ bool wxFileTypeImpl::GetDescription(wxString *desc) const
|
|||||||
wxFileType *
|
wxFileType *
|
||||||
wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e)
|
wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& e)
|
||||||
{
|
{
|
||||||
wxString ext = e ;
|
wxString ext = e ;
|
||||||
ext = ext.Lower() ;
|
ext = ext.Lower() ;
|
||||||
if ( ext == "txt" )
|
if ( ext == "txt" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("text/text");
|
fileType->m_impl->SetFileType("text/text");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "htm" || ext == "html" )
|
else if ( ext == "htm" || ext == "html" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("text/html");
|
fileType->m_impl->SetFileType("text/html");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "gif" )
|
else if ( ext == "gif" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/gif");
|
fileType->m_impl->SetFileType("image/gif");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "png" )
|
else if ( ext == "png" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/png");
|
fileType->m_impl->SetFileType("image/png");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "jpg" || ext == "jpeg" )
|
else if ( ext == "jpg" || ext == "jpeg" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/jpeg");
|
fileType->m_impl->SetFileType("image/jpeg");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "bmp" )
|
else if ( ext == "bmp" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/bmp");
|
fileType->m_impl->SetFileType("image/bmp");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "tif" || ext == "tiff" )
|
else if ( ext == "tif" || ext == "tiff" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/tiff");
|
fileType->m_impl->SetFileType("image/tiff");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "xpm" )
|
else if ( ext == "xpm" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/xpm");
|
fileType->m_impl->SetFileType("image/xpm");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
else if ( ext == "xbm" )
|
else if ( ext == "xbm" )
|
||||||
{
|
{
|
||||||
wxFileType *fileType = new wxFileType;
|
wxFileType *fileType = new wxFileType;
|
||||||
fileType->m_impl->SetFileType("image/xbm");
|
fileType->m_impl->SetFileType("image/xbm");
|
||||||
fileType->m_impl->SetExt(ext);
|
fileType->m_impl->SetExt(ext);
|
||||||
return fileType;
|
return fileType;
|
||||||
}
|
}
|
||||||
// unknown extension
|
|
||||||
return NULL;
|
// unknown extension
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// MIME type -> extension -> file type
|
// MIME type -> extension -> file type
|
||||||
@ -1047,6 +1068,14 @@ wxMimeTypesManagerImpl::GetFileTypeFromMimeType(const wxString& mimeType)
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxFileType **filetypes)
|
||||||
|
{
|
||||||
|
wxFAIL_MSG( _T("TODO") ); // VZ: don't know anything about this for Mac
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#else // Unix
|
#else // Unix
|
||||||
|
|
||||||
MailCapEntry *
|
MailCapEntry *
|
||||||
@ -1443,11 +1472,8 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
|
|||||||
strExtensions.Replace(wxT(","), wxT(" "));
|
strExtensions.Replace(wxT(","), wxT(" "));
|
||||||
|
|
||||||
// also deal with the leading dot
|
// also deal with the leading dot
|
||||||
#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
|
if ( !strExtensions.IsEmpty() && strExtensions[0u] == wxT('.') )
|
||||||
if ( !strExtensions.IsEmpty() && strExtensions[size_t(0)] == wxT('.') ) {
|
{
|
||||||
#else
|
|
||||||
if ( !strExtensions.IsEmpty() && strExtensions[0] == wxT('.') ) {
|
|
||||||
#endif
|
|
||||||
strExtensions.erase(0, 1);
|
strExtensions.erase(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1736,6 +1762,20 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxFileType **filetypes)
|
||||||
|
{
|
||||||
|
size_t count = m_aTypes.GetCount();
|
||||||
|
|
||||||
|
*filetypes = new wxFileType *[count];
|
||||||
|
for ( size_t n = 0; n < count; n++ )
|
||||||
|
{
|
||||||
|
(*filetypes)[n] = new wxFileType;
|
||||||
|
(*filetypes)[n]->m_impl->Init(this, n);
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
// OS type
|
// OS type
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user