summaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorVratislav Podzimek <vpodzime@redhat.com>2012-05-24 15:32:13 +0200
committerVratislav Podzimek <vpodzime@redhat.com>2012-05-24 16:48:09 +0200
commit6176b2386b8ebcc73c22a66425e349bef6d05d68 (patch)
tree2ef651d0bd82f5f0e3b64f6f33055c32662fc1ee /widgets
parent4d4d803d672488abcc08c840a3e295368de1de2b (diff)
downloadanaconda-6176b2386b8ebcc73c22a66425e349bef6d05d68.tar.gz
anaconda-6176b2386b8ebcc73c22a66425e349bef6d05d68.tar.xz
anaconda-6176b2386b8ebcc73c22a66425e349bef6d05d68.zip
Make TimezoneMap suitable for testing
When testing we, need to set the location of the bitmaps our TimezoneMap is using, so let it try to get the location from the environment.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/src/Makefile.am4
-rw-r--r--widgets/src/TimezoneMap.c22
-rw-r--r--widgets/src/tz.c20
-rw-r--r--widgets/src/tz.h5
4 files changed, 38 insertions, 13 deletions
diff --git a/widgets/src/Makefile.am b/widgets/src/Makefile.am
index cef38b56e..79afc8223 100644
--- a/widgets/src/Makefile.am
+++ b/widgets/src/Makefile.am
@@ -53,12 +53,14 @@ SOURCES = $(GISOURCES) $(NONGISOURCES)
HDRS = $(GIHDRS) $(NONGIHDRS)
-TZMAPDATA = '"$(datadir)/anaconda/tzmapdata"'
+WIDGETSDATA = '"$(datadir)/anaconda"'
+TZMAPDATA = '"tzmapdata"'
noinst_HEADERS = gettext.h intl.h
lib_LTLIBRARIES = libAnacondaWidgets.la
libAnacondaWidgets_la_CFLAGS = $(GTK_CFLAGS) $(GLADEUI_CFLAGS) -Wall -g\
+ -DWIDGETS_DATADIR=$(WIDGETSDATA)\
-DTZMAP_DATADIR=$(TZMAPDATA)
libAnacondaWidgets_la_LIBADD = $(GTK_LIBS) $(GLADEUI_LIBS)
libAnacondaWidgets_la_LDFLAGS = $(LTLIBINTL)
diff --git a/widgets/src/TimezoneMap.c b/widgets/src/TimezoneMap.c
index fb2ff5f70..10713909e 100644
--- a/widgets/src/TimezoneMap.c
+++ b/widgets/src/TimezoneMap.c
@@ -24,6 +24,7 @@
#include "TimezoneMap.h"
#include <math.h>
#include <string.h>
+#include <stdlib.h>
#include "tz.h"
/**
@@ -73,7 +74,6 @@ enum {
static guint signals[LAST_SIGNAL];
-
static AnacondaTimezoneMapOffset color_codes[] =
{
{-11.0, 43, 0, 0, 255 },
@@ -335,7 +335,8 @@ anaconda_timezone_map_draw (GtkWidget *widget,
cairo_paint (cr);
/* paint hilight */
- file = g_strdup_printf (TZMAP_DATADIR "/timezone_%s.png",
+ file = g_strdup_printf ("%s/" TZMAP_DATADIR "/timezone_%s.png",
+ get_widgets_datadir(),
g_ascii_formatd (buf, sizeof (buf),
"%g", priv->selected_offset));
orig_hilight = gdk_pixbuf_new_from_file (file, &err);
@@ -360,7 +361,10 @@ anaconda_timezone_map_draw (GtkWidget *widget,
}
/* load pin icon */
- pin = gdk_pixbuf_new_from_file (TZMAP_DATADIR "/pin.png", &err);
+
+ file = g_strdup_printf("%s/" TZMAP_DATADIR "/pin.png", get_widgets_datadir());
+ pin = gdk_pixbuf_new_from_file (file, &err);
+ g_free(file);
if (err) {
g_warning ("Could not load pin icon: %s", err->message);
@@ -521,11 +525,13 @@ static void
anaconda_timezone_map_init (AnacondaTimezoneMap *self) {
AnacondaTimezoneMapPrivate *priv;
GError *err = NULL;
+ gchar *file;
priv = self->priv = TIMEZONE_MAP_PRIVATE (self);
- priv->orig_background = gdk_pixbuf_new_from_file (TZMAP_DATADIR "/bg.png",
- &err);
+ file = g_strdup_printf("%s/" TZMAP_DATADIR "/bg.png", get_widgets_datadir());
+ priv->orig_background = gdk_pixbuf_new_from_file (file, &err);
+ g_free(file);
if (!priv->orig_background) {
g_warning ("Could not load background image: %s",
@@ -533,8 +539,10 @@ anaconda_timezone_map_init (AnacondaTimezoneMap *self) {
g_clear_error (&err);
}
- priv->orig_color_map = gdk_pixbuf_new_from_file (TZMAP_DATADIR "/cc.png",
- &err);
+ file = g_strdup_printf("%s/" TZMAP_DATADIR "/cc.png", get_widgets_datadir());
+ priv->orig_color_map = gdk_pixbuf_new_from_file (file, &err);
+ g_free(file);
+
if (!priv->orig_color_map) {
g_warning ("Could not load background image: %s",
(err) ? err->message : "Unknown error");
diff --git a/widgets/src/tz.c b/widgets/src/tz.c
index 5173808e0..54c0da51c 100644
--- a/widgets/src/tz.c
+++ b/widgets/src/tz.c
@@ -41,6 +41,20 @@ static void sort_locations_by_country (GPtrArray *locations);
static gchar * tz_data_file_get (void);
static void load_backward_tz (TzDB *tz_db);
+/* Returns path to anaconda widgets data directory using the value of the
+ * environment variable ANACONDA_WIDGETS_DATA or WIDGETS_DATADIR macro
+ * (defined in Makefile.am) if the environment variable is not defined.
+ */
+gchar *get_widgets_datadir() {
+ gchar *env_value;
+
+ env_value = getenv("ANACONDA_WIDGETS_DATA");
+ if (env_value == NULL)
+ return WIDGETS_DATADIR;
+ else
+ return env_value;
+}
+
/* ---------------- *
* Public interface *
* ---------------- */
@@ -381,13 +395,17 @@ load_backward_tz (TzDB *tz_db)
GError *error = NULL;
char **lines, *contents;
guint i;
+ gchar *file;
tz_db->backward = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- if (g_file_get_contents (BACKWARDDIR "timezones_backward", &contents, NULL, &error) == FALSE) {
+ file = g_strdup_printf ("%s/" TZMAP_DATADIR "/timezones_backward", get_widgets_datadir());
+ if (g_file_get_contents (file, &contents, NULL, &error) == FALSE) {
g_warning ("Failed to load 'backward' file: %s", error->message);
return;
}
+ g_free(file);
+
lines = g_strsplit (contents, "\n", -1);
g_free (contents);
for (i = 0; lines[i] != NULL; i++) {
diff --git a/widgets/src/tz.h b/widgets/src/tz.h
index 705636470..ec8a569e2 100644
--- a/widgets/src/tz.h
+++ b/widgets/src/tz.h
@@ -22,10 +22,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef BACKWARDDIR
-#define BACKWARDDIR "/usr/share/anaconda/tzmapdata/"
-#endif
-
#ifndef _E_TZ_H
#define _E_TZ_H
@@ -37,6 +33,7 @@ typedef struct _TzDB TzDB;
typedef struct _TzLocation TzLocation;
typedef struct _TzInfo TzInfo;
+gchar *get_widgets_datadir();
struct _TzDB
{