1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// Determines if a string matches a file attribute.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct FileAttributeMatcher(Shared<ffi::GFileAttributeMatcher>);

    match fn {
        ref => |ptr| ffi::g_file_attribute_matcher_ref(ptr),
        unref => |ptr| ffi::g_file_attribute_matcher_unref(ptr),
        type_ => || ffi::g_file_attribute_matcher_get_type(),
    }
}

impl FileAttributeMatcher {
    /// Creates a new file attribute matcher, which matches attributes
    /// against a given string. `GFileAttributeMatchers` are reference
    /// counted structures, and are created with a reference count of 1. If
    /// the number of references falls to 0, the [`FileAttributeMatcher`][crate::FileAttributeMatcher] is
    /// automatically destroyed.
    ///
    /// The `attributes` string should be formatted with specific keys separated
    /// from namespaces with a double colon. Several "namespace::key" strings may be
    /// concatenated with a single comma (e.g. "standard::type,standard::is-hidden").
    /// The wildcard "*" may be used to match all keys and namespaces, or
    /// "namespace::*" will match all keys in a given namespace.
    ///
    /// ## Examples of file attribute matcher strings and results
    ///
    /// - `"*"`: matches all attributes.
    /// - `"standard::is-hidden"`: matches only the key is-hidden in the
    ///  standard namespace.
    /// - `"standard::type,unix::*"`: matches the type key in the standard
    ///  namespace and all keys in the unix namespace.
    /// ## `attributes`
    /// an attribute string to match.
    ///
    /// # Returns
    ///
    /// a [`FileAttributeMatcher`][crate::FileAttributeMatcher]
    #[doc(alias = "g_file_attribute_matcher_new")]
    pub fn new(attributes: &str) -> FileAttributeMatcher {
        unsafe {
            from_glib_full(ffi::g_file_attribute_matcher_new(
                attributes.to_glib_none().0,
            ))
        }
    }

    /// Checks if the matcher will match all of the keys in a given namespace.
    /// This will always return [`true`] if a wildcard character is in use (e.g. if
    /// matcher was created with "standard::*" and `ns` is "standard", or if matcher was created
    /// using "*" and namespace is anything.)
    ///
    /// TODO: this is awkwardly worded.
    /// ## `ns`
    /// a string containing a file attribute namespace.
    ///
    /// # Returns
    ///
    /// [`true`] if the matcher matches all of the entries
    /// in the given `ns`, [`false`] otherwise.
    #[doc(alias = "g_file_attribute_matcher_enumerate_namespace")]
    pub fn enumerate_namespace(&self, ns: &str) -> bool {
        unsafe {
            from_glib(ffi::g_file_attribute_matcher_enumerate_namespace(
                self.to_glib_none().0,
                ns.to_glib_none().0,
            ))
        }
    }

    /// Checks if an attribute will be matched by an attribute matcher. If
    /// the matcher was created with the "*" matching string, this function
    /// will always return [`true`].
    /// ## `attribute`
    /// a file attribute key.
    ///
    /// # Returns
    ///
    /// [`true`] if `attribute` matches `self`. [`false`] otherwise.
    #[doc(alias = "g_file_attribute_matcher_matches")]
    pub fn matches(&self, attribute: &str) -> bool {
        unsafe {
            from_glib(ffi::g_file_attribute_matcher_matches(
                self.to_glib_none().0,
                attribute.to_glib_none().0,
            ))
        }
    }

    /// Checks if a attribute matcher only matches a given attribute. Always
    /// returns [`false`] if "*" was used when creating the matcher.
    /// ## `attribute`
    /// a file attribute key.
    ///
    /// # Returns
    ///
    /// [`true`] if the matcher only matches `attribute`. [`false`] otherwise.
    #[doc(alias = "g_file_attribute_matcher_matches_only")]
    pub fn matches_only(&self, attribute: &str) -> bool {
        unsafe {
            from_glib(ffi::g_file_attribute_matcher_matches_only(
                self.to_glib_none().0,
                attribute.to_glib_none().0,
            ))
        }
    }

    /// Subtracts all attributes of `subtract` from `self` and returns
    /// a matcher that supports those attributes.
    ///
    /// Note that currently it is not possible to remove a single
    /// attribute when the `self` matches the whole namespace - or remove
    /// a namespace or attribute when the matcher matches everything. This
    /// is a limitation of the current implementation, but may be fixed
    /// in the future.
    /// ## `subtract`
    /// The matcher to subtract
    ///
    /// # Returns
    ///
    /// A file attribute matcher matching all attributes of
    ///  `self` that are not matched by `subtract`
    #[doc(alias = "g_file_attribute_matcher_subtract")]
    pub fn subtract(
        &self,
        subtract: Option<&FileAttributeMatcher>,
    ) -> Option<FileAttributeMatcher> {
        unsafe {
            from_glib_full(ffi::g_file_attribute_matcher_subtract(
                self.to_glib_none().0,
                subtract.to_glib_none().0,
            ))
        }
    }

    #[doc(alias = "g_file_attribute_matcher_to_string")]
    #[doc(alias = "to_string")]
    pub fn to_str(&self) -> glib::GString {
        unsafe {
            from_glib_full(ffi::g_file_attribute_matcher_to_string(
                self.to_glib_none().0,
            ))
        }
    }
}

impl fmt::Display for FileAttributeMatcher {
    #[inline]
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str(&self.to_str())
    }
}