Skip to content

Commit

Permalink
MainWindow: GTK 4 prep
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Oct 10, 2023
1 parent 0ab0d36 commit 00e850d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
6 changes: 3 additions & 3 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -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
29 changes: 27 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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") };
Expand Down
6 changes: 3 additions & 3 deletions src/CertButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

public class CertButton : Gtk.ToggleButton {
public class Captive.CertButton : Gtk.ToggleButton {
public enum Security {
NONE,
SECURE,
Expand Down Expand Up @@ -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);
}

Expand Down
46 changes: 8 additions & 38 deletions src/CaptiveLogin.vala → src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TabbedWebView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down

0 comments on commit 00e850d

Please sign in to comment.