File: menudemo.cpp

package info (click to toggle)
kf6-purpose 6.20.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,076 kB
  • sloc: cpp: 4,700; xml: 170; ansic: 34; sh: 31; makefile: 10
file content (50 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
/*
    SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@blue-systems.com>

    SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QApplication>
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
#include <QMimeDatabase>
#include <QStandardPaths>
#include <QUrl>

#include <purpose/alternativesmodel.h>
#include <purpose/menu.h>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    Purpose::Menu menu;
    Purpose::AlternativesModel *model = menu.model();

    QJsonObject input;
    if (app.arguments().length() > 1) {
        QMimeDatabase mime;
        QUrl url = QUrl::fromUserInput(app.arguments().constLast());
        input = QJsonObject{{QStringLiteral("urls"), QJsonArray{url.toString()}}, {QStringLiteral("mimeType"), mime.mimeTypeForUrl(url).name()}};
    } else {
        input =
            QJsonObject{{QStringLiteral("urls"), QJsonArray{QStringLiteral("http://kde.org")}}, {QStringLiteral("mimeType"), QStringLiteral("dummy/thing")}};
    }
    qDebug() << "sharing..." << input;

    model->setInputData(input);
    model->setPluginType(QStringLiteral("Export"));
    menu.reload();
    menu.exec();

    QObject::connect(&menu, &Purpose::Menu::finished, &menu, [&app](const QJsonObject &output, int error, const QString &errorMessage) {
        if (error != 0) {
            qDebug() << "job failed with error" << errorMessage;
        }
        qDebug() << "output:" << output;
        app.quit();
    });

    return app.exec();
}