diff --git a/libkdepim/ldap/ldapclientsearchconfig.cpp b/libkdepim/ldap/ldapclientsearchconfig.cpp --- a/libkdepim/ldap/ldapclientsearchconfig.cpp +++ b/libkdepim/ldap/ldapclientsearchconfig.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -34,23 +35,40 @@ class LdapClientSearchConfig::Private { public: - Private() - : useWallet( false ), + Private(LdapClientSearchConfig *parent) + : q_ptr( parent ), + useWallet( false ), askWallet( true ), - wallet( 0 ) + mWallet( 0 ) { } ~Private() { if (useWallet) { - wallet->deleteLater(); - wallet = 0; + mWallet->deleteLater(); + mWallet = 0; } } + + KWallet::Wallet *wallet() + { + Q_Q(LdapClientSearchConfig); + + if (!mWallet) { + mWallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); + if (mWallet) { + q->connect(mWallet, SIGNAL(walletClosed()), q, SLOT(slotWalletClosed())); + } + } + return mWallet; + } + bool useWallet; bool askWallet; - KWallet::Wallet* wallet; + KWallet::Wallet* mWallet; + LdapClientSearchConfig *const q_ptr; + Q_DECLARE_PUBLIC(LdapClientSearchConfig); }; K_GLOBAL_STATIC_WITH_ARGS( KConfig, s_config, ( QLatin1String("kabldaprc"), KConfig::NoGlobals ) ) @@ -61,7 +79,7 @@ } LdapClientSearchConfig::LdapClientSearchConfig(QObject *parent) - : QObject(parent), d(new LdapClientSearchConfig::Private()) + : QObject(parent), d(new LdapClientSearchConfig::Private(this)) { } @@ -111,29 +129,29 @@ KStandardGuiItem::yes(), KStandardGuiItem::no(), QLatin1String("DoAskToStoreToKwallet"))) { - d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); - if ( d->wallet ) { - connect(d->wallet, SIGNAL(walletClosed()), SLOT(slotWalletClosed())); + + KWallet::Wallet* wallet = d->wallet(); + if ( wallet ) { d->useWallet = true; - if ( !d->wallet->hasFolder( QLatin1String("ldapclient") ) ) { - d->wallet->createFolder( QLatin1String("ldapclient") ); + if ( !wallet->hasFolder( QLatin1String("ldapclient") ) ) { + wallet->createFolder( QLatin1String("ldapclient") ); } - d->wallet->setFolder( QLatin1String("ldapclient") ); - d->wallet->writePassword(pwdBindBNEntry, pwdBindDN ); + wallet->setFolder( QLatin1String("ldapclient") ); + wallet->writePassword(pwdBindBNEntry, pwdBindDN ); config.deleteEntry(pwdBindBNEntry); config.sync(); } } server.setPassword( pwdBindDN ); } else { //Look at in Wallet - d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); - if ( d->wallet ) { + KWallet::Wallet* wallet = d->wallet(); + if ( wallet ) { d->useWallet = true; - if ( !d->wallet->setFolder( QLatin1String("ldapclient") ) ) { - d->wallet->createFolder( QLatin1String("ldapclient") ); - d->wallet->setFolder( QLatin1String("ldapclient") ); + if ( !wallet->setFolder( QLatin1String("ldapclient") ) ) { + wallet->createFolder( QLatin1String("ldapclient") ); + wallet->setFolder( QLatin1String("ldapclient") ); } - d->wallet->readPassword( pwdBindBNEntry, pwdBindDN ); + wallet->readPassword( pwdBindBNEntry, pwdBindDN ); if (!pwdBindDN.isEmpty()) server.setPassword( pwdBindDN ); } else { @@ -184,11 +202,9 @@ const QString passwordEntry = prefix + QString::fromLatin1( "PwdBind%1" ).arg( j ); const QString password = server.password(); if (!password.isEmpty()) { - if (d->useWallet && !d->wallet) { - d->wallet = KWallet::Wallet::openWallet( KWallet::Wallet::LocalWallet(), 0 ); - } - if (d->wallet) { - d->wallet->writePassword(passwordEntry, password ); + KWallet::Wallet* wallet = d->wallet(); + if (d->useWallet && wallet) { + wallet->writePassword(passwordEntry, password ); } else { config.writeEntry( passwordEntry, password ); d->useWallet = false; @@ -227,8 +243,9 @@ void LdapClientSearchConfig::slotWalletClosed() { - delete d->wallet; - d->wallet = 0; + kDebug(5300) << "wallet was closed"; + delete d->mWallet; + d->mWallet = 0; } void LdapClientSearchConfig::askForWallet(bool askForWallet)