From 0af77fcbdeeb6aa1afafb2dbbdbb3e246d99c9df Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sun, 28 Mar 2021 21:36:06 +0300 Subject: [PATCH] kwalletd: indent and format Signed-off-by: Ivailo Monev --- kwalletd/kwalletd.cpp | 1589 +++++++++++++------------ kwalletd/tests/kwalletasync.cpp | 54 +- kwalletd/tests/kwalletautoclose.cpp | 26 +- kwalletd/tests/kwalletautoclose.h | 6 +- kwalletd/tests/kwalletboth.cpp | 87 +- kwalletd/tests/kwalletmany.cpp | 78 +- kwalletd/tests/kwalletmany.h | 24 +- kwalletd/tests/kwalletnoautoclose.cpp | 128 +- kwalletd/tests/kwalletpath.cpp | 30 +- kwalletd/tests/kwalletsync.cpp | 31 +- kwalletd/tests/kwalletwizardtest.cpp | 1 - 11 files changed, 1027 insertions(+), 1027 deletions(-) diff --git a/kwalletd/kwalletd.cpp b/kwalletd/kwalletd.cpp index c6d92877..06c89b67 100644 --- a/kwalletd/kwalletd.cpp +++ b/kwalletd/kwalletd.cpp @@ -268,16 +268,16 @@ void KWalletD::processTransactions() { } int KWalletD::openPath(const QString& path, qlonglong wId, const QString& appid) { - int tId = openPathAsync(path, wId, appid, false); - if (tId < 0) { - return tId; - } + int tId = openPathAsync(path, wId, appid, false); + if (tId < 0) { + return tId; + } - // NOTE the real return value will be sent by the dbusmessage delayed reply - return 0; - // wait for the open-transaction to be processed -// KWalletOpenLoop loop(this); -// return loop.waitForAsyncOpen(tId); + // NOTE the real return value will be sent by the dbusmessage delayed reply + return 0; + // wait for the open-transaction to be processed + // KWalletOpenLoop loop(this); + // return loop.waitForAsyncOpen(tId); } int KWalletD::open(const QString& wallet, qlonglong wId, const QString& appid) { @@ -311,80 +311,82 @@ int KWalletD::open(const QString& wallet, qlonglong wId, const QString& appid) { int KWalletD::openAsync(const QString& wallet, qlonglong wId, const QString& appid, bool handleSession) { - if (!_enabled) { // guard - return -1; - } + if (!_enabled) { // guard + return -1; + } - if (!QRegExp("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\.\\+\\_\\s]+$").exactMatch(wallet)) { - return -1; - } - - KWalletTransaction *xact = new KWalletTransaction(connection()); - _transactions.append(xact); - - xact->appid = appid; - xact->wallet = wallet; - xact->wId = wId; - xact->modal = true; // mark dialogs as modal, the app has blocking wait - xact->tType = KWalletTransaction::Open; - xact->isPath = false; - if (handleSession) { - kDebug() << "openAsync for " << message().service(); - _serviceWatcher.setConnection(connection()); - _serviceWatcher.addWatchedService(message().service()); - xact->service = message().service(); - } - QTimer::singleShot(0, this, SLOT(processTransactions())); - checkActiveDialog(); - // opening is in progress. return the transaction number - return xact->tId; -} - -int KWalletD::openPathAsync(const QString& path, qlonglong wId, const QString& appid, - bool handleSession) { - if (!_enabled) { // gaurd - return -1; - } + if (!QRegExp("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\.\\+\\_\\s]+$").exactMatch(wallet)) { + return -1; + } KWalletTransaction *xact = new KWalletTransaction(connection()); _transactions.append(xact); - xact->appid = appid; - xact->wallet = path; - xact->wId = wId; - xact->modal = true; - xact->tType = KWalletTransaction::Open; - xact->isPath = true; - if (handleSession) { + xact->appid = appid; + xact->wallet = wallet; + xact->wId = wId; + xact->modal = true; // mark dialogs as modal, the app has blocking wait + xact->tType = KWalletTransaction::Open; + xact->isPath = false; + if (handleSession) { + kDebug() << "openAsync for " << message().service(); + _serviceWatcher.setConnection(connection()); + _serviceWatcher.addWatchedService(message().service()); + xact->service = message().service(); + } + QTimer::singleShot(0, this, SLOT(processTransactions())); + checkActiveDialog(); + // opening is in progress. return the transaction number + return xact->tId; +} + +int KWalletD::openPathAsync(const QString& path, qlonglong wId, const QString& appid, + bool handleSession) { + if (!_enabled) { // gaurd + return -1; + } + + KWalletTransaction *xact = new KWalletTransaction(connection()); + _transactions.append(xact); + + xact->appid = appid; + xact->wallet = path; + xact->wId = wId; + xact->modal = true; + xact->tType = KWalletTransaction::Open; + xact->isPath = true; + if (handleSession) { kDebug() << "openPathAsync " << message().service(); _serviceWatcher.setConnection(connection()); _serviceWatcher.addWatchedService(message().service()); - xact->service = message().service(); - } - QTimer::singleShot(0, this, SLOT(processTransactions())); - checkActiveDialog(); - // opening is in progress. return the transaction number - return xact->tId; + xact->service = message().service(); + } + QTimer::singleShot(0, this, SLOT(processTransactions())); + checkActiveDialog(); + // opening is in progress. return the transaction number + return xact->tId; } // Sets up a dialog that will be shown by kwallet. void KWalletD::setupDialog( QWidget* dialog, WId wId, const QString& appid, bool modal ) { - if( wId != 0 ) - KWindowSystem::setMainWindow( dialog, wId ); // correct, set dialog parent - else { - if( appid.isEmpty()) - kWarning() << "Using kwallet without parent window!"; - else - kWarning() << "Application '" << appid << "' using kwallet without parent window!"; - // allow dialog activation even if it interrupts, better than trying hacks - // with keeping the dialog on top or on all desktops - kapp->updateUserTimestamp(); - } - if( modal ) - KWindowSystem::setState( dialog->winId(), NET::Modal ); - else - KWindowSystem::clearState( dialog->winId(), NET::Modal ); - activeDialog = dialog; + if( wId != 0 ) { + KWindowSystem::setMainWindow( dialog, wId ); // correct, set dialog parent + } else { + if( appid.isEmpty()) { + kWarning() << "Using kwallet without parent window!"; + } else { + kWarning() << "Application '" << appid << "' using kwallet without parent window!"; + } + // allow dialog activation even if it interrupts, better than trying hacks + // with keeping the dialog on top or on all desktops + kapp->updateUserTimestamp(); + } + if( modal ) { + KWindowSystem::setState( dialog->winId(), NET::Modal ); + } else { + KWindowSystem::clearState( dialog->winId(), NET::Modal ); + } + activeDialog = dialog; } // If there's a dialog already open and another application tries some operation that'd lead to @@ -394,18 +396,19 @@ void KWalletD::setupDialog( QWidget* dialog, WId wId, const QString& appid, bool // dialog parents. Hopefully to be done in KDE4, for now just use all kinds of bad hacks to make // sure the user doesn't overlook the active dialog. void KWalletD::checkActiveDialog() { - if( !activeDialog ) - return; + if( !activeDialog ) { + return; + } - kapp->updateUserTimestamp(); + kapp->updateUserTimestamp(); - activeDialog->show(); + activeDialog->show(); - WId window = activeDialog->winId(); - KWindowSystem::setState( window, NET::KeepAbove ); - KWindowSystem::setOnAllDesktops( window, true ); - KWindowSystem::forceActiveWindow( window ); - KWindowSystem::raiseWindow( window ); + WId window = activeDialog->winId(); + KWindowSystem::setState( window, NET::KeepAbove ); + KWindowSystem::setOnAllDesktops( window, true ); + KWindowSystem::forceActiveWindow( window ); + KWindowSystem::raiseWindow( window ); } @@ -462,261 +465,261 @@ int KWalletD::doTransactionOpen(const QString& appid, const QString& wallet, boo int KWalletD::internalOpen(const QString& appid, const QString& wallet, bool isPath, WId w, bool modal, const QString& service) { - bool brandNew = false; + bool brandNew = false; - QString thisApp; - if (appid.isEmpty()) { - thisApp = "KDE System"; - } else { - thisApp = appid; - } + QString thisApp; + if (appid.isEmpty()) { + thisApp = "KDE System"; + } else { + thisApp = appid; + } - if (implicitDeny(wallet, thisApp)) { - return -1; - } + if (implicitDeny(wallet, thisApp)) { + return -1; + } - QPair walletInfo = findWallet(wallet); - int rc = walletInfo.first; - if (rc == -1) { - if (_wallets.count() > 20) { - kDebug() << "Too many wallets open."; - return -1; - } + QPair walletInfo = findWallet(wallet); + int rc = walletInfo.first; + if (rc == -1) { + if (_wallets.count() > 20) { + kDebug() << "Too many wallets open."; + return -1; + } - KWallet::Backend *b = new KWallet::Backend(wallet, isPath); - QString password; - bool emptyPass = false; - if ((isPath && QFile::exists(wallet)) || (!isPath && KWallet::Backend::exists(wallet))) { - // this open attempt will set wallet type from the file header, even if password is needed - int pwless = b->open(QByteArray(), w); - if (0 != pwless || !b->isOpen()) { - if (pwless == 0) { - // release, start anew - delete b; - b = new KWallet::Backend(wallet, isPath); - } - KPasswordDialog *kpd = new KPasswordDialog(); - if (appid.isEmpty()) { - kpd->setPrompt(i18n("KDE has requested to open the wallet '%1'. Please enter the password for this wallet below.", Qt::escape(wallet))); - } else { - kpd->setPrompt(i18n("The application '%1' has requested to open the wallet '%2'. Please enter the password for this wallet below.", Qt::escape(appid), Qt::escape(wallet))); - } - brandNew = false; - // don't use KStdGuiItem::open() here which has trailing ellipsis! - kpd->setButtonGuiItem(KDialog::Ok,KGuiItem( i18n( "&Open" ), "wallet-open")); - kpd->setCaption(i18n("KDE Wallet Service")); - kpd->setPixmap(KIcon("kwalletmanager").pixmap(KIconLoader::SizeHuge)); - if (w != KWindowSystem::activeWindow() && w != 0L) { - // If the dialog is modal to a minimized window it might not be visible - // (but still blocking the calling application). Notify the user about - // the request to open the wallet. - KNotification *notification = new KNotification("needsPassword", kpd, - KNotification::Persistent | - KNotification::CloseWhenWidgetActivated); - QStringList actions(i18nc("Text of a button to ignore the open-wallet notification", "Ignore")); - if (appid.isEmpty()) { - notification->setText(i18n("KDE has requested to open a wallet (%1).", - Qt::escape(wallet))); - actions.append(i18nc("Text of a button for switching to the (unnamed) application " - "requesting a password", "Switch there")); - } else { - notification->setText(i18n("%1 has requested to open a wallet (%2).", - Qt::escape(appid), Qt::escape(wallet))); - actions.append(i18nc("Text of a button for switching to the application requesting " - "a password", "Switch to %1", Qt::escape(appid))); - } - notification->setActions(actions); - connect(notification, SIGNAL(action1Activated()), - notification, SLOT(close())); - connect(notification, SIGNAL(action2Activated()), - this, SLOT(activatePasswordDialog())); - notification->sendEvent(); - } - while (!b->isOpen()) { - setupDialog( kpd, w, appid, modal ); - if (kpd->exec() == KDialog::Accepted) { - password = kpd->password(); - int rc = b->open(password.toUtf8()); - if (!b->isOpen()) { - kpd->setPrompt(i18n("Error opening the wallet '%1'. Please try again.
(Error code %2: %3)
", Qt::escape(wallet), rc, KWallet::Backend::openRCToString(rc))); - kpd->setPassword(""); - } - } else { - break; - } - } - delete kpd; - } else { - emptyPass = true; - } - } else { + KWallet::Backend *b = new KWallet::Backend(wallet, isPath); + QString password; + bool emptyPass = false; + if ((isPath && QFile::exists(wallet)) || (!isPath && KWallet::Backend::exists(wallet))) { + // this open attempt will set wallet type from the file header, even if password is needed + int pwless = b->open(QByteArray(), w); + if (0 != pwless || !b->isOpen()) { + if (pwless == 0) { + // release, start anew + delete b; + b = new KWallet::Backend(wallet, isPath); + } + KPasswordDialog *kpd = new KPasswordDialog(); + if (appid.isEmpty()) { + kpd->setPrompt(i18n("KDE has requested to open the wallet '%1'. Please enter the password for this wallet below.", Qt::escape(wallet))); + } else { + kpd->setPrompt(i18n("The application '%1' has requested to open the wallet '%2'. Please enter the password for this wallet below.", Qt::escape(appid), Qt::escape(wallet))); + } + brandNew = false; + // don't use KStdGuiItem::open() here which has trailing ellipsis! + kpd->setButtonGuiItem(KDialog::Ok,KGuiItem( i18n( "&Open" ), "wallet-open")); + kpd->setCaption(i18n("KDE Wallet Service")); + kpd->setPixmap(KIcon("kwalletmanager").pixmap(KIconLoader::SizeHuge)); + if (w != KWindowSystem::activeWindow() && w != 0L) { + // If the dialog is modal to a minimized window it might not be visible + // (but still blocking the calling application). Notify the user about + // the request to open the wallet. + KNotification *notification = new KNotification("needsPassword", kpd, + KNotification::Persistent | + KNotification::CloseWhenWidgetActivated); + QStringList actions(i18nc("Text of a button to ignore the open-wallet notification", "Ignore")); + if (appid.isEmpty()) { + notification->setText(i18n("KDE has requested to open a wallet (%1).", + Qt::escape(wallet))); + actions.append(i18nc("Text of a button for switching to the (unnamed) application " + "requesting a password", "Switch there")); + } else { + notification->setText(i18n("%1 has requested to open a wallet (%2).", + Qt::escape(appid), Qt::escape(wallet))); + actions.append(i18nc("Text of a button for switching to the application requesting " + "a password", "Switch to %1", Qt::escape(appid))); + } + notification->setActions(actions); + connect(notification, SIGNAL(action1Activated()), + notification, SLOT(close())); + connect(notification, SIGNAL(action2Activated()), + this, SLOT(activatePasswordDialog())); + notification->sendEvent(); + } + while (!b->isOpen()) { + setupDialog( kpd, w, appid, modal ); + if (kpd->exec() == KDialog::Accepted) { + password = kpd->password(); + int rc = b->open(password.toUtf8()); + if (!b->isOpen()) { + kpd->setPrompt(i18n("Error opening the wallet '%1'. Please try again.
(Error code %2: %3)
", Qt::escape(wallet), rc, KWallet::Backend::openRCToString(rc))); + kpd->setPassword(""); + } + } else { + break; + } + } + delete kpd; + } else { + emptyPass = true; + } + } else { brandNew = true; b->setCipherType(KWallet::BACKEND_CIPHER_BLOWFISH); - KNewPasswordDialog *kpd = new KNewPasswordDialog(); - if (wallet == KWallet::Wallet::LocalWallet() || - wallet == KWallet::Wallet::NetworkWallet()) - { - // Auto create these wallets. - if (appid.isEmpty()) { - kpd->setPrompt(i18n("KDE has requested to open the wallet. This is used to store sensitive data in a secure fashion. Please enter a password to use with this wallet or click cancel to deny the application's request.")); - } else { - kpd->setPrompt(i18n("The application '%1' has requested to open the KDE wallet. This is used to store sensitive data in a secure fashion. Please enter a password to use with this wallet or click cancel to deny the application's request.", Qt::escape(appid))); - } - } else { - if (appid.length() == 0) { - kpd->setPrompt(i18n("KDE has requested to create a new wallet named '%1'. Please choose a password for this wallet, or cancel to deny the application's request.", Qt::escape(wallet))); - } else { - kpd->setPrompt(i18n("The application '%1' has requested to create a new wallet named '%2'. Please choose a password for this wallet, or cancel to deny the application's request.", Qt::escape(appid), Qt::escape(wallet))); - } - } - kpd->setCaption(i18n("KDE Wallet Service")); - kpd->setButtonGuiItem(KDialog::Ok,KGuiItem(i18n("C&reate"),"document-new")); - kpd->setPixmap(KIcon("kwalletmanager").pixmap(96, 96)); - while (!b->isOpen()) { - setupDialog( kpd, w, appid, modal ); - if (kpd->exec() == KDialog::Accepted) { - password = kpd->password(); - int rc = b->open(password.toUtf8()); - if (!b->isOpen()) { - kpd->setPrompt(i18n("Error opening the wallet '%1'. Please try again.
(Error code %2: %3)
", Qt::escape(wallet), rc, KWallet::Backend::openRCToString(rc))); - } - } else { - break; - } - } - delete kpd; - } + KNewPasswordDialog *kpd = new KNewPasswordDialog(); + if (wallet == KWallet::Wallet::LocalWallet() || + wallet == KWallet::Wallet::NetworkWallet()) { + // Auto create these wallets. + if (appid.isEmpty()) { + kpd->setPrompt(i18n("KDE has requested to open the wallet. This is used to store sensitive data in a secure fashion. Please enter a password to use with this wallet or click cancel to deny the application's request.")); + } else { + kpd->setPrompt(i18n("The application '%1' has requested to open the KDE wallet. This is used to store sensitive data in a secure fashion. Please enter a password to use with this wallet or click cancel to deny the application's request.", Qt::escape(appid))); + } + } else { + if (appid.length() == 0) { + kpd->setPrompt(i18n("KDE has requested to create a new wallet named '%1'. Please choose a password for this wallet, or cancel to deny the application's request.", Qt::escape(wallet))); + } else { + kpd->setPrompt(i18n("The application '%1' has requested to create a new wallet named '%2'. Please choose a password for this wallet, or cancel to deny the application's request.", Qt::escape(appid), Qt::escape(wallet))); + } + } + kpd->setCaption(i18n("KDE Wallet Service")); + kpd->setButtonGuiItem(KDialog::Ok,KGuiItem(i18n("C&reate"),"document-new")); + kpd->setPixmap(KIcon("kwalletmanager").pixmap(96, 96)); + while (!b->isOpen()) { + setupDialog( kpd, w, appid, modal ); + if (kpd->exec() == KDialog::Accepted) { + password = kpd->password(); + int rc = b->open(password.toUtf8()); + if (!b->isOpen()) { + kpd->setPrompt(i18n("Error opening the wallet '%1'. Please try again.
(Error code %2: %3)
", Qt::escape(wallet), rc, KWallet::Backend::openRCToString(rc))); + } + } else { + break; + } + } + delete kpd; + } - - if ((b->cipherType() == KWallet::BACKEND_CIPHER_BLOWFISH) && + + if ((b->cipherType() == KWallet::BACKEND_CIPHER_BLOWFISH) && !emptyPass && (password.isNull() || !b->isOpen())) { - delete b; - return -1; - } + delete b; + return -1; + } - if (emptyPass && !isAuthorizedApp(appid, wallet, w)) { - delete b; - return -1; - } + if (emptyPass && !isAuthorizedApp(appid, wallet, w)) { + delete b; + return -1; + } - _wallets.insert(rc = generateHandle(), b); - _sessions.addSession(appid, service, rc); - _syncTimers.addTimer(rc, _syncTime); + _wallets.insert(rc = generateHandle(), b); + _sessions.addSession(appid, service, rc); + _syncTimers.addTimer(rc, _syncTime); - if (brandNew) { - createFolder(rc, KWallet::Wallet::PasswordFolder(), appid); - createFolder(rc, KWallet::Wallet::FormDataFolder(), appid); - } + if (brandNew) { + createFolder(rc, KWallet::Wallet::PasswordFolder(), appid); + createFolder(rc, KWallet::Wallet::FormDataFolder(), appid); + } - b->ref(); - if (_closeIdle) { - _closeTimers.addTimer(rc, _idleTime); - } - if (brandNew) - emit walletCreated(wallet); - emit walletOpened(wallet); - if (_wallets.count() == 1 && _launchManager) { - KToolInvocation::startServiceByDesktopName("kwalletmanager-kwalletd"); - } - } else { - // prematurely add a reference so that the wallet does not close while the - // authorization dialog is being shown. - walletInfo.second->ref(); - bool isAuthorized = _sessions.hasSession(appid, rc) || isAuthorizedApp(appid, wallet, w); - // as the wallet might have been forcefully closed, find it again to make sure it's - // still available (isAuthorizedApp might show a dialog). - walletInfo = findWallet(wallet); - if (!isAuthorized) { - if (walletInfo.first != -1) { - walletInfo.second->deref(); - // check if the wallet should be closed now. - internalClose(walletInfo.second, walletInfo.first, false); - } - return -1; - } else { - if (walletInfo.first != -1) { - _sessions.addSession(appid, service, rc); - } else { - // wallet was forcefully closed. - return -1; - } - } - } + b->ref(); + if (_closeIdle) { + _closeTimers.addTimer(rc, _idleTime); + } + if (brandNew) { + emit walletCreated(wallet); + } + emit walletOpened(wallet); + if (_wallets.count() == 1 && _launchManager) { + KToolInvocation::startServiceByDesktopName("kwalletmanager-kwalletd"); + } + } else { + // prematurely add a reference so that the wallet does not close while the + // authorization dialog is being shown. + walletInfo.second->ref(); + bool isAuthorized = _sessions.hasSession(appid, rc) || isAuthorizedApp(appid, wallet, w); + // as the wallet might have been forcefully closed, find it again to make sure it's + // still available (isAuthorizedApp might show a dialog). + walletInfo = findWallet(wallet); + if (!isAuthorized) { + if (walletInfo.first != -1) { + walletInfo.second->deref(); + // check if the wallet should be closed now. + internalClose(walletInfo.second, walletInfo.first, false); + } + return -1; + } else { + if (walletInfo.first != -1) { + _sessions.addSession(appid, service, rc); + } else { + // wallet was forcefully closed. + return -1; + } + } + } - return rc; + return rc; } bool KWalletD::isAuthorizedApp(const QString& appid, const QString& wallet, WId w) { - if (!_openPrompt) { - return true; - } + if (!_openPrompt) { + return true; + } - int response = 0; + int response = 0; - QString thisApp; - if (appid.isEmpty()) { - thisApp = "KDE System"; - } else { - thisApp = appid; - } + QString thisApp; + if (appid.isEmpty()) { + thisApp = "KDE System"; + } else { + thisApp = appid; + } - if (!implicitAllow(wallet, thisApp)) { - KConfigGroup cfg = KSharedConfig::openConfig("kwalletrc")->group("Auto Allow"); - if (!cfg.isEntryImmutable(wallet)) { - KBetterThanKDialog *dialog = new KBetterThanKDialog; - dialog->setWindowTitle(i18n("KDE Wallet Service")); - if (appid.isEmpty()) { - dialog->setLabel(i18n("KDE has requested access to the open wallet '%1'.", Qt::escape(wallet))); - } else { - dialog->setLabel(i18n("The application '%1' has requested access to the open wallet '%2'.", Qt::escape(QString(appid)), Qt::escape(wallet))); - } - setupDialog( dialog, w, appid, false ); - response = dialog->exec(); - delete dialog; - } - } + if (!implicitAllow(wallet, thisApp)) { + KConfigGroup cfg = KSharedConfig::openConfig("kwalletrc")->group("Auto Allow"); + if (!cfg.isEntryImmutable(wallet)) { + KBetterThanKDialog *dialog = new KBetterThanKDialog; + dialog->setWindowTitle(i18n("KDE Wallet Service")); + if (appid.isEmpty()) { + dialog->setLabel(i18n("KDE has requested access to the open wallet '%1'.", Qt::escape(wallet))); + } else { + dialog->setLabel(i18n("The application '%1' has requested access to the open wallet '%2'.", Qt::escape(QString(appid)), Qt::escape(wallet))); + } + setupDialog( dialog, w, appid, false ); + response = dialog->exec(); + delete dialog; + } + } - if (response == 0 || response == 1) { - if (response == 1) { - KConfigGroup cfg = KSharedConfig::openConfig("kwalletrc")->group("Auto Allow"); - QStringList apps = cfg.readEntry(wallet, QStringList()); - if (!apps.contains(thisApp)) { - if (cfg.isEntryImmutable(wallet)) { - return false; - } - apps += thisApp; - _implicitAllowMap[wallet] += thisApp; - cfg.writeEntry(wallet, apps); - cfg.sync(); - } - } - } else if (response == 3) { - KConfigGroup cfg = KSharedConfig::openConfig("kwalletrc")->group("Auto Deny"); - QStringList apps = cfg.readEntry(wallet, QStringList()); - if (!apps.contains(thisApp)) { - apps += thisApp; - _implicitDenyMap[wallet] += thisApp; - cfg.writeEntry(wallet, apps); - cfg.sync(); - } - return false; - } else { - return false; - } - return true; + if (response == 0 || response == 1) { + if (response == 1) { + KConfigGroup cfg = KSharedConfig::openConfig("kwalletrc")->group("Auto Allow"); + QStringList apps = cfg.readEntry(wallet, QStringList()); + if (!apps.contains(thisApp)) { + if (cfg.isEntryImmutable(wallet)) { + return false; + } + apps += thisApp; + _implicitAllowMap[wallet] += thisApp; + cfg.writeEntry(wallet, apps); + cfg.sync(); + } + } + } else if (response == 3) { + KConfigGroup cfg = KSharedConfig::openConfig("kwalletrc")->group("Auto Deny"); + QStringList apps = cfg.readEntry(wallet, QStringList()); + if (!apps.contains(thisApp)) { + apps += thisApp; + _implicitDenyMap[wallet] += thisApp; + cfg.writeEntry(wallet, apps); + cfg.sync(); + } + return false; + } else { + return false; + } + return true; } int KWalletD::deleteWallet(const QString& wallet) { int result = -1; - QString path = KGlobal::dirs()->saveLocation("kwallet") + QDir::separator() + wallet + ".kwl"; + QString path = KGlobal::dirs()->saveLocation("kwallet") + QDir::separator() + wallet + ".kwl"; - if (QFile::exists(path)) { - const QPair walletInfo = findWallet(wallet); - internalClose(walletInfo.second, walletInfo.first, true); - QFile::remove(path); - emit walletDeleted(wallet); + if (QFile::exists(path)) { + const QPair walletInfo = findWallet(wallet); + internalClose(walletInfo.second, walletInfo.first, true); + QFile::remove(path); + emit walletDeleted(wallet); // also delete access control entries KConfigGroup cfgAllow = KSharedConfig::openConfig("kwalletrc")->group("Auto Allow"); cfgAllow.deleteEntry(wallet); @@ -725,57 +728,56 @@ int KWalletD::deleteWallet(const QString& wallet) { cfgDeny.deleteEntry(wallet); result = 0; - } + } - return result; + return result; } void KWalletD::changePassword(const QString& wallet, qlonglong wId, const QString& appid) { - KWalletTransaction *xact = new KWalletTransaction(connection()); + KWalletTransaction *xact = new KWalletTransaction(connection()); // message().setDelayedReply(true); xact->message = message(); xact->message.setDelayedReply(true); - xact->appid = appid; - xact->wallet = wallet; - xact->wId = wId; - xact->modal = false; - xact->tType = KWalletTransaction::ChangePassword; + xact->appid = appid; + xact->wallet = wallet; + xact->wId = wId; + xact->modal = false; + xact->tType = KWalletTransaction::ChangePassword; - _transactions.append(xact); + _transactions.append(xact); - QTimer::singleShot(0, this, SLOT(processTransactions())); - checkActiveDialog(); - checkActiveDialog(); + QTimer::singleShot(0, this, SLOT(processTransactions())); + checkActiveDialog(); + checkActiveDialog(); } void KWalletD::initiateSync(int handle) { - // add a timer and reset it right away - _syncTimers.addTimer(handle, _syncTime); - _syncTimers.resetTimer(handle, _syncTime); + // add a timer and reset it right away + _syncTimers.addTimer(handle, _syncTime); + _syncTimers.resetTimer(handle, _syncTime); } void KWalletD::doTransactionChangePassword(const QString& appid, const QString& wallet, qlonglong wId) { + const QPair walletInfo = findWallet(wallet); + int handle = walletInfo.first; + KWallet::Backend* w = walletInfo.second; - const QPair walletInfo = findWallet(wallet); - int handle = walletInfo.first; - KWallet::Backend* w = walletInfo.second; + bool reclose = false; + if (!w) { + handle = doTransactionOpen(appid, wallet, false, wId, false, ""); + if (-1 == handle) { + KMessageBox::sorryWId((WId)wId, i18n("Unable to open wallet. The wallet must be opened in order to change the password."), i18n("KDE Wallet Service")); + return; + } - bool reclose = false; - if (!w) { - handle = doTransactionOpen(appid, wallet, false, wId, false, ""); - if (-1 == handle) { - KMessageBox::sorryWId((WId)wId, i18n("Unable to open wallet. The wallet must be opened in order to change the password."), i18n("KDE Wallet Service")); - return; - } + w = _wallets.value(handle); + reclose = true; + } - w = _wallets.value(handle); - reclose = true; - } - - assert(w); + assert(w); QPointer kpd = new KNewPasswordDialog(); kpd->setPrompt(i18n("Please choose a new password for the wallet '%1'.", Qt::escape(wallet))); @@ -809,583 +811,583 @@ void KWalletD::doTransactionChangePassword(const QString& appid, const QString& int KWalletD::close(const QString& wallet, bool force) { - const QPair walletInfo = findWallet(wallet); - int handle = walletInfo.first; - KWallet::Backend* w = walletInfo.second; + const QPair walletInfo = findWallet(wallet); + int handle = walletInfo.first; + KWallet::Backend* w = walletInfo.second; - return internalClose(w, handle, force); + return internalClose(w, handle, force); } int KWalletD::internalClose(KWallet::Backend *w, int handle, bool force) { - if (w) { - const QString& wallet = w->walletName(); - if ((w->refCount() == 0 && !_leaveOpen) || force) { - // this is only a safety measure. sessions should be gone already. - _sessions.removeAllSessions(handle); - if (_closeIdle) { - _closeTimers.removeTimer(handle); - } - _syncTimers.removeTimer(handle); - _wallets.remove(handle); - w->close(true); - doCloseSignals(handle, wallet); - delete w; - return 0; - } - return 1; - } + if (w) { + const QString& wallet = w->walletName(); + if ((w->refCount() == 0 && !_leaveOpen) || force) { + // this is only a safety measure. sessions should be gone already. + _sessions.removeAllSessions(handle); + if (_closeIdle) { + _closeTimers.removeTimer(handle); + } + _syncTimers.removeTimer(handle); + _wallets.remove(handle); + w->close(true); + doCloseSignals(handle, wallet); + delete w; + return 0; + } + return 1; + } - return -1; + return -1; } int KWalletD::close(int handle, bool force, const QString& appid) { - KWallet::Backend *w = _wallets.value(handle); + KWallet::Backend *w = _wallets.value(handle); - if (w) { - if (_sessions.hasSession(appid, handle)) { - // remove one handle for the application - bool removed = _sessions.removeSession(appid, message().service(), handle); - // alternatively try sessionless - if (removed || _sessions.removeSession(appid, "", handle)) { - w->deref(); - } - return internalClose(w, handle, force); - } - return 1; // not closed, handle unknown - } - return -1; // not open to begin with, or other error + if (w) { + if (_sessions.hasSession(appid, handle)) { + // remove one handle for the application + bool removed = _sessions.removeSession(appid, message().service(), handle); + // alternatively try sessionless + if (removed || _sessions.removeSession(appid, "", handle)) { + w->deref(); + } + return internalClose(w, handle, force); + } + return 1; // not closed, handle unknown + } + return -1; // not open to begin with, or other error } bool KWalletD::isOpen(const QString& wallet) { - const QPair walletInfo = findWallet(wallet); - return walletInfo.second != 0; + const QPair walletInfo = findWallet(wallet); + return walletInfo.second != 0; } bool KWalletD::isOpen(int handle) { - if (handle == 0) { - return false; - } + if (handle == 0) { + return false; + } - KWallet::Backend *rc = _wallets.value(handle); + KWallet::Backend *rc = _wallets.value(handle); - if (rc == 0 && ++_failed > 5) { - _failed = 0; - QTimer::singleShot(0, this, SLOT(notifyFailures())); - } else if (rc != 0) { - _failed = 0; - } + if (rc == 0 && ++_failed > 5) { + _failed = 0; + QTimer::singleShot(0, this, SLOT(notifyFailures())); + } else if (rc != 0) { + _failed = 0; + } - return rc != 0; + return rc != 0; } QStringList KWalletD::wallets() const { - QString path = KGlobal::dirs()->saveLocation("kwallet"); - QDir dir(path, "*.kwl"); - QStringList rc; + QString path = KGlobal::dirs()->saveLocation("kwallet"); + QDir dir(path, "*.kwl"); + QStringList rc; - dir.setFilter(QDir::Files | QDir::Hidden); + dir.setFilter(QDir::Files | QDir::Hidden); - foreach (const QFileInfo &fi, dir.entryInfoList()) { - QString fn = fi.fileName(); - if (fn.endsWith(QLatin1String(".kwl"))) { - fn.truncate(fn.length()-4); - } - rc += fn; - } - return rc; + foreach (const QFileInfo &fi, dir.entryInfoList()) { + QString fn = fi.fileName(); + if (fn.endsWith(QLatin1String(".kwl"))) { + fn.truncate(fn.length()-4); + } + rc += fn; + } + return rc; } void KWalletD::sync(int handle, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - // get the wallet and check if we have a password for it (safety measure) - if ((b = getWallet(appid, handle))) { - QString wallet = b->walletName(); - b->sync(0); - } + // get the wallet and check if we have a password for it (safety measure) + if ((b = getWallet(appid, handle))) { + QString wallet = b->walletName(); + b->sync(0); + } } void KWalletD::timedOutSync(int handle) { - _syncTimers.removeTimer(handle); - if (_wallets.contains(handle) && _wallets[handle]) { - _wallets[handle]->sync(0); - } + _syncTimers.removeTimer(handle); + if (_wallets.contains(handle) && _wallets[handle]) { + _wallets[handle]->sync(0); + } } void KWalletD::doTransactionOpenCancelled(const QString& appid, const QString& wallet, const QString& service) { - // there will only be one session left to remove - all others - // have already been removed in slotServiceOwnerChanged and all - // transactions for opening new sessions have been deleted. - if (!_sessions.hasSession(appid)) { - return; - } + // there will only be one session left to remove - all others + // have already been removed in slotServiceOwnerChanged and all + // transactions for opening new sessions have been deleted. + if (!_sessions.hasSession(appid)) { + return; + } - const QPair walletInfo = findWallet(wallet); - int handle = walletInfo.first; - KWallet::Backend *b = walletInfo.second; - if (handle != -1 && b) { - b->deref(); - internalClose(b, handle, false); - } + const QPair walletInfo = findWallet(wallet); + int handle = walletInfo.first; + KWallet::Backend *b = walletInfo.second; + if (handle != -1 && b) { + b->deref(); + internalClose(b, handle, false); + } - // close the session in case the wallet hasn't been closed yet - _sessions.removeSession(appid, service, handle); + // close the session in case the wallet hasn't been closed yet + _sessions.removeSession(appid, service, handle); } QStringList KWalletD::folderList(int handle, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - return b->folderList(); - } + if ((b = getWallet(appid, handle))) { + return b->folderList(); + } - return QStringList(); + return QStringList(); } bool KWalletD::hasFolder(int handle, const QString& f, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - return b->hasFolder(f); - } + if ((b = getWallet(appid, handle))) { + return b->hasFolder(f); + } - return false; + return false; } bool KWalletD::removeFolder(int handle, const QString& f, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - bool rc = b->removeFolder(f); - initiateSync(handle); - emit folderListUpdated(b->walletName()); - return rc; - } + if ((b = getWallet(appid, handle))) { + bool rc = b->removeFolder(f); + initiateSync(handle); + emit folderListUpdated(b->walletName()); + return rc; + } - return false; + return false; } bool KWalletD::createFolder(int handle, const QString& f, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - bool rc = b->createFolder(f); - initiateSync(handle); - emit folderListUpdated(b->walletName()); - return rc; - } + if ((b = getWallet(appid, handle))) { + bool rc = b->createFolder(f); + initiateSync(handle); + emit folderListUpdated(b->walletName()); + return rc; + } - return false; + return false; } QByteArray KWalletD::readMap(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry *e = b->readEntry(key); - if (e && e->type() == KWallet::Wallet::Map) { - return e->value(); - } - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry *e = b->readEntry(key); + if (e && e->type() == KWallet::Wallet::Map) { + return e->value(); + } + } - return QByteArray(); + return QByteArray(); } QVariantMap KWalletD::readMapList(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - QVariantMap rc; - foreach (KWallet::Entry *entry, b->readEntryList(key)) { - if (entry->type() == KWallet::Wallet::Map) { - rc.insert(entry->key(), entry->value()); - } - } - return rc; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + QVariantMap rc; + foreach (KWallet::Entry *entry, b->readEntryList(key)) { + if (entry->type() == KWallet::Wallet::Map) { + rc.insert(entry->key(), entry->value()); + } + } + return rc; + } - return QVariantMap(); + return QVariantMap(); } QByteArray KWalletD::readEntry(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry *e = b->readEntry(key); - if (e) { - return e->value(); - } - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry *e = b->readEntry(key); + if (e) { + return e->value(); + } + } - return QByteArray(); + return QByteArray(); } QVariantMap KWalletD::readEntryList(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - QVariantMap rc; - foreach (KWallet::Entry *entry, b->readEntryList(key)) { - rc.insert(entry->key(), entry->value()); - } - return rc; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + QVariantMap rc; + foreach (KWallet::Entry *entry, b->readEntryList(key)) { + rc.insert(entry->key(), entry->value()); + } + return rc; + } - return QVariantMap(); + return QVariantMap(); } QStringList KWalletD::entryList(int handle, const QString& folder, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - return b->entryList(); - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + return b->entryList(); + } - return QStringList(); + return QStringList(); } QString KWalletD::readPassword(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry *e = b->readEntry(key); - if (e && e->type() == KWallet::Wallet::Password) { - return e->password(); - } - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry *e = b->readEntry(key); + if (e && e->type() == KWallet::Wallet::Password) { + return e->password(); + } + } - return QString(); + return QString(); } QVariantMap KWalletD::readPasswordList(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - QVariantMap rc; - foreach (KWallet::Entry *entry, b->readEntryList(key)) { - if (entry->type() == KWallet::Wallet::Password) { - rc.insert(entry->key(), entry->password()); - } - } - return rc; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + QVariantMap rc; + foreach (KWallet::Entry *entry, b->readEntryList(key)) { + if (entry->type() == KWallet::Wallet::Password) { + rc.insert(entry->key(), entry->password()); + } + } + return rc; + } - return QVariantMap(); + return QVariantMap(); } int KWalletD::writeMap(int handle, const QString& folder, const QString& key, const QByteArray& value, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry e; - e.setKey(key); - e.setValue(value); - e.setType(KWallet::Wallet::Map); - b->writeEntry(&e); - initiateSync(handle); - emitFolderUpdated(b->walletName(), folder); - return 0; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry e; + e.setKey(key); + e.setValue(value); + e.setType(KWallet::Wallet::Map); + b->writeEntry(&e); + initiateSync(handle); + emitFolderUpdated(b->walletName(), folder); + return 0; + } - return -1; + return -1; } int KWalletD::writeEntry(int handle, const QString& folder, const QString& key, const QByteArray& value, int entryType, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry e; - e.setKey(key); - e.setValue(value); - e.setType(KWallet::Wallet::EntryType(entryType)); - b->writeEntry(&e); - initiateSync(handle); - emitFolderUpdated(b->walletName(), folder); - return 0; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry e; + e.setKey(key); + e.setValue(value); + e.setType(KWallet::Wallet::EntryType(entryType)); + b->writeEntry(&e); + initiateSync(handle); + emitFolderUpdated(b->walletName(), folder); + return 0; + } - return -1; + return -1; } int KWalletD::writeEntry(int handle, const QString& folder, const QString& key, const QByteArray& value, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry e; - e.setKey(key); - e.setValue(value); - e.setType(KWallet::Wallet::Stream); - b->writeEntry(&e); - initiateSync(handle); - emitFolderUpdated(b->walletName(), folder); - return 0; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry e; + e.setKey(key); + e.setValue(value); + e.setType(KWallet::Wallet::Stream); + b->writeEntry(&e); + initiateSync(handle); + emitFolderUpdated(b->walletName(), folder); + return 0; + } - return -1; + return -1; } int KWalletD::writePassword(int handle, const QString& folder, const QString& key, const QString& value, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - KWallet::Entry e; - e.setKey(key); - e.setValue(value); - e.setType(KWallet::Wallet::Password); - b->writeEntry(&e); - initiateSync(handle); - emitFolderUpdated(b->walletName(), folder); - return 0; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + KWallet::Entry e; + e.setKey(key); + e.setValue(value); + e.setType(KWallet::Wallet::Password); + b->writeEntry(&e); + initiateSync(handle); + emitFolderUpdated(b->walletName(), folder); + return 0; + } - return -1; + return -1; } int KWalletD::entryType(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - if (!b->hasFolder(folder)) { - return KWallet::Wallet::Unknown; - } - b->setFolder(folder); - if (b->hasEntry(key)) { - return b->readEntry(key)->type(); - } - } + if ((b = getWallet(appid, handle))) { + if (!b->hasFolder(folder)) { + return KWallet::Wallet::Unknown; + } + b->setFolder(folder); + if (b->hasEntry(key)) { + return b->readEntry(key)->type(); + } + } - return KWallet::Wallet::Unknown; + return KWallet::Wallet::Unknown; } bool KWalletD::hasEntry(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - if (!b->hasFolder(folder)) { - return false; - } - b->setFolder(folder); - return b->hasEntry(key); - } + if ((b = getWallet(appid, handle))) { + if (!b->hasFolder(folder)) { + return false; + } + b->setFolder(folder); + return b->hasEntry(key); + } - return false; + return false; } int KWalletD::removeEntry(int handle, const QString& folder, const QString& key, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - if (!b->hasFolder(folder)) { - return 0; - } - b->setFolder(folder); - bool rc = b->removeEntry(key); - initiateSync(handle); - emitFolderUpdated(b->walletName(), folder); - return rc ? 0 : -3; - } + if ((b = getWallet(appid, handle))) { + if (!b->hasFolder(folder)) { + return 0; + } + b->setFolder(folder); + bool rc = b->removeEntry(key); + initiateSync(handle); + emitFolderUpdated(b->walletName(), folder); + return rc ? 0 : -3; + } - return -1; + return -1; } void KWalletD::slotServiceOwnerChanged(const QString& name, const QString &oldOwner, const QString& newOwner) { - Q_UNUSED(name); - kDebug() << "slotServiceOwnerChanged " << name << ", " << oldOwner << ", " << newOwner; + Q_UNUSED(name); + kDebug() << "slotServiceOwnerChanged " << name << ", " << oldOwner << ", " << newOwner; - if (!newOwner.isEmpty()) { - return; // no application exit, don't care. - } + if (!newOwner.isEmpty()) { + return; // no application exit, don't care. + } - // as we don't have the application id we have to cycle - // all sessions. As an application can basically open wallets - // with several appids, we can't stop if we found one. - QString service(oldOwner); - QList sessremove(_sessions.findSessions(service)); - KWallet::Backend *b = 0; + // as we don't have the application id we have to cycle + // all sessions. As an application can basically open wallets + // with several appids, we can't stop if we found one. + QString service(oldOwner); + QList sessremove(_sessions.findSessions(service)); + KWallet::Backend *b = 0; - // check all sessions for wallets to close - Q_FOREACH(const KWalletAppHandlePair &s, sessremove) { - b = getWallet(s.first, s.second); - if (b) { - b->deref(); - internalClose(b, s.second, false); - } - } + // check all sessions for wallets to close + Q_FOREACH(const KWalletAppHandlePair &s, sessremove) { + b = getWallet(s.first, s.second); + if (b) { + b->deref(); + internalClose(b, s.second, false); + } + } - // remove all the sessions in case they aren't gone yet - Q_FOREACH(const KWalletAppHandlePair &s, sessremove) { - _sessions.removeSession(s.first, service, s.second); - } + // remove all the sessions in case they aren't gone yet + Q_FOREACH(const KWalletAppHandlePair &s, sessremove) { + _sessions.removeSession(s.first, service, s.second); + } - // cancel all open-transactions still running for the service - QList::iterator tit; - for (tit = _transactions.begin(); tit != _transactions.end(); ++tit) { - if ((*tit)->tType == KWalletTransaction::Open && (*tit)->service == oldOwner) { - delete (*tit); - *tit = 0; - } - } - _transactions.removeAll(0); + // cancel all open-transactions still running for the service + QList::iterator tit; + for (tit = _transactions.begin(); tit != _transactions.end(); ++tit) { + if ((*tit)->tType == KWalletTransaction::Open && (*tit)->service == oldOwner) { + delete (*tit); + *tit = 0; + } + } + _transactions.removeAll(0); - // if there's currently an open-transaction being handled, - // mark it as cancelled. - if (_curtrans && _curtrans->tType == KWalletTransaction::Open && - _curtrans->service == oldOwner) { + // if there's currently an open-transaction being handled, + // mark it as cancelled. + if (_curtrans && _curtrans->tType == KWalletTransaction::Open && + _curtrans->service == oldOwner) { kDebug() << "Cancelling current transaction!"; - _curtrans->cancelled = true; - } - _serviceWatcher.removeWatchedService(oldOwner); + _curtrans->cancelled = true; + } + _serviceWatcher.removeWatchedService(oldOwner); } KWallet::Backend *KWalletD::getWallet(const QString& appid, int handle) { - if (handle == 0) { - return 0L; - } + if (handle == 0) { + return 0L; + } - KWallet::Backend *w = _wallets.value(handle); + KWallet::Backend *w = _wallets.value(handle); - if (w) { // the handle is valid - if (_sessions.hasSession(appid, handle)) { - // the app owns this handle - _failed = 0; - if (_closeIdle) { - _closeTimers.resetTimer(handle, _idleTime); - } - return w; - } - } + if (w) { // the handle is valid + if (_sessions.hasSession(appid, handle)) { + // the app owns this handle + _failed = 0; + if (_closeIdle) { + _closeTimers.resetTimer(handle, _idleTime); + } + return w; + } + } - if (++_failed > 5) { - _failed = 0; - QTimer::singleShot(0, this, SLOT(notifyFailures())); - } + if (++_failed > 5) { + _failed = 0; + QTimer::singleShot(0, this, SLOT(notifyFailures())); + } - return 0L; + return 0L; } void KWalletD::notifyFailures() { - if (!_showingFailureNotify) { - _showingFailureNotify = true; - KMessageBox::information(0, i18n("There have been repeated failed attempts to gain access to a wallet. An application may be misbehaving."), i18n("KDE Wallet Service")); - _showingFailureNotify = false; - } + if (!_showingFailureNotify) { + _showingFailureNotify = true; + KMessageBox::information(0, i18n("There have been repeated failed attempts to gain access to a wallet. An application may be misbehaving."), i18n("KDE Wallet Service")); + _showingFailureNotify = false; + } } void KWalletD::doCloseSignals(int handle, const QString& wallet) { - emit walletClosed(handle); - emit walletClosed(wallet); - if (_wallets.isEmpty()) { - emit allWalletsClosed(); - } + emit walletClosed(handle); + emit walletClosed(wallet); + if (_wallets.isEmpty()) { + emit allWalletsClosed(); + } } int KWalletD::renameEntry(int handle, const QString& folder, const QString& oldName, const QString& newName, const QString& appid) { - KWallet::Backend *b; + KWallet::Backend *b; - if ((b = getWallet(appid, handle))) { - b->setFolder(folder); - int rc = b->renameEntry(oldName, newName); - initiateSync(handle); - emitFolderUpdated(b->walletName(), folder); - return rc; - } + if ((b = getWallet(appid, handle))) { + b->setFolder(folder); + int rc = b->renameEntry(oldName, newName); + initiateSync(handle); + emitFolderUpdated(b->walletName(), folder); + return rc; + } - return -1; + return -1; } QStringList KWalletD::users(const QString& wallet) const { - const QPair walletInfo = findWallet(wallet); - return _sessions.getApplications(walletInfo.first); + const QPair walletInfo = findWallet(wallet); + return _sessions.getApplications(walletInfo.first); } bool KWalletD::disconnectApplication(const QString& wallet, const QString& application) { - const QPair walletInfo = findWallet(wallet); - int handle = walletInfo.first; - KWallet::Backend* backend = walletInfo.second; + const QPair walletInfo = findWallet(wallet); + int handle = walletInfo.first; + KWallet::Backend* backend = walletInfo.second; - if (handle != -1 && _sessions.hasSession(application, handle)) { - int removed = _sessions.removeAllSessions(application, handle); + if (handle != -1 && _sessions.hasSession(application, handle)) { + int removed = _sessions.removeAllSessions(application, handle); - for (int i = 0; i < removed; ++i) { - backend->deref(); - } - internalClose(backend, handle, false); + for (int i = 0; i < removed; ++i) { + backend->deref(); + } + internalClose(backend, handle, false); - emit applicationDisconnected(wallet, application); - return true; - } + emit applicationDisconnected(wallet, application); + return true; + } - return false; + return false; } void KWalletD::emitFolderUpdated(const QString& wallet, const QString& folder) { - emit folderUpdated(wallet, folder); + emit folderUpdated(wallet, folder); } void KWalletD::emitWalletListDirty() { - emit walletListDirty(); + emit walletListDirty(); } void KWalletD::reconfigure() { - KConfig cfg("kwalletrc"); - KConfigGroup walletGroup(&cfg, "Wallet"); - _firstUse = walletGroup.readEntry("First Use", true); - _enabled = walletGroup.readEntry("Enabled", true); - _launchManager = walletGroup.readEntry("Launch Manager", false); - _leaveOpen = walletGroup.readEntry("Leave Open", false); - bool idleSave = _closeIdle; - _closeIdle = walletGroup.readEntry("Close When Idle", false); - _openPrompt = walletGroup.readEntry("Prompt on Open", false); - int timeSave = _idleTime; - // in minutes! - _idleTime = walletGroup.readEntry("Idle Timeout", 10) * 60 * 1000; + KConfig cfg("kwalletrc"); + KConfigGroup walletGroup(&cfg, "Wallet"); + _firstUse = walletGroup.readEntry("First Use", true); + _enabled = walletGroup.readEntry("Enabled", true); + _launchManager = walletGroup.readEntry("Launch Manager", false); + _leaveOpen = walletGroup.readEntry("Leave Open", false); + bool idleSave = _closeIdle; + _closeIdle = walletGroup.readEntry("Close When Idle", false); + _openPrompt = walletGroup.readEntry("Prompt on Open", false); + int timeSave = _idleTime; + // in minutes! + _idleTime = walletGroup.readEntry("Idle Timeout", 10) * 60 * 1000; #ifdef Q_WS_X11 if (walletGroup.readEntry("Close on Screensaver", false)) { // BUG 254273 : if kwalletd starts before the screen saver, then the connection fails and kwalletd never receives it's notifications @@ -1399,147 +1401,148 @@ void KWalletD::reconfigure() { } } #endif - // Handle idle changes - if (_closeIdle) { - if (_idleTime != timeSave) { // Timer length changed - Wallets::const_iterator it = _wallets.constBegin(); - const Wallets::const_iterator end = _wallets.constEnd(); - for (; it != end; ++it) { - _closeTimers.resetTimer(it.key(), _idleTime); - } - } + // Handle idle changes + if (_closeIdle) { + if (_idleTime != timeSave) { // Timer length changed + Wallets::const_iterator it = _wallets.constBegin(); + const Wallets::const_iterator end = _wallets.constEnd(); + for (; it != end; ++it) { + _closeTimers.resetTimer(it.key(), _idleTime); + } + } - if (!idleSave) { // add timers for all the wallets - Wallets::const_iterator it = _wallets.constBegin(); - const Wallets::const_iterator end = _wallets.constEnd(); - for (; it != end; ++it) { - _closeTimers.addTimer(it.key(), _idleTime); - } - } - } else { - _closeTimers.clear(); - } + if (!idleSave) { // add timers for all the wallets + Wallets::const_iterator it = _wallets.constBegin(); + const Wallets::const_iterator end = _wallets.constEnd(); + for (; it != end; ++it) { + _closeTimers.addTimer(it.key(), _idleTime); + } + } + } else { + _closeTimers.clear(); + } - // Update the implicit allow stuff - _implicitAllowMap.clear(); - const KConfigGroup autoAllowGroup(&cfg, "Auto Allow"); - QStringList entries = autoAllowGroup.entryMap().keys(); - for (QStringList::const_iterator i = entries.constBegin(); i != entries.constEnd(); ++i) { - _implicitAllowMap[*i] = autoAllowGroup.readEntry(*i, QStringList()); - } + // Update the implicit allow stuff + _implicitAllowMap.clear(); + const KConfigGroup autoAllowGroup(&cfg, "Auto Allow"); + QStringList entries = autoAllowGroup.entryMap().keys(); + for (QStringList::const_iterator i = entries.constBegin(); i != entries.constEnd(); ++i) { + _implicitAllowMap[*i] = autoAllowGroup.readEntry(*i, QStringList()); + } - // Update the implicit allow stuff - _implicitDenyMap.clear(); - const KConfigGroup autoDenyGroup(&cfg, "Auto Deny"); - entries = autoDenyGroup.entryMap().keys(); - for (QStringList::const_iterator i = entries.constBegin(); i != entries.constEnd(); ++i) { - _implicitDenyMap[*i] = autoDenyGroup.readEntry(*i, QStringList()); - } + // Update the implicit allow stuff + _implicitDenyMap.clear(); + const KConfigGroup autoDenyGroup(&cfg, "Auto Deny"); + entries = autoDenyGroup.entryMap().keys(); + for (QStringList::const_iterator i = entries.constBegin(); i != entries.constEnd(); ++i) { + _implicitDenyMap[*i] = autoDenyGroup.readEntry(*i, QStringList()); + } - // Update if wallet was enabled/disabled - if (!_enabled) { // close all wallets - while (!_wallets.isEmpty()) { - Wallets::const_iterator it = _wallets.constBegin(); - internalClose(it.value(), it.key(), true); - } - KUniqueApplication::exit(0); - } + // Update if wallet was enabled/disabled + if (!_enabled) { // close all wallets + while (!_wallets.isEmpty()) { + Wallets::const_iterator it = _wallets.constBegin(); + internalClose(it.value(), it.key(), true); + } + KUniqueApplication::exit(0); + } } bool KWalletD::isEnabled() const { - return _enabled; + return _enabled; } bool KWalletD::folderDoesNotExist(const QString& wallet, const QString& folder) { - if (!wallets().contains(wallet)) { - return true; - } + if (!wallets().contains(wallet)) { + return true; + } - const QPair walletInfo = findWallet(wallet); - if (walletInfo.second) { - return walletInfo.second->folderDoesNotExist(folder); - } + const QPair walletInfo = findWallet(wallet); + if (walletInfo.second) { + return walletInfo.second->folderDoesNotExist(folder); + } - KWallet::Backend *b = new KWallet::Backend(wallet); - b->open(QByteArray()); - bool rc = b->folderDoesNotExist(folder); - delete b; - return rc; + KWallet::Backend *b = new KWallet::Backend(wallet); + b->open(QByteArray()); + bool rc = b->folderDoesNotExist(folder); + delete b; + return rc; } bool KWalletD::keyDoesNotExist(const QString& wallet, const QString& folder, const QString& key) { - if (!wallets().contains(wallet)) { - return true; - } + if (!wallets().contains(wallet)) { + return true; + } - const QPair walletInfo = findWallet(wallet); - if (walletInfo.second) { - return walletInfo.second->entryDoesNotExist(folder, key); - } + const QPair walletInfo = findWallet(wallet); + if (walletInfo.second) { + return walletInfo.second->entryDoesNotExist(folder, key); + } - KWallet::Backend *b = new KWallet::Backend(wallet); - b->open(QByteArray()); - bool rc = b->entryDoesNotExist(folder, key); - delete b; - return rc; + KWallet::Backend *b = new KWallet::Backend(wallet); + b->open(QByteArray()); + bool rc = b->entryDoesNotExist(folder, key); + delete b; + return rc; } bool KWalletD::implicitAllow(const QString& wallet, const QString& app) { - return _implicitAllowMap[wallet].contains(app); + return _implicitAllowMap[wallet].contains(app); } bool KWalletD::implicitDeny(const QString& wallet, const QString& app) { - return _implicitDenyMap[wallet].contains(app); + return _implicitDenyMap[wallet].contains(app); } void KWalletD::timedOutClose(int id) { - KWallet::Backend *w = _wallets.value(id); - if (w) { - internalClose(w, id, true); - } + KWallet::Backend *w = _wallets.value(id); + if (w) { + internalClose(w, id, true); + } } void KWalletD::closeAllWallets() { - Wallets walletsCopy = _wallets; + Wallets walletsCopy = _wallets; - Wallets::const_iterator it = walletsCopy.constBegin(); - const Wallets::const_iterator end = walletsCopy.constEnd(); - for (; it != end; ++it) { - internalClose(it.value(), it.key(), true); - } + Wallets::const_iterator it = walletsCopy.constBegin(); + const Wallets::const_iterator end = walletsCopy.constEnd(); + for (; it != end; ++it) { + internalClose(it.value(), it.key(), true); + } - walletsCopy.clear(); + walletsCopy.clear(); - // All of this should be basically noop. Let's just be safe. - _wallets.clear(); + // All of this should be basically noop. Let's just be safe. + _wallets.clear(); } QString KWalletD::networkWallet() { - return KWallet::Wallet::NetworkWallet(); + return KWallet::Wallet::NetworkWallet(); } QString KWalletD::localWallet() { - return KWallet::Wallet::LocalWallet(); + return KWallet::Wallet::LocalWallet(); } void KWalletD::screenSaverChanged(bool s) { - if (s) - closeAllWallets(); + if (s) { + closeAllWallets(); + } } void KWalletD::activatePasswordDialog() { - checkActiveDialog(); + checkActiveDialog(); } int KWalletD::pamOpen(const QString &wallet, const QByteArray &passwordHash, int sessionTimeout) diff --git a/kwalletd/tests/kwalletasync.cpp b/kwalletd/tests/kwalletasync.cpp index b182495c..8864fffa 100644 --- a/kwalletd/tests/kwalletasync.cpp +++ b/kwalletd/tests/kwalletasync.cpp @@ -20,50 +20,50 @@ static QTextStream _out( stdout, QIODevice::WriteOnly ); void openWallet() { - _out << "About to ask for wallet async" << endl; + _out << "About to ask for wallet async" << endl; - // we have no wallet: ask for one. - KWallet::Wallet *wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous ); + // we have no wallet: ask for one. + KWallet::Wallet *wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous ); - WalletReceiver r; - r.connect( wallet, SIGNAL( walletOpened(bool) ), SLOT( walletOpened(bool) ) ); + WalletReceiver r; + r.connect( wallet, SIGNAL( walletOpened(bool) ), SLOT( walletOpened(bool) ) ); - _out << "About to start 30 second event loop" << endl; + _out << "About to start 30 second event loop" << endl; - QTimer::singleShot( 30000, qApp, SLOT( quit() ) ); - int ret = qApp->exec(); + QTimer::singleShot( 30000, qApp, SLOT( quit() ) ); + int ret = qApp->exec(); - if ( ret == 0 ) - _out << "Timed out!" << endl; - else - _out << "Success!" << endl; + if ( ret == 0 ) { + _out << "Timed out!" << endl; + } else { + _out << "Success!" << endl; + } } void WalletReceiver::walletOpened( bool got ) { - _out << "Got async wallet: " << got << endl; - qApp->exit( 1 ); + _out << "Got async wallet: " << got << endl; + qApp->exit( 1 ); } int main( int argc, char *argv[] ) { - KAboutData aboutData("kwalletasync", 0, ki18n("kwalletasync"), "version"); - KComponentData componentData(&aboutData); - QApplication app( argc, argv ); + KAboutData aboutData("kwalletasync", 0, ki18n("kwalletasync"), "version"); + KComponentData componentData(&aboutData); + QApplication app( argc, argv ); - // force name with D-BUS - QDBusReply reply - = QDBusConnection::sessionBus().interface()->registerService( "org.kde.kwalletasync", - QDBusConnectionInterface::ReplaceExistingService ); + // force name with D-BUS + QDBusReply reply + = QDBusConnection::sessionBus().interface()->registerService( "org.kde.kwalletasync", + QDBusConnectionInterface::ReplaceExistingService ); - if ( !reply.isValid() ) - { - _out << "D-BUS name request returned " << reply.error().name() << endl; - } + if ( !reply.isValid() ) { + _out << "D-BUS name request returned " << reply.error().name() << endl; + } - openWallet(); + openWallet(); - return 0; + return 0; } // vim: set noet ts=4 sts=4 sw=4: diff --git a/kwalletd/tests/kwalletautoclose.cpp b/kwalletd/tests/kwalletautoclose.cpp index 54fd874c..6aedd4a4 100644 --- a/kwalletd/tests/kwalletautoclose.cpp +++ b/kwalletd/tests/kwalletautoclose.cpp @@ -41,23 +41,23 @@ KWalletAutoClose::KWalletAutoClose() : QObject() void KWalletAutoClose::openWallet() { - _out << "Opening wallet synchronously" << endl; - Wallet *wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Synchronous); - _out << "Exiting without closing. The wallet should autoclose." << endl; - Q_UNUSED(wallet); - kapp->exit(0); + _out << "Opening wallet synchronously" << endl; + Wallet *wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Synchronous); + _out << "Exiting without closing. The wallet should autoclose." << endl; + Q_UNUSED(wallet); + kapp->exit(0); } int main(int argc, char *argv[]) { - KAboutData aboutData("kwalletmany", 0, ki18n("kwalletmany"), "version"); - KCmdLineArgs::init(argc, argv, &aboutData); - KApplication app; - KWalletAutoClose m; - - QTimer::singleShot(0, &m, SLOT(openWallet())); - - return app.exec(); + KAboutData aboutData("kwalletmany", 0, ki18n("kwalletmany"), "version"); + KCmdLineArgs::init(argc, argv, &aboutData); + KApplication app; + KWalletAutoClose m; + + QTimer::singleShot(0, &m, SLOT(openWallet())); + + return app.exec(); } #include "moc_kwalletautoclose.cpp" diff --git a/kwalletd/tests/kwalletautoclose.h b/kwalletd/tests/kwalletautoclose.h index d2f51628..51c43905 100644 --- a/kwalletd/tests/kwalletautoclose.h +++ b/kwalletd/tests/kwalletautoclose.h @@ -28,13 +28,13 @@ class KWalletAutoClose : public QObject { - Q_OBJECT + Q_OBJECT public: - KWalletAutoClose(); + KWalletAutoClose(); public Q_SLOTS: - void openWallet(); + void openWallet(); }; #endif // KWALLETAUTOCLOSE_H diff --git a/kwalletd/tests/kwalletboth.cpp b/kwalletd/tests/kwalletboth.cpp index 6dac7bb9..08fdfa0b 100644 --- a/kwalletd/tests/kwalletboth.cpp +++ b/kwalletd/tests/kwalletboth.cpp @@ -21,72 +21,71 @@ static QTextStream _out( stdout, QIODevice::WriteOnly ); void openWallet() { - _out << "About to ask for wallet async" << endl; + _out << "About to ask for wallet async" << endl; - // we have no wallet: ask for one. - KWallet::Wallet *wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous ); + // we have no wallet: ask for one. + KWallet::Wallet *wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Asynchronous ); - WalletReceiver r; - r.connect( wallet, SIGNAL( walletOpened(bool) ), SLOT( walletOpened(bool) ) ); + WalletReceiver r; + r.connect( wallet, SIGNAL( walletOpened(bool) ), SLOT( walletOpened(bool) ) ); - _out << "About to ask for wallet sync" << endl; + _out << "About to ask for wallet sync" << endl; - wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous ); + wallet = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous ); - _out << "Got sync wallet: " << (wallet != 0) << endl; - _out << "About to start 30 second event loop" << endl; + _out << "Got sync wallet: " << (wallet != 0) << endl; + _out << "About to start 30 second event loop" << endl; - QTimer::singleShot( 30000, qApp, SLOT( quit() ) ); - int ret = qApp->exec(); + QTimer::singleShot( 30000, qApp, SLOT( quit() ) ); + int ret = qApp->exec(); + if ( ret == 0 ) { + _out << "Timed out!" << endl; + } else { + _out << "Success!" << endl; + } - if ( ret == 0 ) - _out << "Timed out!" << endl; - else - _out << "Success!" << endl; + QMap p; + ret = wallet->readPasswordList("*", p); + _out << "readPasswordList returned: " << ret << endl; + _out << "readPasswordList returned " << p.keys().count() << " entries" << endl; + QMap > q; + ret = wallet->readMapList("*", q); + _out << "readMapList returned: " << ret << endl; + _out << "readMapList returned " << q.keys().count() << " entries" << endl; - QMap p; - ret = wallet->readPasswordList("*", p); - _out << "readPasswordList returned: " << ret << endl; - _out << "readPasswordList returned " << p.keys().count() << " entries" << endl; - QMap > q; - ret = wallet->readMapList("*", q); - _out << "readMapList returned: " << ret << endl; - _out << "readMapList returned " << q.keys().count() << " entries" << endl; + QMap s; + ret = wallet->readEntryList("*", s); + _out << "readEntryList returned: " << ret << endl; + _out << "readEntryList returned " << s.keys().count() << " entries" << endl; - QMap s; - ret = wallet->readEntryList("*", s); - _out << "readEntryList returned: " << ret << endl; - _out << "readEntryList returned " << s.keys().count() << " entries" << endl; - - delete wallet; + delete wallet; } void WalletReceiver::walletOpened( bool got ) { - _out << "Got async wallet: " << got << endl; - qApp->exit( 1 ); + _out << "Got async wallet: " << got << endl; + qApp->exit( 1 ); } int main( int argc, char *argv[] ) { - KAboutData aboutData("kwalletboth", 0, ki18n("kwalletboth"), "version"); - KComponentData componentData(&aboutData); - QApplication app( argc, argv ); + KAboutData aboutData("kwalletboth", 0, ki18n("kwalletboth"), "version"); + KComponentData componentData(&aboutData); + QApplication app( argc, argv ); - // force name with D-BUS - QDBusReply reply - = QDBusConnection::sessionBus().interface()->registerService( "org.kde.kwalletboth", - QDBusConnectionInterface::ReplaceExistingService ); + // force name with D-BUS + QDBusReply reply + = QDBusConnection::sessionBus().interface()->registerService( "org.kde.kwalletboth", + QDBusConnectionInterface::ReplaceExistingService ); - if ( !reply.isValid() ) - { - _out << "D-BUS name request returned " << reply.error().name() << endl; - } + if ( !reply.isValid() ) { + _out << "D-BUS name request returned " << reply.error().name() << endl; + } - openWallet(); + openWallet(); - return 0; + return 0; } // vim: set noet ts=4 sts=4 sw=4: diff --git a/kwalletd/tests/kwalletmany.cpp b/kwalletd/tests/kwalletmany.cpp index 3953becf..aa8c2956 100644 --- a/kwalletd/tests/kwalletmany.cpp +++ b/kwalletd/tests/kwalletmany.cpp @@ -48,57 +48,57 @@ KWalletMany::~KWalletMany() void KWalletMany::walletOpened(bool open) { - _out << "Got async wallet: " << (open) << endl; - --_pending; - if (_pending == 0) { - quit(); - } + _out << "Got async wallet: " << (open) << endl; + --_pending; + if (_pending == 0) { + quit(); + } } void KWalletMany::quit() { - if (_pending == 0) { - _out << "Success!" << endl; - } else { - _out << "Failed: " << _pending << " requests were not handled!" << endl; - } - _loop.quit(); + if (_pending == 0) { + _out << "Success!" << endl; + } else { + _out << "Failed: " << _pending << " requests were not handled!" << endl; + } + _loop.quit(); } void KWalletMany::openWallet() { - QEventLoop waitLoop; - - // open plenty of wallets in synchronous and asynchronous mode - for (int i = 0; i < NUMWALLETS; ++i) { - // request asynchronous wallet - _out << "About to ask for wallet async" << endl; - Wallet *wallet; - wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Asynchronous); - connect(wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool))); - _wallets.append(wallet); - - QTimer::singleShot(500, &waitLoop, SLOT(quit())); - waitLoop.exec(); - } - - _loop.exec(); - while (!_wallets.isEmpty()) { - delete _wallets.takeFirst(); - } + QEventLoop waitLoop; + + // open plenty of wallets in synchronous and asynchronous mode + for (int i = 0; i < NUMWALLETS; ++i) { + // request asynchronous wallet + _out << "About to ask for wallet async" << endl; + Wallet *wallet; + wallet = Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Asynchronous); + connect(wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool))); + _wallets.append(wallet); + + QTimer::singleShot(500, &waitLoop, SLOT(quit())); + waitLoop.exec(); + } + + _loop.exec(); + while (!_wallets.isEmpty()) { + delete _wallets.takeFirst(); + } } int main(int argc, char *argv[]) { - KAboutData aboutData("kwalletmany", 0, ki18n("kwalletmany"), "version"); - KCmdLineArgs::init(argc, argv, &aboutData); - KApplication app; - KWalletMany m; - - QTimer::singleShot(0, &m, SLOT(openWallet())); - QTimer::singleShot(30000, &m, SLOT(quit())); - - return app.exec(); + KAboutData aboutData("kwalletmany", 0, ki18n("kwalletmany"), "version"); + KCmdLineArgs::init(argc, argv, &aboutData); + KApplication app; + KWalletMany m; + + QTimer::singleShot(0, &m, SLOT(openWallet())); + QTimer::singleShot(30000, &m, SLOT(quit())); + + return app.exec(); } #include "moc_kwalletmany.cpp" diff --git a/kwalletd/tests/kwalletmany.h b/kwalletd/tests/kwalletmany.h index 0f535d3e..6fcaef46 100644 --- a/kwalletd/tests/kwalletmany.h +++ b/kwalletd/tests/kwalletmany.h @@ -33,21 +33,21 @@ namespace KWallet { class Wallet; } class KWalletMany : public QObject { - Q_OBJECT - + Q_OBJECT + public: - KWalletMany(); - ~KWalletMany(); - + KWalletMany(); + ~KWalletMany(); + public slots: - void openWallet(); - void quit(); - void walletOpened(bool open); - + void openWallet(); + void quit(); + void walletOpened(bool open); + private: - QList _wallets; - int _pending; - QEventLoop _loop; + QList _wallets; + int _pending; + QEventLoop _loop; }; #endif // KWALLETMANY_H diff --git a/kwalletd/tests/kwalletnoautoclose.cpp b/kwalletd/tests/kwalletnoautoclose.cpp index c6767632..e2acf4f4 100644 --- a/kwalletd/tests/kwalletnoautoclose.cpp +++ b/kwalletd/tests/kwalletnoautoclose.cpp @@ -34,74 +34,74 @@ static QString _kdewallet; int openAndClose() { - QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd"); - if (!service.isValid()) { - _out << "Constructed service is invalid!" << endl; - return 1; - } - - QDBusReply h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose"); - if (!h.isValid() || h.value() < 0) { - _out << "Opening the wallet failed!" << endl; - _out << "Error: " << h.error().message() << endl; - return 1; - } else { - _out << "Wallet opened." << endl; - } + QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd"); + if (!service.isValid()) { + _out << "Constructed service is invalid!" << endl; + return 1; + } + + QDBusReply h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose"); + if (!h.isValid() || h.value() < 0) { + _out << "Opening the wallet failed!" << endl; + _out << "Error: " << h.error().message() << endl; + return 1; + } else { + _out << "Wallet opened." << endl; + } - _out << "closing the wallet" << endl; - QDBusReply r = service.call(QDBus::Block, "close", h.value(), false, "kwalletnoautoclose"); - - return r; + _out << "closing the wallet" << endl; + QDBusReply r = service.call(QDBus::Block, "close", h.value(), false, "kwalletnoautoclose"); + + return r; } int main(int argc, char *argv[]) { - KAboutData aboutData("kwalletnoautoclose", 0, ki18n("kwalletnoautoclose"), "version"); - KCmdLineArgs::init(argc, argv, &aboutData); - KApplication app; + KAboutData aboutData("kwalletnoautoclose", 0, ki18n("kwalletnoautoclose"), "version"); + KCmdLineArgs::init(argc, argv, &aboutData); + KApplication app; - QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd"); - if (!service.isValid()) { - _out << "Constructed service is invalid!" << endl; - return 1; - } - - QDBusReply r = service.call(QDBus::Block, "isEnabled"); - if (!r.isValid() || !r) { - _out << "kwalletd is disabled or not running!" << endl; - return 1; - } - - QDBusReply kdewallet = service.call(QDBus::Block, "localWallet"); - _kdewallet = kdewallet; - _out << "local wallet is " << _kdewallet << endl; - - QDBusReply open = service.call(QDBus::Block, "isOpen", _kdewallet); - if (open) { - _out << "wallet is already open. Please close to run this test." << endl; - return 1; - } - - int rc; - - _out << "Opening and closing the wallet properly." << endl; - rc = openAndClose(); - if (rc != 0) { - _out << "FAILED!" << endl; - return rc; - } - - _out << "Opening and exiting." << endl; - QDBusReply h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose"); - if (h < 0) { - _out << "Opening the wallet failed!" << endl; - return 1; - } else { - _out << "Wallet opened." << endl; - } - - _out << "Exiting. Wallet should stay open." << endl; - - return 0; + QDBusInterface service("org.kde.kwalletd", "/modules/kwalletd"); + if (!service.isValid()) { + _out << "Constructed service is invalid!" << endl; + return 1; + } + + QDBusReply r = service.call(QDBus::Block, "isEnabled"); + if (!r.isValid() || !r) { + _out << "kwalletd is disabled or not running!" << endl; + return 1; + } + + QDBusReply kdewallet = service.call(QDBus::Block, "localWallet"); + _kdewallet = kdewallet; + _out << "local wallet is " << _kdewallet << endl; + + QDBusReply open = service.call(QDBus::Block, "isOpen", _kdewallet); + if (open) { + _out << "wallet is already open. Please close to run this test." << endl; + return 1; + } + + int rc; + + _out << "Opening and closing the wallet properly." << endl; + rc = openAndClose(); + if (rc != 0) { + _out << "FAILED!" << endl; + return rc; + } + + _out << "Opening and exiting." << endl; + QDBusReply h = service.call(QDBus::Block, "open", _kdewallet, (qlonglong)0, "kwalletnoautoclose"); + if (h < 0) { + _out << "Opening the wallet failed!" << endl; + return 1; + } else { + _out << "Wallet opened." << endl; + } + + _out << "Exiting. Wallet should stay open." << endl; + + return 0; } diff --git a/kwalletd/tests/kwalletpath.cpp b/kwalletd/tests/kwalletpath.cpp index 50180976..dbc1f6b7 100644 --- a/kwalletd/tests/kwalletpath.cpp +++ b/kwalletd/tests/kwalletpath.cpp @@ -17,27 +17,27 @@ static QTextStream _out(stdout, QIODevice::WriteOnly); void openWallet() { - _out << "About to ask for wallet /tmp/test.kwl sync" << endl; + _out << "About to ask for wallet /tmp/test.kwl sync" << endl; - KWallet::Wallet *wallet = KWallet::Wallet::openWallet("/tmp/test.kwl", 0, KWallet::Wallet::Path); + KWallet::Wallet *wallet = KWallet::Wallet::openWallet("/tmp/test.kwl", 0, KWallet::Wallet::Path); - _out << "Got path wallet: " << (wallet != 0) << endl; - - if (wallet) { - _out << "Closing wallet" << endl; - delete wallet; - } - - kapp->exit(0); + _out << "Got path wallet: " << (wallet != 0) << endl; + + if (wallet) { + _out << "Closing wallet" << endl; + delete wallet; + } + + kapp->exit(0); } int main(int argc, char *argv[]) { - KAboutData aboutData("kwalletpath", 0, ki18n("kwalletpath"), "version"); - KCmdLineArgs::init(argc, argv, &aboutData); - KApplication app; + KAboutData aboutData("kwalletpath", 0, ki18n("kwalletpath"), "version"); + KCmdLineArgs::init(argc, argv, &aboutData); + KApplication app; - openWallet(); + openWallet(); - exit(0); + exit(0); } diff --git a/kwalletd/tests/kwalletsync.cpp b/kwalletd/tests/kwalletsync.cpp index 98ed1e95..ede0e4df 100644 --- a/kwalletd/tests/kwalletsync.cpp +++ b/kwalletd/tests/kwalletsync.cpp @@ -18,32 +18,31 @@ static QTextStream _out( stdout, QIODevice::WriteOnly ); void openWallet() { - _out << "About to ask for wallet sync" << endl; + _out << "About to ask for wallet sync" << endl; - KWallet::Wallet *w = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous ); + KWallet::Wallet *w = KWallet::Wallet::openWallet( KWallet::Wallet::NetworkWallet(), 0, KWallet::Wallet::Synchronous ); - _out << "Got sync wallet: " << (w != 0) << endl; + _out << "Got sync wallet: " << (w != 0) << endl; } int main( int argc, char *argv[] ) { - KAboutData aboutData("kwalletsync", 0, ki18n("kwalletsync"), "version"); - KComponentData componentData(&aboutData); - QApplication app( argc, argv ); + KAboutData aboutData("kwalletsync", 0, ki18n("kwalletsync"), "version"); + KComponentData componentData(&aboutData); + QApplication app( argc, argv ); - // force name with D-BUS - QDBusReply reply - = QDBusConnection::sessionBus().interface()->registerService( "org.kde.kwalletsync", - QDBusConnectionInterface::ReplaceExistingService ); + // force name with D-BUS + QDBusReply reply + = QDBusConnection::sessionBus().interface()->registerService( "org.kde.kwalletsync", + QDBusConnectionInterface::ReplaceExistingService ); - if ( !reply.isValid() ) - { - _out << "D-BUS name request returned " << reply.error().name() << endl; - } + if ( !reply.isValid() ) { + _out << "D-BUS name request returned " << reply.error().name() << endl; + } - openWallet(); + openWallet(); - return 0; + return 0; } // vim: set noet ts=4 sts=4 sw=4: diff --git a/kwalletd/tests/kwalletwizardtest.cpp b/kwalletd/tests/kwalletwizardtest.cpp index 62e064dc..3f2d400f 100644 --- a/kwalletd/tests/kwalletwizardtest.cpp +++ b/kwalletd/tests/kwalletwizardtest.cpp @@ -30,7 +30,6 @@ int main(int argc, char **argv) int ret = app.exec(); - return ret; }