コード例 #1
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), "");
  }
}
コード例 #2
0
static void
refresh (JanaGtkRecurrence *self)
{
	gint i;
	gchar *recur_text;
	GtkTextBuffer *buffer;
	
	JanaGtkRecurrencePrivate *priv = RECURRENCE_PRIVATE (self);
	
	if ((!priv->recur) || (!priv->time))
		gtk_widget_hide (priv->end_hbox);
	else
		gtk_widget_show (priv->end_hbox);
	
	/* Update type selector combo box */
	fill_type_combo	(self);
	
	/* Update preview */
	recur_text = jana_utils_recurrence_to_string (priv->recur, priv->time);
	buffer = gtk_text_view_get_buffer (
		GTK_TEXT_VIEW (priv->preview_textview));
	gtk_text_buffer_set_text (buffer, recur_text, -1);
	
	/* Show/hide the appropriate editing widgets and set type combo */
	gtk_widget_hide (priv->week_hbox);
	gtk_widget_hide (priv->month_hbox);
	if (priv->recur) {
		if (priv->recur->end) {
			gchar *time_string = jana_utils_strftime (
				priv->recur->end, "%d/%m/%Y");
			gtk_label_set_text (GTK_LABEL (priv->end_label),
				time_string);
			g_free (time_string);
		} else {
			gtk_label_set_text (GTK_LABEL (priv->end_label),
				"Forever");
		}
		
		if (priv->recur->interval <= 1)
			gtk_widget_set_sensitive (
				priv->interval_dec_button, FALSE);
		else
			gtk_widget_set_sensitive (
				priv->interval_dec_button, TRUE);
		gtk_widget_set_sensitive (priv->interval_inc_button, TRUE);
		
		switch (priv->recur->type) {
		    case JANA_RECURRENCE_DAILY :
			gtk_combo_box_set_active (
				GTK_COMBO_BOX (priv->type_combo), 1);
			break;
		    case JANA_RECURRENCE_WEEKLY :
			for (i = 0; i < 7; i++) {
				gtk_toggle_button_set_active (
					priv->week_buttons[i],
					priv->recur->week_days[i]);
			}
			gtk_widget_show (priv->week_hbox);
			gtk_combo_box_set_active (
				GTK_COMBO_BOX (priv->type_combo), 2);
			break;
		    case JANA_RECURRENCE_MONTHLY :
			if (priv->recur->by_date)
				gtk_toggle_button_set_active (
					priv->bydate_button, TRUE);
			else
				gtk_toggle_button_set_active (
					priv->byday_button, TRUE);
			gtk_widget_show (priv->month_hbox);
			gtk_combo_box_set_active (
				GTK_COMBO_BOX (priv->type_combo), 3);
			break;
		    case JANA_RECURRENCE_YEARLY :
			gtk_combo_box_set_active (
				GTK_COMBO_BOX (priv->type_combo), 4);
			break;
		}
	} else {
		gtk_combo_box_set_active (GTK_COMBO_BOX (priv->type_combo), 0);
		gtk_widget_set_sensitive (priv->interval_dec_button, FALSE);
		gtk_widget_set_sensitive (priv->interval_inc_button, FALSE);
	}
}