Commit 58122cb3 authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

open discover with mimetype when app choosing (if available)

this passes the content_type into the AppChooserDialog as mimetype. if
available it will be passed to discover as --mime argument which causes
discover to automatically filter for applications that associate with
the mimetype.

test case:
- have nothing installed to handle mkv
- try to open mkv
- click discover link
- video players get recommended
parent 74383e26
......@@ -59,7 +59,7 @@ uint AppChooserPortal::ChooseApplication(const QDBusObjectPath &handle,
if (!itemName.isValid()) {
itemName = options.value(QStringLiteral("content_type"));
}
AppChooserDialog *appDialog = new AppChooserDialog(choices, latestChoice, itemName.toString());
AppChooserDialog *appDialog = new AppChooserDialog(choices, latestChoice, itemName.toString(), options.value(QStringLiteral("content_type")).toString());
m_appChooserDialogs.insert(handle.path(), appDialog);
Utils::setParentWindow(appDialog, parent_window);
......
......@@ -33,11 +33,12 @@
#include <KProcess>
#include <kdeclarative/kdeclarative.h>
AppChooserDialog::AppChooserDialog(const QStringList &choices, const QString &defaultApp, const QString &fileName, QDialog *parent, Qt::WindowFlags flags)
AppChooserDialog::AppChooserDialog(const QStringList &choices, const QString &defaultApp, const QString &fileName, const QString &mimeName, QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, m_dialog(new Ui::AppChooserDialog)
, m_defaultChoices(choices)
, m_defaultApp(defaultApp)
, m_mimeName(mimeName)
{
m_dialog->setupUi(this);
......@@ -85,7 +86,11 @@ void AppChooserDialog::onApplicationSelected(const QString& desktopFile)
void AppChooserDialog::onOpenDiscover()
{
KProcess::startDetached(QStringLiteral("plasma-discover"));
QStringList args;
if (!m_mimeName.isEmpty()) {
args << QStringLiteral("--mime") << m_mimeName;
}
KProcess::startDetached(QStringLiteral("plasma-discover"), args);
}
void AppChooserDialog::updateChoices(const QStringList &choices)
......
......@@ -110,7 +110,8 @@ class AppChooserDialog : public QDialog
{
Q_OBJECT
public:
explicit AppChooserDialog(const QStringList &choices, const QString &defaultApp, const QString &fileName, QDialog *parent = nullptr, Qt::WindowFlags flags = {});
explicit AppChooserDialog(const QStringList &choices, const QString &defaultApp, const QString &fileName,
const QString &mimeName = QString(), QDialog *parent = nullptr, Qt::WindowFlags flags = {});
~AppChooserDialog();
void updateChoices(const QStringList &choices);
......@@ -126,6 +127,7 @@ private:
QStringList m_defaultChoices;
QString m_defaultApp;
QString m_selectedApplication;
QString m_mimeName;
};
#endif // XDG_DESKTOP_PORTAL_KDE_APPCHOOSER_DIALOG_H
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