ladybird/Applications/IRCClient/IRCLogBuffer.cpp
Andreas Kling f47945759b LibGUI: Make GTableModel a retainable object.
It became clear that this class needs to support multiple owners.
2019-03-20 03:27:07 +01:00

37 lines
866 B
C++

#include "IRCLogBuffer.h"
#include "IRCLogBufferModel.h"
#include <stdio.h>
#include <time.h>
Retained<IRCLogBuffer> IRCLogBuffer::create()
{
return adopt(*new IRCLogBuffer);
}
IRCLogBuffer::IRCLogBuffer()
: m_model(IRCLogBufferModel::create(*this))
{
}
IRCLogBuffer::~IRCLogBuffer()
{
}
void IRCLogBuffer::add_message(char prefix, const String& name, const String& text, Color color)
{
m_messages.enqueue({ time(nullptr), prefix, name, text, color });
m_model->update();
}
void IRCLogBuffer::add_message(const String& text, Color color)
{
m_messages.enqueue({ time(nullptr), '\0', String(), text, color });
m_model->update();
}
void IRCLogBuffer::dump() const
{
for (auto& message : m_messages) {
printf("%u <%c%8s> %s\n", message.timestamp, message.prefix, message.sender.characters(), message.text.characters());
}
}