Commit 3a68fb8c authored by David Jarvie's avatar David Jarvie
Browse files

Fix alarm list not updating when collection is enabled/disabled

parent ac925456
......@@ -2,6 +2,7 @@
#warning Update a calendar format, enable the calendar, copy old version on top -> crash
#warning Add a directory resource containing 2 alarm types, right click on it -> crash
#warning Set default template calendar to read-only -> crash
#warning Set default archived calendar to read-only, then read-write -> now "other format"
#endif
/*
* akonadimodel.cpp - KAlarm calendar file access using Akonadi
......@@ -185,6 +186,7 @@ QVariant AkonadiModel::data(const QModelIndex& index, int role) const
case AlarmActionsRole:
case AlarmActionRole:
case EnabledRole:
case EnabledTypesRole:
case CommandErrorRole:
case BaseColourRole:
case AlarmTypeRole:
......@@ -202,7 +204,7 @@ QVariant AkonadiModel::data(const QModelIndex& index, int role) const
{
case Qt::DisplayRole:
return displayName_p(collection);
case EnabledRole:
case EnabledTypesRole:
if (!collection.hasAttribute<CollectionAttribute>())
return 0;
return static_cast<int>(collection.attribute<CollectionAttribute>()->enabled());
......@@ -513,7 +515,7 @@ bool AkonadiModel::setData(const QModelIndex& index, const QVariant& value, int
updateCollection = true;
break;
}
case EnabledRole:
case EnabledTypesRole:
{
KAlarm::CalEvent::Types types = static_cast<KAlarm::CalEvent::Types>(value.value<int>());
CollectionAttribute* attr = collection.attribute<CollectionAttribute>(Entity::AddIfMissing);
......
......@@ -53,14 +53,14 @@ class AkonadiModel : public Akonadi::EntityTreeModel
ColumnCount
};
enum { // additional data roles
// Collection and Item roles
EnabledRole = UserRole, // true for enabled alarm, false for disabled
// Collection roles
EnabledTypesRole = UserRole, // alarm types which are enabled for the collection
BaseColourRole, // background colour ignoring collection colour
AlarmTypeRole, // OR of event types which collection contains
IsStandardRole, // OR of event types which collection is standard for
KeepFormatRole, // user has chosen not to update collection's calendar storage format
// Item roles
EnabledRole, // true for enabled alarm, false for disabled
StatusRole, // KAEvent::ACTIVE/ARCHIVED/TEMPLATE
AlarmActionsRole, // KAEvent::Actions
AlarmActionRole, // KAEvent::Action
......
......@@ -724,7 +724,7 @@ void CollectionControlModel::statusChanged(const Collection& collection, Akonadi
// Update the collection's status
AkonadiModel* model = static_cast<AkonadiModel*>(sourceModel());
if (!model->isCollectionBeingDeleted(collection.id()))
model->setData(model->collectionIndex(collection), static_cast<int>(enabled), AkonadiModel::EnabledRole);
model->setData(model->collectionIndex(collection), value, AkonadiModel::EnabledTypesRole);
}
break;
}
......
......@@ -55,6 +55,8 @@ ItemListModel::ItemListModel(KAlarm::CalEvent::Types allowed, QObject* parent)
setDynamicSortFilter(true);
connect(this, SIGNAL(rowsInserted(QModelIndex,int,int)), SLOT(slotRowsInserted()));
connect(this, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(slotRowsRemoved()));
connect(AkonadiModel::instance(), SIGNAL(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)),
SLOT(collectionStatusChanged(Akonadi::Collection,AkonadiModel::Change,QVariant,bool)));
}
int ItemListModel::columnCount(const QModelIndex& /*parent*/) const
......@@ -86,6 +88,31 @@ void ItemListModel::slotRowsRemoved()
}
}
/******************************************************************************
* Called when a collection parameter or status has changed.
* If the collection's enabled status has changed, re-filter the list to add or
* remove its alarms.
*/
void ItemListModel::collectionStatusChanged(const Collection& collection, AkonadiModel::Change change, const QVariant&, bool inserted)
{
Q_UNUSED(inserted);
if (!collection.isValid())
return;
if (change == AkonadiModel::Enabled)
invalidateFilter();
}
bool ItemListModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
if (!EntityMimeTypeFilterModel::filterAcceptsRow(sourceRow, sourceParent))
return false;
// Get the alarm type of the item
QModelIndex sourceIndex = sourceModel()->index(sourceRow, 0, sourceParent);
KAlarm::CalEvent::Type type = static_cast<KAlarm::CalEvent::Type>(sourceModel()->data(sourceIndex, AkonadiModel::StatusRole).toInt());
Collection parent = sourceIndex.data(AkonadiModel::ParentCollectionRole).value<Collection>();
return CollectionControlModel::isEnabled(parent, type);
}
#if 0
QModelIndex ItemListModel::index(int row, int column, const QModelIndex& parent) const
{
......@@ -152,8 +179,8 @@ bool ItemListModel::haveEvents() const
/*=============================================================================
= Class: AlarmListModel
= Filter proxy model containing all alarms of specified mime types in enabled
= collections.
= Filter proxy model containing all alarms (not templates) of specified mime
= types in enabled collections.
Equivalent to AlarmListFilterModel
=============================================================================*/
AlarmListModel* AlarmListModel::mAllInstance = 0;
......
......@@ -62,9 +62,13 @@ class ItemListModel : public Akonadi::EntityMimeTypeFilterModel
*/
void haveEventsStatus(bool have);
protected:
virtual bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const;
private slots:
void slotRowsInserted();
void slotRowsRemoved();
void collectionStatusChanged(const Akonadi::Collection& collection, AkonadiModel::Change change, const QVariant&, bool inserted);
private:
KAlarm::CalEvent::Types mAllowedTypes; // types of events allowed in this model
......
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