static void
penge_calendar_pane_update_calendar_icon (PengeCalendarPane *pane,
                                          JanaTime          *time)
{
  PengeCalendarPanePrivate *priv = GET_PRIVATE (pane);
  GError *error = NULL;
  gchar *path = NULL;

  if (jana_time_get_day (time) != priv->day_of_month)
  {
    priv->day_of_month = jana_time_get_day (time);
    path = g_strdup_printf (CALENDAR_ICON, priv->day_of_month);
    clutter_texture_set_from_file (CLUTTER_TEXTURE (priv->calendar_tex),
                                   path,
                                   &error);

    g_free (path);

    if (error)
    {
      g_warning (G_STRLOC ": Error setting path on calendar texture: %s",
                 error->message);
      g_clear_error (&error);
    }
  }
}
static void
opened_cb (JanaStore *store, JanaGtkEventStore *event_store)
{
	JanaTime *range_start, *range_end;
	
	range_start = jana_ecal_utils_time_today ("UTC");
	range_end = jana_time_duplicate (range_start);

	jana_time_set_day (range_end, jana_time_get_day (range_end) + 5);
	jana_time_set_day (range_start, jana_time_get_day (range_start) - 5);

	store_view = jana_store_get_view (store);
	jana_store_view_set_range (store_view, range_start, range_end);
	jana_gtk_event_store_set_view (event_store, store_view);

	jana_store_view_start (store_view);
	
	g_object_unref (range_start);
	g_object_unref (range_end);
}
int
main (int argc, char **argv)
{
	JanaStore *store;
	JanaDuration *duration;
	GtkTreeModel *event_store;
	GtkWidget *window, *week_view, *scroll;
	
	gtk_init (&argc, &argv);
	
	store = jana_ecal_store_new (JANA_COMPONENT_EVENT);
	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	event_store = jana_gtk_event_store_new ();
	
	range_start = jana_ecal_utils_time_today ("UTC");
	jana_utils_time_set_start_of_week (range_start);
	jana_time_set_isdate (range_start, TRUE);
	range_end = jana_time_duplicate (range_start);
	jana_time_set_day (range_end, jana_time_get_day (range_end) + 7);
	
	duration = jana_duration_new (range_start, range_end);
	jana_time_set_isdate (duration->start, FALSE);
	jana_time_set_hours (duration->start, 6);
	jana_time_set_isdate (duration->end, FALSE);
	jana_time_set_hours (duration->end, 18);

	scroll = gtk_scrolled_window_new (NULL, NULL);
	week_view = jana_gtk_day_view_new (duration, 12);
	jana_duration_free (duration);
	
	/* Set 5 days and 8 hours visible */
	jana_gtk_day_view_set_visible_ratio (JANA_GTK_DAY_VIEW (week_view),
		5.0/7.0, 2.0/3.0);
	
	jana_utils_time_set_start_of_week (range_start);
	jana_utils_time_set_end_of_week (range_end);
	
	gtk_container_add (GTK_CONTAINER (window), scroll);
	gtk_container_add (GTK_CONTAINER (scroll), week_view);
	gtk_window_set_default_size (GTK_WINDOW (window), 512, 384);
	
	g_signal_connect (window, "delete-event",
		G_CALLBACK (gtk_main_quit), NULL);
	g_signal_connect (week_view, "realize",
		G_CALLBACK (realize_cb), NULL);
	
	gtk_widget_show_all (window);
	
	g_signal_connect (store, "opened",
		G_CALLBACK (opened_cb), event_store);

	jana_gtk_day_view_add_store (JANA_GTK_DAY_VIEW (week_view),
		JANA_GTK_EVENT_STORE (event_store));
	jana_store_open (store);
	
	gtk_main ();
	
	g_object_unref (range_start);
	g_object_unref (range_end);
	g_object_unref (store);
	if (store_view) g_object_unref (store_view);
	
	return 0;
}
static void
penge_event_tile_update (PengeEventTile *tile)
{
  PengeEventTilePrivate *priv = GET_PRIVATE (tile);
  gchar *time_str;
  gchar *summary_str;
  JanaTime *t;
  gchar *p;

  if (!priv->event)
    return;

  if (priv->time)
  {
    t = jana_event_get_start (priv->event);

    /* Translate this time into local time */
    jana_time_set_offset (t, jana_time_get_offset (priv->time));

    if (jana_time_get_day (priv->time) != jana_time_get_day (t))
    {
      gchar *tmp_str;
      gchar *day_str;
      ClutterActor *tmp_text;

      tmp_str = jana_utils_strftime (t, "%a");
      day_str = g_utf8_strup (tmp_str, -1);
      g_free (tmp_str);

      time_str = jana_utils_strftime (t, "%H:%M");
      tmp_str = g_strdup_printf ("%s <span size=\"xx-small\">%s</span>",
                                 time_str,
                                 day_str);
      g_free (time_str);
      g_free (day_str);

      tmp_text = mx_label_get_clutter_text (MX_LABEL (priv->time_label));
      clutter_text_set_markup (CLUTTER_TEXT (tmp_text), tmp_str);
      g_free (tmp_str);
    } else {
      time_str = jana_utils_strftime (t, "%H:%M");
      mx_label_set_text (MX_LABEL (priv->time_label), time_str);
      g_free (time_str);
    }

    if (jana_time_get_day (priv->time) != jana_time_get_day (t))
    {
      mx_stylable_set_style_pseudo_class (MX_STYLABLE (priv->time_label),
                                          "past");
    } else {
      mx_stylable_set_style_pseudo_class (MX_STYLABLE (priv->time_label),
                                          NULL);
    }

    g_object_unref (t);
  }

  summary_str = jana_event_get_summary (priv->event);
  if (summary_str)
  {
    /* this hack is courtesy of Chris Lord, we look for a new line character
     * and if we find it replace it with \0. We need this because otherwise
     * new lines in our labels look funn
     */
    p = strchr (summary_str, '\n');
    if (p)
      *p = '\0';
    mx_label_set_text (MX_LABEL (priv->summary_label), summary_str);
    g_free (summary_str);
  } else {
    mx_label_set_text (MX_LABEL (priv->summary_label), "");
  }
}