1use glib::object::Cast;
6use glib::object::IsA;
7use glib::signal::connect_raw;
8use glib::signal::SignalHandlerId;
9use glib::translate::*;
10use glib::GString;
11use glib_sys;
12use gtk_sys;
13use std::boxed::Box as Box_;
14use std::fmt;
15use std::mem;
16use std::mem::transmute;
17use std::ptr;
18use Error;
19use RecentFilter;
20use RecentInfo;
21use RecentSortType;
22
23glib_wrapper! {
24 pub struct RecentChooser(Interface<gtk_sys::GtkRecentChooser>);
25
26 match fn {
27 get_type => || gtk_sys::gtk_recent_chooser_get_type(),
28 }
29}
30
31pub const NONE_RECENT_CHOOSER: Option<&RecentChooser> = None;
32
33pub trait RecentChooserExt: 'static {
34 fn add_filter(&self, filter: &RecentFilter);
35
36 fn get_current_item(&self) -> Option<RecentInfo>;
37
38 fn get_current_uri(&self) -> Option<GString>;
39
40 fn get_filter(&self) -> Option<RecentFilter>;
41
42 fn get_items(&self) -> Vec<RecentInfo>;
43
44 fn get_limit(&self) -> i32;
45
46 fn get_local_only(&self) -> bool;
47
48 fn get_select_multiple(&self) -> bool;
49
50 fn get_show_icons(&self) -> bool;
51
52 fn get_show_not_found(&self) -> bool;
53
54 fn get_show_private(&self) -> bool;
55
56 fn get_show_tips(&self) -> bool;
57
58 fn get_sort_type(&self) -> RecentSortType;
59
60 fn get_uris(&self) -> Vec<GString>;
61
62 fn list_filters(&self) -> Vec<RecentFilter>;
63
64 fn remove_filter(&self, filter: &RecentFilter);
65
66 fn select_all(&self);
67
68 fn select_uri(&self, uri: &str) -> Result<(), Error>;
69
70 fn set_current_uri(&self, uri: &str) -> Result<(), Error>;
71
72 fn set_filter(&self, filter: Option<&RecentFilter>);
73
74 fn set_limit(&self, limit: i32);
75
76 fn set_local_only(&self, local_only: bool);
77
78 fn set_select_multiple(&self, select_multiple: bool);
79
80 fn set_show_icons(&self, show_icons: bool);
81
82 fn set_show_not_found(&self, show_not_found: bool);
83
84 fn set_show_private(&self, show_private: bool);
85
86 fn set_show_tips(&self, show_tips: bool);
87
88 fn set_sort_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(&self, sort_func: P);
89
90 fn set_sort_type(&self, sort_type: RecentSortType);
91
92 fn unselect_all(&self);
93
94 fn unselect_uri(&self, uri: &str);
95
96 fn connect_item_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
97
98 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
99
100 fn connect_property_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
101
102 fn connect_property_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
103
104 fn connect_property_local_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
105
106 fn connect_property_select_multiple_notify<F: Fn(&Self) + 'static>(
107 &self,
108 f: F,
109 ) -> SignalHandlerId;
110
111 fn connect_property_show_icons_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
112
113 fn connect_property_show_not_found_notify<F: Fn(&Self) + 'static>(
114 &self,
115 f: F,
116 ) -> SignalHandlerId;
117
118 fn connect_property_show_private_notify<F: Fn(&Self) + 'static>(&self, f: F)
119 -> SignalHandlerId;
120
121 fn connect_property_show_tips_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
122
123 fn connect_property_sort_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
124}
125
126impl<O: IsA<RecentChooser>> RecentChooserExt for O {
127 fn add_filter(&self, filter: &RecentFilter) {
128 unsafe {
129 gtk_sys::gtk_recent_chooser_add_filter(
130 self.as_ref().to_glib_none().0,
131 filter.to_glib_none().0,
132 );
133 }
134 }
135
136 fn get_current_item(&self) -> Option<RecentInfo> {
137 unsafe {
138 from_glib_full(gtk_sys::gtk_recent_chooser_get_current_item(
139 self.as_ref().to_glib_none().0,
140 ))
141 }
142 }
143
144 fn get_current_uri(&self) -> Option<GString> {
145 unsafe {
146 from_glib_full(gtk_sys::gtk_recent_chooser_get_current_uri(
147 self.as_ref().to_glib_none().0,
148 ))
149 }
150 }
151
152 fn get_filter(&self) -> Option<RecentFilter> {
153 unsafe {
154 from_glib_none(gtk_sys::gtk_recent_chooser_get_filter(
155 self.as_ref().to_glib_none().0,
156 ))
157 }
158 }
159
160 fn get_items(&self) -> Vec<RecentInfo> {
161 unsafe {
162 FromGlibPtrContainer::from_glib_full(gtk_sys::gtk_recent_chooser_get_items(
163 self.as_ref().to_glib_none().0,
164 ))
165 }
166 }
167
168 fn get_limit(&self) -> i32 {
169 unsafe { gtk_sys::gtk_recent_chooser_get_limit(self.as_ref().to_glib_none().0) }
170 }
171
172 fn get_local_only(&self) -> bool {
173 unsafe {
174 from_glib(gtk_sys::gtk_recent_chooser_get_local_only(
175 self.as_ref().to_glib_none().0,
176 ))
177 }
178 }
179
180 fn get_select_multiple(&self) -> bool {
181 unsafe {
182 from_glib(gtk_sys::gtk_recent_chooser_get_select_multiple(
183 self.as_ref().to_glib_none().0,
184 ))
185 }
186 }
187
188 fn get_show_icons(&self) -> bool {
189 unsafe {
190 from_glib(gtk_sys::gtk_recent_chooser_get_show_icons(
191 self.as_ref().to_glib_none().0,
192 ))
193 }
194 }
195
196 fn get_show_not_found(&self) -> bool {
197 unsafe {
198 from_glib(gtk_sys::gtk_recent_chooser_get_show_not_found(
199 self.as_ref().to_glib_none().0,
200 ))
201 }
202 }
203
204 fn get_show_private(&self) -> bool {
205 unsafe {
206 from_glib(gtk_sys::gtk_recent_chooser_get_show_private(
207 self.as_ref().to_glib_none().0,
208 ))
209 }
210 }
211
212 fn get_show_tips(&self) -> bool {
213 unsafe {
214 from_glib(gtk_sys::gtk_recent_chooser_get_show_tips(
215 self.as_ref().to_glib_none().0,
216 ))
217 }
218 }
219
220 fn get_sort_type(&self) -> RecentSortType {
221 unsafe {
222 from_glib(gtk_sys::gtk_recent_chooser_get_sort_type(
223 self.as_ref().to_glib_none().0,
224 ))
225 }
226 }
227
228 fn get_uris(&self) -> Vec<GString> {
229 unsafe {
230 let mut length = mem::uninitialized();
231 let ret = FromGlibContainer::from_glib_full_num(
232 gtk_sys::gtk_recent_chooser_get_uris(self.as_ref().to_glib_none().0, &mut length),
233 length as usize,
234 );
235 ret
236 }
237 }
238
239 fn list_filters(&self) -> Vec<RecentFilter> {
240 unsafe {
241 FromGlibPtrContainer::from_glib_container(gtk_sys::gtk_recent_chooser_list_filters(
242 self.as_ref().to_glib_none().0,
243 ))
244 }
245 }
246
247 fn remove_filter(&self, filter: &RecentFilter) {
248 unsafe {
249 gtk_sys::gtk_recent_chooser_remove_filter(
250 self.as_ref().to_glib_none().0,
251 filter.to_glib_none().0,
252 );
253 }
254 }
255
256 fn select_all(&self) {
257 unsafe {
258 gtk_sys::gtk_recent_chooser_select_all(self.as_ref().to_glib_none().0);
259 }
260 }
261
262 fn select_uri(&self, uri: &str) -> Result<(), Error> {
263 unsafe {
264 let mut error = ptr::null_mut();
265 let _ = gtk_sys::gtk_recent_chooser_select_uri(
266 self.as_ref().to_glib_none().0,
267 uri.to_glib_none().0,
268 &mut error,
269 );
270 if error.is_null() {
271 Ok(())
272 } else {
273 Err(from_glib_full(error))
274 }
275 }
276 }
277
278 fn set_current_uri(&self, uri: &str) -> Result<(), Error> {
279 unsafe {
280 let mut error = ptr::null_mut();
281 let _ = gtk_sys::gtk_recent_chooser_set_current_uri(
282 self.as_ref().to_glib_none().0,
283 uri.to_glib_none().0,
284 &mut error,
285 );
286 if error.is_null() {
287 Ok(())
288 } else {
289 Err(from_glib_full(error))
290 }
291 }
292 }
293
294 fn set_filter(&self, filter: Option<&RecentFilter>) {
295 unsafe {
296 gtk_sys::gtk_recent_chooser_set_filter(
297 self.as_ref().to_glib_none().0,
298 filter.to_glib_none().0,
299 );
300 }
301 }
302
303 fn set_limit(&self, limit: i32) {
304 unsafe {
305 gtk_sys::gtk_recent_chooser_set_limit(self.as_ref().to_glib_none().0, limit);
306 }
307 }
308
309 fn set_local_only(&self, local_only: bool) {
310 unsafe {
311 gtk_sys::gtk_recent_chooser_set_local_only(
312 self.as_ref().to_glib_none().0,
313 local_only.to_glib(),
314 );
315 }
316 }
317
318 fn set_select_multiple(&self, select_multiple: bool) {
319 unsafe {
320 gtk_sys::gtk_recent_chooser_set_select_multiple(
321 self.as_ref().to_glib_none().0,
322 select_multiple.to_glib(),
323 );
324 }
325 }
326
327 fn set_show_icons(&self, show_icons: bool) {
328 unsafe {
329 gtk_sys::gtk_recent_chooser_set_show_icons(
330 self.as_ref().to_glib_none().0,
331 show_icons.to_glib(),
332 );
333 }
334 }
335
336 fn set_show_not_found(&self, show_not_found: bool) {
337 unsafe {
338 gtk_sys::gtk_recent_chooser_set_show_not_found(
339 self.as_ref().to_glib_none().0,
340 show_not_found.to_glib(),
341 );
342 }
343 }
344
345 fn set_show_private(&self, show_private: bool) {
346 unsafe {
347 gtk_sys::gtk_recent_chooser_set_show_private(
348 self.as_ref().to_glib_none().0,
349 show_private.to_glib(),
350 );
351 }
352 }
353
354 fn set_show_tips(&self, show_tips: bool) {
355 unsafe {
356 gtk_sys::gtk_recent_chooser_set_show_tips(
357 self.as_ref().to_glib_none().0,
358 show_tips.to_glib(),
359 );
360 }
361 }
362
363 fn set_sort_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(&self, sort_func: P) {
364 let sort_func_data: Box_<P> = Box::new(sort_func);
365 unsafe extern "C" fn sort_func_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(
366 a: *mut gtk_sys::GtkRecentInfo,
367 b: *mut gtk_sys::GtkRecentInfo,
368 user_data: glib_sys::gpointer,
369 ) -> libc::c_int {
370 let a = from_glib_borrow(a);
371 let b = from_glib_borrow(b);
372 let callback: &P = &*(user_data as *mut _);
373 let res = (*callback)(&a, &b);
374 res
375 }
376 let sort_func = Some(sort_func_func::<P> as _);
377 unsafe extern "C" fn data_destroy_func<P: Fn(&RecentInfo, &RecentInfo) -> i32 + 'static>(
378 data: glib_sys::gpointer,
379 ) {
380 let _callback: Box_<P> = Box_::from_raw(data as *mut _);
381 }
382 let destroy_call3 = Some(data_destroy_func::<P> as _);
383 let super_callback0: Box_<P> = sort_func_data;
384 unsafe {
385 gtk_sys::gtk_recent_chooser_set_sort_func(
386 self.as_ref().to_glib_none().0,
387 sort_func,
388 Box::into_raw(super_callback0) as *mut _,
389 destroy_call3,
390 );
391 }
392 }
393
394 fn set_sort_type(&self, sort_type: RecentSortType) {
395 unsafe {
396 gtk_sys::gtk_recent_chooser_set_sort_type(
397 self.as_ref().to_glib_none().0,
398 sort_type.to_glib(),
399 );
400 }
401 }
402
403 fn unselect_all(&self) {
404 unsafe {
405 gtk_sys::gtk_recent_chooser_unselect_all(self.as_ref().to_glib_none().0);
406 }
407 }
408
409 fn unselect_uri(&self, uri: &str) {
410 unsafe {
411 gtk_sys::gtk_recent_chooser_unselect_uri(
412 self.as_ref().to_glib_none().0,
413 uri.to_glib_none().0,
414 );
415 }
416 }
417
418 fn connect_item_activated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
419 unsafe extern "C" fn item_activated_trampoline<P, F: Fn(&P) + 'static>(
420 this: *mut gtk_sys::GtkRecentChooser,
421 f: glib_sys::gpointer,
422 ) where
423 P: IsA<RecentChooser>,
424 {
425 let f: &F = &*(f as *const F);
426 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
427 }
428 unsafe {
429 let f: Box_<F> = Box_::new(f);
430 connect_raw(
431 self.as_ptr() as *mut _,
432 b"item-activated\0".as_ptr() as *const _,
433 Some(transmute(item_activated_trampoline::<Self, F> as usize)),
434 Box_::into_raw(f),
435 )
436 }
437 }
438
439 fn connect_selection_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
440 unsafe extern "C" fn selection_changed_trampoline<P, F: Fn(&P) + 'static>(
441 this: *mut gtk_sys::GtkRecentChooser,
442 f: glib_sys::gpointer,
443 ) where
444 P: IsA<RecentChooser>,
445 {
446 let f: &F = &*(f as *const F);
447 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
448 }
449 unsafe {
450 let f: Box_<F> = Box_::new(f);
451 connect_raw(
452 self.as_ptr() as *mut _,
453 b"selection-changed\0".as_ptr() as *const _,
454 Some(transmute(selection_changed_trampoline::<Self, F> as usize)),
455 Box_::into_raw(f),
456 )
457 }
458 }
459
460 fn connect_property_filter_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
461 unsafe extern "C" fn notify_filter_trampoline<P, F: Fn(&P) + 'static>(
462 this: *mut gtk_sys::GtkRecentChooser,
463 _param_spec: glib_sys::gpointer,
464 f: glib_sys::gpointer,
465 ) where
466 P: IsA<RecentChooser>,
467 {
468 let f: &F = &*(f as *const F);
469 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
470 }
471 unsafe {
472 let f: Box_<F> = Box_::new(f);
473 connect_raw(
474 self.as_ptr() as *mut _,
475 b"notify::filter\0".as_ptr() as *const _,
476 Some(transmute(notify_filter_trampoline::<Self, F> as usize)),
477 Box_::into_raw(f),
478 )
479 }
480 }
481
482 fn connect_property_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
483 unsafe extern "C" fn notify_limit_trampoline<P, F: Fn(&P) + 'static>(
484 this: *mut gtk_sys::GtkRecentChooser,
485 _param_spec: glib_sys::gpointer,
486 f: glib_sys::gpointer,
487 ) where
488 P: IsA<RecentChooser>,
489 {
490 let f: &F = &*(f as *const F);
491 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
492 }
493 unsafe {
494 let f: Box_<F> = Box_::new(f);
495 connect_raw(
496 self.as_ptr() as *mut _,
497 b"notify::limit\0".as_ptr() as *const _,
498 Some(transmute(notify_limit_trampoline::<Self, F> as usize)),
499 Box_::into_raw(f),
500 )
501 }
502 }
503
504 fn connect_property_local_only_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
505 unsafe extern "C" fn notify_local_only_trampoline<P, F: Fn(&P) + 'static>(
506 this: *mut gtk_sys::GtkRecentChooser,
507 _param_spec: glib_sys::gpointer,
508 f: glib_sys::gpointer,
509 ) where
510 P: IsA<RecentChooser>,
511 {
512 let f: &F = &*(f as *const F);
513 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
514 }
515 unsafe {
516 let f: Box_<F> = Box_::new(f);
517 connect_raw(
518 self.as_ptr() as *mut _,
519 b"notify::local-only\0".as_ptr() as *const _,
520 Some(transmute(notify_local_only_trampoline::<Self, F> as usize)),
521 Box_::into_raw(f),
522 )
523 }
524 }
525
526 fn connect_property_select_multiple_notify<F: Fn(&Self) + 'static>(
527 &self,
528 f: F,
529 ) -> SignalHandlerId {
530 unsafe extern "C" fn notify_select_multiple_trampoline<P, F: Fn(&P) + 'static>(
531 this: *mut gtk_sys::GtkRecentChooser,
532 _param_spec: glib_sys::gpointer,
533 f: glib_sys::gpointer,
534 ) where
535 P: IsA<RecentChooser>,
536 {
537 let f: &F = &*(f as *const F);
538 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
539 }
540 unsafe {
541 let f: Box_<F> = Box_::new(f);
542 connect_raw(
543 self.as_ptr() as *mut _,
544 b"notify::select-multiple\0".as_ptr() as *const _,
545 Some(transmute(
546 notify_select_multiple_trampoline::<Self, F> as usize,
547 )),
548 Box_::into_raw(f),
549 )
550 }
551 }
552
553 fn connect_property_show_icons_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
554 unsafe extern "C" fn notify_show_icons_trampoline<P, F: Fn(&P) + 'static>(
555 this: *mut gtk_sys::GtkRecentChooser,
556 _param_spec: glib_sys::gpointer,
557 f: glib_sys::gpointer,
558 ) where
559 P: IsA<RecentChooser>,
560 {
561 let f: &F = &*(f as *const F);
562 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
563 }
564 unsafe {
565 let f: Box_<F> = Box_::new(f);
566 connect_raw(
567 self.as_ptr() as *mut _,
568 b"notify::show-icons\0".as_ptr() as *const _,
569 Some(transmute(notify_show_icons_trampoline::<Self, F> as usize)),
570 Box_::into_raw(f),
571 )
572 }
573 }
574
575 fn connect_property_show_not_found_notify<F: Fn(&Self) + 'static>(
576 &self,
577 f: F,
578 ) -> SignalHandlerId {
579 unsafe extern "C" fn notify_show_not_found_trampoline<P, F: Fn(&P) + 'static>(
580 this: *mut gtk_sys::GtkRecentChooser,
581 _param_spec: glib_sys::gpointer,
582 f: glib_sys::gpointer,
583 ) where
584 P: IsA<RecentChooser>,
585 {
586 let f: &F = &*(f as *const F);
587 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
588 }
589 unsafe {
590 let f: Box_<F> = Box_::new(f);
591 connect_raw(
592 self.as_ptr() as *mut _,
593 b"notify::show-not-found\0".as_ptr() as *const _,
594 Some(transmute(
595 notify_show_not_found_trampoline::<Self, F> as usize,
596 )),
597 Box_::into_raw(f),
598 )
599 }
600 }
601
602 fn connect_property_show_private_notify<F: Fn(&Self) + 'static>(
603 &self,
604 f: F,
605 ) -> SignalHandlerId {
606 unsafe extern "C" fn notify_show_private_trampoline<P, F: Fn(&P) + 'static>(
607 this: *mut gtk_sys::GtkRecentChooser,
608 _param_spec: glib_sys::gpointer,
609 f: glib_sys::gpointer,
610 ) where
611 P: IsA<RecentChooser>,
612 {
613 let f: &F = &*(f as *const F);
614 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
615 }
616 unsafe {
617 let f: Box_<F> = Box_::new(f);
618 connect_raw(
619 self.as_ptr() as *mut _,
620 b"notify::show-private\0".as_ptr() as *const _,
621 Some(transmute(
622 notify_show_private_trampoline::<Self, F> as usize,
623 )),
624 Box_::into_raw(f),
625 )
626 }
627 }
628
629 fn connect_property_show_tips_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
630 unsafe extern "C" fn notify_show_tips_trampoline<P, F: Fn(&P) + 'static>(
631 this: *mut gtk_sys::GtkRecentChooser,
632 _param_spec: glib_sys::gpointer,
633 f: glib_sys::gpointer,
634 ) where
635 P: IsA<RecentChooser>,
636 {
637 let f: &F = &*(f as *const F);
638 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
639 }
640 unsafe {
641 let f: Box_<F> = Box_::new(f);
642 connect_raw(
643 self.as_ptr() as *mut _,
644 b"notify::show-tips\0".as_ptr() as *const _,
645 Some(transmute(notify_show_tips_trampoline::<Self, F> as usize)),
646 Box_::into_raw(f),
647 )
648 }
649 }
650
651 fn connect_property_sort_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
652 unsafe extern "C" fn notify_sort_type_trampoline<P, F: Fn(&P) + 'static>(
653 this: *mut gtk_sys::GtkRecentChooser,
654 _param_spec: glib_sys::gpointer,
655 f: glib_sys::gpointer,
656 ) where
657 P: IsA<RecentChooser>,
658 {
659 let f: &F = &*(f as *const F);
660 f(&RecentChooser::from_glib_borrow(this).unsafe_cast())
661 }
662 unsafe {
663 let f: Box_<F> = Box_::new(f);
664 connect_raw(
665 self.as_ptr() as *mut _,
666 b"notify::sort-type\0".as_ptr() as *const _,
667 Some(transmute(notify_sort_type_trampoline::<Self, F> as usize)),
668 Box_::into_raw(f),
669 )
670 }
671 }
672}
673
674impl fmt::Display for RecentChooser {
675 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
676 write!(f, "RecentChooser")
677 }
678}