diff --git a/src/common/database/Database.h b/src/common/database/Database.h --- a/src/common/database/Database.h +++ b/src/common/database/Database.h @@ -68,7 +68,7 @@ }; #define DATABASE_TRANSACTION(A) \ - /* enable this for debugging only: qDebug() << "Location:" << __FILE__ << __LINE__; */ \ + /* enable this for debugging only: qCDebug(KAMD_LOG_RESOURCES) << "Location:" << __FILE__ << __LINE__; */ \ Common::Database::Locker lock(A) private: diff --git a/src/common/database/Database.cpp b/src/common/database/Database.cpp --- a/src/common/database/Database.cpp +++ b/src/common/database/Database.cpp @@ -35,6 +35,8 @@ #include #include +#include "Debug.h" + namespace Common { namespace { @@ -92,10 +94,10 @@ m_open = m_database.open(); if (!m_open) { - qWarning() << "KActivities: Database is not open: " - << m_database.connectionName() - << m_database.databaseName() - << m_database.lastError(); + qCWarning(KAMD_LOG_RESOURCES) << "KActivities: Database is not open: " + << m_database.connectionName() + << m_database.databaseName() + << m_database.lastError(); if (info.openMode == Database::ReadWrite) { qFatal("KActivities: Opening the database in RW mode should always succeed"); @@ -105,7 +107,7 @@ ~QSqlDatabaseWrapper() { - qDebug() << "Closing SQL connection: " << m_connectionName; + qCDebug(KAMD_LOG_RESOURCES) << "Closing SQL connection: " << m_connectionName; } QSqlDatabase &get() @@ -202,17 +204,17 @@ auto walResult = ptr->pragma(QStringLiteral("journal_mode = WAL")); if (walResult != "wal") { - qWarning() << "KActivities: Database can not be opened in WAL mode. Check the " - "SQLite version (required >3.7.0). And whether your filesystem " - "supports shared memory"; + qCWarning(KAMD_LOG_RESOURCES) << "KActivities: Database can not be opened in WAL mode. Check the " + "SQLite version (required >3.7.0). And whether your filesystem " + "supports shared memory"; return nullptr; } // We don't have a big database, lets flush the WAL when // it reaches 400k, not 4M as is default ptr->setPragma(QStringLiteral("wal_autocheckpoint = 100")); - qDebug() << "KActivities: Database connection: " << ptr->d->database->connectionName() + qCDebug(KAMD_LOG_RESOURCES) << "KActivities: Database connection: " << ptr->d->database->connectionName() << "\n query_only: " << ptr->pragma(QStringLiteral("query_only")) << "\n journal_mode: " << ptr->pragma(QStringLiteral("journal_mode")) << "\n wal_autocheckpoint: " << ptr->pragma(QStringLiteral("wal_autocheckpoint")) @@ -253,7 +255,7 @@ lastExecutedQuery = query; if (!ignoreErrors && result.lastError().isValid()) { - qWarning() << "SQL: " + qCWarning(KAMD_LOG_RESOURCES) << "SQL: " << "\n error: " << result.lastError() << "\n query: " << query; } diff --git a/src/service/Activities.cpp b/src/service/Activities.cpp --- a/src/service/Activities.cpp +++ b/src/service/Activities.cpp @@ -138,7 +138,7 @@ // configuration file is in a big problem and told us there // are no running activities, and enlists all of them as stopped. // In that case, we will pretend all of them are running - qWarning() << "The config file enlisted all activities as stopped"; + qCWarning(KAMD_LOG_ACTIVITIES) << "The config file enlisted all activities as stopped"; for (const auto &keys: activities.keys()) { activities[keys] = Activities::Running; } @@ -436,7 +436,7 @@ // Initializing config - qDebug() << "Config timer connecting..."; + qCDebug(KAMD_LOG_ACTIVITIES) << "Config timer connecting..."; d->connect(&d->configSyncTimer, SIGNAL(timeout()), SLOT(configSync()), Qt::QueuedConnection); diff --git a/src/service/Application.cpp b/src/service/Application.cpp --- a/src/service/Application.cpp +++ b/src/service/Application.cpp @@ -237,7 +237,7 @@ Application::~Application() { - qDebug() << "Cleaning up..."; + qCDebug(KAMD_LOG_APPLICATION) << "Cleaning up..."; // Waiting for the threads to finish for (const auto thread : s_moduleThreads) { diff --git a/src/service/Plugin.cpp b/src/service/Plugin.cpp --- a/src/service/Plugin.cpp +++ b/src/service/Plugin.cpp @@ -55,7 +55,7 @@ KConfigGroup Plugin::config() const { if (d->name.isEmpty()) { - qWarning() << "The plugin needs a name in order to have a config section"; + qCWarning(KAMD_LOG_APPLICATION) << "The plugin needs a name in order to have a config section"; return KConfigGroup(); } @@ -71,7 +71,7 @@ Q_ASSERT_X(d->name.isEmpty(), "Plugin::setName", "The name can not be set twice"); Q_ASSERT_X(!name.isEmpty(), "Plugin::setName", "The name can not be empty"); - qDebug() << "Setting the name of " << (void*)this << " to " << name; + qCDebug(KAMD_LOG_APPLICATION) << "Setting the name of " << (void*)this << " to " << name; d->name = name; } diff --git a/src/service/ksmserver/KSMServer.cpp b/src/service/ksmserver/KSMServer.cpp --- a/src/service/ksmserver/KSMServer.cpp +++ b/src/service/ksmserver/KSMServer.cpp @@ -152,7 +152,7 @@ void KSMServer::Private::makeRunning(bool value) { if (!kwin) { - qDebug() << "Activities KSM: No kwin, marking activity as: " << value; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: No kwin, marking activity as: " << value; subSessionSendEvent(value ? KSMServer::Started : KSMServer::Stopped); return; } @@ -163,7 +163,7 @@ const auto watcher = new QDBusPendingCallWatcher(call, this); - qDebug() << "Activities KSM: Telling kwin to start/stop activity : " << processingActivity << value; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Telling kwin to start/stop activity : " << processingActivity << value; QObject::connect( watcher, SIGNAL(finished(QDBusPendingCallWatcher *)), this, @@ -174,23 +174,23 @@ void KSMServer::Private::startCallFinished(QDBusPendingCallWatcher *call) { - qDebug() << "Activities KSM: Start call is finished"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Start call is finished"; QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "Activities KSM: Error in getting a reply for start, marking as started"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error in getting a reply for start, marking as started"; subSessionSendEvent(KSMServer::Started); } else { // If we got false, it means something is going on with ksmserver // and it didn't start our activity const auto retval = reply.argumentAt<0>(); if (!retval) { - qDebug() << "Activities KSM: Error starting, marking as stopped"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error starting, marking as stopped"; subSessionSendEvent(KSMServer::Stopped); } else { - qDebug() << "Activities KSM: All OK starting, marking as starting"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: All OK starting, marking as starting"; subSessionSendEvent(KSMServer::Started); } } @@ -200,23 +200,23 @@ void KSMServer::Private::stopCallFinished(QDBusPendingCallWatcher *call) { - qDebug() << "Activities KSM: Stop call is finished"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Stop call is finished"; QDBusPendingReply reply = *call; if (reply.isError()) { - qDebug() << "Activities KSM: Error in getting a reply for stop, marking as stopped"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error in getting a reply for stop, marking as stopped"; subSessionSendEvent(KSMServer::Stopped); } else { // If we got false, it means something is going on with ksmserver // and it didn't stop our activity const auto retval = reply.argumentAt<0>(); if (!retval) { - qDebug() << "Activities KSM: Error stopping, marking as started"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: Error stopping, marking as started"; subSessionSendEvent(KSMServer::FailedToStop); } else { - qDebug() << "Activities KSM: All OK stopping, marking as stopped"; + qCDebug(KAMD_LOG_ACTIVITIES) << "Activities KSM: All OK stopping, marking as stopped"; subSessionSendEvent(KSMServer::Stopped); } } diff --git a/src/service/plugins/runapplication/CMakeLists.txt b/src/service/plugins/runapplication/CMakeLists.txt --- a/src/service/plugins/runapplication/CMakeLists.txt +++ b/src/service/plugins/runapplication/CMakeLists.txt @@ -14,6 +14,7 @@ set ( runapplication_SRCS RunApplicationPlugin.cpp + ${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/service/Debug.cpp ${plugin_implementation_SRCS} ) diff --git a/src/service/plugins/runapplication/RunApplicationPlugin.cpp b/src/service/plugins/runapplication/RunApplicationPlugin.cpp --- a/src/service/plugins/runapplication/RunApplicationPlugin.cpp +++ b/src/service/plugins/runapplication/RunApplicationPlugin.cpp @@ -119,10 +119,10 @@ QString filePath = directory.filePath(item); KService service(filePath); if (service.isValid() && service.isApplication()) { - qDebug() << "Starting: " << service.exec(); + qCDebug(KAMD_LOG_APPLICATION) << "Starting: " << service.exec(); QProcess::startDetached(service.exec()); } else { - qDebug() << "Openning file: " << QUrl::fromLocalFile(filePath); + qCDebug(KAMD_LOG_APPLICATION) << "Openning file: " << QUrl::fromLocalFile(filePath); QDesktopServices::openUrl(QUrl::fromLocalFile(filePath)); } } diff --git a/src/service/plugins/sqlite/CMakeLists.txt b/src/service/plugins/sqlite/CMakeLists.txt --- a/src/service/plugins/sqlite/CMakeLists.txt +++ b/src/service/plugins/sqlite/CMakeLists.txt @@ -10,6 +10,7 @@ ResourceScoreMaintainer.cpp ResourceLinking.cpp + ${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/service/Debug.cpp ${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/common/database/Database.cpp ${KACTIVITIES_CURRENT_ROOT_SOURCE_DIR}/src/common/database/schema/ResourcesDatabaseSchema.cpp diff --git a/src/service/plugins/sqlite/Database.cpp b/src/service/plugins/sqlite/Database.cpp --- a/src/service/plugins/sqlite/Database.cpp +++ b/src/service/plugins/sqlite/Database.cpp @@ -65,11 +65,11 @@ = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kactivitymanagerd/resources/"); - qDebug() << "Creating directory: " << databaseDir; + qCDebug(KAMD_LOG_RESOURCES) << "Creating directory: " << databaseDir; auto created = QDir().mkpath(databaseDir); if (!created || !QDir(databaseDir).exists()) { - qWarning() << "Database folder can not be created!"; + qCWarning(KAMD_LOG_RESOURCES) << "Database folder can not be created!"; } d->database = Common::Database::instance( diff --git a/src/service/plugins/sqlite/ResourceLinking.cpp b/src/service/plugins/sqlite/ResourceLinking.cpp --- a/src/service/plugins/sqlite/ResourceLinking.cpp +++ b/src/service/plugins/sqlite/ResourceLinking.cpp @@ -65,11 +65,11 @@ QString targettedResource, QString usedActivity) { - qDebug() << "Linking " << targettedResource << " to " << usedActivity << " from " << initiatingAgent; + qCDebug(KAMD_LOG_RESOURCES) << "Linking " << targettedResource << " to " << usedActivity << " from " << initiatingAgent; if (!validateArguments(initiatingAgent, targettedResource, usedActivity)) { - qWarning() << "Invalid arguments" << initiatingAgent - << targettedResource << usedActivity; + qCWarning(KAMD_LOG_RESOURCES) << "Invalid arguments" << initiatingAgent + << targettedResource << usedActivity; return; } @@ -107,12 +107,12 @@ ); if (!usedActivity.isEmpty()) { - // qDebug() << "Sending link event added: activities:/" << usedActivity; + // qCDebug(KAMD_LOG_RESOURCES) << "Sending link event added: activities:/" << usedActivity; org::kde::KDirNotify::emitFilesAdded(QUrl(QStringLiteral("activities:/") + usedActivity)); if (usedActivity == StatsPlugin::self()->currentActivity()) { - // qDebug() << "Sending link event added: activities:/current"; + // qCDebug(KAMD_LOG_RESOURCES) << "Sending link event added: activities:/current"; org::kde::KDirNotify::emitFilesAdded( QUrl(QStringLiteral("activities:/current"))); } @@ -126,11 +126,11 @@ QString targettedResource, QString usedActivity) { - // qDebug() << "Unlinking " << targettedResource << " from " << usedActivity << " from " << initiatingAgent; + // qCDebug(KAMD_LOG_RESOURCES) << "Unlinking " << targettedResource << " from " << usedActivity << " from " << initiatingAgent; if (!validateArguments(initiatingAgent, targettedResource, usedActivity)) { - qWarning() << "Invalid arguments" << initiatingAgent - << targettedResource << usedActivity; + qCWarning(KAMD_LOG_RESOURCES) << "Invalid arguments" << initiatingAgent + << targettedResource << usedActivity; return; } @@ -180,12 +180,12 @@ auto mangled = QString::fromLatin1(targettedResource.toUtf8().toBase64( QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)); - // qDebug() << "Sending link event removed: activities:/" << usedActivity << '/' << mangled; + // qCDebug(KAMD_LOG_RESOURCES) << "Sending link event removed: activities:/" << usedActivity << '/' << mangled; org::kde::KDirNotify::emitFilesRemoved( { QUrl(QStringLiteral("activities:/") + usedActivity + '/' + mangled) }); if (usedActivity == StatsPlugin::self()->currentActivity()) { - // qDebug() << "Sending link event removed: activities:/current/" << mangled; + // qCDebug(KAMD_LOG_RESOURCES) << "Sending link event removed: activities:/current/" << mangled; org::kde::KDirNotify::emitFilesRemoved({ QUrl(QStringLiteral("activities:/current/") + mangled) }); } @@ -237,7 +237,7 @@ { // Validating targetted resource if (targettedResource.isEmpty()) { - qDebug() << "Resource is invalid -- empty"; + qCDebug(KAMD_LOG_RESOURCES) << "Resource is invalid -- empty"; return false; } @@ -249,7 +249,7 @@ QFileInfo file(targettedResource); if (!file.exists()) { - qDebug() << "Resource is invalid -- the file does not exist"; + qCDebug(KAMD_LOG_RESOURCES) << "Resource is invalid -- the file does not exist"; return false; } @@ -275,13 +275,13 @@ && usedActivity != ":global" && usedActivity != ":any" && !StatsPlugin::self()->listActivities().contains(usedActivity)) { - qDebug() << "Activity is invalid, it does not exist"; + qCDebug(KAMD_LOG_RESOURCES) << "Activity is invalid, it does not exist"; return false; } - // qDebug() << "agent" << initiatingAgent - // << "resource" << targettedResource - // << "activity" << usedActivity; + // qCDebug(KAMD_LOG_RESOURCES) << "agent" << initiatingAgent + // << "resource" << targettedResource + // << "activity" << usedActivity; return true; } @@ -291,14 +291,14 @@ Q_UNUSED(activity); // Notify KIO - // qDebug() << "Added: activities:/ (" << activity << ")"; + // qCDebug(KAMD_LOG_RESOURCES) << "Added: activities:/ (" << activity << ")"; org::kde::KDirNotify::emitFilesAdded(QUrl(QStringLiteral("activities:/"))); } void ResourceLinking::onActivityRemoved(const QString &activity) { // Notify KIO - // qDebug() << "Removed: activities:/" << activity; + // qCDebug(KAMD_LOG_RESOURCES) << "Removed: activities:/" << activity; org::kde::KDirNotify::emitFilesRemoved( { QUrl(QStringLiteral("activities:/") + activity) }); @@ -310,7 +310,7 @@ Q_UNUSED(activity); // Notify KIO - // qDebug() << "Changed: activities:/current -> " << activity; + // qCDebug(KAMD_LOG_RESOURCES) << "Changed: activities:/current -> " << activity; org::kde::KDirNotify::emitFilesAdded( { QUrl(QStringLiteral("activities:/current")) }); } diff --git a/src/service/plugins/sqlite/ResourceScoreCache.cpp b/src/service/plugins/sqlite/ResourceScoreCache.cpp --- a/src/service/plugins/sqlite/ResourceScoreCache.cpp +++ b/src/service/plugins/sqlite/ResourceScoreCache.cpp @@ -155,7 +155,7 @@ DATABASE_TRANSACTION(*resourcesDatabase()); - qDebug() << "Creating the cache for: " << d->resource; + qCDebug(KAMD_LOG_RESOURCES) << "Creating the cache for: " << d->resource; // This can fail if we have the cache already made auto isCacheNew = Utils::exec( @@ -180,9 +180,9 @@ lastUpdate.setTime_t(result["lastUpdate"].toUInt()); firstUpdate.setTime_t(result["firstUpdate"].toUInt()); - qDebug() << "Already in database? " << (!isCacheNew); - qDebug() << " First update : " << firstUpdate; - qDebug() << " Last update : " << lastUpdate; + qCDebug(KAMD_LOG_RESOURCES) << "Already in database? " << (!isCacheNew); + qCDebug(KAMD_LOG_RESOURCES) << " First update : " << firstUpdate; + qCDebug(KAMD_LOG_RESOURCES) << " Last update : " << lastUpdate; if (isCacheNew) { // If we haven't had the cache before, set the score to 0 @@ -200,10 +200,10 @@ // Calculating the updated score // We are processing all events since the last cache update - qDebug() << "After the adjustment"; - qDebug() << " Current score : " << score; - qDebug() << " First update : " << firstUpdate; - qDebug() << " Last update : " << lastUpdate; + qCDebug(KAMD_LOG_RESOURCES) << "After the adjustment"; + qCDebug(KAMD_LOG_RESOURCES) << " Current score : " << score; + qCDebug(KAMD_LOG_RESOURCES) << " First update : " << firstUpdate; + qCDebug(KAMD_LOG_RESOURCES) << " Last update : " << lastUpdate; Utils::exec(Utils::FailOnError, Queries::self().getScoreAdditionQuery, ":usedActivity", d->activity, @@ -220,7 +220,7 @@ const auto end = result["end"].toUInt(); const auto intervalLength = end - lastEventStart; - qDebug() << "Interval length is " << intervalLength; + qCDebug(KAMD_LOG_RESOURCES) << "Interval length is " << intervalLength; if (intervalLength == 0) { // We have an Accessed event - otherwise, this wouldn't be 0 @@ -232,7 +232,7 @@ } } - qDebug() << " New score : " << score; + qCDebug(KAMD_LOG_RESOURCES) << " New score : " << score; // Updating the score @@ -245,10 +245,10 @@ ); // Notifying the world - qDebug() << "ResourceScoreUpdated:" - << d->activity - << d->application - << d->resource + qCDebug(KAMD_LOG_RESOURCES) << "ResourceScoreUpdated:" + << d->activity + << d->application + << d->resource ; emit QMetaObject::invokeMethod(StatsPlugin::self(), "ResourceScoreUpdated", diff --git a/src/service/plugins/sqlite/Utils.h b/src/service/plugins/sqlite/Utils.h --- a/src/service/plugins/sqlite/Utils.h +++ b/src/service/plugins/sqlite/Utils.h @@ -61,8 +61,8 @@ if (eh == FailOnError) { if ((!success) && (errorCount++ < 2)) { - qDebug() << query.lastQuery(); - qDebug() << query.lastError(); + qCDebug(KAMD_LOG_RESOURCES) << query.lastQuery(); + qCDebug(KAMD_LOG_RESOURCES) << query.lastError(); } Q_ASSERT_X(success, "Uils::exec", "Query failed"); } diff --git a/src/utils/continue_with.h b/src/utils/continue_with.h --- a/src/utils/continue_with.h +++ b/src/utils/continue_with.h @@ -40,7 +40,7 @@ inline void test_continuation(const QJSValue &continuation) { if (!continuation.isCallable()) { - qWarning() << "Passed handler is not callable: " << continuation.toString(); + qCWarning(KAMD_LOG_RESOURCES) << "Passed handler is not callable: " << continuation.toString(); } } @@ -50,16 +50,16 @@ { auto result = continuation.call({ future.result() }); if (result.isError()) { - qWarning() << "Handler returned this error: " << result.toString(); + qCWarning(KAMD_LOG_RESOURCES) << "Handler returned this error: " << result.toString(); } } inline void pass_value(const QFuture &future, QJSValue continuation) { Q_UNUSED(future); auto result = continuation.call({}); if (result.isError()) { - qWarning() << "Handler returned this error: " << result.toString(); + qCWarning(KAMD_LOG_RESOURCES) << "Handler returned this error: " << result.toString(); } } #endif diff --git a/src/utils/dbusfuture_p.cpp b/src/utils/dbusfuture_p.cpp --- a/src/utils/dbusfuture_p.cpp +++ b/src/utils/dbusfuture_p.cpp @@ -29,7 +29,7 @@ { deleteLater(); - // qDebug() << "This is call end"; + // qCDebug(KAMD_LOG_RESOURCES) << "This is call end"; this->reportFinished(); } diff --git a/src/utils/debug_and_return.h b/src/utils/debug_and_return.h --- a/src/utils/debug_and_return.h +++ b/src/utils/debug_and_return.h @@ -31,7 +31,7 @@ template T debug_and_return(const char * message, T && value) { #ifdef QT_DEBUG - qDebug() << message << " " << value; + qCDebug(KAMD_LOG_RESOURCES) << message << " " << value; #endif return std::forward(value); @@ -41,7 +41,7 @@ T debug_and_return(bool debug, const char * message, T && value) { #ifdef QT_DEBUG if (debug) { - qDebug() << message << " " << value; + qCDebug(KAMD_LOG_RESOURCES) << message << " " << value; } #endif