weather-summary.c 21.5 KB
Newer Older
1 2
/*  $Id$
 *
Nick Schermer's avatar
Nick Schermer committed
3
 *  Copyright (c) 2003-2007 Xfce Development Team
4
 *
5 6 7
 *  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
8 9 10 11 12
 *  (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
13
 *  GNU Library General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16 17 18 19 20
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
21
#include <config.h>
22 23 24 25
#endif

#include <libxfcegui4/libxfcegui4.h>

Nick Schermer's avatar
Nick Schermer committed
26 27 28
#include "weather-parsers.h"
#include "weather-data.h"
#include "weather.h"
29

Nick Schermer's avatar
Nick Schermer committed
30 31 32
#include "weather-summary.h"
#include "weather-translate.h"
#include "weather-icon.h"
33

34

35 36 37
static gboolean lnk_clicked (GtkTextTag *tag, GObject *obj,
			     GdkEvent *event, GtkTextIter *iter,
			     GtkWidget *textview);
38

39 40 41 42 43 44
#define BORDER                           8
#define APPEND_BTEXT(text)               gtk_text_buffer_insert_with_tags(GTK_TEXT_BUFFER(buffer),\
                                                                          &iter, text, -1, btag, NULL);
#define APPEND_TEXT_ITEM_REAL(text)      gtk_text_buffer_insert(GTK_TEXT_BUFFER(buffer), \
                                                                &iter, text, -1);\
                                         g_free (value);
45 46
#define APPEND_TEXT_ITEM(text, item)     value = g_strdup_printf("\t%s%s%s %s\n",\
                                                                 text, text?": ":"", \
47 48 49
                                                                 get_data(data, item),\
                                                                 get_unit(unit, item));\
                                         APPEND_TEXT_ITEM_REAL(value);
50 51 52 53 54 55 56 57 58 59
#define APPEND_LINK_ITEM(prefix, text, url, lnk_tag) \
					 gtk_text_buffer_insert(GTK_TEXT_BUFFER(buffer), \
                                                                &iter, prefix, -1);\
					 gtk_text_buffer_insert_with_tags(GTK_TEXT_BUFFER(buffer), \
                                                                &iter, text, -1, lnk_tag, NULL);\
					 gtk_text_buffer_insert(GTK_TEXT_BUFFER(buffer), \
                                                                &iter, "\n", -1);\
					 g_object_set_data_full(G_OBJECT(lnk_tag), "url", g_strdup(url), g_free); \
					 g_signal_connect(G_OBJECT(lnk_tag), "event", \
						G_CALLBACK(lnk_clicked), NULL); 
60

61 62


63 64
static GtkTooltips *tooltips = NULL;

65 66 67 68 69 70
static gboolean lnk_clicked (GtkTextTag *tag, GObject *obj,
			     GdkEvent *event, GtkTextIter *iter,
			     GtkWidget *textview)
{
  if (event->type == GDK_BUTTON_RELEASE) {
    const gchar *url = g_object_get_data(G_OBJECT(tag), "url");
71
    gchar *str = g_strdup_printf("exo-open --launch WebBrowser %s", url);
72

73
    g_spawn_command_line_async(str, NULL);
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
    g_free(str);
  } else if (event->type == GDK_LEAVE_NOTIFY) {
     gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(obj),
				GTK_TEXT_WINDOW_TEXT), NULL);
  } 
  return FALSE;
}

static gboolean
icon_clicked (GtkWidget      *widget,
              GdkEventButton *event,
              gpointer        user_data)
{
  return lnk_clicked(user_data, NULL, (GdkEvent *)(event), NULL, NULL);
}

static GdkCursor *hand_cursor = NULL;
static GdkCursor *text_cursor = NULL;
static gboolean on_icon = FALSE;
static gboolean view_motion_notify(GtkWidget *widget,
				   GdkEventMotion *event,
				   GtkWidget *view)
{
  GtkTextBuffer *buffer;

  buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));

  if (event->x != -1 && event->y != -1) {
    gint bx, by;
    GtkTextIter iter;
    GSList *tags;
    GSList *cur;

    gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(view), 
    						GTK_TEXT_WINDOW_WIDGET,
    						event->x, event->y, &bx, &by);
    gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(view),
    						&iter, bx, by);
    tags = gtk_text_iter_get_tags(&iter);
    for (cur = tags; cur != NULL; cur = cur->next) {
      GtkTextTag *tag = cur->data;
      if (g_object_get_data(G_OBJECT(tag), "url")) {
        gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(view),
				   GTK_TEXT_WINDOW_TEXT), hand_cursor);
        return FALSE;
      }
    }
  }
  if (!on_icon)
    gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(view),
			     GTK_TEXT_WINDOW_TEXT), text_cursor);
  return FALSE;
}

static gboolean icon_motion_notify(GtkWidget *widget,
				   GdkEventMotion *event,
				   GtkWidget *view)
{
  on_icon = TRUE;
  gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(view),
			     GTK_TEXT_WINDOW_TEXT), hand_cursor);
  return FALSE;
}

static gboolean view_leave_notify(GtkWidget *widget,
				   GdkEventMotion *event,
				   GtkWidget *view)
{
  on_icon = FALSE;
  gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(view),
			     GTK_TEXT_WINDOW_TEXT), text_cursor);
  return FALSE;
}

static GtkWidget *weather_channel_evt = NULL;
static void view_scrolled_cb (GtkAdjustment *adj, GtkWidget *view)
{
  if (weather_channel_evt) {
    gint x, y, x1, y1;
    x1 = view->allocation.width - 61 - 5;
    y1 = view->requisition.height - 61 - 5;
    gtk_text_view_buffer_to_window_coords(
			GTK_TEXT_VIEW(view),
			GTK_TEXT_WINDOW_TEXT, x1, y1, &x, &y);
    gtk_text_view_move_child(GTK_TEXT_VIEW(view), 
			weather_channel_evt, x, y);
  }
}

static void view_size_allocate_cb	(GtkWidget	*widget,
					 GtkAllocation	*allocation,
					 gpointer	 data)
{
  view_scrolled_cb(NULL, GTK_WIDGET(data));
}
169 170


171
static GtkWidget *
172 173
create_summary_tab (xml_weather *data,
                    units        unit)
174
{
175
  GtkTextBuffer *buffer;
176
  GtkTextIter    iter;
177
  GtkTextTag    *btag, *ltag0, *ltag1, *ltag2, *ltag3, *ltag4;
178 179
  gchar         *value, *date, *wind, *sun_val, *vis;
  GtkWidget     *view, *frame, *scrolled;
180 181 182
  GdkColor       lnk_color;
  GtkAdjustment *adj;
  GtkWidget     *weather_channel_icon;
183 184 185

  view = gtk_text_view_new ();
  gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
186
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
  frame = gtk_frame_new (NULL);
  scrolled = gtk_scrolled_window_new (NULL, NULL);

  gtk_container_add (GTK_CONTAINER (scrolled), view);
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled),
                                  GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

  gtk_container_set_border_width (GTK_CONTAINER (frame), BORDER);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
  gtk_container_add (GTK_CONTAINER (frame), scrolled);

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (buffer), &iter, 0);
  btag =
    gtk_text_buffer_create_tag (buffer, NULL, "weight", PANGO_WEIGHT_BOLD,
                                NULL);

204 205 206 207 208 209 210
  gdk_color_parse("#0000ff", &lnk_color);
  ltag0 = gtk_text_buffer_create_tag(buffer, "lnk0", "foreground-gdk", &lnk_color, NULL);
  ltag1 = gtk_text_buffer_create_tag(buffer, "lnk1", "foreground-gdk", &lnk_color, NULL);
  ltag2 = gtk_text_buffer_create_tag(buffer, "lnk2", "foreground-gdk", &lnk_color, NULL);
  ltag3 = gtk_text_buffer_create_tag(buffer, "lnk3", "foreground-gdk", &lnk_color, NULL);
  ltag4 = gtk_text_buffer_create_tag(buffer, "lnk4", "foreground-gdk", &lnk_color, NULL);

211 212
  /* head */
  value = g_strdup_printf (_("Weather report for: %s.\n\n"), get_data (data, DNAM));
