Mailcommon

collectionexpiryjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2020-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "collectionexpiryjob.h"
8 #include "mailcommon_debug.h"
9 #include "util/mailutil.h"
10 
11 #include <Akonadi/CollectionModifyJob>
12 
13 using namespace MailCommon;
14 
15 CollectionExpiryJob::CollectionExpiryJob(QObject *parent)
16  : QObject(parent)
17 {
18 }
19 
20 CollectionExpiryJob::~CollectionExpiryJob() = default;
21 
23 {
24  if (mCollection.isValid()) {
25  auto job = new Akonadi::CollectionModifyJob(mCollection, this);
26  connect(job, &Akonadi::CollectionModifyJob::result, this, &CollectionExpiryJob::slotCollectionModified);
27  } else {
28  qCWarning(MAILCOMMON_LOG) << "Collection is not valid";
29  deleteLater();
30  }
31 }
32 
33 void CollectionExpiryJob::setCollection(const Akonadi::Collection &collection)
34 {
35  mCollection = collection;
36 }
37 
38 void CollectionExpiryJob::setExpireNow(bool expireNow)
39 {
40  mExpireNow = expireNow;
41 }
42 
43 void CollectionExpiryJob::slotCollectionModified(KJob *job)
44 {
45  if (job->error()) {
46  qCWarning(MAILCOMMON_LOG) << " Error when we modified collection";
47  deleteLater();
48  return;
49  }
50 
51  // trigger immediate expiry if there is something to do
52  if (mExpireNow) {
53  auto modifiedJob = qobject_cast<Akonadi::CollectionModifyJob *>(job);
54  if (modifiedJob) {
55  MailCommon::Util::expireOldMessages(modifiedJob->collection(), true /*immediate*/);
56  } else {
57  qCWarning(MAILCOMMON_LOG) << " invalid pointer";
58  }
59  }
60  deleteLater();
61 }
void result(KJob *job)
Q_SCRIPTABLE Q_NOREPLY void start()
int error() const
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.