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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT

use glib::translate::*;
use std::cmp;

glib::wrapper! {
    #[derive(Debug, Hash)]
    pub struct Language(Boxed<ffi::GspellLanguage>);

    match fn {
        copy => |ptr| ffi::gspell_language_copy(ptr),
        free => |ptr| ffi::gspell_language_free(ptr),
        type_ => || ffi::gspell_language_get_type(),
    }
}

impl Language {
    #[doc(alias = "gspell_language_compare")]
    fn compare(&self, language_b: &Language) -> i32 {
        unsafe { ffi::gspell_language_compare(self.to_glib_none().0, language_b.to_glib_none().0) }
    }

    ///
    /// # Returns
    ///
    /// the `self` code, for example fr_BE.
    #[doc(alias = "gspell_language_get_code")]
    #[doc(alias = "get_code")]
    pub fn code(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::gspell_language_get_code(self.to_glib_none().0)) }
    }

    /// Returns the `self` name translated to the current locale. For example
    /// "French (Belgium)" is returned if the current locale is in English and the
    /// `self` code is fr_BE.
    ///
    /// # Returns
    ///
    /// the `self` name.
    #[doc(alias = "gspell_language_get_name")]
    #[doc(alias = "get_name")]
    pub fn name(&self) -> Option<glib::GString> {
        unsafe { from_glib_none(ffi::gspell_language_get_name(self.to_glib_none().0)) }
    }

    ///
    /// # Returns
    ///
    /// the list of available
    /// languages, sorted with `gspell_language_compare()`.
    #[doc(alias = "gspell_language_get_available")]
    #[doc(alias = "get_available")]
    pub fn available() -> Vec<Language> {
        assert_initialized_main_thread!();
        unsafe { FromGlibPtrContainer::from_glib_none(ffi::gspell_language_get_available()) }
    }

    /// Finds the best available language based on the current locale.
    ///
    /// # Returns
    ///
    /// the default [`Language`][crate::Language], or [`None`] if no dictionaries
    /// are available.
    #[doc(alias = "gspell_language_get_default")]
    #[doc(alias = "get_default")]
    #[allow(clippy::should_implement_trait)]
    pub fn default() -> Option<Language> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gspell_language_get_default()) }
    }

    /// ## `language_code`
    /// a language code.
    ///
    /// # Returns
    ///
    /// a [`Language`][crate::Language] corresponding to `language_code`, or
    /// [`None`] if not found.
    #[doc(alias = "gspell_language_lookup")]
    pub fn lookup(language_code: &str) -> Option<Language> {
        assert_initialized_main_thread!();
        unsafe { from_glib_none(ffi::gspell_language_lookup(language_code.to_glib_none().0)) }
    }
}

impl PartialEq for Language {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        self.compare(other) == 0
    }
}

impl Eq for Language {}

impl PartialOrd for Language {
    #[inline]
    fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
        Some(self.cmp(other))
    }
}

impl Ord for Language {
    #[inline]
    fn cmp(&self, other: &Self) -> cmp::Ordering {
        self.compare(other).cmp(&0)
    }
}