// Purpose: classes and functions to manage MIME types
// Author: Vadim Zeitlin
// Modified by:
+// Chris Elliott (biol75@york.ac.uk) 5 Dec 00: write support for Win32
// Created: 23.09.98
// RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
+#include "wx/module.h"
#ifdef __BORLANDC__
#pragma hdrstop
// implementation classes:
#if defined(__WXMSW__)
-#include "wx/msw/mimetype.h"
+ #include "wx/msw/mimetype.h"
#elif defined (__WXMAC__)
-#include "wx/mac/mimetype.h"
+ #include "wx/mac/mimetype.h"
#elif defined (__WXPM__)
-#include "wx/os2/mimetype.h"
-#else
-#include "wx/unix/mimetype.h"
+ #include "wx/os2/mimetype.h"
+#else // Unix
+ #include "wx/unix/mimetype.h"
#endif
// ============================================================================
const wxChar *pEnd = wxStrchr(pc, wxT('}'));
if ( pEnd == NULL ) {
wxString mimetype;
- wxLogWarning(_("Unmatched '{' in an entry for "
- "mime type %s."),
+ wxLogWarning(_("Unmatched '{' in an entry for mime type %s."),
params.GetMimeType().c_str());
str << wxT("%{");
}
}
// metamail(1) man page states that if the mailcap entry doesn't have '%s'
- // the program will accept the data on stdin: so give it to it!
- if ( !hasFilename && !str.IsEmpty() ) {
+ // the program will accept the data on stdin so normally we should append
+ // "< %s" to the end of the command in such case, but not all commands
+ // behave like this, in particular a common test is 'test -n "$DISPLAY"'
+ // and appending "< %s" to this command makes the test fail... I don't
+ // know of the correct solution, try to guess what we have to do.
+ if ( !hasFilename && !str.IsEmpty()
+#ifdef __UNIX__
+ && !str.StartsWith(_T("test "))
+#endif // Unix
+ ) {
str << wxT(" < '") << params.GetFileName() << wxT('\'');
}
return m_impl->GetMimeTypes(mimeTypes);
}
-bool wxFileType::GetIcon(wxIcon *icon) const
+bool wxFileType::GetIcon(wxIcon *icon,
+ wxString *iconFile,
+ int *iconIndex) const
{
+#ifdef __WXMSW__
+ return m_impl->GetIcon(icon, iconFile, iconIndex);
+#else
return m_impl->GetIcon(icon);
+#endif
}
bool wxFileType::GetDescription(wxString *desc) const
return m_impl->GetPrintCommand(printCmd, params);
}
+
+size_t wxFileType::GetAllCommands(wxArrayString *verbs,
+ wxArrayString *commands,
+ const wxFileType::MessageParameters& params) const
+{
+ if ( verbs )
+ verbs->Clear();
+ if ( commands )
+ commands->Clear();
+
+#ifdef __WXMSW__
+ return m_impl->GetAllCommands(verbs, commands, params);
+#else // !__WXMSW__
+ // we don't know how to retrieve all commands, so just try the 2 we know
+ // about
+ size_t count = 0;
+ wxString cmd;
+ if ( m_impl->GetOpenCommand(&cmd, params) )
+ {
+ if ( verbs )
+ verbs->Add(_T("Open"));
+ if ( commands )
+ commands->Add(cmd);
+ count++;
+ }
+
+ if ( GetPrintCommand(&cmd, params) )
+ {
+ if ( verbs )
+ verbs->Add(_T("Print"));
+ if ( commands )
+ commands->Add(cmd);
+
+ count++;
+ }
+
+ return count;
+#endif // __WXMSW__/!__WXMSW__
+}
+
+bool wxFileType::SetOpenCommand(const wxString& cmd, bool overwriteprompt)
+{
+ return SetCommand(cmd, _T("open"), overwriteprompt);
+}
+
+bool wxFileType::SetCommand(const wxString& cmd, const wxString& verb,
+ bool overwriteprompt)
+{
+#ifdef __WXMSW__
+ return m_impl->SetCommand(cmd, verb, overwriteprompt);
+#else
+ wxFAIL_MSG(_T("not implemented"));
+
+ return FALSE;
+#endif
+}
+
+bool wxFileType::SetMimeType(const wxString& mimeType)
+{
+ // empty MIME type is meaningless here
+ wxCHECK_MSG( !mimeType.empty(), FALSE, _T("use RemoveMimeType()") );
+
+#ifdef __WXMSW__
+ return m_impl->SetMimeType(mimeType);
+#else
+ wxFAIL_MSG(_T("not implemented"));
+
+ return FALSE;
+#endif
+}
+
+bool wxFileType::SetDefaultIcon(const wxString& cmd, int index)
+{
+ wxString sTmp = cmd;
+ // VZ: should we do this?
+ if ( sTmp.empty() )
+ GetOpenCommand(&sTmp, wxFileType::MessageParameters("", ""));
+
+ wxCHECK_MSG( !sTmp.empty(), FALSE, _T("need the icon file") );
+
+
+#ifdef __WXMSW__
+ return m_impl->SetDefaultIcon (cmd, index);
+#else
+ wxFAIL_MSG(_T("not implemented"));
+
+ return FALSE;
+#endif
+}
+
+// now do remove functions
+bool wxFileType::RemoveOpenCommand()
+{
+ return RemoveCommand(_T("open"));
+}
+
+bool wxFileType::RemoveCommand(const wxString& verb)
+{
+#ifdef __WXMSW__
+ return m_impl->RemoveCommand(verb);
+#else
+ wxFAIL_MSG(_T("not implemented"));
+
+ return FALSE;
+#endif
+}
+
+bool wxFileType::RemoveMimeType()
+{
+#ifdef __WXMSW__
+ return m_impl->RemoveMimeType ();
+#else
+ wxFAIL_MSG(_T("not implemented"));
+
+ return FALSE;
+#endif
+}
+
+bool wxFileType::RemoveDefaultIcon()
+{
+#ifdef __WXMSW__
+ return m_impl->RemoveDefaultIcon();
+#else
+ wxFAIL_MSG(_T("not implemented"));
+
+ return FALSE;
+#endif
+}
+
+bool wxFileType::Unassociate()
+{
+ bool result = TRUE;
+ if ( !RemoveOpenCommand() )
+ result = FALSE;
+ if ( !RemoveDefaultIcon() )
+ result = FALSE;
+ if ( !RemoveMimeType() )
+ result = FALSE;
+
+ // in MSW this leaves a HKCR.xzy key
+ return result;
+}
+
// ----------------------------------------------------------------------------
// wxMimeTypesManager
// ----------------------------------------------------------------------------
void wxMimeTypesManager::EnsureImpl()
{
- if (m_impl == NULL)
+ if ( !m_impl )
m_impl = new wxMimeTypesManagerImpl;
}
wxMimeTypesManager::~wxMimeTypesManager()
{
- if (m_impl != NULL)
- delete m_impl;
+ delete m_impl;
}
wxFileType *
return m_impl->GetFileTypeFromExtension(ext);
}
+wxFileType *
+wxMimeTypesManager::GetOrAllocateFileTypeFromExtension(const wxString& ext)
+{
+ EnsureImpl();
+
+#ifdef __WXMSW__
+ // this writes a root entry to the registry in HKCR.ext
+ return m_impl->GetOrAllocateFileTypeFromExtension(ext);
+#else // !__WXMSW__
+ // VZ: "static const"??? (FIXME)
+ // just make a dummy entry with no writing to file
+ static const wxFileTypeInfo fallback[] =
+ {
+ wxFileTypeInfo("application/x-" + ext,
+ "",
+ "",
+ ext + " format file",
+ ext, NULL),
+ // must terminate the table with this!
+ wxFileTypeInfo()
+ };
+
+ AddFallbacks (fallback);
+ return m_impl->GetFileTypeFromExtension(ext);
+#endif // __WXMSW__/!__WXMSW__
+}
+
+
wxFileType *
wxMimeTypesManager::GetFileTypeFromMimeType(const wxString& mimeType)
{
// and public pointer
wxMimeTypesManager * wxTheMimeTypesManager = &gs_mimeTypesManager;
+class wxMimeTypeCmnModule: public wxModule
+{
+public:
+ wxMimeTypeCmnModule() : wxModule() { }
+ virtual bool OnInit() { return TRUE; }
+ virtual void OnExit()
+ {
+ // this avoids false memory leak allerts:
+ if ( gs_mimeTypesManager.m_impl != NULL )
+ {
+ delete gs_mimeTypesManager.m_impl;
+ gs_mimeTypesManager.m_impl = NULL;
+ }
+ }
+
+ DECLARE_DYNAMIC_CLASS(wxMimeTypeCmnModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxMimeTypeCmnModule, wxModule)
#endif
// wxUSE_FILE && wxUSE_TEXTFILE