/* * openmoko-dates -- OpenMoko Calendar Application * * Authored by Chris Lord * * Copyright (C) 2006-2007 OpenMoko Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser Public License as published by * the Free Software Foundation; version 2 of the license. * * 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 Lesser Public License for more details. * * Current Version: $Rev$ ($Date$) [$Author$] */ #include #include "dates-timezone-tile.h" G_DEFINE_TYPE (DatesTimezoneTile, dates_timezone_tile, TAKU_TYPE_ICON_TILE) #define TIMEZONE_TILE_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DATES_TYPE_TIMEZONE_TILE, \ DatesTimezoneTilePrivate)) typedef struct _DatesTimezoneTilePrivate DatesTimezoneTilePrivate; struct _DatesTimezoneTilePrivate { gchar *search_casefold; }; enum { PROP_TIME = 1, }; static void dates_timezone_tile_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 dates_timezone_tile_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { switch (property_id) { case PROP_TIME : dates_timezone_tile_set_timezone (DATES_TIMEZONE_TILE (object), JANA_ECAL_TIME (g_value_get_object (value))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); } } static void dates_timezone_tile_dispose (GObject *object) { if (G_OBJECT_CLASS (dates_timezone_tile_parent_class)->dispose) G_OBJECT_CLASS (dates_timezone_tile_parent_class)-> dispose (object); } static void dates_timezone_tile_finalize (GObject *object) { DatesTimezoneTilePrivate *priv = TIMEZONE_TILE_PRIVATE (object); g_free (priv->search_casefold); G_OBJECT_CLASS (dates_timezone_tile_parent_class)->finalize (object); } static gboolean dates_timezone_tile_matches_filter (TakuTile *tile, gpointer filter) { gboolean match; gchar *filter_casefold; DatesTimezoneTilePrivate *priv = TIMEZONE_TILE_PRIVATE (tile); if (!filter) return TRUE; filter_casefold = g_utf8_casefold (filter, -1); match = (strstr (priv->search_casefold, filter_casefold)) ? TRUE : FALSE; g_free (filter_casefold); return match; } static void dates_timezone_tile_class_init (DatesTimezoneTileClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); TakuTileClass *tile_class = TAKU_TILE_CLASS (klass); g_type_class_add_private (klass, sizeof (DatesTimezoneTilePrivate)); object_class->get_property = dates_timezone_tile_get_property; object_class->set_property = dates_timezone_tile_set_property; object_class->dispose = dates_timezone_tile_dispose; object_class->finalize = dates_timezone_tile_finalize; tile_class->matches_filter = dates_timezone_tile_matches_filter; g_object_class_install_property ( object_class, PROP_TIME, g_param_spec_object ( "time", "JanaEcalTime *", "A JanaTime to get the timezone details from.", JANA_ECAL_TYPE_TIME, G_PARAM_WRITABLE)); } static void dates_timezone_tile_init (DatesTimezoneTile *self) { } GtkWidget * dates_timezone_tile_new () { return GTK_WIDGET (g_object_new (DATES_TYPE_TIMEZONE_TILE, NULL)); } void dates_timezone_tile_set_timezone (DatesTimezoneTile *tile, JanaEcalTime *time) { gchar *string, *tzname; DatesTimezoneTilePrivate *priv = TIMEZONE_TILE_PRIVATE (tile); if (priv->search_casefold) { taku_icon_tile_set_primary (TAKU_ICON_TILE (tile), ""); taku_icon_tile_set_secondary (TAKU_ICON_TILE (tile), ""); g_free (priv->search_casefold); priv->search_casefold = NULL; } if (!time) return; string = g_strdelimit (g_strdup (jana_ecal_time_get_location (time)), "_", ' '); taku_icon_tile_set_primary (TAKU_ICON_TILE (tile), string); g_free (string); tzname = jana_time_get_tzname (JANA_TIME (time)); string = g_strdup_printf ("%s (UTC %+lg)", tzname, (((gdouble)jana_time_get_offset (JANA_TIME (time)))/60.0)/60.0); g_free (tzname); taku_icon_tile_set_secondary (TAKU_ICON_TILE (tile), string); g_free (string); /* Create case-folded search string */ string = g_strconcat ( taku_icon_tile_get_primary (TAKU_ICON_TILE (tile)), taku_icon_tile_get_secondary (TAKU_ICON_TILE (tile)), NULL); priv->search_casefold = g_utf8_casefold (string, -1); g_free (string); }