Codebase list gnome-applets / 0d0ddd1
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
1 changed file(s) with 21 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
4545 #define MAX_CONSECUTIVE_FAULTS (3)
4646
4747 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 }
4866
4967 static void about_cb (GSimpleAction *action,
5068 GVariant *parameter,
375393 g_object_unref (action_group);
376394
377395 #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));
379397 #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);
381400 #endif
382401
383402 g_signal_connect (gw_applet->gweather_info, "updated",
509528 return 0; /* Do not repeat timeout (will be re-set by update_finish) */
510529 }
511530
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
524531 void gweather_update (GWeatherApplet *gw_applet)
525532 {
526533 gtk_widget_set_tooltip_text (GTK_WIDGET(gw_applet->applet), _("Updating..."));
528535 gweather_info_set_location (gw_applet->gweather_info, get_default_location (gw_applet));
529536 gweather_info_update (gw_applet->gweather_info);
530537 }
531