From 5d76b434cba514e6a14e903968c9ef87ea6930dd Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Sat, 17 Oct 2020 15:58:09 +0200 Subject: [PATCH] Only connect to one test server, take in authentication details on Connection construction --- source/Connection.d | 17 ++++++++++------- source/gui.d | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/source/Connection.d b/source/Connection.d index 3abd0c4..1569ff4 100644 --- a/source/Connection.d +++ b/source/Connection.d @@ -20,16 +20,18 @@ public final class Connection : Thread private DClient client; private Address address; + private string[] auth; /* TODO: Check if we need to protect */ /* TODO: So far usage is in signal handlers (mutex safved) and within te-tl lock for notifications */ private string currentChannel; - this(GUI gui, Address address) + this(GUI gui, Address address, string[] auth) { super(&worker); this.gui = gui; this.address = address; + this.auth = auth; start(); } @@ -41,7 +43,7 @@ public final class Connection : Thread te(); box = getChatPane(); gui.notebook.add(box); - gui.notebook.setTabLabelText(box, "user@"~address.toString()); + gui.notebook.setTabLabelText(box, auth[0]~"@"~address.toString()); gui.notebook.showAll(); tl(); @@ -50,7 +52,7 @@ public final class Connection : Thread * Connects and logs in */ client = new DClient(address); - client.auth("bru", "kak"); /* TODO: DO this without auth (the list in the loop, crahses server) */ + client.auth(auth[0], auth[1]); /* TODO: DO this without auth (the list in the loop, crahses server) */ /* Display all channels */ channelList(); @@ -229,18 +231,19 @@ public final class Connection : Thread userBox.add(new Label("Users")); userBox.add(users); - - textArea = new ListBox(); box.add(channelBox); box.add(textArea); - box.add(userBox); - + box.packEnd(userBox,0,0,0); + + + + return box; } diff --git a/source/gui.d b/source/gui.d index f09c7e3..d7161b2 100644 --- a/source/gui.d +++ b/source/gui.d @@ -11,6 +11,7 @@ import gtk.Box; import gtk.Menu; import gtk.MenuItem; import std.stdio; +import gtk.Statusbar; import Connection; import std.socket; @@ -22,6 +23,8 @@ public class GUI : Thread private MenuBar menuBar; public Notebook notebook; + private Statusbar statusBar; + private Connection[] connections; @@ -53,8 +56,10 @@ public class GUI : Thread /* Test adding a connection */ for(uint i = 0; i < 5; i++) { - connections ~= new Connection(this, parseAddress("0.0.0.0", 7777)); + // connections ~= new Connection(this, parseAddress("0.0.0.0", 7777)); } + + connections ~= new Connection(this, parseAddress("0.0.0.0", 7777), ["testGustav1", "bruh"]); } @@ -90,6 +95,9 @@ public class GUI : Thread box.add(menuBar); notebook = new Notebook(); box.add(notebook); + statusBar = new Statusbar(); + statusBar.add(new Label("Gustav: Bruh")); + box.packEnd(statusBar, 0, 0, 0); //notebook.add(createServerTab()); @@ -116,6 +124,13 @@ public class GUI : Thread Menu gustavMenu = new Menu(); gustavMenuItem.setSubmenu(gustavMenu); + /* Connect option */ + MenuItem connectItem = new MenuItem(); + connectItem.setLabel("Connect"); + connectItem.addOnActivate(&exitButton); + gustavMenu.add(connectItem); + + /* Exit option */ MenuItem exitItem = new MenuItem(); exitItem.setLabel("Exit"); exitItem.addOnActivate(&exitButton); @@ -123,6 +138,8 @@ public class GUI : Thread + + /* Add all menues */ menuBar.add(gustavMenuItem);