File indexing completed on 2024-05-12 05:21:23
0001 /* 0002 This file is part of KOrganizer. 0003 0004 SPDX-FileCopyrightText: 2001, 2003 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0008 */ 0009 0010 #include "kocore.h" 0011 #include "prefs/koprefs.h" 0012 0013 #include <KPluginFactory> 0014 0015 #include <CalendarSupport/IdentityManager> 0016 0017 #include "korganizer_debug.h" 0018 0019 #include <QDBusConnectionInterface> 0020 0021 KOCore *KOCore::mSelf = nullptr; 0022 0023 KOCore *KOCore::self() 0024 { 0025 if (!mSelf) { 0026 mSelf = new KOCore; 0027 } 0028 0029 return mSelf; 0030 } 0031 0032 KOCore::KOCore() 0033 { 0034 // fallback reminder daemon startup 0035 // this should be started by autostart and session management already under normal 0036 // circumstances, but another safety net doesn't hurt 0037 QDBusConnection::sessionBus().interface()->startService(QStringLiteral("org.kde.kalendarac")); 0038 } 0039 0040 KOCore::~KOCore() 0041 { 0042 mSelf = nullptr; 0043 } 0044 0045 QList<KPluginMetaData> KOCore::availableCalendarDecorations() 0046 { 0047 return KPluginMetaData::findPlugins(QStringLiteral("pim6/korganizer")); 0048 } 0049 0050 EventViews::CalendarDecoration::Decoration *KOCore::loadCalendarDecoration(const KPluginMetaData &service) 0051 { 0052 return KPluginFactory::instantiatePlugin<EventViews::CalendarDecoration::Decoration>(service).plugin; 0053 } 0054 0055 void KOCore::addXMLGUIClient(QWidget *wdg, KXMLGUIClient *guiclient) 0056 { 0057 mXMLGUIClients.insert(wdg, guiclient); 0058 } 0059 0060 void KOCore::removeXMLGUIClient(QWidget *wdg) 0061 { 0062 mXMLGUIClients.remove(wdg); 0063 } 0064 0065 KXMLGUIClient *KOCore::xmlguiClient(QWidget *wdg) const 0066 { 0067 if (!wdg) { 0068 return nullptr; 0069 } 0070 0071 QWidget *topLevel = wdg->topLevelWidget(); 0072 QMap<QWidget *, KXMLGUIClient *>::ConstIterator it = mXMLGUIClients.find(topLevel); 0073 if (it != mXMLGUIClients.constEnd()) { 0074 return it.value(); 0075 } 0076 0077 return nullptr; 0078 } 0079 0080 EventViews::CalendarDecoration::Decoration::List KOCore::loadCalendarDecorations() 0081 { 0082 if (!mCalendarDecorationsLoaded) { 0083 const QStringList selectedPlugins = KOPrefs::instance()->mSelectedPlugins; 0084 0085 mCalendarDecorations.clear(); 0086 const QList<KPluginMetaData> plugins = availableCalendarDecorations(); 0087 for (const auto &plugin : plugins) { 0088 QString name = plugin.pluginId(); 0089 if (selectedPlugins.contains(name)) { 0090 EventViews::CalendarDecoration::Decoration *d = loadCalendarDecoration(plugin); 0091 mCalendarDecorations.append(d); 0092 } 0093 } 0094 mCalendarDecorationsLoaded = true; 0095 } 0096 0097 return mCalendarDecorations; 0098 } 0099 0100 void KOCore::unloadPlugins() 0101 { 0102 qDeleteAll(mCalendarDecorations); 0103 mCalendarDecorations.clear(); 0104 mCalendarDecorationsLoaded = false; 0105 } 0106 0107 void KOCore::reloadPlugins() 0108 { 0109 // TODO: does this still apply? 0110 // Plugins should be unloaded, but e.g. komonthview keeps using the old ones 0111 unloadPlugins(); 0112 loadCalendarDecorations(); 0113 } 0114 0115 KIdentityManagementCore::IdentityManager *KOCore::identityManager() 0116 { 0117 return CalendarSupport::IdentityManager::self(); 0118 }