diff options
-rw-r--r-- | configure.ac | 27 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/gamma-w32gdi.c | 43 | ||||
-rw-r--r-- | src/gamma-w32gdi.h | 1 | ||||
-rw-r--r-- | src/location-geoclue.c | 156 | ||||
-rw-r--r-- | src/location-geoclue.h | 4 | ||||
-rw-r--r-- | src/redshift.c | 2 |
7 files changed, 134 insertions, 102 deletions
diff --git a/configure.ac b/configure.ac index c59a36d..261c4ec 100644 --- a/configure.ac +++ b/configure.ac @@ -114,7 +114,7 @@ AC_ARG_ENABLE([gnome-clock], [AC_HELP_STRING([--enable-gnome-clock], [enable GNOME Clock location provider])], [enable_gnome_clock=$enableval],[enable_gnome_clock=maybe]) AS_IF([test "x$enable_gnome_clock" != xno], [ - AS_IF([test $have_glib = yes -a $have_gconf = yes], [ + AS_IF([test "x$have_glib" = "xyes" -a "x$have_gconf" = xyes], [ AC_DEFINE([ENABLE_GNOME_CLOCK], 1, [Define to 1 to enable GNOME Clock location provider]) AC_MSG_RESULT([yes]) @@ -132,15 +132,31 @@ AS_IF([test "x$enable_gnome_clock" != xno], [ ]) AM_CONDITIONAL([ENABLE_GNOME_CLOCK], [test "x$enable_gnome_clock" = xyes]) -# conditionally enable geoclue provider +# Check Geoclue location provider +AC_MSG_CHECKING([whether to enable Geoclue location provider]) AC_ARG_ENABLE([geoclue], [AC_HELP_STRING([--enable-geoclue], - [enable Geoclue location provider])], - [enable_geoclue=yes + [enable Geoclue location provider])], + [enable_geoclue=$enableval],[enable_geoclue=maybe]) +AS_IF([test "x$enable_geoclue" != xno], [ + AS_IF([test "x$have_geoclue" = xyes], [ AC_DEFINE([ENABLE_GEOCLUE], 1, [Define to 1 to enable Geoclue location provider]) - ],[enable_geoclue=no]) + AC_MSG_RESULT([yes]) + enable_geoclue=yes + ], [ + AC_MSG_RESULT([missing dependencies]) + AS_IF([test "x$enable_geoclue" = xyes], [ + AC_MSG_ERROR([missing dependencies for Geoclue location provider]) + ]) + enable_geoclue=no + ]) +], [ + AC_MSG_RESULT([no]) + enable_geoclue=no +]) AM_CONDITIONAL([ENABLE_GEOCLUE], [test "x$enable_geoclue" = xyes]) + # Check for GUI status icon AC_MSG_CHECKING([whether to enable GUI status icon]) AC_ARG_ENABLE([gui], [AC_HELP_STRING([--enable-gui], @@ -197,6 +213,7 @@ echo " Location providers: GNOME Clock: ${enable_gnome_clock} + Geoclue: ${enable_geoclue} GUI: ${enable_gui} " diff --git a/src/Makefile.am b/src/Makefile.am index b19efab..6c4a613 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,8 +58,7 @@ endif if ENABLE_GEOCLUE redshift_SOURCES += location-geoclue.c location-geoclue.h -AM_CFLAGS += $(GLIB_CFLAGS) $(GCONF_CFLAGS) $(GEOCLUE_LIBS) $(GEOCLUE_CFLAGS) +AM_CFLAGS += $(GEOCLUE_CFLAGS) $(GEOCLUE_LIBS) redshift_LDADD += \ - $(GLIB_LIBS) $(GLIB_CFLAGS) \ $(GEOCLUE_LIBS) $(GEOCLUE_CFLAGS) endif diff --git a/src/gamma-w32gdi.c b/src/gamma-w32gdi.c index aa2474d..c5f760e 100644 --- a/src/gamma-w32gdi.c +++ b/src/gamma-w32gdi.c @@ -43,7 +43,6 @@ int w32gdi_init(w32gdi_state_t *state) { state->saved_ramps = NULL; - state->hDC = NULL; return 0; } @@ -54,14 +53,14 @@ w32gdi_start(w32gdi_state_t *state) BOOL r; /* Open device context */ - state->hDC = GetDC(NULL); - if (state->hDC == NULL) { + HDC hDC = GetDC(NULL); + if (hDC == NULL) { fputs(_("Unable to open device context.\n"), stderr); return -1; } /* Check support for gamma ramps */ - int cmcap = GetDeviceCaps(state->hDC, COLORMGMTCAPS); + int cmcap = GetDeviceCaps(hDC, COLORMGMTCAPS); if (cmcap != CM_GAMMA_RAMP) { fputs(_("Display device does not support gamma ramps.\n"), stderr); @@ -72,18 +71,21 @@ w32gdi_start(w32gdi_state_t *state) state->saved_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD)); if (state->saved_ramps == NULL) { perror("malloc"); - ReleaseDC(NULL, state->hDC); + ReleaseDC(NULL, hDC); return -1; } /* Save current gamma ramps so we can restore them at program exit */ - r = GetDeviceGammaRamp(state->hDC, state->saved_ramps); + r = GetDeviceGammaRamp(hDC, state->saved_ramps); if (!r) { fputs(_("Unable to save current gamma ramp.\n"), stderr); - ReleaseDC(NULL, state->hDC); + ReleaseDC(NULL, hDC); return -1; } + /* Release device context */ + ReleaseDC(NULL, hDC); + return 0; } @@ -92,9 +94,6 @@ w32gdi_free(w32gdi_state_t *state) { /* Free saved ramps */ free(state->saved_ramps); - - /* Release device context */ - if (state->hDC != NULL) ReleaseDC(NULL, state->hDC); } @@ -114,9 +113,19 @@ w32gdi_set_option(w32gdi_state_t *state, const char *key, const char *value) void w32gdi_restore(w32gdi_state_t *state) { + /* Open device context */ + HDC hDC = GetDC(NULL); + if (hDC == NULL) { + fputs(_("Unable to open device context.\n"), stderr); + return; + } + /* Restore gamma ramps */ - BOOL r = SetDeviceGammaRamp(state->hDC, state->saved_ramps); + BOOL r = SetDeviceGammaRamp(hDC, state->saved_ramps); if (!r) fputs(_("Unable to restore gamma ramps.\n"), stderr); + + /* Release device context */ + ReleaseDC(NULL, hDC); } int @@ -124,6 +133,13 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) { BOOL r; + /* Open device context */ + HDC hDC = GetDC(NULL); + if (hDC == NULL) { + fputs(_("Unable to open device context.\n"), stderr); + return -1; + } + /* Create new gamma ramps */ WORD *gamma_ramps = malloc(3*GAMMA_RAMP_SIZE*sizeof(WORD)); if (gamma_ramps == NULL) { @@ -139,7 +155,7 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) temp, gamma); /* Set new gamma ramps */ - r = SetDeviceGammaRamp(state->hDC, gamma_ramps); + r = SetDeviceGammaRamp(hDC, gamma_ramps); if (!r) { fputs(_("Unable to set gamma ramps.\n"), stderr); free(gamma_ramps); @@ -148,5 +164,8 @@ w32gdi_set_temperature(w32gdi_state_t *state, int temp, float gamma[3]) free(gamma_ramps); + /* Release device context */ + ReleaseDC(NULL, hDC); + return 0; } diff --git a/src/gamma-w32gdi.h b/src/gamma-w32gdi.h index 6cb9799..9dc2657 100644 --- a/src/gamma-w32gdi.h +++ b/src/gamma-w32gdi.h @@ -25,7 +25,6 @@ typedef struct { - HDC hDC; WORD *saved_ramps; } w32gdi_state_t; 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; } diff --git a/src/location-geoclue.h b/src/location-geoclue.h index 18629af..40ab22c 100644 --- a/src/location-geoclue.h +++ b/src/location-geoclue.h @@ -35,10 +35,10 @@ void location_geoclue_free(location_geoclue_state_t *state); void location_geoclue_print_help(FILE *f); int location_geoclue_set_option(location_geoclue_state_t *state, - const char *key, const char *value); + const char *key, const char *value); int location_geoclue_get_location(location_geoclue_state_t *state, - float *lat, float *lon); + float *lat, float *lon); #endif /* ! _REDSHIFT_LOCATION_GEOCLUE_H */ diff --git a/src/redshift.c b/src/redshift.c index c063835..ac191fc 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -554,6 +554,8 @@ parse_gamma_string(const char *str, float gamma[]) gamma[1] = atof(g_s); /* Blue */ gamma[2] = atof(s); /* Green */ } + + return 0; } static const gamma_method_t * |