213 214 215 216
  APPEND_BTEXT (value);
  g_free (value);

  date = translate_lsup (get_data (data, LSUP));
217 218 219
  value = g_strdup_printf (_("Observation station located in %s\nLast update: %s.\n"),
                           get_data (data, OBST), date ? date : get_data (data, LSUP));
  g_free (date);
220 221
  APPEND_TEXT_ITEM_REAL (value);

222
  /* Temperature */
223 224 225 226 227
  APPEND_BTEXT (_("\nTemperature\n"));
  APPEND_TEXT_ITEM (_("Temperature"), TEMP);
  APPEND_TEXT_ITEM (_("Windchill"), FLIK);

  /* special case for TRANS because of translate_desc */
228
  value = g_strdup_printf ("\t%s: %s\n", _("Description"),
229 230 231 232
                           translate_desc (get_data (data, TRANS)));
  APPEND_TEXT_ITEM_REAL (value);
  APPEND_TEXT_ITEM (_("Dew point"), DEWP);

233
  /* Wind */
234 235 236 237
  APPEND_BTEXT (_("\nWind\n"));
  wind = translate_wind_speed (get_data (data, WIND_SPEED), unit);
  value = g_strdup_printf ("\t%s: %s\n", _("Speed"), wind);
  g_free (wind);
