clock.c 109 KB
Newer Older
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
2
/*
3
 * clock.c: the GNOME clock applet
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
 * Copyright (C) 1997-2003 Free Software Foundation, Inc.
 *
 * This program 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 program 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 program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * Authors:
 *      Miguel de Icaza
 *      Frederico Mena
 *      Stuart Parmenter
 *      Alexander Larsson
 *      George Lebl
 *      Gediminas Paulauskas
 *      Mark McLoughlin
30 31
 */

32 33
#include "config.h"

34 35 36 37 38 39
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <time.h>
40
#include <sys/time.h>
41 42 43
#include <math.h>
#include <locale.h>

44
#include <panel-applet.h>
45
#include <panel-applet-gconf.h>
46

47 48
#include <glib/gi18n.h>

49
#include <gtk/gtk.h>
50
#include <gdk/gdkkeysyms.h>
51
#include <gdk/gdkx.h>
52
#include <gconf/gconf-client.h>
53

54
#include <libgweather/gweather-prefs.h>
55
#include <libgweather/gweather-xml.h>
56 57
#include <libgweather/location-entry.h>
#include <libgweather/timezone-menu.h>
58

59 60 61 62
#ifdef HAVE_LIBECAL
#include <libedataserverui/e-passwords.h>
#endif

63 64 65
#include "clock.h"

#include "calendar-window.h"
66 67 68
#include "clock-location.h"
#include "clock-location-tile.h"
#include "clock-map.h"
69
#include "clock-utils.h"
70
#include "set-timezone.h"
71
#include "system-timezone.h"
Mark McLoughlin's avatar
Mark McLoughlin committed
72

73 74
#define INTERNETSECOND (864)
#define INTERNETBEAT   (86400)
75

76 77
#define NEVER_SENSITIVE "never_sensitive"

78 79 80 81 82 83 84 85 86 87 88 89
#define N_GCONF_PREFS 12 /* Keep this in sync with the number of keys below! */
#define KEY_FORMAT		"format"
#define KEY_SHOW_SECONDS	"show_seconds"
#define KEY_SHOW_DATE		"show_date"
#define KEY_SHOW_WEATHER	"show_weather"
#define KEY_SHOW_TEMPERATURE	"show_temperature"
#define KEY_GMT_TIME		"gmt_time"
#define KEY_CUSTOM_FORMAT	"custom_format"
#define KEY_SHOW_WEEK		"show_week_numbers"
#define KEY_CITIES		"cities"
#define KEY_TEMPERATURE_UNIT	"temperature_unit"
#define KEY_SPEED_UNIT		"speed_unit"
90

91
static GConfEnumStringPair format_type_enum_map [] = {
92 93 94
	{ CLOCK_FORMAT_12,       "12-hour"  },
	{ CLOCK_FORMAT_24,       "24-hour"  },
	{ CLOCK_FORMAT_UNIX,     "unix"     },
95
	{ CLOCK_FORMAT_INTERNET, "internet" },
96 97
	{ CLOCK_FORMAT_CUSTOM,   "custom"   },
	{ 0, NULL }
98 99
};

100 101 102 103 104 105 106
enum {
	COL_CITY_NAME = 0,
	COL_CITY_TZ,
        COL_CITY_LOC,
	COL_CITY_LAST
};

107
typedef struct _ClockData ClockData;
108

109
struct _ClockData {
110
	/* widgets */
111
	GtkWidget *applet;
112

113 114 115 116 117 118 119 120 121
        GtkWidget *panel_button;	/* main toggle button for the whole clock */

	GtkWidget *main_obox;		/* orientable box inside panel_button */
        GtkWidget *weather_obox;        /* orientable box for the weather widgets */

	GtkWidget *clockw;		/* main label for the date/time display */

        GtkWidget *panel_weather_icon;
        GtkWidget *panel_temperature_label;
122

123
	GtkWidget *props;
124
	GtkWidget *about;
125
	GtkWidget *calendar_popup;
126

127 128 129
        GtkWidget *clock_vbox;
	GtkSizeGroup *clock_group;

130
	GtkBuilder *builder;
131 132 133 134 135 136 137 138 139

        /* Preferences dialog */
        GtkWidget *prefs_window;
        GtkTreeView *prefs_locations;

	GtkWidget *prefs_location_add_button;
	GtkWidget *prefs_location_edit_button;
	GtkWidget *prefs_location_remove_button;

140 141
	GWeatherLocationEntry *location_entry;
        GWeatherTimezoneMenu *zone_combo;
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

	GtkWidget *time_settings_button;
	GtkWidget *calendar;
	GtkWidget *hours_spin;
	GtkWidget *minutes_spin;
	GtkWidget *seconds_spin;
	GtkWidget *set_time_button;

	GtkListStore *cities_store;
        GtkWidget *cities_section;
        GtkWidget *map_section;
        GtkWidget *map_widget;

        /* Window to set the time */
	GtkWidget *set_time_window;
	GtkWidget *current_time_label;

159
	/* preferences */
160 161 162 163 164
	ClockFormat  format;
	char        *custom_format;
	gboolean     showseconds;
	gboolean     showdate;
	gboolean     gmt_time;
165
	gboolean     showweek;
166 167 168 169 170 171 172
        gboolean     show_weather;
        gboolean     show_temperature;

        gboolean     use_temperature_default;
        gboolean     use_speed_default;
        TempUnit     temperature_unit;
        SpeedUnit    speed_unit;
173

174 175 176 177
        /* Locations */
        GList *locations;
        GList *location_tiles;

178
	/* runtime data */
Mark McLoughlin's avatar
Mark McLoughlin committed
179 180
        time_t             current_time;
	char              *timeformat;
181
	char              *fallback_timeformat;
Mark McLoughlin's avatar
Mark McLoughlin committed
182 183 184
	guint              timeout;
	PanelAppletOrient  orient;
	int                size;
185
	GtkAllocation      old_allocation;
186

187
	SystemTimezone *systz;
188

189 190 191
	int fixed_width;
	int fixed_height;

192 193 194 195 196 197 198 199
        GtkWidget *showseconds_check;
        GtkWidget *showdate_check;
        GtkWidget *gmt_time_check;
        GtkWidget *custom_hbox;
        GtkWidget *custom_label;
        GtkWidget *custom_entry;
        gboolean   custom_format_shown;

200 201
	gboolean   can_handle_format_12;

202
	guint listeners [N_GCONF_PREFS];
203
};
204

