File indexing completed on 2024-11-24 04:50:44
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 "messagehandler.h" 0006 #include <KAboutData> 0007 #include <KDBusService> 0008 #include <KLocalizedContext> 0009 #include <KLocalizedString> 0010 #include <KWindowSystem> 0011 #include <QApplication> 0012 #include <QCommandLineParser> 0013 #include <QDir> 0014 #include <QIcon> 0015 #include <QQmlApplicationEngine> 0016 #include <QQmlContext> 0017 #include <QQuickStyle> 0018 #include <QQuickWindow> 0019 0020 static void raiseWindow(QWindow *window) 0021 { 0022 KWindowSystem::updateStartupId(window); 0023 KWindowSystem::activateWindow(window); 0024 } 0025 0026 int main(int argc, char *argv[]) 0027 { 0028 QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts); 0029 QApplication app(argc, argv); 0030 KLocalizedString::setApplicationDomain(QByteArrayLiteral("merkuro")); 0031 QCoreApplication::setOrganizationName(QStringLiteral("KDE")); 0032 QCoreApplication::setApplicationName(QStringLiteral("Merkuro Mail")); 0033 0034 // Default to org.kde.desktop style unless the user forces another style 0035 if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) { 0036 QQuickStyle::setStyle(QStringLiteral("org.kde.desktop")); 0037 } 0038 0039 #if defined(Q_OS_WIN) || defined(Q_OS_MAC) 0040 QApplication::setStyle(QStringLiteral("breeze")); 0041 #endif 0042 0043 KAboutData aboutData( 0044 // The program name used internally. 0045 QStringLiteral("merkuro.mail"), 0046 // A displayable program name string. 0047 i18nc("@title", "Merkuro Mail"), 0048 QStringLiteral(MERKURO_VERSION_STRING), 0049 // Short description of what the app does. 0050 i18n("Email Client"), 0051 // The license this code is released under. 0052 KAboutLicense::GPL_V3, 0053 // Copyright Statement. 0054 i18n("(c) KDE Community 2021")); 0055 aboutData.setBugAddress("https://bugs.kde.org/enter_bug.cgi?format=guided&product=merkuro&version=" + QStringLiteral(MERKURO_VERSION_STRING).toUtf8()); 0056 aboutData.addAuthor(i18nc("@info:credit", "Carl Schwan"), 0057 i18nc("@info:credit", "Maintainer"), 0058 QStringLiteral("carl@carlschwan.eu"), 0059 QStringLiteral("https://carlschwan.eu")); 0060 aboutData.addAuthor(i18nc("@info:credit", "Clau Cambra"), 0061 i18nc("@info:credit", "Maintainer"), 0062 QStringLiteral("claudio.cambra@gmail.com"), 0063 QStringLiteral("https://claudiocambra.com")); 0064 KAboutData::setApplicationData(aboutData); 0065 QGuiApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("org.kde.merkuro.mail"))); 0066 0067 QCommandLineParser parser; 0068 aboutData.setupCommandLine(&parser); 0069 parser.process(app); 0070 aboutData.processCommandLine(&parser); 0071 0072 KDBusService service(KDBusService::Unique); 0073 0074 const auto options = parser.optionNames(); 0075 const auto args = parser.positionalArguments(); 0076 QQmlApplicationEngine engine; 0077 engine.rootContext()->setContextObject(new KLocalizedContext(&engine)); 0078 if (args.length() > 0) { 0079 qmlRegisterType<MessageHandler>("org.kde.merkuro.mail.desktop", 1, 0, "MessageHandler"); 0080 QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit); 0081 engine.load(QUrl(QStringLiteral("qrc:/qml/desktopactions/openmbox.qml"))); 0082 const auto rootObjects = engine.rootObjects(); 0083 if (rootObjects.isEmpty()) { 0084 return -1; 0085 } 0086 parser.process(app); 0087 0088 const QStringList args = parser.positionalArguments(); 0089 for (auto obj : rootObjects) { 0090 auto view = qobject_cast<QQuickWindow *>(obj); 0091 auto messageHandler = view->findChild<MessageHandler *>(QStringLiteral("MessageHandler")); 0092 const auto file = QUrl::fromUserInput(args.at(args.count() - 1), QDir::currentPath()); 0093 messageHandler->open(file); 0094 } 0095 } else { 0096 engine.load(QUrl(QStringLiteral("qrc:/qml/app/main.qml"))); 0097 0098 QObject::connect(&service, 0099 &KDBusService::activateRequested, 0100 &engine, 0101 [&engine](const QStringList & /*arguments*/, const QString & /*workingDirectory*/) { 0102 const auto rootObjects = engine.rootObjects(); 0103 for (auto obj : rootObjects) { 0104 auto view = qobject_cast<QQuickWindow *>(obj); 0105 if (view) { 0106 raiseWindow(view); 0107 return; 0108 } 0109 } 0110 }); 0111 } 0112 0113 if (engine.rootObjects().isEmpty()) { 0114 return -1; 0115 } 0116 0117 return app.exec(); 0118 }