aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac25
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/Makefile.am11
-rw-r--r--src/location-gnome-clock.c139
-rw-r--r--src/location-gnome-clock.h36
-rw-r--r--src/redshift.c18
6 files changed, 228 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index b2ee3a7..89cb47a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,6 +20,9 @@ PKG_CHECK_MODULES([XCB], [xcb], [have_xcb=yes], [have_xcb=no])
PKG_CHECK_MODULES([XCB_RANDR], [xcb-randr],
[have_xcb_randr=yes], [have_xcb_randr=no])
+PKG_CHECK_MODULES([GLIB], [glib-2.0], [have_glib=yes], [have_glib=no])
+PKG_CHECK_MODULES([GCONF], [gconf-2.0], [have_gconf=yes], [have_gconf=no])
+
AC_CHECK_HEADER([windows.h], [have_windows_h=yes], [have_windows_h=no])
# Check for Python
@@ -96,6 +99,28 @@ AS_IF([test "x$enable_randr" = xno -a "x$enable_vidmode" = xno -a "x$enable_wing
AC_MSG_ERROR([either RANDR, VidMode or WinGDI must be enabled])
])
+# Check GNOME Clock location provider
+AC_MSG_CHECKING([whether to enable GNOME Clock location provider])
+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], [
+ AC_DEFINE([ENABLE_GNOME_CLOCK], 1,
+ [Define to 1 to enable GNOME Clock location provider])
+ AC_MSG_RESULT([yes])
+ ], [
+ AC_MSG_RESULT([missing dependencies])
+ AS_IF([test "x$enable_gnome_clock" = xyes], [
+ AC_MSG_ERROR([missing dependencies for GNOME Clock location provider])
+ ])
+ enable_gnome_clock=no
+ ])
+], [
+ AC_MSG_RESULT([no])
+])
+AM_CONDITIONAL([ENABLE_GNOME_CLOCK], [test "x$enable_gnome_clock" != xno])
+
# Check for GTK+ status icon
AC_MSG_CHECKING([whether to enable GTK status icon])
AC_ARG_ENABLE([gtk], [AC_HELP_STRING([--enable-gtk],
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 766450e..a46a9d4 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ src/gamma-randr.c
src/gamma-vidmode.c
src/gamma-w32gdi.c
+src/location-gnome-clock.c
src/location-manual.c
src/gtk-redshift/statusicon.py
diff --git a/src/Makefile.am b/src/Makefile.am
index e4f88de..c07aea3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -18,7 +18,8 @@ redshift_SOURCES = \
EXTRA_redshift_SOURCES = \
gamma-randr.c gamma-randr.h \
gamma-vidmode.c gamma-vidmode.h \
- gamma-w32gdi.c gamma-w32gdi.h
+ gamma-w32gdi.c gamma-w32gdi.h \
+ location-gnome-clock.c location-gnome-clock.h
AM_CFLAGS =
redshift_LDADD = @LIBINTL@
@@ -44,3 +45,11 @@ if ENABLE_WINGDI
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
diff --git a/src/location-gnome-clock.c b/src/location-gnome-clock.c
new file mode 100644
index 0000000..3136ff2
--- /dev/null
+++ b/src/location-gnome-clock.c
@@ -0,0 +1,139 @@
+/* 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 <http://www.gnu.org/licenses/>.
+
+ Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
+*/
+
+#include <stdio.h>
+#include <string.h>
+
+#include <gconf/gconf-client.h>
+
+#include "location-gnome-clock.h"
+
+#ifdef ENABLE_NLS
+# include <libintl.h>
+# define _(s) gettext(s)
+#else
+# define _(s) s
+#endif
+
+
+int
+location_gnome_clock_init(location_gnome_clock_state_t *state, char *args)
+{
+ g_type_init();
+
+ GError *error = NULL;
+ GConfClient *client = gconf_client_get_default();
+
+ GSList *applets = gconf_client_all_dirs(client, "/apps/panel/applets",
+ &error);
+ if (error) {
+ fputs(_("Cannot list dirs in `/apps/panel/applets'.\n"),
+ stderr);
+ g_object_unref(client);
+ return -1;
+ }
+
+ char *cities_key = NULL;
+ for (GSList *applet = applets; applet != NULL;
+ applet = g_slist_next(applet)) {
+ char *path = applet->data;
+ if (cities_key == NULL) {
+ char *key = g_strdup_printf("%s/bonobo_iid", path);
+ char *bonobo_iid = gconf_client_get_string(client, key,
+ &error);
+
+ if (!error && bonobo_iid != NULL) {
+ if (!strcmp(bonobo_iid,
+ "OAFIID:GNOME_ClockApplet")) {
+ cities_key = g_strdup_printf(
+ "%s/prefs/cities", path);
+ }
+ g_free(bonobo_iid);
+ }
+
+ g_free(key);
+ }
+ g_free(path);
+ }
+
+ g_slist_free(applets);
+
+ if (cities_key == NULL) {
+ fputs(_("No clock applet was found.\n"), stderr);
+ g_object_unref(client);
+ return -1;
+ }
+
+ GSList *cities = gconf_client_get_list(client, cities_key,
+ GCONF_VALUE_STRING, &error);
+ if (error) {
+ fprintf(stderr, _("Error reading city list: `%s'.\n"),
+ cities_key);
+ g_free(cities_key);
+ g_object_unref(client);
+ return -1;
+ }
+
+ g_free(cities_key);
+
+ char *current_city = NULL;
+ 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);
+
+ if (current_city == NULL) {
+ fputs(_("No city selected as current city.\n"), stderr);
+ return -1;
+ }
+
+ char *lat_str = strstr(current_city, "latitude=\"");
+ char *lon_str = strstr(current_city, "longitude=\"");
+ if (lat_str == NULL || lon_str == NULL) {
+ fputs(_("Location not specified for city.\n"), stderr);
+ return -1;
+ }
+
+ 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;
+}
+
+void
+location_gnome_clock_free(location_gnome_clock_state_t *state)
+{
+}
+
+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
new file mode 100644
index 0000000..6687c30
--- /dev/null
+++ b/src/location-gnome-clock.h
@@ -0,0 +1,36 @@
+/* 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 <http://www.gnu.org/licenses/>.
+
+ Copyright (c) 2010 Jon Lund Steffensen <jonlst@gmail.com>
+*/
+
+#ifndef _REDSHIFT_LOCATION_GNOME_CLOCK_H
+#define _REDSHIFT_LOCATION_GNOME_CLOCK_H
+
+
+typedef struct {
+ float lat;
+ float lon;
+} location_gnome_clock_state_t;
+
+
+int location_gnome_clock_init(location_gnome_clock_state_t *state, char *args);
+void location_gnome_clock_free(location_gnome_clock_state_t *state);
+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 f297c3a..b0c3e04 100644
--- a/src/redshift.c
+++ b/src/redshift.c
@@ -70,6 +70,10 @@
#include "location-manual.h"
+#ifdef ENABLE_GNOME_CLOCK
+# include "location-gnome-clock.h"
+#endif
+
/* Union of state data for gamma adjustment methods */
typedef union {
@@ -121,11 +125,23 @@ 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
} location_state_t;
/* Location provider method structs */
static const location_provider_t location_providers[] = {
+#ifdef ENABLE_GNOME_CLOCK
+ {
+ "GNOME-Clock",
+ (location_provider_init_func *)location_gnome_clock_init,
+ (location_provider_free_func *)location_gnome_clock_free,
+ (location_provider_get_location_func *)
+ location_gnome_clock_get_location
+ },
+#endif
{
"Manual",
(location_provider_init_func *)location_manual_init,
@@ -361,7 +377,7 @@ main(int argc, char *argv[])
/* Try to parse provider name as float */
errno = 0;
char *end;
- float lat = strtof(optarg, &end);
+ float v = strtof(optarg, &end);
if (errno == 0 && *end == ':') {
provider_name = "Manual";
provider_args = optarg;