+++ /dev/null
-From: Valentin Rusu <kde@rusu.info>
-Date: Sat, 31 Aug 2013 23:28:09 +0000
-Subject: Fix the synchronous-mode wallet open logic
-X-Git-Url: http://quickgit.kde.org/?p=kde-runtime.git&a=commitdiff&h=b0f9053ed8abff4ef973b10842f761422ee17f41
----
-Fix the synchronous-mode wallet open logic
-
-BUG: 254198
-
-The wallet synchronous open requests now use qdbus delayed replies.
-The execution path now returns to the main event loop instead of
-a nested event loop. The wallet opening UI logic is correctly handled
-no longer leading to a frozen kwalletd.
-
-Beware that this commit should be used along with the corresponding
-fix of the kdelibs/kdeui module. Failing to updating kdelibs lead to
-an aparently similar freeze condition, as kdeui also used an internal
-event loop, faking synchronous operation when making async kwalletd calls.
----
-
-
---- a/kwalletd/CMakeLists.txt
-+++ b/kwalletd/CMakeLists.txt
-@@ -12,7 +12,6 @@
- main.cpp
- kbetterthankdialog.cpp
- kwalletd.cpp
-- kwalletopenloop.cpp
- kwalletwizard.cpp
- ktimeout.cpp
- kwalletsessionstore.cpp
-
---- a/kwalletd/kwalletd.cpp
-+++ b/kwalletd/kwalletd.cpp
-@@ -55,13 +55,12 @@
- #include <assert.h>
-
- #include "kwalletadaptor.h"
--#include "kwalletopenloop.h"
-
- class KWalletTransaction {
-
- public:
-- KWalletTransaction()
-- : tType(Unknown), cancelled(false), tId(nextTransactionId)
-+ explicit KWalletTransaction(QDBusConnection conn)
-+ : tType(Unknown), cancelled(false), tId(nextTransactionId), res(-1), connection(conn)
- {
- nextTransactionId++;
- // make sure the id is never < 0 as that's used for the
-@@ -90,6 +89,9 @@
- bool modal;
- bool isPath;
- int tId; // transaction id
-+ int res;
-+ QDBusMessage message;
-+ QDBusConnection connection;
-
- private:
- static int nextTransactionId;
-@@ -198,7 +200,7 @@
- } else if (_curtrans->cancelled) {
- // the wallet opened successfully but the application
- // opening exited/crashed while the dialog was still shown.
-- KWalletTransaction *_xact = new KWalletTransaction();
-+ KWalletTransaction *_xact = new KWalletTransaction(_curtrans->connection);
- _xact->tType = KWalletTransaction::CloseCancelled;
- _xact->appid = _curtrans->appid;
- _xact->wallet = _curtrans->wallet;
-@@ -207,11 +209,13 @@
- }
-
- // emit the AsyncOpened signal as a reply
-+ _curtrans->res = res;
- emit walletAsyncOpened(_curtrans->tId, res);
- break;
-
- case KWalletTransaction::OpenFail:
- // emit the AsyncOpened signal with an invalid handle
-+ _curtrans->res = -1;
- emit walletAsyncOpened(_curtrans->tId, -1);
- break;
-
-@@ -230,14 +234,21 @@
- break;
- }
-
-+ // send delayed dbus message reply to the caller
-+ if (_curtrans->message.type() != QDBusMessage::InvalidMessage) {
-+ if (_curtrans->connection.isConnected()) {
-+ QDBusMessage reply = _curtrans->message.createReply();
-+ reply << _curtrans->res;
-+ _curtrans->connection.send(reply);
-+ }
-+ }
-+
- delete _curtrans;
- _curtrans = 0;
- }
-
- _processing = false;
- }
--
--
-
- int KWalletD::openPath(const QString& path, qlonglong wId, const QString& appid) {
- int tId = openPathAsync(path, wId, appid, false);
-@@ -245,20 +256,39 @@
- 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);
-+// KWalletOpenLoop loop(this);
-+// return loop.waitForAsyncOpen(tId);
- }
-
- int KWalletD::open(const QString& wallet, qlonglong wId, const QString& appid) {
-- int tId = openAsync(wallet, wId, appid, false);
-- if (tId < 0) {
-- return tId;
-- }
--
-- // wait for the open-transaction to be processed
-- KWalletOpenLoop loop(this);
-- return loop.waitForAsyncOpen(tId);
-+ if (!_enabled) { // guard
-+ return -1;
-+ }
-+
-+ if (!QRegExp("^[\\w\\^\\&\\'\\@\\{\\}\\[\\]\\,\\$\\=\\!\\-\\#\\(\\)\\%\\.\\+\\_\\s]+$").exactMatch(wallet)) {
-+ return -1;
-+ }
-+
-+ KWalletTransaction *xact = new KWalletTransaction(connection());
-+ _transactions.append(xact);
-+
-+ message().setDelayedReply(true);
-+ xact->message = message();
-+
-+ 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;
-+
-+ QTimer::singleShot(0, this, SLOT(processTransactions()));
-+ checkActiveDialog();
-+ // NOTE the real return value will be sent by the dbusmessage delayed reply
-+ return 0;
- }
-
- int KWalletD::openAsync(const QString& wallet, qlonglong wId, const QString& appid,
-@@ -271,8 +301,8 @@
- return -1;
- }
-
-- KWalletTransaction *xact = new KWalletTransaction;
-- _transactions.append(xact);
-+ KWalletTransaction *xact = new KWalletTransaction(connection());
-+ _transactions.append(xact);
-
- xact->appid = appid;
- xact->wallet = wallet;
-@@ -298,8 +328,8 @@
- return -1;
- }
-
-- KWalletTransaction *xact = new KWalletTransaction;
-- _transactions.append(xact);
-+ KWalletTransaction *xact = new KWalletTransaction(connection());
-+ _transactions.append(xact);
-
- xact->appid = appid;
- xact->wallet = path;
-@@ -674,9 +704,11 @@
-
-
- void KWalletD::changePassword(const QString& wallet, qlonglong wId, const QString& appid) {
-- KWalletTransaction *xact = new KWalletTransaction;
--
-- //msg.setDelayedReply(true);
-+ KWalletTransaction *xact = new KWalletTransaction(connection());
-+
-+ message().setDelayedReply(true);
-+ xact->message = message();
-+
- xact->appid = appid;
- xact->wallet = wallet;
- xact->wId = wId;
-
---- a/kwalletd/kwalletopenloop.cpp
-+++ /dev/null
-@@ -1,46 +0,0 @@
--// -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
--/*
-- This file is part of the KDE libraries
--
-- Copyright (c) 2008 Michael Leupold <lemma@confuego.org>
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Library General Public
-- License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Library General Public License for more details.
--
-- You should have received a copy of the GNU Library General Public License
-- along with this library; see the file COPYING.LIB. If not, write to
-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-- Boston, MA 02110-1301, USA.
--
--*/
--
--#include "kwalletopenloop.h"
--#include "kwalletd.h"
--
--int KWalletOpenLoop::waitForAsyncOpen(int tId)
--{
-- transaction = tId;
-- connect(wallet, SIGNAL(walletAsyncOpened(int, int)),
-- SLOT(walletAsyncOpened(int, int)));
-- exec();
-- disconnect(this, SLOT(walletAsyncOpened(int, int)));
-- return result;
--}
--
--void KWalletOpenLoop::walletAsyncOpened(int tId, int handle)
--{
-- // if our transaction finished, stop waiting
-- if (tId == transaction) {
-- result = handle;
-- quit();
-- }
--}
--
--#include "kwalletopenloop.moc"
---- a/kwalletd/kwalletopenloop.h
-+++ /dev/null
-@@ -1,50 +0,0 @@
--// -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
--/*
-- This file is part of the KDE libraries
--
-- Copyright (c) 2008 Michael Leupold <lemma@confuego.org>
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Library General Public
-- License as published by the Free Software Foundation; either
-- version 2 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Library General Public License for more details.
--
-- You should have received a copy of the GNU Library General Public License
-- along with this library; see the file COPYING.LIB. If not, write to
-- the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-- Boston, MA 02110-1301, USA.
--
--*/
--
--#ifndef KWALLETOPENLOOP_H
--#define KWALLETOPENLOOP_H
--
--#include <QtCore/QEventLoop>
--
--class KWalletD;
--
--class KWalletOpenLoop : public QEventLoop {
-- Q_OBJECT
--
-- public:
-- explicit KWalletOpenLoop(KWalletD* w, QObject* parent = 0)
-- : QEventLoop(parent), wallet(w) {}
--
-- // returns the open handle
-- int waitForAsyncOpen(int tId);
--
-- public slots:
-- void walletAsyncOpened(int tId, int handle);
--
-- private:
-- KWalletD* wallet;
-- int transaction;
-- int result;
--};
--
--#endif
---- a/kwalletd/main.cpp
-+++ b/kwalletd/main.cpp
-@@ -65,6 +65,7 @@
- return (0);
- }
-
-+ kDebug() << "kwalletd started";
- KWalletD walletd;
- return app.exec();
- }
-