Clean up QML registration
authorClaudio Cambra <claudio.cambra@gmail.com>
Thu, 4 Aug 2022 12:41:49 +0000 (14:41 +0200)
committerClaudio Cambra <claudio.cambra@gmail.com>
Wed, 7 Sep 2022 15:00:44 +0000 (17:00 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
src/gui/main.cpp
src/gui/owncloudgui.cpp
src/gui/systray.cpp

index 7b457366a9823d9bd410a7835c41229760165b89..d5d106efd0b4b76468c8b015ccd891ed0727604b 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <cmath>
 #include <csignal>
-#include <qqml.h>
 
 #ifdef Q_OS_UNIX
 #include <sys/time.h>
 #endif
 
 #include "application.h"
-#include "fileactivitylistmodel.h"
+#include "cocoainitializer.h"
 #include "theme.h"
 #include "common/utility.h"
-#include "cocoainitializer.h"
-#include "userstatusselectormodel.h"
-#include "emojimodel.h"
-#include "tray/syncstatussummary.h"
-#include "tray/unifiedsearchresultslistmodel.h"
 
 #if defined(BUILD_UPDATER)
 #include "updater/updater.h"
@@ -67,22 +61,6 @@ int main(int argc, char **argv)
     Q_INIT_RESOURCE(resources);
     Q_INIT_RESOURCE(theme);
 
-    qmlRegisterType<SyncStatusSummary>("com.nextcloud.desktopclient", 1, 0, "SyncStatusSummary");
-    qmlRegisterType<EmojiModel>("com.nextcloud.desktopclient", 1, 0, "EmojiModel");
-    qmlRegisterType<UserStatusSelectorModel>("com.nextcloud.desktopclient", 1, 0, "UserStatusSelectorModel");
-    qmlRegisterType<OCC::ActivityListModel>("com.nextcloud.desktopclient", 1, 0, "ActivityListModel");
-    qmlRegisterType<OCC::FileActivityListModel>("com.nextcloud.desktopclient", 1, 0, "FileActivityListModel");
-    qmlRegisterType<Theme>("com.nextcloud.desktopclient", 1, 0, "Theme");
-    qmlRegisterUncreatableType<OCC::UnifiedSearchResultsListModel>(
-        "com.nextcloud.desktopclient", 1, 0, "UnifiedSearchResultsListModel", "UnifiedSearchResultsListModel");
-    qRegisterMetaType<UnifiedSearchResultsListModel *>("UnifiedSearchResultsListModel*");
-
-    qmlRegisterUncreatableType<OCC::UserStatus>("com.nextcloud.desktopclient", 1, 0, "UserStatus", "Access to Status enum");
-
-    qRegisterMetaTypeStreamOperators<Emoji>();
-    qRegisterMetaType<OCC::UserStatus>("UserStatus");
-
-
     // Work around a bug in KDE's qqc2-desktop-style which breaks
     // buttons with icons not based on a name, by forcing a style name
     // the platformtheme plugin won't try to force qqc2-desktops-style
index db4d4e3c6554c05d3371dd25e585bf52a8170e91..f9a1c8056a19693a786f25041206f289bb93ee00 100644 (file)
  * for more details.
  */
 
-#include "application.h"
 #include "owncloudgui.h"
-#include "theme.h"
-#include "folderman.h"
-#include "progressdispatcher.h"
-#include "owncloudsetupwizard.h"
-#include "sharedialog.h"
-#include "settingsdialog.h"
-#include "logger.h"
-#include "logbrowser.h"
+
 #include "account.h"
+#include "accountmanager.h"
 #include "accountstate.h"
+#include "application.h"
+#include "callstatechecker.h"
+#include "emojimodel.h"
+#include "fileactivitylistmodel.h"
+#include "folderman.h"
+#include "guiutility.h"
+#include "logbrowser.h"
+#include "logger.h"
 #include "openfilemanager.h"
-#include "accountmanager.h"
+#include "owncloudsetupwizard.h"
+#include "progressdispatcher.h"
+#include "settingsdialog.h"
+#include "sharedialog.h"
+#include "theme.h"
+#include "wheelhandler.h"
 #include "common/syncjournalfilerecord.h"
 #include "creds/abstractcredentials.h"
-#include "guiutility.h"
+#include "tray/syncstatussummary.h"
+#include "tray/unifiedsearchresultslistmodel.h"
+
 #ifdef WITH_LIBCLOUDPROVIDERS
 #include "cloudproviders/cloudprovidermanager.h"
 #endif
@@ -107,6 +115,26 @@ ownCloudGui::ownCloudGui(Application *parent)
         this, &ownCloudGui::slotShowOptionalTrayMessage);
     connect(Logger::instance(), &Logger::guiMessage,
         this, &ownCloudGui::slotShowGuiMessage);
