2019-03-16 01:15:19 +01:00
|
|
|
#include "IRCWindowListModel.h"
|
2019-03-18 20:56:45 +01:00
|
|
|
#include "IRCChannel.h"
|
2019-06-07 11:48:03 +02:00
|
|
|
#include "IRCClient.h"
|
|
|
|
|
#include "IRCWindow.h"
|
2019-03-15 14:01:04 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
2019-03-16 01:15:19 +01:00
|
|
|
IRCWindowListModel::IRCWindowListModel(IRCClient& client)
|
2019-03-15 14:01:04 +01:00
|
|
|
: m_client(client)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-16 01:15:19 +01:00
|
|
|
IRCWindowListModel::~IRCWindowListModel()
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 03:27:03 +01:00
|
|
|
int IRCWindowListModel::row_count(const GModelIndex&) const
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
|
|
|
|
return m_client.window_count();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 03:27:03 +01:00
|
|
|
int IRCWindowListModel::column_count(const GModelIndex&) const
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-16 01:15:19 +01:00
|
|
|
String IRCWindowListModel::column_name(int column) const
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
|
|
|
|
switch (column) {
|
2019-06-07 11:48:03 +02:00
|
|
|
case Column::Name:
|
|
|
|
|
return "Name";
|
2019-03-15 14:01:04 +01:00
|
|
|
}
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 01:42:49 +01:00
|
|
|
GModel::ColumnMetadata IRCWindowListModel::column_metadata(int column) const
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
|
|
|
|
switch (column) {
|
2019-06-07 11:48:03 +02:00
|
|
|
case Column::Name:
|
|
|
|
|
return { 70, TextAlignment::CenterLeft };
|
2019-03-15 14:01:04 +01:00
|
|
|
}
|
|
|
|
|
ASSERT_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-18 04:54:07 +01:00
|
|
|
GVariant IRCWindowListModel::data(const GModelIndex& index, Role role) const
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
2019-03-18 04:54:07 +01:00
|
|
|
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());
|
2019-03-16 02:14:53 +01:00
|
|
|
return window.name();
|
2019-03-18 04:54:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-03-16 02:14:53 +01:00
|
|
|
}
|
2019-03-18 04:54:07 +01:00
|
|
|
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);
|
2019-03-18 20:56:45 +01:00
|
|
|
if (!window.channel().is_open())
|
2019-06-30 09:23:16 +02:00
|
|
|
return Color(Color::WarmGray);
|
2019-03-18 04:54:07 +01:00
|
|
|
return Color(Color::Black);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-15 14:01:04 +01:00
|
|
|
}
|
2019-06-07 11:48:03 +02:00
|
|
|
return {};
|
2019-03-15 14:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-16 01:15:19 +01:00
|
|
|
void IRCWindowListModel::update()
|
2019-03-15 14:01:04 +01:00
|
|
|
{
|
|
|
|
|
did_update();
|
|
|
|
|
}
|