238
  APPEND_TEXT_ITEM_REAL (value);
239 240

  wind = translate_wind_direction (get_data (data, WIND_DIRECTION));
241 242 243
  value = g_strdup_printf ("\t%s: %s\n", _("Direction"),
                           wind ? wind : get_data (data, WIND_DIRECTION));
  g_free (wind);
244 245 246 247 248
  APPEND_TEXT_ITEM_REAL (value);

  wind = translate_wind_speed (get_data (data, WIND_GUST), unit);
  value = g_strdup_printf ("\t%s: %s\n", _("Gusts"), wind);
  g_free (wind);
249
  APPEND_TEXT_ITEM_REAL (value);
250

251
  /* UV */
252 253
  APPEND_BTEXT (_("\nUV\n"));
  APPEND_TEXT_ITEM (_("Index"), UV_INDEX);
254
  value = g_strdup_printf ("\t%s: %s\n", _("Risk"),
255 256 257
                           translate_risk (get_data (data, UV_TRANS)));
  APPEND_TEXT_ITEM_REAL (value);

258
  /* Atmospheric pressure */
259 260 261
  APPEND_BTEXT (_("\nAtmospheric pressure\n"));
  APPEND_TEXT_ITEM (_("Pressure"), BAR_R);

262
  value = g_strdup_printf ("\t%s: %s\n",  _("State"),
263 264 265
                           translate_bard (get_data (data, BAR_D)));
  APPEND_TEXT_ITEM_REAL (value);

266
  /* Sun */
267 268 269
  APPEND_BTEXT (_("\nSun\n"));
  sun_val = translate_time (get_data (data, SUNR));
  value = g_strdup_printf ("\t%s: %s\n",
270 271
                           _("Rise"), sun_val ? sun_val : get_data (data, SUNR));
  g_free (sun_val);
272 273 274 275
  APPEND_TEXT_ITEM_REAL (value);

  sun_val = translate_time (get_data (data, SUNS));
  value = g_strdup_printf ("\t%s: %s\n",
276 277
                           _("Set"), sun_val ? sun_val : get_data (data, SUNS));
  g_free (sun_val);
278 279
  APPEND_TEXT_ITEM_REAL (value);

280
  /* Other */
281 282 283 284 285
  APPEND_BTEXT (_("\nOther\n"));
  APPEND_TEXT_ITEM (_("Humidity"), HMID);
  vis = translate_visibility (get_data (data, VIS), unit);
  value = g_strdup_printf ("\t%s: %s\n", _("Visibility"), vis);
  g_free (vis);
286
  APPEND_TEXT_ITEM_REAL (value);
287

