1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 19:47:42 +00:00

IRCClient: Put the unhandled server messages nicely into the server log.

This commit is contained in:
Andreas Kling 2019-03-15 13:16:29 +01:00
parent 850c7504a2
commit f004db19d0
3 changed files with 15 additions and 10 deletions

View file

@ -49,8 +49,6 @@ void IRCAppWindow::setup_widgets()
m_subwindow_container = new GWidget(widget);
m_subwindow_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
m_subwindow_container->set_fill_with_background_color(true);
m_subwindow_container->set_background_color(Color::Yellow);
m_subwindow_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fill);
create_subwindow(IRCSubWindow::Server, "Server");
@ -59,7 +57,5 @@ void IRCAppWindow::setup_widgets()
void IRCAppWindow::create_subwindow(IRCSubWindow::Type type, const String& name)
{
auto* subwindow = new IRCSubWindow(m_client, type, name, m_subwindow_container);
subwindow->set_fill_with_background_color(true);
subwindow->set_background_color(Color::Magenta);
m_subwindows.append(subwindow);
}

View file

@ -235,7 +235,8 @@ void IRCClient::handle(const Message& msg, const String& verbatim)
if (msg.command == "PRIVMSG")
return handle_privmsg(msg);
m_log->add_message(0, "Server", verbatim);
if (msg.arguments.size() >= 2)
m_log->add_message(0, "Server", String::format("[%s] %s", msg.command.characters(), msg.arguments[1].characters()));
}
bool IRCClient::is_nick_prefix(char ch) const

View file

@ -1,6 +1,7 @@
#include "IRCLogBufferModel.h"
#include "IRCLogBuffer.h"
#include <stdio.h>
#include <time.h>
IRCLogBufferModel::IRCLogBufferModel(Retained<IRCLogBuffer>&& log_buffer)
: m_log_buffer(move(log_buffer))
@ -35,20 +36,27 @@ String IRCLogBufferModel::column_name(int column) const
GTableModel::ColumnMetadata IRCLogBufferModel::column_metadata(int column) const
{
switch (column) {
case Column::Timestamp: return { 90, TextAlignment::CenterLeft };
case Column::Timestamp: return { 60, TextAlignment::CenterLeft };
case Column::Prefix: return { 10, TextAlignment::CenterLeft };
case Column::Name: return { 70, TextAlignment::CenterRight };
case Column::Text: return { 400, TextAlignment::CenterLeft };
case Column::Text: return { 800, TextAlignment::CenterLeft };
}
ASSERT_NOT_REACHED();
}
GVariant IRCLogBufferModel::data(const GModelIndex& index, Role role) const
GVariant IRCLogBufferModel::data(const GModelIndex& index, Role) const
{
auto& entry = m_log_buffer->at(index.row());
switch (index.column()) {
case Column::Timestamp: return String::format("%u", entry.timestamp);
case Column::Prefix: return entry.prefix;
case Column::Timestamp: {
auto* tm = localtime(&entry.timestamp);
return String::format("%02u:%02u:%02u", tm->tm_hour, tm->tm_min, tm->tm_sec);
}
case Column::Prefix: {
if (!entry.prefix)
return String("");
return String(&entry.prefix, 1);
}
case Column::Name: return entry.sender;
case Column::Text: return entry.text;
}