205 206 207 208
/* Used to count the number of clock instances. It's there to know when we
 * should free resources that are shared. */
static int clock_numbers = 0;

209
static void  update_clock (ClockData * cd);
210
static void  update_tooltip (ClockData * cd);
211
static void  update_panel_weather (ClockData *cd);
212
static int   clock_timeout_callback (gpointer data);
213
static float get_itime    (time_t current_time);
214

215 216 217
static void set_atk_name_description (GtkWidget *widget,
                                      const char *name,
                                      const char *desc);
218 219 220 221 222 223
static void verb_display_properties_dialog (BonoboUIComponent *uic,
                                            ClockData         *cd,
                                            const gchar       *verbname);

static void display_properties_dialog (ClockData         *cd,
                                       gboolean           start_in_locations_page);
224 225 226 227 228 229
static void display_help_dialog       (BonoboUIComponent *uic,
				       ClockData         *cd,
				       const gchar       *verbname);
static void display_about_dialog      (BonoboUIComponent *uic,
				       ClockData         *cd,
				       const gchar       *verbname);
230
static void position_calendar_popup   (ClockData         *cd);
231
static void update_orient (ClockData *cd);
232 233 234
static void applet_change_orient (PanelApplet       *applet,
				  PanelAppletOrient  orient,
				  ClockData         *cd);
235

236
static void edit_hide (GtkWidget *unused, ClockData *cd);
237 238
static gboolean edit_delete (GtkWidget *unused, GdkEvent *event, ClockData *cd);
static void save_cities_store (ClockData *cd);
239

240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
/* ClockBox, an instantiable GtkBox */

typedef GtkBox      ClockBox;
typedef GtkBoxClass ClockBoxClass;

static GType clock_box_get_type (void);

G_DEFINE_TYPE (ClockBox, clock_box, GTK_TYPE_BOX)

static void
clock_box_init (ClockBox *box)
{
}

static void
clock_box_class_init (ClockBoxClass *klass)
{
}

/* Clock */

261 262 263 264 265 266 267
static inline GtkWidget *
_clock_get_widget (ClockData  *cd,
		   const char *name)
{
	return GTK_WIDGET (gtk_builder_get_object (cd->builder, name));
}

