| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2013 Christoph Cullmann <cullmann@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | |
| 7 | #include <ktexteditor/application.h> |
| 8 | #include <ktexteditor/mainwindow.h> |
| 9 | #include <ktexteditor/plugin.h> |
| 10 | |
| 11 | #include "kateglobal.h" |
| 12 | |
| 13 | namespace KTextEditor |
| 14 | { |
| 15 | Application::Application(QObject *parent) |
| 16 | : QObject(parent) |
| 17 | , d(nullptr) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | Application::~Application() = default; |
| 22 | |
| 23 | bool Application::quit() |
| 24 | { |
| 25 | // dispatch to parent |
| 26 | bool success = false; |
| 27 | QMetaObject::invokeMethod(obj: parent(), member: "quit" , c: Qt::DirectConnection, Q_RETURN_ARG(bool, success)); |
| 28 | |
| 29 | return success; |
| 30 | } |
| 31 | |
| 32 | QList<KTextEditor::MainWindow *> Application::mainWindows() |
| 33 | { |
| 34 | // dispatch to parent |
| 35 | QList<KTextEditor::MainWindow *> mainWindow; |
| 36 | QMetaObject::invokeMethod(obj: parent(), member: "mainWindows" , c: Qt::DirectConnection, Q_RETURN_ARG(QList<KTextEditor::MainWindow *>, mainWindow)); |
| 37 | return mainWindow; |
| 38 | } |
| 39 | |
| 40 | KTextEditor::MainWindow *Application::activeMainWindow() |
| 41 | { |
| 42 | // dispatch to parent |
| 43 | KTextEditor::MainWindow *window = nullptr; |
| 44 | QMetaObject::invokeMethod(obj: parent(), member: "activeMainWindow" , c: Qt::DirectConnection, Q_RETURN_ARG(KTextEditor::MainWindow *, window)); |
| 45 | |
| 46 | // always return some kind of window to not need to check for valid pointer |
| 47 | return window ? window : KTextEditor::EditorPrivate::self()->dummyMainWindow(); |
| 48 | } |
| 49 | |
| 50 | QList<KTextEditor::Document *> Application::documents() |
| 51 | { |
| 52 | // dispatch to parent |
| 53 | QList<KTextEditor::Document *> documents; |
| 54 | QMetaObject::invokeMethod(obj: parent(), member: "documents" , c: Qt::DirectConnection, Q_RETURN_ARG(QList<KTextEditor::Document *>, documents)); |
| 55 | return documents; |
| 56 | } |
| 57 | |
| 58 | KTextEditor::Document *Application::findUrl(const QUrl &url) |
| 59 | { |
| 60 | // dispatch to parent |
| 61 | KTextEditor::Document *document = nullptr; |
| 62 | QMetaObject::invokeMethod(obj: parent(), member: "findUrl" , c: Qt::DirectConnection, Q_RETURN_ARG(KTextEditor::Document *, document), Q_ARG(QUrl, url)); |
| 63 | return document; |
| 64 | } |
| 65 | |
| 66 | KTextEditor::Document *Application::openUrl(const QUrl &url, const QString &encoding) |
| 67 | { |
| 68 | // dispatch to parent |
| 69 | KTextEditor::Document *document = nullptr; |
| 70 | QMetaObject::invokeMethod(obj: parent(), |
| 71 | member: "openUrl" , |
| 72 | c: Qt::DirectConnection, |
| 73 | Q_RETURN_ARG(KTextEditor::Document *, document), |
| 74 | Q_ARG(QUrl, url), |
| 75 | Q_ARG(QString, encoding)); |
| 76 | return document; |
| 77 | } |
| 78 | |
| 79 | bool Application::closeDocument(KTextEditor::Document *document) |
| 80 | { |
| 81 | // dispatch to parent |
| 82 | bool success = false; |
| 83 | QMetaObject::invokeMethod(obj: parent(), member: "closeDocument" , c: Qt::DirectConnection, Q_RETURN_ARG(bool, success), Q_ARG(KTextEditor::Document *, document)); |
| 84 | return success; |
| 85 | } |
| 86 | |
| 87 | bool Application::closeDocuments(const QList<KTextEditor::Document *> &documents) |
| 88 | { |
| 89 | // dispatch to parent |
| 90 | bool success = false; |
| 91 | QMetaObject::invokeMethod(obj: parent(), member: "closeDocuments" , c: Qt::DirectConnection, Q_RETURN_ARG(bool, success), Q_ARG(QList<KTextEditor::Document *>, documents)); |
| 92 | return success; |
| 93 | } |
| 94 | |
| 95 | KTextEditor::Plugin *Application::plugin(const QString &name) |
| 96 | { |
| 97 | // dispatch to parent |
| 98 | Plugin *plugin = nullptr; |
| 99 | QMetaObject::invokeMethod(obj: parent(), member: "plugin" , c: Qt::DirectConnection, Q_RETURN_ARG(KTextEditor::Plugin *, plugin), Q_ARG(QString, name)); |
| 100 | return plugin; |
| 101 | } |
| 102 | |
| 103 | } // namespace KTextEditor |
| 104 | |