Akonadi Mime

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

KDE's Doxygen guidelines are available online.