diff options
58 files changed, 37 insertions, 2788 deletions
diff --git a/Makefile.am b/Makefile.am index feea4de..0229890 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,6 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS} SUBDIRS = \ - libmap \ src \ data \ tests \ diff --git a/configure.ac b/configure.ac index 32be68e..b563ce8 100644 --- a/configure.ac +++ b/configure.ac @@ -105,13 +105,10 @@ PKG_CHECK_MODULES(SERVICE, indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION PKG_CHECK_MODULES(PREF, gio-2.0 >= $GIO_REQUIRED_VERSION gtk+-3.0 >= $GTK3_REQUIRED_VERSION - json-glib-1.0 + timezonemap libgnome-control-center polkit-gobject-1) -PKG_CHECK_MODULES(LIBMAP, gio-2.0 >= $GIO_REQUIRED_VERSION - gtk+-3.0 >= $GTK3_REQUIRED_VERSION) - ########################### # Grab the GSettings Macros ########################### @@ -206,7 +203,6 @@ AM_GLIB_GNU_GETTEXT AC_CONFIG_FILES([ Makefile -libmap/Makefile src/Makefile data/Makefile tests/Makefile diff --git a/libmap/Makefile.am b/libmap/Makefile.am deleted file mode 100644 index a10b835..0000000 --- a/libmap/Makefile.am +++ /dev/null @@ -1,77 +0,0 @@ -uidir = $(pkgdatadir)/libmap/ui -dist_ui_DATA = \ - data/bg.png \ - data/cc.png \ - data/olsen_map.png \ - data/pin.png \ - data/timezone_0.png \ - data/timezone_-10.png \ - data/timezone_10.png \ - data/timezone_10.5.png \ - data/timezone_-1.png \ - data/timezone_1.png \ - data/timezone_-11.png \ - data/timezone_11.png \ - data/timezone_11.5.png \ - data/timezone_12.png \ - data/timezone_12.75.png \ - data/timezone_13.png \ - data/timezone_-2.png \ - data/timezone_2.png \ - data/timezone_-3.png \ - data/timezone_3.png \ - data/timezone_-3.5.png \ - data/timezone_3.5.png \ - data/timezone_-4.png \ - data/timezone_4.png \ - data/timezone_-4.5.png \ - 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 \ - data/timezone_6.png \ - data/timezone_6.5.png \ - data/timezone_-7.png \ - data/timezone_7.png \ - data/timezone_-8.png \ - data/timezone_8.png \ - data/timezone_-9.png \ - data/timezone_9.png \ - data/timezone_-9.5.png \ - data/timezone_9.5.png - -tzdatadir = $(pkgdatadir)/libmap/datetime -dist_tzdata_DATA = backward - -AM_CPPFLAGS = \ - $(LIBMAP_CFLAGS) \ - -DGNOMELOCALEDIR="\"$(datadir)/locale\"" \ - -DGNOMECC_DATA_DIR="\"$(pkgdatadir)/libmap\"" \ - -DDATADIR="\"$(uidir)\"" \ - $(NULL) - -noinst_PROGRAMS = test-timezone - -test_timezone_SOURCES = test-timezone.c tz.c tz.h -test_timezone_LDADD = $(LIBMAP_LIBS) -test_timezone_CFLAGS = $(LIBMAP_CFLAGS) - -all-local: check-local - -# FIXME remove "|| :" when we have all the necessary pixmaps -check-local: test-timezone - $(builddir)/test-timezone $(srcdir)/data || : - -noinst_LTLIBRARIES = libmap.la - -libmap_la_SOURCES = \ - cc-timezone-map.c \ - cc-timezone-map.h \ - tz.c tz.h - -libmap_la_LIBADD = $(LIBMAP_LIBS) -libmap_la_LDFLAGS = $(LIBMAP_LDFLAGS) - diff --git a/libmap/README b/libmap/README deleted file mode 100644 index 6766b42..0000000 --- a/libmap/README +++ /dev/null @@ -1,5 +0,0 @@ -This static library is a copied version of the code in GNOME 3.0's control center panel 'datetime', which itself is a version of Ubiquity's map ported to C. - -Ideally in the future, we can have all three packages using the same code. But for now, for time reasons (hah), it's just a copy. - -To update this copy, put newer versions of the code and data files in place; then fix up any GTK3-isms and add cc_timezone_map_set_coords and friends. And the watermark. diff --git a/libmap/backward b/libmap/backward deleted file mode 100644 index f1f95a8..0000000 --- a/libmap/backward +++ /dev/null @@ -1,118 +0,0 @@ -# <pre> -# @(#)backward 8.9 -# This file is in the public domain, so clarified as of -# 2009-05-17 by Arthur David Olson. - -# This file provides links between current names for time zones -# and their old names. Many names changed in late 1993. - -Link Africa/Asmara Africa/Asmera -Link Africa/Bamako Africa/Timbuktu -Link America/Argentina/Catamarca America/Argentina/ComodRivadavia -Link America/Adak America/Atka -Link America/Argentina/Buenos_Aires America/Buenos_Aires -Link America/Argentina/Catamarca America/Catamarca -Link America/Atikokan America/Coral_Harbour -Link America/Argentina/Cordoba America/Cordoba -Link America/Tijuana America/Ensenada -Link America/Indiana/Indianapolis America/Fort_Wayne -Link America/Indiana/Indianapolis America/Indianapolis -Link America/Argentina/Jujuy America/Jujuy -Link America/Indiana/Knox America/Knox_IN -Link America/Kentucky/Louisville America/Louisville -Link America/Argentina/Mendoza America/Mendoza -Link America/Rio_Branco America/Porto_Acre -Link America/Argentina/Cordoba America/Rosario -Link America/St_Thomas America/Virgin -Link Asia/Ashgabat Asia/Ashkhabad -Link Asia/Chongqing Asia/Chungking -Link Asia/Dhaka Asia/Dacca -Link Asia/Kathmandu Asia/Katmandu -Link Asia/Kolkata Asia/Calcutta -Link Asia/Macau Asia/Macao -Link Asia/Jerusalem Asia/Tel_Aviv -Link Asia/Ho_Chi_Minh Asia/Saigon -Link Asia/Thimphu Asia/Thimbu -Link Asia/Makassar Asia/Ujung_Pandang -Link Asia/Ulaanbaatar Asia/Ulan_Bator -Link Atlantic/Faroe Atlantic/Faeroe -Link Europe/Oslo Atlantic/Jan_Mayen -Link Australia/Sydney Australia/ACT -Link Australia/Sydney Australia/Canberra -Link Australia/Lord_Howe Australia/LHI -Link Australia/Sydney Australia/NSW -Link Australia/Darwin Australia/North -Link Australia/Brisbane Australia/Queensland -Link Australia/Adelaide Australia/South -Link Australia/Hobart Australia/Tasmania -Link Australia/Melbourne Australia/Victoria -Link Australia/Perth Australia/West -Link Australia/Broken_Hill Australia/Yancowinna -Link America/Rio_Branco Brazil/Acre -Link America/Noronha Brazil/DeNoronha -Link America/Sao_Paulo Brazil/East -Link America/Manaus Brazil/West -Link America/Halifax Canada/Atlantic -Link America/Winnipeg Canada/Central -Link America/Regina Canada/East-Saskatchewan -Link America/Toronto Canada/Eastern -Link America/Edmonton Canada/Mountain -Link America/St_Johns Canada/Newfoundland -Link America/Vancouver Canada/Pacific -Link America/Regina Canada/Saskatchewan -Link America/Whitehorse Canada/Yukon -Link America/Santiago Chile/Continental -Link Pacific/Easter Chile/EasterIsland -Link America/Havana Cuba -Link Africa/Cairo Egypt -Link Europe/Dublin Eire -Link Europe/London Europe/Belfast -Link Europe/Chisinau Europe/Tiraspol -Link Europe/London GB -Link Europe/London GB-Eire -Link Etc/GMT GMT+0 -Link Etc/GMT GMT-0 -Link Etc/GMT GMT0 -Link Etc/GMT Greenwich -Link Asia/Hong_Kong Hongkong -Link Atlantic/Reykjavik Iceland -Link Asia/Tehran Iran -Link Asia/Jerusalem Israel -Link America/Jamaica Jamaica -Link Asia/Tokyo Japan -Link Pacific/Kwajalein Kwajalein -Link Africa/Tripoli Libya -Link America/Tijuana Mexico/BajaNorte -Link America/Mazatlan Mexico/BajaSur -Link America/Mexico_City Mexico/General -Link Pacific/Auckland NZ -Link Pacific/Chatham NZ-CHAT -Link America/Denver Navajo -Link Asia/Shanghai PRC -Link Pacific/Pago_Pago Pacific/Samoa -Link Pacific/Chuuk Pacific/Yap -Link Pacific/Chuuk Pacific/Truk -Link Pacific/Pohnpei Pacific/Ponape -Link Europe/Warsaw Poland -Link Europe/Lisbon Portugal -Link Asia/Taipei ROC -Link Asia/Seoul ROK -Link Asia/Singapore Singapore -Link Europe/Istanbul Turkey -Link Etc/UCT UCT -Link America/Anchorage US/Alaska -Link America/Adak US/Aleutian -Link America/Phoenix US/Arizona -Link America/Chicago US/Central -Link America/Indiana/Indianapolis US/East-Indiana -Link America/New_York US/Eastern -Link Pacific/Honolulu US/Hawaii -Link America/Indiana/Knox US/Indiana-Starke -Link America/Detroit US/Michigan -Link America/Denver US/Mountain -Link America/Los_Angeles US/Pacific -Link Pacific/Pago_Pago US/Samoa -Link Etc/UTC UTC -Link Etc/UTC Universal -Link Europe/Moscow W-SU -Link Etc/UTC Zulu diff --git a/libmap/cc-timezone-map.c b/libmap/cc-timezone-map.c deleted file mode 100644 index ff6eee8..0000000 --- a/libmap/cc-timezone-map.c +++ /dev/null @@ -1,1163 +0,0 @@ -/* - * Copyright (C) 2010 Intel, Inc - * Copyright (C) 2011 Canonical Ltd. - * - * Portions from Ubiquity, Copyright (C) 2009 Canonical Ltd. - * Written by Evan Dandrea <evand@ubuntu.com> - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Author: Thomas Wood <thomas.wood@intel.com> - * - */ - -#include "cc-timezone-map.h" -#include <math.h> -#include "tz.h" - -G_DEFINE_TYPE (CcTimezoneMap, cc_timezone_map, GTK_TYPE_WIDGET) - -#define TIMEZONE_MAP_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_TIMEZONE_MAP, CcTimezoneMapPrivate)) - - -typedef struct -{ - gdouble offset; - guchar red; - guchar green; - guchar blue; - guchar alpha; -} CcTimezoneMapOffset; - -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; - - gdouble selected_offset; - - gchar *watermark; - - TzDB *tzdb; - TzLocation *location; - GHashTable *alias_db; -}; - -enum -{ - LOCATION_CHANGED, - LAST_SIGNAL -}; - -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", - "Africa/Addis_Ababa", - "Africa/Algiers", - "Africa/Asmara", - "Africa/Bamako", - "Africa/Bangui", - "Africa/Banjul", - "Africa/Bissau", - "Africa/Blantyre", - "Africa/Brazzaville", - "Africa/Bujumbura", - "Africa/Cairo", - "Africa/Casablanca", - "Africa/Conakry", - "Africa/Dakar", - "Africa/Dar_es_Salaam", - "Africa/Djibouti", - "Africa/Douala", - "Africa/El_Aaiun", - "Africa/Freetown", - "Africa/Gaborone", - "Africa/Harare", - "Africa/Johannesburg", - "Africa/Kampala", - "Africa/Khartoum", - "Africa/Kigali", - "Africa/Kinshasa", - "Africa/Lagos", - "Africa/Libreville", - "Africa/Lome", - "Africa/Luanda", - "Africa/Lubumbashi", - "Africa/Lusaka", - "Africa/Malabo", - "Africa/Maputo", - "Africa/Maseru", - "Africa/Mbabane", - "Africa/Mogadishu", - "Africa/Monrovia", - "Africa/Nairobi", - "Africa/Ndjamena", - "Africa/Niamey", - "Africa/Nouakchott", - "Africa/Ouagadougou", - "Africa/Porto-Novo", - "Africa/Sao_Tome", - "Africa/Tripoli", - "Africa/Tunis", - "Africa/Windhoek", - "America/Adak", - "America/Anguilla", - "America/Antigua", - "America/Araguaina", - "America/Argentina/Buenos_Aires", - "America/Argentina/Catamarca", - "America/Argentina/Cordoba", - "America/Argentina/Jujuy", - "America/Argentina/La_Rioja", - "America/Argentina/Mendoza", - "America/Argentina/Rio_Gallegos", - "America/Argentina/San_Juan", - "America/Argentina/San_Luis", - "America/Argentina/Tucuman", - "America/Argentina/Ushuaia", - "America/Aruba", - "America/Asuncion", - "America/Atikokan", - "America/Bahia", - "America/Barbados", - "America/Belem", - "America/Belize", - "America/Blanc-Sablon", - "America/Boa_Vista", - "America/Bogota", - "America/Boise", - "America/Cambridge_Bay", - "America/Campo_Grande", - "America/Cancun", - "America/Caracas", - "America/Cayenne", - "America/Cayman", - "America/Chicago", - "America/Chihuahua", - "America/Coral_Harbour", - "America/Costa_Rica", - "America/Cuiaba", - "America/Curacao", - "America/Dawson", - "America/Dawson_Creek", - "America/Denver", - "America/Dominica", - "America/Edmonton", - "America/Eirunepe", - "America/El_Salvador", - "America/Fortaleza", - "America/Glace_Bay", - "America/Goose_Bay", - "America/Grand_Turk", - "America/Grenada", - "America/Guadeloupe", - "America/Guatemala", - "America/Guayaquil", - "America/Guyana", - "America/Halifax", - "America/Havana", - "America/Hermosillo", - "America/Indiana/Indianapolis", - "America/Indiana/Knox", - "America/Indiana/Marengo", - "America/Indiana/Petersburg", - "America/Indiana/Vevay", - "America/Indiana/Vincennes", - "America/Indiana/Winamac", - "America/Inuvik", - "America/Iqaluit", - "America/Jamaica", - "America/Juneau", - "America/Kentucky/Louisville", - "America/Kentucky/Monticello", - "America/La_Paz", - "America/Lima", - "America/Los_Angeles", - "America/Maceio", - "America/Managua", - "America/Manaus", - "America/Marigot", - "America/Martinique", - "America/Mazatlan", - "America/Menominee", - "America/Merida", - "America/Mexico_City", - "America/Miquelon", - "America/Moncton", - "America/Monterrey", - "America/Montevideo", - "America/Montreal", - "America/Montserrat", - "America/Nassau", - "America/New_York", - "America/Nipigon", - "America/Noronha", - "America/North_Dakota/Center", - "America/North_Dakota/Salem", - "America/Panama", - "America/Pangnirtung", - "America/Paramaribo", - "America/Phoenix", - "America/Port-au-Prince", - "America/Port_of_Spain", - "America/Porto_Velho", - "America/Puerto_Rico", - "America/Rainy_River", - "America/Rankin_Inlet", - "America/Recife", - "America/Regina", - "America/Resolute", - "America/Rio_Branco", - "America/Santarem", - "America/Santiago", - "America/Santo_Domingo", - "America/Sao_Paulo", - "America/St_Barthelemy", - "America/St_Johns", - "America/St_Kitts", - "America/St_Lucia", - "America/St_Thomas", - "America/St_Vincent", - "America/Tegucigalpa", - "America/Thunder_Bay", - "America/Tijuana", - "America/Toronto", - "America/Tortola", - "America/Vancouver", - "America/Whitehorse", - "America/Winnipeg", - "America/Yellowknife", - "Ameriica/Swift_Current", - "Arctic/Longyearbyen", - "Asia/Aden", - "Asia/Almaty", - "Asia/Amman", - "Asia/Anadyr", - "Asia/Aqtau", - "Asia/Aqtobe", - "Asia/Ashgabat", - "Asia/Baghdad", - "Asia/Bahrain", - "Asia/Baku", - "Asia/Bangkok", - "Asia/Beirut", - "Asia/Bishkek", - "Asia/Brunei", - "Asia/Choibalsan", - "Asia/Chongqing", - "Asia/Colombo", - "Asia/Damascus", - "Asia/Dhaka", - "Asia/Dili", - "Asia/Dubai", - "Asia/Dushanbe", - "Asia/Gaza", - "Asia/Harbin", - "Asia/Ho_Chi_Minh", - "Asia/Hong_Kong", - "Asia/Hovd", - "Asia/Irkutsk", - "Asia/Jakarta", - "Asia/Jayapura", - "Asia/Jerusalem", - "Asia/Kabul", - "Asia/Kamchatka", - "Asia/Karachi", - "Asia/Kashgar", - "Asia/Katmandu", - "Asia/Kolkata", - "Asia/Krasnoyarsk", - "Asia/Kuala_Lumpur", - "Asia/Kuching", - "Asia/Kuwait", - "Asia/Macau", - "Asia/Magadan", - "Asia/Makassar", - "Asia/Manila", - "Asia/Muscat", - "Asia/Nicosia", - "Asia/Novosibirsk", - "Asia/Omsk", - "Asia/Oral", - "Asia/Phnom_Penh", - "Asia/Pontianak", - "Asia/Pyongyang", - "Asia/Qatar", - "Asia/Qyzylorda", - "Asia/Rangoon", - "Asia/Riyadh", - "Asia/Sakhalin", - "Asia/Samarkand", - "Asia/Seoul", - "Asia/Shanghai", - "Asia/Singapore", - "Asia/Taipei", - "Asia/Tashkent", - "Asia/Tbilisi", - "Asia/Tehran", - "Asia/Thimphu", - "Asia/Tokyo", - "Asia/Ulaanbaatar", - "Asia/Urumqi", - "Asia/Vientiane", - "Asia/Vladivostok", - "Asia/Yakutsk", - "Asia/Yekaterinburg", - "Asia/Yerevan", - "Atlantic/Azores", - "Atlantic/Bermuda", - "Atlantic/Canary", - "Atlantic/Cape_Verde", - "Atlantic/Faroe", - "Atlantic/Madeira", - "Atlantic/Reykjavik", - "Atlantic/South_Georgia", - "Atlantic/St_Helena", - "Atlantic/Stanley", - "Australia/Adelaide", - "Australia/Brisbane", - "Australia/Broken_Hill", - "Australia/Currie", - "Australia/Darwin", - "Australia/Eucla", - "Australia/Hobart", - "Australia/Lindeman", - "Australia/Lord_Howe", - "Australia/Melbourne", - "Australia/Perth", - "Australia/Sydney", - "Europe/Amsterdam", - "Europe/Andorra", - "Europe/Athens", - "Europe/Belgrade", - "Europe/Berlin", - "Europe/Bratislava", - "Europe/Brussels", - "Europe/Bucharest", - "Europe/Budapest", - "Europe/Chisinau", - "Europe/Copenhagen", - "Europe/Dublin", - "Europe/Gibraltar", - "Europe/Guernsey", - "Europe/Helsinki", - "Europe/Isle_of_Man", - "Europe/Istanbul", - "Europe/Jersey", - "Europe/Kaliningrad", - "Europe/Kiev", - "Europe/Lisbon", - "Europe/Ljubljana", - "Europe/London", - "Europe/Luxembourg", - "Europe/Madrid", - "Europe/Malta", - "Europe/Marienhamn", - "Europe/Minsk", - "Europe/Monaco", - "Europe/Moscow", - "Europe/Oslo", - "Europe/Paris", - "Europe/Podgorica", - "Europe/Prague", - "Europe/Riga", - "Europe/Rome", - "Europe/Samara", - "Europe/San_Marino", - "Europe/Sarajevo", - "Europe/Simferopol", - "Europe/Skopje", - "Europe/Sofia", - "Europe/Stockholm", - "Europe/Tallinn", - "Europe/Tirane", - "Europe/Uzhgorod", - "Europe/Vaduz", - "Europe/Vatican", - "Europe/Vienna", - "Europe/Vilnius", - "Europe/Volgograd", - "Europe/Warsaw", - "Europe/Zagreb", - "Europe/Zaporozhye", - "Europe/Zurich", - "Indian/Antananarivo", - "Indian/Chagos", - "Indian/Christmas", - "Indian/Cocos", - "Indian/Comoro", - "Indian/Kerguelen", - "Indian/Mahe", - "Indian/Maldives", - "Indian/Mauritius", - "Indian/Mayotte", - "Indian/Reunion", - "Pacific/Apia", - "Pacific/Auckland", - "Pacific/Chatham", - "Pacific/Easter", - "Pacific/Efate", - "Pacific/Enderbury", - "Pacific/Fakaofo", - "Pacific/Fiji", - "Pacific/Funafuti", - "Pacific/Galapagos", - "Pacific/Gambier", - "Pacific/Guadalcanal", - "Pacific/Guam", - "Pacific/Honolulu", - "Pacific/Johnston", - "Pacific/Kiritimati", - "Pacific/Kosrae", - "Pacific/Kwajalein", - "Pacific/Majuro", - "Pacific/Marquesas", - "Pacific/Midway", - "Pacific/Nauru", - "Pacific/Niue", - "Pacific/Norfolk", - "Pacific/Noumea", - "Pacific/Pago_Pago", - "Pacific/Palau", - "Pacific/Pitcairn", - "Pacific/Ponape", - "Pacific/Port_Moresby", - "Pacific/Rarotonga", - "Pacific/Saipan", - "Pacific/Tahiti", - "Pacific/Tarawa", - "Pacific/Tongatapu", - "Pacific/Truk", - "Pacific/Wake", - "Pacific/Wallis" -}; - -static void -cc_timezone_map_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -cc_timezone_map_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - } -} - -static void -cc_timezone_map_dispose (GObject *object) -{ - CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (object)->priv; - - if (priv->orig_background) - { - g_object_unref (priv->orig_background); - 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); - priv->olsen_map = NULL; - - priv->olsen_map_channels = 0; - priv->olsen_map_pixels = NULL; - priv->olsen_map_rowstride = 0; - } - - if (priv->background) - { - g_object_unref (priv->background); - 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); - priv->alias_db = NULL; - } - - if (priv->watermark) - { - g_free (priv->watermark); - priv->watermark = NULL; - } - - G_OBJECT_CLASS (cc_timezone_map_parent_class)->dispose (object); -} - -static void -cc_timezone_map_finalize (GObject *object) -{ - CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (object)->priv; - - if (priv->tzdb) - { - tz_db_free (priv->tzdb); - priv->tzdb = NULL; - } - - - G_OBJECT_CLASS (cc_timezone_map_parent_class)->finalize (object); -} - -/* GtkWidget functions */ -static void -cc_timezone_map_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - /* choose a minimum size small enough to prevent the window - * from growing horizontally - */ - if (minimum != NULL) - *minimum = 300; - if (natural != NULL) - *natural = 300; -} - -static void -cc_timezone_map_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; - gint size; - - /* The + 20 here is a slight tweak to make the map fill the - * panel better without causing horizontal growing - */ - size = 300 * gdk_pixbuf_get_height (priv->orig_background) / gdk_pixbuf_get_width (priv->orig_background) + 20; - if (minimum != NULL) - *minimum = size; - if (natural != NULL) - *natural = size; -} - -static void -cc_timezone_map_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; - - if (priv->background) - g_object_unref (priv->background); - - priv->background = gdk_pixbuf_scale_simple (priv->orig_background, - allocation->width, - 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); -} - -static void -cc_timezone_map_realize (GtkWidget *widget) -{ - GdkWindowAttr attr = { 0, }; - GtkAllocation allocation; - GdkCursor *cursor; - GdkWindow *window; - - gtk_widget_get_allocation (widget, &allocation); - - gtk_widget_set_realized (widget, TRUE); - - attr.window_type = GDK_WINDOW_CHILD; - attr.wclass = GDK_INPUT_OUTPUT; - attr.width = allocation.width; - attr.height = allocation.height; - attr.x = allocation.x; - attr.y = allocation.y; - attr.event_mask = gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK; - - window = gdk_window_new (gtk_widget_get_parent_window (widget), &attr, - GDK_WA_X | GDK_WA_Y); - - gdk_window_set_user_data (window, widget); - - cursor = gdk_cursor_new (GDK_HAND2); - gdk_window_set_cursor (window, cursor); - - gtk_widget_set_window (widget, window); -} - - -static gdouble -convert_longtitude_to_x (gdouble longitude, gint map_width) -{ - const gdouble xdeg_offset = -6; - gdouble x; - - x = (map_width * (180.0 + longitude) / 360.0) - + (map_width * xdeg_offset / 180.0); - - return x; -} - -static gdouble -radians (gdouble degrees) -{ - return (degrees / 360.0) * G_PI * 2; -} - -static gdouble -convert_latitude_to_y (gdouble latitude, gdouble map_height) -{ - gdouble bottom_lat = -59; - gdouble top_lat = 81; - gdouble top_per, y, full_range, top_offset, map_range; - - top_per = top_lat / 180.0; - y = 1.25 * log (tan (G_PI_4 + 0.4 * radians (latitude))); - full_range = 4.6068250867599998; - top_offset = full_range * top_per; - map_range = fabs (1.25 * log (tan (G_PI_4 + 0.4 * radians (bottom_lat))) - top_offset); - y = fabs (y - top_offset); - y = y / map_range; - y = y * map_height; - return y; -} - - -static gboolean -cc_timezone_map_draw (GtkWidget *widget, - cairo_t *cr) -{ - CcTimezoneMapPrivate *priv = CC_TIMEZONE_MAP (widget)->priv; - GdkPixbuf *hilight, *orig_hilight, *pin; - GtkAllocation alloc; - gchar *file; - GError *err = NULL; - gdouble pointx, pointy; - gdouble alpha = 1.0; - char buf[16]; - - gtk_widget_get_allocation (widget, &alloc); - - /* Check if insensitive */ - if (gtk_widget_get_sensitive (widget)) - alpha = 0.5; - - /* paint background */ -#if GTK_CHECK_VERSION(3,0,0) - GdkRGBA rgba; - gtk_style_context_get_background_color (gtk_widget_get_style_context (widget), - gtk_widget_get_state_flags (widget), - &rgba); - gdk_cairo_set_source_rgba (cr, &rgba); -#else - GtkStyle * style = gtk_widget_get_style (widget); - gdk_cairo_set_source_color (cr, &style->bg[gtk_widget_get_state (widget)]); -#endif - cairo_paint (cr); - gdk_cairo_set_source_pixbuf (cr, priv->background, 0, 0); - cairo_paint_with_alpha (cr, alpha); - - /* paint watermark */ - if (priv->watermark) { - cairo_text_extents_t extent; - cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(cr, 12.0); - cairo_set_source_rgba(cr, 1, 1, 1, 0.5); - cairo_text_extents(cr, priv->watermark, &extent); - cairo_move_to(cr, alloc.width - extent.x_advance + extent.x_bearing - 5, - alloc.height - extent.height - extent.y_bearing - 5); - cairo_show_text(cr, priv->watermark); - cairo_stroke(cr); - } - - if (!priv->location) { - return TRUE; - } - - /* paint hilight */ - file = g_strdup_printf (DATADIR "/timezone_%s.png", - g_ascii_formatd (buf, sizeof (buf), - "%g", priv->selected_offset)); - orig_hilight = gdk_pixbuf_new_from_file (file, &err); - g_free (file); - file = NULL; - - if (!orig_hilight) - { - g_warning ("Could not load hilight: %s", - (err) ? err->message : "Unknown Error"); - if (err) - g_clear_error (&err); - } - else - { - - hilight = gdk_pixbuf_scale_simple (orig_hilight, alloc.width, - alloc.height, GDK_INTERP_BILINEAR); - gdk_cairo_set_source_pixbuf (cr, hilight, 0, 0); - - cairo_paint_with_alpha (cr, alpha); - g_object_unref (hilight); - g_object_unref (orig_hilight); - } - - /* load pin icon */ - pin = gdk_pixbuf_new_from_file (DATADIR "/pin.png", &err); - - if (err) - { - g_warning ("Could not load pin icon: %s", err->message); - g_clear_error (&err); - } - - pointx = convert_longtitude_to_x (priv->location->longitude, alloc.width); - pointy = convert_latitude_to_y (priv->location->latitude, alloc.height); - - if (pointy > alloc.height) - pointy = alloc.height; - - if (pin) - { - gdk_cairo_set_source_pixbuf (cr, pin, pointx - 8, pointy - 14); - cairo_paint_with_alpha (cr, alpha); - g_object_unref (pin); - } - - return TRUE; -} - -static void -cc_timezone_map_class_init (CcTimezoneMapClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - g_type_class_add_private (klass, sizeof (CcTimezoneMapPrivate)); - - object_class->get_property = cc_timezone_map_get_property; - object_class->set_property = cc_timezone_map_set_property; - object_class->dispose = cc_timezone_map_dispose; - object_class->finalize = cc_timezone_map_finalize; - - widget_class->get_preferred_width = cc_timezone_map_get_preferred_width; - widget_class->get_preferred_height = cc_timezone_map_get_preferred_height; - widget_class->size_allocate = cc_timezone_map_size_allocate; - widget_class->realize = cc_timezone_map_realize; - widget_class->draw = cc_timezone_map_draw; - - signals[LOCATION_CHANGED] = g_signal_new ("location-changed", - CC_TYPE_TIMEZONE_MAP, - G_SIGNAL_RUN_FIRST, - 0, - NULL, - NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); -} - - -static gint -sort_locations (TzLocation *a, - TzLocation *b) -{ - if (a->dist > b->dist) - return 1; - - if (a->dist < b->dist) - return -1; - - return 0; -} - -static void -set_location (CcTimezoneMap *map, - TzLocation *location) -{ - CcTimezoneMapPrivate *priv = map->priv; - TzInfo *info; - - priv->location = location; - - info = tz_info_from_location (priv->location); - - priv->selected_offset = tz_location_get_utc_offset (priv->location) - / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0); - - g_signal_emit (map, signals[LOCATION_CHANGED], 0, priv->location); - - tz_info_free (info); -} - -static TzLocation * -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; - - const GPtrArray *array; - gint width, height; - GList *distances = NULL; - GtkAllocation alloc; - - 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]; - - - 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); - - /* work out the co-ordinates */ - - array = tz_get_locations (priv->tzdb); - - gtk_widget_get_allocation (widget, &alloc); - width = alloc.width; - height = alloc.height; - - for (i = 0; i < array->len; i++) - { - gdouble pointx, pointy, dx, dy; - TzLocation *loc = array->pdata[i]; - - pointx = convert_longtitude_to_x (loc->longitude, width); - pointy = convert_latitude_to_y (loc->latitude, height); - - dx = pointx - x; - dy = pointy - y; - - loc->dist = dx * dx + dy * dy; - distances = g_list_prepend (distances, loc); - - } - distances = g_list_sort (distances, (GCompareFunc) sort_locations); - - TzLocation * loc = (TzLocation*) distances->data; - - g_list_free (distances); - - return loc; -} - -static gboolean -button_press_event (GtkWidget *widget, - GdkEventButton *event) -{ - TzLocation * loc = get_loc_for_xy (widget, event->x, event->y); - set_location (CC_TIMEZONE_MAP (widget), loc); - return TRUE; -} - -static void -state_flags_changed (GtkWidget *widget) -{ - // To catch sensitivity changes - gtk_widget_queue_draw (widget); -} - -static void -load_backward_tz (CcTimezoneMap *self) -{ - GError *error = NULL; - char **lines, *contents; - guint i; - - self->priv->alias_db = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); - - if (g_file_get_contents (GNOMECC_DATA_DIR "/datetime/backward", &contents, NULL, &error) == FALSE) - { - g_warning ("Failed to load 'backward' file: %s", error->message); - return; - } - lines = g_strsplit (contents, "\n", -1); - g_free (contents); - for (i = 0; lines[i] != NULL; i++) - { - char **items; - guint j; - char *real, *alias; - - if (g_ascii_strncasecmp (lines[i], "Link\t", 5) != 0) - continue; - - items = g_strsplit (lines[i], "\t", -1); - real = NULL; - alias = NULL; - /* Skip the "Link<tab>" part */ - for (j = 1; items[j] != NULL; j++) - { - if (items[j][0] == '\0') - continue; - if (real == NULL) - { - real = items[j]; - continue; - } - alias = items[j]; - break; - } - - if (real == NULL || alias == NULL) - g_warning ("Could not parse line: %s", lines[i]); - - g_hash_table_insert (self->priv->alias_db, g_strdup (alias), g_strdup (real)); - g_strfreev (items); - } - g_strfreev (lines); -} - -static void -cc_timezone_map_init (CcTimezoneMap *self) -{ - CcTimezoneMapPrivate *priv; - GError *err = NULL; - - priv = self->priv = TIMEZONE_MAP_PRIVATE (self); - - priv->orig_background = gdk_pixbuf_new_from_file (DATADIR "/bg.png", - &err); - - if (!priv->orig_background) - { - g_warning ("Could not load background image: %s", - (err) ? err->message : "Unknown error"); - 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) - { - g_warning ("Could not load olsen map: %s", - (err) ? err->message : "Unknown error"); - g_clear_error (&err); - } - priv->olsen_map_channels = gdk_pixbuf_get_n_channels (priv->olsen_map); - priv->olsen_map_pixels = gdk_pixbuf_get_pixels (priv->olsen_map); - priv->olsen_map_rowstride = gdk_pixbuf_get_rowstride (priv->olsen_map); - - priv->tzdb = tz_load_db (); - - g_signal_connect (self, "button-press-event", G_CALLBACK (button_press_event), - NULL); - g_signal_connect (self, "state-flags-changed", G_CALLBACK (state_flags_changed), - NULL); - - load_backward_tz (self); -} - -CcTimezoneMap * -cc_timezone_map_new (void) -{ - return g_object_new (CC_TYPE_TIMEZONE_MAP, NULL); -} - -void -cc_timezone_map_set_timezone (CcTimezoneMap *map, - const gchar *timezone) -{ - GPtrArray *locations; - guint i; - char *real_tz; - - real_tz = g_hash_table_lookup (map->priv->alias_db, timezone); - - locations = tz_get_locations (map->priv->tzdb); - - for (i = 0; i < locations->len; i++) - { - TzLocation *loc = locations->pdata[i]; - - if (!g_strcmp0 (loc->zone, real_tz ? real_tz : timezone)) - { - set_location (map, loc); - break; - } - } - - gtk_widget_queue_draw (GTK_WIDGET (map)); -} - -void -cc_timezone_map_set_coords (CcTimezoneMap *map, gdouble lon, gdouble lat) -{ - const gchar * zone = cc_timezone_map_get_timezone_at_coords (map, lon, lat); - cc_timezone_map_set_timezone (map, zone); -} - -const gchar * -cc_timezone_map_get_timezone_at_coords (CcTimezoneMap *map, gdouble lon, gdouble lat) -{ - gint x = (int)(2048.0 / 360.0 * (180.0 + lon)); - gint y = (int)(1024.0 / 180.0 * (90.0 - lat)); - gint offset = map->priv->olsen_map_rowstride * y + x * map->priv->olsen_map_channels; - guchar color0 = map->priv->olsen_map_pixels[offset]; - guchar color1 = map->priv->olsen_map_pixels[offset + 1]; - gint zone = ((color0 & 248) << 1) + ((color1 >>4) & 15); - - const gchar * city = NULL; - if (zone < G_N_ELEMENTS(olsen_map_timezones)) - city = olsen_map_timezones[zone]; - - if (city != NULL) { - return city; - } - else { - GtkAllocation alloc; - gtk_widget_get_allocation (GTK_WIDGET (map), &alloc); - x = convert_longtitude_to_x(lon, alloc.width); - y = convert_latitude_to_y(lat, alloc.height); - TzLocation * loc = get_loc_for_xy(GTK_WIDGET (map), x, y); - return loc->zone; - } -} - -void -cc_timezone_map_set_watermark (CcTimezoneMap *map, const gchar * watermark) -{ - if (map->priv->watermark) - g_free (map->priv->watermark); - - map->priv->watermark = g_strdup (watermark); - gtk_widget_queue_draw (GTK_WIDGET (map)); -} - -TzLocation * -cc_timezone_map_get_location (CcTimezoneMap *map) -{ - return map->priv->location; -} diff --git a/libmap/cc-timezone-map.h b/libmap/cc-timezone-map.h deleted file mode 100644 index ace1107..0000000 --- a/libmap/cc-timezone-map.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2010 Intel, Inc - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Author: Thomas Wood <thomas.wood@intel.com> - * - */ - - -#ifndef _CC_TIMEZONE_MAP_H -#define _CC_TIMEZONE_MAP_H - -#include <gtk/gtk.h> -#include "tz.h" - -G_BEGIN_DECLS - -#define CC_TYPE_TIMEZONE_MAP cc_timezone_map_get_type() - -#define CC_TIMEZONE_MAP(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - CC_TYPE_TIMEZONE_MAP, CcTimezoneMap)) - -#define CC_TIMEZONE_MAP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - CC_TYPE_TIMEZONE_MAP, CcTimezoneMapClass)) - -#define CC_IS_TIMEZONE_MAP(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - CC_TYPE_TIMEZONE_MAP)) - -#define CC_IS_TIMEZONE_MAP_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - CC_TYPE_TIMEZONE_MAP)) - -#define CC_TIMEZONE_MAP_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - CC_TYPE_TIMEZONE_MAP, CcTimezoneMapClass)) - -typedef struct _CcTimezoneMap CcTimezoneMap; -typedef struct _CcTimezoneMapClass CcTimezoneMapClass; -typedef struct _CcTimezoneMapPrivate CcTimezoneMapPrivate; - -struct _CcTimezoneMap -{ - GtkWidget parent; - - CcTimezoneMapPrivate *priv; -}; - -struct _CcTimezoneMapClass -{ - GtkWidgetClass parent_class; -}; - -GType cc_timezone_map_get_type (void) G_GNUC_CONST; - -CcTimezoneMap *cc_timezone_map_new (void); - -void cc_timezone_map_set_watermark (CcTimezoneMap * map, - const gchar * watermark); -void cc_timezone_map_set_timezone (CcTimezoneMap *map, - const gchar *timezone); -void cc_timezone_map_set_coords (CcTimezoneMap *map, - gdouble lon, gdouble lat); -const gchar * cc_timezone_map_get_timezone_at_coords (CcTimezoneMap *map, - gdouble lon, gdouble lat); -TzLocation * cc_timezone_map_get_location (CcTimezoneMap *map); - -G_END_DECLS - -#endif /* _CC_TIMEZONE_MAP_H */ diff --git a/libmap/data/bg.png b/libmap/data/bg.png Binary files differdeleted file mode 100644 index 4180ee8..0000000 --- a/libmap/data/bg.png +++ /dev/null diff --git a/libmap/data/cc.png b/libmap/data/cc.png Binary files differdeleted file mode 100644 index 54fb668..0000000 --- a/libmap/data/cc.png +++ /dev/null diff --git a/libmap/data/olsen_map.png b/libmap/data/olsen_map.png Binary files differdeleted file mode 100644 index f9bb75c..0000000 --- a/libmap/data/olsen_map.png +++ /dev/null diff --git a/libmap/data/pin.png b/libmap/data/pin.png Binary files differdeleted file mode 100644 index 599a751..0000000 --- a/libmap/data/pin.png +++ /dev/null diff --git a/libmap/data/timezone_-1.png b/libmap/data/timezone_-1.png Binary files differdeleted file mode 100644 index fb00d83..0000000 --- a/libmap/data/timezone_-1.png +++ /dev/null diff --git a/libmap/data/timezone_-10.png b/libmap/data/timezone_-10.png Binary files differdeleted file mode 100644 index 472eb88..0000000 --- a/libmap/data/timezone_-10.png +++ /dev/null diff --git a/libmap/data/timezone_-11.png b/libmap/data/timezone_-11.png Binary files differdeleted file mode 100644 index 5f8c5d6..0000000 --- a/libmap/data/timezone_-11.png +++ /dev/null diff --git a/libmap/data/timezone_-2.png b/libmap/data/timezone_-2.png Binary files differdeleted file mode 100644 index 30a1ec7..0000000 --- a/libmap/data/timezone_-2.png +++ /dev/null diff --git a/libmap/data/timezone_-3.5.png b/libmap/data/timezone_-3.5.png Binary files differdeleted file mode 100644 index c1df00b..0000000 --- a/libmap/data/timezone_-3.5.png +++ /dev/null diff --git a/libmap/data/timezone_-3.png b/libmap/data/timezone_-3.png Binary files differdeleted file mode 100644 index c22dbb6..0000000 --- a/libmap/data/timezone_-3.png +++ /dev/null diff --git a/libmap/data/timezone_-4.5.png b/libmap/data/timezone_-4.5.png Binary files differdeleted file mode 100644 index 9e3c134..0000000 --- a/libmap/data/timezone_-4.5.png +++ /dev/null diff --git a/libmap/data/timezone_-4.png b/libmap/data/timezone_-4.png Binary files differdeleted file mode 100644 index 4b5a431..0000000 --- a/libmap/data/timezone_-4.png +++ /dev/null diff --git a/libmap/data/timezone_-5.5.png b/libmap/data/timezone_-5.5.png Binary files differdeleted file mode 100644 index b1c788d..0000000 --- a/libmap/data/timezone_-5.5.png +++ /dev/null diff --git a/libmap/data/timezone_-5.png b/libmap/data/timezone_-5.png Binary files differdeleted file mode 100644 index 06c15e6..0000000 --- a/libmap/data/timezone_-5.png +++ /dev/null diff --git a/libmap/data/timezone_-6.png b/libmap/data/timezone_-6.png Binary files differdeleted file mode 100644 index 8505fb1..0000000 --- a/libmap/data/timezone_-6.png +++ /dev/null diff --git a/libmap/data/timezone_-7.png b/libmap/data/timezone_-7.png Binary files differdeleted file mode 100644 index fec235d..0000000 --- a/libmap/data/timezone_-7.png +++ /dev/null diff --git a/libmap/data/timezone_-8.png b/libmap/data/timezone_-8.png Binary files differdeleted file mode 100644 index bdad7bf..0000000 --- a/libmap/data/timezone_-8.png +++ /dev/null diff --git a/libmap/data/timezone_-9.5.png b/libmap/data/timezone_-9.5.png Binary files differdeleted file mode 100644 index b1c788d..0000000 --- a/libmap/data/timezone_-9.5.png +++ /dev/null diff --git a/libmap/data/timezone_-9.png b/libmap/data/timezone_-9.png Binary files differdeleted file mode 100644 index 04cb3cb..0000000 --- a/libmap/data/timezone_-9.png +++ /dev/null diff --git a/libmap/data/timezone_0.png b/libmap/data/timezone_0.png Binary files differdeleted file mode 100644 index e59b773..0000000 --- a/libmap/data/timezone_0.png +++ /dev/null diff --git a/libmap/data/timezone_1.png b/libmap/data/timezone_1.png Binary files differdeleted file mode 100644 index 2053b7e..0000000 --- a/libmap/data/timezone_1.png +++ /dev/null diff --git a/libmap/data/timezone_10.5.png b/libmap/data/timezone_10.5.png Binary files differdeleted file mode 100644 index 6ec7f9f..0000000 --- a/libmap/data/timezone_10.5.png +++ /dev/null diff --git a/libmap/data/timezone_10.png b/libmap/data/timezone_10.png Binary files differdeleted file mode 100644 index 475dcf4..0000000 --- a/libmap/data/timezone_10.png +++ /dev/null diff --git a/libmap/data/timezone_11.5.png b/libmap/data/timezone_11.5.png Binary files differdeleted file mode 100644 index afdedd7..0000000 --- a/libmap/data/timezone_11.5.png +++ /dev/null diff --git a/libmap/data/timezone_11.png b/libmap/data/timezone_11.png Binary files differdeleted file mode 100644 index 6168aa2..0000000 --- a/libmap/data/timezone_11.png +++ /dev/null diff --git a/libmap/data/timezone_12.75.png b/libmap/data/timezone_12.75.png Binary files differdeleted file mode 100644 index 4f74a85..0000000 --- a/libmap/data/timezone_12.75.png +++ /dev/null diff --git a/libmap/data/timezone_12.png b/libmap/data/timezone_12.png Binary files differdeleted file mode 100644 index d0b3531..0000000 --- a/libmap/data/timezone_12.png +++ /dev/null diff --git a/libmap/data/timezone_13.png b/libmap/data/timezone_13.png Binary files differdeleted file mode 100644 index fe2f134..0000000 --- a/libmap/data/timezone_13.png +++ /dev/null diff --git a/libmap/data/timezone_2.png b/libmap/data/timezone_2.png Binary files differdeleted file mode 100644 index ec1e874..0000000 --- a/libmap/data/timezone_2.png +++ /dev/null diff --git a/libmap/data/timezone_3.5.png b/libmap/data/timezone_3.5.png Binary files differdeleted file mode 100644 index 2dc7399..0000000 --- a/libmap/data/timezone_3.5.png +++ /dev/null diff --git a/libmap/data/timezone_3.png b/libmap/data/timezone_3.png Binary files differdeleted file mode 100644 index eda59dc..0000000 --- a/libmap/data/timezone_3.png +++ /dev/null diff --git a/libmap/data/timezone_4.5.png b/libmap/data/timezone_4.5.png Binary files differdeleted file mode 100644 index e09ed90..0000000 --- a/libmap/data/timezone_4.5.png +++ /dev/null diff --git a/libmap/data/timezone_4.png b/libmap/data/timezone_4.png Binary files differdeleted file mode 100644 index 483dc53..0000000 --- a/libmap/data/timezone_4.png +++ /dev/null diff --git a/libmap/data/timezone_5.5.png b/libmap/data/timezone_5.5.png Binary files differdeleted file mode 100644 index f904cc2..0000000 --- a/libmap/data/timezone_5.5.png +++ /dev/null diff --git a/libmap/data/timezone_5.75.png b/libmap/data/timezone_5.75.png Binary files differdeleted file mode 100644 index 827ce1a..0000000 --- a/libmap/data/timezone_5.75.png +++ /dev/null diff --git a/libmap/data/timezone_5.png b/libmap/data/timezone_5.png Binary files differdeleted file mode 100644 index 1bb6d20..0000000 --- a/libmap/data/timezone_5.png +++ /dev/null diff --git a/libmap/data/timezone_6.5.png b/libmap/data/timezone_6.5.png Binary files differdeleted file mode 100644 index d307bf3..0000000 --- a/libmap/data/timezone_6.5.png +++ /dev/null diff --git a/libmap/data/timezone_6.png b/libmap/data/timezone_6.png Binary files differdeleted file mode 100644 index 460f9cf..0000000 --- a/libmap/data/timezone_6.png +++ /dev/null diff --git a/libmap/data/timezone_7.png b/libmap/data/timezone_7.png Binary files differdeleted file mode 100644 index 239115a..0000000 --- a/libmap/data/timezone_7.png +++ /dev/null diff --git a/libmap/data/timezone_8.png b/libmap/data/timezone_8.png Binary files differdeleted file mode 100644 index 3627686..0000000 --- a/libmap/data/timezone_8.png +++ /dev/null diff --git a/libmap/data/timezone_9.5.png b/libmap/data/timezone_9.5.png Binary files differdeleted file mode 100644 index 1c3290c..0000000 --- a/libmap/data/timezone_9.5.png +++ /dev/null diff --git a/libmap/data/timezone_9.png b/libmap/data/timezone_9.png Binary files differdeleted file mode 100644 index 65d2e46..0000000 --- a/libmap/data/timezone_9.png +++ /dev/null diff --git a/libmap/test-timezone.c b/libmap/test-timezone.c deleted file mode 100644 index c1935fd..0000000 --- a/libmap/test-timezone.c +++ /dev/null @@ -1,56 +0,0 @@ -#include <config.h> -#include <locale.h> - -#include "tz.h" - -int main (int argc, char **argv) -{ - TzDB *db; - GPtrArray *locs; - guint i; - char *pixmap_dir; - int retval = 0; - - setlocale (LC_ALL, ""); - - if (argc == 2) { - pixmap_dir = g_strdup (argv[1]); - } else if (argc == 1) { - pixmap_dir = g_strdup ("data/"); - } else { - g_message ("Usage: %s [PIXMAP DIRECTORY]", argv[0]); - return 1; - } - - db = tz_load_db (); - locs = tz_get_locations (db); - for (i = 0; i < locs->len ; i++) { - TzLocation *loc = locs->pdata[i]; - TzInfo *info; - char *filename, *path; - gdouble selected_offset; - char buf[16]; - - info = tz_info_from_location (loc); - selected_offset = tz_location_get_utc_offset (loc) - / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0); - - filename = g_strdup_printf ("timezone_%s.png", - g_ascii_formatd (buf, sizeof (buf), - "%g", selected_offset)); - path = g_build_filename (pixmap_dir, filename, NULL); - - if (g_file_test (path, G_FILE_TEST_IS_REGULAR) == FALSE) { - g_message ("File '%s' missing for zone '%s'", filename, loc->zone); - retval = 1; - } - - g_free (filename); - g_free (path); - tz_info_free (info); - } - tz_db_free (db); - g_free (pixmap_dir); - - return retval; -} diff --git a/libmap/tz.c b/libmap/tz.c deleted file mode 100644 index b77a8ef..0000000 --- a/libmap/tz.c +++ /dev/null @@ -1,399 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Generic timezone utilities. - * - * Copyright (C) 2000-2001 Ximian, Inc. - * - * Authors: Hans Petter Jansson <hpj@ximian.com> - * - * Largely based on Michael Fulbright's work on Anaconda. - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - - -#include <glib.h> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <time.h> -#include <math.h> -#include <string.h> -#include "tz.h" - - -/* Forward declarations for private functions */ - -static float convert_pos (gchar *pos, int digits); -static int compare_country_names (const void *a, const void *b); -static void sort_locations_by_country (GPtrArray *locations); -static gchar * tz_data_file_get (void); - - -/* ---------------- * - * Public interface * - * ---------------- */ -TzDB * -tz_load_db (void) -{ - gchar *tz_data_file; - TzDB *tz_db; - FILE *tzfile; - char buf[4096]; - - tz_data_file = tz_data_file_get (); - if (!tz_data_file) { - g_warning ("Could not get the TimeZone data file name"); - return NULL; - } - tzfile = fopen (tz_data_file, "r"); - if (!tzfile) { - g_warning ("Could not open *%s*\n", tz_data_file); - g_free (tz_data_file); - return NULL; - } - - tz_db = g_new0 (TzDB, 1); - tz_db->locations = g_ptr_array_new (); - - while (fgets (buf, sizeof(buf), tzfile)) - { - gchar **tmpstrarr; - gchar *latstr, *lngstr, *p; - TzLocation *loc; - - if (*buf == '#') continue; - - g_strchomp(buf); - tmpstrarr = g_strsplit(buf,"\t", 6); - - latstr = g_strdup (tmpstrarr[1]); - p = latstr + 1; - while (*p != '-' && *p != '+') p++; - lngstr = g_strdup (p); - *p = '\0'; - - loc = g_new0 (TzLocation, 1); - loc->country = g_strdup (tmpstrarr[0]); - loc->zone = g_strdup (tmpstrarr[2]); - loc->latitude = convert_pos (latstr, 2); - loc->longitude = convert_pos (lngstr, 3); - -#ifdef __sun - if (tmpstrarr[3] && *tmpstrarr[3] == '-' && tmpstrarr[4]) - loc->comment = g_strdup (tmpstrarr[4]); - - if (tmpstrarr[3] && *tmpstrarr[3] != '-' && !islower(loc->zone)) { - TzLocation *locgrp; - - /* duplicate entry */ - locgrp = g_new0 (TzLocation, 1); - locgrp->country = g_strdup (tmpstrarr[0]); - locgrp->zone = g_strdup (tmpstrarr[3]); - locgrp->latitude = convert_pos (latstr, 2); - locgrp->longitude = convert_pos (lngstr, 3); - locgrp->comment = (tmpstrarr[4]) ? g_strdup (tmpstrarr[4]) : NULL; - - g_ptr_array_add (tz_db->locations, (gpointer) locgrp); - } -#else - loc->comment = (tmpstrarr[3]) ? g_strdup(tmpstrarr[3]) : NULL; -#endif - - g_ptr_array_add (tz_db->locations, (gpointer) loc); - - g_free (latstr); - g_free (lngstr); - g_strfreev (tmpstrarr); - } - - fclose (tzfile); - - /* now sort by country */ - sort_locations_by_country (tz_db->locations); - - g_free (tz_data_file); - - return tz_db; -} - -static void -tz_location_free (TzLocation *loc) -{ - g_free (loc->country); - g_free (loc->zone); - g_free (loc->comment); - - g_free (loc); -} - -void -tz_db_free (TzDB *db) -{ - g_ptr_array_foreach (db->locations, (GFunc) tz_location_free, NULL); - g_ptr_array_free (db->locations, TRUE); - g_free (db); -} - -static gint -sort_locations (TzLocation *a, - TzLocation *b) -{ - if (a->dist > b->dist) - return 1; - - if (a->dist < b->dist) - return -1; - - return 0; -} - -static gdouble -convert_longtitude_to_x (gdouble longitude, gint map_width) -{ - const gdouble xdeg_offset = -6; - gdouble x; - - x = (map_width * (180.0 + longitude) / 360.0) - + (map_width * xdeg_offset / 180.0); - - return x; -} - -static gdouble -radians (gdouble degrees) -{ - return (degrees / 360.0) * G_PI * 2; -} - -static gdouble -convert_latitude_to_y (gdouble latitude, gdouble map_height) -{ - gdouble bottom_lat = -59; - gdouble top_lat = 81; - gdouble top_per, y, full_range, top_offset, map_range; - - top_per = top_lat / 180.0; - y = 1.25 * log (tan (G_PI_4 + 0.4 * radians (latitude))); - full_range = 4.6068250867599998; - top_offset = full_range * top_per; - map_range = fabs (1.25 * log (tan (G_PI_4 + 0.4 * radians (bottom_lat))) - top_offset); - y = fabs (y - top_offset); - y = y / map_range; - y = y * map_height; - return y; -} - -GPtrArray * -tz_get_locations (TzDB *db) -{ - return db->locations; -} - - -gchar * -tz_location_get_country (TzLocation *loc) -{ - return loc->country; -} - - -gchar * -tz_location_get_zone (TzLocation *loc) -{ - return loc->zone; -} - - -gchar * -tz_location_get_comment (TzLocation *loc) -{ - return loc->comment; -} - - -void -tz_location_get_position (TzLocation *loc, double *longitude, double *latitude) -{ - *longitude = loc->longitude; - *latitude = loc->latitude; -} - -glong -tz_location_get_utc_offset (TzLocation *loc) -{ - TzInfo *tz_info; - glong offset; - - tz_info = tz_info_from_location (loc); - offset = tz_info->utc_offset; - tz_info_free (tz_info); - return offset; -} - -gint -tz_location_set_locally (TzLocation *loc) -{ - time_t curtime; - struct tm *curzone; - gboolean is_dst = FALSE; - gint correction = 0; - - g_return_val_if_fail (loc != NULL, 0); - g_return_val_if_fail (loc->zone != NULL, 0); - - curtime = time (NULL); - curzone = localtime (&curtime); - is_dst = curzone->tm_isdst; - - setenv ("TZ", loc->zone, 1); -#if 0 - curtime = time (NULL); - curzone = localtime (&curtime); - - if (!is_dst && curzone->tm_isdst) { - correction = (60 * 60); - } - else if (is_dst && !curzone->tm_isdst) { - correction = 0; - } -#endif - - return correction; -} - -TzInfo * -tz_info_from_location (TzLocation *loc) -{ - TzInfo *tzinfo; - time_t curtime; - struct tm *curzone; - - g_return_val_if_fail (loc != NULL, NULL); - g_return_val_if_fail (loc->zone != NULL, NULL); - - setenv ("TZ", loc->zone, 1); - -#if 0 - tzset (); -#endif - tzinfo = g_new0 (TzInfo, 1); - - curtime = time (NULL); - curzone = localtime (&curtime); - -#ifndef __sun - /* Currently this solution doesnt seem to work - I get that */ - /* America/Phoenix uses daylight savings, which is wrong */ - tzinfo->tzname_normal = g_strdup (curzone->tm_zone); - if (curzone->tm_isdst) - tzinfo->tzname_daylight = - g_strdup (&curzone->tm_zone[curzone->tm_isdst]); - else - tzinfo->tzname_daylight = NULL; - - tzinfo->utc_offset = curzone->tm_gmtoff; -#else - tzinfo->tzname_normal = NULL; - tzinfo->tzname_daylight = NULL; - tzinfo->utc_offset = 0; -#endif - - tzinfo->daylight = curzone->tm_isdst; - - return tzinfo; -} - - -void -tz_info_free (TzInfo *tzinfo) -{ - g_return_if_fail (tzinfo != NULL); - - if (tzinfo->tzname_normal) g_free (tzinfo->tzname_normal); - if (tzinfo->tzname_daylight) g_free (tzinfo->tzname_daylight); - g_free (tzinfo); -} - -/* ----------------- * - * Private functions * - * ----------------- */ - -static gchar * -tz_data_file_get (void) -{ - gchar *file; - - file = g_strdup (TZ_DATA_FILE); - - return file; -} - -static float -convert_pos (gchar *pos, int digits) -{ - gchar whole[10]; - gchar *fraction; - gint i; - float t1, t2; - - if (!pos || strlen(pos) < 4 || digits > 9) return 0.0; - - for (i = 0; i < digits + 1; i++) whole[i] = pos[i]; - whole[i] = '\0'; - fraction = pos + digits + 1; - - t1 = g_strtod (whole, NULL); - t2 = g_strtod (fraction, NULL); - - if (t1 >= 0.0) return t1 + t2/pow (10.0, strlen(fraction)); - else return t1 - t2/pow (10.0, strlen(fraction)); -} - - -#if 0 - -/* Currently not working */ -static void -free_tzdata (TzLocation *tz) -{ - - if (tz->country) - g_free(tz->country); - if (tz->zone) - g_free(tz->zone); - if (tz->comment) - g_free(tz->comment); - - g_free(tz); -} -#endif - - -static int -compare_country_names (const void *a, const void *b) -{ - const TzLocation *tza = * (TzLocation **) a; - const TzLocation *tzb = * (TzLocation **) b; - - return strcmp (tza->zone, tzb->zone); -} - - -static void -sort_locations_by_country (GPtrArray *locations) -{ - qsort (locations->pdata, locations->len, sizeof (gpointer), - compare_country_names); -} diff --git a/libmap/tz.h b/libmap/tz.h deleted file mode 100644 index 91281a5..0000000 --- a/libmap/tz.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Generic timezone utilities. - * - * Copyright (C) 2000-2001 Ximian, Inc. - * - * Authors: Hans Petter Jansson <hpj@ximian.com> - * - * Largely based on Michael Fulbright's work on Anaconda. - * - * This program 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 2 of the License, or - * (at your option) any later version. - * - * This program 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 this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - - -#ifndef _E_TZ_H -#define _E_TZ_H - -#include <glib.h> - -#ifndef __sun -# define TZ_DATA_FILE "/usr/share/zoneinfo/zone.tab" -#else -# define TZ_DATA_FILE "/usr/share/lib/zoneinfo/tab/zone_sun.tab" -#endif - -typedef struct _TzDB TzDB; -typedef struct _TzLocation TzLocation; -typedef struct _TzInfo TzInfo; - - -struct _TzDB -{ - GPtrArray *locations; -}; - -struct _TzLocation -{ - gchar *country; - gdouble latitude; - gdouble longitude; - gchar *zone; - gchar *comment; - - gdouble dist; /* distance to clicked point for comparison */ -}; - -/* see the glibc info page information on time zone information */ -/* tzname_normal is the default name for the timezone */ -/* tzname_daylight is the name of the zone when in daylight savings */ -/* utc_offset is offset in seconds from utc */ -/* daylight if non-zero then location obeys daylight savings */ - -struct _TzInfo -{ - gchar *tzname_normal; - gchar *tzname_daylight; - glong utc_offset; - gint daylight; -}; - - -TzDB *tz_load_db (void); -void tz_db_free (TzDB *db); -GPtrArray *tz_get_locations (TzDB *db); -void tz_location_get_position (TzLocation *loc, - double *longitude, double *latitude); -char *tz_location_get_country (TzLocation *loc); -gchar *tz_location_get_zone (TzLocation *loc); -gchar *tz_location_get_comment (TzLocation *loc); -glong tz_location_get_utc_offset (TzLocation *loc); -gint tz_location_set_locally (TzLocation *loc); -TzInfo *tz_info_from_location (TzLocation *loc); -void tz_info_free (TzInfo *tz_info); - -#endif diff --git a/src/Makefile.am b/src/Makefile.am index 254022e..328f279 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,32 +46,28 @@ libindicator_datetime_la_SOURCES =\ datetime-prefs.c \ datetime-prefs-locations.c \ datetime-prefs-locations.h \ - timezone-completion.c \ - timezone-completion.h \ utils.c \ utils.h \ settings-shared.h libindicator_datetime_la_CFLAGS = \ -Wall \ -Werror \ - -I$(top_srcdir)/libmap \ $(PREF_CFLAGS) \ -DTIMEZONE_FILE="\"/etc/timezone\"" \ -DPKGDATADIR="\"$(pkgdatadir)\"" libindicator_datetime_la_LIBADD = \ - $(top_builddir)/libmap/libmap.la \ $(PREF_LIBS) libindicator_datetime_la_LDFLAGS = -module -avoid-version gen-%.xml.c: %.xml @echo "Building $@ from $<" - @echo "const char * _$(subst -,_,$(subst .,_,$(basename $<))) = " > $@ + @echo "const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<)))) = " > $@ @sed -e "s:\":\\\\\":g" -e s:^:\": -e s:\$$:\\\\n\": $< >> $@ @echo ";" >> $@ gen-%.xml.h: %.xml @echo "Building $@ from $<" - @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@ + @echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $(notdir $<))));" > $@ BUILT_SOURCES = \ gen-datetime-service.xml.c \ diff --git a/src/datetime-prefs-locations.c b/src/datetime-prefs-locations.c index d865efe..b734a69 100644 --- a/src/datetime-prefs-locations.c +++ b/src/datetime-prefs-locations.c @@ -27,11 +27,11 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <stdlib.h> #include <glib/gi18n-lib.h> #include <gtk/gtk.h> +#include <timezonemap/timezone-completion.h> #include "datetime-prefs-locations.h" #include "settings-shared.h" #include "utils.h" -#include "timezone-completion.h" #define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui" @@ -182,8 +182,8 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, const gchar * zone, * name; gtk_tree_model_get (model, iter, - TIMEZONE_COMPLETION_ZONE, &zone, - TIMEZONE_COMPLETION_NAME, &name, + CC_TIMEZONE_COMPLETION_ZONE, &zone, + CC_TIMEZONE_COMPLETION_NAME, &name, -1); if (zone == NULL || zone[0] == 0) { @@ -191,8 +191,8 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, gdouble lon = 0.0, lat = 0.0; gtk_tree_model_get (model, iter, - TIMEZONE_COMPLETION_LONGITUDE, &strlon, - TIMEZONE_COMPLETION_LATITUDE, &strlat, + CC_TIMEZONE_COMPLETION_LONGITUDE, &strlon, + CC_TIMEZONE_COMPLETION_LATITUDE, &strlat, -1); if (strlon != NULL && strlon[0] != 0) { @@ -245,11 +245,11 @@ query_tooltip (GtkTreeView * tree, gint x, gint y, gboolean keyboard_mode, static void handle_edit_started (GtkCellRendererText * renderer, GtkCellEditable * editable, - gchar * path, TimezoneCompletion * completion) + gchar * path, CcTimezoneCompletion * completion) { if (GTK_IS_ENTRY (editable)) { GtkEntry *entry = GTK_ENTRY (editable); - timezone_completion_watch_entry (completion, entry); + cc_timezone_completion_watch_entry (completion, entry); GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (completion), "store")); GtkTreeIter * store_iter = g_new(GtkTreeIter, 1); @@ -263,7 +263,7 @@ static gboolean update_times (GtkWidget * dlg) { /* For each entry, check zone in column 2 and set column 1 to it's time */ - TimezoneCompletion * completion = TIMEZONE_COMPLETION (g_object_get_data (G_OBJECT (dlg), "completion")); + CcTimezoneCompletion * completion = CC_TIMEZONE_COMPLETION (g_object_get_data (G_OBJECT (dlg), "completion")); GtkListStore * store = GTK_LIST_STORE (g_object_get_data (G_OBJECT (completion), "store")); GObject * cell = G_OBJECT (g_object_get_data (G_OBJECT (completion), "name-cell")); @@ -439,7 +439,7 @@ datetime_setup_locations_dialog (CcTimezoneMap * map) GObject * store = gtk_builder_get_object (builder, "locationsStore"); /* Configure tree */ - TimezoneCompletion * completion = timezone_completion_new (); + CcTimezoneCompletion * completion = cc_timezone_completion_new (); g_object_set_data (G_OBJECT (completion), "tzmap", map); g_object_set_data (G_OBJECT (completion), "store", store); g_signal_connect (completion, "match-selected", G_CALLBACK (timezone_selected), dlg); diff --git a/src/datetime-prefs-locations.h b/src/datetime-prefs-locations.h index e312894..45d3b23 100644 --- a/src/datetime-prefs-locations.h +++ b/src/datetime-prefs-locations.h @@ -24,7 +24,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define __DATETIME_PREFS_LOCATIONS_H__ #include <gtk/gtk.h> -#include "cc-timezone-map.h" +#include <timezonemap/cc-timezone-map.h> G_BEGIN_DECLS diff --git a/src/datetime-prefs.c b/src/datetime-prefs.c index 1b7ddd2..9fdfbed 100644 --- a/src/datetime-prefs.c +++ b/src/datetime-prefs.c @@ -34,13 +34,13 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <gtk/gtk.h> #include <polkit/polkit.h> #include <libgnome-control-center/cc-panel.h> +#include <timezonemap/cc-timezone-map.h> +#include <timezonemap/timezone-completion.h> #include "dbus-shared.h" #include "settings-shared.h" #include "utils.h" #include "datetime-prefs-locations.h" -#include "timezone-completion.h" -#include "cc-timezone-map.h" #define DATETIME_DIALOG_UI_FILE PKGDATADIR "/datetime-dialog.ui" @@ -69,7 +69,7 @@ struct _IndicatorDatetimePanelPrivate gboolean user_edited_time; gboolean changing_time; GtkWidget * loc_dlg; - TimezoneCompletion * completion; + CcTimezoneCompletion * completion; }; struct _IndicatorDatetimePanelClass @@ -243,15 +243,20 @@ sync_entry (IndicatorDatetimePanel * self, const gchar * location) } static void -tz_changed (CcTimezoneMap * map, TzLocation * location, IndicatorDatetimePanel * self) +tz_changed (CcTimezoneMap * map, CcTimezoneLocation * location, IndicatorDatetimePanel * self) { if (location == NULL) return; - g_dbus_proxy_call (self->priv->proxy, "SetTimezone", g_variant_new ("(s)", location->zone), + gchar * zone; + g_object_get (location, "zone", &zone, NULL); + + g_dbus_proxy_call (self->priv->proxy, "SetTimezone", g_variant_new ("(s)", zone), G_DBUS_CALL_FLAGS_NONE, -1, NULL, dbus_set_answered, "timezone"); - sync_entry (self, location->zone); + sync_entry (self, zone); + + g_free (zone); } static void @@ -585,8 +590,8 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, const gchar * name, * zone; gtk_tree_model_get (model, iter, - TIMEZONE_COMPLETION_NAME, &name, - TIMEZONE_COMPLETION_ZONE, &zone, + CC_TIMEZONE_COMPLETION_NAME, &name, + CC_TIMEZONE_COMPLETION_ZONE, &zone, -1); if (zone == NULL || zone[0] == 0) { @@ -594,8 +599,8 @@ timezone_selected (GtkEntryCompletion * widget, GtkTreeModel * model, gdouble lon = 0.0, lat = 0.0; gtk_tree_model_get (model, iter, - TIMEZONE_COMPLETION_LONGITUDE, &strlon, - TIMEZONE_COMPLETION_LATITUDE, &strlat, + CC_TIMEZONE_COMPLETION_LONGITUDE, &strlon, + CC_TIMEZONE_COMPLETION_LATITUDE, &strlat, -1); if (strlon != NULL && strlon[0] != 0) { @@ -626,13 +631,17 @@ entry_focus_out (GtkEntry * entry, GdkEventFocus * event, IndicatorDatetimePanel // If the name left in the entry doesn't match the current timezone name, // show an error icon. It's always an error for the user to manually type in // a timezone. - TzLocation * location = cc_timezone_map_get_location (self->priv->tzmap); + CcTimezoneLocation * location = cc_timezone_map_get_location (self->priv->tzmap); if (location == NULL) return FALSE; - gchar * name = get_current_zone_name (location->zone); + gchar * zone; + g_object_get (location, "zone", &zone, NULL); + + gchar * name = get_current_zone_name (zone); gboolean correct = (g_strcmp0 (gtk_entry_get_text (entry), name) == 0); g_free (name); + g_free (zone); gtk_entry_set_icon_from_stock (entry, GTK_ENTRY_ICON_SECONDARY, correct ? NULL : GTK_STOCK_DIALOG_ERROR); @@ -685,8 +694,8 @@ indicator_datetime_panel_init (IndicatorDatetimePanel * self) cc_timezone_map_set_watermark (self->priv->tzmap, "Geonames.org"); /* And completion entry */ - self->priv->completion = timezone_completion_new (); - timezone_completion_watch_entry (self->priv->completion, GTK_ENTRY (WIG ("timezoneEntry"))); + self->priv->completion = cc_timezone_completion_new (); + cc_timezone_completion_watch_entry (self->priv->completion, GTK_ENTRY (WIG ("timezoneEntry"))); g_signal_connect (self->priv->completion, "match-selected", G_CALLBACK (timezone_selected), self); g_signal_connect (WIG ("timezoneEntry"), "focus-out-event", G_CALLBACK (entry_focus_out), self); @@ -789,7 +798,7 @@ indicator_datetime_panel_dispose (GObject * object) } if (self->priv->completion) { - timezone_completion_watch_entry (self->priv->completion, NULL); + cc_timezone_completion_watch_entry (self->priv->completion, NULL); g_object_unref (self->priv->completion); self->priv->completion = NULL; } diff --git a/src/timezone-completion.c b/src/timezone-completion.c deleted file mode 100644 index a4d4fb5..0000000 --- a/src/timezone-completion.c +++ /dev/null @@ -1,696 +0,0 @@ -/* -*- Mode: C; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- - -Copyright 2011 Canonical Ltd. - -Authors: - Michael Terry <michael.terry@canonical.com> - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, 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 this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <json-glib/json-glib.h> -#include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> -#include <glib/gi18n.h> -#include "timezone-completion.h" -#include "tz.h" - -enum { - LAST_SIGNAL -}; - -/* static guint signals[LAST_SIGNAL] = { }; */ - -struct _TimezoneCompletionPrivate -{ - GtkTreeModel * initial_model; - GtkEntry * entry; - guint queued_request; - guint changed_id; - guint keypress_id; - GCancellable * cancel; - gchar * request_text; - GHashTable * request_table; -}; - -#define GEONAME_URL "http://geoname-lookup.ubuntu.com/?query=%s&release=%s&lang=%s" - -/* Prototypes */ -static void timezone_completion_class_init (TimezoneCompletionClass *klass); -static void timezone_completion_init (TimezoneCompletion *self); -static void timezone_completion_dispose (GObject *object); -static void timezone_completion_finalize (GObject *object); - -G_DEFINE_TYPE (TimezoneCompletion, timezone_completion, GTK_TYPE_ENTRY_COMPLETION); - -static gboolean -match_func (GtkEntryCompletion *completion, const gchar *key, - GtkTreeIter *iter, gpointer user_data) -{ - // geonames does the work for us - return TRUE; -} - -static void -save_and_use_model (TimezoneCompletion * completion, GtkTreeModel * model) -{ - TimezoneCompletionPrivate * priv = completion->priv; - - g_hash_table_insert (priv->request_table, g_strdup (priv->request_text), g_object_ref_sink (model)); - - if (model == priv->initial_model) - gtk_entry_completion_set_match_func (GTK_ENTRY_COMPLETION (completion), NULL, NULL, NULL); - else - gtk_entry_completion_set_match_func (GTK_ENTRY_COMPLETION (completion), match_func, NULL, NULL); - - gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), model); - - if (priv->entry != NULL) { - gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); - - /* By this time, the changed signal has come and gone. We didn't give a - model to use, so no popup appeared for user. Poke the entry again to show - popup in 300ms. */ - g_signal_emit_by_name (priv->entry, "changed"); - } -} - -static gint -sort_zone (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, - gpointer user_data) -{ - /* Anything that has text as a prefix goes first, in mostly sorted order. - Then everything else goes after, in mostly sorted order. */ - const gchar *casefolded_text = (const gchar *)user_data; - - const gchar *namea = NULL, *nameb = NULL; - gtk_tree_model_get (model, a, TIMEZONE_COMPLETION_NAME, &namea, -1); - gtk_tree_model_get (model, b, TIMEZONE_COMPLETION_NAME, &nameb, -1); - - gchar *casefolded_namea = NULL, *casefolded_nameb = NULL; - casefolded_namea = g_utf8_casefold (namea, -1); - casefolded_nameb = g_utf8_casefold (nameb, -1); - - gboolean amatches = FALSE, bmatches = FALSE; - amatches = strncmp (casefolded_text, casefolded_namea, strlen(casefolded_text)) == 0; - bmatches = strncmp (casefolded_text, casefolded_nameb, strlen(casefolded_text)) == 0; - - gint rv; - if (amatches && !bmatches) - rv = -1; - else if (bmatches && !amatches) - rv = 1; - else - rv = g_utf8_collate (casefolded_namea, casefolded_nameb); - - g_free (casefolded_namea); - g_free (casefolded_nameb); - return rv; -} - -static void -json_parse_ready (GObject *object, GAsyncResult *res, gpointer user_data) -{ - TimezoneCompletion * completion = TIMEZONE_COMPLETION (user_data); - TimezoneCompletionPrivate * priv = completion->priv; - GError * error = NULL; - const gchar * prev_name = NULL; - const gchar * prev_admin1 = NULL; - const gchar * prev_country = NULL; - - json_parser_load_from_stream_finish (JSON_PARSER (object), res, &error); - - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel) { - g_cancellable_reset (priv->cancel); - } - - if (error != NULL) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - save_and_use_model (completion, priv->initial_model); - g_warning ("Could not parse geoname JSON data: %s", error->message); - g_error_free (error); - return; - } - - GtkListStore * store = gtk_list_store_new (TIMEZONE_COMPLETION_LAST, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); - - JsonReader * reader = json_reader_new (json_parser_get_root (JSON_PARSER (object))); - - if (!json_reader_is_array (reader)) { - g_warning ("Could not parse geoname JSON data"); - save_and_use_model (completion, priv->initial_model); - g_object_unref (G_OBJECT (reader)); - return; - } - - gint i, count = json_reader_count_elements (reader); - for (i = 0; i < count; ++i) { - if (!json_reader_read_element (reader, i)) - continue; - - if (json_reader_is_object (reader)) { - const gchar * name = NULL; - const gchar * admin1 = NULL; - const gchar * country = NULL; - const gchar * longitude = NULL; - const gchar * latitude = NULL; - gboolean skip = FALSE; - if (json_reader_read_member (reader, "name")) { - name = json_reader_get_string_value (reader); - json_reader_end_member (reader); - } - if (json_reader_read_member (reader, "admin1")) { - admin1 = json_reader_get_string_value (reader); - json_reader_end_member (reader); - } - if (json_reader_read_member (reader, "country")) { - country = json_reader_get_string_value (reader); - json_reader_end_member (reader); - } - if (json_reader_read_member (reader, "longitude")) { - longitude = json_reader_get_string_value (reader); - json_reader_end_member (reader); - } - if (json_reader_read_member (reader, "latitude")) { - latitude = json_reader_get_string_value (reader); - json_reader_end_member (reader); - } - - if (g_strcmp0(name, prev_name) == 0 && - g_strcmp0(admin1, prev_admin1) == 0 && - g_strcmp0(country, prev_country) == 0) { - // Sometimes the data will have duplicate entries that only differ - // in longitude and latitude. e.g. "rio de janeiro", "wellington" - skip = TRUE; - } - - if (!skip) { - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - TIMEZONE_COMPLETION_ZONE, NULL, - TIMEZONE_COMPLETION_NAME, name, - TIMEZONE_COMPLETION_ADMIN1, admin1, - TIMEZONE_COMPLETION_COUNTRY, country, - TIMEZONE_COMPLETION_LONGITUDE, longitude, - TIMEZONE_COMPLETION_LATITUDE, latitude, - -1); - gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (store), - TIMEZONE_COMPLETION_NAME, sort_zone, - g_utf8_casefold(priv->request_text, -1), - g_free); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - TIMEZONE_COMPLETION_NAME, - GTK_SORT_ASCENDING); - } - - prev_name = name; - prev_admin1 = admin1; - prev_country = country; - } - - json_reader_end_element (reader); - } - - if (strlen (priv->request_text) < 4) { - gchar * lower_text = g_ascii_strdown (priv->request_text, -1); - if (g_strcmp0 (lower_text, "ut") == 0 || - g_strcmp0 (lower_text, "utc") == 0) { - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - TIMEZONE_COMPLETION_ZONE, "UTC", - TIMEZONE_COMPLETION_NAME, "UTC", - -1); - } - g_free (lower_text); - } - - save_and_use_model (completion, GTK_TREE_MODEL (store)); - g_object_unref (G_OBJECT (reader)); -} - -static void -geonames_data_ready (GObject *object, GAsyncResult *res, gpointer user_data) -{ - TimezoneCompletion * completion = TIMEZONE_COMPLETION (user_data); - TimezoneCompletionPrivate * priv = completion->priv; - GError * error = NULL; - GFileInputStream * stream; - - stream = g_file_read_finish (G_FILE (object), res, &error); - - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED) && priv->cancel) { - g_cancellable_reset (priv->cancel); - } - - if (error != NULL) { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - save_and_use_model (completion, priv->initial_model); - g_warning ("Could not connect to geoname lookup server: %s", error->message); - g_error_free (error); - return; - } - - JsonParser * parser = json_parser_new (); - json_parser_load_from_stream_async (parser, G_INPUT_STREAM (stream), priv->cancel, - json_parse_ready, user_data); -} - -/* Returns message locale, with possible country info too like en_US */ -static gchar * -get_locale (void) -{ - /* Check LANGUAGE, LC_ALL, LC_MESSAGES, and LANG, treat as colon-separated */ - const gchar *env_names[] = {"LANGUAGE", "LC_ALL", "LC_MESSAGES", "LANG", NULL}; - const gchar *env = NULL; - gint i; - - for (i = 0; env_names[i]; i++) { - env = g_getenv (env_names[i]); - if (env != NULL && env[0] != 0) - break; - } - - if (env == NULL) - return NULL; - - /* Now, we split on colons as expected, but also on . and @ to filter out - extra pieces of locale we don't care about as we only use first chunk. */ - gchar **split = g_strsplit_set (env, ":.@", 2); - if (split == NULL) - return NULL; - - if (split[0] == NULL) { - g_strfreev (split); - return NULL; - } - - gchar *locale = g_strdup (split[0]); - g_strfreev (split); - return locale; -} - -static const gchar * -get_version (void) -{ - static gchar *version = NULL; - - if (version == NULL) { - gchar *stdout = NULL; - g_spawn_command_line_sync ("lsb_release -rs", &stdout, NULL, NULL, NULL); - - if (stdout != NULL) - version = g_strstrip (stdout); - else - version = g_strdup(""); - } - - return version; -} - -static gboolean -request_zones (TimezoneCompletion * completion) -{ - TimezoneCompletionPrivate * priv = completion->priv; - - priv->queued_request = 0; - - if (priv->entry == NULL) { - return FALSE; - } - - /* Cancel any ongoing request */ - if (priv->cancel) { - g_cancellable_cancel (priv->cancel); - g_cancellable_reset (priv->cancel); - } - g_free (priv->request_text); - - const gchar * text = gtk_entry_get_text (priv->entry); - priv->request_text = g_strdup (text); - - gchar * escaped = g_uri_escape_string (text, NULL, FALSE); - const gchar * version = get_version (); - gchar * locale = get_locale (); - gchar * url = g_strdup_printf (GEONAME_URL, escaped, version, locale); - g_free (locale); - g_free (escaped); - - GFile * file = g_file_new_for_uri (url); - g_free (url); - - g_file_read_async (file, G_PRIORITY_DEFAULT, priv->cancel, - geonames_data_ready, completion); - - return FALSE; -} - -static void -entry_changed (GtkEntry * entry, TimezoneCompletion * completion) -{ - TimezoneCompletionPrivate * priv = completion->priv; - - if (priv->queued_request) { - g_source_remove (priv->queued_request); - priv->queued_request = 0; - } - - /* See if we've already got this one */ - const gchar * text = gtk_entry_get_text (priv->entry); - gpointer data; - if (g_hash_table_lookup_extended (priv->request_table, text, NULL, &data)) { - gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), GTK_TREE_MODEL (data)); - } - else { - priv->queued_request = g_timeout_add (300, (GSourceFunc)request_zones, completion); - gtk_entry_completion_set_model (GTK_ENTRY_COMPLETION (completion), NULL); - } - gtk_entry_completion_complete (GTK_ENTRY_COMPLETION (completion)); -} - -static GtkWidget * -get_descendent (GtkWidget * parent, GType type) -{ - if (g_type_is_a (G_OBJECT_TYPE (parent), type)) - return parent; - - if (GTK_IS_CONTAINER (parent)) { - GList * children = gtk_container_get_children (GTK_CONTAINER (parent)); - GList * iter; - for (iter = children; iter; iter = iter->next) { - GtkWidget * found = get_descendent (GTK_WIDGET (iter->data), type); - if (found) { - g_list_free (children); - return found; - } - } - g_list_free (children); - } - - return NULL; -} - -/** - * The popup window and its GtkTreeView are private to our parent completion - * object. We can't get access to discover if there is a highlighted item or - * even if the window is showing right now. So this is a super hack to find - * it by looking through our toplevel's window group and finding a window with - * a GtkTreeView that points at our model. There should be only one ever, so - * we'll use the first one we find. - */ -static GtkTreeView * -find_popup_treeview (GtkWidget * widget, GtkTreeModel * model) -{ - GtkWidget * toplevel = gtk_widget_get_toplevel (widget); - if (!GTK_IS_WINDOW (toplevel)) - return NULL; - - GtkWindowGroup * group = gtk_window_get_group (GTK_WINDOW (toplevel)); - GList * windows = gtk_window_group_list_windows (group); - GList * iter; - for (iter = windows; iter; iter = iter->next) { - if (iter->data == toplevel) - continue; // Skip our own window, we don't have it - GtkWidget * view = get_descendent (GTK_WIDGET (iter->data), GTK_TYPE_TREE_VIEW); - if (view != NULL) { - GtkTreeModel * tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (view)); - if (GTK_IS_TREE_MODEL_FILTER (tree_model)) - tree_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (tree_model)); - if (tree_model == model) { - g_list_free (windows); - return GTK_TREE_VIEW (view); - } - } - } - g_list_free (windows); - - return NULL; -} - -static gboolean -entry_keypress (GtkEntry * entry, GdkEventKey *event, TimezoneCompletion * completion) -{ - if (event->keyval == GDK_KEY_ISO_Enter || - event->keyval == GDK_KEY_KP_Enter || - event->keyval == GDK_KEY_Return) { - /* Make sure that user has a selection to choose, otherwise ignore */ - GtkTreeModel * model = gtk_entry_completion_get_model (GTK_ENTRY_COMPLETION (completion)); - GtkTreeView * view = find_popup_treeview (GTK_WIDGET (entry), model); - if (view == NULL) { - // Just beep if popup hasn't appeared yet. - gtk_widget_error_bell (GTK_WIDGET (entry)); - return TRUE; - } - - GtkTreeSelection * sel = gtk_tree_view_get_selection (view); - GtkTreeModel * sel_model = NULL; - if (!gtk_tree_selection_get_selected (sel, &sel_model, NULL)) { - // No selection, we should help them out and select first item in list - GtkTreeIter iter; - if (gtk_tree_model_get_iter_first (sel_model, &iter)) - gtk_tree_selection_select_iter (sel, &iter); - // And fall through to normal handler code - } - } - - return FALSE; -} - -void -timezone_completion_watch_entry (TimezoneCompletion * completion, GtkEntry * entry) -{ - TimezoneCompletionPrivate * priv = completion->priv; - - if (priv->queued_request) { - g_source_remove (priv->queued_request); - priv->queued_request = 0; - } - if (priv->entry) { - g_signal_handler_disconnect (priv->entry, priv->changed_id); - priv->changed_id = 0; - g_signal_handler_disconnect (priv->entry, priv->keypress_id); - priv->keypress_id = 0; - g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); - gtk_entry_set_completion (priv->entry, NULL); - } - - priv->entry = entry; - - if (entry) { - guint id = g_signal_connect (entry, "changed", G_CALLBACK (entry_changed), completion); - priv->changed_id = id; - - id = g_signal_connect (entry, "key-press-event", G_CALLBACK (entry_keypress), completion); - priv->keypress_id = id; - - g_object_add_weak_pointer (G_OBJECT (entry), (gpointer *)&priv->entry); - - gtk_entry_set_completion (entry, GTK_ENTRY_COMPLETION (completion)); - } -} - -static GtkListStore * -get_initial_model (void) -{ - TzDB * db = tz_load_db (); - GPtrArray * locations = tz_get_locations (db); - - GtkListStore * store = gtk_list_store_new (TIMEZONE_COMPLETION_LAST, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); - - gint i; - for (i = 0; i < locations->len; ++i) { - TzLocation * loc = g_ptr_array_index (locations, i); - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - - /* FIXME: need something better than below for non-English locales */ - const gchar * last_bit = ((const gchar *)strrchr (loc->zone, '/')) + 1; - if (last_bit == NULL) - last_bit = loc->zone; - gchar * name = g_strdup (last_bit); - gchar * underscore; - while ((underscore = strchr (name, '_'))) { - *underscore = ' '; - } - - gtk_list_store_set (store, &iter, - TIMEZONE_COMPLETION_ZONE, loc->zone, - TIMEZONE_COMPLETION_NAME, name, - TIMEZONE_COMPLETION_COUNTRY, loc->country, - -1); - - g_free (name); - } - - GtkTreeIter iter; - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - TIMEZONE_COMPLETION_ZONE, "UTC", - TIMEZONE_COMPLETION_NAME, "UTC", - -1); - - tz_db_free (db); - return store; -} - -static void -data_func (GtkCellLayout *cell_layout, GtkCellRenderer *cell, - GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer user_data) -{ - const gchar * name, * admin1, * country; - - gtk_tree_model_get (GTK_TREE_MODEL (tree_model), iter, - TIMEZONE_COMPLETION_NAME, &name, - TIMEZONE_COMPLETION_ADMIN1, &admin1, - TIMEZONE_COMPLETION_COUNTRY, &country, - -1); - - gchar * user_name; - if (country == NULL || country[0] == 0) { - user_name = g_strdup (name); - } else if (admin1 == NULL || admin1[0] == 0) { - user_name = g_strdup_printf ("%s <small>(%s)</small>", name, country); - } else { - user_name = g_strdup_printf ("%s <small>(%s, %s)</small>", name, admin1, country); - } - - g_object_set (G_OBJECT (cell), "markup", user_name, NULL); -} - -static void -timezone_completion_class_init (TimezoneCompletionClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - g_type_class_add_private (klass, sizeof (TimezoneCompletionPrivate)); - - object_class->dispose = timezone_completion_dispose; - object_class->finalize = timezone_completion_finalize; - - return; -} - -static void -timezone_completion_init (TimezoneCompletion * self) -{ - TimezoneCompletionPrivate *priv; - - self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, - TIMEZONE_COMPLETION_TYPE, - TimezoneCompletionPrivate); - priv = self->priv; - - priv->initial_model = GTK_TREE_MODEL (get_initial_model ()); - - g_object_set (G_OBJECT (self), - "text-column", TIMEZONE_COMPLETION_NAME, - "popup-set-width", FALSE, - NULL); - - priv->cancel = g_cancellable_new (); - - priv->request_table = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); - - GtkCellRenderer * cell = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), cell, TRUE); - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (self), cell, data_func, NULL, NULL); - - return; -} - -static void -timezone_completion_dispose (GObject * object) -{ - G_OBJECT_CLASS (timezone_completion_parent_class)->dispose (object); - - TimezoneCompletion * completion = TIMEZONE_COMPLETION (object); - TimezoneCompletionPrivate * priv = completion->priv; - - if (priv->changed_id) { - if (priv->entry) - g_signal_handler_disconnect (priv->entry, priv->changed_id); - priv->changed_id = 0; - } - - if (priv->keypress_id) { - if (priv->entry) - g_signal_handler_disconnect (priv->entry, priv->keypress_id); - priv->keypress_id = 0; - } - - if (priv->entry != NULL) { - gtk_entry_set_completion (priv->entry, NULL); - g_object_remove_weak_pointer (G_OBJECT (priv->entry), (gpointer *)&priv->entry); - priv->entry = NULL; - } - - if (priv->initial_model != NULL) { - g_object_unref (G_OBJECT (priv->initial_model)); - priv->initial_model = NULL; - } - - if (priv->queued_request) { - g_source_remove (priv->queued_request); - priv->queued_request = 0; - } - - if (priv->cancel != NULL) { - g_cancellable_cancel (priv->cancel); - g_object_unref (priv->cancel); - priv->cancel = NULL; - } - - if (priv->request_text != NULL) { - g_free (priv->request_text); - priv->request_text = NULL; - } - - if (priv->request_table != NULL) { - g_hash_table_destroy (priv->request_table); - priv->request_table = NULL; - } - - return; -} - -static void -timezone_completion_finalize (GObject * object) -{ - G_OBJECT_CLASS (timezone_completion_parent_class)->finalize (object); - return; -} - -TimezoneCompletion * -timezone_completion_new () -{ - TimezoneCompletion * self = g_object_new (TIMEZONE_COMPLETION_TYPE, NULL); - return self; -} - diff --git a/src/timezone-completion.h b/src/timezone-completion.h deleted file mode 100644 index 1592d79..0000000 --- a/src/timezone-completion.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; coding: utf-8; indent-tabs-mode: nil; tab-width: 2 -*- - -Copyright 2011 Canonical Ltd. - -Authors: - Michael Terry <michael.terry@canonical.com> - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, 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 this program. If not, see <http://www.gnu.org/licenses/>. -*/ - -#ifndef __TIMEZONE_COMPLETION_H__ -#define __TIMEZONE_COMPLETION_H__ - -#include <glib.h> -#include <glib-object.h> -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define TIMEZONE_COMPLETION_TYPE (timezone_completion_get_type ()) -#define TIMEZONE_COMPLETION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TIMEZONE_COMPLETION_TYPE, TimezoneCompletion)) -#define TIMEZONE_COMPLETION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TIMEZONE_COMPLETION_TYPE, TimezoneCompletionClass)) -#define IS_TIMEZONE_COMPLETION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TIMEZONE_COMPLETION_TYPE)) -#define IS_TIMEZONE_COMPLETION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TIMEZONE_COMPLETION_TYPE)) -#define TIMEZONE_COMPLETION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TIMEZONE_COMPLETION_TYPE, TimezoneCompletionClass)) - -typedef struct _TimezoneCompletion TimezoneCompletion; -typedef struct _TimezoneCompletionPrivate TimezoneCompletionPrivate; -typedef struct _TimezoneCompletionClass TimezoneCompletionClass; - -struct _TimezoneCompletion { - GtkEntryCompletion parent; - - TimezoneCompletionPrivate *priv; -}; - -struct _TimezoneCompletionClass { - GtkEntryCompletionClass parent_class; -}; - -#define TIMEZONE_COMPLETION_ZONE 0 -#define TIMEZONE_COMPLETION_NAME 1 -#define TIMEZONE_COMPLETION_ADMIN1 2 -#define TIMEZONE_COMPLETION_COUNTRY 3 -#define TIMEZONE_COMPLETION_LONGITUDE 4 -#define TIMEZONE_COMPLETION_LATITUDE 5 -#define TIMEZONE_COMPLETION_LAST 6 - -GType timezone_completion_get_type (void) G_GNUC_CONST; -TimezoneCompletion * timezone_completion_new (); -void timezone_completion_watch_entry (TimezoneCompletion * completion, GtkEntry * entry); - -G_END_DECLS - -#endif /* __TIMEZONE_COMPLETION_H__ */ - |