File indexing completed on 2023-10-01 08:41:44

0001 /*
0002 * Copyright (C) 2011, 2012 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
0003 *
0004 * This library is free software; you can redistribute it and/or
0005 * modify it under the terms of the GNU Lesser General Public
0006 * License as published by the Free Software Foundation; either
0007 * version 2.1 of the License, or (at your option) any later version.
0008 *
0009 * This library is distributed in the hope that it will be useful,
0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012 * Lesser General Public License for more details.
0013 *
0014 * You should have received a copy of the GNU Lesser General Public
0015 * License along with this library; if not, write to the Free Software
0016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0017 */
0018 
0019 #include "debug.h"
0020 
0021 #include <TelepathyQt/Debug>
0022 #include <QLoggingCategory>
0023 
0024 Q_DECLARE_LOGGING_CATEGORY(TELEPATHY_QT)
0025 
0026 namespace KTp
0027 {
0028 
0029 namespace {
0030 QString libraryString;
0031 
0032 static void tpDebugCallback(const QString &libraryName,
0033                             const QString &libraryVersion,
0034                             QtMsgType type,
0035                             const QString &msg)
0036 {
0037     if (Q_UNLIKELY(libraryString.isEmpty())) {
0038         libraryString = QString::fromLatin1("%1:%2()").arg(libraryName, libraryVersion);
0039     }
0040     qCDebug(TELEPATHY_QT) << libraryString << qPrintable(msg);
0041 }
0042 } // namespace
0043 } // namespace KTp
0044 
0045 void KTp::Debug::installCallback(bool debug, bool warning)
0046 {
0047     // Redirect Tp debug and warnings to KDebug output
0048     Tp::setDebugCallback(&tpDebugCallback);
0049 
0050     // Enable telepathy-Qt4 debug
0051     Tp::enableDebug(debug);
0052     Tp::enableWarnings(warning);
0053 }
0054 
0055 Q_LOGGING_CATEGORY(KTP_COMMONINTERNALS, "ktp-common-internals")
0056 Q_LOGGING_CATEGORY(TELEPATHY_QT, "telepathy-qt")