Commit a5f29806 authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

FileFilterHotSpot: check the mime type of the file after cleaning the path

QMimeDataBase will return "application/octet-stream" as the mime type
of something like "path/to/some/textfile.txt:123:123:", because we are
using methods from it that check only the file extension. That meant
some valid text files with line/column suffixes couldn't be opened.

Instead move the mime type check _after_ the file path has been cleaned.
Also account for mime types that aren't recognized, e.g. a text file with
no extension.

BUG: 431601
parent d22236c3
......@@ -54,13 +54,6 @@ void FileFilterHotSpot::activate(QObject *)
QMimeDatabase mdb;
const QMimeType mimeType = mdb.mimeTypeForFile(_filePath, QMimeDatabase::MatchExtension);
if (!mimeType.inherits(QStringLiteral("text/plain"))) {
QString editorExecPath;
int firstBlankIdx = -1;
QString fullCmd;
......@@ -135,6 +128,19 @@ void FileFilterHotSpot::openWithSysDefaultApp(const QString &filePath) const
void FileFilterHotSpot::openWithEditorFromProfile(const QString &fullCmd, const QString &path) const
// Here we are mostly interested in text-based files, e.g. if it's a
// PDF we should let the system default app open it.
QMimeDatabase mdb;
const auto mimeList = mdb.mimeTypesForFileName(path);
qCDebug(KonsoleDebug) << "FileFilterHotSpot: mime types for" << path << ":" << mimeList;
// If mimeList is empty, then it's not a recognized mime type, e.g.
// a text file without an extension
if (mimeList.isEmpty() || !"text/plain"))) {
qCDebug(KonsoleDebug) << "fullCmd:" << fullCmd;
KService::Ptr service(new KService(QString(), fullCmd, QString()));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment