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
53 Q_DECLARE_METATYPE(StringByteArrayMap)
58 class KWalletDLauncher
63 org::kde::KWallet &getInterface();
69 bool m_useKSecretsService;
70 org::kde::KWallet *m_wallet;
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
226 #ifdef HAVE_KSECRETSSERVICE
227 void Wallet::WalletPrivate::createDefaultFolders()
233 folder = PasswordFolder();
236 folder = FormDataFolder();
239 #endif // HAVE_KSECRETSSERVICE
244 :
QObject(0L), d(new WalletPrivate(this, handle, name))
246 if (walletLauncher->m_useKSecretsService) {
250 QDBusServiceWatcher *watcher =
new QDBusServiceWatcher(QString::fromLatin1(s_kwalletdServiceName), QDBusConnection::sessionBus(),
251 QDBusServiceWatcher::WatchForUnregistration,
this);
252 connect(watcher, SIGNAL(serviceUnregistered(
QString)),
253 this, SLOT(walletServiceUnregistered()));
255 connect(&walletLauncher->getInterface(), SIGNAL(
walletClosed(
int)), SLOT(slotWalletClosed(
int)));
258 connect(&walletLauncher->getInterface(), SIGNAL(applicationDisconnected(
QString,
QString)), SLOT(slotApplicationDisconnected(
QString,
QString)));
261 if (d->handle != -1) {
262 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(d->handle);
263 if (r.isValid() && !r) {
273 #ifdef HAVE_KSECRETSSERVICE
274 if (walletLauncher->m_useKSecretsService) {
277 delete d->secretsCollection;
281 if (d->handle != -1) {
282 if (!walletLauncher.isDestroyed()) {
283 walletLauncher->getInterface().close(d->handle,
false,
appid());
285 kDebug(285) <<
"Problem with static destruction sequence."
286 "Destroy any static Wallet before the event-loop exits.";
292 #ifdef HAVE_KSECRETSSERVICE
301 #ifdef HAVE_KSECRETSSERVICE
302 if (walletLauncher->m_useKSecretsService) {
303 KSecretsService::ListCollectionsJob *listJob = KSecretsService::Collection::listCollections();
304 if ( listJob->exec() ) {
305 result = listJob->collections();
308 kDebug(285) <<
"Cannot execute ListCollectionsJob: " << listJob->errorString();
313 QDBusReply<QStringList> r = walletLauncher->getInterface().wallets();
317 kDebug(285) <<
"Invalid DBus reply: " << r.error();
321 #ifdef HAVE_KSECRETSSERVICE
330 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::changePassword().";
334 #ifdef HAVE_KSECRETSSERVICE
335 if (walletLauncher->m_useKSecretsService) {
336 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection( name );
337 KSecretsService::ChangeCollectionPasswordJob* changePwdJob = coll->changePassword();
338 if ( !changePwdJob->exec() ) {
339 kDebug(285) <<
"Cannot execute change password job: " << changePwdJob->errorString();
345 walletLauncher->getInterface().changePassword(name, (qlonglong)w,
appid());
346 #ifdef HAVE_KSECRETSSERVICE
353 #ifdef HAVE_KSECRETSSERVICE
354 if (walletLauncher->m_useKSecretsService) {
355 return walletLauncher->m_cgroup.readEntry(
"Enabled",
true);
359 QDBusReply<bool> r = walletLauncher->getInterface().isEnabled();
363 kDebug(285) <<
"Invalid DBus reply: " << r.error();
368 #ifdef HAVE_KSECRETSSERVICE
375 #ifdef HAVE_KSECRETSSERVICE
376 if (walletLauncher->m_useKSecretsService) {
377 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection( name, KSecretsService::Collection::OpenOnly );
378 KSecretsService::ReadCollectionPropertyJob *readLocked = coll->isLocked();
379 if ( readLocked->exec() ) {
380 return !readLocked->propertyValue().toBool();
383 kDebug() <<
"ReadLocked job failed";
389 QDBusReply<bool> r = walletLauncher->getInterface().isOpen(name);
393 kDebug(285) <<
"Invalid DBus reply: " << r.error();
398 #ifdef HAVE_KSECRETSSERVICE
404 #ifdef HAVE_KSECRETSSERVICE
405 if (walletLauncher->m_useKSecretsService) {
406 kDebug(285) <<
"Wallet::closeWallet NOOP";
411 QDBusReply<int> r = walletLauncher->getInterface().close(name, force);
415 kDebug(285) <<
"Invalid DBus reply: " << r.error();
420 #ifdef HAVE_KSECRETSSERVICE
427 #ifdef HAVE_KSECRETSSERVICE
428 if (walletLauncher->m_useKSecretsService) {
429 KSecretsService::Collection *coll = KSecretsService::Collection::findCollection(name, KSecretsService::Collection::OpenOnly);
430 KJob *deleteJob = coll->deleteCollection();
431 if (!deleteJob->exec()) {
432 kDebug(285) <<
"Cannot execute delete job " << deleteJob->errorString();
434 return deleteJob->error();
438 QDBusReply<int> r = walletLauncher->getInterface().deleteWallet(name);
442 kDebug(285) <<
"Invalid DBus reply: " << r.error();
447 #ifdef HAVE_KSECRETSSERVICE
454 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::openWallet().";
456 #ifdef HAVE_KSECRETSSERVICE
457 if (walletLauncher->m_useKSecretsService) {
460 wallet->d->secretsCollection = KSecretsService::Collection::findCollection(name, KSecretsService::Collection::CreateCollection, QVariantMap(), w);
461 connect( wallet->d->secretsCollection, SIGNAL(statusChanged(
int)), wallet, SLOT(slotCollectionStatusChanged(
int)) );
462 connect( wallet->d->secretsCollection, SIGNAL(deleted()), wallet, SLOT(slotCollectionDeleted()) );
464 kDebug() <<
"WARNING openWallet OpenType=Synchronous requested";
476 connect(&walletLauncher->getInterface(), SIGNAL(walletAsyncOpened(
int,
int)),
477 wallet, SLOT(walletAsyncOpened(
int,
int)));
485 r = walletLauncher->getInterface().open(name, (qlonglong)w,
appid());
491 r = walletLauncher->getInterface().openAsync(name, (qlonglong)w,
appid(),
true);
492 }
else if (ot ==
Path) {
493 r = walletLauncher->getInterface().openPathAsync(name, (qlonglong)w,
appid(),
true);
500 kDebug(285) <<
"Invalid DBus reply: " << r.error();
504 wallet->d->transactionId = r.value();
508 if (wallet->d->transactionId < 0) {
512 wallet->d->handle = r.value();
515 if (wallet->d->transactionId < 0) {
516 QTimer::singleShot(0, wallet, SLOT(emitWalletAsyncOpenError()));
522 #ifdef HAVE_KSECRETSSERVICE
527 void Wallet::slotCollectionStatusChanged(
int status)
529 #ifdef HAVE_KSECRETSSERVICE
530 KSecretsService::Collection::Status collStatus = (KSecretsService::Collection::Status)status;
531 switch ( collStatus ) {
532 case KSecretsService::Collection::NewlyCreated:
533 d->createDefaultFolders();
535 case KSecretsService::Collection::FoundExisting:
538 case KSecretsService::Collection::Deleted:
539 case KSecretsService::Collection::Invalid:
540 case KSecretsService::Collection::Pending:
543 case KSecretsService::Collection::NotFound:
544 emitWalletAsyncOpenError();
550 void Wallet::slotCollectionDeleted()
558 #ifdef HAVE_KSECRETSSERVICE
559 if (walletLauncher->m_useKSecretsService) {
560 kDebug() <<
"Wallet::disconnectApplication NOOP";
565 QDBusReply<bool> r = walletLauncher->getInterface().disconnectApplication(wallet, app);
569 kDebug(285) <<
"Invalid DBus reply: " << r.error();
574 #ifdef HAVE_KSECRETSSERVICE
581 #ifdef HAVE_KSECRETSSERVICE
582 if (walletLauncher->m_useKSecretsService) {
583 kDebug() <<
"KSecretsService does not handle users list";
588 QDBusReply<QStringList> r = walletLauncher->getInterface().users(name);
591 kDebug(285) <<
"Invalid DBus reply: " << r.error();
596 #ifdef HAVE_KSECRETSSERVICE
603 #ifdef HAVE_KSECRETSSERVICE
604 if (walletLauncher->m_useKSecretsService) {
609 if (d->handle == -1) {
613 walletLauncher->getInterface().sync(d->handle,
appid());
614 #ifdef HAVE_KSECRETSSERVICE
622 #ifdef HAVE_KSECRETSSERVICE
623 if (walletLauncher->m_useKSecretsService) {
624 KSecretsService::CollectionLockJob *lockJob = d->secretsCollection->lock();
625 if (lockJob->exec()) {
630 kDebug(285) <<
"Cannot execute KSecretsService::CollectionLockJob : " << lockJob->errorString();
633 return lockJob->error();
637 if (d->handle == -1) {
641 QDBusReply<int> r = walletLauncher->getInterface().close(d->handle,
true,
appid());
649 kDebug(285) <<
"Invalid DBus reply: " << r.error();
652 #ifdef HAVE_KSECRETSSERVICE
664 #ifdef HAVE_KSECRETSSERVICE
665 if (walletLauncher->m_useKSecretsService) {
666 return !d->secretsCollection->isLocked();
670 return d->handle != -1;
671 #ifdef HAVE_KSECRETSSERVICE
679 kDebug(285) <<
"Pass a valid window to KWallet::Wallet::requestChangePassword().";
681 #ifdef HAVE_KSECRETSSERVICE
682 if (walletLauncher->m_useKSecretsService) {
683 KSecretsService::ChangeCollectionPasswordJob *changePwdJob = d->secretsCollection->changePassword();
684 if (!changePwdJob->exec()) {
685 kDebug(285) <<
"Cannot execute ChangeCollectionPasswordJob : " << changePwdJob->errorString();
690 if (d->handle == -1) {
697 walletLauncher->getInterface().changePassword(d->name, (qlonglong)w,
appid());
698 #ifdef HAVE_KSECRETSSERVICE
704 void Wallet::slotWalletClosed(
int handle) {
705 #ifdef HAVE_KSECRETSSERVICE
706 if (walletLauncher->m_useKSecretsService) {
712 if (d->handle == handle) {
718 #ifdef HAVE_KSECRETSSERVICE
725 #ifdef HAVE_KSECRETSSERVICE
726 if (walletLauncher->m_useKSecretsService) {
731 KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs);
733 if (searchJob->exec()) {
734 KSecretsService::ReadCollectionItemsJob::ItemList itemList = searchJob->items();
735 foreach(
const KSecretsService::ReadCollectionItemsJob::Item &item, itemList ) {
736 KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes();
737 if (readAttrsJob->exec()) {
740 if (!folder.isEmpty() && !result.contains(folder)) {
741 result.append(folder);
745 kDebug(285) <<
"Cannot read item attributes : " << readAttrsJob->errorString();
750 kDebug(285) <<
"Cannot execute ReadCollectionItemsJob : " << searchJob->errorString();
756 if (d->handle == -1) {
760 QDBusReply<QStringList> r = walletLauncher->getInterface().folderList(d->handle,
appid());
763 kDebug(285) <<
"Invalid DBus reply: " << r.error();
768 #ifdef HAVE_KSECRETSSERVICE
775 #ifdef HAVE_KSECRETSSERVICE
776 if (walletLauncher->m_useKSecretsService) {
780 KSecretsService::SearchCollectionItemsJob *readItemsJob = d->secretsCollection->searchItems( attrs );
781 if ( readItemsJob->exec() ) {
782 foreach( KSecretsService::SearchCollectionItemsJob::Item item, readItemsJob->items() ) {
783 KSecretsService::ReadItemPropertyJob *readLabelJob = item->label();
784 if ( readLabelJob->exec() ) {
785 result.append( readLabelJob->propertyValue().toString() );
788 kDebug(285) <<
"Cannot execute readLabelJob" << readItemsJob->errorString();
793 kDebug(285) <<
"Cannot execute readItemsJob" << readItemsJob->errorString();
799 if (d->handle == -1) {
803 QDBusReply<QStringList> r = walletLauncher->getInterface().entryList(d->handle, d->folder,
appid());
806 kDebug(285) <<
"Invalid DBus reply: " << r.error();
811 #ifdef HAVE_KSECRETSSERVICE
818 #ifdef HAVE_KSECRETSSERVICE
819 if (walletLauncher->m_useKSecretsService) {
824 return folders.contains(f);
828 if (d->handle == -1) {
832 QDBusReply<bool> r = walletLauncher->getInterface().hasFolder(d->handle, f,
appid());
835 kDebug(285) <<
"Invalid DBus reply: " << r.error();
840 #ifdef HAVE_KSECRETSSERVICE
847 #ifdef HAVE_KSECRETSSERVICE
848 if (walletLauncher->m_useKSecretsService) {
856 if (d->handle == -1) {
861 QDBusReply<bool> r = walletLauncher->getInterface().createFolder(d->handle, f,
appid());
865 kDebug(285) <<
"Invalid DBus reply: " << r.error();
873 #ifdef HAVE_KSECRETSSERVICE
882 #ifdef HAVE_KSECRETSSERVICE
883 if (walletLauncher->m_useKSecretsService) {
891 if (d->handle == -1) {
897 if (f == d->folder) {
906 #ifdef HAVE_KSECRETSSERVICE
915 #ifdef HAVE_KSECRETSSERVICE
916 if (walletLauncher->m_useKSecretsService) {
921 KSecretsService::SearchCollectionItemsJob *searchJob = d->secretsCollection->searchItems(attrs);
922 if (searchJob->exec()) {
923 KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items();
924 if ( !itemList.isEmpty() ) {
926 foreach(
const KSecretsService::SearchCollectionItemsJob::Item &item, itemList ) {
927 KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem();
928 if (!deleteJob->exec()) {
929 kDebug(285) <<
"Cannot delete item : " << deleteJob->errorString();
937 kDebug(285) <<
"Cannot execute KSecretsService::SearchCollectionItemsJob : " << searchJob->errorString();
943 if (d->handle == -1) {
947 QDBusReply<bool> r = walletLauncher->getInterface().removeFolder(d->handle, f,
appid());
948 if (d->folder == f) {
954 kDebug(285) <<
"Invalid DBus reply: " << r.error();
959 #ifdef HAVE_KSECRETSSERVICE
969 #ifdef HAVE_KSECRETSSERVICE
970 QExplicitlySharedDataPointer<KSecretsService::SecretItem> Wallet::WalletPrivate::findItem(
const QString& key )
const
972 QExplicitlySharedDataPointer<KSecretsService::SecretItem> result;
975 attrs[
"Label"] = key;
976 KSecretsService::SearchCollectionItemsJob *searchJob = secretsCollection->searchItems(attrs);
977 if (searchJob->exec()) {
978 KSecretsService::SearchCollectionItemsJob::ItemList itemList = searchJob->items();
979 if ( !itemList.isEmpty() ) {
980 result = itemList.first();
983 kDebug(285) <<
"entry named " << key <<
" not found in folder " << folder;
987 kDebug(285) <<
"Cannot exec KSecretsService::SearchCollectionItemsJob : " << searchJob->errorString();
993 template <
typename T>
994 int Wallet::WalletPrivate::readEntry(
const QString& key, T& value)
const
997 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = findItem(key);
999 KSecretsService::GetSecretItemSecretJob *readJob = item->getSecret();
1000 if ( readJob->exec() ) {
1001 KSecretsService::Secret theSecret = readJob->secret();
1002 kDebug(285) <<
"Secret contentType is " << theSecret.contentType();
1003 value = theSecret.value().value<
T>();
1007 kDebug(285) <<
"Cannot exec GetSecretItemSecretJob : " << readJob->errorString();
1013 bool Wallet::WalletPrivate::readSecret(
const QString& key, KSecretsService::Secret& value)
const
1015 bool result =
false;
1016 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = findItem(key);
1018 KSecretsService::GetSecretItemSecretJob *readJob = item->getSecret();
1019 if ( readJob->exec() ) {
1020 value = readJob->secret();
1024 kDebug(285) <<
"Cannot exec GetSecretItemSecretJob : " << readJob->errorString();
1034 #ifdef HAVE_KSECRETSSERVICE
1035 if (walletLauncher->m_useKSecretsService) {
1036 return d->readEntry<QByteArray>(key, value);
1040 if (d->handle == -1) {
1044 QDBusReply<QByteArray> r = walletLauncher->getInterface().readEntry(d->handle, d->folder, key,
appid());
1049 #ifdef HAVE_KSECRETSSERVICE
1056 #ifdef HAVE_KSECRETSSERVICE
1057 struct Wallet::WalletPrivate::InsertIntoEntryList {
1059 bool operator() ( Wallet::WalletPrivate*,
const QString& label, KSecretsService::SecretItem* item ) {
1060 bool result =
false;
1061 KSecretsService::GetSecretItemSecretJob *readSecretJob = item->getSecret();
1062 if ( readSecretJob->exec() ) {
1063 _value.insert( label, readSecretJob->secret().value().toByteArray() );
1067 kDebug(285) <<
"Cannot execute GetSecretItemSecretJob " << readSecretJob->errorString();
1079 #ifdef HAVE_KSECRETSSERVICE
1080 if (walletLauncher->m_useKSecretsService) {
1081 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoEntryList( value ) );
1087 if (d->handle == -1) {
1091 QDBusReply<QVariantMap> r = walletLauncher->getInterface().readEntryList(d->handle, d->folder, key,
appid());
1095 const QVariantMap val = r.value();
1096 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1097 value.insert(it.key(), it.value().toByteArray());
1100 #ifdef HAVE_KSECRETSSERVICE
1111 #ifdef HAVE_KSECRETSSERVICE
1112 if (walletLauncher->m_useKSecretsService) {
1113 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem(oldName);
1115 KSecretsService::WriteItemPropertyJob *writeJob = item->setLabel(newName);
1116 if (!writeJob->exec()) {
1117 kDebug(285) <<
"Cannot exec WriteItemPropertyJob : " << writeJob->errorString();
1119 rc = writeJob->error();
1122 kDebug(285) <<
"Cannot locate item " << oldName <<
" in folder " << d->folder;
1127 if (d->handle == -1) {
1131 QDBusReply<int> r = walletLauncher->getInterface().renameEntry(d->handle, d->folder, oldName, newName,
appid());
1135 #ifdef HAVE_KSECRETSSERVICE
1146 #ifdef HAVE_KSECRETSSERVICE
1147 if (walletLauncher->m_useKSecretsService) {
1149 rc = d->readEntry< QByteArray >(key, ba);
1150 if ( rc == 0 && !ba.isEmpty()){
1151 QDataStream ds( &ba, QIODevice::ReadOnly );
1159 if (d->handle == -1) {
1163 QDBusReply<QByteArray> r = walletLauncher->getInterface().readMap(d->handle, d->folder, key,
appid());
1168 QDataStream ds(&v, QIODevice::ReadOnly);
1172 #ifdef HAVE_KSECRETSSERVICE
1179 #ifdef HAVE_KSECRETSSERVICE
1180 struct Wallet::WalletPrivate::InsertIntoMapList {
1182 bool operator() ( Wallet::WalletPrivate* d,
const QString& label, KSecretsService::SecretItem* ) {
1183 bool result =
false;
1186 _value.insert( label, map );
1198 #ifdef HAVE_KSECRETSSERVICE
1199 if (walletLauncher->m_useKSecretsService) {
1200 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoMapList( value ) );
1206 if (d->handle == -1) {
1210 QDBusReply<QVariantMap> r =
1211 walletLauncher->getInterface().readMapList(d->handle, d->folder, key,
appid());
1214 const QVariantMap val = r.value();
1215 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1216 QByteArray mapData = it.value().toByteArray();
1217 if (!mapData.isEmpty()) {
1218 QDataStream ds(&mapData, QIODevice::ReadOnly);
1221 value.insert(it.key(), v);
1225 #ifdef HAVE_KSECRETSSERVICE
1236 #ifdef HAVE_KSECRETSSERVICE
1237 if (walletLauncher->m_useKSecretsService) {
1238 rc = d->readEntry<
QString>(key, value);
1242 if (d->handle == -1) {
1246 QDBusReply<QString> r = walletLauncher->getInterface().readPassword(d->handle, d->folder, key,
appid());
1251 #ifdef HAVE_KSECRETSSERVICE
1258 #ifdef HAVE_KSECRETSSERVICE
1259 struct Wallet::WalletPrivate::InsertIntoPasswordList {
1261 bool operator() ( Wallet::WalletPrivate* d,
const QString& label, KSecretsService::SecretItem* ) {
1262 bool result =
false;
1264 if ( d->readEntry<
QString>( label, pwd ) == 0 ) {
1265 _value.insert( label, pwd );
1277 #ifdef HAVE_KSECRETSSERVICE
1278 if (walletLauncher->m_useKSecretsService) {
1279 rc = d->forEachItemThatMatches( key, WalletPrivate::InsertIntoPasswordList( value ) );
1285 if (d->handle == -1) {
1289 QDBusReply<QVariantMap> r = walletLauncher->getInterface().readPasswordList(d->handle, d->folder, key,
appid());
1292 const QVariantMap val = r.value();
1293 for( QVariantMap::const_iterator it = val.begin(); it != val.end(); ++it ) {
1294 value.insert(it.key(), it.value().toString());
1297 #ifdef HAVE_KSECRETSSERVICE
1308 #ifdef HAVE_KSECRETSSERVICE
1309 if (walletLauncher->m_useKSecretsService) {
1310 rc = d->writeEntry( key, value, entryType );
1314 if (d->handle == -1) {
1318 QDBusReply<int> r = walletLauncher->getInterface().writeEntry(d->handle, d->folder, key, value,
int(entryType),
appid());
1322 #ifdef HAVE_KSECRETSSERVICE
1333 #ifdef HAVE_KSECRETSSERVICE
1334 if (walletLauncher->m_useKSecretsService) {
1339 if (d->handle == -1) {
1343 QDBusReply<int> r = walletLauncher->getInterface().writeEntry(d->handle, d->folder, key, value,
appid());
1347 #ifdef HAVE_KSECRETSSERVICE
1358 #ifdef HAVE_KSECRETSSERVICE
1359 if (walletLauncher->m_useKSecretsService) {
1360 d->writeEntry( key, value,
Map );
1366 if (d->handle == -1) {
1371 QDataStream ds(&mapData, QIODevice::WriteOnly);
1373 QDBusReply<int> r = walletLauncher->getInterface().writeMap(d->handle, d->folder, key, mapData,
appid());
1377 #ifdef HAVE_KSECRETSSERVICE
1388 #ifdef HAVE_KSECRETSSERVICE
1389 if (walletLauncher->m_useKSecretsService) {
1390 rc = d->writeEntry( key, value,
Password );
1394 if (d->handle == -1) {
1398 QDBusReply<int> r = walletLauncher->getInterface().writePassword(d->handle, d->folder, key, value,
appid());
1402 #ifdef HAVE_KSECRETSSERVICE
1411 #ifdef HAVE_KSECRETSSERVICE
1412 if (walletLauncher->m_useKSecretsService) {
1413 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1418 if (d->handle == -1) {
1422 QDBusReply<bool> r = walletLauncher->getInterface().hasEntry(d->handle, d->folder, key,
appid());
1425 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1430 #ifdef HAVE_KSECRETSSERVICE
1439 #ifdef HAVE_KSECRETSSERVICE
1440 if (walletLauncher->m_useKSecretsService) {
1441 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1443 KSecretsService::SecretItemDeleteJob *deleteJob = item->deleteItem();
1444 if ( !deleteJob->exec() ) {
1445 kDebug(285) <<
"Cannot execute SecretItemDeleteJob " << deleteJob->errorString();
1447 rc = deleteJob->error();
1452 if (d->handle == -1) {
1456 QDBusReply<int> r = walletLauncher->getInterface().removeEntry(d->handle, d->folder, key,
appid());
1460 #ifdef HAVE_KSECRETSSERVICE
1471 #ifdef HAVE_KSECRETSSERVICE
1472 if (walletLauncher->m_useKSecretsService) {
1473 QExplicitlySharedDataPointer<KSecretsService::SecretItem> item = d->findItem( key );
1475 KSecretsService::ReadItemPropertyJob *readAttrsJob = item->attributes();
1476 if ( readAttrsJob->exec() ) {
1481 rc = entryType.toInt( &ok );
1489 kDebug(285) <<
"Cannot execute GetSecretItemSecretJob " << readAttrsJob->errorString();
1495 if (d->handle == -1) {
1499 QDBusReply<int> r = walletLauncher->getInterface().entryType(d->handle, d->folder, key,
appid());
1503 #ifdef HAVE_KSECRETSSERVICE
1510 void Wallet::WalletPrivate::walletServiceUnregistered()
1513 q->slotWalletClosed(handle);
1517 void Wallet::slotFolderUpdated(
const QString& wallet,
const QString& folder) {
1518 #ifdef HAVE_KSECRETSSERVICE
1519 if (walletLauncher->m_useKSecretsService) {
1525 if (d->name == wallet) {
1528 #ifdef HAVE_KSECRETSSERVICE
1534 void Wallet::slotFolderListUpdated(
const QString& wallet) {
1535 #ifdef HAVE_KSECRETSSERVICE
1536 if (walletLauncher->m_useKSecretsService) {
1542 if (d->name == wallet) {
1545 #ifdef HAVE_KSECRETSSERVICE
1551 void Wallet::slotApplicationDisconnected(
const QString& wallet,
const QString& application) {
1552 #ifdef HAVE_KSECRETSSERVICE
1553 if (walletLauncher->m_useKSecretsService) {
1560 && d->name == wallet
1561 && application ==
appid()) {
1562 slotWalletClosed(d->handle);
1564 #ifdef HAVE_KSECRETSSERVICE
1569 void Wallet::walletAsyncOpened(
int tId,
int handle) {
1570 #ifdef HAVE_KSECRETSSERVICE
1571 if (walletLauncher->m_useKSecretsService) {
1578 if (d->transactionId != tId || d->handle != -1) {
1583 disconnect(
this, SLOT(walletAsyncOpened(
int,
int)));
1587 #ifdef HAVE_KSECRETSSERVICE
1592 void Wallet::emitWalletAsyncOpenError() {
1596 void Wallet::emitWalletOpened() {
1602 #ifdef HAVE_KSECRETSSERVICE
1603 if (walletLauncher->m_useKSecretsService) {
1604 kDebug(285) <<
"WARNING: changing semantics of folderDoesNotExist with KSS: will prompt for the password";
1615 QDBusReply<bool> r = walletLauncher->getInterface().folderDoesNotExist(wallet, folder);
1618 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1623 #ifdef HAVE_KSECRETSSERVICE
1631 #ifdef HAVE_KSECRETSSERVICE
1632 if (walletLauncher->m_useKSecretsService) {
1633 kDebug(285) <<
"WARNING: changing semantics of keyDoesNotExist with KSS: will prompt for the password";
1642 QDBusReply<bool> r = walletLauncher->getInterface().keyDoesNotExist(wallet, folder, key);
1645 kDebug(285) <<
"Invalid DBus reply: " << r.error();
1650 #ifdef HAVE_KSECRETSSERVICE
1660 KWalletDLauncher::KWalletDLauncher()
1664 m_useKSecretsService = m_cgroup.readEntry(
"UseKSecretsService",
false);
1665 #ifdef HAVE_KSECRETSSERVICE
1666 if (m_useKSecretsService) {
1671 m_wallet =
new org::kde::KWallet(QString::fromLatin1(s_kwalletdServiceName),
"/modules/kwalletd", QDBusConnection::sessionBus());
1672 #ifdef HAVE_KSECRETSSERVICE
1677 KWalletDLauncher::~KWalletDLauncher()
1682 org::kde::KWallet &KWalletDLauncher::getInterface()
1685 Q_ASSERT(m_wallet != 0);
1688 if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName)))
1691 bool walletEnabled = m_cgroup.readEntry(
"Enabled",
true);
1692 if (walletEnabled) {
1698 kError(285) <<
"Couldn't start kwalletd: " << error << endl;
1702 (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QString::fromLatin1(s_kwalletdServiceName))) {
1703 kDebug(285) <<
"The kwalletd service is still not registered";
1705 kDebug(285) <<
"The kwalletd service has been registered";
1708 kError(285) <<
"The kwalletd service has been disabled";
1717 #include "kwallet.moc"
virtual bool hasEntry(const QString &key)
Determine if the current folder has they entry key.
virtual void requestChangePassword(WId w)
Request to the wallet service to change the password of the current wallet.
Wallet(int handle, const QString &name)
Construct a KWallet object.
virtual const QString & walletName() const
The name of the current wallet.
KAutostart::StartPhase readEntry(const KConfigGroup &group, const char *key, const KAutostart::StartPhase &aDefault)
virtual bool setFolder(const QString &f)
Set the current working folder to f.
virtual int renameEntry(const QString &oldName, const QString &newName)
Rename the entry oldName to newName.
virtual EntryType entryType(const QString &key)
Determine the type of the entry key in this folder.
void folderListUpdated()
Emitted when the folder list is changed in this wallet.
virtual void virtual_hook(int id, void *data)
QMap< QString, StringStringMap > StringToStringStringMapMap
QString label(StandardShortcut id)
Returns a localized label for user-visible display.
#define K_GLOBAL_STATIC(TYPE, NAME)
const char * name(StandardAction id)
This will return the internal name of a given standard action.
virtual ~Wallet()
Destroy a KWallet object.
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static bool isEnabled()
Determine if the KDE wallet is enabled.
virtual int readMap(const QString &key, QMap< QString, QString > &value)
Read the map entry key from the current folder.
virtual int removeEntry(const QString &key)
Remove the entry key from the current folder.
const KAboutData * aboutData() const
QMap< QString, QByteArray > StringByteArrayMap
int readPasswordList(const QString &key, QMap< QString, QString > &value)
Read the password entry key from the current folder.
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
static Wallet * openWallet(const QString &name, WId w, OpenType ot=Synchronous)
Open the wallet name.
virtual int writePassword(const QString &key, const QString &value)
Write key = value as a password to the current folder.
void walletOpened(bool success)
Emitted when a wallet is opened in asynchronous mode.
virtual int lockWallet()
This closes and locks the current wallet.
virtual bool hasFolder(const QString &f)
Determine if the folder f exists in the wallet.
void folderUpdated(const QString &folder)
Emitted when a folder in this wallet is updated.
virtual bool removeFolder(const QString &f)
Remove the folder f and all its entries from the wallet.
virtual int readPassword(const QString &key, QString &value)
Read the password entry key from the current folder.
virtual QStringList entryList()
Return the list of keys of all entries in this folder.
int readEntryList(const QString &key, QMap< QString, QByteArray > &value)
Read the entries matching key from the current folder.
QString componentName() const
static QStringList walletList()
List all the wallets available.
static bool disconnectApplication(const QString &wallet, const QString &app)
Disconnect the application app from wallet.
void walletClosed()
Emitted when this wallet is closed.
virtual int readEntry(const QString &key, QByteArray &value)
Read the entry key from the current folder.
static void changePassword(const QString &name, WId w)
Request to the wallet service to change the password of the wallet name.
KGuiItem ok()
Returns the 'Ok' gui item.
#define KSS_ATTR_ENTRYFOLDER
NOTE: KSecretsService folder semantics The KWallet API uses folders for organising items...
static void allowExternalProcessWindowActivation(int pid=-1)
Allows a window from another process to raise and activate itself.
QString programName() const
static QStringList users(const QString &wallet)
List the applications that are using the wallet wallet.
int readMapList(const QString &key, QMap< QString, QMap< QString, QString > > &value)
Read the map entry key from the current folder.
virtual bool createFolder(const QString &f)
Created the folder f.
virtual int sync()
This syncs the wallet file on disk with what is in memory.
static int closeWallet(const QString &name, bool force)
Close the wallet name.
virtual QStringList folderList()
Obtain the list of all folders contained in the wallet.
const KComponentData & mainComponent()
static bool keyDoesNotExist(const QString &wallet, const QString &folder, const QString &key)
Determine if an entry in a folder does not exist in a wallet.
QMap< QString, QString > StringStringMap
static int deleteWallet(const QString &name)
Delete the wallet name.
static void registerTypes()
#define KSS_ATTR_WALLETTYPE
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
static const char s_kwalletdServiceName[]
virtual const QString & currentFolder() const
Determine the current working folder in the wallet.
T readEntry(const QString &key, const T &aDefault) const
virtual int writeEntry(const QString &key, const QByteArray &value, EntryType entryType)
Write key = value as a binary entry to the current folder.
virtual bool isOpen() const
Determine if the current wallet is open, and is a valid wallet handle.
static bool folderDoesNotExist(const QString &wallet, const QString &folder)
Determine if a folder does not exist in a wallet.
virtual int writeMap(const QString &key, const QMap< QString, QString > &value)
Write key = value as a map to the current folder.