Skip to content

Commit

Permalink
chore: Update to gtk-rs 0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 authored and jackpot51 committed Oct 8, 2021
1 parent cdafbb6 commit 9d19f0a
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 129 deletions.
232 changes: 149 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions gtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ cascade = "1.0"
clap = "2.33"
fern = "0.6"
firmware-manager = { path = "../" }
gdk = "0.13"
gio = "0.9"
glib = "0.10"
gtk = { version = "0.9", features = [ "v3_22" ] }
gdk = "0.14"
gio = "0.14"
glib = "0.14"
gtk = { version = "0.14", features = [ "v3_22" ] }
html2runes = "1.0"
log = "0.4"
shrinkwraprs = "0.3"
Expand All @@ -30,4 +30,4 @@ rust-embed = "5.9.0"
once_cell = "1.7.2"

# Rust 1.49 required to update
slotmap = "0.4"
slotmap = "0.4"
8 changes: 4 additions & 4 deletions gtk/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ crate-type = [ "cdylib" ]
cdylib-link-lines = "0.1"

[dependencies]
glib = "0.10.0"
gtk-sys = "0.10.0"
gtk = "0.9.0"
glib = "0.14.0"
gtk-sys = "0.14.0"
gtk = "0.14.0"
firmware-manager-gtk = { path = "../", default-features = false, features = [ "fwupd","system76", ] }
i18n-embed = { version = "0.12.0", features = ["fluent-system", "desktop-requester"] }
i18n-embed-fl = "0.5.0"
rust-embed = "5.9.0"
once_cell = "1.7.2"
once_cell = "1.7.2"
6 changes: 3 additions & 3 deletions gtk/src/dialogs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl FirmwareUpdateDialog {
gtk::ButtonBuilder::new()
.label(&fl!("button-reboot-and-install"))
.build();
..get_style_context().add_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
..style_context().add_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
};

