Skip to content

Commit

Permalink
dialog.run () → dialogresponse.connect () (#273)
Browse files Browse the repository at this point in the history
* dialog.run () → dialogresponse.connect ()

* Destroy before resetting

---------

Co-authored-by: Jeremy Wootten <jeremy@elementaryos.org>
  • Loading branch information
danirabbit and Jeremy Wootten authored Oct 19, 2023
1 parent 132fc90 commit 4ad86e9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 40 deletions.
59 changes: 35 additions & 24 deletions src/Views/FirmwareView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,24 @@ public class About.FirmwareView : Granite.SimpleSettingsPage {
detach_image = yield download_file (device, detach_image);
}

if (show_details_dialog (device, detach_caption, detach_image) == false) {
stack.visible_child = deck;
return;
}
var details_dialog = show_details_dialog (device, detach_caption, detach_image);
details_dialog.response.connect ((response) => {
details_dialog.destroy ();
if (response == Gtk.ResponseType.ACCEPT) {
continue_update.begin (device, release);
} else {
stack.visible_child = deck;
return;
}
});

details_dialog.present ();
} else {
continue_update.begin (device, release);
}
}

private async void continue_update (Fwupd.Device device, Fwupd.Release release) {
var path = yield download_file (device, release.get_uri ());

try {
Expand Down Expand Up @@ -317,12 +329,12 @@ public class About.FirmwareView : Granite.SimpleSettingsPage {
badge_icon = new ThemedIcon ("dialog-error"),
transient_for = (Gtk.Window) get_toplevel ()
};
message_dialog.show_all ();
message_dialog.run ();
message_dialog.destroy ();

message_dialog.response.connect (message_dialog.destroy);
message_dialog.present ();
}

private bool show_details_dialog (Fwupd.Device device, string detach_caption, string? detach_image) {
private Granite.MessageDialog show_details_dialog (Fwupd.Device device, string detach_caption, string? detach_image) {
var gicon = new ThemedIcon ("application-x-firmware");
var icons = device.get_icons ();
if (icons.data != null) {
Expand All @@ -347,12 +359,7 @@ public class About.FirmwareView : Granite.SimpleSettingsPage {
message_dialog.custom_bin.add (custom_widget);
}

message_dialog.show_all ();
bool should_continue = message_dialog.run () == Gtk.ResponseType.ACCEPT;

message_dialog.destroy ();

return should_continue;
return message_dialog;
}

private void show_reboot_dialog () {
Expand All @@ -369,12 +376,14 @@ public class About.FirmwareView : Granite.SimpleSettingsPage {
var suggested_button = (Gtk.Button) message_dialog.add_button (_("Restart"), Gtk.ResponseType.ACCEPT);
suggested_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);

message_dialog.show_all ();
if (message_dialog.run () == Gtk.ResponseType.ACCEPT) {
LoginManager.get_instance ().reboot ();
}
message_dialog.response.connect ((response) => {
if (response == Gtk.ResponseType.ACCEPT) {
LoginManager.get_instance ().reboot ();
}
message_dialog.destroy ();
});

message_dialog.destroy ();
message_dialog.present ();
}

private void show_shutdown_dialog () {
Expand All @@ -391,12 +400,14 @@ public class About.FirmwareView : Granite.SimpleSettingsPage {
var suggested_button = (Gtk.Button) message_dialog.add_button (_("Shut Down"), Gtk.ResponseType.ACCEPT);
suggested_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);

message_dialog.show_all ();
if (message_dialog.run () == Gtk.ResponseType.ACCEPT) {
LoginManager.get_instance ().shutdown ();
}
message_dialog.response.connect ((response) => {
if (response == Gtk.ResponseType.ACCEPT) {
LoginManager.get_instance ().shutdown ();
}
message_dialog.destroy ();
});

message_dialog.destroy ();
message_dialog.present ();
}

private void reboot_to_firmware_setup_clicked () {
Expand Down
26 changes: 10 additions & 16 deletions src/Views/OperatingSystemView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,7 @@ public class About.OperatingSystemView : Gtk.Grid {
}
}

/**
* returns true to continue, false to cancel
*/
private bool confirm_restore_action () {
private void settings_restore_clicked () {
var dialog = new Granite.MessageDialog.with_image_from_icon_name (
_("System Settings Will Be Restored to The Factory Defaults"),
_("All system settings and data will be reset to the default values. Personal data, such as music and pictures, will be unaffected."),
Expand All @@ -253,20 +250,17 @@ public class About.OperatingSystemView : Gtk.Grid {
var continue_button = dialog.add_button (_("Restore Settings"), Gtk.ResponseType.ACCEPT);
continue_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);

var result = dialog.run ();
dialog.destroy ();

return result == Gtk.ResponseType.ACCEPT;
}

private void settings_restore_clicked () {
if (confirm_restore_action ()) {
var all_schemas = get_pantheon_schemas ();
dialog.response.connect ((response) => {
dialog.destroy ();
if (response == Gtk.ResponseType.ACCEPT) {
var all_schemas = get_pantheon_schemas ();

foreach (var schema in all_schemas) {
reset_recursively (schema);
foreach (var schema in all_schemas) {
reset_recursively (schema);
}
}
}
});
dialog.present ();
}

private static void reset_all_keys (GLib.Settings settings) {
Expand Down

0 comments on commit 4ad86e9

Please sign in to comment.