File indexing completed on 2024-06-23 05:18:24

0001 /*
0002  * This file is part of KMail.
0003  * SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #pragma once
0009 
0010 #include "messagecomposer_export.h"
0011 
0012 #include <QAbstractItemModel>
0013 
0014 #include <QUrl>
0015 
0016 #include <Akonadi/Item>
0017 #include <MessageCore/AttachmentPart>
0018 
0019 namespace MessageComposer
0020 {
0021 /**
0022  * @brief The AttachmentModel class
0023  */
0024 class MESSAGECOMPOSER_EXPORT AttachmentModel : public QAbstractItemModel
0025 {
0026     Q_OBJECT
0027 
0028 public:
0029     enum {
0030         AttachmentPartRole = Qt::UserRole,
0031         NameRole,
0032         SizeRole,
0033         EncodingRole,
0034         MimeTypeRole,
0035         CompressRole,
0036         EncryptRole,
0037         SignRole,
0038         AutoDisplayRole,
0039     };
0040 
0041     /**
0042      * @todo: get rid of columns and use the roles instead.
0043      */
0044     enum Column {
0045         NameColumn,
0046         SizeColumn,
0047         EncodingColumn,
0048         MimeTypeColumn,
0049         CompressColumn,
0050         EncryptColumn,
0051         SignColumn,
0052         AutoDisplayColumn,
0053         LastColumn, ///< @internal
0054     };
0055 
0056     explicit AttachmentModel(QObject *parent);
0057     ~AttachmentModel() override;
0058 
0059     bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
0060     [[nodiscard]] QMimeData *mimeData(const QModelIndexList &indexes) const override;
0061     [[nodiscard]] QStringList mimeTypes() const override;
0062     [[nodiscard]] Qt::DropActions supportedDropActions() const override;
0063 
0064     /// for the save/discard warning
0065     [[nodiscard]] bool isModified() const;
0066     void setModified(bool modified);
0067 
0068     [[nodiscard]] bool isEncryptEnabled() const;
0069     void setEncryptEnabled(bool enabled);
0070     [[nodiscard]] bool isSignEnabled() const;
0071     void setSignEnabled(bool enabled);
0072     [[nodiscard]] bool isEncryptSelected() const;
0073     /// sets for all
0074     void setEncryptSelected(bool selected);
0075     [[nodiscard]] bool isSignSelected() const;
0076     /// sets for all
0077     void setSignSelected(bool selected);
0078 
0079     [[nodiscard]] bool isAutoDisplayEnabled() const;
0080     void setAutoDisplayEnabled(bool enabled);
0081 
0082     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
0083     [[nodiscard]] bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
0084 
0085     void addAttachment(const MessageCore::AttachmentPart::Ptr &part);
0086     bool updateAttachment(const MessageCore::AttachmentPart::Ptr &part);
0087     [[nodiscard]] bool replaceAttachment(const MessageCore::AttachmentPart::Ptr &oldPart, const MessageCore::AttachmentPart::Ptr &newPart);
0088     [[nodiscard]] bool removeAttachment(const MessageCore::AttachmentPart::Ptr &part);
0089     [[nodiscard]] MessageCore::AttachmentPart::List attachments() const;
0090 
0091     [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
0092     [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0093     [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
0094     [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
0095     [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0096     [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
0097 
0098 Q_SIGNALS:
0099     void encryptEnabled(bool enabled);
0100     void signEnabled(bool enabled);
0101     void autoDisplayEnabled(bool enabled);
0102     void attachUrlsRequested(const QList<QUrl> &urls);
0103     void attachItemsRequester(const Akonadi::Item::List &);
0104     void attachmentRemoved(MessageCore::AttachmentPart::Ptr part);
0105     void attachmentCompressRequested(MessageCore::AttachmentPart::Ptr part, bool compress);
0106 
0107 private:
0108     class AttachmentModelPrivate;
0109     friend class AttachmentModelPrivate;
0110     std::unique_ptr<AttachmentModelPrivate> const d;
0111 };
0112 } //