~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/datetime/cc-timezone-map.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2010 Intel, Inc
 
3
 *
 
4
 * Portions from Ubiquity, Copyright (C) 2009 Canonical Ltd.
 
5
 * Written by Evan Dandrea <evand@ubuntu.com>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
20
 *
 
21
 * Author: Thomas Wood <thomas.wood@intel.com>
 
22
 *
 
23
 */
 
24
 
 
25
#include "cc-timezone-map.h"
 
26
#include <math.h>
 
27
#include <string.h>
 
28
#include "tz.h"
 
29
 
 
30
G_DEFINE_TYPE (CcTimezoneMap, cc_timezone_map, GTK_TYPE_WIDGET)
 
31
 
 
32
#define TIMEZONE_MAP_PRIVATE(o) \
 
33
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_TIMEZONE_MAP, CcTimezoneMapPrivate))
 
34
 
 
35
 
 
36
typedef struct
 
37
{
 
38
  gdouble offset;
 
39
  guchar red;
 
40
  guchar green;
 
41
  guchar blue;
 
42
  guchar alpha;
 
43
} CcTimezoneMapOffset;
 
44
 
 
45
struct _CcTimezoneMapPrivate
 
46
{
 
47
  GdkPixbuf *orig_background;
 
48
  GdkPixbuf *orig_color_map;
 
49
 
 
50
  GdkPixbuf *background;
 
51
  GdkPixbuf *color_map;
 
52
 
 
53
  guchar *visible_map_pixels;
 
54
  gint visible_map_rowstride;
 
55
 
 
56
  gdouble selected_offset;
 
57
 
 
58
  TzDB *tzdb;
 
59
  TzLocation *location;
 
60
};
 
61
 
 
62
enum
 
63
{
 
64
  LOCATION_CHANGED,
 
65
  LAST_SIGNAL
 
66
};
 
67
 
 
68
static guint signals[LAST_SIGNAL];
 
69
 
 
70
 
 
71
static CcTimezoneMapOffset color_codes[] =
 
72
{
 
73
    {-11.0, 43, 0, 0, 255 },
 
74
    {-10.0, 85, 0, 0, 255 },
 
75
    {-9.5, 102, 255, 0, 255 },
 
76
    {-9.0, 128, 0, 0, 255 },
 
77
    {-8.0, 170, 0, 0, 255 },
 
78
    {-7.0, 212, 0, 0, 255 },
 
79
    {-6.0, 255, 0, 1, 255 }, // north
 
80
    {-6.0, 255, 0, 0, 255 }, // south
 
81
    {-5.0, 255, 42, 42, 255 },
 
82
    {-4.5, 192, 255, 0, 255 },
 
83
    {-4.0, 255, 85, 85, 255 },
 
84
    {-3.5, 0, 255, 0, 255 },
 
85
    {-3.0, 255, 128, 128, 255 },
 
86
    {-2.0, 255, 170, 170, 255 },
 
87
    {-1.0, 255, 213, 213, 255 },
 
88
    {0.0, 43, 17, 0, 255 },
 
89
    {1.0, 85, 34, 0, 255 },
 
90
    {2.0, 128, 51, 0, 255 },
 
91
    {3.0, 170, 68, 0, 255 },
 
92
    {3.5, 0, 255, 102, 255 },
 
93
    {4.0, 212, 85, 0, 255 },
 
94
    {4.5, 0, 204, 255, 255 },
 
95
    {5.0, 255, 102, 0, 255 },
 
96
    {5.5, 0, 102, 255, 255 },
 
97
    {5.75, 0, 238, 207, 247 },
 
98
    {6.0, 255, 127, 42, 255 },
 
99
    {6.5, 204, 0, 254, 254 },
 
100
    {7.0, 255, 153, 85, 255 },
 
101
    {8.0, 255, 179, 128, 255 },
 
102
    {9.0, 255, 204, 170, 255 },
 
103
    {9.5, 170, 0, 68, 250 },
 
104
    {10.0, 255, 230, 213, 255 },
 
105
    {10.5, 212, 124, 21, 250 },
 
106
    {11.0, 212, 170, 0, 255 },
 
107
    {11.5, 249, 25, 87, 253 },
 
108
    {12.0, 255, 204, 0, 255 },
 
109
    {12.75, 254, 74, 100, 248 },
 
110
    {13.0, 255, 85, 153, 250 },
 
111
    {-100, 0, 0, 0, 0 }
 
112
};
 
113
 
 
114
 
 
115
static void
 
116
cc_timezone_map_get_property (GObject    *object,
 
117
                              guint       property_id,
 
118
                              GValue     *value,
 
119
                              GParamSpec *pspec)
 
