mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:22:44 +00:00 
			
		
		
		
	IRCClient: Ask the user which IRC server to connect to on startup.
This commit is contained in:
		
							parent
							
								
									76ce68ac48
								
							
						
					
					
						commit
						cc20eef7ef
					
				
					 3 changed files with 20 additions and 8 deletions
				
			
		|  | @ -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(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -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; } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling