1 module ConnectionAssistant;
2 
3 /**
4 * ConnectionAssistant
5 *
6 * This provides a graphical utility for
7 * configuring new connections
8 */
9 
10 import gtk.Assistant;
11 import gtk.Label;
12 import gtk.Box;
13 import gtk.Entry;
14 import gui;
15 import std.conv;
16 
17 public final class ConnectionAssistant : Assistant
18 {
19     /* Associated GUI instance */
20     private GUI gui;
21 
22     Entry serverAddress;
23     Entry serverPort;
24     Entry username;
25     Entry password;
26 
27 
28     this(GUI gui)
29     {
30         this.gui = gui;
31 
32         initWindow();
33     }
34 
35     private void initWindow()
36     {   
37         Assistant connectionAssistant = new Assistant();
38 
39         Label hello = new Label("");
40         hello.setMarkup("<span size=\"15000\">Welcome to the connection setup</span>");
41         connectionAssistant.insertPage(hello, 0);
42         connectionAssistant.setPageTitle(hello, "Welcome");
43 
44         /* Configure a server */
45         Box serverBox = new Box(GtkOrientation.VERTICAL, 1);
46         Label serverBoxTitle = new Label("");
47         serverBoxTitle.setMarkup("<span size=\"15000\">Server details</span>");
48         serverBox.packStart(serverBoxTitle,0,0,30);
49         serverAddress = new Entry();
50         serverBox.add(serverAddress);
51         serverAddress.setPlaceholderText("DNET server address");
52         serverPort = new Entry();
53         serverBox.add(serverPort);
54         serverPort.setPlaceholderText("DNET server port");
55         
56         
57         connectionAssistant.insertPage(serverBox, 1);
58         connectionAssistant.setPageTitle(serverBox, "Network");
59 
60         /* Configure your profile details */
61         Box profileBox = new Box(GtkOrientation.VERTICAL, 1);
62         Label profileBoxTitle = new Label("");
63         profileBoxTitle.setMarkup("<span size=\"15000\">Account details</span>");
64         profileBox.packStart(profileBoxTitle,0,0,30);
65         username = new Entry();
66         profileBox.add(username);
67         username.setPlaceholderText("username");
68         password = new Entry();
69         profileBox.add(password);
70         password.setPlaceholderText("password");
71 
72         connectionAssistant.insertPage(profileBox, 2);
73         connectionAssistant.setPageTitle(profileBox, "Account");
74         
75         /* TODO: We should actually verify inputs before doing this */
76         connectionAssistant.setPageComplete(hello, true);
77         connectionAssistant.setPageComplete(serverBox, true);
78         connectionAssistant.setPageComplete(profileBox, true);
79 
80 
81         /* Summary */
82         Box summaryBox = new Box(GtkOrientation.VERTICAL, 1);
83         Label summaryBoxTitle = new Label("");
84         summaryBoxTitle.setMarkup("<span size=\"15000\">Summary</span>");
85         summaryBox.packStart(summaryBoxTitle,0,0,30);
86         connectionAssistant.insertPage(summaryBox, 4);
87         connectionAssistant.setPageType(summaryBox, GtkAssistantPageType.SUMMARY);
88         
89 
90         connectionAssistant.addOnClose(&assistentComplete);
91         connectionAssistant.addOnCancel(&assistenctCancel);
92 
93         connectionAssistant.showAll();
94 
95 
96         
97     }
98 
99     private void assistenctCancel(Assistant e)
100     {
101         /* TODO: Implement me */
102     }
103 
104     private void assistentComplete(Assistant)
105     {
106         /* Get the server details */
107         string serverAddress = serverAddress.getBuffer().getText();
108         string serverPort = serverPort.getBuffer().getText();
109 
110         /* Get the account details */
111         string accountUsername = username.getBuffer().getText();
112         string accountPassword = password.getBuffer().getText();
113         
114         gui.connectServer(serverAddress, to!(ushort)(serverPort), [accountUsername, accountPassword]);
115     }
116 }