-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testapp.d
307 lines (246 loc) · 8.53 KB
/
testapp.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
module testapp;
import std.stdio;
import gtk.Application : Application;
import gio.Application : GioApplication = Application;
import gtk.ApplicationWindow : ApplicationWindow;
import gtkc.giotypes : GApplicationFlags;
import gdk.Event;
import gio.Menu;
import gio.MenuItem;
import gio.SimpleAction;
import glib.Variant;
import glib.VariantType;
import gtk.HeaderBar;
import gtk.Image;
import gtk.MenuButton;
import gtk.MessageDialog;
import gtk.Popover;
import gtk.Widget;
import gtk.Dialog;
import gtk.Window;
import gtk.Box;
import gtk.Entry;
import gtk.Button;
import gtk.Notebook;
import gtk.EditableIF;
//import gtk.CenterBox;
// import gtk.ResponseType;
class SignInDialog : Dialog
{
//string title, Window parent, GtkDialogFlags flags, string[] buttonsText, ResponseType[] responses
this(ApplicationWindow window)
{
super("Sign into your account.", cast(Window) window, GtkDialogFlags.MODAL, [
"Sign In"
], [ResponseType.NONE]);
//auto btn = new Button("Save");
//btn.setName("btn");
//auto btnCSS = new CSS(btn.getStyleContext());
//btnCSS.addClass("btn_class");
auto box = new Column();
auto emailEntry = new LabeledEntry("Email:");
box.packStart(emailEntry, false, false, 2);
auto contentArea = getContentArea();
contentArea.add(box);
}
}
// Sign up view
class SignUpView : Column
{
this(void delegate() onSuccess)
{
super();
setName("card");
auto viewCSS = new CSS(getStyleContext());
viewCSS.addClass("signUpView");
auto title = new Heading("Create an account.");
title.addClass("h1");
auto businessNameEntry = new LabeledEntry("Business Name:");
businessNameEntry.setPlaceholderText("e.g. Aduma Enterprise");
businessNameEntry.onChange(delegate(EditableIF w) {
businessNameEntry.setError("");
});
//entry.addOnChanged((EditableIF _) {
// update(entry.getBuffer().getText());
//});
auto fnameEntry = new LabeledEntry("First Name:");
fnameEntry.setPlaceholderText("e.g. Kwaku");
fnameEntry.onChange(delegate(EditableIF w) { fnameEntry.setError(""); });
auto lnameEntry = new LabeledEntry("Last Name:");
lnameEntry.setPlaceholderText("e.g. Obeng");
lnameEntry.onChange(delegate(EditableIF _) { lnameEntry.setError(""); });
auto emailEntry = new LabeledEntry("Email:");
emailEntry.setPlaceholderText("e.g. [email protected]");
emailEntry.onChange(delegate(EditableIF _) { emailEntry.setError(""); });
auto passwordEntry = new LabeledEntry("Password:");
passwordEntry.setVisibility(false);
passwordEntry.setPlaceholderText(" ******** ");
passwordEntry.onChange(delegate(EditableIF _) {
passwordEntry.setError("");
});
auto signUpButton = new AppButton("Create Account");
packStart(title, false, false, 2);
packStart(businessNameEntry, false, false, 2);
packStart(fnameEntry, false, false, 2);
packStart(lnameEntry, false, false, 2);
packStart(emailEntry, false, false, 2);
packStart(passwordEntry, false, false, 2);
packStart(signUpButton, false, false, 2);
bool doesHaveErrors()
{
import std.string : strip;
import core.time : MonoTime;
import std.datetime : Clock, UTC, DateTime, SysTime;
string businessName = businessNameEntry.getText();
string fname = fnameEntry.getText();
string lname = lnameEntry.getText();
string email = emailEntry.getText();
string password = passwordEntry.getText();
bool hasErrors = false;
// writeln(SysTime( DateTime()).toUnixTime());
// writeln(Clock.currTime(UTC()).toUnixTime);
if (businessName.strip() == "")
{
hasErrors = true;
businessNameEntry.setError("Please enter your business name.");
}
if (fname.strip() == "")
{
hasErrors = true;
fnameEntry.setError("Please enter your first name.");
}
if (lname.strip() == "")
{
hasErrors = true;
lnameEntry.setError("Please enter your last name.");
}
if (email.strip() == "")
{
hasErrors = true;
emailEntry.setError("Please enter your email address.");
}
if (password.strip() == "")
{
hasErrors = true;
passwordEntry.setError("Please enter a password for your account.");
}
return hasErrors;
}
void handleSignUp(Button btn)
{
if (doesHaveErrors())
return;
string businessName = businessNameEntry.getText();
string fname = fnameEntry.getText();
string lname = lnameEntry.getText();
string email = emailEntry.getText();
string password = passwordEntry.getText();
// create an account
AccountData data;
data.businessName = businessName;
data.fname = fname;
data.lname = lname;
data.email = email;
data.password = password;
if (UserService.createSystemAccount(data))
onSuccess();
}
signUpButton.addOnClicked(&handleSignUp);
}
}
class MainWindow : ApplicationWindow
{
HeaderBar headerBar;
Column signInView;
Column mainView;
SignUpView signUpView;
Notebook notebook;
bool isSignedIn = false;
this(Application application)
{
super(application);
initUI();
// showAll();
}
/**
* Create and initialize the GTK widgets
*/
private void initUI()
{
this.setSizeRequest(1024, 640);
//this.setBorderWidth(10);
// Stack
headerBar = new AppHeaderBar(this);
notebook = new Notebook();
notebook.setName("mainNotebook");
// auto notebookCSS = new CSS(notebook.getStyleContext());
// notebookCSS.addClass("mainNotebbok");
add(notebook);
//writeln(fetchAllUsers());
//writeln(passwordHash("password"));
// Sign in view
auto signInView = new Column();
signInView.setName("card");
auto viewCSS = new CSS(signInView.getStyleContext());
viewCSS.addClass("signInView");
auto emailEntry = new LabeledEntry("Email:");
auto passwordEntry = new LabeledEntry("Password:");
passwordEntry.setVisibility(false);
auto btn = new AppButton("Sign In");
signInView.packStart(emailEntry, false, false, 2);
signInView.packStart(passwordEntry, false, false, 2);
signInView.packStart(btn, false, false, 2);
// test view
mainView = new Column();
mainView.packStart(new LabeledEntry("Number"), false, false, 2);
void handleSignUpSuccess()
{
notebook.setCurrentPage(mainView);
}
signUpView = new SignUpView(&handleSignUpSuccess);
notebook.appendPage(mainView, "Main");
notebook.appendPage(signInView, "Sign In");
notebook.appendPage(signUpView, "Sign Up");
notebook.setShowTabs(true);
showAll();
notebook.setCurrentPage(signUpView);
if (UserService.hasSystemAccount())
{
notebook.setCurrentPage(signInView);
}
void handleSignIn(Button btn)
{
const email = emailEntry.getText();
const password = passwordEntry.getText();
writeln(email, password);
notebook.setCurrentPage(mainView);
//initRestOfUI();
// headerBar.show();
//setTitlebar(headerBar);
//showAll();
// showHeader(headerBar);
}
btn.addOnClicked(&handleSignIn);
//if (!isSignedIn) {
// notebook.setCurrentPage(signInView);
// return;
//}
}
//void initRestOfUI()
//{
// //
//}
void showHeader(HeaderBar headerBar)
{
setTitlebar(headerBar);
showAll();
}
}
int main(string[] args)
{
auto application = new Application("demo.gtkd.Actions", GApplicationFlags.FLAGS_NONE);
application.addOnActivate(delegate void(GioApplication app) {
MainWindow mainWindow = new MainWindow(application);
});
return application.run(args);
}