Changeset View
Changeset View
Standalone View
Standalone View
src/userinfodialog.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright © 2020 Red Hat, Inc | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU Lesser General Public | ||||
6 | * License as published by the Free Software Foundation; either | ||||
7 | * version 2 of the License, or (at your option) any later version. | ||||
8 | * | ||||
9 | * This library is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
12 | * Lesser General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU Lesser General Public | ||||
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | * | ||||
17 | * Authors: | ||||
18 | * Jan Grulich <jgrulich@redhat.com> | ||||
19 | */ | ||||
20 | | ||||
21 | #include "userinfodialog.h" | ||||
22 | #include "ui_userinfodialog.h" | ||||
23 | | ||||
24 | #include "user_interface.h" | ||||
25 | | ||||
26 | #include <unistd.h> | ||||
27 | #include <sys/types.h> | ||||
28 | | ||||
29 | #include <QFileInfo> | ||||
30 | #include <QStandardPaths> | ||||
31 | #include <QQmlContext> | ||||
32 | #include <QQmlEngine> | ||||
33 | #include <QQuickWidget> | ||||
34 | #include <QQuickItem> | ||||
35 | | ||||
36 | #include <kdeclarative/kdeclarative.h> | ||||
37 | | ||||
38 | UserInfoDialog::UserInfoDialog(const QString &reason, QDialog *parent, Qt::WindowFlags flags) | ||||
39 | : QDialog(parent, flags) | ||||
40 | , m_dialog(new Ui::UserInfoDialog) | ||||
41 | { | ||||
42 | m_dialog->setupUi(this); | ||||
43 | | ||||
44 | KDeclarative::KDeclarative kdeclarative; | ||||
45 | kdeclarative.setDeclarativeEngine(m_dialog->quickWidget->engine()); | ||||
46 | kdeclarative.setTranslationDomain(QStringLiteral(TRANSLATION_DOMAIN)); | ||||
47 | kdeclarative.setupEngine(m_dialog->quickWidget->engine()); | ||||
48 | kdeclarative.setupContext(); | ||||
49 | | ||||
50 | QString ifacePath = QStringLiteral("/org/freedesktop/Accounts/User%1").arg(getuid()); | ||||
51 | m_userInterface = new OrgFreedesktopAccountsUserInterface(QStringLiteral("org.freedesktop.Accounts"), ifacePath, QDBusConnection::systemBus(), this); | ||||
52 | | ||||
53 | QString image = QFileInfo::exists(m_userInterface->iconFile()) ? m_userInterface->iconFile() : QString(); | ||||
54 | | ||||
55 | m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("reason"), reason); | ||||
56 | m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("id"), m_userInterface->userName()); | ||||
57 | m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("name"), m_userInterface->realName()); | ||||
58 | if (QFileInfo::exists(m_userInterface->iconFile())) { | ||||
59 | m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("image"), m_userInterface->iconFile()); | ||||
60 | } else { | ||||
61 | m_dialog->quickWidget->rootContext()->setContextProperty(QStringLiteral("image"), QIcon::fromTheme(QStringLiteral("user-identity"))); | ||||
62 | } | ||||
63 | m_dialog->quickWidget->setClearColor(Qt::transparent); | ||||
64 | m_dialog->quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); | ||||
65 | m_dialog->quickWidget->setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("xdg-desktop-portal-kde/qml/UserInfoDialog.qml")))); | ||||
66 | | ||||
67 | QObject *rootItem = m_dialog->quickWidget->rootObject(); | ||||
68 | connect(rootItem, SIGNAL(accepted()), this, SLOT(accept())); | ||||
69 | connect(rootItem, SIGNAL(rejected()), this, SLOT(reject())); | ||||
70 | | ||||
71 | setWindowTitle(i18n("Share Information")); | ||||
72 | } | ||||
73 | | ||||
74 | UserInfoDialog::~UserInfoDialog() | ||||
75 | { | ||||
76 | delete m_dialog; | ||||
77 | } | ||||
78 | | ||||
79 | QString UserInfoDialog::id() const | ||||
80 | { | ||||
81 | return m_userInterface->userName(); | ||||
82 | } | ||||
83 | | ||||
84 | QString UserInfoDialog::image() const | ||||
85 | { | ||||
86 | return m_userInterface->realName(); | ||||
87 | } | ||||
88 | | ||||
89 | QString UserInfoDialog::name() const | ||||
90 | { | ||||
91 | return m_userInterface->iconFile(); | ||||
92 | } |