weather-summary.c 20.6 KB
Newer Older
Florian Rivoal's avatar
Florian Rivoal committed
1
/*  Copyright (c) 2003-2007 Xfce Development Team
2
 *
3 4 5
 *  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
6 7 8 9 10
 *  (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
11
 *  GNU Library General Public License for more details.
12
 *
13
 *  You should have received a copy of the GNU General Public License
14 15 16 17 18
 *  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
19
#include <config.h>
20 21
#endif

22
#include <libxfce4ui/libxfce4ui.h>
23

Nick Schermer's avatar
Nick Schermer committed
24 25
#include "weather-parsers.h"
#include "weather-data.h"
Florian Rivoal's avatar
Florian Rivoal committed
26
#include "weather-http.h"
Nick Schermer's avatar
Nick Schermer committed
27
#include "weather.h"
28

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

33

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

38 39 40 41 42 43
#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);
44 45
#define APPEND_TEXT_ITEM(text, item)     value = g_strdup_printf("\t%s%s%s %s\n",\
                                                                 text, text?": ":"", \
46 47
                                                                 get_data(timeslice, item), \
                                                                 get_unit(timeslice, data->unit, item)); \
48
                                         APPEND_TEXT_ITEM_REAL(value);
49 50 51 52 53 54 55 56 57
#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", \
58
						G_CALLBACK(lnk_clicked), NULL);
59

60 61


62 63
static GtkTooltips *tooltips = NULL;

64 65 66 67 68 69
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");
70
    gchar *str = g_strdup_printf("exo-open --launch WebBrowser %s", url);
71

72
    g_spawn_command_line_async(str, NULL);
73 74 75 76
    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);
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
  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;

106
    gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(view),
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
    						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;
152 153
    x1 = view->allocation.width - 73 - 5;
    y1 = view->requisition.height - 55 - 5;
154 155 156
    gtk_text_view_buffer_to_window_coords(
			GTK_TEXT_VIEW(view),
			GTK_TEXT_WINDOW_TEXT, x1, y1, &x, &y);
157
    gtk_text_view_move_child(GTK_TEXT_VIEW(view),
158 159 160 161 162 163 164 165 166 167
			weather_channel_evt, x, y);
  }
}

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

169 170 171 172 173
static gchar *get_logo_path (void)
{
	gchar *dir = g_strconcat(g_get_user_cache_dir(), G_DIR_SEPARATOR_S,
				"xfce4", G_DIR_SEPARATOR_S, "weather-plugin", NULL);

174
	g_mkdir_with_parents(dir, 0755);
175 176 177 178 179 180 181 182 183
	g_free(dir);

	return g_strconcat(g_get_user_cache_dir(), G_DIR_SEPARATOR_S,
				"xfce4", G_DIR_SEPARATOR_S, "weather-plugin",
				G_DIR_SEPARATOR_S, "weather_logo.jpg", NULL);
}

static void
logo_fetched (gboolean  succeed,
Florian Rivoal's avatar
Florian Rivoal committed
184
           gchar     *result,
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
	   size_t    len,
           gpointer  user_data)
{
	if (succeed && result) {
		gchar *path = get_logo_path();
		GError *error = NULL;
		GdkPixbuf *pixbuf = NULL;
		if (!g_file_set_contents(path, result, len, &error)) {
			printf("err %s\n", error?error->message:"?");
			g_error_free(error);
			g_free(result);
			g_free(path);
			return;
		}
		g_free(result);
		pixbuf = gdk_pixbuf_new_from_file(path, NULL);
		g_free(path);
		if (pixbuf) {
			gtk_image_set_from_pixbuf(GTK_IMAGE(user_data), pixbuf);
			g_object_unref(pixbuf);
		}
	}
}

static GtkWidget *weather_summary_get_logo(xfceweather_data *data)
{
	GtkWidget *image = gtk_image_new();
	GdkPixbuf *pixbuf = NULL;
	gchar *path = get_logo_path();
214

215 216 217
	pixbuf = gdk_pixbuf_new_from_file(path, NULL);
	g_free(path);
	if (pixbuf == NULL) {
218
		weather_http_receive_data ("xoap.weather.com", "/web/common/twc/logos/web_73x55.jpg",
219 220 221 222 223
			data->proxy_host, data->proxy_port, logo_fetched, image);
	} else {
		gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
		g_object_unref(pixbuf);
	}
224

225 226
	return image;
}
227

228
static GtkWidget *
229
create_summary_tab (xfceweather_data *data)
230
{
231
  GtkTextBuffer *buffer;
232
  GtkTextIter    iter;
Colin Leroy's avatar
Colin Leroy committed
233 234
  GtkTextTag    *btag, *ltag1;
  gchar         *value, *wind, *sun_val, *vis;
235
  GtkWidget     *view, *frame, *scrolled;
236 237 238
  GdkColor       lnk_color;
  GtkAdjustment *adj;
  GtkWidget     *weather_channel_icon;
Colin Leroy's avatar
Colin Leroy committed
239 240
  gchar         *start;
  xml_time      *timeslice;
241 242 243

  view = gtk_text_view_new ();
  gtk_text_view_set_editable (GTK_TEXT_VIEW (view), FALSE);
244
  gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (view), FALSE);
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
  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);

262 263 264
  gdk_color_parse("#0000ff", &lnk_color);
  ltag1 = gtk_text_buffer_create_tag(buffer, "lnk1", "foreground-gdk", &lnk_color, NULL);

265
  /* head */