120
{
 
121
  switch (property_id)
 
122
    {
 
123
    default:
 
124
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
125
    }
 
126
}
 
127
 
 
128
static void
 
129
cc_timezone_map_set_property (GObject      *object,
 
130
                              guint         property_id,
 
131
                              const GValue *value,
 
132
                              GParamSpec   *pspec)
 
133
{
 
134
  switch (property_id)
 
135
    {
 
136
    default:
 
137
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
138
    }
 
139
}
 
140
 
 
141
static void
 
142
cc_timezone_map_dispose (GObject *object)
 
143
{
 
144
  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (object)->priv;
 
145
 
 
146
  if (priv->orig_background)
 
147
    {
 
148
      g_object_unref (priv->orig_background);
 
149
      priv->orig_background = NULL;
 
150
    }
 
151
 
 
152
  if (priv->orig_color_map)
 
153
    {
 
154
      g_object_unref (priv->orig_color_map);
 
155
      priv->orig_color_map = NULL;
 
156
    }
 
157
 
 
158
  if (priv->background)
 
159
    {
 
160
      g_object_unref (priv->background);
 
161
      priv->background = NULL;
 
162
    }
 
163
 
 
164
  if (priv->color_map)
 
165
    {
 
166
      g_object_unref (priv->color_map);
 
167
      priv->color_map = NULL;
 
168
 
 
169
      priv->visible_map_pixels = NULL;
 
170
      priv->visible_map_rowstride = 0;
 
171
    }
 
172
 
 
173
  G_OBJECT_CLASS (cc_timezone_map_parent_class)->dispose (object);
 
174
}
 
175
 
 
176
static void
 
177
cc_timezone_map_finalize (GObject *object)
 
178
{
 
179
  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (object)->priv;
 
180
 
 
181
  if (priv->tzdb)
 
182
    {
 
183
      tz_db_free (priv->tzdb);
 
184
      priv->tzdb = NULL;
 
185
    }
 
186
 
 
187
 
 
188
  G_OBJECT_CLASS (cc_timezone_map_parent_class)->finalize (object);
 
189
}
 
190
 
 
191
/* GtkWidget functions */
 
192
static void
 
193
cc_timezone_map_get_preferred_width (GtkWidget *widget,
 
194
                                     gint      *minimum,
 
195
                                     gint      *natural)
 
196
{
 
197
  /* choose a minimum size small enough to prevent the window
 
198
   * from growing horizontally
 
199
   */
 
200
  if (minimum != NULL)
 
201
    *minimum = 300;
 
202
  if (natural != NULL)
 
203
    *natural = 300;
 
204
}
 
205
 
 
206
static void
 
207
cc_timezone_map_get_preferred_height (GtkWidget *widget,
 
208
                                      gint      *minimum,
 
209
                                      gint      *natural)
 
210
{
 
211
  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
 
212
  gint size;
 
213
 
 
214
  /* The + 20 here is a slight tweak to make the map fill the
 
215
   * panel better without causing horizontal growing
 
216
   */
 
217
  size = 300 * gdk_pixbuf_get_height (priv->orig_background) / gdk_pixbuf_get_width (priv->orig_background) + 20;
 
218
  if (minimum != NULL)
 
219
    *minimum = size;
 
220
  if (natural != NULL)
 
221
    *natural = size;
 
222
}
 
223
 
 
224
static void
 
225
cc_timezone_map_size_allocate (GtkWidget     *widget,
 
226
                               GtkAllocation *allocation)
 
227
{
 
228
  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
 
229
 
 
230
  if (priv->background)
 
231
    g_object_unref (priv->background);
 
232
 
 
233
  priv->background = gdk_pixbuf_scale_simple (priv->orig_background,
 
234
                                              allocation->width,
 
235
                                              allocation->height,
 
236
                                              GDK_INTERP_BILINEAR);
 
237
 
 
238
  if (priv->color_map)
 
239
    g_object_unref (priv->color_map);
 
240
 
 
241
  priv->color_map = gdk_pixbuf_scale_simple (priv->orig_color_map,
 
242
                                             allocation->width,
 
243
                                             allocation->height,
 
244
                                             GDK_INTERP_BILINEAR);
 
245
 
 
246
  priv->visible_map_pixels = gdk_pixbuf_get_pixels (priv->color_map);
 
247
  priv->visible_map_rowstride = gdk_pixbuf_get_rowstride (priv->color_map);
 
248
 
 
249
  GTK_WIDGET_CLASS (cc_timezone_map_parent_class)->size_allocate (widget,
 
250
                                                                  allocation);
 
251
}
 
