Commit 6c615124 authored by Tobias Koenig's avatar Tobias Koenig

Fetch the parent collection explicitly

  -> rights are handled correctly now

svn path=/trunk/KDE/kdepim/akonadi/contact/; revision=1016279
parent a9d63252
......@@ -27,6 +27,7 @@
#include "contactmetadata_p.h"
#include "contactmetadataattribute_p.h"
#include <akonadi/collectionfetchjob.h>
#include <akonadi/itemcreatejob.h>
#include <akonadi/itemfetchjob.h>
#include <akonadi/itemfetchscope.h>
......@@ -54,7 +55,8 @@ class ContactEditor::Private
delete mMonitor;
}
void fetchDone( KJob* );
void itemFetchDone( KJob* );
void parentCollectionFetchDone( KJob* );
void storeDone( KJob* );
void itemChanged( const Akonadi::Item &item, const QSet<QByteArray>& );
......@@ -72,7 +74,7 @@ class ContactEditor::Private
bool mReadOnly;
};
void ContactEditor::Private::fetchDone( KJob *job )
void ContactEditor::Private::itemFetchDone( KJob *job )
{
if ( job->error() != KJob::NoError )
return;
......@@ -86,15 +88,37 @@ void ContactEditor::Private::fetchDone( KJob *job )
mItem = fetchJob->items().first();
mReadOnly = false;
if ( mMode == ContactEditor::EditMode ) {
mReadOnly = false;
// if in edit mode we have to fetch the parent collection to find out
// about the modify rights of the item
Akonadi::CollectionFetchJob *collectionFetchJob = new Akonadi::CollectionFetchJob( mItem.parentCollection(),
Akonadi::CollectionFetchJob::Base );
mParent->connect( collectionFetchJob, SIGNAL( result( KJob* ) ),
SLOT( parentCollectionFetchDone( KJob* ) ) );
} else {
const KABC::Addressee addr = mItem.payload<KABC::Addressee>();
mContactMetaData.load( mItem );
loadContact( addr, mContactMetaData );
mEditorWidget->setReadOnly( mReadOnly );
}
}
const Akonadi::Collection parentCollection = mItem.parentCollection();
if ( parentCollection.isValid() )
mReadOnly = !(parentCollection.rights() & Collection::CanChangeItem);
void ContactEditor::Private::parentCollectionFetchDone( KJob *job )
{
if ( job->error() )
return;
mEditorWidget->setReadOnly( mReadOnly );
}
Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
if ( !fetchJob )
return;
const Akonadi::Collection parentCollection = fetchJob->collections().first();
if ( parentCollection.isValid() )
mReadOnly = !(parentCollection.rights() & Collection::CanChangeItem);
mEditorWidget->setReadOnly( mReadOnly );
const KABC::Addressee addr = mItem.payload<KABC::Addressee>();
mContactMetaData.load( mItem );
......@@ -128,7 +152,7 @@ void ContactEditor::Private::itemChanged( const Akonadi::Item&, const QSet<QByte
job->fetchScope().fetchAttribute<ContactMetaDataAttribute>();
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
mParent->connect( job, SIGNAL( result( KJob* ) ), mParent, SLOT( fetchDone( KJob* ) ) );
mParent->connect( job, SIGNAL( result( KJob* ) ), mParent, SLOT( itemFetchDone( KJob* ) ) );
}
}
......@@ -180,7 +204,7 @@ void ContactEditor::loadContact( const Akonadi::Item &item )
job->fetchScope().fetchAttribute<ContactMetaDataAttribute>();
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
connect( job, SIGNAL( result( KJob* ) ), SLOT( fetchDone( KJob* ) ) );
connect( job, SIGNAL( result( KJob* ) ), SLOT( itemFetchDone( KJob* ) ) );
d->setupMonitor();
d->mMonitor->setItemMonitored( item );
......
......@@ -110,7 +110,8 @@ class AKONADI_CONTACT_EXPORT ContactEditor : public QWidget
class Private;
Private* const d;
Q_PRIVATE_SLOT( d, void fetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void itemFetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void parentCollectionFetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void storeDone( KJob* ) )
Q_PRIVATE_SLOT( d, void itemChanged( const Akonadi::Item&, const QSet<QByteArray>& ) )
//@endcond PRIVATE
......
......@@ -26,6 +26,7 @@
#include "ui_contactgroupeditor.h"
#include "waitingoverlay_p.h"
#include <akonadi/collectionfetchjob.h>
#include <akonadi/itemcreatejob.h>
#include <akonadi/itemfetchjob.h>
#include <akonadi/itemfetchscope.h>
......@@ -58,7 +59,8 @@ class ContactGroupEditor::Private
delete mMonitor;
}
void fetchDone( KJob* );
void itemFetchDone( KJob* );
void parentCollectionFetchDone( KJob* );
void storeDone( KJob* );
void itemChanged( const Akonadi::Item &item, const QSet<QByteArray>& );
void memberChanged();
......@@ -85,7 +87,7 @@ class ContactGroupEditor::Private
using namespace Akonadi;
void ContactGroupEditor::Private::fetchDone( KJob *job )
void ContactGroupEditor::Private::itemFetchDone( KJob *job )
{
if ( job->error() )
return;
......@@ -99,13 +101,35 @@ void ContactGroupEditor::Private::fetchDone( KJob *job )
mItem = fetchJob->items().first();
mReadOnly = false;
if ( mMode == ContactGroupEditor::EditMode ) {
mReadOnly = false;
const Akonadi::Collection parentCollection = mItem.parentCollection();
if ( parentCollection.isValid() )
mReadOnly = !(parentCollection.rights() & Collection::CanChangeItem);
// if in edit mode we have to fetch the parent collection to find out
// about the modify rights of the item
Akonadi::CollectionFetchJob *collectionFetchJob = new Akonadi::CollectionFetchJob( mItem.parentCollection(),
Akonadi::CollectionFetchJob::Base );
mParent->connect( collectionFetchJob, SIGNAL( result( KJob* ) ),
SLOT( parentCollectionFetchDone( KJob* ) ) );
} else {
const KABC::ContactGroup group = mItem.payload<KABC::ContactGroup>();
loadContactGroup( group );
setReadOnly( mReadOnly );
}
}
void ContactGroupEditor::Private::parentCollectionFetchDone( KJob *job )
{
if ( job->error() )
return;
Akonadi::CollectionFetchJob *fetchJob = qobject_cast<Akonadi::CollectionFetchJob*>( job );
if ( !fetchJob )
return;
const Akonadi::Collection parentCollection = fetchJob->collections().first();
if ( parentCollection.isValid() )
mReadOnly = !(parentCollection.rights() & Collection::CanChangeItem);
const KABC::ContactGroup group = mItem.payload<KABC::ContactGroup>();
loadContactGroup( group );
......@@ -139,7 +163,7 @@ void ContactGroupEditor::Private::itemChanged( const Item&, const QSet<QByteArra
job->fetchScope().fetchFullPayload();
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
mParent->connect( job, SIGNAL( result( KJob* ) ), mParent, SLOT( fetchDone( KJob* ) ) );
mParent->connect( job, SIGNAL( result( KJob* ) ), mParent, SLOT( itemFetchDone( KJob* ) ) );
new WaitingOverlay( job, mParent );
}
}
......@@ -302,7 +326,7 @@ void ContactGroupEditor::loadContactGroup( const Akonadi::Item &item )
job->fetchScope().fetchFullPayload();
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
connect( job, SIGNAL( result( KJob* ) ), SLOT( fetchDone( KJob* ) ) );
connect( job, SIGNAL( result( KJob* ) ), SLOT( itemFetchDone( KJob* ) ) );
d->setupMonitor();
d->mMonitor->setItemMonitored( item );
......
......@@ -104,7 +104,8 @@ class AKONADI_CONTACT_EXPORT ContactGroupEditor : public QWidget
Q_DISABLE_COPY( ContactGroupEditor )
Q_PRIVATE_SLOT( d, void fetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void itemFetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void parentCollectionFetchDone( KJob* ) )
Q_PRIVATE_SLOT( d, void storeDone( KJob* ) )
Q_PRIVATE_SLOT( d, void itemChanged( const Akonadi::Item&, const QSet<QByteArray>& ) )
Q_PRIVATE_SLOT( d, void memberChanged() )
......
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