mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
* src/app-utils/app-utils/scm: export new dateformat option symbols
* src/app-utils/option-util.[ch]: create dateformat option utility functions * src/app-utils/options.scm: create a dateformat option * src/engine/date.[ch]: create APIs to handle date-format types. - conversions of date-format to/from strings - move the month format enum to here - conversion of month format to/from strings * src/gnome/top-level.c: move date-format string conversion from here * src/gnome-utils/dialog-options.c: implement a date-format options that uses the gnc-date-format widget. * src/gnome-utils/gnc-date-format.h: remove month format (to date.h) Initial fix for #99574 git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8496 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
54d2f07fec
commit
a58203a43a
13
ChangeLog
13
ChangeLog
@ -6,6 +6,19 @@
|
||||
* src/gnome-utils/gnc-date-format.c: ignore empty "custom" formats.
|
||||
* src/gnome-utils/gnc-query-list.c: add a test for NULL.
|
||||
|
||||
* src/app-utils/app-utils/scm: export new dateformat option symbols
|
||||
* src/app-utils/option-util.[ch]: create dateformat option utility functions
|
||||
* src/app-utils/options.scm: create a dateformat option
|
||||
* src/engine/date.[ch]: create APIs to handle date-format types.
|
||||
- conversions of date-format to/from strings
|
||||
- move the month format enum to here
|
||||
- conversion of month format to/from strings
|
||||
* src/gnome/top-level.c: move date-format string conversion from here
|
||||
* src/gnome-utils/dialog-options.c: implement a date-format options
|
||||
that uses the gnc-date-format widget.
|
||||
* src/gnome-utils/gnc-date-format.h: remove month format (to date.h)
|
||||
Initial fix for #99574
|
||||
|
||||
2003-06-08 Christian Stimming <stimming@tuhh.de>
|
||||
|
||||
* src/import-export/hbci/*.c: Remove old unused code.
|
||||
|
@ -75,6 +75,8 @@
|
||||
(export gnc:make-internal-option)
|
||||
(export gnc:make-query-option)
|
||||
(export gnc:make-color-option)
|
||||
(export gnc:make-dateformat-option)
|
||||
(export gnc:dateformat-get-format)
|
||||
|
||||
(export gnc:color->html)
|
||||
(export gnc:color-option->html)
|
||||
|
@ -2688,3 +2688,112 @@ gnc_option_db_set_option_selectable_by_name(SCM guile_option,
|
||||
|
||||
gnc_option_set_selectable (option, selectable);
|
||||
}
|
||||
|
||||
/* the value is a list of:
|
||||
* format(symbol), month(symbol), include-years(bool), custom-string(string)
|
||||
*/
|
||||
|
||||
gboolean gnc_dateformat_option_value_parse(SCM value, DateFormat *format,
|
||||
GNCDateMonthFormat *months,
|
||||
gboolean *years, char **custom)
|
||||
{
|
||||
SCM val;
|
||||
char *str;
|
||||
|
||||
if (!SCM_LISTP(value) || SCM_NULLP(value))
|
||||
return TRUE;
|
||||
|
||||
do {
|
||||
|
||||
/* Parse the format */
|
||||
val = SCM_CAR(value);
|
||||
value = SCM_CDR(value);
|
||||
if (!SCM_SYMBOLP(val))
|
||||
break;
|
||||
str = gh_symbol2newstr (val, NULL);
|
||||
if (!str)
|
||||
break;
|
||||
|
||||
if (format) {
|
||||
if (gnc_date_string_to_dateformat(str, format)) {
|
||||
free(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* parse the months */
|
||||
val = SCM_CAR(value);
|
||||
value = SCM_CDR(value);
|
||||
if (!SCM_SYMBOLP(val))
|
||||
break;
|
||||
str = gh_symbol2newstr (val, NULL);
|
||||
if (!str)
|
||||
break;
|
||||
|
||||
if (months) {
|
||||
if (gnc_date_string_to_monthformat(str, months)) {
|
||||
free(str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* parse the years */
|
||||
val = SCM_CAR(value);
|
||||
value = SCM_CDR(value);
|
||||
if (!SCM_BOOLP(val))
|
||||
break;
|
||||
|
||||
if (years)
|
||||
*years = SCM_NFALSEP(val);
|
||||
|
||||
/* parse the custom */
|
||||
val = SCM_CAR(value);
|
||||
value = SCM_CDR(value);
|
||||
if (!SCM_STRINGP(val))
|
||||
break;
|
||||
if (!SCM_NULLP(value))
|
||||
break;
|
||||
|
||||
if (custom)
|
||||
*custom = gh_scm2newstr(val, NULL);
|
||||
|
||||
return FALSE;
|
||||
|
||||
} while (FALSE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SCM gnc_dateformat_option_set_value(DateFormat format, GNCDateMonthFormat months,
|
||||
gboolean years, const char *custom)
|
||||
{
|
||||
SCM value = SCM_EOL;
|
||||
SCM val;
|
||||
const char *str;
|
||||
|
||||
/* build the list in reverse order */
|
||||
if (custom)
|
||||
val = scm_mem2string(custom, strlen(custom));
|
||||
else
|
||||
val = SCM_BOOL_F;
|
||||
value = scm_cons(val, value);
|
||||
|
||||
val = SCM_BOOL(years);
|
||||
value = scm_cons(val, value);
|
||||
|
||||
str = gnc_date_monthformat_to_string(months);
|
||||
if (str)
|
||||
val = scm_str2symbol(str);
|
||||
else
|
||||
val = SCM_BOOL_F;
|
||||
value = scm_cons(val, value);
|
||||
|
||||
str = gnc_date_dateformat_to_string(format);
|
||||
if (str)
|
||||
val = scm_str2symbol(str);
|
||||
else
|
||||
val = SCM_BOOL_F;
|
||||
value = scm_cons(val, value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
@ -254,6 +254,13 @@ void gnc_option_db_set_option_selectable_by_name(SCM guile_options,
|
||||
const char *name,
|
||||
gboolean selectable);
|
||||
|
||||
gboolean gnc_dateformat_option_value_parse(SCM value, DateFormat *format,
|
||||
GNCDateMonthFormat *months,
|
||||
gboolean *years, char **custom);
|
||||
SCM gnc_dateformat_option_set_value(DateFormat format, GNCDateMonthFormat months,
|
||||
gboolean years, const char *custom);
|
||||
|
||||
|
||||
/* private */
|
||||
void gncp_option_db_register_option(GNCOptionDBHandle handle,
|
||||
SCM guile_option);
|
||||
|
@ -1130,6 +1130,65 @@
|
||||
(range (car (gnc:option-data color-option))))
|
||||
(gnc:color->hex-string color range)))
|
||||
|
||||
;;
|
||||
;; dateformat option
|
||||
;;
|
||||
(define (gnc:make-dateformat-option
|
||||
section
|
||||
name
|
||||
sort-tag
|
||||
documentation-string
|
||||
default-value)
|
||||
|
||||
(define (def-value)
|
||||
(if (list? default-value)
|
||||
default-value
|
||||
'(locale number #t "")))
|
||||
|
||||
(let* ((value (def-value))
|
||||
(value->string (lambda ()
|
||||
(string-append "'" (gnc:value->string value)))))
|
||||
(gnc:make-option
|
||||
section name sort-tag 'dateformat documentation-string
|
||||
(lambda () value)
|
||||
(lambda (x) (set! value x))
|
||||
(lambda () (def-value))
|
||||
(gnc:restore-form-generator value->string)
|
||||
(lambda (f p)
|
||||
(gnc:kvp-frame-set-slot-path
|
||||
f (symbol->string (car value)) (append p '("fmt")))
|
||||
(gnc:kvp-frame-set-slot-path
|
||||
f (symbol->string (cadr value)) (append p '("month")))
|
||||
(gnc:kvp-frame-set-slot-path
|
||||
f (if (caddr value) 1 0) (append p '("years")))
|
||||
(gnc:kvp-frame-set-slot-path f (cadddr value) (append p '("custom"))))
|
||||
(lambda (f p)
|
||||
(let ((fmt (gnc:kvp-frame-get-slot-path f (append p '("fmt"))))
|
||||
(month (gnc:kvp-frame-get-slot-path f (append p '("month"))))
|
||||
(years (gnc:kvp-frame-get-slot-path f (append p '("years"))))
|
||||
(custom (gnc:kvp-frame-get-slot-path f (append p '("custom")))))
|
||||
(if (and
|
||||
fmt (string? fmt)
|
||||
month (string? month)
|
||||
years (number? years)
|
||||
custom (string? custom))
|
||||
(set! value (list (string->symbol fmt) (string->symbol month)
|
||||
(if (= years 0) #f #t) custom)))))
|
||||
(lambda (x)
|
||||
(cond ((not (list? x)) (list #f "dateformat-option: not a list"))
|
||||
((not (= (length x) 4))
|
||||
(list #f "dateformat-option: wrong list length" (length x)))
|
||||
((not (symbol? (car x)))
|
||||
(list #f "dateformat-option: no format symbol"))
|
||||
((not (symbol? (cadr x)))
|
||||
(list #f "dateformat-option: no months symbol"))
|
||||
((not (string? (cadddr x)))
|
||||
(list #f "dateformat-option: no custom string"))
|
||||
(else (list #t x))))
|
||||
#f #f #f #f)))
|
||||
|
||||
(define (gnc:dateformat-get-format v)
|
||||
(cadddr v))
|
||||
|
||||
;; Create a new options database
|
||||
(define (gnc:new-options)
|
||||
|
@ -68,6 +68,87 @@ static DateFormat prevDateFormat = DATE_FORMAT_LOCALE;
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
static short module = MOD_ENGINE;
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
const char*
|
||||
gnc_date_dateformat_to_string(DateFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case DATE_FORMAT_US:
|
||||
return "us";
|
||||
case DATE_FORMAT_UK:
|
||||
return "uk";
|
||||
case DATE_FORMAT_CE:
|
||||
return "ce";
|
||||
case DATE_FORMAT_ISO:
|
||||
return "iso";
|
||||
case DATE_FORMAT_LOCALE:
|
||||
return "locale";
|
||||
case DATE_FORMAT_CUSTOM:
|
||||
return "custom";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_date_string_to_dateformat(const char* fmt_str, DateFormat *format)
|
||||
{
|
||||
if (!fmt_str)
|
||||
return TRUE;
|
||||
|
||||
if (!strcmp(fmt_str, "us"))
|
||||
*format = DATE_FORMAT_US;
|
||||
else if (!strcmp(fmt_str, "uk"))
|
||||
*format = DATE_FORMAT_UK;
|
||||
else if (!strcmp(fmt_str, "ce"))
|
||||
*format = DATE_FORMAT_CE;
|
||||
else if (!strcmp(fmt_str, "iso"))
|
||||
*format = DATE_FORMAT_ISO;
|
||||
else if (!strcmp(fmt_str, "locale"))
|
||||
*format = DATE_FORMAT_LOCALE;
|
||||
else if (!strcmp(fmt_str, "custom"))
|
||||
*format = DATE_FORMAT_CUSTOM;
|
||||
else
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
gnc_date_monthformat_to_string(GNCDateMonthFormat format)
|
||||
{
|
||||
switch (format) {
|
||||
case GNCDATE_MONTH_NUMBER:
|
||||
return "number";
|
||||
case GNCDATE_MONTH_ABBREV:
|
||||
return "abbrev";
|
||||
case GNCDATE_MONTH_NAME:
|
||||
return "name";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_date_string_to_monthformat(const char *fmt_str, GNCDateMonthFormat *format)
|
||||
{
|
||||
if (!fmt_str)
|
||||
return TRUE;
|
||||
|
||||
if (!strcmp(fmt_str, "number"))
|
||||
*format = GNCDATE_MONTH_NUMBER;
|
||||
else if (!strcmp(fmt_str, "abbrev"))
|
||||
*format = GNCDATE_MONTH_ABBREV;
|
||||
else if (!strcmp(fmt_str, "name"))
|
||||
*format = GNCDATE_MONTH_NAME;
|
||||
else
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
@ -61,6 +61,28 @@ typedef enum
|
||||
#define MAX_DATE_LENGTH 11
|
||||
|
||||
|
||||
/**
|
||||
* This is how to format the month, as a number, an abbreviated string,
|
||||
* or the full name.
|
||||
*/
|
||||
typedef enum {
|
||||
GNCDATE_MONTH_NUMBER,
|
||||
GNCDATE_MONTH_ABBREV,
|
||||
GNCDATE_MONTH_NAME
|
||||
} GNCDateMonthFormat;
|
||||
|
||||
|
||||
/* The string->value versions return 0 on success and 1 on failure */
|
||||
const char* gnc_date_dateformat_to_string(DateFormat format);
|
||||
gboolean gnc_date_string_to_dateformat(const char* format_string,
|
||||
DateFormat *format);
|
||||
|
||||
|
||||
const char* gnc_date_monthformat_to_string(GNCDateMonthFormat format);
|
||||
gboolean gnc_date_string_to_monthformat(const char *format_string,
|
||||
GNCDateMonthFormat *format);
|
||||
|
||||
|
||||
/** Datatypes *******************************************************/
|
||||
|
||||
/** struct timespec64 is just like the unix 'struct timespec' except
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "messages.h"
|
||||
#include "option-util.h"
|
||||
#include "guile-mappings.h"
|
||||
#include "gnc-date-format.h"
|
||||
|
||||
|
||||
/* This static indicates the debugging module that this .o belongs to. */
|
||||
@ -2160,6 +2161,23 @@ gnc_option_set_ui_widget_radiobutton (GNCOption *option, GtkBox *page_box,
|
||||
return value;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
gnc_option_set_ui_widget_dateformat (GNCOption *option, GtkBox *page_box,
|
||||
GtkTooltips *tooltips,
|
||||
char *name, char *documentation,
|
||||
/* Return values */
|
||||
GtkWidget **enclosing, gboolean *packed)
|
||||
{
|
||||
*enclosing = gnc_date_format_new_with_label(name);
|
||||
gnc_option_set_widget (option, *enclosing);
|
||||
|
||||
gnc_option_set_ui_value(option, FALSE);
|
||||
gtk_signal_connect(GTK_OBJECT(*enclosing), "format_changed",
|
||||
GTK_SIGNAL_FUNC(gnc_date_option_changed_cb), option);
|
||||
gtk_widget_show_all(*enclosing);
|
||||
return *enclosing;
|
||||
}
|
||||
|
||||
/* SET VALUE */
|
||||
|
||||
static gboolean
|
||||
@ -2539,6 +2557,31 @@ gnc_option_set_ui_value_radiobutton (GNCOption *option, gboolean use_default,
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_option_set_ui_value_dateformat (GNCOption *option, gboolean use_default,
|
||||
GtkWidget *widget, SCM value)
|
||||
{
|
||||
GNCDateFormat * gdf = GNC_DATE_FORMAT(widget);
|
||||
DateFormat format;
|
||||
GNCDateMonthFormat months;
|
||||
gboolean years;
|
||||
char *custom;
|
||||
|
||||
if (gnc_dateformat_option_value_parse(value, &format, &months, &years, &custom))
|
||||
return TRUE;
|
||||
|
||||
gnc_date_format_set_format(gdf, format);
|
||||
gnc_date_format_set_months(gdf, months);
|
||||
gnc_date_format_set_years(gdf, years);
|
||||
gnc_date_format_set_custom(gdf, custom);
|
||||
gnc_date_format_refresh(gdf);
|
||||
|
||||
if (custom)
|
||||
free(custom);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* GET VALUE */
|
||||
|
||||
static SCM
|
||||
@ -2784,6 +2827,23 @@ gnc_option_get_ui_value_radiobutton (GNCOption *option, GtkWidget *widget)
|
||||
return (gnc_option_permissible_value(option, index));
|
||||
}
|
||||
|
||||
static SCM
|
||||
gnc_option_get_ui_value_dateformat (GNCOption *option, GtkWidget *widget)
|
||||
{
|
||||
GNCDateFormat *gdf = GNC_DATE_FORMAT(widget);
|
||||
DateFormat format;
|
||||
GNCDateMonthFormat months;
|
||||
gboolean years;
|
||||
const char* custom;
|
||||
|
||||
format = gnc_date_format_get_format(gdf);
|
||||
months = gnc_date_format_get_months(gdf);
|
||||
years = gnc_date_format_get_years(gdf);
|
||||
custom = gnc_date_format_get_custom(gdf);
|
||||
|
||||
return (gnc_dateformat_option_set_value(format, months, years, custom));
|
||||
}
|
||||
|
||||
/* INITIALIZATION */
|
||||
|
||||
static void gnc_options_initialize_options (void)
|
||||
@ -2819,6 +2879,8 @@ static void gnc_options_initialize_options (void)
|
||||
gnc_option_set_ui_value_pixmap, gnc_option_get_ui_value_pixmap },
|
||||
{ "radiobutton", gnc_option_set_ui_widget_radiobutton,
|
||||
gnc_option_set_ui_value_radiobutton, gnc_option_get_ui_value_radiobutton },
|
||||
{ "dateformat", gnc_option_set_ui_widget_dateformat,
|
||||
gnc_option_set_ui_value_dateformat, gnc_option_get_ui_value_dateformat },
|
||||
{ NULL, NULL, NULL, NULL }
|
||||
};
|
||||
int i;
|
||||
|
@ -32,16 +32,6 @@
|
||||
#include <gnome.h>
|
||||
#include "date.h"
|
||||
|
||||
/**
|
||||
* This is how to format the month, as a number, an abbreviated string,
|
||||
* or the full name.
|
||||
*/
|
||||
typedef enum {
|
||||
GNCDATE_MONTH_NUMBER,
|
||||
GNCDATE_MONTH_ABBREV,
|
||||
GNCDATE_MONTH_NAME
|
||||
} GNCDateMonthFormat;
|
||||
|
||||
#define GNC_DATE_FORMAT(obj) GTK_CHECK_CAST (obj, gnc_date_format_get_type(), GNCDateFormat)
|
||||
#define GNC_DATE_FORMAT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gnc_date_format_get_type(), GNCDateFormatClass)
|
||||
#define GNC_IS_DATE_FORMAT(obj) GTK_CHECK_TYPE (obj, gnc_date_format_get_type ())
|
||||
|
@ -577,34 +577,11 @@ gnc_configure_date_format (void)
|
||||
|
||||
DateFormat df;
|
||||
|
||||
if( safe_strcmp(format_code, "us") == 0)
|
||||
{
|
||||
df = DATE_FORMAT_US;
|
||||
}
|
||||
|
||||
else if( safe_strcmp(format_code, "uk") == 0)
|
||||
{
|
||||
df = DATE_FORMAT_UK;
|
||||
}
|
||||
|
||||
else if( safe_strcmp(format_code, "ce") == 0)
|
||||
{
|
||||
df = DATE_FORMAT_CE;
|
||||
}
|
||||
|
||||
else if( safe_strcmp(format_code, "iso") == 0)
|
||||
{
|
||||
df = DATE_FORMAT_ISO;
|
||||
}
|
||||
|
||||
else if( safe_strcmp(format_code, "locale") == 0)
|
||||
{
|
||||
df = DATE_FORMAT_LOCALE;
|
||||
}
|
||||
|
||||
else
|
||||
if (gnc_date_string_to_dateformat(format_code, &df))
|
||||
{
|
||||
PERR("Incorrect date format code");
|
||||
if (format_code != NULL)
|
||||
free(format_code);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user