252
 
 
253
static void
 
254
cc_timezone_map_realize (GtkWidget *widget)
 
255
{
 
256
  GdkWindowAttr attr = { 0, };
 
257
  GtkAllocation allocation;
 
258
  GdkCursor *cursor;
 
259
  GdkWindow *window;
 
260
 
 
261
  gtk_widget_get_allocation (widget, &allocation);
 
262
 
 
263
  gtk_widget_set_realized (widget, TRUE);
 
264
 
 
265
  attr.window_type = GDK_WINDOW_CHILD;
 
266
  attr.wclass = GDK_INPUT_OUTPUT;
 
267
  attr.width = allocation.width;
 
268
  attr.height = allocation.height;
 
269
  attr.x = allocation.x;
 
270
  attr.y = allocation.y;
 
271
  attr.event_mask = gtk_widget_get_events (widget)
 
272
                                 | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK;
 
273
 
 
274
  window = gdk_window_new (gtk_widget_get_parent_window (widget), &attr,
 
275
                           GDK_WA_X | GDK_WA_Y);
 
276
 
 
277
  cursor = gdk_cursor_new (GDK_HAND2);
 
278
  gdk_window_set_cursor (window, cursor);
 
279
 
 
280
  gdk_window_set_user_data (window, widget);
 
281
  gtk_widget_set_window (widget, window);
 
282
}
 
283
 
 
284
 
 
285
static gdouble
 
286
convert_longtitude_to_x (gdouble longitude, gint map_width)
 
287
{
 
288
  const gdouble xdeg_offset = -6;
 
289
  gdouble x;
 
290
 
 
291
  x = (map_width * (180.0 + longitude) / 360.0)
 
292
    + (map_width * xdeg_offset / 180.0);
 
293
 
 
294
  return x;
 
295
}
 
296
 
 
297
static gdouble
 
298
radians (gdouble degrees)
 
299
{
 
300
  return (degrees / 360.0) * G_PI * 2;
 
301
}
 
302
 
 
303
static gdouble
 
304
convert_latitude_to_y (gdouble latitude, gdouble map_height)
 
305
{
 
306
  gdouble bottom_lat = -59;
 
307
  gdouble top_lat = 81;
 
308
  gdouble top_per, y, full_range, top_offset, map_range;
 
309
 
 
310
  top_per = top_lat / 180.0;
 
311
  y = 1.25 * log (tan (G_PI_4 + 0.4 * radians (latitude)));
 
312
  full_range = 4.6068250867599998;
 
313
  top_offset = full_range * top_per;
 
314
  map_range = fabs (1.25 * log (tan (G_PI_4 + 0.4 * radians (bottom_lat))) - top_offset);
 
315
  y = fabs (y - top_offset);
 
316
  y = y / map_range;
 
317
  y = y * map_height;
 
318
  return y;
 
319
}
 
320
 
 
321
 
 
322
static gboolean
 
323
cc_timezone_map_draw (GtkWidget *widget,
 
324
                      cairo_t   *cr)
 
325
{
 
326
  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
 
327
  GdkPixbuf *hilight, *orig_hilight, *pin;
 
328
  GtkAllocation alloc;
 
329
  gchar *file;
 
330
  GError *err = NULL;
 
331
  gdouble pointx, pointy;
 
332
  char buf[16];
 
333
 
 
334
  gtk_widget_get_allocation (widget, &alloc);
 
335
 
 
336
  /* paint background */
 
337
  gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0);
 
338
  cairo_paint (cr);
 
339
 
 
340
  /* paint hilight */
 
341
  file = g_strdup_printf (DATADIR "/timezone_%s.png",
 
342
                          g_ascii_formatd (buf, sizeof (buf),
 
343
                                           "%g", priv->selected_offset));
 
344
  orig_hilight = gdk_pixbuf_new_from_file (file, &err);
 
345
  g_free (file);
 
346
  file = NULL;
 
347
 
 
348
  if (!orig_hilight)
 
349
    {
 
350
      g_warning ("Could not load hilight: %s",
 
351
                 (err) ? err->message : "Unknown Error");
 
352
      if (err)
 
353
        g_clear_error (&err);
 
354
    }
 
355
  else
 
356
    {
 
357
 
 
358
      hilight = gdk_pixbuf_scale_simple (orig_hilight, alloc.width,
 
359
                                         alloc.height, GDK_INTERP_BILINEAR);
 
360
      gdk_cairo_set_source_pixbuf (cr, hilight, 0, 0);
 
361
 
 
362
      cairo_paint (cr);
 
363
      g_object_unref (hilight);
 
364
      g_object_unref (orig_hilight);
 
365
    }
 
