- Updated the time zone map images

- Updated the city data from geonames.org
- Fix a memory leak and potential crash with the locations list
- Cycle through a smaller list of map locations on repeated clicks
This commit is contained in:
David Shea 2015-05-01 13:24:40 -04:00
parent ff29a1dbae
commit 28bd411837
8 changed files with 48473 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/libtimezonemap_0.4.1.tar.gz
/libtimezonemap_0.4.2.tar.gz
/timezone_pngs.tar.gz

View File

@ -0,0 +1,71 @@
From 604173ca272ffcdffb2c1846232bb6613a10e28f Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Tue, 24 Mar 2015 10:04:53 -0400
Subject: [PATCH 1/2] Fix a memory leak and potential crash with the locations
list
Store the head of the locations list separately so that the references
to list elements are not lost as the list is iterated over. If the end
of the list of reached, restart at the beginning.
---
src/cc-timezone-map.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/src/cc-timezone-map.c b/src/cc-timezone-map.c
index 993f379..3de453e 100644
--- a/src/cc-timezone-map.c
+++ b/src/cc-timezone-map.c
@@ -68,6 +68,8 @@ struct _CcTimezoneMapPrivate
CcTimezoneLocation *location;
GHashTable *alias_db;
GList *distances;
+ /* Store the head of the list separately so it can be freed later */
+ GList *distances_head;
gint previous_x;
gint previous_y;
@@ -594,9 +596,10 @@ cc_timezone_map_dispose (GObject *object)
g_hash_table_destroy (priv->alias_db);
priv->alias_db = NULL;
}
- if (priv->distances)
+ if (priv->distances_head)
{
- g_list_free (priv->distances);
+ g_list_free (priv->distances_head);
+ priv->distances_head = NULL;
priv->distances = NULL;
}
@@ -991,10 +994,13 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
if (x == priv->previous_x && y == priv->previous_y)
{
priv->distances = g_list_next (priv->distances);
+ if (!priv->distances)
+ priv->distances = priv->distances_head;
+
location = (CcTimezoneLocation*) priv->distances->data;
} else {
- g_list_free (priv->distances);
- priv->distances = NULL;
+ g_list_free (priv->distances_head);
+ priv->distances_head = NULL;
for (i = 0; i < array->len; i++)
{
gdouble pointx, pointy, dx, dy;
@@ -1007,9 +1013,10 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
dy = pointy - y;
cc_timezone_location_set_dist(loc, (gdouble) dx * dx + dy * dy);
- priv->distances = g_list_prepend (priv->distances, loc);
+ priv->distances_head = g_list_prepend (priv->distances_head, loc);
}
- priv->distances = g_list_sort (priv->distances, (GCompareFunc) sort_locations);
+ priv->distances_head = g_list_sort (priv->distances_head, (GCompareFunc) sort_locations);
+ priv->distances = priv->distances_head;
location = (CcTimezoneLocation*) priv->distances->data;
priv->previous_x = x;
priv->previous_y = y;
--
2.1.0

View File

@ -0,0 +1,209 @@
From c416784822821d7f69f77be6aa8814ab6f3c959f Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Mon, 2 Dec 2013 16:55:01 -0500
Subject: [PATCH 1/6] Remove the color codes map.
cc.png is used to map locations on a map (usually mouse clicks) to time zone
offsets. However, in every case except one, the offset set by get_loc_for_xy()
is immediately overwritten by set_location(). For the exception case
(cc_timezone_map_get_timezone_at_coords), having the selected_offset property
change during the call is an unexpected side effect.
Furthermore, the data in the color_codes array was not entirely in sync with
the data in cc.png (e.g., no color_codes entry for UTC+14), and the borders
between zones in cc.png are feathered instead of being zones of a single pixel
value, so clicks around the borders would result in no zone being selected. If
cc.png is ever revived, it needs to be regenerated from the SVG source.
---
src/Makefile.am | 1 -
src/cc-timezone-map.c | 102 --------------------------------------------------
src/data/cc.png | Bin 53948 -> 0 bytes
3 files changed, 103 deletions(-)
delete mode 100644 src/data/cc.png
diff --git a/src/Makefile.am b/src/Makefile.am
index 2eec6d7..fdf465c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,7 +3,6 @@ CLEANFILES =
uidir = $(pkgdatadir)/ui
dist_ui_DATA = \
data/bg.png \
- data/cc.png \
data/olsen_map.png \
data/pin.png \
data/timezone_0.png \
diff --git a/src/cc-timezone-map.c b/src/cc-timezone-map.c
index 993f379..97d1221 100644
--- a/src/cc-timezone-map.c
+++ b/src/cc-timezone-map.c
@@ -46,15 +46,10 @@ typedef struct
struct _CcTimezoneMapPrivate
{
GdkPixbuf *orig_background;
- GdkPixbuf *orig_color_map;
GdkPixbuf *background;
- GdkPixbuf *color_map;
GdkPixbuf *olsen_map;
- guchar *visible_map_pixels;
- gint visible_map_rowstride;
-
gint olsen_map_channels;
guchar *olsen_map_pixels;
gint olsen_map_rowstride;
@@ -86,50 +81,6 @@ enum {
static guint signals[LAST_SIGNAL];
-
-static CcTimezoneMapOffset color_codes[] =
-{
- {-11.0, 43, 0, 0, 255 },
- {-10.0, 85, 0, 0, 255 },
- {-9.5, 102, 255, 0, 255 },
- {-9.0, 128, 0, 0, 255 },
- {-8.0, 170, 0, 0, 255 },
- {-7.0, 212, 0, 0, 255 },
- {-6.0, 255, 0, 1, 255 }, // north
- {-6.0, 255, 0, 0, 255 }, // south
- {-5.0, 255, 42, 42, 255 },
- {-4.5, 192, 255, 0, 255 },
- {-4.0, 255, 85, 85, 255 },
- {-3.5, 0, 255, 0, 255 },
- {-3.0, 255, 128, 128, 255 },
- {-2.0, 255, 170, 170, 255 },
- {-1.0, 255, 213, 213, 255 },
- {0.0, 43, 17, 0, 255 },
- {1.0, 85, 34, 0, 255 },
- {2.0, 128, 51, 0, 255 },
- {3.0, 170, 68, 0, 255 },
- {3.5, 0, 255, 102, 255 },
- {4.0, 212, 85, 0, 255 },
- {4.5, 0, 204, 255, 255 },
- {5.0, 255, 102, 0, 255 },
- {5.5, 0, 102, 255, 255 },
- {5.75, 0, 238, 207, 247 },
- {6.0, 255, 127, 42, 255 },
- {6.5, 204, 0, 254, 254 },
- {7.0, 255, 153, 85, 255 },
- {8.0, 255, 179, 128, 255 },
- {9.0, 255, 204, 170, 255 },
- {9.5, 170, 0, 68, 250 },
- {10.0, 255, 230, 213, 255 },
- {10.5, 212, 124, 21, 250 },
- {11.0, 212, 170, 0, 255 },
- {11.5, 249, 25, 87, 253 },
- {12.0, 255, 204, 0, 255 },
- {12.75, 254, 74, 100, 248 },
- {13.0, 255, 85, 153, 250 },
- {-100, 0, 0, 0, 0 }
-};
-
static const gchar * olsen_map_timezones[] = {
"Africa/Abidjan",
"Africa/Accra",
@@ -558,12 +509,6 @@ cc_timezone_map_dispose (GObject *object)
priv->orig_background = NULL;
}
- if (priv->orig_color_map)
- {
- g_object_unref (priv->orig_color_map);
- priv->orig_color_map = NULL;
- }
-
if (priv->olsen_map)
{
g_object_unref (priv->olsen_map);
@@ -580,15 +525,6 @@ cc_timezone_map_dispose (GObject *object)
priv->background = NULL;
}
- if (priv->color_map)
- {
- g_object_unref (priv->color_map);
- priv->color_map = NULL;
-
- priv->visible_map_pixels = NULL;
- priv->visible_map_rowstride = 0;
- }
-
if (priv->alias_db)
{
g_hash_table_destroy (priv->alias_db);
@@ -671,17 +607,6 @@ cc_timezone_map_size_allocate (GtkWidget *widget,
allocation->height,
GDK_INTERP_BILINEAR);
- if (priv->color_map)
- g_object_unref (priv->color_map);
-
- priv->color_map = gdk_pixbuf_scale_simple (priv->orig_color_map,
- allocation->width,
- allocation->height,
- GDK_INTERP_BILINEAR);
-
- priv->visible_map_pixels = gdk_pixbuf_get_pixels (priv->color_map);
- priv->visible_map_rowstride = gdk_pixbuf_get_rowstride (priv->color_map);
-
GTK_WIDGET_CLASS (cc_timezone_map_parent_class)->size_allocate (widget,
allocation);
}
@@ -946,7 +871,6 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
{
CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv;
guchar r, g, b, a;
- guchar *pixels;
gint rowstride;
gint i;
@@ -955,28 +879,11 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
GtkAllocation alloc;
CcTimezoneLocation* location;
- rowstride = priv->visible_map_rowstride;
- pixels = priv->visible_map_pixels;
-
- r = pixels[(rowstride * y + x * 4)];
- g = pixels[(rowstride * y + x * 4) + 1];
- b = pixels[(rowstride * y + x * 4) + 2];
- a = pixels[(rowstride * y + x * 4) + 3];
-
-
if ((x - priv->previous_x < 5 && x - priv->previous_x > -5) &&
(y - priv->previous_y < 5 && y - priv->previous_y > -5)) {
x = priv->previous_x;
y = priv->previous_y;
}
- for (i = 0; color_codes[i].offset != -100; i++)
- {
- if (color_codes[i].red == r && color_codes[i].green == g
- && color_codes[i].blue == b && color_codes[i].alpha == a)
- {
- priv->selected_offset = color_codes[i].offset;
- }
- }
gtk_widget_queue_draw (widget);
@@ -1106,15 +1013,6 @@ cc_timezone_map_init (CcTimezoneMap *self)
g_clear_error (&err);
}
- priv->orig_color_map = gdk_pixbuf_new_from_file (DATADIR "/cc.png",
- &err);
- if (!priv->orig_color_map)
- {
- g_warning ("Could not load background image: %s",
- (err) ? err->message : "Unknown error");
- g_clear_error (&err);
- }
-
priv->olsen_map = gdk_pixbuf_new_from_file (DATADIR "/olsen_map.png",
&err);
if (!priv->olsen_map)
--
2.1.0

View File

@ -0,0 +1,56 @@
From ed19e892a5f1e22d3141f81c1da04f9f91719643 Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Tue, 24 Mar 2015 10:36:51 -0400
Subject: [PATCH 2/2] Cycle through a smaller list of map locations on repeated
clicks.
Cycling through the entire map causes erratic jumps between locations,
especially if starting in a sparsely populated area. Limit the candidate
locations to those within 50px of the mouse click, or the nearest
location if no location is within 50px.
---
src/cc-timezone-map.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/cc-timezone-map.c b/src/cc-timezone-map.c
index 3de453e..ed80a01 100644
--- a/src/cc-timezone-map.c
+++ b/src/cc-timezone-map.c
@@ -999,6 +999,8 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
location = (CcTimezoneLocation*) priv->distances->data;
} else {
+ GList *node;
+
g_list_free (priv->distances_head);
priv->distances_head = NULL;
for (i = 0; i < array->len; i++)
@@ -1016,6 +1018,25 @@ get_loc_for_xy (GtkWidget * widget, gint x, gint y)
priv->distances_head = g_list_prepend (priv->distances_head, loc);
}
priv->distances_head = g_list_sort (priv->distances_head, (GCompareFunc) sort_locations);
+
+ /* Remove locations from the list with a distance of greater than 50px,
+ * so that repeated clicks cycle through a smaller area instead of
+ * jumping all over the map. Start with the second element to ensure
+ * that at least one element stays in the list.
+ */
+ node = priv->distances_head->next;
+ while (node != NULL)
+ {
+ if (cc_timezone_location_get_dist(node->data) > (50 * 50))
+ {
+ /* Cut the list off here */
+ node->prev->next = NULL;
+ g_list_free(node);
+ }
+
+ node = g_list_next(node);
+ }
+
priv->distances = priv->distances_head;
location = (CcTimezoneLocation*) priv->distances->data;
priv->previous_x = x;
--
2.1.0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
From dae825d29bfaaad2226aa4ad4b122ef2f28fcf59 Mon Sep 17 00:00:00 2001
From: David Shea <dshea@redhat.com>
Date: Tue, 3 Dec 2013 15:21:35 -0500
Subject: [PATCH 6/6] Removed timezone_-5.5.
There is no UTC-5:30 zone, and the file itself is a misnamed copy of
timezone_-9.5.png.
---
src/Makefile.am | 1 -
src/data/timezone_-5.5.png | Bin 437 -> 0 bytes
2 files changed, 1 deletion(-)
delete mode 100644 src/data/timezone_-5.5.png
diff --git a/src/Makefile.am b/src/Makefile.am
index fdf465c..df23a83 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -29,7 +29,6 @@ dist_ui_DATA = \
data/timezone_4.5.png \
data/timezone_-5.png \
data/timezone_5.png \
- data/timezone_-5.5.png \
data/timezone_5.5.png \
data/timezone_5.75.png \
data/timezone_-6.png \
--
2.1.0

View File

@ -1,14 +1,27 @@
Name: libtimezonemap
Version: 0.4.2
Release: 5%{?dist}
Release: 6%{?dist}
Summary: Time zone map widget for Gtk+
Group: System Environment/Libraries
License: GPLv3
URL: https://launchpad.net/timezonemap
Source0: http://archive.ubuntu.com/ubuntu/pool/main/libt/libtimezonemap/%{name}_%{version}.tar.gz
# The binary portion of lp:~dshea/timezonemap/pixmaps-update
Source1: timezone_pngs.tar.gz
# From lp:~dshea/timezonemap/glade-catalog
Patch1: 0001-Added-a-glade-catalog-file.patch
# From lp:~dshea/timezonemap/pixmaps-update
Patch2: 0001-Remove-the-color-codes-map.patch
Patch3: 0005-Import-the-latest-data-from-geonames.org.patch
Patch4: 0006-Removed-timezone_-5.5.patch
# From lp:~dshea/timezonemap/location-cycle
Patch5: 0001-Fix-a-memory-leak-and-potential-crash-with-the-locat.patch
Patch6: 0002-Cycle-through-a-smaller-list-of-map-locations-on-rep.patch
BuildRequires: glib2-devel >= 2.26
BuildRequires: gtk3-devel >= 3.1.4
BuildRequires: json-glib-devel
@ -34,7 +47,11 @@ files used for building applications that use %{name}.
%prep
%setup -q
%setup -a 1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%build
./autogen.sh
@ -64,6 +81,12 @@ rm -f %{buildroot}%{_libdir}/*.la
%{_datadir}/glade/catalogs/TimezoneMap.xml
%changelog
* Fri May 1 2015 David Shea <dshea@redhat.com> - 0.4.2-6
- Updated the time zone map images
- Updated the city data from geonames.org
- Fix a memory leak and potential crash with the locations list
- Cycle through a smaller list of map locations on repeated clicks
* Wed Jan 28 2015 David Shea <dshea@redhat.com> - 0.4.2-5
- Use %license for the license file

View File

@ -1 +1 @@
daaf4d2761e90bbc22d424dfff1f83c1 libtimezonemap_0.4.2.tar.gz
1dda8a50b19a7d7996194ef80ccac724 timezone_pngs.tar.gz