diff options
Diffstat (limited to 'Applications/IRCClient')
-rw-r--r-- | Applications/IRCClient/IRCAppWindow.cpp | 9 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.cpp | 15 | ||||
-rw-r--r-- | Applications/IRCClient/IRCClient.h | 4 |
3 files changed, 20 insertions, 8 deletions
diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp index f8bc17b989..4889168078 100644 --- a/Applications/IRCClient/IRCAppWindow.cpp +++ b/Applications/IRCClient/IRCAppWindow.cpp @@ -12,9 +12,9 @@ #include <LibGUI/GInputBox.h> #include <LibGUI/GSplitter.h> #include <stdio.h> +#include <stdlib.h> IRCAppWindow::IRCAppWindow() - : m_client("127.0.0.1", 6667) { update_title(); set_rect(200, 200, 600, 400); @@ -52,6 +52,13 @@ void IRCAppWindow::setup_client() m_client.join_channel("#test"); }; + GInputBox input_box("Enter server:", "Connect to server", this); + auto result = input_box.exec(); + if (result == GInputBox::ExecCancel) + ::exit(0); + + m_client.set_server(input_box.text_value(), 6667); + update_title(); m_client.connect(); } diff --git a/Applications/IRCClient/IRCClient.cpp b/Applications/IRCClient/IRCClient.cpp index 922716f862..e8cf682339 100644 --- a/Applications/IRCClient/IRCClient.cpp +++ b/Applications/IRCClient/IRCClient.cpp @@ -27,10 +27,8 @@ enum IRCNumeric { RPL_ENDOFNAMES = 366, }; -IRCClient::IRCClient(const String& address, int port) - : m_hostname(address) - , m_port(port) - , m_nickname("anon") +IRCClient::IRCClient() + : m_nickname("seren1ty") , m_client_window_list_model(IRCWindowListModel::create(*this)) , m_log(IRCLogBuffer::create()) { @@ -41,13 +39,18 @@ IRCClient::~IRCClient() { } +void IRCClient::set_server(const String &hostname, int port) +{ + m_hostname = hostname; + m_port = port; +} + bool IRCClient::connect() { if (m_socket->is_connected()) ASSERT_NOT_REACHED(); - IPv4Address ipv4_address(127, 0, 0, 1); - bool success = m_socket->connect(GSocketAddress(ipv4_address), m_port); + bool success = m_socket->connect(m_hostname, m_port); if (!success) return false; diff --git a/Applications/IRCClient/IRCClient.h b/Applications/IRCClient/IRCClient.h index 2c582da420..a3173afa26 100644 --- a/Applications/IRCClient/IRCClient.h +++ b/Applications/IRCClient/IRCClient.h @@ -17,9 +17,11 @@ class IRCClient final : public GObject { friend class IRCChannel; friend class IRCQuery; public: - IRCClient(const String& address, int port = 6667); + IRCClient(); virtual ~IRCClient() override; + void set_server(const String& hostname, int port = 6667); + bool connect(); String hostname() const { return m_hostname; } |