Pimcommon

aclentrydialog.cpp
1/*
2 * SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3 * SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kdab.com>
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 */
7
8#include "aclentrydialog_p.h"
9#include "aclutils_p.h"
10
11#include <PimCommonAkonadi/AddresseeLineEdit>
12
13#include <Akonadi/EmailAddressSelectionDialog>
14
15#include <KLocalizedString>
16
17#include <QButtonGroup>
18#include <QDialogButtonBox>
19#include <QGridLayout>
20#include <QGroupBox>
21#include <QLabel>
22#include <QPushButton>
23#include <QRadioButton>
24#include <QVBoxLayout>
25
26using namespace PimCommon;
27
28class AclEntryDialog::AclEntryDialogPrivate
29{
30public:
31 AclEntryDialogPrivate(AclEntryDialog *qq)
32 : q(qq)
33 {
34 }
35
36 void slotChanged();
37 void slotSelectAddresses();
38
39 AclEntryDialog *const q;
40 QButtonGroup *mButtonGroup = nullptr;
41 PimCommon::AddresseeLineEdit *mUserIdLineEdit = nullptr;
42 QVBoxLayout *mButtonLayout = nullptr;
43 KIMAP::Acl::Rights mCustomPermissions;
44 QPushButton *mOkButton = nullptr;
45};
46
47void AclEntryDialog::AclEntryDialogPrivate::slotChanged()
48{
49 mOkButton->setEnabled(!mUserIdLineEdit->text().trimmed().isEmpty() && mButtonGroup->checkedButton() != nullptr);
50}
51
52void AclEntryDialog::AclEntryDialogPrivate::slotSelectAddresses()
53{
55
56 if (!dlg.exec()) {
57 return;
58 }
59
60 const QString text = !dlg.selectedAddresses().isEmpty() ? dlg.selectedAddresses().at(0).quotedEmail() : QString();
61
62 mUserIdLineEdit->setText(text);
63}
64
65AclEntryDialog::AclEntryDialog(QWidget *parent)
66 : QDialog(parent)
67 , d(new AclEntryDialogPrivate(this))
68{
69 auto mainLayout = new QVBoxLayout(this);
71 d->mOkButton = buttonBox->button(QDialogButtonBox::Ok);
72 d->mOkButton->setDefault(true);
73 d->mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
74 connect(buttonBox, &QDialogButtonBox::accepted, this, &AclEntryDialog::accept);
75 connect(buttonBox, &QDialogButtonBox::rejected, this, &AclEntryDialog::reject);
76
77 auto page = new QWidget(this);
78 mainLayout->addWidget(page);
79 mainLayout->addWidget(buttonBox);
80
81 auto layout = new QGridLayout(page);
82 layout->setContentsMargins({});
83
84 auto label = new QLabel(i18nc("@label:textbox", "&User identifier:"), page);
85 layout->addWidget(label, 0, 0);
86
87 d->mUserIdLineEdit = new PimCommon::AddresseeLineEdit(page);
88 layout->addWidget(d->mUserIdLineEdit, 0, 1);
89 label->setBuddy(d->mUserIdLineEdit);
90 d->mUserIdLineEdit->setWhatsThis(i18nc("@info:whatsthis",
91 "The User Identifier is the login of the user on the IMAP server. "
92 "This can be a simple user name or the full email address of the user; "
93 "the login for your own account on the server will tell you which one it is."));
94
95 auto button = new QPushButton(i18nc("select an email address", "Se&lect..."), page);
96 layout->addWidget(button, 0, 2);
97
98 auto groupBox = new QGroupBox(i18n("Permissions"), page);
99 d->mButtonLayout = new QVBoxLayout(groupBox);
100
101 d->mButtonGroup = new QButtonGroup(groupBox);
102
103 for (unsigned int i = 0; i < AclUtils::standardPermissionsCount(); ++i) {
104 const KIMAP::Acl::Rights aclRightPermissions = AclUtils::permissionsForIndex(i);
105
106 auto radioButton = new QRadioButton(AclUtils::permissionsToUserString(aclRightPermissions), groupBox);
107 d->mButtonLayout->addWidget(radioButton);
108 d->mButtonGroup->addButton(radioButton, aclRightPermissions);
109 }
110
111 d->mButtonLayout->addStretch(1);
112 layout->addWidget(groupBox, 1, 0, 1, 3);
113
114 label = new QLabel(i18nc("@label:textbox", "<b>Note: </b>Renaming requires write permissions on the parent folder."), page);
115 layout->addWidget(label, 2, 0, 1, 3);
116 layout->setRowStretch(2, 10);
117
118 connect(d->mUserIdLineEdit, &AddresseeLineEdit::textChanged, this, [this]() {
119 d->slotChanged();
120 });
121 connect(button, &QPushButton::clicked, this, [this]() {
122 d->slotSelectAddresses();
123 });
124 connect(d->mButtonGroup, &QButtonGroup::buttonClicked, this, [this]() {
125 d->slotChanged();
126 });
127
128 d->mOkButton->setEnabled(false);
129
130 d->mUserIdLineEdit->setFocus();
131}
132
133AclEntryDialog::~AclEntryDialog() = default;
134
135void AclEntryDialog::setUserId(const QString &userId)
136{
137 d->mUserIdLineEdit->setText(userId);
138
139 d->mOkButton->setEnabled(!userId.isEmpty());
140}
141
142QString AclEntryDialog::userId() const
143{
144 return d->mUserIdLineEdit->text();
145}
146
147void AclEntryDialog::setPermissions(KIMAP::Acl::Rights permissions)
148{
149 QAbstractButton *button = d->mButtonGroup->button(KIMAP::Acl::normalizedRights(permissions));
150
151 if (button) {
152 button->setChecked(true);
153 } else {
154 auto radioButton = new QRadioButton(AclUtils::permissionsToUserString(permissions));
155
156 d->mButtonLayout->addWidget(radioButton);
157 d->mButtonGroup->addButton(radioButton, permissions);
158 }
159
160 d->mCustomPermissions = permissions;
161}
162
163KIMAP::Acl::Rights AclEntryDialog::permissions() const
164{
165 QAbstractButton *button = d->mButtonGroup->checkedButton();
166
167 if (!button) {
168 return d->mCustomPermissions;
169 }
170
171 return KIMAP::Acl::denormalizedRights(static_cast<KIMAP::Acl::Rights>(d->mButtonGroup->id(button)));
172}
173
174#include "moc_aclentrydialog_p.cpp"
Akonadi::EmailAddressSelection::List selectedAddresses() const override
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KIMAP_EXPORT Rights denormalizedRights(Rights rights)
KIMAP_EXPORT Rights normalizedRights(Rights rights)
QString label(StandardShortcut id)
folderdialogacltab.h
void setChecked(bool)
void clicked(bool checked)
void buttonClicked(QAbstractButton *button)
QAbstractButton * checkedButton() const const
const_reference at(qsizetype i) const const
bool isEmpty() const const
bool isEmpty() const const
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:14:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.