فهرست منبع

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

Andreas Kling 6 سال پیش
والد
کامیت
cc20eef7ef
3فایلهای تغییر یافته به همراه20 افزوده شده و 8 حذف شده
  1. 8 1
      Applications/IRCClient/IRCAppWindow.cpp
  2. 9 6
      Applications/IRCClient/IRCClient.cpp
  3. 3 1
      Applications/IRCClient/IRCClient.h

+ 8 - 1
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();
 }
 

+ 9 - 6
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;
 

+ 3 - 1
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; }