Add logging category for platform services

Rather than being hidden behind a compile time flag or uncategorized

Change-Id: I3bc1781351220441134fb9815644e905273a1e40
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
David Redondo 2025-02-05 12:18:53 +01:00
parent 0770171dcd
commit 3c8bc2721c
7 changed files with 18 additions and 24 deletions

View File

@ -9,6 +9,8 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(lcQpaServices, "qt.qpa.services", QtWarningMsg)
/*! /*!
\class QPlatformServices \class QPlatformServices
\since 5.0 \since 5.0

View File

@ -15,9 +15,12 @@
#include <QtGui/qtguiglobal.h> #include <QtGui/qtguiglobal.h>
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtCore/qloggingcategory.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(lcQpaServices, Q_GUI_EXPORT)
class QUrl; class QUrl;
class QWindow; class QWindow;

View File

@ -46,8 +46,6 @@ using namespace Qt::StringLiterals;
#if QT_CONFIG(multiprocess) #if QT_CONFIG(multiprocess)
enum { debug = 0 };
static inline QByteArray detectDesktopEnvironment() static inline QByteArray detectDesktopEnvironment()
{ {
const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP"); const QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
@ -136,8 +134,7 @@ static inline bool launch(const QString &launcher, const QUrl &url,
{ {
const QString command = launcher + u' ' + QLatin1StringView(url.toEncoded()); const QString command = launcher + u' ' + QLatin1StringView(url.toEncoded());
if (debug) qCDebug(lcQpaServices, "Launching %s", qPrintable(command));
qDebug("Launching %s", qPrintable(command));
#if !QT_CONFIG(process) #if !QT_CONFIG(process)
if (!xdgActivationToken.isEmpty()) if (!xdgActivationToken.isEmpty())
qputenv("XDG_ACTIVATION_TOKEN", xdgActivationToken.toUtf8()); qputenv("XDG_ACTIVATION_TOKEN", xdgActivationToken.toUtf8());
@ -162,8 +159,7 @@ static inline bool launch(const QString &launcher, const QUrl &url,
} }
# endif # endif
if (!ok) if (!ok)
qWarning("Launch failed (%s)", qPrintable(command)); qCWarning(lcQpaServices, "Launch failed (%s)", qPrintable(command));
return ok; return ok;
} }
@ -501,7 +497,7 @@ bool QDesktopUnixServices::openUrl(const QUrl &url)
if (m_webBrowser.isEmpty() if (m_webBrowser.isEmpty()
&& !detectWebBrowser(desktopEnvironment(), true, &m_webBrowser)) { && !detectWebBrowser(desktopEnvironment(), true, &m_webBrowser)) {
qWarning("Unable to detect a web browser to launch '%s'", qPrintable(url.toString())); qCWarning(lcQpaServices, "Unable to detect a web browser to launch '%s'", qPrintable(url.toString()));
return false; return false;
} }
return launch(m_webBrowser, url, xdgActivationToken); return launch(m_webBrowser, url, xdgActivationToken);
@ -535,7 +531,7 @@ bool QDesktopUnixServices::openDocument(const QUrl &url)
if (m_documentLauncher.isEmpty() if (m_documentLauncher.isEmpty()
&& !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) { && !detectWebBrowser(desktopEnvironment(), false, &m_documentLauncher)) {
qWarning("Unable to detect a launcher for '%s'", qPrintable(url.toString())); qCWarning(lcQpaServices, "Unable to detect a launcher for '%s'", qPrintable(url.toString()));
return false; return false;
} }
return launch(m_documentLauncher, url, xdgActivationToken); return launch(m_documentLauncher, url, xdgActivationToken);
@ -616,7 +612,7 @@ void QDesktopUnixServices::setApplicationBadge(qint64 number)
{ {
#if QT_CONFIG(dbus) #if QT_CONFIG(dbus)
if (qGuiApp->desktopFileName().isEmpty()) { if (qGuiApp->desktopFileName().isEmpty()) {
qWarning("QGuiApplication::desktopFileName() is empty"); qCWarning(lcQpaServices, "Cannot set badge number - QGuiApplication::desktopFileName() is empty");
return; return;
} }

View File

@ -42,7 +42,6 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaApplication)
Q_DECLARE_LOGGING_CATEGORY(lcQpaClipboard) Q_DECLARE_LOGGING_CATEGORY(lcQpaClipboard)
Q_DECLARE_LOGGING_CATEGORY(lcQpaDialogs) Q_DECLARE_LOGGING_CATEGORY(lcQpaDialogs)
Q_DECLARE_LOGGING_CATEGORY(lcQpaMenus) Q_DECLARE_LOGGING_CATEGORY(lcQpaMenus)
Q_DECLARE_LOGGING_CATEGORY(lcQpaServices)
class QPixmap; class QPixmap;
class QString; class QString;

View File

@ -29,7 +29,6 @@ Q_LOGGING_CATEGORY(lcQpaApplication, "qt.qpa.application");
Q_LOGGING_CATEGORY(lcQpaClipboard, "qt.qpa.clipboard") Q_LOGGING_CATEGORY(lcQpaClipboard, "qt.qpa.clipboard")
Q_LOGGING_CATEGORY(lcQpaDialogs, "qt.qpa.dialogs") Q_LOGGING_CATEGORY(lcQpaDialogs, "qt.qpa.dialogs")
Q_LOGGING_CATEGORY(lcQpaMenus, "qt.qpa.menus") Q_LOGGING_CATEGORY(lcQpaMenus, "qt.qpa.menus")
Q_LOGGING_CATEGORY(lcQpaServices, "qt.qpa.services")
// //
// Conversion Functions // Conversion Functions

View File

@ -17,7 +17,7 @@ QT_BEGIN_NAMESPACE
bool QIOSServices::openUrl(const QUrl &url) bool QIOSServices::openUrl(const QUrl &url)
{ {
if (qt_apple_isApplicationExtension()) { if (qt_apple_isApplicationExtension()) {
qWarning() << "openUrl not implement for application extensions yet"; qCWarning(lcQpaServices) << "openUrl not implement for application extensions yet";
return false; return false;
} }

View File

@ -21,8 +21,6 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals; using namespace Qt::StringLiterals;
enum { debug = 0 };
class QWindowsShellExecuteThread : public QThread class QWindowsShellExecuteThread : public QThread
{ {
public: public:
@ -83,11 +81,10 @@ static bool openWebBrowser(const QUrl &url)
thread.wait(); thread.wait();
const auto result = reinterpret_cast<quintptr>(thread.result()); const auto result = reinterpret_cast<quintptr>(thread.result());
if (debug) qCDebug(lcQpaServices) << urlS << QString::fromWCharArray(browserExecutable) << result;
qDebug() << __FUNCTION__ << urlS << QString::fromWCharArray(browserExecutable) << result;
// ShellExecute returns a value greater than 32 if successful // ShellExecute returns a value greater than 32 if successful
if (result <= 32) { if (result <= 32) {
qWarning("%s", qPrintable(msgShellExecuteFailed(url, result))); qCWarning(lcQpaServices, "%s", qPrintable(msgShellExecuteFailed(url, result)));
return false; return false;
} }
return true; return true;
@ -112,7 +109,7 @@ static inline bool shellExecute(const QUrl &url)
// ShellExecute returns a value greater than 32 if successful // ShellExecute returns a value greater than 32 if successful
if (result <= 32) { if (result <= 32) {
qWarning("%s", qPrintable(msgShellExecuteFailed(url, result))); qCWarning(lcQpaServices, "%s", qPrintable(msgShellExecuteFailed(url, result)));
return false; return false;
} }
return true; return true;
@ -132,8 +129,7 @@ static inline QString mailCommand()
.stringValue( L"Progid"); .stringValue( L"Progid");
const auto mailto = keyName.isEmpty() ? "mailto"_L1 : QLatin1StringView(); const auto mailto = keyName.isEmpty() ? "mailto"_L1 : QLatin1StringView();
keyName += mailto + "\\Shell\\Open\\Command"_L1; keyName += mailto + "\\Shell\\Open\\Command"_L1;
if (debug) qCDebug(lcQpaServices) << "keyName=" << keyName;
qDebug() << __FUNCTION__ << "keyName=" << keyName;
const QString command = QWinRegistryKey(HKEY_CLASSES_ROOT, keyName).stringValue(L""); const QString command = QWinRegistryKey(HKEY_CLASSES_ROOT, keyName).stringValue(L"");
// QTBUG-57816: As of Windows 10, if there is no mail client installed, an entry like // QTBUG-57816: As of Windows 10, if there is no mail client installed, an entry like
// "rundll32.exe .. url.dll,MailToProtocolHandler %l" is returned. Launching it // "rundll32.exe .. url.dll,MailToProtocolHandler %l" is returned. Launching it
@ -151,12 +147,12 @@ static inline bool launchMail(const QUrl &url)
{ {
QString command = mailCommand(); QString command = mailCommand();
if (command.isEmpty()) { if (command.isEmpty()) {
qWarning("Cannot launch '%ls': There is no mail program installed.", qUtf16Printable(url.toString())); qCWarning(lcQpaServices, "Cannot launch '%ls': There is no mail program installed.", qUtf16Printable(url.toString()));
return false; return false;
} }
// Fix mail launch if no param is expected in this command. // Fix mail launch if no param is expected in this command.
if (command.indexOf("%1"_L1) < 0) { if (command.indexOf("%1"_L1) < 0) {
qWarning() << "The mail command lacks the '%1' parameter."; qWarning(lcQpaServices) << "The mail command lacks the '%1' parameter.";
return false; return false;
} }
//Make sure the path for the process is in quotes //Make sure the path for the process is in quotes
@ -171,8 +167,7 @@ static inline bool launchMail(const QUrl &url)
// Pass the url as the parameter. Should use QProcess::startDetached(), // Pass the url as the parameter. Should use QProcess::startDetached(),
// but that cannot handle a Windows command line [yet]. // but that cannot handle a Windows command line [yet].
command.replace("%1"_L1, url.toString(QUrl::FullyEncoded)); command.replace("%1"_L1, url.toString(QUrl::FullyEncoded));
if (debug) qCDebug(lcQpaServices) << "Launching" << command;
qDebug() << __FUNCTION__ << "Launching" << command;
//start the process //start the process
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi)); ZeroMemory(&pi, sizeof(pi));