From 79bfe9eed44486fbf59e6d482abdbc649c41cee5 Mon Sep 17 00:00:00 2001 From: Jon Lund Steffensen Date: Mon, 9 Dec 2013 14:07:01 -0500 Subject: Remove Gnome Clock location provider This was basically a hack that happened to work because the Gnome Clock applet could store the current location of the user, and Redshift was able to fetch this location through GConf. Since Redshift for some time now has supported a config file where the location can be set, there is not really any reason to use an external, fragile solution to do the same. --- src/Makefile.am | 8 -- src/location-gnome-clock.c | 210 --------------------------------------------- src/location-gnome-clock.h | 44 ---------- src/redshift.c | 21 ----- 4 files changed, 283 deletions(-) delete mode 100644 src/location-gnome-clock.c delete mode 100644 src/location-gnome-clock.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ae1755a..15caf2c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,7 +21,6 @@ EXTRA_redshift_SOURCES = \ gamma-randr.c gamma-randr.h \ gamma-vidmode.c gamma-vidmode.h \ gamma-w32gdi.c gamma-w32gdi.h \ - location-gnome-clock.c location-gnome-clock.h \ location-geoclue.c location-geoclue.h AM_CFLAGS = @@ -49,13 +48,6 @@ redshift_SOURCES += gamma-w32gdi.c gamma-w32gdi.h redshift_LDADD += -lgdi32 endif -if ENABLE_GNOME_CLOCK -redshift_SOURCES += location-gnome-clock.c location-gnome-clock.h -AM_CFLAGS += $(GLIB_CFLAGS) $(GCONF_CFLAGS) -redshift_LDADD += \ - $(GLIB_LIBS) $(GLIB_CFLAGS) \ - $(GCONF_LIBS) $(GCONF_CFLAGS) -endif if ENABLE_GEOCLUE redshift_SOURCES += location-geoclue.c location-geoclue.h diff --git a/src/location-gnome-clock.c b/src/location-gnome-clock.c deleted file mode 100644 index f68af2f..0000000 --- a/src/location-gnome-clock.c +++ /dev/null @@ -1,210 +0,0 @@ -/* location-gnome-clock.c -- GNOME Panel Clock location provider source - This file is part of Redshift. - - Redshift is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Redshift is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Redshift. If not, see . - - Copyright (c) 2010 Jon Lund Steffensen -*/ - -#include -#include - -#include - -#include "location-gnome-clock.h" - -#ifdef ENABLE_NLS -# include -# define _(s) gettext(s) -#else -# define _(s) s -#endif - - -/* Find current selected city for the clock applet with the specified id. - Returns NULL if not found. */ -static char * -find_current_city(GConfClient *client, const char *id) -{ - char *current_city = NULL; - char *cities_key = g_strdup_printf("/apps/panel/applets/%s" - "/prefs/cities", id); - GSList *cities = gconf_client_get_list(client, - cities_key, - GCONF_VALUE_STRING, NULL); - - if (cities == NULL) { - fprintf(stderr, _("Error reading city list: `%s'.\n"), - cities_key); - g_free(cities_key); - return NULL; - } - - g_free(cities_key); - - for (GSList *city = cities; city != NULL; - city = g_slist_next(city)) { - char *city_spec = city->data; - char *c = strstr(city_spec, "current=\"true\""); - if (c) current_city = g_strdup(city_spec); - g_free(city->data); - } - g_slist_free(cities); - - return current_city; -} - -int -location_gnome_clock_init(location_gnome_clock_state_t *state) -{ - g_type_init(); - - GConfClient *client = gconf_client_get_default(); - - /* Get a list of active applets in the panel. */ - GSList *applets = gconf_client_get_list(client, - "/apps/panel/general/applet_id_list", - GCONF_VALUE_STRING, NULL); - if (applets == NULL) { - /* JDS has an alternate list of applets. */ - applets = gconf_client_get_list(client, - "/apps/panel/general/applet_id_list_jds", - GCONF_VALUE_STRING, NULL); - } - - if (applets == NULL) { - fputs(_("Cannot list GNOME panel applets.\n"), stderr); - g_slist_free(applets); - g_object_unref(client); - return -1; - } - - /* Go through each applet and check if it is a clock applet. - When a clock applet is found, check whether there is a - city selected as the current city. */ - char *current_city = NULL; - - /* Keep track of the number of clock applets found to be able to give - better error output if something fails. */ - int clock_applet_count = 0; - - for (GSList *applet = applets; applet != NULL; - applet = g_slist_next(applet)) { - char *id = applet->data; - if (current_city == NULL) { - char *key = g_strdup_printf("/apps/panel/applets/%s" - "/bonobo_iid", id); - char *bonobo_iid = gconf_client_get_string(client, key, - NULL); - - /* Try both gnome-panel 2.30.x and earlier bonobo_iid - key and newer applet_iid. */ - if (bonobo_iid != NULL && - !strcmp(bonobo_iid, "OAFIID:GNOME_ClockApplet")) { - clock_applet_count += 1; - current_city = find_current_city(client, id); - } else { - g_free(key); - key = g_strdup_printf("/apps/panel/applets/%s" - "/applet_iid", id); - char *applet_iid = gconf_client_get_string(client, key, - NULL); - - if (applet_iid != NULL && - !strcmp(applet_iid, "ClockAppletFactory::ClockApplet")) { - clock_applet_count += 1; - current_city = find_current_city(client, id); - } - - g_free(applet_iid); - } - - g_free(bonobo_iid); - g_free(key); - } - g_free(id); - } - - g_slist_free(applets); - g_object_unref(client); - - /* Check whether an applet and a current city was found. */ - - if (clock_applet_count == 0) { - fputs(_("No clock applet was found.\n"), stderr); - return -1; - } - - if (current_city == NULL) { - fputs(_("No city selected as current city.\n"), stderr); - return -1; - } - - /* Find coords for selected city and parse as number. */ - - char *lat_str = strstr(current_city, "latitude=\""); - char *lon_str = strstr(current_city, "longitude=\""); - if (lat_str == NULL || lon_str == NULL) { - fprintf(stderr, - _("Location not specified for city `%s'.\n"), - current_city); - g_free(current_city); - return -1; - } - - g_free(current_city); - - char *lat_num_str = lat_str + strlen("latitude=\""); - char *lon_num_str = lon_str + strlen("longitude=\""); - - state->lat = g_ascii_strtod(lat_num_str, NULL); - state->lon = g_ascii_strtod(lon_num_str, NULL); - - return 0; -} - -int -location_gnome_clock_start(location_gnome_clock_state_t *state) -{ - return 0; -} - -void -location_gnome_clock_free(location_gnome_clock_state_t *state) -{ -} - -void -location_gnome_clock_print_help(FILE *f) -{ - fputs(_("Use the location as set in the GNOME Clock applet.\n"), f); - fputs("\n", f); -} - -int -location_gnome_clock_set_option(location_gnome_clock_state_t *state, - const char *key, const char *value) -{ - return -1; -} - -int -location_gnome_clock_get_location(location_gnome_clock_state_t *state, - float *lat, float *lon) -{ - *lat = state->lat; - *lon = state->lon; - - return 0; -} diff --git a/src/location-gnome-clock.h b/src/location-gnome-clock.h deleted file mode 100644 index 052ce91..0000000 --- a/src/location-gnome-clock.h +++ /dev/null @@ -1,44 +0,0 @@ -/* location-gnome-clock.h -- GNOME Panel Clock location provider header - This file is part of Redshift. - - Redshift is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Redshift is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Redshift. If not, see . - - Copyright (c) 2010 Jon Lund Steffensen -*/ - -#ifndef _REDSHIFT_LOCATION_GNOME_CLOCK_H -#define _REDSHIFT_LOCATION_GNOME_CLOCK_H - -#include - - -typedef struct { - float lat; - float lon; -} location_gnome_clock_state_t; - - -int location_gnome_clock_init(location_gnome_clock_state_t *state); -int location_gnome_clock_start(location_gnome_clock_state_t *state); -void location_gnome_clock_free(location_gnome_clock_state_t *state); - -void location_gnome_clock_print_help(FILE *f); -int location_gnome_clock_set_option(location_gnome_clock_state_t *state, - const char *key, const char *value); - -int location_gnome_clock_get_location(location_gnome_clock_state_t *state, - float *lat, float *lon); - - -#endif /* ! _REDSHIFT_LOCATION_GNOME_CLOCK_H */ diff --git a/src/redshift.c b/src/redshift.c index a1273d4..7352ab2 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -68,10 +68,6 @@ #include "location-manual.h" -#ifdef ENABLE_GNOME_CLOCK -# include "location-gnome-clock.h" -#endif - #ifdef ENABLE_GEOCLUE # include "location-geoclue.h" #endif @@ -146,9 +142,6 @@ static const gamma_method_t gamma_methods[] = { /* Union of state data for location providers */ typedef union { location_manual_state_t manual; -#ifdef ENABLE_GNOME_CLOCK - location_gnome_clock_state_t gnome_clock; -#endif #ifdef ENABLE_GEOCLUE location_geoclue_state_t geoclue; #endif @@ -170,20 +163,6 @@ static const location_provider_t location_providers[] = { (location_provider_get_location_func *) location_geoclue_get_location }, -#endif -#ifdef ENABLE_GNOME_CLOCK - { - "gnome-clock", - (location_provider_init_func *)location_gnome_clock_init, - (location_provider_start_func *)location_gnome_clock_start, - (location_provider_free_func *)location_gnome_clock_free, - (location_provider_print_help_func *) - location_gnome_clock_print_help, - (location_provider_set_option_func *) - location_gnome_clock_set_option, - (location_provider_get_location_func *) - location_gnome_clock_get_location - }, #endif { "manual", -- cgit v1.2.3-70-g09d2