Commit 7f28b67f authored by Jan Grulich's avatar Jan Grulich

Add Access portal for requesting hardware access

parent 28fce3a2
[portal]
DBusName=org.freedesktop.impl.portal.desktop.kde
Interfaces=org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Email;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.Inhibit;org.freedesktop.impl.portal.Notification;org.freedesktop.impl.portal.Print
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Email;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.Inhibit;org.freedesktop.impl.portal.Notification;org.freedesktop.impl.portal.Print
UseIn=KDE
......@@ -6,6 +6,8 @@ include_directories(
set(xdg_desktop_portal_kde_SRCS
xdg-desktop-portal-kde.cpp
access.cpp
accessdialog.cpp
appchooser.cpp
appchooserdialog.cpp
desktopportal.cpp
......@@ -18,6 +20,7 @@ set(xdg_desktop_portal_kde_SRCS
)
ki18n_wrap_ui(xdg_desktop_portal_kde_SRCS
accessdialog.ui
appchooserdialog.ui
)
......
/*
* 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 <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#include "accessdialog.h"
#include "ui_accessdialog.h"
#include <QLoggingCategory>
#include <QSettings>
#include <QStandardPaths>
#include <QPushButton>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccessDialog, "xdg-desktop-portal-kde-access-dialog")
AccessDialog::AccessDialog(QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, m_dialog(new Ui::AccessDialog)
{
m_dialog->setupUi(this);
connect(m_dialog->buttonBox, &QDialogButtonBox::accepted, this, &AccessDialog::accept);
connect(m_dialog->buttonBox, &QDialogButtonBox::rejected, this, &AccessDialog::reject);
m_dialog->iconLabel->setPixmap(QIcon::fromTheme(QLatin1String("dialog-question")).pixmap(QSize(64, 64)));
setWindowTitle(i18n("Request device access"));
}
AccessDialog::~AccessDialog()
{
delete m_dialog;
}
void AccessDialog::setAcceptLabel(const QString &label)
{
m_dialog->buttonBox->button(QDialogButtonBox::Ok)->setText(label);
}
void AccessDialog::setBody(const QString &body)
{
m_dialog->bodyLabel->setText(body);
}
void AccessDialog::setIcon(const QString &icon)
{
m_dialog->iconLabel->setPixmap(QIcon::fromTheme(icon).pixmap(QSize(64, 64)));
}
void AccessDialog::setRejectLabel(const QString &label)
{
m_dialog->buttonBox->button(QDialogButtonBox::Cancel)->setText(label);
}
void AccessDialog::setSubtitle(const QString &subtitle)
{
m_dialog->subtitleLabel->setText(subtitle);
}
void AccessDialog::setTitle(const QString &title)
{
m_dialog->titleLabel->setText(title);
}
/*
* 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 <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_ACCESS_DIALOG_H
#define XDG_DESKTOP_PORTAL_KDE_ACCESS_DIALOG_H
#include <QDialog>
namespace Ui
{
class AccessDialog;
}
class AccessDialog : public QDialog
{
Q_OBJECT
public:
AccessDialog(QDialog *parent = nullptr, Qt::WindowFlags flags = 0);
~AccessDialog();
void setAcceptLabel(const QString &label);
void setBody(const QString &body);
void setIcon(const QString &icon);
void setRejectLabel(const QString &label);
void setTitle(const QString &title);
void setSubtitle(const QString &subtitle);
private:
Ui::AccessDialog * m_dialog;
};
#endif // XDG_DESKTOP_PORTAL_KDE_ACCESS_DIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AccessDialog</class>
<widget class="QDialog" name="AccessDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>392</width>
<height>162</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="iconLabel">
<property name="text">
<string>Icon</string>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="titleLabel">
<property name="styleSheet">
<string notr="true">font-weight: bold</string>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="subtitleLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QLabel" name="bodyLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
/*
* Copyright © 2016 Red Hat, Inc
* 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
......
......@@ -30,6 +30,7 @@ Q_LOGGING_CATEGORY(XdgDesktopPortalKdeDesktopPortal, "xdg-desktop-portal-kde-des
DesktopPortal::DesktopPortal(QObject *parent)
: QDBusVirtualObject(parent)
, m_access(new Access())
, m_appChooser(new AppChooser())
, m_email(new Email())
, m_fileChooser(new FileChooser())
......@@ -41,6 +42,7 @@ DesktopPortal::DesktopPortal(QObject *parent)
DesktopPortal::~DesktopPortal()
{
delete m_access;
delete m_appChooser;
delete m_email;
delete m_fileChooser;
......@@ -61,7 +63,26 @@ bool DesktopPortal::handleMessage(const QDBusMessage &message, const QDBusConnec
qCDebug(XdgDesktopPortalKdeDesktopPortal) << message.path();
QList<QVariant> arguments;
if (message.interface() == QLatin1String("org.freedesktop.impl.portal.AppChooser")) {
if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Access")) {
if (message.member() == QLatin1String("AccessDialog")) {
QVariantMap results;
QVariantMap options;
QDBusArgument dbusArgument = message.arguments().at(6).value<QDBusArgument>();
dbusArgument >> options;
uint response = m_access->accessDialog(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
message.arguments().at(1).toString(), // app_id
message.arguments().at(2).toString(), // parent_window
message.arguments().at(3).toString(), // title
message.arguments().at(4).toString(), // subtitle
message.arguments().at(5).toString(), // body
options, // options
results);
arguments << response;
arguments << results;
}
} else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.AppChooser")) {
if (message.member() == QLatin1String("ChooseApplication")) {
QVariantMap results;
QVariantMap choices;
......@@ -206,6 +227,19 @@ QString DesktopPortal::introspect(const QString &path) const
if (path == QLatin1String("/org/freedesktop/portal/desktop/") || path == QLatin1String("/org/freedesktop/portal/desktop")) {
nodes = QStringLiteral(
"<interface name=\"org.freedesktop.impl.portal.Access\">"
" <method name=\"AccessDialog\">"
" <arg type=\"o\" name=\"handle\" direction=\"in\"/>"
" <arg type=\"s\" name=\"app_id\" direction=\"in\"/>"
" <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>"
" <arg type=\"s\" name=\"title\" direction=\"in\"/>"
" <arg type=\"s\" name=\"subtitle\" direction=\"in\"/>"
" <arg type=\"s\" name=\"body\" direction=\"in\"/>"
" <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>"
" <arg type=\"u\" name=\"response\" direction=\"out\"/>"
" <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>"
" </method>"
"</interface>"
"<interface name=\"org.freedesktop.impl.portal.AppChooser\">"
" <method name=\"ChooseApplication\">"
" <arg type=\"o\" name=\"handle\" direction=\"in\"/>"
......
......@@ -24,6 +24,7 @@
#include <QObject>
#include <QDBusVirtualObject>
#include "access.h"
#include "appchooser.h"
#include "email.h"
#include "filechooser.h"
......@@ -41,6 +42,7 @@ public:
bool handleMessage(const QDBusMessage &message, const QDBusConnection &connection) Q_DECL_OVERRIDE;
QString introspect(const QString &path) const Q_DECL_OVERRIDE;
private:
Access *m_access;
AppChooser *m_appChooser;
Email *m_email;
FileChooser *m_fileChooser;
......
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