From 3c4c538de8bf86c327661f15be0b325a87497a5e Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Wed, 10 Apr 2024 20:47:29 +0200 Subject: [PATCH] Use declarative type registration for remaining types --- .gitignore | 1 + src/CMakeLists.txt | 1 + src/devtools/FeatureFlagPage.qml | 2 - src/foreigntypes.h | 56 +++++++++++++++++++++++++ src/login/WelcomePage.qml | 1 - src/main.cpp | 12 ------ src/qml/AccountMenu.qml | 1 - src/qml/AccountSwitchDialog.qml | 1 - src/qml/ChatBar.qml | 1 - src/qml/CollapsedRoomDelegate.qml | 1 - src/qml/DelegateContextMenu.qml | 1 - src/qml/EmojiSas.qml | 2 - src/qml/FileDelegateContextMenu.qml | 1 - src/qml/GlobalMenu.qml | 2 - src/qml/HoverActions.qml | 1 - src/qml/KeyVerificationDialog.qml | 2 - src/qml/Main.qml | 2 - src/qml/MessageDelegateContextMenu.qml | 1 - src/qml/NeochatMaximizeComponent.qml | 1 - src/qml/RoomDelegate.qml | 1 - src/qml/RoomDrawer.qml | 1 - src/qml/RoomInformation.qml | 1 - src/qml/RoomListPage.qml | 2 - src/qml/RoomPage.qml | 1 - src/qml/TimelineView.qml | 1 - src/qml/UnlockSSSSDialog.qml | 2 - src/qml/UserInfo.qml | 2 - src/qml/VerificationCanceled.qml | 2 - src/settings/About.qml | 4 -- src/settings/AccountsPage.qml | 1 - src/settings/AppearanceSettingsPage.qml | 1 - src/settings/ColorScheme.qml | 1 - src/settings/NeoChatGeneralPage.qml | 1 - src/settings/NetworkProxyPage.qml | 2 - src/settings/Permissions.qml | 1 - src/timeline/FileComponent.qml | 1 - src/timeline/MessageDelegate.qml | 1 - src/timeline/ReactionDelegate.qml | 3 +- src/timeline/SectionDelegate.qml | 2 +- src/timeline/StateDelegate.qml | 2 +- src/timeline/TimelineDelegate.qml | 1 - 41 files changed, 62 insertions(+), 62 deletions(-) create mode 100644 src/foreigntypes.h diff --git a/.gitignore b/.gitignore index 8256fd455..6cf574851 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ kate.project.ctags.* .idea/ cmake-build-* src/res.generated.qrc +.qmlls.ini diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2f14e6cb..8a5c41dd2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -174,6 +174,7 @@ add_library(neochat STATIC sharehandler.h models/roomtreeitem.cpp models/roomtreeitem.h + foreigntypes.h ) set_source_files_properties(qml/OsmLocationPlugin.qml PROPERTIES diff --git a/src/devtools/FeatureFlagPage.qml b/src/devtools/FeatureFlagPage.qml index 76d8189db..cd59ccaf0 100644 --- a/src/devtools/FeatureFlagPage.qml +++ b/src/devtools/FeatureFlagPage.qml @@ -7,8 +7,6 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard -import org.kde.neochat.config - FormCard.FormCardPage { id: root diff --git a/src/foreigntypes.h b/src/foreigntypes.h new file mode 100644 index 000000000..88d1e127e --- /dev/null +++ b/src/foreigntypes.h @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: 2024 Tobias Fella +// SPDX-License-Identifier: LGPL-2.0-or-later + +#pragma once + +#include + +#include +#include +#if __has_include("Quotient/e2ee/sssshandler.h") +#include +#endif + +#include "controller.h" +#include "neochatconfig.h" + +struct ForeignConfig { + Q_GADGET + QML_FOREIGN(NeoChatConfig) + QML_NAMED_ELEMENT(Config) + QML_SINGLETON +public: + static NeoChatConfig *create(QQmlEngine *, QJSEngine *) + { + QQmlEngine::setObjectOwnership(NeoChatConfig::self(), QQmlEngine::CppOwnership); + return NeoChatConfig::self(); + } +}; + +struct ForeignAccountRegistry { + Q_GADGET + QML_FOREIGN(Quotient::AccountRegistry) + QML_NAMED_ELEMENT(AccountRegistry) + QML_SINGLETON +public: + static Quotient::AccountRegistry *create(QQmlEngine *, QJSEngine *) + { + QQmlEngine::setObjectOwnership(&Controller::instance().accounts(), QQmlEngine::CppOwnership); + return &Controller::instance().accounts(); + } +}; + +struct ForeignKeyVerificationSession { + Q_GADGET + QML_FOREIGN(Quotient::KeyVerificationSession) + QML_NAMED_ELEMENT(KeyVerificationSession) + QML_UNCREATABLE("") +}; + +#if __has_include("Quotient/e2ee/sssshandler.h") +struct ForeignSSSSHandler { + Q_GADGET + QML_FOREIGN(Quotient::SSSSHandler) + QML_NAMED_ELEMENT(SSSSHandler) +}; +#endif diff --git a/src/login/WelcomePage.qml b/src/login/WelcomePage.qml index ce64dccb3..5631b526a 100644 --- a/src/login/WelcomePage.qml +++ b/src/login/WelcomePage.qml @@ -10,7 +10,6 @@ import org.kde.kirigamiaddons.formcard as FormCard import org.kde.neochat import org.kde.neochat.settings -import org.kde.neochat.accounts FormCard.FormCardPage { id: root diff --git a/src/main.cpp b/src/main.cpp index 35536466f..7d9765fad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,11 +35,6 @@ #include "neochat-version.h" -#include -#if __has_include("Quotient/e2ee/sssshandler.h") -#include -#endif -#include #include #include "blurhashimageprovider.h" @@ -234,13 +229,6 @@ int main(int argc, char *argv[]) Q_IMPORT_QML_PLUGIN(org_kde_neochat_loginPlugin) qml_register_types_org_kde_neochat(); - qmlRegisterSingletonInstance("org.kde.neochat.config", 1, 0, "Config", NeoChatConfig::self()); - qmlRegisterSingletonInstance("org.kde.neochat.accounts", 1, 0, "AccountRegistry", &Controller::instance().accounts()); - - qmlRegisterUncreatableType("com.github.quotient_im.libquotient", 1, 0, "KeyVerificationSession", {}); -#if __has_include("Quotient/e2ee/sssshandler.h") - qmlRegisterType("com.github.quotient_im.libquotient", 1, 0, "SSSSHandler"); -#endif QQmlApplicationEngine engine; diff --git a/src/qml/AccountMenu.qml b/src/qml/AccountMenu.qml index 3ce5b4bdd..7ae7edf29 100644 --- a/src/qml/AccountMenu.qml +++ b/src/qml/AccountMenu.qml @@ -10,7 +10,6 @@ import org.kde.kirigami as Kirigami import org.kde.neochat import org.kde.neochat.settings import org.kde.neochat.devtools -import org.kde.neochat.config QQC2.Menu { id: root diff --git a/src/qml/AccountSwitchDialog.qml b/src/qml/AccountSwitchDialog.qml index aecb02220..06e0e9705 100644 --- a/src/qml/AccountSwitchDialog.qml +++ b/src/qml/AccountSwitchDialog.qml @@ -10,7 +10,6 @@ import org.kde.kirigamiaddons.labs.components as KirigamiComponents import org.kde.kirigamiaddons.delegates as Delegates import org.kde.neochat -import org.kde.neochat.accounts Kirigami.Dialog { id: root diff --git a/src/qml/ChatBar.qml b/src/qml/ChatBar.qml index cfc6018bd..6eed73bf3 100644 --- a/src/qml/ChatBar.qml +++ b/src/qml/ChatBar.qml @@ -9,7 +9,6 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.neochat -import org.kde.neochat.config /** * @brief A component for typing and sending chat messages. diff --git a/src/qml/CollapsedRoomDelegate.qml b/src/qml/CollapsedRoomDelegate.qml index bd994867a..3ab84048c 100644 --- a/src/qml/CollapsedRoomDelegate.qml +++ b/src/qml/CollapsedRoomDelegate.qml @@ -11,7 +11,6 @@ import org.kde.kirigamiaddons.labs.components as KirigamiComponents import org.kde.kitemmodels import org.kde.neochat -import org.kde.neochat.config QQC2.ItemDelegate { id: root diff --git a/src/qml/DelegateContextMenu.qml b/src/qml/DelegateContextMenu.qml index 84f41e25e..224c15aab 100644 --- a/src/qml/DelegateContextMenu.qml +++ b/src/qml/DelegateContextMenu.qml @@ -10,7 +10,6 @@ import org.kde.kirigamiaddons.components as KirigamiComponents import org.kde.kirigamiaddons.formcard as FormCard import org.kde.neochat -import org.kde.neochat.config /** * @brief The base menu for most message types. diff --git a/src/qml/EmojiSas.qml b/src/qml/EmojiSas.qml index 6f703131b..4df36cec7 100644 --- a/src/qml/EmojiSas.qml +++ b/src/qml/EmojiSas.qml @@ -5,8 +5,6 @@ import QtQuick import QtQuick.Controls as QQC2 import QtQml -import com.github.quotient_im.libquotient - import org.kde.kirigami as Kirigami import org.kde.neochat diff --git a/src/qml/FileDelegateContextMenu.qml b/src/qml/FileDelegateContextMenu.qml index 3de2f0a3c..071beebd8 100644 --- a/src/qml/FileDelegateContextMenu.qml +++ b/src/qml/FileDelegateContextMenu.qml @@ -8,7 +8,6 @@ import Qt.labs.platform import org.kde.kirigami as Kirigami import org.kde.neochat -import org.kde.neochat.config /** * @brief The menu for media messages. diff --git a/src/qml/GlobalMenu.qml b/src/qml/GlobalMenu.qml index e81f22367..1a574f439 100644 --- a/src/qml/GlobalMenu.qml +++ b/src/qml/GlobalMenu.qml @@ -9,8 +9,6 @@ import QtQuick.Layouts import org.kde.neochat import org.kde.neochat.settings -import org.kde.neochat.config -import org.kde.neochat.accounts Labs.MenuBar { id: root diff --git a/src/qml/HoverActions.qml b/src/qml/HoverActions.qml index 6beb2595b..fb840ebdd 100644 --- a/src/qml/HoverActions.qml +++ b/src/qml/HoverActions.qml @@ -7,7 +7,6 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.neochat -import org.kde.neochat.config /** * @brief A component that provides a set of actions when a message is hovered in the timeline. diff --git a/src/qml/KeyVerificationDialog.qml b/src/qml/KeyVerificationDialog.qml index 4c72dfe17..75ee31d98 100644 --- a/src/qml/KeyVerificationDialog.qml +++ b/src/qml/KeyVerificationDialog.qml @@ -6,8 +6,6 @@ import QtQuick.Controls as QQC2 import QtQuick.Layouts import QtQml -import com.github.quotient_im.libquotient - import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.delegates as Delegates import org.kde.neochat diff --git a/src/qml/Main.qml b/src/qml/Main.qml index 52f167c0c..20e3fe348 100644 --- a/src/qml/Main.qml +++ b/src/qml/Main.qml @@ -10,8 +10,6 @@ import org.kde.kirigami as Kirigami import org.kde.neochat import org.kde.neochat.login import org.kde.neochat.settings -import org.kde.neochat.config -import org.kde.neochat.accounts Kirigami.ApplicationWindow { id: root diff --git a/src/qml/MessageDelegateContextMenu.qml b/src/qml/MessageDelegateContextMenu.qml index 8c1686779..d864b4d15 100644 --- a/src/qml/MessageDelegateContextMenu.qml +++ b/src/qml/MessageDelegateContextMenu.qml @@ -10,7 +10,6 @@ import org.kde.kirigamiaddons.components as KirigamiComponents import org.kde.kirigamiaddons.formcard as FormCard import org.kde.neochat -import org.kde.neochat.config /** * @brief The menu for normal messages. diff --git a/src/qml/NeochatMaximizeComponent.qml b/src/qml/NeochatMaximizeComponent.qml index fd5c3e916..8126b7952 100644 --- a/src/qml/NeochatMaximizeComponent.qml +++ b/src/qml/NeochatMaximizeComponent.qml @@ -10,7 +10,6 @@ import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.labs.components as Components import org.kde.neochat -import org.kde.neochat.config Components.AlbumMaximizeComponent { id: root diff --git a/src/qml/RoomDelegate.qml b/src/qml/RoomDelegate.qml index 26a7d0dcf..127bad0bb 100644 --- a/src/qml/RoomDelegate.qml +++ b/src/qml/RoomDelegate.qml @@ -12,7 +12,6 @@ import org.kde.kirigamiaddons.labs.components as Components import org.kde.kitemmodels import org.kde.neochat -import org.kde.neochat.config Delegates.RoundedItemDelegate { id: root diff --git a/src/qml/RoomDrawer.qml b/src/qml/RoomDrawer.qml index d8aeca43c..670636f6c 100644 --- a/src/qml/RoomDrawer.qml +++ b/src/qml/RoomDrawer.qml @@ -11,7 +11,6 @@ import org.kde.kitemmodels import org.kde.neochat import org.kde.neochat.settings -import org.kde.neochat.config Kirigami.OverlayDrawer { id: root diff --git a/src/qml/RoomInformation.qml b/src/qml/RoomInformation.qml index 1711cfea7..ebad48d8f 100644 --- a/src/qml/RoomInformation.qml +++ b/src/qml/RoomInformation.qml @@ -11,7 +11,6 @@ import org.kde.kirigamiaddons.labs.components as KirigamiComponents import org.kde.kitemmodels import org.kde.neochat -import org.kde.neochat.config /** * @brief Component for visualising the room information. diff --git a/src/qml/RoomListPage.qml b/src/qml/RoomListPage.qml index d0bac42ae..ff85d65cf 100644 --- a/src/qml/RoomListPage.qml +++ b/src/qml/RoomListPage.qml @@ -13,8 +13,6 @@ import org.kde.kirigamiaddons.components as KirigamiComponents import org.kde.kirigamiaddons.delegates as Delegates import org.kde.neochat -import org.kde.neochat.config -import org.kde.neochat.accounts Kirigami.Page { id: root diff --git a/src/qml/RoomPage.qml b/src/qml/RoomPage.qml index 7560eb9d2..85634acf5 100644 --- a/src/qml/RoomPage.qml +++ b/src/qml/RoomPage.qml @@ -12,7 +12,6 @@ import org.kde.kirigami as Kirigami import org.kde.kitemmodels import org.kde.neochat -import org.kde.neochat.config Kirigami.Page { id: root diff --git a/src/qml/TimelineView.qml b/src/qml/TimelineView.qml index 09dcb86fa..cf3f81fd9 100644 --- a/src/qml/TimelineView.qml +++ b/src/qml/TimelineView.qml @@ -12,7 +12,6 @@ import org.kde.kirigami as Kirigami import org.kde.kitemmodels import org.kde.neochat -import org.kde.neochat.config import org.kde.neochat.timeline QQC2.ScrollView { diff --git a/src/qml/UnlockSSSSDialog.qml b/src/qml/UnlockSSSSDialog.qml index e5299c876..b9be89acc 100644 --- a/src/qml/UnlockSSSSDialog.qml +++ b/src/qml/UnlockSSSSDialog.qml @@ -9,8 +9,6 @@ import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.labs.components as KirigamiComponents -import com.github.quotient_im.libquotient - import org.kde.neochat FormCard.FormCardPage { diff --git a/src/qml/UserInfo.qml b/src/qml/UserInfo.qml index 68e59e2ec..19fbfdd4d 100644 --- a/src/qml/UserInfo.qml +++ b/src/qml/UserInfo.qml @@ -10,8 +10,6 @@ import org.kde.kirigamiaddons.delegates as Delegates import org.kde.neochat import org.kde.neochat.settings -import org.kde.neochat.config -import org.kde.neochat.accounts RowLayout { id: root diff --git a/src/qml/VerificationCanceled.qml b/src/qml/VerificationCanceled.qml index 02f31ac23..a0f5e3384 100644 --- a/src/qml/VerificationCanceled.qml +++ b/src/qml/VerificationCanceled.qml @@ -4,8 +4,6 @@ import QtQuick import QtQml -import com.github.quotient_im.libquotient - import org.kde.neochat Message { diff --git a/src/settings/About.qml b/src/settings/About.qml index 8bdb96ce7..aca24d50b 100644 --- a/src/settings/About.qml +++ b/src/settings/About.qml @@ -2,12 +2,8 @@ // SPDX-FileCopyrightText: 2021 Carl Schwan // SPDX-License-Identifier: LGPL-2.0-or-later -import QtQuick.Layouts import org.kde.kirigamiaddons.formcard as FormCard -import org.kde.neochat -import org.kde.coreaddons FormCard.AboutPage { title: i18nc("@title:window", "About NeoChat") - aboutData: AboutData } diff --git a/src/settings/AccountsPage.qml b/src/settings/AccountsPage.qml index afd622578..97235972c 100644 --- a/src/settings/AccountsPage.qml +++ b/src/settings/AccountsPage.qml @@ -12,7 +12,6 @@ import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.labs.components as KirigamiComponents import org.kde.neochat -import org.kde.neochat.accounts FormCard.FormCardPage { id: root diff --git a/src/settings/AppearanceSettingsPage.qml b/src/settings/AppearanceSettingsPage.qml index 19f1dc734..5bd9d025c 100644 --- a/src/settings/AppearanceSettingsPage.qml +++ b/src/settings/AppearanceSettingsPage.qml @@ -11,7 +11,6 @@ import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.labs.components as KirigamiComponents import org.kde.neochat -import org.kde.neochat.config FormCard.FormCardPage { id: root diff --git a/src/settings/ColorScheme.qml b/src/settings/ColorScheme.qml index 83ad7d3df..b0acccf0f 100644 --- a/src/settings/ColorScheme.qml +++ b/src/settings/ColorScheme.qml @@ -7,7 +7,6 @@ import QtQuick.Layouts import org.kde.kirigamiaddons.formcard as FormCard import org.kde.neochat -import org.kde.neochat.config FormCard.FormComboBoxDelegate { id: root diff --git a/src/settings/NeoChatGeneralPage.qml b/src/settings/NeoChatGeneralPage.qml index 062c4c4f9..af7612789 100644 --- a/src/settings/NeoChatGeneralPage.qml +++ b/src/settings/NeoChatGeneralPage.qml @@ -10,7 +10,6 @@ import org.kde.kirigamiaddons.formcard as FormCard import org.kde.neochat import org.kde.neochat.devtools -import org.kde.neochat.config FormCard.FormCardPage { title: i18nc("@title:window", "General") diff --git a/src/settings/NetworkProxyPage.qml b/src/settings/NetworkProxyPage.qml index 39ce6e641..926c6d45d 100644 --- a/src/settings/NetworkProxyPage.qml +++ b/src/settings/NetworkProxyPage.qml @@ -7,8 +7,6 @@ import QtQuick.Layouts import org.kde.kirigamiaddons.formcard as FormCard -import org.kde.neochat.config - FormCard.FormCardPage { id: root diff --git a/src/settings/Permissions.qml b/src/settings/Permissions.qml index 3825150b7..b0799fc49 100644 --- a/src/settings/Permissions.qml +++ b/src/settings/Permissions.qml @@ -9,7 +9,6 @@ import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import org.kde.kirigamiaddons.delegates as Delegates import org.kde.kirigamiaddons.labs.components as KirigamiComponents -import org.kde.kitemmodels import org.kde.neochat diff --git a/src/timeline/FileComponent.qml b/src/timeline/FileComponent.qml index 23a60aef2..2fcbdd60b 100644 --- a/src/timeline/FileComponent.qml +++ b/src/timeline/FileComponent.qml @@ -12,7 +12,6 @@ import org.kde.coreaddons import org.kde.kirigami as Kirigami import org.kde.neochat -import org.kde.neochat.config /** * @brief A component to show a file from a message. diff --git a/src/timeline/MessageDelegate.qml b/src/timeline/MessageDelegate.qml index 7c9896781..3319f1c95 100644 --- a/src/timeline/MessageDelegate.qml +++ b/src/timeline/MessageDelegate.qml @@ -10,7 +10,6 @@ import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.components as KirigamiComponents import org.kde.neochat -import org.kde.neochat.config /** * @brief The base delegate for all messages in the timeline. diff --git a/src/timeline/ReactionDelegate.qml b/src/timeline/ReactionDelegate.qml index 8259f7891..3b1ba1755 100644 --- a/src/timeline/ReactionDelegate.qml +++ b/src/timeline/ReactionDelegate.qml @@ -6,7 +6,8 @@ import QtQuick import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami -import org.kde.neochat.config + +import org.kde.neochat Flow { id: root diff --git a/src/timeline/SectionDelegate.qml b/src/timeline/SectionDelegate.qml index 41da284c6..083ab7bc8 100644 --- a/src/timeline/SectionDelegate.qml +++ b/src/timeline/SectionDelegate.qml @@ -8,7 +8,7 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami -import org.kde.neochat.config +import org.kde.neochat QQC2.ItemDelegate { id: root diff --git a/src/timeline/StateDelegate.qml b/src/timeline/StateDelegate.qml index be1be8dd9..ae1c9d35e 100644 --- a/src/timeline/StateDelegate.qml +++ b/src/timeline/StateDelegate.qml @@ -8,7 +8,7 @@ import QtQuick.Layouts import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.labs.components as KirigamiComponents -import org.kde.neochat.config +import org.kde.neochat /** * @brief A timeline delegate for visualising an aggregated list of consecutive state events. diff --git a/src/timeline/TimelineDelegate.qml b/src/timeline/TimelineDelegate.qml index bb99eef24..b7bd7f1b6 100644 --- a/src/timeline/TimelineDelegate.qml +++ b/src/timeline/TimelineDelegate.qml @@ -6,7 +6,6 @@ import QtQuick import org.kde.kirigami as Kirigami import org.kde.neochat -import org.kde.neochat.config /** * @brief The base Item for all delegates in the timeline.