Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2020 Canonical Ltd. |
4 |
|
|
* |
5 |
|
|
* This program is free software; you can redistribute it and/or modify |
6 |
|
|
* it under the terms of the GNU General Public License as published by |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
* (at your option) any later version. |
9 |
|
|
* |
10 |
|
|
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
|
|
* |
15 |
|
|
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
17 |
|
|
*/ |
18 |
|
|
|
19 |
|
|
#include "cc-language-row.h" |
20 |
|
|
#include "cc-common-resources.h" |
21 |
|
|
|
22 |
|
|
#define GNOME_DESKTOP_USE_UNSTABLE_API |
23 |
|
|
#include <libgnome-desktop/gnome-languages.h> |
24 |
|
|
|
25 |
|
|
struct _CcLanguageRow { |
26 |
|
|
GtkListBoxRow parent_instance; |
27 |
|
|
|
28 |
|
|
GtkImage *check_image; |
29 |
|
|
GtkLabel *country_label; |
30 |
|
|
GtkLabel *language_label; |
31 |
|
|
|
32 |
|
|
gchar *locale_id; |
33 |
|
|
gchar *language; |
34 |
|
|
gchar *language_local; |
35 |
|
|
gchar *country; |
36 |
|
|
gchar *country_local; |
37 |
|
|
|
38 |
|
|
gboolean is_extra; |
39 |
|
|
}; |
40 |
|
|
|
41 |
|
✗ |
G_DEFINE_TYPE (CcLanguageRow, cc_language_row, GTK_TYPE_LIST_BOX_ROW) |
42 |
|
|
|
43 |
|
|
static gchar * |
44 |
|
✗ |
get_language_label (const gchar *language_code, |
45 |
|
|
const gchar *modifier, |
46 |
|
|
const gchar *locale_id) |
47 |
|
|
{ |
48 |
|
✗ |
g_autofree gchar *language = NULL; |
49 |
|
|
|
50 |
|
✗ |
language = gnome_get_language_from_code (language_code, locale_id); |
51 |
|
|
|
52 |
|
✗ |
if (modifier == NULL) |
53 |
|
✗ |
return g_steal_pointer (&language); |
54 |
|
|
else |
55 |
|
|
{ |
56 |
|
✗ |
g_autofree gchar *t_mod = gnome_get_translated_modifier (modifier, locale_id); |
57 |
|
✗ |
return g_strdup_printf ("%s — %s", language, t_mod); |
58 |
|
|
} |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
static void |
62 |
|
✗ |
cc_language_row_dispose (GObject *object) |
63 |
|
|
{ |
64 |
|
✗ |
CcLanguageRow *self = CC_LANGUAGE_ROW (object); |
65 |
|
|
|
66 |
|
✗ |
g_clear_pointer (&self->locale_id, g_free); |
67 |
|
✗ |
g_clear_pointer (&self->country, g_free); |
68 |
|
✗ |
g_clear_pointer (&self->country_local, g_free); |
69 |
|
✗ |
g_clear_pointer (&self->language, g_free); |
70 |
|
✗ |
g_clear_pointer (&self->language_local, g_free); |
71 |
|
|
|
72 |
|
✗ |
G_OBJECT_CLASS (cc_language_row_parent_class)->dispose (object); |
73 |
|
✗ |
} |
74 |
|
|
|
75 |
|
|
void |
76 |
|
✗ |
cc_language_row_class_init (CcLanguageRowClass *klass) |
77 |
|
|
{ |
78 |
|
✗ |
GObjectClass *object_class = G_OBJECT_CLASS (klass); |
79 |
|
✗ |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); |
80 |
|
|
|
81 |
|
✗ |
object_class->dispose = cc_language_row_dispose; |
82 |
|
|
|
83 |
|
✗ |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/common/cc-language-row.ui"); |
84 |
|
|
|
85 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcLanguageRow, check_image); |
86 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcLanguageRow, country_label); |
87 |
|
✗ |
gtk_widget_class_bind_template_child (widget_class, CcLanguageRow, language_label); |
88 |
|
✗ |
} |
89 |
|
|
|
90 |
|
|
void |
91 |
|
✗ |
cc_language_row_init (CcLanguageRow *self) |
92 |
|
|
{ |
93 |
|
✗ |
g_resources_register (cc_common_get_resource ()); |
94 |
|
|
|
95 |
|
✗ |
gtk_widget_init_template (GTK_WIDGET (self)); |
96 |
|
✗ |
} |
97 |
|
|
|
98 |
|
|
CcLanguageRow * |
99 |
|
✗ |
cc_language_row_new (const gchar *locale_id) |
100 |
|
|
{ |
101 |
|
|
CcLanguageRow *self; |
102 |
|
✗ |
g_autofree gchar *language_code = NULL; |
103 |
|
✗ |
g_autofree gchar *country_code = NULL; |
104 |
|
✗ |
g_autofree gchar *modifier = NULL; |
105 |
|
|
|
106 |
|
✗ |
self = CC_LANGUAGE_ROW (g_object_new (CC_TYPE_LANGUAGE_ROW, NULL)); |
107 |
|
✗ |
self->locale_id = g_strdup (locale_id); |
108 |
|
|
|
109 |
|
✗ |
gnome_parse_locale (locale_id, &language_code, &country_code, NULL, &modifier); |
110 |
|
|
|
111 |
|
✗ |
self->language = get_language_label (language_code, modifier, locale_id); |
112 |
|
✗ |
self->language_local = get_language_label (language_code, modifier, NULL); |
113 |
|
✗ |
gtk_label_set_label (self->language_label, self->language); |
114 |
|
|
|
115 |
|
✗ |
if (country_code == NULL) |
116 |
|
|
{ |
117 |
|
✗ |
self->country = NULL; |
118 |
|
✗ |
self->country_local = NULL; |
119 |
|
|
} |
120 |
|
|
else |
121 |
|
|
{ |
122 |
|
✗ |
self->country = gnome_get_country_from_code (country_code, locale_id); |
123 |
|
✗ |
self->country_local = gnome_get_country_from_code (country_code, NULL); |
124 |
|
✗ |
gtk_label_set_label (self->country_label, self->country); |
125 |
|
|
} |
126 |
|
|
|
127 |
|
✗ |
return self; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
const gchar * |
131 |
|
✗ |
cc_language_row_get_locale_id (CcLanguageRow *self) |
132 |
|
|
{ |
133 |
|
✗ |
g_return_val_if_fail (CC_IS_LANGUAGE_ROW (self), NULL); |
134 |
|
✗ |
return self->locale_id; |
135 |
|
|
} |
136 |
|
|
|
137 |
|
|
const gchar * |
138 |
|
✗ |
cc_language_row_get_language (CcLanguageRow *self) |
139 |
|
|
{ |
140 |
|
✗ |
g_return_val_if_fail (CC_IS_LANGUAGE_ROW (self), NULL); |
141 |
|
✗ |
return self->language; |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
const gchar * |
145 |
|
✗ |
cc_language_row_get_language_local (CcLanguageRow *self) |
146 |
|
|
{ |
147 |
|
✗ |
g_return_val_if_fail (CC_IS_LANGUAGE_ROW (self), NULL); |
148 |
|
✗ |
return self->language_local; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
const gchar * |
152 |
|
✗ |
cc_language_row_get_country (CcLanguageRow *self) |
153 |
|
|
{ |
154 |
|
✗ |
g_return_val_if_fail (CC_IS_LANGUAGE_ROW (self), NULL); |
155 |
|
✗ |
return self->country; |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
const gchar * |
159 |
|
✗ |
cc_language_row_get_country_local (CcLanguageRow *self) |
160 |
|
|
{ |
161 |
|
✗ |
g_return_val_if_fail (CC_IS_LANGUAGE_ROW (self), NULL); |
162 |
|
✗ |
return self->country_local; |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
void |
166 |
|
✗ |
cc_language_row_set_checked (CcLanguageRow *self, gboolean checked) |
167 |
|
|
{ |
168 |
|
✗ |
g_return_if_fail (CC_IS_LANGUAGE_ROW (self)); |
169 |
|
✗ |
gtk_widget_set_visible (GTK_WIDGET (self->check_image), checked); |
170 |
|
|
} |
171 |
|
|
|
172 |
|
|
void |
173 |
|
✗ |
cc_language_row_set_is_extra (CcLanguageRow *self, gboolean is_extra) |
174 |
|
|
{ |
175 |
|
✗ |
g_return_if_fail (CC_IS_LANGUAGE_ROW (self)); |
176 |
|
✗ |
self->is_extra = is_extra; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
gboolean |
180 |
|
✗ |
cc_language_row_get_is_extra (CcLanguageRow *self) |
181 |
|
|
{ |
182 |
|
✗ |
g_return_val_if_fail (CC_IS_LANGUAGE_ROW (self), FALSE); |
183 |
|
✗ |
return self->is_extra; |
184 |
|
|
} |
185 |
|
|
|