File indexing completed on 2025-01-05 04:49:41

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "expireaccounttrashfolderconfigwidget.h"
0008 #include "libexpireaccounttrashfolderconfig_debug.h"
0009 #include <Akonadi/AgentManager>
0010 #include <Akonadi/SpecialMailCollections>
0011 #include <MailCommon/CollectionExpiryWidget>
0012 #include <QVBoxLayout>
0013 
0014 ExpireAccountTrashFolderConfigWidget::ExpireAccountTrashFolderConfigWidget(QWidget *parent)
0015     : QWidget(parent)
0016     , mCollectionExpiryWidget(new MailCommon::CollectionExpiryWidget(this))
0017 {
0018     auto mainLayout = new QVBoxLayout(this);
0019     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0020     mainLayout->setContentsMargins({});
0021 
0022     mCollectionExpiryWidget->setObjectName(QLatin1StringView("mCollectionExpiryWidget"));
0023     connect(mCollectionExpiryWidget,
0024             &MailCommon::CollectionExpiryWidget::saveAndExpireRequested,
0025             this,
0026             &ExpireAccountTrashFolderConfigWidget::slotSaveAndExpireRequested);
0027     mainLayout->addWidget(mCollectionExpiryWidget);
0028 }
0029 
0030 ExpireAccountTrashFolderConfigWidget::~ExpireAccountTrashFolderConfigWidget() = default;
0031 
0032 void ExpireAccountTrashFolderConfigWidget::save(bool saveSettings, bool expireNow)
0033 {
0034     const MailCommon::CollectionExpirySettings settings = mCollectionExpiryWidget->settings();
0035     const Akonadi::AgentInstance::List agents = Akonadi::AgentManager::self()->instances();
0036     QList<Akonadi::Collection::Id> mListCollection;
0037     for (const Akonadi::AgentInstance &agent : agents) {
0038         Akonadi::Collection trashCol = Akonadi::SpecialMailCollections::self()->collection(Akonadi::SpecialMailCollections::Trash, agent);
0039         const auto trashColId = trashCol.id();
0040         // qCDebug(LIBEXPIREACCOUNTTRASHFOLDERCONFIG_PLUGIN_LOG) << "Trash collection found " << trashCol;
0041         if (trashCol.isValid()) {
0042             qCDebug(LIBEXPIREACCOUNTTRASHFOLDERCONFIG_PLUGIN_LOG) << "Trash collection valid found " << trashCol;
0043             if (mListCollection.contains(trashColId)) {
0044                 continue;
0045             }
0046             mListCollection.append(trashColId);
0047             mCollectionExpiryWidget->save(settings, trashCol, saveSettings, expireNow);
0048         }
0049     }
0050 }
0051 
0052 void ExpireAccountTrashFolderConfigWidget::save()
0053 {
0054     save(true, false);
0055 }
0056 
0057 void ExpireAccountTrashFolderConfigWidget::slotSaveAndExpireRequested()
0058 {
0059     save(true, true);
0060 }
0061 
0062 #include "moc_expireaccounttrashfolderconfigwidget.cpp"