Robert Graham Merkel's tip-of-the-day patch.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2516 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-06-26 19:38:45 +00:00
parent b584889b9d
commit 5640eeec3a
17 changed files with 906 additions and 392 deletions

View File

@ -1,3 +1,34 @@
2000-06-26 Robert Graham Merkel <rgmerk@mira.net>
* src/guile/global-options.[ch] (gnc_option_refresh_ui_by_name):
New function to make refreshing the GUI options possible from C as
well as scheme.
(gnc_set_boolean_option): C function to set boolean options from
outside the options dialog.
* src/gnome/dialog-totd.[ch]: New files containing the GUI
functions for doing tips of the day.
* src/guile/tip-of-the-day.[ch]: New files with a C interface for
the scheme tip of the day engine.
* src/guile/option-util.[ch] (gnc_option_db_set_boolean_option):
New function to set a boolean option.
* src/scm/tip-of-the-day.scm: New file: an interface for reading
in and passing tips to the gui in text form.
* src/scm/tip-list.scm: A list of tips as a Scheme list. File
should probably be shifted somewhere else.
* src/scm/startup.scm: Loads tip-of-the-day.scm
* src/scm/prefs.scm: Add an option for displaying tips of the day
at startup. Also added gnc:support line.
* src/gnome/window-main.c (gnc_ui_totd_cb): Added menu entries and
callbacks to add "tips of the day" to help menu.
2000-06-23 Dave Peticolas <dave@krondo.com>
* src/gnome/dialog-utils.c (gnc_window_adjust_for_screen): new

25
README
View File

@ -1,15 +1,18 @@
###########################################################################
DEVELOPMENT RELEASE
============================================================
Gnucash 1.5.x README file.
The version 1.3.x series of GnuCash are experimental development
releases. They may or may not work. Use at your own risk.
NOTE: THIS IS A DEVELOPMENT RELEASE!!! THIS VERSION HAS NOT
BEEN TESTED PROPERLY AND MAY DO ABSOLUTELY ANYTHING!
The last stable, production version was gnucash-1.2.5.
The next stable, production version will be gnucash-1.4.x
USE AT YOUR OWN RISK (AND KEEP *LOTS* OF BACKUPS)
###########################################################################
If you want something a bit more tested, please use the
1.4 stable series.
------------------------------------------------------------
==================
Table of Contents:
------------------
- Overview
- Upgrading from 1.2.x
@ -342,14 +345,10 @@ Supported OS's
GnuCash 1.3.x is known to work with the following operating systems:
GNU/Linux -- x86 & Alpha
GNU/Linux -- x86, Sparc, Alpha
Solaris -- Sparc
FreeBSD -- x86
It probably works with the following :
OpenBSD -- x86 (needs to be confirmed one way or another)
OpenBSD -- x86
Previous versions have been known to work on the following platforms, but
their current status is unknown:

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ libgncgnome_a_SOURCES = \
dialog-add.c \
dialog-edit.c \
dialog-utils.c \
dialog-totd.c \
extensions.c \
query-user.c \
reconcile-list.c \
@ -48,6 +49,7 @@ noinst_HEADERS = \
dialog-options.h \
dialog-print-check.h \
dialog-qif-import.h \
dialog-totd.h \
dialog-transfer.h \
dialog-utils.h \
extensions.h \

View File

