File indexing completed on 2024-05-12 05:13:14

0001 /*
0002   SPDX-FileCopyrightText: 2013 Sérgio Martins <iamsergio@gmail.com>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
0005 */
0006 
0007 #include "calendarsingleton.h"
0008 #include "kcalprefs.h"
0009 
0010 #include <KCalendarCore/Person>
0011 
0012 /**
0013  * Singleton is implemented through qApp parenting because we can't rely on K_GLOBAL_STATIC.
0014  *
0015  * QWidgets and QAbstractItemModels can't be global because their dtor depends on other globals
0016  * and the order of global destruction is undefined.
0017  */
0018 Akonadi::ETMCalendar::Ptr CalendarSupport::calendarSingleton(bool createIfNull)
0019 {
0020     static Akonadi::ETMCalendar::Ptr calendar;
0021 
0022     if (!calendar && createIfNull) {
0023         calendar = Akonadi::ETMCalendar::Ptr(new Akonadi::ETMCalendar());
0024         calendar->setCollectionFilteringEnabled(false);
0025         calendar->setOwner(KCalendarCore::Person(KCalPrefs::instance()->fullName(), KCalPrefs::instance()->email()));
0026     }
0027 
0028     return calendar;
0029 }