File indexing completed on 2024-12-08 04:34:23

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 #include "libruqolawidgets_private_export.h"
0009 #include <QObject>
0010 class RocketChatAccount;
0011 class QProgressDialog;
0012 class LIBRUQOLAWIDGETS_TESTS_EXPORT MessageAttachmentDownloadAndSaveJob : public QObject
0013 {
0014     Q_OBJECT
0015 public:
0016     enum class ActionType {
0017         Unknown = 0,
0018         DownloadOnly,
0019         DownloadAndSave,
0020     };
0021     Q_ENUM(ActionType)
0022 
0023     enum class AttachmentType {
0024         Unknown = 0,
0025         Image,
0026         Video,
0027         Sound,
0028     };
0029     Q_ENUM(AttachmentType)
0030 
0031     struct LIBRUQOLAWIDGETS_TESTS_EXPORT MessageAttachmentDownloadJobInfo {
0032         [[nodiscard]] bool isValid() const;
0033         QString attachmentPath;
0034         MessageAttachmentDownloadAndSaveJob::AttachmentType attachmentType = MessageAttachmentDownloadAndSaveJob::AttachmentType::Unknown;
0035         MessageAttachmentDownloadAndSaveJob::ActionType actionType = MessageAttachmentDownloadAndSaveJob::ActionType::Unknown;
0036         bool needToDownloadAttachment = false;
0037         QWidget *parentWidget = nullptr;
0038     };
0039 
0040     explicit MessageAttachmentDownloadAndSaveJob(QObject *parent = nullptr);
0041     ~MessageAttachmentDownloadAndSaveJob() override;
0042 
0043     [[nodiscard]] MessageAttachmentDownloadJobInfo info() const;
0044     void setInfo(const MessageAttachmentDownloadJobInfo &newInfo);
0045 
0046     [[nodiscard]] RocketChatAccount *rocketChatAccount() const;
0047     void setRocketChatAccount(RocketChatAccount *newRocketChatAccount);
0048 
0049     [[nodiscard]] bool canStart() const;
0050 
0051     void start();
0052 
0053 Q_SIGNALS:
0054     void downloadDone(const QString &url);
0055     void attachmentFileDownloadDone(const QString &url);
0056 
0057 private:
0058     LIBRUQOLAWIDGETS_NO_EXPORT void slotDownloadDone(const QString &path);
0059     LIBRUQOLAWIDGETS_NO_EXPORT void slotDownloadCancel();
0060     LIBRUQOLAWIDGETS_NO_EXPORT void assignProgressDialogStr(QProgressDialog *progressDialog);
0061     LIBRUQOLAWIDGETS_NO_EXPORT void slotFileDownloaded(const QString &filePath, const QUrl &cacheImageUrl);
0062     [[nodiscard]] LIBRUQOLAWIDGETS_NO_EXPORT QString saveFileString() const;
0063     MessageAttachmentDownloadJobInfo mInfo;
0064     RocketChatAccount *mRocketChatAccount = nullptr;
0065     QProgressDialog *mProgressDialogBox = nullptr;
0066 };
0067 Q_DECLARE_TYPEINFO(MessageAttachmentDownloadAndSaveJob::MessageAttachmentDownloadJobInfo, Q_RELOCATABLE_TYPE);