cargo: Update dependencies

This commit is contained in:
Sophie Herold 2022-11-02 21:11:43 +01:00
parent 743577757f
commit 3d6564377a
11 changed files with 574 additions and 271 deletions

654
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,33 +4,34 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
anyhow = "1.0.35" anyhow = "1.0.66"
gtk-macros = "0.3.0" gtk-macros = "0.3.0"
log = "0.4.11" log = "0.4.17"
once_cell = "1.9.0" once_cell = "1.16.0"
pretty_env_logger = "0.4.0" pretty_env_logger = "0.4.0"
futures-channel = "0.3.19" futures-channel = "0.3.25"
futures = "0.3.21" futures = "0.3.25"
svg_metadata = "0.4.2" svg_metadata = "0.4.3"
regex = "1.6.0" regex = "1.6.0"
url = "2.3.1"
[dependencies.ashpd] [dependencies.ashpd]
version = "0.3" version = "0.4.0-alpha.1"
features = ["feature_gtk4"] features = ["gtk4"]
[dependencies.gtk] [dependencies.gtk]
package = "gtk4" package = "gtk4"
version = "0.4.4" version = "0.5.1"
features = ["v4_6"] features = ["v4_6"]
[dependencies.gio] [dependencies.gio]
package = "gio" package = "gio"
version = "0.15.2" version = "0.16.2"
features = ["v2_70"] features = ["v2_70"]
[dependencies.adw] [dependencies.adw]
package = "libadwaita" package = "libadwaita"
version = "0.2.0-alpha.2" version = "0.2.0"
features = ["v1_2"] features = ["v1_2"]
[dependencies.gettext-rs] [dependencies.gettext-rs]

View file

