Akonadi Mime

messagestatus.h
1 /* -*- mode: C++ -*-
2  This file is part of Akonadi.
3  SPDX-FileCopyrightText: 2005 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 #pragma once
10 
11 #include <QSet>
12 
13 #include "akonadi-mime_export.h"
14 
15 class QString;
16 
17 namespace Akonadi
18 {
19 //---------------------------------------------------------------------------
20 /**
21  @short Akonadi KMime Message Status.
22  @author Andreas Gungl <[email protected]>
23 
24  The class encapsulates the handling of the different flags
25  which describe the status of a message.
26  The flags themselves are not intended to be used outside this class.
27 
28  In the status pairs Watched/Ignored and Spam/Ham, there both
29  values can't be set at the same time, however they can
30  be unset at the same time.
31 
32  Note that this class does not sync with the Akonadi storage. It is
33  used as an in-memory helper when manipulating Akonadi items.
34 
35  @since 4.6.
36 */
37 class AKONADI_MIME_EXPORT MessageStatus
38 {
39 public:
40  /** Constructor - sets status initially to unknown. */
41  MessageStatus();
42 
43  /** Compare the status with that from another instance.
44  @return true if the stati are equal, false if different.
45  @param other message status to compare with current object
46  */
47  bool operator==(MessageStatus other) const;
48 
49  /** Compare the status with that from another instance.
50  @return true if the stati are equal, false if different.
51  @param other message status to compare with current object
52  */
53  bool operator!=(MessageStatus other) const;
54 
55  /** Check, if some of the flags in the status match
56  with those flags from another instance.
57  @return true if at least one flag is set in both stati.
58  @param other message status to compare objects' flags
59  */
60  bool operator&(MessageStatus other) const;
61 
62  /** Clear all status flags, this resets to unknown. */
63  void clear();
64 
65  /** Set / add stati described by another MessageStatus object.
66  This can be used to merge in multiple stati at once without
67  using the single setter methods.
68  However, internally the setters are used anyway to ensure the
69  integrity of the resulting status.
70  @param other message status to set
71  */
72  void set(MessageStatus other);
73 
74  /** Toggle one or more stati described by another MessageStatus object.
75  Internally the setters are used to ensure the integrity of the
76  resulting status.
77  @param other message status to toggle
78  */
79  void toggle(MessageStatus other);
80 
81  /* ----- getters ----------------------------------------------------- */
82 
83  /** Check for Unknown status.
84  @return true if status is unknown.
85  */
86  Q_REQUIRED_RESULT bool isOfUnknownStatus() const;
87 
88  /** Check for Read status. Note that ignored messages are read.
89  @return true if status is read.
90  */
91  Q_REQUIRED_RESULT bool isRead() const;
92 
93  /** Check for Deleted status.
94  @return true if status is deleted.
95  */
96  Q_REQUIRED_RESULT bool isDeleted() const;
97 
98  /** Check for Replied status.
99  @return true if status is replied.
100  */
101  Q_REQUIRED_RESULT bool isReplied() const;
102 
103  /** Check for Forwarded status.
104  @return true if status is forwarded.
105  */
106  Q_REQUIRED_RESULT bool isForwarded() const;
107 
108  /** Check for Queued status.
109  @return true if status is queued.
110  */
111  Q_REQUIRED_RESULT bool isQueued() const;
112 
113  /** Check for Sent status.
114  @return true if status is sent.
115  */
116  Q_REQUIRED_RESULT bool isSent() const;
117 
118  /** Check for Important status.
119  @return true if status is important.
120  */
121  Q_REQUIRED_RESULT bool isImportant() const;
122 
123  /** Check for Watched status.
124  @return true if status is watched.
125  */
126  Q_REQUIRED_RESULT bool isWatched() const;
127 
128  /** Check for Ignored status.
129  @return true if status is ignored.
130  */
131  Q_REQUIRED_RESULT bool isIgnored() const;
132 
133  /** Check for ToAct status.
134  @return true if status is action item.
135  */
136  Q_REQUIRED_RESULT bool isToAct() const;
137 
138  /** Check for Spam status.
139  @return true if status is spam.
140  */
141  Q_REQUIRED_RESULT bool isSpam() const;
142 
143  /** Check for Ham status.
144  @return true if status is not spam.
145  */
146  Q_REQUIRED_RESULT bool isHam() const;
147 
148  /** Check for Attachment status.
149  @return true if status indicates an attachment.
150  */
151  Q_REQUIRED_RESULT bool hasAttachment() const;
152 
153  /** Check for Invitation status.
154  @return true if status indicates an invitation.
155  */
156  Q_REQUIRED_RESULT bool hasInvitation() const;
157 
158  /** Check for Signed status.
159  @return true if status is signed.
160  */
161  Q_REQUIRED_RESULT bool isSigned() const;
162 
163  /** Check for Encrypted status.
164  @return true if status is encrypted.
165  */
166  Q_REQUIRED_RESULT bool isEncrypted() const;
167 
168  /** Check for error status.
169  @return true if status indicates an error.
170  */
171  Q_REQUIRED_RESULT bool hasError() const;
172 
173  /* ----- setters ----------------------------------------------------- */
174 
175  /**
176  * Set the status to read
177  * @param read new read status
178  */
179  void setRead(bool read = true);
180 
181  /** Set the status for deleted.
182  @param deleted Set (true) or unset (false) this status flag.
183  */
184  void setDeleted(bool deleted = true);
185 
186  /** Set the status for replied.
187  @param replied Set (true) or unset (false) this status flag.
188  */
189  void setReplied(bool replied = true);
190 
191  /** Set the status for forwarded.
192  @param forwarded Set (true) or unset (false) this status flag.
193  */
194  void setForwarded(bool forwarded = true);
195 
196  /** Set the status for queued.
197  @param queued Set (true) or unset (false) this status flag.
198  */
199  void setQueued(bool queued = true);
200 
201  /** Set the status for sent.
202  @param sent Set (true) or unset (false) this status flag.
203  */
204  void setSent(bool sent = true);
205 
206  /** Set the status for important.
207  @param important Set (true) or unset (false) this status flag.
208  */
209  void setImportant(bool important = true);
210 
211  /** Set the status to watched.
212  @param watched Set (true) or unset (false) this status flag.
213  */
214  void setWatched(bool watched = true);
215 
216  /** Set the status to ignored.
217  @param ignored Set (true) or unset (false) this status flag.
218  */
219  void setIgnored(bool ignored = true);
220 
221  /** Set the status to action item.
222  @param toAct Set (true) or unset (false) this status flag.
223  */
224  void setToAct(bool toAct = true);
225 
226  /** Set the status to spam.
227  @param spam Set (true) or unset (false) this status flag.
228  */
229  void setSpam(bool spam = true);
230 
231  /** Set the status to not spam.
232  @param ham Set (true) or unset (false) this status flag.
233  */
234  void setHam(bool ham = true);
235 
236  /** Set the status for an attachment.
237  @param hasAttachment Set (true) or unset (false) this status flag.
238  */
239  void setHasAttachment(bool hasAttachment = true);
240 
241  /** Set the status for an invitation.
242  @param hasInvitation Set (true) or unset (false) this status flag.
243  */
244  void setHasInvitation(bool hasInvitation = true);
245 
246  /** Set the status to signed.
247  @param value Set (true) or unset (false) this status flag.
248  */
249  void setSigned(bool value = true);
250 
251  /** Set the status to encrypted.
252  @param value Set (true) or unset (false) this status flag.
253  */
254  void setEncrypted(bool value = true);
255 
256  /** Set the status to error.
257  @param value Set (true) or unset (false) this status flag.
258  */
259  void setHasError(bool value = true);
260 
261  /* ----- state representation --------------------------------------- */
262 
263  /** Get the status as a whole e.g. for storage in an index.
264  D on't manipulte the *index via this value, this bypasses
265  all integrity checks in the setter methods.
266  @return The status encoded in bits.
267  */
268  Q_REQUIRED_RESULT qint32 toQInt32() const;
269 
270  /** Set the status as a whole e.g. for reading from an index.
271  Don't manipulte the index via this value, this bypasses
272  all integrity checks in the setter methods.
273  @param status The status encoded in bits to be set in this instance.
274  */
275  void fromQInt32(qint32 status);
276 
277  /** Convert the status to a string representation.
278  @return A string containing coded uppercase letters
279  which describe the status.
280 
281  @note This code is legacy for the KMail1 indexes
282  */
283  Q_REQUIRED_RESULT QString statusStr() const;
284 
285  /** Set the status based on a string representation.
286  @param aStr The status string to be analyzed.
287  Normally it is a string obtained using
288  getStatusStr().
289 
290  @note This code is legacy for the KMail1 indexes
291  */
292  void setStatusFromStr(const QString &aStr);
293 
294  /** Get the status as a whole e.g. for storage as IMAP flags.
295  @return The status encoded in flags.
296  */
297  Q_REQUIRED_RESULT QSet<QByteArray> statusFlags() const;
298 
299  /** Set the status as a whole e.g. for reading from IMAP flags.
300  @param flags set of flags for status as a whole
301  */
302  void setStatusFromFlags(const QSet<QByteArray> &flags);
303 
304  /* ----- static accessors to simple states --------------------------- */
305 
306  /** Return a special status that expresses Unread.
307  This status can only be used for comparison with other states.
308  */
309  static const MessageStatus statusUnread();
310 
311  /** Return a predefined status initialized as Read as is useful
312  e.g. when providing a state for comparison.
313  @return A reference to a status instance initialized as Read.
314  */
315  static const MessageStatus statusRead();
316 
317  /** Return a predefined status initialized as Deleted as is useful
318  e.g. when providing a state for comparison.
319  @return A reference to a status instance initialized as Deleted.
320  */
321  static const MessageStatus statusDeleted();
322 
323  /** Return a predefined status initialized as Replied as is useful
324  e.g. when providing a state for comparison.
325  @return A reference to a status instance initialized as Replied.
326  */
327  static const MessageStatus statusReplied();
328 
329  /** Return a predefined status initialized as Forwarded as is useful
330  e.g. when providing a state for comparison.
331  @return A reference to a status instance initialized as Forwarded.
332  */
333  static const MessageStatus statusForwarded();
334 
335  /** Return a predefined status initialized as Queued as is useful
336  e.g. when providing a state for comparison.
337  @return A reference to a status instance initialized as Queued.
338  */
339  static const MessageStatus statusQueued();
340 
341  /** Return a predefined status initialized as Sent as is useful
342  e.g. when providing a state for comparison.
343  @return A reference to a status instance initialized as Sent.
344  */
345  static const MessageStatus statusSent();
346 
347  /** Return a predefined status initialized as Important as is useful
348  e.g. when providing a state for comparison.
349  @return A reference to a status instance initialized as Important.
350  */
351  static const MessageStatus statusImportant();
352 
353  /** Return a predefined status initialized as Watched as is useful
354  e.g. when providing a state for comparison.
355  @return A reference to a status instance initialized as Watched.
356  */
357  static const MessageStatus statusWatched();
358 
359  /** Return a predefined status initialized as Ignored as is useful
360  e.g. when providing a state for comparison.
361  @return A reference to a status instance initialized as Ignored.
362  */
363  static const MessageStatus statusIgnored();
364 
365  /** Return a predefined status initialized as Action Item as is useful
366  e.g. when providing a state for comparison.
367  @return A reference to a status instance initialized as ToAct.
368  */
369  static const MessageStatus statusToAct();
370 
371  /** Return a predefined status initialized as Spam as is useful
372  e.g. when providing a state for comparison.
373  @return A reference to a status instance initialized as Spam.
374  */
375  static const MessageStatus statusSpam();
376 
377  /** Return a predefined status initialized as Ham as is useful
378  e.g. when providing a state for comparison.
379  @return A reference to a status instance initialized as Ham.
380  */
381  static const MessageStatus statusHam();
382 
383  /** Return a predefined status initialized as Attachment as is useful
384  e.g. when providing a state for comparison.
385  @return A reference to a status instance initialized as Attachment.
386  */
387  static const MessageStatus statusHasAttachment();
388 
389  /** Return a predefined status initialized as Invitation as is useful
390  e.g. when providing a state for comparison.
391  @return A reference to a status instance initialized as Invitation.
392  */
393  static const MessageStatus statusHasInvitation();
394 
395  /** Return a predefined status initialized as Signed as is useful
396  e.g. when providing a state for comparison.
397  @return A reference to a status instance initialized as Signed.
398  */
399  static const MessageStatus statusSigned();
400 
401  /** Return a predefined status initialized as Encrypted as is useful
402  e.g. when providing a state for comparison.
403  @return A reference to a status instance initialized as Encrypted.
404  */
405  static const MessageStatus statusEncrypted();
406 
407  /** Return a predefined status initialized as Error as is useful
408  e.g. when providing a state for comparison.
409  @return A reference to a status instance initialized as Error.
410  */
411  static const MessageStatus statusHasError();
412 
413 private:
414  quint32 mStatus;
415 };
416 } // namespace Akonadi
417 
Akonadi KMime Message Status.
Definition: messagestatus.h:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Apr 22 2021 23:09:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.