File indexing completed on 2024-04-28 05:50:31
0001 /* 0002 * Copyright 2019 Eike Hein <hein@kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU General Public License as 0006 * published by the Free Software Foundation; either version 2 of 0007 * the License or (at your option) version 3 or any later version 0008 * accepted by the membership of KDE e.V. (or its successor approved 0009 * by the membership of KDE e.V.), which shall act as a proxy 0010 * defined in Section 14 of version 3 of the license. 0011 * 0012 * This program is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include "autosettingshandler.h" 0022 #include "gstreamer/gstreamerintegration.h" 0023 #include "permissions.h" 0024 #include "settings.h" 0025 0026 // Remove warnings related to gstreamer library 0027 #ifdef __GNUC__ 0028 #pragma GCC diagnostic push 0029 #pragma GCC diagnostic ignored "-Wold-style-cast" 0030 #else 0031 #pragma warning(push, 0) 0032 #endif 0033 #include <gst/gst.h> 0034 #ifdef __GNUC__ 0035 #pragma GCC diagnostic pop 0036 #else 0037 #pragma warning(pop, 0) 0038 #endif 0039 0040 #include <KAboutData> 0041 #ifndef Q_OS_ANDROID 0042 #include <KCrash> 0043 #endif 0044 #include <KLocalizedContext> 0045 #include <KLocalizedString> 0046 0047 #ifdef Q_OS_ANDROID 0048 #include <QGuiApplication> 0049 #include <QtAndroid> 0050 #else 0051 #include <QApplication> 0052 #endif 0053 0054 #include <QCommandLineParser> 0055 #include <QIcon> 0056 #include <QQmlApplicationEngine> 0057 #include <QQmlContext> 0058 #include <QQmlEngine> 0059 #include <QQuickView> 0060 0061 #ifdef Q_OS_ANDROID 0062 extern "C" gboolean gst_qt_android_init(GError **error); 0063 0064 Q_DECL_EXPORT 0065 #endif 0066 int main(int argc, char *argv[]) 0067 { 0068 int ret; 0069 0070 #ifndef Q_OS_ANDROID 0071 gst_init(&argc, &argv); 0072 #else 0073 if (!gst_qt_android_init(nullptr)) { 0074 return -1; 0075 } 0076 #endif 0077 GStreamerIntegration::init(); 0078 0079 QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 0080 0081 #ifdef Q_OS_ANDROID 0082 QGuiApplication app(argc, argv); 0083 #else 0084 QApplication app(argc, argv); 0085 #endif 0086 0087 KLocalizedString::setApplicationDomain("kirogi"); 0088 0089 KAboutData aboutData(QStringLiteral("kirogi"), 0090 xi18nc("@title", "<application>Kirogi</application>"), 0091 QStringLiteral("0.1-dev"), 0092 xi18nc("@title", "A ground control application for drones."), 0093 KAboutLicense::GPL, 0094 xi18nc("@info:credit", "(c) 2019 The Kirogi Team"), 0095 QString(), 0096 QStringLiteral("https://www.kirogi.org/")); 0097 0098 aboutData.setOrganizationDomain(QByteArray("kde.org")); 0099 aboutData.setProductName(QByteArray("kirogi")); 0100 0101 aboutData.addAuthor(xi18nc("@info:credit", "Eike Hein"), xi18nc("@info:credit", "Founder, Lead Developer"), QStringLiteral("hein@kde.org")); 0102 0103 aboutData.addAuthor(xi18nc("@info:credit", "Patrick José Pereira"), xi18nc("@info:credit", "Developer"), QStringLiteral("patrickjp@kde.org")); 0104 0105 aboutData.addAuthor(xi18nc("@info:credit", "Rafael Brandmaier"), 0106 xi18nc("@info:credit", "Application icon"), 0107 QStringLiteral("rafael.brandmaier@kdemail.net")); 0108 0109 aboutData.addAuthor(xi18nc("@info:credit", "L. 'AsmoArael' C."), xi18nc("@info:credit", "Mascot artwork"), QStringLiteral("lc.jarryh99@outlook.fr")); 0110 0111 KAboutData::setApplicationData(aboutData); 0112 QCommandLineParser parser; 0113 parser.addHelpOption(); 0114 parser.addVersionOption(); 0115 0116 aboutData.setupCommandLine(&parser); 0117 parser.process(app); 0118 aboutData.processCommandLine(&parser); 0119 0120 app.setApplicationName(aboutData.componentName()); 0121 app.setApplicationDisplayName(aboutData.displayName()); 0122 app.setOrganizationDomain(aboutData.organizationDomain()); 0123 app.setApplicationVersion(aboutData.version()); 0124 app.setWindowIcon(QIcon::fromTheme(QStringLiteral("kirogi"))); 0125 0126 #ifndef Q_OS_ANDROID 0127 KCrash::initialize(); 0128 #endif 0129 0130 QQmlApplicationEngine engine(&app); 0131 AutoSettingsHandler settingsHandler; 0132 settingsHandler.addSettings(Settings::self()); 0133 0134 /* Add relative path to import paths to cover the case when the application 0135 * is not installed in the system. */ 0136 engine.addImportPath(QCoreApplication::applicationDirPath() + "/../lib/qml"); 0137 0138 // For i18n. 0139 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0140 0141 engine.rootContext()->setContextProperty(QStringLiteral("kirogiAboutData"), QVariant::fromValue(aboutData)); 0142 0143 engine.rootContext()->setContextProperty(QStringLiteral("kirogiSettings"), Settings::self()); 0144 0145 engine.rootContext()->setContextProperty( 0146 QStringLiteral("locationPermissions"), 0147 QVariant::fromValue( 0148 new Permissions({QStringLiteral("android.permission.ACCESS_COARSE_LOCATION"), QStringLiteral("android.permission.ACCESS_FINE_LOCATION")}, &app))); 0149 0150 engine.load(QUrl(QStringLiteral("qrc:///main.qml"))); 0151 0152 if (engine.rootObjects().isEmpty()) { 0153 qCritical() << "Application failed to load."; 0154 return -1; 0155 } 0156 0157 #ifdef Q_OS_ANDROID 0158 QtAndroid::hideSplashScreen(); 0159 #endif 0160 0161 ret = app.exec(); 0162 return ret; 0163 }