Colin Leroy's avatar
Colin Leroy committed
266
  value = g_strdup_printf (_("Weather report for: %s.\n\n"), data->location_name);
267 268
  APPEND_BTEXT (value);
  g_free (value);
Colin Leroy's avatar
Colin Leroy committed
269 270

  timeslice = get_current_timeslice(data->weatherdata, FALSE);
Colin Leroy's avatar
Colin Leroy committed
271
  value = g_strdup_printf (_("Coordinates: lat %s lon %s\nData applies to: %s\n"),
Colin Leroy's avatar
Colin Leroy committed
272
                           data->lat, data->lon, ctime(&timeslice->start));
273 274
  APPEND_TEXT_ITEM_REAL (value);

275
  /* Temperature */
276
  APPEND_BTEXT (_("\nTemperature\n"));
Colin Leroy's avatar
Colin Leroy committed
277
  APPEND_TEXT_ITEM (_("Temperature"), TEMPERATURE);
278

279
  /* Wind */
280
  APPEND_BTEXT (_("\nWind\n"));
281
  wind = translate_wind_speed (timeslice, get_data (timeslice, WIND_SPEED), data->unit);
Colin Leroy's avatar
Colin Leroy committed
282
  value = g_strdup_printf ("\t%s: %s (%s on the Beaufort scale)\n", _("Speed"), wind,
283
                           get_data (timeslice, WIND_BEAUFORT));
284
  g_free (wind);
285
  APPEND_TEXT_ITEM_REAL (value);
286

287
  wind = translate_wind_direction (get_data (timeslice, WIND_DIRECTION));
Colin Leroy's avatar
Colin Leroy committed
288
  value = g_strdup_printf ("\t%s: %s (%s%s)\n", _("Direction"),
289 290 291
                           wind ? wind : get_data (timeslice, WIND_DIRECTION),
                           get_data (timeslice, WIND_DIRECTION_DEG),
                           get_unit (timeslice, data->unit, WIND_DIRECTION_DEG));
292
  g_free (wind);
293
  APPEND_TEXT_ITEM_REAL (value);
294

295
  /* Atmospheric pressure */
296
  APPEND_BTEXT (_("\nAtmospheric pressure\n"));
Colin Leroy's avatar
Colin Leroy committed
297
  APPEND_TEXT_ITEM (_("Pressure"), PRESSURE);
298

299
  /* Other */
300
  APPEND_BTEXT (_("\nOther\n"));
