Pimcommon

aclutils.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 "aclutils_p.h"
9
10#include <KLazyLocalizedString>
11#include <KLocalizedString>
12
13using namespace PimCommon;
14
15static const struct {
16 KIMAP::Acl::Rights permissions;
17 const KLazyLocalizedString userString;
18} standardPermissions[] = {
19 {KIMAP::Acl::None, kli18nc("Permissions", "None")},
20
21 {KIMAP::Acl::Lookup | KIMAP::Acl::Read | KIMAP::Acl::KeepSeen, kli18nc("Permissions", "Read")},
22
24
27 kli18nc("Permissions", "Write")},
28
31 kli18nc("Permissions", "All")}};
32
33uint AclUtils::standardPermissionsCount()
34{
35 return sizeof(standardPermissions) / sizeof(*standardPermissions);
36}
37
38KIMAP::Acl::Rights AclUtils::permissionsForIndex(uint index)
39{
40 Q_ASSERT(index < standardPermissionsCount());
41
42 return standardPermissions[index].permissions;
43}
44
45int AclUtils::indexForPermissions(KIMAP::Acl::Rights permissions)
46{
47 const uint maxSize(sizeof(standardPermissions) / sizeof(*standardPermissions));
48 for (uint i = 0; i < maxSize; ++i) {
49 if (KIMAP::Acl::normalizedRights(permissions) == standardPermissions[i].permissions) {
50 return i;
51 }
52 }
53
54 return -1;
55}
56
57QString AclUtils::permissionsToUserString(KIMAP::Acl::Rights permissions)
58{
59 const uint maxSize(sizeof(standardPermissions) / sizeof(*standardPermissions));
60 for (uint i = 0; i < maxSize; ++i) {
61 if (KIMAP::Acl::normalizedRights(permissions) == standardPermissions[i].permissions) {
62 return KLocalizedString(standardPermissions[i].userString).toString();
63 }
64 }
65
66 return i18n("Custom Permissions (%1)", QString::fromLatin1(KIMAP::Acl::rightsToString(permissions)));
67}
68
69QString AclUtils::guessUserName(const QString &loginName, const QString &serverName)
70{
71 int pos = loginName.indexOf(QLatin1Char('@'));
72 if (pos != -1) {
73 // strip of the domain part and use user name only
74 return loginName.left(pos);
75 } else {
76 pos = serverName.lastIndexOf(QLatin1Char('.'));
77 if (pos == -1) { // no qualified domain name, only hostname
78 return QStringLiteral("%1@%2").arg(loginName, serverName);
79 }
80
81 pos = serverName.lastIndexOf(QLatin1Char('.'), pos - 1);
82 if (pos == -1) { // a simple domain name e.g. mydomain.org
83 return QStringLiteral("%1@%2").arg(loginName, serverName);
84 } else {
85 return QStringLiteral("%1@%2").arg(loginName, serverName.mid(pos + 1));
86 }
87 }
88}
QString toString() const
QString i18n(const char *text, const TYPE &arg...)
KIMAP_EXPORT QByteArray rightsToString(Rights rights)
KIMAP_EXPORT Rights normalizedRights(Rights rights)
folderdialogacltab.h
QString fromLatin1(QByteArrayView str)
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) const const
QString mid(qsizetype position, qsizetype n) const const
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.