summaryrefslogtreecommitdiff
path: root/libmateweather/mateweather-mateconf.c
blob: f8f6f1b99458ef1a6f9f11221649184520a2a0c0 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
 * mateweather-mateconf.c: MateConf interaction methods for mateweather.
 *
 * Copyright (C) 2005 Philip Langdale, Papadimitriou Spiros
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Authors:
 *     Philip Langdale <philipl@mail.utexas.edu>
 *     Papadimitriou Spiros <spapadim+@cs.cmu.edu>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string.h>

#define MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE
#include "mateweather-mateconf.h"
#include "weather-priv.h"

struct _MateWeatherMateConf
{
    MateConfClient *mateconf;
    char *prefix;
};


MateWeatherMateConf *
mateweather_mateconf_new (const char *prefix)
{
    MateWeatherMateConf *ctx = g_new0 (MateWeatherMateConf, 1);
    ctx->mateconf = mateconf_client_get_default ();
    ctx->prefix = g_strdup (prefix);

    return ctx;
}


void
mateweather_mateconf_free (MateWeatherMateConf *ctx)
{
    if (!ctx)
        return;

    g_object_unref (ctx->mateconf);
    g_free (ctx->prefix);
    g_free (ctx);
}


MateConfClient *
mateweather_mateconf_get_client (MateWeatherMateConf *ctx)
{
    g_return_val_if_fail (ctx != NULL, NULL);
    return ctx->mateconf;
}


gchar *
mateweather_mateconf_get_full_key (MateWeatherMateConf *ctx,
			     const gchar   *key)
{
    g_return_val_if_fail (ctx != NULL, NULL);
    g_return_val_if_fail (key != NULL, NULL);

    return g_strdup_printf ("%s/%s", ctx->prefix, key);
}

void
mateweather_mateconf_set_bool (MateWeatherMateConf  *ctx,
			 const gchar    *key,
			 gboolean        the_bool,
			 GError        **opt_error)
{
    gchar *full_key;

    g_return_if_fail (ctx != NULL);
    g_return_if_fail (key != NULL);
    g_return_if_fail (opt_error == NULL || *opt_error == NULL);

    full_key = mateweather_mateconf_get_full_key (ctx, key);
    mateconf_client_set_bool (ctx->mateconf, full_key, the_bool, opt_error);
    g_free (full_key);
}

void
mateweather_mateconf_set_int (MateWeatherMateConf  *ctx,
			const gchar    *key,
			gint            the_int,
			GError        **opt_error)
{
    gchar *full_key;

    g_return_if_fail (ctx != NULL);
    g_return_if_fail (key != NULL);
    g_return_if_fail (opt_error == NULL || *opt_error == NULL);

    full_key = mateweather_mateconf_get_full_key (ctx, key);
    mateconf_client_set_int (ctx->mateconf, full_key, the_int, opt_error);
    g_free (full_key);
}

void
mateweather_mateconf_set_string (MateWeatherMateConf  *ctx,
			   const gchar    *key,
			   const gchar    *the_string,
			   GError        **opt_error)
{
    gchar *full_key;

    g_return_if_fail (ctx != NULL);
    g_return_if_fail (key != NULL);
    g_return_if_fail (opt_error == NULL || *opt_error == NULL);

    full_key = mateweather_mateconf_get_full_key (ctx, key);
    mateconf_client_set_string (ctx->mateconf, full_key, the_string, opt_error);
    g_free (full_key);
}

gboolean
mateweather_mateconf_get_bool (MateWeatherMateConf  *ctx,
			 const gchar    *key,
			 GError        **opt_error)
{
    gchar *full_key;
    gboolean ret;

    g_return_val_if_fail (ctx != NULL, FALSE);
    g_return_val_if_fail (key != NULL, FALSE);
    g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, FALSE);

    full_key = mateweather_mateconf_get_full_key (ctx, key);
    ret = mateconf_client_get_bool (ctx->mateconf, full_key, opt_error);
    g_free (full_key);
    return ret;
}

gint
mateweather_mateconf_get_int (MateWeatherMateConf  *ctx,
			const gchar    *key,
			GError        **opt_error)
{
    gchar *full_key;
    gint ret;

    g_return_val_if_fail (ctx != NULL, 0);
    g_return_val_if_fail (key != NULL, 0);
    g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, 0);

    full_key = mateweather_mateconf_get_full_key (ctx, key);
    ret = mateconf_client_get_int (ctx->mateconf, full_key, opt_error);
    g_free (full_key);
    return ret;
}

gchar *
mateweather_mateconf_get_string (MateWeatherMateConf  *ctx,
			   const gchar    *key,
			   GError        **opt_error)
{
    gchar *full_key;
    gchar *ret;

    g_return_val_if_fail (ctx != NULL, NULL);
    g_return_val_if_fail (key != NULL, NULL);
    g_return_val_if_fail (opt_error == NULL || *opt_error == NULL, NULL);

    full_key = mateweather_mateconf_get_full_key (ctx, key);
    ret = mateconf_client_get_string (ctx->mateconf, full_key, opt_error);
    g_free (full_key);
    return ret;
}


