kasts/src/main.cpp

136 lines
4.8 KiB
C++
Raw Normal View History

2020-02-28 23:25:08 +01:00
/**
2020-08-14 20:56:04 +02:00
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
2021-04-08 13:16:36 +02:00
* SPDX-FileCopyrightText: 2021 Bart De Vries <bart@mogwai.be>
2020-02-28 23:25:08 +01:00
*
2020-08-14 20:56:04 +02:00
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
2020-02-28 23:25:08 +01:00
*/
#include <QCommandLineOption>
2020-05-18 16:47:12 +02:00
#include <QCommandLineParser>
2020-02-28 23:25:08 +01:00
#include <QQmlApplicationEngine>
2020-03-26 14:16:19 +01:00
#include <QQmlContext>
2020-08-17 20:21:56 +02:00
#include <QQuickStyle>
2021-05-01 21:35:37 +02:00
#include <QQuickView>
#include <QString>
#include <QStringList>
2020-03-26 14:16:19 +01:00
2020-10-08 20:52:31 +02:00
#ifdef Q_OS_ANDROID
#include <QGuiApplication>
#else
#include <QApplication>
#endif
2020-03-26 14:16:19 +01:00
#include <KAboutData>
2020-04-21 23:27:15 +02:00
#include <KLocalizedContext>
2020-04-22 02:17:57 +02:00
#include <KLocalizedString>
2020-02-28 23:25:08 +01:00
2021-05-01 21:35:37 +02:00
#include "audiomanager.h"
2020-04-22 02:17:57 +02:00
#include "database.h"
2021-05-01 21:35:37 +02:00
#include "datamanager.h"
#include "downloadprogressmodel.h"
2020-10-09 13:47:35 +02:00
#include "entriesmodel.h"
2021-04-17 22:54:35 +02:00
#include "episodemodel.h"
#include "errorlogmodel.h"
2021-05-01 21:35:37 +02:00
#include "feedsmodel.h"
#include "fetcher.h"
2021-05-28 23:16:35 +02:00
#include "kasts-version.h"
#include "mpris2/mpris2.h"
2021-05-01 21:35:37 +02:00
#include "queuemodel.h"
#include "settingsmanager.h"
2020-02-28 23:25:08 +01:00
2020-04-21 23:27:15 +02:00
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
2020-04-21 23:27:15 +02:00
int main(int argc, char *argv[])
2020-02-28 23:25:08 +01:00
{
2020-04-21 23:27:15 +02:00
#ifdef Q_OS_ANDROID
QGuiApplication app(argc, argv);
2020-08-17 20:21:56 +02:00
QQuickStyle::setStyle(QStringLiteral("Material"));
2020-04-21 23:27:15 +02:00
#else
2020-02-28 23:25:08 +01:00
QApplication app(argc, argv);
2021-05-28 23:16:35 +02:00
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
2021-04-18 16:55:03 +02:00
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
}
#endif
#ifdef Q_OS_WINDOWS
if (AttachConsole(ATTACH_PARENT_PROCESS)) {
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
QApplication::setStyle(QStringLiteral("breeze"));
auto font = app.font();
font.setPointSize(10);
app.setFont(font);
2020-04-21 23:27:15 +02:00
#endif
2020-02-28 23:25:08 +01:00
QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
2021-05-03 22:16:19 +02:00
QCoreApplication::setApplicationName(QStringLiteral("Kasts"));
2020-02-28 23:25:08 +01:00
QQmlApplicationEngine engine;
2020-04-21 23:27:15 +02:00
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
2021-05-03 22:16:19 +02:00
KLocalizedString::setApplicationDomain("kasts");
2020-02-28 23:25:08 +01:00
2020-05-11 21:13:27 +02:00
QCommandLineParser parser;
2021-05-28 22:16:14 +02:00
parser.setApplicationDescription(i18n("Podcast Application"));
2021-05-28 23:16:35 +02:00
QCommandLineOption addFeedOption(QStringList() << QStringLiteral("a") << QStringLiteral("add"),
i18n("Adds a new podcast to subscriptions."),
i18n("Podcast URL"),
QStringLiteral("none"));
parser.addOption(addFeedOption);
2020-05-11 21:13:27 +02:00
2021-05-03 22:16:19 +02:00
KAboutData about(QStringLiteral("kasts"),
i18n("Kasts"),
QStringLiteral(KASTS_VERSION_STRING),
2021-05-11 12:57:57 +02:00
i18n("Podcast Player"),
2021-05-01 21:35:37 +02:00
KAboutLicense::GPL,
i18n("© 2020-2021 KDE Community"));
2020-04-15 21:21:08 +02:00
about.addAuthor(i18n("Tobias Fella"), QString(), QStringLiteral("fella@posteo.de"));
about.addAuthor(i18n("Bart De Vries"), QString(), QStringLiteral("bart@mogwai.be"));
2020-03-26 14:16:19 +01:00
KAboutData::setApplicationData(about);
2020-06-01 01:11:21 +02:00
about.setupCommandLine(&parser);
parser.process(app);
QString feedURL = parser.value(addFeedOption);
2021-05-28 23:16:35 +02:00
if (feedURL != QStringLiteral("none")) {
Database::instance();
DataManager::instance().addFeed(feedURL);
}
2020-06-01 01:11:21 +02:00
about.processCommandLine(&parser);
2020-03-26 14:16:19 +01:00
engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(about));
2021-05-03 22:16:19 +02:00
qmlRegisterType<FeedsModel>("org.kde.kasts", 1, 0, "FeedsModel");
qmlRegisterType<QueueModel>("org.kde.kasts", 1, 0, "QueueModel");
qmlRegisterType<EpisodeModel>("org.kde.kasts", 1, 0, "EpisodeModel");
qmlRegisterType<Mpris2>("org.kde.kasts", 1, 0, "Mpris2");
qmlRegisterUncreatableType<EntriesModel>("org.kde.kasts", 1, 0, "EntriesModel", QStringLiteral("Get from Feed"));
qmlRegisterUncreatableType<Enclosure>("org.kde.kasts", 1, 0, "Enclosure", QStringLiteral("Only for enums"));
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "Fetcher", &Fetcher::instance());
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "Database", &Database::instance());
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "DataManager", &DataManager::instance());
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "SettingsManager", SettingsManager::self());
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "DownloadProgressModel", &DownloadProgressModel::instance());
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "ErrorLogModel", &ErrorLogModel::instance());
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "AudioManager", &AudioManager::instance());
qRegisterMetaType<Entry *>("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);
2020-02-28 23:25:08 +01:00
engine.load(QUrl(QStringLiteral("qrc:///main.qml")));
if (engine.rootObjects().isEmpty()) {
return -1;
}
return app.exec();
}