Git commit e6abe7c77ebcebfbd89393eb3898e5e6f9a261b1 by Valentin Rusu. Committed on 01/11/2011 at 00:16. Pushed by vrusu into branch 'master'. Fixed collection sync; fixed crash after collection delete M +2 -2 daemon/backend/ksecret/ksecretcollection.cpp M +1 -0 daemon/backend/ksecret/ksecretjobs.cpp M +92 -31 daemon/frontend/secret/collection.cpp M +2 -0 daemon/frontend/secret/collection.h http://commits.kde.org/ksecretservice/e6abe7c77ebcebfbd89393eb3898e5e6f9a26= 1b1 diff --git a/daemon/backend/ksecret/ksecretcollection.cpp b/daemon/backend/= ksecret/ksecretcollection.cpp index 48dbb27..71cf92d 100644 --- a/daemon/backend/ksecret/ksecretcollection.cpp +++ b/daemon/backend/ksecret/ksecretcollection.cpp @@ -69,7 +69,7 @@ KSecretCollection *KSecretCollection::create(const QStrin= g &id, const QCA::Secur } = KSecretCollection::KSecretCollection(BackendCollectionManager *parent) - : BackendCollection(parent), m_locked(), m_encryptionFilter(0), m_dirt= y(true) + : BackendCollection(parent), m_locked(), m_encryptionFilter(0), m_dirt= y(false) { m_syncTimer.setSingleShot(true); connect(&m_syncTimer, SIGNAL(timeout()), SLOT(sync())); @@ -576,10 +576,10 @@ void KSecretCollection::setDirty(bool dirty) m_dirty =3D dirty; if ( dirty ) { m_secret.m_modified =3D QDateTime::currentDateTimeUtc(); - startSyncTimer(); } } } + startSyncTimer(); } = bool KSecretCollection::serialize(QString &errorMessage) const diff --git a/daemon/backend/ksecret/ksecretjobs.cpp b/daemon/backend/ksecre= t/ksecretjobs.cpp index fcf939c..868a9eb 100644 --- a/daemon/backend/ksecret/ksecretjobs.cpp +++ b/daemon/backend/ksecret/ksecretjobs.cpp @@ -282,6 +282,7 @@ void KSecretUnlockCollectionJob::askPasswordJobResult(K= Job *job) } else { m_passwordAsked =3D true; = + m_collectionPerm =3D collection()->applicationPermission( unlockIn= fo().m_peer.exePath() ); if ( m_collectionPerm =3D=3D PermissionUndefined ) { // ask for the ACL preference if the application is unknown by= this collection AbstractUiManager *uiManager =3D BackendMaster::instance()->ui= Manager(); diff --git a/daemon/frontend/secret/collection.cpp b/daemon/frontend/secret= /collection.cpp index c9c521b..710117d 100644 --- a/daemon/frontend/secret/collection.cpp +++ b/daemon/frontend/secret/collection.cpp @@ -31,9 +31,10 @@ #include #include #include +#include = Collection::Collection(BackendCollection *collection, Service *service) - : QObject(service), m_service(service), m_collection(collection) + : QObject(service), m_service(service), m_collection(collection), m_de= leted(false) { Q_ASSERT(collection); m_objectPath.setPath(service->objectPath().path() + "/collection/" + c= ollection->id()); @@ -59,71 +60,123 @@ const QList &Collection::items() const return m_itemPaths; } = -void Collection::setLabel(const QString &label) +void Collection::setLabel( const QString &label ) { - BackendReturn rc =3D m_collection->setLabel(label); - if(rc.isError()) { - // TODO: generate D-Bus error + if ( !m_deleted && m_collection ) { + BackendReturn rc =3D m_collection->setLabel( label ); + if ( rc.isError() ) { + sendErrorReply( QDBusError::Failed, rc.errorMessage() ); + } + } + else { + sendErrorReply( QDBusError::InvalidObjectPath, ki18n("The collecti= on has been deleted").toString() ); } } = QString Collection::label() const { - BackendReturn rc =3D m_collection->label(); - if(rc.isError()) { - // TODO: generate D-Bus error + QString result; + if ( !m_deleted && m_collection ) { + BackendReturn rc =3D m_collection->label(); + if(rc.isError()) { + sendErrorReply( QDBusError::Failed, rc.errorMessage() ); + } + result =3D rc.value(); + } + else { + sendErrorReply( QDBusError::InvalidObjectPath, ki18n("The collecti= on has been deleted").toString() ); } - return rc.value(); + return result; } = bool Collection::locked() const { - return m_collection->isLocked(); + bool result =3D true; + if ( !m_deleted && m_collection ) { + result =3D m_collection->isLocked(); + } + return result; } = qulonglong Collection::created() const { - return m_collection->created().toTime_t(); + if ( !m_deleted && m_collection ) { + return m_collection->created().toTime_t(); + } + return 0; } = qulonglong Collection::modified() const { - return m_collection->modified().toTime_t(); + if ( !m_deleted && m_collection ) { + return m_collection->modified().toTime_t(); + } + return 0; } = QDBusObjectPath Collection::deleteCollection() { - CollectionDeleteInfo deleteInfo(getCallingPeer()); - // TODO: init peer here - DeleteCollectionJob *dcj =3D m_collection->createDeleteJob(deleteInfo); - if(dcj->isImmediate()) { - dcj->exec(); - return QDBusObjectPath("/"); - } else { - SingleJobPrompt *p =3D new SingleJobPrompt(m_service, dcj, this); - return p->objectPath(); + QDBusObjectPath result("/"); + if ( m_collection && !m_deleted ) { + CollectionDeleteInfo deleteInfo(getCallingPeer()); + // TODO: init peer here + DeleteCollectionJob *dcj =3D m_collection->createDeleteJob(deleteI= nfo); + if(dcj->isImmediate()) { + dcj->exec(); + } else { + SingleJobPrompt *p =3D new SingleJobPrompt(m_service, dcj, thi= s); + result =3D p->objectPath(); + } + } + else { + if ( m_deleted ) { + sendErrorReply( QDBusError::Failed, ki18n("Collection was alre= ady deleted").toString() ); + } + else { + sendErrorReply( QDBusError::InternalError ); + } + } + return result; +} + +void Collection::slotCollectionDeleted(BackendCollection* coll) +{ + if ( coll =3D=3D m_collection ) { + m_collection =3D 0; + m_deleted =3D true; } } = QList Collection::searchItems(const QMap &attributes) { QList rc; - BackendReturn > br =3D m_collection->searchItems(a= ttributes); - if(br.isError()) { - // TODO: generate D-Bus error - } else { - Q_FOREACH(BackendItem * item, br.value()) { - rc.append(QDBusObjectPath(m_objectPath.path() + '/' + item->id= ())); + if ( m_collection ) { + BackendReturn > br =3D m_collection->searchIte= ms(attributes); + if(br.isError()) { + sendErrorReply( QDBusError::Failed, br.errorMessage() ); + } else { + Q_FOREACH(BackendItem * item, br.value()) { + rc.append(QDBusObjectPath(m_objectPath.path() + '/' + item= ->id())); + } } } + else { + sendErrorReply( QDBusError::InternalError ); + } return rc; } = +// FIXME: this method needs some refactoring for the sake of it's readabil= ity QDBusObjectPath Collection::createItem(const QMap &prop= erties, const SecretStruct &secret, = bool replace, QDBusObjectPath &prompt) { + if ( !m_collection ) { + sendErrorReply( QDBusError::InternalError ); + return QDBusObjectPath("/"); + } + = // default label? QString label; QMap attributes; @@ -133,7 +186,9 @@ QDBusObjectPath Collection::createItem(const QMap &properties QObject *object =3D QDBusConnection::sessionBus().objectRegisteredAt(s= ecret.m_session.path()); Session *session; if(!(session =3D qobject_cast(object))) { - // TODO: error, requires session + kDebug() << "ERROR there is no available session"; + sendErrorReply( QDBusError::InternalError ); + return QDBusObjectPath("/"); } = if(properties.contains("Locked")) { @@ -175,9 +230,15 @@ QDBusObjectPath Collection::createItem(const QMap &properties = QDBusObjectPath Collection::changePassword() { - ChangeAuthenticationCollectionJob *cpj =3D m_collection->createChangeA= uthenticationJob( getCallingPeer() ); - SingleJobPrompt *pj =3D new SingleJobPrompt(m_service, cpj, this ); - return pj->objectPath(); + if ( m_collection ) { + ChangeAuthenticationCollectionJob *cpj =3D m_collection->createCha= ngeAuthenticationJob( getCallingPeer() ); + SingleJobPrompt *pj =3D new SingleJobPrompt(m_service, cpj, this ); + return pj->objectPath(); + } + else { + sendErrorReply( QDBusError::InternalError ); + return QDBusObjectPath("/"); + } } = BackendCollection *Collection::backendCollection() const diff --git a/daemon/frontend/secret/collection.h b/daemon/frontend/secret/c= ollection.h index 7e3c255..6a688a1 100644 --- a/daemon/frontend/secret/collection.h +++ b/daemon/frontend/secret/collection.h @@ -172,6 +172,7 @@ private Q_SLOTS: void slotItemDeleted(BackendItem *item); // handle itemChanged() calls from a backend collection void slotItemChanged(BackendItem *item); + void slotCollectionDeleted(BackendCollection *coll); = private: Service *m_service; // parent service @@ -179,6 +180,7 @@ private: QDBusObjectPath m_objectPath; QList m_itemPaths; // cache for items' object paths QMap< QDBusObjectPath, Item*> m_items; + bool m_deleted; }; = #endif