Generate logging category for AutoDetectAPN

This commit is contained in:
Nicolas Fella 2026-04-06 13:36:35 +02:00
parent 86cea76edd
commit f553dc96b8
2 changed files with 14 additions and 8 deletions

View file

@ -20,3 +20,10 @@ target_link_libraries(kded_plasma_mobile_autodetect_apn PRIVATE
KF6::ModemManagerQt KF6::ModemManagerQt
QCoro::DBus QCoro::DBus
) )
ecm_qt_declare_logging_category(kded_plasma_mobile_autodetect_apn
HEADER autodetectapn_debug.h
IDENTIFIER AUTODETECTAPN_LOG
CATEGORY_NAME org.kde.plasma.autodetectapn
DESCRIPTION "Plasma Mobile Autodetect APNs"
)

View file

@ -27,11 +27,10 @@
#include <ModemManagerQt/Modem3Gpp> #include <ModemManagerQt/Modem3Gpp>
#include "autodetectapn.h" #include "autodetectapn.h"
#include "autodetectapn_debug.h"
K_PLUGIN_FACTORY_WITH_JSON(StartFactory, "kded_plasma_mobile_autodetectapn.json", registerPlugin<AutoDetectAPN>();) K_PLUGIN_FACTORY_WITH_JSON(StartFactory, "kded_plasma_mobile_autodetectapn.json", registerPlugin<AutoDetectAPN>();)
static const QLoggingCategory LOGGING_CATEGORY("plasma-mobile-autodetectapn");
AutoDetectAPN::AutoDetectAPN(QObject *parent, const QList<QVariant> &) AutoDetectAPN::AutoDetectAPN(QObject *parent, const QList<QVariant> &)
: KDEDModule{parent} : KDEDModule{parent}
{ {
@ -41,11 +40,11 @@ AutoDetectAPN::AutoDetectAPN(QObject *parent, const QList<QVariant> &)
QCoro::Task<void> AutoDetectAPN::checkAndAddAutodetectedAPN() QCoro::Task<void> AutoDetectAPN::checkAndAddAutodetectedAPN()
{ {
if (!KRuntimePlatform::runtimePlatform().contains(QStringLiteral("phone"))) { if (!KRuntimePlatform::runtimePlatform().contains(QStringLiteral("phone"))) {
qCDebug(LOGGING_CATEGORY) << "Not running APN autodetection because this is not a Plasma Mobile session..."; qCDebug(AUTODETECTAPN_LOG) << "Not running APN autodetection because this is not a Plasma Mobile session...";
co_return; co_return;
} }
qCDebug(LOGGING_CATEGORY) << "Running APN autodetection..."; qCDebug(AUTODETECTAPN_LOG) << "Running APN autodetection...";
for (ModemManager::ModemDevice::Ptr mmDevice : ModemManager::modemDevices()) { for (ModemManager::ModemDevice::Ptr mmDevice : ModemManager::modemDevices()) {
ModemManager::Modem::Ptr mmModem = mmDevice->modemInterface(); ModemManager::Modem::Ptr mmModem = mmDevice->modemInterface();
@ -65,7 +64,7 @@ QCoro::Task<void> AutoDetectAPN::checkAndAddAutodetectedAPN()
// TODO: currently just check if there are any NM connections, this doesn't work if the user swapped out their SIM. // TODO: currently just check if there are any NM connections, this doesn't work if the user swapped out their SIM.
// we need something that detects when this occurs // we need something that detects when this occurs
if (!nmModem->availableConnections().empty()) { if (!nmModem->availableConnections().empty()) {
qCDebug(LOGGING_CATEGORY) << "Modem" << nmModem->uni() << "already has a connection configured"; qCDebug(AUTODETECTAPN_LOG) << "Modem" << nmModem->uni() << "already has a connection configured";
continue; continue;
} }
@ -78,7 +77,7 @@ QCoro::Task<void> AutoDetectAPN::checkAndAddAutodetectedAPN()
// Autodetect an APN // Autodetect an APN
std::optional<APNEntry> detectedAPNOpt = findAPN(operatorCode, gid1, spn, imsi); std::optional<APNEntry> detectedAPNOpt = findAPN(operatorCode, gid1, spn, imsi);
if (detectedAPNOpt == std::nullopt || (*detectedAPNOpt).apn.isEmpty()) { if (detectedAPNOpt == std::nullopt || (*detectedAPNOpt).apn.isEmpty()) {
qCDebug(LOGGING_CATEGORY) << "Could not find an APN for the SIM with code" << operatorCode; qCDebug(AUTODETECTAPN_LOG) << "Could not find an APN for the SIM with code" << operatorCode;
continue; continue;
} }
@ -115,9 +114,9 @@ QCoro::Task<void> AutoDetectAPN::checkAndAddAutodetectedAPN()
} }
if (!reply.isValid()) { if (!reply.isValid()) {
qCWarning(LOGGING_CATEGORY) << "Error adding autodetected connection:" << reply.error().message(); qCWarning(AUTODETECTAPN_LOG) << "Error adding autodetected connection:" << reply.error().message();
} else { } else {
qCDebug(LOGGING_CATEGORY) << "Successfully autodetected" << detectedAPN.carrier << "with APN" << detectedAPN.apn << "."; qCDebug(AUTODETECTAPN_LOG) << "Successfully autodetected" << detectedAPN.carrier << "with APN" << detectedAPN.apn << ".";
} }
} }
} }