diff options
Diffstat (limited to 'src/location-geoclue.c')
-rw-r--r-- | src/location-geoclue.c | 156 |
1 files changed, 76 insertions, 80 deletions
diff --git a/src/location-geoclue.c b/src/location-geoclue.c index 4d9c892..6946dd8 100644 --- a/src/location-geoclue.c +++ b/src/location-geoclue.c @@ -20,9 +20,6 @@ #include <stdio.h> #include <string.h> -#include <math.h> - -#include <gconf/gconf-client.h> #include <geoclue/geoclue-master.h> #include <geoclue/geoclue-position.h> @@ -41,7 +38,7 @@ int location_geoclue_init(location_geoclue_state_t *state) { - g_type_init (); + g_type_init(); state->position = NULL; state->provider = NULL; @@ -57,51 +54,47 @@ location_geoclue_start(location_geoclue_state_t *state) GeoclueMasterClient *client = NULL; GError *error = NULL; gchar *name = NULL; - gchar *desc = NULL; if (!(state->provider && state->provider_path)) { - master = geoclue_master_get_default (); - client = geoclue_master_create_client (master, NULL, NULL); - - if (!geoclue_master_client_set_requirements (client, - GEOCLUE_ACCURACY_LEVEL_REGION, - 0, FALSE, - GEOCLUE_RESOURCE_NETWORK, - &error)) { - g_printerr (_("Can't set requirements for master: %s"), - error->message); - g_error_free (error); - g_object_unref (client); - return 1; + master = geoclue_master_get_default(); + client = geoclue_master_create_client(master, NULL, NULL); + + if (!geoclue_master_client_set_requirements(client, + GEOCLUE_ACCURACY_LEVEL_REGION, + 0, FALSE, + GEOCLUE_RESOURCE_NETWORK, + &error)) { + g_printerr(_("Can't set requirements for master: %s"), + error->message); + g_error_free(error); + g_object_unref(client); + + return -1; } - state->position = geoclue_master_client_create_position (client, NULL); - } - else { - state->position = geoclue_position_new (state->provider, - state->provider_path); + state->position = geoclue_master_client_create_position(client, NULL); + } else { + state->position = geoclue_position_new(state->provider, + state->provider_path); } - if (geoclue_provider_get_provider_info (GEOCLUE_PROVIDER (state->position), - &name, &desc, NULL)) { - fprintf (stdout, _("Started provider '%s':\n"), name); - fprintf (stdout, "%s\n", desc); - g_free (name); - g_free (desc); - } - else { - fputs(_("Could not find a usable Geoclue provider.\n"), stderr); + if (geoclue_provider_get_provider_info(GEOCLUE_PROVIDER(state->position), + &name, NULL, NULL)) { + fprintf(stdout, _("Started Geoclue provider `%s'.\n"), name); + g_free(name); + } else { + fputs(_("Could not find a usable Geoclue provider.\n"), stderr); fputs(_("Try setting name and path to specify which to use.\n"), stderr); - return 1; + return -1; } + return 0; } void location_geoclue_free(location_geoclue_state_t *state) { - if (state->position != NULL) - g_object_unref (state->position); + if (state->position != NULL) g_object_unref(state->position); } void @@ -109,82 +102,85 @@ location_geoclue_print_help(FILE *f) { fputs(_("Use the location as discovered by a Geoclue provider.\n"), f); fputs("\n", f); + + /* TRANSLATORS: Geoclue help output + left column must not be translated */ + fputs(_(" name=N\tName of Geoclue provider (or `default')\n" + " path=N\tPath of Geoclue provider (or `default')\n"), f); + fputs("\n", f); } int location_geoclue_set_option(location_geoclue_state_t *state, - const char *key, const char *value) + const char *key, const char *value) { - const char *provider = NULL, *path = NULL; - int i = 0; + const char *provider = NULL; + const char *path = NULL; - /* Parse string value */ - if (key != NULL && strcasecmp(key, "name") == 0) { - if (value != NULL && strcasecmp(value, "default") == 0) + /* Parse string value */ + if (key != NULL && strcasecmp(key, "name") == 0) { + if (value != NULL && strcasecmp(value, "default") == 0) { provider = DEFAULT_PROVIDER; - else if (value != NULL) + } else if (value != NULL) { provider = value; - else { - fputs(_("Must specify a provider 'name' (or use 'default').\n"), stderr); - return -1; + } else { + fputs(_("Must specify a provider `name' (or use `default').\n"), stderr); + return -1; } - state->provider = provider; - } - else if (key != NULL && strcasecmp(key, "path") == 0) { - if (value != NULL && strcasecmp(value, "default") == 0) + + /* TODO I don't think we own the string here, should be copied. */ + state->provider = provider; + } else if (key != NULL && strcasecmp(key, "path") == 0) { + if (value != NULL && strcasecmp(value, "default") == 0) { path = DEFAULT_PROVIDER_PATH; - else if (value != NULL) + } else if (value != NULL) { path = value; - else { - fputs(_("Must specify a provider 'path' (or use 'default').\n"), stderr); - return -1; + } else { + fputs(_("Must specify a provider `path' (or use `default').\n"), stderr); + return -1; } - state->provider_path = path; - } - else if (key == NULL) { + + /* TODO I don't think we own the string here, should be copied. */ + state->provider_path = path; + } else if (key == NULL) { return -1; - } - else { - fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); - return -1; - } + } else { + fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key); + return -1; + } - return 0; + return 0; } int location_geoclue_get_location(location_geoclue_state_t *state, - float *lat, float *lon) + float *lat, float *lon) { GeocluePositionFields fields; GError *error = NULL; double latitude = 0, longitude = 0; - fields = geoclue_position_get_position (state->position, NULL, - &latitude, &longitude, NULL, - NULL, &error); + fields = geoclue_position_get_position(state->position, NULL, + &latitude, &longitude, NULL, + NULL, &error); if (error) { - g_printerr (_("Could not get location: %s.\n"), error->message); - g_error_free (error); - return 1; + g_printerr(_("Could not get location: %s.\n"), error->message); + g_error_free(error); + return -1; } if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE && fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) { - fprintf (stdout, _("According to the geoclue provider we're at:\n")); - fprintf (stdout, _("Latitude: %.3f %s\n"), - fabs(latitude), - latitude <= 0 ? _("S") : _("N")); - fprintf (stdout, _("Longitude: %.3f %s\n"), - fabs(longitude), - longitude <= 0 ? _("W") : _("E")); + fprintf(stdout, _("According to the geoclue provider" + " we're at: %.2f, %.2f\n"), + latitude, longitude); } else { - g_warning (_("Provider does not have a valid location available.")); - return 1; + g_warning(_("Provider does not have a valid location available.")); + return -1; } - lat = &latitude; - lon = &longitude; + *lat = latitude; + *lon = longitude; return 0; } |