268 269 270 271 272
static void
unfix_size (ClockData *cd)
{
	cd->fixed_width = -1;
	cd->fixed_height = -1;
273
	gtk_widget_queue_resize (cd->panel_button);
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
static int
calculate_minimum_width (GtkWidget   *widget,
			 const gchar *text)
{
	PangoContext *context;
	PangoLayout  *layout;
	int	      width, height;
	int	      focus_width = 0;
	int	      focus_pad = 0;

	context = gtk_widget_get_pango_context (widget);

	layout = pango_layout_new (context);
	pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
	pango_layout_set_text (layout, text, -1);
	pango_layout_get_pixel_size (layout, &width, &height);
	g_object_unref (G_OBJECT (layout));
	layout = NULL;

	gtk_widget_style_get (widget,
			      "focus-line-width", &focus_width,
			      "focus-padding", &focus_pad,
			      NULL);

	width += 2 * (focus_width + focus_pad + widget->style->xthickness);

	return width;
}

305
static void
306 307
clock_set_timeout (ClockData *cd,
		   time_t     now)
308 309 310
{
	int timeouttime;

311 312 313 314 315 316 317 318 319 320 321 322 323 324
	if (cd->format == CLOCK_FORMAT_INTERNET) {
		int itime_ms;

		itime_ms = ((unsigned int) (get_itime (now) * 1000));

		if (!cd->showseconds)
			timeouttime = (999 - itime_ms % 1000) * 86.4 + 1;
		else {
			struct timeval tv;
			gettimeofday (&tv, NULL);
			itime_ms += (tv.tv_usec * 86.4) / 1000;
			timeouttime = ((999 - itime_ms % 1000) * 86.4) / 100 + 1;
		}
	} else {
325
 		struct timeval tv;
Vincent Untz's avatar
Vincent Untz committed
326

327
		gettimeofday (&tv, NULL);
328
 		timeouttime = (G_USEC_PER_SEC - tv.tv_usec)/1000+1;
Vincent Untz's avatar
Vincent Untz committed
329 330

		/* timeout of one minute if we don't care about the seconds */
331
 		if (cd->format != CLOCK_FORMAT_UNIX &&
332 333
		    !cd->showseconds && 
		    (!cd->set_time_window || !GTK_WIDGET_VISIBLE (cd->set_time_window)))
334
 			timeouttime += 1000 * (59 - now % 60);
335
 	}
336

337 338 339 340 341
	cd->timeout = g_timeout_add (timeouttime,
	                             clock_timeout_callback,
	                             cd);
}

342
static int
343
clock_timeout_callback (gpointer data)
344
{
345
	ClockData *cd = data;
346
	time_t new_time;
347

348
        time (&new_time);
349

350 351
	if (!cd->showseconds && 
	    (!cd->set_time_window || !GTK_WIDGET_VISIBLE (cd->set_time_window)) &&
352 353
	    cd->format != CLOCK_FORMAT_UNIX &&
	    cd->format != CLOCK_FORMAT_CUSTOM) {
354
		if (cd->format == CLOCK_FORMAT_INTERNET &&
355 356
		    (unsigned int)get_itime (new_time) !=
		    (unsigned int)get_itime (cd->current_time)) {
357 358 359 360 361
			update_clock (cd);
		} else if ((cd->format == CLOCK_FORMAT_12 ||
			    cd->format == CLOCK_FORMAT_24) &&
			   new_time / 60 != cd->current_time / 60) {
			update_clock (cd);
362
		}
363
	} else {
364 365
		update_clock (cd);
	}
366

367
	clock_set_timeout (cd, new_time);
368 369

	return FALSE;
370 371
}

372 373 374 375 376 377 378
static float
get_itime (time_t current_time)
{
	struct tm *tm;
	float itime;
	time_t bmt;

379
	/* BMT (Biel Mean Time) is GMT+1 */
380
	bmt = current_time + 3600;
381
	tm = gmtime (&bmt);
382
	itime = (tm->tm_hour*3600.0 + tm->tm_min*60.0 + tm->tm_sec)/86.4;
383 384 385

	return itime;
}
386

387 388 389 390 391 392 393 394 395 396 397 398
/* adapted from panel-toplevel.c */
static int
calculate_minimum_height (GtkWidget        *widget,
                          PanelAppletOrient orientation)
{
        PangoContext     *context;
        PangoFontMetrics *metrics;
        int               focus_width = 0;
        int               focus_pad = 0;
        int               ascent;
        int               descent;
        int               thickness;
399

400 401 402 403
        context = gtk_widget_get_pango_context (widget);
        metrics = pango_context_get_metrics (context,
                                             widget->style->font_desc,
                                             pango_context_get_language (context));
404

405 406
        ascent  = pango_font_metrics_get_ascent  (metrics);
        descent = pango_font_metrics_get_descent (metrics);
407

408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
        pango_font_metrics_unref (metrics);

        gtk_widget_style_get (widget,
                              "focus-line-width", &focus_width,
                              "focus-padding", &focus_pad,
                              NULL);

        if (orientation == PANEL_APPLET_ORIENT_UP
            || orientation == PANEL_APPLET_ORIENT_DOWN) {
                thickness = widget->style->ythickness;
        } else {
                thickness = widget->style->xthickness;
        }

        return PANGO_PIXELS (ascent + descent) + 2 * (focus_width + focus_pad + thickness);
}

static gboolean
use_two_line_format (ClockData *cd)
{
428
        if (cd->size >= 2 * calculate_minimum_height (cd->panel_button, cd->orient))
429 430 431 432 433
                return TRUE;

        return FALSE;
}

434 435 436
static char *
get_updated_timeformat (ClockData *cd,
			gboolean   safe)
437
{
438 439 440
 /* Show date in another line if panel is vertical, or
  * horizontal but large enough to hold two lines of text
  */
441
	char       *result;
442
	const char *time_format;
443
	char       *time_gravity_format;
444 445 446
	const char *date_format;
	char       *clock_format;

447
	if (cd->format == CLOCK_FORMAT_12)
448 449 450
		/* Translators: This is a strftime format string.
		 * It is used to display the time in 12-hours format (eg, like
		 * in the US: 8:10 am). The %p expands to am/pm. */
451 452
		time_format = cd->showseconds ? _("%l:%M:%S %p") : _("%l:%M %p");
	else
453 454 455
		/* Translators: This is a strftime format string.
		 * It is used to display the time in 24-hours format (eg, like
		 * in France: 20:10). */
456 457
		time_format = cd->showseconds ? _("%H:%M:%S") : _("%H:%M");

458 459 460 461 462 463 464 465 466
	if (!safe) {
		/* FIXME: we need this for bug #410169 in pango. We'll be able
		 * to remove this at a later stage. */
		time_gravity_format = g_strdup_printf ("<span gravity=\"south\">%s</span>",
						       time_format);
	} else {
		time_gravity_format = g_strdup (time_format);
	}

467
	if (!cd->showdate)
468
		clock_format = g_strdup (time_gravity_format);
469 470

	else {
471 472 473 474 475
		/* Translators: This is a strftime format string.
		 * It is used to display the date. Replace %e with %d if, when
		 * the day of the month as a decimal number is a single digit,
		 * it should begin with a 0 in your locale (e.g. "May 01"
		 * instead of "May  1"). */
476
		date_format = _("%a %b %e");
477

478
		if (use_two_line_format (cd))
479 480 481 482
			/* translators: reverse the order of these arguments
			 *              if the time should come before the
			 *              date on a clock in your locale.
			 */
483
			clock_format = g_strdup_printf (_("%1$s\n%2$s"),
484 485
							date_format,
							time_gravity_format);
486
		else
487 488 489 490
			/* translators: reverse the order of these arguments
			 *              if the time should come before the
			 *              date on a clock in your locale.
			 */
491
			clock_format = g_strdup_printf (_("%1$s, %2$s"),
492 493
							date_format,
							time_gravity_format);
494
	}
495

496
	g_free (time_gravity_format);
497

498
	result = g_locale_from_utf8 (clock_format, -1, NULL, NULL, NULL);
499
	g_free (clock_format);
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514

	/* let's be paranoid */
	if (!result)
		result = g_strdup ("???");

	return result;
}

static void
update_timeformat (ClockData *cd)
{
	g_free (cd->timeformat);
	cd->timeformat = get_updated_timeformat (cd, FALSE);
	g_free (cd->fallback_timeformat);
	cd->fallback_timeformat = get_updated_timeformat (cd, TRUE);
515 516
}

517
/* sets accessible name and description for the widget */
518
static void
519 520 521
set_atk_name_description (GtkWidget  *widget,
			  const char *name,
			  const char *desc)
522
{
523 524
	AtkObject *obj;
	obj = gtk_widget_get_accessible (widget);
525 526 527 528 529

	/* return if gail is not loaded */
	if (!GTK_IS_ACCESSIBLE (obj))
		return;

530 531 532 533
	if (desc != NULL)
		atk_object_set_description (obj, desc);
	if (name != NULL)
		atk_object_set_name (obj, name);
534
}
535 536

static void
537 538 539 540 541 542 543 544
update_location_tiles (ClockData *cd)
{
        GList *l;

        for (l = cd->location_tiles; l; l = l->next) {
                ClockLocationTile *tile;

                tile = CLOCK_LOCATION_TILE (l->data);
545
                clock_location_tile_refresh (tile, FALSE);
546 547 548 549 550
        }
}

static char *
format_time (ClockData *cd)
551
{
552
	struct tm *tm;
553 554
	char hour[256];
	char *utf8;
Mark McLoughlin's avatar
Mark McLoughlin committed
555

556 557
	utf8 = NULL;

558
	if (cd->gmt_time)
Mark McLoughlin's avatar
Mark McLoughlin committed
559
		tm = gmtime (&cd->current_time);
560
	else
Mark McLoughlin's avatar
Mark McLoughlin committed
561
		tm = localtime (&cd->current_time);
562

563
	if (cd->format == CLOCK_FORMAT_UNIX) {
564
		if (use_two_line_format (cd)) {
565 566 567
			utf8 = g_strdup_printf ("%lu\n%05lu",
						(unsigned long)(cd->current_time / 100000L),
						(unsigned long)(cd->current_time % 100000L));
568
		} else {
569 570
			utf8 = g_strdup_printf ("%lu",
						(unsigned long)cd->current_time);
571
		}
572
	} else if (cd->format == CLOCK_FORMAT_INTERNET) {
Mark McLoughlin's avatar
Mark McLoughlin committed
573
		float itime = get_itime (cd->current_time);
574
		if (cd->showseconds)
575
			utf8 = g_strdup_printf ("@%3.2f", itime);
576
		else
577
			utf8 = g_strdup_printf ("@%3d", (unsigned int) itime);
578 579 580 581 582 583 584 585
	} else if (cd->format == CLOCK_FORMAT_CUSTOM) {
		char *timeformat = g_locale_from_utf8 (cd->custom_format, -1,
						       NULL, NULL, NULL);
		if (!timeformat)
			strcpy (hour, "???");
		else if (strftime (hour, sizeof (hour), timeformat, tm) <= 0)
			strcpy (hour, "???");
		g_free (timeformat);
586 587

		utf8 = g_locale_to_utf8 (hour, -1, NULL, NULL, NULL);
588 589
	} else {
		if (strftime (hour, sizeof (hour), cd->timeformat, tm) <= 0)
590
			strcpy (hour, "???");
591 592

		utf8 = g_locale_to_utf8 (hour, -1, NULL, NULL, NULL);
593
        }
594

595
	if (!utf8)
596
		utf8 = g_strdup (hour);
597

598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
        return utf8;
}

static gchar *
format_time_24 (ClockData *cd)
{
	struct tm *tm;
	gchar buf[128];

	tm = localtime (&cd->current_time);
	strftime (buf, sizeof (buf) - 1, "%k:%M:%S", tm);
	return g_locale_to_utf8 (buf, -1, NULL, NULL, NULL);
}

static void
update_clock (ClockData * cd)
{
	gboolean use_markup;
        char *utf8;

        use_markup = FALSE;

	time (&cd->current_time);
        utf8 = format_time (cd);

	use_markup = FALSE;
        if (pango_parse_markup (utf8, -1, 0, NULL, NULL, NULL, NULL))
                use_markup = TRUE;

627 628 629 630 631
	if (use_markup)
		gtk_label_set_markup (GTK_LABEL (cd->clockw), utf8);
	else
		gtk_label_set_text (GTK_LABEL (cd->clockw), utf8);

632
	g_free (utf8);
633

634
	update_orient (cd);
635
	gtk_widget_queue_resize (cd->panel_button);
636

637
	update_tooltip (cd);
638 639 640 641 642 643 644 645 646 647 648
        update_location_tiles (cd);

        if (cd->map_widget && cd->calendar_popup && GTK_WIDGET_VISIBLE (cd->calendar_popup))
                clock_map_update_time (CLOCK_MAP (cd->map_widget));

	if (cd->current_time_label &&
	    GTK_WIDGET_VISIBLE (cd->current_time_label)) {
		utf8 = format_time_24 (cd);
		gtk_label_set_text (GTK_LABEL (cd->current_time_label), utf8);
		g_free (utf8);
	}
649 650 651 652 653
}

static void
update_tooltip (ClockData * cd)
{
654
        if (!cd->showdate) {
655 656 657
		struct tm *tm;
		char date[256];
		char *utf8, *loc;
658 659 660 661
                char *zone;
                time_t now_t;
                struct tm now;
                char *tip;
662 663 664 665 666 667 668 669

		if (cd->gmt_time)
			tm = gmtime (&cd->current_time);
		else
			tm = localtime (&cd->current_time);

		utf8 = NULL;

670 671 672 673
                /* Show date in tooltip. */
		/* Translators: This is a strftime format string.
		 * It is used to display a date. Please leave "%%s" as it is:
		 * it will be used to insert the timezone name later. */
674
                loc = g_locale_from_utf8 (_("%A %B %d (%%s)"), -1, NULL, NULL, NULL);
675 676 677 678 679 680 681
                if (!loc)
                        strcpy (date, "???");
                else if (strftime (date, sizeof (date), loc, tm) <= 0)
                        strcpy (date, "???");
                g_free (loc);

                utf8 = g_locale_to_utf8 (date, -1, NULL, NULL, NULL);
682 683 684 685 686 687 688

                /* Add the timezone name */

                tzset ();
                time (&now_t);
                localtime_r (&now_t, &now);

689
                if (now.tm_isdst > 0) {
690 691 692 693 694 695 696 697
                        zone = tzname[1];
                } else {
                        zone = tzname[0];
                }

                tip = g_strdup_printf (utf8, zone);

                gtk_widget_set_tooltip_text (cd->panel_button, tip);
698
                g_free (utf8);
699
                g_free (tip);
700 701
        } else {
#ifdef HAVE_LIBECAL
702
		if (cd->calendar_popup)
703
			gtk_widget_set_tooltip_text (cd->panel_button,
704
						     _("Click to hide your appointments and tasks"));
705
		else
706
			gtk_widget_set_tooltip_text (cd->panel_button,
707
						     _("Click to view your appointments and tasks"));
708
#else
709
		if (cd->calendar_popup)
710
			gtk_widget_set_tooltip_text (cd->panel_button,
711
						     _("Click to hide month calendar"));
712
		else
713
			gtk_widget_set_tooltip_text (cd->panel_button,
714
						     _("Click to view month calendar"));
715 716
#endif
        }
717 718
}

719 720 721
static void
refresh_clock (ClockData *cd)
{
722
	unfix_size (cd);
Mark McLoughlin's avatar
Mark McLoughlin committed
723
	update_clock (cd);
724 725 726 727 728
}

static void
refresh_clock_timeout(ClockData *cd)
{
729
	unfix_size (cd);
730

731 732
	update_timeformat (cd);

733 734 735
	if (cd->timeout)
		g_source_remove (cd->timeout);

Mark McLoughlin's avatar
Mark McLoughlin committed
736
	update_clock (cd);
737

738
	clock_set_timeout (cd, cd->current_time);
739 740
}

741 742 743 744 745 746 747 748 749 750 751 752
/**
 * This is like refresh_clock_timeout(), except that we only care about whether
 * the time actually changed. We don't care about the format.
 */
static void
refresh_click_timeout_time_only (ClockData *cd)
{
	if (cd->timeout)
		g_source_remove (cd->timeout);
	clock_timeout_callback (cd);
}

753
static void
754 755 756 757 758 759 760 761 762 763 764 765 766
free_locations (ClockData *cd)
{
        GList *l;

        for (l = cd->locations; l; l = l->next)
                g_object_unref (l->data);

        g_list_free (cd->locations);
        cd->locations = NULL;
}

static void
destroy_clock (GtkWidget * widget, ClockData *cd)
767
{
768 769 770 771 772 773 774 775 776
	GConfClient *client;
	int          i;

	client = gconf_client_get_default ();

	for (i = 0; i < N_GCONF_PREFS; i++)
		gconf_client_notify_remove (
				client, cd->listeners [i]);

777 778
	g_object_unref (G_OBJECT (client));

Mark McLoughlin's avatar
Mark McLoughlin committed
779
	if (cd->timeout)
780
		g_source_remove (cd->timeout);
Mark McLoughlin's avatar
Mark McLoughlin committed
781 782
        cd->timeout = 0;

783 784
	if (cd->about)
		gtk_widget_destroy (cd->about);
Mark McLoughlin's avatar
Mark McLoughlin committed
785
        cd->about = NULL;
786

Mark McLoughlin's avatar
Mark McLoughlin committed
787
	if (cd->props)
788
		gtk_widget_destroy (cd->props);
Mark McLoughlin's avatar
Mark McLoughlin committed
789
        cd->props = NULL;
790

791 792 793 794
	if (cd->calendar_popup)
		gtk_widget_destroy (cd->calendar_popup);
	cd->calendar_popup = NULL;

795
	g_free (cd->timeformat);
796
	g_free (cd->fallback_timeformat);
797
	g_free (cd->custom_format);
798 799 800 801 802 803

        free_locations (cd);

        g_list_free (cd->location_tiles);
        cd->location_tiles = NULL;

804 805 806 807 808
	if (cd->systz) {
		g_object_unref (cd->systz);
		cd->systz = NULL;
	}

809 810 811 812 813
        if (cd->cities_store) {
                g_object_unref (cd->cities_store);
                cd->cities_store = NULL;
        }

814 815 816 817 818
	if (cd->builder) {
		g_object_unref (cd->builder);
		cd->builder = NULL;
	}

819
	g_free (cd);
820 821 822 823 824 825 826

#ifdef HAVE_LIBECAL
	if (clock_numbers > 0) {
		e_passwords_shutdown ();
		clock_numbers--;
	}
#endif
827 828
}

829
static gboolean
830 831 832
close_on_escape (GtkWidget       *widget,
		 GdkEventKey     *event,
		 GtkToggleButton *toggle_button)
833
{
834
	if (event->keyval == GDK_Escape) {
835
		gtk_toggle_button_set_active (toggle_button, FALSE);
836 837 838 839 840 841
		return TRUE;
	}

	return FALSE;
}

842
static gboolean
843 844 845
delete_event (GtkWidget       *widget,
	      GdkEvent        *event,
	      GtkToggleButton *toggle_button)
846
{
847
	gtk_toggle_button_set_active (toggle_button, FALSE);
848 849 850
	return TRUE;
}

851 852 853 854 855 856 857 858 859 860
static void
edit_locations_cb (CalendarWindow *calwin, gpointer data)
{
        ClockData *cd;

        cd = data;

        display_properties_dialog (cd, TRUE);
}

861
static GtkWidget *
862
create_calendar (ClockData *cd)
Mark McLoughlin's avatar
Mark McLoughlin committed
863
{
864 865
	GtkWidget *window;
	char      *prefs_dir;
Mark McLoughlin's avatar
Mark McLoughlin committed
866

867 868 869 870 871
	prefs_dir = panel_applet_get_preferences_key (PANEL_APPLET (cd->applet));
	window = calendar_window_new (&cd->current_time,
				      prefs_dir,
				      cd->orient == PANEL_APPLET_ORIENT_UP);
	g_free (prefs_dir);
Mark McLoughlin's avatar
Mark McLoughlin committed
872

873 874 875 876 877 878
	calendar_window_set_utc_time (CALENDAR_WINDOW (window),
				      cd->gmt_time);
	calendar_window_set_show_weeks (CALENDAR_WINDOW (window),
					cd->showweek);
	calendar_window_set_time_format (CALENDAR_WINDOW (window),
					 cd->format);
Mark McLoughlin's avatar
Mark McLoughlin committed
879

880 881 882
        gtk_window_set_screen (GTK_WINDOW (window),
			       gtk_widget_get_screen (cd->applet));

883 884
        g_signal_connect (window, "edit-locations",
                          G_CALLBACK (edit_locations_cb), cd);
885 886

	g_signal_connect (window, "delete_event",
887
			  G_CALLBACK (delete_event), cd->panel_button);
888
	g_signal_connect (window, "key_press_event",
889
			  G_CALLBACK (close_on_escape), cd->panel_button);
890

891
	return window;
892 893 894
}

static void
895
position_calendar_popup (ClockData *cd)
896 897 898
{
	GtkRequisition  req;
	GdkScreen      *screen;
899
	GdkRectangle    monitor;
900
	GdkGravity      gravity = GDK_GRAVITY_NORTH_WEST;
901 902 903
	int             button_w, button_h;
	int             x, y;
	int             w, h;
904 905
	int             i, n;
	gboolean        found_monitor = FALSE;
906

907
	/* Get root origin of the toggle button, and position above that. */
908
	gdk_window_get_origin (cd->panel_button->window, &x, &y);
909

910 911
	gtk_window_get_size (GTK_WINDOW (cd->calendar_popup), &w, &h);
	gtk_widget_size_request (cd->calendar_popup, &req);
912 913 914
	w = req.width;
	h = req.height;

915 916
	button_w = cd->panel_button->allocation.width;
	button_h = cd->panel_button->allocation.height;
917

918
	screen = gtk_window_get_screen (GTK_WINDOW (cd->calendar_popup));
919

920 921 922 923 924 925 926 927 928 929
	n = gdk_screen_get_n_monitors (screen);
	for (i = 0; i < n; i++) {
		gdk_screen_get_monitor_geometry (screen, i, &monitor);
		if (x >= monitor.x && x <= monitor.x + monitor.width &&
		    y >= monitor.y && y <= monitor.y + monitor.height) {
			found_monitor = TRUE;
			break;
		}
	}

930
	if (!found_monitor) {
931 932 933 934 935 936 937
		/* eek, we should be on one of those xinerama
		   monitors */
		monitor.x = 0;
		monitor.y = 0;
		monitor.width = gdk_screen_get_width (screen);
		monitor.height = gdk_screen_get_height (screen);
	}
938

939 940 941 942 943 944
	/* Based on panel orientation, position the popup.
	 * Ignore window gravity since the window is undecorated.
	 * The orientations are all named backward from what
	 * I expected.
	 */
	switch (cd->orient) {
945
	case PANEL_APPLET_ORIENT_RIGHT:
946
		x += button_w;
947 948
		if ((y + h) > monitor.y + monitor.height)
			y -= (y + h) - (monitor.y + monitor.height);
949 950 951 952 953 954

		if ((y + h) > (monitor.height / 2))
			gravity = GDK_GRAVITY_SOUTH_WEST;
		else
			gravity = GDK_GRAVITY_NORTH_WEST;

955
		break;
956
	case PANEL_APPLET_ORIENT_LEFT:
957
		x -= w;
958 959
		if ((y + h) > monitor.y + monitor.height)
			y -= (y + h) - (monitor.y + monitor.height);
960 961 962 963 964 965

		if ((y + h) > (monitor.height / 2))
			gravity = GDK_GRAVITY_SOUTH_EAST;
		else
			gravity = GDK_GRAVITY_NORTH_EAST;

966
		break;
967
	case PANEL_APPLET_ORIENT_DOWN:
968
		y += button_h;
969 970
		if ((x + w) > monitor.x + monitor.width)
			x -= (x + w) - (monitor.x + monitor.width);
971 972 973

		gravity = GDK_GRAVITY_NORTH_WEST;

974
		break;
975
	case PANEL_APPLET_ORIENT_UP:
976
		y -= h;
977 978
		if ((x + w) > monitor.x + monitor.width)
			x -= (x + w) - (monitor.x + monitor.width);
979 980 981

		gravity = GDK_GRAVITY_SOUTH_WEST;

982 983
		break;
	}
984

985 986
	gtk_window_move (GTK_WINDOW (cd->calendar_popup), x, y);
	gtk_window_set_gravity (GTK_WINDOW (cd->calendar_popup), gravity);
987 988 989
}

static void
990
add_to_group (GtkWidget *child, gpointer data)
991
{
992
	GtkSizeGroup *group = data;
993

994 995
	gtk_size_group_add_widget (group, child);
}
996

997 998 999 1000
static void
create_clock_window (ClockData *cd)
{
	GtkWidget *locations_box;
1001

1002 1003
        locations_box = calendar_window_get_locations_box (CALENDAR_WINDOW (cd->calendar_popup));
        gtk_widget_show (locations_box);
1004

1005 1006
	cd->clock_vbox = gtk_vbox_new (FALSE, 6);
	gtk_container_add (GTK_CONTAINER (locations_box), cd->clock_vbox);
1007

1008 1009
	cd->clock_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
	gtk_size_group_set_ignore_hidden (cd->clock_group, FALSE);
1010

1011 1012 1013 1014
	gtk_container_foreach (GTK_CONTAINER (locations_box),
			       (GtkCallback) add_to_group,
			       cd->clock_group);
}
1015

1016 1017 1018 1019 1020
static gint
sort_locations_by_name (gconstpointer a, gconstpointer b)
{
        ClockLocation *loc_a = (ClockLocation *) a;
        ClockLocation *loc_b = (ClockLocation *) b;
1021

1022 1023
        const char *name_a = clock_location_get_display_name (loc_a);
        const char *name_b = clock_location_get_display_name (loc_b);
1024

1025 1026
        return strcmp (name_a, name_b);
}
1027

1028 1029 1030 1031 1032 1033
static void
create_cities_store (ClockData *cd)
{
	GtkTreeIter iter;
        GList *cities = cd->locations;
        GList *list = NULL;
1034

1035 1036 1037 1038
        if (cd->cities_store) {
                g_object_unref (G_OBJECT (cd->cities_store));
                cd->cities_store = NULL;
        }
1039

1040 1041 1042 1043 1044
	/* City name, Timezone name, Coordinates in lat/long */
	cd->cities_store = g_object_ref (gtk_list_store_new (COL_CITY_LAST,
                                                             G_TYPE_STRING,		/* COL_CITY_NAME */
                                                             G_TYPE_STRING,		/* COL_CITY_TZ */
                                                             CLOCK_LOCATION_TYPE));	/* COL_CITY_LOC */
1045

1046 1047
        list = g_list_copy (cities);
        list = g_list_sort (list, sort_locations_by_name);
1048

1049 1050 1051
	while (list) {
		ClockLocation *loc = CLOCK_LOCATION (list->data);

1052 1053
		gtk_list_store_append (cd->cities_store, &iter);
		gtk_list_store_set (cd->cities_store, &iter,
1054
				    COL_CITY_NAME, clock_location_get_display_name (loc),
1055 1056 1057 1058 1059
				    /* FIXME: translate the timezone */
				    COL_CITY_TZ, clock_location_get_timezone (loc),
                                    COL_CITY_LOC, loc,
				    -1);

1060
                list = list->next;
1061
	}
Matthias Clasen's avatar
Matthias Clasen committed
1062 1063 1064

	 
	if (cd->prefs_window) { 	 
1065
		GtkWidget *widget = _clock_get_widget (cd, "cities_list"); 	 
Matthias Clasen's avatar
Matthias Clasen committed
1066 1067 1068
		gtk_tree_view_set_model (GTK_TREE_VIEW (widget), 	 
		GTK_TREE_MODEL (cd->cities_store)); 	 
	}
1069 1070
}

1071 1072
static gint
sort_locations_by_time (gconstpointer a, gconstpointer b)
1073
{
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086
        ClockLocation *loc_a = (ClockLocation *) a;
        ClockLocation *loc_b = (ClockLocation *) b;

        struct tm tm_a;
        struct tm tm_b;
        gint ret;

        clock_location_localtime (loc_a, &tm_a);
        clock_location_localtime (loc_b, &tm_b);

        ret = (tm_a.tm_year == tm_b.tm_year) ? 0 : 1;
        if (ret) {
                return (tm_a.tm_year < tm_b.tm_year) ? -1 : 1;
Mark McLoughlin's avatar
Mark McLoughlin committed
1087 1088
        }

1089 1090 1091
        ret = (tm_a.tm_mon == tm_b.tm_mon) ? 0 : 1;
        if (ret) {
                return (tm_a.tm_mon < tm_b.tm_mon) ? -1 : 1;
Mark McLoughlin's avatar
Mark McLoughlin committed
1092 1093
        }

1094 1095 1096 1097
        ret = (tm_a.tm_mday == tm_b.tm_mday) ? 0 : 1;
        if (ret) {
                return (tm_a.tm_mday < tm_b.tm_mday) ? -1 : 1;
        }
1098

1099 1100 1101
        ret = (tm_a.tm_hour == tm_b.tm_hour) ? 0 : 1;
        if (ret) {
                return (tm_a.tm_hour < tm_b.tm_hour) ? -1 : 1;
1102
        }
1103

1104 1105 1106
        ret = (tm_a.tm_min == tm_b.tm_min) ? 0 : 1;
        if (ret) {
                return (tm_a.tm_min < tm_b.tm_min) ? -1 : 1;
1107 1108
        }

1109 1110 1111 1112
        ret = (tm_a.tm_sec == tm_b.tm_sec) ? 0 : 1;
        if (ret) {
                return (tm_a.tm_sec < tm_b.tm_sec) ? -1 : 1;
        }
1113

1114
        return ret;
1115 1116 1117
}

static void
1118
location_tile_pressed_cb (ClockLocationTile *tile, gpointer data)
1119
{
1120 1121
        ClockData *cd = data;
        ClockLocation *loc;
1122

1123
        loc = clock_location_tile_get_location (tile);
1124

1125
        clock_map_blink_location (CLOCK_MAP (cd->map_widget), loc);
1126

1127
        g_object_unref (loc);
1128 1129
}

1130 1131
static ClockFormat
location_tile_need_clock_format_cb(ClockLocationTile *tile, gpointer data)
1132
{
1133
        ClockData *cd = data;
1134

1135
        return cd->format;
1136
}
1137

1138
static void
1139
create_cities_section (ClockData *cd)
1140
{
1141 1142 1143
        GList *node;
        ClockLocationTile *city;
        GList *cities;
1144

1145 1146 1147 1148
        if (cd->cities_section) {
                gtk_widget_destroy (cd->cities_section);
                cd->cities_section = NULL;
        }
1149

1150 1151
        g_list_free (cd->location_tiles);
        cd->location_tiles = NULL;
1152

1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174
        cd->cities_section = gtk_vbox_new (FALSE, 6);
        gtk_container_set_border_width (GTK_CONTAINER (cd->cities_section), 0);

	cities = cd->locations;
        if (g_list_length (cities) == 0) {
                /* if the list is empty, don't bother showing the
                   cities section */
                gtk_widget_hide (cd->cities_section);
                return;
        }

        /* Copy the existing list, so we can sort it nondestructively */
        node = g_list_copy (cities);
        node = g_list_sort (node, sort_locations_by_time);
        node = g_list_reverse (node);

        while (node) {
                ClockLocation *loc = node->data;

                city = clock_location_tile_new (loc, CLOCK_FACE_SMALL);
                g_signal_connect (city, "tile-pressed",
                                  G_CALLBACK (location_tile_pressed_cb), cd);
1175 1176 1177
                g_signal_connect (city, "need-clock-format",
                                  G_CALLBACK (location_tile_need_clock_format_cb), cd);

1178 1179 1180 1181 1182 1183
                gtk_box_pack_start (GTK_BOX (cd->cities_section),
                                    GTK_WIDGET (city),
                                    FALSE, FALSE, 0);

                cd->location_tiles = g_list_prepend (cd->location_tiles, city);

1184 1185
                clock_location_tile_refresh (city, TRUE);

1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
                node = g_list_next (node);
        }

        g_list_free (node);

        gtk_box_pack_end (GTK_BOX (cd->clock_vbox),
                          cd->cities_section, FALSE, FALSE, 0);

        gtk_widget_show_all (cd->cities_section);
}

static GList *
map_need_locations_cb (ClockMap *map, gpointer data)
{
        ClockData *cd = data;

        return cd->locations;
}

static void
create_map_section (ClockData *cd)
{
        ClockMap *map;

        if (cd->map_widget) {
                gtk_widget_destroy (GTK_WIDGET (cd->map_section));
                cd->map_widget = NULL;
        }

        map = clock_map_new ();
        g_signal_connect (map, "need-locations",
                          G_CALLBACK (map_need_locations_cb), cd);

        cd->map_section = gtk_alignment_new (0, 0, 1, 1);
        cd->map_widget = GTK_WIDGET (map);

        gtk_container_add (GTK_CONTAINER (cd->map_section), cd->map_widget);

        gtk_alignment_set_padding (GTK_ALIGNMENT (cd->map_section), 1, 1, 1, 1);

        gtk_box_pack_start (GTK_BOX (cd->clock_vbox), cd->map_section, FALSE, FALSE, 0);
        gtk_widget_show (cd->map_widget);
        gtk_widget_show (cd->map_section);
}

static void
update_calendar_popup (ClockData *cd)
{
        if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd->panel_button))) {
                if (cd->calendar_popup) {
                        gtk_widget_destroy (cd->calendar_popup);
                        cd->calendar_popup = NULL;
                        cd->cities_section = NULL;
                        cd->map_section = NULL;
                        cd->map_widget = NULL;
1241
			cd->clock_vbox = NULL;
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
			
        		g_list_free (cd->location_tiles);
        		cd->location_tiles = NULL;
                }
		update_tooltip (cd);
                return;
        }

        if (!cd->calendar_popup) {
                cd->calendar_popup = create_calendar (cd);
                g_object_add_weak_pointer (G_OBJECT (cd->calendar_popup),
                                           (gpointer *) &cd->calendar_popup);
		update_tooltip (cd);

                create_clock_window (cd);
                create_cities_store (cd);
                create_cities_section (cd);
                create_map_section (cd);
        }

        if (cd->calendar_popup && GTK_WIDGET_REALIZED (cd->panel_button)) {
		calendar_window_refresh (CALENDAR_WINDOW (cd->calendar_popup));
		position_calendar_popup (cd);
		gtk_window_present (GTK_WINDOW (cd->calendar_popup));
        }
}

