// This file was generated by gir (https://github.com/gtk-rs/gir)
// from ../gir-files
// from ../pps-girs
// DO NOT EDIT

use crate::{ffi, Job};
use glib::{prelude::*, translate::*};

glib::wrapper! {
    #[doc(alias = "PpsJobLoad")]
    pub struct JobLoad(Object<ffi::PpsJobLoad, ffi::PpsJobLoadClass>) @extends Job;

    match fn {
        type_ => || ffi::pps_job_load_get_type(),
    }
}

impl JobLoad {
    pub const NONE: Option<&'static JobLoad> = None;

    #[doc(alias = "pps_job_load_new")]
    pub fn new() -> JobLoad {
        assert_initialized_main_thread!();
        unsafe { Job::from_glib_full(ffi::pps_job_load_new()).unsafe_cast() }
    }
}

impl Default for JobLoad {
    fn default() -> Self {
        Self::new()
    }
}

pub trait JobLoadExt: IsA<JobLoad> + 'static {
    #[cfg(feature = "v46")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v46")))]
    #[doc(alias = "pps_job_load_get_loaded_document")]
    #[doc(alias = "get_loaded_document")]
    fn loaded_document(&self) -> Option<papers_document::Document> {
        unsafe {
            from_glib_full(ffi::pps_job_load_get_loaded_document(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_job_load_get_password")]
    #[doc(alias = "get_password")]
    fn password(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::pps_job_load_get_password(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "pps_job_load_get_password_save")]
    #[doc(alias = "get_password_save")]
    fn password_save(&self) -> gio::PasswordSave {
        unsafe {
            from_glib(ffi::pps_job_load_get_password_save(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    #[cfg(feature = "v46")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v46")))]
    #[doc(alias = "pps_job_load_set_fd")]
    fn set_fd(&self, fd: i32, mime_type: &str) -> Result<(), glib::Error> {
        unsafe {
            let mut error = std::ptr::null_mut();
            let is_ok = ffi::pps_job_load_set_fd(
                self.as_ref().to_glib_none().0,
                fd,
                mime_type.to_glib_none().0,
                &mut error,
            );
            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
            if error.is_null() {
                Ok(())
            } else {
                Err(from_glib_full(error))
            }
        }
    }

    #[doc(alias = "pps_job_load_set_password")]
    fn set_password(&self, password: Option<&str>) {
        unsafe {
            ffi::pps_job_load_set_password(
                self.as_ref().to_glib_none().0,
                password.to_glib_none().0,
            );
        }
    }

    #[doc(alias = "pps_job_load_set_password_save")]
    fn set_password_save(&self, save: gio::PasswordSave) {
        unsafe {
            ffi::pps_job_load_set_password_save(self.as_ref().to_glib_none().0, save.into_glib());
        }
    }

    #[doc(alias = "pps_job_load_set_uri")]
    fn set_uri(&self, uri: &str) {
        unsafe {
            ffi::pps_job_load_set_uri(self.as_ref().to_glib_none().0, uri.to_glib_none().0);
        }
    }

    #[cfg(feature = "v46")]
    #[cfg_attr(docsrs, doc(cfg(feature = "v46")))]
    #[doc(alias = "pps_job_load_take_fd")]
    fn take_fd(&self, fd: i32, mime_type: &str) {
        unsafe {
            ffi::pps_job_load_take_fd(
                self.as_ref().to_glib_none().0,
                fd,
                mime_type.to_glib_none().0,
            );
        }
    }
}

impl<O: IsA<JobLoad>> JobLoadExt for O {}
