Skip to content

Commit d22239b

Browse files
committedMay 13, 2024
Log categorized only when logging category is enabled. Fixes #33
1 parent 67c6e8d commit d22239b

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed
 

‎CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ set(KF_MAJOR_VERSION "6")
1212

1313
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_MODULE_PATH})
1414

15+
include(ECMQtDeclareLoggingCategory)
1516
include(KDEInstallDirs)
1617
include(KDECMakeSettings)
1718
include(KDECompilerSettings)

‎src/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ set(I3PagerPlugin_SRCS
88
workspace.cpp
99
workspace.h)
1010

11+
ecm_qt_declare_logging_category(I3PagerPlugin_SRCS
12+
HEADER i3pager_debug.h
13+
IDENTIFIER I3PAGER
14+
CATEGORY_NAME org.kde.I3Pager
15+
DESCRIPTION "I3Pager Plasmoid"
16+
EXPORT I3Pager
17+
)
18+
1119
add_library(I3PagerPlugin SHARED ${I3PagerPlugin_SRCS})
1220
target_compile_options(I3PagerPlugin PRIVATE -fexceptions)
1321

@@ -31,3 +39,6 @@ target_link_libraries(I3PagerPlugin
3139
# install plugin
3240
install(TARGETS I3PagerPlugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/private/I3Pager)
3341
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/private/I3Pager)
42+
ecm_qt_install_logging_categories(EXPORT I3PAGER
43+
FILE org.kde.i3pager.categories
44+
DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR})

‎src/i3listener.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "i3listener.h"
7+
#include "i3pager_debug.h"
78
#include <QDebug>
89
#include <QLocalSocket>
910
#include <QSocketNotifier>
@@ -28,25 +29,25 @@ void I3ListenerThread::handleI3Events() {
2829

2930
// Workspace events handler
3031
conn.signal_workspace_event.connect([this](const i3ipc::workspace_event_t& ev) {
31-
qDebug() << "workspace_event: " << (char)ev.type;
32+
qCDebug(I3PAGER) << "workspace_event: " << (char)ev.type;
3233
if (ev.current) {
33-
qDebug() << "\tSwitched to #" << ev.current->num << " - \"" << QString::fromStdString(ev.current->name) << '"';
34+
qCDebug(I3PAGER) << "\tSwitched to #" << ev.current->num << " - \"" << QString::fromStdString(ev.current->name) << '"';
3435
Q_EMIT workspacesChanged();
3536
}
3637
});
3738

3839
// Mode events handler
3940
conn.signal_mode_event.connect([this](const i3ipc::mode_t& i3mode) {
4041
const auto mode = QString::fromStdString(i3mode.change);
41-
qDebug() << "mode: " << mode;
42+
qCDebug(I3PAGER) << "mode: " << mode;
4243
Q_EMIT modeChanged(mode);
4344
});
4445

4546
while (!stopping) {
4647
conn.handle_event();
4748
}
4849
} catch (std::exception const& e) {
49-
qWarning() << "Exception in i3listener handle events:" << e.what();
50+
qCWarning(I3PAGER) << "Exception in i3listener handle events:" << e.what();
5051
}
5152
}
5253

‎src/i3pager.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "i3pager.h"
77

88
#include <i3ipc++/ipc.hpp>
9+
#include "i3pager_debug.h"
910
#include "i3listener.h"
1011
#include <future>
1112
#include <QDebug>
@@ -16,7 +17,7 @@ I3Pager::I3Pager(QObject* parent)
1617
currentScreenPrivate = QString();
1718
mode = "default";
1819

19-
qDebug() << "Starting i3 listener";
20+
qCDebug(I3PAGER) << "Starting i3 listener";
2021
this->i3ListenerThread = new I3ListenerThread(this);
2122
connect(i3ListenerThread, &I3ListenerThread::modeChanged, this, [=](const QString& mode) {
2223
this->mode = mode;
@@ -27,14 +28,14 @@ I3Pager::I3Pager(QObject* parent)
2728
});
2829
connect(i3ListenerThread, &I3ListenerThread::finished, i3ListenerThread, &QObject::deleteLater);
2930
i3ListenerThread->start();
30-
qDebug() << "i3 listener started";
31+
qCDebug(I3PAGER) << "i3 listener started";
3132
}
3233

3334
I3Pager::~I3Pager() {
34-
qDebug() << "I3Pager destructor";
35+
qCDebug(I3PAGER) << "I3Pager destructor";
3536
this->i3ListenerThread->stop();
3637
this->i3ListenerThread->wait();
37-
qDebug() << "I3Pager destructor done";
38+
qCDebug(I3PAGER) << "I3Pager destructor done";
3839
}
3940

