Cleanup logging in RoomListModel
This commit is contained in:
@@ -67,6 +67,13 @@ ecm_qt_declare_logging_category(LibNeoChat
|
|||||||
DEFAULT_SEVERITY Info
|
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)
|
if (TARGET KF6::KIOWidgets)
|
||||||
target_compile_definitions(LibNeoChat PUBLIC -DHAVE_KIO)
|
target_compile_definitions(LibNeoChat PUBLIC -DHAVE_KIO)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "eventhandler.h"
|
#include "eventhandler.h"
|
||||||
#include "neochatconnection.h"
|
#include "neochatconnection.h"
|
||||||
#include "neochatroom.h"
|
#include "neochatroom.h"
|
||||||
|
#include "roomlistlogging.h"
|
||||||
#include "spacehierarchycache.h"
|
#include "spacehierarchycache.h"
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
@@ -45,7 +46,7 @@ void RoomListModel::setConnection(NeoChatConnection *connection)
|
|||||||
m_connection->disconnect(this);
|
m_connection->disconnect(this);
|
||||||
}
|
}
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
qDebug() << "Removing current connection...";
|
qCDebug(RoomList) << "Removing current connection";
|
||||||
m_connection = nullptr;
|
m_connection = nullptr;
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
m_rooms.clear();
|
m_rooms.clear();
|
||||||
@@ -103,14 +104,15 @@ NeoChatRoom *RoomListModel::roomAt(int row) const
|
|||||||
|
|
||||||
void RoomListModel::doAddRoom(Room *r)
|
void RoomListModel::doAddRoom(Room *r)
|
||||||
{
|
{
|
||||||
if (auto room = static_cast<NeoChatRoom *>(r)) {
|
Q_ASSERT(r);
|
||||||
m_rooms.append(room);
|
if (!r) {
|
||||||
connectRoomSignals(room);
|
qCCritical(RoomList) << "Attempt to add nullptr to the room list";
|
||||||
Q_EMIT roomAdded(room);
|
return;
|
||||||
} else {
|
|
||||||
qCritical() << "Attempt to add nullptr to the room list";
|
|
||||||
Q_ASSERT(false);
|
|
||||||
}
|
}
|
||||||
|
const auto room = static_cast<NeoChatRoom *>(r);
|
||||||
|
m_rooms.append(room);
|
||||||
|
connectRoomSignals(room);
|
||||||
|
Q_EMIT roomAdded(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomListModel::connectRoomSignals(NeoChatRoom *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
|
// 2. (prev != nullptr) accepting/rejecting an invitation or inviting to
|
||||||
// the previously left room (in both cases prev has the previous state).
|
// the previously left room (in both cases prev has the previous state).
|
||||||
if (prev == room) {
|
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));
|
refresh(static_cast<NeoChatRoom *>(room));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prev && room->id() != prev->id()) {
|
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.
|
// That doesn't look right but technically we still can do it.
|
||||||
}
|
}
|
||||||
// Ok, we're through with pre-checks, now for the real thing.
|
// 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)
|
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);
|
const auto it = std::find(m_rooms.begin(), m_rooms.end(), room);
|
||||||
if (it == m_rooms.end()) {
|
if (it == m_rooms.end()) {
|
||||||
return; // Already deleted, nothing to do
|
return; // Already deleted, nothing to do
|
||||||
}
|
}
|
||||||
qDebug() << "Erasing room" << room->id();
|
qCDebug(RoomList) << "Erasing room" << room->id();
|
||||||
const int row = it - m_rooms.begin();
|
const int row = it - m_rooms.begin();
|
||||||
beginRemoveRows(QModelIndex(), row, row);
|
beginRemoveRows(QModelIndex(), row, row);
|
||||||
m_rooms.erase(it);
|
m_rooms.erase(it);
|
||||||
@@ -211,7 +213,7 @@ QVariant RoomListModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (index.row() >= m_rooms.count()) {
|
if (index.row() >= m_rooms.count()) {
|
||||||
qDebug() << "UserListModel: something wrong here...";
|
qCWarning(RoomList) << __FUNCTION__ << "called with invalid index" << index << m_rooms.count();
|
||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
NeoChatRoom *room = m_rooms.at(index.row());
|
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);
|
const auto it = std::find(m_rooms.begin(), m_rooms.end(), room);
|
||||||
if (it == m_rooms.end()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
const auto idx = index(it - m_rooms.begin());
|
const auto idx = index(it - m_rooms.begin());
|
||||||
|
|||||||
Reference in New Issue
Block a user