[go: up one dir, main page]

logo
Expand description

Open/save file(s) chooser.

Examples

Opening a file

use ashpd::desktop::file_chooser::{Choice, FileChooserProxy, FileFilter, OpenFileOptions};
use ashpd::WindowIdentifier;

async fn run() -> ashpd::Result<()> {
    let connection = zbus::Connection::session().await?;

    let proxy = FileChooserProxy::new(&connection).await?;
    let files = proxy
        .open_file(
            &WindowIdentifier::default(),
            "open a file to read",
            OpenFileOptions::default()
                .accept_label("read")
                .modal(true)
                .multiple(true)
                .add_choice(
                    Choice::new("encoding", "Encoding", "latin15")
                        .insert("utf8", "Unicode (UTF-8)")
                        .insert("latin15", "Western"),
                )
                // A trick to have a checkbox
                .add_choice(Choice::boolean("re-encode", "Re-encode", false))
                .add_filter(FileFilter::new("SVG Image").mimetype("image/svg+xml")),
        )
        .await?;

    println!("{:#?}", files);

    Ok(())
}

Ask to save a file

use ashpd::desktop::file_chooser::{FileChooserProxy, FileFilter, SaveFileOptions};
use ashpd::WindowIdentifier;

async fn run() -> ashpd::Result<()> {
    let connection = zbus::Connection::session().await?;
    let proxy = FileChooserProxy::new(&connection).await?;
    let files = proxy
        .save_file(
            &WindowIdentifier::default(),
            "open a file to write",
            SaveFileOptions::default()
                .accept_label("write")
                .current_name("image.jpg")
                .modal(true)
                .add_filter(FileFilter::new("JPEG Image").glob("*.jpg")),
        )
        .await?;

    println!("{:#?}", files);

    Ok(())
}

Ask to save multiple files

use ashpd::desktop::file_chooser::{FileChooserProxy, SaveFilesOptions};
use ashpd::WindowIdentifier;

async fn run() -> ashpd::Result<()> {
    let connection = zbus::Connection::session().await?;

    let proxy = FileChooserProxy::new(&connection).await?;
    let files = proxy
        .save_files(
            &WindowIdentifier::default(),
            "open files to write",
            SaveFilesOptions::default()
                .accept_label("write files")
                .modal(true)
                .current_folder("/home/bilelmoussaoui/Pictures")
                .files(&["test.jpg", "awesome.png"]),
        )
        .await?;

    println!("{:#?}", files);

    Ok(())
}

Structs

Presents the user with a choice to select from or as a checkbox.

The interface lets sandboxed applications ask the user for access to files outside the sandbox. The portal backend will present the user with a file chooser dialog.

A file filter, to limit the available file choices to a mimetype or a glob pattern.

Specified options for a FileChooserProxy::open_file request.

Specified options for a FileChooserProxy::save_file request.

Specified options for a FileChooserProxy::save_files request.