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

0001 /*
0002  * SPDX-FileCopyrightText: 2020 Red Hat Inc
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  *
0006  * SPDX-FileCopyrightText: 2020 Jan Grulich <jgrulich@redhat.com>
0007  */
0008 
0009 #include "userinfodialog.h"
0010 
0011 #include "user_interface.h"
0012 
0013 #include <sys/types.h>
0014 #include <unistd.h>
0015 
0016 #include <QFileInfo>
0017 #include <QQmlContext>
0018 #include <QQmlEngine>
0019 #include <QQuickItem>
0020 #include <QQuickWidget>
0021 #include <QStandardPaths>
0022 
0023 #include <KLocalizedString>
0024 
0025 UserInfoDialog::UserInfoDialog(const QString &reason, QObject *parent)
0026     : QuickDialog(parent)
0027 {
0028     QString ifacePath = QStringLiteral("/org/freedesktop/Accounts/User%1").arg(getuid());
0029     m_userInterface = new OrgFreedesktopAccountsUserInterface(QStringLiteral("org.freedesktop.Accounts"), ifacePath, QDBusConnection::systemBus(), this);
0030 
0031     QString image = QFileInfo::exists(m_userInterface->iconFile()) ? m_userInterface->iconFile() : QString();
0032     QVariantMap props = {{"title", i18n("Share Information")},
0033                          {"subtitle", i18n("Share your personal information with the requesting application?")},
0034                          {"reason", reason},
0035                          {"userName", m_userInterface->userName()},
0036                          {"realName", m_userInterface->realName()}};
0037 
0038     if (QFileInfo::exists(m_userInterface->iconFile())) {
0039         props.insert(QStringLiteral("iconName"), m_userInterface->iconFile());
0040     } else {
0041         props.insert(QStringLiteral("iconName"), QStringLiteral("user-identity"));
0042     }
0043     create("qrc:/UserInfoDialog.qml", props);
0044 }
0045 
0046 UserInfoDialog::~UserInfoDialog()
0047 {
0048 }
0049 
0050 QString UserInfoDialog::id() const
0051 {
0052     return m_userInterface->userName();
0053 }
0054 
0055 QString UserInfoDialog::image() const
0056 {
0057     return QUrl::fromLocalFile(m_userInterface->iconFile()).toString();
0058 }
0059 
0060 QString UserInfoDialog::name() const
0061 {
0062     return m_userInterface->realName();
0063 }