366
 
 
367
  /* load pin icon */
 
368
  pin = gdk_pixbuf_new_from_file (DATADIR "/pin.png", &err);
 
369
 
 
370
  if (err)
 
371
    {
 
372
      g_warning ("Could not load pin icon: %s", err->message);
 
373
      g_clear_error (&err);
 
374
    }
 
375
 
 
376
  if (priv->location)
 
377
    {
 
378
      pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width);
 
379
      pointy = convert_latitude_to_y (priv->location->latitude, alloc.height);
 
380
 
 
381
      if (pointy > alloc.height)
 
382
        pointy = alloc.height;
 
383
 
 
384
      if (pin)
 
385
        {
 
386
          gdk_cairo_set_source_pixbuf (cr, pin, pointx - 8, pointy - 14);
 
387
          cairo_paint (cr);
 
388
        }
 
389
    }
 
390
 
 
391
  if (pin)
 
392
    {
 
393
      g_object_unref (pin);
 
394
    }
 
395
 
 
396
  return TRUE;
 
397
}
 
398
 
 
399
 
 
400
static void
 
401
cc_timezone_map_class_init (CcTimezoneMapClass *klass)
 
402
{
 
403
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
404
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
405
 
 
406
  g_type_class_add_private (klass, sizeof (CcTimezoneMapPrivate));
 
407
 
 
408
  object_class->get_property = cc_timezone_map_get_property;
 
409
  object_class->set_property = cc_timezone_map_set_property;
 
410
  object_class->dispose = cc_timezone_map_dispose;
 
411
  object_class->finalize = cc_timezone_map_finalize;
 
412
 
 
413
  widget_class->get_preferred_width = cc_timezone_map_get_preferred_width;
 
414
  widget_class->get_preferred_height = cc_timezone_map_get_preferred_height;
 
415
  widget_class->size_allocate = cc_timezone_map_size_allocate;
 
416
  widget_class->realize = cc_timezone_map_realize;
 
417
  widget_class->draw = cc_timezone_map_draw;
 
418
 
 
419
  signals[LOCATION_CHANGED] = g_signal_new ("location-changed",
 
420
                                            CC_TYPE_TIMEZONE_MAP,
 
421
                                            G_SIGNAL_RUN_FIRST,
 
422
                                            0,
 
423
                                            NULL,
 
424
                                            NULL,
 
425
                                            g_cclosure_marshal_VOID__POINTER,
 
426
                                            G_TYPE_NONE, 1,
 
427
                                            G_TYPE_POINTER);
 
428
}
 
429
 
 
430
 
 
431
static gint
 
432
sort_locations (TzLocation *a,
 
433
                TzLocation *b)
 
434
{
 
435
  if (a->dist > b->dist)
 
436
    return 1;
 
437
 
 
438
  if (a->dist < b->dist)
 
439
    return -1;
 
440
 
 
441
  return 0;
 
442
}
 
443
 
 
444
static void
 
445
set_location (CcTimezoneMap *map,
 
446
              TzLocation    *location)
 
447
{
 
448
  CcTimezoneMapPrivate *priv = map->priv;
 
449
  TzInfo *info;
 
450
 
 
451
  priv->location = location;
 
452
 
 
453
  info = tz_info_from_location (priv->location);
 
454
 
 
455
  priv->selected_offset = tz_location_get_utc_offset (priv->location)
 
456
    / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0);
 
457
 
 
458
  g_signal_emit (map, signals[LOCATION_CHANGED], 0, priv->location);
 
459
 
 
460
  tz_info_free (info);
 
461
}
 
462
 
 
463
static gboolean
 
464
button_press_event (GtkWidget      *widget,
 
465
                    GdkEventButton *event)
 
