Commit dce6b631 authored by David Jarvie's avatar David Jarvie
Browse files

Fix startup order for resource classes, to ensure all signals are emitted

parent fc39709e
Pipeline #34485 passed with stage
in 22 minutes and 44 seconds
......@@ -227,12 +227,14 @@ bool KAlarmApp::initialiseTimerResources()
{
qCDebug(KALARM_LOG) << "KAlarmApp::initialise: initialising calendars";
Desktop::setMainWindowFunc(&mainWidget);
DataModel::initialise();
ResourcesCalendar* resourcesCalendar = ResourcesCalendar::create(KALARM_NAME, KALARM_VERSION);
connect(resourcesCalendar, &ResourcesCalendar::earliestAlarmChanged, this, &KAlarmApp::checkNextDueAlarm);
connect(resourcesCalendar, &ResourcesCalendar::atLoginEventAdded, this, &KAlarmApp::atLoginEventAdded);
resourcesCalendar->start();
// First, initialise calendar resources, which need to be ready to
// receive signals when resources initialise.
ResourcesCalendar::initialise(KALARM_NAME, KALARM_VERSION);
connect(ResourcesCalendar::instance(), &ResourcesCalendar::earliestAlarmChanged, this, &KAlarmApp::checkNextDueAlarm);
connect(ResourcesCalendar::instance(), &ResourcesCalendar::atLoginEventAdded, this, &KAlarmApp::atLoginEventAdded);
DisplayCalendar::initialise();
// Finally, initialise the resources which generate signals as they initialise.
DataModel::initialise();
return true;
}
return false;
......
......@@ -614,6 +614,7 @@ void Resources::checkResourcesPopulated()
return;
}
mPopulated = true;
qCDebug(KALARM_LOG) << "Resources::checkResourcesPopulated: emit signal";
Q_EMIT instance()->resourcesPopulated();
}
}
......
......@@ -36,7 +36,10 @@ class Resources : public QObject
{
Q_OBJECT
public:
/** Creates the unique Resources instance. */
/** Creates the unique Resources instance.
* Note that this merely creates a container for individual resources,
* and doesn't create or initialise any ResourceType instances.
*/
static Resources* instance();
~Resources();
......
......@@ -42,20 +42,29 @@ bool ResourcesCalendar::mHaveDisabledAlarms {false};
* different. The resources calendar contains the active alarms, archived alarms
* and alarm templates;
*/
ResourcesCalendar* ResourcesCalendar::create(const QByteArray& appName, const QByteArray& appVersion)
void ResourcesCalendar::initialise(const QByteArray& appName, const QByteArray& appVersion)
{
if (mInstance)
return nullptr;
KACalendar::setProductId(appName, appVersion);
KCalendarCore::CalFormat::setApplication(QString::fromLatin1(appName), QString::fromLatin1(KACalendar::icalProductId()));
mInstance = new ResourcesCalendar();
return mInstance;
if (!mInstance)
{
KACalendar::setProductId(appName, appVersion);
KCalendarCore::CalFormat::setApplication(QString::fromLatin1(appName), QString::fromLatin1(KACalendar::icalProductId()));
mInstance = new ResourcesCalendar();
}
}
/******************************************************************************
* Start resource calendar processing.
* Terminate access to the resource calendars.
*/
void ResourcesCalendar::start()
void ResourcesCalendar::terminate()
{
delete mInstance;
mInstance = nullptr;
}
/******************************************************************************
* Constructor for the resources calendar.
*/
ResourcesCalendar::ResourcesCalendar()
{
Resources* resources = Resources::instance();
connect(resources, &Resources::resourceAdded, this, &ResourcesCalendar::slotResourceAdded);
......@@ -71,22 +80,6 @@ void ResourcesCalendar::start()
slotResourceAdded(resource);
}
/******************************************************************************
* Terminate access to the resource calendars.
*/
void ResourcesCalendar::terminate()
{
delete mInstance;
mInstance = nullptr;
}
/******************************************************************************
* Constructor for the resources calendar.
*/
ResourcesCalendar::ResourcesCalendar()
{
}
ResourcesCalendar::~ResourcesCalendar()
{
// Resource map should be empty, but just in case...
......
......@@ -46,13 +46,7 @@ class ResourcesCalendar : public QObject
Q_OBJECT
public:
~ResourcesCalendar() override;
/** Create the resources calendar, to enable signal/slot connections to be made to it. */
static ResourcesCalendar* create(const QByteArray& appName, const QByteArray& appVersion);
/** Start resource calendar processing. */
void start();
static void initialise(const QByteArray& appName, const QByteArray& appVersion);
static void terminate();
static KAEvent earliestAlarm();
static void setAlarmPending(const KAEvent&, bool pending = true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment