File indexing completed on 2024-05-12 16:23:40
0001 /** 0002 * SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include <QCommandLineOption> 0008 #include <QCommandLineParser> 0009 #include <QQmlApplicationEngine> 0010 #include <QQmlContext> 0011 #include <QQuickStyle> 0012 #include <QQuickView> 0013 #include <QString> 0014 #include <QStringList> 0015 0016 #ifdef Q_OS_ANDROID 0017 #include <QGuiApplication> 0018 #else 0019 #include <QApplication> 0020 #endif 0021 0022 #include <KAboutData> 0023 #include <KLocalizedContext> 0024 #include <KLocalizedString> 0025 0026 #include "alligator-version.h" 0027 #include "alligatorsettings.h" 0028 #include "database.h" 0029 #include "entriesmodel.h" 0030 #include "entriesproxymodel.h" 0031 #include "feedgroupsmodel.h" 0032 #include "feedsmodel.h" 0033 #include "feedsproxymodel.h" 0034 #include "fetcher.h" 0035 0036 #ifdef Q_OS_WINDOWS 0037 #include <windows.h> 0038 #endif 0039 0040 #ifdef Q_OS_ANDROID 0041 Q_DECL_EXPORT 0042 #endif 0043 0044 int main(int argc, char *argv[]) 0045 { 0046 #ifdef Q_OS_ANDROID 0047 QGuiApplication app(argc, argv); 0048 QQuickStyle::setStyle(QStringLiteral("org.kde.breeze")); 0049 #else 0050 QApplication app(argc, argv); 0051 if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { 0052 QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); 0053 } 0054 #endif 0055 0056 #ifdef Q_OS_WINDOWS 0057 if (AttachConsole(ATTACH_PARENT_PROCESS)) { 0058 FILE *outFile = freopen("CONOUT$", "w", stdout); 0059 if (!outFile) 0060 qWarning() << "Failed to reopen stdout"; 0061 FILE *errFile = freopen("CONOUT$", "w", stderr); 0062 if (!errFile) 0063 qWarning() << "Failed to reopen stderr"; 0064 } 0065 0066 QApplication::setStyle(QStringLiteral("breeze")); 0067 auto font = app.font(); 0068 font.setPointSize(10); 0069 app.setFont(font); 0070 #endif 0071 KLocalizedString::setApplicationDomain("alligator"); 0072 0073 QCoreApplication::setOrganizationName(QStringLiteral("KDE")); 0074 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); 0075 QCoreApplication::setApplicationName(QStringLiteral("Alligator")); 0076 0077 KAboutData about(QStringLiteral("alligator"), 0078 i18n("Alligator"), 0079 QStringLiteral(ALLIGATOR_VERSION_STRING), 0080 i18n("Feed Reader"), 0081 KAboutLicense::GPL, 0082 i18n("© 2020-2022 KDE Community")); 0083 about.addAuthor(i18n("Tobias Fella"), QString(), QStringLiteral("fella@posteo.de"), QStringLiteral("https://tobiasfella.de")); 0084 KAboutData::setApplicationData(about); 0085 0086 qmlRegisterType<FeedsModel>("org.kde.alligator", 1, 0, "FeedsModel"); 0087 qmlRegisterType<FeedGroupsModel>("org.kde.alligator", 1, 0, "FeedGroupsModel"); 0088 qmlRegisterType<FeedsProxyModel>("org.kde.alligator", 1, 0, "FeedsProxyModel"); 0089 0090 qmlRegisterType<EntriesModel>("org.kde.alligator", 1, 0, "EntriesModel"); 0091 qmlRegisterType<EntriesProxyModel>("org.kde.alligator", 1, 0, "EntriesProxyModel"); 0092 0093 qmlRegisterSingletonType("org.kde.alligator", 1, 0, "About", [](QQmlEngine *engine, QJSEngine *) -> QJSValue { 0094 return engine->toScriptValue(KAboutData::applicationData()); 0095 }); 0096 0097 AlligatorSettings settings; 0098 qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "Config", &settings); 0099 qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "Fetcher", &Fetcher::instance()); 0100 qmlRegisterSingletonInstance("org.kde.alligator", 1, 0, "Database", &Database::instance()); 0101 0102 QQmlApplicationEngine engine; 0103 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0104 0105 QCommandLineParser parser; 0106 parser.setApplicationDescription(i18n("RSS/Atom Feed Reader")); 0107 QCommandLineOption addFeedOption(QStringList() << QStringLiteral("a") << QStringLiteral("addfeed"), 0108 i18n("Adds a new feed to database."), 0109 i18n("feed URL"), 0110 QStringLiteral("none")); 0111 parser.addOption(addFeedOption); 0112 0113 about.setupCommandLine(&parser); 0114 parser.process(app); 0115 QString feedURL = parser.value(addFeedOption); 0116 if (feedURL != QStringLiteral("none")) 0117 Database::instance().addFeed(feedURL); 0118 about.processCommandLine(&parser); 0119 0120 QObject::connect(&app, &QCoreApplication::aboutToQuit, &settings, &AlligatorSettings::save); 0121 0122 Database::instance(); 0123 0124 engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); 0125 0126 if (engine.rootObjects().isEmpty()) { 0127 return -1; 0128 } 0129 0130 return app.exec(); 0131 }