Commit 75a8fa72 authored by Jan Grulich's avatar Jan Grulich

Add new Account portal

Summary:
Account portal allows applications to get information from libaccount.

Screenshot of the dialog:
{F8145223}

Reviewers: #plasma, ngraham

Reviewed By: ngraham

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D27783
parent f2a893ca
[portal]
DBusName=org.freedesktop.impl.portal.desktop.kde
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;org.freedesktop.impl.portal.ScreenCast;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.RemoteDesktop;org.freedesktop.impl.portal.Settings
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.Account;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;org.freedesktop.impl.portal.ScreenCast;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.RemoteDesktop;org.freedesktop.impl.portal.Settings
UseIn=KDE
<!DOCTYPE node PUBLIC
"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
<interface name="org.freedesktop.Accounts.User">
<property name="UserName" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
The username of the user.
</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="RealName" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
The users real name.
</doc:para>
</doc:description>
</doc:doc>
</property>
<property name="IconFile" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
The filename of a png file containing the users icon.
</doc:para>
</doc:description>
</doc:doc>
</property>
<signal name="Changed">
<doc:doc>
<doc:description>
<doc:para>
Emitted when the user is changed.
</doc:para>
</doc:description>
</doc:doc>
</signal>
</interface>
</node>
......@@ -6,6 +6,7 @@ set(xdg_desktop_portal_kde_SRCS
xdg-desktop-portal-kde.cpp
access.cpp
accessdialog.cpp
account.cpp
appchooser.cpp
appchooserdialog.cpp
desktopportal.cpp
......@@ -20,6 +21,7 @@ set(xdg_desktop_portal_kde_SRCS
screenshotdialog.cpp
settings.cpp
utils.cpp
userinfodialog.cpp
)
if (SCREENCAST_ENABLED)
......@@ -42,8 +44,13 @@ ki18n_wrap_ui(xdg_desktop_portal_kde_SRCS
accessdialog.ui
appchooserdialog.ui
screenshotdialog.ui
userinfodialog.ui
)
set_source_files_properties(../data/org.freedesktop.Accounts.User.xml PROPERTIES NO_NAMESPACE TRUE)
qt5_add_dbus_interface(xdg_desktop_portal_kde_SRCS ../data/org.freedesktop.Accounts.User.xml user_interface)
add_executable(xdg-desktop-portal-kde ${xdg_desktop_portal_kde_SRCS})
target_link_libraries(xdg-desktop-portal-kde
......@@ -75,4 +82,5 @@ install(TARGETS xdg-desktop-portal-kde DESTINATION ${KDE_INSTALL_LIBEXECDIR})
install(FILES
qml/AppChooserDialog.qml
qml/UserInfoDialog.qml
DESTINATION ${KDE_INSTALL_DATADIR}/xdg-desktop-portal-kde/qml)
/*
* Copyright © 2020 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 "account.h"
#include "userinfodialog.h"
#include "utils.h"
#include <QLoggingCategory>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeAccount, "xdp-kde-account")
AccountPortal::AccountPortal(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
}
AccountPortal::~AccountPortal()
{
}
uint AccountPortal::GetUserInformation(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QVariantMap &options,
QVariantMap &results)
{
qCDebug(XdgDesktopPortalKdeAccount) << "GetUserInformation called with parameters:";
qCDebug(XdgDesktopPortalKdeAccount) << " handle: " << handle.path();
qCDebug(XdgDesktopPortalKdeAccount) << " parent_window: " << parent_window;
qCDebug(XdgDesktopPortalKdeAccount) << " app_id: " << app_id;
qCDebug(XdgDesktopPortalKdeAccount) << " options: " << options;
QString reason;
if (options.contains(QStringLiteral("reason"))) {
reason = options.value(QStringLiteral("reason")).toString();
}
UserInfoDialog *userInfoDialog = new UserInfoDialog(reason);
Utils::setParentWindow(userInfoDialog, parent_window);
int result = userInfoDialog->exec();
if (result) {
results.insert(QStringLiteral("id"), userInfoDialog->id());
results.insert(QStringLiteral("name"), userInfoDialog->name());
results.insert(QStringLiteral("image"), userInfoDialog->image());
}
userInfoDialog->deleteLater();
return !result;
}
/*
* Copyright © 2020 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_ACCOUNT_H
#define XDG_DESKTOP_PORTAL_KDE_ACCOUNT_H
#include <QDBusAbstractAdaptor>
#include <QDBusObjectPath>
class AccountPortal : public QDBusAbstractAdaptor
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.Account")
public:
explicit AccountPortal(QObject *parent);
~AccountPortal();
public Q_SLOTS:
uint GetUserInformation(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QVariantMap &options,
QVariantMap &results);
};
#endif // XDG_DESKTOP_PORTAL_KDE_ACCOUNT_H
......@@ -27,6 +27,7 @@ Q_LOGGING_CATEGORY(XdgDesktopPortalKdeDesktopPortal, "xdp-kde-desktop-portal")
DesktopPortal::DesktopPortal(QObject *parent)
: QObject(parent)
, m_access(new AccessPortal(this))
, m_account(new AccountPortal(this))
, m_appChooser(new AppChooserPortal(this))
, m_email(new EmailPortal(this))
, m_fileChooser(new FileChooserPortal(this))
......
......@@ -25,6 +25,7 @@
#include <QDBusContext>
#include "access.h"
#include "account.h"
#include "appchooser.h"
#include "email.h"
#include "filechooser.h"
......@@ -48,6 +49,7 @@ public:
private:
AccessPortal *m_access;
AccountPortal *m_account;
AppChooserPortal *m_appChooser;
EmailPortal *m_email;
FileChooserPortal *m_fileChooser;
......
/*
* Copyright © 2020 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>
*/
import QtQuick 2.12
import QtQuick.Controls 2.12 as QQC2
import QtQuick.Layouts 1.12
import org.kde.plasma.core 2.0
import org.kde.kirigami 2.9 as Kirigami
Item {
id: root
signal accepted()
signal rejected()
Rectangle {
id: background
anchors.fill: parent
color: Kirigami.Theme.backgroundColor
}
ColumnLayout {
anchors.fill: parent
RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
Kirigami.Icon {
height: units.iconSizes.enormous
width: units.iconSizes.enormous
source: image
}
ColumnLayout {
Kirigami.Heading {
id: nameText
Layout.fillWidth: true
text: name
}
Kirigami.Heading {
id: idText
Layout.fillWidth: true
level: 3
text: id
}
}
}
QQC2.Label {
Layout.alignment: Qt.AlignTop
Layout.fillWidth: true
text: i18n("Share your personal information with the requesting application?")
wrapMode: Text.WordWrap
}
QQC2.Label {
Layout.fillWidth: true
text: reason
wrapMode: Text.WordWrap
}
RowLayout {
Layout.alignment: Qt.AlignBottom | Qt.AlignRight
QQC2.Button {
text: i18n("Share")
onClicked: accepted()
}
QQC2.Button {
text: i18n("Cancel")
onClicked: rejected()
}
}
}
}
/*
* Copyright © 2020 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 "userinfodialog.h"
#include "ui_userinfodialog.h"
#include "user_interface.h"
#include <unistd.h>
#include <sys/types.h>
#include <QFileInfo>
#include <QStandardPaths>
#include <QQmlContext>
#include <QQmlEngine>
#include <QQuickWidget>
#include <QQuickItem>
#include <kdeclarative/kdeclarative.h>
UserInfoDialog::UserInfoDialog(const QString &reason, QDialog *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
, m_dialog(new Ui::UserInfoDialog)
{
m_dialog->setupUi(this);
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(m_dialog->quickWidget->engine());
kdeclarative.setTranslationDomain(QStringLiteral(TRANSLATION_DOMAIN));
kdeclarative.setupEngine(m_dialog->quickWidget->engine());
kdeclarative.setupContext();
QString ifacePath = QStringLiteral("/org/freedesktop/Accounts/User%1").arg(getuid());
m_userInterface = new OrgFreedesktopAccountsUserInterface(QStringLiteral("org.freedesktop.Accounts"), ifacePath, QDBusConnection::systemBus(), this);
QString image = QFileInfo::exists(m_userInterface->iconFile()) ? m_userInterface->iconFile() : QString();
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("reason"), reason);
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("id"), m_userInterface->userName());
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("name"), m_userInterface->realName());
if (QFileInfo::exists(m_userInterface->iconFile())) {
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("image"), m_userInterface->iconFile());
} else {
m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("image"), QIcon::fromTheme(QStringLiteral("user-identity")));
}
m_dialog->quickWidget->setClearColor(Qt::transparent);
m_dialog->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
m_dialog->quickWidget->setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("xdg-desktop-portal-kde/qml/UserInfoDialog.qml"))));
QObject *rootItem = m_dialog->quickWidget->rootObject();
connect(rootItem, SIGNAL(accepted()), this, SLOT(accept()));
connect(rootItem, SIGNAL(rejected()), this, SLOT(reject()));
setWindowTitle(i18n("Share Information"));
}
UserInfoDialog::~UserInfoDialog()
{
delete m_dialog;
}
QString UserInfoDialog::id() const
{
return m_userInterface->userName();
}
QString UserInfoDialog::image() const
{
return m_userInterface->realName();
}
QString UserInfoDialog::name() const
{
return m_userInterface->iconFile();
}
/*
* Copyright © 2020 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_USERINFO_DIALOG_H
#define XDG_DESKTOP_PORTAL_KDE_USERINFO_DIALOG_H
#include <QDialog>
namespace Ui
{
class UserInfoDialog;
}
class OrgFreedesktopAccountsUserInterface;
class UserInfoDialog : public QDialog
{
Q_OBJECT
public:
explicit UserInfoDialog(const QString &reason, QDialog *parent = nullptr, Qt::WindowFlags flags = {});
~UserInfoDialog();
QString id() const;
QString name() const;
QString image() const;
private:
Ui::UserInfoDialog *m_dialog;
OrgFreedesktopAccountsUserInterface *m_userInterface;
};
#endif // XDG_DESKTOP_PORTAL_KDE_USERINFO_DIALOG_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>UserInfoDialog</class>
<widget class="QDialog" name="AppChooserDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>360</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QQuickWidget" name="quickWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="resizeMode">
<enum>QQuickWidget::SizeRootObjectToView</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QQuickWidget</class>
<extends>QWidget</extends>
<header location="global">QtQuickWidgets/QQuickWidget</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
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