Add location_t type with lat/lon fields

This commit is contained in:
Jon Lund Steffensen
2015-01-04 16:32:47 -05:00
parent 0510031b69
commit 799b08214d
10 changed files with 56 additions and 43 deletions
+3 -1
View File
@@ -22,6 +22,8 @@
#include <stdio.h>
#include "redshift.h"
int location_corelocation_init(void *state);
int location_corelocation_start(void *state);
@@ -32,7 +34,7 @@ int location_corelocation_set_option(void *state,
const char *key, const char *value);
int location_corelocation_get_location(void *state,
float *lat, float *lon);
location_t *location);
#endif /* ! REDSHIFT_LOCATION_CORELOCATION_H */
+4 -3
View File
@@ -25,6 +25,7 @@
#import <CoreLocation/CoreLocation.h>
#include "location-corelocation.h"
#include "redshift.h"
#include <stdio.h>
@@ -143,7 +144,7 @@ location_corelocation_set_option(void *state,
int
location_corelocation_get_location(void *state,
float *lat, float *lon)
location_t *location)
{
int result = -1;
@@ -153,8 +154,8 @@ location_corelocation_get_location(void *state,
CFRunLoopRun();
if (delegate.success) {
*lat = delegate.latitude;
*lon = delegate.longitude;
location->lat = delegate.latitude;
location->lon = delegate.longitude;
result = 0;
}
}
+4 -3
View File
@@ -28,6 +28,7 @@
#include <glib-object.h>
#include "location-geoclue.h"
#include "redshift.h"
#ifdef ENABLE_NLS
# include <libintl.h>
@@ -185,7 +186,7 @@ location_geoclue_set_option(location_geoclue_state_t *state,
int
location_geoclue_get_location(location_geoclue_state_t *state,
float *lat, float *lon)
location_t *location)
{
GeocluePositionFields fields;
GError *error = NULL;
@@ -210,8 +211,8 @@ location_geoclue_get_location(location_geoclue_state_t *state,
return -1;
}
*lat = latitude;
*lon = longitude;
location->lat = latitude;
location->lon = longitude;
return 0;
}
+3 -1
View File
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <geoclue/geoclue-position.h>
#include "redshift.h"
typedef struct {
GeocluePosition *position; /* main geoclue object */
char *provider; /* name of a geoclue provider */
@@ -38,7 +40,7 @@ int location_geoclue_set_option(location_geoclue_state_t *state,
const char *key, const char *value);
int location_geoclue_get_location(location_geoclue_state_t *state,
float *lat, float *lon);
location_t *loc);
#endif /* ! REDSHIFT_LOCATION_GEOCLUE_H */
+6 -7
View File
@@ -25,6 +25,7 @@
#include <gio/gio.h>
#include "location-geoclue2.h"
#include "redshift.h"
#ifdef ENABLE_NLS
# include <libintl.h>
@@ -38,8 +39,7 @@ typedef struct {
GMainLoop *loop;
int available;
float latitude;
float longitude;
location_t location;
} get_location_data_t;
@@ -120,11 +120,11 @@ geoclue_client_signal_cb(GDBusProxy *client, gchar *sender_name,
/* Read location properties */
GVariant *lat_v = g_dbus_proxy_get_cached_property(location,
"Latitude");
data->latitude = g_variant_get_double(lat_v);
data->location.lat = g_variant_get_double(lat_v);
GVariant *lon_v = g_dbus_proxy_get_cached_property(location,
"Longitude");
data->longitude = g_variant_get_double(lon_v);
data->location.lon = g_variant_get_double(lon_v);
data->available = 1;
@@ -273,7 +273,7 @@ on_name_vanished(GDBusConnection *connection, const gchar *name,
int
location_geoclue2_get_location(void *state,
float *lat, float *lon)
location_t *location)
{
get_location_data_t data;
data.available = 0;
@@ -291,8 +291,7 @@ location_geoclue2_get_location(void *state,
if (!data.available) return -1;
*lat = data.latitude;
*lon = data.longitude;
*location = data.location;
return 0;
}
+3 -1
View File
@@ -22,6 +22,8 @@
#include <stdio.h>
#include "redshift.h"
int location_geoclue2_init(void *state);
int location_geoclue2_start(void *state);
@@ -32,7 +34,7 @@ int location_geoclue2_set_option(void *state,
const char *key, const char *value);
int location_geoclue2_get_location(void *state,
float *lat, float *lon);
location_t *loc);
#endif /* ! REDSHIFT_LOCATION_GEOCLUE2_H */
+9 -10
View File
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
*/
#include <stdio.h>
@@ -36,8 +36,8 @@
int
location_manual_init(location_manual_state_t *state)
{
state->lat = NAN;
state->lon = NAN;
state->loc.lat = NAN;
state->loc.lon = NAN;
return 0;
}
@@ -46,7 +46,7 @@ int
location_manual_start(location_manual_state_t *state)
{
/* Latitude and longitude must be set */
if (isnan(state->lat) || isnan(state->lon)) {
if (isnan(state->loc.lat) || isnan(state->loc.lon)) {
fputs(_("Latitude and longitude must be set.\n"), stderr);
exit(EXIT_FAILURE);
}
@@ -89,9 +89,9 @@ location_manual_set_option(location_manual_state_t *state, const char *key,
}
if (strcasecmp(key, "lat") == 0) {
state->lat = v;
state->loc.lat = v;
} else if (strcasecmp(key, "lon") == 0) {
state->lon = v;
state->loc.lon = v;
} else {
fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
return -1;
@@ -101,11 +101,10 @@ location_manual_set_option(location_manual_state_t *state, const char *key,
}
int
location_manual_get_location(location_manual_state_t *state, float *lat,
float *lon)
location_manual_get_location(location_manual_state_t *state,
location_t *loc)
{
*lat = state->lat;
*lon = state->lon;
*loc = state->loc;
return 0;
}
+6 -5
View File
@@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with Redshift. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
Copyright (c) 2010-2014 Jon Lund Steffensen <jonlst@gmail.com>
*/
#ifndef REDSHIFT_LOCATION_MANUAL_H
@@ -22,10 +22,11 @@
#include <stdio.h>
#include "redshift.h"
typedef struct {
float lat;
float lon;
location_t loc;
} location_manual_state_t;
@@ -37,8 +38,8 @@ void location_manual_print_help(FILE *f);
int location_manual_set_option(location_manual_state_t *state,
const char *key, const char *value);
int location_manual_get_location(location_manual_state_t *state, float *lat,
float *lon);
int location_manual_get_location(location_manual_state_t *state,
location_t *loc);
#endif /* ! REDSHIFT_LOCATION_MANUAL_H */
+11 -9
View File
@@ -1119,8 +1119,7 @@ main(int argc, char *argv[])
if (transition < 0) transition = 1;
float lat = NAN;
float lon = NAN;
location_t loc = { NAN, NAN };
/* Initialize location provider. If provider is NULL
try all providers until one that works is found. */
@@ -1167,7 +1166,7 @@ main(int argc, char *argv[])
}
/* Get current location. */
r = provider->get_location(&location_state, &lat, &lon);
r = provider->get_location(&location_state, &loc);
if (r < 0) {
fputs(_("Unable to get location from provider.\n"),
stderr);
@@ -1190,8 +1189,10 @@ main(int argc, char *argv[])
The string following each number is an abreviation for
north, source, east or west (N, S, E, W). */
printf(_("Location: %.2f %s, %.2f %s\n"),
fabs(lat), lat >= 0.f ? north : south,
fabs(lon), lon >= 0.f ? east : west);
fabs(loc.lat),
loc.lat >= 0.f ? north : south,
fabs(loc.lon),
loc.lon >= 0.f ? east : west);
printf(_("Temperatures: %dK at day, %dK at night\n"),
day.temperature, night.temperature);
@@ -1202,7 +1203,7 @@ main(int argc, char *argv[])
}
/* Latitude */
if (lat < MIN_LAT || lat > MAX_LAT) {
if (loc.lat < MIN_LAT || loc.lat > MAX_LAT) {
/* TRANSLATORS: Append degree symbols if possible. */
fprintf(stderr,
_("Latitude must be between %.1f and %.1f.\n"),
@@ -1211,7 +1212,7 @@ main(int argc, char *argv[])
}
/* Longitude */
if (lon < MIN_LON || lon > MAX_LON) {
if (loc.lon < MIN_LON || loc.lon > MAX_LON) {
/* TRANSLATORS: Append degree symbols if possible. */
fprintf(stderr,
_("Longitude must be between"
@@ -1339,7 +1340,7 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
double elevation = solar_elevation(now, lat, lon);
double elevation = solar_elevation(now, loc.lat, loc.lon);
if (verbose) {
/* TRANSLATORS: Append degree symbol if possible. */
@@ -1555,7 +1556,8 @@ main(int argc, char *argv[])
}
/* Current angular elevation of the sun */
double elevation = solar_elevation(now, lat, lon);
double elevation =
solar_elevation(now, loc.lat, loc.lon);
/* Use elevation of sun to set color temperature */
color_setting_t interp;
+7 -3
View File
@@ -24,6 +24,12 @@
#include <stdlib.h>
/* Location */
typedef struct {
float lat;
float lon;
} location_t;
/* Periods of day. */
typedef enum {
PERIOD_NONE = 0,
@@ -32,7 +38,6 @@ typedef enum {
PERIOD_TRANSITION
} period_t;
/* Color setting */
typedef struct {
int temperature;
@@ -84,8 +89,7 @@ typedef void location_provider_free_func(void *state);
typedef void location_provider_print_help_func(FILE *f);
typedef int location_provider_set_option_func(void *state, const char *key,
const char *value);
typedef int location_provider_get_location_func(void *state, float *lat,
float *lon);
typedef int location_provider_get_location_func(void *state, location_t *loc);
typedef struct {
char *name;