@ -1,5 +1,5 @@
project('loupe', 'rust', project('loupe', 'rust',
version: '42.alpha', version: '43.alpha',
meson_version: '>= 0.59.0', meson_version: '>= 0.59.0',
default_options: [ 'warning_level=2', default_options: [ 'warning_level=2',
], ],

View file

@ -48,8 +48,10 @@ mod imp {
// Overrides GObject vfuncs // Overrides GObject vfuncs
impl ObjectImpl for LpApplication { impl ObjectImpl for LpApplication {
fn constructed(&self, obj: &Self::Type) { fn constructed(&self) {
self.parent_constructed(obj); let obj = self.instance();
self.parent_constructed();
// Force dark theme // Force dark theme
obj.style_manager() obj.style_manager()
@ -62,15 +64,17 @@ mod imp {
// Overrides GApplication vfuncs // Overrides GApplication vfuncs
impl ApplicationImpl for LpApplication { impl ApplicationImpl for LpApplication {
fn activate(&self, application: &Self::Type) { fn activate(&self) {
let window = LpWindow::new(application); let application = self.instance();
let window = LpWindow::new(&*application);
window.present(); window.present();
} }
// Handles opening files from the command line or other applications // Handles opening files from the command line or other applications
fn open(&self, application: &Self::Type, files: &[gio::File], _hint: &str) { fn open(&self, files: &[gio::File], _hint: &str) {
let application = self.instance();
for file in files { for file in files {
let win = LpWindow::new(application); let win = LpWindow::new(&*application);
win.set_image_from_file(file, true); win.set_image_from_file(file, true);
win.show(); win.show();
} }
@ -102,7 +106,6 @@ impl LpApplication {
("flags", &gio::ApplicationFlags::HANDLES_OPEN), ("flags", &gio::ApplicationFlags::HANDLES_OPEN),
("resource-base-path", &"/org/gnome/Loupe/".to_string()), ("resource-base-path", &"/org/gnome/Loupe/".to_string()),
]) ])
.unwrap()
} }
pub fn setup_actions(&self) { pub fn setup_actions(&self) {

View file

@ -46,15 +46,15 @@ mod imp {
impl ObjectImpl for LpFileModel {} impl ObjectImpl for LpFileModel {}
impl ListModelImpl for LpFileModel { impl ListModelImpl for LpFileModel {
fn item_type(&self, _list_model: &Self::Type) -> glib::Type { fn item_type(&self) -> glib::Type {
gio::File::static_type() gio::File::static_type()
} }
fn n_items(&self, _list_model: &Self::Type) -> u32 { fn n_items(&self) -> u32 {
self.inner.borrow().len() as u32 self.inner.borrow().len() as u32
} }
fn item(&self, _list_model: &Self::Type, position: u32) -> Option<glib::Object> { fn item(&self, position: u32) -> Option<glib::Object> {
self.inner self.inner
.borrow() .borrow()
.get(position as usize) .get(position as usize)
@ -69,7 +69,7 @@ glib::wrapper! {
impl LpFileModel { impl LpFileModel {
pub fn from_directory(directory: &gio::File) -> Self { pub fn from_directory(directory: &gio::File) -> Self {
let model = glib::Object::new::<Self>(&[]).expect("Could not create LpFileModel"); let model = glib::Object::new::<Self>(&[]);
{ {
// Here we use a nested scope so that the mutable borrow only lasts as long as we need it // Here we use a nested scope so that the mutable borrow only lasts as long as we need it

View file

@ -23,7 +23,7 @@ mod imp {
impl ObjectImpl for Thumbnail {} impl ObjectImpl for Thumbnail {}
impl PaintableImpl for Thumbnail { impl PaintableImpl for Thumbnail {
fn intrinsic_height(&self, _paintable: &Self::Type) -> i32 { fn intrinsic_height(&self) -> i32 {
let image = self.image.get().unwrap(); let image = self.image.get().unwrap();
let width = image.intrinsic_width(); let width = image.intrinsic_width();
let height = image.intrinsic_height(); let height = image.intrinsic_height();
@ -36,7 +36,7 @@ mod imp {
} }
} }
fn intrinsic_width(&self, _paintable: &Self::Type) -> i32 { fn intrinsic_width(&self) -> i32 {
let image = self.image.get().unwrap(); let image = self.image.get().unwrap();
let width = image.intrinsic_width(); let width = image.intrinsic_width();
let height = image.intrinsic_height(); let height = image.intrinsic_height();
@ -49,17 +49,12 @@ mod imp {
} }
} }
fn intrinsic_aspect_ratio(&self, _paintable: &Self::Type) -> f64 { fn intrinsic_aspect_ratio(&self) -> f64 {
self.image.get().unwrap().intrinsic_aspect_ratio() self.image.get().unwrap().intrinsic_aspect_ratio()
} }
fn snapshot( fn snapshot(&self, snapshot: &gdk::Snapshot, _width: f64, _height: f64) {
&self, let paintable = self.instance();
paintable: &Self::Type,
snapshot: &gdk::Snapshot,
_width: f64,
_height: f64,
) {
let width = paintable.intrinsic_width() as f64; let width = paintable.intrinsic_width() as f64;
let height = paintable.intrinsic_height() as f64; let height = paintable.intrinsic_height() as f64;
@ -79,7 +74,7 @@ glib::wrapper! {
impl Thumbnail { impl Thumbnail {
pub fn new(paintable: &impl glib::IsA<gdk::Paintable>) -> Self { pub fn new(paintable: &impl glib::IsA<gdk::Paintable>) -> Self {
let object = glib::Object::new::<Self>(&[]).unwrap(); let object = glib::Object::new::<Self>(&[]);
let imp = object.imp(); let imp = object.imp();
imp.image.set(paintable.clone().upcast()).unwrap(); imp.image.set(paintable.clone().upcast()).unwrap();

View file

@ -58,32 +58,30 @@ mod imp {
PROPERTIES.as_ref() PROPERTIES.as_ref()
} }
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let obj = self.instance();
match pspec.name() { match pspec.name() {
"file" => obj.file().to_value(), "file" => obj.file().to_value(),
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
fn set_property( fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
&self, let obj = self.instance();
obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
) {
match pspec.name() { match pspec.name() {
"file" => obj.set_file(&value.get().unwrap()), "file" => obj.set_file(&value.get().unwrap()),
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
fn constructed(&self, obj: &Self::Type) { fn constructed(&self) {
let obj = self.instance();
obj.set_hexpand(true); obj.set_hexpand(true);
obj.set_vexpand(true); obj.set_vexpand(true);
} }
fn dispose(&self, obj: &Self::Type) { fn dispose(&self) {
let obj = self.instance();
while let Some(child) = obj.first_child() { while let Some(child) = obj.first_child() {
child.unparent(); child.unparent();
} }
@ -91,14 +89,15 @@ mod imp {
} }
impl WidgetImpl for LpImage { impl WidgetImpl for LpImage {
fn snapshot(&self, widget: &Self::Type, snapshot: &gtk::Snapshot) { fn snapshot(&self, snapshot: &gtk::Snapshot) {
if let Some(texture) = self.texture.borrow().as_ref() { if let Some(texture) = self.texture.borrow().as_ref() {
let widget = self.instance();
let width = widget.width() as f64; let width = widget.width() as f64;
let height = widget.height() as f64; let height = widget.height() as f64;
let texture_ratio = texture.intrinsic_aspect_ratio(); let texture_ratio = texture.intrinsic_aspect_ratio();
if texture_ratio == 0.0 { if texture_ratio == 0.0 {
texture.snapshot(snapshot.upcast_ref(), width, height); texture.snapshot(snapshot, width, height);
} else { } else {
let widget_ratio = width / height; let widget_ratio = width / height;
@ -113,22 +112,17 @@ mod imp {
snapshot.save(); snapshot.save();
snapshot.translate(&graphene::Point::new(x as f32, y as f32)); snapshot.translate(&graphene::Point::new(x as f32, y as f32));
texture.snapshot(snapshot.upcast_ref(), snapshot_width, snapshot_height); texture.snapshot(snapshot, snapshot_width, snapshot_height);
snapshot.restore(); snapshot.restore();
} }
} }
} }
fn request_mode(&self, _widget: &Self::Type) -> gtk::SizeRequestMode { fn request_mode(&self) -> gtk::SizeRequestMode {
gtk::SizeRequestMode::HeightForWidth gtk::SizeRequestMode::HeightForWidth
} }
fn measure( fn measure(&self, orienation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
&self,
_widget: &Self::Type,
orienation: gtk::Orientation,
for_size: i32,
) -> (i32, i32, i32, i32) {
if let Some(texture) = self.texture.borrow().as_ref() { if let Some(texture) = self.texture.borrow().as_ref() {
let default_size = 16.0; // Fall back to default icon size; Just a guess since the API GtkPicture uses is private let default_size = 16.0; // Fall back to default icon size; Just a guess since the API GtkPicture uses is private
let measurement = if for_size < 0 { 0 } else { for_size }; let measurement = if for_size < 0 { 0 } else { for_size };

View file

@ -70,8 +70,10 @@ mod imp {
} }
impl ObjectImpl for LpImagePage { impl ObjectImpl for LpImagePage {
fn constructed(&self, obj: &Self::Type) { fn constructed(&self) {
self.parent_constructed(obj); let obj = self.instance();
self.parent_constructed();
self.click_gesture self.click_gesture
.connect_pressed(clone!(@weak obj => move |gesture, _, x, y| { .connect_pressed(clone!(@weak obj => move |gesture, _, x, y| {
@ -100,7 +102,7 @@ glib::wrapper! {
impl LpImagePage { impl LpImagePage {
pub fn from_file(file: &gio::File) -> Self { pub fn from_file(file: &gio::File) -> Self {
let obj = glib::Object::new::<Self>(&[]).unwrap(); let obj = glib::Object::new::<Self>(&[]);
obj.imp().file.set(file.clone()).unwrap(); obj.imp().file.set(file.clone()).unwrap();
// This doesn't work properly for items not explicitly selected // This doesn't work properly for items not explicitly selected

View file

@ -97,15 +97,18 @@ mod imp {
PROPERTIES.as_ref() PROPERTIES.as_ref()
} }
fn property(&self, obj: &Self::Type, _id: usize, psec: &glib::ParamSpec) -> glib::Value { fn property(&self, _id: usize, psec: &glib::ParamSpec) -> glib::Value {
let obj = self.instance();
match psec.name() { match psec.name() {
"active-file" => obj.active_file().to_value(), "active-file" => obj.active_file().to_value(),
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
fn constructed(&self, obj: &Self::Type) { fn constructed(&self) {
self.parent_constructed(obj); let obj = self.instance();
self.parent_constructed();
let source = gtk::DragSource::new(); let source = gtk::DragSource::new();
source.set_exclusive(true); source.set_exclusive(true);
@ -386,28 +389,38 @@ impl LpImageView {
pub fn set_background(&self) -> anyhow::Result<()> { pub fn set_background(&self) -> anyhow::Result<()> {
let background = self.uri().context("No URI for current file")?; let background = self.uri().context("No URI for current file")?;
spawn!(clone!(@weak self as view => async move { spawn!(clone!(@weak self as view =>
async move {
let id = WindowIdentifier::from_native( let id = WindowIdentifier::from_native(
&view.native().expect("View should have a GtkNative"), &view.native().expect("View should have a GtkNative"),
) )
.await; .await;
let _ = match wallpaper::set_from_uri( let _ = match wallpaper::WallpaperRequest::default()
&id, .set_on(wallpaper::SetOn::Background)
&background, .show_preview(true)
true, .identifier(id)
wallpaper::SetOn::Background, .build_uri(&background)
) .await
.await { {
// We use `1` here because we can't pass enums directly as GVariants, // We use `1` here because we can't pass enums directly as GVariants,
// so we need to use the C int value of the enum. // so we need to use the C int value of the enum.
// `TOAST_PRIORITY_NORMAL = 0`, and `TOAST_PRIORITY_HIGH = 1` // `TOAST_PRIORITY_NORMAL = 0`, and `TOAST_PRIORITY_HIGH = 1`
Ok(_) => view.activate_action("win.show-toast", Some(&(i18n("Set as background."), 1).to_variant())).unwrap(), Ok(_) => view
.activate_action(
"win.show-toast",
Some(&(i18n("Set as background."), 1).to_variant()),
)
.unwrap(),
Err(err) => { Err(err) => {
if !matches!(err, Error::Response(ResponseError::Cancelled)) { if !matches!(err, Error::Response(ResponseError::Cancelled)) {
view.activate_action("win.show-toast", Some(&(i18n("Could not set background."), 1).to_variant())).unwrap(); view.activate_action(
"win.show-toast",
Some(&(i18n("Could not set background."), 1).to_variant()),
)
.unwrap();
} }
}, }
}; };
})); }));
@ -475,8 +488,9 @@ impl LpImageView {
} }
} }
pub fn uri(&self) -> Option<String> { pub fn uri(&self) -> Option<url::Url> {
self.active_file().map(|f| f.uri().to_string()) self.active_file()
.and_then(|f| url::Url::parse(&f.uri()).ok())
} }
pub fn active_file(&self) -> Option<gio::File> { pub fn active_file(&self) -> Option<gio::File> {

View file

@ -101,7 +101,8 @@ mod imp {
PROPERTIES.as_ref() PROPERTIES.as_ref()
} }
fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
let obj = self.instance();
let prop_name = pspec.name(); let prop_name = pspec.name();
match prop_name { match prop_name {
@ -112,13 +113,8 @@ mod imp {
} }
} }
fn set_property( fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
&self, let obj = self.instance();
obj: &Self::Type,
_id: usize,
value: &glib::Value,
pspec: &glib::ParamSpec,
) {
let prop_name = pspec.name(); let prop_name = pspec.name();
match prop_name { match prop_name {
@ -127,8 +123,10 @@ mod imp {
} }
} }
fn constructed(&self, obj: &Self::Type) { fn constructed(&self) {
self.parent_constructed(obj); let obj = self.instance();
self.parent_constructed();
obj.action_set_enabled("properties.open-folder", false); obj.action_set_enabled("properties.open-folder", false);
} }
} }
@ -303,7 +301,7 @@ impl LpPropertiesView {
{ {
spawn!(clone!(@weak self as view => async move { spawn!(clone!(@weak self as view => async move {
let id = WindowIdentifier::from_native(&view.native().expect("No GtkNative for view")).await; let id = WindowIdentifier::from_native(&view.native().expect("No GtkNative for view")).await;
if let Err(e) = open_uri::open_directory(&id, &directory).await { if let Err(e) = open_uri::OpenDirectoryRequest::default().identifier(id).build(&directory).await {
log::error!("Could not open parent directory: {e}"); log::error!("Could not open parent directory: {e}");
}; };
})); }));

View file

@ -127,8 +127,10 @@ mod imp {
} }
impl ObjectImpl for LpWindow { impl ObjectImpl for LpWindow {
fn constructed(&self, obj: &Self::Type) { fn constructed(&self) {
self.parent_constructed(obj); let obj = self.instance();
self.parent_constructed();
if config::PROFILE == ".Devel" { if config::PROFILE == ".Devel" {
obj.add_css_class("devel"); obj.add_css_class("devel");
@ -206,7 +208,7 @@ glib::wrapper! {
#[gtk::template_callbacks] #[gtk::template_callbacks]
impl LpWindow { impl LpWindow {
pub fn new<A: IsA<gtk::Application>>(app: &A) -> Self { pub fn new<A: IsA<gtk::Application>>(app: &A) -> Self {
glib::Object::new(&[("application", app)]).expect("Failed to create LpWindow") glib::Object::new(&[("application", app)])
} }
fn toggle_fullscreen(&self, fullscreen: bool) { fn toggle_fullscreen(&self, fullscreen: bool) {
@ -264,7 +266,11 @@ impl LpWindow {
{ {
spawn!(clone!(@weak self as win => async move { spawn!(clone!(@weak self as win => async move {
if let Err(e) = if let Err(e) =
open_uri::open_file(&WindowIdentifier::from_native(&win).await, &file, true, true).await open_uri::OpenFileRequest::default()
.ask(true)
.writeable(true)
.identifier(WindowIdentifier::from_native(&win).await)
.build_file(&file).await
{ {
log::error!("Could not open image in external program: {}", e); log::error!("Could not open image in external program: {}", e);
} }
@ -345,7 +351,7 @@ impl LpWindow {
// Ensure the window surface exists // Ensure the window surface exists
if !self.is_realized() { if !self.is_realized() {
self.realize(); WidgetExt::realize(self);
} }
let display = gdk::Display::default().unwrap(); let display = gdk::Display::default().unwrap();