@ -118,14 +118,14 @@ l = @l@
noinst_LIBRARIES = libgncgnome.a
libgncgnome_a_SOURCES = top-level.c window-main.c window-register.c window-adjust.c window-help.c cursors.c account-tree.c dialog-budget.c window-reconcile.c window-html.c dialog-options.c dialog-filebox.c dialog-transfer.c dialog-add.c dialog-edit.c dialog-utils.c extensions.c query-user.c reconcile-list.c window-report.c gnc-dateedit.c gnc-currency-edit.c dialog-qif-import.c glade-gnc-dialogs.c gnc-datedelta.c dialog-account-picker.c print-session.c file-history.c dialog-print-check.c dialog-find-transactions.c
libgncgnome_a_SOURCES = top-level.c window-main.c window-register.c window-adjust.c window-help.c cursors.c account-tree.c dialog-budget.c window-reconcile.c window-html.c dialog-options.c dialog-filebox.c dialog-transfer.c dialog-add.c dialog-edit.c dialog-utils.c dialog-totd.c extensions.c query-user.c reconcile-list.c window-report.c gnc-dateedit.c gnc-currency-edit.c dialog-qif-import.c glade-gnc-dialogs.c gnc-datedelta.c dialog-account-picker.c print-session.c file-history.c dialog-print-check.c dialog-find-transactions.c
gnomeappdir = ${datadir}/gnome/apps/Applications
gnomeapp_DATA = gnucash.desktop
noinst_HEADERS = account-tree.h account-treeP.h cursors.h dialog-account-picker.h dialog-add.h dialog-budget.h dialog-edit.h dialog-find-transactions.h dialog-options.h dialog-print-check.h dialog-qif-import.h dialog-transfer.h dialog-utils.h extensions.h glade-cb-gnc-dialogs.h glade-gnc-dialogs.h glade-support-gnc-dialogs.h gnc-currency-edit.h gnc-datedelta.h gnc-dateedit.h gnome-top-level.h print-session.h query-user.h reconcile-list.h reconcile-listP.h window-help.h window-html.h window-main.h window-mainP.h window-reconcile.h window-register.h window-report.h
noinst_HEADERS = account-tree.h account-treeP.h cursors.h dialog-account-picker.h dialog-add.h dialog-budget.h dialog-edit.h dialog-find-transactions.h dialog-options.h dialog-print-check.h dialog-qif-import.h dialog-totd.h dialog-transfer.h dialog-utils.h extensions.h glade-cb-gnc-dialogs.h glade-gnc-dialogs.h glade-support-gnc-dialogs.h gnc-currency-edit.h gnc-datedelta.h gnc-dateedit.h gnome-top-level.h print-session.h query-user.h reconcile-list.h reconcile-listP.h window-help.h window-html.h window-main.h window-mainP.h window-reconcile.h window-register.h window-report.h
EXTRA_DIST = .cvsignore gnc-dialogs.glade gnucash.desktop
@ -154,8 +154,8 @@ libgncgnome_a_OBJECTS = top-level.o window-main.o window-register.o \
window-adjust.o window-help.o cursors.o account-tree.o dialog-budget.o \
window-reconcile.o window-html.o dialog-options.o dialog-filebox.o \
dialog-transfer.o dialog-add.o dialog-edit.o dialog-utils.o \
extensions.o query-user.o reconcile-list.o window-report.o \
gnc-dateedit.o gnc-currency-edit.o dialog-qif-import.o \
dialog-totd.o extensions.o query-user.o reconcile-list.o \
window-report.o gnc-dateedit.o gnc-currency-edit.o dialog-qif-import.o \
glade-gnc-dialogs.o gnc-datedelta.o dialog-account-picker.o \
print-session.o file-history.o dialog-print-check.o \
dialog-find-transactions.o
@ -180,8 +180,8 @@ DEP_FILES = .deps/account-tree.P .deps/cursors.P \
.deps/dialog-edit.P .deps/dialog-filebox.P \
.deps/dialog-find-transactions.P .deps/dialog-options.P \
.deps/dialog-print-check.P .deps/dialog-qif-import.P \
.deps/dialog-transfer.P .deps/dialog-utils.P .deps/extensions.P \
.deps/file-history.P .deps/glade-gnc-dialogs.P \
.deps/dialog-totd.P .deps/dialog-transfer.P .deps/dialog-utils.P \
.deps/extensions.P .deps/file-history.P .deps/glade-gnc-dialogs.P \
.deps/gnc-currency-edit.P .deps/gnc-datedelta.P .deps/gnc-dateedit.P \
.deps/print-session.P .deps/query-user.P .deps/reconcile-list.P \
.deps/top-level.P .deps/window-adjust.P .deps/window-help.P \

276
src/gnome/dialog-totd.c Normal file
View File

