From ae6bfa6ff6e6b0e69410fdbbe6101b4d10235e6d Mon Sep 17 00:00:00 2001
From: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
Date: Fri, 23 Oct 2026 20:24:09 -0300
Subject: Normalize TQt GLib loop detection
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Sebastião Guerra <sebastiao.luiz.guerra@gmail.com>
---
 ConfigureChecks.cmake           |  5 ++++-
 src/CMakeLists.txt              |  5 +++--
 src/main.cpp                    | 29 +++++------------------------
 src/polkit-agent-event-loop.cpp | 33 +++++++++++++++++++++++++++++++++
 src/polkit-agent-event-loop.h   | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+), 27 deletions(-)
 create mode 100644 src/polkit-agent-event-loop.cpp
 create mode 100644 src/polkit-agent-event-loop.h

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index a4656c9..509f920 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -33,7 +33,10 @@ if( NOT POLKIT_TQT_FOUND )
 endif( )
 
 pkg_get_variable( TQT_CONFIG tqt-mt qt_config )
-if( "glibmainloop" IN_LIST TQT_CONFIG )
+# FindPkgConfig may return this value as a CMake list rather than a command string.
+string( REPLACE ";" " " TQT_CONFIG_STRING "${TQT_CONFIG}" )
+separate_arguments( TQT_CONFIG_LIST NATIVE_COMMAND "${TQT_CONFIG_STRING}" )
+if( "glibmainloop" IN_LIST TQT_CONFIG_LIST )
   set( POLKIT_AGENT_TQT_GLIBMAINLOOP TRUE )
 else( )
   pkg_search_module( GLIB2 glib-2.0 )
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 269791e..fd68a98 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -31,6 +31,7 @@ else( )
   include_directories( ${GLIB2_INCLUDE_DIRS} )
   link_directories( ${GLIB2_LIBRARY_DIRS} )
   set( POLKIT_AGENT_GLIB_LIBRARIES ${GLIB2_LIBRARIES} )
+  set( POLKIT_AGENT_EVENT_LOOP_SOURCES polkit-agent-event-loop.h polkit-agent-event-loop.cpp )
 endif( )
 
 
@@ -46,7 +47,7 @@ tde_create_translated_desktop(
 tde_add_executable( polkit-agent-tde AUTOMOC
   SOURCES AuthDialogWidget.ui AuthDetailsWidget.ui AuthDialog.h AuthDialog.cpp
           polkit-listener.h polkit-listener.cpp polkit-agent-tde.h polkit-agent-tde.cpp main.cpp
-  LINK tdecore-shared tdeui-shared polkit-tqt-agent-shared
-       ${POLKIT_AGENT_GLIB_LIBRARIES}
+          ${POLKIT_AGENT_EVENT_LOOP_SOURCES}
+  LINK tdecore-shared tdeui-shared polkit-tqt-agent-shared ${POLKIT_AGENT_GLIB_LIBRARIES}
   DESTINATION ${BIN_INSTALL_DIR}
 )
diff --git a/src/main.cpp b/src/main.cpp
index e194f86..32d993b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,36 +22,13 @@
 #include <tdecmdlineargs.h>
 #include <tdelocale.h>
 #ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
-#include <tqeventloop.h>
-#include <glib.h>
+#include "polkit-agent-event-loop.h"
 #endif
 
 #include "polkit-agent-tde.h"
 
-#ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
-class PolkitAgentEventLoop : public TQEventLoop
-{
-public:
-  PolkitAgentEventLoop() : TQEventLoop()
-  {
-    startTimer(100);
-  }
-
-  bool processEvents(ProcessEventsFlags flags) override
-  {
-    bool glibProcessed = g_main_context_iteration(nullptr, false);
-    bool tqtProcessed = TQEventLoop::processEvents(flags);
-    return glibProcessed || tqtProcessed;
-  }
-};
-#endif
-
 int main(int argc, char *argv[])
 {
-#ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
-  PolkitAgentEventLoop glibEventLoop;
-#endif
-
   TDEAboutData aboutData("polkit-agent-tde", I18N_NOOP("Polkit-Agent-TDE"), "0.99.1",
           I18N_NOOP("A Polkit authentication agent for TDE"), TDEAboutData::License_GPL,
           I18N_NOOP("(c) 2009 Red Hat, Inc."));
@@ -66,6 +43,10 @@ int main(int argc, char *argv[])
     return 0;
   }
 
+#ifndef POLKIT_AGENT_TQT_GLIBMAINLOOP
+  PolkitAgentEventLoop glibEventLoop;
+#endif
+
   PolkitAgentTDE agent;
   agent.disableSessionManagement();
   return agent.exec();
diff --git a/src/polkit-agent-event-loop.cpp b/src/polkit-agent-event-loop.cpp
new file mode 100644
index 0000000..b5ba57c
--- /dev/null
+++ b/src/polkit-agent-event-loop.cpp
@@ -0,0 +1,33 @@
+/*  This file is part of the TDE project
+    Copyright (C) 2026 Trinity Desktop Project
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This program 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
+    General Public License for more details.
+
+    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 02110-1301, USA.
+*/
+
+#include "polkit-agent-event-loop.h"
+
+#include <glib.h>
+
+PolkitAgentEventLoop::PolkitAgentEventLoop() : TQEventLoop()
+{
+  startTimer(100);
+}
+
+bool PolkitAgentEventLoop::processEvents(ProcessEventsFlags flags)
+{
+  bool glibProcessed = g_main_context_iteration(nullptr, false);
+  bool tqtProcessed = TQEventLoop::processEvents(flags);
+  return glibProcessed || tqtProcessed;
+}
diff --git a/src/polkit-agent-event-loop.h b/src/polkit-agent-event-loop.h
new file mode 100644
index 0000000..c8ac838
--- /dev/null
+++ b/src/polkit-agent-event-loop.h
@@ -0,0 +1,32 @@
+/*  This file is part of the TDE project
+    Copyright (C) 2026 Trinity Desktop Project
+
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This program 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
+    General Public License for more details.
+
+    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 02110-1301, USA.
+*/
+
+#ifndef POLKIT_AGENT_EVENT_LOOP_H
+#define POLKIT_AGENT_EVENT_LOOP_H
+
+#include <tqeventloop.h>
+
+class PolkitAgentEventLoop : public TQEventLoop
+{
+public:
+  PolkitAgentEventLoop();
+
+  bool processEvents(ProcessEventsFlags flags) override;
+};
+
+#endif // POLKIT_AGENT_EVENT_LOOP_H
-- 
cgit v1.2.3

