diff --git a/src/access.cpp b/src/access.cpp new file mode 100644 index 0000000..194415d --- /dev/null +++ b/src/access.cpp @@ -0,0 +1,86 @@ +/* + * Copyright © 2017 Red Hat, Inc + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: + * Jan Grulich + */ + +#include "access.h" +#include "accessdialog.h" + +#include + +#include + +Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccess, "xdg-desktop-portal-kde-access") + +Access::Access(QObject *parent) + : QObject(parent) +{ +} + +Access::~Access() +{ +} + +uint Access::accessDialog(const QDBusObjectPath &handle, + const QString &app_id, + const QString &parent_window, + const QString &title, + const QString &subtitle, + const QString &body, + const QVariantMap &options, + QVariantMap &results) +{ + qCDebug(XdgDesktopPortalKdeAccess) << "AccessDialog called with parameters:"; + qCDebug(XdgDesktopPortalKdeAccess) << " handle: " << handle.path(); + qCDebug(XdgDesktopPortalKdeAccess) << " app_id: " << app_id; + qCDebug(XdgDesktopPortalKdeAccess) << " parent_window: " << parent_window; + qCDebug(XdgDesktopPortalKdeAccess) << " title: " << title; + qCDebug(XdgDesktopPortalKdeAccess) << " subtitle: " << subtitle; + qCDebug(XdgDesktopPortalKdeAccess) << " body: " << body; + qCDebug(XdgDesktopPortalKdeAccess) << " options: " << options; + + AccessDialog *accessDialog = new AccessDialog(); + accessDialog->setBody(body); + accessDialog->setTitle(title); + accessDialog->setSubtitle(subtitle); + + if (options.contains(QLatin1String("modal"))) { + accessDialog->setModal(options.value(QLatin1String("modal")).toBool()); + } + + if (options.contains(QLatin1String("deny_label"))) { + accessDialog->setRejectLabel(options.value(QLatin1String("deny_label")).toString()); + } + + if (options.contains(QLatin1String("grant_label"))) { + accessDialog->setAcceptLabel(options.value(QLatin1String("grant_label")).toString()); + } + + if (options.contains(QLatin1String("icon"))) { + accessDialog->setIcon(options.value(QLatin1String("icon")).toString()); + } + + // TODO choices + + if (accessDialog->exec()) { + accessDialog->deleteLater(); + return 0; + } + accessDialog->deleteLater(); + + return 1; +} diff --git a/src/access.h b/src/access.h new file mode 100644 index 0000000..65ffd38 --- /dev/null +++ b/src/access.h @@ -0,0 +1,47 @@ +/* + * Copyright © 2017 Red Hat, Inc + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + * Authors: + * Jan Grulich + */ + +#ifndef XDG_DESKTOP_PORTAL_KDE_ACCESS_H +#define XDG_DESKTOP_PORTAL_KDE_ACCESS_H + +#include +#include + +class Access : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.Access") +public: + Access(QObject *parent = nullptr); + ~Access(); + +public Q_SLOTS: + uint accessDialog(const QDBusObjectPath &handle, + const QString &app_id, + const QString &parent_window, + const QString &title, + const QString &subtitle, + const QString &body, + const QVariantMap &options, + QVariantMap &results); +}; + +#endif // XDG_DESKTOP_PORTAL_KDE_ACCESS_H +