4041
QList<QString> I3Pager::getScreenNames() {
@@ -46,11 +47,11 @@ QList<QString> I3Pager::getScreenNames() {
4647
for (auto& screen : screens) {
4748
if (screen->active) {
4849
screenList.append(QString::fromStdString(screen->name));
49-
qDebug() << "Screen name:" << QString::fromStdString(screen->name);
50+
qCDebug(I3PAGER) << "Screen name:" << QString::fromStdString(screen->name);
5051
}
5152
}
5253
} catch (std::exception const& e) {
53-
qWarning() << "Exception while retrieving screen names: " << e.what();
54+
qCWarning(I3PAGER) << "Exception while retrieving screen names: " << e.what();
5455
}
5556

5657
return screenList;
@@ -61,7 +62,7 @@ QList<Workspace> I3Pager::getWorkspaces(bool filterByCurrentScreen, QString orde
6162
try {
6263
i3ipc::connection conn;
6364
auto i3workspaceList = conn.get_workspaces();
64-
qDebug() << "Loading workspaces:";
65+
qCDebug(I3PAGER) << "Loading workspaces:";
6566

6667
for (auto& i3workspace : i3workspaceList) {
6768
Workspace workspace;
@@ -77,8 +78,8 @@ QList<Workspace> I3Pager::getWorkspaces(bool filterByCurrentScreen, QString orde
7778
workspace.visible = i3workspace->visible;
7879
workspace.urgent = i3workspace->urgent;
7980

80-
qDebug() << "i3Workspace name:" << QString::fromStdString(i3workspace->name);
81-
qDebug() << "Workspace:"
81+
qCDebug(I3PAGER) << "i3Workspace name:" << QString::fromStdString(i3workspace->name);
82+
qCDebug(I3PAGER) << "Workspace:"
8283
<< "id:" << workspace.id
8384
<< "index:" << workspace.index
8485
<< "name:" << workspace.name
@@ -90,7 +91,7 @@ QList<Workspace> I3Pager::getWorkspaces(bool filterByCurrentScreen, QString orde
9091
workspaceList.append(workspace);
9192
}
9293
} catch (std::exception const& e) {
93-
qWarning() << "Exception while retrieving workspaces:" << e.what();
94+
qCWarning(I3PAGER) << "Exception while retrieving workspaces:" << e.what();
9495
}
9596

9697
if (filterByCurrentScreen) {

‎src/workspace.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@
44
*/
55

66
#include "workspace.h"
7+
#include "i3pager_debug.h"
78
#include <algorithm>
89
#include <QDebug>
910

1011
QList<Workspace> Workspace::filterByCurrentScreen(QList<Workspace> inputWorkspaces, QString currentScreen) {
1112
QList<Workspace> outputWorkspaces;
12-
qDebug() << "Filtering by current screen:" << currentScreen;
13+
qCDebug(I3PAGER) << "Filtering by current screen:" << currentScreen;
1314
for (auto workspace : inputWorkspaces) {
1415
if (currentScreen == workspace.output) {
15-
qDebug() << "Added workspace:" << workspace.name << "output:" << workspace.output;
16+
qCDebug(I3PAGER) << "Added workspace:" << workspace.name << "output:" << workspace.output;
1617
outputWorkspaces.append(workspace);
1718
} else {
18-
qDebug() << "Removed workspace:" << workspace.name << "output:" << workspace.output;
19+
qCDebug(I3PAGER) << "Removed workspace:" << workspace.name << "output:" << workspace.output;
1920
}
2021
}
2122
return outputWorkspaces;
@@ -30,11 +31,11 @@ QList<Workspace> Workspace::orderByName(QList<Workspace> inputWorkspaces) {
3031

3132
QList<Workspace> Workspace::orderByOutput(QList<Workspace> inputWorkspaces, QList<QString> outputList) {
3233
QList<Workspace> outputWorkspaces;
33-
qDebug() << "Ordering workspaces by screens:" << outputList;
34+
qCDebug(I3PAGER) << "Ordering workspaces by screens:" << outputList;
3435
for (auto output : outputList) {
3536
for (auto workspace : inputWorkspaces) {
3637
if (workspace.output == output) {
37-
qDebug() << "Added workspace:" << workspace.name << "output:" << workspace.output;
38+
qCDebug(I3PAGER) << "Added workspace:" << workspace.name << "output:" << workspace.output;
3839
outputWorkspaces.append(workspace);
3940
}
4041
}

0 commit comments

Comments
 (0)
Please sign in to comment.