diff --git a/src/main.cpp b/src/main.cpp index f61ea193..7e583acb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,40 +51,6 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); QCoreApplication::setApplicationName(QStringLiteral("Alligator")); - qmlRegisterType("org.kde.alligator", 1, 0, "FeedsModel"); - qmlRegisterType("org.kde.alligator", 1, 0, "QueueModel"); - qmlRegisterType("org.kde.alligator", 1, 0, "EpisodeModel"); - qmlRegisterUncreatableType("org.kde.alligator", 1, 0, "EntriesModel", QStringLiteral("Get from Feed")); - qmlRegisterUncreatableType("org.kde.alligator", 1, 0, "Enclosure", QStringLiteral("Only for enums")); - qmlRegisterSingletonType("org.kde.alligator", 1, 0, "Fetcher", [](QQmlEngine *engine, QJSEngine *) -> QObject * { - engine->setObjectOwnership(&Fetcher::instance(), QQmlEngine::CppOwnership); - return &Fetcher::instance(); - }); - qmlRegisterSingletonType("org.kde.alligator", 1, 0, "Database", [](QQmlEngine *engine, QJSEngine *) -> QObject * { - engine->setObjectOwnership(&Database::instance(), QQmlEngine::CppOwnership); - return &Database::instance(); - }); - qmlRegisterSingletonType("org.kde.alligator", 1, 0, "DataManager", [](QQmlEngine *engine, QJSEngine *) -> QObject * { - engine->setObjectOwnership(&DataManager::instance(), QQmlEngine::CppOwnership); - return &DataManager::instance(); - }); - qmlRegisterSingletonType("org.kde.alligator", 1, 0, "SettingsManager", [](QQmlEngine *engine, QJSEngine *) -> QObject * { - engine->setObjectOwnership(SettingsManager::self(), QQmlEngine::CppOwnership); - return SettingsManager::self(); - }); - qmlRegisterSingletonType("org.kde.alligator", 1, 0, "DownloadProgressModel", [](QQmlEngine *engine, QJSEngine *) -> QObject * { - engine->setObjectOwnership(&DownloadProgressModel::instance(), QQmlEngine::CppOwnership); - return &DownloadProgressModel::instance(); - }); - qmlRegisterSingletonType("org.kde.alligator", 1, 0, "ErrorLogModel", [](QQmlEngine *engine, QJSEngine *) -> QObject * { - engine->setObjectOwnership(&ErrorLogModel::instance(), QQmlEngine::CppOwnership); - return &ErrorLogModel::instance(); - }); - qmlRegisterType("org.kde.alligator", 1, 0, "AudioManager"); - qmlRegisterType("org.kde.alligator", 1, 0, "Mpris2"); - - qRegisterMetaType("const Entry*"); // "hack" to make qml understand Entry* - QQmlApplicationEngine engine; engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); KLocalizedString::setApplicationDomain("alligator"); @@ -108,6 +74,24 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(about)); + qmlRegisterType("org.kde.alligator", 1, 0, "FeedsModel"); + qmlRegisterType("org.kde.alligator", 1, 0, "QueueModel"); + qmlRegisterType("org.kde.alligator", 1, 0, "EpisodeModel"); + qmlRegisterType("org.kde.alligator", 1, 0, "AudioManager"); + qmlRegisterType("org.kde.alligator", 1, 0, "Mpris2"); + + qmlRegisterUncreatableType("org.kde.alligator", 1, 0, "EntriesModel", QStringLiteral("Get from Feed")); + qmlRegisterUncreatableType("org.kde.alligator", 1, 0, "Enclosure", QStringLiteral("Only for enums")); + + qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "Fetcher", &Fetcher::instance()); + qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "Database", &Database::instance()); + qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "DataManager", &DataManager::instance()); + qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "SettingsManager", SettingsManager::self()); + qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "DownloadProgressModel", &DownloadProgressModel::instance()); + qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "ErrorLogModel", &ErrorLogModel::instance()); + + qRegisterMetaType("const Entry*"); // "hack" to make qml understand Entry* + // Make sure that settings are saved before the application exits QObject::connect(&app, &QCoreApplication::aboutToQuit, SettingsManager::self(), &SettingsManager::save);