[kdevplatform/1.7] shell: Use match accuracy when asking for mime type.
Kevin Funk
kfunk at kde.org
Fri Sep 12 07:52:21 UTC 2014
On Sunday 07 September 2014 15:00:11 Sergey Kalinichev wrote:
> Git commit 03a3ce34bef71245e97b18fcf9b80e500c4ae46f by Sergey Kalinichev.
> Committed on 07/09/2014 at 11:42.
> Pushed by skalinichev into branch '1.7'.
>
> Use match accuracy when asking for mime type.
>
> Ask KMimeType about match accuracy and if it's very low don't
> register languages for that mime type.
>
> Otherwise we can accidently register e.g. *.txt files as supported by
> c++ language support plugin.
>
> REVIEW: 120085
>
> M +7 -3 shell/languagecontroller.cpp
>
> http://commits.kde.org/kdevplatform/03a3ce34bef71245e97b18fcf9b80e500c4ae46f
>
> diff --git a/shell/languagecontroller.cpp b/shell/languagecontroller.cpp
> index 817c1ce..0dec986 100644
> --- a/shell/languagecontroller.cpp
> +++ b/shell/languagecontroller.cpp
> @@ -297,11 +297,12 @@ QList<ILanguage*>
> LanguageController::languagesForUrl(const KUrl &url) return languages;
>
> KMimeType::Ptr mimeType;
> -
> +
> + int accuracy = 0;
> if(!extension.isEmpty()) {
> // If we have recognized a file extension, allow using the
> file-contents // to look up the type. We will cache it after all.
> - mimeType = KMimeType::findByUrl(url);
> + mimeType = KMimeType::findByUrl(url, 0, false, false, &accuracy);
> } else {
> // If we have not recognized a file extension, do not allow using
> the file-contents // to look up the type. We cannot cache the result, and
> thus we might end up reading @@ -319,8 +320,11 @@ QList<ILanguage*>
> LanguageController::languagesForUrl(const KUrl &url)
>
> languages = languagesForMimetype(mimeType->name());
>
> - if(!extension.isEmpty())
> + // E.g. because of some txt file that begins with /* and considered as
> c++ file + // we don't want the c++ language support to parse all txt
> files. + if(!extension.isEmpty() && accuracy > 80) {
> d->fileExtensionCache.insert(extension, languages);
> + }
>
> return languages;
> }
FYI: I had to skip this patch when merging 1.7 into master.
There's no suitable replacement for 'accuracy' in Qt5's
QMimeDataBase/QMimeType API.
I've sent a mail to kde-devel asking how to port this.
--
Kevin Funk | kfunk at kde.org | http://kfunk.org
More information about the KDevelop-devel
mailing list