WeatherLocation *
mateweather_mateconf_get_location (MateWeatherMateConf *ctx)
{
    WeatherLocation *location;
    gchar *name, *code, *zone, *radar, *coordinates;

    g_return_val_if_fail (ctx != NULL, NULL);

    name = mateweather_mateconf_get_string (ctx, "location4", NULL);
    if (!name)
    {
        /* TRANSLATOR: Change this to the default location name,
         * used when you first start the Weather Applet. This is
	 * the common localised name that corresponds to
	 * the location code (DEFAULT_CODE) you will put on the next message
	 * For example, for the Greek locale, we set this to "Athens", the
	 * capital city and we write it in Greek. It's important to translate
	 * this name.
	 *
	 * If you do not require a DEFAULT_LOCATION, set this to
	 * "DEFAULT_LOCATION".
	 */
        if (strcmp ("DEFAULT_LOCATION", _("DEFAULT_LOCATION")))
            name = g_strdup (_("DEFAULT_LOCATION"));
        else
            name = g_strdup ("Pittsburgh");
    }

    code = mateweather_mateconf_get_string (ctx, "location1", NULL);
    if (!code)
    {
        /* TRANSLATOR: Change this to the code of your default location that
	 * corresponds to the DEFAULT_LOCATION name you put above. This is
	 * normally a four-letter (ICAO) code and can be found in
	 * http://git.gnome.org/cgit/libmateweather/plain/data/Locations.xml.in
	 * NB. The web page is over 1.7MB in size.
	 * Pick a default location like a capital city so that it would be ok
	 * for more of your users. For example, for Greek, we use "LGAV" for
	 * the capital city, Athens.
	 *
	 * If you do not require a DEFAULT_CODE, set this to "DEFAULT_CODE".
	 */
        if (strcmp ("DEFAULT_CODE", _("DEFAULT_CODE")))
            code = g_strdup (_("DEFAULT_CODE"));
        else
    	    code = g_strdup ("KPIT");
    }

    zone = mateweather_mateconf_get_string (ctx, "location2", NULL);
    if (!zone)
    {
        /* TRANSLATOR: Change this to the zone of your default location that
	 * corresponds to the DEFAULT_LOCATION and DEFAULT_CODE you put above.
	 * Normally, US and Canada locations have zones while the rest do not.
	 * Check
	 * http://git.gnome.org/cgit/libmateweather/plain/data/Locations.xml.in
	 * as any zone you put here must also be present in the Locations.xml
	 * file.
	 *
	 * If your default location does not have a zone, set this to
	 * "DEFAULT_ZONE".
	 */
        if (strcmp ("DEFAULT_ZONE", _("DEFAULT_ZONE")))
            zone = g_strdup (_("DEFAULT_ZONE" ));
        else
            zone = g_strdup ("PAZ021");
    }

    radar = mateweather_mateconf_get_string (ctx, "location3", NULL);
    if (!radar)
    {
        /* TRANSLATOR: Change this to the radar of your default location that
	 * corresponds to the DEFAULT_LOCATION and DEFAULT_CODE you put above.
	 * Normally, US and Canada locations have radar names while the rest do
	 * not. Check
	 * http://git.gnome.org/cgit/libmateweather/plain/data/Locations.xml.in
	 * as any radar you put here must also be present in the Locations.xml
	 * file.
	 *
	 * If your default location does not have a radar, set this to " "
	 * (or space).
	 * If you do not have a default location, set this to DEFAULT_RADAR.
	 */
        if (strcmp ("DEFAULT_RADAR", _("DEFAULT_RADAR")))
            radar = g_strdup (_("DEFAULT_RADAR"));
        else
            radar = g_strdup ("pit");
    }

    coordinates = mateweather_mateconf_get_string (ctx, "coordinates", NULL);
    if (!coordinates)
    {
        /* TRANSLATOR: Change this to the coordinates of your default location
	 * that corresponds to the DEFAULT_LOCATION and DEFAULT_CODE you put
	 * above. Check
	 * http://git.gnome.org/cgit/libmateweather/plain/data/Locations.xml.in
	 * as any coordinates you put here must also be present in the
	 * Locations.xml file.
	 *
	 * If your default location does not have known coordinates, set this
	 * to " " (or space).
	 * If you do not have a default location, set this to
	 * DEFAULT_COORDINATES.
	 */
	if (strcmp ("DEFAULT_COORDINATES", _("DEFAULT_COORDINATES")))
	    coordinates = g_strdup (_("DEFAULT_COORDINATES"));
	else
	    coordinates = g_strdup ("40-32N 080-13W");
    }

    location = weather_location_new (name, code, zone, radar, coordinates,
				     NULL, NULL);

    g_free (name);
    g_free (code);
    g_free (zone);
    g_free (radar);
    g_free (coordinates);

    return location;
}