File indexing completed on 2024-04-28 05:36:49

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 uint AccessPortal::AccessDialog(const QDBusObjectPath &handle,
0023                                 const QString &app_id,
0024                                 const QString &parent_window,
0025                                 const QString &title,
0026                                 const QString &subtitle,
0027                                 const QString &body,
0028                                 const QVariantMap &options,
0029                                 QVariantMap &results)
0030 {
0031     qCDebug(XdgDesktopPortalKdeAccess) << "AccessDialog called with parameters:";
0032     qCDebug(XdgDesktopPortalKdeAccess) << "    handle: " << handle.path();
0033     qCDebug(XdgDesktopPortalKdeAccess) << "    app_id: " << app_id;
0034     qCDebug(XdgDesktopPortalKdeAccess) << "    parent_window: " << parent_window;
0035     qCDebug(XdgDesktopPortalKdeAccess) << "    title: " << title;
0036     qCDebug(XdgDesktopPortalKdeAccess) << "    subtitle: " << subtitle;
0037     qCDebug(XdgDesktopPortalKdeAccess) << "    body: " << body;
0038     qCDebug(XdgDesktopPortalKdeAccess) << "    options: " << options;
0039 
0040     auto accessDialog = new ::AccessDialog();
0041     accessDialog->setBody(body);
0042     accessDialog->setTitle(title);
0043     accessDialog->setSubtitle(subtitle);
0044 
0045     if (options.contains(QStringLiteral("deny_label"))) {
0046         accessDialog->setRejectLabel(options.value(QStringLiteral("deny_label")).toString());
0047     }
0048 
0049     if (options.contains(QStringLiteral("grant_label"))) {
0050         accessDialog->setAcceptLabel(options.value(QStringLiteral("grant_label")).toString());
0051     }
0052 
0053     if (options.contains(QStringLiteral("icon"))) {
0054         accessDialog->setIcon(options.value(QStringLiteral("icon")).toString());
0055     }
0056 
0057     // TODO choices
0058     Q_UNUSED(results);
0059 
0060     accessDialog->createDialog();
0061     Utils::setParentWindow(accessDialog->windowHandle(), parent_window);
0062     Request::makeClosableDialogRequest(handle, accessDialog);
0063     if (options.contains(QStringLiteral("modal"))) {
0064         accessDialog->windowHandle()->setModality(options.value(QStringLiteral("modal")).toBool() ? Qt::WindowModal : Qt::NonModal);
0065     }
0066 
0067     if (accessDialog->exec()) {
0068         accessDialog->deleteLater();
0069         return 0;
0070     }
0071     accessDialog->deleteLater();
0072 
0073     return 1;
0074 }