general: Use stable rust dependencies

This commit is contained in:
Christopher Davis 2021-06-27 15:28:35 -07:00
parent 4ef2b61ecd
commit 73188840ae
6 changed files with 158 additions and 183 deletions

View file

@ -40,7 +40,13 @@ mod imp {
//
// For this derive macro, you need to have
// `use gtk::CompositeTemplate` in your code.
#[derive(Debug, CompositeTemplate)]
//
// Because all of our member fields implement the
// `Default` trait, we can use `#[derive(Default)]`.
// If some member fields did not implement default,
// we'd need to have a `new()` function in the
// `impl ObjectSubclass for $TYPE` section.
#[derive(Default, Debug, CompositeTemplate)]
#[template(resource = "/org/gnome/ImageViewer/gtk/window.ui")]
pub struct IvWindow {
// Template children are used with the
@ -58,33 +64,18 @@ mod imp {
pub open_gesture: TemplateChild<gtk::GestureClick>,
}
#[glib::object_subclass]
impl ObjectSubclass for IvWindow {
const NAME: &'static str = "IvWindow";
type Type = super::IvWindow;
type ParentType = libadwaita::ApplicationWindow;
type Interfaces = ();
type Instance = glib::subclass::simple::InstanceStruct<Self>;
type Class = glib::subclass::simple::ClassStruct<Self>;
glib::object_subclass!();
fn new() -> Self {
Self {
// For the initial value, use this function.
headerbar: TemplateChild::default(),
stack: TemplateChild::default(),
status_page: TemplateChild::default(),
image_view: TemplateChild::default(),
open_gesture: TemplateChild::default(),
}
}
fn class_init(klass: &mut Self::Class) {
// bind_template() is a function generated by the
// CompositeTemplate macro to bind all children at once.
Self::bind_template(klass);
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self::Type>) {
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
@ -104,7 +95,7 @@ mod imp {
// Set help overlay
let builder = gtk::Builder::from_resource("/org/gnome/ImageViewer/gtk/help_overlay.ui");
let help_overlay = builder.get_object("help_overlay").unwrap();
let help_overlay = builder.object("help_overlay").unwrap();
obj.set_help_overlay(Some(&help_overlay));
// For callbacks, you will want to reference the GTK docs on
@ -146,7 +137,7 @@ impl IvWindow {
self,
"toggle-fullscreen",
clone!(@weak self as win => move |_, _| {
win.set_property_fullscreened(!win.get_property_fullscreened());
win.set_fullscreened(!win.is_fullscreened());
})
);
@ -207,7 +198,7 @@ impl IvWindow {
chooser.connect_response(
clone!(@weak self as win, @strong chooser => move |_, resp| {
if resp == gtk::ResponseType::Accept {
if let Some(file) = chooser.get_file() {
if let Some(file) = chooser.file() {
win.set_image_from_file(&file);
}
}
@ -249,12 +240,12 @@ impl IvWindow {
pub fn set_image_from_file(&self, file: &gio::File) {
let imp = imp::IvWindow::from_instance(self);
log::debug!("Loading file: {}", file.get_uri().to_string());
log::debug!("Loading file: {}", file.uri().to_string());
imp.image_view.set_image_from_file(file);
imp.stack.set_visible_child(&*imp.image_view);
if let Some(name) = file.get_basename() {
if let Some(name) = file.basename() {
self.set_title(Some(
name.file_name().expect("Missing name").to_str().unwrap(),
));
@ -294,18 +285,18 @@ impl IvWindow {
let mut final_width = img_width;
let mut final_height = img_height;
let header_height = imp.headerbar.get_height();
let header_height = imp.headerbar.height();
// Ensure the window surface exists
if !self.get_realized() {
if !self.is_realized() {
self.realize();
}
let display = gdk::Display::get_default().unwrap();
let display = gdk::Display::default().unwrap();
let monitor = display
.get_monitor_at_surface(&self.get_native().unwrap().get_surface().unwrap())
.monitor_at_surface(&self.native().unwrap().surface().unwrap())
.unwrap();
let monitor_geometry = monitor.get_geometry();
let monitor_geometry = monitor.geometry();
let monitor_width = monitor_geometry.width;
let monitor_height = monitor_geometry.height;