libayatana_appindicator/
lib.rs

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
extern crate glib;
extern crate gtk;
extern crate gtk_sys;
#[cfg(feature = "dynamic")]
extern crate libayatana_appindicator_sys;

use gtk::glib::translate::ToGlibPtr;
#[cfg(feature = "dynamic")]
use libayatana_appindicator_sys::AppIndicator as AppIndicatorRaw;
#[cfg(feature = "dynamic")]
pub use libayatana_appindicator_sys::*;

#[cfg(not(feature = "dynamic"))]
mod bindings;
#[cfg(not(feature = "dynamic"))]
use crate::bindings::AppIndicator as AppIndicatorRaw;
#[cfg(not(feature = "dynamic"))]
pub use crate::bindings::*;

pub struct AppIndicator {
    air: *mut AppIndicatorRaw,
}
pub enum AppIndicatorCategory {
    ApplicationStatus = 0,
    Communications = 1,
    SystemServices = 2,
    Hardware = 3,
    Other = 4,
}
pub enum AppIndicatorStatus {
    Passive = 0,
    Active = 1,
    Attention = 2,
}
impl AppIndicator {
    pub fn new(title: &str, icon: &str) -> AppIndicator {
        AppIndicator {
            air: unsafe {
                app_indicator_new(
                    title.to_glib_none().0,
                    icon.to_glib_none().0,
                    AppIndicatorCategory::ApplicationStatus as u32,
                )
            },
        }
    }

    pub fn with_path(
        title: &str,
        icon: &str,
        theme_path: &str,
    ) -> AppIndicator {
        AppIndicator {
            air: unsafe {
                app_indicator_new_with_path(
                    title.to_glib_none().0,
                    icon.to_glib_none().0,
                    AppIndicatorCategory::ApplicationStatus as u32,
                    theme_path.to_glib_none().0,
                )
            },
        }
    }

    pub fn set_status(&mut self, status: AppIndicatorStatus) {
        unsafe {
            app_indicator_set_status(self.air, status as u32);
        }
    }

    pub fn set_menu(&mut self, menu: &mut gtk::Menu) {
        unsafe {
            app_indicator_set_menu(self.air, menu.to_glib_none().0);
        }
    }

    pub fn set_label(&mut self, label: &str, guide: &str) {
        unsafe {
            app_indicator_set_label(
                self.air,
                label.to_glib_none().0,
                guide.to_glib_none().0,
            );
        }
    }

    pub fn set_title(&mut self, title: &str) {
        unsafe {
            app_indicator_set_title(self.air, title.to_glib_none().0);
        }
    }

    pub fn set_icon(&mut self, name: &str) {
        unsafe {
            app_indicator_set_icon(self.air, name.to_glib_none().0);
        }
    }
    pub fn set_icon_theme_path(&mut self, path: &str) {
        unsafe {
            app_indicator_set_icon_theme_path(self.air, path.to_glib_none().0);
        }
    }

    pub fn set_icon_full(&mut self, name: &str, desc: &str) {
        unsafe {
            app_indicator_set_icon_full(
                self.air,
                name.to_glib_none().0,
                desc.to_glib_none().0,
            );
        }
    }

    pub fn set_attention_icon(&mut self, name: &str) {
        unsafe {
            app_indicator_set_attention_icon(self.air, name.to_glib_none().0);
        }
    }

    pub fn set_attention_icon_full(&mut self, name: &str, desc: &str) {
        unsafe {
            app_indicator_set_attention_icon_full(
                self.air,
                name.to_glib_none().0,
                desc.to_glib_none().0,
            );
        }
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {}
}