File indexing completed on 2024-11-24 04:50:45
0001 /* -*- mode: C++ -*- 0002 This file is part of Akonadi. 0003 SPDX-FileCopyrightText: 2005 Andreas Gungl <a.gungl@gmx.de> 0004 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 0005 SPDX-FileCopyrightText: 2010 Leo Franchi <lfranchi@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 #pragma once 0010 0011 #include <QDebug> 0012 #include <QSet> 0013 0014 class QString; 0015 0016 //--------------------------------------------------------------------------- 0017 /** 0018 @short Akonadi KMime Message Status. 0019 @author Andreas Gungl <a.gungl@gmx.de> 0020 0021 The class encapsulates the handling of the different flags 0022 which describe the status of a message. 0023 The flags themselves are not intended to be used outside this class. 0024 0025 In the status pairs Watched/Ignored and Spam/Ham, there both 0026 values can't be set at the same time, however they can 0027 be unset at the same time. 0028 0029 Note that this class does not sync with the Akonadi storage. It is 0030 used as an in-memory helper when manipulating Akonadi items. 0031 0032 @since 4.6. 0033 */ 0034 class MessageStatus 0035 { 0036 Q_GADGET 0037 Q_PROPERTY(bool isOfUnknownStatus READ isOfUnknownStatus) 0038 Q_PROPERTY(bool isRead READ isRead WRITE setRead) 0039 Q_PROPERTY(bool isDeleted READ isDeleted WRITE setDeleted) 0040 Q_PROPERTY(bool isReplied READ isReplied WRITE setReplied) 0041 Q_PROPERTY(bool isForwarded READ isForwarded WRITE setForwarded) 0042 Q_PROPERTY(bool isQueued READ isQueued WRITE setQueued) 0043 Q_PROPERTY(bool isSent READ isSent WRITE setSent) 0044 Q_PROPERTY(bool isImportant READ isImportant WRITE setImportant) 0045 Q_PROPERTY(bool isWatched READ isWatched WRITE setWatched) 0046 Q_PROPERTY(bool isIgnored READ isIgnored WRITE setIgnored) 0047 Q_PROPERTY(bool isSpam READ isSpam WRITE setSpam) 0048 Q_PROPERTY(bool isHam READ isHam WRITE setHam) 0049 Q_PROPERTY(bool isToAct READ isToAct WRITE setToAct) 0050 Q_PROPERTY(bool hasAttachment READ hasAttachment WRITE setHasAttachment) 0051 Q_PROPERTY(bool hasInvitation READ hasInvitation WRITE setHasInvitation) 0052 Q_PROPERTY(bool isEncrypted READ isEncrypted WRITE setEncrypted) 0053 Q_PROPERTY(bool isSigned READ isSigned WRITE setSigned) 0054 Q_PROPERTY(bool hasError READ hasError WRITE setHasError) 0055 0056 public: 0057 /** Constructor - sets status initially to unknown. */ 0058 MessageStatus(); 0059 0060 /** Compare the status with that from another instance. 0061 @return true if the stati are equal, false if different. 0062 @param other message status to compare with current object 0063 */ 0064 bool operator==(MessageStatus other) const; 0065 0066 /** Compare the status with that from another instance. 0067 @return true if the stati are equal, false if different. 0068 @param other message status to compare with current object 0069 */ 0070 bool operator!=(MessageStatus other) const; 0071 0072 /** Check, if some of the flags in the status match 0073 with those flags from another instance. 0074 @return true if at least one flag is set in both stati. 0075 @param other message status to compare objects' flags 0076 */ 0077 bool operator&(MessageStatus other) const; 0078 0079 /** Clear all status flags, this resets to unknown. */ 0080 void clear(); 0081 0082 /** Set / add stati described by another MessageStatus object. 0083 This can be used to merge in multiple stati at once without 0084 using the single setter methods. 0085 However, internally the setters are used anyway to ensure the 0086 integrity of the resulting status. 0087 @param other message status to set 0088 */ 0089 void set(MessageStatus other); 0090 0091 /** Toggle one or more stati described by another MessageStatus object. 0092 Internally the setters are used to ensure the integrity of the 0093 resulting status. 0094 @param other message status to toggle 0095 */ 0096 void toggle(MessageStatus other); 0097 0098 /* ----- getters ----------------------------------------------------- */ 0099 0100 /** Check for Unknown status. 0101 @return true if status is unknown. 0102 */ 0103 [[nodiscard]] bool isOfUnknownStatus() const; 0104 0105 /** Check for Read status. Note that ignored messages are read. 0106 @return true if status is read. 0107 */ 0108 [[nodiscard]] bool isRead() const; 0109 0110 /** Check for Deleted status. 0111 @return true if status is deleted. 0112 */ 0113 [[nodiscard]] bool isDeleted() const; 0114 0115 /** Check for Replied status. 0116 @return true if status is replied. 0117 */ 0118 [[nodiscard]] bool isReplied() const; 0119 0120 /** Check for Forwarded status. 0121 @return true if status is forwarded. 0122 */ 0123 [[nodiscard]] bool isForwarded() const; 0124 0125 /** Check for Queued status. 0126 @return true if status is queued. 0127 */ 0128 [[nodiscard]] bool isQueued() const; 0129 0130 /** Check for Sent status. 0131 @return true if status is sent. 0132 */ 0133 [[nodiscard]] bool isSent() const; 0134 0135 /** Check for Important status. 0136 @return true if status is important. 0137 */ 0138 [[nodiscard]] bool isImportant() const; 0139 0140 /** Check for Watched status. 0141 @return true if status is watched. 0142 */ 0143 [[nodiscard]] bool isWatched() const; 0144 0145 /** Check for Ignored status. 0146 @return true if status is ignored. 0147 */ 0148 [[nodiscard]] bool isIgnored() const; 0149 0150 /** Check for ToAct status. 0151 @return true if status is action item. 0152 */ 0153 [[nodiscard]] bool isToAct() const; 0154 0155 /** Check for Spam status. 0156 @return true if status is spam. 0157 */ 0158 [[nodiscard]] bool isSpam() const; 0159 0160 /** Check for Ham status. 0161 @return true if status is not spam. 0162 */ 0163 [[nodiscard]] bool isHam() const; 0164 0165 /** Check for Attachment status. 0166 @return true if status indicates an attachment. 0167 */ 0168 [[nodiscard]] bool hasAttachment() const; 0169 0170 /** Check for Invitation status. 0171 @return true if status indicates an invitation. 0172 */ 0173 [[nodiscard]] bool hasInvitation() const; 0174 0175 /** Check for Signed status. 0176 @return true if status is signed. 0177 */ 0178 [[nodiscard]] bool isSigned() const; 0179 0180 /** Check for Encrypted status. 0181 @return true if status is encrypted. 0182 */ 0183 [[nodiscard]] bool isEncrypted() const; 0184 0185 /** Check for error status. 0186 @return true if status indicates an error. 0187 */ 0188 [[nodiscard]] bool hasError() const; 0189 0190 /* ----- setters ----------------------------------------------------- */ 0191 0192 /** 0193 * Set the status to read 0194 * @param read new read status 0195 */ 0196 void setRead(bool read = true); 0197 0198 /** Set the status for deleted. 0199 @param deleted Set (true) or unset (false) this status flag. 0200 */ 0201 void setDeleted(bool deleted = true); 0202 0203 /** Set the status for replied. 0204 @param replied Set (true) or unset (false) this status flag. 0205 */ 0206 void setReplied(bool replied = true); 0207 0208 /** Set the status for forwarded. 0209 @param forwarded Set (true) or unset (false) this status flag. 0210 */ 0211 void setForwarded(bool forwarded = true); 0212 0213 /** Set the status for queued. 0214 @param queued Set (true) or unset (false) this status flag. 0215 */ 0216 void setQueued(bool queued = true); 0217 0218 /** Set the status for sent. 0219 @param sent Set (true) or unset (false) this status flag. 0220 */ 0221 void setSent(bool sent = true); 0222 0223 /** Set the status for important. 0224 @param important Set (true) or unset (false) this status flag. 0225 */ 0226 void setImportant(bool important = true); 0227 0228 /** Set the status to watched. 0229 @param watched Set (true) or unset (false) this status flag. 0230 */ 0231 void setWatched(bool watched = true); 0232 0233 /** Set the status to ignored. 0234 @param ignored Set (true) or unset (false) this status flag. 0235 */ 0236 void setIgnored(bool ignored = true); 0237 0238 /** Set the status to action item. 0239 @param toAct Set (true) or unset (false) this status flag. 0240 */ 0241 void setToAct(bool toAct = true); 0242 0243 /** Set the status to spam. 0244 @param spam Set (true) or unset (false) this status flag. 0245 */ 0246 void setSpam(bool spam = true); 0247 0248 /** Set the status to not spam. 0249 @param ham Set (true) or unset (false) this status flag. 0250 */ 0251 void setHam(bool ham = true); 0252 0253 /** Set the status for an attachment. 0254 @param hasAttachment Set (true) or unset (false) this status flag. 0255 */ 0256 void setHasAttachment(bool hasAttachment = true); 0257 0258 /** Set the status for an invitation. 0259 @param hasInvitation Set (true) or unset (false) this status flag. 0260 */ 0261 void setHasInvitation(bool hasInvitation = true); 0262 0263 /** Set the status to signed. 0264 @param value Set (true) or unset (false) this status flag. 0265 */ 0266 void setSigned(bool value = true); 0267 0268 /** Set the status to encrypted. 0269 @param value Set (true) or unset (false) this status flag. 0270 */ 0271 void setEncrypted(bool value = true); 0272 0273 /** Set the status to error. 0274 @param value Set (true) or unset (false) this status flag. 0275 */ 0276 void setHasError(bool value = true); 0277 0278 /* ----- state representation --------------------------------------- */ 0279 0280 /** Get the status as a whole e.g. for storage in an index. 0281 D on't manipulte the *index via this value, this bypasses 0282 all integrity checks in the setter methods. 0283 @return The status encoded in bits. 0284 */ 0285 [[nodiscard]] qint32 toQInt32() const; 0286 0287 /** Set the status as a whole e.g. for reading from an index. 0288 Don't manipulte the index via this value, this bypasses 0289 all integrity checks in the setter methods. 0290 @param status The status encoded in bits to be set in this instance. 0291 */ 0292 void fromQInt32(qint32 status); 0293 0294 /** Convert the status to a string representation. 0295 @return A string containing coded uppercase letters 0296 which describe the status. 0297 0298 @note This code is legacy for the KMail1 indexes 0299 */ 0300 [[nodiscard]] QString statusStr() const; 0301 0302 /** Set the status based on a string representation. 0303 @param aStr The status string to be analyzed. 0304 Normally it is a string obtained using 0305 getStatusStr(). 0306 0307 @note This code is legacy for the KMail1 indexes 0308 */ 0309 void setStatusFromStr(const QString &aStr); 0310 0311 /** Get the status as a whole e.g. for storage as IMAP flags. 0312 @return The status encoded in flags. 0313 */ 0314 [[nodiscard]] QSet<QByteArray> statusFlags() const; 0315 0316 /** Set the status as a whole e.g. for reading from IMAP flags. 0317 @param flags set of flags for status as a whole 0318 */ 0319 void setStatusFromFlags(const QSet<QByteArray> &flags); 0320 0321 /* ----- static accessors to simple states --------------------------- */ 0322 0323 /** Return a special status that expresses Unread. 0324 This status can only be used for comparison with other states. 0325 */ 0326 static const MessageStatus statusUnread(); 0327 0328 /** Return a predefined status initialized as Read as is useful 0329 e.g. when providing a state for comparison. 0330 @return A reference to a status instance initialized as Read. 0331 */ 0332 static const MessageStatus statusRead(); 0333 0334 /** Return a predefined status initialized as Deleted as is useful 0335 e.g. when providing a state for comparison. 0336 @return A reference to a status instance initialized as Deleted. 0337 */ 0338 static const MessageStatus statusDeleted(); 0339 0340 /** Return a predefined status initialized as Replied as is useful 0341 e.g. when providing a state for comparison. 0342 @return A reference to a status instance initialized as Replied. 0343 */ 0344 static const MessageStatus statusReplied(); 0345 0346 /** Return a predefined status initialized as Forwarded as is useful 0347 e.g. when providing a state for comparison. 0348 @return A reference to a status instance initialized as Forwarded. 0349 */ 0350 static const MessageStatus statusForwarded(); 0351 0352 /** Return a predefined status initialized as Queued as is useful 0353 e.g. when providing a state for comparison. 0354 @return A reference to a status instance initialized as Queued. 0355 */ 0356 static const MessageStatus statusQueued(); 0357 0358 /** Return a predefined status initialized as Sent as is useful 0359 e.g. when providing a state for comparison. 0360 @return A reference to a status instance initialized as Sent. 0361 */ 0362 static const MessageStatus statusSent(); 0363 0364 /** Return a predefined status initialized as Important as is useful 0365 e.g. when providing a state for comparison. 0366 @return A reference to a status instance initialized as Important. 0367 */ 0368 static const MessageStatus statusImportant(); 0369 0370 /** Return a predefined status initialized as Watched as is useful 0371 e.g. when providing a state for comparison. 0372 @return A reference to a status instance initialized as Watched. 0373 */ 0374 static const MessageStatus statusWatched(); 0375 0376 /** Return a predefined status initialized as Ignored as is useful 0377 e.g. when providing a state for comparison. 0378 @return A reference to a status instance initialized as Ignored. 0379 */ 0380 static const MessageStatus statusIgnored(); 0381 0382 /** Return a predefined status initialized as Action Item as is useful 0383 e.g. when providing a state for comparison. 0384 @return A reference to a status instance initialized as ToAct. 0385 */ 0386 static const MessageStatus statusToAct(); 0387 0388 /** Return a predefined status initialized as Spam as is useful 0389 e.g. when providing a state for comparison. 0390 @return A reference to a status instance initialized as Spam. 0391 */ 0392 static const MessageStatus statusSpam(); 0393 0394 /** Return a predefined status initialized as Ham as is useful 0395 e.g. when providing a state for comparison. 0396 @return A reference to a status instance initialized as Ham. 0397 */ 0398 static const MessageStatus statusHam(); 0399 0400 /** Return a predefined status initialized as Attachment as is useful 0401 e.g. when providing a state for comparison. 0402 @return A reference to a status instance initialized as Attachment. 0403 */ 0404 static const MessageStatus statusHasAttachment(); 0405 0406 /** Return a predefined status initialized as Invitation as is useful 0407 e.g. when providing a state for comparison. 0408 @return A reference to a status instance initialized as Invitation. 0409 */ 0410 static const MessageStatus statusHasInvitation(); 0411 0412 /** Return a predefined status initialized as Signed as is useful 0413 e.g. when providing a state for comparison. 0414 @return A reference to a status instance initialized as Signed. 0415 */ 0416 static const MessageStatus statusSigned(); 0417 0418 /** Return a predefined status initialized as Encrypted as is useful 0419 e.g. when providing a state for comparison. 0420 @return A reference to a status instance initialized as Encrypted. 0421 */ 0422 static const MessageStatus statusEncrypted(); 0423 0424 /** Return a predefined status initialized as Error as is useful 0425 e.g. when providing a state for comparison. 0426 @return A reference to a status instance initialized as Error. 0427 */ 0428 static const MessageStatus statusHasError(); 0429 0430 private: 0431 quint32 mStatus; 0432 }; 0433 0434 QDebug operator<<(QDebug d, const MessageStatus &t);