Messagelib

markmessagereadhandler.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
3 SPDX-FileContributor: Tobias Koenig <tokoe@kdab.com>
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/MessageFlags>
14#include <Akonadi/Session>
15
16#include <QTimer>
17
18using namespace MessageViewer;
19Q_GLOBAL_STATIC(Akonadi::Item::List, sListItem)
20
21class MarkMessageReadHandler::MarkMessageReadHandlerPrivate
22{
23public:
24 MarkMessageReadHandlerPrivate(MarkMessageReadHandler *qq)
25 : q(qq)
26 {
27 }
28
29 void handleMessages();
30
32 Akonadi::Item mItemQueue;
33 QTimer mTimer;
34};
35
36void 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
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
void setFlag(const QByteArray &name)
A viewer handler to mark viewed messages as read.
void setItem(const Akonadi::Item &item) override
This method is called whenever a message item has been loaded into the view.
MarkMessageReadHandler(QObject *parent=nullptr)
Creates a new mark message read handler.
~MarkMessageReadHandler() override
Destroys the mark message read handler.
AKONADI_MIME_EXPORT const char Seen[]
AKONADI_MIME_EXPORT const char Queued[]
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:26 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.