File indexing completed on 2024-11-24 04:50:42

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #include "../config-merkuro.h"
0005 #include <KAboutData>
0006 #include <KDBusService>
0007 #include <KLocalizedContext>
0008 #include <KLocalizedString>
0009 #include <KWindowSystem>
0010 #include <QApplication>
0011 #include <QCommandLineParser>
0012 #include <QIcon>
0013 #include <QQmlApplicationEngine>
0014 #include <QQmlContext>
0015 #include <QQuickStyle>
0016 #include <QQuickWindow>
0017 
0018 static void raiseWindow(QWindow *window)
0019 {
0020     KWindowSystem::updateStartupId(window);
0021     KWindowSystem::activateWindow(window);
0022 }
0023 
0024 int main(int argc, char *argv[])
0025 {
0026     QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
0027     QApplication app(argc, argv);
0028     KLocalizedString::setApplicationDomain(QByteArrayLiteral("merkuro"));
0029     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
0030     QCoreApplication::setApplicationName(QStringLiteral("Merkuro Contact"));
0031 
0032     // Default to org.kde.desktop style unless the user forces another style
0033     if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
0034         QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
0035     }
0036 
0037 #if defined(Q_OS_WIN) || defined(Q_OS_MAC)
0038     QApplication::setStyle(QStringLiteral("breeze"));
0039 #endif
0040 
0041     KAboutData aboutData(
0042         // The program name used internally.
0043         QStringLiteral("merkuro.contact"),
0044         // A displayable program name string.
0045         i18nc("@title", "Merkuro Contact"),
0046         QStringLiteral(MERKURO_VERSION_STRING),
0047         // Short description of what the app does.
0048         i18n("Address Book Application"),
0049         // The license this code is released under.
0050         KAboutLicense::GPL_V3,
0051         // Copyright Statement.
0052         i18n("(c) KDE Community 2021"));
0053     aboutData.setBugAddress("https://bugs.kde.org/enter_bug.cgi?format=guided&product=merkuro&version=" + QStringLiteral(MERKURO_VERSION_STRING).toUtf8());
0054     aboutData.addAuthor(i18nc("@info:credit", "Carl Schwan"),
0055                         i18nc("@info:credit", "Maintainer"),
0056                         QStringLiteral("carl@carlschwan.eu"),
0057                         QStringLiteral("https://carlschwan.eu"));
0058     aboutData.addAuthor(i18nc("@info:credit", "Clau Cambra"),
0059                         i18nc("@info:credit", "Maintainer"),
0060                         QStringLiteral("claudio.cambra@gmail.com"),
0061                         QStringLiteral("https://claudiocambra.com"));
0062     KAboutData::setApplicationData(aboutData);
0063     QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.merkuro.contact")));
0064 
0065     QCommandLineParser parser;
0066     aboutData.setupCommandLine(&parser);
0067     parser.process(app);
0068     aboutData.processCommandLine(&parser);
0069 
0070     KDBusService service(KDBusService::Unique);
0071 
0072     QQmlApplicationEngine engine;
0073     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0074     engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
0075 
0076     QObject::connect(&service, &KDBusService::activateRequested, &engine, [&engine](const QStringList & /*arguments*/, const QString & /*workingDirectory*/) {
0077         const auto rootObjects = engine.rootObjects();
0078         for (auto obj : rootObjects) {
0079             auto view = qobject_cast<QQuickWindow *>(obj);
0080             if (view) {
0081                 raiseWindow(view);
0082                 return;
0083             }
0084         }
0085     });
0086 
0087     if (engine.rootObjects().isEmpty()) {
0088         return -1;
0089     }
0090 
0091     return app.exec();
0092 }