From 8d5be66f2b9983669eb4835e94ff3c25c1d6607f Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Fri, 23 Oct 2020 23:39:37 +0200 Subject: [PATCH] Connection assistant now moved to its own object and can now spawn new connections --- source/ConnectionAssistant.d | 108 +++++++++++++++++++++++++++++++++++ source/gui.d | 61 ++------------------ 2 files changed, 114 insertions(+), 55 deletions(-) create mode 100644 source/ConnectionAssistant.d diff --git a/source/ConnectionAssistant.d b/source/ConnectionAssistant.d new file mode 100644 index 0000000..c963c81 --- /dev/null +++ b/source/ConnectionAssistant.d @@ -0,0 +1,108 @@ +module ConnectionAssistant; + +/** +* ConnectionAssistant +* +* This provides a graphical utility for +* configuring new connections +*/ + +import gtk.Assistant; +import gtk.Label; +import gtk.Box; +import gtk.Entry; +import gui; +import std.conv; + +public final class ConnectionAssistant : Assistant +{ + /* Associated GUI instance */ + private GUI gui; + + Entry serverAddress; + Entry serverPort; + Entry username; + Entry password; + + + this(GUI gui) + { + this.gui = gui; + + initWindow(); + } + + private void initWindow() + { + Assistant connectionAssistant = new Assistant(); + + Label hello = new Label(""); + hello.setMarkup("Welcome to the connection setup"); + connectionAssistant.insertPage(hello, 0); + connectionAssistant.setPageTitle(hello, "Welcome"); + + /* Configure a server */ + Box serverBox = new Box(GtkOrientation.VERTICAL, 1); + Label serverBoxTitle = new Label(""); + serverBoxTitle.setMarkup("Server details"); + serverBox.packStart(serverBoxTitle,0,0,30); + serverAddress = new Entry(); + serverBox.add(serverAddress); + serverAddress.setPlaceholderText("DNET server address"); + serverPort = new Entry(); + serverBox.add(serverPort); + serverPort.setPlaceholderText("DNET server port"); + + + connectionAssistant.insertPage(serverBox, 1); + connectionAssistant.setPageTitle(serverBox, "Network"); + + /* Configure your profile details */ + Box profileBox = new Box(GtkOrientation.VERTICAL, 1); + Label profileBoxTitle = new Label(""); + profileBoxTitle.setMarkup("Account details"); + profileBox.packStart(profileBoxTitle,0,0,30); + username = new Entry(); + profileBox.add(username); + username.setPlaceholderText("username"); + password = new Entry(); + profileBox.add(password); + password.setPlaceholderText("password"); + + connectionAssistant.insertPage(profileBox, 2); + connectionAssistant.setPageTitle(profileBox, "Account"); + + /* TODO: We should actually verify inputs before doing this */ + connectionAssistant.setPageComplete(hello, true); + connectionAssistant.setPageComplete(serverBox, true); + connectionAssistant.setPageComplete(profileBox, true); + + + /* Summary */ + Box summaryBox = new Box(GtkOrientation.VERTICAL, 1); + Label summaryBoxTitle = new Label(""); + summaryBoxTitle.setMarkup("Summary"); + summaryBox.packStart(summaryBoxTitle,0,0,30); + connectionAssistant.insertPage(summaryBox, 4); + connectionAssistant.setPageType(summaryBox, GtkAssistantPageType.SUMMARY); + + + connectionAssistant.showAll(); + + + connectionAssistant.addOnClose(&assistentComplete); + } + + private void assistentComplete(Assistant e) + { + /* Get the server details */ + string serverAddress = serverAddress.getBuffer().getText(); + string serverPort = serverPort.getBuffer().getText(); + + /* Get the account details */ + string accountUsername = username.getBuffer().getText(); + string accountPassword = password.getBuffer().getText(); + + gui.connectServer(serverAddress, to!(ushort)(serverPort), [accountUsername, accountPassword]); + } +} \ No newline at end of file diff --git a/source/gui.d b/source/gui.d index 72c34fb..babf27a 100644 --- a/source/gui.d +++ b/source/gui.d @@ -128,7 +128,7 @@ public class GUI : Thread private bool welcomeGenesisLabelClick(string, Label) { - connectServer("0.0.0.0", 7777); + connectServer("0.0.0.0", 7777, ["testGustav"~to!(string)(connections.length), "bruh"]); return 1; } @@ -469,60 +469,11 @@ public class GUI : Thread private bool conifgureConnectionsAssistant(string, Label) { - setupConnection(); + import ConnectionAssistant; + ConnectionAssistant ass = new ConnectionAssistant(this); return 0; } - - private void setupConnection() - { - import gtk.Assistant; - Assistant connectionAssistant = new Assistant(); - - Label hello = new Label(""); - hello.setMarkup("Welcome to the connection setup"); - connectionAssistant.insertPage(hello, 0); - connectionAssistant.setPageTitle(hello, "Welcome"); - - /* Configure a server */ - Box serverBox = new Box(GtkOrientation.VERTICAL, 1); - Label serverBoxTitle = new Label(""); - serverBoxTitle.setMarkup("Server details"); - serverBox.packStart(serverBoxTitle,0,0,30); - Entry serverAddress = new Entry(); - serverBox.add(serverAddress); - serverAddress.setPlaceholderText("DNET server address"); - Entry serverPort = new Entry(); - serverBox.add(serverPort); - serverPort.setPlaceholderText("DNET server port"); - - - connectionAssistant.insertPage(serverBox, 1); - connectionAssistant.setPageTitle(serverBox, "Network"); - - /* Configure your profile details */ - Box profileBox = new Box(GtkOrientation.VERTICAL, 1); - Label profileBoxTitle = new Label(""); - profileBoxTitle.setMarkup("Account details"); - profileBox.packStart(profileBoxTitle,0,0,30); - Entry username = new Entry(); - profileBox.add(username); - username.setPlaceholderText("username"); - Entry password = new Entry(); - profileBox.add(password); - password.setPlaceholderText("password"); - - connectionAssistant.insertPage(profileBox, 2); - connectionAssistant.setPageTitle(profileBox, "Account"); - - connectionAssistant.setPageComplete(hello, true); - connectionAssistant.setPageComplete(serverBox, true); - - - connectionAssistant.showAll(); - } - - private void setStatus(ToolButton x) { /* If there are any available connections */ @@ -620,7 +571,7 @@ public class GUI : Thread private void connectButton(MenuItem) { - connectServer("0.0.0.0", 7777); + connectServer("0.0.0.0", 7777, ["testGustav"~to!(string)(connections.length), "bruh"]); } /** @@ -630,7 +581,7 @@ public class GUI : Thread * NOTE: To be called only by a GTK signal * handler */ - private void connectServer(string address, ushort port) + public void connectServer(string address, ushort port, string[] authDetails) { /** * If this is our first connection then @@ -649,7 +600,7 @@ public class GUI : Thread } /* Create the new Connection */ - Connection newConnection = new Connection(this, parseAddress(address, port), ["testGustav"~to!(string)(connections.length), "bruh"]); + Connection newConnection = new Connection(this, parseAddress(address, port), authDetails); connections ~= newConnection; // import UserDirectory;