File indexing completed on 2024-05-26 05:38:21

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 #include "applicationintegration.h"
0005 #include <KApplicationTrader>
0006 #include <KIO/ApplicationLauncherJob>
0007 
0008 ApplicationIntegration::ApplicationIntegration(QObject *parent)
0009     : QObject(parent)
0010 {
0011     const auto services = KApplicationTrader::queryByMimeType(QStringLiteral("text/calendar"));
0012 
0013     if (!services.isEmpty()) {
0014         const KService::Ptr app = services.first();
0015 
0016         if (app->desktopEntryName() == QLatin1String("org.kde.korganizer") || app->desktopEntryName() == QLatin1String("org.kde.kalendar")) {
0017             m_calendarService = app;
0018         }
0019     }
0020 }
0021 
0022 bool ApplicationIntegration::calendarInstalled() const
0023 {
0024     return m_calendarService != nullptr;
0025 }
0026 
0027 void ApplicationIntegration::launchCalendar() const
0028 {
0029     Q_ASSERT(m_calendarService);
0030 
0031     auto job = new KIO::ApplicationLauncherJob(m_calendarService);
0032     job->start();
0033 }