File indexing completed on 2025-01-19 03:41:33
0001 /* 0002 This file is part of the KDE libraries 0003 SPDX-FileCopyrightText: 2021 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 0008 #ifndef KEMAILCLIENTLAUNCHERJOB_H 0009 #define KEMAILCLIENTLAUNCHERJOB_H 0010 0011 #include "kiogui_export.h" 0012 #include <KJob> 0013 #include <memory> 0014 0015 class KEMailClientLauncherJobPrivate; 0016 0017 /** 0018 * @class KEMailClientLauncherJob kemailclientlauncherjob.h <KEMailClientLauncherJob> 0019 * 0020 * @brief KEMailClientLauncherJob starts a mail client in order to compose a new mail. 0021 * 0022 * It creates a startup notification and finishes it on success or on error (for the taskbar). 0023 * It also emits an error message if necessary (e.g. "program not found"). 0024 * 0025 * The job finishes when the application is successfully started. 0026 * For error handling, either connect to the result() signal, or for a simple messagebox on error, 0027 * you can do 0028 * @code 0029 * job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); 0030 * @endcode 0031 * 0032 * @since 5.87 0033 */ 0034 class KIOGUI_EXPORT KEMailClientLauncherJob : public KJob 0035 { 0036 Q_OBJECT 0037 public: 0038 /** 0039 * Creates a KEMailClientLauncherJob. 0040 * @param parent the parent QObject 0041 */ 0042 explicit KEMailClientLauncherJob(QObject *parent = nullptr); 0043 0044 /** 0045 * Destructor 0046 * 0047 * Note that jobs auto-delete themselves after emitting result 0048 */ 0049 ~KEMailClientLauncherJob() override; 0050 0051 /** 0052 * Sets the email address(es) that will be used in the To field for the email 0053 * @param to recipients; each entry can use the format "someone@example.com" or "John Doe <someone@example.com>" 0054 */ 0055 void setTo(const QStringList &to); 0056 /** 0057 * Sets the email address(es) that will be used in the CC field for the email 0058 * @param cc recipients; each entry can use the format "someone@example.com" or "John Doe <someone@example.com>" 0059 */ 0060 void setCc(const QStringList &cc); 0061 /** 0062 * Sets the email address(es) that will be used in the Bcc field for the email 0063 * @param bcc recipients; each entry can use the format "someone@example.com" or "John Doe <someone@example.com>" 0064 * @since 5.96 0065 */ 0066 void setBcc(const QStringList &bcc); 0067 /** 0068 * Sets the subject for the email 0069 * @param subject the email subject 0070 */ 0071 void setSubject(const QString &subject); 0072 /** 0073 * Sets the body for the email 0074 * @param body the email body 0075 */ 0076 void setBody(const QString &body); 0077 /** 0078 * Sets attachments for the email 0079 * @param urls URLs of the attachments for the email 0080 * Remember to use QUrl::fromLocalFile() to construct those URLs from local file paths. 0081 */ 0082 void setAttachments(const QList<QUrl> &urls); 0083 0084 /** 0085 * Sets the platform-specific startup id of the mail client launch. 0086 * @param startupId startup id, if any (otherwise ""). 0087 * For X11, this would be the id for the Startup Notification protocol. 0088 * For Wayland, this would be the token for the XDG Activation protocol. 0089 */ 0090 void setStartupId(const QByteArray &startupId); 0091 0092 /** 0093 * Starts the job. 0094 * You must call this, after having called all the necessary setters. 0095 */ 0096 void start() override; 0097 0098 private: 0099 friend class KEMailClientLauncherJobTest; 0100 QUrl mailToUrl() const; // for the unittest 0101 QStringList thunderbirdArguments() const; // for the unittest 0102 0103 KIOGUI_NO_EXPORT void emitDelayedResult(); 0104 0105 friend class KEMailClientLauncherJobPrivate; 0106 std::unique_ptr<KEMailClientLauncherJobPrivate> d; 0107 }; 0108 0109 #endif // KEMAILCLIENTLAUNCHERJOB_H