+
+    qmlRegisterType<SyncStatusSummary>("com.nextcloud.desktopclient", 1, 0, "SyncStatusSummary");
+    qmlRegisterType<EmojiModel>("com.nextcloud.desktopclient", 1, 0, "EmojiModel");
+    qmlRegisterType<UserStatusSelectorModel>("com.nextcloud.desktopclient", 1, 0, "UserStatusSelectorModel");
+    qmlRegisterType<ActivityListModel>("com.nextcloud.desktopclient", 1, 0, "ActivityListModel");
+    qmlRegisterType<ActivityListModel>("com.nextcloud.desktopclient", 1, 0, "FileActivityListModel");
+    qmlRegisterType<WheelHandler>("com.nextcloud.desktopclient", 1, 0, "WheelHandler");
+    qmlRegisterType<CallStateChecker>("com.nextcloud.desktopclient", 1, 0, "CallStateChecker");
+
+    qmlRegisterUncreatableType<UnifiedSearchResultsListModel>("com.nextcloud.desktopclient", 1, 0, "UnifiedSearchResultsListModel", "UnifiedSearchResultsListModel");
+    qmlRegisterUncreatableType<UserStatus>("com.nextcloud.desktopclient", 1, 0, "UserStatus", "Access to Status enum");
+
+    qRegisterMetaTypeStreamOperators<Emoji>();
+    qRegisterMetaType<UnifiedSearchResultsListModel *>("UnifiedSearchResultsListModel*");
+    qRegisterMetaType<UserStatus>("UserStatus");
+
+    qmlRegisterSingletonInstance("com.nextcloud.desktopclient", 1, 0, "UserModel", UserModel::instance());
+    qmlRegisterSingletonInstance("com.nextcloud.desktopclient", 1, 0, "UserAppsModel", UserAppsModel::instance());
+    qmlRegisterSingletonInstance("com.nextcloud.desktopclient", 1, 0, "Theme", Theme::instance());
+    qmlRegisterSingletonInstance("com.nextcloud.desktopclient", 1, 0, "Systray", Systray::instance());
 }
 
 void ownCloudGui::createTray()
index 51ba0e267f2f170218ee0d277cf1d986969fb00f..05ced5e36bd78a84425c95e38a45537dfa71443b 100644 (file)
@@ -74,33 +74,6 @@ void Systray::setTrayEngine(QQmlApplicationEngine *trayEngine)
 Systray::Systray()
     : QSystemTrayIcon(nullptr)
 {
-    qmlRegisterSingletonType<UserModel>("com.nextcloud.desktopclient", 1, 0, "UserModel",
-        [](QQmlEngine *, QJSEngine *) -> QObject * {
-            return UserModel::instance();
-        }
-    );
-
-    qmlRegisterSingletonType<UserAppsModel>("com.nextcloud.desktopclient", 1, 0, "UserAppsModel",
-        [](QQmlEngine *, QJSEngine *) -> QObject * {
-            return UserAppsModel::instance();
-        }
-    );
-
-    qmlRegisterSingletonType<Systray>("com.nextcloud.desktopclient", 1, 0, "Theme",
-        [](QQmlEngine *, QJSEngine *) -> QObject * {
-            return Theme::instance();
-        }
-    );
-
-    qmlRegisterSingletonType<Systray>("com.nextcloud.desktopclient", 1, 0, "Systray",
-        [](QQmlEngine *, QJSEngine *) -> QObject * {
-            return Systray::instance();
-        }
-    );
-
-    qmlRegisterType<WheelHandler>("com.nextcloud.desktopclient", 1, 0, "WheelHandler");
-    qmlRegisterType<CallStateChecker>("com.nextcloud.desktopclient", 1, 0, "CallStateChecker");
-
 #if defined(Q_OS_MACOS) && defined(BUILD_OWNCLOUD_OSX_BUNDLE)
     setUserNotificationCenterDelegate();
     checkNotificationAuth(MacNotificationAuthorizationOptions::Default); // No provisional auth, ask user explicitly first time