diff options
-rw-r--r-- | Applications/IRCClient/IRCChannel.cpp | 36 | ||||
-rw-r--r-- | Applications/IRCClient/IRCChannel.h | 3 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.cpp | 9 | ||||
-rw-r--r-- | Applications/IRCClient/IRCLogBuffer.cpp | 10 | ||||
-rw-r--r-- | Applications/IRCClient/IRCLogBuffer.h | 5 | ||||
-rw-r--r-- | Applications/IRCClient/IRCLogBufferModel.cpp | 4 | ||||
-rw-r--r-- | Applications/IRCClient/IRCQuery.cpp | 5 | ||||
-rw-r--r-- | Applications/IRCClient/IRCQuery.h | 2 | ||||
-rw-r--r-- | Applications/IRCClient/IRCWindowListModel.cpp | 3 | ||||
-rw-r--r-- | SharedGraphics/Color.cpp | 3 | ||||
-rw-r--r-- | SharedGraphics/Color.h | 3 |
11 files changed, 60 insertions, 23 deletions
diff --git a/Applications/IRCClient/IRCChannel.cpp b/Applications/IRCClient/IRCChannel.cpp index 6e2a01b64c..381f461ffe 100644 --- a/Applications/IRCClient/IRCChannel.cpp +++ b/Applications/IRCClient/IRCChannel.cpp @@ -32,14 +32,24 @@ void IRCChannel::add_member(const String& name, char prefix) } } m_members.append({ name, prefix }); - dump(); + m_member_model->update(); } -void IRCChannel::add_message(char prefix, const String& name, const String& text) +void IRCChannel::remove_member(const String& name) { + m_members.remove_first_matching([&] (auto& member) { return name == member.name; }); +} + +void IRCChannel::add_message(char prefix, const String& name, const String& text, Color color) +{ + log().add_message(prefix, name, text, color); + window().did_add_message(); +} + +void IRCChannel::add_message(const String& text, Color color) +{ + log().add_message(text, color); window().did_add_message(); - log().add_message(prefix, name, text); - dump(); } void IRCChannel::dump() const @@ -60,19 +70,25 @@ void IRCChannel::handle_join(const String& nick, const String& hostmask) { if (nick == m_client.nickname()) m_open = true; - add_message(' ', "", String::format("*** %s [%s] has joined %s", nick.characters(), hostmask.characters(), m_name.characters())); + add_message(String::format("*** %s [%s] has joined %s", nick.characters(), hostmask.characters(), m_name.characters()), Color::DarkGreen); } void IRCChannel::handle_part(const String& nick, const String& hostmask) { - if (nick == m_client.nickname()) + if (nick == m_client.nickname()) { m_open = false; - add_message(' ', "", String::format("*** %s [%s] has parted from %s", nick.characters(), hostmask.characters(), m_name.characters())); + m_members.clear(); + } else { + remove_member(nick); + } + m_member_model->update(); + add_message(String::format("*** %s [%s] has parted from %s", nick.characters(), hostmask.characters(), m_name.characters()), Color::DarkGreen); } void IRCChannel::handle_topic(const String& nick, const String& topic) { - if (nick == m_client.nickname()) - m_open = false; - add_message(' ', "", String::format("*** %s set topic to \"%s\"", nick.characters(), topic.characters())); + if (nick.is_null()) + add_message(String::format("*** Topic is \"%s\"", topic.characters()), Color::DarkBlue); + else + add_message(String::format("*** %s set topic to \"%s\"", nick.characters(), topic.characters()), Color::DarkBlue); } diff --git a/Applications/IRCClient/IRCChannel.h b/Applications/IRCClient/IRCChannel.h index 94a037597c..9bbdc71fc8 100644 --- a/Applications/IRCClient/IRCChannel.h +++ b/Applications/IRCClient/IRCChannel.h @@ -24,7 +24,8 @@ public: void add_member(const String& name, char prefix); void remove_member(const String& name); - void add_message(char prefix, const String& name, const String& text); + void add_message(char prefix, const String& name, const String& text, Color = Color::Black); + void add_message(const String& text, Color = Color::Black); void dump() const; diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 3607f34799..5892b7771a 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -369,7 +369,7 @@ void IRCClient::handle_join(const Message& msg) void IRCClient::handle_part(const Message& msg) { - if (msg.arguments.size() != 1) + if (msg.arguments.size() < 1) return; auto prefix_parts = msg.prefix.split('!'); if (prefix_parts.size() < 1) @@ -393,12 +393,11 @@ void IRCClient::handle_topic(const Message& msg) void IRCClient::handle_rpl_topic(const Message& msg) { - if (msg.arguments.size() != 3) + if (msg.arguments.size() < 3) return; - auto& nick = msg.arguments[0]; auto& channel_name = msg.arguments[1]; auto& topic = msg.arguments[2]; - ensure_channel(channel_name).handle_topic(nick, topic); + ensure_channel(channel_name).handle_topic({ }, topic); // FIXME: Handle RPL_TOPICWHOTIME so we can know who set it and when. } @@ -501,7 +500,7 @@ void IRCClient::handle_rpl_topicwhotime(const Message& msg) tm->tm_sec ); } - ensure_channel(channel_name).add_message(0, "", String::format("Topic set by %s at %s", nick.characters(), setat.characters())); + ensure_channel(channel_name).add_message(String::format("*** (set by %s at %s)", nick.characters(), setat.characters()), Color::DarkBlue); } void IRCClient::register_subwindow(IRCWindow& subwindow) diff --git a/Applications/IRCClient/IRCLogBuffer.cpp b/Applications/IRCClient/IRCLogBuffer.cpp index e9450ae804..69b35a2adf 100644 --- a/Applications/IRCClient/IRCLogBuffer.cpp +++ b/Applications/IRCClient/IRCLogBuffer.cpp @@ -17,9 +17,15 @@ IRCLogBuffer::~IRCLogBuffer() { } -void IRCLogBuffer::add_message(char prefix, const String& name, const String& text) +void IRCLogBuffer::add_message(char prefix, const String& name, const String& text, Color color) { - m_messages.enqueue({ time(nullptr), prefix, name, text }); + 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(); } diff --git a/Applications/IRCClient/IRCLogBuffer.h b/Applications/IRCClient/IRCLogBuffer.h index 979feaaf30..6be5576be7 100644 --- a/Applications/IRCClient/IRCLogBuffer.h +++ b/Applications/IRCClient/IRCLogBuffer.h @@ -4,6 +4,7 @@ #include <AK/CircularQueue.h> #include <AK/Retainable.h> #include <AK/RetainPtr.h> +#include <SharedGraphics/Color.h> class IRCLogBufferModel; @@ -17,11 +18,13 @@ public: char prefix { 0 }; String sender; String text; + Color color { Color::Black }; }; int count() const { return m_messages.size(); } const Message& at(int index) const { return m_messages.at(index); } - void add_message(char prefix, const String& name, const String& text); + void add_message(char prefix, const String& name, const String& text, Color = Color::Black); + void add_message(const String& text, Color = Color::Black); void dump() const; const IRCLogBufferModel* model() const { return m_model; } diff --git a/Applications/IRCClient/IRCLogBufferModel.cpp b/Applications/IRCClient/IRCLogBufferModel.cpp index 07262fb59f..e5aea977b9 100644 --- a/Applications/IRCClient/IRCLogBufferModel.cpp +++ b/Applications/IRCClient/IRCLogBufferModel.cpp @@ -59,6 +59,10 @@ GVariant IRCLogBufferModel::data(const GModelIndex& index, Role role) const case Column::Text: return entry.text; } } + if (role == Role::ForegroundColor) { + if (index.column() == Column::Text) + return m_log_buffer->at(index.row()).color; + } return { }; } diff --git a/Applications/IRCClient/IRCQuery.cpp b/Applications/IRCClient/IRCQuery.cpp index 932a07b250..a592c01012 100644 --- a/Applications/IRCClient/IRCQuery.cpp +++ b/Applications/IRCClient/IRCQuery.cpp @@ -27,11 +27,10 @@ void IRCQuery::dump() const log().dump(); } -void IRCQuery::add_message(char prefix, const String& name, const String& text) +void IRCQuery::add_message(char prefix, const String& name, const String& text, Color color) { + log().add_message(prefix, name, text, color); window().did_add_message(); - log().add_message(prefix, name, text); - dump(); } void IRCQuery::say(const String& text) diff --git a/Applications/IRCClient/IRCQuery.h b/Applications/IRCClient/IRCQuery.h index 7e73364536..8d26d92881 100644 --- a/Applications/IRCClient/IRCQuery.h +++ b/Applications/IRCClient/IRCQuery.h @@ -16,7 +16,7 @@ public: ~IRCQuery(); String name() const { return m_name; } - void add_message(char prefix, const String& name, const String& text); + void add_message(char prefix, const String& name, const String& text, Color = Color::Black); void dump() const; diff --git a/Applications/IRCClient/IRCWindowListModel.cpp b/Applications/IRCClient/IRCWindowListModel.cpp index 214e2a9747..a167df21fe 100644 --- a/Applications/IRCClient/IRCWindowListModel.cpp +++ b/Applications/IRCClient/IRCWindowListModel.cpp @@ -1,6 +1,7 @@ #include "IRCWindowListModel.h" #include "IRCWindow.h" #include "IRCClient.h" +#include "IRCChannel.h" #include <stdio.h> #include <time.h> @@ -58,6 +59,8 @@ GVariant IRCWindowListModel::data(const GModelIndex& index, Role role) const auto& window = m_client.window_at(index.row()); if (window.unread_count()) return Color(Color::Red); + if (!window.channel().is_open()) + return Color(Color::LightGray); return Color(Color::Black); } } diff --git a/SharedGraphics/Color.cpp b/SharedGraphics/Color.cpp index 5e4102d2f2..f93b48b458 100644 --- a/SharedGraphics/Color.cpp +++ b/SharedGraphics/Color.cpp @@ -20,6 +20,9 @@ Color::Color(NamedColor named) case DarkGray: rgb = { 64, 64, 64 }; break; case MidGray: rgb = { 127, 127, 127 }; break; case LightGray: rgb = { 192, 192, 192 }; break; + case DarkGreen: rgb = { 0, 128, 0 }; break; + case DarkBlue: rgb = { 0, 0, 128 }; break; + case DarkRed: rgb = { 128, 0, 0 }; break; default: ASSERT_NOT_REACHED(); break; } diff --git a/SharedGraphics/Color.h b/SharedGraphics/Color.h index 9e4dbb0321..f077c0da72 100644 --- a/SharedGraphics/Color.h +++ b/SharedGraphics/Color.h @@ -23,6 +23,9 @@ public: DarkGray, MidGray, LightGray, + DarkGreen, + DarkBlue, + DarkRed, }; Color() { } |