File indexing completed on 2025-01-05 04:58:17

0001 /**
0002  *
0003  *  SPDX-FileCopyrightText: 2004 David Faure <faure@kde.org>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #include "collectionaclpage.h"
0009 #include "aclmanager.h"
0010 #include "collectionaclwidget.h"
0011 #include "imapaclattribute.h"
0012 #include <Akonadi/Collection>
0013 #include <KLocalizedString>
0014 #include <QHBoxLayout>
0015 
0016 using namespace PimCommon;
0017 
0018 class PimCommon::CollectionAclPagePrivate
0019 {
0020 public:
0021     CollectionAclPagePrivate() = default;
0022 
0023     CollectionAclWidget *mCollectionAclWidget = nullptr;
0024 };
0025 
0026 CollectionAclPage::CollectionAclPage(QWidget *parent)
0027     : CollectionPropertiesPage(parent)
0028     , d(new PimCommon::CollectionAclPagePrivate)
0029 {
0030     setObjectName(QLatin1StringView("PimCommon::CollectionAclPage"));
0031 
0032     setPageTitle(i18n("Access Control"));
0033     init();
0034 }
0035 
0036 CollectionAclPage::~CollectionAclPage() = default;
0037 
0038 void CollectionAclPage::init()
0039 {
0040     auto layout = new QHBoxLayout(this);
0041     layout->setContentsMargins({});
0042     d->mCollectionAclWidget = new CollectionAclWidget(this);
0043     layout->addWidget(d->mCollectionAclWidget);
0044 }
0045 
0046 bool CollectionAclPage::canHandle(const Akonadi::Collection &collection) const
0047 {
0048     return collection.hasAttribute<PimCommon::ImapAclAttribute>();
0049 }
0050 
0051 void CollectionAclPage::load(const Akonadi::Collection &collection)
0052 {
0053     d->mCollectionAclWidget->aclManager()->setCollection(collection);
0054 }
0055 
0056 void CollectionAclPage::save(Akonadi::Collection &collection)
0057 {
0058     d->mCollectionAclWidget->aclManager()->save(d->mCollectionAclWidget->recursive());
0059 
0060     // The collection dialog expects the changed collection to run
0061     // its own ItemModifyJob, so make him happy...
0062     const auto origCol = d->mCollectionAclWidget->aclManager()->collection();
0063     collection.addAttribute(origCol.attribute<PimCommon::ImapAclAttribute>()->clone());
0064 }
0065 
0066 #include "moc_collectionaclpage.cpp"