Cleanup logging in RoomListModel

This commit is contained in:
Tobias Fella
2026-02-20 13:52:50 +01:00
parent 7cfac2151e
commit 44ec1e3529
2 changed files with 23 additions and 14 deletions

View File

@@ -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()

View File

@@ -9,6 +9,7 @@
#include "eventhandler.h"
#include "neochatconnection.h"
#include "neochatroom.h"
#include "roomlistlogging.h"
#include "spacehierarchycache.h"
#include <KLocalizedString>
@@ -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<NeoChatRoom *>(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<NeoChatRoom *>(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<NeoChatRoom *>(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<int> &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());