Akonadi Mime

messagestatus.cpp
1 /*
2  This file is part of Akonadi.
3  SPDX-FileCopyrightText: 2003 Andreas Gungl <[email protected]>
4  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
5  SPDX-FileCopyrightText: 2010 Leo Franchi <[email protected]>
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 
22 enum 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()) {
123  }
124  if (other.hasInvitation()) {
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 
194 {
195  return mStatus == StatusUnknown;
196 }
197 
199 {
200  return (mStatus & StatusRead) || (mStatus & StatusIgnored);
201 }
202 
204 {
205  return mStatus & StatusDeleted;
206 }
207 
209 {
210  return mStatus & StatusReplied;
211 }
212 
214 {
215  return mStatus & StatusForwarded;
216 }
217 
219 {
220  return mStatus & StatusQueued;
221 }
222 
224 {
225  return mStatus & StatusSent;
226 }
227 
229 {
230  return mStatus & StatusFlag;
231 }
232 
234 {
235  return mStatus & StatusWatched;
236 }
237 
239 {
240  return mStatus & StatusIgnored;
241 }
242 
244 {
245  return mStatus & StatusToAct;
246 }
247 
249 {
250  return mStatus & StatusSpam;
251 }
252 
254 {
255  return mStatus & StatusHam;
256 }
257 
259 {
260  return mStatus & StatusHasAttachment;
261 }
262 
264 {
265  return mStatus & StatusHasInvitation;
266 }
267 
269 {
270  return mStatus & StatusSigned;
271 }
272 
274 {
275  return mStatus & StatusEncrypted;
276 }
277 
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 QLatin1String(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'))) {
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) {
649  } else if (upperedFlag == Akonadi::MessageFlags::HasInvitation) {
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 
673 {
675  st.setRead();
676  return st;
677 }
678 
680 {
682  st.setDeleted();
683  return st;
684 }
685 
687 {
689  st.setReplied();
690  return st;
691 }
692 
694 {
696  st.setForwarded();
697  return st;
698 }
699 
701 {
703  st.setQueued();
704  return st;
705 }
706 
708 {
710  st.setSent();
711  return st;
712 }
713 
715 {
717  st.setImportant();
718  return st;
719 }
720 
722 {
724  st.setWatched();
725  return st;
726 }
727 
729 {
731  st.setIgnored();
732  return st;
733 }
734 
736 {
738  st.setToAct();
739  return st;
740 }
741 
743 {
745  st.setSpam();
746  return st;
747 }
748 
750 {
752  st.setHam();
753  return st;
754 }
755 
757 {
759  st.setHasAttachment();
760  return st;
761 }
762 
764 {
765  MessageStatus st;
766  st.setHasInvitation();
767  return st;
768 }
769 
771 {
772  MessageStatus st;
773  st.setSigned();
774  return st;
775 }
776 
778 {
779  MessageStatus st;
780  st.setEncrypted();
781  return st;
782 }
783 
785 {
786  MessageStatus st;
787  st.setHasError();
788  return st;
789 }
bool isOfUnknownStatus() const
Check for Unknown status.
bool isReplied() const
Check for Replied status.
bool hasError() const
Check for error status.
static const MessageStatus statusEncrypted()
Return a predefined status initialized as Encrypted as is useful e.g.
bool isHam() const
Check for Ham status.
static const MessageStatus statusIgnored()
Return a predefined status initialized as Ignored as is useful e.g.
AKONADI_MIME_EXPORT const char HasError[]
The flag for a message being marked with an error.
void setRead(bool read=true)
Set the status to read.
static const MessageStatus statusWatched()
Return a predefined status initialized as Watched as is useful e.g.
AKONADI_MIME_EXPORT const char Watched[]
The flag for a message being marked as watched.
AKONADI_MIME_EXPORT const char Deleted[]
The flag for a message being deleted by the user.
void setWatched(bool watched=true)
Set the status to watched.
static const MessageStatus statusHasAttachment()
Return a predefined status initialized as Attachment as is useful e.g.
void setHasInvitation(bool hasInvitation=true)
Set the status for an invitation.
qint32 toQInt32() const
Get the status as a whole e.g.
AKONADI_MIME_EXPORT const char Answered[]
The flag for a message being replied to by the user.
bool isSpam() const
Check for Spam status.
QByteArray toUpper() const const
bool isSigned() const
Check for Signed status.
void setSpam(bool spam=true)
Set the status to spam.
void setToAct(bool toAct=true)
Set the status to action item.
void fromQInt32(qint32 status)
Set the status as a whole e.g.
AKONADI_MIME_EXPORT const char Spam[]
The flag for a message being marked as spam.
bool isSent() const
Check for Sent status.
QSet< QByteArray > statusFlags() const
Get the status as a whole e.g.
AKONADI_MIME_EXPORT const char Forwarded[]
The flag for a message being marked as forwarded.
bool isQueued() const
Check for Queued status.
static const MessageStatus statusToAct()
Return a predefined status initialized as Action Item as is useful e.g.
bool hasInvitation() const
Check for Invitation status.
void setImportant(bool important=true)
Set the status for important.
static const MessageStatus statusUnread()
Return a special status that expresses Unread.
bool isIgnored() const
Check for Ignored status.
AKONADI_MIME_EXPORT const char HasAttachment[]
The flag for a message being marked as having an attachment.
void clear()
Clear all status flags, this resets to unknown.
void setHam(bool ham=true)
Set the status to not spam.
void setStatusFromFlags(const QSet< QByteArray > &flags)
Set the status as a whole e.g.
MessageStatus()
Constructor - sets status initially to unknown.
static const MessageStatus statusHasError()
Return a predefined status initialized as Error as is useful e.g.
bool operator==(MessageStatus other) const
Compare the status with that from another instance.
static const MessageStatus statusRead()
Return a predefined status initialized as Read as is useful e.g.
static const MessageStatus statusSent()
Return a predefined status initialized as Sent as is useful e.g.
static const MessageStatus statusSigned()
Return a predefined status initialized as Signed as is useful e.g.
static const MessageStatus statusImportant()
Return a predefined status initialized as Important as is useful e.g.
bool isToAct() const
Check for ToAct status.
void setReplied(bool replied=true)
Set the status for replied.
AKONADI_MIME_EXPORT const char Ignored[]
The flag for a message being marked as ignored.
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.
static const MessageStatus statusHam()
Return a predefined status initialized as Ham as is useful e.g.
bool isWatched() const
Check for Watched status.
void setQueued(bool queued=true)
Set the status for queued.
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
static const MessageStatus statusDeleted()
Return a predefined status initialized as Deleted as is useful e.g.
AKONADI_MIME_EXPORT const char Encrypted[]
The flag for a message being marked as encrypted.
bool isForwarded() const
Check for Forwarded status.
void setSigned(bool value=true)
Set the status to signed.
AKONADI_MIME_EXPORT const char Signed[]
The flag for a message being marked as signed.
bool operator!=(MessageStatus other) const
Compare the status with that from another instance.
static const MessageStatus statusSpam()
Return a predefined status initialized as Spam as is useful e.g.
AKONADI_MIME_EXPORT const char Replied[]
The flag for a message being marked as replied.
bool isDeleted() const
Check for Deleted status.
void setHasError(bool value=true)
Set the status to error.
void setIgnored(bool ignored=true)
Set the status to ignored.
static const MessageStatus statusQueued()
Return a predefined status initialized as Queued as is useful e.g.
AKONADI_MIME_EXPORT const char Queued[]
The flag for a message being marked as queued.
Akonadi KMime Message Status.
Definition: messagestatus.h:38
AKONADI_MIME_EXPORT const char Sent[]
The flag for a message being marked as sent.
static const MessageStatus statusReplied()
Return a predefined status initialized as Replied as is useful e.g.
void setEncrypted(bool value=true)
Set the status to encrypted.
void setHasAttachment(bool hasAttachment=true)
Set the status for an attachment.
AKONADI_MIME_EXPORT const char Ham[]
The flag for a message being marked as ham.
void setStatusFromStr(const QString &aStr)
Set the status based on a string representation.
AKONADI_MIME_EXPORT const char ToAct[]
The flag for a message being marked as action item to act on.
static const MessageStatus statusHasInvitation()
Return a predefined status initialized as Invitation as is useful e.g.
AKONADI_MIME_EXPORT const char HasInvitation[]
The flag for a message being marked as having an invitation.
void toggle(MessageStatus other)
Toggle one or more stati described by another MessageStatus object.
void setDeleted(bool deleted=true)
Set the status for deleted.
bool isEncrypted() const
Check for Encrypted status.
QString statusStr() const
Convert the status to a string representation.
void setForwarded(bool forwarded=true)
Set the status for forwarded.
bool hasAttachment() const
Check for Attachment status.
AKONADI_MIME_EXPORT const char Seen[]
The flag for a message being seen (i.e.
bool isRead() const
Check for Read status.
void set(MessageStatus other)
Set / add stati described by another MessageStatus object.
bool isImportant() const
Check for Important status.
AKONADI_MIME_EXPORT const char Flagged[]
The flag for a message being marked as flagged.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Jan 26 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.