]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/mimetype.cpp
Fixed wxMotif's wxExecute again, added OnPaint capability to wxFrame,
[wxWidgets.git] / src / common / mimetype.cpp
index 513c35b3fc55598bf995591537ae626186ed86f4..e4dcc9cf34583143eb1f451694ffe38670a9c94e 100644 (file)
@@ -170,7 +170,7 @@ public:
 //  * compose and composetyped fields are used to determine the program to be
 //    called to create a new message pert in the specified format (unused).
 //
-// Parameter/filename xpansion: 
+// Parameter/filename xpansion:
 //  * %s is replaced with the (full) file name
 //  * %t is replaced with MIME type/subtype of the entry
 //  * for multipart type only %n is replaced with the nnumber of parts and %F is
@@ -189,7 +189,7 @@ public:
 // comments. Each record has one of two following forms:
 //  a) for "brief" format:
 //      <mime type>  <space separated list of extensions>
-//  b) for "expanded" format: 
+//  b) for "expanded" format:
 //      type=<mime type> \ desc="<description>" \ exts="ext"
 //
 // We try to autodetect the format of mime.types: if a non-comment line starts
@@ -337,8 +337,8 @@ wxString wxFileType::ExpandCommand(const wxString& command,
                 case 's':
                     // '%s' expands into file name (quoted because it might
                     // contain spaces) - except if there are already quotes
-                    // there because otherwise some programs may get confused by
-                    // double double quotes
+                    // there because otherwise some programs may get confused
+                    // by double double quotes
 #if 0
                     if ( *(pc - 2) == '"' )
                         str << params.GetFileName();
@@ -448,6 +448,28 @@ wxFileType::GetPrintCommand(wxString *printCmd,
 // wxMimeTypesManager
 // ----------------------------------------------------------------------------
 
+bool wxMimeTypesManager::IsOfType(const wxString& mimeType,
+                                  const wxString& wildcard)
+{
+    wxASSERT_MSG( mimeType.Find('*') == wxNOT_FOUND,
+                  "first MIME type can't contain wildcards" );
+
+    // all comparaisons are case insensitive (2nd arg of IsSameAs() is FALSE)
+    if ( wildcard.BeforeFirst('/').IsSameAs(mimeType.BeforeFirst('/'), FALSE) )
+    {
+        wxString strSubtype = wildcard.AfterFirst('/');
+
+        if ( strSubtype == '*' ||
+             strSubtype.IsSameAs(mimeType.AfterFirst('/'), FALSE) )
+        {
+            // matches (either exactly or it's a wildcard)
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
 wxMimeTypesManager::wxMimeTypesManager()
 {
     m_impl = new wxMimeTypesManagerImpl;
@@ -804,11 +826,11 @@ wxMimeTypesManagerImpl::GetFileTypeFromExtension(const wxString& ext)
             extensions = extensions.AfterFirst(' ');
 
             // consider extensions as not being case-sensitive
-            if ( field.IsSameAs(ext, FALSE /* no case */) ) { 
+            if ( field.IsSameAs(ext, FALSE /* no case */) ) {
                 // found
                 wxFileType *fileType = new wxFileType;
                 fileType->m_impl->Init(this, n);
-                
+
                 return fileType;
             }
         }
@@ -1031,8 +1053,8 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName)
         } currentToken = Field_Type;
 
         // the flags and field values on the current line
-        bool needsterminal = false,
-             copiousoutput = false;
+        bool needsterminal = FALSE,
+             copiousoutput = FALSE;
         wxString strType,
                  strOpenCmd,
                  strPrintCmd,
@@ -1094,8 +1116,8 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName)
                                 // is this something of the form foo=bar?
                                 const char *pEq = strchr(curField, '=');
                                 if ( pEq != NULL ) {
-                                    wxString lhs = curField.Before('='),
-                                             rhs = curField.After('=');
+                                    wxString lhs = curField.BeforeFirst('='),
+                                             rhs = curField.AfterFirst('=');
 
                                     lhs.Trim(TRUE);     // from right
                                     rhs.Trim(FALSE);    // from left
@@ -1143,12 +1165,14 @@ void wxMimeTypesManagerImpl::ReadMailcap(const wxString& strFileName)
                                 {
                                     // don't flood the user with error messages
                                     // if we don't understand something in his
-                                    // mailcap
+                                    // mailcap, but give them in debug mode
+                                    // because this might be useful for the
+                                    // programmer
                                     wxLogDebug
                                     (
-                                      _("Mailcap file %s, line %d: unknown "
-                                        "field '%s' for the MIME type "
-                                        "'%s' ignored."),
+                                      "Mailcap file %s, line %d: unknown "
+                                      "field '%s' for the MIME type "
+                                      "'%s' ignored.",
                                       strFileName.c_str(),
                                       nLine + 1,
                                       curField.c_str(),