1 /*
2 * (C) 2008 Pablo Sanxiao <psanxiao@gmail.com>
3 * Igalia
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 3 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 * Authors:
19 * Pablo Sanxiao <psanxiao@gmail.com>
20 * Ignacio Casal Quinteiro <icq@gnome.org>
21 */
22
23 #include "gtr-application.h"
24 #include "gtr-profile.h"
25 #include "gtr-preferences-dialog.h"
26 #include "gtr-utils.h"
27
28 #include <glib.h>
29
30 typedef struct
31 {
32 /* Identify the profile */
33 gchar *name;
34
35 /* Authentication token */
36 gchar *auth_token;
37
38 /* Translator's information */
39 gchar *author_name;
40 gchar *author_email;
41
42 /* Complete language name */
43 gchar *language_name;
44
45 /* Language code. Example: "en" -> English */
46 gchar *language_code;
47
48 /* Set of characters. Example: UTF-8 */
49 gchar *charset;
50
51 /* Encoding. Example: 8 bits */
52 gchar *encoding;
53
54 /* Email of the group of translation */
55 gchar *group_email;
56
57 /* Plural forms */
58 gchar *plural_forms;
59 } GtrProfilePrivate;
60
G_DEFINE_TYPE_WITH_PRIVATE(GtrProfile,gtr_profile,G_TYPE_OBJECT)61 G_DEFINE_TYPE_WITH_PRIVATE (GtrProfile, gtr_profile, G_TYPE_OBJECT)
62
63 static void
64 gtr_profile_init (GtrProfile *profile)
65 {
66 }
67
68 static void
gtr_profile_finalize(GObject * object)69 gtr_profile_finalize (GObject *object)
70 {
71 GtrProfile *profile = GTR_PROFILE (object);
72 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
73
74 g_free (priv->name);
75 g_free (priv->auth_token);
76 g_free (priv->author_name);
77 g_free (priv->author_email);
78 g_free (priv->language_name);
79 g_free (priv->language_code);
80 g_free (priv->charset);
81 g_free (priv->encoding);
82 g_free (priv->group_email);
83 g_free (priv->plural_forms);
84
85 G_OBJECT_CLASS (gtr_profile_parent_class)->finalize (object);
86 }
87
88 static void
gtr_profile_class_init(GtrProfileClass * klass)89 gtr_profile_class_init (GtrProfileClass *klass)
90 {
91 GObjectClass *object_class = G_OBJECT_CLASS (klass);
92
93 object_class->finalize = gtr_profile_finalize;
94 }
95
96 /*
97 * Public methods
98 */
99
100 GtrProfile *
gtr_profile_new(void)101 gtr_profile_new (void)
102 {
103 return g_object_new (GTR_TYPE_PROFILE, NULL);
104 }
105
106 const gchar *
gtr_profile_get_name(GtrProfile * profile)107 gtr_profile_get_name (GtrProfile *profile)
108 {
109 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
110 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
111
112 return priv->name;
113 }
114
115 void
gtr_profile_set_name(GtrProfile * profile,const gchar * data)116 gtr_profile_set_name (GtrProfile *profile,
117 const gchar *data)
118 {
119 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
120 g_return_if_fail (GTR_IS_PROFILE (profile));
121 g_return_if_fail (data != NULL);
122
123 g_free (priv->name);
124 priv->name = g_strdup (data);
125 }
126
127 const gchar *
gtr_profile_get_auth_token(GtrProfile * profile)128 gtr_profile_get_auth_token (GtrProfile *profile)
129 {
130 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
131 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
132
133 return priv->auth_token;
134 }
135
136 void
gtr_profile_set_auth_token(GtrProfile * profile,const gchar * data)137 gtr_profile_set_auth_token (GtrProfile *profile,
138 const gchar *data)
139 {
140 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
141 g_return_if_fail (GTR_IS_PROFILE (profile));
142 g_return_if_fail (data != NULL);
143
144 g_free (priv->auth_token);
145 priv->auth_token = g_strdup (data);
146 }
147
148 const gchar *
gtr_profile_get_author_name(GtrProfile * profile)149 gtr_profile_get_author_name (GtrProfile *profile)
150 {
151 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
152 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
153
154 return priv->author_name;
155 }
156
157 void
gtr_profile_set_author_name(GtrProfile * profile,const gchar * data)158 gtr_profile_set_author_name (GtrProfile *profile,
159 const gchar *data)
160 {
161 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
162 g_return_if_fail (GTR_IS_PROFILE (profile));
163 g_return_if_fail (data != NULL);
164
165 g_free (priv->author_name);
166 priv->author_name = g_strdup (data);
167 }
168
169 const gchar *
gtr_profile_get_author_email(GtrProfile * profile)170 gtr_profile_get_author_email (GtrProfile *profile)
171 {
172 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
173 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
174
175 return priv->author_email;
176 }
177
178 void
gtr_profile_set_author_email(GtrProfile * profile,const gchar * data)179 gtr_profile_set_author_email (GtrProfile *profile,
180 const gchar *data)
181 {
182 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
183 g_return_if_fail (GTR_IS_PROFILE (profile));
184 g_return_if_fail (data != NULL);
185
186 g_free (priv->author_email);
187 priv->author_email = g_strdup (data);
188 }
189
190 const gchar *
gtr_profile_get_language_name(GtrProfile * profile)191 gtr_profile_get_language_name (GtrProfile *profile)
192 {
193 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
194 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
195
196 return priv->language_name;
197 }
198
199 void
gtr_profile_set_language_name(GtrProfile * profile,const gchar * data)200 gtr_profile_set_language_name (GtrProfile *profile,
201 const gchar *data)
202 {
203 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
204 g_return_if_fail (GTR_IS_PROFILE (profile));
205 g_return_if_fail (data != NULL);
206
207 g_free (priv->language_name);
208 priv->language_name = g_strdup (data);
209 }
210
211 const gchar *
gtr_profile_get_language_code(GtrProfile * profile)212 gtr_profile_get_language_code (GtrProfile *profile)
213 {
214 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
215 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
216
217 return priv->language_code;
218 }
219
220 void
gtr_profile_set_language_code(GtrProfile * profile,const gchar * data)221 gtr_profile_set_language_code (GtrProfile *profile,
222 const gchar *data)
223 {
224 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
225 g_return_if_fail (GTR_IS_PROFILE (profile));
226 g_return_if_fail (data != NULL);
227
228 g_free (priv->language_code);
229 priv->language_code = g_strdup (data);
230 }
231
232 const gchar *
gtr_profile_get_charset(GtrProfile * profile)233 gtr_profile_get_charset (GtrProfile *profile)
234 {
235 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
236 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
237
238 return priv->charset;
239 }
240
241 void
gtr_profile_set_charset(GtrProfile * profile,const gchar * data)242 gtr_profile_set_charset (GtrProfile *profile,
243 const gchar *data)
244 {
245 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
246 g_return_if_fail (GTR_IS_PROFILE (profile));
247 g_return_if_fail (data != NULL);
248
249 g_free (priv->charset);
250 priv->charset = g_strdup (data);
251 }
252
253 const gchar *
gtr_profile_get_encoding(GtrProfile * profile)254 gtr_profile_get_encoding (GtrProfile *profile)
255 {
256 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
257 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
258
259 return priv->encoding;
260 }
261
262 void
gtr_profile_set_encoding(GtrProfile * profile,const gchar * data)263 gtr_profile_set_encoding (GtrProfile *profile,
264 const gchar *data)
265 {
266 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
267 g_return_if_fail (GTR_IS_PROFILE (profile));
268 g_return_if_fail (data != NULL);
269
270 g_free (priv->encoding);
271 priv->encoding = g_strdup (data);
272 }
273
274 const gchar *
gtr_profile_get_group_email(GtrProfile * profile)275 gtr_profile_get_group_email (GtrProfile *profile)
276 {
277 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
278 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
279
280 return priv->group_email;
281 }
282
283 void
gtr_profile_set_group_email(GtrProfile * profile,const gchar * data)284 gtr_profile_set_group_email (GtrProfile *profile,
285 const gchar *data)
286 {
287 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
288 g_return_if_fail (GTR_IS_PROFILE (profile));
289 g_return_if_fail (data != NULL);
290
291 g_free (priv->group_email);
292 priv->group_email = g_strdup (data);
293 }
294
295 const gchar *
gtr_profile_get_plural_forms(GtrProfile * profile)296 gtr_profile_get_plural_forms (GtrProfile *profile)
297 {
298 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
299 g_return_val_if_fail (GTR_IS_PROFILE (profile), NULL);
300
301 return priv->plural_forms;
302 }
303
304 void
gtr_profile_set_plural_forms(GtrProfile * profile,const gchar * data)305 gtr_profile_set_plural_forms (GtrProfile *profile,
306 const gchar *data)
307 {
308 GtrProfilePrivate *priv = gtr_profile_get_instance_private (profile);
309 g_return_if_fail (GTR_IS_PROFILE (profile));
310 g_return_if_fail (data != NULL);
311
312 g_free (priv->plural_forms);
313 priv->plural_forms = g_strdup (data);
314 }