Exemplo n.º 1
0
const gchar *qof_date_text_format_get_string(QofDateFormat df)
{
    switch (df)
    {
    case QOF_DATE_FORMAT_US:
        return "%b %d, %Y";
    case QOF_DATE_FORMAT_UK:
    case QOF_DATE_FORMAT_CE:
        return "%d %b %Y";
    case QOF_DATE_FORMAT_UTC:
        return "%Y-%m-%dT%H:%M:%SZ";
    case QOF_DATE_FORMAT_ISO:
        return "%Y-%b-%d";
    case QOF_DATE_FORMAT_UNSET: // use global
        return qof_date_text_format_get_string (dateFormat);
    case QOF_DATE_FORMAT_LOCALE:
    default:
        break;
    };
    return GNC_D_FMT;
}
Exemplo n.º 2
0
void
gnc_date_format_refresh (GNCDateFormat *gdf)
{
    GNCDateFormatPriv *priv;
    int sel_option;
    gboolean enable_year, enable_month, enable_custom, check_modifiers;
    static gchar *format, *c;
    gchar date_string[MAX_DATE_LEN];
    time64 secs_now;
    struct tm today;

    g_return_if_fail(gdf);
    g_return_if_fail(GNC_IS_DATE_FORMAT(gdf));

    priv = GNC_DATE_FORMAT_GET_PRIVATE(gdf);
    sel_option =
        gtk_combo_box_get_active(GTK_COMBO_BOX(priv->format_combobox));

    switch (sel_option)
    {
    case QOF_DATE_FORMAT_CUSTOM:
        format = g_strdup(gtk_entry_get_text(GTK_ENTRY(priv->custom_entry)));
        enable_year = enable_month = check_modifiers = FALSE;
        enable_custom = TRUE;
        break;

    case QOF_DATE_FORMAT_LOCALE:
    case QOF_DATE_FORMAT_UTC:
        format = g_strdup(qof_date_format_get_string(sel_option));
        enable_year = enable_month = check_modifiers = enable_custom = FALSE;
        break;

    case QOF_DATE_FORMAT_ISO:
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->months_number), TRUE);
        enable_year = check_modifiers = TRUE;
        enable_month = enable_custom = FALSE;
        break;

    default:
        enable_year = enable_month = check_modifiers = TRUE;
        enable_custom = FALSE;
        break;
    }

    /* Tweak widget sensitivities, as appropriate. */
    gnc_date_format_enable_year(gdf, enable_year);
    gnc_date_format_enable_month(gdf, enable_month);
    gnc_date_format_enable_format(gdf, enable_custom);

    /* Update the format string based upon the user's preferences */
    if (check_modifiers)
    {
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->months_number)))
        {
            format = g_strdup(qof_date_format_get_string(sel_option));
        }
        else
        {
            format = g_strdup(qof_date_text_format_get_string(sel_option));
            if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->months_name)))
            {
                c = strchr(format, 'b');
                if (c)
                    *c = 'B';
            }
        }
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(priv->years_button)))
        {
            c = strchr(format, 'y');
            if (c)
                *c = 'Y';
        }
    }

    /*
     * Give feedback on the format string so users can see how it works
     * without having to read the strftime man page. Prevent recursive
     * signals.
     */
    g_signal_handlers_block_matched(priv->custom_entry, G_SIGNAL_MATCH_DATA,
                                    0, 0, NULL, NULL, gdf);
    gtk_entry_set_text(GTK_ENTRY(priv->custom_entry), format);
    g_signal_handlers_unblock_matched(priv->custom_entry, G_SIGNAL_MATCH_DATA,
                                      0, 0, NULL, NULL, gdf);

    /* Visual feedback on what the date will look like. */
    secs_now = gnc_time (NULL);
    gnc_localtime_r (&secs_now, &today);
    qof_strftime(date_string, MAX_DATE_LEN, format, &today);
    gtk_label_set_text(GTK_LABEL(priv->sample_label), date_string);
    g_free(format);
}