Commit 23eae65d authored by David Jarvie's avatar David Jarvie

Bug 427722: Prevent resources being disabled on logout

parent 118674b7
Pipeline #37776 failed with stage
in 9 minutes and 24 seconds
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
set(PIM_VERSION "5.15.3")
set(PIM_VERSION ${PIM_VERSION})
set(RELEASE_SERVICE_VERSION "20.08.3")
set(KALARM_VERSION "3.0.2")
set(KALARM_VERSION "3.0.3")
project(kalarm VERSION ${KALARM_VERSION})
......
KAlarm Change Log
=== Version 3.0.3 (KDE Applications 20.08.3) --- 15 October 2020 ===
+ Prevent resources being disabled at logout [KDE Bug 427722]
=== Version 3.0.2 (KDE Applications 20.08.2) --- 3 October 2020 ===
+ Fix repeat-at-login alarms not triggering when KAlarm starts.
+ If command generating text for display alarm fails, only display error message,
......
......@@ -135,13 +135,14 @@ FileResourceDataModel::FileResourceDataModel(QObject* parent)
FileResourceDataModel::~FileResourceDataModel()
{
qCDebug(KALARM_LOG) << "FileResourceDataModel::~FileResourceDataModel";
ResourceFilterCheckListModel::disable(); // prevent resources being disabled when they are removed
while (!mResources.isEmpty())
removeResource(mResources.first());
if (mInstance == this)
{
mInstance = nullptr;
mInstanceIsOurs = false;
}
while (!mResources.isEmpty())
removeResource(mResources.first());
delete Resources::instance();
}
......
......@@ -387,7 +387,7 @@ void ResourceCheckListModel::slotRowsInsertedRemoved()
*/
void ResourceCheckListModel::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
{
if (mResetting)
if (mResetting || mDisabled)
return;
const QModelIndexList sel = selected.indexes();
for (const QModelIndex& ix : sel)
......@@ -459,6 +459,8 @@ QByteArray ResourceCheckListModel::debugType(const char* func) const
= Proxy model providing a checkable resource list, filtered to contain only one
= alarm type. The selected alarm type may be changed as desired.
=============================================================================*/
ResourceFilterCheckListModel* ResourceFilterCheckListModel::mInstance {nullptr};
ResourceFilterCheckListModel::ResourceFilterCheckListModel(QObject* parent)
: QSortFilterProxyModel(parent)
{
......@@ -466,6 +468,12 @@ ResourceFilterCheckListModel::ResourceFilterCheckListModel(QObject* parent)
setSortCaseSensitivity(Qt::CaseInsensitive);
}
ResourceFilterCheckListModel::~ResourceFilterCheckListModel()
{
if (this == mInstance)
mInstance = nullptr;
}
void ResourceFilterCheckListModel::init()
{
setEventTypeFilter(CalEvent::ACTIVE); // ensure that sourceModel() is a valid model
......@@ -525,6 +533,16 @@ Resource ResourceFilterCheckListModel::resource(const QModelIndex& index) const
return static_cast<ResourceCheckListModel*>(sourceModel())->resource(mapToSource(index));
}
void ResourceFilterCheckListModel::disable()
{
if (mInstance)
{
mInstance->mActiveModel->disable();
mInstance->mArchivedModel->disable();
mInstance->mTemplateModel->disable();
}
}
QVariant ResourceFilterCheckListModel::data(const QModelIndex& index, int role) const
{
switch (role)
......
......@@ -46,8 +46,8 @@ public:
/** Constructs a new instance.
* @tparam DataModel The data model class to use as the source model. It must
* have the following methods:
* static Model* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
* static Model* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
*/
template <class DataModel>
static ResourceFilterModel* create(QObject* parent = nullptr);
......@@ -106,9 +106,9 @@ class ResourceListModel : public KDescendantsProxyModel
public:
/** Constructs a new instance.
* @tparam DataModel The data model class to use as the source model. It must
* have the following methods:
* static DataModel* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
* have the following methods:
* static DataModel* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
*/
template <class DataModel>
static ResourceListModel* create(QObject* parent = nullptr);
......@@ -144,9 +144,9 @@ class ResourceCheckListModel : public KCheckableProxyModel
public:
/** Constructs a new instance.
* @tparam DataModel The data model class to use as the source model. It must
* have the following methods:
* static DataModel* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
* have the following methods:
* static DataModel* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
*/
template <class DataModel>
static ResourceCheckListModel* create(CalEvent::Type, QObject* parent = nullptr);
......@@ -154,6 +154,7 @@ public:
~ResourceCheckListModel();
Resource resource(int row) const;
Resource resource(const QModelIndex&) const;
void disable() { mDisabled = true; }
QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex&, const QVariant& value, int role) override;
......@@ -176,6 +177,7 @@ private:
CalEvent::Type mAlarmType; // alarm type contained in this model
QItemSelectionModel* mSelectionModel;
bool mResetting {false}; // currently handling rows inserted/removed
bool mDisabled {false}; // resources are being deleted on program exit
};
......@@ -188,19 +190,21 @@ class ResourceFilterCheckListModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
/** Constructs a new instance.
/** Constructs the unique instance.
* @tparam DataModel The data model class to use as the source model. It must
* have the following methods:
* static DataModel* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
* QString tooltip(const Resource&, CalEvent::Types) const;
* have the following methods:
* static DataModel* instance(); - returns the unique instance.
* QModelIndex resourceIndex(const Resource&) const;
* QString tooltip(const Resource&, CalEvent::Types) const;
*/
template <class DataModel>
static ResourceFilterCheckListModel* create(QObject* parent = nullptr);
~ResourceFilterCheckListModel();
void setEventTypeFilter(CalEvent::Type);
Resource resource(int row) const;
Resource resource(const QModelIndex&) const;
static void disable();
QVariant data(const QModelIndex&, int role = Qt::DisplayRole) const override;
protected:
......@@ -217,6 +221,7 @@ private:
explicit ResourceFilterCheckListModel(QObject* parent);
void init();
static ResourceFilterCheckListModel* mInstance;
ResourceCheckListModel* mActiveModel {nullptr};
ResourceCheckListModel* mArchivedModel {nullptr};
ResourceCheckListModel* mTemplateModel {nullptr};
......@@ -279,13 +284,15 @@ ResourceCheckListModel* ResourceCheckListModel::create(CalEvent::Type type, QObj
template <class DataModel>
ResourceFilterCheckListModel* ResourceFilterCheckListModel::create(QObject* parent)
{
ResourceFilterCheckListModel* model = new ResourceFilterCheckListModel(parent);
model->mActiveModel = ResourceCheckListModel::create<DataModel>(CalEvent::ACTIVE, model);
model->mArchivedModel = ResourceCheckListModel::create<DataModel>(CalEvent::ARCHIVED, model);
model->mTemplateModel = ResourceCheckListModel::create<DataModel>(CalEvent::TEMPLATE, model);
model->mTooltipFunction = [](const Resource& r, CalEvent::Types t) { return DataModel::instance()->tooltip(r, t); };
model->init();
return model;
if (mInstance)
return nullptr;
mInstance = new ResourceFilterCheckListModel(parent);
mInstance->mActiveModel = ResourceCheckListModel::create<DataModel>(CalEvent::ACTIVE, mInstance);
mInstance->mArchivedModel = ResourceCheckListModel::create<DataModel>(CalEvent::ARCHIVED, mInstance);
mInstance->mTemplateModel = ResourceCheckListModel::create<DataModel>(CalEvent::TEMPLATE, mInstance);
mInstance->mTooltipFunction = [](const Resource& r, CalEvent::Types t) { return DataModel::instance()->tooltip(r, t); };
mInstance->init();
return mInstance;
}
#endif // RESOURCEMODEL_H
......
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