File indexing completed on 2024-04-28 16:55:43

0001 /*
0002  * SPDX-FileCopyrightText: 2017 Red Hat Inc
0003  * SPDX-License-Identifier: LGPL-2.0-or-later
0004  *
0005  * SPDX-FileCopyrightText: 2017 Jan Grulich <jgrulich@redhat.com>
0006  * SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
0007  */
0008 
0009 #include "access.h"
0010 #include "access_debug.h"
0011 #include "accessdialog.h"
0012 #include "request.h"
0013 #include "utils.h"
0014 
0015 #include <QWindow>
0016 
0017 AccessPortal::AccessPortal(QObject *parent)
0018     : QDBusAbstractAdaptor(parent)
0019 {
0020 }
0021 
0022 AccessPortal::~AccessPortal()
0023 {
0024 }
0025 
0026 uint AccessPortal::AccessDialog(const QDBusObjectPath &handle,
0027                                 const QString &app_id,
0028                                 const QString &parent_window,
0029                                 const QString &title,
0030                                 const QString &subtitle,
0031                                 const QString &body,
0032                                 const QVariantMap &options,
0033                                 QVariantMap &results)
0034 {
0035     qCDebug(XdgDesktopPortalKdeAccess) << "AccessDialog called with parameters:";
0036     qCDebug(XdgDesktopPortalKdeAccess) << "    handle: " << handle.path();
0037     qCDebug(XdgDesktopPortalKdeAccess) << "    app_id: " << app_id;
0038     qCDebug(XdgDesktopPortalKdeAccess) << "    parent_window: " << parent_window;
0039     qCDebug(XdgDesktopPortalKdeAccess) << "    title: " << title;
0040     qCDebug(XdgDesktopPortalKdeAccess) << "    subtitle: " << subtitle;
0041     qCDebug(XdgDesktopPortalKdeAccess) << "    body: " << body;
0042     qCDebug(XdgDesktopPortalKdeAccess) << "    options: " << options;
0043 
0044     auto accessDialog = new ::AccessDialog();
0045     accessDialog->setBody(body);
0046     accessDialog->setTitle(title);
0047     accessDialog->setSubtitle(subtitle);
0048 
0049     if (options.contains(QStringLiteral("deny_label"))) {
0050         accessDialog->setRejectLabel(options.value(QStringLiteral("deny_label")).toString());
0051     }
0052 
0053     if (options.contains(QStringLiteral("grant_label"))) {
0054         accessDialog->setAcceptLabel(options.value(QStringLiteral("grant_label")).toString());
0055     }
0056 
0057     if (options.contains(QStringLiteral("icon"))) {
0058         accessDialog->setIcon(options.value(QStringLiteral("icon")).toString());
0059     }
0060 
0061     // TODO choices
0062     Q_UNUSED(results);
0063 
0064     accessDialog->createDialog();
0065     Utils::setParentWindow(accessDialog->windowHandle(), parent_window);
0066     Request::makeClosableDialogRequest(handle, accessDialog);
0067     if (options.contains(QStringLiteral("modal"))) {
0068         accessDialog->windowHandle()->setModality(options.value(QStringLiteral("modal")).toBool() ? Qt::WindowModal : Qt::NonModal);
0069     }
0070 
0071     if (accessDialog->exec()) {
0072         accessDialog->deleteLater();
0073         return 0;
0074     }
0075     accessDialog->deleteLater();
0076 
0077     return 1;
0078 }