// 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".
#include "wx/defs.h"
#endif
-#if (wxUSE_FILE && wxUSE_TEXTFILE) || defined(__WXMSW__)
+#if wxUSE_FILE && wxUSE_TEXTFILE
#ifndef WX_PRECOMP
#include "wx/string.h"
// 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
// ----------------------------------------------------------------------------
{
m_next = NULL;
}
+
+ ~MailCapEntry()
+ {
+ if (m_next) delete m_next;
+ }
// accessors
const wxString& GetOpenCmd() const { return m_openCmd; }
// with blank lines separating the entries and indented lines starting with
// TABs. We're interested in the field icon-filename whose value is the path
// containing the icon.
+//
+// Update (Chris Elliott): apparently there may be an optional "[lang]" prefix
+// just before the field name.
void wxGNOMEIconHandler::LoadIconsFromKeyFile(const wxString& filename)
{
// this is a field=value ling
pc++; // skip leading TAB
+ // skip optional "[lang]"
+ if ( *pc == _T('[') )
+ {
+ while ( *pc )
+ {
+ if ( *pc++ == _T(']') )
+ break;
+ }
+ }
+
static const int lenField = 13; // strlen("icon-filename")
if ( wxStrncmp(pc, _T("icon-filename"), lenField) == 0 )
{
dirs.Add(_T("/usr/share"));
dirs.Add(_T("/opt/kde/share"));
icondirs.Add(_T("/usr/share/icons/"));
+ icondirs.Add(_T("/usr/X11R6/share/icons/")); // Debian/Corel linux
icondirs.Add(_T("/opt/kde/share/icons/"));
}
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());
}
handlers[hn]->GetMimeInfoRecords(this);
}
+
+wxMimeTypesManagerImpl::~wxMimeTypesManagerImpl()
+{
+ size_t cnt = m_aEntries.GetCount();
+ for (size_t i = 0; i < cnt; i++) delete m_aEntries[i];
+}
+
+
wxFileType *
wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext)
{
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() )
}
}
else {
- // unquoted string ends at the first space
- for ( pEnd = pc; !wxIsspace(*pEnd); pEnd++ )
+ // unquoted string ends at the first space or at the end of
+ // line
+ for ( pEnd = pc; *pEnd && !wxIsspace(*pEnd); pEnd++ )
;
}
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() )
}
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
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);
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