288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
  APPEND_BTEXT (_("\nMore on weather.com\n"));
  value = g_strdup_printf("http://www.weather.com/?par=xoap&site=wx_logo&cm_ven=bd_oap&cm_cat=%s&cm_pla=HomePage&cm_ite=Logo",
  		PARTNER_ID);
  g_object_set_data_full(G_OBJECT(ltag0), "url", value, g_free);

  APPEND_LINK_ITEM ("\t", get_data (data, LNK1_TXT), get_data (data, LNK1), ltag1);
  APPEND_LINK_ITEM ("\t", get_data (data, LNK2_TXT), get_data (data, LNK2), ltag2);
  APPEND_LINK_ITEM ("\t", get_data (data, LNK3_TXT), get_data (data, LNK3), ltag3);
  APPEND_LINK_ITEM ("\t", get_data (data, LNK4_TXT), get_data (data, LNK4), ltag4);

  g_signal_connect(G_OBJECT(view), "motion-notify-event",
		   G_CALLBACK(view_motion_notify), view);
  g_signal_connect(G_OBJECT(view), "leave-notify-event",
		   G_CALLBACK(view_leave_notify), view);
		   
  weather_channel_icon = gtk_image_new_from_pixbuf(get_icon("weather_channel", -1));
  if (weather_channel_icon) {
    weather_channel_evt = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(weather_channel_evt), weather_channel_icon);
    gtk_text_view_add_child_in_window(GTK_TEXT_VIEW(view), weather_channel_evt, 
                                      GTK_TEXT_WINDOW_TEXT, 0, 0);
    gtk_widget_show_all(weather_channel_evt);
    adj = gtk_scrolled_window_get_vadjustment(
	    GTK_SCROLLED_WINDOW(scrolled));
    g_signal_connect(G_OBJECT(adj), "value-changed",
		     G_CALLBACK(view_scrolled_cb), view);
    g_signal_connect(G_OBJECT(view), "size_allocate",
		     G_CALLBACK(view_size_allocate_cb),
		     view);
    g_signal_connect(G_OBJECT(weather_channel_evt), "button-release-event",
		     G_CALLBACK(icon_clicked),
		     ltag0);
    g_signal_connect(G_OBJECT(weather_channel_evt), "enter-notify-event",
		     G_CALLBACK(icon_motion_notify), view);
    g_signal_connect(G_OBJECT(weather_channel_evt), "visibility-notify-event",
		     G_CALLBACK(icon_motion_notify), view);
    g_signal_connect(G_OBJECT(weather_channel_evt), "motion-notify-event",
		     G_CALLBACK(icon_motion_notify), view);
    g_signal_connect(G_OBJECT(weather_channel_evt), "leave-notify-event",
		     G_CALLBACK(view_leave_notify), view);
  }
  if (hand_cursor == NULL)
    hand_cursor = gdk_cursor_new(GDK_HAND2);
  if (text_cursor == NULL)
    text_cursor = gdk_cursor_new(GDK_XTERM);
333

334

335 336
  return frame;
}
337

338
static GtkWidget *
339 340
make_forecast (xml_dayf *weatherdata,
               units     unit)
341
{
342 343
  GtkWidget *item_vbox, *temp_hbox, *icon_hbox,
            *label, *icon_d, *icon_n, *box_d, *box_n;
344
  GdkPixbuf *icon;
345
  gchar     *str, *day, *wind;
346 347 348 349 350 351 352 353 354 355 356

  DBG ("this day %s", weatherdata->day);

  item_vbox = gtk_vbox_new (FALSE, 0);
  gtk_container_set_border_width (GTK_CONTAINER (item_vbox), 6);


  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);

  day = translate_day (get_data_f (weatherdata, WDAY));
357 358
  str = g_strdup_printf ("<b>%s</b>", day ? day : get_data_f (weatherdata, WDAY));
  g_free (day);
359 360 361

  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
362

363 364 365 366
  gtk_box_pack_start (GTK_BOX (item_vbox), label, FALSE, FALSE, 0);

  icon_hbox = gtk_hbox_new (FALSE, 0);

367
  icon = get_icon (get_data_f (weatherdata, ICON_D), 48);
368 369
  icon_d = gtk_image_new_from_pixbuf (icon);
  box_d = gtk_event_box_new ();
370
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (box_d), FALSE);
371 372
  gtk_container_add (GTK_CONTAINER (box_d), icon_d);

