1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

IRCClient: Ask the user which IRC server to connect to on startup.

This commit is contained in:
Andreas Kling 2019-04-02 20:40:45 +02:00
parent 76ce68ac48
commit cc20eef7ef
3 changed files with 20 additions and 8 deletions

View file

@ -12,9 +12,9 @@
#include <LibGUI/GInputBox.h> #include <LibGUI/GInputBox.h>
#include <LibGUI/GSplitter.h> #include <LibGUI/GSplitter.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
IRCAppWindow::IRCAppWindow() IRCAppWindow::IRCAppWindow()
: m_client("127.0.0.1", 6667)
{ {
update_title(); update_title();
set_rect(200, 200, 600, 400); set_rect(200, 200, 600, 400);
@ -52,6 +52,13 @@ void IRCAppWindow::setup_client()
m_client.join_channel("#test"); 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(); m_client.connect();
} }

View file

@ -27,10 +27,8 @@ enum IRCNumeric {
RPL_ENDOFNAMES = 366, RPL_ENDOFNAMES = 366,
}; };
IRCClient::IRCClient(const String& address, int port) IRCClient::IRCClient()
: m_hostname(address) : m_nickname("seren1ty")
, m_port(port)
, m_nickname("anon")
, m_client_window_list_model(IRCWindowListModel::create(*this)) , m_client_window_list_model(IRCWindowListModel::create(*this))
, m_log(IRCLogBuffer::create()) , 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() bool IRCClient::connect()
{ {
if (m_socket->is_connected()) if (m_socket->is_connected())
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
IPv4Address ipv4_address(127, 0, 0, 1); bool success = m_socket->connect(m_hostname, m_port);
bool success = m_socket->connect(GSocketAddress(ipv4_address), m_port);
if (!success) if (!success)
return false; return false;

View file

@ -17,9 +17,11 @@ class IRCClient final : public GObject {
friend class IRCChannel; friend class IRCChannel;
friend class IRCQuery; friend class IRCQuery;
public: public:
IRCClient(const String& address, int port = 6667); IRCClient();
virtual ~IRCClient() override; virtual ~IRCClient() override;
void set_server(const String& hostname, int port = 6667);
bool connect(); bool connect();
String hostname() const { return m_hostname; } String hostname() const { return m_hostname; }