2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-03-15 21:15:19 -03:00
|
|
|
#include "IRCWindowListModel.h"
|
2019-03-18 16:56:45 -03:00
|
|
|
#include "IRCChannel.h"
|
2019-06-07 06:48:03 -03:00
|
|
|
#include "IRCClient.h"
|
2019-03-15 10:01:04 -03:00
|
|
|
|
2019-03-15 21:15:19 -03:00
|
|
|
IRCWindowListModel::IRCWindowListModel(IRCClient& client)
|
2019-03-15 10:01:04 -03:00
|
|
|
: m_client(client)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 21:15:19 -03:00
|
|
|
IRCWindowListModel::~IRCWindowListModel()
|
2019-03-15 10:01:04 -03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
int IRCWindowListModel::row_count(const GUI::ModelIndex&) const
|
2019-03-15 10:01:04 -03:00
|
|
|
{
|
2020-09-10 13:42:26 -03:00
|
|
|
return m_client->window_count();
|
2019-03-15 10:01:04 -03:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
int IRCWindowListModel::column_count(const GUI::ModelIndex&) const
|
2019-03-15 10:01:04 -03:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 21:15:19 -03:00
|
|
|
String IRCWindowListModel::column_name(int column) const
|
2019-03-15 10:01:04 -03:00
|
|
|
{
|
|
|
|
|
switch (column) {
|
2019-06-07 06:48:03 -03:00
|
|
|
case Column::Name:
|
|
|
|
|
return "Name";
|
2019-03-15 10:01:04 -03:00
|
|
|
}
|
2021-02-23 16:42:32 -03:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-03-15 10:01:04 -03:00
|
|
|
}
|
|
|
|
|
|
2020-08-16 11:00:07 -03:00
|
|
|
GUI::Variant IRCWindowListModel::data(const GUI::ModelIndex& index, GUI::ModelRole role) const
|
2019-03-15 10:01:04 -03:00
|
|
|
{
|
2020-08-16 11:00:07 -03:00
|
|
|
if (role == GUI::ModelRole::TextAlignment)
|
2020-05-21 14:36:09 -03:00
|
|
|
return Gfx::TextAlignment::CenterLeft;
|
2020-08-16 11:00:07 -03:00
|
|
|
if (role == GUI::ModelRole::Display) {
|
2019-03-18 00:54:07 -03:00
|
|
|
switch (index.column()) {
|
|
|
|
|
case Column::Name: {
|
2020-09-10 13:42:26 -03:00
|
|
|
auto& window = m_client->window_at(index.row());
|
2019-03-18 00:54:07 -03:00
|
|
|
if (window.unread_count())
|
2020-10-06 09:16:35 -03:00
|
|
|
return String::formatted("{} ({})", window.name(), window.unread_count());
|
2019-03-15 22:14:53 -03:00
|
|
|
return window.name();
|
2019-03-18 00:54:07 -03:00
|
|
|
}
|
|
|
|
|
}
|
2019-03-15 22:14:53 -03:00
|
|
|
}
|
2020-08-16 11:00:07 -03:00
|
|
|
if (role == GUI::ModelRole::ForegroundColor) {
|
2019-03-18 00:54:07 -03:00
|
|
|
switch (index.column()) {
|
|
|
|
|
case Column::Name: {
|
2020-09-10 13:42:26 -03:00
|
|
|
auto& window = m_client->window_at(index.row());
|
2019-03-18 00:54:07 -03:00
|
|
|
if (window.unread_count())
|
|
|
|
|
return Color(Color::Red);
|
2019-03-18 16:56:45 -03:00
|
|
|
if (!window.channel().is_open())
|
2019-06-30 04:23:16 -03:00
|
|
|
return Color(Color::WarmGray);
|
2019-03-18 00:54:07 -03:00
|
|
|
return Color(Color::Black);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-15 10:01:04 -03:00
|
|
|
}
|
2019-06-07 06:48:03 -03:00
|
|
|
return {};
|
2019-03-15 10:01:04 -03:00
|
|
|
}
|
|
|
|
|
|
2019-03-15 21:15:19 -03:00
|
|
|
void IRCWindowListModel::update()
|
2019-03-15 10:01:04 -03:00
|
|
|
{
|
|
|
|
|
did_update();
|
|
|
|
|
}
|