Re: [newui] [PATCH] Make TimezoneMap better suitable for testing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Looks good and I have seen it working.

----- Original Message -----
> 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.
> ---
>  widgets/src/Makefile.am   |    4 +++-
>  widgets/src/TimezoneMap.c |   22 +++++++++++++++-------
>  widgets/src/tz.c          |   17 ++++++++++++++++-
>  widgets/src/tz.h          |    5 +----
>  4 files changed, 35 insertions(+), 13 deletions(-)
> 
> diff --git a/widgets/src/Makefile.am b/widgets/src/Makefile.am
> index cef38b5..79afc82 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 fb2ff5f..1071390 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 5173808..ca42f8c 100644
> --- a/widgets/src/tz.c
> +++ b/widgets/src/tz.c
> @@ -41,6 +41,17 @@ static void sort_locations_by_country (GPtrArray
> *locations);
>  static gchar * tz_data_file_get (void);
>  static void load_backward_tz (TzDB *tz_db);
>  
> +gchar *get_widgets_datadir() {
> +    gchar *env_value;
> +
> +    env_value = getenv("ANACONDA_WIDGETS_DATA");
> +    if (env_value == NULL)
> +        //defined in the widgets/src/Makefile.am
> +        return WIDGETS_DATADIR;
> +    else
> +        return env_value;
> +}
> +
>  /* ---------------- *
>   * Public interface *
>   * ---------------- */
> @@ -381,13 +392,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 7056364..ec8a569 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
>  {
> --
> 1.7.4.4
> 
> _______________________________________________
> Anaconda-devel-list mailing list
> Anaconda-devel-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list
> 

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux