Commit b8ead2df authored by Harald Sitter's avatar Harald Sitter 🏳️‍🌈
Browse files

add a proprietary appchooser interface

this can be used by plasma-integration to link up KIO's open with
extension point with our UX
parent 7b0219ea
Pipeline #220130 passed with stage
in 1 minute and 8 seconds
......@@ -39,6 +39,8 @@ PWD.SystemDialog
checkable: true
checked: !AppModel.showOnlyPreferredApps
visible: AppModel.sourceModel.hasPreferredApps
onVisibleChanged: AppModel.showOnlyPreferredApps = visible
onClicked: {
AppModel.showOnlyPreferredApps = !AppModel.showOnlyPreferredApps
......
......@@ -12,6 +12,11 @@
#include "request.h"
#include "utils.h"
#include <KLocalizedString>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusServiceWatcher>
AppChooserPortal::AppChooserPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
......@@ -72,3 +77,35 @@ void AppChooserPortal::UpdateChoices(const QDBusObjectPath &handle, const QStrin
m_appChooserDialogs.value(handle.path())->updateChoices(choices);
}
}
uint AppChooserPortal::ChooseApplicationPrivate(const QString &parent_window,
const QStringList &urls,
const QVariantMap &options,
const QDBusMessage &msg,
QVariantMap &results)
{
qCDebug(XdgDesktopPortalKdeAppChooser) << "ChooseApplicationPrivate called with parameters:";
qCDebug(XdgDesktopPortalKdeAppChooser) << " parent_window: " << parent_window;
qCDebug(XdgDesktopPortalKdeAppChooser) << " urls: " << urls;
qCDebug(XdgDesktopPortalKdeAppChooser) << " options: " << options;
if (urls.isEmpty()) {
return 1;
}
const QString itemName = urls.size() == 1 ? urls.at(0) : i18nc("count of files to open", "%1 files", urls.size());
AppChooserDialog appDialog({}, {}, itemName, options.value(QStringLiteral("content_type")).toString());
Utils::setParentWindow(appDialog.windowHandle(), parent_window);
QDBusServiceWatcher watcher(msg.service(), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForUnregistration);
connect(&watcher, &QDBusServiceWatcher::serviceUnregistered, &appDialog, [&appDialog] {
appDialog.reject();
});
const bool result = appDialog.exec();
if (result) {
results.insert(QStringLiteral("choice"), appDialog.selectedApplication());
}
return result ? 0 : 1;
}
......@@ -4,6 +4,7 @@
* SPDX-License-Identifier: LGPL-2.0-or-later
*
* SPDX-FileCopyrightText: 2016-2018 Jan Grulich <jgrulich@redhat.com>
* SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_APPCHOOSER_H
......@@ -12,6 +13,7 @@
#include <QDBusAbstractAdaptor>
#include <QDBusObjectPath>
class QDBusMessage;
class AppChooserDialog;
class AppChooserPortal : public QDBusAbstractAdaptor
......@@ -29,6 +31,9 @@ public Q_SLOTS:
const QStringList &choices,
const QVariantMap &options,
QVariantMap &results);
uint
ChooseApplicationPrivate(const QString &parent_window, const QStringList &urls, const QVariantMap &options, const QDBusMessage &msg, QVariantMap &results);
void UpdateChoices(const QDBusObjectPath &handle, const QStringList &choices);
private:
......
......@@ -221,6 +221,9 @@ AppModel::~AppModel()
void AppModel::setPreferredApps(const QStringList &possiblyAliasedList)
{
m_hasPreferredApps = false;
Q_EMIT hasPreferredAppsChanged();
// In the event that we get incoming NoDisplay entries that are AliasFor another desktop file,
// switch the NoDisplay name for the aliased name.
QStringList list;
......@@ -244,6 +247,8 @@ void AppModel::setPreferredApps(const QStringList &possiblyAliasedList)
if (list.contains(item.applicationDesktopFile())) {
item.setApplicationCategory(ApplicationItem::PreferredApplication);
changed = true;
m_hasPreferredApps = true;
Q_EMIT hasPreferredAppsChanged();
}
if (changed) {
......
......@@ -102,6 +102,7 @@ private:
class AppModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(bool hasPreferredApps MEMBER m_hasPreferredApps NOTIFY hasPreferredAppsChanged)
public:
enum ItemRoles {
ApplicationNameRole = Qt::UserRole + 1,
......@@ -119,11 +120,15 @@ public:
int rowCount(const QModelIndex &parent) const override;
QHash<int, QByteArray> roleNames() const override;
Q_SIGNALS:
void hasPreferredAppsChanged();
private:
void loadApplications();
QList<ApplicationItem> m_list;
QHash<QString, QString> m_noDisplayAliasesFor;
bool m_hasPreferredApps = false;
};
class AppChooserDialog : public QuickDialog
......
Supports Markdown
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