mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Code cleanup, fix a date bug.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2890 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -81,7 +81,7 @@ gnc_date_option_set_select_method(GNCOption *option, gboolean use_absolute,
|
|||||||
{
|
{
|
||||||
GList* widget_list;
|
GList* widget_list;
|
||||||
GtkWidget *ab_button, *rel_button, *rel_widget, *ab_widget;
|
GtkWidget *ab_button, *rel_button, *rel_widget, *ab_widget;
|
||||||
|
|
||||||
widget_list = gtk_container_children(GTK_CONTAINER(option->widget));
|
widget_list = gtk_container_children(GTK_CONTAINER(option->widget));
|
||||||
ab_button = g_list_nth_data(widget_list, GNC_RD_WID_AB_BUTTON_POS);
|
ab_button = g_list_nth_data(widget_list, GNC_RD_WID_AB_BUTTON_POS);
|
||||||
ab_widget = g_list_nth_data(widget_list, GNC_RD_WID_AB_WIDGET_POS);
|
ab_widget = g_list_nth_data(widget_list, GNC_RD_WID_AB_WIDGET_POS);
|
||||||
@@ -206,9 +206,9 @@ gnc_option_set_ui_value(GNCOption *option, gboolean use_default)
|
|||||||
int index;
|
int index;
|
||||||
char *date_option_type;
|
char *date_option_type;
|
||||||
char *symbol_str;
|
char *symbol_str;
|
||||||
|
|
||||||
date_option_type = gnc_option_date_option_get_subtype(option);
|
date_option_type = gnc_option_date_option_get_subtype(option);
|
||||||
|
|
||||||
if (gh_vector_p(value))
|
if (gh_vector_p(value))
|
||||||
{
|
{
|
||||||
symbol = gh_vector_ref(value, gh_int2scm(0));
|
symbol = gh_vector_ref(value, gh_int2scm(0));
|
||||||
@@ -253,7 +253,7 @@ gnc_option_set_ui_value(GNCOption *option, gboolean use_default)
|
|||||||
if (gnc_timepair_p(tp))
|
if (gnc_timepair_p(tp))
|
||||||
{
|
{
|
||||||
ts = gnc_timepair2timespec(tp);
|
ts = gnc_timepair2timespec(tp);
|
||||||
|
|
||||||
if (safe_strcmp(date_option_type, "absolute") == 0)
|
if (safe_strcmp(date_option_type, "absolute") == 0)
|
||||||
{
|
{
|
||||||
gnc_date_edit_set_time(GNC_DATE_EDIT(option->widget), ts.tv_sec);
|
gnc_date_edit_set_time(GNC_DATE_EDIT(option->widget), ts.tv_sec);
|
||||||
@@ -284,7 +284,6 @@ gnc_option_set_ui_value(GNCOption *option, gboolean use_default)
|
|||||||
}
|
}
|
||||||
free(symbol_str);
|
free(symbol_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -456,7 +455,8 @@ gnc_option_get_ui_value(GNCOption *option)
|
|||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
SCM type, val;
|
SCM type, val;
|
||||||
char *subtype = gnc_option_date_option_get_subtype(option);
|
char *subtype = gnc_option_date_option_get_subtype(option);
|
||||||
|
|
||||||
if(safe_strcmp(subtype, "relative") == 0)
|
if(safe_strcmp(subtype, "relative") == 0)
|
||||||
{
|
{
|
||||||
index = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(option->widget),
|
index = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(option->widget),
|
||||||
@@ -468,10 +468,10 @@ gnc_option_get_ui_value(GNCOption *option)
|
|||||||
else if (safe_strcmp(subtype, "absolute") == 0)
|
else if (safe_strcmp(subtype, "absolute") == 0)
|
||||||
{
|
{
|
||||||
Timespec ts;
|
Timespec ts;
|
||||||
|
|
||||||
ts.tv_sec = gnc_date_edit_get_date(GNC_DATE_EDIT(option->widget));
|
ts.tv_sec = gnc_date_edit_get_date(GNC_DATE_EDIT(option->widget));
|
||||||
ts.tv_nsec = 0;
|
ts.tv_nsec = 0;
|
||||||
|
|
||||||
result = gh_cons(gh_symbol2scm("absolute"), gnc_timespec2timepair(ts));
|
result = gh_cons(gh_symbol2scm("absolute"), gnc_timespec2timepair(ts));
|
||||||
}
|
}
|
||||||
else if (safe_strcmp(subtype, "both") == 0)
|
else if (safe_strcmp(subtype, "both") == 0)
|
||||||
@@ -503,8 +503,7 @@ gnc_option_get_ui_value(GNCOption *option)
|
|||||||
}
|
}
|
||||||
g_free(subtype);
|
g_free(subtype);
|
||||||
}
|
}
|
||||||
|
else if (safe_strcmp(type, "account-list") == 0)
|
||||||
else if (safe_strcmp(type, "account-list") == 0)
|
|
||||||
{
|
{
|
||||||
GNCAccountTree *tree;
|
GNCAccountTree *tree;
|
||||||
GList *list;
|
GList *list;
|
||||||
|
|||||||
@@ -216,6 +216,7 @@
|
|||||||
(set-tm:year zd 0)
|
(set-tm:year zd 0)
|
||||||
(set-tm:yday zd 0)
|
(set-tm:yday zd 0)
|
||||||
(set-tm:wday zd 0)
|
(set-tm:wday zd 0)
|
||||||
|
(set-tm:isdst zd 0)
|
||||||
zd))
|
zd))
|
||||||
|
|
||||||
(define SecDelta
|
(define SecDelta
|
||||||
@@ -288,6 +289,7 @@
|
|||||||
(set-tm:hour bdt 23)
|
(set-tm:hour bdt 23)
|
||||||
(let ((newtime (car (mktime bdt))))
|
(let ((newtime (car (mktime bdt))))
|
||||||
(cons newtime 0))))
|
(cons newtime 0))))
|
||||||
|
|
||||||
(define (gnc:reldate-get-symbol x) (vector-ref x 0))
|
(define (gnc:reldate-get-symbol x) (vector-ref x 0))
|
||||||
(define (gnc:reldate-get-string x) (vector-ref x 1))
|
(define (gnc:reldate-get-string x) (vector-ref x 1))
|
||||||
(define (gnc:reldate-get-desc x) (vector-ref x 2))
|
(define (gnc:reldate-get-desc x) (vector-ref x 2))
|
||||||
@@ -311,7 +313,6 @@
|
|||||||
(if rel-date-data
|
(if rel-date-data
|
||||||
((gnc:reldate-get-fn rel-date-data))
|
((gnc:reldate-get-fn rel-date-data))
|
||||||
(gnc:error "Tried to look up an undefined date symbol"))))
|
(gnc:error "Tried to look up an undefined date symbol"))))
|
||||||
|
|
||||||
|
|
||||||
(define (gnc:get-relative-date-strings date-symbol)
|
(define (gnc:get-relative-date-strings date-symbol)
|
||||||
(let ((rel-date-info (hash-ref gnc:relative-date-hash date-symbol)))
|
(let ((rel-date-info (hash-ref gnc:relative-date-hash date-symbol)))
|
||||||
@@ -334,6 +335,7 @@
|
|||||||
(set-tm:hour now 0)
|
(set-tm:hour now 0)
|
||||||
(set-tm:mday now 1)
|
(set-tm:mday now 1)
|
||||||
(set-tm:mon now 0)
|
(set-tm:mon now 0)
|
||||||
|
(set-tm:isdst now 0)
|
||||||
(gnc:secs->timepair (car (mktime now)))))
|
(gnc:secs->timepair (car (mktime now)))))
|
||||||
|
|
||||||
(define (gnc:get-start-prev-year)
|
(define (gnc:get-start-prev-year)
|
||||||
@@ -344,7 +346,8 @@
|
|||||||
(set-tm:mday now 1)
|
(set-tm:mday now 1)
|
||||||
(set-tm:mon now 0)
|
(set-tm:mon now 0)
|
||||||
(set-tm:year now (- (tm:year now) 1))
|
(set-tm:year now (- (tm:year now) 1))
|
||||||
(gnc:secs->timepair (car (mktime now)))))
|
(set-tm:isdst now 0)
|
||||||
|
(gnc:secs->timepair (car (mktime now)))))
|
||||||
|
|
||||||
(define (gnc:get-end-prev-year)
|
(define (gnc:get-end-prev-year)
|
||||||
(let ((now (localtime (current-time))))
|
(let ((now (localtime (current-time))))
|
||||||
@@ -354,8 +357,8 @@
|
|||||||
(set-tm:mday now 31)
|
(set-tm:mday now 31)
|
||||||
(set-tm:mon now 11)
|
(set-tm:mon now 11)
|
||||||
(set-tm:year now (- (tm:year now) 1))
|
(set-tm:year now (- (tm:year now) 1))
|
||||||
(gnc:secs->timepair (car (mktime now)))))
|
(set-tm:isdst now 0)
|
||||||
|
(gnc:secs->timepair (car (mktime now)))))
|
||||||
|
|
||||||
;; FIXME:: Replace with option when it becomes available
|
;; FIXME:: Replace with option when it becomes available
|
||||||
(define (gnc:get-start-cur-fin-year)
|
(define (gnc:get-start-cur-fin-year)
|
||||||
@@ -388,7 +391,6 @@
|
|||||||
(set-tm:mon now 6)
|
(set-tm:mon now 6)
|
||||||
(set-tm:year now (- (tm:year now) 2))
|
(set-tm:year now (- (tm:year now) 2))
|
||||||
(cons (car (mktime now)) 0))
|
(cons (car (mktime now)) 0))
|
||||||
|
|
||||||
(begin
|
(begin
|
||||||
(set-tm:sec now 0)
|
(set-tm:sec now 0)
|
||||||
(set-tm:min now 0)
|
(set-tm:min now 0)
|
||||||
@@ -408,7 +410,6 @@
|
|||||||
(set-tm:mday now 30)
|
(set-tm:mday now 30)
|
||||||
(set-tm:mon now 5)
|
(set-tm:mon now 5)
|
||||||
(cons (car (mktime now)) 0))
|
(cons (car (mktime now)) 0))
|
||||||
|
|
||||||
(begin
|
(begin
|
||||||
(set-tm:sec now 59)
|
(set-tm:sec now 59)
|
||||||
(set-tm:min now 59)
|
(set-tm:min now 59)
|
||||||
@@ -452,7 +453,6 @@
|
|||||||
(set-tm:mday (gnc:days-in-month (+ (tm:month now) 1)) (+ (tm:year) 1900))
|
(set-tm:mday (gnc:days-in-month (+ (tm:month now) 1)) (+ (tm:year) 1900))
|
||||||
(cons (car (mktime now)) 0)))
|
(cons (car (mktime now)) 0)))
|
||||||
|
|
||||||
|
|
||||||
(define (gnc:get-start-current-quarter)
|
(define (gnc:get-start-current-quarter)
|
||||||
(let ((now (localtime (current-time))))
|
(let ((now (localtime (current-time))))
|
||||||
(set-tm:sec now 0)
|
(set-tm:sec now 0)
|
||||||
|
|||||||
@@ -314,9 +314,9 @@
|
|||||||
(or
|
(or
|
||||||
(and (eq? 'relative (car date)) (symbol? (cdr date)))
|
(and (eq? 'relative (car date)) (symbol? (cdr date)))
|
||||||
(and (eq? 'absolute (car date))
|
(and (eq? 'absolute (car date))
|
||||||
(pair? (cdr date))
|
(pair? (cdr date))
|
||||||
(exact? (cadr date))
|
(exact? (cadr date))
|
||||||
(exact? (cddr date))))))
|
(exact? (cddr date))))))
|
||||||
(define (list-lookup list item)
|
(define (list-lookup list item)
|
||||||
(cond
|
(cond
|
||||||
((null? list) #f)
|
((null? list) #f)
|
||||||
@@ -327,30 +327,29 @@
|
|||||||
(string-append "'" (gnc:value->string value)))))
|
(string-append "'" (gnc:value->string value)))))
|
||||||
(gnc:make-option
|
(gnc:make-option
|
||||||
section name sort-tag 'date documentation-string
|
section name sort-tag 'date documentation-string
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(if (eq? (car value) 'relative)
|
(if (eq? (car value) 'relative)
|
||||||
|
|
||||||
(vector 'relative (gnc:get-absolute-from-relative-date
|
(vector 'relative (gnc:get-absolute-from-relative-date
|
||||||
(cdr value)) (cdr value))
|
(cdr value)) (cdr value))
|
||||||
(vector 'absolute (cdr value))))
|
(vector 'absolute (cdr value))))
|
||||||
(lambda (date)
|
(lambda (date)
|
||||||
(if (date-legal date)
|
(if (date-legal date)
|
||||||
(set! value date)
|
(set! value date)
|
||||||
(gnc:error "Illegal date value set")))
|
(gnc:error "Illegal date value set")))
|
||||||
default-getter
|
default-getter
|
||||||
(gnc:restore-form-generator value->string)
|
(gnc:restore-form-generator value->string)
|
||||||
(lambda (date)
|
(lambda (date)
|
||||||
(if (date-legal date)
|
(if (date-legal date)
|
||||||
(list #t date)
|
(list #t date)
|
||||||
(list #f "date-option: illegal date")))
|
(list #f "date-option: illegal date")))
|
||||||
(vector subtype show-time relative-date-list)
|
(vector subtype show-time relative-date-list)
|
||||||
(vector (lambda () (length relative-date-list))
|
(vector (lambda () (length relative-date-list))
|
||||||
(lambda (x) (list-ref relative-date-list x))
|
(lambda (x) (list-ref relative-date-list x))
|
||||||
(lambda (x) (gnc:get-relative-date-string
|
(lambda (x) (gnc:get-relative-date-string
|
||||||
(list-ref relative-date-list x)))
|
(list-ref relative-date-list x)))
|
||||||
(lambda (x) (gnc:get-relative-date-desc
|
(lambda (x) (gnc:get-relative-date-desc
|
||||||
(list-ref relative-date-list x)))
|
(list-ref relative-date-list x)))
|
||||||
(lambda (x) (list-lookup relative-date-list x)))
|
(lambda (x) (list-lookup relative-date-list x)))
|
||||||
#f
|
#f
|
||||||
#f)))
|
#f)))
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
(display ")")
|
(display ")")
|
||||||
(newline)
|
(newline)
|
||||||
(newline port))))
|
(newline port))))
|
||||||
|
|
||||||
(define (report-output->string tree)
|
(define (report-output->string tree)
|
||||||
(call-with-output-string
|
(call-with-output-string
|
||||||
(lambda (port)
|
(lambda (port)
|
||||||
|
|||||||
@@ -81,18 +81,20 @@
|
|||||||
(lambda () (cons 'absolute (cons (current-time) 0)))
|
(lambda () (cons 'absolute (cons (current-time) 0)))
|
||||||
#t 'absolute #f ))
|
#t 'absolute #f ))
|
||||||
|
|
||||||
(gnc:register-hello-world-option
|
(gnc:register-hello-world-option
|
||||||
(gnc:make-date-option
|
(gnc:make-date-option
|
||||||
"Hello, World!" "Combo Date Option"
|
"Hello, World!" "Combo Date Option"
|
||||||
"y" "This is a combination date option"
|
"y" "This is a combination date option"
|
||||||
(lambda () (cons 'relative 'start-cal-year))
|
(lambda () (cons 'relative 'start-cal-year))
|
||||||
#f 'both '(start-cal-year start-prev-year end-prev-year) ))
|
#f 'both '(start-cal-year start-prev-year end-prev-year) ))
|
||||||
(gnc:register-hello-world-option
|
|
||||||
|
(gnc:register-hello-world-option
|
||||||
(gnc:make-date-option
|
(gnc:make-date-option
|
||||||
"Hello, World!" "Relative Date Option"
|
"Hello, World!" "Relative Date Option"
|
||||||
"x" "This is a relative date option"
|
"x" "This is a relative date option"
|
||||||
(lambda () (cons 'relative 'start-cal-year))
|
(lambda () (cons 'relative 'start-cal-year))
|
||||||
#f 'relative '(start-cal-year start-prev-year end-prev-year) ))
|
#f 'relative '(start-cal-year start-prev-year end-prev-year) ))
|
||||||
|
|
||||||
;; This is a number range option. The user can enter a number
|
;; This is a number range option. The user can enter a number
|
||||||
;; between a lower and upper bound given below. There are also
|
;; between a lower and upper bound given below. There are also
|
||||||
;; arrows the user can click to go up or down, the amount changed
|
;; arrows the user can click to go up or down, the amount changed
|
||||||
@@ -235,8 +237,7 @@
|
|||||||
;; The first thing we do is make local variables for all the specific
|
;; The first thing we do is make local variables for all the specific
|
||||||
;; options in the set of options given to the function. This set will
|
;; options in the set of options given to the function. This set will
|
||||||
;; be generated by the options generator above.
|
;; be generated by the options generator above.
|
||||||
(let ((dummy (display options))
|
(let ((bool-val (op-value "Hello, World!" "Boolean Option"))
|
||||||
(bool-val (op-value "Hello, World!" "Boolean Option"))
|
|
||||||
(mult-val (op-value "Hello, World!" "Multi Choice Option"))
|
(mult-val (op-value "Hello, World!" "Multi Choice Option"))
|
||||||
(string-val (op-value "Hello, World!" "String Option"))
|
(string-val (op-value "Hello, World!" "String Option"))
|
||||||
(date-val (gnc:date-option-absolute-time (op-value "Hello, World!" "Just a Date Option")))
|
(date-val (gnc:date-option-absolute-time (op-value "Hello, World!" "Just a Date Option")))
|
||||||
@@ -251,7 +252,7 @@
|
|||||||
|
|
||||||
;; Crash if asked to.
|
;; Crash if asked to.
|
||||||
(if crash-val (string-length #f));; string-length needs a string
|
(if crash-val (string-length #f));; string-length needs a string
|
||||||
|
|
||||||
(let ((time-string (strftime "%X" (localtime (current-time))))
|
(let ((time-string (strftime "%X" (localtime (current-time))))
|
||||||
(date-string (strftime "%x" (localtime (car date-val))))
|
(date-string (strftime "%x" (localtime (car date-val))))
|
||||||
(date-string2 (strftime "%x %X" (localtime (car date2-val))))
|
(date-string2 (strftime "%x %X" (localtime (car date2-val))))
|
||||||
@@ -267,7 +268,7 @@
|
|||||||
(html-start-document-color (gnc:color-option->html color-op))
|
(html-start-document-color (gnc:color-option->html color-op))
|
||||||
|
|
||||||
;; Here we get the title using the string database and 'lookup.
|
;; Here we get the title using the string database and 'lookup.
|
||||||
"<h2>Hello World </h2>"
|
"<h2>" (string-db 'lookup 'title) "</h2>"
|
||||||
|
|
||||||
;; Here we user our paragraph helper
|
;; Here we user our paragraph helper
|
||||||
(make-para 'para-1
|
(make-para 'para-1
|
||||||
|
|||||||
Reference in New Issue
Block a user