gweather: create GWeatherInfo with location
Otherwise applet will never update data without user interaction.
At the same time, fix memory leak.
Alberts Muktupāvels
6 years ago
45 | 45 | #define MAX_CONSECUTIVE_FAULTS (3) |
46 | 46 | |
47 | 47 | static void update_finish (GWeatherInfo *info, gpointer data); |
48 | ||
49 | static GWeatherLocation* | |
50 | get_default_location (GWeatherApplet *gw_applet) | |
51 | { | |
52 | GWeatherLocation *world; | |
53 | GWeatherLocation *location; | |
54 | const gchar *station_code; | |
55 | GVariant *default_loc; | |
56 | ||
57 | default_loc = g_settings_get_value (gw_applet->lib_settings, "default-location"); | |
58 | g_variant_get (default_loc, "(&s&sm(dd))", NULL, &station_code, NULL, NULL, NULL); | |
59 | ||
60 | world = gweather_location_get_world (); | |
61 | location = gweather_location_find_by_station_code (world, station_code); | |
62 | g_variant_unref (default_loc); | |
63 | ||
64 | return location; | |
65 | } | |
48 | 66 | |
49 | 67 | static void about_cb (GSimpleAction *action, |
50 | 68 | GVariant *parameter, |
375 | 393 | g_object_unref (action_group); |
376 | 394 | |
377 | 395 | #if GWEATHER_CHECK_VERSION (3, 27, 2) |
378 | gw_applet->gweather_info = gweather_info_new (NULL); | |
396 | gw_applet->gweather_info = gweather_info_new (get_default_location (gw_applet)); | |
379 | 397 | #else |
380 | gw_applet->gweather_info = gweather_info_new (NULL, GWEATHER_FORECAST_LIST); | |
398 | gw_applet->gweather_info = gweather_info_new (get_default_location (gw_applet), | |
399 | GWEATHER_FORECAST_LIST); | |
381 | 400 | #endif |
382 | 401 | |
383 | 402 | g_signal_connect (gw_applet->gweather_info, "updated", |
509 | 528 | return 0; /* Do not repeat timeout (will be re-set by update_finish) */ |
510 | 529 | } |
511 | 530 | |
512 | static GWeatherLocation* | |
513 | get_default_location (GWeatherApplet *gw_applet) | |
514 | { | |
515 | const gchar *station_code; | |
516 | GVariant *default_loc; | |
517 | ||
518 | default_loc = g_settings_get_value (gw_applet->lib_settings, "default-location"); | |
519 | g_variant_get (default_loc, "(&s&sm(dd))", NULL, &station_code, NULL, NULL, NULL); | |
520 | ||
521 | return gweather_location_find_by_station_code (gweather_location_get_world (), station_code); | |
522 | } | |
523 | ||
524 | 531 | void gweather_update (GWeatherApplet *gw_applet) |
525 | 532 | { |
526 | 533 | gtk_widget_set_tooltip_text (GTK_WIDGET(gw_applet->applet), _("Updating...")); |
528 | 535 | gweather_info_set_location (gw_applet->gweather_info, get_default_location (gw_applet)); |
529 | 536 | gweather_info_update (gw_applet->gweather_info); |
530 | 537 | } |
531 |