|
|
|
@ -30,6 +30,7 @@ RoomList::RoomList(QWidget *parent) |
|
|
|
|
, ui(new Ui::RoomList) |
|
|
|
|
{ |
|
|
|
|
ui->setupUi(this); |
|
|
|
|
ui->scrollVerticalLayout->addStretch(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RoomList::~RoomList() |
|
|
|
@ -37,22 +38,30 @@ RoomList::~RoomList() |
|
|
|
|
delete ui; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RoomList::clear() |
|
|
|
|
{ |
|
|
|
|
for (const auto &room : rooms_) |
|
|
|
|
room->deleteLater(); |
|
|
|
|
|
|
|
|
|
rooms_.clear(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
RoomInfo RoomList::extractRoomInfo(const State &room_state) |
|
|
|
|
{ |
|
|
|
|
RoomInfo info; |
|
|
|
|
|
|
|
|
|
auto events = room_state.events(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < events.count(); i++) { |
|
|
|
|
if (events[i].type() == "m.room.name") { |
|
|
|
|
info.setName(events[i].content().value("name").toString()); |
|
|
|
|
} else if (events[i].type() == "m.room.topic") { |
|
|
|
|
info.setTopic(events[i].content().value("topic").toString()); |
|
|
|
|
} else if (events[i].type() == "m.room.avatar") { |
|
|
|
|
info.setAvatarUrl(QUrl(events[i].content().value("url").toString())); |
|
|
|
|
} else if (events[i].type() == "m.room.canonical_alias") { |
|
|
|
|
for (const auto &event : events) { |
|
|
|
|
if (event.type() == "m.room.name") { |
|
|
|
|
info.setName(event.content().value("name").toString()); |
|
|
|
|
} else if (event.type() == "m.room.topic") { |
|
|
|
|
info.setTopic(event.content().value("topic").toString()); |
|
|
|
|
} else if (event.type() == "m.room.avatar") { |
|
|
|
|
info.setAvatarUrl(QUrl(event.content().value("url").toString())); |
|
|
|
|
} else if (event.type() == "m.room.canonical_alias") { |
|
|
|
|
if (info.name().isEmpty()) |
|
|
|
|
info.setName(events[i].content().value("alias").toString()); |
|
|
|
|
info.setName(event.content().value("alias").toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -61,7 +70,7 @@ RoomInfo RoomList::extractRoomInfo(const State &room_state) |
|
|
|
|
|
|
|
|
|
void RoomList::setInitialRooms(const Rooms &rooms) |
|
|
|
|
{ |
|
|
|
|
available_rooms_.clear(); |
|
|
|
|
rooms_.clear(); |
|
|
|
|
|
|
|
|
|
for (auto it = rooms.join().constBegin(); it != rooms.join().constEnd(); it++) { |
|
|
|
|
RoomInfo info = RoomList::extractRoomInfo(it.value().state()); |
|
|
|
@ -79,24 +88,23 @@ void RoomList::setInitialRooms(const Rooms &rooms) |
|
|
|
|
this, |
|
|
|
|
SLOT(highlightSelectedRoom(const RoomInfo &))); |
|
|
|
|
|
|
|
|
|
available_rooms_.insert(it.key(), room_item); |
|
|
|
|
rooms_.insert(it.key(), room_item); |
|
|
|
|
|
|
|
|
|
ui->scrollVerticalLayout->addWidget(room_item); |
|
|
|
|
int pos = ui->scrollVerticalLayout->count() - 1; |
|
|
|
|
ui->scrollVerticalLayout->insertWidget(pos, room_item); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO: Move this into its own function.
|
|
|
|
|
auto first_room = available_rooms_.first(); |
|
|
|
|
auto first_room = rooms_.first(); |
|
|
|
|
first_room->setPressedState(true); |
|
|
|
|
emit roomChanged(first_room->info()); |
|
|
|
|
|
|
|
|
|
ui->scrollVerticalLayout->addStretch(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RoomList::highlightSelectedRoom(const RoomInfo &info) |
|
|
|
|
{ |
|
|
|
|
emit roomChanged(info); |
|
|
|
|
|
|
|
|
|
for (auto it = available_rooms_.constBegin(); it != available_rooms_.constEnd(); it++) { |
|
|
|
|
for (auto it = rooms_.constBegin(); it != rooms_.constEnd(); it++) { |
|
|
|
|
if (it.key() != info.id()) |
|
|
|
|
it.value()->setPressedState(false); |
|
|
|
|
} |
|
|
|
@ -104,16 +112,11 @@ void RoomList::highlightSelectedRoom(const RoomInfo &info) |
|
|
|
|
|
|
|
|
|
void RoomList::updateRoomAvatar(const QString &roomid, const QImage &avatar_image) |
|
|
|
|
{ |
|
|
|
|
if (!available_rooms_.contains(roomid)) { |
|
|
|
|
if (!rooms_.contains(roomid)) { |
|
|
|
|
qDebug() << "Avatar update on non existent room" << roomid; |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
auto list_item = available_rooms_.value(roomid); |
|
|
|
|
auto list_item = rooms_.value(roomid); |
|
|
|
|
list_item->setAvatar(avatar_image); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RoomList::appendRoom(QString name) |
|
|
|
|
{ |
|
|
|
|
Q_UNUSED(name); |
|
|
|
|
} |
|
|
|
|