@@ -28,111 +28,108 @@ public final class Window : ApplicationWindow {
2828 icon.setFromGicon(new ThemedIcon (" gtk-add" ), GtkIconSize.LARGE_TOOLBAR );
2929 addBtn.setImage(icon);
3030
31- addCallback = (Button) {
32- auto d = new Dialog(" Add a new account" , this , GtkDialogFlags.MODAL ,
33- [" Cancel" , " Add" ], [
34- ResponseType.CANCEL , ResponseType.ACCEPT
35- ]);
36-
37- d.getWidgetForResponse(ResponseType.ACCEPT ).setSensitive(false );
38- scope (exit)
39- d.destroy ();
40-
41- d.setDefaultResponse(ResponseType.ACCEPT );
42- d.setDefaultSize(400 , - 1 );
43-
44- auto box = new VBox(false , 0 );
45- auto hbox = new HBox(false , 0 );
46-
47- auto name_ent = new Entry();
48- auto secret_ent = new Entry();
49- auto username_ent = new Entry();
50-
51- const void delegate (EditableIF) cb = (EditableIF) {
52- d.getWidgetForResponse(ResponseType.ACCEPT ).setSensitive(name_ent.getText()
53- .length > 0 && secret_ent.getText().length > 0 );
54- };
55- name_ent.addOnChanged(cb);
56- secret_ent.addOnChanged(cb);
57-
58- auto lbl1 = new Label(" The name of this account:" );
59- auto lbl2 = new Label(" The secret code that you got:" );
60- auto lbl3 = new Label(" Your username (optional):" );
61- lbl1.setAlignment(0 , 0 );
62- lbl2.setAlignment(0 , 0 );
63- lbl3.setAlignment(0 , 0 );
64- lbl2.setMarginTop(10 );
65- lbl3.setMarginTop(10 );
66-
67- box.packStart(lbl1, false , false , 5 );
68- box.packStart(name_ent, false , false , 0 );
69- box.packStart(lbl2, false , false , 5 );
70- box.packStart(secret_ent, false , false , 0 );
71- box.packStart(lbl3, false , false , 5 );
72- box.packStart(username_ent, false , false , 0 );
73-
74- box.setMarginStart(15 );
75- box.setMarginEnd(15 );
76- username_ent.setMarginBottom(15 );
77- d.getContentArea().add(box);
78- d.showAll();
79- const res = d.run();
80-
81- if (res == ResponseType.ACCEPT ) {
82- Account acc = {
83- name: name_ent.getText(), secret: secret_ent.getText()};
84- storage.addAccount(acc);
85- reloadAccountList();
86- }
87- };
88- addBtn.addOnClicked(addCallback);
89- header.add(addBtn);
90- setTitlebar(header);
91-
92- contents = new VBox(false , 0 );
93- reloadAccountList();
31+ addBtn.addOnClicked(&onAddClicked);
32+ header.add(addBtn);
33+ setTitlebar(header);
9434
95- add(contents );
96- }
35+ contents = new VBox( false , 0 );
36+ reloadAccountList();
9737
98- private :
99- void reloadAccountList () {
100- import std.conv : to;
38+ add(contents);
39+ }
10140
102- header.setTitle(storage.countAccounts().to! string ~ " Accounts" );
41+ private :
42+
43+ void onAddClicked (Button b) {
44+ auto d = new Dialog(" Add a new account" , this , GtkDialogFlags.MODAL ,
45+ [" Cancel" , " Add" ], [ResponseType.CANCEL , ResponseType.ACCEPT ]);
46+
47+ d.getWidgetForResponse(ResponseType.ACCEPT ).setSensitive(false );
48+ scope (exit)
49+ d.destroy ();
50+
51+ d.setDefaultResponse(ResponseType.ACCEPT );
52+ d.setDefaultSize(400 , - 1 );
53+
54+ auto box = new VBox(false , 0 );
55+ auto hbox = new HBox(false , 0 );
56+
57+ auto name_ent = new Entry();
58+ auto secret_ent = new Entry();
59+ auto username_ent = new Entry(" @" );
60+
61+ const void delegate (EditableIF) cb = (EditableIF) {
62+ d.getWidgetForResponse(ResponseType.ACCEPT ).setSensitive(name_ent.getText()
63+ .length > 0 && secret_ent.getText().length > 0 );
64+ };
65+ name_ent.addOnChanged(cb);
66+ secret_ent.addOnChanged(cb);
67+
68+ auto lbl1 = new Label(" The name of this account:" );
69+ auto lbl2 = new Label(" The secret code that you got:" );
70+ auto lbl3 = new Label(" Your username (optional):" );
71+ lbl1.setAlignment(0 , 0 );
72+ lbl2.setAlignment(0 , 0 );
73+ lbl3.setAlignment(0 , 0 );
74+ lbl2.setMarginTop(10 );
75+ lbl3.setMarginTop(10 );
76+
77+ box.packStart(lbl1, false , false , 5 );
78+ box.packStart(name_ent, false , false , 0 );
79+ box.packStart(lbl2, false , false , 5 );
80+ box.packStart(secret_ent, false , false , 0 );
81+ box.packStart(lbl3, false , false , 5 );
82+ box.packStart(username_ent, false , false , 0 );
83+
84+ box.setMarginStart(15 );
85+ box.setMarginEnd(15 );
86+ username_ent.setMarginBottom(15 );
87+ d.getContentArea().add(box);
88+ d.showAll();
89+ const res = d.run();
90+
91+ if (res == ResponseType.ACCEPT ) {
92+ storage.addAccount(Account(name_ent.getText(),
93+ secret_ent.getText(), username_ent.getText()));
94+ reloadAccountList();
95+ }
96+ }
10397
104- if (auto t = contents.getChildren()) {
105- foreach (ref w; t.toArray! Widget()) {
106- contents.remove(w);
107- w.destroy ();
108- }
109- }
110- if (storage.countAccounts() == 0 ) {
111- auto welcome = new Welcome(" Authomata" ,
112- " You currently don't have any accounts. Use the button below to add the first one" );
113- auto ic = new Image();
114- ic.setFromIconName(" gtk-add" , GtkIconSize.LARGE_TOOLBAR );
115- welcome.addButton(" Add an account" ,
116- " Add a new 2-factor authentication account" , ic, addCallback);
117- contents.packStart(welcome, true , true , 0 );
118- } else {
119- auto s = new ScrolledWindow();
120- auto vb = new VBox(false , 0 );
121-
122- auto title = new Label(" Authomata" );
123- title.getStyleContext().addClass(" app-title" );
124- vb.packStart(title, false , false , 20 );
125-
126- foreach (acc; storage.getAccounts())
127- vb.packStart(new AccountView (acc), false , false , 5 );
128- s.add(vb);
129- contents.packStart(s, true , true , 0 );
98+ void reloadAccountList () {
99+ import std.conv : to;
100+
101+ header.setTitle(storage.countAccounts().to! string ~ " Accounts" );
102+ if (auto t = contents.getChildren()) {
103+ foreach (ref w; t.toArray! Widget()) {
104+ contents.remove(w);
105+ w.destroy ();
130106 }
131- contents.showAll();
132107 }
133-
134- Storage storage;
135- VBox contents;
136- void delegate (Button) addCallback;
137- HeaderBar header;
108+ if (storage.countAccounts() == 0 ) {
109+ auto welcome = new Welcome(" Authomata" ,
110+ " You currently don't have any accounts. Use the button below to add the first one" );
111+ auto ic = new Image();
112+ ic.setFromIconName(" gtk-add" , GtkIconSize.LARGE_TOOLBAR );
113+ welcome.addButton(" Add an account" ,
114+ " Add a new 2-factor authentication account" , ic, &onAddClicked);
115+ contents.packStart(welcome, true , true , 0 );
116+ } else {
117+ auto s = new ScrolledWindow();
118+ auto vb = new VBox(false , 0 );
119+
120+ auto title = new Label(" Authomata" );
121+ title.getStyleContext().addClass(" app-title" );
122+ vb.packStart(title, false , false , 20 );
123+
124+ foreach (acc; storage.getAccounts())
125+ vb.packStart(new AccountView (acc), false , false , 5 );
126+ s.add(vb);
127+ contents.packStart(s, true , true , 0 );
128+ }
129+ contents.showAll();
138130 }
131+
132+ Storage storage;
133+ VBox contents;
134+ HeaderBar header;
135+ }
0 commit comments