Serenity Operating System
at portability 96 lines 3.4 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include "IRCLogBuffer.h" 30#include <AK/String.h> 31#include <AK/CircularQueue.h> 32#include <AK/RefPtr.h> 33#include <AK/RefCounted.h> 34#include <AK/Vector.h> 35 36class IRCClient; 37class IRCChannelMemberListModel; 38class IRCWindow; 39 40class IRCChannel : public RefCounted<IRCChannel> { 41public: 42 static NonnullRefPtr<IRCChannel> create(IRCClient&, const String&); 43 ~IRCChannel(); 44 45 bool is_open() const { return m_open; } 46 void set_open(bool b) { m_open = b; } 47 48 String name() const { return m_name; } 49 50 void add_member(const String& name, char prefix); 51 void remove_member(const String& name); 52 53 void add_message(char prefix, const String& name, const String& text, Color = Color::Black); 54 void add_message(const String& text, Color = Color::Black); 55 56 void dump() const; 57 58 void say(const String&); 59 60 const IRCLogBuffer& log() const { return *m_log; } 61 IRCLogBuffer& log() { return *m_log; } 62 63 IRCChannelMemberListModel* member_model() { return m_member_model.ptr(); } 64 const IRCChannelMemberListModel* member_model() const { return m_member_model.ptr(); } 65 66 int member_count() const { return m_members.size(); } 67 String member_at(int i) { return m_members[i].name; } 68 69 void handle_join(const String& nick, const String& hostmask); 70 void handle_part(const String& nick, const String& hostmask); 71 void handle_topic(const String& nick, const String& topic); 72 73 IRCWindow& window() { return *m_window; } 74 const IRCWindow& window() const { return *m_window; } 75 76 String topic() const { return m_topic; } 77 78 void notify_nick_changed(const String& old_nick, const String& new_nick); 79 80private: 81 IRCChannel(IRCClient&, const String&); 82 83 IRCClient& m_client; 84 String m_name; 85 String m_topic; 86 struct Member { 87 String name; 88 char prefix { 0 }; 89 }; 90 Vector<Member> m_members; 91 bool m_open { false }; 92 93 NonnullRefPtr<IRCLogBuffer> m_log; 94 NonnullRefPtr<IRCChannelMemberListModel> m_member_model; 95 IRCWindow* m_window { nullptr }; 96};