File indexing completed on 2024-12-15 04:54:38

0001 /******************************************************************************
0002  *
0003  *  SPDX-FileCopyrightText: 2008 Szymon Tomasz Stefanek <pragma@kvirc.net>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  *
0007  *******************************************************************************/
0008 
0009 #pragma once
0010 
0011 #include "core/item.h"
0012 #include "core/modelinvariantindex.h"
0013 
0014 #include "messagelist_export.h"
0015 #include "theme.h"
0016 #include <QColor>
0017 #include <QFont>
0018 #include <QPixmap>
0019 #include <QString>
0020 
0021 namespace Akonadi
0022 {
0023 class Item;
0024 }
0025 
0026 namespace MessageList
0027 {
0028 namespace Core
0029 {
0030 class MessageItemPrivate;
0031 /**
0032  * @brief The MessageItem class
0033  */
0034 class MESSAGELIST_EXPORT MessageItem : public Item, public ModelInvariantIndex
0035 {
0036 public:
0037     class MESSAGELIST_EXPORT Tag
0038     {
0039     public:
0040         explicit Tag(const QPixmap &pix, const QString &tagName, const QString &tagId);
0041         ~Tag();
0042         const QPixmap &pixmap() const;
0043         const QString &name() const;
0044         const QString &id() const;
0045         const QColor &textColor() const;
0046         const QColor &backgroundColor() const;
0047         const QFont &font() const;
0048         int priority() const;
0049 
0050         void setTextColor(const QColor &textColor);
0051         void setBackgroundColor(const QColor &backgroundColor);
0052         void setFont(const QFont &font);
0053         void setPriority(int priority);
0054 
0055     private:
0056         class TagPrivate;
0057         std::unique_ptr<TagPrivate> const d;
0058     };
0059 
0060     enum ThreadingStatus {
0061         PerfectParentFound, ///< this message found a perfect parent to attach to
0062         ImperfectParentFound, ///< this message found an imperfect parent to attach to (might be fixed later)
0063         ParentMissing, ///< this message might belong to a thread but its parent is actually missing
0064         NonThreadable ///< this message does not look as being threadable
0065     };
0066 
0067     enum EncryptionState { NotEncrypted, PartiallyEncrypted, FullyEncrypted, EncryptionStateUnknown };
0068 
0069     enum SignatureState { NotSigned, PartiallySigned, FullySigned, SignatureStateUnknown };
0070 
0071     explicit MessageItem();
0072     ~MessageItem() override;
0073 
0074 public:
0075     /// Returns the list of tags for this item.
0076     virtual QList<Tag *> tagList() const;
0077 
0078     /// Returns true if this message has an annotation.
0079     virtual bool hasAnnotation() const;
0080 
0081     /// Returns the annotation of the message, given that hasAnnotation() is true
0082     [[nodiscard]] QString annotation() const;
0083 
0084     /// Shows a dialog to edit or delete the annotation
0085     void editAnnotation(QWidget *parent);
0086 
0087     /**
0088      * Returns Tag associated to this message that has the specified id or 0
0089      * if no such tag exists. mTagList will be 0 in 99% of the cases.
0090      */
0091     const Tag *findTag(const QString &szTagId) const;
0092 
0093     [[nodiscard]] QString tagListDescription() const;
0094 
0095     /// Deletes all cached tags. The next time someone asks this item for the tags, they are
0096     /// fetched again
0097     void invalidateTagCache();
0098 
0099     /// Same as invalidateTagCache(), only for the annotation
0100     void invalidateAnnotationCache();
0101 
0102     const QColor &textColor() const;
0103 
0104     const QColor &backgroundColor() const;
0105 
0106     [[nodiscard]] bool isBold() const
0107     {
0108         return font().bold();
0109     }
0110 
0111     [[nodiscard]] bool isItalic() const
0112     {
0113         return font().italic();
0114     }
0115 
0116     [[nodiscard]] SignatureState signatureState() const;
0117 
0118     void setSignatureState(SignatureState state);
0119 
0120     [[nodiscard]] EncryptionState encryptionState() const;
0121 
0122     void setEncryptionState(EncryptionState state);
0123 
0124     [[nodiscard]] QByteArray messageIdMD5() const;
0125 
0126     void setMessageIdMD5(const QByteArray &md5);
0127 
0128     [[nodiscard]] QByteArray inReplyToIdMD5() const;
0129 
0130     void setInReplyToIdMD5(const QByteArray &md5);
0131 
0132     [[nodiscard]] QByteArray referencesIdMD5() const;
0133 
0134     void setReferencesIdMD5(const QByteArray &md5);
0135 
0136     void setSubjectIsPrefixed(bool subjectIsPrefixed);
0137 
0138     [[nodiscard]] bool subjectIsPrefixed() const;
0139 
0140     [[nodiscard]] QByteArray strippedSubjectMD5() const;
0141 
0142     void setStrippedSubjectMD5(const QByteArray &md5);
0143 
0144     [[nodiscard]] bool aboutToBeRemoved() const;
0145 
0146     void setAboutToBeRemoved(bool aboutToBeRemoved);
0147 
0148     [[nodiscard]] ThreadingStatus threadingStatus() const;
0149 
0150     void setThreadingStatus(ThreadingStatus threadingStatus);
0151 
0152     [[nodiscard]] unsigned long uniqueId() const;
0153 
0154     Akonadi::Item akonadiItem() const;
0155     void setAkonadiItem(const Akonadi::Item &item);
0156 
0157     MessageItem *topmostMessage();
0158 
0159     QString accessibleText(const MessageList::Core::Theme *theme, int columnIndex);
0160 
0161     /**
0162      * Appends the whole subtree originating at this item
0163      * to the specified list. This item is included!
0164      */
0165     void subTreeToList(QList<MessageItem *> &list);
0166 
0167     //
0168     // Colors and fonts shared by all message items.
0169     // textColor() and font() will take the message status into account and return
0170     // one of these.
0171     // Call these setters only once when reading the colors from the config file.
0172     //
0173     static void setUnreadMessageColor(const QColor &color);
0174     static void setImportantMessageColor(const QColor &color);
0175     static void setToDoMessageColor(const QColor &color);
0176     static void setGeneralFont(const QFont &font);
0177     static void setUnreadMessageFont(const QFont &font);
0178     static void setImportantMessageFont(const QFont &font);
0179     static void setToDoMessageFont(const QFont &font);
0180 
0181 protected:
0182     explicit MessageItem(MessageItemPrivate *dd);
0183 
0184 private:
0185     MESSAGELIST_NO_EXPORT const QFont &font() const;
0186 
0187     MESSAGELIST_NO_EXPORT QString accessibleTextForField(Theme::ContentItem::Type field);
0188 
0189     Q_DECLARE_PRIVATE(MessageItem)
0190 };
0191 
0192 class FakeItemPrivate;
0193 
0194 /// A message item that can have a fake tag list and a fake annotation
0195 class FakeItem : public MessageItem
0196 {
0197 public:
0198     explicit FakeItem();
0199     ~FakeItem() override;
0200 
0201     /// Reimplemented to return the fake tag list
0202     QList<Tag *> tagList() const override;
0203 
0204     /// Sets a list of fake tags for this item
0205     void setFakeTags(const QList<Tag *> &tagList);
0206 
0207     /// Reimplemented to always return true
0208     bool hasAnnotation() const override;
0209 
0210 private:
0211     Q_DECLARE_PRIVATE(FakeItem)
0212 };
0213 } // namespace Core
0214 } // namespace MessageList