-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
Description
Besides of the documentation, it would be good to also add an inline example, such as:
#include <TelepathyQt/BaseDebug>
static QPointer<Tp::BaseDebug> debugInterfacePtr;
static QtMessageHandler defaultMessageHandler = nullptr;
void telepathyDebugHandler(QtMsgType type, const QMessageLogContext &context,
const QString &msg)
{
if (!debugInterfacePtr.isNull()) {
const QString domain = QStringLiteral("%1:%2, %3")
.arg(QString::fromLatin1(context.file))
.arg(context.line)
.arg(QString::fromLatin1(context.function));
switch (type) {
case QtDebugMsg:
debugInterfacePtr->newDebugMessage(domain, Tp::DebugLevelDebug, msg);
break;
case QtInfoMsg:
debugInterfacePtr->newDebugMessage(domain, Tp::DebugLevelInfo, msg);
break;
case QtWarningMsg:
debugInterfacePtr->newDebugMessage(domain, Tp::DebugLevelWarning, msg);
break;
case QtCriticalMsg:
debugInterfacePtr->newDebugMessage(domain, Tp::DebugLevelCritical, msg);
break;
case QtFatalMsg:
debugInterfacePtr->newDebugMessage(domain, Tp::DebugLevelError, msg);
break;
}
}
if (defaultMessageHandler) {
defaultMessageHandler(type, context, msg);
return;
}
const QString logMessage = qFormatLogMessage(type, context, msg);
if (logMessage.isNull()) {
return;
}
fprintf(stderr, "%s\n", logMessage.toLocal8Bit().constData());
fflush(stderr);
}
bool enableDebugInterface()
{
if (!debugInterfacePtr.isNull()) {
return debugInterfacePtr->isRegistered();
}
debugInterfacePtr = new Tp::BaseDebug();
debugInterfacePtr->setGetMessagesLimit(-1);
if (!debugInterfacePtr->registerObject(TP_QT_CONNECTION_MANAGER_BUS_NAME_BASE
+ QLatin1String("example"))) {
return false;
}
defaultMessageHandler = qInstallMessageHandler(telepathyDebugHandler);
return true;
}
void disableDebugInterface()
{
if (debugInterfacePtr.isNull()) {
return;
}
qInstallMessageHandler(defaultMessageHandler);
debugInterfacePtr->deleteLater();
debugInterfacePtr.clear();
defaultMessageHandler = nullptr;
}