1818 *
1919 */
2020
21- public class Obliviate.MainView : Gtk .Overlay {
21+ public class Obliviate.MainView : Gtk .Box {
22+ private Gtk . Overlay overlay;
2223 private Gtk . Grid grid;
23- private Granite . Widgets . Toast toast;
24+ private Granite . Toast toast;
2425
2526 private Gtk . Entry site;
26- private Gtk . Entry cipher_key;
27- private Gtk . Entry generated_pass;
28- private Gtk . ToggleButton show_generated_pass;
27+ private Gtk . PasswordEntry cipher_key;
28+ private Gtk . PasswordEntry generated_pass;
2929 private Gtk . Button copy_btn;
3030 private Gtk . Button copy_without_symbols_btn;
3131 private Gtk . Label clearing_label;
3232 private Gtk . ProgressBar clearing_progress;
3333
34- private Gtk . Clipboard clipboard;
34+ private Gdk . Clipboard clipboard;
3535 private const float CLIPBOARD_LIFE = 30 ;
3636 private uint timeout_id;
3737
3838 construct {
39+ overlay = new Gtk .Overlay ();
40+
3941 grid = new Gtk .Grid () {
4042 row_spacing = 4 ,
4143 column_spacing = 4 ,
42- margin = 30 ,
44+ margin_top = 30 ,
45+ margin_bottom = 30 ,
46+ margin_start = 30 ,
47+ margin_end = 30 ,
4348 halign = Gtk . Align . CENTER
4449 };
4550
46- toast = new Granite . Widgets .Toast (_ (" Copied to clipboard" ));
51+ var toast = new Granite .Toast (_ (" Copied to clipboard" ));
4752
48- add (grid);
49- add_overlay (toast);
53+ overlay . set_child (grid);
54+ overlay . add_overlay (toast);
5055
5156 var site_label = new Gtk .Label (_ (" Site:" )) {
5257 halign = Gtk . Align . END ,
5358 margin_end = 4
5459 };
5560
5661 site = new Gtk .Entry () {
57- placeholder_text = _ ("GitHub ")
62+ placeholder_text = _ ("GitHub "),
63+ primary_icon_name = "dialog-information-symbolic",
64+ primary_icon_tooltip_text = "Site is not case-sensitive. “GitHub” equals “github”."
5865 };
5966
6067 site.changed.connect (handle_generate_password );
6168
62- var site_info = new Gtk .Image .from_icon_name (" dialog-information-symbolic" , Gtk . IconSize . MENU ) {
63- tooltip_text = _ ("Site is not case -sensitive . “GitHub ” equals “github ”.")
64- };
65-
6669 var cipher_key_label = new Gtk .Label (_ (" Cipher key:" )) {
6770 halign = Gtk . Align . END ,
6871 margin_end = 4
6972 };
7073
71- // TODO: replace with Gtk.PasswordEntry after updating to Gtk4
72- cipher_key = new Gtk .Entry () {
73- visibility = false ,
74- caps_lock_warning = true ,
75- input_purpose = Gtk . InputPurpose . PASSWORD ,
74+ cipher_key = new Gtk .PasswordEntry () {
75+ show_peek_icon = true ,
7676 placeholder_text = _ ("correct horse battery staple "),
7777 width_chars = 24
7878 };
7979
8080 cipher_key.changed.connect (handle_generate_password );
8181
82- var show_cipher_key = new Gtk .ToggleButton () {
83- active = true ,
84- tooltip_text = _ ("Show or hide the cipher key ")
85- };
86-
87- show_cipher_key.add (new Gtk .Image .from_icon_name ("image -red -eye -symbolic ", Gtk .IconSize .BUTTON ));
88- show_cipher_key.bind_property ("active ", cipher_key , "visibility ", BindingFlags .INVERT_BOOLEAN );
89-
90- generated_pass = new Gtk .Entry () {
91- visibility = false ,
82+ this . generated_pass = new Gtk .PasswordEntry () {
83+ show_peek_icon = true ,
9284 editable = false ,
93- sensitive = false
94- };
95-
96- generated_pass.get_style_context ().add_class (Gtk .STYLE_CLASS_FLAT );
97-
98- show_generated_pass = new Gtk .ToggleButton () {
99- active = true ,
100- tooltip_text = _ ("Show or hide the password "),
101- sensitive = false
85+ sensitive = false ,
86+ width_chars = 24
10287 };
10388
104- show_generated_pass.add (new Gtk .Image .from_icon_name ("image -red -eye -symbolic ", Gtk .IconSize .BUTTON ));
105- show_generated_pass.bind_property ("active ", generated_pass , "visibility ", BindingFlags .INVERT_BOOLEAN );
89+ this.generated_pass.add_css_class (Granite .STYLE_CLASS_FLAT );
10690
10791 copy_btn = new Gtk .Button .with_label (_ (" Copy" )) {
10892 sensitive = false
10993 };
11094
111- copy_btn.get_style_context () .add_class ( Gtk .STYLE_CLASS_SUGGESTED_ACTION );
95+ copy_btn.add_css_class ( Granite .STYLE_CLASS_SUGGESTED_ACTION );
11296
11397 copy_btn.clicked.connect (() => {
11498 handle_copy ();
@@ -123,8 +107,8 @@ public class Obliviate.MainView : Gtk.Overlay {
123107 });
124108
125109 var button_box = new Gtk .Box (Gtk . Orientation . HORIZONTAL , 6 );
126- button_box.pack_start (copy_btn );
127- button_box.pack_end (copy_without_symbols_btn );
110+ button_box.prepend (copy_btn );
111+ button_box.append (copy_without_symbols_btn );
128112
129113 clearing_label = new Gtk .Label (ngettext (
130114 " Clearing clipboard in %.0f second" ,
@@ -140,45 +124,42 @@ public class Obliviate.MainView : Gtk.Overlay {
140124 fraction = 1
141125 };
142126
143- clearing_progress.get_style_context () .add_class ( Gtk .STYLE_CLASS_FLAT );
127+ clearing_progress.add_css_class ( Granite .STYLE_CLASS_FLAT );
144128
145129 var plus_label = new Gtk .Label (" +" );
146- plus_label.get_style_context () .add_class ("sign ");
130+ plus_label.add_css_class ("sign ");
147131
148132 var equals_label = new Gtk .Label (" =" );
149- equals_label.get_style_context () .add_class ("sign ");
133+ equals_label.add_css_class ("sign ");
150134
151135 grid.attach (site_label , 0 , 0 , 1 , 1 );
152136 grid.attach_next_to (site , site_label , Gtk .PositionType .RIGHT );
153- grid.attach_next_to (site_info , site , Gtk .PositionType .RIGHT );
154137
155138 grid.attach_next_to (plus_label , site , Gtk .PositionType .BOTTOM );
156139
157140 grid.attach (cipher_key_label , 0 , 2 , 1 , 1 );
158141 grid.attach_next_to (cipher_key , cipher_key_label , Gtk .PositionType .RIGHT );
159- grid.attach_next_to (show_cipher_key , cipher_key , Gtk .PositionType .RIGHT );
160142
161143 grid.attach_next_to (equals_label , cipher_key , Gtk .PositionType .BOTTOM );
162144
163145 grid.attach_next_to (generated_pass , equals_label , Gtk .PositionType .BOTTOM );
164- grid.attach_next_to (show_generated_pass , generated_pass , Gtk .PositionType .RIGHT );
165146 grid.attach_next_to (button_box , generated_pass , Gtk .PositionType .BOTTOM );
166147
167- clipboard = Gtk.Clipboard.get_default (Gdk .Display .get_default ());
148+ clipboard = this.get_clipboard ();
149+
150+ append (overlay );
168151 }
169152
170153 private void handle_generate_password () {
171154 if (site. text. length == 0 || cipher_key. text. length == 0 ) {
172155 generated_pass. text = " " ;
173- show_generated_pass. sensitive = false ;
174156 copy_btn. sensitive = false ;
175157 copy_without_symbols_btn. sensitive = false ;
176158 return ;
177159 }
178160
179161 try {
180162 generated_pass. text = Service . derive_password (cipher_key. text, site. text. down ());
181- show_generated_pass. sensitive = true ;
182163 copy_btn. sensitive = true ;
183164 copy_without_symbols_btn. sensitive = true ;
184165 animate_password ();
@@ -195,7 +176,7 @@ public class Obliviate.MainView : Gtk.Overlay {
195176 ? Service . remove_symbols (generated_pass. text)
196177 : generated_pass. text;
197178
198- clipboard. set_text (text_to_copy, generated_pass . text . length );
179+ clipboard. set_text (text_to_copy);
199180
200181 toast. title = _ (" Copied to clipboard" );
201182 toast. send_notification ();
@@ -205,7 +186,7 @@ public class Obliviate.MainView : Gtk.Overlay {
205186 float seconds_left = CLIPBOARD_LIFE ;
206187 timeout_id = Timeout . add_seconds (1 , () = > {
207188 if (seconds_left == 0 ) {
208- clipboard. clear ( );
189+ clipboard. set_text ( " " );
209190
210191 toast. title = _ (" Cleared the clipboard" );
211192 toast. send_notification ();
@@ -242,10 +223,9 @@ public class Obliviate.MainView : Gtk.Overlay {
242223 }
243224
244225 private void animate_password () {
245- var password_style = generated_pass. get_style_context ();
246- password_style. add_class (" regenerating" );
226+ generated_pass. add_css_class (" regenerating" );
247227 Timeout . add (100 , () = > {
248- password_style . remove_class (" regenerating" );
228+ generated_pass . remove_css_class (" regenerating" );
249229 return false ;
250230 });
251231 }
0 commit comments