~ubuntu-branches/ubuntu/wily/redshift/wily

« back to all changes in this revision

Viewing changes to .pc/retry-geoclue.patch/src/location-geoclue.c

  • Committer: Package Import Robot
  • Author(s): Jonathan Davies
  • Date: 2013-11-08 09:47:22 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131108094722-mdl1c0cl5a6ljsyx
Tags: 1.8-0ubuntu1
* New upstream release.
* debian/control:
  - Created transition package for gtk-redshift → redshift-gtk.
  - Added autoconf, autopoint and libtool to build-dependencies for upstream
    "bootstrap" script.
  - Added libxext-dev to build-dependencies, needed for vidmode check.
  - Updated Standards-Version.
* debian/gtk-redshift.* files renamed to redshift-gtk.*.
* debian/redshift-gtk.links: Created to make transitional symlink from old
  name to new.
* Dropped: debian/patches/retry-geoclue.patch - let's try upstream's code
  instead.
* debian/patches/retry-geoclue.patch: Also dropped, this seems to have been
  a provider issue.
* debian/rules:
  - Removed dh_auto_install override.
  - Created dh_clean override to clean up files left behind by upstream
    bootstrap script.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* location-geoclue.c -- Geoclue location provider source
2
 
   This file is part of Redshift.
3
 
 
4
 
   Redshift is free software: you can redistribute it and/or modify
5
 
   it under the terms of the GNU General Public License as published by
6
 
   the Free Software Foundation, either version 3 of the License, or
7
 
   (at your option) any later version.
8
 
 
9
 
   Redshift is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
   GNU General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU General Public License
15
 
   along with Redshift.  If not, see <http://www.gnu.org/licenses/>.
16
 
 
17
 
   Copyright (c) 2010  Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com>
18
 
*/
19
 
 
20
 
#include <stdio.h>
21
 
#include <string.h>
22
 
 
23
 
#include <geoclue/geoclue-master.h>
24
 
#include <geoclue/geoclue-position.h>
25
 
 
26
 
#include "location-geoclue.h"
27
 
 
28
 
#ifdef ENABLE_NLS
29
 
# include <libintl.h>
30
 
# define _(s) gettext(s)
31
 
#else
32
 
# define _(s) s
33
 
#endif
34
 
 
35
 
#define DEFAULT_PROVIDER "org.freedesktop.Geoclue.Providers.UbuntuGeoIP"
36
 
#define DEFAULT_PROVIDER_PATH "/org/freedesktop/Geoclue/Providers/UbuntuGeoIP"
37
 
 
38
 
int
39
 
location_geoclue_init(location_geoclue_state_t *state)
40
 
{
41
 
        g_type_init();
42
 
        
43
 
        state->position = NULL;
44
 
        state->provider = NULL;
45
 
        state->provider_path = NULL;
46
 
        
47
 
        return 0;
48
 
}
49
 
 
50
 
int
51
 
location_geoclue_start(location_geoclue_state_t *state)
52
 
{
53
 
        GeoclueMaster *master = NULL;
54
 
        GeoclueMasterClient *client = NULL;
55
 
        GError *error = NULL;
56
 
        gchar *name = NULL;
57
 
 
58
 
        if (!(state->provider && state->provider_path)) {
59
 
                master = geoclue_master_get_default();
60
 
                client = geoclue_master_create_client(master, NULL, NULL);
61
 
 
62
 
                if (!geoclue_master_client_set_requirements(client,
63
 
                                                            GEOCLUE_ACCURACY_LEVEL_REGION,
64
 
                                                            0, FALSE,
65
 
                                                            GEOCLUE_RESOURCE_NETWORK,
66
 
                                                            &error)) {
67
 
                        g_printerr(_("Can't set requirements for master: %s"),
68
 
                                   error->message);
69
 
                        g_error_free(error);
70
 
                        g_object_unref(client);
71
 
 
72
 
                        return -1;
73
 
                }
74
 
 
75
 
                state->position = geoclue_master_client_create_position(client, NULL);
76
 
        } else {
77
 
                state->position = geoclue_position_new(state->provider,
78
 
                                                       state->provider_path);
79
 
        }
80
 
 
81
 
        if (geoclue_provider_get_provider_info(GEOCLUE_PROVIDER(state->position),
82
 
                                               &name, NULL, NULL)) {
83
 
                fprintf(stdout, _("Started Geoclue provider `%s'.\n"), name);
84
 
                g_free(name);
85
 
        } else {
86
 
                fputs(_("Could not find a usable Geoclue provider.\n"), stderr);
87
 
                fputs(_("Try setting name and path to specify which to use.\n"), stderr);
88
 
                return -1;
89
 
        }
90
 
 
91
 
        return 0;
92
 
}
93
 
 
94
 
