CafeWeatherLocation: libcafeweather Reference Manual

## CafeWeatherLocation CafeWeatherLocation |

## Functions

CafeWeatherLocation * | cafeweather_location_new_world ()
CafeWeatherLocation * | cafeweather_location_ref ()
void | cafeweather_location_unref ()
const char * | cafeweather_location_get_name ()
const char * | cafeweather_location_get_sort_name ()
CafeWeatherLocationLevel | cafeweather_location_get_level ()
CafeWeatherLocation * | cafeweather_location_get_parent ()
CafeWeatherLocation ** | cafeweather_location_get_children ()
void | cafeweather_location_free_children ()
gboolean | cafeweather_location_has_coords ()
void | cafeweather_location_get_coords ()
double | cafeweather_location_get_distance ()
const char * | cafeweather_location_get_country ()
CafeWeatherTimezone * | cafeweather_location_get_timezone ()
CafeWeatherTimezone ** | cafeweather_location_get_timezones ()
void | cafeweather_location_free_timezones ()
const char * | cafeweather_location_get_code ()
char * | cafeweather_location_get_city_name ()
WeatherInfo * | cafeweather_location_get_weather ()

## Types and Values

| CafeWeatherLocation
enum | CafeWeatherLocationLevel

## Object Hierarchy

        GBoxed
        ╰── CafeWeatherLocation
        GEnum
        ╰── CafeWeatherLocationLevel

## Description

A CafeWeatherLocation represents a "location" of some type known to libcafeweather; anything from a single weather station to the entire world. See CafeWeatherLocationLevel for information about how the hierarchy of locations works.

## Functions

### cafeweather_location_new_world ()

    CafeWeatherLocation *
    cafeweather_location_new_world (gboolean use_regions);

Creates a new CafeWeatherLocation of type `CAFEWEATHER_LOCATION_WORLD`, representing a hierarchy containing all of the locations from Locations.xml.

If `use_regions` is `TRUE`, the immediate children of the returned location will be `CAFEWEATHER_LOCATION_REGION` nodes, representing the top-level "regions" of Locations.xml (the continents and a few other divisions), and the country-level nodes will be the children of the regions. If `use_regions` is `FALSE`, the regions will be skipped, and the children of the returned location will be the `CAFEWEATHER_LOCATION_COUNTRY` nodes.

#### Parameters

use_regions | whether or not to divide the world into regions |

#### Returns

a `CAFEWEATHER_LOCATION_WORLD` location, or `NULL` if Locations.xml could not be found or could not be parsed.

[allow-none]

### cafeweather_location_ref ()

    CafeWeatherLocation *
    cafeweather_location_ref (CafeWeatherLocation *loc);

Adds 1 to `loc` 's reference count.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc`

### cafeweather_location_unref ()

    void
    cafeweather_location_unref (CafeWeatherLocation *loc);

Subtracts 1 from `loc` 's reference count, and frees it if the reference count reaches 0.

#### Parameters

loc | a CafeWeatherLocation |

### cafeweather_location_get_name ()

    const char *
    cafeweather_location_get_name (CafeWeatherLocation *loc);

Gets `loc` 's name, localized into the current language.

Note that `CAFEWEATHER_LOCATION_WEATHER_STATION` nodes are not localized, and so the name returned for those nodes will always be in English, and should therefore not be displayed to the user. (FIXME: should we just not return a name?)

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's name

### cafeweather_location_get_sort_name ()

    const char *
    cafeweather_location_get_sort_name (CafeWeatherLocation *loc);

Gets `loc` 's "sort name", which is the name after having `g_utf8_normalize()` (with `G_NORMALIZE_ALL`) and `g_utf8_casefold()` called on it. You can use this to sort locations, or to comparing user input against a location name.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's sort name

### cafeweather_location_get_level ()

    CafeWeatherLocationLevel
    cafeweather_location_get_level (CafeWeatherLocation *loc);

Gets `loc` 's level, from `CAFEWEATHER_LOCATION_WORLD`, to `CAFEWEATHER_LOCATION_WEATHER_STATION`.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's level

### cafeweather_location_get_parent ()

    CafeWeatherLocation *
    cafeweather_location_get_parent (CafeWeatherLocation *loc);

Gets `loc` 's parent location.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's parent, or `NULL` if `loc` is a `CAFEWEATHER_LOCATION_WORLD` node.

[transfer none][allow-none]

### cafeweather_location_get_children ()

    CafeWeatherLocation **
    cafeweather_location_get_children (CafeWeatherLocation *loc);

Gets an array of `loc` 's children; this is owned by `loc` and will not remain valid if `loc` is freed.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's children. (May be empty, but will not be `NULL`.).

[transfer none][array zero-terminated=1]

### cafeweather_location_free_children ()

    void
    cafeweather_location_free_children (CafeWeatherLocation *loc,
                                        CafeWeatherLocation **children);

`cafeweather_location_free_children` is deprecated and should not be used in newly-written code.

This is a no-op.

This is a no-op. Do not use it.

#### Parameters

