File indexing completed on 2024-05-12 05:28:16

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 <QObject>
0008 
0009 #include <QAbstractItemModel>
0010 #include <QModelIndex>
0011 
0012 #include <memory>
0013 
0014 namespace MimeTreeParser
0015 {
0016 class ObjectTreeParser;
0017 }
0018 class AttachmentModelPrivate;
0019 
0020 class AttachmentModel : public QAbstractItemModel
0021 {
0022     Q_OBJECT
0023 public:
0024     AttachmentModel(std::shared_ptr<MimeTreeParser::ObjectTreeParser> parser);
0025     ~AttachmentModel();
0026 
0027 public:
0028     enum Roles { TypeRole = Qt::UserRole + 1, IconRole, NameRole, SizeRole, IsEncryptedRole, IsSignedRole };
0029 
0030     QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
0031     QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
0032     QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
0033     QModelIndex parent(const QModelIndex &index) const Q_DECL_OVERRIDE;
0034     int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
0035     int columnCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
0036 
0037     Q_INVOKABLE bool saveAttachmentToDisk(const QModelIndex &parent);
0038     Q_INVOKABLE bool openAttachment(const QModelIndex &index);
0039 
0040     Q_INVOKABLE bool importPublicKey(const QModelIndex &index);
0041 
0042 private:
0043     std::unique_ptr<AttachmentModelPrivate> d;
0044 };