Skip to content

Commit

Permalink
Port to Gtk4 (#109)
Browse files Browse the repository at this point in the history
* Make compile

* Can't subclass menubutton

* Fix merge regressions

* Fix cookie manager
  • Loading branch information
danirabbit committed Oct 16, 2023
1 parent 9995c4a commit bcd7305
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 48 deletions.
8 changes: 4 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
5 changes: 3 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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 ();
Expand Down
66 changes: 25 additions & 41 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*
*/

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;
private Gtk.Label cert_issuer;
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;
Expand All @@ -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 ("");

Expand All @@ -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,
Expand All @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -236,7 +231,6 @@ public class Captive.MainWindow : Hdy.ApplicationWindow {
});

webview.load_uri (uri);
show_all ();

return webview;
}
Expand All @@ -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 ();
}
}
2 changes: 1 addition & 1 deletion src/TabbedWebView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bcd7305

Please sign in to comment.