File indexing completed on 2024-12-22 05:05:18
0001 // SPDX-FileCopyrightText: 2016 Sandro Knauß <knauss@kolabsys.com> 0002 // SPDX-FileCopyCopyright: 2017 Christian Mollekopf <mollekopf@kolabsys.com> 0003 // SPDX-License-Identifier: LGPL-2.0-or-later 0004 0005 #pragma once 0006 0007 #include "mimetreeparser_core_export.h" 0008 #include "objecttreeparser.h" 0009 #include <QAbstractTableModel> 0010 #include <QModelIndex> 0011 0012 #include <memory> 0013 0014 namespace MimeTreeParser 0015 { 0016 class ObjectTreeParser; 0017 } 0018 class AttachmentModelPrivate; 0019 0020 class MIMETREEPARSER_CORE_EXPORT AttachmentModel : public QAbstractTableModel 0021 { 0022 Q_OBJECT 0023 public: 0024 AttachmentModel(std::shared_ptr<MimeTreeParser::ObjectTreeParser> parser); 0025 ~AttachmentModel(); 0026 0027 public: 0028 enum Roles { 0029 TypeRole = Qt::UserRole + 1, 0030 IconRole, 0031 NameRole, 0032 SizeRole, 0033 IsEncryptedRole, 0034 IsSignedRole, 0035 AttachmentPartRole, 0036 }; 0037 0038 enum Columns { 0039 NameColumn = 0, 0040 SizeColumn, 0041 IsEncryptedColumn, 0042 IsSignedColumn, 0043 ColumnCount, 0044 }; 0045 0046 QHash<int, QByteArray> roleNames() const override; 0047 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0048 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0049 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0050 int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0051 0052 Q_INVOKABLE bool openAttachment(const int row); 0053 Q_INVOKABLE bool importPublicKey(const int row); 0054 0055 bool openAttachment(const MimeTreeParser::MessagePart::Ptr &message); 0056 bool importPublicKey(const MimeTreeParser::MessagePart::Ptr &message); 0057 0058 Q_INVOKABLE QString saveAttachmentToPath(const int row, const QString &path); 0059 QString saveAttachmentToPath(const MimeTreeParser::MessagePart::Ptr &part, const QString &path); 0060 0061 Q_SIGNALS: 0062 void info(const QString &message); 0063 void errorOccurred(const QString &message); 0064 0065 private: 0066 std::unique_ptr<AttachmentModelPrivate> d; 0067 };