Skip to content

Commit

Permalink
feat(gtk): Display dialog with changelogs when clicking devices
Browse files Browse the repository at this point in the history
When a device is clicked, a dialog will appear with a changelog of past
releases. If the device has updates available, the updates button will
also be displayed, else otherwise hidden.

Closes #7
  • Loading branch information
mmstick committed Aug 13, 2019
1 parent 825693d commit 527ccfc
Show file tree
Hide file tree
Showing 5 changed files with 288 additions and 149 deletions.
17 changes: 9 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions gtk/src/dialogs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use gtk::prelude::*;
pub struct FirmwareUpdateDialog(gtk::Dialog);

impl FirmwareUpdateDialog {
pub fn new<S: AsRef<str>, I: Iterator<Item = (S, S)>>(version: &str, changelog: I) -> Self {
pub fn new<S: AsRef<str>, I: Iterator<Item = (S, S)>>(
version: &str,
changelog: I,
upgradeable: bool,
needs_reboot: bool,
) -> Self {
let changelog_entries = &cascade! {
gtk::Box::new(gtk::Orientation::Vertical, 12);
};
Expand Down Expand Up @@ -34,7 +39,7 @@ impl FirmwareUpdateDialog {

let reboot = cascade! {
gtk::ButtonBuilder::new()
.label("Reboot and Install")
.label(if needs_reboot { "Reboot and Install" } else { "Install" })
.build();
..get_style_context().add_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
};
Expand Down Expand Up @@ -106,6 +111,8 @@ impl FirmwareUpdateDialog {
});
};

dialog.show_all();

{
let dialog = dialog.downgrade();
cancel.connect_clicked(move |_| {
Expand All @@ -115,13 +122,15 @@ impl FirmwareUpdateDialog {
});
}

{
if upgradeable {
let dialog = dialog.downgrade();
reboot.connect_clicked(move |_| {
if let Some(dialog) = dialog.upgrade() {
dialog.response(gtk::ResponseType::Accept);
}
});
} else {
reboot.hide();
}

Self(dialog)
Expand Down
Loading

0 comments on commit 527ccfc

Please sign in to comment.