summaryrefslogtreecommitdiff
path: root/Applications/IRCClient/IRCLogBuffer.cpp
blob: fb5934b071946b18b2c5dc1db24a44260266c0fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "IRCLogBuffer.h"
#include "IRCLogBufferModel.h"
#include <stdio.h>
#include <time.h>

NonnullRefPtr<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());
    }
}