Akonadi Mime

messagestatus.cpp
1/*
2 This file is part of Akonadi.
3 SPDX-FileCopyrightText: 2003 Andreas Gungl <a.gungl@gmx.de>
4 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "messagestatus.h"
11
12#include "messageflags.h"
13
14#include <QString>
15
16/** The message status format. These can be or'd together.
17 Note, that the StatusIgnored implies the
18 status to be Read.
19 This is done in isRead() and related getters.
20 So we can preserve the state when switching a
21 thread to Ignored and back. */
22enum Status {
23 StatusUnknown = 0x00000000,
24 StatusUnread = 0x00000002, // deprecated
25 StatusRead = 0x00000004,
26 StatusDeleted = 0x00000010,
27 StatusReplied = 0x00000020,
28 StatusForwarded = 0x00000040,
29 StatusQueued = 0x00000080,
30 StatusSent = 0x00000100,
31 StatusFlag = 0x00000200, // flag means important
32 StatusWatched = 0x00000400,
33 StatusIgnored = 0x00000800, // forces isRead()
34 StatusToAct = 0x00001000,
35 StatusSpam = 0x00002000,
36 StatusHam = 0x00004000,
37 StatusHasAttachment = 0x00008000,
38 StatusHasInvitation = 0x00010000,
39 StatusSigned = 0x00020000,
40 StatusEncrypted = 0x00040000,
41 StatusHasError = 0x00080000
42};
43
45{
46 mStatus = StatusUnknown;
47}
48
50{
51 return mStatus == other.mStatus;
52}
53
55{
56 return mStatus != other.mStatus;
57}
58
60{
61 if (mStatus == StatusUnread) {
62 return !(other.mStatus & StatusRead);
63 }
64
65 if (other.mStatus == StatusUnread) {
66 return !(mStatus & StatusRead);
67 }
68
69 return mStatus & other.mStatus;
70}
71
73{
74 mStatus = StatusUnknown;
75}
76
78{
79 Q_ASSERT(!(other.mStatus & StatusUnread));
80
81 // Those stati are exclusive, but we have to lock at the
82 // internal representation because Ignored can manipulate
83 // the result of the getter methods.
84 if (other.mStatus & StatusRead) {
85 setRead();
86 }
87 if (other.isDeleted()) {
88 setDeleted();
89 }
90 if (other.isReplied()) {
91 setReplied();
92 }
93 if (other.isForwarded()) {
94 setForwarded();
95 }
96 if (other.isQueued()) {
97 setQueued();
98 }
99 if (other.isSent()) {
100 setSent();
101 }
102 if (other.isImportant()) {
103 setImportant();
104 }
105
106 if (other.isWatched()) {
107 setWatched();
108 }
109 if (other.isIgnored()) {
110 setIgnored();
111 }
112 if (other.isToAct()) {
113 setToAct();
114 }
115 if (other.isSpam()) {
116 setSpam();
117 }
118 if (other.isHam()) {
119 setHam();
120 }
121 if (other.hasAttachment()) {
122 setHasAttachment();
123 }
124 if (other.hasInvitation()) {
125 setHasInvitation();
126 }
127 if (other.isSigned()) {
128 setSigned();
129 }
130 if (other.isEncrypted()) {
131 setEncrypted();
132 }
133 if (other.hasError()) {
134 setHasError();
135 }
136}
137
139{
140 Q_ASSERT(!(other.mStatus & StatusUnread));
141
142 if (other.isDeleted()) {
143 setDeleted(!(mStatus & StatusDeleted));
144 }
145 if (other.isReplied()) {
146 setReplied(!(mStatus & StatusReplied));
147 }
148 if (other.isForwarded()) {
149 setForwarded(!(mStatus & StatusForwarded));
150 }
151 if (other.isQueued()) {
152 setQueued(!(mStatus & StatusQueued));
153 }
154 if (other.isSent()) {
155 setSent(!(mStatus & StatusSent));
156 }
157 if (other.isImportant()) {
158 setImportant(!(mStatus & StatusFlag));
159 }
160
161 if (other.isWatched()) {
162 setWatched(!(mStatus & StatusWatched));
163 }
164 if (other.isIgnored()) {
165 setIgnored(!(mStatus & StatusIgnored));
166 }
167 if (other.isToAct()) {
168 setToAct(!(mStatus & StatusToAct));
169 }
170 if (other.isSpam()) {
171 setSpam(!(mStatus & StatusSpam));
172 }
173 if (other.isHam()) {
174 setHam(!(mStatus & StatusHam));
175 }
176 if (other.hasAttachment()) {
177 setHasAttachment(!(mStatus & StatusHasAttachment));
178 }
179 if (other.hasInvitation()) {
180 setHasInvitation(!(mStatus & StatusHasInvitation));
181 }
182 if (other.isSigned()) {
183 setSigned(!(mStatus & StatusSigned));
184 }
185 if (other.isEncrypted()) {
186 setEncrypted(!(mStatus & StatusEncrypted));
187 }
188 if (other.hasError()) {
189 setHasError(!(mStatus & StatusHasError));
190 }
191}
192
193bool Akonadi::MessageStatus::isOfUnknownStatus() const
194{
195 return mStatus == StatusUnknown;
196}
197
198bool Akonadi::MessageStatus::isRead() const
199{
200 return (mStatus & StatusRead) || (mStatus & StatusIgnored);
201}
202
203bool Akonadi::MessageStatus::isDeleted() const
204{
205 return mStatus & StatusDeleted;
206}
207
208bool Akonadi::MessageStatus::isReplied() const
209{
210 return mStatus & StatusReplied;
211}
212
213bool Akonadi::MessageStatus::isForwarded() const
214{
215 return mStatus & StatusForwarded;
216}
217
218bool Akonadi::MessageStatus::isQueued() const
219{
220 return mStatus & StatusQueued;
221}
222
223bool Akonadi::MessageStatus::isSent() const
224{
225 return mStatus & StatusSent;
226}
227
228bool Akonadi::MessageStatus::isImportant() const
229{
230 return mStatus & StatusFlag;
231}
232
233bool Akonadi::MessageStatus::isWatched() const
234{
235 return mStatus & StatusWatched;
236}
237
238bool Akonadi::MessageStatus::isIgnored() const
239{
240 return mStatus & StatusIgnored;
241}
242
243bool Akonadi::MessageStatus::isToAct() const
244{
245 return mStatus & StatusToAct;
246}
247
248bool Akonadi::MessageStatus::isSpam() const
249{
250 return mStatus & StatusSpam;
251}
252
253bool Akonadi::MessageStatus::isHam() const
254{
255 return mStatus & StatusHam;
256}
257
258bool Akonadi::MessageStatus::hasAttachment() const
259{
260 return mStatus & StatusHasAttachment;
261}
262
263bool Akonadi::MessageStatus::hasInvitation() const
264{
265 return mStatus & StatusHasInvitation;
266}
267
268bool Akonadi::MessageStatus::isSigned() const
269{
270 return mStatus & StatusSigned;
271}
272
273bool Akonadi::MessageStatus::isEncrypted() const
274{
275 return mStatus & StatusEncrypted;
276}
277
278bool Akonadi::MessageStatus::hasError() const
279{
280 return mStatus & StatusHasError;
281}
282
284{
285 if (read) {
286 mStatus |= StatusRead;
287 } else {
288 mStatus &= ~StatusRead;
289 }
290}
291
293{
294 if (deleted) {
295 mStatus |= StatusDeleted;
296 } else {
297 mStatus &= ~StatusDeleted;
298 }
299}
300
302{
303 if (replied) {
304 mStatus |= StatusReplied;
305 } else {
306 mStatus &= ~StatusReplied;
307 }
308}
309
311{
312 if (forwarded) {
313 mStatus |= StatusForwarded;
314 } else {
315 mStatus &= ~StatusForwarded;
316 }
317}
318
320{
321 if (queued) {
322 mStatus |= StatusQueued;
323 } else {
324 mStatus &= ~StatusQueued;
325 }
326}
327
329{
330 if (sent) {
331 mStatus &= ~StatusQueued;
332 mStatus |= StatusSent;
333 } else {
334 mStatus &= ~StatusSent;
335 }
336}
337
339{
340 if (important) {
341 mStatus |= StatusFlag;
342 } else {
343 mStatus &= ~StatusFlag;
344 }
345}
346
347// Watched and ignored are mutually exclusive
349{
350 if (watched) {
351 mStatus &= ~StatusIgnored;
352 mStatus |= StatusWatched;
353 } else {
354 mStatus &= ~StatusWatched;
355 }
356}
357
359{
360 if (ignored) {
361 mStatus &= ~StatusWatched;
362 mStatus |= StatusIgnored;
363 } else {
364 mStatus &= ~StatusIgnored;
365 }
366}
367
369{
370 if (toAct) {
371 mStatus |= StatusToAct;
372 } else {
373 mStatus &= ~StatusToAct;
374 }
375}
376
377// Ham and Spam are mutually exclusive
379{
380 if (spam) {
381 mStatus &= ~StatusHam;
382 mStatus |= StatusSpam;
383 } else {
384 mStatus &= ~StatusSpam;
385 }
386}
387
389{
390 if (ham) {
391 mStatus &= ~StatusSpam;
392 mStatus |= StatusHam;
393 } else {
394 mStatus &= ~StatusHam;
395 }
396}
397
399{
400 if (withAttachment) {
401 mStatus |= StatusHasAttachment;
402 } else {
403 mStatus &= ~StatusHasAttachment;
404 }
405}
406
408{
409 if (withInvitation) {
410 mStatus |= StatusHasInvitation;
411 } else {
412 mStatus &= ~StatusHasInvitation;
413 }
414}
415
417{
418 if (value) {
419 mStatus |= StatusSigned;
420 } else {
421 mStatus &= ~StatusSigned;
422 }
423}
424
426{
427 if (value) {
428 mStatus |= StatusEncrypted;
429 } else {
430 mStatus &= ~StatusEncrypted;
431 }
432}
433
435{
436 if (hasError) {
437 mStatus |= StatusHasError;
438 } else {
439 mStatus &= ~StatusHasError;
440 }
441}
442
444{
445 return mStatus;
446}
447
449{
450 mStatus = status;
451}
452
454{
455 QByteArray sstr;
456 if (mStatus & StatusRead) {
457 sstr += 'R';
458 } else {
459 sstr += 'U';
460 }
461 if (mStatus & StatusDeleted) {
462 sstr += 'D';
463 }
464 if (mStatus & StatusReplied) {
465 sstr += 'A';
466 }
467 if (mStatus & StatusForwarded) {
468 sstr += 'F';
469 }
470 if (mStatus & StatusQueued) {
471 sstr += 'Q';
472 }
473 if (mStatus & StatusToAct) {
474 sstr += 'K';
475 }
476 if (mStatus & StatusSent) {
477 sstr += 'S';
478 }
479 if (mStatus & StatusFlag) {
480 sstr += 'G';
481 }
482 if (mStatus & StatusWatched) {
483 sstr += 'W';
484 }
485 if (mStatus & StatusIgnored) {
486 sstr += 'I';
487 }
488 if (mStatus & StatusSpam) {
489 sstr += 'P';
490 }
491 if (mStatus & StatusHam) {
492 sstr += 'H';
493 }
494 if (mStatus & StatusHasAttachment) {
495 sstr += 'T';
496 }
497
498 return QLatin1StringView(sstr);
499}
500
502{
503 mStatus = StatusUnknown;
504
505 if (aStr.contains(QLatin1Char('U'))) {
506 setRead(false);
507 }
508 if (aStr.contains(QLatin1Char('R'))) {
509 setRead();
510 }
511 if (aStr.contains(QLatin1Char('D'))) {
512 setDeleted();
513 }
514 if (aStr.contains(QLatin1Char('A'))) {
515 setReplied();
516 }
517 if (aStr.contains(QLatin1Char('F'))) {
518 setForwarded();
519 }
520 if (aStr.contains(QLatin1Char('Q'))) {
521 setQueued();
522 }
523 if (aStr.contains(QLatin1Char('K'))) {
524 setToAct();
525 }
526 if (aStr.contains(QLatin1Char('S'))) {
527 setSent();
528 }
529 if (aStr.contains(QLatin1Char('G'))) {
530 setImportant();
531 }
532 if (aStr.contains(QLatin1Char('W'))) {
533 setWatched();
534 }
535 if (aStr.contains(QLatin1Char('I'))) {
536 setIgnored();
537 }
538 if (aStr.contains(QLatin1Char('P'))) {
539 setSpam();
540 }
541 if (aStr.contains(QLatin1Char('H'))) {
542 setHam();
543 }
544 if (aStr.contains(QLatin1Char('T'))) {
545 setHasAttachment();
546 }
547 if (aStr.contains(QLatin1Char('C'))) {
548 setHasAttachment(false);
549 }
550}
551
553{
554 QSet<QByteArray> flags;
555
556 if (mStatus & StatusDeleted) {
558 } else {
559 if (mStatus & StatusRead) {
561 }
562 if (mStatus & StatusReplied) {
564 }
565 if (mStatus & StatusFlag) {
567 }
568
569 // non standard flags
570 if (mStatus & StatusSent) {
572 }
573 if (mStatus & StatusQueued) {
575 }
576 if (mStatus & StatusReplied) {
578 }
579 if (mStatus & StatusForwarded) {
581 }
582 if (mStatus & StatusToAct) {
584 }
585 if (mStatus & StatusWatched) {
587 }
588 if (mStatus & StatusIgnored) {
590 }
591 if (mStatus & StatusHasAttachment) {
593 }
594 if (mStatus & StatusHasInvitation) {
596 }
597 if (mStatus & StatusSigned) {
599 }
600 if (mStatus & StatusEncrypted) {
602 }
603 if (mStatus & StatusSpam) {
605 }
606 if (mStatus & StatusHam) {
608 }
609 if (mStatus & StatusHasError) {
611 }
612 }
613
614 return flags;
615}
616
618{
619 mStatus = StatusUnknown;
620
621 for (const QByteArray &flag : flags) {
622 const QByteArray &upperedFlag = flag.toUpper();
623 if (upperedFlag == Akonadi::MessageFlags::Deleted) {
624 setDeleted();
625 } else if (upperedFlag == Akonadi::MessageFlags::Seen) {
626 setRead();
627 } else if (upperedFlag == Akonadi::MessageFlags::Answered) {
628 setReplied();
629 } else if (upperedFlag == Akonadi::MessageFlags::Flagged) {
630 setImportant();
631
632 // non standard flags
633 } else if (upperedFlag == Akonadi::MessageFlags::Sent) {
634 setSent();
635 } else if (upperedFlag == Akonadi::MessageFlags::Queued) {
636 setQueued();
637 } else if (upperedFlag == Akonadi::MessageFlags::Replied) {
638 setReplied();
639 } else if (upperedFlag == Akonadi::MessageFlags::Forwarded) {
640 setForwarded();
641 } else if (upperedFlag == Akonadi::MessageFlags::ToAct) {
642 setToAct();
643 } else if (upperedFlag == Akonadi::MessageFlags::Watched) {
644 setWatched();
645 } else if (upperedFlag == Akonadi::MessageFlags::Ignored) {
646 setIgnored();
647 } else if (upperedFlag == Akonadi::MessageFlags::HasAttachment) {
648 setHasAttachment();
649 } else if (upperedFlag == Akonadi::MessageFlags::HasInvitation) {
650 setHasInvitation();
651 } else if (upperedFlag == Akonadi::MessageFlags::Signed) {
652 setSigned();
653 } else if (upperedFlag == Akonadi::MessageFlags::Encrypted) {
654 setEncrypted();
655 } else if (upperedFlag == Akonadi::MessageFlags::Spam) {
656 setSpam();
657 } else if (upperedFlag == Akonadi::MessageFlags::Ham) {
658 setHam();
659 } else if (upperedFlag == Akonadi::MessageFlags::HasError) {
660 setHasError();
661 }
662 }
663}
664
666{
668 st.mStatus = StatusUnread;
669 return st;
670}
671
678
685
692
699
706
713
720
727
734
741
748
755
762
769
776
783
790
791QDebug operator<<(QDebug d, const Akonadi::MessageStatus &t)
792{
793 d << "status " << t.statusStr();
794 return d;
795}
796
797#include "moc_messagestatus.cpp"
Akonadi KMime Message Status.
void setQueued(bool queued=true)
Set the status for queued.
void setHam(bool ham=true)
Set the status to not spam.
MessageStatus()
Constructor - sets status initially to unknown.
static const MessageStatus statusRead()
Return a predefined status initialized as Read as is useful e.g.
void fromQInt32(qint32 status)
Set the status as a whole e.g.
QString statusStr() const
Convert the status to a string representation.
void setHasError(bool value=true)
Set the status to error.
static const MessageStatus statusSent()
Return a predefined status initialized as Sent as is useful e.g.
static const MessageStatus statusUnread()
Return a special status that expresses Unread.
static const MessageStatus statusHasAttachment()
Return a predefined status initialized as Attachment as is useful e.g.
static const MessageStatus statusSpam()
Return a predefined status initialized as Spam as is useful e.g.
void setEncrypted(bool value=true)
Set the status to encrypted.
void setRead(bool read=true)
Set the status to read.
qint32 toQInt32() const
Get the status as a whole e.g.
void set(MessageStatus other)
Set / add stati described by another MessageStatus object.
void setHasInvitation(bool hasInvitation=true)
Set the status for an invitation.
static const MessageStatus statusSigned()
Return a predefined status initialized as Signed as is useful e.g.
static const MessageStatus statusHasInvitation()
Return a predefined status initialized as Invitation as is useful e.g.
void setForwarded(bool forwarded=true)
Set the status for forwarded.
static const MessageStatus statusDeleted()
Return a predefined status initialized as Deleted as is useful e.g.
static const MessageStatus statusReplied()
Return a predefined status initialized as Replied as is useful e.g.
void setSigned(bool value=true)
Set the status to signed.
void setSpam(bool spam=true)
Set the status to spam.
void setDeleted(bool deleted=true)
Set the status for deleted.
void setStatusFromFlags(const QSet< QByteArray > &flags)
Set the status as a whole e.g.
static const MessageStatus statusImportant()
Return a predefined status initialized as Important as is useful e.g.
static const MessageStatus statusWatched()
Return a predefined status initialized as Watched as is useful e.g.
void clear()
Clear all status flags, this resets to unknown.
void setIgnored(bool ignored=true)
Set the status to ignored.
void setStatusFromStr(const QString &aStr)
Set the status based on a string representation.
void setToAct(bool toAct=true)
Set the status to action item.
void setSent(bool sent=true)
Set the status for sent.
static const MessageStatus statusForwarded()
Return a predefined status initialized as Forwarded as is useful e.g.
bool operator&(MessageStatus other) const
Check, if some of the flags in the status match with those flags from another instance.
void setReplied(bool replied=true)
Set the status for replied.
void setHasAttachment(bool hasAttachment=true)
Set the status for an attachment.
bool operator!=(MessageStatus other) const
Compare the status with that from another instance.
static const MessageStatus statusToAct()
Return a predefined status initialized as Action Item as is useful e.g.
bool operator==(MessageStatus other) const
Compare the status with that from another instance.
static const MessageStatus statusQueued()
Return a predefined status initialized as Queued as is useful e.g.
void toggle(MessageStatus other)
Toggle one or more stati described by another MessageStatus object.
static const MessageStatus statusIgnored()
Return a predefined status initialized as Ignored as is useful e.g.
static const MessageStatus statusHam()
Return a predefined status initialized as Ham as is useful e.g.
static const MessageStatus statusHasError()
Return a predefined status initialized as Error as is useful e.g.
void setImportant(bool important=true)
Set the status for important.
static const MessageStatus statusEncrypted()
Return a predefined status initialized as Encrypted as is useful e.g.
QSet< QByteArray > statusFlags() const
Get the status as a whole e.g.
void setWatched(bool watched=true)
Set the status to watched.
Q_SCRIPTABLE CaptureState status()
AKONADI_MIME_EXPORT const char HasInvitation[]
The flag for a message being marked as having an invitation.
AKONADI_MIME_EXPORT const char Watched[]
The flag for a message being marked as watched.
AKONADI_MIME_EXPORT const char Ham[]
The flag for a message being marked as ham.
AKONADI_MIME_EXPORT const char Encrypted[]
The flag for a message being marked as encrypted.
AKONADI_MIME_EXPORT const char ToAct[]
The flag for a message being marked as action item to act on.
AKONADI_MIME_EXPORT const char Answered[]
The flag for a message being replied to by the user.
AKONADI_MIME_EXPORT const char Replied[]
The flag for a message being marked as replied.
AKONADI_MIME_EXPORT const char Spam[]
The flag for a message being marked as spam.
AKONADI_MIME_EXPORT const char Seen[]
The flag for a message being seen (i.e.
AKONADI_MIME_EXPORT const char Forwarded[]
The flag for a message being marked as forwarded.
AKONADI_MIME_EXPORT const char Deleted[]
The flag for a message being deleted by the user.
AKONADI_MIME_EXPORT const char HasError[]
The flag for a message being marked with an error.
AKONADI_MIME_EXPORT const char Ignored[]
The flag for a message being marked as ignored.
AKONADI_MIME_EXPORT const char Sent[]
The flag for a message being marked as sent.
AKONADI_MIME_EXPORT const char HasAttachment[]
The flag for a message being marked as having an attachment.
AKONADI_MIME_EXPORT const char Flagged[]
The flag for a message being marked as flagged.
AKONADI_MIME_EXPORT const char Queued[]
The flag for a message being marked as queued.
AKONADI_MIME_EXPORT const char Signed[]
The flag for a message being marked as signed.
QByteArray toUpper() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.