static void
toggle_calendar (GtkWidget *button,
                 ClockData *cd)
{
1273 1274 1275
	/* if time is wrong, the user might try to fix it by clicking on the
	 * clock */
	refresh_click_timeout_time_only (cd);
1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
	update_calendar_popup (cd);
}

static gboolean
do_not_eat_button_press (GtkWidget      *widget,
                         GdkEventButton *event)
{
	if (event->button != 1)
		g_signal_stop_emission_by_name (widget, "button_press_event");

	return FALSE;
}

/* Don't request smaller size then the last one we did, this avoids
   jumping when proportional fonts are used.  We must take care to
   call "unfix_size" whenever options are changed or such where
   we'd want to forget the fixed size */
static void
clock_size_request (GtkWidget *clock, GtkRequisition *req, gpointer data)
{
	ClockData *cd = data;

	if (req->width > cd->fixed_width)
		cd->fixed_width = req->width;
	if (req->height > cd->fixed_height)
		cd->fixed_height = req->height;
	req->width = cd->fixed_width;
	req->height = cd->fixed_height;
}

static void
clock_update_text_gravity (GtkWidget *label)
{
	PangoLayout  *layout;
	PangoContext *context;

	layout = gtk_label_get_layout (GTK_LABEL (label));
	context = pango_layout_get_context (layout);
	pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
}