373 374 375
  if (G_LIKELY (icon))
    g_object_unref (G_OBJECT (icon));

376
  icon = get_icon (get_data_f (weatherdata, ICON_N), 48);
377 378
  icon_n = gtk_image_new_from_pixbuf (icon);
  box_n = gtk_event_box_new ();
379
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (box_n), FALSE);
380 381
  gtk_container_add (GTK_CONTAINER (box_n), icon_n);

382 383 384
  if (G_LIKELY (icon))
    g_object_unref (G_OBJECT (icon));

385 386 387
  if (G_UNLIKELY (!tooltips))
    tooltips = gtk_tooltips_new ();

388 389
  str = g_strdup_printf (_("Day: %s"),
                         translate_desc (get_data_f (weatherdata, TRANS_D)));
390 391
  gtk_tooltips_set_tip (tooltips, box_d, str, NULL);
  g_free (str);
392 393 394

  str = g_strdup_printf (_("Night: %s"),
                         translate_desc (get_data_f (weatherdata, TRANS_N)));
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
  gtk_tooltips_set_tip (tooltips, box_n, str, NULL);
  g_free (str);

  gtk_box_pack_start (GTK_BOX (icon_hbox), box_d, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (icon_hbox), box_n, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (item_vbox), icon_hbox, FALSE, FALSE, 0);

  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  gtk_label_set_markup (GTK_LABEL (label), _("<b>Precipitation</b>"));
  gtk_box_pack_start (GTK_BOX (item_vbox), label, FALSE, FALSE, 0);

  temp_hbox = gtk_hbox_new (FALSE, 0);
  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  str = g_strdup_printf ("%s %%", get_data_f (weatherdata, PPCP_D));
  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);
414

415 416 417 418 419
  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  str = g_strdup_printf ("%s %%", get_data_f (weatherdata, PPCP_N));
  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
420

421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (item_vbox), temp_hbox, FALSE, FALSE, 0);

  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  gtk_label_set_markup (GTK_LABEL (label), _("<b>Temperature</b>"));
  gtk_box_pack_start (GTK_BOX (item_vbox), label, FALSE, FALSE, 0);

  temp_hbox = gtk_hbox_new (FALSE, 0);
  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  str = g_strdup_printf ("<span foreground=\"red\">%s</span> %s",
                         get_data_f (weatherdata, TEMP_MAX), get_unit (unit,
                                                                       TEMP));
  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);
  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  str = g_strdup_printf ("<span foreground=\"blue\">%s</span> %s",
                         get_data_f (weatherdata, TEMP_MIN), get_unit (unit,
                                                                       TEMP));
  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (item_vbox), temp_hbox, FALSE, FALSE, 0);

  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  gtk_label_set_markup (GTK_LABEL (label), _("<b>Wind</b>"));
  gtk_box_pack_start (GTK_BOX (item_vbox), label, FALSE, FALSE, 0);

  temp_hbox = gtk_hbox_new (FALSE, 0);
  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);

  wind = translate_wind_direction (get_data_f (weatherdata, W_DIRECTION_D));
  gtk_label_set_markup (GTK_LABEL (label),
                        wind ? wind : get_data_f (weatherdata,
                                                  W_DIRECTION_D));
461
  g_free (wind);
462 463 464 465 466 467 468 469 470 471

  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);

  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);

  wind = translate_wind_direction (get_data_f (weatherdata, W_DIRECTION_N));
  gtk_label_set_markup (GTK_LABEL (label),
                        wind ? wind : get_data_f (weatherdata,
                                                  W_DIRECTION_N));
472 473
  g_free (wind);

474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (item_vbox), temp_hbox, FALSE, FALSE, 0);

  /* speed */
  temp_hbox = gtk_hbox_new (FALSE, 2);
  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  str = g_strdup_printf ("%s %s", get_data_f (weatherdata, W_SPEED_D),
                         get_unit (unit, WIND_SPEED));
  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);

  label = gtk_label_new (NULL);
  gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
  str = g_strdup_printf ("%s %s", get_data_f (weatherdata, W_SPEED_N),
                         get_unit (unit, WIND_SPEED));
  gtk_label_set_markup (GTK_LABEL (label), str);
  g_free (str);
  gtk_box_pack_start (GTK_BOX (temp_hbox), label, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (item_vbox), temp_hbox, FALSE, FALSE, 0);

  DBG ("Done");

  return item_vbox;
