fixed KDE link file reading code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9354 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -679,45 +679,69 @@ void wxKDEIconHandler::LoadLinksForMimeSubtype(const wxString& dirbase,
|
|||||||
if ( !file.ReadAll(&text) )
|
if ( !file.ReadAll(&text) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int pos;
|
// first find the description string: it is the value in either "Comment="
|
||||||
const wxChar *pc;
|
// line or "Comment[<locale_name>]=" one
|
||||||
|
int posComment = wxNOT_FOUND;
|
||||||
|
|
||||||
// before trying to find an icon, grab mimetype information
|
wxString comment;
|
||||||
// (because BFU's machine would hardly have well-edited mime.types but (s)he might
|
#if wxUSE_INTL
|
||||||
// have edited it in control panel...)
|
wxLocale *locale = wxGetLocale();
|
||||||
|
if ( locale )
|
||||||
wxString mime_extension, mime_desc;
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
pc = text.c_str() + pos + mime_desc.Length();
|
// try "Comment[locale name]" first
|
||||||
mime_desc = wxEmptyString;
|
comment << _T("Comment[") + locale->GetName() + _T("]=");
|
||||||
while ( *pc && *pc != _T('\n') ) mime_desc += *pc++;
|
|
||||||
|
posComment = text.Find(comment);
|
||||||
|
}
|
||||||
|
#endif // wxUSE_INTL
|
||||||
|
|
||||||
|
if ( posComment == wxNOT_FOUND )
|
||||||
|
{
|
||||||
|
comment = _T("Comment=");
|
||||||
|
|
||||||
|
posComment = text.Find(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = text.Find(_T("Patterns="));
|
wxString mime_desc;
|
||||||
if (pos != wxNOT_FOUND)
|
if ( posComment != wxNOT_FOUND )
|
||||||
|
{
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// next find the extensions
|
||||||
|
wxString mime_extension;
|
||||||
|
|
||||||
|
int posExts = text.Find(_T("Patterns="));
|
||||||
|
if ( posExts != wxNOT_FOUND )
|
||||||
{
|
{
|
||||||
wxString exts;
|
wxString exts;
|
||||||
pc = text.c_str() + pos + 9;
|
const wxChar *pc = text.c_str() + posExts + 9; // strlen("Patterns=")
|
||||||
while ( *pc && *pc != _T('\n') ) exts += *pc++;
|
while ( *pc && *pc != _T('\n') )
|
||||||
wxStringTokenizer tokenizer(exts, _T(";"));
|
|
||||||
wxString e;
|
|
||||||
|
|
||||||
while (tokenizer.HasMoreTokens())
|
|
||||||
{
|
{
|
||||||
e = tokenizer.GetNextToken();
|
exts += *pc++;
|
||||||
if (e.Left(2) != _T("*.")) continue; // don't support too difficult patterns
|
}
|
||||||
mime_extension << e.Mid(2);
|
|
||||||
|
wxStringTokenizer tokenizer(exts, _T(";"));
|
||||||
|
while ( tokenizer.HasMoreTokens() )
|
||||||
|
{
|
||||||
|
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 << _T(' ');
|
||||||
}
|
}
|
||||||
mime_extension.RemoveLast();
|
|
||||||
|
mime_extension << e.Mid(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ms_infoTypes.Add(mimetype);
|
ms_infoTypes.Add(mimetype);
|
||||||
@@ -726,8 +750,8 @@ void wxKDEIconHandler::LoadLinksForMimeSubtype(const wxString& dirbase,
|
|||||||
|
|
||||||
// ok, now we can take care of icon:
|
// ok, now we can take care of icon:
|
||||||
|
|
||||||
pos = text.Find(_T("Icon="));
|
int posIcon = text.Find(_T("Icon="));
|
||||||
if ( pos == wxNOT_FOUND )
|
if ( posIcon == wxNOT_FOUND )
|
||||||
{
|
{
|
||||||
// no icon info
|
// no icon info
|
||||||
return;
|
return;
|
||||||
@@ -735,7 +759,7 @@ void wxKDEIconHandler::LoadLinksForMimeSubtype(const wxString& dirbase,
|
|||||||
|
|
||||||
wxString icon;
|
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') )
|
while ( *pc && *pc != _T('\n') )
|
||||||
{
|
{
|
||||||
icon += *pc++;
|
icon += *pc++;
|
||||||
|
Reference in New Issue
Block a user