1 2 3 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 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 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 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 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 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 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 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 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 592 593 594 595 596 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 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from
// from gir-files (https://github.com/gtk-rs/gir-files.git)
// DO NOT EDIT
use crate::{
ffi, ConditionPhenomenon, ConditionQualifier, DistanceUnit, Location, MoonLatitude, MoonPhase,
PressureUnit, Provider, Sky, SpeedUnit, TemperatureUnit, WindDirection,
};
use glib::{
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::boxed::Box as Box_;
glib::wrapper! {
/// `GWeatherInfo` provides a handy way to access weather conditions
/// and forecasts from a [`Location`][crate::Location], aggregating multiple
/// different web services.
///
/// It includes also astronomical data such as sunrise times and
/// moon phases.
///
/// ## Properties
///
///
/// #### `application-id`
/// A unique identifier, typically in the form of reverse DNS notation,
/// for the application that is querying the weather information.
///
/// Weather providers require this information.
///
/// Readable | Writeable
///
///
/// #### `contact-info`
/// An email address or any other contact form URL.
///
/// Weather providers require this information.
///
/// Readable | Writeable
///
///
/// #### `enabled-providers`
/// The enabled weather providers.
///
/// Readable | Writeable
///
///
/// #### `location`
/// The location of the weather information.
///
/// Readable | Writeable | Construct
///
/// ## Signals
///
///
/// #### `updated`
/// This signal is emitted after the initial fetch of the weather
/// data from upstream services, and after every successful call
/// to [`Info::update()`][crate::Info::update()].
///
///
#[doc(alias = "GWeatherInfo")]
pub struct Info(Object<ffi::GWeatherInfo, ffi::GWeatherInfoClass>);
match fn {
type_ => || ffi::gweather_info_get_type(),
}
}
impl Info {
/// Builds a new `GWeatherInfo` that will provide weather information about
/// the given location.
///
/// In order to retrieve the weather information, you will need to enable
/// the desired providers and then call [`update()`][Self::update()]. If
/// you want to be notified of the completion of the weather information
/// update, you should connect to the [`updated`][struct@crate::Info#updated]
/// signal before updating the `GWeatherInfo` instance.
/// ## `location`
/// the desidered location
///
/// # Returns
///
/// a new weather information instance
#[doc(alias = "gweather_info_new")]
pub fn new(location: Option<&Location>) -> Info {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::gweather_info_new(location.to_glib_none().0)) }
}
// rustdoc-stripper-ignore-next
/// Creates a new builder-pattern struct instance to construct [`Info`] objects.
///
/// This method returns an instance of [`InfoBuilder`](crate::builders::InfoBuilder) which can be used to create [`Info`] objects.
pub fn builder() -> InfoBuilder {
InfoBuilder::new()
}
#[doc(alias = "gweather_info_abort")]
pub fn abort(&self) {
unsafe {
ffi::gweather_info_abort(self.to_glib_none().0);
}
}
#[doc(alias = "gweather_info_get_apparent")]
#[doc(alias = "get_apparent")]
pub fn apparent(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_apparent(self.to_glib_none().0)) }
}
/// Get the [application ID](https://docs.flatpak.org/en/latest/conventions.html#application-ids)
/// of the application fetching the weather.
///
/// # Returns
///
/// the application ID
#[doc(alias = "gweather_info_get_application_id")]
#[doc(alias = "get_application_id")]
#[doc(alias = "application-id")]
pub fn application_id(&self) -> glib::GString {
unsafe { from_glib_none(ffi::gweather_info_get_application_id(self.to_glib_none().0)) }
}
/// Some weather services require the application showing the
/// data to include an attribution text, possibly including links
/// to the service website.
/// This must be shown prominently toghether with the data.
///
/// # Returns
///
/// the required attribution text, in Pango
/// markup form, or [`None`] if not required
#[doc(alias = "gweather_info_get_attribution")]
#[doc(alias = "get_attribution")]
pub fn attribution(&self) -> glib::GString {
unsafe { from_glib_none(ffi::gweather_info_get_attribution(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_conditions")]
#[doc(alias = "get_conditions")]
pub fn conditions(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_conditions(self.to_glib_none().0)) }
}
/// Get the contact information of the application fetching the weather.
///
/// # Returns
///
/// the contact information
#[doc(alias = "gweather_info_get_contact_info")]
#[doc(alias = "get_contact_info")]
#[doc(alias = "contact-info")]
pub fn contact_info(&self) -> glib::GString {
unsafe { from_glib_none(ffi::gweather_info_get_contact_info(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_dew")]
#[doc(alias = "get_dew")]
pub fn dew(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_dew(self.to_glib_none().0)) }
}
/// Gets the bitmask of enabled #GWeatherProvider weather
/// providers.
#[doc(alias = "gweather_info_get_enabled_providers")]
#[doc(alias = "get_enabled_providers")]
#[doc(alias = "enabled-providers")]
pub fn enabled_providers(&self) -> Provider {
unsafe {
from_glib(ffi::gweather_info_get_enabled_providers(
self.to_glib_none().0,
))
}
}
///
/// # Returns
///
/// list
/// of GWeatherInfo* objects for the forecast.
/// The list is owned by the 'info' object thus is alive as long
/// as the 'info'. The 'update' property is the date/time when the
/// forecast info is used for.
#[doc(alias = "gweather_info_get_forecast_list")]
#[doc(alias = "get_forecast_list")]
pub fn forecast_list(&self) -> Vec<Info> {
unsafe {
FromGlibPtrContainer::from_glib_none(ffi::gweather_info_get_forecast_list(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gweather_info_get_humidity")]
#[doc(alias = "get_humidity")]
pub fn humidity(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_humidity(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_icon_name")]
#[doc(alias = "get_icon_name")]
pub fn icon_name(&self) -> glib::GString {
unsafe { from_glib_none(ffi::gweather_info_get_icon_name(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_location")]
#[doc(alias = "get_location")]
pub fn location(&self) -> Location {
unsafe { from_glib_none(ffi::gweather_info_get_location(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_location_name")]
#[doc(alias = "get_location_name")]
pub fn location_name(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_location_name(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_pressure")]
#[doc(alias = "get_pressure")]
pub fn pressure(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_pressure(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_sky")]
#[doc(alias = "get_sky")]
pub fn sky(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_sky(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_sunrise")]
#[doc(alias = "get_sunrise")]
pub fn sunrise(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_sunrise(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_sunset")]
#[doc(alias = "get_sunset")]
pub fn sunset(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_sunset(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_symbolic_icon_name")]
#[doc(alias = "get_symbolic_icon_name")]
pub fn symbolic_icon_name(&self) -> glib::GString {
unsafe {
from_glib_none(ffi::gweather_info_get_symbolic_icon_name(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gweather_info_get_temp")]
#[doc(alias = "get_temp")]
pub fn temp(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_temp(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_temp_max")]
#[doc(alias = "get_temp_max")]
pub fn temp_max(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_temp_max(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_temp_min")]
#[doc(alias = "get_temp_min")]
pub fn temp_min(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_temp_min(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_temp_summary")]
#[doc(alias = "get_temp_summary")]
pub fn temp_summary(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_temp_summary(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_get_update")]
pub fn get_update(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_update(self.to_glib_none().0)) }
}
/// ## `unit`
/// the desired unit, as a #GWeatherTemperatureUnit
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the apparent temperature
#[doc(alias = "gweather_info_get_value_apparent")]
#[doc(alias = "get_value_apparent")]
pub fn value_apparent(&self, unit: TemperatureUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_apparent(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// Fills out @phenomenon and @qualifier with current weather conditions.
///
/// # Returns
///
/// TRUE is out arguments are valid, FALSE otherwise.
///
/// ## `phenomenon`
/// a location for a #GWeatherConditionPhenomenon.
///
/// ## `qualifier`
/// a location for a #GWeatherConditionQualifier.
#[doc(alias = "gweather_info_get_value_conditions")]
#[doc(alias = "get_value_conditions")]
pub fn value_conditions(&self) -> Option<(ConditionPhenomenon, ConditionQualifier)> {
unsafe {
let mut phenomenon = std::mem::MaybeUninit::uninit();
let mut qualifier = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_conditions(
self.to_glib_none().0,
phenomenon.as_mut_ptr(),
qualifier.as_mut_ptr(),
));
if ret {
Some((
from_glib(phenomenon.assume_init()),
from_glib(qualifier.assume_init()),
))
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherTemperatureUnit
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the dew point
#[doc(alias = "gweather_info_get_value_dew")]
#[doc(alias = "get_value_dew")]
pub fn value_dew(&self, unit: TemperatureUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_dew(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the current moon phase
///
/// ## `lat`
/// the moon declension
#[doc(alias = "gweather_info_get_value_moonphase")]
#[doc(alias = "get_value_moonphase")]
pub fn value_moonphase(&self) -> Option<(MoonPhase, MoonLatitude)> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let mut lat = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_moonphase(
self.to_glib_none().0,
value.as_mut_ptr(),
lat.as_mut_ptr(),
));
if ret {
Some((value.assume_init(), lat.assume_init()))
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherPressureUnit
///
/// # Returns
///
/// TRUE if @value is valid, FALSE otherwise.
///
/// ## `value`
/// forecasted pressure, expressed in @unit
#[doc(alias = "gweather_info_get_value_pressure")]
#[doc(alias = "get_value_pressure")]
pub fn value_pressure(&self, unit: PressureUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_pressure(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// Fills out @sky with current sky conditions.
///
/// # Returns
///
/// TRUE is @sky is valid, FALSE otherwise.
///
/// ## `sky`
/// a location for a #GWeatherSky.
#[doc(alias = "gweather_info_get_value_sky")]
#[doc(alias = "get_value_sky")]
pub fn value_sky(&self) -> Option<Sky> {
unsafe {
let mut sky = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_sky(
self.to_glib_none().0,
sky.as_mut_ptr(),
));
if ret {
Some(from_glib(sky.assume_init()))
} else {
None
}
}
}
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the time of sunrise
#[doc(alias = "gweather_info_get_value_sunrise")]
#[doc(alias = "get_value_sunrise")]
pub fn value_sunrise(&self) -> Option<libc::c_ulong> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_sunrise(
self.to_glib_none().0,
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the time of sunset
#[doc(alias = "gweather_info_get_value_sunset")]
#[doc(alias = "get_value_sunset")]
pub fn value_sunset(&self) -> Option<libc::c_ulong> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_sunset(
self.to_glib_none().0,
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherTemperatureUnit
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the temperature value
#[doc(alias = "gweather_info_get_value_temp")]
#[doc(alias = "get_value_temp")]
pub fn value_temp(&self, unit: TemperatureUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_temp(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherTemperatureUnit
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the maximum temperature value
#[doc(alias = "gweather_info_get_value_temp_max")]
#[doc(alias = "get_value_temp_max")]
pub fn value_temp_max(&self, unit: TemperatureUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_temp_max(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherTemperatureUnit
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the minimum temperature value
#[doc(alias = "gweather_info_get_value_temp_min")]
#[doc(alias = "get_value_temp_min")]
pub fn value_temp_min(&self, unit: TemperatureUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_temp_min(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// Note that @value may be 0 if @self has not yet been updated.
///
/// # Returns
///
/// TRUE is @value is valid, FALSE otherwise.
///
/// ## `value`
/// the time @self was last updated
#[doc(alias = "gweather_info_get_value_update")]
#[doc(alias = "get_value_update")]
pub fn value_update(&self) -> Option<libc::c_long> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_update(
self.to_glib_none().0,
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherDistanceUnit
///
/// # Returns
///
/// TRUE if @value is valid, FALSE otherwise.
///
/// ## `value`
/// forecasted visibility, expressed in @unit
#[doc(alias = "gweather_info_get_value_visibility")]
#[doc(alias = "get_value_visibility")]
pub fn value_visibility(&self, unit: DistanceUnit) -> Option<f64> {
unsafe {
let mut value = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_visibility(
self.to_glib_none().0,
unit.into_glib(),
value.as_mut_ptr(),
));
if ret {
Some(value.assume_init())
} else {
None
}
}
}
/// ## `unit`
/// the desired unit, as a #GWeatherSpeedUnit
///
/// # Returns
///
/// TRUE if @speed and @direction are valid, FALSE otherwise.
///
/// ## `speed`
/// forecasted wind speed
///
/// ## `direction`
/// forecasted wind direction
#[doc(alias = "gweather_info_get_value_wind")]
#[doc(alias = "get_value_wind")]
pub fn value_wind(&self, unit: SpeedUnit) -> Option<(f64, WindDirection)> {
unsafe {
let mut speed = std::mem::MaybeUninit::uninit();
let mut direction = std::mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gweather_info_get_value_wind(
self.to_glib_none().0,
unit.into_glib(),
speed.as_mut_ptr(),
direction.as_mut_ptr(),
));
if ret {
Some((speed.assume_init(), from_glib(direction.assume_init())))
} else {
None
}
}
}
#[doc(alias = "gweather_info_get_visibility")]
#[doc(alias = "get_visibility")]
pub fn visibility(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_visibility(self.to_glib_none().0)) }
}
///
/// # Returns
///
/// a summary for current weather conditions.
#[doc(alias = "gweather_info_get_weather_summary")]
#[doc(alias = "get_weather_summary")]
pub fn weather_summary(&self) -> glib::GString {
unsafe {
from_glib_full(ffi::gweather_info_get_weather_summary(
self.to_glib_none().0,
))
}
}
#[doc(alias = "gweather_info_get_wind")]
#[doc(alias = "get_wind")]
pub fn wind(&self) -> glib::GString {
unsafe { from_glib_full(ffi::gweather_info_get_wind(self.to_glib_none().0)) }
}
///
/// # Returns
///
/// Whether it is daytime (that is, if the sun is visible)
/// or not at the location and the point of time referred by @self.
/// This is mostly equivalent to comparing the return value
/// of gweather_info_get_value_sunrise() and
/// gweather_info_get_value_sunset(), but it accounts also
/// for midnight sun and polar night, for locations within
/// the Artic and Antartic circles.
#[doc(alias = "gweather_info_is_daytime")]
pub fn is_daytime(&self) -> bool {
unsafe { from_glib(ffi::gweather_info_is_daytime(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_is_valid")]
pub fn is_valid(&self) -> bool {
unsafe { from_glib(ffi::gweather_info_is_valid(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_network_error")]
pub fn network_error(&self) -> bool {
unsafe { from_glib(ffi::gweather_info_network_error(self.to_glib_none().0)) }
}
#[doc(alias = "gweather_info_next_sun_event")]
pub fn next_sun_event(&self) -> i32 {
unsafe { ffi::gweather_info_next_sun_event(self.to_glib_none().0) }
}
/// Sets the [application ID](https://docs.flatpak.org/en/latest/conventions.html#application-ids)
/// of the application fetching the weather. It is a requirement
/// for using any of the online weather providers.
///
/// If the application uses #GApplication, then the application ID
/// will be automatically filled in.
/// ## `application_id`
/// the application ID to set
#[doc(alias = "gweather_info_set_application_id")]
#[doc(alias = "application-id")]
pub fn set_application_id(&self, application_id: &str) {
unsafe {
ffi::gweather_info_set_application_id(
self.to_glib_none().0,
application_id.to_glib_none().0,
);
}
}
/// Sets the contact information for the application fetching the
/// weather. It is a requirement for using any of the online
/// weather providers as it allows API providers to contact application
/// developers in case of terms of use breaches.
///
/// The contact information should be an email address, or the full
/// URL to an online contact form which weather providers can use
/// to contact the application developer. Avoid using bug tracker
/// URLs which require creating accounts.
/// ## `contact_info`
/// the contact information for the application
#[doc(alias = "gweather_info_set_contact_info")]
#[doc(alias = "contact-info")]
pub fn set_contact_info(&self, contact_info: &str) {
unsafe {
ffi::gweather_info_set_contact_info(
self.to_glib_none().0,
contact_info.to_glib_none().0,
);
}
}
/// Sets the enabled providers for fetching the weather. Note
/// that it is up to the application developer to make sure that
/// the terms of use for each service are respected.
///
/// Online providers will not be enabled if the application ID is
/// not set to a valid value.
/// ## `providers`
/// a bitmask of #GWeatherProvider
#[doc(alias = "gweather_info_set_enabled_providers")]
#[doc(alias = "enabled-providers")]
pub fn set_enabled_providers(&self, providers: Provider) {
unsafe {
ffi::gweather_info_set_enabled_providers(self.to_glib_none().0, providers.into_glib());
}
}
/// Changes the location of the weather report.
///
/// Note that this will clear any forecast or current conditions, and
/// you must call [`update()`][Self::update()] to obtain the new data.
/// ## `location`
/// a location for which weather is desired
#[doc(alias = "gweather_info_set_location")]
#[doc(alias = "location")]
pub fn set_location(&self, location: Option<&Location>) {
unsafe {
ffi::gweather_info_set_location(self.to_glib_none().0, location.to_glib_none().0);
}
}
/// Requests a reload of weather conditions and forecast data from
/// enabled network services.
/// This call does no synchronous IO: rather, the result is delivered
/// by emitting the #GWeatherInfo::updated signal.
/// Note that if no network services are enabled, the signal will not
/// be emitted. See #GWeatherInfo:enabled-providers for details.
#[doc(alias = "gweather_info_update")]
pub fn update(&self) {
unsafe {
ffi::gweather_info_update(self.to_glib_none().0);
}
}
/// Ensures that any data cached from the network is stored to disk.
/// Calling this is not necessary, as the cache will be saved when
/// the last reference to a #GWeatherInfo will be dropped.
/// On the other hand, it must be called if there is any chance that
/// the application will be closed without unreffing all objects, such
/// as when using a language binding that employs a GC.
#[doc(alias = "gweather_info_store_cache")]
pub fn store_cache() {
assert_initialized_main_thread!();
unsafe {
ffi::gweather_info_store_cache();
}
}
/// This signal is emitted after the initial fetch of the weather
/// data from upstream services, and after every successful call
/// to [`update()`][Self::update()].
#[doc(alias = "updated")]
pub fn connect_updated<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn updated_trampoline<F: Fn(&Info) + 'static>(
this: *mut ffi::GWeatherInfo,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"updated\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
updated_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "application-id")]
pub fn connect_application_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_application_id_trampoline<F: Fn(&Info) + 'static>(
this: *mut ffi::GWeatherInfo,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::application-id\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_application_id_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "contact-info")]
pub fn connect_contact_info_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_contact_info_trampoline<F: Fn(&Info) + 'static>(
this: *mut ffi::GWeatherInfo,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::contact-info\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_contact_info_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "enabled-providers")]
pub fn connect_enabled_providers_notify<F: Fn(&Self) + 'static>(
&self,
f: F,
) -> SignalHandlerId {
unsafe extern "C" fn notify_enabled_providers_trampoline<F: Fn(&Info) + 'static>(
this: *mut ffi::GWeatherInfo,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::enabled-providers\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_enabled_providers_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "location")]
pub fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_location_trampoline<F: Fn(&Info) + 'static>(
this: *mut ffi::GWeatherInfo,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
let f: &F = &*(f as *const F);
f(&from_glib_borrow(this))
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"notify::location\0".as_ptr() as *const _,
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_location_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl Default for Info {
fn default() -> Self {
glib::object::Object::new::<Self>()
}
}
// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`Info`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct InfoBuilder {
builder: glib::object::ObjectBuilder<'static, Info>,
}
impl InfoBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
/// A unique identifier, typically in the form of reverse DNS notation,
/// for the application that is querying the weather information.
///
/// Weather providers require this information.
pub fn application_id(self, application_id: impl Into<glib::GString>) -> Self {
Self {
builder: self
.builder
.property("application-id", application_id.into()),
}
}
/// An email address or any other contact form URL.
///
/// Weather providers require this information.
pub fn contact_info(self, contact_info: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("contact-info", contact_info.into()),
}
}
/// The enabled weather providers.
pub fn enabled_providers(self, enabled_providers: Provider) -> Self {
Self {
builder: self
.builder
.property("enabled-providers", enabled_providers),
}
}
/// The location of the weather information.
pub fn location(self, location: &Location) -> Self {
Self {
builder: self.builder.property("location", location.clone()),
}
}
// rustdoc-stripper-ignore-next
/// Build the [`Info`].
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> Info {
self.builder.build()
}
}