Serenity Operating System
at hosted 82 lines 2.8 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 <LibGUI/Widget.h> 30#include <LibWeb/Forward.h> 31 32class IRCChannel; 33class IRCClient; 34class IRCQuery; 35class IRCLogBuffer; 36 37class IRCWindow : public GUI::Widget { 38 C_OBJECT(IRCWindow) 39public: 40 enum Type { 41 Server, 42 Channel, 43 Query, 44 }; 45 46 virtual ~IRCWindow() override; 47 48 String name() const { return m_name; } 49 void set_name(const String& name) { m_name = name; } 50 51 Type type() const { return m_type; } 52 53 void set_log_buffer(const IRCLogBuffer&); 54 55 bool is_active() const; 56 57 int unread_count() const; 58 void clear_unread_count(); 59 60 void did_add_message(const String& name = {}, const String& message = {}); 61 62 IRCChannel& channel() { return *(IRCChannel*)m_owner; } 63 const IRCChannel& channel() const { return *(const IRCChannel*)m_owner; } 64 65 IRCQuery& query() { return *(IRCQuery*)m_owner; } 66 const IRCQuery& query() const { return *(const IRCQuery*)m_owner; } 67 68private: 69 IRCWindow(IRCClient&, void* owner, Type, const String& name); 70 71 void post_notification_if_needed(const String& name, const String& message); 72 73 IRCClient& m_client; 74 void* m_owner { nullptr }; 75 Type m_type; 76 String m_name; 77 RefPtr<Web::HtmlView> m_html_view; 78 RefPtr<GUI::TextEditor> m_text_editor; 79 RefPtr<IRCLogBuffer> m_log_buffer; 80 RefPtr<GUI::Menu> m_context_menu; 81 int m_unread_count { 0 }; 82};