/cpw/tomkiewicz/masterpassword: 8852b9a4dd2a: Better usage of QC...

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


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

Description:

Better usage of QCoreApplication

diffstat:

 libpurple/plugins/keyrings/kwallet.cpp |  35 +++++++++++----------------------
 1 files changed, 12 insertions(+), 23 deletions(-)

diffs (99 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
@@ -48,6 +48,7 @@
 #define KWALLET_FOLDER_NAME "libpurple"
 
 PurpleKeyring *keyring_handler = NULL;
+QCoreApplication *qCoreApp = NULL;
 
 #define ERR_KWALLETPLUGIN kwallet_plugin_error_domain()
 
@@ -90,12 +91,8 @@ class engine : private QObject, private 
 		bool closing;
 		bool externallyClosed;
 
-		QCoreApplication *app;
 		KWallet::Wallet *wallet;
 
-		gint idle_handle;
-		static bool idle_cb(engine *me);
-
 		void reopenWallet();
 		void executeRequests();
 };
@@ -151,11 +148,6 @@ KWalletPlugin::engine::engine()
 	closing = false;
 	externallyClosed = false;
 	wallet = NULL;
-	idle_handle = 0;
-
-	int argc = 0;
-	app = new QCoreApplication(argc, NULL);
-	app->setApplicationName(KWALLET_APP_NAME);
 
 	reopenWallet();
 }
@@ -197,9 +189,6 @@ KWalletPlugin::engine::~engine()
 {
 	closing = true;
 
-	if (idle_handle)
-		g_source_remove(idle_handle);
-
 	while (!isEmpty()) {
 		request *req = dequeue();
 		req->abort();
@@ -207,7 +196,6 @@ KWalletPlugin::engine::~engine()
 	}
 
 	delete wallet;
-	delete app;
 
 	pinstance = NULL;
 }
@@ -278,19 +266,9 @@ KWalletPlugin::engine::queue(request *re
 	executeRequests();
 }
 
-bool
-KWalletPlugin::engine::idle_cb(KWalletPlugin::engine *me)
-{
-	me->app->processEvents();
-	return true;
-}
-
 void
 KWalletPlugin::engine::executeRequests()
 {
-	if (idle_handle == 0)
-		idle_handle = g_idle_add((GSourceFunc)idle_cb, this);
-
 	if (externallyClosed) {
 		reopenWallet();
 	} else if (connected || failed) {
@@ -447,6 +425,12 @@ kwallet_export(PurpleAccount *account, c
 static gboolean
 kwallet_load(PurplePlugin *plugin)
 {
+	if (!qCoreApp) {
+		int argc = 0;
+		qCoreApp = new QCoreApplication(argc, NULL);
+		qCoreApp->setApplicationName(KWALLET_APP_NAME);
+	}
+
 	keyring_handler = purple_keyring_new();
 
 	purple_keyring_set_name(keyring_handler, KWALLET_NAME);
@@ -477,6 +461,11 @@ kwallet_unload(PurplePlugin *plugin)
 	purple_keyring_free(keyring_handler);
 	keyring_handler = NULL;
 
+	if (qCoreApp) {
+		delete qCoreApp;
+		qCoreApp = NULL;
+	}
+
 	return TRUE;
 }
 



More information about the Commits mailing list