From 44ec1e3529f58c113ea83d3abc81fba1fbb4db5a Mon Sep 17 00:00:00 2001 From: Tobias Fella Date: Fri, 20 Feb 2026 13:52:50 +0100 Subject: [PATCH] Cleanup logging in RoomListModel --- src/libneochat/CMakeLists.txt | 7 ++++++ src/libneochat/models/roomlistmodel.cpp | 30 +++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/libneochat/CMakeLists.txt b/src/libneochat/CMakeLists.txt index 4579ed095..ec34c4f1c 100644 --- a/src/libneochat/CMakeLists.txt +++ b/src/libneochat/CMakeLists.txt @@ -67,6 +67,13 @@ ecm_qt_declare_logging_category(LibNeoChat DEFAULT_SEVERITY Info ) +ecm_qt_declare_logging_category(LibNeoChat + HEADER "roomlistlogging.h" + IDENTIFIER "RoomList" + CATEGORY_NAME "org.kde.neochat.roomlist" + DEFAULT_SEVERITY Info +) + if (TARGET KF6::KIOWidgets) target_compile_definitions(LibNeoChat PUBLIC -DHAVE_KIO) endif() diff --git a/src/libneochat/models/roomlistmodel.cpp b/src/libneochat/models/roomlistmodel.cpp index e098b97bb..d97549190 100644 --- a/src/libneochat/models/roomlistmodel.cpp +++ b/src/libneochat/models/roomlistmodel.cpp @@ -9,6 +9,7 @@ #include "eventhandler.h" #include "neochatconnection.h" #include "neochatroom.h" +#include "roomlistlogging.h" #include "spacehierarchycache.h" #include @@ -45,7 +46,7 @@ void RoomListModel::setConnection(NeoChatConnection *connection) m_connection->disconnect(this); } if (!connection) { - qDebug() << "Removing current connection..."; + qCDebug(RoomList) << "Removing current connection"; m_connection = nullptr; beginResetModel(); m_rooms.clear(); @@ -103,14 +104,15 @@ NeoChatRoom *RoomListModel::roomAt(int row) const void RoomListModel::doAddRoom(Room *r) { - if (auto room = static_cast(r)) { - m_rooms.append(room); - connectRoomSignals(room); - Q_EMIT roomAdded(room); - } else { - qCritical() << "Attempt to add nullptr to the room list"; - Q_ASSERT(false); + Q_ASSERT(r); + if (!r) { + qCCritical(RoomList) << "Attempt to add nullptr to the room list"; + return; } + const auto room = static_cast(r); + m_rooms.append(room); + connectRoomSignals(room); + Q_EMIT roomAdded(room); } void RoomListModel::connectRoomSignals(NeoChatRoom *room) @@ -153,12 +155,12 @@ void RoomListModel::updateRoom(Room *room, Room *prev) // 2. (prev != nullptr) accepting/rejecting an invitation or inviting to // the previously left room (in both cases prev has the previous state). if (prev == room) { - qCritical() << "RoomListModel::updateRoom: room tried to replace itself"; + qCCritical(RoomList) << "RoomListModel::updateRoom: room tried to replace itself"; refresh(static_cast(room)); return; } if (prev && room->id() != prev->id()) { - qCritical() << "RoomListModel::updateRoom: attempt to update room" << room->id() << "to" << prev->id(); + qCCritical(RoomList) << "RoomListModel::updateRoom: attempt to update room" << room->id() << "to" << prev->id(); // That doesn't look right but technically we still can do it. } // Ok, we're through with pre-checks, now for the real thing. @@ -184,12 +186,12 @@ void RoomListModel::updateRoom(Room *room, Room *prev) void RoomListModel::deleteRoom(Room *room) { - qDebug() << "Deleting room" << room->id(); + qCDebug(RoomList) << "Deleting room" << room->id(); const auto it = std::find(m_rooms.begin(), m_rooms.end(), room); if (it == m_rooms.end()) { return; // Already deleted, nothing to do } - qDebug() << "Erasing room" << room->id(); + qCDebug(RoomList) << "Erasing room" << room->id(); const int row = it - m_rooms.begin(); beginRemoveRows(QModelIndex(), row, row); m_rooms.erase(it); @@ -211,7 +213,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const } if (index.row() >= m_rooms.count()) { - qDebug() << "UserListModel: something wrong here..."; + qCWarning(RoomList) << __FUNCTION__ << "called with invalid index" << index << m_rooms.count(); return QVariant(); } NeoChatRoom *room = m_rooms.at(index.row()); @@ -289,7 +291,7 @@ void RoomListModel::refresh(NeoChatRoom *room, const QList &roles) { const auto it = std::find(m_rooms.begin(), m_rooms.end(), room); if (it == m_rooms.end()) { - qCritical() << "Room" << room->id() << "not found in the room list"; + qCCritical(RoomList) << "Room" << room->id() << "not found in the room list"; return; } const auto idx = index(it - m_rooms.begin());