2020-10-23 21:39:37 +00:00
|
|
|
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;
|
2020-10-24 10:08:56 +00:00
|
|
|
import std.string : cmp, strip;
|
2020-10-23 21:39:37 +00:00
|
|
|
|
|
|
|
public final class ConnectionAssistant : Assistant
|
|
|
|
{
|
|
|
|
/* Associated GUI instance */
|
|
|
|
private GUI gui;
|
|
|
|
|
2020-10-24 10:08:56 +00:00
|
|
|
private Entry serverAddress;
|
|
|
|
private Entry serverPort;
|
|
|
|
private Entry username;
|
|
|
|
private Entry password;
|
2020-10-23 21:39:37 +00:00
|
|
|
|
2020-10-24 10:08:00 +00:00
|
|
|
/* Summary box */
|
|
|
|
Box summaryBox;
|
|
|
|
|
2020-10-23 21:39:37 +00:00
|
|
|
|
|
|
|
this(GUI gui)
|
|
|
|
{
|
|
|
|
this.gui = gui;
|
|
|
|
|
|
|
|
initWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initWindow()
|
|
|
|
{
|
|
|
|
Assistant connectionAssistant = new Assistant();
|
|
|
|
|
|
|
|
Label hello = new Label("");
|
|
|
|
hello.setMarkup("<span size=\"15000\">Welcome to the connection setup</span>");
|
|
|
|
connectionAssistant.insertPage(hello, 0);
|
|
|
|
connectionAssistant.setPageTitle(hello, "Welcome");
|
|
|
|
|
|
|
|
/* Configure a server */
|
|
|
|
Box serverBox = new Box(GtkOrientation.VERTICAL, 1);
|
|
|
|
Label serverBoxTitle = new Label("");
|
|
|
|
serverBoxTitle.setMarkup("<span size=\"15000\">Server details</span>");
|
|
|
|
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("<span size=\"15000\">Account details</span>");
|
|
|
|
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 */
|
2020-10-24 10:08:00 +00:00
|
|
|
summaryBox = new Box(GtkOrientation.VERTICAL, 1);
|
2020-10-23 21:39:37 +00:00
|
|
|
Label summaryBoxTitle = new Label("");
|
|
|
|
summaryBoxTitle.setMarkup("<span size=\"15000\">Summary</span>");
|
|
|
|
summaryBox.packStart(summaryBoxTitle,0,0,30);
|
2020-10-24 10:08:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-23 21:39:37 +00:00
|
|
|
connectionAssistant.insertPage(summaryBox, 4);
|
|
|
|
connectionAssistant.setPageType(summaryBox, GtkAssistantPageType.SUMMARY);
|
|
|
|
|
|
|
|
|
2020-10-23 22:14:30 +00:00
|
|
|
connectionAssistant.addOnClose(&assistentComplete);
|
|
|
|
connectionAssistant.addOnCancel(&assistenctCancel);
|
|
|
|
|
2020-10-23 21:39:37 +00:00
|
|
|
connectionAssistant.showAll();
|
2020-10-23 22:14:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void assistenctCancel(Assistant e)
|
|
|
|
{
|
2020-10-24 09:59:20 +00:00
|
|
|
/* TODO: Get this to work */
|
|
|
|
/* TODO: The `.close()` doesn't seem to work */
|
2020-10-23 21:39:37 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 10:08:00 +00:00
|
|
|
/* 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("<b>Server Address:</b> "~serverAddress.getBuffer().getText());
|
|
|
|
|
|
|
|
Label serverPortLabel = new Label("");
|
|
|
|
serverPortLabel.setMarkup("<b>Server Port:</b> "~serverPort.getBuffer().getText());
|
|
|
|
|
|
|
|
Label accountUsername = new Label("");
|
|
|
|
accountUsername.setMarkup("<b>Account username:</b> "~username.getBuffer().getText());
|
|
|
|
|
|
|
|
Label accountPassword = new Label("");
|
|
|
|
accountPassword.setMarkup("<b>Account password:</b> "~password.getBuffer().getText());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
summaryBox.add(serverAddressLabel);
|
|
|
|
summaryBox.add(serverPortLabel);
|
|
|
|
summaryBox.add(accountUsername);
|
|
|
|
summaryBox.add(accountPassword);
|
|
|
|
}
|
|
|
|
|
2020-10-23 22:14:30 +00:00
|
|
|
private void assistentComplete(Assistant)
|
2020-10-23 21:39:37 +00:00
|
|
|
{
|
|
|
|
/* Get the server details */
|
2020-10-24 10:08:56 +00:00
|
|
|
string serverAddress = strip(serverAddress.getBuffer().getText());
|
|
|
|
string serverPort = strip(serverPort.getBuffer().getText());
|
2020-10-23 21:39:37 +00:00
|
|
|
|
|
|
|
/* Get the account details */
|
2020-10-24 10:08:56 +00:00
|
|
|
string accountUsername = strip(username.getBuffer().getText());
|
2020-10-23 21:39:37 +00:00
|
|
|
string accountPassword = password.getBuffer().getText();
|
2020-10-24 10:08:56 +00:00
|
|
|
|
|
|
|
/* TODO: Check for emptiness */
|
|
|
|
|
2020-10-23 21:39:37 +00:00
|
|
|
|
2020-10-24 09:51:47 +00:00
|
|
|
/* Create a new Connection */
|
2020-10-23 21:39:37 +00:00
|
|
|
gui.connectServer(serverAddress, to!(ushort)(serverPort), [accountUsername, accountPassword]);
|
|
|
|
}
|
|
|
|
}
|