Skip to content

Commit

Permalink
Migrate to adaptive dialogs from libadwaita 1.5
Browse files Browse the repository at this point in the history
See: https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/migrating-to-adaptive-dialogs.html.

Can't say I'm a huge fan of them, but they're alright. This also means that
now application almost never opens another window - the only exception is
the shortcuts dialog, which is still a separate window, oddly enough.
  • Loading branch information
v1993 committed Aug 31, 2024
1 parent 76fd3dc commit 90da712
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Note for those using `flatpak-builder`: you'll want to update git submodules as

### Dependencies

* GTK >= 4.10
* libadwaita >= 1.4
* GTK >= 4.13
* libadwaita >= 1.5
* GLib >= 2.76
* GUsb (reasonably new)
* libportal (optional for non-sandbox builds)
Expand Down
21 changes: 8 additions & 13 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ namespace NXDumpClient {
}

public async bool query_app_exit() {
var dialog = new Adw.MessageDialog(main_window, _("Confirm exit"), _("A file transfer is currently in progress.\nAre you sure you want to quit?")) {
var dialog = new Adw.AlertDialog(_("Confirm exit"), _("A file transfer is currently in progress.\nAre you sure you want to quit?")) {
close_response = "cancel",
default_response = "confirm",

};
dialog.add_response("cancel", C_("deny app exit", "Cancel"));
dialog.add_response("confirm", C_("confirm app exit", "Confirm exit"));
dialog.set_response_appearance("confirm", DESTRUCTIVE);
var res = yield dialog.choose(cancellable);
var res = yield dialog.choose(main_window, cancellable);
return res == "confirm";
}

Expand Down Expand Up @@ -393,10 +393,8 @@ namespace NXDumpClient {
main_window.present();
#if PROMPT_FOR_UDEV_RULES
if (!prompted_for_udev_rules) {
var udev_dialog = new UdevRulesDialog() {
transient_for = main_window
};
udev_dialog.present();
var udev_dialog = new UdevRulesDialog();
udev_dialog.present(main_window);
}
#endif
}
Expand All @@ -410,8 +408,7 @@ namespace NXDumpClient {
}

private void on_about_action() {
var about = new Adw.AboutWindow.from_appdata("/org/v1993/NXDumpClient/appdata.xml", BuildConfig.VERSION) {
transient_for = main_window,
var about = new Adw.AboutDialog.from_appdata("/org/v1993/NXDumpClient/appdata.xml", BuildConfig.VERSION) {
translator_credits = _("translator-credits"),
developers = {
"v19930312"
Expand All @@ -427,15 +424,13 @@ namespace NXDumpClient {
}
);

about.present();
about.present(main_window);
}

private void on_preferences_action() {
var preferences = new PreferencesWindow() {
transient_for = main_window
};
var preferences = new PreferencesDialog();

preferences.present();
preferences.present(main_window);
}

private void on_show_file_action(SimpleAction action, Variant? param)
Expand Down
2 changes: 1 addition & 1 deletion src/PreferencesWindow.blp → src/PreferencesDialog.blp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Gtk 4.0;
using Adw 1;

template $NXDumpClientPreferencesWindow: Adw.PreferencesWindow {
template $NXDumpClientPreferencesDialog: Adw.PreferencesDialog {
Adw.PreferencesPage {
title: _("General settings");

Expand Down
23 changes: 17 additions & 6 deletions src/PreferencesWindow.vala → src/PreferencesDialog.vala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PreferencesWindow.vala
/* PreferencesDialog.vala
*
* Copyright 2023 v1993 <v19930312@gmail.com>
*
Expand All @@ -19,7 +19,7 @@
*/

// Debug option to use libportal even out of sandbox.
// This is theoretically safe to have always, but may hit bugs in portal backends.
// This is theoretically safe to have always on, but may hit bugs in portal backends.
private const bool FORCE_LIBPORTAL = false;

public enum NcaChecksumMode {
Expand All @@ -29,8 +29,8 @@ public enum NcaChecksumMode {
}

namespace NXDumpClient {
[GtkTemplate (ui = "/org/v1993/NXDumpClient/PreferencesWindow.ui")]
class PreferencesWindow: Adw.PreferencesWindow {
[GtkTemplate (ui = "/org/v1993/NXDumpClient/PreferencesDialog.ui")]
class PreferencesDialog: Adw.PreferencesDialog {
[GtkChild]
private unowned FileRow destination_directory;
[GtkChild]
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace NXDumpClient {
var app = new Application();
cancellable = new Cancellable();
app.cancellable.connect(cancellable.cancel);
// Cancel all pending operations once this window is closed to avoid references sticking around
// Cancel all pending operations once this dialog is closed to avoid references sticking around
((Gtk.Widget)this).unrealize.connect(this.on_unrealized);

notify["allow-background"].connect(this.background_changed);
Expand Down Expand Up @@ -154,6 +154,17 @@ namespace NXDumpClient {
}

#if WITH_LIBPORTAL
private Xdp.Parent? make_xdp_parent() {
var? toplevel = get_root() as Gtk.Window;
if (toplevel == null) {
// This is unexpected, but not critical
warning("Failed to find root window for preferences dialog");
return null;
}

return Xdp.parent_new_gtk(toplevel);
}

private async void request_background() {
/*
* The following cases require us to make a request:
Expand Down Expand Up @@ -190,7 +201,7 @@ namespace NXDumpClient {
var flags = need_autostart ? Xdp.BackgroundFlags.AUTOSTART : Xdp.BackgroundFlags.NONE;
debug("Requesting background, autostart: %s", need_autostart.to_string());
authorized = yield portal.request_background(
Xdp.parent_new_gtk(this),
make_xdp_parent(),
C_("reason for background activity", "Dumping applications without interaction"),
autostart_cmd,
flags,
Expand Down
22 changes: 12 additions & 10 deletions src/UdevRulesDialog.blp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Gtk 4.0;
using Adw 1;

template $NXDumpClientUdevRulesDialog: Adw.Window {
template $NXDumpClientUdevRulesDialog: Adw.Dialog {
title: _("Udev rules installation");
modal: true;

content: Adw.ToolbarView {
child: Adw.ToolbarView {
[top]
Adw.HeaderBar {
}
Expand All @@ -14,21 +13,24 @@ template $NXDumpClientUdevRulesDialog: Adw.Window {
margin-start: 5;
margin-end: 5;
margin-bottom: 5;
spacing: 20;
orientation: vertical;

spacing: 20;
Label {
styles [ "title-4" ]
halign: center;
justify: center;
label: _("Udev rules must be installed for this program to work.\nPlease exectute the following command to do so:");
wrap: true;
label: _("Udev rules must be installed for this program to work. Please exectute the following command to do so:");
}

Label {
halign: center;
justify: center;
selectable: true;
label: bind template.command_line_for_installation;
Gtk.ScrolledWindow {
child: Label {
halign: center;
justify: center;
selectable: true;
label: bind template.command_line_for_installation;
};
}

CheckButton checkbox {
Expand Down
2 changes: 1 addition & 1 deletion src/UdevRulesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#if PROMPT_FOR_UDEV_RULES
namespace NXDumpClient {
[GtkTemplate (ui = "/org/v1993/NXDumpClient/UdevRulesDialog.ui")]
public class UdevRulesDialog: Adw.Window {
public class UdevRulesDialog: Adw.Dialog {
protected string command_line_for_installation {
owned get {
var cmd = argv0;
Expand Down
8 changes: 4 additions & 4 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ nxdc_sources_native = [

'Application.vala',
'Window.vala',
'PreferencesWindow.vala',
'PreferencesDialog.vala',
'UdevRulesDialog.vala',
'UsbContext.vala',
'UsbDeviceClient.vala',
Expand All @@ -19,7 +19,7 @@ nxdc_sources_native = [

nxdc_blueprints = files(
'Window.blp',
'PreferencesWindow.blp',
'PreferencesDialog.blp',
'UdevRulesDialog.blp',

'gtk/help-overlay.blp',
Expand All @@ -32,8 +32,8 @@ extra_vala_args = []
nxdc_deps = [
dependency('glib-2.0', version: '>=2.76'),
dependency('gio-2.0'),
dependency('gtk4', version: '>=4.10'),
dependency('libadwaita-1', version: '>= 1.4'),
dependency('gtk4', version: '>=4.13'),
dependency('libadwaita-1', version: '>= 1.5'),

dependency('gusb'),
]
Expand Down
2 changes: 1 addition & 1 deletion src/nxdumpclient.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<gresources>
<gresource prefix="/org/v1993/NXDumpClient">
<file preprocess="xml-stripblanks">Window.ui</file>
<file preprocess="xml-stripblanks">PreferencesWindow.ui</file>
<file preprocess="xml-stripblanks">PreferencesDialog.ui</file>
<file preprocess="xml-stripblanks">UdevRulesDialog.ui</file>

<file preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
Expand Down

0 comments on commit 90da712

Please sign in to comment.