summaryrefslogtreecommitdiff
blob: 22564ac79aeb1ee4287f5602beb9e85eb5cb85d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using Gtk;
using Client;

public partial class MainWindow : Gtk.Window
{
	TcpChatClient tcpChat;

	public MainWindow() : base(Gtk.WindowType.Toplevel)
	{
		Build();
		tcpChat = new TcpChatClient();
		tcpChat.PropertyChanged += (sender, args) =>
			outputTv.Buffer.Text = tcpChat.Log;
	}

	protected void OnDeleteEvent(object sender, DeleteEventArgs a)
	{
		Application.Quit();
		a.RetVal = true;
	}

	protected async void Connect(object sender, EventArgs e)
	{
		await tcpChat.Connect(ipEntry.Text, Int32.Parse(portEntry.Text));
		tcpChat.SendMessage($"{usernameEntry.Text} connected.");
	}

	protected void SendMessage(object sender, EventArgs e)
	{
		string message = $"{usernameEntry.Text}: {messageEntry.Text}";
		tcpChat.SendMessage(message);
		messageEntry.Text = "";
	}
}