[Gnucash-changes] Report toolbar items work.
Joshua Sled
jsled at cvs.gnucash.org
Mon May 31 14:52:34 EDT 2004
Log Message:
-----------
Report toolbar items work.
Tags:
----
gnucash-gnome2-dev
Modified Files:
--------------
gnucash:
ChangeLog
GNOME2_STATUS
gnucash/src/report/report-gnome:
gnc-plugin-page-report.c
Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.131
retrieving revision 1.1487.2.132
diff -LChangeLog -LChangeLog -u -r1.1487.2.131 -r1.1487.2.132
--- ChangeLog
+++ ChangeLog
@@ -1,5 +1,13 @@
2004-05-31 Joshua Sled <jsled at asynchronous.org>
+ * src/report/report-gnome/gnc-plugin-page-report.c
+ (gnc_plugin_page_report_set_fwd_button),
+ (gnc_plugin_page_report_set_back_button): forw/back action sensitivity
+ (gnc_plugin_page_report_*_cb): Provide functional backing
+ [forw/back/reload/stop/export/options/print].
+
+2004-05-31 Joshua Sled <jsled at asynchronous.org>
+
* src/report/report-gnome/gnc-plugin-page-report-ui.xml: Add
report UI decl.
Index: GNOME2_STATUS
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/Attic/GNOME2_STATUS,v
retrieving revision 1.1.2.23
retrieving revision 1.1.2.24
diff -LGNOME2_STATUS -LGNOME2_STATUS -u -r1.1.2.23 -r1.1.2.24
--- GNOME2_STATUS
+++ GNOME2_STATUS
@@ -62,7 +62,7 @@
Actions
Check and Repair (all)
Reports
- Business
+ Business [see below]
Business <- remove ?
Register Toolbar
@@ -109,9 +109,6 @@
Goldberg of Gnumeric regarding Gnome Office Graphing [GOG] to be
factored out of gnumeric into libgoffice.
- - Report actions [forw/back/export/options/print] need relevant
- backing.
-
- Business reports menu
a/ one-level deeper than it should be
b/ empty
@@ -146,3 +143,5 @@
account code or the account name, but not being able to
reparent the account. (Maybe add DND support for this in the
long term?)
+
+4/ Print-preview support.
Index: gnc-plugin-page-report.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/report/report-gnome/Attic/gnc-plugin-page-report.c,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -Lsrc/report/report-gnome/gnc-plugin-page-report.c -Lsrc/report/report-gnome/gnc-plugin-page-report.c -u -r1.1.2.5 -r1.1.2.6
--- src/report/report-gnome/gnc-plugin-page-report.c
+++ src/report/report-gnome/gnc-plugin-page-report.c
@@ -28,9 +28,11 @@
#include "config.h"
+#include <errno.h>
#include <gtk/gtk.h>
#include <g-wrap-wct.h>
#include <libguile.h>
+#include <sys/stat.h>
#include "egg-menu-merge.h"
#include "gnc-component-manager.h"
@@ -38,6 +40,7 @@
#include "gnc-gnome-utils.h"
#include "gnc-html-history.h"
#include "gnc-html.h"
+#include "gnc-file-dialog.h"
#include "gnc-plugin-page-report.h"
#include "gnc-report.h"
#include "gnc-ui-util.h"
@@ -87,8 +90,8 @@
void gnc_plugin_page_report_add_edited_report(GncPluginPageReportPrivate * win, SCM report);
void gnc_plugin_page_report_raise_editor(SCM report);
-static void gnc_plugin_page_report_back_cb(EggAction *action, GncPluginPageReport *rep);
static void gnc_plugin_page_report_forw_cb(EggAction *action, GncPluginPageReport *rep);
+static void gnc_plugin_page_report_back_cb(EggAction *action, GncPluginPageReport *rep);
static void gnc_plugin_page_report_reload_cb(EggAction *action, GncPluginPageReport *rep);
static void gnc_plugin_page_report_stop_cb(EggAction *action, GncPluginPageReport *rep);
static void gnc_plugin_page_report_export_cb(EggAction *action, GncPluginPageReport *rep);
@@ -482,14 +485,20 @@
GncPluginPageReportPrivate * report = data;
SCM dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
- if (report->cur_report != SCM_BOOL_F) {
- /* it's probably already dirty, but make sure */
- scm_call_2(dirty_report, report->cur_report, SCM_BOOL_T);
-
- /* Now queue the fact that we need to reload this report */
- report->need_reload = TRUE;
- gtk_widget_queue_draw(GTK_WIDGET(report->container));
- }
+ DEBUG( "option_change" );
+ if (report->cur_report == SCM_BOOL_F)
+ return;
+ DEBUG( "set-dirty, queue-draw" );
+
+ /* it's probably already dirty, but make sure */
+ scm_call_2(dirty_report, report->cur_report, SCM_BOOL_T);
+
+ /* Now queue the fact that we need to reload this report */
+ report->need_reload = TRUE;
+ // jsled: this doesn't seem to cause any effect.
+ gtk_widget_queue_draw( GTK_WIDGET(report->container) );
+ // jsled: this does.
+ gnc_html_reload( report->html );
}
static void
@@ -542,43 +551,10 @@
{
// FIXME?
DEBUG( "report-refresh called" );
+ // something like ... gnc_plugin_page_report_redraw( NULL, (GncPluginPageReportPrivate*)data );
return;
}
-static void
-gnc_plugin_page_report_set_fwd_button(GncPluginPageReportPrivate * win, int enabled)
-{
-#if 0
- GnomeApp * app = win->mc->app;
- GnomeUIInfo * info;
-
- /* the code below is broken, so just return */
- return;
-
- if(app) {
- info = gnome_mdi_get_child_menu_info(app);
- if(info) gtk_widget_set_sensitive(info[1].widget, enabled);
- }
-#endif /* 0 -- broken */
-}
-
-static void
-gnc_plugin_page_report_set_back_button(GncPluginPageReportPrivate * win, int enabled)
-{
-#if 0
- GnomeApp * app = win->mc->app;
- GnomeUIInfo * info;
-
- /* the code below is broken, so just return */
- return;
-
- if(app) {
- info = gnome_mdi_get_child_menu_info(app);
- if(info) gtk_widget_set_sensitive(info[0].widget, enabled);
- }
-#endif /* 0 */
-}
-
static
void
gnc_plugin_page_report_destroy_widget( GncPluginPage *plugin_page )
@@ -714,23 +690,15 @@
gnc_plugin_page_add_book(parent, gnc_get_current_book());
/* Create menu and toolbar information. */
-
/* Note that we're not actually doing the merge, here ... just setup
* the UI objects. See gnc_plugin_page_report_[un]merge_actions(...) */
- // Report actions [1.<historical> order]
- // * fwd, back, reload, stop,
- // * export
- // * options
- // * print
-
action_group = egg_action_group_new ("GncPluginPageReportActions");
priv->action_group = action_group;
egg_action_group_add_actions( action_group,
report_actions,
num_report_actions,
plugin_page );
-
active_pages = g_list_append (active_pages, plugin_page);
}
@@ -781,54 +749,301 @@
gnc_plugin_page_report_destroy (win);
}
-// ------------------------------------------------------------
-// GTK ACTION CALLBACKS
+static void
+gnc_plugin_page_report_set_fwd_button(GncPluginPageReportPrivate *win, int enabled)
+{
+ GValue value = { 0 };
+ EggAction *act;
-static
-void
-gnc_plugin_page_report_back_cb( EggAction *action, GncPluginPageReport *report )
+ act = egg_action_group_get_action( win->action_group, "ReportForwAction" );
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, enabled);
+ g_object_set_property( G_OBJECT(act), "sensitive", &value );
+}
+
+static void
+gnc_plugin_page_report_set_back_button(GncPluginPageReportPrivate *win, int enabled)
{
- DEBUG( "back" );
+ GValue value = { 0 };
+ EggAction *act;
+
+ act = egg_action_group_get_action( win->action_group, "ReportBackAction" );
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, enabled);
+ g_object_set_property( G_OBJECT(act), "sensitive", &value );
}
-static
-void
+// ------------------------------------------------------------
+// GTK ACTION CALLBACKS
+
+static void
gnc_plugin_page_report_forw_cb( EggAction *action, GncPluginPageReport *report )
{
+ gnc_html_history_node * node = NULL;
+
DEBUG( "forw" );
+ gnc_html_history_forward(gnc_html_get_history(report->priv->html));
+ node = gnc_html_history_get_current(gnc_html_get_history(report->priv->html));
+ if (node) {
+ gnc_html_show_url(report->priv->html, node->type, node->location,
+ node->label, 0);
+ }
}
-static
-void
+static void
+gnc_plugin_page_report_back_cb( EggAction *action, GncPluginPageReport *report )
+{
+ gnc_html_history_node * node;
+
+ DEBUG( "back" );
+ gnc_html_history_back(gnc_html_get_history(report->priv->html));
+ node = gnc_html_history_get_current(gnc_html_get_history(report->priv->html));
+ if(node) {
+ gnc_html_show_url(report->priv->html, node->type, node->location,
+ node->label, 0);
+ }
+}
+
+static void
gnc_plugin_page_report_reload_cb( EggAction *action, GncPluginPageReport *report )
{
+ SCM dirty_report;
+
DEBUG( "reload" );
+ if (report->priv->cur_report == SCM_BOOL_F)
+ return;
+
+ DEBUG( "reload-redraw" );
+ dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
+ scm_call_2(dirty_report, report->priv->cur_report, SCM_BOOL_T);
+
+ report->priv->need_reload = TRUE;
+ /* now queue the fact that we need to reload this report */
+
+ // this doens't seem to do anything...
+ gtk_widget_queue_draw( GTK_WIDGET(report->priv->container) );
+
+ // this does...
+ gnc_html_reload( report->priv->html );
}
-static
-void
+static void
gnc_plugin_page_report_stop_cb( EggAction *action, GncPluginPageReport *report )
{
- DEBUG( "stop" );
+ gnc_html_cancel(report->priv->html);
}
-static
-void
+/* Returns SCM_BOOL_F if cancel. Returns SCM_BOOL_T if html.
+ * Otherwise returns pair from export_types. */
+static SCM
+gnc_get_export_type_choice (SCM export_types)
+{
+ GList * choices = NULL;
+ gboolean bad = FALSE;
+ GList * node;
+ int choice;
+ SCM tail;
+
+ if (!SCM_LISTP (export_types))
+ return SCM_BOOL_F;
+
+ for (tail = export_types; !SCM_NULLP (tail); tail = SCM_CDR (tail))
+ {
+ SCM pair = SCM_CAR (tail);
+ char * name;
+ SCM scm;
+
+ if (!SCM_CONSP (pair))
+ {
+ g_warning ("unexpected list element");
+ bad = TRUE;
+ break;
+ }
+
+ scm = SCM_CAR (pair);
+ if (!SCM_STRINGP (scm))
+ {
+ g_warning ("unexpected pair element");
+ bad = TRUE;
+ break;
+ }
+
+ name = gh_scm2newstr (scm, NULL);
+ choices = g_list_prepend (choices, g_strdup (name));
+ if (name) free (name);
+ }
+
+ if (!bad)
+ {
+ choices = g_list_reverse (choices);
+
+ choices = g_list_prepend (choices, g_strdup (_("HTML")));
+
+ choice = gnc_choose_radio_option_dialog
+ (NULL, _("Choose export format"),
+ _("Choose the export format for this report:"), 0, choices);
+ }
+ else
+ choice = -1;
+
+ for (node = choices; node; node = node->next)
+ g_free (node->data);
+ g_list_free (choices);
+
+ if (choice < 0)
+ return SCM_BOOL_F;
+
+ if (choice == 0)
+ return SCM_BOOL_T;
+
+ choice--;
+ if (choice >= scm_ilength (export_types))
+ return SCM_BOOL_F;
+
+ return scm_list_ref (export_types, scm_int2num (choice));
+}
+
+static char *
+gnc_get_export_filename (SCM choice)
+{
+ char * filepath;
+ struct stat statbuf;
+ char * title;
+ char * type;
+ int rc;
+
+ if (choice == SCM_BOOL_T)
+ type = g_strdup (_("HTML"));
+ else
+ {
+ char * s = gh_scm2newstr (SCM_CAR (choice), NULL);
+ type = g_strdup (s);
+ if (s) free (s);
+ }
+
+ /* %s is the type of what is about to be saved, e.g. "HTML". */
+ title = g_strdup_printf (_("Save %s To File"), type);
+
+ filepath = gnc_file_dialog (title, NULL, NULL);
+
+ g_free (title);
+ g_free (type);
+
+ if (!filepath)
+ return NULL;
+
+ rc = stat (filepath, &statbuf);
+
+ /* Check for an error that isn't a non-existant file. */
+ if (rc != 0 && errno != ENOENT)
+ {
+ /* %s is the strerror(3) string of the error that occurred. */
+ const char *format = _("You cannot save to that filename.\n\n%s");
+
+ gnc_error_dialog (NULL, format, strerror(errno));
+ g_free(filepath);
+ return NULL;
+ }
+
+ /* Check for a file that isn't a regular file. */
+ if (rc == 0 && !S_ISREG (statbuf.st_mode))
+ {
+ const char *message = _("You cannot save to that file.");
+
+ gnc_error_dialog (NULL, message);
+ g_free(filepath);
+ return NULL;
+ }
+
+ if (rc == 0)
+ {
+ const char *format = _("The file \n %s\n already exists.\n"
+ "Are you sure you want to overwrite it?");
+
+ if (!gnc_verify_dialog (NULL, FALSE, format, filepath)) {
+ g_free(filepath);
+ return NULL;
+ }
+ }
+
+ return filepath;
+}
+
+static void
gnc_plugin_page_report_export_cb( EggAction *action, GncPluginPageReport *report )
{
- DEBUG( "export" );
+ GncPluginPageReportPrivate *priv = report->priv;
+ char * filepath;
+ SCM export_types;
+ SCM export_thunk;
+ gboolean result;
+ SCM choice;
+
+ export_types = scm_call_1 (scm_c_eval_string ("gnc:report-export-types"),
+ priv->cur_report);
+
+ export_thunk = scm_call_1 (scm_c_eval_string ("gnc:report-export-thunk"),
+ priv->cur_report);
+
+ if (SCM_LISTP (export_types) && SCM_PROCEDUREP (export_thunk))
+ choice = gnc_get_export_type_choice (export_types);
+ else
+ choice = SCM_BOOL_T;
+
+ if (choice == SCM_BOOL_F)
+ return;
+
+ filepath = gnc_get_export_filename (choice);
+ if (!filepath)
+ return;
+
+ if (SCM_CONSP (choice))
+ {
+ SCM file_scm;
+ SCM res;
+
+ choice = SCM_CDR (choice);
+ file_scm = scm_makfrom0str (filepath);
+
+ res = scm_call_3 (export_thunk, priv->cur_report, choice, file_scm);
+
+ result = (res != SCM_BOOL_F);
+ }
+ else
+ result = gnc_html_export (priv->html, filepath);
+
+ if (!result)
+ {
+ const char *fmt = _("Could not open the file\n"
+ " %s\n%s");
+ gnc_error_dialog( NULL, fmt, filepath ? filepath : "(null)",
+ strerror (errno) ? strerror (errno) : "" );
+ }
+
+ g_free(filepath);
+ return;
}
-static
-void
+static void
gnc_plugin_page_report_options_cb( EggAction *action, GncPluginPageReport *report )
{
- DEBUG( "options" );
+ GncPluginPageReportPrivate *priv = report->priv;
+ SCM start_editor = scm_c_eval_string("gnc:report-edit-options");
+
+ if (priv->cur_report == SCM_BOOL_F)
+ return;
+
+ if (scm_call_1(start_editor, priv->cur_report) == SCM_BOOL_F) {
+ gnc_warning_dialog(GTK_WIDGET(gnc_ui_get_toplevel()),
+ _("There are no options for this report."));
+ }
+ else {
+ gnc_plugin_page_report_add_edited_report(priv, priv->cur_report);
+ }
}
-static
-void
+static void
gnc_plugin_page_report_print_cb( EggAction *action, GncPluginPageReport *report )
{
- DEBUG( "print" );
+ gnc_html_print(report->priv->html);
}
More information about the gnucash-changes
mailing list