@ -0,0 +1,276 @@
/********************************************************************\
* dialog-totd.c -- Dialog to display a "tip of the day" *
* Copyright (C) 2000 Robert Merkel <rgmerk@mira.net> *
* Large fractions borrowed from gnome-hint (Copyright (C) 2000) *
* Free Software Foundation *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
#include "top-level.h"
#include <gnome.h>
#include <libgnomeui/gnome-window-icon.h>
#include "global-options.h"
#include "query-user.h"
#include "messages.h"
#include "util.h"
#include "tip-of-the-day.h"
#include "dialog-totd.h"
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_GUI;
static GtkWidget *disable_cb = NULL;
static GtkWidget *canvas = NULL;
static GtkWidget *scrollwin = NULL;
static GnomeCanvasItem *hint_item;
static GnomeCanvasItem *blue_background;
static GnomeCanvasItem *white_background;
static int width = 400, height = 200;
/** Prototypes *********************************************************/
static void draw_on_canvas(GtkWidget *canvas, char *hint);
static void grow_text_if_necessary(void);
/** Implementations ***************************************************/
/************************************************************************\
* gnc_ui_totd_dialog_create_and_run *
* display and run the "Tip of the Day" dialog *
* *
* Returns: nothing *
\************************************************************************/
void
gnc_ui_totd_dialog_create_and_run(void)
{
GtkWidget *win;
gint status;
gboolean config_set_success;
char *new_hint;
gboolean old_enabled, new_enabled;
win = gnome_dialog_new(TOTD_STR,
GNOME_STOCK_BUTTON_PREV,
GNOME_STOCK_BUTTON_NEXT,
GNOME_STOCK_BUTTON_CLOSE,
NULL);
gnome_dialog_set_parent(GNOME_DIALOG(win), GTK_WINDOW(gnc_get_ui_data()));
scrollwin = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
GTK_POLICY_NEVER,
GTK_POLICY_NEVER);
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(win)->vbox), scrollwin, TRUE, TRUE, 0);
canvas = gnome_canvas_new();
gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas),
0.0,0.0,width,height);
gtk_widget_set_usize(canvas,width,height);
gtk_widget_ensure_style(canvas);
gtk_container_add(GTK_CONTAINER(scrollwin), canvas);
new_hint = gnc_get_current_tip();
draw_on_canvas(canvas, new_hint);
free(new_hint);
gtk_widget_show_all(scrollwin);
old_enabled = gnc_lookup_boolean_option("General",
"Display \"Tip of the Day\"",
TRUE);
disable_cb = gtk_check_button_new_with_label(DISPLAY_NEXT_TIME_STR);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (disable_cb),
old_enabled);
gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(win)->vbox), disable_cb, TRUE, TRUE, 0);
gtk_widget_show(disable_cb);
do
{
status = gnome_dialog_run(GNOME_DIALOG(win));
// printf("status = %d\n", status);
switch(status)
{
case 0: /* previous hint */
gnc_decrement_tip();
new_hint = gnc_get_current_tip();
gnome_canvas_item_set(hint_item,
"text",new_hint,
NULL);
grow_text_if_necessary();
free(new_hint);
break;
case 1: /* next hint */
gnc_increment_tip();
new_hint = gnc_get_current_tip();
gnome_canvas_item_set(hint_item,
"text",new_hint,
NULL);
grow_text_if_necessary();
free(new_hint);
break;
default:
status = -1;
break;
}
} while(status >= 0);
new_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(disable_cb));
gtk_widget_destroy(win);
gnc_increment_tip();
if(new_enabled != old_enabled)
{
config_set_success = gnc_set_boolean_option("General",
"Display \"Tip of the Day\"",
new_enabled);
gnc_option_refresh_ui_by_name("General", "Display \"Tip of the Day\"");
if(new_enabled == FALSE)
{
gnc_info_dialog(REENABLE_TIPS_MSG);
}
}
}
/* increases the size of the canvas and enables scrolling if the text
gets big enough */
static void
grow_text_if_necessary(void)
{
double w,h;
int ww,hh;
int changed = FALSE;
gtk_object_get(GTK_OBJECT(hint_item),
"text_width",&w,
"text_height",&h,
NULL);
/*add border, and 10 pixels around*/
w+=75+10;
h+=50+10;
/*some sanity limits*/
/*if(w>800) w = 800;
if(h>600) h = 600;*/
if(w>width) {
width = w;
changed = TRUE;
}
if(h>height) {
height = h;
changed = TRUE;
}
if(!changed)
return;
/*limits on size*/
ww = width; hh = height;
if(ww>720) ww = 720;
if(hh>450) hh = 450;
if(ww != width || hh != height)
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
else
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin),
GTK_POLICY_NEVER,
GTK_POLICY_NEVER);
/*here we grow the canvas*/
gtk_widget_set_usize(canvas,ww,hh);
gnome_canvas_set_scroll_region(GNOME_CANVAS(canvas),
0.0,0.0,width,height);
gnome_canvas_item_set(blue_background,
"x2",(double)width,
"y2",(double)height,
NULL);
gnome_canvas_item_set(white_background,
"x2",(double)width,
"y2",(double)height,
NULL);
gnome_canvas_item_set(hint_item,
"x",(double)(((width-75)/2)+75),
"y",(double)(((height-50)/2)+50),
"clip_width",(double)(width-75),
"clip_height",(double)(height-50),
NULL);
}
/* places items on the canvas to make up the tip of the day */
static void
draw_on_canvas(GtkWidget *canvas, char *hint)
{
GnomeCanvasItem *item;
blue_background = gnome_canvas_item_new(
gnome_canvas_root(GNOME_CANVAS(canvas)),
gnome_canvas_rect_get_type(),
"x1",(double)0.0,
"y1",(double)0.0,
"x2",(double)400.0,
"y2",(double)200.0,
"fill_color","sea green",
NULL);
white_background = gnome_canvas_item_new(
gnome_canvas_root(GNOME_CANVAS(canvas)),
gnome_canvas_rect_get_type(),
"x1",(double)75.0,
"y1",(double)50.0,
"x2",(double)400.0,
"y2",(double)200.0,
"fill_color","white",
NULL);
hint_item = gnome_canvas_item_new(
gnome_canvas_root(GNOME_CANVAS(canvas)),
gnome_canvas_text_get_type(),
"x",(double)237.5,
"y",(double)125.0,
"fill_color","black",
"font_gdk",canvas->style->font,
"clip_width",(double)325.0,
"clip_height",(double)150.0,
"clip",TRUE,
"text",hint,
NULL);
item = gnome_canvas_item_new(
gnome_canvas_root(GNOME_CANVAS(canvas)),
gnome_canvas_text_get_type(),
"x",(double)200.0,
"y",(double)25.0,
"fill_color","white",
"font",_("-*-helvetica-bold-r-normal-*-*-180-*-*-p-*-*-*"),
"text",TOTD_STR,
NULL);
grow_text_if_necessary();
}
/********************** END OF FILE *********************************\
\********************************************************************/

