From 00e850dda383baf7cd17ca2ceabfbc401713db07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Tue, 10 Oct 2023 12:06:10 -0700 Subject: [PATCH] MainWindow: GTK 4 prep --- meson.build | 2 +- po/POTFILES | 6 +-- src/Application.vala | 29 +++++++++++++- src/CertButton.vala | 6 +-- src/{CaptiveLogin.vala => MainWindow.vala} | 46 ++++------------------ src/TabbedWebView.vala | 2 +- 6 files changed, 43 insertions(+), 48 deletions(-) rename src/{CaptiveLogin.vala => MainWindow.vala} (80%) diff --git a/meson.build b/meson.build index 806b525d..3ddd34a9 100644 --- a/meson.build +++ b/meson.build @@ -24,8 +24,8 @@ executable( meson.project_name(), config_file, 'src/Application.vala', - 'src/CaptiveLogin.vala', 'src/CertButton.vala', + 'src/MainWindow.vala', 'src/TabbedWebView.vala', dependencies: [ dependency('gcr-3'), diff --git a/po/POTFILES b/po/POTFILES index a19eeb1b..8f3d71bd 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -1,4 +1,4 @@ -src/TabbedWebView.vala -src/CertButton.vala -src/CaptiveLogin.vala src/Application.vala +src/CertButton.vala +src/MainWindow.vala +src/TabbedWebView.vala diff --git a/src/Application.vala b/src/Application.vala index e125601b..d5e129fe 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -46,11 +46,36 @@ public class Captive.Application : Gtk.Application { if (!is_busy) { mark_busy (); - var browser = new CaptiveLogin (this); - browser.start (debug_url); + var main_window = new MainWindow (this); + + settings.bind ("window-height", main_window, "default-height", DEFAULT); + settings.bind ("window-width", main_window, "default-width", DEFAULT); + + if (settings.get_boolean ("is-maximized")) { + main_window.maximize (); + } + + settings.bind ("is-maximized", main_window, "is-maximized", SettingsBindFlags.SET); + + main_window.start (debug_url); } } + public override void startup () { + base.startup (); + + Hdy.init (); + + var granite_settings = Granite.Settings.get_default (); + var gtk_settings = Gtk.Settings.get_default (); + + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == DARK; + + granite_settings.notify["prefers-color-scheme"].connect (() => { + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == DARK; + }); + } + public override int command_line (ApplicationCommandLine command_line) { OptionEntry[] options = new OptionEntry[1]; options[0] = { "url", 'u', 0, OptionArg.STRING, ref debug_url, _("Load this address in the browser window"), _("URL") }; diff --git a/src/CertButton.vala b/src/CertButton.vala index 0123b2cd..f6ecbe64 100644 --- a/src/CertButton.vala +++ b/src/CertButton.vala @@ -18,7 +18,7 @@ * */ -public class CertButton : Gtk.ToggleButton { +public class Captive.CertButton : Gtk.ToggleButton { public enum Security { NONE, SECURE, @@ -68,11 +68,11 @@ public class CertButton : Gtk.ToggleButton { } } - public CaptiveLogin captive_login_window { + public MainWindow captive_login_window { get; set construct; } - public CertButton (CaptiveLogin captive_login_window) { + public CertButton (MainWindow captive_login_window) { Object (security: Security.LOADING, captive_login_window: captive_login_window); } diff --git a/src/CaptiveLogin.vala b/src/MainWindow.vala similarity index 80% rename from src/CaptiveLogin.vala rename to src/MainWindow.vala index ba855163..23f75b24 100644 --- a/src/CaptiveLogin.vala +++ b/src/MainWindow.vala @@ -18,7 +18,7 @@ * */ -public class CaptiveLogin : Hdy.ApplicationWindow { +public class Captive.MainWindow : Hdy.ApplicationWindow { private const string DUMMY_URL = "http://capnet.elementary.io"; private CertButton cert_button; @@ -28,41 +28,22 @@ public class CaptiveLogin : Hdy.ApplicationWindow { // When a download is passed to the browser, it triggers the load failed signal private bool download_requested = false; - public CaptiveLogin (Gtk.Application app) { + public MainWindow (Gtk.Application app) { Object (application: app); - - set_default_size (Captive.Application.settings.get_int ("window-width"), Captive.Application.settings.get_int ("window-height")); - - if (Captive.Application.settings.get_boolean ("is-maximized")) { - maximize (); - } } construct { - Hdy.init (); - - var granite_settings = Granite.Settings.get_default (); - var gtk_settings = Gtk.Settings.get_default (); - - gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; - - granite_settings.notify["prefers-color-scheme"].connect (() => { - gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; - }); - cert_button = new CertButton (this); title_label = new Gtk.Label (_("Log in")); title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE); - var header_grid = new Gtk.Grid () { - column_spacing = 6 - }; - header_grid.add (cert_button); - header_grid.add (title_label); + var header_box = new Gtk.Box (HORIZONTAL, 6); + header_box.add (cert_button); + header_box.add (title_label); var header = new Hdy.HeaderBar () { - custom_title = header_grid, + custom_title = header_box, show_close_button = true }; header.get_style_context ().add_class ("default-decoration"); @@ -83,13 +64,7 @@ public class CaptiveLogin : Hdy.ApplicationWindow { box.add (tabbar); box.add (tabview); - add (box); - - set_keep_above (true); - skip_taskbar_hint = true; - stick (); - - this.destroy.connect (application.quit); + child = box; tabview.notify["selected-page"].connect (() => { var webview = (TabbedWebView) tabview.get_selected_page ().child; @@ -108,7 +83,7 @@ public class CaptiveLogin : Hdy.ApplicationWindow { }); } - bool is_privacy_mode_enabled () { + private bool is_privacy_mode_enabled () { var privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy"); return !privacy_settings.get_boolean ("remember-recent-files") || !privacy_settings.get_boolean ("remember-app-usage"); @@ -212,11 +187,6 @@ public class CaptiveLogin : Hdy.ApplicationWindow { 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); - if (is_maximized) { - Captive.Application.settings.set_boolean ("is-maximized", true); - } else { - Captive.Application.settings.set_boolean ("is-maximized", false); - } return false; } diff --git a/src/TabbedWebView.vala b/src/TabbedWebView.vala index 4853b9c9..ea90b7bc 100644 --- a/src/TabbedWebView.vala +++ b/src/TabbedWebView.vala @@ -18,7 +18,7 @@ * */ -public class TabbedWebView : WebKit.WebView { +public class Captive.TabbedWebView : WebKit.WebView { public bool load_cookies { get; construct; } public CertButton.Security security { get; private set; }