File: kemailclientlauncherjobtest_gui.cpp

package info (click to toggle)
kio 5.116.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 41,496 kB
  • sloc: cpp: 123,468; xml: 528; ansic: 466; ruby: 60; sh: 21; makefile: 13
file content (45 lines) | stat: -rw-r--r-- 1,418 bytes parent folder | download | duplicates (3)
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();
}