void
95
 
location_geoclue_free(location_geoclue_state_t *state)
96
 
{
97
 
        if (state->position != NULL) g_object_unref(state->position);
98
 
}
99
 
 
100
 
void
101
 
location_geoclue_print_help(FILE *f)
102
 
{
103
 
        fputs(_("Use the location as discovered by a Geoclue provider.\n"), f);
104
 
        fputs("\n", f);
105
 
 
106
 
        /* TRANSLATORS: Geoclue help output
107
 
           left column must not be translated */
108
 
        fputs(_("  name=N\tName of Geoclue provider (or `default')\n"
109
 
                "  path=N\tPath of Geoclue provider (or `default')\n"), f);
110
 
        fputs("\n", f);
111
 
}
112
 
 
113
 
int
114
 
location_geoclue_set_option(location_geoclue_state_t *state,
115
 
                            const char *key, const char *value)
116
 
{
117
 
        const char *provider = NULL;
118
 
        const char *path = NULL;
119
 
 
120
 
        /* Parse string value */
121
 
        if (key != NULL && strcasecmp(key, "name") == 0) {
122
 
                if (value != NULL && strcasecmp(value, "default") == 0) {
123
 
                        provider = DEFAULT_PROVIDER;
124
 
                } else if (value != NULL) {
125
 
                        provider = value;
126
 
                } else {
127
 
                        fputs(_("Must specify a provider `name' (or use `default').\n"), stderr);
128
 
                        return -1;
129
 
                }
130
 
 
131
 
                /* TODO I don't think we own the string here, should be copied. */
132
 
                state->provider = provider;
133
 
        } else if (key != NULL && strcasecmp(key, "path") == 0) {
134
 
                if (value != NULL && strcasecmp(value, "default") == 0) {
135
 
                        path = DEFAULT_PROVIDER_PATH;
136
 
                } else if (value != NULL) {
137
 
                        path = value;
138
 
                } else {
139
 
                        fputs(_("Must specify a provider `path' (or use `default').\n"), stderr);
140
 
                        return -1;
141
 
                }
142
 
 
143
 
                /* TODO I don't think we own the string here, should be copied. */
144
 
                state->provider_path = path;
145
 
        } else if (key == NULL) {
146
 
                return -1;
147
 
        } else {
148
 
                fprintf(stderr, _("Unknown method parameter: `%s'.\n"), key);
149
 
                return -1;
150
 
        }
151
 
 
152
 
        return 0;
153
 
}
154
 
 
155
 
int
156
 
location_geoclue_get_location(location_geoclue_state_t *state,
157
 
                              float *lat, float *lon)
158
 
{
159
 
        GeocluePositionFields fields;
160
 
        GError *error = NULL;
161
 
        double latitude = 0, longitude = 0;
162
 
 
163
 
        fields = geoclue_position_get_position(state->position, NULL,
164
 
                                               &latitude, &longitude, NULL,
165
 
                                               NULL, &error);
166
 
        if (error) {
167
 
                g_printerr(_("Could not get location: %s.\n"), error->message);
168
 
                g_error_free(error);
169
 
                return -1;
170
 
        }
171
 
        
172
 
        if (fields & GEOCLUE_POSITION_FIELDS_LATITUDE &&
173
 
            fields & GEOCLUE_POSITION_FIELDS_LONGITUDE) {
174
 
                fprintf(stdout, _("According to the geoclue provider"
175
 
                                  " we're at: %.2f, %.2f\n"),
176
 
                        latitude, longitude);
177
 
        } else {
178
 
                g_warning(_("Provider does not have a valid location available."));
179
 
                return -1;
180
 
        }
181
 
 
182
 
        *lat = latitude;
183
 
        *lon = longitude;
184
 
 
185
 
        return 0;
186
 
}