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
// Copyright 2013-2015, The Rust-GNOME Project Developers.
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

//! GPermission — An object representing the permission to perform a certain action

use glib_container::GlibContainer;
use ffi;

pub struct Permission {
    pointer: *mut ffi::GPermission
}

impl Permission {
    /// Gets the value of the 'allowed' property. This property is true if the caller
    /// currently has permission to perform the action that permission represents the
    /// permission to perform.
    pub fn get_allowed(&self) -> bool {
        match unsafe { ffi::g_permission_get_allowed(self.pointer) } {
            0 => false,
            _ => true
        }
    }

    /// Gets the value of the 'can-acquire' property. This property is true if it is
    /// generally possible to acquire the permission by calling g_permission_acquire().
    pub fn get_can_acquire(&self) -> bool {
        match unsafe { ffi::g_permission_get_can_acquire(self.pointer) } {
            0 => false,
            _ => true
        }
    }

    /// Gets the value of the 'can-release' property. This property is true if it is
    /// generally possible to release the permission by calling g_permission_release().
    pub fn get_can_release(&self) -> bool {
        match unsafe { ffi::g_permission_get_can_release(self.pointer) } {
            0 => false,
            _ => true
        }
    }

    /// This function is called by the GPermission implementation to update the properties
    /// of the permission. You should never call this function except from a GPermission
    /// implementation.
    /// 
    /// GObject notify signals are generated, as appropriate.
    pub fn impl_update(&self, allowed: bool, can_acquire: bool, can_release: bool) {
        unsafe { ffi::g_permission_impl_update(self.pointer,
            if allowed == true { 1 } else { 0 },
            if can_acquire == true { 1 } else { 0 },
            if can_release == true { 1 } else { 0 }) }
    }
}

/*impl Drop for Permission {
    fn drop(&mut self) {
        self.release();
    }
}*/

impl GlibContainer<*mut ffi::GPermission> for Permission {
    fn wrap(pointer: *mut ffi::GPermission) -> Permission {
        Permission {
            pointer: pointer
        }
    }

    fn unwrap(&self) -> *mut ffi::GPermission {
        self.pointer
    }
}