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  * Parts based on KMail code by:
0006  * Various authors.
0007  *
0008  * SPDX-License-Identifier: GPL-2.0-or-later
0009  */
0010 
0011 #pragma once
0012 
0013 #include "messagecomposer_export.h"
0014 
0015 #include "editorwatcher.h"
0016 
0017 #include <QObject>
0018 #include <QUrl>
0019 
0020 #include <KService>
0021 #include <MessageCore/AttachmentPart>
0022 
0023 class KActionCollection;
0024 class QAction;
0025 class KJob;
0026 namespace MessageComposer
0027 {
0028 class AttachmentModel;
0029 /**
0030  * @brief The AttachmentControllerBase class
0031  */
0032 class MESSAGECOMPOSER_EXPORT AttachmentControllerBase : public QObject
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     AttachmentControllerBase(MessageComposer::AttachmentModel *model, QWidget *wParent, KActionCollection *actionCollection);
0038     ~AttachmentControllerBase() override;
0039 
0040     void createActions();
0041 
0042     // TODO dnd stuff...
0043 
0044     void setSelectedParts(const MessageCore::AttachmentPart::List &selectedParts);
0045 
0046     void setAttachOwnVcard(bool attachVcard);
0047     [[nodiscard]] bool attachOwnVcard() const;
0048     void setIdentityHasOwnVcard(bool state);
0049 
0050 public Q_SLOTS:
0051     /// model sets these
0052     void setEncryptEnabled(bool enabled);
0053     void setSignEnabled(bool enabled);
0054     /// compression is async...
0055     void compressAttachment(const MessageCore::AttachmentPart::Ptr &part, bool compress);
0056     void showContextMenu();
0057     void openAttachment(const MessageCore::AttachmentPart::Ptr &part);
0058     void viewAttachment(const MessageCore::AttachmentPart::Ptr &part);
0059     void editAttachment(MessageCore::AttachmentPart::Ptr part,
0060                         MessageComposer::EditorWatcher::OpenWithOption option = MessageComposer::EditorWatcher::NoOpenWithDialog);
0061     void editAttachmentWith(const MessageCore::AttachmentPart::Ptr &part);
0062     void saveAttachmentAs(const MessageCore::AttachmentPart::Ptr &part);
0063     void attachmentProperties(const MessageCore::AttachmentPart::Ptr &part);
0064     void showAddAttachmentFileDialog();
0065     void showAddAttachmentCompressedDirectoryDialog();
0066     /// sets sign, encrypt, shows properties dialog if so configured
0067     void addAttachment(const MessageCore::AttachmentPart::Ptr &part);
0068     void addAttachment(const QUrl &url);
0069     void addAttachmentUrlSync(const QUrl &url);
0070     void addAttachments(const QList<QUrl> &urls);
0071     void showAttachPublicKeyDialog();
0072     void showAttachVcard();
0073     void showAttachClipBoard();
0074     virtual void attachMyPublicKey();
0075 
0076 Q_SIGNALS:
0077     void actionsCreated();
0078     void refreshSelection();
0079     void showAttachment(KMime::Content *content, const QByteArray &charset);
0080     void selectedAllAttachment();
0081     void addOwnVcard(bool);
0082     void fileAttached();
0083 
0084 protected:
0085     void exportPublicKey(const QString &fingerprint);
0086     void enableAttachPublicKey(bool enable);
0087     void enableAttachMyPublicKey(bool enable);
0088     void byteArrayToRemoteFile(const QByteArray &aData, const QUrl &aURL, bool overwrite = false);
0089     void openWith(const KService::Ptr &offer = KService::Ptr());
0090 
0091 private:
0092     MESSAGECOMPOSER_NO_EXPORT void attachDirectory(const QUrl &url);
0093     MESSAGECOMPOSER_NO_EXPORT void slotPutResult(KJob *job);
0094     MESSAGECOMPOSER_NO_EXPORT void slotOpenWithDialog();
0095     MESSAGECOMPOSER_NO_EXPORT void slotOpenWithAction(QAction *act);
0096 
0097 private:
0098     class AttachmentControllerBasePrivate;
0099     std::unique_ptr<AttachmentControllerBasePrivate> const d;
0100 };
0101 } //