499 500
}

501 502


503
static GtkWidget *
504 505
create_forecast_tab (xml_weather *data,
                     units        unit)
506
{
507
  GtkWidget *widg = gtk_hbox_new (FALSE, 0);
508
  guint      i;
509

510
  gtk_container_set_border_width (GTK_CONTAINER (widg), 6);
511

512
  if (data && data->dayf)
Nick Schermer's avatar
Nick Schermer committed
513
    {
514
      for (i = 0; i < XML_WEATHER_DAYF_N - 1; i++)
515
        {
516 517
          if (!data->dayf[i])
            break;
Nick Schermer's avatar
Nick Schermer committed
518

519
          DBG ("%s", data->dayf[i]->day);
Nick Schermer's avatar
Nick Schermer committed
520

521 522 523 524 525
          gtk_box_pack_start (GTK_BOX (widg),
                              make_forecast (data->dayf[i], unit), FALSE,
                              FALSE, 0);
          gtk_box_pack_start (GTK_BOX (widg), gtk_vseparator_new (), TRUE,
                              TRUE, 0);
526
        }
Nick Schermer's avatar
Nick Schermer committed
527

528 529 530 531
      if (data->dayf[i])
        gtk_box_pack_start (GTK_BOX (widg),
                            make_forecast (data->dayf[i], unit), FALSE, FALSE,
                            0);
Nick Schermer's avatar
Nick Schermer committed
532
    }
533

534
  return widg;
535
}
536

537 538 539 540 541 542 543
static void
summary_dialog_response (GtkWidget          *dlg,
                         gint                response,
                         GtkWidget          *window)
{
	if (response == GTK_RESPONSE_ACCEPT)
		gtk_widget_destroy(window);
544
	else if (response == GTK_RESPONSE_HELP)
545 546 547
		g_spawn_command_line_async ("exo-open --launch WebBrowser " PLUGIN_WEBSITE, NULL);
}

548
GtkWidget *
549 550
create_summary_window (xml_weather *data,
                       units        unit)
551
{
552
  GtkWidget *window, *notebook, *vbox;
553
  gchar     *title;
554
  GdkPixbuf *icon;
555

556 557 558
  window = xfce_titled_dialog_new_with_buttons (_("Weather Update"),
                                                NULL,
                                                GTK_DIALOG_NO_SEPARATOR,
559 560 561
                                                GTK_STOCK_ABOUT, 
						GTK_RESPONSE_HELP,
                                                GTK_STOCK_CLOSE,
562
                                                GTK_RESPONSE_ACCEPT, NULL);
563

564
  title = g_strdup_printf (_("Weather report for: %s"), get_data (data, DNAM));
Nick Schermer's avatar
Nick Schermer committed
565

566 567
  xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (window), title);
  g_free (title);
568

569 570 571
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE,
                      0);
572

573
  icon = get_icon (get_data (data, WICON), 48);
574

575
  if (!icon)
576
    icon = get_icon ("99", 48);
577

578
  gtk_window_set_icon (GTK_WINDOW (window), icon);
579 580 581

  if (G_LIKELY (icon))
    g_object_unref (G_OBJECT (icon));
582

583 584 585 586 587
  notebook = gtk_notebook_new ();
  gtk_container_set_border_width (GTK_CONTAINER (notebook), BORDER);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                            create_forecast_tab (data, unit),
                            gtk_label_new (_("Forecast")));
588 589 590
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                            create_summary_tab (data, unit),
                            gtk_label_new (_("Details")));
591

592
  gtk_box_pack_start (GTK_BOX (vbox), notebook, TRUE, TRUE, 0);
593

594
  g_signal_connect (G_OBJECT (window), "response",
595
                    G_CALLBACK (summary_dialog_response), window);
596

597
  gtk_window_set_default_size (GTK_WINDOW (window), 500, 400);
598

599
  return window;
600
}