Messagelib

markmessagereadhandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
3  SPDX-FileContributor: Tobias Koenig <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "markmessagereadhandler.h"
9 
10 #include "settings/messageviewersettings.h"
11 
12 #include <Akonadi/ItemModifyJob>
13 #include <Akonadi/KMime/MessageFlags>
14 #include <Akonadi/Session>
15 
16 #include <QTimer>
17 
18 using namespace MessageViewer;
20 
21 class MarkMessageReadHandler::MarkMessageReadHandlerPrivate
22 {
23 public:
24  MarkMessageReadHandlerPrivate(MarkMessageReadHandler *qq)
25  : q(qq)
26  {
27  }
28 
29  void handleMessages();
30 
31  MarkMessageReadHandler *const q;
32  Akonadi::Item mItemQueue;
33  QTimer mTimer;
34 };
35 
36 void MarkMessageReadHandler::MarkMessageReadHandlerPrivate::handleMessages()
37 {
38  Akonadi::Item item = mItemQueue;
39 
40  // mark as read
42 
43  auto modifyJob = new Akonadi::ItemModifyJob(item, q->session());
44  modifyJob->disableRevisionCheck();
45  modifyJob->setIgnorePayload(true);
46  sListItem->removeAll(item);
47 }
48 
50  : QObject(parent)
51  , d(new MarkMessageReadHandlerPrivate(this))
52 {
53  d->mTimer.setSingleShot(true);
54  connect(&d->mTimer, &QTimer::timeout, this, [this]() {
55  d->handleMessages();
56  });
57 }
58 
60 {
61  if (d->mTimer.isActive()) {
62  d->mTimer.stop();
63  }
64 }
65 
67 {
68  if (MessageViewer::MessageViewerSettings::self()->delayedMarkAsRead()) {
69  if (sListItem->contains(item) || d->mItemQueue == item || item.hasFlag(Akonadi::MessageFlags::Queued)) {
70  return;
71  }
72  if (d->mTimer.isActive()) {
73  d->mTimer.stop();
74  }
76  return;
77  }
78 
79  sListItem->removeAll(d->mItemQueue);
80  d->mItemQueue = item;
81  sListItem->append(item);
82 
83  const int delayedMarkTime = MessageViewer::MessageViewerSettings::self()->delayedMarkTime();
84  if (delayedMarkTime != 0) {
85  d->mTimer.start(delayedMarkTime * 1000);
86  } else {
87  d->handleMessages();
88  }
89  }
90 }
91 
92 #include "moc_markmessagereadhandler.cpp"
bool hasFlag(const QByteArray &name) const
A viewer handler to mark viewed messages as read.
void setFlag(const QByteArray &name)
~MarkMessageReadHandler() override
Destroys the mark message read handler.
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
void setItem(const Akonadi::Item &item) override
This method is called whenever a message item has been loaded into the view.
void timeout()
MarkMessageReadHandler(QObject *parent=nullptr)
Creates a new mark message read handler.
AKONADI_MIME_EXPORT const char Queued[]
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
AKONADI_MIME_EXPORT const char Seen[]
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Dec 6 2021 23:04:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.