Commit e3982b7b authored by David Jarvie's avatar David Jarvie

Prevent collections which have no resource from being displayed

Collections which don't belong to a resource can't be used or
edited, so they shouldn't be displayed to the user, and the alarms
they contain also shouldn't be displayed or used.
parent 248275c0
......@@ -1587,19 +1587,22 @@ void AkonadiModel::slotRowsInserted(const QModelIndex& parent, int start, int en
const Collection collection = ix.data(CollectionRole).value<Collection>();
if (collection.isValid())
{
// A collection has been inserted
// A collection has been inserted.
// Ignore it if it isn't owned by a valid resource.
kDebug() << "Collection" << collection.id() << collection.name();
QSet<QByteArray> attrs;
attrs += CollectionAttribute::name();
setCollectionChanged(collection, attrs, true);
emit collectionAdded(collection);
if (!mCollectionsBeingCreated.contains(collection.remoteId())
&& (collection.rights() & writableRights) == writableRights)
if (AgentManager::self()->instance(collection.resource()).isValid())
{
// Update to current KAlarm format if necessary, and if the user agrees
CalendarMigrator::updateToCurrentFormat(collection, false, MainWindow::mainMainWindow());
QSet<QByteArray> attrs;
attrs += CollectionAttribute::name();
setCollectionChanged(collection, attrs, true);
emit collectionAdded(collection);
if (!mCollectionsBeingCreated.contains(collection.remoteId())
&& (collection.rights() & writableRights) == writableRights)
{
// Update to current KAlarm format if necessary, and if the user agrees
CalendarMigrator::updateToCurrentFormat(collection, false, MainWindow::mainMainWindow());
}
}
}
else
......
......@@ -26,6 +26,7 @@
#include <kalarmcal/collectionattribute.h>
#include <kalarmcal/compatibilityattribute.h>
#include <akonadi/agentmanager.h>
#include <akonadi/collectiondialog.h>
#include <akonadi/collectiondeletejob.h>
#include <akonadi/collectionmodifyjob.h>
......@@ -116,11 +117,13 @@ bool CollectionMimeTypeFilterModel::filterAcceptsRow(int sourceRow, const QModel
{
if (!EntityMimeTypeFilterModel::filterAcceptsRow(sourceRow, sourceParent))
return false;
if (!mWritableOnly && mAlarmType == CalEvent::EMPTY)
return true;
AkonadiModel* model = AkonadiModel::instance();
QModelIndex ix = model->index(sourceRow, 0, sourceParent);
Collection collection = model->data(ix, AkonadiModel::CollectionRole).value<Collection>();
if (!AgentManager::self()->instance(collection.resource()).isValid())
return false;
if (!mWritableOnly && mAlarmType == CalEvent::EMPTY)
return true;
if (mWritableOnly && (collection.rights() & writableRights) != writableRights)
return false;
if (mAlarmType != CalEvent::EMPTY && !collection.contentMimeTypes().contains(CalEvent::mimeType(mAlarmType)))
......@@ -680,6 +683,8 @@ void CollectionControlModel::findEnabledCollections(const EntityMimeTypeFilterMo
{
const QModelIndex ix = filter->index(row, 0, parent);
const Collection collection = model->data(filter->mapToSource(ix), AkonadiModel::CollectionRole).value<Collection>();
if (!AgentManager::self()->instance(collection.resource()).isValid())
continue; // the collection doesn't belong to a resource, so omit it
CalEvent::Types enabled = !collection.hasAttribute<CollectionAttribute>() ? CalEvent::EMPTY
: collection.attribute<CollectionAttribute>()->enabled();
CalEvent::Types canEnable = checkTypesToEnable(collection, collections, enabled);
......@@ -701,6 +706,13 @@ bool CollectionControlModel::isEnabled(const Collection& collection, CalEvent::T
{
if (!collection.isValid() || !instance()->collections().contains(collection))
return false;
if (!AgentManager::self()->instance(collection.resource()).isValid())
{
// The collection doesn't belong to a resource, so it can't be used.
// Remove it from the list of collections.
instance()->removeCollection(collection);
return false;
}
Collection col = collection;
AkonadiModel::instance()->refresh(col); // update with latest data
return col.hasAttribute<CollectionAttribute>()
......
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