7 #include "akremotelog.h" 10 #include <QCoreApplication> 14 #include <QLoggingCategory> 16 #include <QDBusConnection> 17 #include <QDBusInterface> 18 #include <QDBusPendingCallWatcher> 19 #include <QDBusPendingReply> 20 #include <QDBusServiceWatcher> 22 #include <private/instance_p.h> 24 #define AKONADICONSOLE_SERVICE "org.kde.akonadiconsole" 25 #define AKONADICONSOLE_LOGGER_PATH "/logger" 26 #define AKONADICONSOLE_LOGGER_INTERFACE "org.kde.akonadiconsole.logger" 30 class RemoteLogger :
public QObject 34 explicit RemoteLogger()
39 this, &RemoteLogger::deleteLater);
49 this, &RemoteLogger::serviceRegistered);
51 this, &RemoteLogger::serviceUnregistered);
53 mOldHandler = qInstallMessageHandler(dbusLogger);
61 qInstallMessageHandler(mOldHandler);
66 static RemoteLogger *
self()
72 void serviceRegistered(
const QString &service)
74 mAkonadiConsoleInterface = std::make_unique<QDBusInterface>(service,
75 QStringLiteral(AKONADICONSOLE_LOGGER_PATH),
76 QStringLiteral(AKONADICONSOLE_LOGGER_INTERFACE),
78 if (!mAkonadiConsoleInterface->isValid()) {
79 mAkonadiConsoleInterface.reset();
83 connect(mAkonadiConsoleInterface.get(), SIGNAL(enabledChanged(
bool)),
84 this, SLOT(onAkonadiConsoleLoggingEnabled(
bool)));
95 onAkonadiConsoleLoggingEnabled(reply.
argumentAt<0>());
100 void serviceUnregistered(
const QString & )
102 onAkonadiConsoleLoggingEnabled(
false);
103 mAkonadiConsoleInterface.reset();
106 void onAkonadiConsoleLoggingEnabled(
bool enabled)
108 if (mEnabled == enabled) {
123 mOldFilter =
nullptr;
128 QString akonadiConsoleServiceName()
130 QString service = QStringLiteral(AKONADICONSOLE_SERVICE);
131 if (Akonadi::Instance::hasIdentifier()) {
132 service += QStringLiteral(
"-%1").
arg(Akonadi::Instance::identifier());
139 auto *
const that =
self();
144 if (qstrncmp(cat->
categoryName(),
"org.kde.pim.", 12) == 0) {
149 }
else if (that->mOldFilter) {
150 that->mOldFilter(cat);
156 auto *
const that =
self();
162 that->mOldHandler(type, ctx, msg);
164 if (that->mEnabled) {
165 that->mAkonadiConsoleInterface->asyncCallWithArgumentList(
166 QStringLiteral(
"message"),
169 qApp->applicationPid(),
static_cast<int>(type),
178 QtMessageHandler mOldHandler =
nullptr;
179 std::unique_ptr<QDBusInterface> mAkonadiConsoleInterface;
180 bool mEnabled =
false;
182 static RemoteLogger *sInstance;
185 RemoteLogger *RemoteLogger::sInstance =
nullptr;
189 void akInitRemoteLog()
193 if (!RemoteLogger::self()) {
199 #include "akremotelog.moc" void setEnabled(QtMsgType type, bool enable)
void serviceRegistered(const QString &serviceName)
void finished(QDBusPendingCallWatcher *self)
QLoggingCategory::CategoryFilter installFilter(QLoggingCategory::CategoryFilter filter)
QDBusConnection sessionBus()
qint64 currentMSecsSinceEpoch()
QString fromUtf8(const char *str, int size)
void serviceUnregistered(const QString &serviceName)
const char * categoryName() const const
QVariant argumentAt(int index) const const
QThread * currentThread()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString applicationName()
bool isError() const const