loc | a CafeWeatherLocation |
children | an array of `loc` 's children |

### cafeweather_location_has_coords ()

    gboolean
    cafeweather_location_has_coords (CafeWeatherLocation *loc);

Checks if `loc` has valid latitude and longitude.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`TRUE` if `loc` has valid latitude and longitude.

### cafeweather_location_get_coords ()

    void
    cafeweather_location_get_coords (CafeWeatherLocation *loc,
                                     double *latitude,
                                     double *longitude);

Gets `loc` 's coordinates; you must check `cafeweather_location_has_coords()` before calling this.

#### Parameters

loc | a CafeWeatherLocation |
latitude | on return will contain `loc` 's latitude. | [out]
longitude | on return will contain `loc` 's longitude. | [out]

### cafeweather_location_get_distance ()

    double
    cafeweather_location_get_distance (CafeWeatherLocation *loc,
                                       CafeWeatherLocation *loc2);

Determines the distance in kilometers between `loc` and `loc2` .

#### Parameters

loc | a CafeWeatherLocation |
loc2 | a second CafeWeatherLocation |

#### Returns

the distance between `loc` and `loc2` .

### cafeweather_location_get_country ()

    const char *
    cafeweather_location_get_country (CafeWeatherLocation *loc);

Gets the ISO 3166 country code of `loc` (or `NULL` if `loc` is a region- or world-level location)

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's country code (or `NULL` if `loc` is a region- or world-level location).

[allow-none]

### cafeweather_location_get_timezone ()

    CafeWeatherTimezone *
    cafeweather_location_get_timezone (CafeWeatherLocation *loc);

Gets the timezone associated with `loc` , if known.

The timezone is owned either by `loc` or by one of its parents. FIXME.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's timezone, or `NULL`.

[transfer none][allow-none]

### cafeweather_location_get_timezones ()

    CafeWeatherTimezone **
    cafeweather_location_get_timezones (CafeWeatherLocation *loc);

Gets an array of all timezones associated with any location under `loc` . You can use `cafeweather_location_free_timezones()` to free this array.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

an array of timezones. May be empty but will not be `NULL`.

[transfer full][array zero-terminated=1]

### cafeweather_location_free_timezones ()

    void
    cafeweather_location_free_timezones (CafeWeatherLocation *loc,
                                         CafeWeatherTimezone **zones);

Frees the array of timezones returned by `cafeweather_location_get_timezones()`.

#### Parameters

loc | a CafeWeatherLocation |
zones | an array returned from `cafeweather_location_get_timezones()` |

### cafeweather_location_get_code ()

    const char *
    cafeweather_location_get_code (CafeWeatherLocation *loc);

Gets the METAR station code associated with a `CAFEWEATHER_LOCATION_WEATHER_STATION` location.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

`loc` 's METAR station code, or `NULL`.

[allow-none]

### cafeweather_location_get_city_name ()

    char *
    cafeweather_location_get_city_name (CafeWeatherLocation *loc);

For a `CAFEWEATHER_LOCATION_CITY` location, this is equivalent to `cafeweather_location_get_name()`. For a `CAFEWEATHER_LOCATION_WEATHER_STATION` location, it is equivalent to calling `cafeweather_location_get_name()` on the location's parent. For other locations it will return `NULL`.

#### Parameters

loc | a CafeWeatherLocation |

#### Returns

(allow-none) `loc` 's city name, or `NULL`

### cafeweather_location_get_weather ()

    WeatherInfo *
    cafeweather_location_get_weather (CafeWeatherLocation *loc);

Creates a WeatherInfo corresponding to `loc` ; you can use `weather_info_update()` to fill it in.

#### Parameters

loc | a `CafeWeatherLocation` |

#### Returns

a WeatherInfo corresponding to `loc` .

[transfer full]

## Types and Values

### CafeWeatherLocation

    typedef struct _CafeWeatherLocation CafeWeatherLocation;

### enum CafeWeatherLocationLevel

The size/scope of a particular CafeWeatherLocation.

Locations form a hierarchy, with a `CAFEWEATHER_LOCATION_WORLD` location at the top, divided into regions or countries, and so on. Countries may or may not be divided into "adm1"s, and "adm1"s may or may not be divided into "adm2"s. A city will have at least one, and possibly several, weather stations inside it. Weather stations will never appear outside of cities.

#### Members

CAFEWEATHER_LOCATION_WORLD | A location representing the entire world. |
CAFEWEATHER_LOCATION_REGION | A location representing a continent or other top-level region. |
CAFEWEATHER_LOCATION_COUNTRY | A location representing a "country" (or other geographic unit that has an ISO-3166 country code) |
CAFEWEATHER_LOCATION_ADM1 | A location representing a "first-level administrative division"; ie, a state, province, or similar division. |
CAFEWEATHER_LOCATION_ADM2 | A location representing a subdivision of a `CAFEWEATHER_LOCATION_ADM1` location. (Not currently used.) |
CAFEWEATHER_LOCATION_CITY | A location representing a city |
CAFEWEATHER_LOCATION_WEATHER_STATION | A location representing a weather station. |