libayatana_appindicator/
lib.rs

1extern crate glib;
2extern crate gtk;
3extern crate gtk_sys;
4#[cfg(feature = "dynamic")]
5extern crate libayatana_appindicator_sys;
6
7use gtk::glib::translate::ToGlibPtr;
8#[cfg(feature = "dynamic")]
9use libayatana_appindicator_sys::AppIndicator as AppIndicatorRaw;
10#[cfg(feature = "dynamic")]
11pub use libayatana_appindicator_sys::*;
12
13#[cfg(not(feature = "dynamic"))]
14mod bindings;
15#[cfg(not(feature = "dynamic"))]
16use crate::bindings::AppIndicator as AppIndicatorRaw;
17#[cfg(not(feature = "dynamic"))]
18pub use crate::bindings::*;
19
20pub struct AppIndicator {
21    air: *mut AppIndicatorRaw,
22}
23pub enum AppIndicatorCategory {
24    ApplicationStatus = 0,
25    Communications = 1,
26    SystemServices = 2,
27    Hardware = 3,
28    Other = 4,
29}
30pub enum AppIndicatorStatus {
31    Passive = 0,
32    Active = 1,
33    Attention = 2,
34}
35impl AppIndicator {
36    pub fn new(title: &str, icon: &str) -> AppIndicator {
37        AppIndicator {
38            air: unsafe {
39                app_indicator_new(
40                    title.to_glib_none().0,
41                    icon.to_glib_none().0,
42                    AppIndicatorCategory::ApplicationStatus as u32,
43                )
44            },
45        }
46    }
47
48    pub fn with_path(
49        title: &str,
50        icon: &str,
51        theme_path: &str,
52    ) -> AppIndicator {
53        AppIndicator {
54            air: unsafe {
55                app_indicator_new_with_path(
56                    title.to_glib_none().0,
57                    icon.to_glib_none().0,
58                    AppIndicatorCategory::ApplicationStatus as u32,
59                    theme_path.to_glib_none().0,
60                )
61            },
62        }
63    }
64
65    pub fn set_status(&mut self, status: AppIndicatorStatus) {
66        unsafe {
67            app_indicator_set_status(self.air, status as u32);
68        }
69    }
70
71    pub fn set_menu(&mut self, menu: &mut gtk::Menu) {
72        unsafe {
73            app_indicator_set_menu(self.air, menu.to_glib_none().0);
74        }
75    }
76
77    pub fn set_label(&mut self, label: &str, guide: &str) {
78        unsafe {
79            app_indicator_set_label(
80                self.air,
81                label.to_glib_none().0,
82                guide.to_glib_none().0,
83            );
84        }
85    }
86
87    pub fn set_title(&mut self, title: &str) {
88        unsafe {
89            app_indicator_set_title(self.air, title.to_glib_none().0);
90        }
91    }
92
93    pub fn set_icon(&mut self, name: &str) {
94        unsafe {
95            app_indicator_set_icon(self.air, name.to_glib_none().0);
96        }
97    }
98    pub fn set_icon_theme_path(&mut self, path: &str) {
99        unsafe {
100            app_indicator_set_icon_theme_path(self.air, path.to_glib_none().0);
101        }
102    }
103
104    pub fn set_icon_full(&mut self, name: &str, desc: &str) {
105        unsafe {
106            app_indicator_set_icon_full(
107                self.air,
108                name.to_glib_none().0,
109                desc.to_glib_none().0,
110            );
111        }
112    }
113
114    pub fn set_attention_icon(&mut self, name: &str) {
115        unsafe {
116            app_indicator_set_attention_icon(self.air, name.to_glib_none().0);
117        }
118    }
119
120    pub fn set_attention_icon_full(&mut self, name: &str, desc: &str) {
121        unsafe {
122            app_indicator_set_attention_icon_full(
123                self.air,
124                name.to_glib_none().0,
125                desc.to_glib_none().0,
126            );
127        }
128    }
129}
130
131#[cfg(test)]
132mod tests {
133    #[test]
134    fn it_works() {}
135}