28
src/gnome/dialog-totd.h Normal file
View File

@ -0,0 +1,28 @@
/********************************************************************\
* dialog-totd.h : dialog to display a "tip of the day" *
* Copyright (C) 2000 Robert Merkel <rgmerk@mira.net> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 59 Temple Place - Suite 330 Fax: +1-617-542-2652 *
* Boston, MA 02111-1307, USA gnu@gnu.org *
\********************************************************************/
#ifndef __DIALOG_TOTD_H_
#define __DIALOG_TOTD_H_
void gnc_ui_totd_dialog_create_and_run(void);
#endif

View File

@ -52,6 +52,7 @@
#include "dialog-edit.h"
#include "dialog-qif-import.h"
#include "dialog-find-transactions.h"
#include "dialog-totd.h"
#include "file-history.h"
#include "EuroUtils.h"
#include "Scrub.h"
@ -260,6 +261,13 @@ gnc_ui_about_cb (GtkWidget *widget, gpointer data)
gnome_dialog_run_and_close(GNOME_DIALOG(about));
}
static void
gnc_ui_totd_cb (GtkWidget *widget, gpointer data)
{
gnc_ui_totd_dialog_create_and_run();
return;
}
static void
gnc_ui_help_cb ( GtkWidget *widget, gpointer data )
{
@ -952,7 +960,16 @@ gnc_main_create_menus(GnomeApp *app, GtkWidget *account_tree,
GNOME_APP_PIXMAP_NONE, NULL,
0, 0, NULL
},
{
GNOME_APP_UI_ITEM,
TOTD_MENU_STR_N, TOOLTIP_TOTD_N,
gnc_ui_totd_cb, NULL, NULL,
GNOME_APP_PIXMAP_NONE, NULL,
0, 0, NULL
},
GNOMEUIINFO_MENU_ABOUT_ITEM(gnc_ui_about_cb, NULL),
GNOMEUIINFO_END
};

View File

