/cpw/tomkiewicz/masterpassword: a83c82be880d: Kwallet: cosmetic ...

Tomasz Wasilczyk tomkiewicz at cpw.pidgin.im
Tue Mar 19 15:19:22 EDT 2013


Changeset: a83c82be880d89cbabed2587a3a0d96bc00d1a6c
Author:	 Tomasz Wasilczyk <tomkiewicz at cpw.pidgin.im>
Date:	 2013-03-19 20:19 +0100
Branch:	 soc.2008.masterpassword
URL: https://hg.pidgin.im/cpw/tomkiewicz/masterpassword/rev/a83c82be880d

Description:

Kwallet: cosmetic changes, mostly formatting

diffstat:

 libpurple/plugins/keyrings/kwallet.cpp |  270 +++++++++++++++++---------------
 1 files changed, 146 insertions(+), 124 deletions(-)

diffs (truncated from 481 to 300 lines):

diff --git a/libpurple/plugins/keyrings/kwallet.cpp b/libpurple/plugins/keyrings/kwallet.cpp
--- a/libpurple/plugins/keyrings/kwallet.cpp
+++ b/libpurple/plugins/keyrings/kwallet.cpp
@@ -24,7 +24,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program ; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
  */
 
 #include "internal.h"
@@ -49,7 +49,7 @@
 
 PurpleKeyring *keyring_handler = NULL;
 
