improv: feature gate for xdg_portal
This commit is contained in:
parent
8e6aea650a
commit
63568a8d9c
12 changed files with 53 additions and 53 deletions
|
|
@ -120,7 +120,6 @@ x11 = ["iced/x11", "iced_winit/x11"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
apply = "0.3.0"
|
apply = "0.3.0"
|
||||||
ashpd = { version = "0.12.3", default-features = false, optional = true }
|
|
||||||
async-fs = { version = "2.2", optional = true }
|
async-fs = { version = "2.2", optional = true }
|
||||||
async-std = { workspace = true, optional = true }
|
async-std = { workspace = true, optional = true }
|
||||||
auto_enums = "0.8.8"
|
auto_enums = "0.8.8"
|
||||||
|
|
@ -174,6 +173,7 @@ cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-c
|
||||||
cosmic-config = { path = "cosmic-config", features = ["dbus"] }
|
cosmic-config = { path = "cosmic-config", features = ["dbus"] }
|
||||||
cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
ashpd = { version = "0.12.3", default-features = false, optional = true }
|
||||||
|
|
||||||
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
|
[target.'cfg(all(unix, not(target_os = "macos")))'.dependencies]
|
||||||
freedesktop-icons = { package = "cosmic-freedesktop-icons", git = "https://github.com/pop-os/freedesktop-icons" }
|
freedesktop-icons = { package = "cosmic-freedesktop-icons", git = "https://github.com/pop-os/freedesktop-icons" }
|
||||||
|
|
|
||||||
2
iced
2
iced
|
|
@ -1 +1 @@
|
||||||
Subproject commit 7177c92bb0b10382acafdec1af7441312138c69e
|
Subproject commit 7b5d58ecbde79b105baf938e8065ab4ba4e5a35d
|
||||||
|
|
@ -76,6 +76,6 @@ pub enum Action {
|
||||||
/// Capabilities the window manager supports
|
/// Capabilities the window manager supports
|
||||||
#[cfg(wayland_platform)]
|
#[cfg(wayland_platform)]
|
||||||
WmCapabilities(iced::window::Id, WindowManagerCapabilities),
|
WmCapabilities(iced::window::Id, WindowManagerCapabilities),
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
DesktopSettings(crate::theme::portal::Desktop),
|
DesktopSettings(crate::theme::portal::Desktop),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -678,7 +678,7 @@ where
|
||||||
})
|
})
|
||||||
.map(crate::Action::Cosmic),
|
.map(crate::Action::Cosmic),
|
||||||
window_events.map(crate::Action::Cosmic),
|
window_events.map(crate::Action::Cosmic),
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
crate::theme::portal::desktop_settings()
|
crate::theme::portal::desktop_settings()
|
||||||
.map(Action::DesktopSettings)
|
.map(Action::DesktopSettings)
|
||||||
.map(crate::Action::Cosmic),
|
.map(crate::Action::Cosmic),
|
||||||
|
|
@ -1250,7 +1250,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
return self.app.dbus_connection(conn);
|
return self.app.dbus_connection(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
Action::DesktopSettings(crate::theme::portal::Desktop::ColorScheme(s)) => {
|
Action::DesktopSettings(crate::theme::portal::Desktop::ColorScheme(s)) => {
|
||||||
use ashpd::desktop::settings::ColorScheme;
|
use ashpd::desktop::settings::ColorScheme;
|
||||||
if match THEME.lock().unwrap().theme_type {
|
if match THEME.lock().unwrap().theme_type {
|
||||||
|
|
@ -1332,7 +1332,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
Action::DesktopSettings(crate::theme::portal::Desktop::Accent(c)) => {
|
Action::DesktopSettings(crate::theme::portal::Desktop::Accent(c)) => {
|
||||||
use palette::Srgba;
|
use palette::Srgba;
|
||||||
let c = Srgba::new(c.red() as f32, c.green() as f32, c.blue() as f32, 1.0);
|
let c = Srgba::new(c.red() as f32, c.green() as f32, c.blue() as f32, 1.0);
|
||||||
|
|
@ -1361,7 +1361,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
Action::DesktopSettings(crate::theme::portal::Desktop::Contrast(_)) => {
|
Action::DesktopSettings(crate::theme::portal::Desktop::Contrast(_)) => {
|
||||||
// TODO when high contrast is integrated in settings and all custom themes
|
// TODO when high contrast is integrated in settings and all custom themes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2023 System76 <info@system76.com>
|
// Copyright 2023 System76 <info@system76.com>
|
||||||
// SPDX-License-Identifier: MPL-2.0
|
// SPDX-License-Identifier: MPL-2.0
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
use std::os::fd::AsFd;
|
use std::os::fd::AsFd;
|
||||||
|
|
||||||
use iced::window;
|
use iced::window;
|
||||||
|
|
@ -47,7 +47,7 @@ pub fn toggle_maximize<M>(id: window::Id) -> iced::Task<crate::Action<M>> {
|
||||||
iced_runtime::window::toggle_maximize(id)
|
iced_runtime::window::toggle_maximize(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn file_transfer_send(
|
pub fn file_transfer_send(
|
||||||
writeable: bool,
|
writeable: bool,
|
||||||
auto_stop: bool,
|
auto_stop: bool,
|
||||||
|
|
@ -63,7 +63,7 @@ pub fn file_transfer_send(
|
||||||
|
|
||||||
/// Receive the files offered over the xdg share portal using the `key`.
|
/// Receive the files offered over the xdg share portal using the `key`.
|
||||||
/// Returns a list of file paths.
|
/// Returns a list of file paths.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn file_transfer_receive(key: String) -> iced::Task<ashpd::Result<Vec<String>>> {
|
pub fn file_transfer_receive(key: String) -> iced::Task<ashpd::Result<Vec<String>>> {
|
||||||
iced::Task::future(async move {
|
iced::Task::future(async move {
|
||||||
let file_transfer = ashpd::documents::FileTransfer::new().await?;
|
let file_transfer = ashpd::documents::FileTransfer::new().await?;
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ pub mod open;
|
||||||
/// Save file dialog.
|
/// Save file dialog.
|
||||||
pub mod save;
|
pub mod save;
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub use ashpd::desktop::file_chooser::{Choice, FileFilter};
|
pub use ashpd::desktop::file_chooser::{Choice, FileFilter};
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
@ -139,7 +139,7 @@ pub enum Error {
|
||||||
UrlAbsolute,
|
UrlAbsolute,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub type DialogError = ashpd::Error;
|
pub type DialogError = ashpd::Error;
|
||||||
|
|
||||||
#[cfg(feature = "rfd")]
|
#[cfg(feature = "rfd")]
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
//! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog)
|
//! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog)
|
||||||
//! example in our repository.
|
//! example in our repository.
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub use portal::{FileResponse, MultiFileResponse, file, files, folder, folders};
|
pub use portal::{FileResponse, MultiFileResponse, file, files, folder, folders};
|
||||||
|
|
||||||
#[cfg(feature = "rfd")]
|
#[cfg(feature = "rfd")]
|
||||||
|
|
@ -24,7 +24,7 @@ pub struct Dialog {
|
||||||
title: String,
|
title: String,
|
||||||
|
|
||||||
/// The label for the accept button. Mnemonic underlines are allowed.
|
/// The label for the accept button. Mnemonic underlines are allowed.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
accept_label: Option<String>,
|
accept_label: Option<String>,
|
||||||
|
|
||||||
|
|
@ -39,17 +39,17 @@ pub struct Dialog {
|
||||||
file_name: Option<String>,
|
file_name: Option<String>,
|
||||||
|
|
||||||
/// Modal dialogs require user input before continuing the program.
|
/// Modal dialogs require user input before continuing the program.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
modal: bool,
|
modal: bool,
|
||||||
|
|
||||||
/// Adds a list of choices.
|
/// Adds a list of choices.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
choices: Vec<super::Choice>,
|
choices: Vec<super::Choice>,
|
||||||
|
|
||||||
/// Specifies the default file filter.
|
/// Specifies the default file filter.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
current_filter: Option<super::FileFilter>,
|
current_filter: Option<super::FileFilter>,
|
||||||
|
|
||||||
|
|
@ -62,36 +62,36 @@ impl Dialog {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
accept_label: None,
|
accept_label: None,
|
||||||
directory: None,
|
directory: None,
|
||||||
file_name: None,
|
file_name: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
modal: true,
|
modal: true,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
current_filter: None,
|
current_filter: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
choices: Vec::new(),
|
choices: Vec::new(),
|
||||||
filters: Vec::new(),
|
filters: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The label for the accept button. Mnemonic underlines are allowed.
|
/// The label for the accept button. Mnemonic underlines are allowed.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn accept_label(mut self, label: impl Into<String>) -> Self {
|
pub fn accept_label(mut self, label: impl Into<String>) -> Self {
|
||||||
self.accept_label = Some(label.into());
|
self.accept_label = Some(label.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a choice.
|
/// Adds a choice.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn choice(mut self, choice: impl Into<super::Choice>) -> Self {
|
pub fn choice(mut self, choice: impl Into<super::Choice>) -> Self {
|
||||||
self.choices.push(choice.into());
|
self.choices.push(choice.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Specifies the default file filter.
|
/// Specifies the default file filter.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn current_filter(mut self, filter: impl Into<super::FileFilter>) -> Self {
|
pub fn current_filter(mut self, filter: impl Into<super::FileFilter>) -> Self {
|
||||||
self.current_filter = Some(filter.into());
|
self.current_filter = Some(filter.into());
|
||||||
self
|
self
|
||||||
|
|
@ -104,7 +104,7 @@ impl Dialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modal dialogs require user input before continuing the program.
|
/// Modal dialogs require user input before continuing the program.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn modal(mut self, modal: bool) -> Self {
|
pub fn modal(mut self, modal: bool) -> Self {
|
||||||
self.modal = modal;
|
self.modal = modal;
|
||||||
self
|
self
|
||||||
|
|
@ -131,7 +131,7 @@ impl Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
mod portal {
|
mod portal {
|
||||||
use super::Dialog;
|
use super::Dialog;
|
||||||
use crate::dialog::file_chooser::Error;
|
use crate::dialog::file_chooser::Error;
|
||||||
|
|
@ -147,7 +147,7 @@ mod portal {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new file dialog, and begins to await its responses.
|
/// Creates a new file dialog, and begins to await its responses.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
dialog: super::Dialog,
|
dialog: super::Dialog,
|
||||||
folders: bool,
|
folders: bool,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
//! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog)
|
//! Check out the [open-dialog](https://github.com/pop-os/libcosmic/tree/master/examples/open-dialog)
|
||||||
//! example in our repository.
|
//! example in our repository.
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub use portal::{Response, file};
|
pub use portal::{Response, file};
|
||||||
|
|
||||||
#[cfg(feature = "rfd")]
|
#[cfg(feature = "rfd")]
|
||||||
|
|
@ -23,12 +23,12 @@ pub struct Dialog {
|
||||||
title: String,
|
title: String,
|
||||||
|
|
||||||
/// The label for the accept button. Mnemonic underlines are allowed.
|
/// The label for the accept button. Mnemonic underlines are allowed.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
accept_label: Option<String>,
|
accept_label: Option<String>,
|
||||||
|
|
||||||
/// Modal dialogs require user input before continuing the program.
|
/// Modal dialogs require user input before continuing the program.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
modal: bool,
|
modal: bool,
|
||||||
|
|
||||||
|
|
@ -41,17 +41,17 @@ pub struct Dialog {
|
||||||
directory: Option<PathBuf>,
|
directory: Option<PathBuf>,
|
||||||
|
|
||||||
/// Sets the absolute path of the file
|
/// Sets the absolute path of the file
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
current_file: Option<PathBuf>,
|
current_file: Option<PathBuf>,
|
||||||
|
|
||||||
/// Adds a list of choices.
|
/// Adds a list of choices.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
choices: Vec<super::Choice>,
|
choices: Vec<super::Choice>,
|
||||||
|
|
||||||
/// Specifies the default file filter.
|
/// Specifies the default file filter.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[setters(skip)]
|
#[setters(skip)]
|
||||||
current_filter: Option<super::FileFilter>,
|
current_filter: Option<super::FileFilter>,
|
||||||
|
|
||||||
|
|
@ -64,38 +64,38 @@ impl Dialog {
|
||||||
pub const fn new() -> Self {
|
pub const fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
title: String::new(),
|
title: String::new(),
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
accept_label: None,
|
accept_label: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
modal: true,
|
modal: true,
|
||||||
file_name: None,
|
file_name: None,
|
||||||
directory: None,
|
directory: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
current_file: None,
|
current_file: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
current_filter: None,
|
current_filter: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
choices: Vec::new(),
|
choices: Vec::new(),
|
||||||
filters: Vec::new(),
|
filters: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The label for the accept button. Mnemonic underlines are allowed.
|
/// The label for the accept button. Mnemonic underlines are allowed.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn accept_label(mut self, label: impl Into<String>) -> Self {
|
pub fn accept_label(mut self, label: impl Into<String>) -> Self {
|
||||||
self.accept_label = Some(label.into());
|
self.accept_label = Some(label.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a choice.
|
/// Adds a choice.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn choice(mut self, choice: impl Into<super::Choice>) -> Self {
|
pub fn choice(mut self, choice: impl Into<super::Choice>) -> Self {
|
||||||
self.choices.push(choice.into());
|
self.choices.push(choice.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the current file filter.
|
/// Set the current file filter.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn current_filter(mut self, filter: impl Into<super::FileFilter>) -> Self {
|
pub fn current_filter(mut self, filter: impl Into<super::FileFilter>) -> Self {
|
||||||
self.current_filter = Some(filter.into());
|
self.current_filter = Some(filter.into());
|
||||||
self
|
self
|
||||||
|
|
@ -108,7 +108,7 @@ impl Dialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Modal dialogs require user input before continuing the program.
|
/// Modal dialogs require user input before continuing the program.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub fn modal(mut self, modal: bool) -> Self {
|
pub fn modal(mut self, modal: bool) -> Self {
|
||||||
self.modal = modal;
|
self.modal = modal;
|
||||||
self
|
self
|
||||||
|
|
@ -126,7 +126,7 @@ impl Default for Dialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
mod portal {
|
mod portal {
|
||||||
use super::Dialog;
|
use super::Dialog;
|
||||||
use crate::dialog::file_chooser::Error;
|
use crate::dialog::file_chooser::Error;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
//! Create dialogs for retrieving user input.
|
//! Create dialogs for retrieving user input.
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub use ashpd;
|
pub use ashpd;
|
||||||
|
|
||||||
pub mod file_chooser;
|
pub mod file_chooser;
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ pub use dbus_activation::DbusActivation;
|
||||||
#[cfg(feature = "desktop")]
|
#[cfg(feature = "desktop")]
|
||||||
pub mod desktop;
|
pub mod desktop;
|
||||||
|
|
||||||
#[cfg(any(feature = "xdg-portal", feature = "rfd"))]
|
#[cfg(any(xdg_portal, feature = "rfd"))]
|
||||||
pub mod dialog;
|
pub mod dialog;
|
||||||
|
|
||||||
pub mod executor;
|
pub mod executor;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
//! Contains the [`Theme`] type and its widget stylesheet implementations.
|
//! Contains the [`Theme`] type and its widget stylesheet implementations.
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub mod portal;
|
pub mod portal;
|
||||||
pub mod style;
|
pub mod style;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ pub fn dnd_destination_for_data<'a, T: AllowedMimeTypes, Message: 'static>(
|
||||||
|
|
||||||
static DRAG_ID_COUNTER: AtomicU64 = AtomicU64::new(0);
|
static DRAG_ID_COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||||
const DND_DEST_LOG_TARGET: &str = "libcosmic::widget::dnd_destination";
|
const DND_DEST_LOG_TARGET: &str = "libcosmic::widget::dnd_destination";
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
pub const FILE_TRANSFER_MIME: &str = "application/vnd.portal.filetransfer";
|
pub const FILE_TRANSFER_MIME: &str = "application/vnd.portal.filetransfer";
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
|
@ -64,7 +64,7 @@ pub struct DndDestination<'a, Message> {
|
||||||
on_action_selected: Option<Box<dyn Fn(DndAction) -> Message>>,
|
on_action_selected: Option<Box<dyn Fn(DndAction) -> Message>>,
|
||||||
on_data_received: Option<Box<dyn Fn(String, Vec<u8>) -> Message>>,
|
on_data_received: Option<Box<dyn Fn(String, Vec<u8>) -> Message>>,
|
||||||
on_finish: Option<Box<dyn Fn(String, Vec<u8>, DndAction, f64, f64) -> Message>>,
|
on_finish: Option<Box<dyn Fn(String, Vec<u8>, DndAction, f64, f64) -> Message>>,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
on_file_transfer: Option<Box<dyn Fn(String) -> Message>>,
|
on_file_transfer: Option<Box<dyn Fn(String) -> Message>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> {
|
||||||
on_action_selected: None,
|
on_action_selected: None,
|
||||||
on_data_received: None,
|
on_data_received: None,
|
||||||
on_finish: None,
|
on_finish: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
on_file_transfer: None,
|
on_file_transfer: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +119,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> {
|
||||||
on_finish: Some(Box::new(move |mime, data, action, _, _| {
|
on_finish: Some(Box::new(move |mime, data, action, _, _| {
|
||||||
on_finish(T::try_from((data, mime)).ok(), action)
|
on_finish(T::try_from((data, mime)).ok(), action)
|
||||||
})),
|
})),
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
on_file_transfer: None,
|
on_file_transfer: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -156,7 +156,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> {
|
||||||
on_action_selected: None,
|
on_action_selected: None,
|
||||||
on_data_received: None,
|
on_data_received: None,
|
||||||
on_finish: None,
|
on_finish: None,
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
on_file_transfer: None,
|
on_file_transfer: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,7 +239,7 @@ impl<'a, Message: 'static> DndDestination<'a, Message> {
|
||||||
/// Add a message that will be emitted instead of [`on_data_received`](Self::on_data_received) if the dropped files
|
/// Add a message that will be emitted instead of [`on_data_received`](Self::on_data_received) if the dropped files
|
||||||
/// are offered through the xdg share portal. You can then use [`crate::command::file_transfer_receive`]
|
/// are offered through the xdg share portal. You can then use [`crate::command::file_transfer_receive`]
|
||||||
/// with the key to receive the files.
|
/// with the key to receive the files.
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn on_file_transfer(mut self, f: impl Fn(String) -> Message + 'static) -> Self {
|
pub fn on_file_transfer(mut self, f: impl Fn(String) -> Message + 'static) -> Self {
|
||||||
match self.mime_types.iter().position(|v| v == "text/uri-list") {
|
match self.mime_types.iter().position(|v| v == "text/uri-list") {
|
||||||
|
|
@ -514,7 +514,7 @@ impl<Message: 'static> Widget<Message, crate::Theme, crate::Renderer>
|
||||||
data.len()
|
data.len()
|
||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "xdg-portal")]
|
#[cfg(xdg_portal)]
|
||||||
if mime_type == FILE_TRANSFER_MIME
|
if mime_type == FILE_TRANSFER_MIME
|
||||||
&& let Some(f) = self.on_file_transfer.as_ref()
|
&& let Some(f) = self.on_file_transfer.as_ref()
|
||||||
&& let Ok(s) = String::from_utf8(data[..data.len() - 1].to_vec())
|
&& let Ok(s) = String::from_utf8(data[..data.len() - 1].to_vec())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue