Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9229ddbb authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Replace ImapResource's Tracer with custom QLoggingCategory

parent 1b46756f
......@@ -42,7 +42,6 @@ set( imapresource_LIB_SRCS
resourcestate.cpp
collectionmetadatahelper.cpp
replacemessagejob.cpp
tracer.cpp
utils.cpp
${AKONADI_COLLECTIONATTRIBUTES_SHARED_SOURCES}
${AKONADI_IMAPATTRIBUTES_SHARED_SOURCES}
......@@ -50,6 +49,12 @@ set( imapresource_LIB_SRCS
ecm_qt_declare_logging_category(imapresource_LIB_SRCS HEADER imapresource_debug.h IDENTIFIER IMAPRESOURCE_LOG CATEGORY_NAME org.kde.pim.imapresource)
ecm_qt_declare_logging_category(imapresource_LIB_SRCS HEADER imapresource_trace.h
IDENTIFIER IMAPRESOURCE_TRACE
CATEGORY_NAME org.kde.pim.imapresource.trace
DEFAULT_SEVERITY Debug
)
kcfg_generate_dbus_interface( ${CMAKE_CURRENT_SOURCE_DIR}/imapresource.kcfg org.kde.Akonadi.Imap.Settings )
kconfig_add_kcfg_files(imapresource_LIB_SRCS settingsbase.kcfgc)
......
......@@ -29,7 +29,6 @@
#include "settings.h"
#include "sessionpool.h"
#include "sessionuiproxy.h"
#include "tracer.h"
#include "utils.h"
#include "config-imap.h"
......
......@@ -25,13 +25,13 @@
#include <KLocalizedString>
#include "imapresource_debug.h"
#include "imapresource_trace.h"
#include "collectionflagsattribute.h"
#include <imapaclattribute.h>
#include "imapflags.h"
#include "sessionpool.h"
#include "resourcestateinterface.h"
#include "tracer.h"
ResourceTask::ResourceTask(ActionIfNoSession action, ResourceStateInterface::Ptr resource, QObject *parent)
: QObject(parent)
......@@ -58,7 +58,7 @@ ResourceTask::~ResourceTask()
void ResourceTask::start(SessionPool *pool)
{
Trace() << metaObject()->className();
qCDebug(IMAPRESOURCE_TRACE) << metaObject()->className();
m_pool = pool;
connect(m_pool, &SessionPool::sessionRequestDone,
this, &ResourceTask::onSessionRequested);
......@@ -117,7 +117,7 @@ void ResourceTask::onSessionRequested(qint64 requestId, KIMAP::Session *session,
m_session = session;
if (errorCode != SessionPool::NoError) {
Trace() << "Error on: " << metaObject()->className();
qCDebug(IMAPRESOURCE_TRACE) << "Error on: " << metaObject()->className();
switch (m_actionIfNoSession) {
case CancelIfNoSession:
qCDebug(IMAPRESOURCE_LOG) << "Cancelling this request. Probably there is no more session available.";
......@@ -141,7 +141,7 @@ void ResourceTask::onSessionRequested(qint64 requestId, KIMAP::Session *session,
connect(m_pool, &SessionPool::disconnectDone,
this, &ResourceTask::onPoolDisconnect);
Trace() << "starting: " << metaObject()->className();
qCDebug(IMAPRESOURCE_TRACE) << "starting: " << metaObject()->className();
doStart(m_session);
}
......@@ -152,7 +152,7 @@ void ResourceTask::onConnectionLost(KIMAP::Session *session)
// the pointer, we don't need to release it once the
// task is done
m_session = nullptr;
Trace() << metaObject()->className();
qCDebug(IMAPRESOURCE_TRACE) << metaObject()->className();
cancelTask(i18n("Connection lost"));
}
}
......@@ -164,7 +164,7 @@ void ResourceTask::onPoolDisconnect()
// release our session anymore
m_pool = nullptr;
Trace() << metaObject()->className();
qCDebug(IMAPRESOURCE_TRACE) << metaObject()->className();
cancelTask(i18n("Connection lost"));
}
......@@ -514,8 +514,7 @@ QList<QByteArray> ResourceTask::toAkonadiFlags(const QList<QByteArray> &flags)
void ResourceTask::kill()
{
Trace() << metaObject()->className();
qCDebug(IMAPRESOURCE_LOG);
qCDebug(IMAPRESOURCE_TRACE) << metaObject()->className();
cancelTask(i18n("killed"));
}
......
#include "tracer.h"
#include "imapresource_debug.h"
#include <QString>
#include <QIODevice>
#include <QCoreApplication>
#include <iostream>
class DebugStream : public QIODevice
{
public:
QString m_location;
DebugStream()
: QIODevice()
{
open(WriteOnly);
}
virtual ~DebugStream()
{
}
bool isSequential() const override
{
return true;
}
qint64 readData(char *, qint64) override
{
return 0; /* eof */
}
qint64 readLineData(char *, qint64) override
{
return 0; /* eof */
}
qint64 writeData(const char *data, qint64 len) override
{
const QByteArray buf = QByteArray::fromRawData(data, len);
if (!qEnvironmentVariableIsEmpty("IMAP_TRACE")) {
// qt_message_output(QtDebugMsg, buf.trimmed().constData());
std::cout << buf.trimmed().constData() << std::endl;
}
return len;
}
private:
Q_DISABLE_COPY(DebugStream)
};
QDebug debugStream(int line, const char *file, const char *function)
{
static DebugStream stream;
QDebug debug(&stream);
static QByteArray programName;
if (programName.isEmpty()) {
if (QCoreApplication::instance()) {
programName = QCoreApplication::instance()->applicationName().toLocal8Bit();
} else {
programName = "<unknown program name>";
}
}
Q_UNUSED(line);
Q_UNUSED(file);
debug << QStringLiteral("Trace:%1(%2) %3:").arg(QString::fromLatin1(programName)).arg(unsigned(QCoreApplication::applicationPid())).arg(QLatin1String(function)) /* << file << ":" << line */;
return debug;
}
#pragma once
#include "imapresource_debug.h"
QDebug debugStream(int line, const char *file, const char *function);
#define Trace() debugStream(__LINE__, __FILE__, Q_FUNC_INFO)
......@@ -35,7 +35,17 @@ set(kolabresource_SRCS
updatemessagejob.cpp
)
ecm_qt_declare_logging_category(kolabresource_SRCS HEADER kolabresource_debug.h IDENTIFIER KOLABRESOURCE_LOG CATEGORY_NAME org.kde.pim.kolabresource)
ecm_qt_declare_logging_category(kolabresource_SRCS
HEADER kolabresource_debug.h
IDENTIFIER KOLABRESOURCE_LOG
CATEGORY_NAME org.kde.pim.kolabresource
)
ecm_qt_declare_logging_category(kolabresource_SRCS
HEADER kolabresource_trace.h
IDENTIFIER KOLABRESOURCE_TRACE
CATEGORY_NAME org.kde.pim.kolamresource.trace
DEFAULT_SEVERITY Debug
)
kconfig_add_kcfg_files(kolabresource_SRCS ../imap/settingsbase.kcfgc)
......
......@@ -21,6 +21,7 @@
#include "kolabchangeitemsrelationstask.h"
#include "kolabresource_debug.h"
#include "kolabresource_trace.h"
#include <imapflags.h>
#include "pimkolab/kolabformat/kolabobject.h"
......@@ -34,7 +35,6 @@
#include <AkonadiCore/ItemFetchJob>
#include <AkonadiCore/ItemFetchScope>
#include "tracer.h"
#include "kolabhelpers.h"
KolabChangeItemsRelationsTask::KolabChangeItemsRelationsTask(const ResourceStateInterface::Ptr &resource, QObject *parent)
......@@ -46,7 +46,7 @@ KolabChangeItemsRelationsTask::KolabChangeItemsRelationsTask(const ResourceState
void KolabChangeItemsRelationsTask::startRelationTask(KIMAP::Session *session)
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
mSession = session;
mAddedRelations = resourceState()->addedRelations();
mRemovedRelations = resourceState()->removedRelations();
......@@ -56,7 +56,7 @@ void KolabChangeItemsRelationsTask::startRelationTask(KIMAP::Session *session)
void KolabChangeItemsRelationsTask::processNextRelation()
{
Trace() << mAddedRelations.size() << mRemovedRelations.size();
qCDebug(KOLABRESOURCE_TRACE) << mAddedRelations.size() << mRemovedRelations.size();
Akonadi::Relation relation;
if (!mAddedRelations.isEmpty()) {
relation = mAddedRelations.takeFirst();
......@@ -65,11 +65,11 @@ void KolabChangeItemsRelationsTask::processNextRelation()
relation = mRemovedRelations.takeFirst();
mAdding = false;
} else {
Trace() << "Processing done";
qCDebug(KOLABRESOURCE_TRACE) << "Processing done";
changeProcessed();
return;
}
Trace() << "Processing " << (mAdding ? " add " : " remove ") << relation;
qCDebug(KOLABRESOURCE_TRACE) << "Processing " << (mAdding ? " add " : " remove ") << relation;
//We have to fetch it again in case it changed since the notification was emitted (which is likely)
//Otherwise we get an empty remoteid for new tags that were immediately applied on an item
......@@ -79,7 +79,7 @@ void KolabChangeItemsRelationsTask::processNextRelation()
void KolabChangeItemsRelationsTask::onRelationFetchDone(KJob *job)
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
if (job->error()) {
qCWarning(KOLABRESOURCE_LOG) << "RelatonFetch failed: " << job->errorString();
processNextRelation();
......@@ -154,7 +154,7 @@ void KolabChangeItemsRelationsTask::onItemsFetched(KJob *job)
void KolabChangeItemsRelationsTask::removeRelation(const Akonadi::Relation &relation)
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
mCurrentRelation = relation;
const QString mailBox = mailBoxForCollection(relationCollection());
......@@ -185,7 +185,7 @@ void KolabChangeItemsRelationsTask::triggerStoreJob()
KIMAP::ImapSet set;
set.add(mCurrentRelation.remoteId().toLong());
Trace() << set.toImapSequenceSet();
qCDebug(KOLABRESOURCE_TRACE) << set.toImapSequenceSet();
KIMAP::StoreJob *store = new KIMAP::StoreJob(mSession);
store->setUidBased(true);
......
......@@ -19,6 +19,7 @@
#include "kolabhelpers.h"
#include "kolabresource_debug.h"
#include "kolabresource_trace.h"
#include <KMime/KMimeMessage>
#include <KCalCore/Incidence>
#include <AkonadiCore/Collection>
......@@ -29,7 +30,6 @@
#include "pimkolab/kolabformat/errorhandler.h"
#include <KLocalizedString>
#include <QColor>
#include "tracer.h"
bool KolabHelpers::checkForErrors(const Akonadi::Item &item)
{
......@@ -515,7 +515,7 @@ QList<QByteArray> KolabHelpers::ancestorChain(const Akonadi::Collection &col)
QString KolabHelpers::createMemberUrl(const Akonadi::Item &item, const QString &user)
{
Trace() << item.id() << item.mimeType() << item.gid() << item.hasPayload();
qCDebug(KOLABRESOURCE_TRACE) << item.id() << item.mimeType() << item.gid() << item.hasPayload();
Kolab::RelationMember member;
if (item.mimeType() == KMime::Message::mimeType()) {
if (!item.hasPayload<KMime::Message::Ptr>()) {
......
......@@ -21,12 +21,12 @@
#include "kolabremovetagtask.h"
#include "kolabresource_debug.h"
#include "kolabresource_trace.h"
#include <imapflags.h>
#include <kimap/selectjob.h>
#include <kimap/session.h>
#include <kimap/storejob.h>
#include "tracer.h"
KolabRemoveTagTask::KolabRemoveTagTask(const ResourceStateInterface::Ptr &resource, QObject *parent)
: KolabRelationResourceTask(resource, parent)
......@@ -41,7 +41,6 @@ void KolabRemoveTagTask::startRelationTask(KIMAP::Session *session)
const QString mailBox = mailBoxForCollection(relationCollection());
Trace() << mailBox;
qCDebug(KOLABRESOURCE_LOG) << "Deleting tag " << resourceState()->tag().name() << " from " << mailBox;
if (session->selectedMailBox() != mailBox) {
......@@ -61,7 +60,7 @@ void KolabRemoveTagTask::triggerStoreJob(KIMAP::Session *session)
{
KIMAP::ImapSet set;
set.add(resourceState()->tag().remoteId().toLong());
Trace() << set.toImapSequenceSet();
qCDebug(KOLABRESOURCE_TRACE) << set.toImapSequenceSet();
KIMAP::StoreJob *store = new KIMAP::StoreJob(session);
store->setUidBased(true);
......@@ -85,7 +84,7 @@ void KolabRemoveTagTask::onSelectDone(KJob *job)
void KolabRemoveTagTask::onStoreFlagsDone(KJob *job)
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
//TODO use UID EXPUNGE if available
if (job->error()) {
qCWarning(KOLABRESOURCE_LOG) << "Failed to append flags: " << job->errorString();
......
......@@ -20,6 +20,7 @@
#include "kolabresource.h"
#include "kolabresource_debug.h"
#include "kolabresource_trace.h"
#include "setupserver.h"
#include "sessionpool.h"
#include "sessionuiproxy.h"
......@@ -48,7 +49,6 @@
#include "kolabremovetagtask.h"
#include "kolabretrievecollectionstask.h"
#include "kolabretrievetagstask.h"
#include "tracer.h"
KolabResource::KolabResource(const QString &id)
: ImapResourceBase(id)
......@@ -128,7 +128,7 @@ ResourceStateInterface::Ptr KolabResource::createResourceState(const TaskArgumen
void KolabResource::retrieveCollections()
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
Q_EMIT status(AgentBase::Running, i18nc("@info:status", "Retrieving folders"));
startTask(new KolabRetrieveCollectionsTask(createResourceState(TaskArguments()), this));
......@@ -138,7 +138,7 @@ void KolabResource::retrieveCollections()
void KolabResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collection &collection)
{
Trace() << item.id() << collection.id();
qCDebug(KOLABRESOURCE_TRACE) << item.id() << collection.id();
bool ok = true;
const Akonadi::Item imapItem = KolabHelpers::translateToImap(item, ok);
if (!ok) {
......@@ -151,7 +151,7 @@ void KolabResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collecti
void KolabResource::itemChanged(const Akonadi::Item &item, const QSet< QByteArray > &parts)
{
Trace() << item.id() << parts;
qCDebug(KOLABRESOURCE_TRACE) << item.id() << parts;
bool ok = true;
const Akonadi::Item imapItem = KolabHelpers::translateToImap(item, ok);
if (!ok) {
......@@ -164,7 +164,7 @@ void KolabResource::itemChanged(const Akonadi::Item &item, const QSet< QByteArra
void KolabResource::itemsMoved(const Akonadi::Item::List &items, const Akonadi::Collection &source, const Akonadi::Collection &destination)
{
Trace() << items.size() << source.id() << destination.id();
qCDebug(KOLABRESOURCE_TRACE) << items.size() << source.id() << destination.id();
bool ok = true;
const Akonadi::Item::List imapItems = KolabHelpers::translateToImap(items, ok);
if (!ok) {
......@@ -177,7 +177,7 @@ void KolabResource::itemsMoved(const Akonadi::Item::List &items, const Akonadi::
static Akonadi::Collection updateAnnotations(const Akonadi::Collection &collection)
{
Trace() << collection.id();
qCDebug(KOLABRESOURCE_TRACE) << collection.id();
//Set the annotations on new folders
const QByteArray kolabType = KolabHelpers::kolabTypeForMimeType(collection.contentMimeTypes());
Akonadi::Collection col = collection;
......@@ -208,7 +208,7 @@ static Akonadi::Collection updateAnnotations(const Akonadi::Collection &collecti
void KolabResource::collectionAdded(const Akonadi::Collection &collection, const Akonadi::Collection &parent)
{
Trace() << collection.id() << parent.id();
qCDebug(KOLABRESOURCE_TRACE) << collection.id() << parent.id();
//Set the annotations on new folders
const Akonadi::Collection col = updateAnnotations(collection);
//TODO we need to save the collections as well if the annotations have changed
......@@ -218,7 +218,7 @@ void KolabResource::collectionAdded(const Akonadi::Collection &collection, const
void KolabResource::collectionChanged(const Akonadi::Collection &collection, const QSet< QByteArray > &parts)
{
Trace() << collection.id() << parts;
qCDebug(KOLABRESOURCE_TRACE) << collection.id() << parts;
QSet<QByteArray> p = parts;
//Update annotations if necessary
//FIXME col ?????
......@@ -236,49 +236,49 @@ void KolabResource::collectionChanged(const Akonadi::Collection &collection, con
void KolabResource::tagAdded(const Akonadi::Tag &tag)
{
Trace() << tag.id();
qCDebug(KOLABRESOURCE_TRACE) << tag.id();
KolabAddTagTask *task = new KolabAddTagTask(createResourceState(TaskArguments(tag)), this);
startTask(task);
}
void KolabResource::tagChanged(const Akonadi::Tag &tag)
{
Trace() << tag.id();
qCDebug(KOLABRESOURCE_TRACE) << tag.id();
KolabChangeTagTask *task = new KolabChangeTagTask(createResourceState(TaskArguments(tag)), QSharedPointer<TagConverter>(new TagConverter), this);
startTask(task);
}
void KolabResource::tagRemoved(const Akonadi::Tag &tag)
{
Trace() << tag.id();
qCDebug(KOLABRESOURCE_TRACE) << tag.id();
KolabRemoveTagTask *task = new KolabRemoveTagTask(createResourceState(TaskArguments(tag)), this);
startTask(task);
}
void KolabResource::itemsTagsChanged(const Akonadi::Item::List &items, const QSet<Akonadi::Tag> &addedTags, const QSet<Akonadi::Tag> &removedTags)
{
Trace() << items.size() << addedTags.size() << removedTags.size();
qCDebug(KOLABRESOURCE_TRACE) << items.size() << addedTags.size() << removedTags.size();
KolabChangeItemsTagsTask *task = new KolabChangeItemsTagsTask(createResourceState(TaskArguments(items, addedTags, removedTags)), QSharedPointer<TagConverter>(new TagConverter), this);
startTask(task);
}
void KolabResource::retrieveTags()
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
KolabRetrieveTagTask *task = new KolabRetrieveTagTask(createResourceState(TaskArguments()), KolabRetrieveTagTask::RetrieveTags, this);
startTask(task);
}
void KolabResource::retrieveRelations()
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
KolabRetrieveTagTask *task = new KolabRetrieveTagTask(createResourceState(TaskArguments()), KolabRetrieveTagTask::RetrieveRelations, this);
startTask(task);
}
void KolabResource::itemsRelationsChanged(const Akonadi::Item::List &items, const Akonadi::Relation::List &addedRelations, const Akonadi::Relation::List &removedRelations)
{
Trace() << items.size() << addedRelations.size() << removedRelations.size();
qCDebug(KOLABRESOURCE_TRACE) << items.size() << addedRelations.size() << removedRelations.size();
KolabChangeItemsRelationsTask *task = new KolabChangeItemsRelationsTask(createResourceState(TaskArguments(items, addedRelations, removedRelations)));
startTask(task);
}
......
......@@ -22,8 +22,9 @@
#include "kolabretrievecollectionstask.h"
#include "kolabhelpers.h"
#include "tracer.h"
#include "kolabresource_debug.h"
#include "kolabresource_trace.h"
#include <noselectattribute.h>
#include <noinferiorsattribute.h>
......@@ -74,7 +75,7 @@ RetrieveMetadataJob::RetrieveMetadataJob(KIMAP::Session *session, const QStringL
void RetrieveMetadataJob::start()
{
Trace();
qCDebug(KOLABRESOURCE_TRACE);
//Fill the map with empty entires so we set the mimetype to mail if no metadata is retrieved
for (const QString &mailbox : qAsConst(mMailboxes)) {
mMetadata.insert(mailbox, QMap<QByteArray, QByteArray>());
......@@ -176,7 +177,7 @@ void RetrieveMetadataJob::onRightsReceived(KJob *job)
void RetrieveMetadataJob::checkDone()
{
if (!mJobs) {
Trace() << "done";
qCDebug(KOLABRESOURCE_TRACE) << "done";
qCDebug(KOLABRESOURCE_LOG) << "done";
emitResult();
}
......@@ -206,7 +207,6 @@ KolabRetrieveCollectionsTask::~KolabRetrieveCollectionsTask()
void KolabRetrieveCollectionsTask::doStart(KIMAP::Session *session)
{
Trace();
qCDebug(KOLABRESOURCE_LOG) << "Starting collection retrieval";
mTime.start();
mSession = session;
......@@ -243,7 +243,7 @@ void KolabRetrieveCollectionsTask::doStart(KIMAP::Session *session)
mMailCollections.insert(QString(), root);
Trace() << "subscription enabled: " << isSubscriptionEnabled();
qCDebug(KOLABRESOURCE_TRACE) << "subscription enabled: " << isSubscriptionEnabled();
//jobs are serialized by the session
if (isSubscriptionEnabled()) {
KIMAP::ListJob *fullListJob = new KIMAP::ListJob(session);
......@@ -410,7 +410,6 @@ void KolabRetrieveCollectionsTask::createCollection(const QString &mailbox, cons
void KolabRetrieveCollectionsTask::onMailBoxesReceiveDone(KJob *job)
{
Trace();
qCDebug(KOLABRESOURCE_LOG) << "All mailboxes received: " << mTime.elapsed();
qCDebug(KOLABRESOURCE_LOG) << "in total: " << mMailCollections.size();
mJobs--;
......@@ -495,7 +494,6 @@ void KolabRetrieveCollectionsTask::applyMetadata(const QHash<QString, QMap<QByte
void KolabRetrieveCollectionsTask::onMetadataRetrieved(KJob *job)
{
Trace();
qCDebug(KOLABRESOURCE_LOG) << mTime.elapsed();
mJobs--;
if (job->error()) {
......@@ -512,7 +510,6 @@ void KolabRetrieveCollectionsTask::onMetadataRetrieved(KJob *job)
void KolabRetrieveCollectionsTask::checkDone()
{
if (!mJobs) {
Trace() << "done " << mMailCollections.size();
collectionsRetrieved(Akonadi::valuesToVector(mMailCollections));
qCDebug(KOLABRESOURCE_LOG) << "done " << mTime.elapsed();
}
......@@ -528,7 +525,6 @@ void KolabRetrieveCollectionsTask::onFullMailBoxesReceived(const QList< KIMAP::M
void KolabRetrieveCollectionsTask::onFullMailBoxesReceiveDone(KJob *job)
{
Trace();
qCDebug(KOLABRESOURCE_LOG) << "received subscribed collections " << mTime.elapsed();
mJobs--;
if (job->error()) {
......
......@@ -19,13 +19,13 @@
#include "kolabretrievetagstask.h"
#include "kolabresource_debug.h"
#include "kolabresource_trace.h"
#include "tagchangehelper.h"
#include <kimap/selectjob.h>
#include <kimap/fetchjob.h>
#include <imapflags.h>
#include "pimkolab/kolabformat/kolabobject.h"
#include "tracer.h"
KolabRetrieveTagTask::KolabRetrieveTagTask(const ResourceStateInterface::Ptr &resource, RetrieveType type, QObject *parent)
: KolabRelationResourceTask(resource, parent)
......@@ -143,7 +143,7 @@ void KolabRetrieveTagTask::extractTag(const Kolab::KolabObjectReader &reader, qi
tag.setRemoteId(QByteArray::number(remoteUid));
mTags << tag;
Trace() << "Extracted tag: " << tag.gid() << " remoteId: " << remoteUid << tag.remoteId();
qCDebug(KOLABRESOURCE_TRACE) << "Extracted tag: " << tag.gid() << " remoteId: " << remoteUid << tag.remoteId();
Akonadi::Item::List members;
const QStringList lstMemberUrl = reader.getTagMembers();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment