This commit was manufactured by cvs2svn to create tag 'WX_2_2_6'.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/tags/WX_2_2_6@9545 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -9,8 +9,16 @@
|
||||
// Licence: wxWindows license (part of wxExtra library)
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "mimetype.h"
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "mimetype.h"
|
||||
#endif
|
||||
|
||||
// for compilers that support precompilation, includes "wx.h".
|
||||
@@ -24,7 +32,7 @@
|
||||
#include "wx/defs.h"
|
||||
#endif
|
||||
|
||||
#if (wxUSE_FILE && wxUSE_TEXTFILE) || defined(__WXMSW__)
|
||||
#if wxUSE_FILE && wxUSE_TEXTFILE
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/string.h"
|
||||
@@ -54,6 +62,22 @@
|
||||
// in case we're compiling in non-GUI mode
|
||||
class WXDLLEXPORT wxIcon;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// MIME code tracing mask
|
||||
#define TRACE_MIME _T("mime")
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// there are some fields which we don't understand but for which we don't give
|
||||
// warnings as we know that they're not important - this function is used to
|
||||
// test for them
|
||||
static bool IsKnownUnimportantField(const wxString& field);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private classes
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -873,17 +897,26 @@ wxFileTypeImpl::GetEntry(const wxFileType::MessageParameters& params) const
|
||||
wxString command;
|
||||
MailCapEntry *entry = m_manager->m_aEntries[m_index[0]];
|
||||
while ( entry != NULL ) {
|
||||
// notice that an empty command would always succeed (it's ok)
|
||||
// get the command to run as the test for this entry
|
||||
command = wxFileType::ExpandCommand(entry->GetTestCmd(), params);
|
||||
|
||||
if ( command.IsEmpty() || (wxSystem(command) == 0) ) {
|
||||
// ok, passed
|
||||
wxLogTrace(wxT("Test '%s' for mime type '%s' succeeded."),
|
||||
// don't trace the test result if there is no test at all
|
||||
if ( command.IsEmpty() )
|
||||
{
|
||||
// no test at all, ok
|
||||
break;
|
||||
}
|
||||
|
||||
if ( wxSystem(command) == 0 ) {
|
||||
// ok, test passed
|
||||
wxLogTrace(TRACE_MIME,
|
||||
wxT("Test '%s' for mime type '%s' succeeded."),
|
||||
command.c_str(), params.GetMimeType().c_str());
|
||||
break;
|
||||
}
|
||||
else {
|
||||
wxLogTrace(wxT("Test '%s' for mime type '%s' failed."),
|
||||
wxLogTrace(TRACE_MIME,
|
||||
wxT("Test '%s' for mime type '%s' failed."),
|
||||
command.c_str(), params.GetMimeType().c_str());
|
||||
}
|
||||
|
||||
@@ -1189,7 +1222,8 @@ void wxMimeTypesManagerImpl::AddMailcapInfo(const wxString& strType,
|
||||
|
||||
bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
|
||||
{
|
||||
wxLogTrace(wxT("--- Parsing mime.types file '%s' ---"), strFileName.c_str());
|
||||
wxLogTrace(TRACE_MIME, wxT("--- Parsing mime.types file '%s' ---"),
|
||||
strFileName.c_str());
|
||||
|
||||
wxTextFile file(strFileName);
|
||||
if ( !file.Open() )
|
||||
@@ -1345,7 +1379,8 @@ bool wxMimeTypesManagerImpl::ReadMimeTypes(const wxString& strFileName)
|
||||
bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
bool fallback)
|
||||
{
|
||||
wxLogTrace(wxT("--- Parsing mailcap file '%s' ---"), strFileName.c_str());
|
||||
wxLogTrace(TRACE_MIME, wxT("--- Parsing mailcap file '%s' ---"),
|
||||
strFileName.c_str());
|
||||
|
||||
wxTextFile file(strFileName);
|
||||
if ( !file.Open() )
|
||||
@@ -1393,18 +1428,31 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
strTest,
|
||||
strDesc,
|
||||
curField; // accumulator
|
||||
for ( bool cont = TRUE; cont; pc++ ) {
|
||||
bool cont = TRUE;
|
||||
while ( cont ) {
|
||||
switch ( *pc ) {
|
||||
case wxT('\\'):
|
||||
// interpret the next character literally (notice that
|
||||
// backslash can be used for line continuation)
|
||||
if ( *++pc == wxT('\0') ) {
|
||||
// fetch the next line.
|
||||
// fetch the next line if there is one
|
||||
if ( nLine == nLineCount - 1 ) {
|
||||
// something is wrong, bail out
|
||||
cont = FALSE;
|
||||
|
||||
// pc currently points to nowhere, but after the next
|
||||
// pc++ in the for line it will point to the beginning
|
||||
// of the next line in the file
|
||||
pc = file[++nLine].c_str() - 1;
|
||||
wxLogDebug(wxT("Mailcap file %s, line %d: "
|
||||
"'\\' on the end of the last line "
|
||||
"ignored."),
|
||||
strFileName.c_str(),
|
||||
nLine + 1);
|
||||
}
|
||||
else {
|
||||
// pass to the beginning of the next line
|
||||
pc = file[++nLine].c_str();
|
||||
|
||||
// skip pc++ at the end of the loop
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// just a normal character
|
||||
@@ -1426,6 +1474,12 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
switch ( currentToken ) {
|
||||
case Field_Type:
|
||||
strType = curField;
|
||||
if ( strType.empty() ) {
|
||||
// I don't think that this is a valid mailcap
|
||||
// entry, but try to interpret it somehow
|
||||
strType = _T('*');
|
||||
}
|
||||
|
||||
if ( strType.Find(wxT('/')) == wxNOT_FOUND ) {
|
||||
// we interpret "type" as "type/*"
|
||||
strType += wxT("/*");
|
||||
@@ -1441,7 +1495,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
break;
|
||||
|
||||
case Field_Other:
|
||||
{
|
||||
if ( !curField.empty() ) {
|
||||
// "good" mailcap entry?
|
||||
bool ok = TRUE;
|
||||
|
||||
@@ -1480,25 +1534,23 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
}
|
||||
else {
|
||||
// no, it's a simple flag
|
||||
// TODO support the flags:
|
||||
// 1. create an xterm for 'needsterminal'
|
||||
// 2. append "| $PAGER" for 'copiousoutput'
|
||||
if ( curField == wxT("needsterminal") )
|
||||
needsterminal = TRUE;
|
||||
else if ( curField == wxT("copiousoutput") )
|
||||
else if ( curField == wxT("copiousoutput")) {
|
||||
// copiousoutput impies that the
|
||||
// viewer is a console program
|
||||
needsterminal =
|
||||
copiousoutput = TRUE;
|
||||
else if ( curField == wxT("textualnewlines") )
|
||||
; // ignore
|
||||
else
|
||||
}
|
||||
else {
|
||||
// unknown flag
|
||||
ok = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !ok )
|
||||
{
|
||||
// we don't understand this field, but
|
||||
// Netscape stores info in it, so don't warn
|
||||
// about it
|
||||
if ( curField.Left(16u) != "x-mozilla-flags=" )
|
||||
if ( !IsKnownUnimportantField(curField) )
|
||||
{
|
||||
// don't flood the user with error
|
||||
// messages if we don't understand
|
||||
@@ -1518,6 +1570,7 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
}
|
||||
}
|
||||
}
|
||||
//else: the field is empty, ignore silently
|
||||
|
||||
// it already has this value
|
||||
//currentToken = Field_Other;
|
||||
@@ -1534,6 +1587,9 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
default:
|
||||
curField += *pc;
|
||||
}
|
||||
|
||||
// continue in the same line
|
||||
pc++;
|
||||
}
|
||||
|
||||
// check that we really read something reasonable
|
||||
@@ -1543,6 +1599,19 @@ bool wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName,
|
||||
strFileName.c_str(), nLine + 1);
|
||||
}
|
||||
else {
|
||||
// support for flags:
|
||||
// 1. create an xterm for 'needsterminal'
|
||||
// 2. append "| $PAGER" for 'copiousoutput'
|
||||
if ( copiousoutput ) {
|
||||
const wxChar *p = wxGetenv(_T("PAGER"));
|
||||
strOpenCmd << _T(" | ") << (p ? p : _T("more"));
|
||||
}
|
||||
|
||||
if ( needsterminal ) {
|
||||
strOpenCmd.Printf(_T("xterm -e sh -c '%s'"),
|
||||
strOpenCmd.c_str());
|
||||
}
|
||||
|
||||
MailCapEntry *entry = new MailCapEntry(strOpenCmd,
|
||||
strPrintCmd,
|
||||
strTest);
|
||||
@@ -1638,6 +1707,29 @@ size_t wxMimeTypesManagerImpl::EnumAllFileTypes(wxArrayString& mimetypes)
|
||||
return mimetypes.GetCount();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static bool IsKnownUnimportantField(const wxString& fieldAll)
|
||||
{
|
||||
static const wxChar *knownFields[] =
|
||||
{
|
||||
_T("x-mozilla-flags"),
|
||||
_T("nametemplate"),
|
||||
_T("textualnewlines"),
|
||||
};
|
||||
|
||||
wxString field = fieldAll.BeforeFirst(_T('='));
|
||||
for ( size_t n = 0; n < WXSIZEOF(knownFields); n++ )
|
||||
{
|
||||
if ( field.CmpNoCase(knownFields[n]) == 0 )
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
// wxUSE_FILE && wxUSE_TEXTFILE
|
||||
|
||||
|
Reference in New Issue
Block a user