fix issues with Qt application object in kwallet plugin

Mon, 13 Mar 2023 15:23:16 -0500

author
Markus Fischer <ivanhoe@fiscari.de>
date
Mon, 13 Mar 2023 15:23:16 -0500
changeset 42146
f63bd4f70ce9
parent 42145
f9b76a91e3ae
child 42147
d202e153dd70

fix issues with Qt application object in kwallet plugin

Use QGuiApplication instead of QCoreApplication to avoid runtime warning "Cannot use KWindowSystem without a QGuiApplication"
Provide argc and argv for QGuiApplication object as its documentation requires:
"The data referred to by argc and argv must stay valid for the entire lifetime of the QGuiApplication object. In addition, argc must be greater than zero and argv must contain at least one valid character string."

Testing Done:
* set kwallet as credential provider
* connected account with saved credentials
* disconnected credential provider externally
* created and connected new account and saved credentials
* restarted pidgin to let accounts autoconnect

Reviewed at https://reviews.imfreedom.org/r/2338/

libpurple/plugins/kwallet/purplekwallet.cpp file | annotate | diff | comparison | revisions
meson.build file | annotate | diff | comparison | revisions
--- a/libpurple/plugins/kwallet/purplekwallet.cpp	Mon Mar 13 15:12:12 2023 -0500
+++ b/libpurple/plugins/kwallet/purplekwallet.cpp	Mon Mar 13 15:23:16 2023 -0500
@@ -24,7 +24,7 @@
 
 #include <purple.h>
 
-#include <QCoreApplication>
+#include <QGuiApplication>
 
 #include <kwallet.h>
 
@@ -33,8 +33,12 @@
 /******************************************************************************
  * Globals
  *****************************************************************************/
-static QCoreApplication *qCoreApp = NULL;
+static QGuiApplication *guiApp = NULL;
 static PurpleCredentialProvider *instance = NULL;
+static char *argv[] = {
+	(char*)"purplekwallet",
+};
+static int argc = G_N_ELEMENTS(argv);
 
 #define PURPLE_KWALLET_DOMAIN (g_quark_from_static_string("purple-kwallet"))
 #define PURPLE_KWALLET_WALLET_NAME (KWallet::Wallet::NetworkWallet())
@@ -569,10 +573,9 @@
 
 	purple_kwallet_provider_register_type(G_TYPE_MODULE(plugin));
 
-	if(qCoreApp == NULL) {
-		int argc = 0;
-		qCoreApp = new QCoreApplication(argc, NULL);
-		qCoreApp->setApplicationName(purple_kwallet_get_ui_name());
+	if(guiApp == NULL) {
+		guiApp = new QGuiApplication(argc, argv);
+		guiApp->setApplicationName(purple_kwallet_get_ui_name());
 	}
 
 	if(!KWallet::Wallet::isEnabled()) {
@@ -604,9 +607,9 @@
 		return ret;
 	}
 
-	if(qCoreApp != NULL) {
-		delete qCoreApp;
-		qCoreApp = NULL;
+	if(guiApp != NULL) {
+		delete guiApp;
+		guiApp = NULL;
 	}
 
 	g_clear_object(&instance);
--- a/meson.build	Mon Mar 13 15:12:12 2023 -0500
+++ b/meson.build	Mon Mar 13 15:23:16 2023 -0500
@@ -452,7 +452,7 @@
 
 	qt5 = import('qt5')
 
-	qt5_dep = dependency('qt5', modules: ['Core'], required : get_option('kwallet'))
+	qt5_dep = dependency('qt5', modules: ['Core', 'Gui'], required : get_option('kwallet'))
 
 	kwallet = dependency('KF5Wallet', required : get_option('kwallet'))
 endif

mercurial