├── .github └── FUNDING.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── COPYRIGHT ├── Cargo.toml ├── Gir.toml ├── LICENSE ├── Makefile ├── README.md ├── appveyor.yml ├── build.rs ├── src ├── app_info.rs ├── application.rs ├── auto │ ├── action.rs │ ├── action_group.rs │ ├── action_map.rs │ ├── app_info.rs │ ├── app_info_monitor.rs │ ├── app_launch_context.rs │ ├── application.rs │ ├── application_command_line.rs │ ├── buffered_input_stream.rs │ ├── buffered_output_stream.rs │ ├── bytes_icon.rs │ ├── cancellable.rs │ ├── charset_converter.rs │ ├── constants.rs │ ├── converter.rs │ ├── converter_input_stream.rs │ ├── converter_output_stream.rs │ ├── credentials.rs │ ├── data_input_stream.rs │ ├── data_output_stream.rs │ ├── dbus_arg_info.rs │ ├── dbus_auth_observer.rs │ ├── dbus_connection.rs │ ├── dbus_interface.rs │ ├── dbus_interface_info.rs │ ├── dbus_interface_skeleton.rs │ ├── dbus_menu_model.rs │ ├── dbus_message.rs │ ├── dbus_method_info.rs │ ├── dbus_method_invocation.rs │ ├── dbus_node_info.rs │ ├── dbus_object.rs │ ├── dbus_property_info.rs │ ├── dbus_proxy.rs │ ├── dbus_server.rs │ ├── dbus_signal_info.rs │ ├── desktop_app_info.rs │ ├── drive.rs │ ├── emblem.rs │ ├── emblemed_icon.rs │ ├── enums.rs │ ├── file.rs │ ├── file_attribute_matcher.rs │ ├── file_enumerator.rs │ ├── file_icon.rs │ ├── file_info.rs │ ├── file_input_stream.rs │ ├── file_io_stream.rs │ ├── file_monitor.rs │ ├── file_output_stream.rs │ ├── filename_completer.rs │ ├── filter_input_stream.rs │ ├── filter_output_stream.rs │ ├── flags.rs │ ├── functions.rs │ ├── icon.rs │ ├── inet_address.rs │ ├── inet_address_mask.rs │ ├── inet_socket_address.rs │ ├── input_stream.rs │ ├── io_stream.rs │ ├── list_model.rs │ ├── list_store.rs │ ├── loadable_icon.rs │ ├── memory_input_stream.rs │ ├── memory_monitor.rs │ ├── memory_output_stream.rs │ ├── menu.rs │ ├── menu_attribute_iter.rs │ ├── menu_item.rs │ ├── menu_link_iter.rs │ ├── menu_model.rs │ ├── mod.rs │ ├── mount.rs │ ├── mount_operation.rs │ ├── network_address.rs │ ├── network_monitor.rs │ ├── network_service.rs │ ├── notification.rs │ ├── output_stream.rs │ ├── permission.rs │ ├── pollable_input_stream.rs │ ├── pollable_output_stream.rs │ ├── property_action.rs │ ├── proxy.rs │ ├── proxy_address.rs │ ├── proxy_resolver.rs │ ├── remote_action_group.rs │ ├── resolver.rs │ ├── resource.rs │ ├── seekable.rs │ ├── settings.rs │ ├── settings_backend.rs │ ├── settings_schema.rs │ ├── settings_schema_key.rs │ ├── settings_schema_source.rs │ ├── simple_action.rs │ ├── simple_action_group.rs │ ├── simple_io_stream.rs │ ├── simple_permission.rs │ ├── socket.rs │ ├── socket_address.rs │ ├── socket_address_enumerator.rs │ ├── socket_client.rs │ ├── socket_connectable.rs │ ├── socket_connection.rs │ ├── socket_listener.rs │ ├── socket_service.rs │ ├── srv_target.rs │ ├── subprocess.rs │ ├── subprocess_launcher.rs │ ├── tcp_connection.rs │ ├── themed_icon.rs │ ├── threaded_socket_service.rs │ ├── tls_certificate.rs │ ├── tls_client_connection.rs │ ├── tls_connection.rs │ ├── tls_database.rs │ ├── tls_file_database.rs │ ├── tls_interaction.rs │ ├── tls_password.rs │ ├── tls_server_connection.rs │ ├── unix_fd_list.rs │ ├── unix_input_stream.rs │ ├── unix_mount_entry.rs │ ├── unix_mount_point.rs │ ├── unix_output_stream.rs │ ├── unix_socket_address.rs │ ├── versions.txt │ ├── vfs.rs │ ├── volume.rs │ ├── volume_monitor.rs │ ├── zlib_compressor.rs │ └── zlib_decompressor.rs ├── cancellable.rs ├── converter.rs ├── data_input_stream.rs ├── dbus.rs ├── dbus_connection.rs ├── dbus_message.rs ├── dbus_method_invocation.rs ├── desktop_app_info.rs ├── error.rs ├── file.rs ├── file_attribute_matcher.rs ├── file_enumerator.rs ├── file_info.rs ├── flags.rs ├── gio_future.rs ├── inet_address.rs ├── input_stream.rs ├── io_stream.rs ├── lib.rs ├── list_store.rs ├── memory_input_stream.rs ├── memory_output_stream.rs ├── output_stream.rs ├── pollable_input_stream.rs ├── pollable_output_stream.rs ├── prelude.rs ├── read_input_stream.rs ├── resource.rs ├── settings.rs ├── socket.rs ├── subclass │ ├── application.rs │ ├── input_stream.rs │ ├── io_stream.rs │ ├── mod.rs │ ├── output_stream.rs │ └── seekable.rs ├── subprocess.rs ├── subprocess_launcher.rs ├── test_util.rs ├── threaded_socket_service.rs ├── tls_connection.rs ├── unix_fd_list.rs ├── unix_input_stream.rs ├── unix_mount_entry.rs ├── unix_mount_point.rs ├── unix_output_stream.rs ├── unix_socket_address.rs └── write_output_stream.rs └── tests ├── check_gir.rs ├── com.github.gtk-rs.test.gschema.xml ├── futures.rs └── std_io_copy.rs /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | open_collective: gtk-rs 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Cargo.lock 2 | /target 3 | .idea 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "gir"] 2 | path = gir 3 | url = https://github.com/gtk-rs/gir.git 4 | [submodule "gir-files"] 5 | path = gir-files 6 | url = https://github.com/gtk-rs/gir-files.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | language: rust 3 | os: 4 | - linux 5 | - osx 6 | 7 | rust: 8 | - stable 9 | - 1.40.0 10 | - beta 11 | - nightly 12 | 13 | env: 14 | - GTK=3.14 FEATURES= 15 | - GTK=3.24 FEATURES=v2_48 16 | 17 | jobs: 18 | exclude: 19 | - os: osx 20 | env: GTK=3.24 FEATURES=v2_48 21 | 22 | addons: 23 | apt: 24 | packages: 25 | - libgtk-3-dev 26 | - libmount-dev 27 | 28 | before_install: 29 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi 30 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew unlink python@2; fi 31 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install gtk+3 cairo atk; fi 32 | 33 | script: 34 | - rustc --version 35 | - if [ "$TRAVIS_RUST_VERSION" == "stable" ] && [ "$GTK" == "3.14" ]; then 36 | rustup component add rustfmt; 37 | make regen_check; 38 | fi 39 | - cargo doc --features "dox,embed-lgpl-docs" 40 | - cargo test --features "$FEATURES,embed-lgpl-docs" 41 | # catch any sneaked in lgpl docs 42 | - cargo build --features "$FEATURES,purge-lgpl-docs" --jobs 1 43 | - git diff -R --exit-code 44 | - rustc --version 45 | - mkdir .cargo 46 | - echo 'paths = ["."]' > .cargo/config 47 | - git clone -q --depth 50 -b pending https://github.com/gtk-rs/examples _examples 48 | - cd _examples 49 | - ./build_travis.sh 50 | - if [ "$TRAVIS_RUST_VERSION" == "stable" ] && [ "$GTK" == "3.14" ]; then 51 | cd ..; 52 | git clone https://github.com/gtk-rs/checker; 53 | cd checker && cargo build --release; 54 | cd .. && ./checker/target/release/checker .; 55 | fi 56 | - if [ "$TRAVIS_OS_NAME" == "linux" ] && [ "$TRAVIS_RUST_VERSION" == "stable"] && [ "$GTK" == "3.24" ]; then 57 | rustup component add clippy; 58 | cargo clippy --features "$FEATURES,embed-lgpl-docs" --tests -- -D warnings; 59 | fi 60 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | The Gtk-rs Project is copyright 2013-2016, The Gtk-rs Project Developers: 2 | 3 | Adam Crume 4 | Adolfo Ochagavía 5 | Andre Bogus 6 | Anton Konjahin 7 | Arne Dussin 8 | Boden Garman 9 | Brian Kropf 10 | Bryant Mairs 11 | Chris Greenaway 12 | Chris Palmer 13 | Corey Farwell 14 | Daniel Zalevskiy 15 | David Li 16 | Edward Shaw 17 | Edward Yang 18 | Esption 19 | Evgenii Pashkin 20 | Geoffrey French 21 | Gleb Kozyrev 22 | Glenn Watson 23 | Google Inc. 24 | Guillaume Gomez 25 | Gulshan Singh 26 | Jakob Gillich 27 | James Shepherdson 28 | Jeremy Letang 29 | John Vrbanac 30 | kennytm 31 | Laurence Tratt 32 | Lionel Flandrin 33 | Lucas Werkmeister 34 | Lukas Diekmann 35 | Mathijs Henquet 36 | Maxwell Koo 37 | mitaa 38 | Nick Herman 39 | Nicolas Koch 40 | Oliver Schneider 41 | Ömer Sinan Ağacan 42 | Ralph Giles 43 | Paul Dennis 44 | Paul Hendry 45 | Philipp Brüschweiler 46 | Raphael Nestler 47 | Robertas 48 | Romain Gauthier 49 | S.J.R. van Schaik 50 | Sebastian Schulze 51 | Silvio Fricke 52 | Simon Sapin 53 | Steve Klabnik 54 | Tobias Bales 55 | trolleyman 56 | Umur Gedik 57 | UrKr 58 | Vojtech Kral 59 | Zach Oakes 60 | Zach Ploskey 61 | 62 | The Gtk-rs Project is licensed under the MIT license, see the LICENSE file 63 | or . 64 | 65 | This project provides interoperability with various GNOME libraries but doesn't 66 | distribute any parts of them. Distributing compiled libraries and executables 67 | that link to those libraries may be subject to terms of the GNU LGPL, see the 68 | LGPL file. 69 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gio" 3 | license = "MIT" 4 | homepage = "https://gtk-rs.org/" 5 | authors = ["The Gtk-rs Project Developers"] 6 | keywords = ["glib", "gio", "gtk-rs", "gnome"] 7 | readme = "README.md" 8 | documentation = "https://gtk-rs.org/docs/gio/" 9 | version = "0.9.0" 10 | description = "Rust bindings for the Gio library" 11 | repository = "https://github.com/gtk-rs/gio" 12 | build = "build.rs" 13 | exclude = [ 14 | "gir-files/*", 15 | ] 16 | 17 | [badges] 18 | appveyor = { repository = "GuillaumeGomez/gio", service = "github" } 19 | travis-ci = { repository = "gtk-rs/gio" } 20 | 21 | [lib] 22 | name = "gio" 23 | 24 | [features] 25 | v2_44 = ["gio-sys/v2_44", "glib/v2_44"] 26 | v2_46 = ["v2_44", "gio-sys/v2_46", "glib/v2_46"] 27 | v2_48 = ["v2_46", "gio-sys/v2_48", "glib/v2_48"] 28 | v2_50 = ["v2_48", "gio-sys/v2_50", "glib/v2_50"] 29 | v2_52 = ["v2_50", "gio-sys/v2_52", "glib/v2_52"] 30 | v2_54 = ["v2_52", "gio-sys/v2_54", "glib/v2_54"] 31 | v2_56 = ["v2_54", "gio-sys/v2_56", "glib/v2_56"] 32 | v2_58 = ["v2_56", "gio-sys/v2_58", "glib/v2_58"] 33 | v2_60 = ["v2_58", "gio-sys/v2_60", "glib/v2_60"] 34 | v2_62 = ["v2_60", "gio-sys/v2_62", "glib/v2_62"] 35 | v2_64 = ["v2_62", "gio-sys/v2_64", "glib/v2_64"] 36 | v2_66 = ["v2_64", "gio-sys/v2_66", "glib/v2_66"] 37 | dox = ["gio-sys/dox", "glib/dox"] 38 | purge-lgpl-docs = ["gtk-rs-lgpl-docs"] 39 | embed-lgpl-docs = ["gtk-rs-lgpl-docs"] 40 | 41 | [package.metadata.docs.rs] 42 | features = ["dox", "embed-lgpl-docs"] 43 | 44 | [build-dependencies.gtk-rs-lgpl-docs] 45 | version = "0.1" 46 | optional = true 47 | git = "https://github.com/gtk-rs/lgpl-docs" 48 | 49 | [dependencies] 50 | libc = "0.2" 51 | bitflags = "1.0" 52 | once_cell = "1.0" 53 | futures = "0.3" 54 | futures-core = "0.3" 55 | futures-channel = "0.3" 56 | futures-util = "0.3" 57 | futures-io = "0.3" 58 | gio-sys = { git = "https://github.com/gtk-rs/sys" } 59 | glib-sys = { git = "https://github.com/gtk-rs/sys" } 60 | glib = { git = "https://github.com/gtk-rs/glib" } 61 | gobject-sys = { git = "https://github.com/gtk-rs/sys" } 62 | thiserror = "1" 63 | 64 | [dev-dependencies] 65 | gir-format-check = "^0.1" 66 | serial_test = "0.4" 67 | serial_test_derive = "0.4" 68 | 69 | [[test]] 70 | name = "futures" 71 | path = "tests/futures.rs" 72 | edition = "2018" 73 | # Defining one [[test]] disable test targets auto discovery = 74 | # TODO: remove once crate has been ported to 2018 and tests/futures.rs removed = 75 | 76 | [[test]] 77 | name = "std_io_copy" 78 | path = "tests/std_io_copy.rs" 79 | 80 | [[test]] 81 | name = "check_gir" 82 | path = "tests/check_gir.rs" 83 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2015, The Gtk-rs Project Developers. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | GIR = gir/target/bin/gir 2 | GIR_SRC = gir/Cargo.toml gir/Cargo.lock gir/build.rs $(shell find gir/src -name '*.rs') 3 | GIR_FILES = gir-files/Gio-2.0.gir 4 | 5 | # Run `gir` generating the bindings 6 | gir : src/auto/mod.rs 7 | cargo fmt 8 | 9 | doc: $(GIR) $(GIR_FILES) 10 | $(GIR) -m doc -c Gir.toml 11 | 12 | not_bound: $(GIR) $(GIR_FILES) 13 | $(GIR) -m not_bound -c Gir.toml 14 | 15 | regen_check: $(GIR) $(GIR_FILES) 16 | rm src/auto/* 17 | $(GIR) -c Gir.toml 18 | cargo fmt 19 | git diff -R --exit-code 20 | 21 | src/auto/mod.rs : Gir.toml $(GIR) $(GIR_FILES) 22 | $(GIR) -c Gir.toml 23 | 24 | $(GIR) : $(GIR_SRC) 25 | rm -f gir/target/bin/gir 26 | cargo install --path gir --root gir/target 27 | rm -f gir/target/.crates.toml 28 | 29 | $(GIR_SRC) $(GIR_FILES) : 30 | git submodule update --init 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gio [![Build Status](https://travis-ci.org/gtk-rs/gio.png?branch=master)](https://travis-ci.org/gtk-rs/gio) [![Build status](https://ci.appveyor.com/api/projects/status/4773nkca4q8ayn4x/branch/master?svg=true)](https://ci.appveyor.com/project/GuillaumeGomez/gio) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gtk-rs/gtk) 2 | 3 | GIO bindings for Rust. 4 | 5 | - [Gtk-rs project site](https://gtk-rs.org/) 6 | 7 | - [Online documentation](https://gtk-rs.org/docs-src/) 8 | 9 | - [Readme](https://github.com/gtk-rs/gtk/blob/master/README.md) in our 10 | [main repo](https://github.com/gtk-rs/gtk) 11 | 12 | ## License 13 | 14 | MIT 15 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | environment: 2 | matrix: 3 | - RUST: stable 4 | BITS: 32 5 | - RUST: stable 6 | BITS: 64 7 | 8 | install: 9 | - IF "%BITS%" == "32" SET ARCH=i686 10 | - IF "%BITS%" == "64" SET ARCH=x86_64 11 | - curl -sSf -o rustup-init.exe https://win.rustup.rs 12 | - rustup-init.exe --default-host "%ARCH%-pc-windows-gnu" --default-toolchain %RUST% -y 13 | - SET PATH=C:\Users\appveyor\.cargo\bin;C:\msys64\mingw%BITS%\bin;%PATH%;C:\msys64\usr\bin 14 | - rustc -Vv 15 | - cargo -Vv 16 | - pacman --noconfirm -S mingw-w64-%ARCH%-gtk3 17 | 18 | build_script: 19 | - cargo doc --features "dox" 20 | - cargo test 21 | - cargo test --features v2_58 22 | - mkdir .cargo 23 | - echo paths = ["."] > .cargo\config 24 | - git clone -q --depth 50 -b pending https://github.com/gtk-rs/examples _examples 25 | - cd _examples 26 | - cargo build 27 | - cargo build --features gtk_3_24 28 | 29 | test: false 30 | -------------------------------------------------------------------------------- /build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | manage_docs(); 3 | } 4 | 5 | #[cfg(all( 6 | any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs"), 7 | not(all(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs")) 8 | ))] 9 | fn manage_docs() { 10 | extern crate lgpl_docs; 11 | const PATH: &str = "src"; 12 | const IGNORES: &[&str] = &["lib.rs", "prelude.rs"]; 13 | lgpl_docs::purge(PATH, IGNORES); 14 | if cfg!(feature = "embed-lgpl-docs") { 15 | lgpl_docs::embed(lgpl_docs::Library::Gio, PATH, IGNORES); 16 | } 17 | } 18 | 19 | #[cfg(any( 20 | all(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs"), 21 | not(any(feature = "embed-lgpl-docs", feature = "purge-lgpl-docs")) 22 | ))] 23 | fn manage_docs() {} 24 | -------------------------------------------------------------------------------- /src/application.rs: -------------------------------------------------------------------------------- 1 | use gio_sys; 2 | use glib::object::Cast; 3 | use glib::object::IsA; 4 | use glib::signal::{connect_raw, SignalHandlerId}; 5 | use glib::translate::*; 6 | use glib::GString; 7 | use glib_sys; 8 | use libc; 9 | use std::boxed::Box as Box_; 10 | use std::mem::transmute; 11 | use Application; 12 | use File; 13 | 14 | pub trait ApplicationExtManual { 15 | fn run(&self, argv: &[String]) -> i32; 16 | fn connect_open(&self, f: F) -> SignalHandlerId; 17 | } 18 | 19 | impl> ApplicationExtManual for O { 20 | fn run(&self, argv: &[String]) -> i32 { 21 | let argc = argv.len() as i32; 22 | unsafe { 23 | gio_sys::g_application_run(self.as_ref().to_glib_none().0, argc, argv.to_glib_none().0) 24 | } 25 | } 26 | 27 | fn connect_open(&self, f: F) -> SignalHandlerId { 28 | unsafe extern "C" fn open_trampoline( 29 | this: *mut gio_sys::GApplication, 30 | files: *const *mut gio_sys::GFile, 31 | n_files: libc::c_int, 32 | hint: *mut libc::c_char, 33 | f: glib_sys::gpointer, 34 | ) where 35 | P: IsA, 36 | { 37 | let f: &F = &*(f as *const F); 38 | let files: Vec = FromGlibContainer::from_glib_none_num(files, n_files as usize); 39 | f( 40 | &Application::from_glib_borrow(this).unsafe_cast_ref(), 41 | &files, 42 | &GString::from_glib_borrow(hint), 43 | ) 44 | } 45 | unsafe { 46 | let f: Box_ = Box_::new(f); 47 | connect_raw( 48 | self.as_ptr() as *mut _, 49 | b"open\0".as_ptr() as *const _, 50 | Some(transmute::<_, unsafe extern "C" fn()>( 51 | open_trampoline:: as *const (), 52 | )), 53 | Box_::into_raw(f), 54 | ) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/auto/action_map.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use Action; 10 | 11 | glib_wrapper! { 12 | pub struct ActionMap(Interface); 13 | 14 | match fn { 15 | get_type => || gio_sys::g_action_map_get_type(), 16 | } 17 | } 18 | 19 | pub const NONE_ACTION_MAP: Option<&ActionMap> = None; 20 | 21 | pub trait ActionMapExt: 'static { 22 | fn add_action>(&self, action: &P); 23 | 24 | //fn add_action_entries(&self, entries: /*Ignored*/&[&ActionEntry], user_data: /*Unimplemented*/Option); 25 | 26 | fn lookup_action(&self, action_name: &str) -> Option; 27 | 28 | fn remove_action(&self, action_name: &str); 29 | } 30 | 31 | impl> ActionMapExt for O { 32 | fn add_action>(&self, action: &P) { 33 | unsafe { 34 | gio_sys::g_action_map_add_action( 35 | self.as_ref().to_glib_none().0, 36 | action.as_ref().to_glib_none().0, 37 | ); 38 | } 39 | } 40 | 41 | //fn add_action_entries(&self, entries: /*Ignored*/&[&ActionEntry], user_data: /*Unimplemented*/Option) { 42 | // unsafe { TODO: call gio_sys:g_action_map_add_action_entries() } 43 | //} 44 | 45 | fn lookup_action(&self, action_name: &str) -> Option { 46 | unsafe { 47 | from_glib_none(gio_sys::g_action_map_lookup_action( 48 | self.as_ref().to_glib_none().0, 49 | action_name.to_glib_none().0, 50 | )) 51 | } 52 | } 53 | 54 | fn remove_action(&self, action_name: &str) { 55 | unsafe { 56 | gio_sys::g_action_map_remove_action( 57 | self.as_ref().to_glib_none().0, 58 | action_name.to_glib_none().0, 59 | ); 60 | } 61 | } 62 | } 63 | 64 | impl fmt::Display for ActionMap { 65 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 66 | write!(f, "ActionMap") 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/auto/app_info_monitor.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::ObjectType as ObjectType_; 7 | use glib::signal::connect_raw; 8 | use glib::signal::SignalHandlerId; 9 | use glib::translate::*; 10 | use glib_sys; 11 | use std::boxed::Box as Box_; 12 | use std::fmt; 13 | use std::mem::transmute; 14 | 15 | glib_wrapper! { 16 | pub struct AppInfoMonitor(Object); 17 | 18 | match fn { 19 | get_type => || gio_sys::g_app_info_monitor_get_type(), 20 | } 21 | } 22 | 23 | impl AppInfoMonitor { 24 | pub fn get() -> AppInfoMonitor { 25 | unsafe { from_glib_full(gio_sys::g_app_info_monitor_get()) } 26 | } 27 | 28 | pub fn connect_changed(&self, f: F) -> SignalHandlerId { 29 | unsafe extern "C" fn changed_trampoline( 30 | this: *mut gio_sys::GAppInfoMonitor, 31 | f: glib_sys::gpointer, 32 | ) { 33 | let f: &F = &*(f as *const F); 34 | f(&from_glib_borrow(this)) 35 | } 36 | unsafe { 37 | let f: Box_ = Box_::new(f); 38 | connect_raw( 39 | self.as_ptr() as *mut _, 40 | b"changed\0".as_ptr() as *const _, 41 | Some(transmute::<_, unsafe extern "C" fn()>( 42 | changed_trampoline:: as *const (), 43 | )), 44 | Box_::into_raw(f), 45 | ) 46 | } 47 | } 48 | } 49 | 50 | impl fmt::Display for AppInfoMonitor { 51 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 52 | write!(f, "AppInfoMonitor") 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/auto/bytes_icon.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use Icon; 10 | use LoadableIcon; 11 | 12 | glib_wrapper! { 13 | pub struct BytesIcon(Object) @implements Icon, LoadableIcon; 14 | 15 | match fn { 16 | get_type => || gio_sys::g_bytes_icon_get_type(), 17 | } 18 | } 19 | 20 | impl BytesIcon { 21 | pub fn new(bytes: &glib::Bytes) -> BytesIcon { 22 | unsafe { from_glib_full(gio_sys::g_bytes_icon_new(bytes.to_glib_none().0)) } 23 | } 24 | 25 | pub fn get_bytes(&self) -> Option { 26 | unsafe { from_glib_none(gio_sys::g_bytes_icon_get_bytes(self.to_glib_none().0)) } 27 | } 28 | } 29 | 30 | impl fmt::Display for BytesIcon { 31 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 32 | write!(f, "BytesIcon") 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/auto/converter.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | 10 | glib_wrapper! { 11 | pub struct Converter(Interface); 12 | 13 | match fn { 14 | get_type => || gio_sys::g_converter_get_type(), 15 | } 16 | } 17 | 18 | pub const NONE_CONVERTER: Option<&Converter> = None; 19 | 20 | pub trait ConverterExt: 'static { 21 | fn reset(&self); 22 | } 23 | 24 | impl> ConverterExt for O { 25 | fn reset(&self) { 26 | unsafe { 27 | gio_sys::g_converter_reset(self.as_ref().to_glib_none().0); 28 | } 29 | } 30 | } 31 | 32 | impl fmt::Display for Converter { 33 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 34 | write!(f, "Converter") 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/auto/converter_input_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::StaticType; 10 | use glib::ToValue; 11 | use std::fmt; 12 | use Converter; 13 | use FilterInputStream; 14 | use InputStream; 15 | use PollableInputStream; 16 | 17 | glib_wrapper! { 18 | pub struct ConverterInputStream(Object) @extends FilterInputStream, InputStream, @implements PollableInputStream; 19 | 20 | match fn { 21 | get_type => || gio_sys::g_converter_input_stream_get_type(), 22 | } 23 | } 24 | 25 | impl ConverterInputStream { 26 | pub fn new, Q: IsA>( 27 | base_stream: &P, 28 | converter: &Q, 29 | ) -> ConverterInputStream { 30 | unsafe { 31 | InputStream::from_glib_full(gio_sys::g_converter_input_stream_new( 32 | base_stream.as_ref().to_glib_none().0, 33 | converter.as_ref().to_glib_none().0, 34 | )) 35 | .unsafe_cast() 36 | } 37 | } 38 | } 39 | 40 | #[derive(Clone, Default)] 41 | pub struct ConverterInputStreamBuilder { 42 | converter: Option, 43 | base_stream: Option, 44 | close_base_stream: Option, 45 | } 46 | 47 | impl ConverterInputStreamBuilder { 48 | pub fn new() -> Self { 49 | Self::default() 50 | } 51 | 52 | pub fn build(self) -> ConverterInputStream { 53 | let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 54 | if let Some(ref converter) = self.converter { 55 | properties.push(("converter", converter)); 56 | } 57 | if let Some(ref base_stream) = self.base_stream { 58 | properties.push(("base-stream", base_stream)); 59 | } 60 | if let Some(ref close_base_stream) = self.close_base_stream { 61 | properties.push(("close-base-stream", close_base_stream)); 62 | } 63 | let ret = glib::Object::new(ConverterInputStream::static_type(), &properties) 64 | .expect("object new") 65 | .downcast::() 66 | .expect("downcast"); 67 | ret 68 | } 69 | 70 | pub fn converter>(mut self, converter: &P) -> Self { 71 | self.converter = Some(converter.clone().upcast()); 72 | self 73 | } 74 | 75 | pub fn base_stream>(mut self, base_stream: &P) -> Self { 76 | self.base_stream = Some(base_stream.clone().upcast()); 77 | self 78 | } 79 | 80 | pub fn close_base_stream(mut self, close_base_stream: bool) -> Self { 81 | self.close_base_stream = Some(close_base_stream); 82 | self 83 | } 84 | } 85 | 86 | pub const NONE_CONVERTER_INPUT_STREAM: Option<&ConverterInputStream> = None; 87 | 88 | pub trait ConverterInputStreamExt: 'static { 89 | fn get_converter(&self) -> Option; 90 | } 91 | 92 | impl> ConverterInputStreamExt for O { 93 | fn get_converter(&self) -> Option { 94 | unsafe { 95 | from_glib_none(gio_sys::g_converter_input_stream_get_converter( 96 | self.as_ref().to_glib_none().0, 97 | )) 98 | } 99 | } 100 | } 101 | 102 | impl fmt::Display for ConverterInputStream { 103 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 104 | write!(f, "ConverterInputStream") 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/auto/converter_output_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::StaticType; 10 | use glib::ToValue; 11 | use std::fmt; 12 | use Converter; 13 | use FilterOutputStream; 14 | use OutputStream; 15 | use PollableOutputStream; 16 | 17 | glib_wrapper! { 18 | pub struct ConverterOutputStream(Object) @extends FilterOutputStream, OutputStream, @implements PollableOutputStream; 19 | 20 | match fn { 21 | get_type => || gio_sys::g_converter_output_stream_get_type(), 22 | } 23 | } 24 | 25 | impl ConverterOutputStream { 26 | pub fn new, Q: IsA>( 27 | base_stream: &P, 28 | converter: &Q, 29 | ) -> ConverterOutputStream { 30 | unsafe { 31 | OutputStream::from_glib_full(gio_sys::g_converter_output_stream_new( 32 | base_stream.as_ref().to_glib_none().0, 33 | converter.as_ref().to_glib_none().0, 34 | )) 35 | .unsafe_cast() 36 | } 37 | } 38 | } 39 | 40 | #[derive(Clone, Default)] 41 | pub struct ConverterOutputStreamBuilder { 42 | converter: Option, 43 | base_stream: Option, 44 | close_base_stream: Option, 45 | } 46 | 47 | impl ConverterOutputStreamBuilder { 48 | pub fn new() -> Self { 49 | Self::default() 50 | } 51 | 52 | pub fn build(self) -> ConverterOutputStream { 53 | let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; 54 | if let Some(ref converter) = self.converter { 55 | properties.push(("converter", converter)); 56 | } 57 | if let Some(ref base_stream) = self.base_stream { 58 | properties.push(("base-stream", base_stream)); 59 | } 60 | if let Some(ref close_base_stream) = self.close_base_stream { 61 | properties.push(("close-base-stream", close_base_stream)); 62 | } 63 | let ret = glib::Object::new(ConverterOutputStream::static_type(), &properties) 64 | .expect("object new") 65 | .downcast::() 66 | .expect("downcast"); 67 | ret 68 | } 69 | 70 | pub fn converter>(mut self, converter: &P) -> Self { 71 | self.converter = Some(converter.clone().upcast()); 72 | self 73 | } 74 | 75 | pub fn base_stream>(mut self, base_stream: &P) -> Self { 76 | self.base_stream = Some(base_stream.clone().upcast()); 77 | self 78 | } 79 | 80 | pub fn close_base_stream(mut self, close_base_stream: bool) -> Self { 81 | self.close_base_stream = Some(close_base_stream); 82 | self 83 | } 84 | } 85 | 86 | pub const NONE_CONVERTER_OUTPUT_STREAM: Option<&ConverterOutputStream> = None; 87 | 88 | pub trait ConverterOutputStreamExt: 'static { 89 | fn get_converter(&self) -> Option; 90 | } 91 | 92 | impl> ConverterOutputStreamExt for O { 93 | fn get_converter(&self) -> Option { 94 | unsafe { 95 | from_glib_none(gio_sys::g_converter_output_stream_get_converter( 96 | self.as_ref().to_glib_none().0, 97 | )) 98 | } 99 | } 100 | } 101 | 102 | impl fmt::Display for ConverterOutputStream { 103 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 104 | write!(f, "ConverterOutputStream") 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/auto/credentials.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use glib::GString; 9 | use std::fmt; 10 | use std::ptr; 11 | 12 | glib_wrapper! { 13 | pub struct Credentials(Object); 14 | 15 | match fn { 16 | get_type => || gio_sys::g_credentials_get_type(), 17 | } 18 | } 19 | 20 | impl Credentials { 21 | pub fn new() -> Credentials { 22 | unsafe { from_glib_full(gio_sys::g_credentials_new()) } 23 | } 24 | 25 | //pub fn get_native(&self, native_type: CredentialsType) -> /*Unimplemented*/Option { 26 | // unsafe { TODO: call gio_sys:g_credentials_get_native() } 27 | //} 28 | 29 | #[cfg(any(unix, feature = "dox"))] 30 | pub fn get_unix_pid(&self) -> Result { 31 | unsafe { 32 | let mut error = ptr::null_mut(); 33 | let ret = gio_sys::g_credentials_get_unix_pid(self.to_glib_none().0, &mut error); 34 | if error.is_null() { 35 | Ok(ret) 36 | } else { 37 | Err(from_glib_full(error)) 38 | } 39 | } 40 | } 41 | 42 | #[cfg(any(unix, feature = "dox"))] 43 | pub fn get_unix_user(&self) -> Result { 44 | unsafe { 45 | let mut error = ptr::null_mut(); 46 | let ret = gio_sys::g_credentials_get_unix_user(self.to_glib_none().0, &mut error); 47 | if error.is_null() { 48 | Ok(ret) 49 | } else { 50 | Err(from_glib_full(error)) 51 | } 52 | } 53 | } 54 | 55 | pub fn is_same_user(&self, other_credentials: &Credentials) -> Result<(), glib::Error> { 56 | unsafe { 57 | let mut error = ptr::null_mut(); 58 | let _ = gio_sys::g_credentials_is_same_user( 59 | self.to_glib_none().0, 60 | other_credentials.to_glib_none().0, 61 | &mut error, 62 | ); 63 | if error.is_null() { 64 | Ok(()) 65 | } else { 66 | Err(from_glib_full(error)) 67 | } 68 | } 69 | } 70 | 71 | //pub fn set_native(&self, native_type: CredentialsType, native: /*Unimplemented*/Fundamental: Pointer) { 72 | // unsafe { TODO: call gio_sys:g_credentials_set_native() } 73 | //} 74 | 75 | #[cfg(any(unix, feature = "dox"))] 76 | pub fn set_unix_user(&self, uid: u32) -> Result<(), glib::Error> { 77 | unsafe { 78 | let mut error = ptr::null_mut(); 79 | let _ = gio_sys::g_credentials_set_unix_user(self.to_glib_none().0, uid, &mut error); 80 | if error.is_null() { 81 | Ok(()) 82 | } else { 83 | Err(from_glib_full(error)) 84 | } 85 | } 86 | } 87 | 88 | pub fn to_string(&self) -> GString { 89 | unsafe { from_glib_full(gio_sys::g_credentials_to_string(self.to_glib_none().0)) } 90 | } 91 | } 92 | 93 | impl Default for Credentials { 94 | fn default() -> Self { 95 | Self::new() 96 | } 97 | } 98 | 99 | impl fmt::Display for Credentials { 100 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 101 | write!(f, "Credentials") 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/auto/dbus_arg_info.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | 8 | glib_wrapper! { 9 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 10 | pub struct DBusArgInfo(Shared); 11 | 12 | match fn { 13 | ref => |ptr| gio_sys::g_dbus_arg_info_ref(ptr), 14 | unref => |ptr| gio_sys::g_dbus_arg_info_unref(ptr), 15 | get_type => || gio_sys::g_dbus_arg_info_get_type(), 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/auto/dbus_interface.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use DBusInterfaceInfo; 10 | use DBusObject; 11 | 12 | glib_wrapper! { 13 | pub struct DBusInterface(Interface); 14 | 15 | match fn { 16 | get_type => || gio_sys::g_dbus_interface_get_type(), 17 | } 18 | } 19 | 20 | pub const NONE_DBUS_INTERFACE: Option<&DBusInterface> = None; 21 | 22 | pub trait DBusInterfaceExt: 'static { 23 | fn get(&self) -> Option; 24 | 25 | fn get_info(&self) -> Option; 26 | 27 | fn set_object>(&self, object: Option<&P>); 28 | } 29 | 30 | impl> DBusInterfaceExt for O { 31 | fn get(&self) -> Option { 32 | unsafe { 33 | from_glib_full(gio_sys::g_dbus_interface_dup_object( 34 | self.as_ref().to_glib_none().0, 35 | )) 36 | } 37 | } 38 | 39 | fn get_info(&self) -> Option { 40 | unsafe { 41 | from_glib_none(gio_sys::g_dbus_interface_get_info( 42 | self.as_ref().to_glib_none().0, 43 | )) 44 | } 45 | } 46 | 47 | fn set_object>(&self, object: Option<&P>) { 48 | unsafe { 49 | gio_sys::g_dbus_interface_set_object( 50 | self.as_ref().to_glib_none().0, 51 | object.map(|p| p.as_ref()).to_glib_none().0, 52 | ); 53 | } 54 | } 55 | } 56 | 57 | impl fmt::Display for DBusInterface { 58 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 59 | write!(f, "DBusInterface") 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/auto/dbus_interface_info.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use DBusMethodInfo; 9 | use DBusPropertyInfo; 10 | use DBusSignalInfo; 11 | 12 | glib_wrapper! { 13 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 14 | pub struct DBusInterfaceInfo(Shared); 15 | 16 | match fn { 17 | ref => |ptr| gio_sys::g_dbus_interface_info_ref(ptr), 18 | unref => |ptr| gio_sys::g_dbus_interface_info_unref(ptr), 19 | get_type => || gio_sys::g_dbus_interface_info_get_type(), 20 | } 21 | } 22 | 23 | impl DBusInterfaceInfo { 24 | pub fn generate_xml(&self, indent: u32, string_builder: &mut glib::String) { 25 | unsafe { 26 | gio_sys::g_dbus_interface_info_generate_xml( 27 | self.to_glib_none().0, 28 | indent, 29 | string_builder.to_glib_none_mut().0, 30 | ); 31 | } 32 | } 33 | 34 | pub fn lookup_method(&self, name: &str) -> Option { 35 | unsafe { 36 | from_glib_none(gio_sys::g_dbus_interface_info_lookup_method( 37 | self.to_glib_none().0, 38 | name.to_glib_none().0, 39 | )) 40 | } 41 | } 42 | 43 | pub fn lookup_property(&self, name: &str) -> Option { 44 | unsafe { 45 | from_glib_none(gio_sys::g_dbus_interface_info_lookup_property( 46 | self.to_glib_none().0, 47 | name.to_glib_none().0, 48 | )) 49 | } 50 | } 51 | 52 | pub fn lookup_signal(&self, name: &str) -> Option { 53 | unsafe { 54 | from_glib_none(gio_sys::g_dbus_interface_info_lookup_signal( 55 | self.to_glib_none().0, 56 | name.to_glib_none().0, 57 | )) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/auto/dbus_menu_model.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | use std::fmt; 8 | use DBusConnection; 9 | use MenuModel; 10 | 11 | glib_wrapper! { 12 | pub struct DBusMenuModel(Object) @extends MenuModel; 13 | 14 | match fn { 15 | get_type => || gio_sys::g_dbus_menu_model_get_type(), 16 | } 17 | } 18 | 19 | impl DBusMenuModel { 20 | pub fn get( 21 | connection: &DBusConnection, 22 | bus_name: Option<&str>, 23 | object_path: &str, 24 | ) -> Option { 25 | unsafe { 26 | from_glib_full(gio_sys::g_dbus_menu_model_get( 27 | connection.to_glib_none().0, 28 | bus_name.to_glib_none().0, 29 | object_path.to_glib_none().0, 30 | )) 31 | } 32 | } 33 | } 34 | 35 | impl fmt::Display for DBusMenuModel { 36 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 37 | write!(f, "DBusMenuModel") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/auto/dbus_method_info.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | 8 | glib_wrapper! { 9 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 10 | pub struct DBusMethodInfo(Shared); 11 | 12 | match fn { 13 | ref => |ptr| gio_sys::g_dbus_method_info_ref(ptr), 14 | unref => |ptr| gio_sys::g_dbus_method_info_unref(ptr), 15 | get_type => || gio_sys::g_dbus_method_info_get_type(), 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/auto/dbus_node_info.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use std::ptr; 9 | use DBusInterfaceInfo; 10 | 11 | glib_wrapper! { 12 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 13 | pub struct DBusNodeInfo(Shared); 14 | 15 | match fn { 16 | ref => |ptr| gio_sys::g_dbus_node_info_ref(ptr), 17 | unref => |ptr| gio_sys::g_dbus_node_info_unref(ptr), 18 | get_type => || gio_sys::g_dbus_node_info_get_type(), 19 | } 20 | } 21 | 22 | impl DBusNodeInfo { 23 | pub fn new_for_xml(xml_data: &str) -> Result { 24 | unsafe { 25 | let mut error = ptr::null_mut(); 26 | let ret = gio_sys::g_dbus_node_info_new_for_xml(xml_data.to_glib_none().0, &mut error); 27 | if error.is_null() { 28 | Ok(from_glib_full(ret)) 29 | } else { 30 | Err(from_glib_full(error)) 31 | } 32 | } 33 | } 34 | 35 | pub fn generate_xml(&self, indent: u32, string_builder: &mut glib::String) { 36 | unsafe { 37 | gio_sys::g_dbus_node_info_generate_xml( 38 | self.to_glib_none().0, 39 | indent, 40 | string_builder.to_glib_none_mut().0, 41 | ); 42 | } 43 | } 44 | 45 | pub fn lookup_interface(&self, name: &str) -> Option { 46 | unsafe { 47 | from_glib_none(gio_sys::g_dbus_node_info_lookup_interface( 48 | self.to_glib_none().0, 49 | name.to_glib_none().0, 50 | )) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/auto/dbus_property_info.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | 8 | glib_wrapper! { 9 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 10 | pub struct DBusPropertyInfo(Shared); 11 | 12 | match fn { 13 | ref => |ptr| gio_sys::g_dbus_property_info_ref(ptr), 14 | unref => |ptr| gio_sys::g_dbus_property_info_unref(ptr), 15 | get_type => || gio_sys::g_dbus_property_info_get_type(), 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/auto/dbus_signal_info.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | 8 | glib_wrapper! { 9 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 10 | pub struct DBusSignalInfo(Shared); 11 | 12 | match fn { 13 | ref => |ptr| gio_sys::g_dbus_signal_info_ref(ptr), 14 | unref => |ptr| gio_sys::g_dbus_signal_info_unref(ptr), 15 | get_type => || gio_sys::g_dbus_signal_info_get_type(), 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/auto/emblem.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use EmblemOrigin; 10 | use Icon; 11 | 12 | glib_wrapper! { 13 | pub struct Emblem(Object) @implements Icon; 14 | 15 | match fn { 16 | get_type => || gio_sys::g_emblem_get_type(), 17 | } 18 | } 19 | 20 | impl Emblem { 21 | pub fn new>(icon: &P) -> Emblem { 22 | unsafe { from_glib_full(gio_sys::g_emblem_new(icon.as_ref().to_glib_none().0)) } 23 | } 24 | 25 | pub fn with_origin>(icon: &P, origin: EmblemOrigin) -> Emblem { 26 | unsafe { 27 | from_glib_full(gio_sys::g_emblem_new_with_origin( 28 | icon.as_ref().to_glib_none().0, 29 | origin.to_glib(), 30 | )) 31 | } 32 | } 33 | 34 | pub fn get_icon(&self) -> Option { 35 | unsafe { from_glib_none(gio_sys::g_emblem_get_icon(self.to_glib_none().0)) } 36 | } 37 | 38 | pub fn get_origin(&self) -> EmblemOrigin { 39 | unsafe { from_glib(gio_sys::g_emblem_get_origin(self.to_glib_none().0)) } 40 | } 41 | } 42 | 43 | impl fmt::Display for Emblem { 44 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 45 | write!(f, "Emblem") 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/auto/emblemed_icon.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use glib::StaticType; 9 | use glib::Value; 10 | use gobject_sys; 11 | use std::fmt; 12 | use Emblem; 13 | use Icon; 14 | 15 | glib_wrapper! { 16 | pub struct EmblemedIcon(Object) @implements Icon; 17 | 18 | match fn { 19 | get_type => || gio_sys::g_emblemed_icon_get_type(), 20 | } 21 | } 22 | 23 | impl EmblemedIcon { 24 | pub fn new>(icon: &P, emblem: Option<&Emblem>) -> EmblemedIcon { 25 | unsafe { 26 | from_glib_full(gio_sys::g_emblemed_icon_new( 27 | icon.as_ref().to_glib_none().0, 28 | emblem.to_glib_none().0, 29 | )) 30 | } 31 | } 32 | } 33 | 34 | pub const NONE_EMBLEMED_ICON: Option<&EmblemedIcon> = None; 35 | 36 | pub trait EmblemedIconExt: 'static { 37 | fn add_emblem(&self, emblem: &Emblem); 38 | 39 | fn clear_emblems(&self); 40 | 41 | fn get_emblems(&self) -> Vec; 42 | 43 | fn get_icon(&self) -> Option; 44 | 45 | fn get_property_gicon(&self) -> Option; 46 | } 47 | 48 | impl> EmblemedIconExt for O { 49 | fn add_emblem(&self, emblem: &Emblem) { 50 | unsafe { 51 | gio_sys::g_emblemed_icon_add_emblem( 52 | self.as_ref().to_glib_none().0, 53 | emblem.to_glib_none().0, 54 | ); 55 | } 56 | } 57 | 58 | fn clear_emblems(&self) { 59 | unsafe { 60 | gio_sys::g_emblemed_icon_clear_emblems(self.as_ref().to_glib_none().0); 61 | } 62 | } 63 | 64 | fn get_emblems(&self) -> Vec { 65 | unsafe { 66 | FromGlibPtrContainer::from_glib_none(gio_sys::g_emblemed_icon_get_emblems( 67 | self.as_ref().to_glib_none().0, 68 | )) 69 | } 70 | } 71 | 72 | fn get_icon(&self) -> Option { 73 | unsafe { 74 | from_glib_none(gio_sys::g_emblemed_icon_get_icon( 75 | self.as_ref().to_glib_none().0, 76 | )) 77 | } 78 | } 79 | 80 | fn get_property_gicon(&self) -> Option { 81 | unsafe { 82 | let mut value = Value::from_type(::static_type()); 83 | gobject_sys::g_object_get_property( 84 | self.to_glib_none().0 as *mut gobject_sys::GObject, 85 | b"gicon\0".as_ptr() as *const _, 86 | value.to_glib_none_mut().0, 87 | ); 88 | value 89 | .get() 90 | .expect("Return Value for property `gicon` getter") 91 | } 92 | } 93 | } 94 | 95 | impl fmt::Display for EmblemedIcon { 96 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 97 | write!(f, "EmblemedIcon") 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/auto/file_attribute_matcher.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | use glib::GString; 8 | use std::fmt; 9 | 10 | glib_wrapper! { 11 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 12 | pub struct FileAttributeMatcher(Shared); 13 | 14 | match fn { 15 | ref => |ptr| gio_sys::g_file_attribute_matcher_ref(ptr), 16 | unref => |ptr| gio_sys::g_file_attribute_matcher_unref(ptr), 17 | get_type => || gio_sys::g_file_attribute_matcher_get_type(), 18 | } 19 | } 20 | 21 | impl FileAttributeMatcher { 22 | pub fn new(attributes: &str) -> FileAttributeMatcher { 23 | unsafe { 24 | from_glib_full(gio_sys::g_file_attribute_matcher_new( 25 | attributes.to_glib_none().0, 26 | )) 27 | } 28 | } 29 | 30 | pub fn enumerate_namespace(&self, ns: &str) -> bool { 31 | unsafe { 32 | from_glib(gio_sys::g_file_attribute_matcher_enumerate_namespace( 33 | self.to_glib_none().0, 34 | ns.to_glib_none().0, 35 | )) 36 | } 37 | } 38 | 39 | pub fn matches(&self, attribute: &str) -> bool { 40 | unsafe { 41 | from_glib(gio_sys::g_file_attribute_matcher_matches( 42 | self.to_glib_none().0, 43 | attribute.to_glib_none().0, 44 | )) 45 | } 46 | } 47 | 48 | pub fn matches_only(&self, attribute: &str) -> bool { 49 | unsafe { 50 | from_glib(gio_sys::g_file_attribute_matcher_matches_only( 51 | self.to_glib_none().0, 52 | attribute.to_glib_none().0, 53 | )) 54 | } 55 | } 56 | 57 | pub fn subtract( 58 | &self, 59 | subtract: Option<&FileAttributeMatcher>, 60 | ) -> Option { 61 | unsafe { 62 | from_glib_full(gio_sys::g_file_attribute_matcher_subtract( 63 | self.to_glib_none().0, 64 | subtract.to_glib_none().0, 65 | )) 66 | } 67 | } 68 | 69 | fn to_string(&self) -> GString { 70 | unsafe { 71 | from_glib_full(gio_sys::g_file_attribute_matcher_to_string( 72 | self.to_glib_none().0, 73 | )) 74 | } 75 | } 76 | } 77 | 78 | impl fmt::Display for FileAttributeMatcher { 79 | #[inline] 80 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 81 | write!(f, "{}", self.to_string()) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/auto/file_icon.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use File; 10 | use Icon; 11 | use LoadableIcon; 12 | 13 | glib_wrapper! { 14 | pub struct FileIcon(Object) @implements Icon, LoadableIcon; 15 | 16 | match fn { 17 | get_type => || gio_sys::g_file_icon_get_type(), 18 | } 19 | } 20 | 21 | impl FileIcon { 22 | pub fn new>(file: &P) -> FileIcon { 23 | unsafe { from_glib_full(gio_sys::g_file_icon_new(file.as_ref().to_glib_none().0)) } 24 | } 25 | 26 | pub fn get_file(&self) -> Option { 27 | unsafe { from_glib_none(gio_sys::g_file_icon_get_file(self.to_glib_none().0)) } 28 | } 29 | } 30 | 31 | impl fmt::Display for FileIcon { 32 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 33 | write!(f, "FileIcon") 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/auto/filename_completer.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib::GString; 12 | use glib_sys; 13 | use std::boxed::Box as Box_; 14 | use std::fmt; 15 | use std::mem::transmute; 16 | 17 | glib_wrapper! { 18 | pub struct FilenameCompleter(Object); 19 | 20 | match fn { 21 | get_type => || gio_sys::g_filename_completer_get_type(), 22 | } 23 | } 24 | 25 | impl FilenameCompleter { 26 | pub fn new() -> FilenameCompleter { 27 | unsafe { from_glib_full(gio_sys::g_filename_completer_new()) } 28 | } 29 | } 30 | 31 | impl Default for FilenameCompleter { 32 | fn default() -> Self { 33 | Self::new() 34 | } 35 | } 36 | 37 | pub const NONE_FILENAME_COMPLETER: Option<&FilenameCompleter> = None; 38 | 39 | pub trait FilenameCompleterExt: 'static { 40 | fn get_completion_suffix(&self, initial_text: &str) -> Option; 41 | 42 | fn get_completions(&self, initial_text: &str) -> Vec; 43 | 44 | fn set_dirs_only(&self, dirs_only: bool); 45 | 46 | fn connect_got_completion_data(&self, f: F) -> SignalHandlerId; 47 | } 48 | 49 | impl> FilenameCompleterExt for O { 50 | fn get_completion_suffix(&self, initial_text: &str) -> Option { 51 | unsafe { 52 | from_glib_full(gio_sys::g_filename_completer_get_completion_suffix( 53 | self.as_ref().to_glib_none().0, 54 | initial_text.to_glib_none().0, 55 | )) 56 | } 57 | } 58 | 59 | fn get_completions(&self, initial_text: &str) -> Vec { 60 | unsafe { 61 | FromGlibPtrContainer::from_glib_full(gio_sys::g_filename_completer_get_completions( 62 | self.as_ref().to_glib_none().0, 63 | initial_text.to_glib_none().0, 64 | )) 65 | } 66 | } 67 | 68 | fn set_dirs_only(&self, dirs_only: bool) { 69 | unsafe { 70 | gio_sys::g_filename_completer_set_dirs_only( 71 | self.as_ref().to_glib_none().0, 72 | dirs_only.to_glib(), 73 | ); 74 | } 75 | } 76 | 77 | fn connect_got_completion_data(&self, f: F) -> SignalHandlerId { 78 | unsafe extern "C" fn got_completion_data_trampoline( 79 | this: *mut gio_sys::GFilenameCompleter, 80 | f: glib_sys::gpointer, 81 | ) where 82 | P: IsA, 83 | { 84 | let f: &F = &*(f as *const F); 85 | f(&FilenameCompleter::from_glib_borrow(this).unsafe_cast_ref()) 86 | } 87 | unsafe { 88 | let f: Box_ = Box_::new(f); 89 | connect_raw( 90 | self.as_ptr() as *mut _, 91 | b"got-completion-data\0".as_ptr() as *const _, 92 | Some(transmute::<_, unsafe extern "C" fn()>( 93 | got_completion_data_trampoline:: as *const (), 94 | )), 95 | Box_::into_raw(f), 96 | ) 97 | } 98 | } 99 | } 100 | 101 | impl fmt::Display for FilenameCompleter { 102 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 103 | write!(f, "FilenameCompleter") 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/auto/filter_input_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib_sys; 12 | use std::boxed::Box as Box_; 13 | use std::fmt; 14 | use std::mem::transmute; 15 | use InputStream; 16 | 17 | glib_wrapper! { 18 | pub struct FilterInputStream(Object) @extends InputStream; 19 | 20 | match fn { 21 | get_type => || gio_sys::g_filter_input_stream_get_type(), 22 | } 23 | } 24 | 25 | pub const NONE_FILTER_INPUT_STREAM: Option<&FilterInputStream> = None; 26 | 27 | pub trait FilterInputStreamExt: 'static { 28 | fn get_base_stream(&self) -> Option; 29 | 30 | fn get_close_base_stream(&self) -> bool; 31 | 32 | fn set_close_base_stream(&self, close_base: bool); 33 | 34 | fn connect_property_close_base_stream_notify( 35 | &self, 36 | f: F, 37 | ) -> SignalHandlerId; 38 | } 39 | 40 | impl> FilterInputStreamExt for O { 41 | fn get_base_stream(&self) -> Option { 42 | unsafe { 43 | from_glib_none(gio_sys::g_filter_input_stream_get_base_stream( 44 | self.as_ref().to_glib_none().0, 45 | )) 46 | } 47 | } 48 | 49 | fn get_close_base_stream(&self) -> bool { 50 | unsafe { 51 | from_glib(gio_sys::g_filter_input_stream_get_close_base_stream( 52 | self.as_ref().to_glib_none().0, 53 | )) 54 | } 55 | } 56 | 57 | fn set_close_base_stream(&self, close_base: bool) { 58 | unsafe { 59 | gio_sys::g_filter_input_stream_set_close_base_stream( 60 | self.as_ref().to_glib_none().0, 61 | close_base.to_glib(), 62 | ); 63 | } 64 | } 65 | 66 | fn connect_property_close_base_stream_notify( 67 | &self, 68 | f: F, 69 | ) -> SignalHandlerId { 70 | unsafe extern "C" fn notify_close_base_stream_trampoline( 71 | this: *mut gio_sys::GFilterInputStream, 72 | _param_spec: glib_sys::gpointer, 73 | f: glib_sys::gpointer, 74 | ) where 75 | P: IsA, 76 | { 77 | let f: &F = &*(f as *const F); 78 | f(&FilterInputStream::from_glib_borrow(this).unsafe_cast_ref()) 79 | } 80 | unsafe { 81 | let f: Box_ = Box_::new(f); 82 | connect_raw( 83 | self.as_ptr() as *mut _, 84 | b"notify::close-base-stream\0".as_ptr() as *const _, 85 | Some(transmute::<_, unsafe extern "C" fn()>( 86 | notify_close_base_stream_trampoline:: as *const (), 87 | )), 88 | Box_::into_raw(f), 89 | ) 90 | } 91 | } 92 | } 93 | 94 | impl fmt::Display for FilterInputStream { 95 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 96 | write!(f, "FilterInputStream") 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/auto/filter_output_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib_sys; 12 | use std::boxed::Box as Box_; 13 | use std::fmt; 14 | use std::mem::transmute; 15 | use OutputStream; 16 | 17 | glib_wrapper! { 18 | pub struct FilterOutputStream(Object) @extends OutputStream; 19 | 20 | match fn { 21 | get_type => || gio_sys::g_filter_output_stream_get_type(), 22 | } 23 | } 24 | 25 | pub const NONE_FILTER_OUTPUT_STREAM: Option<&FilterOutputStream> = None; 26 | 27 | pub trait FilterOutputStreamExt: 'static { 28 | fn get_base_stream(&self) -> Option; 29 | 30 | fn get_close_base_stream(&self) -> bool; 31 | 32 | fn set_close_base_stream(&self, close_base: bool); 33 | 34 | fn connect_property_close_base_stream_notify( 35 | &self, 36 | f: F, 37 | ) -> SignalHandlerId; 38 | } 39 | 40 | impl> FilterOutputStreamExt for O { 41 | fn get_base_stream(&self) -> Option { 42 | unsafe { 43 | from_glib_none(gio_sys::g_filter_output_stream_get_base_stream( 44 | self.as_ref().to_glib_none().0, 45 | )) 46 | } 47 | } 48 | 49 | fn get_close_base_stream(&self) -> bool { 50 | unsafe { 51 | from_glib(gio_sys::g_filter_output_stream_get_close_base_stream( 52 | self.as_ref().to_glib_none().0, 53 | )) 54 | } 55 | } 56 | 57 | fn set_close_base_stream(&self, close_base: bool) { 58 | unsafe { 59 | gio_sys::g_filter_output_stream_set_close_base_stream( 60 | self.as_ref().to_glib_none().0, 61 | close_base.to_glib(), 62 | ); 63 | } 64 | } 65 | 66 | fn connect_property_close_base_stream_notify( 67 | &self, 68 | f: F, 69 | ) -> SignalHandlerId { 70 | unsafe extern "C" fn notify_close_base_stream_trampoline( 71 | this: *mut gio_sys::GFilterOutputStream, 72 | _param_spec: glib_sys::gpointer, 73 | f: glib_sys::gpointer, 74 | ) where 75 | P: IsA, 76 | { 77 | let f: &F = &*(f as *const F); 78 | f(&FilterOutputStream::from_glib_borrow(this).unsafe_cast_ref()) 79 | } 80 | unsafe { 81 | let f: Box_ = Box_::new(f); 82 | connect_raw( 83 | self.as_ptr() as *mut _, 84 | b"notify::close-base-stream\0".as_ptr() as *const _, 85 | Some(transmute::<_, unsafe extern "C" fn()>( 86 | notify_close_base_stream_trampoline:: as *const (), 87 | )), 88 | Box_::into_raw(f), 89 | ) 90 | } 91 | } 92 | } 93 | 94 | impl fmt::Display for FilterOutputStream { 95 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 96 | write!(f, "FilterOutputStream") 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/auto/icon.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::GString; 10 | use glib_sys; 11 | use std::fmt; 12 | use std::ptr; 13 | 14 | glib_wrapper! { 15 | pub struct Icon(Interface); 16 | 17 | match fn { 18 | get_type => || gio_sys::g_icon_get_type(), 19 | } 20 | } 21 | 22 | impl Icon { 23 | pub fn deserialize(value: &glib::Variant) -> Option { 24 | unsafe { from_glib_full(gio_sys::g_icon_deserialize(value.to_glib_none().0)) } 25 | } 26 | 27 | pub fn hash(&self) -> u32 { 28 | unsafe { 29 | gio_sys::g_icon_hash( 30 | ToGlibPtr::<*mut gio_sys::GIcon>::to_glib_none(self).0 as glib_sys::gconstpointer, 31 | ) 32 | } 33 | } 34 | 35 | pub fn new_for_string(str: &str) -> Result { 36 | unsafe { 37 | let mut error = ptr::null_mut(); 38 | let ret = gio_sys::g_icon_new_for_string(str.to_glib_none().0, &mut error); 39 | if error.is_null() { 40 | Ok(from_glib_full(ret)) 41 | } else { 42 | Err(from_glib_full(error)) 43 | } 44 | } 45 | } 46 | } 47 | 48 | pub const NONE_ICON: Option<&Icon> = None; 49 | 50 | pub trait IconExt: 'static { 51 | fn equal>(&self, icon2: Option<&P>) -> bool; 52 | 53 | fn serialize(&self) -> Option; 54 | 55 | fn to_string(&self) -> Option; 56 | } 57 | 58 | impl> IconExt for O { 59 | fn equal>(&self, icon2: Option<&P>) -> bool { 60 | unsafe { 61 | from_glib(gio_sys::g_icon_equal( 62 | self.as_ref().to_glib_none().0, 63 | icon2.map(|p| p.as_ref()).to_glib_none().0, 64 | )) 65 | } 66 | } 67 | 68 | fn serialize(&self) -> Option { 69 | unsafe { from_glib_full(gio_sys::g_icon_serialize(self.as_ref().to_glib_none().0)) } 70 | } 71 | 72 | fn to_string(&self) -> Option { 73 | unsafe { from_glib_full(gio_sys::g_icon_to_string(self.as_ref().to_glib_none().0)) } 74 | } 75 | } 76 | 77 | impl fmt::Display for Icon { 78 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 79 | write!(f, "Icon") 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/auto/inet_socket_address.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use std::fmt; 10 | use InetAddress; 11 | use SocketAddress; 12 | use SocketConnectable; 13 | 14 | glib_wrapper! { 15 | pub struct InetSocketAddress(Object) @extends SocketAddress, @implements SocketConnectable; 16 | 17 | match fn { 18 | get_type => || gio_sys::g_inet_socket_address_get_type(), 19 | } 20 | } 21 | 22 | impl InetSocketAddress { 23 | pub fn new>(address: &P, port: u16) -> InetSocketAddress { 24 | unsafe { 25 | SocketAddress::from_glib_full(gio_sys::g_inet_socket_address_new( 26 | address.as_ref().to_glib_none().0, 27 | port, 28 | )) 29 | .unsafe_cast() 30 | } 31 | } 32 | 33 | pub fn from_string(address: &str, port: u32) -> Option { 34 | unsafe { 35 | Option::::from_glib_full(gio_sys::g_inet_socket_address_new_from_string( 36 | address.to_glib_none().0, 37 | port, 38 | )) 39 | .map(|o| o.unsafe_cast()) 40 | } 41 | } 42 | } 43 | 44 | unsafe impl Send for InetSocketAddress {} 45 | unsafe impl Sync for InetSocketAddress {} 46 | 47 | pub const NONE_INET_SOCKET_ADDRESS: Option<&InetSocketAddress> = None; 48 | 49 | pub trait InetSocketAddressExt: 'static { 50 | fn get_address(&self) -> Option; 51 | 52 | fn get_flowinfo(&self) -> u32; 53 | 54 | fn get_port(&self) -> u16; 55 | 56 | fn get_scope_id(&self) -> u32; 57 | } 58 | 59 | impl> InetSocketAddressExt for O { 60 | fn get_address(&self) -> Option { 61 | unsafe { 62 | from_glib_none(gio_sys::g_inet_socket_address_get_address( 63 | self.as_ref().to_glib_none().0, 64 | )) 65 | } 66 | } 67 | 68 | fn get_flowinfo(&self) -> u32 { 69 | unsafe { gio_sys::g_inet_socket_address_get_flowinfo(self.as_ref().to_glib_none().0) } 70 | } 71 | 72 | fn get_port(&self) -> u16 { 73 | unsafe { gio_sys::g_inet_socket_address_get_port(self.as_ref().to_glib_none().0) } 74 | } 75 | 76 | fn get_scope_id(&self) -> u32 { 77 | unsafe { gio_sys::g_inet_socket_address_get_scope_id(self.as_ref().to_glib_none().0) } 78 | } 79 | } 80 | 81 | impl fmt::Display for InetSocketAddress { 82 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 83 | write!(f, "InetSocketAddress") 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/auto/memory_input_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::Cast; 8 | use glib::object::IsA; 9 | use glib::translate::*; 10 | use std::fmt; 11 | use InputStream; 12 | use PollableInputStream; 13 | use Seekable; 14 | 15 | glib_wrapper! { 16 | pub struct MemoryInputStream(Object) @extends InputStream, @implements PollableInputStream, Seekable; 17 | 18 | match fn { 19 | get_type => || gio_sys::g_memory_input_stream_get_type(), 20 | } 21 | } 22 | 23 | impl MemoryInputStream { 24 | pub fn new() -> MemoryInputStream { 25 | unsafe { InputStream::from_glib_full(gio_sys::g_memory_input_stream_new()).unsafe_cast() } 26 | } 27 | 28 | pub fn from_bytes(bytes: &glib::Bytes) -> MemoryInputStream { 29 | unsafe { 30 | InputStream::from_glib_full(gio_sys::g_memory_input_stream_new_from_bytes( 31 | bytes.to_glib_none().0, 32 | )) 33 | .unsafe_cast() 34 | } 35 | } 36 | } 37 | 38 | impl Default for MemoryInputStream { 39 | fn default() -> Self { 40 | Self::new() 41 | } 42 | } 43 | 44 | pub const NONE_MEMORY_INPUT_STREAM: Option<&MemoryInputStream> = None; 45 | 46 | pub trait MemoryInputStreamExt: 'static { 47 | fn add_bytes(&self, bytes: &glib::Bytes); 48 | } 49 | 50 | impl> MemoryInputStreamExt for O { 51 | fn add_bytes(&self, bytes: &glib::Bytes) { 52 | unsafe { 53 | gio_sys::g_memory_input_stream_add_bytes( 54 | self.as_ref().to_glib_none().0, 55 | bytes.to_glib_none().0, 56 | ); 57 | } 58 | } 59 | } 60 | 61 | impl fmt::Display for MemoryInputStream { 62 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 63 | write!(f, "MemoryInputStream") 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/auto/memory_monitor.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | #[cfg(any(feature = "v2_64", feature = "dox"))] 7 | use glib::object::Cast; 8 | use glib::object::IsA; 9 | #[cfg(any(feature = "v2_64", feature = "dox"))] 10 | use glib::signal::connect_raw; 11 | #[cfg(any(feature = "v2_64", feature = "dox"))] 12 | use glib::signal::SignalHandlerId; 13 | use glib::translate::*; 14 | #[cfg(any(feature = "v2_64", feature = "dox"))] 15 | use glib_sys; 16 | #[cfg(any(feature = "v2_64", feature = "dox"))] 17 | use std::boxed::Box as Box_; 18 | use std::fmt; 19 | #[cfg(any(feature = "v2_64", feature = "dox"))] 20 | use std::mem::transmute; 21 | #[cfg(any(feature = "v2_64", feature = "dox"))] 22 | use MemoryMonitorWarningLevel; 23 | 24 | glib_wrapper! { 25 | pub struct MemoryMonitor(Interface); 26 | 27 | match fn { 28 | get_type => || gio_sys::g_memory_monitor_get_type(), 29 | } 30 | } 31 | 32 | impl MemoryMonitor { 33 | #[cfg(any(feature = "v2_64", feature = "dox"))] 34 | pub fn dup_default() -> Option { 35 | unsafe { from_glib_full(gio_sys::g_memory_monitor_dup_default()) } 36 | } 37 | } 38 | 39 | pub const NONE_MEMORY_MONITOR: Option<&MemoryMonitor> = None; 40 | 41 | pub trait MemoryMonitorExt: 'static { 42 | #[cfg(any(feature = "v2_64", feature = "dox"))] 43 | fn connect_low_memory_warning( 44 | &self, 45 | f: F, 46 | ) -> SignalHandlerId; 47 | } 48 | 49 | impl> MemoryMonitorExt for O { 50 | #[cfg(any(feature = "v2_64", feature = "dox"))] 51 | fn connect_low_memory_warning( 52 | &self, 53 | f: F, 54 | ) -> SignalHandlerId { 55 | unsafe extern "C" fn low_memory_warning_trampoline< 56 | P, 57 | F: Fn(&P, MemoryMonitorWarningLevel) + 'static, 58 | >( 59 | this: *mut gio_sys::GMemoryMonitor, 60 | level: gio_sys::GMemoryMonitorWarningLevel, 61 | f: glib_sys::gpointer, 62 | ) where 63 | P: IsA, 64 | { 65 | let f: &F = &*(f as *const F); 66 | f( 67 | &MemoryMonitor::from_glib_borrow(this).unsafe_cast_ref(), 68 | from_glib(level), 69 | ) 70 | } 71 | unsafe { 72 | let f: Box_ = Box_::new(f); 73 | connect_raw( 74 | self.as_ptr() as *mut _, 75 | b"low-memory-warning\0".as_ptr() as *const _, 76 | Some(transmute::<_, unsafe extern "C" fn()>( 77 | low_memory_warning_trampoline:: as *const (), 78 | )), 79 | Box_::into_raw(f), 80 | ) 81 | } 82 | } 83 | } 84 | 85 | impl fmt::Display for MemoryMonitor { 86 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 87 | write!(f, "MemoryMonitor") 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/auto/memory_output_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::Cast; 8 | use glib::object::IsA; 9 | use glib::signal::connect_raw; 10 | use glib::signal::SignalHandlerId; 11 | use glib::translate::*; 12 | use glib_sys; 13 | use std::boxed::Box as Box_; 14 | use std::fmt; 15 | use std::mem::transmute; 16 | use OutputStream; 17 | use PollableOutputStream; 18 | use Seekable; 19 | 20 | glib_wrapper! { 21 | pub struct MemoryOutputStream(Object) @extends OutputStream, @implements PollableOutputStream, Seekable; 22 | 23 | match fn { 24 | get_type => || gio_sys::g_memory_output_stream_get_type(), 25 | } 26 | } 27 | 28 | impl MemoryOutputStream { 29 | pub fn new_resizable() -> MemoryOutputStream { 30 | unsafe { 31 | OutputStream::from_glib_full(gio_sys::g_memory_output_stream_new_resizable()) 32 | .unsafe_cast() 33 | } 34 | } 35 | } 36 | 37 | pub const NONE_MEMORY_OUTPUT_STREAM: Option<&MemoryOutputStream> = None; 38 | 39 | pub trait MemoryOutputStreamExt: 'static { 40 | fn get_data_size(&self) -> usize; 41 | 42 | fn steal_as_bytes(&self) -> Option; 43 | 44 | fn connect_property_data_size_notify(&self, f: F) -> SignalHandlerId; 45 | } 46 | 47 | impl> MemoryOutputStreamExt for O { 48 | fn get_data_size(&self) -> usize { 49 | unsafe { gio_sys::g_memory_output_stream_get_data_size(self.as_ref().to_glib_none().0) } 50 | } 51 | 52 | fn steal_as_bytes(&self) -> Option { 53 | unsafe { 54 | from_glib_full(gio_sys::g_memory_output_stream_steal_as_bytes( 55 | self.as_ref().to_glib_none().0, 56 | )) 57 | } 58 | } 59 | 60 | fn connect_property_data_size_notify(&self, f: F) -> SignalHandlerId { 61 | unsafe extern "C" fn notify_data_size_trampoline( 62 | this: *mut gio_sys::GMemoryOutputStream, 63 | _param_spec: glib_sys::gpointer, 64 | f: glib_sys::gpointer, 65 | ) where 66 | P: IsA, 67 | { 68 | let f: &F = &*(f as *const F); 69 | f(&MemoryOutputStream::from_glib_borrow(this).unsafe_cast_ref()) 70 | } 71 | unsafe { 72 | let f: Box_ = Box_::new(f); 73 | connect_raw( 74 | self.as_ptr() as *mut _, 75 | b"notify::data-size\0".as_ptr() as *const _, 76 | Some(transmute::<_, unsafe extern "C" fn()>( 77 | notify_data_size_trampoline:: as *const (), 78 | )), 79 | Box_::into_raw(f), 80 | ) 81 | } 82 | } 83 | } 84 | 85 | impl fmt::Display for MemoryOutputStream { 86 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 87 | write!(f, "MemoryOutputStream") 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/auto/menu_attribute_iter.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::GString; 10 | use std::fmt; 11 | use std::ptr; 12 | 13 | glib_wrapper! { 14 | pub struct MenuAttributeIter(Object); 15 | 16 | match fn { 17 | get_type => || gio_sys::g_menu_attribute_iter_get_type(), 18 | } 19 | } 20 | 21 | pub const NONE_MENU_ATTRIBUTE_ITER: Option<&MenuAttributeIter> = None; 22 | 23 | pub trait MenuAttributeIterExt: 'static { 24 | fn get_name(&self) -> Option; 25 | 26 | fn get_next(&self) -> Option<(GString, glib::Variant)>; 27 | 28 | fn get_value(&self) -> Option; 29 | 30 | fn next(&self) -> bool; 31 | } 32 | 33 | impl> MenuAttributeIterExt for O { 34 | fn get_name(&self) -> Option { 35 | unsafe { 36 | from_glib_none(gio_sys::g_menu_attribute_iter_get_name( 37 | self.as_ref().to_glib_none().0, 38 | )) 39 | } 40 | } 41 | 42 | fn get_next(&self) -> Option<(GString, glib::Variant)> { 43 | unsafe { 44 | let mut out_name = ptr::null(); 45 | let mut value = ptr::null_mut(); 46 | let ret = from_glib(gio_sys::g_menu_attribute_iter_get_next( 47 | self.as_ref().to_glib_none().0, 48 | &mut out_name, 49 | &mut value, 50 | )); 51 | if ret { 52 | Some((from_glib_none(out_name), from_glib_full(value))) 53 | } else { 54 | None 55 | } 56 | } 57 | } 58 | 59 | fn get_value(&self) -> Option { 60 | unsafe { 61 | from_glib_full(gio_sys::g_menu_attribute_iter_get_value( 62 | self.as_ref().to_glib_none().0, 63 | )) 64 | } 65 | } 66 | 67 | fn next(&self) -> bool { 68 | unsafe { 69 | from_glib(gio_sys::g_menu_attribute_iter_next( 70 | self.as_ref().to_glib_none().0, 71 | )) 72 | } 73 | } 74 | } 75 | 76 | impl fmt::Display for MenuAttributeIter { 77 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 78 | write!(f, "MenuAttributeIter") 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/auto/menu_link_iter.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use glib::GString; 9 | use std::fmt; 10 | use std::ptr; 11 | use MenuModel; 12 | 13 | glib_wrapper! { 14 | pub struct MenuLinkIter(Object); 15 | 16 | match fn { 17 | get_type => || gio_sys::g_menu_link_iter_get_type(), 18 | } 19 | } 20 | 21 | pub const NONE_MENU_LINK_ITER: Option<&MenuLinkIter> = None; 22 | 23 | pub trait MenuLinkIterExt: 'static { 24 | fn get_name(&self) -> Option; 25 | 26 | fn get_next(&self) -> Option<(GString, MenuModel)>; 27 | 28 | fn get_value(&self) -> Option; 29 | 30 | fn next(&self) -> bool; 31 | } 32 | 33 | impl> MenuLinkIterExt for O { 34 | fn get_name(&self) -> Option { 35 | unsafe { 36 | from_glib_none(gio_sys::g_menu_link_iter_get_name( 37 | self.as_ref().to_glib_none().0, 38 | )) 39 | } 40 | } 41 | 42 | fn get_next(&self) -> Option<(GString, MenuModel)> { 43 | unsafe { 44 | let mut out_link = ptr::null(); 45 | let mut value = ptr::null_mut(); 46 | let ret = from_glib(gio_sys::g_menu_link_iter_get_next( 47 | self.as_ref().to_glib_none().0, 48 | &mut out_link, 49 | &mut value, 50 | )); 51 | if ret { 52 | Some((from_glib_none(out_link), from_glib_full(value))) 53 | } else { 54 | None 55 | } 56 | } 57 | } 58 | 59 | fn get_value(&self) -> Option { 60 | unsafe { 61 | from_glib_full(gio_sys::g_menu_link_iter_get_value( 62 | self.as_ref().to_glib_none().0, 63 | )) 64 | } 65 | } 66 | 67 | fn next(&self) -> bool { 68 | unsafe { 69 | from_glib(gio_sys::g_menu_link_iter_next( 70 | self.as_ref().to_glib_none().0, 71 | )) 72 | } 73 | } 74 | } 75 | 76 | impl fmt::Display for MenuLinkIter { 77 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 78 | write!(f, "MenuLinkIter") 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/auto/network_address.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::GString; 10 | use std::fmt; 11 | use std::ptr; 12 | use SocketConnectable; 13 | 14 | glib_wrapper! { 15 | pub struct NetworkAddress(Object) @implements SocketConnectable; 16 | 17 | match fn { 18 | get_type => || gio_sys::g_network_address_get_type(), 19 | } 20 | } 21 | 22 | impl NetworkAddress { 23 | pub fn new(hostname: &str, port: u16) -> NetworkAddress { 24 | unsafe { 25 | from_glib_full(gio_sys::g_network_address_new( 26 | hostname.to_glib_none().0, 27 | port, 28 | )) 29 | } 30 | } 31 | 32 | #[cfg(any(feature = "v2_44", feature = "dox"))] 33 | pub fn new_loopback(port: u16) -> NetworkAddress { 34 | unsafe { from_glib_full(gio_sys::g_network_address_new_loopback(port)) } 35 | } 36 | 37 | pub fn parse(host_and_port: &str, default_port: u16) -> Result { 38 | unsafe { 39 | let mut error = ptr::null_mut(); 40 | let ret = gio_sys::g_network_address_parse( 41 | host_and_port.to_glib_none().0, 42 | default_port, 43 | &mut error, 44 | ); 45 | if error.is_null() { 46 | Ok(from_glib_full(ret)) 47 | } else { 48 | Err(from_glib_full(error)) 49 | } 50 | } 51 | } 52 | 53 | pub fn parse_uri(uri: &str, default_port: u16) -> Result { 54 | unsafe { 55 | let mut error = ptr::null_mut(); 56 | let ret = gio_sys::g_network_address_parse_uri( 57 | uri.to_glib_none().0, 58 | default_port, 59 | &mut error, 60 | ); 61 | if error.is_null() { 62 | Ok(from_glib_full(ret)) 63 | } else { 64 | Err(from_glib_full(error)) 65 | } 66 | } 67 | } 68 | } 69 | 70 | unsafe impl Send for NetworkAddress {} 71 | unsafe impl Sync for NetworkAddress {} 72 | 73 | pub const NONE_NETWORK_ADDRESS: Option<&NetworkAddress> = None; 74 | 75 | pub trait NetworkAddressExt: 'static { 76 | fn get_hostname(&self) -> Option; 77 | 78 | fn get_port(&self) -> u16; 79 | 80 | fn get_scheme(&self) -> Option; 81 | } 82 | 83 | impl> NetworkAddressExt for O { 84 | fn get_hostname(&self) -> Option { 85 | unsafe { 86 | from_glib_none(gio_sys::g_network_address_get_hostname( 87 | self.as_ref().to_glib_none().0, 88 | )) 89 | } 90 | } 91 | 92 | fn get_port(&self) -> u16 { 93 | unsafe { gio_sys::g_network_address_get_port(self.as_ref().to_glib_none().0) } 94 | } 95 | 96 | fn get_scheme(&self) -> Option { 97 | unsafe { 98 | from_glib_none(gio_sys::g_network_address_get_scheme( 99 | self.as_ref().to_glib_none().0, 100 | )) 101 | } 102 | } 103 | } 104 | 105 | impl fmt::Display for NetworkAddress { 106 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 107 | write!(f, "NetworkAddress") 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/auto/network_service.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib::GString; 12 | use glib_sys; 13 | use std::boxed::Box as Box_; 14 | use std::fmt; 15 | use std::mem::transmute; 16 | use SocketConnectable; 17 | 18 | glib_wrapper! { 19 | pub struct NetworkService(Object) @implements SocketConnectable; 20 | 21 | match fn { 22 | get_type => || gio_sys::g_network_service_get_type(), 23 | } 24 | } 25 | 26 | impl NetworkService { 27 | pub fn new(service: &str, protocol: &str, domain: &str) -> NetworkService { 28 | unsafe { 29 | from_glib_full(gio_sys::g_network_service_new( 30 | service.to_glib_none().0, 31 | protocol.to_glib_none().0, 32 | domain.to_glib_none().0, 33 | )) 34 | } 35 | } 36 | } 37 | 38 | pub const NONE_NETWORK_SERVICE: Option<&NetworkService> = None; 39 | 40 | pub trait NetworkServiceExt: 'static { 41 | fn get_domain(&self) -> Option; 42 | 43 | fn get_protocol(&self) -> Option; 44 | 45 | fn get_scheme(&self) -> Option; 46 | 47 | fn get_service(&self) -> Option; 48 | 49 | fn set_scheme(&self, scheme: &str); 50 | 51 | fn connect_property_scheme_notify(&self, f: F) -> SignalHandlerId; 52 | } 53 | 54 | impl> NetworkServiceExt for O { 55 | fn get_domain(&self) -> Option { 56 | unsafe { 57 | from_glib_none(gio_sys::g_network_service_get_domain( 58 | self.as_ref().to_glib_none().0, 59 | )) 60 | } 61 | } 62 | 63 | fn get_protocol(&self) -> Option { 64 | unsafe { 65 | from_glib_none(gio_sys::g_network_service_get_protocol( 66 | self.as_ref().to_glib_none().0, 67 | )) 68 | } 69 | } 70 | 71 | fn get_scheme(&self) -> Option { 72 | unsafe { 73 | from_glib_none(gio_sys::g_network_service_get_scheme( 74 | self.as_ref().to_glib_none().0, 75 | )) 76 | } 77 | } 78 | 79 | fn get_service(&self) -> Option { 80 | unsafe { 81 | from_glib_none(gio_sys::g_network_service_get_service( 82 | self.as_ref().to_glib_none().0, 83 | )) 84 | } 85 | } 86 | 87 | fn set_scheme(&self, scheme: &str) { 88 | unsafe { 89 | gio_sys::g_network_service_set_scheme( 90 | self.as_ref().to_glib_none().0, 91 | scheme.to_glib_none().0, 92 | ); 93 | } 94 | } 95 | 96 | fn connect_property_scheme_notify(&self, f: F) -> SignalHandlerId { 97 | unsafe extern "C" fn notify_scheme_trampoline( 98 | this: *mut gio_sys::GNetworkService, 99 | _param_spec: glib_sys::gpointer, 100 | f: glib_sys::gpointer, 101 | ) where 102 | P: IsA, 103 | { 104 | let f: &F = &*(f as *const F); 105 | f(&NetworkService::from_glib_borrow(this).unsafe_cast_ref()) 106 | } 107 | unsafe { 108 | let f: Box_ = Box_::new(f); 109 | connect_raw( 110 | self.as_ptr() as *mut _, 111 | b"notify::scheme\0".as_ptr() as *const _, 112 | Some(transmute::<_, unsafe extern "C" fn()>( 113 | notify_scheme_trampoline:: as *const (), 114 | )), 115 | Box_::into_raw(f), 116 | ) 117 | } 118 | } 119 | } 120 | 121 | impl fmt::Display for NetworkService { 122 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 123 | write!(f, "NetworkService") 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/auto/notification.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use std::fmt; 10 | use Icon; 11 | use NotificationPriority; 12 | 13 | glib_wrapper! { 14 | pub struct Notification(Object); 15 | 16 | match fn { 17 | get_type => || gio_sys::g_notification_get_type(), 18 | } 19 | } 20 | 21 | impl Notification { 22 | pub fn new(title: &str) -> Notification { 23 | unsafe { from_glib_full(gio_sys::g_notification_new(title.to_glib_none().0)) } 24 | } 25 | 26 | pub fn add_button(&self, label: &str, detailed_action: &str) { 27 | unsafe { 28 | gio_sys::g_notification_add_button( 29 | self.to_glib_none().0, 30 | label.to_glib_none().0, 31 | detailed_action.to_glib_none().0, 32 | ); 33 | } 34 | } 35 | 36 | //pub fn add_button_with_target(&self, label: &str, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { 37 | // unsafe { TODO: call gio_sys:g_notification_add_button_with_target() } 38 | //} 39 | 40 | pub fn add_button_with_target_value( 41 | &self, 42 | label: &str, 43 | action: &str, 44 | target: Option<&glib::Variant>, 45 | ) { 46 | unsafe { 47 | gio_sys::g_notification_add_button_with_target_value( 48 | self.to_glib_none().0, 49 | label.to_glib_none().0, 50 | action.to_glib_none().0, 51 | target.to_glib_none().0, 52 | ); 53 | } 54 | } 55 | 56 | pub fn set_body(&self, body: Option<&str>) { 57 | unsafe { 58 | gio_sys::g_notification_set_body(self.to_glib_none().0, body.to_glib_none().0); 59 | } 60 | } 61 | 62 | pub fn set_default_action(&self, detailed_action: &str) { 63 | unsafe { 64 | gio_sys::g_notification_set_default_action( 65 | self.to_glib_none().0, 66 | detailed_action.to_glib_none().0, 67 | ); 68 | } 69 | } 70 | 71 | //pub fn set_default_action_and_target(&self, action: &str, target_format: Option<&str>, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { 72 | // unsafe { TODO: call gio_sys:g_notification_set_default_action_and_target() } 73 | //} 74 | 75 | pub fn set_default_action_and_target_value( 76 | &self, 77 | action: &str, 78 | target: Option<&glib::Variant>, 79 | ) { 80 | unsafe { 81 | gio_sys::g_notification_set_default_action_and_target_value( 82 | self.to_glib_none().0, 83 | action.to_glib_none().0, 84 | target.to_glib_none().0, 85 | ); 86 | } 87 | } 88 | 89 | pub fn set_icon>(&self, icon: &P) { 90 | unsafe { 91 | gio_sys::g_notification_set_icon(self.to_glib_none().0, icon.as_ref().to_glib_none().0); 92 | } 93 | } 94 | 95 | pub fn set_priority(&self, priority: NotificationPriority) { 96 | unsafe { 97 | gio_sys::g_notification_set_priority(self.to_glib_none().0, priority.to_glib()); 98 | } 99 | } 100 | 101 | pub fn set_title(&self, title: &str) { 102 | unsafe { 103 | gio_sys::g_notification_set_title(self.to_glib_none().0, title.to_glib_none().0); 104 | } 105 | } 106 | } 107 | 108 | impl fmt::Display for Notification { 109 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 110 | write!(f, "Notification") 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/auto/pollable_input_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use InputStream; 10 | 11 | glib_wrapper! { 12 | pub struct PollableInputStream(Interface) @requires InputStream; 13 | 14 | match fn { 15 | get_type => || gio_sys::g_pollable_input_stream_get_type(), 16 | } 17 | } 18 | 19 | pub const NONE_POLLABLE_INPUT_STREAM: Option<&PollableInputStream> = None; 20 | 21 | pub trait PollableInputStreamExt: 'static { 22 | fn can_poll(&self) -> bool; 23 | 24 | fn is_readable(&self) -> bool; 25 | } 26 | 27 | impl> PollableInputStreamExt for O { 28 | fn can_poll(&self) -> bool { 29 | unsafe { 30 | from_glib(gio_sys::g_pollable_input_stream_can_poll( 31 | self.as_ref().to_glib_none().0, 32 | )) 33 | } 34 | } 35 | 36 | fn is_readable(&self) -> bool { 37 | unsafe { 38 | from_glib(gio_sys::g_pollable_input_stream_is_readable( 39 | self.as_ref().to_glib_none().0, 40 | )) 41 | } 42 | } 43 | } 44 | 45 | impl fmt::Display for PollableInputStream { 46 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 47 | write!(f, "PollableInputStream") 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/auto/pollable_output_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use std::fmt; 10 | use std::ptr; 11 | use Cancellable; 12 | use OutputStream; 13 | 14 | glib_wrapper! { 15 | pub struct PollableOutputStream(Interface) @requires OutputStream; 16 | 17 | match fn { 18 | get_type => || gio_sys::g_pollable_output_stream_get_type(), 19 | } 20 | } 21 | 22 | pub const NONE_POLLABLE_OUTPUT_STREAM: Option<&PollableOutputStream> = None; 23 | 24 | pub trait PollableOutputStreamExt: 'static { 25 | fn can_poll(&self) -> bool; 26 | 27 | fn is_writable(&self) -> bool; 28 | 29 | fn write_nonblocking>( 30 | &self, 31 | buffer: &[u8], 32 | cancellable: Option<&P>, 33 | ) -> Result; 34 | 35 | //#[cfg(any(feature = "v2_60", feature = "dox"))] 36 | //fn writev_nonblocking>(&self, vectors: /*Ignored*/&[&OutputVector], cancellable: Option<&P>) -> Result<(/*Ignored*/PollableReturn, usize), glib::Error>; 37 | } 38 | 39 | impl> PollableOutputStreamExt for O { 40 | fn can_poll(&self) -> bool { 41 | unsafe { 42 | from_glib(gio_sys::g_pollable_output_stream_can_poll( 43 | self.as_ref().to_glib_none().0, 44 | )) 45 | } 46 | } 47 | 48 | fn is_writable(&self) -> bool { 49 | unsafe { 50 | from_glib(gio_sys::g_pollable_output_stream_is_writable( 51 | self.as_ref().to_glib_none().0, 52 | )) 53 | } 54 | } 55 | 56 | fn write_nonblocking>( 57 | &self, 58 | buffer: &[u8], 59 | cancellable: Option<&P>, 60 | ) -> Result { 61 | let count = buffer.len() as usize; 62 | unsafe { 63 | let mut error = ptr::null_mut(); 64 | let ret = gio_sys::g_pollable_output_stream_write_nonblocking( 65 | self.as_ref().to_glib_none().0, 66 | buffer.to_glib_none().0, 67 | count, 68 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 69 | &mut error, 70 | ); 71 | if error.is_null() { 72 | Ok(ret) 73 | } else { 74 | Err(from_glib_full(error)) 75 | } 76 | } 77 | } 78 | 79 | //#[cfg(any(feature = "v2_60", feature = "dox"))] 80 | //fn writev_nonblocking>(&self, vectors: /*Ignored*/&[&OutputVector], cancellable: Option<&P>) -> Result<(/*Ignored*/PollableReturn, usize), glib::Error> { 81 | // unsafe { TODO: call gio_sys:g_pollable_output_stream_writev_nonblocking() } 82 | //} 83 | } 84 | 85 | impl fmt::Display for PollableOutputStream { 86 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 87 | write!(f, "PollableOutputStream") 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/auto/proxy_address.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::GString; 10 | use std::fmt; 11 | use InetAddress; 12 | use InetSocketAddress; 13 | use SocketAddress; 14 | use SocketConnectable; 15 | 16 | glib_wrapper! { 17 | pub struct ProxyAddress(Object) @extends InetSocketAddress, SocketAddress, @implements SocketConnectable; 18 | 19 | match fn { 20 | get_type => || gio_sys::g_proxy_address_get_type(), 21 | } 22 | } 23 | 24 | impl ProxyAddress { 25 | pub fn new>( 26 | inetaddr: &P, 27 | port: u16, 28 | protocol: &str, 29 | dest_hostname: &str, 30 | dest_port: u16, 31 | username: Option<&str>, 32 | password: Option<&str>, 33 | ) -> ProxyAddress { 34 | unsafe { 35 | SocketAddress::from_glib_full(gio_sys::g_proxy_address_new( 36 | inetaddr.as_ref().to_glib_none().0, 37 | port, 38 | protocol.to_glib_none().0, 39 | dest_hostname.to_glib_none().0, 40 | dest_port, 41 | username.to_glib_none().0, 42 | password.to_glib_none().0, 43 | )) 44 | .unsafe_cast() 45 | } 46 | } 47 | } 48 | 49 | unsafe impl Send for ProxyAddress {} 50 | unsafe impl Sync for ProxyAddress {} 51 | 52 | pub const NONE_PROXY_ADDRESS: Option<&ProxyAddress> = None; 53 | 54 | pub trait ProxyAddressExt: 'static { 55 | fn get_destination_hostname(&self) -> GString; 56 | 57 | fn get_destination_port(&self) -> u16; 58 | 59 | fn get_destination_protocol(&self) -> Option; 60 | 61 | fn get_password(&self) -> Option; 62 | 63 | fn get_protocol(&self) -> GString; 64 | 65 | fn get_uri(&self) -> Option; 66 | 67 | fn get_username(&self) -> Option; 68 | } 69 | 70 | impl> ProxyAddressExt for O { 71 | fn get_destination_hostname(&self) -> GString { 72 | unsafe { 73 | from_glib_none(gio_sys::g_proxy_address_get_destination_hostname( 74 | self.as_ref().to_glib_none().0, 75 | )) 76 | } 77 | } 78 | 79 | fn get_destination_port(&self) -> u16 { 80 | unsafe { gio_sys::g_proxy_address_get_destination_port(self.as_ref().to_glib_none().0) } 81 | } 82 | 83 | fn get_destination_protocol(&self) -> Option { 84 | unsafe { 85 | from_glib_none(gio_sys::g_proxy_address_get_destination_protocol( 86 | self.as_ref().to_glib_none().0, 87 | )) 88 | } 89 | } 90 | 91 | fn get_password(&self) -> Option { 92 | unsafe { 93 | from_glib_none(gio_sys::g_proxy_address_get_password( 94 | self.as_ref().to_glib_none().0, 95 | )) 96 | } 97 | } 98 | 99 | fn get_protocol(&self) -> GString { 100 | unsafe { 101 | from_glib_none(gio_sys::g_proxy_address_get_protocol( 102 | self.as_ref().to_glib_none().0, 103 | )) 104 | } 105 | } 106 | 107 | fn get_uri(&self) -> Option { 108 | unsafe { 109 | from_glib_none(gio_sys::g_proxy_address_get_uri( 110 | self.as_ref().to_glib_none().0, 111 | )) 112 | } 113 | } 114 | 115 | fn get_username(&self) -> Option { 116 | unsafe { 117 | from_glib_none(gio_sys::g_proxy_address_get_username( 118 | self.as_ref().to_glib_none().0, 119 | )) 120 | } 121 | } 122 | } 123 | 124 | impl fmt::Display for ProxyAddress { 125 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 126 | write!(f, "ProxyAddress") 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/auto/remote_action_group.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use std::fmt; 10 | use ActionGroup; 11 | 12 | glib_wrapper! { 13 | pub struct RemoteActionGroup(Interface) @requires ActionGroup; 14 | 15 | match fn { 16 | get_type => || gio_sys::g_remote_action_group_get_type(), 17 | } 18 | } 19 | 20 | pub const NONE_REMOTE_ACTION_GROUP: Option<&RemoteActionGroup> = None; 21 | 22 | pub trait RemoteActionGroupExt: 'static { 23 | fn activate_action_full( 24 | &self, 25 | action_name: &str, 26 | parameter: Option<&glib::Variant>, 27 | platform_data: &glib::Variant, 28 | ); 29 | 30 | fn change_action_state_full( 31 | &self, 32 | action_name: &str, 33 | value: &glib::Variant, 34 | platform_data: &glib::Variant, 35 | ); 36 | } 37 | 38 | impl> RemoteActionGroupExt for O { 39 | fn activate_action_full( 40 | &self, 41 | action_name: &str, 42 | parameter: Option<&glib::Variant>, 43 | platform_data: &glib::Variant, 44 | ) { 45 | unsafe { 46 | gio_sys::g_remote_action_group_activate_action_full( 47 | self.as_ref().to_glib_none().0, 48 | action_name.to_glib_none().0, 49 | parameter.to_glib_none().0, 50 | platform_data.to_glib_none().0, 51 | ); 52 | } 53 | } 54 | 55 | fn change_action_state_full( 56 | &self, 57 | action_name: &str, 58 | value: &glib::Variant, 59 | platform_data: &glib::Variant, 60 | ) { 61 | unsafe { 62 | gio_sys::g_remote_action_group_change_action_state_full( 63 | self.as_ref().to_glib_none().0, 64 | action_name.to_glib_none().0, 65 | value.to_glib_none().0, 66 | platform_data.to_glib_none().0, 67 | ); 68 | } 69 | } 70 | } 71 | 72 | impl fmt::Display for RemoteActionGroup { 73 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 74 | write!(f, "RemoteActionGroup") 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/auto/resource.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use glib::GString; 9 | use std; 10 | use std::mem; 11 | use std::ptr; 12 | use InputStream; 13 | use ResourceLookupFlags; 14 | 15 | glib_wrapper! { 16 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 17 | pub struct Resource(Shared); 18 | 19 | match fn { 20 | ref => |ptr| gio_sys::g_resource_ref(ptr), 21 | unref => |ptr| gio_sys::g_resource_unref(ptr), 22 | get_type => || gio_sys::g_resource_get_type(), 23 | } 24 | } 25 | 26 | impl Resource { 27 | pub fn enumerate_children( 28 | &self, 29 | path: &str, 30 | lookup_flags: ResourceLookupFlags, 31 | ) -> Result, glib::Error> { 32 | unsafe { 33 | let mut error = ptr::null_mut(); 34 | let ret = gio_sys::g_resource_enumerate_children( 35 | self.to_glib_none().0, 36 | path.to_glib_none().0, 37 | lookup_flags.to_glib(), 38 | &mut error, 39 | ); 40 | if error.is_null() { 41 | Ok(FromGlibPtrContainer::from_glib_full(ret)) 42 | } else { 43 | Err(from_glib_full(error)) 44 | } 45 | } 46 | } 47 | 48 | pub fn get_info( 49 | &self, 50 | path: &str, 51 | lookup_flags: ResourceLookupFlags, 52 | ) -> Result<(usize, u32), glib::Error> { 53 | unsafe { 54 | let mut size = mem::MaybeUninit::uninit(); 55 | let mut flags = mem::MaybeUninit::uninit(); 56 | let mut error = ptr::null_mut(); 57 | let _ = gio_sys::g_resource_get_info( 58 | self.to_glib_none().0, 59 | path.to_glib_none().0, 60 | lookup_flags.to_glib(), 61 | size.as_mut_ptr(), 62 | flags.as_mut_ptr(), 63 | &mut error, 64 | ); 65 | let size = size.assume_init(); 66 | let flags = flags.assume_init(); 67 | if error.is_null() { 68 | Ok((size, flags)) 69 | } else { 70 | Err(from_glib_full(error)) 71 | } 72 | } 73 | } 74 | 75 | pub fn lookup_data( 76 | &self, 77 | path: &str, 78 | lookup_flags: ResourceLookupFlags, 79 | ) -> Result { 80 | unsafe { 81 | let mut error = ptr::null_mut(); 82 | let ret = gio_sys::g_resource_lookup_data( 83 | self.to_glib_none().0, 84 | path.to_glib_none().0, 85 | lookup_flags.to_glib(), 86 | &mut error, 87 | ); 88 | if error.is_null() { 89 | Ok(from_glib_full(ret)) 90 | } else { 91 | Err(from_glib_full(error)) 92 | } 93 | } 94 | } 95 | 96 | pub fn open_stream( 97 | &self, 98 | path: &str, 99 | lookup_flags: ResourceLookupFlags, 100 | ) -> Result { 101 | unsafe { 102 | let mut error = ptr::null_mut(); 103 | let ret = gio_sys::g_resource_open_stream( 104 | self.to_glib_none().0, 105 | path.to_glib_none().0, 106 | lookup_flags.to_glib(), 107 | &mut error, 108 | ); 109 | if error.is_null() { 110 | Ok(from_glib_full(ret)) 111 | } else { 112 | Err(from_glib_full(error)) 113 | } 114 | } 115 | } 116 | 117 | pub fn load>(filename: P) -> Result { 118 | unsafe { 119 | let mut error = ptr::null_mut(); 120 | let ret = gio_sys::g_resource_load(filename.as_ref().to_glib_none().0, &mut error); 121 | if error.is_null() { 122 | Ok(from_glib_full(ret)) 123 | } else { 124 | Err(from_glib_full(error)) 125 | } 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/auto/seekable.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use std::fmt; 10 | use std::ptr; 11 | use Cancellable; 12 | 13 | glib_wrapper! { 14 | pub struct Seekable(Interface); 15 | 16 | match fn { 17 | get_type => || gio_sys::g_seekable_get_type(), 18 | } 19 | } 20 | 21 | pub const NONE_SEEKABLE: Option<&Seekable> = None; 22 | 23 | pub trait SeekableExt: 'static { 24 | fn can_seek(&self) -> bool; 25 | 26 | fn can_truncate(&self) -> bool; 27 | 28 | fn seek>( 29 | &self, 30 | offset: i64, 31 | type_: glib::SeekType, 32 | cancellable: Option<&P>, 33 | ) -> Result<(), glib::Error>; 34 | 35 | fn tell(&self) -> i64; 36 | 37 | fn truncate>( 38 | &self, 39 | offset: i64, 40 | cancellable: Option<&P>, 41 | ) -> Result<(), glib::Error>; 42 | } 43 | 44 | impl> SeekableExt for O { 45 | fn can_seek(&self) -> bool { 46 | unsafe { from_glib(gio_sys::g_seekable_can_seek(self.as_ref().to_glib_none().0)) } 47 | } 48 | 49 | fn can_truncate(&self) -> bool { 50 | unsafe { 51 | from_glib(gio_sys::g_seekable_can_truncate( 52 | self.as_ref().to_glib_none().0, 53 | )) 54 | } 55 | } 56 | 57 | fn seek>( 58 | &self, 59 | offset: i64, 60 | type_: glib::SeekType, 61 | cancellable: Option<&P>, 62 | ) -> Result<(), glib::Error> { 63 | unsafe { 64 | let mut error = ptr::null_mut(); 65 | let _ = gio_sys::g_seekable_seek( 66 | self.as_ref().to_glib_none().0, 67 | offset, 68 | type_.to_glib(), 69 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 70 | &mut error, 71 | ); 72 | if error.is_null() { 73 | Ok(()) 74 | } else { 75 | Err(from_glib_full(error)) 76 | } 77 | } 78 | } 79 | 80 | fn tell(&self) -> i64 { 81 | unsafe { gio_sys::g_seekable_tell(self.as_ref().to_glib_none().0) } 82 | } 83 | 84 | fn truncate>( 85 | &self, 86 | offset: i64, 87 | cancellable: Option<&P>, 88 | ) -> Result<(), glib::Error> { 89 | unsafe { 90 | let mut error = ptr::null_mut(); 91 | let _ = gio_sys::g_seekable_truncate( 92 | self.as_ref().to_glib_none().0, 93 | offset, 94 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 95 | &mut error, 96 | ); 97 | if error.is_null() { 98 | Ok(()) 99 | } else { 100 | Err(from_glib_full(error)) 101 | } 102 | } 103 | } 104 | } 105 | 106 | impl fmt::Display for Seekable { 107 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 108 | write!(f, "Seekable") 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/auto/settings_backend.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | 10 | glib_wrapper! { 11 | pub struct SettingsBackend(Object); 12 | 13 | match fn { 14 | get_type => || gio_sys::g_settings_backend_get_type(), 15 | } 16 | } 17 | 18 | impl SettingsBackend { 19 | //pub fn flatten_tree(tree: /*Ignored*/&glib::Tree) -> (GString, Vec, Vec) { 20 | // unsafe { TODO: call gio_sys:g_settings_backend_flatten_tree() } 21 | //} 22 | 23 | pub fn get_default() -> Option { 24 | unsafe { from_glib_full(gio_sys::g_settings_backend_get_default()) } 25 | } 26 | } 27 | 28 | pub const NONE_SETTINGS_BACKEND: Option<&SettingsBackend> = None; 29 | 30 | pub trait SettingsBackendExt: 'static { 31 | //fn changed(&self, key: &str, origin_tag: /*Unimplemented*/Option); 32 | 33 | //fn changed_tree(&self, tree: /*Ignored*/&glib::Tree, origin_tag: /*Unimplemented*/Option); 34 | 35 | //fn keys_changed(&self, path: &str, items: &[&str], origin_tag: /*Unimplemented*/Option); 36 | 37 | //fn path_changed(&self, path: &str, origin_tag: /*Unimplemented*/Option); 38 | 39 | fn path_writable_changed(&self, path: &str); 40 | 41 | fn writable_changed(&self, key: &str); 42 | } 43 | 44 | impl> SettingsBackendExt for O { 45 | //fn changed(&self, key: &str, origin_tag: /*Unimplemented*/Option) { 46 | // unsafe { TODO: call gio_sys:g_settings_backend_changed() } 47 | //} 48 | 49 | //fn changed_tree(&self, tree: /*Ignored*/&glib::Tree, origin_tag: /*Unimplemented*/Option) { 50 | // unsafe { TODO: call gio_sys:g_settings_backend_changed_tree() } 51 | //} 52 | 53 | //fn keys_changed(&self, path: &str, items: &[&str], origin_tag: /*Unimplemented*/Option) { 54 | // unsafe { TODO: call gio_sys:g_settings_backend_keys_changed() } 55 | //} 56 | 57 | //fn path_changed(&self, path: &str, origin_tag: /*Unimplemented*/Option) { 58 | // unsafe { TODO: call gio_sys:g_settings_backend_path_changed() } 59 | //} 60 | 61 | fn path_writable_changed(&self, path: &str) { 62 | unsafe { 63 | gio_sys::g_settings_backend_path_writable_changed( 64 | self.as_ref().to_glib_none().0, 65 | path.to_glib_none().0, 66 | ); 67 | } 68 | } 69 | 70 | fn writable_changed(&self, key: &str) { 71 | unsafe { 72 | gio_sys::g_settings_backend_writable_changed( 73 | self.as_ref().to_glib_none().0, 74 | key.to_glib_none().0, 75 | ); 76 | } 77 | } 78 | } 79 | 80 | impl fmt::Display for SettingsBackend { 81 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 82 | write!(f, "SettingsBackend") 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/auto/settings_schema.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | use glib::GString; 8 | use SettingsSchemaKey; 9 | 10 | glib_wrapper! { 11 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 12 | pub struct SettingsSchema(Shared); 13 | 14 | match fn { 15 | ref => |ptr| gio_sys::g_settings_schema_ref(ptr), 16 | unref => |ptr| gio_sys::g_settings_schema_unref(ptr), 17 | get_type => || gio_sys::g_settings_schema_get_type(), 18 | } 19 | } 20 | 21 | impl SettingsSchema { 22 | pub fn get_id(&self) -> Option { 23 | unsafe { from_glib_none(gio_sys::g_settings_schema_get_id(self.to_glib_none().0)) } 24 | } 25 | 26 | pub fn get_key(&self, name: &str) -> Option { 27 | unsafe { 28 | from_glib_full(gio_sys::g_settings_schema_get_key( 29 | self.to_glib_none().0, 30 | name.to_glib_none().0, 31 | )) 32 | } 33 | } 34 | 35 | pub fn get_path(&self) -> Option { 36 | unsafe { from_glib_none(gio_sys::g_settings_schema_get_path(self.to_glib_none().0)) } 37 | } 38 | 39 | pub fn has_key(&self, name: &str) -> bool { 40 | unsafe { 41 | from_glib(gio_sys::g_settings_schema_has_key( 42 | self.to_glib_none().0, 43 | name.to_glib_none().0, 44 | )) 45 | } 46 | } 47 | 48 | #[cfg(any(feature = "v2_44", feature = "dox"))] 49 | pub fn list_children(&self) -> Vec { 50 | unsafe { 51 | FromGlibPtrContainer::from_glib_full(gio_sys::g_settings_schema_list_children( 52 | self.to_glib_none().0, 53 | )) 54 | } 55 | } 56 | 57 | #[cfg(any(feature = "v2_46", feature = "dox"))] 58 | pub fn list_keys(&self) -> Vec { 59 | unsafe { 60 | FromGlibPtrContainer::from_glib_full(gio_sys::g_settings_schema_list_keys( 61 | self.to_glib_none().0, 62 | )) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/auto/settings_schema_key.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use glib::GString; 9 | 10 | glib_wrapper! { 11 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 12 | pub struct SettingsSchemaKey(Shared); 13 | 14 | match fn { 15 | ref => |ptr| gio_sys::g_settings_schema_key_ref(ptr), 16 | unref => |ptr| gio_sys::g_settings_schema_key_unref(ptr), 17 | get_type => || gio_sys::g_settings_schema_key_get_type(), 18 | } 19 | } 20 | 21 | impl SettingsSchemaKey { 22 | pub fn get_default_value(&self) -> Option { 23 | unsafe { 24 | from_glib_full(gio_sys::g_settings_schema_key_get_default_value( 25 | self.to_glib_none().0, 26 | )) 27 | } 28 | } 29 | 30 | pub fn get_description(&self) -> Option { 31 | unsafe { 32 | from_glib_none(gio_sys::g_settings_schema_key_get_description( 33 | self.to_glib_none().0, 34 | )) 35 | } 36 | } 37 | 38 | #[cfg(any(feature = "v2_44", feature = "dox"))] 39 | pub fn get_name(&self) -> Option { 40 | unsafe { 41 | from_glib_none(gio_sys::g_settings_schema_key_get_name( 42 | self.to_glib_none().0, 43 | )) 44 | } 45 | } 46 | 47 | pub fn get_range(&self) -> Option { 48 | unsafe { 49 | from_glib_full(gio_sys::g_settings_schema_key_get_range( 50 | self.to_glib_none().0, 51 | )) 52 | } 53 | } 54 | 55 | pub fn get_summary(&self) -> Option { 56 | unsafe { 57 | from_glib_none(gio_sys::g_settings_schema_key_get_summary( 58 | self.to_glib_none().0, 59 | )) 60 | } 61 | } 62 | 63 | pub fn get_value_type(&self) -> Option { 64 | unsafe { 65 | from_glib_none(gio_sys::g_settings_schema_key_get_value_type( 66 | self.to_glib_none().0, 67 | )) 68 | } 69 | } 70 | 71 | pub fn range_check(&self, value: &glib::Variant) -> bool { 72 | unsafe { 73 | from_glib(gio_sys::g_settings_schema_key_range_check( 74 | self.to_glib_none().0, 75 | value.to_glib_none().0, 76 | )) 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/auto/settings_schema_source.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use glib::GString; 9 | use std; 10 | use std::ptr; 11 | use SettingsSchema; 12 | 13 | glib_wrapper! { 14 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 15 | pub struct SettingsSchemaSource(Shared); 16 | 17 | match fn { 18 | ref => |ptr| gio_sys::g_settings_schema_source_ref(ptr), 19 | unref => |ptr| gio_sys::g_settings_schema_source_unref(ptr), 20 | get_type => || gio_sys::g_settings_schema_source_get_type(), 21 | } 22 | } 23 | 24 | impl SettingsSchemaSource { 25 | pub fn from_directory>( 26 | directory: P, 27 | parent: Option<&SettingsSchemaSource>, 28 | trusted: bool, 29 | ) -> Result { 30 | unsafe { 31 | let mut error = ptr::null_mut(); 32 | let ret = gio_sys::g_settings_schema_source_new_from_directory( 33 | directory.as_ref().to_glib_none().0, 34 | parent.to_glib_none().0, 35 | trusted.to_glib(), 36 | &mut error, 37 | ); 38 | if error.is_null() { 39 | Ok(from_glib_full(ret)) 40 | } else { 41 | Err(from_glib_full(error)) 42 | } 43 | } 44 | } 45 | 46 | pub fn list_schemas(&self, recursive: bool) -> (Vec, Vec) { 47 | unsafe { 48 | let mut non_relocatable = ptr::null_mut(); 49 | let mut relocatable = ptr::null_mut(); 50 | gio_sys::g_settings_schema_source_list_schemas( 51 | self.to_glib_none().0, 52 | recursive.to_glib(), 53 | &mut non_relocatable, 54 | &mut relocatable, 55 | ); 56 | ( 57 | FromGlibPtrContainer::from_glib_full(non_relocatable), 58 | FromGlibPtrContainer::from_glib_full(relocatable), 59 | ) 60 | } 61 | } 62 | 63 | pub fn lookup(&self, schema_id: &str, recursive: bool) -> Option { 64 | unsafe { 65 | from_glib_full(gio_sys::g_settings_schema_source_lookup( 66 | self.to_glib_none().0, 67 | schema_id.to_glib_none().0, 68 | recursive.to_glib(), 69 | )) 70 | } 71 | } 72 | 73 | pub fn get_default() -> Option { 74 | unsafe { from_glib_none(gio_sys::g_settings_schema_source_get_default()) } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/auto/simple_action_group.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | use std::fmt; 8 | use ActionGroup; 9 | use ActionMap; 10 | 11 | glib_wrapper! { 12 | pub struct SimpleActionGroup(Object) @implements ActionGroup, ActionMap; 13 | 14 | match fn { 15 | get_type => || gio_sys::g_simple_action_group_get_type(), 16 | } 17 | } 18 | 19 | impl SimpleActionGroup { 20 | pub fn new() -> SimpleActionGroup { 21 | unsafe { from_glib_full(gio_sys::g_simple_action_group_new()) } 22 | } 23 | } 24 | 25 | impl Default for SimpleActionGroup { 26 | fn default() -> Self { 27 | Self::new() 28 | } 29 | } 30 | 31 | pub const NONE_SIMPLE_ACTION_GROUP: Option<&SimpleActionGroup> = None; 32 | 33 | impl fmt::Display for SimpleActionGroup { 34 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 35 | write!(f, "SimpleActionGroup") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/auto/simple_io_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | #[cfg(any(feature = "v2_44", feature = "dox"))] 7 | use glib::object::Cast; 8 | #[cfg(any(feature = "v2_44", feature = "dox"))] 9 | use glib::object::IsA; 10 | use glib::translate::*; 11 | use std::fmt; 12 | use IOStream; 13 | #[cfg(any(feature = "v2_44", feature = "dox"))] 14 | use InputStream; 15 | #[cfg(any(feature = "v2_44", feature = "dox"))] 16 | use OutputStream; 17 | 18 | glib_wrapper! { 19 | pub struct SimpleIOStream(Object) @extends IOStream; 20 | 21 | match fn { 22 | get_type => || gio_sys::g_simple_io_stream_get_type(), 23 | } 24 | } 25 | 26 | impl SimpleIOStream { 27 | #[cfg(any(feature = "v2_44", feature = "dox"))] 28 | pub fn new, Q: IsA>( 29 | input_stream: &P, 30 | output_stream: &Q, 31 | ) -> SimpleIOStream { 32 | unsafe { 33 | IOStream::from_glib_full(gio_sys::g_simple_io_stream_new( 34 | input_stream.as_ref().to_glib_none().0, 35 | output_stream.as_ref().to_glib_none().0, 36 | )) 37 | .unsafe_cast() 38 | } 39 | } 40 | } 41 | 42 | impl fmt::Display for SimpleIOStream { 43 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 44 | write!(f, "SimpleIOStream") 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/auto/simple_permission.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use Permission; 10 | 11 | glib_wrapper! { 12 | pub struct SimplePermission(Object) @extends Permission; 13 | 14 | match fn { 15 | get_type => || gio_sys::g_simple_permission_get_type(), 16 | } 17 | } 18 | 19 | impl SimplePermission { 20 | pub fn new(allowed: bool) -> SimplePermission { 21 | unsafe { 22 | Permission::from_glib_full(gio_sys::g_simple_permission_new(allowed.to_glib())) 23 | .unsafe_cast() 24 | } 25 | } 26 | } 27 | 28 | impl fmt::Display for SimplePermission { 29 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 30 | write!(f, "SimplePermission") 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/auto/socket_address.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib_sys; 12 | use std::boxed::Box as Box_; 13 | use std::fmt; 14 | use std::mem::transmute; 15 | use SocketConnectable; 16 | use SocketFamily; 17 | 18 | glib_wrapper! { 19 | pub struct SocketAddress(Object) @implements SocketConnectable; 20 | 21 | match fn { 22 | get_type => || gio_sys::g_socket_address_get_type(), 23 | } 24 | } 25 | 26 | impl SocketAddress { 27 | //pub fn from_native(native: /*Unimplemented*/Fundamental: Pointer, len: usize) -> SocketAddress { 28 | // unsafe { TODO: call gio_sys:g_socket_address_new_from_native() } 29 | //} 30 | } 31 | 32 | unsafe impl Send for SocketAddress {} 33 | unsafe impl Sync for SocketAddress {} 34 | 35 | pub const NONE_SOCKET_ADDRESS: Option<&SocketAddress> = None; 36 | 37 | pub trait SocketAddressExt: 'static { 38 | fn get_family(&self) -> SocketFamily; 39 | 40 | fn get_native_size(&self) -> isize; 41 | 42 | //fn to_native(&self, dest: /*Unimplemented*/Option, destlen: usize) -> Result<(), glib::Error>; 43 | 44 | fn connect_property_family_notify( 45 | &self, 46 | f: F, 47 | ) -> SignalHandlerId; 48 | } 49 | 50 | impl> SocketAddressExt for O { 51 | fn get_family(&self) -> SocketFamily { 52 | unsafe { 53 | from_glib(gio_sys::g_socket_address_get_family( 54 | self.as_ref().to_glib_none().0, 55 | )) 56 | } 57 | } 58 | 59 | fn get_native_size(&self) -> isize { 60 | unsafe { gio_sys::g_socket_address_get_native_size(self.as_ref().to_glib_none().0) } 61 | } 62 | 63 | //fn to_native(&self, dest: /*Unimplemented*/Option, destlen: usize) -> Result<(), glib::Error> { 64 | // unsafe { TODO: call gio_sys:g_socket_address_to_native() } 65 | //} 66 | 67 | fn connect_property_family_notify( 68 | &self, 69 | f: F, 70 | ) -> SignalHandlerId { 71 | unsafe extern "C" fn notify_family_trampoline( 72 | this: *mut gio_sys::GSocketAddress, 73 | _param_spec: glib_sys::gpointer, 74 | f: glib_sys::gpointer, 75 | ) where 76 | P: IsA, 77 | { 78 | let f: &F = &*(f as *const F); 79 | f(&SocketAddress::from_glib_borrow(this).unsafe_cast_ref()) 80 | } 81 | unsafe { 82 | let f: Box_ = Box_::new(f); 83 | connect_raw( 84 | self.as_ptr() as *mut _, 85 | b"notify::family\0".as_ptr() as *const _, 86 | Some(transmute::<_, unsafe extern "C" fn()>( 87 | notify_family_trampoline:: as *const (), 88 | )), 89 | Box_::into_raw(f), 90 | ) 91 | } 92 | } 93 | } 94 | 95 | impl fmt::Display for SocketAddress { 96 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 97 | write!(f, "SocketAddress") 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/auto/socket_address_enumerator.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib_sys; 10 | use gobject_sys; 11 | use std::boxed::Box as Box_; 12 | use std::fmt; 13 | use std::pin::Pin; 14 | use std::ptr; 15 | use Cancellable; 16 | use SocketAddress; 17 | 18 | glib_wrapper! { 19 | pub struct SocketAddressEnumerator(Object); 20 | 21 | match fn { 22 | get_type => || gio_sys::g_socket_address_enumerator_get_type(), 23 | } 24 | } 25 | 26 | pub const NONE_SOCKET_ADDRESS_ENUMERATOR: Option<&SocketAddressEnumerator> = None; 27 | 28 | pub trait SocketAddressEnumeratorExt: 'static { 29 | fn next>( 30 | &self, 31 | cancellable: Option<&P>, 32 | ) -> Result; 33 | 34 | fn next_async< 35 | P: IsA, 36 | Q: FnOnce(Result) + Send + 'static, 37 | >( 38 | &self, 39 | cancellable: Option<&P>, 40 | callback: Q, 41 | ); 42 | 43 | fn next_async_future( 44 | &self, 45 | ) -> Pin> + 'static>>; 46 | } 47 | 48 | impl> SocketAddressEnumeratorExt for O { 49 | fn next>( 50 | &self, 51 | cancellable: Option<&P>, 52 | ) -> Result { 53 | unsafe { 54 | let mut error = ptr::null_mut(); 55 | let ret = gio_sys::g_socket_address_enumerator_next( 56 | self.as_ref().to_glib_none().0, 57 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 58 | &mut error, 59 | ); 60 | if error.is_null() { 61 | Ok(from_glib_full(ret)) 62 | } else { 63 | Err(from_glib_full(error)) 64 | } 65 | } 66 | } 67 | 68 | fn next_async< 69 | P: IsA, 70 | Q: FnOnce(Result) + Send + 'static, 71 | >( 72 | &self, 73 | cancellable: Option<&P>, 74 | callback: Q, 75 | ) { 76 | let user_data: Box_ = Box_::new(callback); 77 | unsafe extern "C" fn next_async_trampoline< 78 | Q: FnOnce(Result) + Send + 'static, 79 | >( 80 | _source_object: *mut gobject_sys::GObject, 81 | res: *mut gio_sys::GAsyncResult, 82 | user_data: glib_sys::gpointer, 83 | ) { 84 | let mut error = ptr::null_mut(); 85 | let ret = gio_sys::g_socket_address_enumerator_next_finish( 86 | _source_object as *mut _, 87 | res, 88 | &mut error, 89 | ); 90 | let result = if error.is_null() { 91 | Ok(from_glib_full(ret)) 92 | } else { 93 | Err(from_glib_full(error)) 94 | }; 95 | let callback: Box_ = Box_::from_raw(user_data as *mut _); 96 | callback(result); 97 | } 98 | let callback = next_async_trampoline::; 99 | unsafe { 100 | gio_sys::g_socket_address_enumerator_next_async( 101 | self.as_ref().to_glib_none().0, 102 | cancellable.map(|p| p.as_ref()).to_glib_none().0, 103 | Some(callback), 104 | Box_::into_raw(user_data) as *mut _, 105 | ); 106 | } 107 | } 108 | 109 | fn next_async_future( 110 | &self, 111 | ) -> Pin> + 'static>> 112 | { 113 | Box_::pin(crate::GioFuture::new(self, move |obj, send| { 114 | let cancellable = Cancellable::new(); 115 | obj.next_async(Some(&cancellable), move |res| { 116 | send.resolve(res); 117 | }); 118 | 119 | cancellable 120 | })) 121 | } 122 | } 123 | 124 | impl fmt::Display for SocketAddressEnumerator { 125 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 126 | write!(f, "SocketAddressEnumerator") 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/auto/socket_connectable.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | #[cfg(any(feature = "v2_48", feature = "dox"))] 9 | use glib::GString; 10 | use std::fmt; 11 | use SocketAddressEnumerator; 12 | 13 | glib_wrapper! { 14 | pub struct SocketConnectable(Interface); 15 | 16 | match fn { 17 | get_type => || gio_sys::g_socket_connectable_get_type(), 18 | } 19 | } 20 | 21 | pub const NONE_SOCKET_CONNECTABLE: Option<&SocketConnectable> = None; 22 | 23 | pub trait SocketConnectableExt: 'static { 24 | fn enumerate(&self) -> Option; 25 | 26 | fn proxy_enumerate(&self) -> Option; 27 | 28 | #[cfg(any(feature = "v2_48", feature = "dox"))] 29 | fn to_string(&self) -> Option; 30 | } 31 | 32 | impl> SocketConnectableExt for O { 33 | fn enumerate(&self) -> Option { 34 | unsafe { 35 | from_glib_full(gio_sys::g_socket_connectable_enumerate( 36 | self.as_ref().to_glib_none().0, 37 | )) 38 | } 39 | } 40 | 41 | fn proxy_enumerate(&self) -> Option { 42 | unsafe { 43 | from_glib_full(gio_sys::g_socket_connectable_proxy_enumerate( 44 | self.as_ref().to_glib_none().0, 45 | )) 46 | } 47 | } 48 | 49 | #[cfg(any(feature = "v2_48", feature = "dox"))] 50 | fn to_string(&self) -> Option { 51 | unsafe { 52 | from_glib_full(gio_sys::g_socket_connectable_to_string( 53 | self.as_ref().to_glib_none().0, 54 | )) 55 | } 56 | } 57 | } 58 | 59 | impl fmt::Display for SocketConnectable { 60 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 61 | write!(f, "SocketConnectable") 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/auto/srv_target.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::translate::*; 7 | use glib::GString; 8 | 9 | glib_wrapper! { 10 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] 11 | pub struct SrvTarget(Boxed); 12 | 13 | match fn { 14 | copy => |ptr| gio_sys::g_srv_target_copy(mut_override(ptr)), 15 | free => |ptr| gio_sys::g_srv_target_free(ptr), 16 | get_type => || gio_sys::g_srv_target_get_type(), 17 | } 18 | } 19 | 20 | impl SrvTarget { 21 | pub fn new(hostname: &str, port: u16, priority: u16, weight: u16) -> SrvTarget { 22 | unsafe { 23 | from_glib_full(gio_sys::g_srv_target_new( 24 | hostname.to_glib_none().0, 25 | port, 26 | priority, 27 | weight, 28 | )) 29 | } 30 | } 31 | 32 | pub fn get_hostname(&mut self) -> Option { 33 | unsafe { 34 | from_glib_none(gio_sys::g_srv_target_get_hostname( 35 | self.to_glib_none_mut().0, 36 | )) 37 | } 38 | } 39 | 40 | pub fn get_port(&mut self) -> u16 { 41 | unsafe { gio_sys::g_srv_target_get_port(self.to_glib_none_mut().0) } 42 | } 43 | 44 | pub fn get_priority(&mut self) -> u16 { 45 | unsafe { gio_sys::g_srv_target_get_priority(self.to_glib_none_mut().0) } 46 | } 47 | 48 | pub fn get_weight(&mut self) -> u16 { 49 | unsafe { gio_sys::g_srv_target_get_weight(self.to_glib_none_mut().0) } 50 | } 51 | 52 | //pub fn list_sort(targets: /*Unimplemented*/&[&Fundamental: Pointer]) -> /*Unimplemented*/Vec { 53 | // unsafe { TODO: call gio_sys:g_srv_target_list_sort() } 54 | //} 55 | } 56 | -------------------------------------------------------------------------------- /src/auto/tcp_connection.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib_sys; 12 | use std::boxed::Box as Box_; 13 | use std::fmt; 14 | use std::mem::transmute; 15 | use IOStream; 16 | use SocketConnection; 17 | 18 | glib_wrapper! { 19 | pub struct TcpConnection(Object) @extends SocketConnection, IOStream; 20 | 21 | match fn { 22 | get_type => || gio_sys::g_tcp_connection_get_type(), 23 | } 24 | } 25 | 26 | pub const NONE_TCP_CONNECTION: Option<&TcpConnection> = None; 27 | 28 | pub trait TcpConnectionExt: 'static { 29 | fn get_graceful_disconnect(&self) -> bool; 30 | 31 | fn set_graceful_disconnect(&self, graceful_disconnect: bool); 32 | 33 | fn connect_property_graceful_disconnect_notify( 34 | &self, 35 | f: F, 36 | ) -> SignalHandlerId; 37 | } 38 | 39 | impl> TcpConnectionExt for O { 40 | fn get_graceful_disconnect(&self) -> bool { 41 | unsafe { 42 | from_glib(gio_sys::g_tcp_connection_get_graceful_disconnect( 43 | self.as_ref().to_glib_none().0, 44 | )) 45 | } 46 | } 47 | 48 | fn set_graceful_disconnect(&self, graceful_disconnect: bool) { 49 | unsafe { 50 | gio_sys::g_tcp_connection_set_graceful_disconnect( 51 | self.as_ref().to_glib_none().0, 52 | graceful_disconnect.to_glib(), 53 | ); 54 | } 55 | } 56 | 57 | fn connect_property_graceful_disconnect_notify( 58 | &self, 59 | f: F, 60 | ) -> SignalHandlerId { 61 | unsafe extern "C" fn notify_graceful_disconnect_trampoline( 62 | this: *mut gio_sys::GTcpConnection, 63 | _param_spec: glib_sys::gpointer, 64 | f: glib_sys::gpointer, 65 | ) where 66 | P: IsA, 67 | { 68 | let f: &F = &*(f as *const F); 69 | f(&TcpConnection::from_glib_borrow(this).unsafe_cast_ref()) 70 | } 71 | unsafe { 72 | let f: Box_ = Box_::new(f); 73 | connect_raw( 74 | self.as_ptr() as *mut _, 75 | b"notify::graceful-disconnect\0".as_ptr() as *const _, 76 | Some(transmute::<_, unsafe extern "C" fn()>( 77 | notify_graceful_disconnect_trampoline:: as *const (), 78 | )), 79 | Box_::into_raw(f), 80 | ) 81 | } 82 | } 83 | } 84 | 85 | impl fmt::Display for TcpConnection { 86 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 87 | write!(f, "TcpConnection") 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/auto/themed_icon.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::ObjectType as ObjectType_; 7 | use glib::signal::connect_raw; 8 | use glib::signal::SignalHandlerId; 9 | use glib::translate::*; 10 | use glib::GString; 11 | use glib::StaticType; 12 | use glib::Value; 13 | use glib_sys; 14 | use gobject_sys; 15 | use std::boxed::Box as Box_; 16 | use std::fmt; 17 | use std::mem::transmute; 18 | use Icon; 19 | 20 | glib_wrapper! { 21 | pub struct ThemedIcon(Object) @implements Icon; 22 | 23 | match fn { 24 | get_type => || gio_sys::g_themed_icon_get_type(), 25 | } 26 | } 27 | 28 | impl ThemedIcon { 29 | pub fn new(iconname: &str) -> ThemedIcon { 30 | unsafe { from_glib_full(gio_sys::g_themed_icon_new(iconname.to_glib_none().0)) } 31 | } 32 | 33 | pub fn from_names(iconnames: &[&str]) -> ThemedIcon { 34 | let len = iconnames.len() as i32; 35 | unsafe { 36 | from_glib_full(gio_sys::g_themed_icon_new_from_names( 37 | iconnames.to_glib_none().0, 38 | len, 39 | )) 40 | } 41 | } 42 | 43 | pub fn with_default_fallbacks(iconname: &str) -> ThemedIcon { 44 | unsafe { 45 | from_glib_full(gio_sys::g_themed_icon_new_with_default_fallbacks( 46 | iconname.to_glib_none().0, 47 | )) 48 | } 49 | } 50 | 51 | pub fn append_name(&self, iconname: &str) { 52 | unsafe { 53 | gio_sys::g_themed_icon_append_name(self.to_glib_none().0, iconname.to_glib_none().0); 54 | } 55 | } 56 | 57 | pub fn get_names(&self) -> Vec { 58 | unsafe { 59 | FromGlibPtrContainer::from_glib_none(gio_sys::g_themed_icon_get_names( 60 | self.to_glib_none().0, 61 | )) 62 | } 63 | } 64 | 65 | pub fn prepend_name(&self, iconname: &str) { 66 | unsafe { 67 | gio_sys::g_themed_icon_prepend_name(self.to_glib_none().0, iconname.to_glib_none().0); 68 | } 69 | } 70 | 71 | pub fn get_property_use_default_fallbacks(&self) -> bool { 72 | unsafe { 73 | let mut value = Value::from_type(::static_type()); 74 | gobject_sys::g_object_get_property( 75 | self.as_ptr() as *mut gobject_sys::GObject, 76 | b"use-default-fallbacks\0".as_ptr() as *const _, 77 | value.to_glib_none_mut().0, 78 | ); 79 | value 80 | .get() 81 | .expect("Return Value for property `use-default-fallbacks` getter") 82 | .unwrap() 83 | } 84 | } 85 | 86 | pub fn connect_property_names_notify( 87 | &self, 88 | f: F, 89 | ) -> SignalHandlerId { 90 | unsafe extern "C" fn notify_names_trampoline( 91 | this: *mut gio_sys::GThemedIcon, 92 | _param_spec: glib_sys::gpointer, 93 | f: glib_sys::gpointer, 94 | ) { 95 | let f: &F = &*(f as *const F); 96 | f(&from_glib_borrow(this)) 97 | } 98 | unsafe { 99 | let f: Box_ = Box_::new(f); 100 | connect_raw( 101 | self.as_ptr() as *mut _, 102 | b"notify::names\0".as_ptr() as *const _, 103 | Some(transmute::<_, unsafe extern "C" fn()>( 104 | notify_names_trampoline:: as *const (), 105 | )), 106 | Box_::into_raw(f), 107 | ) 108 | } 109 | } 110 | } 111 | 112 | impl fmt::Display for ThemedIcon { 113 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 114 | write!(f, "ThemedIcon") 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/auto/threaded_socket_service.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::Cast; 8 | use glib::object::IsA; 9 | use glib::signal::connect_raw; 10 | use glib::signal::SignalHandlerId; 11 | use glib::translate::*; 12 | use glib::StaticType; 13 | use glib::Value; 14 | use glib_sys; 15 | use gobject_sys; 16 | use std::boxed::Box as Box_; 17 | use std::fmt; 18 | use std::mem::transmute; 19 | use SocketConnection; 20 | use SocketListener; 21 | use SocketService; 22 | 23 | glib_wrapper! { 24 | pub struct ThreadedSocketService(Object) @extends SocketService, SocketListener; 25 | 26 | match fn { 27 | get_type => || gio_sys::g_threaded_socket_service_get_type(), 28 | } 29 | } 30 | 31 | pub const NONE_THREADED_SOCKET_SERVICE: Option<&ThreadedSocketService> = None; 32 | 33 | pub trait ThreadedSocketServiceExt: 'static { 34 | fn get_property_max_threads(&self) -> i32; 35 | 36 | fn connect_run) -> bool + 'static>( 37 | &self, 38 | f: F, 39 | ) -> SignalHandlerId; 40 | } 41 | 42 | impl> ThreadedSocketServiceExt for O { 43 | fn get_property_max_threads(&self) -> i32 { 44 | unsafe { 45 | let mut value = Value::from_type(::static_type()); 46 | gobject_sys::g_object_get_property( 47 | self.to_glib_none().0 as *mut gobject_sys::GObject, 48 | b"max-threads\0".as_ptr() as *const _, 49 | value.to_glib_none_mut().0, 50 | ); 51 | value 52 | .get() 53 | .expect("Return Value for property `max-threads` getter") 54 | .unwrap() 55 | } 56 | } 57 | 58 | fn connect_run) -> bool + 'static>( 59 | &self, 60 | f: F, 61 | ) -> SignalHandlerId { 62 | unsafe extern "C" fn run_trampoline< 63 | P, 64 | F: Fn(&P, &SocketConnection, Option<&glib::Object>) -> bool + 'static, 65 | >( 66 | this: *mut gio_sys::GThreadedSocketService, 67 | connection: *mut gio_sys::GSocketConnection, 68 | source_object: *mut gobject_sys::GObject, 69 | f: glib_sys::gpointer, 70 | ) -> glib_sys::gboolean 71 | where 72 | P: IsA, 73 | { 74 | let f: &F = &*(f as *const F); 75 | f( 76 | &ThreadedSocketService::from_glib_borrow(this).unsafe_cast_ref(), 77 | &from_glib_borrow(connection), 78 | Option::::from_glib_borrow(source_object) 79 | .as_ref() 80 | .as_ref(), 81 | ) 82 | .to_glib() 83 | } 84 | unsafe { 85 | let f: Box_ = Box_::new(f); 86 | connect_raw( 87 | self.as_ptr() as *mut _, 88 | b"run\0".as_ptr() as *const _, 89 | Some(transmute::<_, unsafe extern "C" fn()>( 90 | run_trampoline:: as *const (), 91 | )), 92 | Box_::into_raw(f), 93 | ) 94 | } 95 | } 96 | } 97 | 98 | impl fmt::Display for ThreadedSocketService { 99 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 100 | write!(f, "ThreadedSocketService") 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/auto/tls_file_database.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::Cast; 8 | use glib::object::IsA; 9 | use glib::signal::connect_raw; 10 | use glib::signal::SignalHandlerId; 11 | use glib::translate::*; 12 | use glib::GString; 13 | use glib::StaticType; 14 | use glib::Value; 15 | use glib_sys; 16 | use gobject_sys; 17 | use std; 18 | use std::boxed::Box as Box_; 19 | use std::fmt; 20 | use std::mem::transmute; 21 | use std::ptr; 22 | use TlsDatabase; 23 | 24 | glib_wrapper! { 25 | pub struct TlsFileDatabase(Interface) @requires TlsDatabase; 26 | 27 | match fn { 28 | get_type => || gio_sys::g_tls_file_database_get_type(), 29 | } 30 | } 31 | 32 | impl TlsFileDatabase { 33 | pub fn new>(anchors: P) -> Result { 34 | unsafe { 35 | let mut error = ptr::null_mut(); 36 | let ret = 37 | gio_sys::g_tls_file_database_new(anchors.as_ref().to_glib_none().0, &mut error); 38 | if error.is_null() { 39 | Ok(from_glib_full(ret)) 40 | } else { 41 | Err(from_glib_full(error)) 42 | } 43 | } 44 | } 45 | } 46 | 47 | pub const NONE_TLS_FILE_DATABASE: Option<&TlsFileDatabase> = None; 48 | 49 | pub trait TlsFileDatabaseExt: 'static { 50 | fn get_property_anchors(&self) -> Option; 51 | 52 | fn set_property_anchors(&self, anchors: Option<&str>); 53 | 54 | fn connect_property_anchors_notify(&self, f: F) -> SignalHandlerId; 55 | } 56 | 57 | impl> TlsFileDatabaseExt for O { 58 | fn get_property_anchors(&self) -> Option { 59 | unsafe { 60 | let mut value = Value::from_type(::static_type()); 61 | gobject_sys::g_object_get_property( 62 | self.to_glib_none().0 as *mut gobject_sys::GObject, 63 | b"anchors\0".as_ptr() as *const _, 64 | value.to_glib_none_mut().0, 65 | ); 66 | value 67 | .get() 68 | .expect("Return Value for property `anchors` getter") 69 | } 70 | } 71 | 72 | fn set_property_anchors(&self, anchors: Option<&str>) { 73 | unsafe { 74 | gobject_sys::g_object_set_property( 75 | self.to_glib_none().0 as *mut gobject_sys::GObject, 76 | b"anchors\0".as_ptr() as *const _, 77 | Value::from(anchors).to_glib_none().0, 78 | ); 79 | } 80 | } 81 | 82 | fn connect_property_anchors_notify(&self, f: F) -> SignalHandlerId { 83 | unsafe extern "C" fn notify_anchors_trampoline( 84 | this: *mut gio_sys::GTlsFileDatabase, 85 | _param_spec: glib_sys::gpointer, 86 | f: glib_sys::gpointer, 87 | ) where 88 | P: IsA, 89 | { 90 | let f: &F = &*(f as *const F); 91 | f(&TlsFileDatabase::from_glib_borrow(this).unsafe_cast_ref()) 92 | } 93 | unsafe { 94 | let f: Box_ = Box_::new(f); 95 | connect_raw( 96 | self.as_ptr() as *mut _, 97 | b"notify::anchors\0".as_ptr() as *const _, 98 | Some(transmute::<_, unsafe extern "C" fn()>( 99 | notify_anchors_trampoline:: as *const (), 100 | )), 101 | Box_::into_raw(f), 102 | ) 103 | } 104 | } 105 | } 106 | 107 | impl fmt::Display for TlsFileDatabase { 108 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 109 | write!(f, "TlsFileDatabase") 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/auto/unix_fd_list.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | 10 | glib_wrapper! { 11 | pub struct UnixFDList(Object); 12 | 13 | match fn { 14 | get_type => || gio_sys::g_unix_fd_list_get_type(), 15 | } 16 | } 17 | 18 | impl UnixFDList { 19 | pub fn new() -> UnixFDList { 20 | unsafe { from_glib_full(gio_sys::g_unix_fd_list_new()) } 21 | } 22 | } 23 | 24 | impl Default for UnixFDList { 25 | fn default() -> Self { 26 | Self::new() 27 | } 28 | } 29 | 30 | pub const NONE_UNIX_FD_LIST: Option<&UnixFDList> = None; 31 | 32 | pub trait UnixFDListExt: 'static { 33 | fn get_length(&self) -> i32; 34 | } 35 | 36 | impl> UnixFDListExt for O { 37 | fn get_length(&self) -> i32 { 38 | unsafe { gio_sys::g_unix_fd_list_get_length(self.as_ref().to_glib_none().0) } 39 | } 40 | } 41 | 42 | impl fmt::Display for UnixFDList { 43 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 44 | write!(f, "UnixFDList") 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/auto/unix_input_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use InputStream; 10 | use PollableInputStream; 11 | 12 | glib_wrapper! { 13 | pub struct UnixInputStream(Object) @extends InputStream, @implements PollableInputStream; 14 | 15 | match fn { 16 | get_type => || gio_sys::g_unix_input_stream_get_type(), 17 | } 18 | } 19 | 20 | pub const NONE_UNIX_INPUT_STREAM: Option<&UnixInputStream> = None; 21 | 22 | pub trait UnixInputStreamExt: 'static { 23 | fn get_close_fd(&self) -> bool; 24 | } 25 | 26 | impl> UnixInputStreamExt for O { 27 | fn get_close_fd(&self) -> bool { 28 | unsafe { 29 | from_glib(gio_sys::g_unix_input_stream_get_close_fd( 30 | self.as_ref().to_glib_none().0, 31 | )) 32 | } 33 | } 34 | } 35 | 36 | impl fmt::Display for UnixInputStream { 37 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 38 | write!(f, "UnixInputStream") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/auto/unix_mount_entry.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use gobject_sys; 7 | 8 | glib_wrapper! { 9 | #[derive(Debug)] 10 | pub struct UnixMountEntry(Boxed); 11 | 12 | match fn { 13 | copy => |ptr| gobject_sys::g_boxed_copy(gio_sys::g_unix_mount_entry_get_type(), ptr as *mut _) as *mut gio_sys::GUnixMountEntry, 14 | free => |ptr| gobject_sys::g_boxed_free(gio_sys::g_unix_mount_entry_get_type(), ptr as *mut _), 15 | get_type => || gio_sys::g_unix_mount_entry_get_type(), 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/auto/unix_output_stream.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::IsA; 7 | use glib::translate::*; 8 | use std::fmt; 9 | use OutputStream; 10 | use PollableOutputStream; 11 | 12 | glib_wrapper! { 13 | pub struct UnixOutputStream(Object) @extends OutputStream, @implements PollableOutputStream; 14 | 15 | match fn { 16 | get_type => || gio_sys::g_unix_output_stream_get_type(), 17 | } 18 | } 19 | 20 | pub const NONE_UNIX_OUTPUT_STREAM: Option<&UnixOutputStream> = None; 21 | 22 | pub trait UnixOutputStreamExt: 'static { 23 | fn get_close_fd(&self) -> bool; 24 | } 25 | 26 | impl> UnixOutputStreamExt for O { 27 | fn get_close_fd(&self) -> bool { 28 | unsafe { 29 | from_glib(gio_sys::g_unix_output_stream_get_close_fd( 30 | self.as_ref().to_glib_none().0, 31 | )) 32 | } 33 | } 34 | } 35 | 36 | impl fmt::Display for UnixOutputStream { 37 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 38 | write!(f, "UnixOutputStream") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/auto/unix_socket_address.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib::StaticType; 10 | use glib::Value; 11 | use gobject_sys; 12 | use std::fmt; 13 | use SocketAddress; 14 | use SocketConnectable; 15 | use UnixSocketAddressType; 16 | 17 | glib_wrapper! { 18 | pub struct UnixSocketAddress(Object) @extends SocketAddress, @implements SocketConnectable; 19 | 20 | match fn { 21 | get_type => || gio_sys::g_unix_socket_address_get_type(), 22 | } 23 | } 24 | 25 | impl UnixSocketAddress { 26 | //pub fn new_abstract(path: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 10 }) -> UnixSocketAddress { 27 | // unsafe { TODO: call gio_sys:g_unix_socket_address_new_abstract() } 28 | //} 29 | 30 | //pub fn with_type(path: /*Unimplemented*/&CArray TypeId { ns_id: 0, id: 10 }, type_: UnixSocketAddressType) -> UnixSocketAddress { 31 | // unsafe { TODO: call gio_sys:g_unix_socket_address_new_with_type() } 32 | //} 33 | 34 | pub fn abstract_names_supported() -> bool { 35 | unsafe { from_glib(gio_sys::g_unix_socket_address_abstract_names_supported()) } 36 | } 37 | } 38 | 39 | unsafe impl Send for UnixSocketAddress {} 40 | unsafe impl Sync for UnixSocketAddress {} 41 | 42 | pub const NONE_UNIX_SOCKET_ADDRESS: Option<&UnixSocketAddress> = None; 43 | 44 | pub trait UnixSocketAddressExt: 'static { 45 | fn get_address_type(&self) -> UnixSocketAddressType; 46 | 47 | fn get_is_abstract(&self) -> bool; 48 | 49 | fn get_path_len(&self) -> usize; 50 | 51 | fn get_property_abstract(&self) -> bool; 52 | 53 | fn get_property_path_as_array(&self) -> Option; 54 | } 55 | 56 | impl> UnixSocketAddressExt for O { 57 | fn get_address_type(&self) -> UnixSocketAddressType { 58 | unsafe { 59 | from_glib(gio_sys::g_unix_socket_address_get_address_type( 60 | self.as_ref().to_glib_none().0, 61 | )) 62 | } 63 | } 64 | 65 | fn get_is_abstract(&self) -> bool { 66 | unsafe { 67 | from_glib(gio_sys::g_unix_socket_address_get_is_abstract( 68 | self.as_ref().to_glib_none().0, 69 | )) 70 | } 71 | } 72 | 73 | fn get_path_len(&self) -> usize { 74 | unsafe { gio_sys::g_unix_socket_address_get_path_len(self.as_ref().to_glib_none().0) } 75 | } 76 | 77 | fn get_property_abstract(&self) -> bool { 78 | unsafe { 79 | let mut value = Value::from_type(::static_type()); 80 | gobject_sys::g_object_get_property( 81 | self.to_glib_none().0 as *mut gobject_sys::GObject, 82 | b"abstract\0".as_ptr() as *const _, 83 | value.to_glib_none_mut().0, 84 | ); 85 | value 86 | .get() 87 | .expect("Return Value for property `abstract` getter") 88 | .unwrap() 89 | } 90 | } 91 | 92 | fn get_property_path_as_array(&self) -> Option { 93 | unsafe { 94 | let mut value = Value::from_type(::static_type()); 95 | gobject_sys::g_object_get_property( 96 | self.to_glib_none().0 as *mut gobject_sys::GObject, 97 | b"path-as-array\0".as_ptr() as *const _, 98 | value.to_glib_none_mut().0, 99 | ); 100 | value 101 | .get() 102 | .expect("Return Value for property `path-as-array` getter") 103 | } 104 | } 105 | } 106 | 107 | impl fmt::Display for UnixSocketAddress { 108 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 109 | write!(f, "UnixSocketAddress") 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/auto/versions.txt: -------------------------------------------------------------------------------- 1 | Generated by gir (https://github.com/gtk-rs/gir @ ad40c01) 2 | from gir-files (https://github.com/gtk-rs/gir-files @ 8a626fd) 3 | -------------------------------------------------------------------------------- /src/auto/zlib_decompressor.rs: -------------------------------------------------------------------------------- 1 | // This file was generated by gir (https://github.com/gtk-rs/gir) 2 | // from gir-files (https://github.com/gtk-rs/gir-files) 3 | // DO NOT EDIT 4 | 5 | use gio_sys; 6 | use glib::object::Cast; 7 | use glib::object::IsA; 8 | use glib::signal::connect_raw; 9 | use glib::signal::SignalHandlerId; 10 | use glib::translate::*; 11 | use glib::StaticType; 12 | use glib::Value; 13 | use glib_sys; 14 | use gobject_sys; 15 | use std::boxed::Box as Box_; 16 | use std::fmt; 17 | use std::mem::transmute; 18 | use Converter; 19 | use FileInfo; 20 | use ZlibCompressorFormat; 21 | 22 | glib_wrapper! { 23 | pub struct ZlibDecompressor(Object) @implements Converter; 24 | 25 | match fn { 26 | get_type => || gio_sys::g_zlib_decompressor_get_type(), 27 | } 28 | } 29 | 30 | impl ZlibDecompressor { 31 | pub fn new(format: ZlibCompressorFormat) -> ZlibDecompressor { 32 | unsafe { from_glib_full(gio_sys::g_zlib_decompressor_new(format.to_glib())) } 33 | } 34 | } 35 | 36 | pub const NONE_ZLIB_DECOMPRESSOR: Option<&ZlibDecompressor> = None; 37 | 38 | pub trait ZlibDecompressorExt: 'static { 39 | fn get_file_info(&self) -> Option; 40 | 41 | fn get_property_format(&self) -> ZlibCompressorFormat; 42 | 43 | fn connect_property_file_info_notify(&self, f: F) -> SignalHandlerId; 44 | } 45 | 46 | impl> ZlibDecompressorExt for O { 47 | fn get_file_info(&self) -> Option { 48 | unsafe { 49 | from_glib_none(gio_sys::g_zlib_decompressor_get_file_info( 50 | self.as_ref().to_glib_none().0, 51 | )) 52 | } 53 | } 54 | 55 | fn get_property_format(&self) -> ZlibCompressorFormat { 56 | unsafe { 57 | let mut value = Value::from_type(::static_type()); 58 | gobject_sys::g_object_get_property( 59 | self.to_glib_none().0 as *mut gobject_sys::GObject, 60 | b"format\0".as_ptr() as *const _, 61 | value.to_glib_none_mut().0, 62 | ); 63 | value 64 | .get() 65 | .expect("Return Value for property `format` getter") 66 | .unwrap() 67 | } 68 | } 69 | 70 | fn connect_property_file_info_notify(&self, f: F) -> SignalHandlerId { 71 | unsafe extern "C" fn notify_file_info_trampoline( 72 | this: *mut gio_sys::GZlibDecompressor, 73 | _param_spec: glib_sys::gpointer, 74 | f: glib_sys::gpointer, 75 | ) where 76 | P: IsA, 77 | { 78 | let f: &F = &*(f as *const F); 79 | f(&ZlibDecompressor::from_glib_borrow(this).unsafe_cast_ref()) 80 | } 81 | unsafe { 82 | let f: Box_ = Box_::new(f); 83 | connect_raw( 84 | self.as_ptr() as *mut _, 85 | b"notify::file-info\0".as_ptr() as *const _, 86 | Some(transmute::<_, unsafe extern "C" fn()>( 87 | notify_file_info_trampoline:: as *const (), 88 | )), 89 | Box_::into_raw(f), 90 | ) 91 | } 92 | } 93 | } 94 | 95 | impl fmt::Display for ZlibDecompressor { 96 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 97 | write!(f, "ZlibDecompressor") 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/cancellable.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use crate::CancellableExt; 6 | 7 | #[test] 8 | fn check_callback() { 9 | let c = crate::Cancellable::new(); 10 | c.connect_cancelled(|_| {}); 11 | c.cancel(); // if it doesn't crash at this point, then we're good to go! 12 | } 13 | -------------------------------------------------------------------------------- /src/converter.rs: -------------------------------------------------------------------------------- 1 | use gio_sys; 2 | use glib::object::IsA; 3 | use glib::translate::*; 4 | use std::mem; 5 | use std::ptr; 6 | use Converter; 7 | use ConverterFlags; 8 | use ConverterResult; 9 | 10 | pub trait ConverterExtManual { 11 | fn convert, OUT: AsMut<[u8]>>( 12 | &self, 13 | inbuf: IN, 14 | outbuf: OUT, 15 | flags: ConverterFlags, 16 | ) -> Result<(ConverterResult, usize, usize), glib::Error>; 17 | } 18 | 19 | impl> ConverterExtManual for O { 20 | fn convert, OUT: AsMut<[u8]>>( 21 | &self, 22 | inbuf: IN, 23 | outbuf: OUT, 24 | flags: ConverterFlags, 25 | ) -> Result<(ConverterResult, usize, usize), glib::Error> { 26 | let inbuf: Box = Box::new(inbuf); 27 | let (inbuf_size, inbuf) = { 28 | let slice = (*inbuf).as_ref(); 29 | (slice.len(), slice.as_ptr()) 30 | }; 31 | let mut outbuf: Box = Box::new(outbuf); 32 | let (outbuf_size, outbuf) = { 33 | let slice = (*outbuf).as_mut(); 34 | (slice.len(), slice.as_mut_ptr()) 35 | }; 36 | unsafe { 37 | let mut bytes_read = mem::MaybeUninit::uninit(); 38 | let mut bytes_written = mem::MaybeUninit::uninit(); 39 | let mut error = ptr::null_mut(); 40 | let ret = gio_sys::g_converter_convert( 41 | self.as_ref().to_glib_none().0, 42 | mut_override(inbuf), 43 | inbuf_size, 44 | outbuf, 45 | outbuf_size, 46 | flags.to_glib(), 47 | bytes_read.as_mut_ptr(), 48 | bytes_written.as_mut_ptr(), 49 | &mut error, 50 | ); 51 | if error.is_null() { 52 | Ok(( 53 | from_glib(ret), 54 | bytes_read.assume_init(), 55 | bytes_written.assume_init(), 56 | )) 57 | } else { 58 | Err(from_glib_full(error)) 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/dbus_message.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use std::fmt; 6 | use DBusMessage; 7 | 8 | impl fmt::Display for DBusMessage { 9 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 10 | write!( 11 | f, 12 | "{}", 13 | self.print(0).unwrap_or_else(|| "".into()) 14 | ) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/dbus_method_invocation.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gio_sys; 6 | use glib::error::ErrorDomain; 7 | use glib::translate::*; 8 | use DBusMethodInvocation; 9 | 10 | impl DBusMethodInvocation { 11 | pub fn return_error(&self, error: T, message: &str) { 12 | unsafe { 13 | gio_sys::g_dbus_method_invocation_return_error_literal( 14 | self.to_glib_full(), 15 | T::domain().to_glib(), 16 | error.code(), 17 | message.to_glib_none().0, 18 | ); 19 | } 20 | } 21 | 22 | pub fn return_gerror(&self, error: glib::Error) { 23 | unsafe { 24 | gio_sys::g_dbus_method_invocation_return_gerror( 25 | self.to_glib_full(), 26 | error.to_glib_none().0, 27 | ); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/error.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use std::io; 6 | use IOErrorEnum; 7 | 8 | impl From for io::ErrorKind { 9 | fn from(kind: IOErrorEnum) -> Self { 10 | match kind { 11 | IOErrorEnum::NotFound => io::ErrorKind::NotFound, 12 | IOErrorEnum::Exists => io::ErrorKind::AlreadyExists, 13 | IOErrorEnum::InvalidFilename => io::ErrorKind::InvalidInput, 14 | IOErrorEnum::InvalidArgument => io::ErrorKind::InvalidInput, 15 | IOErrorEnum::PermissionDenied => io::ErrorKind::PermissionDenied, 16 | IOErrorEnum::AddressInUse => io::ErrorKind::AddrInUse, 17 | IOErrorEnum::TimedOut => io::ErrorKind::TimedOut, 18 | IOErrorEnum::WouldBlock => io::ErrorKind::WouldBlock, 19 | IOErrorEnum::InvalidData => io::ErrorKind::InvalidData, 20 | IOErrorEnum::ConnectionRefused => io::ErrorKind::ConnectionRefused, 21 | IOErrorEnum::BrokenPipe => io::ErrorKind::BrokenPipe, 22 | IOErrorEnum::NotConnected => io::ErrorKind::NotConnected, 23 | _ => io::ErrorKind::Other, 24 | } 25 | } 26 | } 27 | 28 | pub(crate) fn to_std_io_result(result: Result) -> io::Result { 29 | result.map_err(|g_error| match g_error.kind::() { 30 | Some(io_error_enum) => io::Error::new(io_error_enum.into(), g_error), 31 | None => io::Error::new(io::ErrorKind::Other, g_error), 32 | }) 33 | } 34 | -------------------------------------------------------------------------------- /src/file_attribute_matcher.rs: -------------------------------------------------------------------------------- 1 | use gio_sys; 2 | use glib::translate::*; 3 | use glib::GString; 4 | use std::iter::{IntoIterator, Iterator}; 5 | 6 | pub struct FileAttributematcherIter(::FileAttributeMatcher); 7 | 8 | impl Iterator for FileAttributematcherIter { 9 | type Item = GString; 10 | 11 | fn next(&mut self) -> Option { 12 | unsafe { 13 | from_glib_none(gio_sys::g_file_attribute_matcher_enumerate_next( 14 | self.0.to_glib_none().0, 15 | )) 16 | } 17 | } 18 | } 19 | 20 | impl IntoIterator for ::FileAttributeMatcher { 21 | type Item = GString; 22 | type IntoIter = FileAttributematcherIter; 23 | 24 | fn into_iter(self) -> Self::IntoIter { 25 | FileAttributematcherIter(self) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/file_enumerator.rs: -------------------------------------------------------------------------------- 1 | use std::iter::Iterator; 2 | use FileEnumerator; 3 | use FileEnumeratorExt; 4 | use FileInfo; 5 | 6 | impl Iterator for FileEnumerator { 7 | type Item = Result; 8 | 9 | fn next(&mut self) -> Option> { 10 | match self.next_file(::NONE_CANCELLABLE) { 11 | Err(err) => Some(Err(err)), 12 | Ok(file_info) => file_info.map(Ok), 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/file_info.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::object::IsA; 8 | use glib::translate::*; 9 | use glib_sys; 10 | use gobject_sys; 11 | use std::mem; 12 | use std::pin::Pin; 13 | use std::ptr; 14 | use std::time::{Duration, SystemTime}; 15 | use FileInfo; 16 | 17 | impl FileInfo { 18 | #[cfg_attr(feature = "v2_62", deprecated)] 19 | pub fn get_modification_time(&self) -> SystemTime { 20 | unsafe { 21 | let mut result = mem::MaybeUninit::uninit(); 22 | gio_sys::g_file_info_get_modification_time(self.to_glib_none().0, result.as_mut_ptr()); 23 | let result = result.assume_init(); 24 | 25 | if result.tv_sec > 0 { 26 | let duration = Duration::from_secs(result.tv_sec as u64) 27 | + Duration::from_millis(result.tv_usec as u64); 28 | SystemTime::UNIX_EPOCH + duration 29 | } else { 30 | let duration = Duration::from_secs((-result.tv_sec) as u64) 31 | + Duration::from_millis(result.tv_usec as u64); 32 | SystemTime::UNIX_EPOCH - duration 33 | } 34 | } 35 | } 36 | 37 | #[cfg_attr(feature = "v2_62", deprecated)] 38 | pub fn set_modification_time(&self, mtime: SystemTime) { 39 | let diff = mtime 40 | .duration_since(SystemTime::UNIX_EPOCH) 41 | .expect("failed to convert time"); 42 | unsafe { 43 | gio_sys::g_file_info_set_modification_time( 44 | self.to_glib_none().0, 45 | mut_override(&glib_sys::GTimeVal { 46 | tv_sec: diff.as_secs() as _, 47 | tv_usec: diff.subsec_micros() as _, 48 | }), 49 | ); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/flags.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use ApplicationFlags; 6 | 7 | impl Default for ApplicationFlags { 8 | fn default() -> ApplicationFlags { 9 | ApplicationFlags::empty() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/inet_address.rs: -------------------------------------------------------------------------------- 1 | use gio_sys; 2 | use glib::object::IsA; 3 | use glib::translate::*; 4 | use InetAddress; 5 | use InetAddressExt; 6 | use SocketFamily; 7 | 8 | use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; 9 | 10 | #[derive(Debug)] 11 | pub enum InetAddressBytes<'a> { 12 | V4(&'a [u8; 4]), 13 | V6(&'a [u8; 16]), 14 | } 15 | 16 | impl<'a> InetAddressBytes<'a> { 17 | fn deref(&self) -> &[u8] { 18 | use self::InetAddressBytes::*; 19 | 20 | match *self { 21 | V4(bytes) => bytes, 22 | V6(bytes) => bytes, 23 | } 24 | } 25 | } 26 | 27 | impl InetAddress { 28 | pub fn from_bytes(inet_address_bytes: InetAddressBytes) -> Self { 29 | let bytes = inet_address_bytes.deref(); 30 | 31 | let family = match inet_address_bytes { 32 | InetAddressBytes::V4(_) => SocketFamily::Ipv4, 33 | InetAddressBytes::V6(_) => SocketFamily::Ipv6, 34 | }; 35 | unsafe { 36 | from_glib_full(gio_sys::g_inet_address_new_from_bytes( 37 | bytes.to_glib_none().0, 38 | family.to_glib(), 39 | )) 40 | } 41 | } 42 | } 43 | 44 | pub trait InetAddressExtManual { 45 | fn to_bytes<'a>(&'a self) -> Option>; 46 | } 47 | 48 | impl> InetAddressExtManual for O { 49 | /// Returns `None` in case the address has a native size different than 4 and 16. 50 | fn to_bytes<'a>(&'a self) -> Option> { 51 | let size = self.get_native_size(); 52 | unsafe { 53 | let bytes = gio_sys::g_inet_address_to_bytes(self.as_ref().to_glib_none().0); 54 | if size == 4 { 55 | Some(InetAddressBytes::V4(&*(bytes as *const [u8; 4]))) 56 | } else if size == 16 { 57 | Some(InetAddressBytes::V6(&*(bytes as *const [u8; 16]))) 58 | } else { 59 | None 60 | } 61 | } 62 | } 63 | } 64 | 65 | impl From for InetAddress { 66 | fn from(addr: IpAddr) -> Self { 67 | match addr { 68 | IpAddr::V4(v4) => InetAddress::from_bytes(InetAddressBytes::V4(&v4.octets())), 69 | IpAddr::V6(v6) => InetAddress::from_bytes(InetAddressBytes::V6(&v6.octets())), 70 | } 71 | } 72 | } 73 | 74 | impl Into for InetAddress { 75 | fn into(self) -> IpAddr { 76 | let size = self.get_native_size(); 77 | unsafe { 78 | let bytes = gio_sys::g_inet_address_to_bytes(self.to_glib_none().0); 79 | if size == 4 { 80 | IpAddr::V4(Ipv4Addr::from(*(bytes as *const [u8; 4]))) 81 | } else if size == 16 { 82 | IpAddr::V6(Ipv6Addr::from(*(bytes as *const [u16; 8]))) 83 | } else { 84 | panic!("Unknown IP kind"); 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/io_stream.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use futures_core::task::{Context, Poll}; 6 | use futures_io::{AsyncRead, AsyncWrite}; 7 | use glib::object::{Cast, IsA}; 8 | use pollable_input_stream::PollableInputStreamExtManual; 9 | use pollable_output_stream::PollableOutputStreamExtManual; 10 | use std::io; 11 | use std::pin::Pin; 12 | use IOStream; 13 | use IOStreamExt; 14 | use InputStreamAsyncRead; 15 | use OutputStreamAsyncWrite; 16 | use PollableInputStream; 17 | use PollableOutputStream; 18 | 19 | pub trait IOStreamExtManual: Sized + IsA { 20 | fn into_async_read_write(self) -> Result, Self> { 21 | let write = self 22 | .get_output_stream() 23 | .and_then(|s| s.dynamic_cast::().ok()) 24 | .and_then(|s| s.into_async_write().ok()); 25 | 26 | let read = self 27 | .get_input_stream() 28 | .and_then(|s| s.dynamic_cast::().ok()) 29 | .and_then(|s| s.into_async_read().ok()); 30 | 31 | let (read, write) = match (read, write) { 32 | (Some(read), Some(write)) => (read, write), 33 | _ => return Err(self), 34 | }; 35 | 36 | Ok(IOStreamAsyncReadWrite { 37 | io_stream: self, 38 | read, 39 | write, 40 | }) 41 | } 42 | } 43 | 44 | impl> IOStreamExtManual for O {} 45 | 46 | #[derive(Debug)] 47 | pub struct IOStreamAsyncReadWrite { 48 | io_stream: T, 49 | read: InputStreamAsyncRead, 50 | write: OutputStreamAsyncWrite, 51 | } 52 | 53 | impl> IOStreamAsyncReadWrite { 54 | pub fn input_stream(&self) -> &PollableInputStream { 55 | self.read.input_stream() 56 | } 57 | 58 | pub fn output_stream(&self) -> &PollableOutputStream { 59 | self.write.output_stream() 60 | } 61 | 62 | pub fn into_io_stream(self) -> T { 63 | self.io_stream 64 | } 65 | 66 | pub fn io_stream(&self) -> &T { 67 | &self.io_stream 68 | } 69 | } 70 | 71 | impl + std::marker::Unpin> AsyncRead for IOStreamAsyncReadWrite { 72 | fn poll_read( 73 | self: Pin<&mut Self>, 74 | cx: &mut Context<'_>, 75 | buf: &mut [u8], 76 | ) -> Poll> { 77 | Pin::new(&mut Pin::get_mut(self).read).poll_read(cx, buf) 78 | } 79 | } 80 | 81 | impl + std::marker::Unpin> AsyncWrite for IOStreamAsyncReadWrite { 82 | fn poll_write( 83 | self: Pin<&mut Self>, 84 | cx: &mut Context<'_>, 85 | buf: &[u8], 86 | ) -> Poll> { 87 | Pin::new(&mut Pin::get_mut(self).write).poll_write(cx, buf) 88 | } 89 | 90 | fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { 91 | Pin::new(&mut Pin::get_mut(self).write).poll_close(cx) 92 | } 93 | 94 | fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { 95 | Pin::new(&mut Pin::get_mut(self).write).poll_flush(cx) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | #![allow(deprecated)] 6 | #![allow(clippy::let_and_return)] 7 | #![allow(clippy::too_many_arguments)] 8 | #![allow(clippy::type_complexity)] 9 | 10 | #[macro_use] 11 | extern crate bitflags; 12 | extern crate once_cell; 13 | #[macro_use] 14 | extern crate glib; 15 | #[cfg_attr(test, macro_use)] 16 | #[cfg(test)] 17 | extern crate serial_test_derive; 18 | 19 | extern crate gio_sys; 20 | extern crate glib_sys; 21 | extern crate gobject_sys; 22 | extern crate libc; 23 | 24 | extern crate futures_channel; 25 | extern crate futures_core; 26 | extern crate futures_io; 27 | extern crate futures_util; 28 | 29 | mod app_info; 30 | mod application; 31 | #[cfg(test)] 32 | mod cancellable; 33 | mod converter; 34 | mod data_input_stream; 35 | mod dbus; 36 | pub use dbus::*; 37 | mod dbus_connection; 38 | pub use dbus_connection::{ 39 | ActionGroupExportId, FilterId, MenuModelExportId, RegistrationId, SignalSubscriptionId, 40 | WatcherId, 41 | }; 42 | mod dbus_message; 43 | mod dbus_method_invocation; 44 | #[cfg(any(all(not(windows), not(target_os = "macos")), feature = "dox"))] 45 | mod desktop_app_info; 46 | mod error; 47 | mod file; 48 | mod file_attribute_matcher; 49 | pub use file_attribute_matcher::FileAttributematcherIter; 50 | mod file_enumerator; 51 | mod file_info; 52 | mod flags; 53 | mod inet_address; 54 | mod io_stream; 55 | pub use io_stream::IOStreamAsyncReadWrite; 56 | mod input_stream; 57 | pub use input_stream::{InputStreamAsyncBufRead, InputStreamRead}; 58 | #[cfg(any(feature = "v2_44", feature = "dox"))] 59 | mod list_store; 60 | mod memory_input_stream; 61 | mod memory_output_stream; 62 | mod output_stream; 63 | pub use output_stream::OutputStreamWrite; 64 | mod pollable_input_stream; 65 | pub use pollable_input_stream::InputStreamAsyncRead; 66 | mod pollable_output_stream; 67 | pub use pollable_output_stream::OutputStreamAsyncWrite; 68 | mod resource; 69 | mod settings; 70 | mod socket; 71 | mod subprocess; 72 | mod subprocess_launcher; 73 | mod threaded_socket_service; 74 | #[cfg(any(unix, feature = "dox"))] 75 | mod unix_fd_list; 76 | #[cfg(any(unix, feature = "dox"))] 77 | mod unix_input_stream; 78 | #[cfg(any(unix, feature = "dox"))] 79 | #[cfg(any(feature = "v2_54", feature = "dox"))] 80 | mod unix_mount_entry; 81 | #[cfg(any(unix, feature = "dox"))] 82 | #[cfg(any(feature = "v2_54", feature = "dox"))] 83 | mod unix_mount_point; 84 | #[cfg(any(unix, feature = "dox"))] 85 | mod unix_output_stream; 86 | #[cfg(any(unix, feature = "dox"))] 87 | mod unix_socket_address; 88 | pub use inet_address::InetAddressBytes; 89 | 90 | #[cfg(test)] 91 | mod test_util; 92 | 93 | pub use auto::functions::*; 94 | pub use auto::*; 95 | 96 | pub mod prelude; 97 | 98 | #[allow(clippy::cast_ptr_alignment)] 99 | #[allow(clippy::wrong_self_convention)] 100 | mod auto; 101 | 102 | mod gio_future; 103 | pub use gio_future::*; 104 | 105 | #[macro_use] 106 | pub mod subclass; 107 | mod read_input_stream; 108 | pub use read_input_stream::ReadInputStream; 109 | mod write_output_stream; 110 | pub use write_output_stream::WriteOutputStream; 111 | mod tls_connection; 112 | pub use tls_connection::TlsConnectionManualExt; 113 | -------------------------------------------------------------------------------- /src/list_store.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use glib::{IsA, Object}; 9 | use glib_sys; 10 | use gobject_sys; 11 | use std::cmp::Ordering; 12 | use ListStore; 13 | 14 | pub trait ListStoreExtManual { 15 | fn insert_sorted, F: FnMut(&Object, &Object) -> Ordering>( 16 | &self, 17 | item: &P, 18 | compare_func: F, 19 | ) -> u32; 20 | 21 | #[cfg(any(feature = "v2_46", feature = "dox"))] 22 | fn sort Ordering>(&self, compare_func: F); 23 | } 24 | 25 | impl> ListStoreExtManual for O { 26 | fn insert_sorted, F: FnMut(&Object, &Object) -> Ordering>( 27 | &self, 28 | item: &P, 29 | compare_func: F, 30 | ) -> u32 { 31 | unsafe { 32 | let mut func = compare_func; 33 | let func_obj: &mut (dyn FnMut(&Object, &Object) -> Ordering) = &mut func; 34 | let func_ptr = &func_obj as *const &mut (dyn FnMut(&Object, &Object) -> Ordering) 35 | as glib_sys::gpointer; 36 | 37 | gio_sys::g_list_store_insert_sorted( 38 | self.as_ref().to_glib_none().0, 39 | item.as_ref().to_glib_none().0, 40 | Some(compare_func_trampoline), 41 | func_ptr, 42 | ) 43 | } 44 | } 45 | 46 | #[cfg(any(feature = "v2_46", feature = "dox"))] 47 | fn sort Ordering>(&self, compare_func: F) { 48 | unsafe { 49 | let mut func = compare_func; 50 | let func_obj: &mut (dyn FnMut(&Object, &Object) -> Ordering) = &mut func; 51 | let func_ptr = &func_obj as *const &mut (dyn FnMut(&Object, &Object) -> Ordering) 52 | as glib_sys::gpointer; 53 | 54 | gio_sys::g_list_store_sort( 55 | self.as_ref().to_glib_none().0, 56 | Some(compare_func_trampoline), 57 | func_ptr, 58 | ) 59 | } 60 | } 61 | } 62 | 63 | unsafe extern "C" fn compare_func_trampoline( 64 | a: glib_sys::gconstpointer, 65 | b: glib_sys::gconstpointer, 66 | func: glib_sys::gpointer, 67 | ) -> i32 { 68 | let func = func as *mut &mut (dyn FnMut(&Object, &Object) -> Ordering); 69 | 70 | let a = from_glib_borrow(a as *mut gobject_sys::GObject); 71 | let b = from_glib_borrow(b as *mut gobject_sys::GObject); 72 | 73 | match (*func)(&a, &b) { 74 | Ordering::Less => -1, 75 | Ordering::Equal => 0, 76 | Ordering::Greater => 1, 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/memory_input_stream.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2017, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | #[cfg(test)] 6 | mod tests { 7 | use crate::prelude::*; 8 | use crate::MemoryInputStream; 9 | use glib::Bytes; 10 | 11 | #[test] 12 | fn new() { 13 | let strm = MemoryInputStream::new(); 14 | let ret = strm.skip(1, ::NONE_CANCELLABLE); 15 | assert!(!ret.is_err()); 16 | assert_eq!(ret.unwrap(), 0); 17 | 18 | let mut buf = vec![0; 10]; 19 | let ret = strm.read(&mut buf, ::NONE_CANCELLABLE).unwrap(); 20 | assert_eq!(ret, 0); 21 | } 22 | 23 | #[test] 24 | fn from_bytes() { 25 | let b = Bytes::from_owned(vec![1, 2, 3]); 26 | let strm = MemoryInputStream::from_bytes(&b); 27 | let mut buf = vec![0; 10]; 28 | let ret = strm.read(&mut buf, ::NONE_CANCELLABLE).unwrap(); 29 | assert_eq!(ret, 3); 30 | assert_eq!(buf[0], 1); 31 | assert_eq!(buf[1], 2); 32 | assert_eq!(buf[2], 3); 33 | 34 | let ret = strm.skip(10, ::NONE_CANCELLABLE).unwrap(); 35 | assert_eq!(ret, 0); 36 | } 37 | 38 | #[test] 39 | fn add_bytes() { 40 | let strm = MemoryInputStream::new(); 41 | let b = Bytes::from_owned(vec![1, 2, 3]); 42 | strm.add_bytes(&b); 43 | let mut buf = vec![0; 10]; 44 | let ret = strm.read(&mut buf, ::NONE_CANCELLABLE).unwrap(); 45 | assert_eq!(ret, 3); 46 | assert_eq!(buf[0], 1); 47 | assert_eq!(buf[1], 2); 48 | assert_eq!(buf[2], 3); 49 | 50 | let ret = strm.skip(10, ::NONE_CANCELLABLE).unwrap(); 51 | assert_eq!(ret, 0); 52 | } 53 | 54 | #[test] 55 | fn read_async_future() { 56 | use futures_util::future::TryFutureExt; 57 | 58 | let c = glib::MainContext::new(); 59 | 60 | let buf = vec![0; 10]; 61 | let b = glib::Bytes::from_owned(vec![1, 2, 3]); 62 | let strm = MemoryInputStream::from_bytes(&b); 63 | 64 | let res = c 65 | .block_on( 66 | strm.read_async_future(buf, glib::PRIORITY_DEFAULT) 67 | .map_err(|(_buf, err)| err) 68 | .map_ok(move |(mut buf, len)| { 69 | buf.truncate(len); 70 | buf 71 | }), 72 | ) 73 | .unwrap(); 74 | 75 | assert_eq!(res, vec![1, 2, 3]); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/memory_output_stream.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2017, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | #[cfg(test)] 6 | mod tests { 7 | use crate::prelude::*; 8 | use crate::MemoryOutputStream; 9 | 10 | #[test] 11 | fn steal_empty() { 12 | let strm = MemoryOutputStream::new_resizable(); 13 | assert_eq!(strm.get_data_size(), 0); 14 | 15 | assert!(strm.close(::NONE_CANCELLABLE).is_ok()); 16 | assert_eq!(strm.steal_as_bytes().unwrap(), [].as_ref()); 17 | } 18 | 19 | #[test] 20 | fn steal() { 21 | let strm = MemoryOutputStream::new_resizable(); 22 | 23 | assert!(strm.write(&[1, 2, 3], ::NONE_CANCELLABLE).is_ok()); 24 | assert_eq!(strm.get_data_size(), 3); 25 | 26 | assert!(strm.write(&[4, 5], ::NONE_CANCELLABLE).is_ok()); 27 | assert_eq!(strm.get_data_size(), 5); 28 | 29 | assert!(strm.close(::NONE_CANCELLABLE).is_ok()); 30 | assert_eq!(strm.steal_as_bytes().unwrap(), [1, 2, 3, 4, 5].as_ref()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/prelude.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | //! Traits and essential types intended for blanket imports. 6 | 7 | #[doc(hidden)] 8 | pub use glib::prelude::*; 9 | 10 | pub use auto::traits::*; 11 | 12 | #[cfg(any(feature = "v2_60", feature = "dox"))] 13 | pub use app_info::AppInfoExtManual; 14 | pub use application::*; 15 | pub use converter::*; 16 | pub use data_input_stream::DataInputStreamExtManual; 17 | #[cfg(any(feature = "v2_58", feature = "dox"))] 18 | #[cfg(any(all(not(windows), not(target_os = "macos")), feature = "dox"))] 19 | pub use desktop_app_info::DesktopAppInfoExtManual; 20 | pub use file::FileExtManual; 21 | pub use inet_address::InetAddressExtManual; 22 | pub use input_stream::InputStreamExtManual; 23 | pub use io_stream::IOStreamExtManual; 24 | #[cfg(any(feature = "v2_44", feature = "dox"))] 25 | pub use list_store::ListStoreExtManual; 26 | pub use output_stream::OutputStreamExtManual; 27 | pub use pollable_input_stream::PollableInputStreamExtManual; 28 | pub use pollable_output_stream::PollableOutputStreamExtManual; 29 | pub use settings::SettingsExtManual; 30 | pub use socket::*; 31 | #[cfg(any(unix, feature = "dox"))] 32 | pub use unix_input_stream::UnixInputStreamExtManual; 33 | #[cfg(any(unix, feature = "dox"))] 34 | pub use unix_output_stream::UnixOutputStreamExtManual; 35 | #[cfg(any(unix, feature = "dox"))] 36 | pub use unix_socket_address::{UnixSocketAddressExtManual, UnixSocketAddressPath}; 37 | -------------------------------------------------------------------------------- /src/resource.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2017, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gio_sys; 6 | use glib; 7 | use glib::translate::*; 8 | use glib_sys; 9 | use std::mem; 10 | use std::ptr; 11 | use Resource; 12 | 13 | impl Resource { 14 | pub fn from_data(data: &glib::Bytes) -> Result { 15 | unsafe { 16 | let mut error = ptr::null_mut(); 17 | 18 | // Create a copy of data if it is not pointer-aligned 19 | // https://bugzilla.gnome.org/show_bug.cgi?id=790030 20 | let mut data = data.clone(); 21 | let data_ptr = glib_sys::g_bytes_get_data(data.to_glib_none().0, ptr::null_mut()); 22 | if data_ptr as usize % mem::align_of::<*const u8>() != 0 { 23 | data = glib::Bytes::from(&*data); 24 | } 25 | 26 | let ret = gio_sys::g_resource_new_from_data(data.to_glib_none().0, &mut error); 27 | if error.is_null() { 28 | Ok(from_glib_full(ret)) 29 | } else { 30 | Err(from_glib_full(error)) 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/settings.rs: -------------------------------------------------------------------------------- 1 | use glib::variant::FromVariant; 2 | use glib::{BoolError, IsA, ToVariant}; 3 | use {Settings, SettingsExt}; 4 | 5 | pub trait SettingsExtManual { 6 | fn get(&self, key: &str) -> U; 7 | 8 | fn set(&self, key: &str, value: &U) -> Result<(), BoolError>; 9 | } 10 | 11 | impl> SettingsExtManual for O { 12 | fn get(&self, key: &str) -> U { 13 | let val = self.get_value(key); 14 | FromVariant::from_variant(&val).unwrap_or_else(|| { 15 | panic!( 16 | "Type mismatch: Expected '{}' got '{}'", 17 | U::static_variant_type().to_str(), 18 | val.type_() 19 | ) 20 | }) 21 | } 22 | 23 | fn set(&self, key: &str, value: &U) -> Result<(), BoolError> { 24 | self.set_value(key, &value.to_variant()) 25 | } 26 | } 27 | 28 | #[cfg(test)] 29 | mod test { 30 | use super::*; 31 | use std::env::set_var; 32 | use std::process::Command; 33 | use std::str::from_utf8; 34 | use std::sync::Once; 35 | 36 | static INIT: Once = Once::new(); 37 | 38 | fn set_env() { 39 | INIT.call_once(|| { 40 | let output = Command::new("glib-compile-schemas") 41 | .args(&[ 42 | &format!("{}/tests", env!("CARGO_MANIFEST_DIR")), 43 | "--targetdir", 44 | env!("OUT_DIR"), 45 | ]) 46 | .output() 47 | .unwrap(); 48 | 49 | if !output.status.success() { 50 | println!("Failed to generate GSchema!"); 51 | println!( 52 | "glib-compile-schemas stdout: {}", 53 | from_utf8(&output.stdout).unwrap() 54 | ); 55 | println!( 56 | "glib-compile-schemas stderr: {}", 57 | from_utf8(&output.stderr).unwrap() 58 | ); 59 | panic!("Can't test without GSchemas!"); 60 | } 61 | 62 | set_var("GSETTINGS_SCHEMA_DIR", env!("OUT_DIR")); 63 | set_var("GSETTINGS_BACKEND", "memory"); 64 | }); 65 | } 66 | 67 | #[test] 68 | #[serial] 69 | fn string_get() { 70 | set_env(); 71 | let settings = Settings::new("com.github.gtk-rs.test"); 72 | assert_eq!(settings.get::("test-string").as_str(), "Good"); 73 | } 74 | 75 | #[test] 76 | #[serial] 77 | fn bool_set_get() { 78 | set_env(); 79 | let settings = Settings::new("com.github.gtk-rs.test"); 80 | settings.set("test-bool", &false).unwrap(); 81 | assert!(!settings.get::("test-bool")); 82 | } 83 | 84 | #[test] 85 | #[should_panic] 86 | #[serial] 87 | fn wrong_type() { 88 | set_env(); 89 | let settings = Settings::new("com.github.gtk-rs.test"); 90 | settings.get::("test-string"); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/subclass/mod.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | mod application; 6 | mod input_stream; 7 | mod io_stream; 8 | mod output_stream; 9 | mod seekable; 10 | 11 | pub use self::application::ArgumentList; 12 | pub use self::prelude::*; 13 | 14 | pub mod prelude { 15 | pub use super::application::{ApplicationImpl, ApplicationImplExt}; 16 | pub use super::input_stream::{InputStreamImpl, InputStreamImplExt}; 17 | pub use super::io_stream::{IOStreamImpl, IOStreamImplExt}; 18 | pub use super::output_stream::{OutputStreamImpl, OutputStreamImplExt}; 19 | pub use super::seekable::SeekableImpl; 20 | pub use glib::subclass::prelude::*; 21 | } 22 | -------------------------------------------------------------------------------- /src/subclass/seekable.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2019, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gio_sys; 6 | use glib_sys; 7 | 8 | use glib::translate::*; 9 | use glib::Error; 10 | use glib::SeekType; 11 | 12 | use glib::subclass::prelude::*; 13 | 14 | use std::mem; 15 | 16 | use Cancellable; 17 | use Seekable; 18 | 19 | pub trait SeekableImpl: ObjectImpl + Send { 20 | fn tell(&self, seekable: &Seekable) -> i64; 21 | fn can_seek(&self, seekable: &Seekable) -> bool; 22 | fn seek( 23 | &self, 24 | seekable: &Seekable, 25 | offset: i64, 26 | type_: SeekType, 27 | cancellable: Option<&Cancellable>, 28 | ) -> Result<(), Error>; 29 | fn can_truncate(&self, seekable: &Seekable) -> bool; 30 | fn truncate( 31 | &self, 32 | seekable: &Seekable, 33 | offset: i64, 34 | cancellable: Option<&Cancellable>, 35 | ) -> Result<(), Error>; 36 | } 37 | 38 | unsafe impl IsImplementable for Seekable { 39 | unsafe extern "C" fn interface_init( 40 | iface: glib_sys::gpointer, 41 | _iface_data: glib_sys::gpointer, 42 | ) { 43 | let seekable_iface = &mut *(iface as *mut gio_sys::GSeekableIface); 44 | 45 | seekable_iface.tell = Some(seekable_tell::); 46 | seekable_iface.can_seek = Some(seekable_can_seek::); 47 | seekable_iface.seek = Some(seekable_seek::); 48 | seekable_iface.can_truncate = Some(seekable_can_truncate::); 49 | seekable_iface.truncate_fn = Some(seekable_truncate::); 50 | } 51 | } 52 | 53 | unsafe extern "C" fn seekable_tell(seekable: *mut gio_sys::GSeekable) -> i64 { 54 | let instance = &*(seekable as *mut T::Instance); 55 | let imp = instance.get_impl(); 56 | 57 | imp.tell(&from_glib_borrow(seekable)) 58 | } 59 | 60 | unsafe extern "C" fn seekable_can_seek( 61 | seekable: *mut gio_sys::GSeekable, 62 | ) -> glib_sys::gboolean { 63 | let instance = &*(seekable as *mut T::Instance); 64 | let imp = instance.get_impl(); 65 | 66 | imp.can_seek(&from_glib_borrow(seekable)).to_glib() 67 | } 68 | 69 | unsafe extern "C" fn seekable_seek( 70 | seekable: *mut gio_sys::GSeekable, 71 | offset: i64, 72 | type_: glib_sys::GSeekType, 73 | cancellable: *mut gio_sys::GCancellable, 74 | err: *mut *mut glib_sys::GError, 75 | ) -> glib_sys::gboolean { 76 | let instance = &*(seekable as *mut T::Instance); 77 | let imp = instance.get_impl(); 78 | 79 | match imp.seek( 80 | &from_glib_borrow(seekable), 81 | offset, 82 | from_glib(type_), 83 | Option::::from_glib_borrow(cancellable) 84 | .as_ref() 85 | .as_ref(), 86 | ) { 87 | Ok(()) => glib_sys::GTRUE, 88 | Err(e) => { 89 | let mut e = mem::ManuallyDrop::new(e); 90 | *err = e.to_glib_none_mut().0; 91 | glib_sys::GFALSE 92 | } 93 | } 94 | } 95 | 96 | unsafe extern "C" fn seekable_can_truncate( 97 | seekable: *mut gio_sys::GSeekable, 98 | ) -> glib_sys::gboolean { 99 | let instance = &*(seekable as *mut T::Instance); 100 | let imp = instance.get_impl(); 101 | 102 | imp.can_truncate(&from_glib_borrow(seekable)).to_glib() 103 | } 104 | 105 | unsafe extern "C" fn seekable_truncate( 106 | seekable: *mut gio_sys::GSeekable, 107 | offset: i64, 108 | cancellable: *mut gio_sys::GCancellable, 109 | err: *mut *mut glib_sys::GError, 110 | ) -> glib_sys::gboolean { 111 | let instance = &*(seekable as *mut T::Instance); 112 | let imp = instance.get_impl(); 113 | 114 | match imp.truncate( 115 | &from_glib_borrow(seekable), 116 | offset, 117 | Option::::from_glib_borrow(cancellable) 118 | .as_ref() 119 | .as_ref(), 120 | ) { 121 | Ok(()) => glib_sys::GTRUE, 122 | Err(e) => { 123 | let mut e = mem::ManuallyDrop::new(e); 124 | *err = e.to_glib_none_mut().0; 125 | glib_sys::GFALSE 126 | } 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/subprocess.rs: -------------------------------------------------------------------------------- 1 | use gio_sys; 2 | use glib::object::IsA; 3 | use glib::translate::*; 4 | use glib::GString; 5 | use glib_sys; 6 | use gobject_sys; 7 | use libc::c_char; 8 | use std::pin::Pin; 9 | use std::ptr; 10 | use Cancellable; 11 | use Subprocess; 12 | 13 | impl Subprocess { 14 | pub fn communicate_utf8_async< 15 | R: FnOnce(Result<(Option, Option), glib::Error>) + Send + 'static, 16 | C: IsA, 17 | >( 18 | &self, 19 | stdin_buf: Option, 20 | cancellable: Option<&C>, 21 | callback: R, 22 | ) { 23 | let stdin_buf = stdin_buf.to_glib_full(); 24 | let cancellable = cancellable.map(|c| c.as_ref()); 25 | let gcancellable = cancellable.to_glib_none(); 26 | let user_data: Box<(R, *mut c_char)> = Box::new((callback, stdin_buf)); 27 | unsafe extern "C" fn communicate_utf8_async_trampoline< 28 | R: FnOnce(Result<(Option, Option), glib::Error>) + Send + 'static, 29 | >( 30 | _source_object: *mut gobject_sys::GObject, 31 | res: *mut gio_sys::GAsyncResult, 32 | user_data: glib_sys::gpointer, 33 | ) { 34 | let mut error = ptr::null_mut(); 35 | let mut stdout_buf = ptr::null_mut(); 36 | let mut stderr_buf = ptr::null_mut(); 37 | let _ = gio_sys::g_subprocess_communicate_utf8_finish( 38 | _source_object as *mut _, 39 | res, 40 | &mut stdout_buf, 41 | &mut stderr_buf, 42 | &mut error, 43 | ); 44 | let result = if error.is_null() { 45 | Ok((from_glib_full(stdout_buf), from_glib_full(stderr_buf))) 46 | } else { 47 | Err(from_glib_full(error)) 48 | }; 49 | let callback: Box<(R, *mut c_char)> = Box::from_raw(user_data as *mut _); 50 | glib_sys::g_free(callback.1 as *mut _); 51 | callback.0(result); 52 | } 53 | unsafe { 54 | gio_sys::g_subprocess_communicate_utf8_async( 55 | self.to_glib_none().0, 56 | stdin_buf, 57 | gcancellable.0, 58 | Some(communicate_utf8_async_trampoline::), 59 | Box::into_raw(user_data) as *mut _, 60 | ); 61 | } 62 | } 63 | 64 | pub fn communicate_utf8_async_future( 65 | &self, 66 | stdin_buf: Option, 67 | ) -> Pin< 68 | Box< 69 | dyn std::future::Future< 70 | Output = Result<(Option, Option), glib::Error>, 71 | > + 'static, 72 | >, 73 | > { 74 | Box::pin(crate::GioFuture::new(self, move |obj, send| { 75 | let cancellable = Cancellable::new(); 76 | obj.communicate_utf8_async(stdin_buf, Some(&cancellable), move |res| { 77 | send.resolve(res); 78 | }); 79 | 80 | cancellable 81 | })) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/subprocess_launcher.rs: -------------------------------------------------------------------------------- 1 | #[cfg(any(unix, feature = "dox"))] 2 | use gio_sys; 3 | #[cfg(any(unix, feature = "dox"))] 4 | use glib::translate::*; 5 | #[cfg(any(unix, all(feature = "dox", unix)))] 6 | use std::os::unix::io::IntoRawFd; 7 | use SubprocessLauncher; 8 | 9 | #[cfg(all(feature = "dox", not(unix)))] 10 | pub trait IntoRawFd: Sized { 11 | fn into_raw_fd(self) -> i32 { 12 | 0 13 | } 14 | } 15 | 16 | impl SubprocessLauncher { 17 | #[cfg(any(unix, feature = "dox"))] 18 | pub fn take_fd(&self, source_fd: F, target_fd: G) { 19 | unsafe { 20 | gio_sys::g_subprocess_launcher_take_fd( 21 | self.to_glib_none().0, 22 | source_fd.into_raw_fd(), 23 | target_fd.into_raw_fd(), 24 | ); 25 | } 26 | } 27 | 28 | #[cfg(any(unix, feature = "dox"))] 29 | pub fn take_stderr_fd(&self, fd: F) { 30 | unsafe { 31 | gio_sys::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, fd.into_raw_fd()); 32 | } 33 | } 34 | 35 | #[cfg(any(unix, feature = "dox"))] 36 | pub fn take_stdin_fd(&self, fd: F) { 37 | unsafe { 38 | gio_sys::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, fd.into_raw_fd()); 39 | } 40 | } 41 | 42 | #[cfg(any(unix, feature = "dox"))] 43 | pub fn take_stdout_fd(&self, fd: F) { 44 | unsafe { 45 | gio_sys::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, fd.into_raw_fd()); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test_util.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2017, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use glib::*; 6 | use std::sync::mpsc::{channel, Sender}; 7 | 8 | #[allow(dead_code)] 9 | pub fn run_async, MainLoop) + Send + 'static>( 10 | start: Q, 11 | ) -> T { 12 | let c = MainContext::new(); 13 | let l = MainLoop::new(Some(&c), false); 14 | let l_clone = l.clone(); 15 | 16 | let (tx, rx) = channel(); 17 | 18 | c.push_thread_default(); 19 | c.invoke(move || { 20 | start(tx, l_clone); 21 | }); 22 | 23 | l.run(); 24 | c.pop_thread_default(); 25 | 26 | let ret = rx.recv().unwrap(); 27 | ret 28 | } 29 | -------------------------------------------------------------------------------- /src/threaded_socket_service.rs: -------------------------------------------------------------------------------- 1 | use glib::translate::FromGlibPtrFull; 2 | use glib::Cast; 3 | 4 | use SocketService; 5 | use ThreadedSocketService; 6 | 7 | impl ThreadedSocketService { 8 | pub fn new(max_threads: Option) -> ThreadedSocketService { 9 | let max_threads = max_threads.map(|x| x as i32).unwrap_or(-1); 10 | unsafe { 11 | SocketService::from_glib_full(gio_sys::g_threaded_socket_service_new(max_threads)) 12 | .unsafe_cast() 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/tls_connection.rs: -------------------------------------------------------------------------------- 1 | #[cfg(any(feature = "v2_66", feature = "dox"))] 2 | use auto::TlsChannelBindingType; 3 | use auto::TlsConnection; 4 | #[cfg(any(feature = "v2_66", feature = "dox"))] 5 | use glib::translate::*; 6 | use glib::IsA; 7 | #[cfg(any(feature = "v2_66", feature = "dox"))] 8 | use std::ptr; 9 | 10 | pub trait TlsConnectionManualExt { 11 | #[cfg(any(feature = "v2_66", feature = "dox"))] 12 | fn get_channel_binding_data( 13 | &self, 14 | type_: TlsChannelBindingType, 15 | ) -> Result; 16 | } 17 | 18 | impl> TlsConnectionManualExt for O { 19 | #[cfg(any(feature = "v2_66", feature = "dox"))] 20 | fn get_channel_binding_data( 21 | &self, 22 | type_: TlsChannelBindingType, 23 | ) -> Result { 24 | unsafe { 25 | let data = ptr::null_mut(); 26 | let mut error = ptr::null_mut(); 27 | let _ = gio_sys::g_tls_connection_get_channel_binding_data( 28 | self.as_ptr() as *mut _, 29 | type_.to_glib(), 30 | data, 31 | &mut error, 32 | ); 33 | if error.is_null() { 34 | Ok(from_glib_none(data)) 35 | } else { 36 | Err(from_glib_full(error)) 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/unix_fd_list.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use glib::object::IsA; 6 | use glib::translate::*; 7 | use std::{mem, ptr}; 8 | use UnixFDList; 9 | 10 | #[cfg(unix)] 11 | use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; 12 | 13 | #[cfg(all(not(unix), feature = "dox"))] 14 | use socket::{AsRawFd, IntoRawFd, RawFd}; 15 | 16 | impl UnixFDList { 17 | pub fn from_array(fds: T) -> UnixFDList 18 | where 19 | T: IntoIterator, 20 | T::Item: IntoRawFd, 21 | { 22 | let fds = fds.into_iter().map(|t| t.into_raw_fd()).collect::>(); 23 | unsafe { 24 | from_glib_full(gio_sys::g_unix_fd_list_new_from_array( 25 | fds.to_glib_none().0, 26 | fds.len() as i32, 27 | )) 28 | } 29 | } 30 | } 31 | 32 | pub trait UnixFDListExtManual: Sized { 33 | fn append(&self, fd: T) -> Result; 34 | 35 | fn get(&self, index_: i32) -> Result; 36 | 37 | fn peek_fds(&self) -> Vec; 38 | 39 | fn steal_fds(&self) -> Vec; 40 | } 41 | 42 | impl> UnixFDListExtManual for O { 43 | fn append(&self, fd: T) -> Result { 44 | unsafe { 45 | let mut error = ptr::null_mut(); 46 | let ret = gio_sys::g_unix_fd_list_append( 47 | self.as_ref().to_glib_none().0, 48 | fd.as_raw_fd(), 49 | &mut error, 50 | ); 51 | if error.is_null() { 52 | Ok(ret) 53 | } else { 54 | Err(from_glib_full(error)) 55 | } 56 | } 57 | } 58 | 59 | fn get(&self, index_: i32) -> Result { 60 | unsafe { 61 | let mut error = ptr::null_mut(); 62 | let ret = 63 | gio_sys::g_unix_fd_list_get(self.as_ref().to_glib_none().0, index_, &mut error); 64 | if error.is_null() { 65 | Ok(ret) 66 | } else { 67 | Err(from_glib_full(error)) 68 | } 69 | } 70 | } 71 | 72 | fn peek_fds(&self) -> Vec { 73 | unsafe { 74 | let mut length = mem::MaybeUninit::uninit(); 75 | let ret = FromGlibContainer::from_glib_none_num( 76 | gio_sys::g_unix_fd_list_peek_fds( 77 | self.as_ref().to_glib_none().0, 78 | length.as_mut_ptr(), 79 | ), 80 | length.assume_init() as usize, 81 | ); 82 | ret 83 | } 84 | } 85 | 86 | fn steal_fds(&self) -> Vec { 87 | unsafe { 88 | let mut length = mem::MaybeUninit::uninit(); 89 | let ret = FromGlibContainer::from_glib_full_num( 90 | gio_sys::g_unix_fd_list_steal_fds( 91 | self.as_ref().to_glib_none().0, 92 | length.as_mut_ptr(), 93 | ), 94 | length.assume_init() as usize, 95 | ); 96 | ret 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/unix_input_stream.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use glib::object::{Cast, IsA}; 6 | use glib::translate::*; 7 | use InputStream; 8 | use UnixInputStream; 9 | 10 | #[cfg(unix)] 11 | use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; 12 | 13 | #[cfg(all(not(unix), feature = "dox"))] 14 | use socket::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; 15 | 16 | impl UnixInputStream { 17 | pub unsafe fn new(fd: T) -> UnixInputStream { 18 | let fd = fd.into_raw_fd(); 19 | let close_fd = true.to_glib(); 20 | InputStream::from_glib_full(gio_sys::g_unix_input_stream_new(fd, close_fd)).unsafe_cast() 21 | } 22 | } 23 | 24 | impl AsRawFd for UnixInputStream { 25 | fn as_raw_fd(&self) -> RawFd { 26 | unsafe { gio_sys::g_unix_input_stream_get_fd(self.to_glib_none().0) as _ } 27 | } 28 | } 29 | 30 | pub trait UnixInputStreamExtManual: Sized { 31 | fn get_fd(&self) -> T; 32 | unsafe fn set_close_fd(&self, close_fd: bool); 33 | } 34 | 35 | impl> UnixInputStreamExtManual for O { 36 | fn get_fd(&self) -> T { 37 | unsafe { 38 | T::from_raw_fd(gio_sys::g_unix_input_stream_get_fd( 39 | self.as_ref().to_glib_none().0, 40 | )) 41 | } 42 | } 43 | 44 | unsafe fn set_close_fd(&self, close_fd: bool) { 45 | gio_sys::g_unix_input_stream_set_close_fd( 46 | self.as_ref().to_glib_none().0, 47 | close_fd.to_glib(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/unix_mount_point.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2019, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use glib::translate::*; 6 | use std::mem; 7 | use UnixMountPoint; 8 | 9 | impl UnixMountPoint { 10 | #[cfg(any(unix, feature = "dox"))] 11 | pub fn get_mount_points() -> (Vec, u64) { 12 | unsafe { 13 | let mut time_read = mem::MaybeUninit::uninit(); 14 | let ret = FromGlibPtrContainer::from_glib_full(gio_sys::g_unix_mount_points_get( 15 | time_read.as_mut_ptr(), 16 | )); 17 | let time_read = time_read.assume_init(); 18 | (ret, time_read) 19 | } 20 | } 21 | 22 | pub fn is_changed_since(time: u64) -> bool { 23 | unsafe { from_glib(gio_sys::g_unix_mount_points_changed_since(time)) } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/unix_output_stream.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use glib::object::{Cast, IsA}; 6 | use glib::translate::*; 7 | use OutputStream; 8 | use UnixOutputStream; 9 | 10 | #[cfg(unix)] 11 | use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; 12 | 13 | #[cfg(all(not(unix), feature = "dox"))] 14 | use socket::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; 15 | 16 | impl UnixOutputStream { 17 | pub unsafe fn new(fd: T) -> UnixOutputStream { 18 | let fd = fd.into_raw_fd(); 19 | let close_fd = true.to_glib(); 20 | OutputStream::from_glib_full(gio_sys::g_unix_output_stream_new(fd, close_fd)).unsafe_cast() 21 | } 22 | } 23 | 24 | impl AsRawFd for UnixOutputStream { 25 | fn as_raw_fd(&self) -> RawFd { 26 | unsafe { gio_sys::g_unix_output_stream_get_fd(self.to_glib_none().0) as _ } 27 | } 28 | } 29 | 30 | pub trait UnixOutputStreamExtManual: Sized { 31 | fn get_fd(&self) -> T; 32 | unsafe fn set_close_fd(&self, close_fd: bool); 33 | } 34 | 35 | impl> UnixOutputStreamExtManual for O { 36 | fn get_fd(&self) -> T { 37 | unsafe { 38 | T::from_raw_fd(gio_sys::g_unix_output_stream_get_fd( 39 | self.as_ref().to_glib_none().0, 40 | )) 41 | } 42 | } 43 | 44 | unsafe fn set_close_fd(&self, close_fd: bool) { 45 | gio_sys::g_unix_output_stream_set_close_fd( 46 | self.as_ref().to_glib_none().0, 47 | close_fd.to_glib(), 48 | ); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/unix_socket_address.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | use gio_sys; 6 | use glib::object::{Cast, IsA}; 7 | use glib::translate::*; 8 | use libc; 9 | use std::ffi::OsStr; 10 | #[cfg(unix)] 11 | use std::os::unix::ffi::OsStrExt; 12 | use std::path; 13 | use std::ptr; 14 | use std::slice; 15 | use SocketAddress; 16 | use UnixSocketAddress; 17 | use UnixSocketAddressExt; 18 | use UnixSocketAddressType; 19 | 20 | #[derive(Debug)] 21 | pub enum UnixSocketAddressPath<'a> { 22 | Path(&'a path::Path), 23 | Anonymous, 24 | Abstract(&'a [u8]), 25 | AbstractPadded(&'a [u8]), 26 | } 27 | 28 | impl<'a> UnixSocketAddressPath<'a> { 29 | fn to_type(&self) -> UnixSocketAddressType { 30 | use self::UnixSocketAddressPath::*; 31 | 32 | match *self { 33 | Path(_) => UnixSocketAddressType::Path, 34 | Anonymous => UnixSocketAddressType::Anonymous, 35 | Abstract(_) => UnixSocketAddressType::Abstract, 36 | AbstractPadded(_) => UnixSocketAddressType::AbstractPadded, 37 | } 38 | } 39 | } 40 | 41 | impl UnixSocketAddress { 42 | pub fn new(path: &path::Path) -> UnixSocketAddress { 43 | unsafe { 44 | SocketAddress::from_glib_full(gio_sys::g_unix_socket_address_new(path.to_glib_none().0)) 45 | .unsafe_cast() 46 | } 47 | } 48 | 49 | pub fn with_type(address_type: UnixSocketAddressPath) -> Self { 50 | use self::UnixSocketAddressPath::*; 51 | 52 | let type_ = address_type.to_type(); 53 | let (path, len) = match address_type { 54 | Path(path) => (path.to_glib_none().0, path.as_os_str().len()), 55 | Abstract(path) | AbstractPadded(path) => { 56 | (path.to_glib_none().0 as *mut libc::c_char, path.len()) 57 | } 58 | Anonymous => (ptr::null_mut(), 0), 59 | }; 60 | unsafe { 61 | SocketAddress::from_glib_full(gio_sys::g_unix_socket_address_new_with_type( 62 | path, 63 | len as i32, 64 | type_.to_glib(), 65 | )) 66 | .unsafe_cast() 67 | } 68 | } 69 | } 70 | 71 | pub trait UnixSocketAddressExtManual { 72 | fn get_path(&self) -> Option; 73 | } 74 | 75 | impl> UnixSocketAddressExtManual for O { 76 | fn get_path(&self) -> Option { 77 | use self::UnixSocketAddressPath::*; 78 | 79 | let path = unsafe { 80 | let path = gio_sys::g_unix_socket_address_get_path(self.as_ref().to_glib_none().0); 81 | if path.is_null() { 82 | &[] 83 | } else { 84 | slice::from_raw_parts(path as *const u8, self.get_path_len()) 85 | } 86 | }; 87 | match self.get_address_type() { 88 | UnixSocketAddressType::Anonymous => Some(Anonymous), 89 | #[cfg(not(feature = "dox"))] 90 | UnixSocketAddressType::Path => Some(Path(path::Path::new(OsStr::from_bytes(path)))), 91 | #[cfg(feature = "dox")] 92 | UnixSocketAddressType::Path => unreachable!(), 93 | UnixSocketAddressType::Abstract => Some(Abstract(path)), 94 | UnixSocketAddressType::AbstractPadded => Some(AbstractPadded(path)), 95 | UnixSocketAddressType::Invalid | UnixSocketAddressType::__Unknown(_) => None, 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /tests/check_gir.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2013-2018, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | extern crate gir_format_check; 6 | 7 | #[test] 8 | fn check_gir_file() { 9 | let res = gir_format_check::check_gir_file("Gir.toml"); 10 | println!("{}", res.to_string()); 11 | assert_eq!(res.nb_errors, 0); 12 | } 13 | -------------------------------------------------------------------------------- /tests/com.github.gtk-rs.test.gschema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | "Good" 9 | 10 | 11 | 12 | true 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /tests/futures.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020, The Gtk-rs Project Developers. 2 | // See the COPYRIGHT file at the top-level directory of this distribution. 3 | // Licensed under the MIT license, see the LICENSE file or 4 | 5 | // This target is build with edition 2018 for testing futures API. 6 | // TODO: merge to the test module of the corresponding source files once the crate 7 | // has been ported to 2018. 8 | 9 | use futures::prelude::*; 10 | use gio::prelude::*; 11 | use gio::MemoryInputStream; 12 | use glib::Bytes; 13 | use std::error::Error; 14 | 15 | #[test] 16 | fn async_read() { 17 | async fn run() -> Result<(), Box> { 18 | let b = Bytes::from_owned(vec![1, 2, 3]); 19 | 20 | // Adapter is big enough to read everything in one read 21 | let mut read = MemoryInputStream::from_bytes(&b).into_async_buf_read(8); 22 | let mut buf = [0u8; 4]; 23 | assert_eq!(read.read(&mut buf).await?, 3); 24 | assert_eq!(buf, [1, 2, 3, 0]); 25 | assert_eq!(read.read(&mut buf).await?, 0); 26 | 27 | let mut read = MemoryInputStream::from_bytes(&b).into_async_buf_read(8); 28 | let mut buf = [0u8; 1]; 29 | assert_eq!(read.read(&mut buf).await?, 1); 30 | assert_eq!(buf, [1]); 31 | assert_eq!(read.read(&mut buf).await?, 1); 32 | assert_eq!(buf, [2]); 33 | assert_eq!(read.read(&mut buf).await?, 1); 34 | assert_eq!(buf, [3]); 35 | assert_eq!(read.read(&mut buf).await?, 0); 36 | 37 | // Adapter is NOT big enough to read everything in one read 38 | let mut read = MemoryInputStream::from_bytes(&b).into_async_buf_read(2); 39 | let mut buf = [0u8; 4]; 40 | assert_eq!(read.read(&mut buf).await?, 2); 41 | assert_eq!(buf, [1, 2, 0, 0]); 42 | assert_eq!(read.read(&mut buf).await?, 1); 43 | assert_eq!(buf[0], 3); 44 | assert_eq!(read.read(&mut buf).await?, 0); 45 | 46 | let mut read = MemoryInputStream::from_bytes(&b).into_async_buf_read(2); 47 | let mut buf = [0u8; 1]; 48 | assert_eq!(read.read(&mut buf).await?, 1); 49 | assert_eq!(buf, [1]); 50 | assert_eq!(read.read(&mut buf).await?, 1); 51 | assert_eq!(buf, [2]); 52 | assert_eq!(read.read(&mut buf).await?, 1); 53 | assert_eq!(buf, [3]); 54 | assert_eq!(read.read(&mut buf).await?, 0); 55 | 56 | Ok(()) 57 | } 58 | 59 | let main_context = glib::MainContext::new(); 60 | main_context.block_on(run()).unwrap(); 61 | } 62 | 63 | #[test] 64 | fn async_buf_read() { 65 | async fn run() -> Result<(), Box> { 66 | let b = Bytes::from_owned(vec![1, 2, 3]); 67 | // Adapter is big enough to read everything in one read 68 | let mut read = MemoryInputStream::from_bytes(&b).into_async_buf_read(16); 69 | let mut buf = String::new(); 70 | assert_eq!(read.read_line(&mut buf).await?, 3); 71 | assert_eq!(buf.as_bytes(), [1, 2, 3]); 72 | assert_eq!(read.read_line(&mut buf).await?, 0); 73 | 74 | // Adapter is NOT big enough to read everything in one read 75 | let mut read = MemoryInputStream::from_bytes(&b).into_async_buf_read(2); 76 | let mut buf = String::new(); 77 | assert_eq!(read.read_line(&mut buf).await?, 3); 78 | assert_eq!(buf.as_bytes(), [1, 2, 3]); 79 | assert_eq!(read.read_line(&mut buf).await?, 0); 80 | 81 | Ok(()) 82 | } 83 | 84 | let main_context = glib::MainContext::new(); 85 | main_context.block_on(run()).unwrap(); 86 | } 87 | -------------------------------------------------------------------------------- /tests/std_io_copy.rs: -------------------------------------------------------------------------------- 1 | #![cfg(feature = "v2_36")] 2 | 3 | extern crate gio; 4 | extern crate glib; 5 | 6 | use gio::prelude::*; 7 | use std::io; 8 | 9 | #[test] 10 | #[cfg(feature = "v2_36")] 11 | fn std_io_copy_with_gio() { 12 | let bytes = glib::Bytes::from_owned([1, 2, 3]); 13 | let mut read = gio::MemoryInputStream::new_from_bytes(&bytes).into_read(); 14 | let mut write = gio::MemoryOutputStream::new_resizable().into_write(); 15 | 16 | let result = io::copy(&mut read, &mut write); 17 | 18 | let out_stream = write.into_output_stream(); 19 | out_stream.close(gio::NONE_CANCELLABLE).unwrap(); 20 | assert_eq!(result.unwrap(), 3); 21 | assert_eq!(out_stream.steal_as_bytes().unwrap(), bytes); 22 | } 23 | --------------------------------------------------------------------------------