From 276c7463f35b7f3ec8dfdbe80b29448f2e503d93 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 12 Feb 2001 17:21:04 +0000 Subject: [PATCH] fixed KDE link file reading code git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9354 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/unix/mimetype.cpp | 84 +++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/src/unix/mimetype.cpp b/src/unix/mimetype.cpp index 05bb2f89ab..fffd9d50dd 100644 --- a/src/unix/mimetype.cpp +++ b/src/unix/mimetype.cpp @@ -679,45 +679,69 @@ void wxKDEIconHandler::LoadLinksForMimeSubtype(const wxString& dirbase, if ( !file.ReadAll(&text) ) return; - int pos; - const wxChar *pc; + // first find the description string: it is the value in either "Comment=" + // line or "Comment[]=" one + int posComment = wxNOT_FOUND; + + wxString comment; +#if wxUSE_INTL + wxLocale *locale = wxGetLocale(); + if ( locale ) + { + // try "Comment[locale name]" first + comment << _T("Comment[") + locale->GetName() + _T("]="); - // before trying to find an icon, grab mimetype information - // (because BFU's machine would hardly have well-edited mime.types but (s)he might - // have edited it in control panel...) + posComment = text.Find(comment); + } +#endif // wxUSE_INTL - wxString mime_extension, mime_desc; + if ( posComment == wxNOT_FOUND ) + { + comment = _T("Comment="); - pos = wxNOT_FOUND; - if (wxGetLocale() != NULL) - mime_desc = _T("Comment[") + wxGetLocale()->GetName() + _T("]="); - if (pos == wxNOT_FOUND) mime_desc = _T("Comment="); - pos = text.Find(mime_desc); - if (pos == wxNOT_FOUND) mime_desc = wxEmptyString; - else + posComment = text.Find(comment); + } + + wxString mime_desc; + if ( posComment != wxNOT_FOUND ) { - pc = text.c_str() + pos + mime_desc.Length(); - mime_desc = wxEmptyString; - while ( *pc && *pc != _T('\n') ) mime_desc += *pc++; + // found desc: it follows the comment until the end of line + const wxChar *pc = text.c_str() + posComment + comment.length(); + while ( *pc && *pc != _T('\n') ) + { + mime_desc += *pc++; + } } + //else: no description - pos = text.Find(_T("Patterns=")); - if (pos != wxNOT_FOUND) + // next find the extensions + wxString mime_extension; + + int posExts = text.Find(_T("Patterns=")); + if ( posExts != wxNOT_FOUND ) { wxString exts; - pc = text.c_str() + pos + 9; - while ( *pc && *pc != _T('\n') ) exts += *pc++; - wxStringTokenizer tokenizer(exts, _T(";")); - wxString e; + const wxChar *pc = text.c_str() + posExts + 9; // strlen("Patterns=") + while ( *pc && *pc != _T('\n') ) + { + exts += *pc++; + } - while (tokenizer.HasMoreTokens()) + wxStringTokenizer tokenizer(exts, _T(";")); + while ( tokenizer.HasMoreTokens() ) { - e = tokenizer.GetNextToken(); - if (e.Left(2) != _T("*.")) continue; // don't support too difficult patterns + wxString e = tokenizer.GetNextToken(); + if ( e.Left(2) != _T("*.") ) + continue; // don't support too difficult patterns + + if ( !mime_extension.empty() ) + { + // separate from the previous ext + mime_extension << _T(' '); + } + mime_extension << e.Mid(2); - mime_extension << _T(' '); } - mime_extension.RemoveLast(); } ms_infoTypes.Add(mimetype); @@ -726,8 +750,8 @@ void wxKDEIconHandler::LoadLinksForMimeSubtype(const wxString& dirbase, // ok, now we can take care of icon: - pos = text.Find(_T("Icon=")); - if ( pos == wxNOT_FOUND ) + int posIcon = text.Find(_T("Icon=")); + if ( posIcon == wxNOT_FOUND ) { // no icon info return; @@ -735,7 +759,7 @@ void wxKDEIconHandler::LoadLinksForMimeSubtype(const wxString& dirbase, wxString icon; - pc = text.c_str() + pos + 5; // 5 == strlen("Icon=") + const wxChar *pc = text.c_str() + posIcon + 5; // 5 == strlen("Icon=") while ( *pc && *pc != _T('\n') ) { icon += *pc++; -- 2.47.2