Commit 975e4072 authored by David Jarvie's avatar David Jarvie
Browse files

Remove duplicate calls to FileResourceDataModel::addResource()

addResource(), which is potentially calculation intensive, was
called twice every time a resource was newly enabled.
parent 58afa2b6
Pipeline #84193 passed with stage
in 11 minutes and 41 seconds
......@@ -106,22 +106,14 @@ void FileResource::setEnabled(CalEvent::Type type, bool enabled)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setEnabled(type, enabled);
if (changes)
{
handleSettingsChange(changes);
Resources::notifySettingsChanged(this, changes, oldEnabled);
}
handleEnabledChange(changes, oldEnabled);
}
void FileResource::setEnabled(CalEvent::Types types)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setEnabled(types);
if (changes)
{
handleSettingsChange(changes);
Resources::notifySettingsChanged(this, changes, oldEnabled);
}
handleEnabledChange(changes, oldEnabled);
}
bool FileResource::readOnly() const
......@@ -132,7 +124,7 @@ bool FileResource::readOnly() const
void FileResource::setReadOnly(bool ronly)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setReadOnly(ronly);
Changes changes = mSettings->setReadOnly(ronly);
if (changes)
{
handleSettingsChange(changes);
......@@ -172,7 +164,7 @@ bool FileResource::keepFormat() const
void FileResource::setKeepFormat(bool keep)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setKeepFormat(keep);
Changes changes = mSettings->setKeepFormat(keep);
if (changes)
{
handleSettingsChange(changes);
......@@ -188,7 +180,7 @@ QColor FileResource::backgroundColour() const
void FileResource::setBackgroundColour(const QColor& colour)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setBackgroundColour(colour);
Changes changes = mSettings->setBackgroundColour(colour);
if (changes)
{
handleSettingsChange(changes);
......@@ -209,7 +201,7 @@ CalEvent::Types FileResource::configStandardTypes() const
void FileResource::configSetStandard(CalEvent::Type type, bool standard)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setStandard(type, standard);
Changes changes = mSettings->setStandard(type, standard);
if (changes)
{
handleSettingsChange(changes);
......@@ -220,7 +212,7 @@ void FileResource::configSetStandard(CalEvent::Type type, bool standard)
void FileResource::configSetStandard(CalEvent::Types types)
{
const CalEvent::Types oldEnabled = mSettings->enabledTypes();
const Changes changes = mSettings->setStandard(types);
Changes changes = mSettings->setStandard(types);
if (changes)
{
handleSettingsChange(changes);
......@@ -266,9 +258,9 @@ void FileResource::editResource(QWidget* dialogParent)
// Note that the location and alarm type cannot be changed.
qCDebug(KALARM_LOG) << "FileResource::editResource: Edited" << dlg->displayName();
setReadOnly(dlg->readOnly());
const Changes change = mSettings->setDisplayName(dlg->displayName());
if (change != NoChange)
Resources::notifySettingsChanged(this, change, enabled);
Changes changes = mSettings->setDisplayName(dlg->displayName());
if (changes != NoChange)
Resources::notifySettingsChanged(this, changes, enabled);
}
break;
}
......@@ -644,15 +636,15 @@ KACalendar::Compat FileResource::getCompatibility(const KCalendarCore::FileStora
/******************************************************************************
* Called when the resource settings have changed.
*/
void FileResource::handleSettingsChange(Changes change)
void FileResource::handleSettingsChange(Changes& changes)
{
qCDebug(KALARM_LOG) << "FileResource::handleSettingsChange:" << displayId();
if (change & AlarmTypes)
if (changes & AlarmTypes)
{
qCDebug(KALARM_LOG) << "FileResource::handleSettingsChange:" << displayId() << "Update alarm types";
load();
}
if (change & Enabled)
if (changes & Enabled)
{
qCDebug(KALARM_LOG) << "FileResource::handleSettingsChange:" << displayId() << "Update enabled status";
if (mSettings->enabledTypes())
......@@ -663,8 +655,21 @@ void FileResource::handleSettingsChange(Changes change)
// are updated. Also, when the calendar is loaded, disabled alarm
// types are not fully processed by loaded().
load();
changes |= Loaded;
}
}
}
/******************************************************************************
* Called when the resource settings have changed.
*/
void FileResource::handleEnabledChange(Changes changes, CalEvent::Types oldEnabled)
{
if (changes)
{
handleSettingsChange(changes);
Resources::notifySettingsChanged(this, changes, oldEnabled);
}
}
// vim: et sw=4:
......@@ -375,7 +375,7 @@ protected:
* @note Resources::notifySettingsChanged() is called after this, to
* notify clients.
*/
virtual void handleSettingsChange(Changes);
virtual void handleSettingsChange(Changes&);
FileResourceSettings* mSettings; // the resource's configuration
int mVersion {KACalendar::IncompatibleFormat}; // the calendar format version
......@@ -386,6 +386,9 @@ typedef QHash<const QString&, KACalendar::Compat> CompatibilityMap; // indexed
CompatibilityMap mCompatibilityMap; // whether individual events are in compatible format
*/
Status mStatus {Status::NotConfigured}; // current status of resource
private:
void handleEnabledChange(Changes changes, CalEvent::Types oldEnabled);
};
......
/*
* fileresourcedatamodel.cpp - model containing file system resources and their events
* Program: kalarm
* SPDX-FileCopyrightText: 2007-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2007-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -410,14 +410,19 @@ void FileResourceDataModel::slotResourceLoaded(Resource& resource)
/******************************************************************************
* Called when a resource setting has changed.
*/
void FileResourceDataModel::slotResourceSettingsChanged(Resource& res, ResourceType::Changes change)
void FileResourceDataModel::slotResourceSettingsChanged(Resource& res, ResourceType::Changes changes)
{
if (change & ResourceType::Enabled)
if (changes & ResourceType::Enabled)
{
if (res.enabledTypes())
{
qCDebug(KALARM_LOG) << "FileResourceDataModel::slotResourceSettingsChanged: Enabled" << res.displayName();
addResource(res);
// If the resource has just been loaded, addResource() will already
// have been called, so don't call it again.
if (!(changes & ResourceType::Loaded))
{
qCDebug(KALARM_LOG) << "FileResourceDataModel::slotResourceSettingsChanged: Enabled" << res.displayName();
addResource(res);
}
}
else
{
......@@ -425,14 +430,14 @@ void FileResourceDataModel::slotResourceSettingsChanged(Resource& res, ResourceT
removeResourceEvents(res);
}
}
if (change & (ResourceType::Name | ResourceType::Standard | ResourceType::ReadOnly))
if (changes & (ResourceType::Name | ResourceType::Standard | ResourceType::ReadOnly))
{
qCDebug(KALARM_LOG) << "FileResourceDataModel::slotResourceSettingsChanged:" << res.displayName();
const QModelIndex resourceIx = resourceIndex(res);
if (resourceIx.isValid())
Q_EMIT dataChanged(resourceIx, resourceIx);
}
if (change & ResourceType::BackgroundColour)
if (changes & ResourceType::BackgroundColour)
{
qCDebug(KALARM_LOG) << "FileResourceDataModel::slotResourceSettingsChanged: Colour" << res.displayName();
const QVector<Node*>& eventNodes = mResourceNodes.value(res);
......@@ -441,7 +446,7 @@ void FileResourceDataModel::slotResourceSettingsChanged(Resource& res, ResourceT
Q_EMIT dataChanged(createIndex(0, 0, eventNodes[0]), createIndex(lastRow, ColumnCount - 1, eventNodes[lastRow]));
}
// if (change & (ResourceType::AlarmTypes | ResourceType::KeepFormat | ResourceType::UpdateFormat))
// if (changes & (ResourceType::AlarmTypes | ResourceType::KeepFormat | ResourceType::UpdateFormat))
// qCDebug(KALARM_LOG) << "FileResourceDataModel::slotResourceSettingsChanged: UNHANDLED" << res.displayName();
}
......
......@@ -426,8 +426,6 @@ void Resources::notifySettingsChanged(ResourceType* res, ResourceType::Changes c
if (change & ResourceType::Enabled)
{
ResourceType::Changes change = ResourceType::Enabled;
// Find which alarm types (if any) have been newly enabled.
const CalEvent::Types extra = res->enabledTypes() & ~oldEnabled;
CalEvent::Types std = res->configStandardTypes();
......@@ -456,6 +454,8 @@ void Resources::notifySettingsChanged(ResourceType* res, ResourceType::Changes c
}
if (std)
change |= ResourceType::Standard;
if (res->enabledTypes() == oldEnabled)
change &= ~ResourceType::Enabled;
}
Q_EMIT manager->settingsChanged(r, change);
......
......@@ -53,7 +53,9 @@ public:
ReadOnly = 0x10, //!< The resource's read-only setting.
KeepFormat = 0x20, //!< Whether the user has chosen not to convert to the current KAlarm format.
UpdateFormat = 0x40, //!< The resource should now be converted to the current KAlarm format.
BackgroundColour = 0x80 //!< The background colour to display the resource.
BackgroundColour = 0x80, //!< The background colour to display the resource.
// Non-status types...
Loaded = 0x100 //!< The resource has been loaded from file. Note that this is an event notification type, not a status type.
};
Q_DECLARE_FLAGS(Changes, Change)
......
......@@ -2,7 +2,7 @@
* singlefileresource.cpp - calendar resource held in a single file
* Program: kalarm
* Partly based on ICalResourceBase and SingleFileResource in kdepim-runtime.
* SPDX-FileCopyrightText: 2009-2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2009-2021 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2008 Bertjan Broeksema <broeksema@kde.org>
* SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@kde.org>
* SPDX-FileCopyrightText: 2006 Till Adam <adam@kde.org>
......@@ -758,10 +758,10 @@ void SingleFileResource::slotUploadJobResult(KJob* job)
/******************************************************************************
* Called when the resource settings have changed.
*/
void SingleFileResource::handleSettingsChange(Changes change)
void SingleFileResource::handleSettingsChange(Changes& changes)
{
qCDebug(KALARM_LOG) << "SingleFileResource::handleSettingsChange:" << displayId();
if (change & UpdateFormat)
if (changes & UpdateFormat)
{
if (mSettings->updateFormat())
{
......@@ -799,7 +799,7 @@ void SingleFileResource::handleSettingsChange(Changes change)
mSettings->save();
}
}
FileResource::handleSettingsChange(change);
FileResource::handleSettingsChange(changes);
}
// vim: et sw=4:
/*
* singlefileresource.h - calendar resource held in a single file
* Program: kalarm
* SPDX-FileCopyrightText: 2020 David Jarvie <djarvie@kde.org>
* SPDX-FileCopyrightText: 2020-2021 David Jarvie <djarvie@kde.org>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
......@@ -169,7 +169,7 @@ protected:
* @note Resources::notifySettingsChanged() is called after this, to
* notify clients.
*/
void handleSettingsChange(Changes) override;
void handleSettingsChange(Changes&) override;
/**
* Generates the full path for the cache file in the case that a remote file
......
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