let dialog = gtk::DialogBuilder::new()
Expand All @@ -66,7 +66,7 @@ impl FirmwareUpdateDialog {
.build();

let headerbar = dialog
.get_header_bar()
.header_bar()
.expect("dialog generated without header bar")
.downcast::<gtk::HeaderBar>()
.expect("dialog header bar is not a header bar");
Expand All @@ -85,7 +85,7 @@ impl FirmwareUpdateDialog {
};

cascade! {
dialog.get_content_area();
dialog.content_area();
..set_orientation(gtk::Orientation::Horizontal);
..set_border_width(12);
..set_spacing(12);
Expand Down
9 changes: 5 additions & 4 deletions gtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use std::{
Arc,
},
thread::{self, JoinHandle},
time::Duration,
};
use yansi::Paint;

Expand Down Expand Up @@ -122,7 +123,7 @@ impl FirmwareWidget {
..set_no_show_all(true);
};

let area = info_bar.get_content_area();
let area = info_bar.content_area();
area.add(&info_bar_label);

let stack = cascade! {
Expand Down Expand Up @@ -151,7 +152,7 @@ impl FirmwareWidget {
..add(&stack);
..set_can_default(true);
..connect_key_press_event(move |_, event| {
gtk::Inhibit(if event.get_keyval() == gdk::keys::constants::F5 {
gtk::Inhibit(if event.keyval() == gdk::keys::constants::F5 {
let _ = sender.send(FirmwareEvent::Scan);
true
} else {
Expand Down Expand Up @@ -389,7 +390,7 @@ impl FirmwareWidget {
fn connect_progress_events(rx_progress: Receiver<ActivateEvent>) {
let mut active_widgets: HashSet<gtk::ProgressBar> = HashSet::new();
let mut remove = Vec::new();
glib::timeout_add_local(100, move || {
glib::timeout_add_local(Duration::from_millis(100), move || {
loop {
match rx_progress.try_recv() {
Ok(ActivateEvent::Activate(widget)) => {
Expand All @@ -415,7 +416,7 @@ impl FirmwareWidget {
}

for widget in &active_widgets {
let new_value = widget.get_fraction() + widget.get_pulse_step();
let new_value = widget.fraction() + widget.pulse_step();
widget.set_fraction(if new_value > 1.0 { 1.0 } else { new_value });
}

Expand Down
10 changes: 5 additions & 5 deletions gtk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() {
let application = gtk::ApplicationBuilder::new().application_id(APP_ID).build();

application.connect_activate(|app| {
if let Some(window) = app.get_window_by_id(0) {
if let Some(window) = app.window_by_id(0) {
window.present();
}
});
Expand Down Expand Up @@ -76,9 +76,9 @@ fn main() {
});
..connect_key_press_event(move |window, event| {
use gdk::keys::constants as key;
gtk::Inhibit(match event.get_keyval() {
key::q if event.get_state().contains(gdk::ModifierType::CONTROL_MASK) => {
let _ = window.emit("delete-event", &[&gdk::Event::new(gdk::EventType::Delete)]);
gtk::Inhibit(match event.keyval() {
key::q if event.state().contains(gdk::ModifierType::CONTROL_MASK) => {
let _ = window.emit_by_name("delete-event", &[&gdk::Event::new(gdk::EventType::Delete)]);
true
}
_ => false
Expand All @@ -87,7 +87,7 @@ fn main() {
};
});

application.run(&[]);
application.run();
}

/// Manages argument parsing for the GTK application via clap.
Expand Down
4 changes: 2 additions & 2 deletions gtk/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ fn reveal<F: FnMut() -> gtk::Container>(
entity: Entity,
mut func: F,
) {
let reveal = if revealer.get_reveal_child() {
let reveal = if revealer.is_child_revealed() {
false
} else {
// If the content to be revealed has not been generated yet, do so.
if revealer.get_child().is_none() {
if revealer.child().is_none() {
let widget = func();

let container = cascade! {
Expand Down
8 changes: 4 additions & 4 deletions gtk/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use core::num::NonZeroU8;

pub trait DynamicGtkResize
where
Self: gtk::WidgetExt,
Self: gtk::traits::WidgetExt,
{
/// When this widget is resized, the `other` widget will also be resized to the given width and
/// height percent (1-100);
///
/// This is most useful for dynamically resizing the child of a container to be a certain % of
/// the parent's dimensions.
fn dynamic_resize<W: gtk::WidgetExt + 'static>(
fn dynamic_resize<W: gtk::traits::WidgetExt + 'static>(
&self,
other: W,
width_percent: Option<NonZeroU8>,
Expand Down Expand Up @@ -37,7 +37,7 @@ where
// yet, so this will ensure that we get the correct value after init.
let parent = self.clone();
glib::idle_add_local(move || {
parent.size_allocate(&mut parent.get_allocation());
parent.size_allocate(&mut parent.allocation());
glib::Continue(false)
});
}
Expand All @@ -47,4 +47,4 @@ fn calc_side(measurement: i32, percent: NonZeroU8) -> i32 {
measurement * i32::from(percent.get()) / 100
}

impl<T: gtk::WidgetExt> DynamicGtkResize for T {}
impl<T: gtk::traits::WidgetExt> DynamicGtkResize for T {}
26 changes: 13 additions & 13 deletions gtk/src/views/devices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ impl DevicesView {
..set_margin_bottom(12);
..set_selection_mode(gtk::SelectionMode::None);
..connect_row_activated(move |_, row| {
let widget = row.get_child()
let widget = row.child()
.and_then(|w| w.downcast::<gtk::Box>().ok())
.and_then(|w| w.get_children().into_iter().next());
.and_then(|w| w.children().into_iter().next());

if let Some(widget) = widget {
let _ = widget.emit("button_press_event", &[&gdk::Event::new(gdk::EventType::ButtonPress)]);
let _ = widget.emit_by_name("button_press_event", &[&gdk::Event::new(gdk::EventType::ButtonPress)]);
}
});
};
Expand All @@ -44,23 +44,23 @@ impl DevicesView {
..set_no_show_all(true);
..set_selection_mode(gtk::SelectionMode::None);
..connect_row_activated(move |_, row| {
let widget = row.get_child()
let widget = row.child()
.and_then(|w| w.downcast::<gtk::Box>().ok())
.and_then(|w| w.get_children().into_iter().next());
.and_then(|w| w.children().into_iter().next());

if let Some(widget) = widget {
let _ = widget.emit("button_press_event", &[&gdk::Event::new(gdk::EventType::ButtonPress)]);
let _ = widget.emit_by_name("button_press_event", &[&gdk::Event::new(gdk::EventType::ButtonPress)]);
}
});
..connect_key_press_event(move |listbox, event| {
gtk::Inhibit(
if event.get_keyval() == gdk::keys::constants::Up {
listbox.get_children()
if event.keyval() == gdk::keys::constants::Up {
listbox.children()
.into_iter()
.filter_map(|widget| widget.downcast::<gtk::ListBoxRow>().ok())
.next()
.and_then(|row| if row.has_focus() { upper.upgrade() } else { None })
.and_then(|upper| upper.get_children().into_iter().last())
.and_then(|upper| upper.children().into_iter().last())
.map_or(false, |child| {
child.grab_focus();
true
Expand All @@ -74,14 +74,14 @@ impl DevicesView {

let lower = device_firmware.downgrade();
system_firmware.connect_key_press_event(move |listbox, event| {
gtk::Inhibit(if event.get_keyval() == gdk::keys::constants::Down {
gtk::Inhibit(if event.keyval() == gdk::keys::constants::Down {
listbox
.get_children()
.children()
.into_iter()
.filter_map(|widget| widget.downcast::<gtk::ListBoxRow>().ok())
.last()
.and_then(|row| if row.has_focus() { lower.upgrade() } else { None })
.and_then(|lower| lower.get_children().into_iter().next())
.and_then(|lower| lower.children().into_iter().next())
.map_or(false, |child| {
child.grab_focus();
true
Expand Down Expand Up @@ -195,7 +195,7 @@ impl DevicesView {
///
/// This is responsible for creating a device widget and assigning it to the given parent
/// container.
fn append(&self, parent: &impl gtk::ContainerExt, info: &FirmwareInfo) -> DeviceWidget {
fn append(&self, parent: &impl gtk::traits::ContainerExt, info: &FirmwareInfo) -> DeviceWidget {
let widget = DeviceWidget::new(info);
self.sg.add_widget(&widget.event_box);
parent.add(widget.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion gtk/src/views/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn error_view(icon: &str, reason: &str) -> gtk::Container {
.xalign(0.0)
.yalign(0.0)
.build();
..get_style_context().add_class(&gtk::STYLE_CLASS_DIM_LABEL);
..style_context().add_class(&gtk::STYLE_CLASS_DIM_LABEL);
});
..show_all();
};
Expand Down
8 changes: 4 additions & 4 deletions gtk/src/widgets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl DeviceWidget {
.xalign(0.0)
.valign(gtk::Align::Start)
.build();
..get_style_context().add_class(&gtk::STYLE_CLASS_DIM_LABEL);
..style_context().add_class(&gtk::STYLE_CLASS_DIM_LABEL);
};

let button = cascade! {
Expand All @@ -63,7 +63,7 @@ impl DeviceWidget {
.hexpand(true)
.vexpand(true)
.build();
..get_style_context().add_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
..style_context().add_class(&gtk::STYLE_CLASS_SUGGESTED_ACTION);
};

let progress = cascade! {
Expand Down Expand Up @@ -96,11 +96,11 @@ impl DeviceWidget {
let dropdown_image_ = dropdown_image.downgrade();
let revealer = cascade! {
gtk::Revealer::new();
..connect_property_reveal_child_notify(move |revealer| {
..connect_reveal_child_notify(move |revealer| {
dropdown_image_.upgrade()
.expect("dropdown image did not exist")
.set_from_icon_name(
Some(if revealer.get_reveal_child() {
Some(if revealer.is_child_revealed() {
"pan-down-symbolic"
} else {
"pan-end-symbolic"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.47.0
1.51.0

0 comments on commit 9d19f0a

Please sign in to comment.