Skip to content

Commit

Permalink
feat: Port MessageDialog & AboutWindow to Adw.Dialog (#21)
Browse files Browse the repository at this point in the history
* feat: Port MessageDialog & AboutWindow to `Adw.Dialog`

Update runtime version in the Flatpak manifest and GitHub CI to Nightly
to use `Adw.Dialog`.

`Adw.MessageDialog` -> `Adw.AlertDialog`
`Adw.AboutWindow` -> `Adw.AboutDialog`

* Manifest: bump to GNOME 46

* Manifest: switch back to 45 image

* MetaInfo: mention new dialogs

* Meson: bump Adwaita version to 1.5

---------

Co-authored-by: Cassidy James Blaede <[email protected]>
  • Loading branch information
sungsphinx and cassidyjames authored Mar 20, 2024
1 parent aaa6d0e commit 833219d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
1 change: 0 additions & 1 deletion com.cassidyjames.butler.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
}
]
}

1 change: 1 addition & 0 deletions data/metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<p>GNOME 46</p>
<ul>
<li>Target GNOME 46 runtime</li>
<li>Improved dialogs using new Adwaita widgets</li>
<li>Improved light brand color for Flathub and app store clients</li>
</ul>
</description>
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ executable(
dependencies: [
dependency('glib-2.0'),
dependency('gtk4'),
dependency('libadwaita-1', version: '>=1.4.2'),
dependency('libadwaita-1', version: '>=1.5'),
dependency('webkitgtk-6.0'),
meson.get_compiler('vala').find_library('posix'),
],
Expand Down
36 changes: 16 additions & 20 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

public class Butler.MainWindow : Adw.ApplicationWindow {
public Adw.AboutWindow about_window;
public Adw.AboutDialog about_dialog;
public Adw.Banner demo_banner;
public Adw.Toast fullscreen_toast;
public Adw.ToastOverlay toast_overlay;
Expand All @@ -23,9 +23,9 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
public MainWindow (Gtk.Application application) {
Object (
application: application,
height_request: 180,
height_request: 294,
resizable: true,
width_request: 300
width_request: 360
);
add_action_entries (ACTION_ENTRIES, this);
}
Expand All @@ -34,11 +34,9 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
maximized = App.settings.get_boolean ("window-maximized");
fullscreened = App.settings.get_boolean ("window-fullscreened");

about_window = new Adw.AboutWindow.from_appdata (
about_dialog = new Adw.AboutDialog.from_appdata (
"/com/cassidyjames/butler/metainfo.xml", VERSION
) {
transient_for = this,
hide_on_close = true,
comments = _("Companion app to access your Home Assistant dashboard"),

/// The translator credits. Please translate this with your name(s).
Expand All @@ -48,17 +46,17 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
"Tobias Bernard https://tobiasbernard.com/",
},
};
about_window.copyright = "© 2020–%i %s".printf (
about_dialog.copyright = "© 2020–%i %s".printf (
new DateTime.now_local ().get_year (),
about_window.developer_name
about_dialog.developer_name
);
about_window.add_link (_("About Home Assistant"), "https://www.home-assistant.io/");
about_window.add_link (_("Home Assistant Privacy Policy"), "https://www.home-assistant.io/privacy/");
about_dialog.add_link (_("About Home Assistant"), "https://www.home-assistant.io/");
about_dialog.add_link (_("Home Assistant Privacy Policy"), "https://www.home-assistant.io/privacy/");

// Set MainWindow properties from the AppData already fetched and parsed
// by the AboutWindow construction
icon_name = about_window.application_icon;
title = about_window.application_name;
// by the AboutDialog construction
icon_name = about_dialog.application_icon;
title = about_dialog.application_name;

var home_button = new Gtk.Button.from_icon_name ("go-home-symbolic") {
tooltip_text = _("Go Home")
Expand Down Expand Up @@ -282,8 +280,7 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
placeholder_text = default_server
};

var server_dialog = new Adw.MessageDialog (
this,
var server_dialog = new Adw.AlertDialog (
_("Set Server URL"),
_("Enter the full URL including any custom port")
) {
Expand All @@ -299,7 +296,7 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
server_dialog.add_response ("save", _("_Set Server"));
server_dialog.set_response_appearance ("save", Adw.ResponseAppearance.SUGGESTED);

server_dialog.present ();
server_dialog.present (this);

server_dialog.response.connect ((response_id) => {
if (response_id == "save") {
Expand Down Expand Up @@ -328,8 +325,7 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
private void on_log_out_activate () {
string server = App.settings.get_string ("server");

var log_out_dialog = new Adw.MessageDialog (
this,
var log_out_dialog = new Adw.AlertDialog (
_("Log out of Home Assistant?"),
_("You will need to re-enter your username and password for <b>%s</b> to log back in.").printf (server)
) {
Expand All @@ -340,7 +336,7 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
log_out_dialog.add_response ("log_out", _("_Log Out"));
log_out_dialog.set_response_appearance ("log_out", Adw.ResponseAppearance.DESTRUCTIVE);

log_out_dialog.present ();
log_out_dialog.present (this);

log_out_dialog.response.connect ((response_id) => {
if (response_id == "log_out") {
Expand All @@ -350,6 +346,6 @@ public class Butler.MainWindow : Adw.ApplicationWindow {
}

private void on_about_activate () {
about_window.present ();
about_dialog.present (this);
}
}

0 comments on commit 833219d

Please sign in to comment.