Colin Leroy's avatar
Colin Leroy committed
301 302 303 304 305
  APPEND_TEXT_ITEM (_("Humidity"), HUMIDITY);
  APPEND_TEXT_ITEM (_("Low clouds"), CLOUDINESS_LOW);
  APPEND_TEXT_ITEM (_("Medium clouds"), CLOUDINESS_MED);
  APPEND_TEXT_ITEM (_("High clouds"), CLOUDINESS_HIGH);
  APPEND_TEXT_ITEM (_("Fog"), FOG);
306

Colin Leroy's avatar
Colin Leroy committed
307 308
  APPEND_BTEXT (_("\nData from The Norwegian Meteorological Institute\n"));
  APPEND_LINK_ITEM ("\t", "Thanks to met.no", "http://met.no/", ltag1);
309 310 311 312 313

  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);
Colin Leroy's avatar
Colin Leroy committed
314

315 316 317 318
  if (hand_cursor == NULL)
    hand_cursor = gdk_cursor_new(GDK_HAND2);
  if (text_cursor == NULL)
    text_cursor = gdk_cursor_new(GDK_XTERM);
319

320

321 322
  return frame;
}
323

324
static GtkWidget *
Colin Leroy's avatar
Colin Leroy committed
325
make_forecast (xml_weather *weatherdata,
326
               units     unit)
327
{
328 329
  GtkWidget *item_vbox, *temp_hbox, *icon_hbox,
            *label, *icon_d, *icon_n, *box_d, *box_n;
330
  GdkPixbuf *icon;
331
  gchar     *str, *day, *wind;
332

Colin Leroy's avatar
Colin Leroy committed
333 334
  item_vbox = gtk_vbox_new (FALSE, 0);
#if 0
335 336 337 338 339 340 341 342 343
  DBG ("this day %s", weatherdata->day);

  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));
344 345
  str = g_strdup_printf ("<b>%s</b>", day ? day : get_data_f (weatherdata, WDAY));
  g_free (day);
346 347 348

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

350 351 352 353
  gtk_box_pack_start (GTK_BOX (item_vbox), label, FALSE, FALSE, 0);

  icon_hbox = gtk_hbox_new (FALSE, 0);

354
  icon = get_icon (get_data_f (weatherdata, ICON_D), 48);
355 356
  icon_d = gtk_image_new_from_pixbuf (icon);
  box_d = gtk_event_box_new ();
357
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (box_d), FALSE);
358 359
  gtk_container_add (GTK_CONTAINER (box_d), icon_d);

360 361 362
  if (G_LIKELY (icon))
    g_object_unref (G_OBJECT (icon));

363
  icon = get_icon (get_data_f (weatherdata, ICON_N), 48);
364 365
  icon_n = gtk_image_new_from_pixbuf (icon);
  box_n = gtk_event_box_new ();
366
  gtk_event_box_set_visible_window (GTK_EVENT_BOX (box_n), FALSE);
367 368
  gtk_container_add (GTK_CONTAINER (box_n), icon_n);

369 370 371
  if (G_LIKELY (icon))
    g_object_unref (G_OBJECT (icon));

372 373 374
  if (G_UNLIKELY (!tooltips))
    tooltips = gtk_tooltips_new ();

375 376
  str = g_strdup_printf (_("Day: %s"),
                         translate_desc (get_data_f (weatherdata, TRANS_D)));
377 378
  gtk_tooltips_set_tip (tooltips, box_d, str, NULL);
  g_free (str);
379 380 381

  str = g_strdup_printf (_("Night: %s"),
                         translate_desc (get_data_f (weatherdata, TRANS_N)));
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
  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);
401

402 403 404 405 406
  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);
407

408 409 410 411 412 413 414 415 416 417 418 419 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
  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));
448
  g_free (wind);
449 450 451 452 453 454 455 456 457 458

  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));
459 460
  g_free (wind);

461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
  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");
Colin Leroy's avatar
Colin Leroy committed
484
#endif
485
  return item_vbox;
486 487
}

488 489


