From bcd73051cd1c11ffd82aff4529cb57ee60df0e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Mon, 16 Oct 2023 07:46:56 -0700 Subject: [PATCH] Port to Gtk4 (#109) * Make compile * Can't subclass menubutton * Fix merge regressions * Fix cookie manager --- meson.build | 8 ++--- src/Application.vala | 5 ++-- src/MainWindow.vala | 66 ++++++++++++++++-------------------------- src/TabbedWebView.vala | 2 +- 4 files changed, 33 insertions(+), 48 deletions(-) diff --git a/meson.build b/meson.build index 86ff9ed..33176db 100644 --- a/meson.build +++ b/meson.build @@ -31,10 +31,10 @@ executable( dependency('gio-2.0'), dependency('glib-2.0'), dependency('gobject-2.0'), - dependency('gtk+-3.0'), - dependency('granite'), - dependency('libhandy-1', version: '>=1.0.0'), - dependency('webkit2gtk-4.1') + dependency('granite-7', version: '>=7.0.0'), + dependency('gtk4'), + dependency('libadwaita-1', version: '>=1.0.0'), + dependency('webkitgtk-6.0') ], install : true ) diff --git a/src/Application.vala b/src/Application.vala index d5e129f..3b32cdf 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -55,7 +55,7 @@ public class Captive.Application : Gtk.Application { main_window.maximize (); } - settings.bind ("is-maximized", main_window, "is-maximized", SettingsBindFlags.SET); + settings.bind ("is-maximized", main_window, "maximized", SettingsBindFlags.SET); main_window.start (debug_url); } @@ -64,7 +64,8 @@ public class Captive.Application : Gtk.Application { public override void startup () { base.startup (); - Hdy.init (); + Granite.init (); + Adw.init (); var granite_settings = Granite.Settings.get_default (); var gtk_settings = Gtk.Settings.get_default (); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 192a39c..a125814 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -18,9 +18,10 @@ * */ -public class Captive.MainWindow : Hdy.ApplicationWindow { +public class Captive.MainWindow : Gtk.ApplicationWindow { private const string DUMMY_URL = "http://capnet.elementary.io"; + private Adw.TabView tabview; private Granite.HeaderLabel cert_subject; private Gtk.Image popover_image; private Gtk.Label cert_expiry; @@ -28,7 +29,6 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { private Gtk.Label popover_label; private Gtk.Label title_label; private Gtk.MenuButton cert_button; - private Hdy.TabView tabview; // When a download is passed to the browser, it triggers the load failed signal private bool download_requested = false; @@ -49,7 +49,7 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { wrap = true, wrap_mode = WORD_CHAR }; - popover_label.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + popover_label.add_css_class (Granite.STYLE_CLASS_H3_LABEL); cert_subject = new Granite.HeaderLabel (""); @@ -65,10 +65,10 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { }; var cert_box = new Gtk.Box (VERTICAL, 3); - cert_box.get_style_context ().add_class (Gtk.STYLE_CLASS_VIEW); - cert_box.add (cert_subject); - cert_box.add (cert_issuer); - cert_box.add (cert_expiry); + cert_box.add_css_class (Granite.STYLE_CLASS_VIEW); + cert_box.append (cert_subject); + cert_box.append (cert_issuer); + cert_box.append (cert_expiry); var frame = new Gtk.Frame (null) { child = cert_box, @@ -85,45 +85,43 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { grid.attach (popover_image, 0, 0, 1, 2); grid.attach (popover_label, 1, 0); grid.attach (frame, 1, 1); - grid.show_all (); - var popover = new Gtk.Popover (null) { + var popover = new Gtk.Popover () { child = grid }; cert_button = new Gtk.MenuButton () { popover = popover }; - cert_button.get_style_context ().add_class ("titlebutton"); + cert_button.add_css_class ("titlebutton"); title_label = new Gtk.Label (_("Log in")); - title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE); + title_label.add_css_class (Granite.STYLE_CLASS_TITLE_LABEL); var header_box = new Gtk.Box (HORIZONTAL, 6); - header_box.add (cert_button); - header_box.add (title_label); + header_box.append (cert_button); + header_box.append (title_label); - var header = new Hdy.HeaderBar () { - custom_title = header_box, - show_close_button = true + titlebar = new Gtk.HeaderBar () { + title_widget = header_box, + show_title_buttons = true }; - header.get_style_context ().add_class ("default-decoration"); + titlebar.add_css_class ("default-decoration"); - tabview = new Hdy.TabView () { + tabview = new Adw.TabView () { hexpand = true, vexpand = true }; - var tabbar = new Hdy.TabBar () { + var tabbar = new Adw.TabBar () { expand_tabs = false, inverted = true, view = tabview }; var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - box.add (header); - box.add (tabbar); - box.add (tabview); + box.append (tabbar); + box.append (tabview); child = box; @@ -145,21 +143,18 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { } private void update_security (TabbedWebView web_view) { - string icon_name = web_view.security.to_icon_name (); - cert_button.image = new Gtk.Image.from_icon_name (icon_name, BUTTON); + cert_button.icon_name = icon_name = web_view.security.to_icon_name (); cert_button.tooltip_text = web_view.security_to_string (); popover_label.label = cert_button.tooltip_text; if (web_view.security == SECURE) { - popover_label.get_style_context ().remove_class (Gtk.STYLE_CLASS_WARNING); - popover_label.get_style_context ().add_class ("success"); + popover_label.css_classes = {"success"}; } else { - popover_label.get_style_context ().remove_class ("success"); - popover_label.get_style_context ().add_class (Gtk.STYLE_CLASS_WARNING); + popover_label.css_classes = {Granite.STYLE_CLASS_WARNING}; } - popover_image.icon_name = icon_name.replace ("-symbolic", ""); + popover_image.icon_name = cert_button.icon_name.replace ("-symbolic", ""); cert_button.sensitive = web_view.security != NONE && web_view.security != LOADING; @@ -236,7 +231,6 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { }); webview.load_uri (uri); - show_all (); return webview; } @@ -260,16 +254,6 @@ public class Captive.MainWindow : Hdy.ApplicationWindow { return true; }); - show_all (); - } - - public override bool delete_event (Gdk.EventAny event) { - int window_width; - int window_height; - get_size (out window_width, out window_height); - Captive.Application.settings.set_int ("window-width", window_width); - Captive.Application.settings.set_int ("window-height", window_height); - - return false; + present (); } } diff --git a/src/TabbedWebView.vala b/src/TabbedWebView.vala index 683313d..6319517 100644 --- a/src/TabbedWebView.vala +++ b/src/TabbedWebView.vala @@ -61,7 +61,7 @@ public class Captive.TabbedWebView : WebKit.WebView { ); if (FileUtils.test (cookies_db_path, FileTest.IS_REGULAR)) { - var cookie_manager = get_context ().get_cookie_manager (); + var cookie_manager = network_session.get_cookie_manager (); cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); cookie_manager.set_persistent_storage (cookies_db_path, WebKit.CookiePersistentStorage.SQLITE);