Commit 04d92f58 authored by Albert Astals Cid's avatar Albert Astals Cid
Browse files

File dialog: Use mimetypes instead of file extensions

Only if you're on a new enough KIO, we need
a1acb7744455b57dc972b3073f6e1dce0d49d965
and
7bf4d793a5ac54280c45660dbd04de4fa99dc994
present since 5.73 to make the UI usable

BUGS: 422574
parent 8966b715
Pipeline #32212 passed with stage
in 16 minutes and 12 seconds
......@@ -53,6 +53,8 @@
#include <KActivities/ResourceInstance>
#endif
#include <kio_version.h>
// local includes
#include "../interfaces/viewerinterface.h"
#include "kdocumentviewer.h"
......@@ -435,6 +437,15 @@ void Shell::fileOpen()
dlg->setFileMode(QFileDialog::ExistingFiles); // Allow selection of more than one file
QMimeDatabase mimeDatabase;
#if KIO_VERSION >= QT_VERSION_CHECK(5, 73, 0)
QStringList mimetypes;
for (const QString &mimeName : qAsConst(m_fileformats)) {
QMimeType mimeType = mimeDatabase.mimeTypeForName(mimeName);
mimetypes << mimeType.name();
}
mimetypes << "application/octet-stream";
dlg->setMimeTypeFilters(mimetypes);
#else
QSet<QString> globPatterns;
QMap<QString, QStringList> namedGlobs;
for (const QString &mimeName : qAsConst(m_fileformats)) {
......@@ -457,6 +468,7 @@ void Shell::fileOpen()
namePatterns.prepend(i18n("All files (*)"));
namePatterns.prepend(i18n("All supported files (%1)", allGlobPatterns.join(QLatin1Char(' '))));
dlg->setNameFilters(namePatterns);
#endif
dlg->setWindowTitle(i18n("Open Document"));
if (dlg->exec() && dlg) {
......
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