Warning, file /pim/mailcommon/src/job/expiredeletejob.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /** 0002 * SPDX-FileCopyrightText: 2024 Laurent Montel <montel@kde.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "expiredeletejob.h" 0008 #include "mailcommon_debug.h" 0009 #include <Akonadi/ItemDeleteJob> 0010 #include <KLocalizedString> 0011 #include <PimCommon/BroadcastStatus> 0012 using PimCommon::BroadcastStatus; 0013 0014 ExpireDeleteJob::ExpireDeleteJob(QObject *parent) 0015 : QObject{parent} 0016 { 0017 } 0018 0019 ExpireDeleteJob::~ExpireDeleteJob() = default; 0020 0021 Akonadi::Item::List ExpireDeleteJob::removedMsgs() const 0022 { 0023 return mRemovedMsgs; 0024 } 0025 0026 void ExpireDeleteJob::setRemovedMsgs(const Akonadi::Item::List &newRemovedMsgs) 0027 { 0028 mRemovedMsgs = newRemovedMsgs; 0029 } 0030 0031 void ExpireDeleteJob::start() 0032 { 0033 if (mRemovedMsgs.isEmpty()) { 0034 qCDebug(MAILCOMMON_LOG) << "ExpireDeleteJob: nothing to do"; 0035 finished(); 0036 return; 0037 } 0038 Akonadi::Item::List ids; 0039 ids.reserve(100); 0040 for (const Akonadi::Item &item : mRemovedMsgs) { 0041 ids.append(item); 0042 if (ids.count() >= 100) { 0043 auto job = new Akonadi::ItemDeleteJob(ids, this); 0044 mRunningJobs.append(job); 0045 connect(job, &Akonadi::ItemDeleteJob::result, this, &ExpireDeleteJob::slotExpireDone); 0046 ids.clear(); 0047 ids.reserve(100); 0048 } 0049 } 0050 if (!ids.isEmpty()) { 0051 auto job = new Akonadi::ItemDeleteJob(ids, this); 0052 mRunningJobs.append(job); 0053 connect(job, &Akonadi::ItemDeleteJob::result, this, &ExpireDeleteJob::slotExpireDone); 0054 } 0055 } 0056 0057 void ExpireDeleteJob::slotExpireDone(KJob *job) 0058 { 0059 if (job->error()) { 0060 qCCritical(MAILCOMMON_LOG) << job->error() << job->errorString(); 0061 } 0062 QString msg; 0063 const int error = job->error(); 0064 switch (error) { 0065 case KJob::NoError: 0066 msg = i18np("Removed 1 old message from folder %2.", "Removed %1 old messages from folder %2.", mRemovedMsgs.count(), mSourceFolderName); 0067 break; 0068 0069 case Akonadi::Job::UserCanceled: 0070 msg = i18n("Removing old messages from folder %1 was canceled.", mSourceFolderName); 0071 break; 0072 0073 default: // any other error 0074 msg = i18n("Removing old messages from folder %1 failed.", mSourceFolderName); 0075 break; 0076 } 0077 0078 // TODO cancel all job when user cancel it. 0079 // Return when we have an error. 0080 0081 mRunningJobs.removeOne(job); 0082 if (mRunningJobs.isEmpty()) { 0083 finished(); 0084 } 0085 BroadcastStatus::instance()->setStatusMsg(msg); 0086 } 0087 0088 QString ExpireDeleteJob::sourceFolderName() const 0089 { 0090 return mSourceFolderName; 0091 } 0092 0093 void ExpireDeleteJob::setSourceFolderName(const QString &newSourceFolderName) 0094 { 0095 mSourceFolderName = newSourceFolderName; 0096 } 0097 0098 void ExpireDeleteJob::finished() 0099 { 0100 Q_EMIT expireDeleteDone(); 0101 deleteLater(); 0102 } 0103 0104 #include "moc_expiredeletejob.cpp"