diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e47d9bb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "rust-analyzer.linkedProjects": [ + "./Cargo.toml", + "./Cargo.toml" + ] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index a49352e..e95beb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,6 +23,17 @@ version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec6d3da8e550377a85339063af6e3735f4b1d9392108da4e083a1b3b9820288" +[[package]] +name = "dbus" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" +dependencies = [ + "libc", + "libdbus-sys", + "winapi", +] + [[package]] name = "getrandom" version = "0.2.12" @@ -46,6 +57,15 @@ version = "0.2.153" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +[[package]] +name = "libdbus-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" +dependencies = [ + "pkg-config", +] + [[package]] name = "memchr" version = "2.7.1" @@ -57,11 +77,18 @@ name = "mycelium" version = "0.1.0" dependencies = [ "configparser", + "dbus", "glob", "rand", "untildify", ] +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -139,3 +166,25 @@ name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index bad2c32..6b011ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ edition = "2021" [dependencies] configparser = "3.0.4" +dbus = "0.9.7" glob = "0.3.1" rand = "0.8.5" untildify = { path = "../untildify" } diff --git a/src/config.rs b/src/config.rs index e4e0f72..e4ceff1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,7 @@ use untildify; #[derive(Debug)] pub struct Monitors { - monitors: Vec, + pub monitors: Vec, } impl Monitors { diff --git a/src/files.rs b/src/files.rs index 41b9e31..47c62be 100644 --- a/src/files.rs +++ b/src/files.rs @@ -2,8 +2,6 @@ use core::fmt; use glob::glob; use rand::seq::SliceRandom; use std::fmt::Write as _; -use std::io::Write as _; -use std::process::exit; use crate::config::*; use crate::enums::*; @@ -44,31 +42,16 @@ impl Wallpapers { ), } } - // Todo implement a random selector for a given key, like `wallpapers.random_selection(MonitorType::Ultrawide)` - pub fn random_selection(&self, monitor_type: MonitorType) { + + pub fn random_selection(&self, monitor_type: &MonitorType) -> &Wallpaper { match monitor_type { - MonitorType::Ultrawide => { - println!( - "{:?}", - self.ultrawide.choose(&mut rand::thread_rng()).unwrap() - ); - } - MonitorType::Horizontal => { - println!( - "{:?}", - self.horizontal.choose(&mut rand::thread_rng()).unwrap() - ); - } - MonitorType::Vertical => { - println!( - "{:?}", - self.vertical.choose(&mut rand::thread_rng()).unwrap() - ); - } - _ => {} + MonitorType::Ultrawide => self.ultrawide.choose(&mut rand::thread_rng()).unwrap(), + MonitorType::Horizontal => self.horizontal.choose(&mut rand::thread_rng()).unwrap(), + MonitorType::Vertical => self.vertical.choose(&mut rand::thread_rng()).unwrap(), + _ => self.horizontal.choose(&mut rand::thread_rng()).unwrap(), } } - // Todo implement a function to load all files of particular filetypes into the Vec + pub fn load_images(&mut self, monitor_type: MonitorType) { let path = self .config @@ -99,7 +82,7 @@ impl Wallpapers { MonitorType::Ultrawide => self.ultrawide.push(Wallpaper { path: filepath }), MonitorType::Horizontal => self.horizontal.push(Wallpaper { path: filepath }), MonitorType::Vertical => self.vertical.push(Wallpaper { path: filepath }), - _ => {} + MonitorType::Error => self.horizontal.push(Wallpaper { path: filepath }), } } diff --git a/src/handlers/dbus.rs b/src/handlers/dbus.rs new file mode 100644 index 0000000..ab4dc30 --- /dev/null +++ b/src/handlers/dbus.rs @@ -0,0 +1,43 @@ +use dbus::blocking::Connection; +use std::time::Duration; + +pub fn test() -> Result<(), Box> { + // First open up a connection to the session bus + let conn = Connection::new_session()?; + + // Second, create a wrapper struct around the connection that makes it easy + // to send method calls to a specific destination and path. + let proxy = conn.with_proxy( + "org.kde.plasmashell", + "/PlasmaShell", + Duration::from_millis(5000), + ); + + use dbus_s::OrgKdePlasmaShell; + // Now make the method call. The ListNames method call takes zero input parameters and + // one output parameter which is an array of strings + // Therefore the input is a zero tuple "()", and the output is a single tuple "(names, )" + + let test = " + var allDesktops = desktops(); + allDesktops[0].wallpaperPlugin = 'org.kde.image'; + allDesktops[0].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General'); + allDesktops[0].writeConfig('Image', 'file:///home/ben/Pictures/wallpaper-ultra/wallhaven-pkj7gm.png');w + allDesktops[1].wallpaperPlugin = 'org.kde.image'; + allDesktops[1].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General'); + allDesktops[1].writeConfig('Image', 'file:///home/ben/Pictures/wallpaper-hor/papes/1490136858978.jpg'); + "; + + proxy.evaluate_script(test); + + // let (_, error): (String, dbus::Error) = proxy + // .method_call("org.kde.PlasmaShell", "evaluateScript", (test,)) + // .unwrap(); + + // Let's print all the names to stdout + // for name in names { + // println!("{}", name); + // } + + Ok(()) +} diff --git a/src/handlers/dbus_s.rs b/src/handlers/dbus_s.rs new file mode 100644 index 0000000..ba83f95 --- /dev/null +++ b/src/handlers/dbus_s.rs @@ -0,0 +1,276 @@ +// This code was autogenerated with `dbus-codegen-rust -g -m None -d org.kde.plasmashell -p /PlasmaShell`, see https://github.com/diwic/dbus-rs +use dbus; +#[allow(unused_imports)] +use dbus::arg; +use dbus::blocking; + +pub trait OrgKdePlasmaShell { + fn toggle_dashboard(&self) -> Result<(), dbus::Error>; + fn toggle_activity_manager(&self) -> Result<(), dbus::Error>; + fn toggle_widget_explorer(&self) -> Result<(), dbus::Error>; + fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error>; + fn evaluate_script(&self, script: &str) -> Result; + fn color(&self) -> Result; + fn dump_current_layout_js(&self) -> Result, dbus::Error>; + fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error>; + fn activate_launcher_menu(&self) -> Result<(), dbus::Error>; + fn refresh_current_shell(&self) -> Result<(), dbus::Error>; + fn wallpaper(&self, screen_num: u32) -> Result; + fn set_wallpaper( + &self, + wallpaper_plugin: &str, + parameters: &str, + screen_num: u32, + ) -> Result<(), dbus::Error>; + fn edit_mode(&self) -> Result; + fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error>; +} + +#[derive(Debug)] +pub struct OrgKdePlasmaShellWallpaperChanged { + pub screen_num: u32, +} + +impl arg::AppendAll for OrgKdePlasmaShellWallpaperChanged { + fn append(&self, i: &mut arg::IterAppend) { + arg::RefArg::append(&self.screen_num, i); + } +} + +impl arg::ReadAll for OrgKdePlasmaShellWallpaperChanged { + fn read(i: &mut arg::Iter) -> Result { + Ok(OrgKdePlasmaShellWallpaperChanged { + screen_num: i.read()?, + }) + } +} + +impl dbus::message::SignalArgs for OrgKdePlasmaShellWallpaperChanged { + const NAME: &'static str = "wallpaperChanged"; + const INTERFACE: &'static str = "org.kde.PlasmaShell"; +} + +#[derive(Debug)] +pub struct OrgKdePlasmaShellColorChanged { + pub changed_color: String, +} + +impl arg::AppendAll for OrgKdePlasmaShellColorChanged { + fn append(&self, i: &mut arg::IterAppend) { + arg::RefArg::append(&self.changed_color, i); + } +} + +impl arg::ReadAll for OrgKdePlasmaShellColorChanged { + fn read(i: &mut arg::Iter) -> Result { + Ok(OrgKdePlasmaShellColorChanged { + changed_color: i.read()?, + }) + } +} + +impl dbus::message::SignalArgs for OrgKdePlasmaShellColorChanged { + const NAME: &'static str = "colorChanged"; + const INTERFACE: &'static str = "org.kde.PlasmaShell"; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgKdePlasmaShell + for blocking::Proxy<'a, C> +{ + fn toggle_dashboard(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "toggleDashboard", ()) + } + + fn toggle_activity_manager(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "toggleActivityManager", ()) + } + + fn toggle_widget_explorer(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "toggleWidgetExplorer", ()) + } + + fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "setDashboardShown", (show,)) + } + + fn evaluate_script(&self, script: &str) -> Result { + self.method_call("org.kde.PlasmaShell", "evaluateScript", (script,)) + .and_then(|r: (String,)| Ok(r.0)) + } + + fn color(&self) -> Result { + self.method_call("org.kde.PlasmaShell", "color", ()) + .and_then(|r: (u32,)| Ok(r.0)) + } + + fn dump_current_layout_js(&self) -> Result, dbus::Error> { + self.method_call("org.kde.PlasmaShell", "dumpCurrentLayoutJS", ()) + .and_then(|r: (Vec,)| Ok(r.0)) + } + + fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error> { + self.method_call( + "org.kde.PlasmaShell", + "loadLookAndFeelDefaultLayout", + (layout,), + ) + } + + fn activate_launcher_menu(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "activateLauncherMenu", ()) + } + + fn refresh_current_shell(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "refreshCurrentShell", ()) + } + + fn wallpaper(&self, screen_num: u32) -> Result { + self.method_call("org.kde.PlasmaShell", "wallpaper", (screen_num,)) + .and_then(|r: (arg::PropMap,)| Ok(r.0)) + } + + fn set_wallpaper( + &self, + wallpaper_plugin: &str, + parameters: &str, + screen_num: u32, + ) -> Result<(), dbus::Error> { + self.method_call( + "org.kde.PlasmaShell", + "setWallpaper", + (wallpaper_plugin, parameters, screen_num), + ) + } + + fn edit_mode(&self) -> Result { + ::get( + self, + "org.kde.PlasmaShell", + "editMode", + ) + } + + fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error> { + ::set( + self, + "org.kde.PlasmaShell", + "editMode", + value, + ) + } +} + +pub trait OrgFreedesktopDBusProperties { + fn get arg::Get<'b> + 'static>( + &self, + interface_name: &str, + property_name: &str, + ) -> Result; + fn set( + &self, + interface_name: &str, + property_name: &str, + value: I2, + ) -> Result<(), dbus::Error>; + fn get_all(&self, interface_name: &str) -> Result; +} + +#[derive(Debug)] +pub struct OrgFreedesktopDBusPropertiesPropertiesChanged { + pub interface_name: String, + pub changed_properties: arg::PropMap, + pub invalidated_properties: Vec, +} + +impl arg::AppendAll for OrgFreedesktopDBusPropertiesPropertiesChanged { + fn append(&self, i: &mut arg::IterAppend) { + arg::RefArg::append(&self.interface_name, i); + arg::RefArg::append(&self.changed_properties, i); + arg::RefArg::append(&self.invalidated_properties, i); + } +} + +impl arg::ReadAll for OrgFreedesktopDBusPropertiesPropertiesChanged { + fn read(i: &mut arg::Iter) -> Result { + Ok(OrgFreedesktopDBusPropertiesPropertiesChanged { + interface_name: i.read()?, + changed_properties: i.read()?, + invalidated_properties: i.read()?, + }) + } +} + +impl dbus::message::SignalArgs for OrgFreedesktopDBusPropertiesPropertiesChanged { + const NAME: &'static str = "PropertiesChanged"; + const INTERFACE: &'static str = "org.freedesktop.DBus.Properties"; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgFreedesktopDBusProperties + for blocking::Proxy<'a, C> +{ + fn get arg::Get<'b> + 'static>( + &self, + interface_name: &str, + property_name: &str, + ) -> Result { + self.method_call( + "org.freedesktop.DBus.Properties", + "Get", + (interface_name, property_name), + ) + .and_then(|r: (arg::Variant,)| Ok((r.0).0)) + } + + fn set( + &self, + interface_name: &str, + property_name: &str, + value: I2, + ) -> Result<(), dbus::Error> { + self.method_call( + "org.freedesktop.DBus.Properties", + "Set", + (interface_name, property_name, arg::Variant(value)), + ) + } + + fn get_all(&self, interface_name: &str) -> Result { + self.method_call( + "org.freedesktop.DBus.Properties", + "GetAll", + (interface_name,), + ) + .and_then(|r: (arg::PropMap,)| Ok(r.0)) + } +} + +pub trait OrgFreedesktopDBusIntrospectable { + fn introspect(&self) -> Result; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> + OrgFreedesktopDBusIntrospectable for blocking::Proxy<'a, C> +{ + fn introspect(&self) -> Result { + self.method_call("org.freedesktop.DBus.Introspectable", "Introspect", ()) + .and_then(|r: (String,)| Ok(r.0)) + } +} + +pub trait OrgFreedesktopDBusPeer { + fn ping(&self) -> Result<(), dbus::Error>; + fn get_machine_id(&self) -> Result; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgFreedesktopDBusPeer + for blocking::Proxy<'a, C> +{ + fn ping(&self) -> Result<(), dbus::Error> { + self.method_call("org.freedesktop.DBus.Peer", "Ping", ()) + } + + fn get_machine_id(&self) -> Result { + self.method_call("org.freedesktop.DBus.Peer", "GetMachineId", ()) + .and_then(|r: (String,)| Ok(r.0)) + } +} diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs new file mode 100644 index 0000000..a408d83 --- /dev/null +++ b/src/handlers/mod.rs @@ -0,0 +1,4 @@ +pub mod dbus_s; +use dbus_s::*; +pub mod plasma; +use plasma::*; diff --git a/src/handlers/plasma.rs b/src/handlers/plasma.rs new file mode 100644 index 0000000..ad34944 --- /dev/null +++ b/src/handlers/plasma.rs @@ -0,0 +1,57 @@ +use crate::config::Monitors; +use crate::handlers::dbus_s; +use crate::Wallpapers; + +use dbus::blocking::Connection; +use std::fmt::Write as _; +use std::time::Duration; + +pub fn change_wallpapers(wallpapers: &Wallpapers) { + // First open up a connection to the session bus + let conn = Connection::new_session().unwrap(); + + // Second, create a wrapper struct around the connection that makes it easy + // to send method calls to a specific destination and path. + let proxy = conn.with_proxy( + "org.kde.plasmashell", + "/PlasmaShell", + Duration::from_millis(5000), + ); + + use dbus_s::OrgKdePlasmaShell; + + let javascript = generate_js(wallpapers); + let resp = proxy.evaluate_script(javascript.as_ref()); + match resp { + Ok(str) => {} + Err(e) => println!("{}", e), + } +} + +pub fn generate_js(wallpapers: &Wallpapers) -> String { + let mut javascript = String::new(); + javascript.push_str("var allDesktops = desktops();\n"); + let mut count = 0; + for monitor in wallpapers.config.monitors.monitors.iter() { + let mut file_buff = String::new(); + let _ = write!( + &mut file_buff, + "file://{}", + wallpapers.random_selection(monitor) + ); + let mut boilerplate = String::new(); + // let boilerplate_formatter = ; + let _ = write!( + &mut boilerplate, + " + allDesktops[{0}].wallpaperPlugin = 'org.kde.image'; + allDesktops[{0}].currentConfigGroup = Array('Wallpaper', 'org.kde.image', 'General'); + allDesktops[{0}].writeConfig('Image', '{1}'); + ", + count, file_buff + ); + javascript.push_str(&boilerplate); + count += 1; + } + javascript +} diff --git a/src/main.rs b/src/main.rs index 6c58361..508fd6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,11 +3,15 @@ mod enums; use enums::*; mod files; use files::*; +mod handlers; fn main() { let mut wallpapers = Wallpapers::new(); wallpapers.load_all(); - wallpapers.random_selection(MonitorType::Ultrawide); - println!("{}", ""); + wallpapers.random_selection(&MonitorType::Ultrawide); + wallpapers.random_selection(&MonitorType::Horizontal); + wallpapers.random_selection(&MonitorType::Vertical); + let resp = handlers::plasma::change_wallpapers(&wallpapers); + // println!("{}", resp); } diff --git a/test.rs b/test.rs new file mode 100644 index 0000000..8f51ab7 --- /dev/null +++ b/test.rs @@ -0,0 +1,215 @@ +// This code was autogenerated with `dbus-codegen-rust -g -m None -d org.kde.plasmashell -p /PlasmaShell`, see https://github.com/diwic/dbus-rs +use dbus as dbus; +#[allow(unused_imports)] +use dbus::arg; +use dbus::blocking; + +pub trait OrgKdePlasmaShell { + fn toggle_dashboard(&self) -> Result<(), dbus::Error>; + fn toggle_activity_manager(&self) -> Result<(), dbus::Error>; + fn toggle_widget_explorer(&self) -> Result<(), dbus::Error>; + fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error>; + fn evaluate_script(&self, script: &str) -> Result; + fn color(&self) -> Result; + fn dump_current_layout_js(&self) -> Result, dbus::Error>; + fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error>; + fn activate_launcher_menu(&self) -> Result<(), dbus::Error>; + fn refresh_current_shell(&self) -> Result<(), dbus::Error>; + fn wallpaper(&self, screen_num: u32) -> Result; + fn set_wallpaper(&self, wallpaper_plugin: &str, parameters: arg::PropMap, screen_num: u32) -> Result<(), dbus::Error>; + fn edit_mode(&self) -> Result; + fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error>; +} + +#[derive(Debug)] +pub struct OrgKdePlasmaShellWallpaperChanged { + pub screen_num: u32, +} + +impl arg::AppendAll for OrgKdePlasmaShellWallpaperChanged { + fn append(&self, i: &mut arg::IterAppend) { + arg::RefArg::append(&self.screen_num, i); + } +} + +impl arg::ReadAll for OrgKdePlasmaShellWallpaperChanged { + fn read(i: &mut arg::Iter) -> Result { + Ok(OrgKdePlasmaShellWallpaperChanged { + screen_num: i.read()?, + }) + } +} + +impl dbus::message::SignalArgs for OrgKdePlasmaShellWallpaperChanged { + const NAME: &'static str = "wallpaperChanged"; + const INTERFACE: &'static str = "org.kde.PlasmaShell"; +} + +#[derive(Debug)] +pub struct OrgKdePlasmaShellColorChanged { + pub changed_color: String, +} + +impl arg::AppendAll for OrgKdePlasmaShellColorChanged { + fn append(&self, i: &mut arg::IterAppend) { + arg::RefArg::append(&self.changed_color, i); + } +} + +impl arg::ReadAll for OrgKdePlasmaShellColorChanged { + fn read(i: &mut arg::Iter) -> Result { + Ok(OrgKdePlasmaShellColorChanged { + changed_color: i.read()?, + }) + } +} + +impl dbus::message::SignalArgs for OrgKdePlasmaShellColorChanged { + const NAME: &'static str = "colorChanged"; + const INTERFACE: &'static str = "org.kde.PlasmaShell"; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgKdePlasmaShell for blocking::Proxy<'a, C> { + + fn toggle_dashboard(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "toggleDashboard", ()) + } + + fn toggle_activity_manager(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "toggleActivityManager", ()) + } + + fn toggle_widget_explorer(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "toggleWidgetExplorer", ()) + } + + fn set_dashboard_shown(&self, show: bool) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "setDashboardShown", (show, )) + } + + fn evaluate_script(&self, script: &str) -> Result { + self.method_call("org.kde.PlasmaShell", "evaluateScript", (script, )) + .and_then(|r: (String, )| Ok(r.0, )) + } + + fn color(&self) -> Result { + self.method_call("org.kde.PlasmaShell", "color", ()) + .and_then(|r: (u32, )| Ok(r.0, )) + } + + fn dump_current_layout_js(&self) -> Result, dbus::Error> { + self.method_call("org.kde.PlasmaShell", "dumpCurrentLayoutJS", ()) + .and_then(|r: (Vec, )| Ok(r.0, )) + } + + fn load_look_and_feel_default_layout(&self, layout: &str) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "loadLookAndFeelDefaultLayout", (layout, )) + } + + fn activate_launcher_menu(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "activateLauncherMenu", ()) + } + + fn refresh_current_shell(&self) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "refreshCurrentShell", ()) + } + + fn wallpaper(&self, screen_num: u32) -> Result { + self.method_call("org.kde.PlasmaShell", "wallpaper", (screen_num, )) + .and_then(|r: (arg::PropMap, )| Ok(r.0, )) + } + + fn set_wallpaper(&self, wallpaper_plugin: &str, parameters: arg::PropMap, screen_num: u32) -> Result<(), dbus::Error> { + self.method_call("org.kde.PlasmaShell", "setWallpaper", (wallpaper_plugin, parameters, screen_num, )) + } + + fn edit_mode(&self) -> Result { + ::get(self, "org.kde.PlasmaShell", "editMode") + } + + fn setedit_mode(&self, value: bool) -> Result<(), dbus::Error> { + ::set(self, "org.kde.PlasmaShell", "editMode", value) + } +} + +pub trait OrgFreedesktopDBusProperties { + fn get arg::Get<'b> + 'static>(&self, interface_name: &str, property_name: &str) -> Result; + fn set(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), dbus::Error>; + fn get_all(&self, interface_name: &str) -> Result; +} + +#[derive(Debug)] +pub struct OrgFreedesktopDBusPropertiesPropertiesChanged { + pub interface_name: String, + pub changed_properties: arg::PropMap, + pub invalidated_properties: Vec, +} + +impl arg::AppendAll for OrgFreedesktopDBusPropertiesPropertiesChanged { + fn append(&self, i: &mut arg::IterAppend) { + arg::RefArg::append(&self.interface_name, i); + arg::RefArg::append(&self.changed_properties, i); + arg::RefArg::append(&self.invalidated_properties, i); + } +} + +impl arg::ReadAll for OrgFreedesktopDBusPropertiesPropertiesChanged { + fn read(i: &mut arg::Iter) -> Result { + Ok(OrgFreedesktopDBusPropertiesPropertiesChanged { + interface_name: i.read()?, + changed_properties: i.read()?, + invalidated_properties: i.read()?, + }) + } +} + +impl dbus::message::SignalArgs for OrgFreedesktopDBusPropertiesPropertiesChanged { + const NAME: &'static str = "PropertiesChanged"; + const INTERFACE: &'static str = "org.freedesktop.DBus.Properties"; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgFreedesktopDBusProperties for blocking::Proxy<'a, C> { + + fn get arg::Get<'b> + 'static>(&self, interface_name: &str, property_name: &str) -> Result { + self.method_call("org.freedesktop.DBus.Properties", "Get", (interface_name, property_name, )) + .and_then(|r: (arg::Variant, )| Ok((r.0).0, )) + } + + fn set(&self, interface_name: &str, property_name: &str, value: I2) -> Result<(), dbus::Error> { + self.method_call("org.freedesktop.DBus.Properties", "Set", (interface_name, property_name, arg::Variant(value), )) + } + + fn get_all(&self, interface_name: &str) -> Result { + self.method_call("org.freedesktop.DBus.Properties", "GetAll", (interface_name, )) + .and_then(|r: (arg::PropMap, )| Ok(r.0, )) + } +} + +pub trait OrgFreedesktopDBusIntrospectable { + fn introspect(&self) -> Result; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgFreedesktopDBusIntrospectable for blocking::Proxy<'a, C> { + + fn introspect(&self) -> Result { + self.method_call("org.freedesktop.DBus.Introspectable", "Introspect", ()) + .and_then(|r: (String, )| Ok(r.0, )) + } +} + +pub trait OrgFreedesktopDBusPeer { + fn ping(&self) -> Result<(), dbus::Error>; + fn get_machine_id(&self) -> Result; +} + +impl<'a, T: blocking::BlockingSender, C: ::std::ops::Deref> OrgFreedesktopDBusPeer for blocking::Proxy<'a, C> { + + fn ping(&self) -> Result<(), dbus::Error> { + self.method_call("org.freedesktop.DBus.Peer", "Ping", ()) + } + + fn get_machine_id(&self) -> Result { + self.method_call("org.freedesktop.DBus.Peer", "GetMachineId", ()) + .and_then(|r: (String, )| Ok(r.0, )) + } +}