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

@ -38,22 +38,18 @@ mod imp {
}
// Sets up the basics for the GObject
// The `#[glib::object_subclass] macro implements
// some boilerplate code for the object setup, e.g. get_type()
#[glib::object_subclass]
impl ObjectSubclass for IvApplication {
const NAME: &'static str = "IvApplication";
type Type = super::IvApplication;
type ParentType = gtk::Application;
type Interfaces = ();
type Instance = glib::subclass::simple::InstanceStruct<Self>;
type Class = glib::subclass::simple::ClassStruct<Self>;
// This macro implements some boilerplate code
// for the object setup, e.g. get_type()
glib::object_subclass!();
// Initialize with default values
fn new() -> Self {
let gtk_settings =
gtk::Settings::get_default().expect("Could not get default GTK settings");
gtk::Settings::default().expect("Could not get default GTK settings");
Self { gtk_settings }
}
@ -65,12 +61,12 @@ mod imp {
self.parent_constructed(obj);
// Set up the CSS and force dark theme
let display = gdk::Display::get_default().unwrap();
let display = gdk::Display::default().unwrap();
let provider = gtk::CssProvider::new();
provider.load_from_resource("/org/gnome/ImageViewer/image-viewer.css");
gtk::StyleContext::add_provider_for_display(&display, &provider, 600);
self.gtk_settings
.set_property_gtk_application_prefer_dark_theme(true);
.set_gtk_application_prefer_dark_theme(true);
// Set up the actions
obj.setup_actions();
@ -195,7 +191,7 @@ impl IvApplication {
.version(config::VERSION)
.build();
if let Some(window) = self.get_active_window() {
if let Some(window) = self.active_window() {
dialog.set_modal(true);
dialog.set_transient_for(Some(&window));
}

View file

@ -42,6 +42,6 @@ fn main() {
gio::resources_register(&res);
let app = IvApplication::new();
let ret = app.run(&std::env::args().collect::<Vec<_>>());
let ret = app.run();
std::process::exit(ret);
}

View file

@ -60,15 +60,11 @@ mod imp {
pub popover_menu_model: RefCell<Option<gio::MenuModel>>,
}
#[glib::object_subclass]
impl ObjectSubclass for IvImageView {
const NAME: &'static str = "IvImageView";
type Type = super::IvImageView;
type ParentType = libadwaita::Bin;
type Interfaces = ();
type Instance = subclass::simple::InstanceStruct<Self>;
type Class = subclass::simple::ClassStruct<Self>;
glib::object_subclass!();
fn new() -> Self {
let connection =
@ -92,7 +88,7 @@ mod imp {
Self::bind_template(klass);
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self::Type>) {
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
@ -101,21 +97,21 @@ mod imp {
fn properties() -> &'static [glib::ParamSpec] {
static PROPERTIES: Lazy<Vec<glib::ParamSpec>> = Lazy::new(|| {
vec![
glib::ParamSpec::boolean(
glib::ParamSpec::new_boolean(
"header-visible",
"Header visible",
"Whether or not the headerbar is visible",
false,
glib::ParamFlags::READWRITE,
),
glib::ParamSpec::object(
glib::ParamSpec::new_object(
"primary-menu-model",
"Primary Menu Model",
"The menu model for the menu button",
gio::MenuModel::static_type(),
glib::ParamFlags::READWRITE,
),
glib::ParamSpec::object(
glib::ParamSpec::new_object(
"popover-menu-model",
"Popover Menu Model",
"The menu model for the menu button",
@ -148,13 +144,8 @@ mod imp {
SIGNALS.as_ref()
}
fn get_property(
&self,
_obj: &Self::Type,
_id: usize,
psec: &glib::ParamSpec,
) -> glib::Value {
match psec.get_name() {
fn property(&self, _obj: &Self::Type, _id: usize, psec: &glib::ParamSpec) -> glib::Value {
match psec.name() {
"header-visible" => self.header_visible.get().to_value(),
"primary-menu-model" => self.menu_model.borrow().to_value(),
"popover-menu-model" => self.popover_menu_model.borrow().to_value(),
@ -169,10 +160,9 @@ mod imp {
value: &glib::Value,
psec: &glib::ParamSpec,
) {
match psec.get_name() {
match psec.name() {
"header-visible" => {
self.header_visible
.set(value.get().unwrap().unwrap_or_default());
self.header_visible.set(value.get::<bool>().unwrap());
}
"primary-menu-model" => {
let model: Option<gio::MenuModel> = value.get().unwrap();
@ -231,9 +221,9 @@ impl IvImageView {
}
fn load_dimensions_from_file(&self, file: &gio::File) -> anyhow::Result<()> {
let pb = file.get_path().context("No path for current file")?;
let pb = file.path().context("No path for current file")?;
let (_, width, height) =
gdk_pixbuf::Pixbuf::get_file_info(&pb.as_path()).context("Could not get file info")?;
gdk_pixbuf::Pixbuf::file_info(&pb.as_path()).context("Could not get file info")?;
log::debug!("Image dimensions: {} x {}", width, height);
let _ = self.emit_by_name("dimensions-loaded", &[&width, &height]);
@ -264,9 +254,9 @@ impl IvImageView {
pub fn print(&self) -> anyhow::Result<()> {
let imp = imp::IvImageView::from_instance(&self);
let file = imp.picture.get_file().context("No file to print")?;
let file = imp.picture.file().context("No file to print")?;
let operation = gtk::PrintOperation::new();
let path = file.get_path().context("No path for current file")?;
let path = file.path().context("No path for current file")?;
let pb = gdk_pixbuf::Pixbuf::from_file(path)?;
let setup = gtk::PageSetup::default();
@ -282,13 +272,13 @@ impl IvImageView {
});
operation.connect_draw_page(clone!(@weak pb => move |_, ctx, _| {
let cr = ctx.get_cairo_context().expect("No cairo context for print context");
let cr = ctx.cairo_context().expect("No cairo context for print context");
cr.set_source_pixbuf(&pb, 0.0, 0.0);
cr.paint();
}));
log::debug!("Running print operation...");
let root = self.get_root().context("Could not get root for widget")?;
let root = self.root().context("Could not get root for widget")?;
let window = root
.downcast_ref::<gtk::Window>()
.context("Could not downcast to GtkWindow")?;
@ -299,8 +289,8 @@ impl IvImageView {
pub fn uri(&self) -> Option<String> {
let imp = imp::IvImageView::from_instance(&self);
let file = imp.picture.get_file()?;
Some(file.get_uri().to_string())
let file = imp.picture.file()?;
Some(file.uri().to_string())
}
pub fn show_popover_at(&self, x: f64, y: f64) {
@ -322,9 +312,9 @@ impl IvImageView {
f: F,
) -> glib::SignalHandlerId {
self.connect_local("dimensions-loaded", true, move |values| {
let view = values[0].get::<Self>().unwrap().unwrap();
let width = values[1].get::<i32>().unwrap().unwrap();
let height = values[2].get::<i32>().unwrap().unwrap();
let view = values[0].get::<Self>().unwrap();
let width = values[1].get::<i32>().unwrap();
let height = values[2].get::<i32>().unwrap();
f(&view, width, height);

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;