Porting uses of 'accuracy' in KMimeType API

David Faure faure at kde.org
Sun Oct 12 07:41:31 UTC 2014


On Friday 12 September 2014 21:06:36 Kevin Funk wrote:
> On Friday 12 September 2014 10:50:36 David Faure wrote:
> > On Friday 12 September 2014 09:39:42 Kevin Funk wrote:
> > > Heya,
> > > 
> > > Context: Forward-porting some patches in KDevelop involving KMimeType
> > > API.
> > > 
> > > I've just noticed that in Qt5, QMimeDataBase/QMimeType doesn't allow me
> > > to
> > > retrieve the accuracy of a match anymore, while KMimeType did. For
> > > example,
> > > compare the possible arguments for QMimeDataBase::mimeTypeForUrl vs.
> > > KMimeType::findByUrl.
> > > 
> > > What's the suggested way to deal with this? As far as I can see, there
> > > are
> > > no porting notes about that particular matter.
> > 
> > You're telling me everything I know already, but not the important bit
> > which is: what do you need the accuracy for?
> 
> Well, this is ancient, performance-critical code inside KDevelop. We
> basically cache a extension -> language mapping for performance reasons.
> Just recently we introduced code that avoids caching extensions for which
> the KMimeType lookup yielded a very low accuracy.
> 
> Also see: https://git.reviewboard.kde.org/r/120085/

OK, I see.
I confirm that putting /* at the top of a text file without extension (or 
without a known extension) leads to text/x-csrc.

To avoid this, you could decide to only trust extensions.
In an IDE, I'd say that's probably valid.
i.e. I would do
db.mimeTypeForFile(fileName, QMimeDatabase::MatchExtension);

(I was about to suggest to compare the result of MatchExtension
and MatchContent, but that wouldn't make sense. If there's an extension then 
you want to use that, and only if there isn't, then MatchContent can be 
useful, but leads to exactly what you don't want: inaccurate results).

MatchContent is more useful in e.g. an image viewer than in a C++ IDE,
because image formats are much more strictly defined and easy to recognize. 

-- 
David Faure, faure at kde.org, http://www.davidfaure.fr
Working on KDE Frameworks 5



More information about the Kde-frameworks-devel mailing list