cargo: Update dependencies
This commit is contained in:
parent
743577757f
commit
3d6564377a
11 changed files with 574 additions and 271 deletions
|
|
@ -48,8 +48,10 @@ mod imp {
|
|||
|
||||
// Overrides GObject vfuncs
|
||||
impl ObjectImpl for LpApplication {
|
||||
fn constructed(&self, obj: &Self::Type) {
|
||||
self.parent_constructed(obj);
|
||||
fn constructed(&self) {
|
||||
let obj = self.instance();
|
||||
|
||||
self.parent_constructed();
|
||||
|
||||
// Force dark theme
|
||||
obj.style_manager()
|
||||
|
|
@ -62,15 +64,17 @@ mod imp {
|
|||
|
||||
// Overrides GApplication vfuncs
|
||||
impl ApplicationImpl for LpApplication {
|
||||
fn activate(&self, application: &Self::Type) {
|
||||
let window = LpWindow::new(application);
|
||||
fn activate(&self) {
|
||||
let application = self.instance();
|
||||
let window = LpWindow::new(&*application);
|
||||
window.present();
|
||||
}
|
||||
|
||||
// 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 {
|
||||
let win = LpWindow::new(application);
|
||||
let win = LpWindow::new(&*application);
|
||||
win.set_image_from_file(file, true);
|
||||
win.show();
|
||||
}
|
||||
|
|
@ -102,7 +106,6 @@ impl LpApplication {
|
|||
("flags", &gio::ApplicationFlags::HANDLES_OPEN),
|
||||
("resource-base-path", &"/org/gnome/Loupe/".to_string()),
|
||||
])
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn setup_actions(&self) {
|
||||
|
|
|
|||
|
|
@ -46,15 +46,15 @@ mod imp {
|
|||
impl ObjectImpl 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()
|
||||
}
|
||||
|
||||
fn n_items(&self, _list_model: &Self::Type) -> u32 {
|
||||
fn n_items(&self) -> 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
|
||||
.borrow()
|
||||
.get(position as usize)
|
||||
|
|
@ -69,7 +69,7 @@ glib::wrapper! {
|
|||
|
||||
impl LpFileModel {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ mod imp {
|
|||
|
||||
impl ObjectImpl 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 width = image.intrinsic_width();
|
||||
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 width = image.intrinsic_width();
|
||||
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()
|
||||
}
|
||||
|
||||
fn snapshot(
|
||||
&self,
|
||||
paintable: &Self::Type,
|
||||
snapshot: &gdk::Snapshot,
|
||||
_width: f64,
|
||||
_height: f64,
|
||||
) {
|
||||
fn snapshot(&self, snapshot: &gdk::Snapshot, _width: f64, _height: f64) {
|
||||
let paintable = self.instance();
|
||||
let width = paintable.intrinsic_width() as f64;
|
||||
let height = paintable.intrinsic_height() as f64;
|
||||
|
||||
|
|
@ -79,7 +74,7 @@ glib::wrapper! {
|
|||
|
||||
impl Thumbnail {
|
||||
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();
|
||||
|
||||
imp.image.set(paintable.clone().upcast()).unwrap();
|
||||
|
|
|
|||
|
|
@ -58,32 +58,30 @@ mod imp {
|
|||
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() {
|
||||
"file" => obj.file().to_value(),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &glib::ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||
let obj = self.instance();
|
||||
match pspec.name() {
|
||||
"file" => obj.set_file(&value.get().unwrap()),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn constructed(&self, obj: &Self::Type) {
|
||||
fn constructed(&self) {
|
||||
let obj = self.instance();
|
||||
obj.set_hexpand(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() {
|
||||
child.unparent();
|
||||
}
|
||||
|
|
@ -91,14 +89,15 @@ mod imp {
|
|||
}
|
||||
|
||||
impl WidgetImpl for LpImage {
|
||||
fn snapshot(&self, widget: &Self::Type, snapshot: >k::Snapshot) {
|
||||
fn snapshot(&self, snapshot: >k::Snapshot) {
|
||||
if let Some(texture) = self.texture.borrow().as_ref() {
|
||||
let widget = self.instance();
|
||||
let width = widget.width() as f64;
|
||||
let height = widget.height() as f64;
|
||||
let texture_ratio = texture.intrinsic_aspect_ratio();
|
||||
|
||||
if texture_ratio == 0.0 {
|
||||
texture.snapshot(snapshot.upcast_ref(), width, height);
|
||||
texture.snapshot(snapshot, width, height);
|
||||
} else {
|
||||
let widget_ratio = width / height;
|
||||
|
||||
|
|
@ -113,22 +112,17 @@ mod imp {
|
|||
|
||||
snapshot.save();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn request_mode(&self, _widget: &Self::Type) -> gtk::SizeRequestMode {
|
||||
fn request_mode(&self) -> gtk::SizeRequestMode {
|
||||
gtk::SizeRequestMode::HeightForWidth
|
||||
}
|
||||
|
||||
fn measure(
|
||||
&self,
|
||||
_widget: &Self::Type,
|
||||
orienation: gtk::Orientation,
|
||||
for_size: i32,
|
||||
) -> (i32, i32, i32, i32) {
|
||||
fn measure(&self, orienation: gtk::Orientation, for_size: i32) -> (i32, i32, i32, i32) {
|
||||
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 measurement = if for_size < 0 { 0 } else { for_size };
|
||||
|
|
|
|||
|
|
@ -70,8 +70,10 @@ mod imp {
|
|||
}
|
||||
|
||||
impl ObjectImpl for LpImagePage {
|
||||
fn constructed(&self, obj: &Self::Type) {
|
||||
self.parent_constructed(obj);
|
||||
fn constructed(&self) {
|
||||
let obj = self.instance();
|
||||
|
||||
self.parent_constructed();
|
||||
|
||||
self.click_gesture
|
||||
.connect_pressed(clone!(@weak obj => move |gesture, _, x, y| {
|
||||
|
|
@ -100,7 +102,7 @@ glib::wrapper! {
|
|||
|
||||
impl LpImagePage {
|
||||
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();
|
||||
|
||||
// This doesn't work properly for items not explicitly selected
|
||||
|
|
|
|||
|
|
@ -97,15 +97,18 @@ mod imp {
|
|||
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() {
|
||||
"active-file" => obj.active_file().to_value(),
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn constructed(&self, obj: &Self::Type) {
|
||||
self.parent_constructed(obj);
|
||||
fn constructed(&self) {
|
||||
let obj = self.instance();
|
||||
|
||||
self.parent_constructed();
|
||||
|
||||
let source = gtk::DragSource::new();
|
||||
source.set_exclusive(true);
|
||||
|
|
@ -386,28 +389,38 @@ impl LpImageView {
|
|||
|
||||
pub fn set_background(&self) -> anyhow::Result<()> {
|
||||
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(
|
||||
&view.native().expect("View should have a GtkNative"),
|
||||
)
|
||||
.await;
|
||||
|
||||
let _ = match wallpaper::set_from_uri(
|
||||
&id,
|
||||
&background,
|
||||
true,
|
||||
wallpaper::SetOn::Background,
|
||||
)
|
||||
.await {
|
||||
let _ = match wallpaper::WallpaperRequest::default()
|
||||
.set_on(wallpaper::SetOn::Background)
|
||||
.show_preview(true)
|
||||
.identifier(id)
|
||||
.build_uri(&background)
|
||||
.await
|
||||
{
|
||||
// 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.
|
||||
// `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) => {
|
||||
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> {
|
||||
self.active_file().map(|f| f.uri().to_string())
|
||||
pub fn uri(&self) -> Option<url::Url> {
|
||||
self.active_file()
|
||||
.and_then(|f| url::Url::parse(&f.uri()).ok())
|
||||
}
|
||||
|
||||
pub fn active_file(&self) -> Option<gio::File> {
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ mod imp {
|
|||
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();
|
||||
|
||||
match prop_name {
|
||||
|
|
@ -112,13 +113,8 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_property(
|
||||
&self,
|
||||
obj: &Self::Type,
|
||||
_id: usize,
|
||||
value: &glib::Value,
|
||||
pspec: &glib::ParamSpec,
|
||||
) {
|
||||
fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
|
||||
let obj = self.instance();
|
||||
let prop_name = pspec.name();
|
||||
|
||||
match prop_name {
|
||||
|
|
@ -127,8 +123,10 @@ mod imp {
|
|||
}
|
||||
}
|
||||
|
||||
fn constructed(&self, obj: &Self::Type) {
|
||||
self.parent_constructed(obj);
|
||||
fn constructed(&self) {
|
||||
let obj = self.instance();
|
||||
|
||||
self.parent_constructed();
|
||||
obj.action_set_enabled("properties.open-folder", false);
|
||||
}
|
||||
}
|
||||
|
|
@ -303,7 +301,7 @@ impl LpPropertiesView {
|
|||
{
|
||||
spawn!(clone!(@weak self as view => async move {
|
||||
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}");
|
||||
};
|
||||
}));
|
||||
|
|
|
|||
|
|
@ -127,8 +127,10 @@ mod imp {
|
|||
}
|
||||
|
||||
impl ObjectImpl for LpWindow {
|
||||
fn constructed(&self, obj: &Self::Type) {
|
||||
self.parent_constructed(obj);
|
||||
fn constructed(&self) {
|
||||
let obj = self.instance();
|
||||
|
||||
self.parent_constructed();
|
||||
|
||||
if config::PROFILE == ".Devel" {
|
||||
obj.add_css_class("devel");
|
||||
|
|
@ -206,7 +208,7 @@ glib::wrapper! {
|
|||
#[gtk::template_callbacks]
|
||||
impl LpWindow {
|
||||
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) {
|
||||
|
|
@ -264,7 +266,11 @@ impl LpWindow {
|
|||
{
|
||||
spawn!(clone!(@weak self as win => async move {
|
||||
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);
|
||||
}
|
||||
|
|
@ -345,7 +351,7 @@ impl LpWindow {
|
|||
|
||||
// Ensure the window surface exists
|
||||
if !self.is_realized() {
|
||||
self.realize();
|
||||
WidgetExt::realize(self);
|
||||
}
|
||||
|
||||
let display = gdk::Display::default().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue