Skip to content

Commit db5b049

Browse files
teamconsdar5hak
andauthored
Port to GTK4
* gtk4 ? but broken libgcrypt * trying stuff with libgpg-error * forgot this * Update debug message to print if regex fails * Lint * Update meson.build Co-authored-by: Darshak Parikh <[email protected]> * Add flag to build gcrypt correctly * Use Granite style class in lieu of deprecated GTK ones * Replace LibHandy headerbar with GTK one * Use newer Gdk.Clipboard * Replace Gtk.Entry + peek button with Gtk.PasswordEntry * Update layout widgets to GTK4 * Fix overlay for proper composition in GTK4 --------- Co-authored-by: Darshak Parikh <[email protected]> Co-authored-by: Darshak Parikh <[email protected]>
1 parent 59e23c3 commit db5b049

13 files changed

+116
-127
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ build
22
builddir
33
.flatpak-builder
44
*~
5+
.flatpak
6+
.vscode

com.github.elfenware.obliviate.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
app-id: com.github.elfenware.obliviate
22

33
runtime: io.elementary.Platform
4-
runtime-version: '7'
4+
runtime-version: '8.2'
55
sdk: io.elementary.Sdk
66

77
command: com.github.elfenware.obliviate
88

99
finish-args:
1010
- '--share=ipc'
11+
- '--device=dri'
1112
- '--socket=fallback-x11'
1213
- '--socket=wayland'
1314

@@ -18,6 +19,15 @@ modules:
1819
- type: archive
1920
url: https://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-1.8.8.tar.bz2
2021
sha256: 895de2bb981dd127f0821d1ce13fadf7d760f9fa7737648b15f2c1fe13cc5af5
22+
modules:
23+
- name: libgpg-error
24+
buildsystem: autotools
25+
config-opts:
26+
- "--enable-install-gpg-error-config"
27+
sources:
28+
- type: archive
29+
url: https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-1.55.tar.gz
30+
sha256: bda09f51d7ed64565e41069d782bfcc4984aed908ae68bee01fb692b64ea96e2
2131
- name: obliviate
2232
buildsystem: meson
2333
sources:

data/com.github.elfenware.obliviate.appdata.xml.in renamed to data/com.github.elfenware.obliviate.metainfo.xml.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
<p>Bonus: If you need your passwords on another device, you can get them on the web from obliviate.app.</p>
2020
</description>
2121
<releases>
22+
<release version="3.0.0" date="2022-06-05">
23+
<description>
24+
<ul>
25+
<li>Move to modern tech</li>
26+
</ul>
27+
</description>
28+
</release>
2229
<release version="2.4.0" date="2022-06-05">
2330
<description>
2431
<ul>

data/meson.build

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ endforeach
1616
i18n.merge_file (
1717
input: meson.project_name () + '.desktop.in',
1818
output: meson.project_name () + '.desktop',
19-
po_dir: join_paths (meson.source_root (), 'po', 'extra'),
19+
po_dir: join_paths (meson.project_source_root (), 'po', 'extra'),
2020
type: 'desktop',
2121
install: true,
2222
install_dir: join_paths (get_option ('datadir'), 'applications')
2323
)
2424

2525
# Translate and install our .appdata.xml file so AppCenter will see it
2626
i18n.merge_file (
27-
input: meson.project_name () + '.appdata.xml.in',
28-
output: meson.project_name () + '.appdata.xml',
29-
po_dir: join_paths (meson.source_root (), 'po', 'extra'),
27+
input: meson.project_name () + '.metainfo.xml.in',
28+
output: meson.project_name () + '.metainfo.xml',
29+
po_dir: join_paths (meson.project_source_root (), 'po', 'extra'),
3030
install: true,
3131
install_dir: join_paths (get_option ('datadir'), 'metainfo')
3232
)

meson.build

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
project (
33
'com.github.elfenware.obliviate',
44
'vala', 'c',
5-
version: '2.4.0'
5+
version: '3.0.0'
66
)
77

88
# Translation module
@@ -38,9 +38,8 @@ asresources = gnome.compile_resources (
3838
# Listing dependencies
3939
dependencies = [
4040
dependency ('glib-2.0'),
41-
dependency ('granite'),
42-
dependency ('gtk+-3.0'),
43-
dependency ('libhandy-1'),
41+
dependency ('granite-7'),
42+
dependency ('gtk4'),
4443
declare_dependency (dependencies: [
4544
meson.get_compiler ('c').find_library ('libgcrypt'),
4645
meson.get_compiler ('vala').find_library ('gcrypt', dirs: join_paths (meson.current_source_dir (), 'vapi'))
@@ -62,4 +61,8 @@ executable (
6261
subdir('data')
6362
subdir('po')
6463

65-
meson.add_install_script ('meson/post_install.py')
64+
gnome.post_install(
65+
glib_compile_schemas: true,
66+
gtk_update_icon_cache: true,
67+
update_desktop_database: true
68+
)

meson/post_install.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

po/extra/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Install metadata translations
22
i18n.gettext ('extra',
33
args: [
4-
'--directory=' + meson.source_root (),
4+
'--directory=' + meson.project_source_root (),
55
'--from-code=UTF-8'
66
],
77
install: false

po/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Install main translations
22
i18n.gettext (meson.project_name (),
33
args: [
4-
'--directory=' + meson.source_root (),
4+
'--directory=' + meson.project_source_root (),
55
'--from-code=UTF-8',
66
'-cTRANSLATORS'
77
],

src/Application.vala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*/
2020

21-
public class Obliviate.Application : Granite.Application {
21+
public class Obliviate.Application : Gtk.Application {
2222
private Obliviate.MainWindow window;
2323

2424
public Application () {
@@ -52,8 +52,8 @@ public class Obliviate.Application : Granite.Application {
5252

5353
var provider = new Gtk.CssProvider ();
5454
provider.load_from_resource ("/com/github/elfenware/obliviate/Application.css");
55-
Gtk.StyleContext.add_provider_for_screen (
56-
Gdk.Screen.get_default (),
55+
Gtk.StyleContext.add_provider_for_display (
56+
Gdk.Display.get_default (),
5757
provider,
5858
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
5959
);

src/MainView.vala

Lines changed: 38 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,97 +18,81 @@
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. “GitHubequalsgithub”.")
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

Comments
 (0)