mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 02:03:06 -05:00
d466f2634d
This makes it possible to specify the text color for each table cell. Use this to make the IRCClient show unread window list items in red.
77 lines
1.7 KiB
C++
77 lines
1.7 KiB
C++
#include "IRCWindowListModel.h"
|
|
#include "IRCWindow.h"
|
|
#include "IRCClient.h"
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
|
|
IRCWindowListModel::IRCWindowListModel(IRCClient& client)
|
|
: m_client(client)
|
|
{
|
|
set_activates_on_selection(true);
|
|
}
|
|
|
|
IRCWindowListModel::~IRCWindowListModel()
|
|
{
|
|
}
|
|
|
|
int IRCWindowListModel::row_count() const
|
|
{
|
|
return m_client.window_count();
|
|
}
|
|
|
|
int IRCWindowListModel::column_count() const
|
|
{
|
|
return 1;
|
|
}
|
|
|
|
String IRCWindowListModel::column_name(int column) const
|
|
{
|
|
switch (column) {
|
|
case Column::Name: return "Name";
|
|
}
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
|
|
GTableModel::ColumnMetadata IRCWindowListModel::column_metadata(int column) const
|
|
{
|
|
switch (column) {
|
|
case Column::Name: return { 70, TextAlignment::CenterLeft };
|
|
}
|
|
ASSERT_NOT_REACHED();
|
|
}
|
|
|
|
GVariant IRCWindowListModel::data(const GModelIndex& index, Role role) const
|
|
{
|
|
if (role == Role::Display) {
|
|
switch (index.column()) {
|
|
case Column::Name: {
|
|
auto& window = m_client.window_at(index.row());
|
|
if (window.unread_count())
|
|
return String::format("%s (%d)", window.name().characters(), window.unread_count());
|
|
return window.name();
|
|
}
|
|
}
|
|
}
|
|
if (role == Role::ForegroundColor) {
|
|
switch (index.column()) {
|
|
case Column::Name: {
|
|
auto& window = m_client.window_at(index.row());
|
|
if (window.unread_count())
|
|
return Color(Color::Red);
|
|
return Color(Color::Black);
|
|
}
|
|
}
|
|
}
|
|
return { };
|
|
}
|
|
|
|
void IRCWindowListModel::update()
|
|
{
|
|
did_update();
|
|
}
|
|
|
|
void IRCWindowListModel::activate(const GModelIndex& index)
|
|
{
|
|
if (on_activation)
|
|
on_activation(m_client.window_at(index.row()));
|
|
}
|