File indexing completed on 2024-11-03 12:40:04

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.0-only
0006 */
0007 
0008 #include <KEMailClientLauncherJob>
0009 #include <KIO/JobUiDelegate>
0010 #include <KIO/JobUiDelegateFactory>
0011 #include <QApplication>
0012 #include <QDebug>
0013 #include <QDir>
0014 #include <QUrl>
0015 
0016 int main(int argc, char *argv[])
0017 {
0018     QApplication app(argc, argv);
0019 
0020     auto *job = new KEMailClientLauncherJob;
0021     job->setTo({"David Faure <faure@kde.org>", "Another person <null@kde.org>"});
0022     job->setCc({"CC me please <null@kde.org>"});
0023     job->setSubject("This is the test email's subject");
0024     job->setBody("This email was created by kemailclientlauncherjobtest_gui in KIO.");
0025     const QStringList urls = app.arguments();
0026     QList<QUrl> attachments;
0027     std::transform(urls.cbegin(), urls.cend(), std::back_inserter(attachments), [](const QString &arg) {
0028         return QUrl::fromUserInput(arg, QDir::currentPath());
0029     });
0030     job->setAttachments(attachments);
0031     job->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr));
0032     job->start();
0033 
0034     QObject::connect(job, &KJob::result, &app, [&]() {
0035         if (job->error()) {
0036             qWarning() << job->errorString();
0037             app.exit(1);
0038         } else {
0039             qDebug() << "Successfully started";
0040             app.exit(0);
0041         }
0042     });
0043 
0044     return app.exec();
0045 }