-#define ERR_KWALLETPLUGIN 	kwallet_plugin_error_domain()
+#define ERR_KWALLETPLUGIN kwallet_plugin_error_domain()
 
 namespace KWalletPlugin {
 
@@ -57,7 +57,8 @@ class request
 {
 	public:
 		virtual ~request();
-		virtual void abort() = 0;
+		virtual void detailedAbort(enum PurpleKeyringError error) = 0;
+		void abort();
 		virtual void execute(KWallet::Wallet *wallet) = 0;
 
 	protected:
@@ -74,33 +75,37 @@ class engine : private QObject, private 
 		engine();
 		~engine();
 		void queue(request *req);
-		static engine *Instance();
+		static engine *instance();
 		static void closeInstance();
-		bool closing;
 
 	private slots:
 		void walletOpened(bool opened);
 		void walletClosed();
 
 	private:
-		QCoreApplication *app;
+		static engine *pinstance;
+
 		bool connected;
 		bool failed;
+		bool closing;
 		bool externallyClosed;
+
+		QCoreApplication *app;
 		KWallet::Wallet *wallet;
-		static engine *pinstance;
+
 		gint idle_handle;
 		static bool idle_cb(engine *me);
+
 		void reopenWallet();
-
-		void ExecuteRequests();
+		void executeRequests();
 };
 
 class save_request : public request
 {
 	public:
-		save_request(PurpleAccount *account, const char *password, PurpleKeyringSaveCallback cb, void *data);
-		void abort();
+		save_request(PurpleAccount *account, const char *password,
+			PurpleKeyringSaveCallback cb, void *data);
+		void detailedAbort(enum PurpleKeyringError error);
 		void execute(KWallet::Wallet *wallet);
 
 	private:
@@ -110,8 +115,9 @@ class save_request : public request
 class read_request : public request
 {
 	public:
-		read_request(PurpleAccount *account, PurpleKeyringReadCallback cb, void *data);
-		void abort();
+		read_request(PurpleAccount *account,
+			PurpleKeyringReadCallback cb, void *data);
+		void detailedAbort(enum PurpleKeyringError error);
 		void execute(KWallet::Wallet *wallet);
 
 	private:
@@ -132,9 +138,20 @@ KWalletPlugin::request::~request()
 {
 }
 
+void
+KWalletPlugin::request::abort()
+{
+	detailedAbort(PURPLE_KEYRING_ERROR_UNKNOWN);
+}
+
 KWalletPlugin::engine::engine()
 {
-	closing = FALSE;
+	connected = false;
+	failed = false;
+	closing = false;
+	externallyClosed = false;
+	wallet = NULL;
+	idle_handle = 0;
 
 	int argc = 0;
 	app = new QCoreApplication(argc, NULL);
@@ -146,21 +163,34 @@ KWalletPlugin::engine::engine()
 void
 KWalletPlugin::engine::reopenWallet()
 {
-	connected = FALSE;
-	failed = FALSE;
-	externallyClosed = FALSE;
-
-	wallet = KWallet::Wallet::openWallet(KWALLET_WALLET_NAME, 0, KWallet::Wallet::Asynchronous);
-	if (wallet == NULL) {
-		failed = TRUE;
-		purple_debug_error("keyring-kwallet", "failed opening a wallet\n");
+	if (closing) {
+		purple_debug_error("keyring-kwallet",
+			"wallet is closing right now\n");
+		failed = true;
 		return;
 	}
 
-	failed |= !connect(wallet, SIGNAL(walletClosed()), SLOT(walletClosed()));
-	failed |= !connect(wallet, SIGNAL(walletOpened(bool)), SLOT(walletOpened(bool)));
-	if (failed)
-		purple_debug_error("keyring-kwallet", "failed connecting to wallet signal\n");
+	connected = false;
+	failed = false;
+	externallyClosed = false;
+
+	wallet = KWallet::Wallet::openWallet(KWALLET_WALLET_NAME, 0,
+		KWallet::Wallet::Asynchronous);
+	if (wallet == NULL) {
+		failed = true;
+		purple_debug_error("keyring-kwallet",
+			"failed opening a wallet\n");
+		return;
+	}
+
+	failed |= !connect(wallet, SIGNAL(walletClosed()),
+		SLOT(walletClosed()));
+	failed |= !connect(wallet, SIGNAL(walletOpened(bool)),
+		SLOT(walletOpened(bool)));
+	if (failed) {
+		purple_debug_error("keyring-kwallet",
+			"failed connecting to wallet signal\n");
+	}
 }
 
 KWalletPlugin::engine::~engine()
@@ -183,7 +213,7 @@ KWalletPlugin::engine::~engine()
 }
 
 KWalletPlugin::engine *
-KWalletPlugin::engine::Instance()
+KWalletPlugin::engine::instance()
 {
 	if (pinstance == NULL)
 		pinstance = new engine;
@@ -217,22 +247,27 @@ KWalletPlugin::engine::walletOpened(bool
 
 	if (!wallet->hasFolder(KWALLET_FOLDER_NAME)) {
 		if (!wallet->createFolder(KWALLET_FOLDER_NAME)) {
-			purple_debug_error("keyring-kwallet", "couldn't create \"" KWALLET_FOLDER_NAME "\" folder in wallet\n");
-			failed = TRUE;
+			purple_debug_error("keyring-kwallet",
+				"couldn't create \"" KWALLET_FOLDER_NAME
+				"\" folder in wallet\n");
+			failed = true;
 		}
 	}
 	if (!failed)
 		wallet->setFolder(KWALLET_FOLDER_NAME);
 
-	ExecuteRequests();
+	executeRequests();
 }
 
 void
 KWalletPlugin::engine::walletClosed()
 {
 	if (!closing) {
-		externallyClosed = TRUE;
-		purple_debug_info("keyring-kwallet", "wallet was externally closed\n");
+		purple_debug_info("keyring-kwallet",
+			"wallet was externally closed\n");
+		externallyClosed = true;
+		delete wallet;
+		wallet = NULL;
 	}
 }
 
@@ -240,7 +275,7 @@ void
 KWalletPlugin::engine::queue(request *req)
 {
 	enqueue(req);
-	ExecuteRequests();
+	executeRequests();
 }
 
 bool
@@ -251,7 +286,7 @@ KWalletPlugin::engine::idle_cb(KWalletPl
 }
 
 void
-KWalletPlugin::engine::ExecuteRequests()
+KWalletPlugin::engine::executeRequests()
 {
 	if (idle_handle == 0)
 		idle_handle = g_idle_add((GSourceFunc)idle_cb, this);
@@ -272,49 +307,52 @@ KWalletPlugin::engine::ExecuteRequests()
 	}
 }
 
-KWalletPlugin::save_request::save_request(PurpleAccount *acc, const char *pw, PurpleKeyringSaveCallback cb, void *userdata)
+KWalletPlugin::save_request::save_request(PurpleAccount *acc, const char *pw,
+	PurpleKeyringSaveCallback cb, void *userdata)
 {
-	account  = acc;
-	data     = userdata;
+	account = acc;
+	data = userdata;
 	callback = cb;
 	password = QString(pw);
 }
 
-KWalletPlugin::read_request::read_request(PurpleAccount *acc, PurpleKeyringReadCallback cb, void *userdata)
+KWalletPlugin::read_request::read_request(PurpleAccount *acc,
+	PurpleKeyringReadCallback cb, void *userdata)
 {
-	account  = acc;
-	data     = userdata;
+	account = acc;
+	data = userdata;
 	callback = cb;
 	password = QString();
 }
 
 void
-KWalletPlugin::save_request::abort()
+KWalletPlugin::save_request::detailedAbort(enum PurpleKeyringError error)
 {
-	GError *error;
-	if (callback != NULL) {
-		error = g_error_new(ERR_KWALLETPLUGIN,
-		                    PURPLE_KEYRING_ERROR_UNKNOWN,
-		                    "Failed to save password");
-		callback(account, error, data);
-		g_error_free(error);
-	}
+	GError *gerror;
+	if (callback == NULL)
+		return;
+
+	gerror = g_error_new(ERR_KWALLETPLUGIN, error,
+		"Failed to save password");
+	callback(account, gerror, data);
+	g_error_free(gerror);
 }
 
 void
-KWalletPlugin::read_request::abort()
+KWalletPlugin::read_request::detailedAbort(enum PurpleKeyringError error)
 {
-	GError *error;
-	if (callback != NULL) {
-		error = g_error_new(ERR_KWALLETPLUGIN,
-		                    PURPLE_KEYRING_ERROR_UNKNOWN,
-		                    "Failed to read password");
-		callback(account, NULL, error, data);
-		g_error_free(error);
-	}
+	GError *gerror;
+	if (callback == NULL)
+		return;
+
+	gerror = g_error_new(ERR_KWALLETPLUGIN, error,
+		"Failed to read password");
+	callback(account, NULL, gerror, data);
+	g_error_free(gerror);
 }
 
-static QString kwallet_account_key(PurpleAccount *account)
+static QString
+kwallet_account_key(PurpleAccount *account)
 {
 	return QString(purple_account_get_protocol_id(account)) + ":" +
 		purple_account_get_username(account);
@@ -330,7 +368,8 @@ KWalletPlugin::read_request::execute(KWa
 	result = wallet->readPassword(kwallet_account_key(account), password);
 
 	if (result != 0) {



More information about the Commits mailing list