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; import std.string : cmp, strip; public final class ConnectionAssistant : Assistant { /* Associated GUI instance */ private GUI gui; private Entry serverAddress; private Entry serverPort; private Entry username; private Entry password; /* Summary box */ Box summaryBox; 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 */ 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.addOnClose(&assistentComplete); connectionAssistant.addOnCancel(&assistenctCancel); connectionAssistant.showAll(); } private void assistenctCancel(Assistant e) { /* TODO: Get this to work */ /* TODO: The `.close()` doesn't seem to work */ } /* TODO: I want this code to run when we are on the summary page */ private void kak() { /* Summary data */ Label serverAddressLabel = new Label(""); serverAddressLabel.setMarkup("Server Address: "~serverAddress.getBuffer().getText()); Label serverPortLabel = new Label(""); serverPortLabel.setMarkup("Server Port: "~serverPort.getBuffer().getText()); Label accountUsername = new Label(""); accountUsername.setMarkup("Account username: "~username.getBuffer().getText()); Label accountPassword = new Label(""); accountPassword.setMarkup("Account password: "~password.getBuffer().getText()); summaryBox.add(serverAddressLabel); summaryBox.add(serverPortLabel); summaryBox.add(accountUsername); summaryBox.add(accountPassword); } private void assistentComplete(Assistant) { /* Get the server details */ string serverAddress = strip(serverAddress.getBuffer().getText()); string serverPort = strip(serverPort.getBuffer().getText()); /* Get the account details */ string accountUsername = strip(username.getBuffer().getText()); string accountPassword = password.getBuffer().getText(); /* TODO: Check for emptiness */ if(cmp(serverAddress, "") == 0 || cmp(serverPort, "") == 0 || cmp(accountUsername, "") == 0 || cmp(accountPassword, "") == 0) { /* TODO: Handle error here */ } else { /* Create a new Connection */ gui.connectServer(serverAddress, to!(ushort)(serverPort), [accountUsername, accountPassword]); } } }