24 #include "config-kwallet.h"
26 #include <QtGui/QApplication>
27 #include <QtCore/QPointer>
28 #include <QtGui/QWidget>
29 #include <QtDBus/QtDBus>
36 #include <kdeversion.h>
42 #ifdef HAVE_KSECRETSSERVICE
43 #include "ksecretsservice/ksecretsservicecollection.h"
46 #include "kwallet_interface.h"
48 #ifdef HAVE_KSECRETSSERVICE
58 class KWalletDLauncher
63 org::kde::KWallet &getInterface();
69 bool m_useKSecretsService;
70 org::kde::KWallet *m_wallet;
78 if (KGlobal::hasMainComponent()) {
88 return qApp->applicationName();
93 static bool registered =
false;
95 #ifdef HAVE_KSECRETSSERVICE
96 qDBusRegisterMetaType<KSecretsService::StringStringMap>();
97 qDBusRegisterMetaType<StringToStringStringMapMap>();
99 qDBusRegisterMetaType<StringByteArrayMap>();
104 bool Wallet::isUsingKSecretsService()
106 return walletLauncher->m_useKSecretsService;
112 if (!cfg.
readEntry(
"Use One Wallet",
true)) {
115 return "localwallet";
146 class Wallet::WalletPrivate
150 : q(wallet),
name(n), handle(h)
151 #ifdef HAVE_KSECRETSSERVICE
152 , secretsCollection(0)
156 void walletServiceUnregistered();
158 #ifdef HAVE_KSECRETSSERVICE
159 template <
typename T>
160 int writeEntry(
const QString& key,
const T &value, Wallet::EntryType entryType ) {
162 KSecretsService::Secret secret;
163 secret.setValue( QVariant::fromValue<T>(value) );
168 KSecretsService::CreateCollectionItemJob *createItemJob = secretsCollection->createItem( key, attrs, secret );
170 if ( !createItemJob->exec() ) {
171 kDebug(285) <<
"Cannot execute CreateCollectionItemJob : " << createItemJob->errorString();
173 rc = createItemJob->error();
177 QExplicitlySharedDataPointer<KSecretsService::SecretItem> findItem(
const QString& key )
const;
179 bool readSecret(
const QString& key, KSecretsService::Secret& value )
const;
181 template <
typename V>
182 int forEachItemThatMatches(
const QString &key, V verb ) {
186 KSecretsService::SearchCollectionItemsJob *searchItemsJob = secretsCollection->searchItems(attrs);
187 if ( searchItemsJob->exec() ) {
188 QRegExp re(key, Qt::CaseSensitive, QRegExp::Wildcard);
189 foreach( KSecretsService::SearchCollectionItemsJob::Item item , searchItemsJob->items() ) {
190 KSecretsService::ReadItemPropertyJob *readLabelJob = item->label();
191 if ( readLabelJob->exec() ) {
192 QString label = readLabelJob->propertyValue().toString();
193 if ( re.exactMatch( label ) ) {
194 if ( verb(
this, label, item.data() ) ) {
200 kDebug(285) <<
"Cannot execute ReadItemPropertyJob " << readLabelJob->errorString();
205 kDebug(285) <<
"Cannot execute KSecretsService::SearchCollectionItemsJob " << searchItemsJob->errorString();
210 void createDefaultFolders();
212 struct InsertIntoEntryList;
213 struct InsertIntoMapList;
214 struct InsertIntoPasswordList;
216 KSecretsService::Collection *secretsCollection;
217 #endif // HAVE_KSECRETSSERVICE
224 QPointer<QEventLoop> loop;
227 #ifdef HAVE_KSECRETSSERVICE
228 void Wallet::WalletPrivate::createDefaultFolders()
234 folder = PasswordFolder();
237 folder = FormDataFolder();
240 #endif // HAVE_KSECRETSSERVICE
245 :
QObject(0L), d(new WalletPrivate(this, handle, name))
247 if (walletLauncher->m_useKSecretsService) {
251 QDBusServiceWatcher *watcher =
new QDBusServiceWatcher(QString::fromLatin1(s_kwalletdServiceName), QDBusConnection::sessionBus(),
252 QDBusServiceWatcher::WatchForUnregistration,
this);
253 connect(watcher, SIGNAL(serviceUnregistered(
QString)),
254 this, SLOT(walletServiceUnregistered()));
256 connect(&walletLauncher->getInterface(), SIGNAL(
walletClosed(
int)), SLOT(slotWalletClosed(
int)));
259 connect(&walletLauncher->getInterface(), SIGNAL(applicationDisconnected(
QString,
QString)), SLOT(slotApplicationDisconnected(
QString,
QString)));
262 if (d->handle != -1) {
263 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(d->handle);
264 if (r.isValid() && !r) {
274 #ifdef HAVE_KSECRETSSERVICE
275 if (walletLauncher->m_useKSecretsService) {
278 delete d->secretsCollection;
282 if (d->handle != -1) {
283 if (!walletLauncher.isDestroyed()) {
284 walletLauncher->getInterface().close(d->handle,
false,
appid());
286 kDebug(285) <<
"Problem with static destruction sequence."
287 "Destroy any static Wallet before the event-loop exits.";
293 #ifdef HAVE_KSECRETSSERVICE
302 #ifdef HAVE_KSECRETSSERVICE
303 if (walletLauncher->m_useKSecretsService) {
304 KSecretsService::ListCollectionsJob *listJob = KSecretsService::Collection::listCollections();
305 if ( listJob->exec() ) {
306 result = listJob->collections();
309 kDebug(285) <<
"Cannot execute ListCollectionsJob: " << listJob->errorString();
314 QDBusReply<QStringList> r = walletLauncher->getInterface().wallets();
318 kDebug(285) <<
"Invalid DBus reply: " << r.error();
322 #ifdef HAVE_KSECRETSSERVICE
331 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::changePassword().";
335 #ifdef HAVE_KSECRETSSERVICE
336 if (walletLauncher->m_useKSecretsService) {
337 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection( name );
338 KSecretsService::ChangeCollectionPasswordJob* changePwdJob = coll->changePassword();
339 if ( !changePwdJob->exec() ) {
340 kDebug(285) <<
"Cannot execute change password job: " << changePwdJob->errorString();
346 walletLauncher->getInterface().changePassword(name, (qlonglong)w,
appid());
347 #ifdef HAVE_KSECRETSSERVICE
354 #ifdef HAVE_KSECRETSSERVICE
355 if (walletLauncher->m_useKSecretsService) {
356 return walletLauncher->m_cgroup.readEntry(
"Enabled",
true);
360 QDBusReply<bool> r = walletLauncher->getInterface().isEnabled();
364 kDebug(285) <<
"Invalid DBus reply: " << r.error();
369 #ifdef HAVE_KSECRETSSERVICE
376 #ifdef HAVE_KSECRETSSERVICE
377 if (walletLauncher->m_useKSecretsService) {
378 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection( name, KSecretsService::Collection::OpenOnly );
379 KSecretsService::ReadCollectionPropertyJob *readLocked = coll->isLocked();
380 if ( readLocked->exec() ) {
381 return !readLocked->propertyValue().toBool();
384 kDebug() <<
"ReadLocked job failed";
390 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(name);
394 kDebug(285) <<
"Invalid DBus reply: " << r.error();
399 #ifdef HAVE_KSECRETSSERVICE
405 #ifdef HAVE_KSECRETSSERVICE
406 if (walletLauncher->m_useKSecretsService) {
407 kDebug(285) <<
"Wallet::closeWallet NOOP";
412 QDBusReply<int> r = walletLauncher->getInterface().close(name, force);
416 kDebug(285) <<
"Invalid DBus reply: " << r.error();
421 #ifdef HAVE_KSECRETSSERVICE
428 #ifdef HAVE_KSECRETSSERVICE
429 if (walletLauncher->m_useKSecretsService) {
430 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection(name, KSecretsService::Collection::OpenOnly);
431 KJob *deleteJob = coll->deleteCollection();
432 if (!deleteJob->exec()) {
433 kDebug(285) <<
"Cannot execute delete job " << deleteJob->errorString();
435 return deleteJob->error();
439 QDBusReply<int> r = walletLauncher->getInterface().deleteWallet(name);
443 kDebug(285) <<
"Invalid DBus reply: " << r.error();
448 #ifdef HAVE_KSECRETSSERVICE
455 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::openWallet().";
457 #ifdef HAVE_KSECRETSSERVICE
458 if (walletLauncher->m_useKSecretsService) {
461 wallet->d->secretsCollection = KSecretsService::Collection::findCollection(name, KSecretsService::Collection::CreateCollection, QVariantMap(), w);
462 connect( wallet->d->secretsCollection, SIGNAL(statusChanged(
int)), wallet, SLOT(slotCollectionStatusChanged(
int)) );
463 connect( wallet->d->secretsCollection, SIGNAL(deleted()), wallet, SLOT(slotCollectionDeleted()) );
465 kDebug() <<
"WARNING openWallet OpenType=Synchronous requested";
477 connect(&walletLauncher->getInterface(), SIGNAL(walletAsyncOpened(
int,
int)),
478 wallet, SLOT(walletAsyncOpened(
int,
int)));
492 r = walletLauncher->getInterface().openAsync(name, (qlonglong)w,
appid(),
true);
493 }
else if (ot ==
Path) {
494 r = walletLauncher->getInterface().openPathAsync(name, (qlonglong)w,
appid(),
true);
501 kDebug(285) <<
"Invalid DBus reply: " << r.error();
505 wallet->d->transactionId = r.value();
509 if (wallet->d->transactionId < 0) {
515 wallet->d->loop = &loop;
517 if (wallet->d->handle < 0) {
523 if (wallet->d->transactionId < 0) {
524 QTimer::singleShot(0, wallet, SLOT(emitWalletAsyncOpenError()));
530 #ifdef HAVE_KSECRETSSERVICE
535 void Wallet::slotCollectionStatusChanged(
int status)
537 #ifdef HAVE_KSECRETSSERVICE
538 KSecretsService::Collection::Status collStatus = (KSecretsService::Collection::Status)status;
539 switch ( collStatus ) {
540 case KSecretsService::Collection::NewlyCreated:
541 d->createDefaultFolders();
543 case KSecretsService::Collection::FoundExisting:
546 case KSecretsService::Collection::Deleted:
547 case KSecretsService::Collection::Invalid:
548 case KSecretsService::Collection::Pending:
551 case KSecretsService::Collection::NotFound:
552 emitWalletAsyncOpenError();
558 void Wallet::slotCollectionDeleted()
566 #ifdef HAVE_KSECRETSSERVICE
567 if (walletLauncher->m_useKSecretsService) {
568 kDebug() <<
"Wallet::disconnectApplication NOOP";
573 QDBusReply<bool> r = walletLauncher->getInterface().disconnectApplication(wallet, app);
577 kDebug(285) <<
"Invalid DBus reply: " << r.error();
582 #ifdef HAVE_KSECRETSSERVICE
589 #ifdef HAVE_KSECRETSSERVICE
590 if (walletLauncher->m_useKSecretsService) {
591 kDebug() <<
"KSecretsService does not handle users list";
596 QDBusReply<QStringList> r = walletLauncher->getInterface().users(name);
599 kDebug(285) <<
"Invalid DBus reply: " << r.error();
604 #ifdef HAVE_KSECRETSSERVICE
611 #ifdef HAVE_KSECRETSSERVICE
612 if (walletLauncher->m_useKSecretsService) {
617 if (d->handle == -1) {
621 walletLauncher->getInterface().sync(d->handle,
appid());
622 #ifdef HAVE_KSECRETSSERVICE
630 #ifdef HAVE_KSECRETSSERVICE
631 if (walletLauncher->m_useKSecretsService) {
632 KSecretsService::CollectionLockJob *lockJob = d->secretsCollection->lock();
633 if (lockJob->exec()) {
638 kDebug(285) <<
"Cannot execute KSecretsService::CollectionLockJob : " << lockJob->errorString();
641 return lockJob->error();
645 if (d->handle == -1) {
649 QDBusReply<int> r = walletLauncher->getInterface().close(d->handle,
true,
appid());
657 kDebug(285) <<
"Invalid DBus reply: " << r.error();
660 #ifdef HAVE_KSECRETSSERVICE
672 #ifdef HAVE_KSECRETSSERVICE
673 if (walletLauncher->m_useKSecretsService) {
674 return !d->secretsCollection->isLocked();
678 return d->handle != -1;
679 #ifdef HAVE_KSECRETSSERVICE
687 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::requestChangePassword().";
689 #ifdef HAVE_KSECRETSSERVICE
690 if (walletLauncher->m_useKSecretsService) {
691 KSecretsService::ChangeCollectionPasswordJob *changePwdJob = d->secretsCollection->changePassword();
692 if (!changePwdJob->exec()) {
693 kDebug(285) <<
"Cannot execute ChangeCollectionPasswordJob : " << changePwdJob->errorString();
698 if (d->handle == -1) {
705 walletLauncher->getInterface().changePassword(d->name, (qlonglong)w,
appid());
706 #ifdef HAVE_KSECRETSSERVICE
712 void Wallet::slotWalletClosed(
int handle) {
713 #ifdef HAVE_KSECRETSSERVICE
714 if (walletLauncher->m_useKSecretsService) {
720 if (d->handle == handle) {
726 #ifdef HAVE_KSECRETSSERVICE
733 #ifdef HAVE_KSECRETSSERVICE
734 if (walletLauncher->m_useKSecretsService) {
739 KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs);
741 if (searchJob->exec()) {
742 KSecretsService::ReadCollectionItemsJob::ItemList itemList = searchJob->items();
743 foreach(
const KSecretsService::ReadCollectionItemsJob::Item &item, itemList ) {
744 KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes();
745 if (readAttrsJob->exec()) {
748 if (!folder.isEmpty() && !result.contains(folder)) {
749 result.append(folder);
753 kDebug(285) <<
"Cannot read item attributes : " << readAttrsJob->errorString();
758 kDebug(285) <<
"Cannot execute ReadCollectionItemsJob : " << searchJob->errorString();
764 if (d->handle == -1) {
768 QDBusReply<QStringList> r = walletLauncher->getInterface().folderList(d->handle,
appid());
771 kDebug(285) <<
"Invalid DBus reply: " << r.error();
776 #ifdef HAVE_KSECRETSSERVICE
783 #ifdef HAVE_KSECRETSSERVICE
784 if (walletLauncher->m_useKSecretsService) {
788 KSecretsService::SearchCollectionItemsJob *readItemsJob = d->secretsCollection->searchItems( attrs );
789 if ( readItemsJob->exec() ) {
790 foreach( KSecretsService::SearchCollectionItemsJob::Item item, readItemsJob->items() ) {
791 KSecretsService::ReadItemPropertyJob *readLabelJob = item->label();
792 if ( readLabelJob->exec() ) {
793 result.append( readLabelJob->propertyValue().toString() );
796 kDebug(285) <<
"Cannot execute readLabelJob" << readItemsJob->errorString();
801 kDebug(285) <<
"Cannot execute readItemsJob" << readItemsJob->errorString();
807 if (d->handle == -1) {
811 QDBusReply<QStringList> r = walletLauncher->getInterface().entryList(d->handle, d->folder,
appid());
814 kDebug(285) <<
"Invalid DBus reply: " << r.error();
819 #ifdef HAVE_KSECRETSSERVICE
826 #ifdef HAVE_KSECRETSSERVICE
827 if (walletLauncher->m_useKSecretsService) {
832 return folders.contains(f);
836 if (d->handle == -1) {
840 QDBusReply<bool> r = walletLauncher->getInterface().hasFolder(d->handle, f,
appid());
843 kDebug(285) <<
"Invalid DBus reply: " << r.error();
848 #ifdef HAVE_KSECRETSSERVICE
855 #ifdef HAVE_KSECRETSSERVICE
856 if (walletLauncher->m_useKSecretsService) {
864 if (d->handle == -1) {
869 QDBusReply<bool> r = walletLauncher->getInterface().createFolder(d->handle, f,
appid());
873 kDebug(285) <<
"Invalid DBus reply: " << r.error();
881 #ifdef HAVE_KSECRETSSERVICE
890 #ifdef HAVE_KSECRETSSERVICE
891 if (walletLauncher->m_useKSecretsService) {
899 if (d->handle == -1) {
905 if (f == d->folder) {
914 #ifdef HAVE_KSECRETSSERVICE
923 #ifdef HAVE_KSECRETSSERVICE
924 if (walletLauncher->m_useKSecretsService) {
929 KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs);
930 if (searchJob->exec()) {
931 KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items();
932 if ( !itemList.isEmpty() ) {
934 foreach(
const KSecretsService::SearchCollectionItemsJob::Item &item, itemList ) {
935 KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem();
936 if (!deleteJob->exec()) {
937 kDebug(285) <<
"Cannot delete item : " << deleteJob->errorString();
945 kDebug(285) <<
"Cannot execute KSecretsService::SearchCollectionItemsJob : " << searchJob->errorString();
951 if (d->handle == -1) {
955 QDBusReply<bool> r = walletLauncher->getInterface().removeFolder(d->handle, f,
appid());
956 if (d->folder == f) {
962 kDebug(285) <<
"Invalid DBus reply: " << r.error();
967 #ifdef HAVE_KSECRETSSERVICE
977 #ifdef HAVE_KSECRETSSERVICE
978 QExplicitlySharedDataPointer<KSecretsService::SecretItem> Wallet::WalletPrivate::findItem(
const QString& key )
const
980 QExplicitlySharedDataPointer<KSecretsService::SecretItem> result;
983 attrs[
"Label"] = key;
984 KSecretsService::SearchCollectionItemsJob *searchJob = secretsCollection->searchItems(attrs);
985 if (searchJob->exec()) {
986 KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items();
987 if ( !itemList.isEmpty() ) {
988 result = itemList.first();
991 kDebug(285) <<
"entry named " << key <<
" not found in folder " << folder;
995 kDebug(285) <<
"Cannot exec KSecretsService::SearchCollectionItemsJob : " << searchJob->errorString();
1001 template <
typename T>
1002 int Wallet::WalletPrivate::readEntry(
const QString& key, T& value)
const
1005 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = findItem(key);
1007 KSecretsService::GetSecretItemSecretJob *readJob = item->getSecret();
1008 if ( readJob->exec() ) {
1009 KSecretsService::Secret theSecret = readJob->secret();
1010 kDebug(285) <<
"Secret contentType is " << theSecret.contentType();
1011 value = theSecret.value().value<
T>();
1015 kDebug(285) <<
"Cannot exec GetSecretItemSecretJob : " << readJob->errorString();
1021 bool Wallet::WalletPrivate::readSecret(
const QString& key, KSecretsService::Secret& value)
const
1023 bool result =
false;
1024 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = findItem(key);
1026 KSecretsService::GetSecretItemSecretJob *readJob = item->getSecret();
1027 if ( readJob->exec() ) {
1028 value = readJob->secret();
1032 kDebug(285) <<
"Cannot exec GetSecretItemSecretJob : " << readJob->errorString();
1042 #ifdef HAVE_KSECRETSSERVICE
1043 if (walletLauncher->m_useKSecretsService) {
1044 return d->readEntry<QByteArray>(key, value);
1048 if (d->handle == -1) {
1052 QDBusReply<QByteArray> r = walletLauncher->getInterface().readEntry(d->handle, d->folder, key,
appid());
1057 #ifdef HAVE_KSECRETSSERVICE
1064 #ifdef HAVE_KSECRETSSERVICE
1065 struct Wallet::WalletPrivate::InsertIntoEntryList {
1067 bool operator() ( Wallet::WalletPrivate*,
const QString& label, KSecretsService::SecretItem* item ) {
1068 bool result =
false;
1069 KSecretsService::GetSecretItemSecretJob *readSecretJob = item->getSecret();
1070 if ( readSecretJob->exec() ) {
1071 _value.insert( label, readSecretJob->secret().value().toByteArray() );
1075 kDebug(285) <<
"Cannot execute GetSecretItemSecretJob " << readSecretJob->errorString();
1087 #ifdef HAVE_KSECRETSSERVICE
1088 if (walletLauncher->m_useKSecretsService) {
1089 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoEntryList( value ) );
1095 if (d->handle == -1) {
1099 QDBusReply<QVariantMap> r = walletLauncher->getInterface().readEntryList(d->handle, d->folder, key,
appid());
1103 const QVariantMap val = r.value();
1104 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1105 value.insert(it.key(), it.value().toByteArray());
1108 #ifdef HAVE_KSECRETSSERVICE
1119 #ifdef HAVE_KSECRETSSERVICE
1120 if (walletLauncher->m_useKSecretsService) {
1121 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem(oldName);
1123 KSecretsService::WriteItemPropertyJob *writeJob = item->setLabel(newName);
1124 if (!writeJob->exec()) {
1125 kDebug(285) <<
"Cannot exec WriteItemPropertyJob : " << writeJob->errorString();
1127 rc = writeJob->error();
1130 kDebug(285) <<
"Cannot locate item " << oldName <<
" in folder " << d->folder;
1135 if (d->handle == -1) {
1139 QDBusReply<int> r = walletLauncher->getInterface().renameEntry(d->handle, d->folder, oldName, newName,
appid());
1143 #ifdef HAVE_KSECRETSSERVICE
1154 #ifdef HAVE_KSECRETSSERVICE
1155 if (walletLauncher->m_useKSecretsService) {
1157 rc = d->readEntry< QByteArray >(key, ba);
1158 if ( rc == 0 && !ba.isEmpty()){
1159 QDataStream ds( &ba, QIODevice::ReadOnly );
1167 if (d->handle == -1) {
1171 QDBusReply<QByteArray> r = walletLauncher->getInterface().readMap(d->handle, d->folder, key,
appid());
1176 QDataStream ds(&v, QIODevice::ReadOnly);
1180 #ifdef HAVE_KSECRETSSERVICE
1187 #ifdef HAVE_KSECRETSSERVICE
1188 struct Wallet::WalletPrivate::InsertIntoMapList {
1190 bool operator() ( Wallet::WalletPrivate* d,
const QString& label, KSecretsService::SecretItem* ) {
1191 bool result =
false;
1194 _value.insert( label, map );
1206 #ifdef HAVE_KSECRETSSERVICE
1207 if (walletLauncher->m_useKSecretsService) {
1208 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoMapList( value ) );
1214 if (d->handle == -1) {
1218 QDBusReply<QVariantMap> r =
1219 walletLauncher->getInterface().readMapList(d->handle, d->folder, key,
appid());
1222 const QVariantMap val = r.value();
1223 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1224 QByteArray mapData = it.value().toByteArray();
1225 if (!mapData.isEmpty()) {
1226 QDataStream ds(&mapData, QIODevice::ReadOnly);
1229 value.insert(it.key(), v);
1233 #ifdef HAVE_KSECRETSSERVICE
1244 #ifdef HAVE_KSECRETSSERVICE
1245 if (walletLauncher->m_useKSecretsService) {
1246 rc = d->readEntry<
QString>(key, value);
1250 if (d->handle == -1) {
1254 QDBusReply<QString> r = walletLauncher->getInterface().readPassword(d->handle, d->folder, key,
appid());
1259 #ifdef HAVE_KSECRETSSERVICE
1266 #ifdef HAVE_KSECRETSSERVICE
1267 struct Wallet::WalletPrivate::InsertIntoPasswordList {
1269 bool operator() ( Wallet::WalletPrivate* d,
const QString& label, KSecretsService::SecretItem* ) {
1270 bool result =
false;
1272 if ( d->readEntry<
QString>( label, pwd ) == 0 ) {
1273 _value.insert( label, pwd );
1285 #ifdef HAVE_KSECRETSSERVICE
1286 if (walletLauncher->m_useKSecretsService) {
1287 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoPasswordList( value ) );
1293 if (d->handle == -1) {
1297 QDBusReply<QVariantMap> r = walletLauncher->getInterface().readPasswordList(d->handle, d->folder, key,
appid());
1300 const QVariantMap val = r.value();
1301 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1302 value.insert(it.key(), it.value().toString());
1305 #ifdef HAVE_KSECRETSSERVICE
1316 #ifdef HAVE_KSECRETSSERVICE
1317 if (walletLauncher->m_useKSecretsService) {
1318 rc = d->writeEntry( key, value, entryType );
1322 if (d->handle == -1) {
1326 QDBusReply<int> r = walletLauncher->getInterface().writeEntry(d->handle, d->folder, key, value,
int(entryType),
appid());
1330 #ifdef HAVE_KSECRETSSERVICE
1341 #ifdef HAVE_KSECRETSSERVICE
1342 if (walletLauncher->m_useKSecretsService) {
1347 if (d->handle == -1) {
1351 QDBusReply<int> r = walletLauncher->getInterface().writeEntry(d->handle, d->folder, key, value,
appid());
1355 #ifdef HAVE_KSECRETSSERVICE
1366 #ifdef HAVE_KSECRETSSERVICE
1367 if (walletLauncher->m_useKSecretsService) {
1368 d->writeEntry( key, value,
Map );
1374 if (d->handle == -1) {
1379 QDataStream ds(&mapData, QIODevice::WriteOnly);
1381 QDBusReply<int> r = walletLauncher->getInterface().writeMap(d->handle, d->folder, key, mapData,
appid());
1385 #ifdef HAVE_KSECRETSSERVICE
1396 #ifdef HAVE_KSECRETSSERVICE
1397 if (walletLauncher->m_useKSecretsService) {
1398 rc = d->writeEntry( key, value,
Password );
1402 if (d->handle == -1) {
1406 QDBusReply<int> r = walletLauncher->getInterface().writePassword(d->handle, d->folder, key, value,
appid());
1410 #ifdef HAVE_KSECRETSSERVICE
1419 #ifdef HAVE_KSECRETSSERVICE
1420 if (walletLauncher->m_useKSecretsService) {
1421 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1426 if (d->handle == -1) {
1430 QDBusReply<bool> r = walletLauncher->getInterface().hasEntry(d->handle, d->folder, key,
appid());
1433 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1438 #ifdef HAVE_KSECRETSSERVICE
1447 #ifdef HAVE_KSECRETSSERVICE
1448 if (walletLauncher->m_useKSecretsService) {
1449 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1451 KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem();
1452 if ( !deleteJob->exec() ) {
1453 kDebug(285) <<
"Cannot execute SecretItemDeleteJob " << deleteJob->errorString();
1455 rc = deleteJob->error();
1460 if (d->handle == -1) {
1464 QDBusReply<int> r = walletLauncher->getInterface().removeEntry(d->handle, d->folder, key,
appid());
1468 #ifdef HAVE_KSECRETSSERVICE
1479 #ifdef HAVE_KSECRETSSERVICE
1480 if (walletLauncher->m_useKSecretsService) {
1481 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1483 KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes();
1484 if ( readAttrsJob->exec() ) {
1489 rc = entryType.toInt( &ok );
1497 kDebug(285) <<
"Cannot execute GetSecretItemSecretJob " << readAttrsJob->errorString();
1503 if (d->handle == -1) {
1507 QDBusReply<int> r = walletLauncher->getInterface().entryType(d->handle, d->folder, key,
appid());
1511 #ifdef HAVE_KSECRETSSERVICE
1518 void Wallet::WalletPrivate::walletServiceUnregistered()
1525 q->slotWalletClosed(handle);
1529 void Wallet::slotFolderUpdated(
const QString& wallet,
const QString& folder) {
1530 #ifdef HAVE_KSECRETSSERVICE
1531 if (walletLauncher->m_useKSecretsService) {
1537 if (d->name == wallet) {
1540 #ifdef HAVE_KSECRETSSERVICE
1546 void Wallet::slotFolderListUpdated(
const QString& wallet) {
1547 #ifdef HAVE_KSECRETSSERVICE
1548 if (walletLauncher->m_useKSecretsService) {
1554 if (d->name == wallet) {
1557 #ifdef HAVE_KSECRETSSERVICE
1563 void Wallet::slotApplicationDisconnected(
const QString& wallet,
const QString& application) {
1564 #ifdef HAVE_KSECRETSSERVICE
1565 if (walletLauncher->m_useKSecretsService) {
1572 && d->name == wallet
1573 && application ==
appid()) {
1574 slotWalletClosed(d->handle);
1576 #ifdef HAVE_KSECRETSSERVICE
1581 void Wallet::walletAsyncOpened(
int tId,
int handle) {
1582 #ifdef HAVE_KSECRETSSERVICE
1583 if (walletLauncher->m_useKSecretsService) {
1590 if (d->transactionId != tId || d->handle != -1) {
1595 disconnect(
this, SLOT(walletAsyncOpened(
int,
int)));
1599 #ifdef HAVE_KSECRETSSERVICE
1604 void Wallet::emitWalletAsyncOpenError() {
1608 void Wallet::emitWalletOpened() {
1614 #ifdef HAVE_KSECRETSSERVICE
1615 if (walletLauncher->m_useKSecretsService) {
1616 kDebug(285) <<
"WARNING: changing semantics of folderDoesNotExist with KSS: will prompt for the password";
1627 QDBusReply<bool> r = walletLauncher->getInterface().folderDoesNotExist(wallet, folder);
1630 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1635 #ifdef HAVE_KSECRETSSERVICE
1643 #ifdef HAVE_KSECRETSSERVICE
1644 if (walletLauncher->m_useKSecretsService) {
1645 kDebug(285) <<
"WARNING: changing semantics of keyDoesNotExist with KSS: will prompt for the password";
1654 QDBusReply<bool> r = walletLauncher->getInterface().keyDoesNotExist(wallet, folder, key);
1657 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1662 #ifdef HAVE_KSECRETSSERVICE
1672 KWalletDLauncher::KWalletDLauncher()
1676 m_useKSecretsService = m_cgroup.readEntry(
"UseKSecretsService",
false);
1677 #ifdef HAVE_KSECRETSSERVICE
1678 if (m_useKSecretsService) {
1683 m_wallet =
new org::kde::KWallet(QString::fromLatin1(s_kwalletdServiceName),
"/modules/kwalletd", QDBusConnection::sessionBus());
1684 #ifdef HAVE_KSECRETSSERVICE
1689 KWalletDLauncher::~KWalletDLauncher()
1694 org::kde::KWallet &KWalletDLauncher::getInterface()
1697 Q_ASSERT(m_wallet != 0);
1700 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName)))
1703 bool walletEnabled = m_cgroup.readEntry(
"Enabled",
true);
1704 if (walletEnabled) {
1710 kError(285) <<
"Couldn't start kwalletd: " << error << endl;
1714 (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName))) {
1715 kDebug(285) <<
"The kwalletd service is still not registered";
1717 kDebug(285) <<
"The kwalletd service has been registered";
1720 kError(285) <<
"The kwalletd service has been disabled";
1729 #include "kwallet.moc"