1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
/*
This file is part of the KDE libraries
SPDX-FileCopyrightText: 2021 David Faure <faure@kde.org>
SPDX-License-Identifier: LGPL-2.0-only
*/
#include <KEMailClientLauncherJob>
#include <KIO/JobUiDelegate>
#include <KIO/JobUiDelegateFactory>
#include <QApplication>
#include <QDebug>
#include <QDir>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
auto *job = new KEMailClientLauncherJob;
job->setTo({"David Faure <faure@kde.org>", "Another person <null@kde.org>"});
job->setCc({"CC me please <null@kde.org>"});
job->setSubject("This is the test email's subject");
job->setBody("This email was created by kemailclientlauncherjobtest_gui in KIO.");
const QStringList urls = app.arguments();
QList<QUrl> attachments;
std::transform(urls.cbegin(), urls.cend(), std::back_inserter(attachments), [](const QString &arg) {
return QUrl::fromUserInput(arg, QDir::currentPath());
});
job->setAttachments(attachments);
job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr));
job->start();
QObject::connect(job, &KJob::result, &app, [&]() {
if (job->error()) {
qWarning() << job->errorString();
app.exit(1);
} else {
qDebug() << "Successfully started";
app.exit(0);
}
});
return app.exec();
}
|