466
{
 
467
  CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
 
468
  gint x, y;
 
469
  guchar r, g, b, a;
 
470
  guchar *pixels;
 
471
  gint rowstride;
 
472
  gint i;
 
473
 
 
474
  const GPtrArray *array;
 
475
  gint width, height;
 
476
  GList *distances = NULL;
 
477
  GtkAllocation alloc;
 
478
 
 
479
  x = event->x;
 
480
  y = event->y;
 
481
 
 
482
 
 
483
  rowstride = priv->visible_map_rowstride;
 
484
  pixels = priv->visible_map_pixels;
 
485
 
 
486
  r = pixels[(rowstride * y + x * 4)];
 
487
  g = pixels[(rowstride * y + x * 4) + 1];
 
488
  b = pixels[(rowstride * y + x * 4) + 2];
 
489
  a = pixels[(rowstride * y + x * 4) + 3];
 
490
 
 
491
 
 
492
  for (i = 0; color_codes[i].offset != -100; i++)
 
493
    {
 
494
       if (color_codes[i].red == r && color_codes[i].green == g
 
495
           && color_codes[i].blue == b && color_codes[i].alpha == a)
 
496
         {
 
497
           priv->selected_offset = color_codes[i].offset;
 
498
         }
 
499
    }
 
500
 
 
501
  gtk_widget_queue_draw (widget);
 
502
 
 
503
  /* work out the co-ordinates */
 
504
 
 
505
  array = tz_get_locations (priv->tzdb);
 
506
 
 
507
  gtk_widget_get_allocation (widget, &alloc);
 
508
  width = alloc.width;
 
509
  height = alloc.height;
 
510
 
 
511
  for (i = 0; i < array->len; i++)
 
512
    {
 
513
      gdouble pointx, pointy, dx, dy;
 
514
      TzLocation *loc = array->pdata[i];
 
515
 
 
516
      pointx = convert_longtitude_to_x (loc->longitude, width);
 
517
      pointy = convert_latitude_to_y (loc->latitude, height);
 
518
 
 
519
      dx = pointx - x;
 
520
      dy = pointy - y;
 
521
 
 
522
      loc->dist = dx * dx + dy * dy;
 
523
      distances = g_list_prepend (distances, loc);
 
524
 
 
525
    }
 
526
  distances = g_list_sort (distances, (GCompareFunc) sort_locations);
 
527
 
 
528
 
 
529
  set_location (CC_TIMEZONE_MAP (widget), (TzLocation*) distances->data);
 
530
 
 
531
  g_list_free (distances);
 
532
 
 
533
  return TRUE;
 
534
}
 
535
 
 
536
static void
 
537
cc_timezone_map_init (CcTimezoneMap *self)
 
538
{
 
539
  CcTimezoneMapPrivate *priv;
 
540
  GError *err = NULL;
 
541
 
 
542
  priv = self->priv = TIMEZONE_MAP_PRIVATE (self);
 
543
 
 
544
  priv->orig_background = gdk_pixbuf_new_from_file (DATADIR "/bg.png",
 
545
                                                    &err);
 
546
 
 
547
  if (!priv->orig_background)
 
548
    {
 
549
      g_warning ("Could not load background image: %s",
 
550
                 (err) ? err->message : "Unknown error");
 
551
      g_clear_error (&err);
 
552
    }
 
553
 
 
554
  priv->orig_color_map = gdk_pixbuf_new_from_file (DATADIR "/cc.png",
 
555
                                                   &err);
 
556
  if (!priv->orig_color_map)
 
557
    {
 
558
      g_warning ("Could not load background image: %s",
 
559
                 (err) ? err->message : "Unknown error");
 
560
      g_clear_error (&err);
 
561
    }
 
562
 
 
563
  priv->tzdb = tz_load_db ();
 
564
 
 
565
  g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event),
 
566
                    NULL);
 
567
}
 
568
 
 
569
CcTimezoneMap *
 
570
cc_timezone_map_new (void)
 
571
{
 
572
  return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL);
 
573
}
 
574
 
 
575
gboolean
 
576
cc_timezone_map_set_timezone (CcTimezoneMap *map,
 
577
                              const gchar   *timezone)
 
578
{
 
579
  GPtrArray *locations;
 
580
  guint i;
 
581
  char *real_tz;
 
582
  gboolean ret;
 
583
 
 
584
  real_tz = tz_info_get_clean_name (map->priv->tzdb, timezone);
 
585
 
 
586
  locations = tz_get_locations (map->priv->tzdb);
 
587
  ret = FALSE;
 
588
 
 
589
  for (i = 0; i < locations->len; i++)
 
590
    {
 
591
      TzLocation *loc = locations->pdata[i];
 
592
 
 
593
      if (!g_strcmp0 (loc->zone, real_tz ? real_tz : timezone))
 
594
        {
 
595
          set_location (map, loc);
 
596
          ret = TRUE;
 
597
          break;
 
598
        }
 
599
    }
 
600
 
 
601
  if (ret)
 
602
    gtk_widget_queue_draw (GTK_WIDGET (map));
 
603
 
 
604
  g_free (real_tz);
 
605
 
 
606
  return ret;
 
607
}
 
608
 
 
609
TzLocation *
 
610
cc_timezone_map_get_location (CcTimezoneMap *map)
 
611
{
 
612
  return map->priv->location;
 
613
}