490
static GtkWidget *
491
create_forecast_tab (xfceweather_data *data)
492
{
493
  GtkWidget *widg = gtk_hbox_new (FALSE, 0);
494
  guint      i;
495

496
  gtk_container_set_border_width (GTK_CONTAINER (widg), 6);
Colin Leroy's avatar
Colin Leroy committed
497
#if 0
498
  if (data->weatherdata && data->weatherdata->dayf)
Nick Schermer's avatar
Nick Schermer committed
499
    {
500
      for (i = 0; i < XML_WEATHER_DAYF_N - 1; i++)
501
        {
502
          if (!data->weatherdata->dayf[i])
503
            break;
Nick Schermer's avatar
Nick Schermer committed
504

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

507
          gtk_box_pack_start (GTK_BOX (widg),
508
                              make_forecast (data->weatherdata->dayf[i], data->unit), FALSE,
509 510 511
                              FALSE, 0);
          gtk_box_pack_start (GTK_BOX (widg), gtk_vseparator_new (), TRUE,
                              TRUE, 0);
512
        }
Nick Schermer's avatar
Nick Schermer committed
513

514
      if (data->weatherdata->dayf[i])
515
        gtk_box_pack_start (GTK_BOX (widg),
516
                            make_forecast (data->weatherdata->dayf[i], data->unit), FALSE, FALSE,
517
                            0);
Nick Schermer's avatar
Nick Schermer committed
518
    }
Colin Leroy's avatar
Colin Leroy committed
519
#endif
520
  return widg;
521
}
522

523 524 525 526 527 528 529
static void
summary_dialog_response (GtkWidget          *dlg,
                         gint                response,
                         GtkWidget          *window)
{
	if (response == GTK_RESPONSE_ACCEPT)
		gtk_widget_destroy(window);
530
	else if (response == GTK_RESPONSE_HELP)
531 532 533
		g_spawn_command_line_async ("exo-open --launch WebBrowser " PLUGIN_WEBSITE, NULL);
}

534
GtkWidget *
535
create_summary_window (xfceweather_data *data)
536
{
Harald Judt's avatar
Harald Judt committed
537
  GtkWidget *window, *notebook, *vbox, *hbox, *label;
538
  gchar     *title;
539
  GdkPixbuf *icon;
540
  xml_time  *timeslice;
541

542 543 544
  window = xfce_titled_dialog_new_with_buttons (_("Weather Update"),
                                                NULL,
                                                GTK_DIALOG_NO_SEPARATOR,
545
                                                GTK_STOCK_ABOUT,
546 547
						GTK_RESPONSE_HELP,
                                                GTK_STOCK_CLOSE,
548
                                                GTK_RESPONSE_ACCEPT, NULL);
Harald Judt's avatar
Harald Judt committed
549 550 551 552 553
  if (data->location_name != NULL) {
    title = g_strdup_printf (_("Weather report for: %s"), data->location_name);
    xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (window), title);
    g_free (title);
  }
554

555 556 557
  vbox = gtk_vbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), vbox, TRUE, TRUE,
                      0);
558

559
  timeslice = get_current_timeslice(data->weatherdata, TRUE);
560
  icon = get_icon (get_data (timeslice, SYMBOL), 48, is_night_time());
561

562
  gtk_window_set_icon (GTK_WINDOW (window), icon);
563 564 565

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

Harald Judt's avatar
Harald Judt committed
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
  if (data->location_name == NULL || data->weatherdata == NULL) {
    hbox = gtk_hbox_new (FALSE, 0);
    gtk_widget_show(hbox);
    if (data->location_name == NULL)
      label = gtk_label_new(_("Please set a location in the plugin settings."));
    else
      label = gtk_label_new(_("Currently no data available."));
    gtk_widget_show(label);
    gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET(label),
                        TRUE, TRUE, 0);

    gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET(hbox),
                        TRUE, TRUE, 0);
  } else {
    notebook = gtk_notebook_new ();
    gtk_container_set_border_width (GTK_CONTAINER (notebook), BORDER);
    gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                              create_forecast_tab (data),
                              gtk_label_new (_("Forecast")));
    gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
                              create_summary_tab (data),
                              gtk_label_new (_("Details")));

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

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

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

598
  return window;
599
}