From b86d0e2d0545a22ac2179e2f7bdf5762a0a5fec4 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Sat, 5 Mar 2022 21:52:06 +0100 Subject: [PATCH 1/5] cargo: Set to 2021 edition --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4b0e705..3e622ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "obfuscate" version = "0.0.4" authors = ["Bilal Elmoussaoui "] -edition = "2018" +edition = "2021" [dependencies] gtk = { package = "gtk4", version = "0.4" } -- GitLab From f6b21f6aa0b4be0d1b0ab702554445dc1ff38ff0 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Sat, 5 Mar 2022 21:52:26 +0100 Subject: [PATCH 2/5] drawing_area: Accept files This fixes https://github.com/flathub/com.belmoussaoui.Obfuscate/issues/8 --- src/widgets/drawing_area.rs | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/widgets/drawing_area.rs b/src/widgets/drawing_area.rs index 3073d29..bb30a60 100644 --- a/src/widgets/drawing_area.rs +++ b/src/widgets/drawing_area.rs @@ -180,30 +180,15 @@ mod imp { })); obj.add_controller(&scroll_controller); - let content_formats = gdk::ContentFormatsBuilder::new().add_mime_type("text/uri-list").build(); - let drop_target = gtk::DropTargetAsync::new(Some(&content_formats), gdk::DragAction::LINK); - drop_target.connect_drop(clone!(@weak obj as this => @default-return false, move |_, drop, _x, _y| { - let formats = drop.formats(); - // we have a uri - // note that we can't open files outside of the sandbox, especially if you dnd files from a GTK 3 app. - if formats.contain_mime_type("text/uri-list") { - drop.read_value_async( - String::static_type(), - glib::PRIORITY_DEFAULT, - gio::Cancellable::NONE, - clone!(@weak drop, @weak this => move |val| { - if let Ok(uri) = val.map(|v| v.get::().unwrap()) { - let file = gio::File::for_uri(&uri); - if let Err(err) = this.load_file(&file) { - log::error!("DND file URI failed to load: {}", err); - } - } - drop.finish(gdk::DragAction::LINK); - }), - ); - return true; + let drop_target = gtk::DropTarget::new(gio::File::static_type(), gdk::DragAction::COPY); + drop_target.connect_drop(glib::clone!(@weak obj => @default-return false, move |_, value, _, _| { + if let Ok(file) = value.get::() { + obj.load_file(&file) + .unwrap_or_else(|err| log::error!("Could not load file: {}", err)); + true + } else { + false } - false })); obj.add_controller(&drop_target); } -- GitLab From 4263e259731a6228aabe519b5c8f9aca51f053ab Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Sat, 5 Mar 2022 22:06:01 +0100 Subject: [PATCH 3/5] window: Add a drop target to the welcome screen --- src/widgets/window.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/widgets/window.rs b/src/widgets/window.rs index 8b47b28..ded9d8a 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -4,7 +4,7 @@ use crate::widgets::drawing_area::{DrawingArea, Filter}; use adw::subclass::prelude::*; use anyhow::Result; use gtk::{ - gio, + gdk, gio, gio::prelude::SettingsExt, glib::{self, clone}, prelude::*, @@ -130,6 +130,17 @@ mod imp { obj.set_view(View::Empty); obj.load_state(); self.status_page.set_icon_name(Some(APP_ID)); + + let drop_target = gtk::DropTarget::new(gio::File::static_type(), gdk::DragAction::COPY); + drop_target.connect_drop(glib::clone!(@strong obj => @default-return false, move |_, value, _, _| { + if let Ok(file) = value.get::() { + obj.open_file(&file); + true + } else { + false + } + })); + self.status_page.add_controller(&drop_target); } } -- GitLab From 7d06dd8bb479065624eb2d3f5e1f68136db20f7a Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Sat, 5 Mar 2022 22:57:07 +0100 Subject: [PATCH 4/5] drawing_area: Use load_file from window --- src/widgets/drawing_area.rs | 6 ++++-- src/widgets/window.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/widgets/drawing_area.rs b/src/widgets/drawing_area.rs index bb30a60..058299f 100644 --- a/src/widgets/drawing_area.rs +++ b/src/widgets/drawing_area.rs @@ -7,6 +7,8 @@ use gtk::{ subclass::prelude::*, }; +use crate::widgets::Window; + #[derive(Debug, Eq, PartialEq, Clone, Copy, glib::Enum)] #[repr(u32)] #[enum_type(name = "Filter")] @@ -183,8 +185,8 @@ mod imp { let drop_target = gtk::DropTarget::new(gio::File::static_type(), gdk::DragAction::COPY); drop_target.connect_drop(glib::clone!(@weak obj => @default-return false, move |_, value, _, _| { if let Ok(file) = value.get::() { - obj.load_file(&file) - .unwrap_or_else(|err| log::error!("Could not load file: {}", err)); + let window = obj.root().unwrap().downcast::().unwrap(); + window.open_file(&file); true } else { false diff --git a/src/widgets/window.rs b/src/widgets/window.rs index ded9d8a..d917a58 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -159,7 +159,7 @@ mod imp { glib::wrapper! { pub struct Window(ObjectSubclass) - @extends gtk::Widget, gtk::Window, adw::ApplicationWindow, gtk::ApplicationWindow, gio::ActionMap; + @extends gtk::Widget, gtk::Window, adw::ApplicationWindow, gtk::Root, gtk::ApplicationWindow, gio::ActionMap; } impl Window { -- GitLab From 8830d29ab4276c84ffc1ef9674468bb112e937a2 Mon Sep 17 00:00:00 2001 From: Maximiliano Sandoval R Date: Sun, 6 Mar 2022 11:45:09 +0100 Subject: [PATCH 5/5] window: Fix glib wrapper --- src/widgets/window.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widgets/window.rs b/src/widgets/window.rs index d917a58..bf8ee18 100644 --- a/src/widgets/window.rs +++ b/src/widgets/window.rs @@ -159,7 +159,8 @@ mod imp { glib::wrapper! { pub struct Window(ObjectSubclass) - @extends gtk::Widget, gtk::Window, adw::ApplicationWindow, gtk::Root, gtk::ApplicationWindow, gio::ActionMap; + @extends gtk::Widget, gtk::Window, adw::ApplicationWindow, gtk::ApplicationWindow, + @implements gtk::Root, gio::ActionMap; } impl Window { -- GitLab