[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ksecretservice] daemon: Fixed collection sync;
From: Valentin Rusu <kde () rusu ! info>
Date: 2011-10-31 23:16:38
Message-ID: 20111031231638.76AA1A60A6 () git ! kde ! org
[Download RAW message or body]
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/e6abe7c77ebcebfbd89393eb3898e5e6f9a261b1
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 QString &id, \
const QCA::Secur }
KSecretCollection::KSecretCollection(BackendCollectionManager *parent)
- : BackendCollection(parent), m_locked(), m_encryptionFilter(0), m_dirty(true)
+ : BackendCollection(parent), m_locked(), m_encryptionFilter(0), m_dirty(false)
{
m_syncTimer.setSingleShot(true);
connect(&m_syncTimer, SIGNAL(timeout()), SLOT(sync()));
@@ -576,10 +576,10 @@ void KSecretCollection::setDirty(bool dirty)
m_dirty = dirty;
if ( dirty ) {
m_secret.m_modified = QDateTime::currentDateTimeUtc();
- startSyncTimer();
}
}
}
+ startSyncTimer();
}
bool KSecretCollection::serialize(QString &errorMessage) const
diff --git a/daemon/backend/ksecret/ksecretjobs.cpp \
b/daemon/backend/ksecret/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(KJob *job)
} else {
m_passwordAsked = true;
+ m_collectionPerm = collection()->applicationPermission( \
unlockInfo().m_peer.exePath() ); if ( m_collectionPerm == PermissionUndefined ) {
// ask for the ACL preference if the application is unknown by this \
collection
AbstractUiManager *uiManager = BackendMaster::instance()->uiManager();
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 <kdebug.h>
#include <QtDBus/QDBusConnection>
#include <QtCore/QDebug>
+#include <klocalizedstring.h>
Collection::Collection(BackendCollection *collection, Service *service)
- : QObject(service), m_service(service), m_collection(collection)
+ : QObject(service), m_service(service), m_collection(collection), \
m_deleted(false) {
Q_ASSERT(collection);
m_objectPath.setPath(service->objectPath().path() + "/collection/" + \
collection->id()); @@ -59,71 +60,123 @@ const QList<QDBusObjectPath> \
&Collection::items() const return m_itemPaths;
}
-void Collection::setLabel(const QString &label)
+void Collection::setLabel( const QString &label )
{
- BackendReturn<void> rc = m_collection->setLabel(label);
- if(rc.isError()) {
- // TODO: generate D-Bus error
+ if ( !m_deleted && m_collection ) {
+ BackendReturn<void> rc = m_collection->setLabel( label );
+ if ( rc.isError() ) {
+ sendErrorReply( QDBusError::Failed, rc.errorMessage() );
+ }
+ }
+ else {
+ sendErrorReply( QDBusError::InvalidObjectPath, ki18n("The collection has \
been deleted").toString() ); }
}
QString Collection::label() const
{
- BackendReturn<QString> rc = m_collection->label();
- if(rc.isError()) {
- // TODO: generate D-Bus error
+ QString result;
+ if ( !m_deleted && m_collection ) {
+ BackendReturn<QString> rc = m_collection->label();
+ if(rc.isError()) {
+ sendErrorReply( QDBusError::Failed, rc.errorMessage() );
+ }
+ result = rc.value();
+ }
+ else {
+ sendErrorReply( QDBusError::InvalidObjectPath, ki18n("The collection has \
been deleted").toString() ); }
- return rc.value();
+ return result;
}
bool Collection::locked() const
{
- return m_collection->isLocked();
+ bool result = true;
+ if ( !m_deleted && m_collection ) {
+ result = 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 = m_collection->createDeleteJob(deleteInfo);
- if(dcj->isImmediate()) {
- dcj->exec();
- return QDBusObjectPath("/");
- } else {
- SingleJobPrompt *p = 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 = m_collection->createDeleteJob(deleteInfo);
+ if(dcj->isImmediate()) {
+ dcj->exec();
+ } else {
+ SingleJobPrompt *p = new SingleJobPrompt(m_service, dcj, this);
+ result = p->objectPath();
+ }
+ }
+ else {
+ if ( m_deleted ) {
+ sendErrorReply( QDBusError::Failed, ki18n("Collection was already \
deleted").toString() ); + }
+ else {
+ sendErrorReply( QDBusError::InternalError );
+ }
+ }
+ return result;
+}
+
+void Collection::slotCollectionDeleted(BackendCollection* coll)
+{
+ if ( coll == m_collection ) {
+ m_collection = 0;
+ m_deleted = true;
}
}
QList<QDBusObjectPath> Collection::searchItems(const QMap<QString, QString> \
&attributes) {
QList<QDBusObjectPath> rc;
- BackendReturn<QList<BackendItem*> > br = m_collection->searchItems(attributes);
- 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<QList<BackendItem*> > br = \
m_collection->searchItems(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 readability
QDBusObjectPath Collection::createItem(const QMap<QString, QVariant> &properties,
const SecretStruct &secret,
bool replace,
QDBusObjectPath &prompt)
{
+ if ( !m_collection ) {
+ sendErrorReply( QDBusError::InternalError );
+ return QDBusObjectPath("/");
+ }
+
// default label?
QString label;
QMap<QString, QString> attributes;
@@ -133,7 +186,9 @@ QDBusObjectPath Collection::createItem(const QMap<QString, \
QVariant> &properties
QObject *object = \
QDBusConnection::sessionBus().objectRegisteredAt(secret.m_session.path()); Session \
*session; if(!(session = qobject_cast<Session*>(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<QString, \
QVariant> &properties
QDBusObjectPath Collection::changePassword()
{
- ChangeAuthenticationCollectionJob *cpj = \
m_collection->createChangeAuthenticationJob( getCallingPeer() );
- SingleJobPrompt *pj = new SingleJobPrompt(m_service, cpj, this );
- return pj->objectPath();
+ if ( m_collection ) {
+ ChangeAuthenticationCollectionJob *cpj = \
m_collection->createChangeAuthenticationJob( getCallingPeer() ); + \
SingleJobPrompt *pj = 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/collection.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<QDBusObjectPath> m_itemPaths; // cache for items' object paths
QMap< QDBusObjectPath, Item*> m_items;
+ bool m_deleted;
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic