expireaccounttrashfolderconfigwidget.cpp 2.67 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
   Copyright (C) 2020 Laurent Montel <montel@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include "expireaccounttrashfolderconfigwidget.h"
21
#include <MailCommon/CollectionExpiryWidget>
Laurent Montel's avatar
Laurent Montel committed
22 23
#include <AkonadiCore/AgentManager>
#include <akonadi/kmime/specialmailcollections.h>
24 25 26 27 28 29 30 31
#include <QVBoxLayout>

ExpireAccountTrashFolderConfigWidget::ExpireAccountTrashFolderConfigWidget(QWidget *parent)
    : QWidget(parent)
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->setObjectName(QStringLiteral("mainLayout"));
    mainLayout->setContentsMargins(0, 0, 0, 0);
32 33 34 35


     mCollectionExpiryWidget = new MailCommon::CollectionExpiryWidget(this);
     mCollectionExpiryWidget->setObjectName(QStringLiteral("mCollectionExpiryWidget"));
36
     connect(mCollectionExpiryWidget, &MailCommon::CollectionExpiryWidget::saveAndExpireRequested, this, &ExpireAccountTrashFolderConfigWidget::slotSaveAndExpireRequested);
37
     mainLayout->addWidget(mCollectionExpiryWidget);
38 39 40 41 42 43 44
}

ExpireAccountTrashFolderConfigWidget::~ExpireAccountTrashFolderConfigWidget()
{

}

Laurent Montel's avatar
Laurent Montel committed
45
void ExpireAccountTrashFolderConfigWidget::save(bool saveSettings, bool expireNow)
46
{
Laurent Montel's avatar
Laurent Montel committed
47
    const MailCommon::CollectionExpirySettings settings = mCollectionExpiryWidget->settings();
Laurent Montel's avatar
Laurent Montel committed
48
    const Akonadi::AgentInstance::List agents = Akonadi::AgentManager::self()->instances();
Laurent Montel's avatar
Laurent Montel committed
49
    QList<Akonadi::Collection::Id> mListCollection;
Laurent Montel's avatar
Laurent Montel committed
50 51
    for (const Akonadi::AgentInstance &agent : agents) {
        Akonadi::Collection trashCol = Akonadi::SpecialMailCollections::self()->collection(Akonadi::SpecialMailCollections::Trash, agent);
Laurent Montel's avatar
Laurent Montel committed
52 53 54 55
        if (mListCollection.contains(trashCol.id())) {
            continue;
        }
        mListCollection.append(trashCol.id());
Laurent Montel's avatar
Laurent Montel committed
56
        if (trashCol.isValid()) {
Laurent Montel's avatar
Laurent Montel committed
57
            mCollectionExpiryWidget->save(settings, trashCol, saveSettings, expireNow);
Laurent Montel's avatar
Laurent Montel committed
58 59
        }
    }
60 61
}

Laurent Montel's avatar
Laurent Montel committed
62 63 64 65 66
void ExpireAccountTrashFolderConfigWidget::save()
{
    save(true, false);
}

67
void ExpireAccountTrashFolderConfigWidget::slotSaveAndExpireRequested()
68
{
Laurent Montel's avatar
Laurent Montel committed
69
    save(true, true);
70
}