@ -139,6 +139,10 @@
"window.\nAre you sure you want to cancel?")
#define RECN_TRANS_WARN _("Warning! This is a reconciled transaction. " \
"Do you want do continue?")
#define REENABLE_TIPS_MSG _("You have disabled \"Tip of the Day\"\n" \
"You can re-enable them from the General\n" \
"section of the Preferences menu")
#define REG_CURR_MSG _("You cannot transfer funds from the %s " \
"account.\nIt does not have a matching " \
"currency.")
@ -314,6 +318,8 @@
#define TOOLTIP_SORT_BY_STMT _(TOOLTIP_SORT_BY_STMT_N)
#define TOOLTIP_STANDARD_ORD_N N_("Keep normal account order")
#define TOOLTIP_STANDARD_ORD _(TOOLTIP_STANDARD_ORD_N)
#define TOOLTIP_TOTD_N N_("Tips of the Day")
#define TOOLTIP_TOTD _(TOOLTIP_TOTD_N)
#define TOOLTIP_TRANSFER_N N_("Transfer funds from one account to "\
"another")
#define TOOLTIP_TRANSFER _(TOOLTIP_TRANSFER_N)
@ -409,6 +415,8 @@
#define SORT_ORDER_MENU_STR _(SORT_ORDER_MENU_STR_N)
#define STYLE_MENU_STR_N N_("_Style")
#define STYLE_MENU_STR _(STYLE_MENU_STR_N)
#define TOTD_MENU_STR_N N_("_Tips Of The Day")
#define TOTD_MENU_STR _(TOTD_MENU_STR_N)
#define TRANSACTION_MENU_STR_N N_("_Transaction")
#define TRANSACTION_MENU_STR _(TRANSACTION_MENU_STR_N)
#define TRANSFER_MENU_STR _("_Transfer")
@ -433,6 +441,7 @@
#define DATE_RANGE_STR _("Date Range")
#define DEL_ACC_STR _("Delete Account")
#define DEL_TRANS_STR _("Delete Transaction")
#define DISPLAY_NEXT_TIME_STR _("Display this dialog next time")
#define DOUBLE_LINE_STR_N N_("Double Line")
#define DOUBLE_LINE_STR _(DOUBLE_LINE_STR_N)
#define EDIT_ACCT_STR _("Edit Account")
@ -507,6 +516,7 @@
#define STANDARD_ORDER_STR_N N_("Standard order")
#define STANDARD_ORDER_STR _(STANDARD_ORDER_STR_N)
#define STATEMENT_DATE_C_STR _("Statement Date:")
#define TOTD_STR _("Tip of the Day:")
#define TOP_ACCT_STR _("Top level account")
#define TOTAL_SHARES_STR _("Total Shares")
#define VERIFY_CHANGES_STR _("Verify Changes")

View File

@ -33,6 +33,8 @@ gnc_regular_scm_files = \
substring-search.scm \
testbed.scm \
text-export.scm \
tip-of-the-day.scm \
tip-list.scm \
utilities.scm \
xml-generator.scm

View File

@ -123,7 +123,7 @@ gncscmdir = ${GNC_SCM_INSTALL_DIR}
gnc_autogen_scm_files = bootstrap.scm
gnc_regular_scm_files = bs-interp.scm c-interface.scm command-line.scm config-var.scm currencies.scm date-utilities.scm depend.scm doc.scm engine-interface.scm engine-utilities.scm extensions.scm graph.scm hooks.scm html-generator.scm main.scm options.scm path.scm prefs.scm report-utilities.scm report.scm slib-backup.scm startup.scm structure.scm substring-search.scm testbed.scm text-export.scm utilities.scm xml-generator.scm
gnc_regular_scm_files = bs-interp.scm c-interface.scm command-line.scm config-var.scm currencies.scm date-utilities.scm depend.scm doc.scm engine-interface.scm engine-utilities.scm extensions.scm graph.scm hooks.scm html-generator.scm main.scm options.scm path.scm prefs.scm report-utilities.scm report.scm slib-backup.scm startup.scm structure.scm substring-search.scm testbed.scm text-export.scm tip-of-the-day.scm tip-list.scm utilities.scm xml-generator.scm
gncscm_DATA = ${gnc_autogen_scm_files} ${gnc_regular_scm_files}

View File