static inline void
force_no_focus_padding (GtkWidget *widget)
{
        static gboolean first_time = TRUE;

        if (first_time) {
                gtk_rc_parse_string ("\n"
                                     "   style \"clock-applet-button-style\"\n"
                                     "   {\n"
                                     "      GtkWidget::focus-line-width=0\n"
                                     "      GtkWidget::focus-padding=0\n"
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
                                     "   }\n"
                                     "\n"
                                     "    widget \"*.clock-applet-button\" style \"clock-applet-button-style\"\n"
                                     "\n");
                first_time = FALSE;
        }

        gtk_widget_set_name (widget, "clock-applet-button");
}

1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352
static GtkWidget *
create_main_clock_button (void)
{
        GtkWidget *button;

        button = gtk_toggle_button_new ();
	gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);

        force_no_focus_padding (button);

        return button;
}

static GtkWidget *
create_main_clock_label (ClockData *cd)
1353
{
1354
        GtkWidget *label;
1355

1356 1357
        label = gtk_label_new (NULL);
	g_signal_connect (label, "size_request",
1358 1359
			  G_CALLBACK (clock_size_request),
			  cd);
1360
	g_signal_connect_swapped (label, "style_set",
1361 1362
				  G_CALLBACK (unfix_size),
				  cd);
1363 1364 1365
	gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
	clock_update_text_gravity (label);
	g_signal_connect (label, "screen-changed",
1366 1367
			  G_CALLBACK (clock_update_text_gravity),
			  NULL);
1368

1369 1370
        return label;
}
1371

1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
static gboolean
weather_tooltip (GtkWidget   *widget,
                 gint         x,
                 gint         y,
                 gboolean     keyboard_mode,
                 GtkTooltip  *tooltip,
                 ClockData   *cd)
{
        GList *locations, *l;
        WeatherInfo *info;
1382

1383
        locations = cd->locations;
1384

1385
        for (l = locations; l; l = l->next) {
1386 1387 1388
		ClockLocation *location = l->data;
                if (clock_location_is_current (location)) {
                        info = clock_location_get_weather_info (location);
1389 1390
                        if (!info || !weather_info_is_valid (info))
                                continue;
1391

1392
                        weather_info_setup_tooltip (info, location, tooltip);
Vincent Untz's avatar