gboolean
cc_timezone_map_set_timezone (CcTimezoneMap *map,
                              const gchar   *timezone)
{
  GPtrArray *locations;
  guint i;
  char *real_tz;
  gboolean ret;

  real_tz = tz_info_get_clean_name (map->priv->tzdb, timezone);

  locations = tz_get_locations (map->priv->tzdb);
  ret = FALSE;

  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);
          ret = TRUE;
          break;
        }
    }

  if (ret)
    gtk_widget_queue_draw (GTK_WIDGET (map));

  g_free (real_tz);

  return ret;
}
Beispiel #2
0
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool tzn::got(const char* tzcode, TzLocation& locret, TzInfo& nforet, bool exact)
{
	DEBUGLOGB;
	int  fnd = 0;
	bool ret = false;

	DEBUGLOGP("requested entry tzcode is %s, exact is %s\n", tzcode, exact ? "on" : "off");

	GPtrArray* locs = tz_get_locations(tzdb);

	if( locs )
	{
		char*       tzn = tz_info_get_clean_name(tzdb, tzcode);
		const char* tzs = tzn ? tzn : (!exact ? tzcode : NULL);

		if( tzs )
		{
			DEBUGLOGP("requested entry tzcode (cleaned) is %s\n", tzs);

			TzInfo*     nfo;
			TzLocation* loc;
			bool        got;
			bool        cont_ok,  city_ok;
			const char* cont_db, *city_db;
			const char* cont_in = strchr (tzs, '/'); // end of continent string for search string
			const char* city_in = strrchr(tzs, '/'); // begin of city string for search string
			int         cont_il = cont_in ? cont_in-tzs     : 0;
			int         city_il = city_in ? strlen(city_in) : 0;

			DEBUGLOGP("cont_in is %s\n", cont_in);
			DEBUGLOGP("city_in is %s\n", city_in);

			if( !exact || (exact && g_quark_try_string(tzs)) ) // NOTE: according to tz.c comments, this will work
			{
				for( size_t i = 0; i < locs->len; i++ )
				{
					if( !(loc   = (TzLocation*)locs->pdata[i]) ) continue;
					if( !(nfo   =  tz_info_from_location(loc)) ) continue;

					if( !(got   =  stricmp(loc->zone, tzs) == 0) && !exact )
					{
						cont_db =  strchr (loc->zone, '/'); // end of continent string in db
						city_db =  strrchr(loc->zone, '/'); // begin of city string in db

						if( cont_db != city_db )
						{
							// just compare the 1st and last partitions, i.e., continent and city,
							// disregarding the 'middle' part, i.e., country or state

							DEBUGLOGS("tzcode (cleaned) not found and exact is off");
							DEBUGLOGS("comparing just the continent and city strings");
							DEBUGLOGP("cont_db is %s\n", cont_db);
							DEBUGLOGP("city_db is %s\n", city_db);

							cont_ok = cont_in && cont_db && cont_il == (cont_db-loc->zone) && strnicmp(tzs,     loc->zone, cont_il) == 0;
							city_ok = city_in && city_db && city_il == strlen(city_db)     && strnicmp(city_in, city_db,   city_il) == 0;
							got     = cont_ok && city_ok;

							DEBUGLOGP("cont_ok is %s, city_ok is %s\n", cont_ok ? "on" : "off", city_ok ? "on" : "off");
						}
					}

					if( got )
					{
//						DEBUGLOGP("%s/%s/%s\n", loc->country, loc->zone, loc->comment);
						DEBUGLOGP("%s\n", loc->zone);
						locret = *loc;
						nforet = *nfo;
						ret    = true;
						fnd++;
					}

					tz_info_free(nfo);

					if( fnd > 1 ) break;
//					if( ret ) break;
				}
			}
#ifdef DEBUGLOG
			else
				DEBUGLOGS("requested entry tzcode (cleaned) not found");
#endif
		}

		if( tzn )
			g_free(tzn);
	}

	DEBUGLOGE;
	return ret && fnd == 1;
}