@ -33,6 +33,8 @@
;;; permanent, and if they leave the variable value different from the
;;; default, should be saved to ~/.gnucash/config.auto.
(gnc:support "config-var.scm")
(define (gnc:make-config-var description
set-action-func
equality-func

View File

@ -21,6 +21,8 @@
;;;; This is not functional yet, but it should be close...
(gnc:support "hooks.scm")
;;; Private
;; Central repository for all hooks -- so we can look them up later by name.

View File

@ -56,6 +56,7 @@
;; eq?
;; #f))
(gnc:support "prefs.scm")
(define gnc:*options-entries* (gnc:new-options))
@ -382,6 +383,11 @@ the account instead of opening a register." #f))
"General" "Use accounting labels"
"e" "Only use 'debit' and 'credit' instead of informal synonyms" #f))
(gnc:register-configuration-option
(gnc:make-simple-boolean-option
"General" "Display \"Tip of the Day\""
"f" "Display hints for using GnuCash at startup" #t))
;(gnc:register-configuration-option
; (gnc:make-number-range-option
; "General" "Default precision"

View File

@ -34,4 +34,5 @@
(gnc:load "prefs.scm")
(gnc:load "command-line.scm")
(gnc:load "hooks.scm")
(gnc:load "tip-of-the-day.scm")
(gnc:load "main.scm")

5
src/scm/tip-list.scm Normal file
View File

@ -0,0 +1,5 @@
(
("Hello World" "I'm a teapot")
("Hi there" "Yoo hoo!")
("Misc Tips" "Yes, it's me!!")
)

110
src/scm/tip-of-the-day.scm Normal file
View File

@ -0,0 +1,110 @@
;; tip-of-the-day.scm -*-scheme-*-
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2 of
;; the License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 59 Temple Place - Suite 330 Fax: +1-617-542-2652
;; Boston, MA 02111-1307, USA gnu@gnu.org
;; Scheme functions for supporting tooltips
;; Written by Robert Merkel <rgmerk@mira.net>
;; Tips should be written as a list of lists of string. Each list of strings
;; represents one tip
(gnc:depend "config-var.scm")
(gnc:depend "prefs.scm")
(gnc:depend "hooks.scm")
(define (non-negative-integer? value)
(and (integer? value) (>= value 0)))
(define gnc:*current-tip-number*
(gnc:make-config-var
"Which tip we're up to"
; (lambda (x) (if (and (integer? x) (>= x 0)) '(x) #f))
(lambda (var value) (if (non-negative-integer? value) (list value) #f))
=
0))
(define gnc:*number-of-tips*
(gnc:make-config-var
"Total number of tips"
(lambda(var value) (if (non-negative-integer? value) (list value) #f))
=
0))
(define gnc:*tip-file*
(gnc:make-config-var
"Tip file"
(lambda (var value) (if (string? value) (list value) #f))
string=?
"tip-list.scm"))
(define gnc:*tip-list* '())
(define (string-fold list-strings concatenator)
(if (null? list-strings)
""
(string-append (car list-strings) concatenator
(string-fold (cdr list-strings) concatenator))))
(define (gnc:read-tips)
(let ((in-port (open-input-file
(gnc:find-in-directories
(gnc:config-var-value-get gnc:*tip-file*)
(gnc:config-var-value-get gnc:*load-path*)))))
(set! gnc:*tip-list* (read in-port))
(if (not (= (length gnc:*tip-list*)
(gnc:config-var-value-get gnc:*current-tip-number*)))
(begin
(gnc:config-var-value-set! gnc:*number-of-tips* #t
(length gnc:*tip-list*))
(if (<= (gnc:config-var-value-get gnc:*number-of-tips*)
(gnc:config-var-value-get gnc:*current-tip-number*))
(gnc:config-var-value-set! #t gnc:*current-tip-number 0))))
(close-port in-port)
#f))
(define (gnc:get-current-tip)
(string-fold (list-ref gnc:*tip-list*
(gnc:config-var-value-get gnc:*current-tip-number*))
"\n"))
(define (gnc:increment-tip-number)
(let ((new-value (+ (gnc:config-var-value-get gnc:*current-tip-number*) 1)))
(if (< new-value (gnc:config-var-value-get gnc:*number-of-tips*))
(gnc:config-var-value-set! gnc:*current-tip-number* #t new-value)
(gnc:config-var-value-set! gnc:*current-tip-number* #t 0))))
(define (gnc:decrement-tip-number)
(let ((new-value (- (gnc:config-var-value-get gnc:*current-tip-number*) 1)))
(if (< new-value 0)
(gnc:config-var-value-set! gnc:*current-tip-number* #t
(- (gnc:config-var-value-get
gnc:*number-of-tips*) 1))
(gnc:config-var-value-set! gnc:*current-tip-number* #t new-value))))
(gnc:read-tips)
(let ((tip-opt (gnc:lookup-global-option "General"
"Display \"Tip of the Day\"")))
(if (gnc:option-value tip-opt)
(let ((mainopen-hook (gnc:hook-lookup 'main-window-opened-hook)))
(gnc:hook-add-dangler
mainopen-hook
(lambda (window)
(gnc:ui-totd-dialog-create-and-run))))))