r20730 - gnucash/trunk/src - Bug #651648 - Change Account period Druid to an Assistant
Geert Janssens
gjanssens at code.gnucash.org
Wed Jun 1 13:34:51 EDT 2011
Author: gjanssens
Date: 2011-06-01 13:34:51 -0400 (Wed, 01 Jun 2011)
New Revision: 20730
Trac: http://svn.gnucash.org/trac/changeset/20730
Added:
gnucash/trunk/src/gnome/assistant-acct-period.c
gnucash/trunk/src/gnome/assistant-acct-period.h
Removed:
gnucash/trunk/src/gnome/druid-acct-period.c
gnucash/trunk/src/gnome/druid-acct-period.h
gnucash/trunk/src/gnome/glade/Makefile.am
gnucash/trunk/src/gnome/glade/acctperiod.glade
Modified:
gnucash/trunk/src/engine/gnc-engine.h
gnucash/trunk/src/gnome/Makefile.am
gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c
gnucash/trunk/src/gnome/gtkbuilder/acctperiod.glade
Log:
Bug #651648 - Change Account period Druid to an Assistant
Patch by Bob
Modified: gnucash/trunk/src/engine/gnc-engine.h
===================================================================
--- gnucash/trunk/src/engine/gnc-engine.h 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/engine/gnc-engine.h 2011-06-01 17:34:51 UTC (rev 20730)
@@ -63,6 +63,7 @@
#define GNC_MOD_PREFS "gnc.pref"
#define GNC_MOD_IMPORT "gnc.import"
#define GNC_MOD_DRUID "gnc.druids"
+#define GNC_MOD_ASSISTANT "gnc.assistant"
#define GNC_MOD_TEST "gnc.tests"
#define GNC_MOD_BUDGET "gnc.budget"
//@}
Modified: gnucash/trunk/src/gnome/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome/Makefile.am 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/Makefile.am 2011-06-01 17:34:51 UTC (rev 20730)
@@ -24,6 +24,7 @@
libgnc_gnome_la_SOURCES = \
swig-gnome.c \
+ assistant-acct-period.c \
assistant-hierarchy.c \
assistant-stock-split.c \
dialog-commodities.c \
@@ -38,7 +39,6 @@
dialog-sx-from-trans.c \
dialog-sx-since-last-run.c \
dialog-tax-info.c \
- druid-acct-period.c \
druid-loan.c \
gnc-plugin-account-tree.c \
gnc-plugin-basic-commands.c \
@@ -64,6 +64,7 @@
appicondir = $(datadir)/pixmaps
noinst_HEADERS = \
+ assistant-acct-period.h \
assistant-hierarchy.h \
assistant-stock-split.h \
dialog-fincalc.h \
@@ -74,7 +75,6 @@
dialog-sx-editor.h \
dialog-sx-from-trans.h \
dialog-sx-since-last-run.h \
- druid-acct-period.h \
druid-loan.h \
gnc-plugin-account-tree.h \
gnc-plugin-basic-commands.h \
Copied: gnucash/trunk/src/gnome/assistant-acct-period.c (from rev 20729, gnucash/trunk/src/gnome/druid-acct-period.c)
===================================================================
--- gnucash/trunk/src/gnome/assistant-acct-period.c (rev 0)
+++ gnucash/trunk/src/gnome/assistant-acct-period.c 2011-06-01 17:34:51 UTC (rev 20730)
@@ -0,0 +1,700 @@
+/********************************************************************\
+ * assistant-acct-period.c - accouting period assistant for GnuCash *
+ * Copyright (C) 2001 Gnumatic, Inc. *
+ * Copyright (C) 2001 Dave Peticolas <dave at krondo.com> *
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org> *
+ * Copyright (C) 2011 Robert Fewell *
+ * *
+ * 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 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+\********************************************************************/
+/*************************************************************************\
+ * This is still a work in progress so may damage your data, to enable *
+ * for testing do the following :- *
+ * Add a define entry to gnc-plugin-basic-commands.c as below *
+ * #define CLOSE_BOOKS_ACTUALLY_WORKS *
+ * *
+ * Add the following to gnc-plugin-basic-commands-ui.xml on line 43 *
+ * <menuitem name="ActionsCloseBooks" action="ActionsCloseBooksAction"/> *
+\*************************************************************************/
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "Recurrence.h"
+#include "Period.h"
+#include "Query.h"
+#include "Scrub.h"
+#include "Scrub3.h"
+#include "Transaction.h"
+#include "dialog-utils.h"
+#include "assistant-acct-period.h"
+#include "assistant-utils.h"
+#include "gnc-component-manager.h"
+#include "qof.h"
+#include "gnc-file.h"
+#include "gnc-frequency.h"
+#include "gnc-gdate-utils.h"
+#include "gnc-gui-query.h"
+#include "gnc-ui-util.h"
+#include "misc-gnome-utils.h"
+#include "gnc-session.h"
+
+#define ASSISTANT_ACCT_PERIOD_CM_CLASS "assistant-acct-period"
+/*#define REALLY_DO_CLOSE_BOOKS */
+
+static QofLogModule log_module = GNC_MOD_ASSISTANT;
+
+/** structures *********************************************************/
+typedef struct
+{
+ GtkWidget * window;
+ GtkWidget * assistant;
+ GncFrequency *period_menu;
+ GtkWidget * period_remarks;
+ GtkWidget * close_results;
+ GtkWidget * book_details;
+ GtkWidget * book_title;
+ GtkTextView * book_notes;
+ GtkWidget * apply_label;
+ GtkWidget * summary;
+
+ time_t earliest;
+ char * earliest_str;
+ GDate closing_date;
+ GDate prev_closing_date;
+ GList *period;
+ int close_status;
+
+} AcctPeriodInfo;
+
+/* =============================================================== */
+
+void ap_assistant_window_destroy_cb (GtkObject *object, gpointer user_data);
+void ap_assistant_prepare (GtkAssistant *assistant, GtkWidget *page,
+ gpointer user_data);
+void ap_assistant_menu_prepare (GtkAssistant *assistant, gpointer user_data);
+void ap_assistant_book_prepare (GtkAssistant *assistant, gpointer user_data);
+void ap_assistant_apply_prepare (GtkAssistant *assistant, gpointer user_data);
+void ap_assistant_summary_prepare (GtkAssistant *assistant, gpointer user_data);
+
+gboolean ap_validate_menu (GtkAssistant *assistant, gpointer user_data);
+
+void ap_assistant_finish (GtkAssistant *gtkassistant, gpointer user_data);
+void ap_assistant_cancel (GtkAssistant *gtkassistant, gpointer user_data);
+void ap_assistant_close (GtkAssistant *gtkassistant, gpointer user_data);
+
+/* =============================================================== */
+/* Find the earliest date occuring in the book. Do this by making
+ * a query and sorting by date. Since the truncated sort returns
+ * only the *last* search results, sort in decreasing order.
+ */
+static time_t
+get_earliest_in_book (QofBook *book)
+{
+ QofQuery *q;
+ GSList *p1, *p2;
+ GList *res;
+ time_t earliest;
+
+ q = qof_query_create_for(GNC_ID_SPLIT);
+ qof_query_set_max_results(q, 1);
+ qof_query_set_book (q, book);
+
+ /* Sort by transaction date */
+ p1 = g_slist_prepend (NULL, TRANS_DATE_POSTED);
+ p1 = g_slist_prepend (p1, SPLIT_TRANS);
+ p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT);
+ qof_query_set_sort_order (q, p1, p2, NULL);
+
+ /* Reverse the sort order */
+ qof_query_set_sort_increasing (q, FALSE, FALSE, FALSE);
+
+ /* Run the query, find the earliest transaction date */
+ res = qof_query_run (q);
+
+ if (res)
+ {
+ earliest = xaccQueryGetEarliestDateFound (q);
+ }
+ else
+ {
+ /* If no results, we don't want to bomb totally */
+ earliest = time (0);
+ }
+
+ qof_query_destroy (q);
+ return earliest;
+}
+
+/* =============================================================== */
+/* Find the number of transactions occuring before the indicated date.
+ * Do this by making a query and counting the results.
+ */
+
+static int
+get_num_xactions_before_date(QofBook *book, time_t close_date)
+{
+ QofQuery *q;
+ GSList *param;
+ QofQueryPredData *pred;
+ Timespec ts;
+ GList *res, *n;
+ int cnt = 0;
+
+ q = qof_query_create_for(GNC_ID_TRANS);
+ qof_query_set_max_results(q, -1);
+ qof_query_set_book (q, book);
+
+ /* Look for transactions earlier than the closing date */
+ param = g_slist_prepend (NULL, TRANS_DATE_POSTED);
+ timespecFromTime_t (&ts, close_date);
+ pred = qof_query_date_predicate (QOF_COMPARE_LTE, QOF_DATE_MATCH_NORMAL, ts);
+ qof_query_add_term (q, param, pred, QOF_QUERY_FIRST_TERM);
+
+ /* Run the query, find how many transactions there are */
+ res = qof_query_run (q);
+
+ cnt = 0;
+ for (n = res; n; n = n->next) cnt ++;
+
+ qof_query_destroy (q);
+ return cnt;
+}
+
+/* =============================================================== */
+
+static const char *
+get_close_status_str (AcctPeriodInfo *info)
+{
+ const char * str;
+
+ /* Tell user about how the previous book closing went. */
+ switch (info->close_status)
+ {
+ case -1:
+ str = "";
+ break;
+ case 0:
+ str = _("The book was closed successfully.");
+ break;
+ default:
+ str = "";
+ }
+ return str;
+}
+
+/* =============================================================== */
+
+static void
+ap_assistant_destroy_cb (GtkObject *object, gpointer data)
+{
+ AcctPeriodInfo *info = data;
+
+ gnc_unregister_gui_component_by_data (ASSISTANT_ACCT_PERIOD_CM_CLASS, info);
+
+ // do we need gnc_frequency_destroy or is this automatic ??
+ recurrenceListFree(&info->period);
+ g_free (info->earliest_str);
+ g_free (info);
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_cancel (GtkAssistant *assistant, gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+ gnc_close_gui_component_by_data (ASSISTANT_ACCT_PERIOD_CM_CLASS, info);
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_close (GtkAssistant *assistant, gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+ gnc_close_gui_component_by_data (ASSISTANT_ACCT_PERIOD_CM_CLASS, info);
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_prepare (GtkAssistant *assistant, GtkWidget *page,
+ gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+ gint currentpage = gtk_assistant_get_current_page(assistant);
+
+ switch (currentpage)
+ {
+ case 1:
+ /* Current page is Menu page */
+ ap_assistant_menu_prepare(assistant, user_data);
+ break;
+ case 2:
+ /* Current page is Book page */
+ ap_assistant_book_prepare (assistant, user_data);
+ break;
+ case 3:
+ /* Current page is Apply page */
+ ap_assistant_apply_prepare (assistant, user_data);
+ break;
+ case 4:
+ /* Current page is Summary page */
+ ap_assistant_summary_prepare (assistant, user_data);
+ break;
+ }
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_menu_prepare (GtkAssistant *assistant, gpointer user_data)
+{
+ int nperiods;
+ GDate period_begin, period_end, date_now;
+ const char *remarks_text;
+ char * str;
+
+ AcctPeriodInfo *info = user_data;
+
+ ENTER ("info=%p", info);
+
+ /* Pull info from widget, push into freq spec */
+ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
+ recurrenceListFree(&info->period);
+ gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);
+
+ /* Count the number of periods that would be generated. */
+ g_date_clear (&period_begin, 1);
+ g_date_clear (&period_end, 1);
+ g_date_clear (&date_now, 1);
+ nperiods = 0;
+ period_end = info->closing_date;
+ g_date_set_time_t (&date_now, time(NULL));
+
+ while (0 > g_date_compare(&period_end, &date_now ))
+ {
+ nperiods ++;
+ PINFO ("Period = %d and End date is %d/%d/%d", nperiods,
+ g_date_get_month(&period_end),
+ g_date_get_day(&period_end),
+ g_date_get_year(&period_end));
+ period_begin = period_end;
+ recurrenceListNextInstance(info->period, &period_begin, &period_end);
+
+ /* FIXME Check for valid period_end, not sure why it wont be!!! */
+ if (g_date_valid (&period_end) != TRUE)
+ break;
+ }
+
+ /* Find the date of the earliest transaction in the current book.
+ * Note that this could have changed since last time, since
+ * we may have closed books since last time. */
+ info->earliest = get_earliest_in_book (gnc_get_current_book());
+ info->earliest_str = qof_print_date(info->earliest);
+ PINFO ("Date of earliest transaction is %ld %s", info->earliest, ctime (&info->earliest));
+
+ /* Display the results */
+ remarks_text =
+ _("The earliest transaction date found in this book is %s. "
+ "Based on the selection made above, this book will be split "
+ "into %d books.");
+ str = g_strdup_printf (remarks_text, info->earliest_str, nperiods);
+ gtk_label_set_text (GTK_LABEL(info->period_remarks), str);
+ g_free (str);
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_book_prepare (GtkAssistant *assistant, gpointer user_data)
+{
+ QofBook *currbook;
+ char close_date_str[MAX_DATE_LENGTH];
+ char prev_close_date_str[MAX_DATE_LENGTH];
+ const char *period_text;
+ char *str;
+ const char *cstr;
+ int ntrans, nacc;
+ GtkTextBuffer *buffer;
+
+ AcctPeriodInfo *info = user_data;
+
+ ENTER ("info=%p", info);
+
+ /* Tell user about how the previous book closing went. */
+ cstr = get_close_status_str (info);
+ gtk_label_set_text (GTK_LABEL(info->close_results), cstr);
+ info->close_status = -1;
+
+ /* Pull info from widget, push into freq spec */
+ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
+ recurrenceListFree(&info->period);
+ gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);
+
+ qof_print_date_dmy_buff (close_date_str, MAX_DATE_LENGTH,
+ g_date_get_day(&info->closing_date),
+ g_date_get_month(&info->closing_date),
+ g_date_get_year(&info->closing_date));
+
+ currbook = gnc_get_current_book();
+ ntrans = get_num_xactions_before_date(currbook,
+ gnc_timet_get_day_end_gdate (&info->closing_date));
+
+ nacc = gnc_account_n_descendants (gnc_book_get_root_account (currbook));
+
+ /* Display the book info */
+ period_text =
+ _("You have asked for a book to be created. This book "
+ "will contain all transactions up to midnight %s "
+ "(for a total of %d transactions spread over %d accounts).\n\n "
+ "Amend the Title and Notes or Click on 'Forward' to procede.\n "
+ "Click on 'Back' to adjust the dates or 'Cancel'.");
+ str = g_strdup_printf (period_text, close_date_str, ntrans, nacc);
+ gtk_label_set_text (GTK_LABEL(info->book_details), str);
+ g_free (str);
+
+ gtk_widget_show (GTK_WIDGET (info->book_details));
+
+ /* Create default settings for the title, notes fields */
+ qof_print_date_dmy_buff (prev_close_date_str, MAX_DATE_LENGTH,
+ g_date_get_day(&info->prev_closing_date),
+ g_date_get_month(&info->prev_closing_date),
+ g_date_get_year(&info->prev_closing_date));
+
+ str = g_strdup_printf (_("Period %s - %s"), prev_close_date_str, close_date_str);
+ gtk_entry_set_text (GTK_ENTRY(info->book_title), str);
+
+ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(info->book_notes));
+ gtk_text_buffer_set_text(buffer, str, -1);
+
+ g_free (str);
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_apply_prepare (GtkAssistant *assistant, gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+ const char *apply_text;
+ const char *btitle;
+ char *str;
+ apply_text =
+ _("The book will be created with the title %s when you\n\n"
+ "Click on 'Apply', Click on 'Back' to adjust or 'Cancel'.");
+
+ btitle = gtk_entry_get_text (GTK_ENTRY(info->book_title));
+ str = g_strdup_printf (apply_text, btitle);
+ gtk_label_set_text (GTK_LABEL(info->apply_label), str);
+ g_free (str);
+}
+
+/* =============================================================== */
+
+static void
+ap_assistant_menu_changed_cb (GtkWidget *widget, gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+ GtkAssistant *assistant = GTK_ASSISTANT(info->window);
+ gint num = gtk_assistant_get_current_page (assistant);
+ GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
+
+ ENTER ("info=%p", info);
+ ap_assistant_menu_prepare (assistant, info);
+ gtk_assistant_set_page_complete (assistant, page, ap_validate_menu (assistant, user_data));
+}
+
+/* =============================================================== */
+
+gboolean
+ap_validate_menu (GtkAssistant *assistant, gpointer user_data)
+{
+ GDate date_now;
+ AcctPeriodInfo *info = user_data;
+ ENTER("info=%p", info);
+
+ /* Pull info from widget, push into freq spec */
+ //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
+ recurrenceListFree(&info->period);
+ gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);
+
+ if (0 <= g_date_compare(&info->prev_closing_date, &info->closing_date))
+ {
+ /* Closing date must be greater than closing date of previous book */
+ return FALSE;
+ }
+
+ g_date_clear (&date_now, 1);
+ g_date_set_time_t (&date_now, time(NULL));
+ if (0 < g_date_compare(&info->closing_date, &date_now))
+ {
+ /* Closing date must be in the future */
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/* =============================================================== */
+
+static void
+scrub_all(void)
+{
+ Account *root = gnc_get_current_root_account ();
+ xaccAccountTreeScrubOrphans (root);
+ xaccAccountTreeScrubImbalance (root);
+ // XXX: Lots are disabled
+ // xaccAccountTreeScrubLots (root);
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_finish (GtkAssistant *assistant, gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+ GtkTextBuffer * buffer;
+ GtkTextIter startiter,enditer;
+ gint len;
+ QofBook *closed_book = NULL, *current_book;
+ const char *btitle;
+ char *bnotes;
+ Timespec closing_date;
+ KvpFrame *book_frame;
+ gboolean really_do_close_books = FALSE;
+
+ ENTER("info=%p", info);
+
+ current_book = gnc_get_current_book ();
+
+ btitle = gtk_entry_get_text (GTK_ENTRY(info->book_title));
+ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(info->book_notes));
+ len = gtk_text_buffer_get_char_count (buffer);
+ gtk_text_buffer_get_iter_at_offset(buffer, &startiter, 0);
+ gtk_text_buffer_get_iter_at_offset(buffer, &enditer, len);
+
+ bnotes = gtk_text_buffer_get_text(buffer,&startiter,&enditer ,0);
+ PINFO("Book title is - %s\n", btitle);
+
+ timespecFromTime_t (&closing_date,
+ gnc_timet_get_day_end_gdate (&info->closing_date));
+
+#ifdef REALLY_DO_CLOSE_BOOKS
+ really_do_close_books = TRUE;
+#endif /* REALLY_DO_CLOSE_BOOKS */
+
+ if (really_do_close_books)
+ {
+ /* Close the books ! */
+ qof_event_suspend ();
+ gnc_suspend_gui_refresh ();
+
+ scrub_all();
+ closed_book = gnc_book_close_period (current_book, closing_date, NULL, btitle);
+
+ book_frame = qof_book_get_slots(closed_book);
+ kvp_frame_set_str (book_frame, "/book/title", btitle);
+ kvp_frame_set_str (book_frame, "/book/notes", bnotes);
+
+ qof_session_add_book (gnc_get_current_session(), closed_book);
+
+ /* We must save now; if we don't, and the user bails without saving,
+ * then opening account balances will be incorrect, and this can only
+ * lead to unhappiness.
+ */
+ gnc_file_save ();
+ gnc_resume_gui_refresh ();
+ qof_event_resume ();
+ gnc_gui_refresh_all (); /* resume above should have been enough ??? */
+ }
+ g_free(bnotes);
+
+ /* Report the status back to the user. */
+ info->close_status = 0; /* XXX fixme success or failure? */
+
+ /* Find the next closing date ... */
+ info->prev_closing_date = info->closing_date;
+ recurrenceListNextInstance(info->period, &info->prev_closing_date, &info->closing_date);
+
+
+ /* FIXME Test for valid closing date, not sure why it wont be!!! */
+ if(g_date_valid(&info->closing_date) == TRUE)
+ {
+ /* If the next closing date is in the future, then we are done. */
+ if (time(NULL) > gnc_timet_get_day_end_gdate (&info->closing_date))
+ {
+ /* Load up the GUI for the next closing period. */
+ gnc_frequency_setup_recurrence(info->period_menu, NULL, &info->closing_date);
+ /* Jump back to the Close Book page. */
+ gtk_assistant_set_current_page (GTK_ASSISTANT(info->window),1);
+ }
+ }
+}
+
+/* =============================================================== */
+
+void
+ap_assistant_summary_prepare (GtkAssistant *assistant, gpointer user_data)
+{
+ const char *msg;
+ char *str;
+ AcctPeriodInfo *info = user_data;
+ ENTER ("info=%p", info);
+
+ /* Translation FIXME: Can this %s-containing message please be
+ replaced by one single message? Either this closing went
+ successfully ("success", "congratulations") or something else
+ should be displayed anyway. */
+ msg = _("%s\nCongratulations! You are done closing books!\n");
+
+ str = g_strdup_printf (msg, get_close_status_str (info));
+ gtk_label_set_text (GTK_LABEL(info->summary), str);
+ g_free (str);
+
+}
+
+/* =============================================================== */
+
+static GtkWidget *
+ap_assistant_create (AcctPeriodInfo *info)
+{
+ GtkBuilder *builder;
+ GtkWidget *window;
+ GtkWidget *box;
+
+ builder = gtk_builder_new();
+ gnc_builder_add_from_file (builder ,"acctperiod.glade", "Account Period Assistant");
+ window = GTK_WIDGET(gtk_builder_get_object (builder, "Account Period Assistant"));
+ info->window = window;
+
+ /* Set the assistant colors */
+ gnc_assistant_set_colors (GTK_ASSISTANT (info->window));
+
+ /* Enable all pages except menu page. */
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
+ GTK_WIDGET(gtk_builder_get_object(builder, "start_page")),
+ TRUE);
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
+ GTK_WIDGET(gtk_builder_get_object(builder, "book_page")),
+ TRUE);
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
+ GTK_WIDGET(gtk_builder_get_object(builder, "finish_page")),
+ TRUE);
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (window),
+ GTK_WIDGET(gtk_builder_get_object(builder, "summary_page")),
+ TRUE);
+
+ info->close_status = -1;
+
+ /* Find the date of the earliest transaction in the book.
+ * Add a year minus a day as the first guess for book closing,
+ * and use that to set up the freq spec widget. */
+ info->earliest = get_earliest_in_book (gnc_get_current_book());
+ info->earliest_str = qof_print_date(info->earliest);
+ PINFO ("date of earliest transaction is %ld %s",
+ info->earliest, ctime (&info->earliest));
+
+ g_date_clear (&info->closing_date, 1);
+ g_date_set_time_t (&info->closing_date, info->earliest);
+ g_date_clear (&info->prev_closing_date, 1);
+ info->prev_closing_date = info->closing_date;
+ g_date_add_years (&info->closing_date, 1);
+
+ {
+ Recurrence *r = g_new0(Recurrence, 1);
+ recurrenceSet(r, 1, PERIOD_MONTH, &info->closing_date, WEEKEND_ADJ_NONE);
+ info->period = NULL;
+ info->period = g_list_append(info->period, r);
+ }
+
+ info->period_menu = GNC_FREQUENCY(
+ gnc_frequency_new_from_recurrence(info->period, &info->closing_date));
+
+ /* Change the text so that its more mainingful for this assistant */
+ gnc_frequency_set_frequency_label_text(info->period_menu, _("Period:"));
+ gnc_frequency_set_date_label_text(info->period_menu, _("Closing Date:"));
+
+ /* Reparent to the correct location */
+
+ box = GTK_WIDGET(gtk_builder_get_object(builder, "period_hbox"));
+ gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (info->period_menu), TRUE, TRUE, 0);
+ g_signal_connect (info->period_menu, "changed",
+ G_CALLBACK (ap_assistant_menu_changed_cb), info);
+
+ /* Get handles to all of the other widgets we'll need */
+ info->period_remarks = GTK_WIDGET(gtk_builder_get_object(builder, "remarks_label"));
+
+ info->close_results = GTK_WIDGET(gtk_builder_get_object(builder, "results_label"));
+
+ info->book_details = GTK_WIDGET(gtk_builder_get_object(builder, "book_label"));
+
+ info->book_title = GTK_WIDGET(gtk_builder_get_object(builder, "book_title_entry"));
+
+ info->book_notes = GTK_TEXT_VIEW(gtk_builder_get_object(builder, "book_notes_view"));
+
+ info->apply_label = GTK_WIDGET(gtk_builder_get_object(builder, "finish_page"));
+
+ info->summary = GTK_WIDGET(gtk_builder_get_object(builder, "summary_label"));
+
+ g_signal_connect (G_OBJECT(window), "destroy",
+ G_CALLBACK (ap_assistant_destroy_cb), info);
+
+ gtk_builder_connect_signals(builder, info);
+ g_object_unref(G_OBJECT(builder));
+ return window;
+}
+
+/* =============================================================== */
+
+static void
+ap_close_handler (gpointer user_data)
+{
+ AcctPeriodInfo *info = user_data;
+
+ gtk_widget_destroy (info->window);
+}
+
+/********************************************************************\
+ * gnc_acct_period_dialog *
+ * opens up a assistant to configure accounting periods *
+ * *
+ * Args: none *
+ * Return: nothing *
+\********************************************************************/
+
+void
+gnc_acct_period_dialog (void)
+{
+ AcctPeriodInfo *info;
+ gint component_id;
+
+ info = g_new0 (AcctPeriodInfo, 1);
+
+ ap_assistant_create (info);
+
+ component_id = gnc_register_gui_component (ASSISTANT_ACCT_PERIOD_CM_CLASS,
+ NULL, ap_close_handler,
+ info);
+
+ gtk_widget_show_all (info->window);
+
+ gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
+}
Copied: gnucash/trunk/src/gnome/assistant-acct-period.h (from rev 20729, gnucash/trunk/src/gnome/druid-acct-period.h)
===================================================================
--- gnucash/trunk/src/gnome/assistant-acct-period.h (rev 0)
+++ gnucash/trunk/src/gnome/assistant-acct-period.h 2011-06-01 17:34:51 UTC (rev 20730)
@@ -0,0 +1,36 @@
+/********************************************************************\
+ * assistant-acct-period.h - accounting period assistant for GnuCash*
+ * Copyright (C) 2003 Linas Vepstas <linas at linas.org> *
+ * Copyright (C) 2011 Robert Fewell *
+ * *
+ * 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 *
+ * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
+ * Boston, MA 02110-1301, USA gnu at gnu.org *
+\********************************************************************/
+
+#ifndef GNC_ASSISTANT_ACCT_PERIOD_H
+#define GNC_ASSISTANT_ACCT_PERIOD_H
+
+/********************************************************************\
+ * gnc_acct_period_dialog *
+ * opens up a window to set up accounting period *
+ * *
+ * Args: none *
+ * Return: nothing *
+\********************************************************************/
+void gnc_acct_period_dialog (void);
+
+#endif
Deleted: gnucash/trunk/src/gnome/druid-acct-period.c
===================================================================
--- gnucash/trunk/src/gnome/druid-acct-period.c 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/druid-acct-period.c 2011-06-01 17:34:51 UTC (rev 20730)
@@ -1,648 +0,0 @@
-/********************************************************************\
- * druid-acct-period.c -- accouting period druid for GnuCash *
- * Copyright (C) 2001 Gnumatic, Inc. *
- * Copyright (C) 2001 Dave Peticolas <dave at krondo.com> *
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org> *
- * *
- * 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 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
-\********************************************************************/
-
-#include "config.h"
-
-#include <gnome.h>
-#include <glib/gi18n.h>
-
-#include "Recurrence.h"
-#include "Period.h"
-#include "Query.h"
-#include "Scrub.h"
-#include "Scrub3.h"
-#include "Transaction.h"
-#include "dialog-utils.h"
-#include "druid-acct-period.h"
-#include "druid-utils.h"
-#include "gnc-component-manager.h"
-#include "qof.h"
-#include "gnc-file.h"
-#include "gnc-frequency.h"
-#include "gnc-gdate-utils.h"
-#include "gnc-gui-query.h"
-#include "gnc-ui-util.h"
-#include "misc-gnome-utils.h"
-#include "gnc-session.h"
-
-#define DRUID_ACCT_PERIOD_CM_CLASS "druid-acct-period"
-
-static QofLogModule log_module = GNC_MOD_DRUID;
-
-/** structures *********************************************************/
-typedef struct
-{
- GtkWidget * window;
- GnomeDruid * druid;
- GnomeDruidPage *start_page;
- GnomeDruidPage *menu_page;
- GnomeDruidPage *book_page;
- GnomeDruidPage *finish_page;
- GncFrequency *period_menu;
- GtkLabel * period_remarks;
- GtkLabel * close_results;
- GtkLabel * book_details;
- GtkEntry * book_title;
- GtkTextView * book_notes;
-
- time_t earliest;
- char * earliest_str;
- GDate closing_date;
- GDate prev_closing_date;
- GList *period;
- int close_status;
-
-} AcctPeriodInfo;
-
-
-/* =============================================================== */
-/* Find the earliest date occuring in the book. Do this by making
- * a query and sorting by date. Since the truncated sort returns
- * only the *last* search results, sort in decreasing order.
- */
-static time_t
-get_earliest_in_book (QofBook *book)
-{
- QofQuery *q;
- GSList *p1, *p2;
- GList *res;
- time_t earliest;
-
- q = qof_query_create_for(GNC_ID_SPLIT);
- qof_query_set_max_results(q, 1);
- qof_query_set_book (q, book);
-
- /* Sort by transaction date */
- p1 = g_slist_prepend (NULL, TRANS_DATE_POSTED);
- p1 = g_slist_prepend (p1, SPLIT_TRANS);
- p2 = g_slist_prepend (NULL, QUERY_DEFAULT_SORT);
- qof_query_set_sort_order (q, p1, p2, NULL);
-
- /* Reverse the sort order */
- qof_query_set_sort_increasing (q, FALSE, FALSE, FALSE);
-
- /* Run the query, find the earliest transaction date */
- res = qof_query_run (q);
-
- if (res)
- {
- earliest = xaccQueryGetEarliestDateFound (q);
- }
- else
- {
- /* If no results, we don't want to bomb totally */
- earliest = time (0);
- }
-
- qof_query_destroy (q);
- return earliest;
-}
-
-/* =============================================================== */
-/* Find the number of transactions occuring before the indicated date.
- * Do this by making a query and counting the results.
- */
-
-static int
-get_num_xactions_before_date(QofBook *book, time_t close_date)
-{
- QofQuery *q;
- GSList *param;
- QofQueryPredData *pred;
- Timespec ts;
- GList *res, *n;
- int cnt = 0;
-
- q = qof_query_create_for(GNC_ID_TRANS);
- qof_query_set_max_results(q, -1);
- qof_query_set_book (q, book);
-
- /* Look for transactions earlier than the closing date */
- param = g_slist_prepend (NULL, TRANS_DATE_POSTED);
- timespecFromTime_t (&ts, close_date);
- pred = qof_query_date_predicate (QOF_COMPARE_LTE, QOF_DATE_MATCH_NORMAL, ts);
- qof_query_add_term (q, param, pred, QOF_QUERY_FIRST_TERM);
-
- /* Run the query, find how many transactions there are */
- res = qof_query_run (q);
-
- cnt = 0;
- for (n = res; n; n = n->next) cnt ++;
-
- qof_query_destroy (q);
- return cnt;
-}
-
-/* =============================================================== */
-
-static const char *
-get_close_status_str (AcctPeriodInfo *info)
-{
- const char * str;
-
- /* Tell user about how the previous book closing went. */
- switch (info->close_status)
- {
- case -1:
- str = "";
- break;
- case 0:
- str = _("The book was closed successfully.");
- break;
- default:
- str = "";
- }
- return str;
-}
-
-/* =============================================================== */
-
-static void
-ap_window_destroy_cb (GtkObject *object, gpointer data)
-{
- AcctPeriodInfo *info = data;
-
- gnc_unregister_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info);
-
- // do we need gnc_frequency_destroy or is this automatic ??
- recurrenceListFree(&info->period);
- g_free (info->earliest_str);
- g_free (info);
-}
-
-static void
-ap_finish (GnomeDruidPageEdge *druidpage,
- GtkWidget *druid,
- gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
- gnc_close_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info);
-}
-
-static void
-ap_druid_cancel (GnomeDruid *druid, gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
- gnc_close_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info);
-}
-
-/* =============================================================== */
-
-static void
-prepare_remarks (AcctPeriodInfo *info)
-{
- int nperiods;
- GDate period_begin, period_end, date_now;
- const char *remarks_text;
- char * str;
- ENTER ("info=%p", info);
-
- /* Pull info from widget, push into freq spec */
- //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
- recurrenceListFree(&info->period);
- gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);
-
- /* Count the number of periods that would be generated. */
- g_date_clear (&period_begin, 1);
- g_date_clear (&period_end, 1);
- g_date_clear (&date_now, 1);
- nperiods = 0;
- period_end = info->closing_date;
- g_date_set_time_t (&date_now, time(NULL));
-
- while (0 > g_date_compare(&period_end, &date_now ))
- {
- nperiods ++;
- PINFO ("period=%d end date=%d/%d/%d", nperiods,
- g_date_get_month(&period_end),
- g_date_get_day(&period_end),
- g_date_get_year(&period_end));
- period_begin = period_end;
- recurrenceListNextInstance(info->period, &period_begin, &period_end);
- }
-
- /* Display the results */
- remarks_text =
- _("The earliest transaction date found in this book is %s. "
- "Based on the selection made above, this book will be split "
- "into %d books. Click on 'Forward' to start closing the "
- "earliest book.");
- str = g_strdup_printf (remarks_text, info->earliest_str, nperiods);
- gtk_label_set_text (info->period_remarks, str);
- g_free (str);
-}
-
-/* =============================================================== */
-
-static void
-show_book_details (AcctPeriodInfo *info)
-{
- QofBook *currbook;
- char close_date_str[MAX_DATE_LENGTH];
- char prev_close_date_str[MAX_DATE_LENGTH];
- const char *period_text;
- char *str;
- const char *cstr;
- int ntrans, nacc;
-
- ENTER ("info=%p", info);
-
- /* Tell user about how the previous book closing went. */
- cstr = get_close_status_str (info);
- gtk_label_set_text (info->close_results, cstr);
- info->close_status = -1;
-
- /* Pull info from widget, push into freq spec */
- //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
- recurrenceListFree(&info->period);
- gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);
-
- qof_print_date_dmy_buff (close_date_str, MAX_DATE_LENGTH,
- g_date_get_day(&info->closing_date),
- g_date_get_month(&info->closing_date),
- g_date_get_year(&info->closing_date));
-
- currbook = gnc_get_current_book();
- ntrans = get_num_xactions_before_date(currbook,
- gnc_timet_get_day_end_gdate (&info->closing_date));
-
- nacc = gnc_account_n_descendants (gnc_book_get_root_account (currbook));
-
- /* Display the book info */
- period_text =
- _("You have asked for a book to be created. This book "
- "will contain all transactions up to midnight %s "
- "(for a total of %d transactions spread over %d accounts). "
- "Click on 'Forward' to create this book. "
- "Click on 'Back' to adjust the dates.");
- str = g_strdup_printf (period_text, close_date_str, ntrans, nacc);
- gtk_label_set_text (info->book_details, str);
- g_free (str);
-
- /* Weird bug fix ! */
- gtk_widget_show (GTK_WIDGET (info->book_details));
-
- /* Create default settings for the title, notes fields */
- qof_print_date_dmy_buff (prev_close_date_str, MAX_DATE_LENGTH,
- g_date_get_day(&info->prev_closing_date),
- g_date_get_month(&info->prev_closing_date),
- g_date_get_year(&info->prev_closing_date));
-
- str = g_strdup_printf (_("Period %s - %s"), prev_close_date_str, close_date_str);
- gtk_entry_set_text (info->book_title, str);
- xxxgtk_textview_set_text (info->book_notes, str);
- g_free (str);
-
-}
-
-/* =============================================================== */
-
-static void
-ap_changed (GtkWidget *widget, gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
-
- ENTER ("info=%p", info);
- prepare_remarks (info);
-}
-
-
-static void
-ap_show_menu (GnomeDruidPage *druidpage,
- GtkWidget *druid,
- gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
- ENTER("info=%p", info);
-
- /* Find the date of the earliest transaction in the current book.
- * Note that this could have changed since last time, since
- * we may have closed books since last time. */
- info->earliest = get_earliest_in_book (gnc_get_current_book());
- info->earliest_str = qof_print_date(info->earliest);
- PINFO ("date of earliest is %ld %s", info->earliest, ctime (&info->earliest));
-
- prepare_remarks (info);
-}
-
-static gboolean
-ap_validate_menu (GnomeDruidPage *druidpage,
- GtkWidget *druid,
- gpointer user_data)
-{
- GDate date_now;
- AcctPeriodInfo *info = user_data;
- ENTER("info=%p", info);
-
- /* Pull info from widget, push into freq spec */
- //gnc_frequency_save_state (info->period_menu, info->period, &info->closing_date);
- recurrenceListFree(&info->period);
- gnc_frequency_save_to_recurrence(info->period_menu, &info->period, &info->closing_date);
-
- if (0 <= g_date_compare(&info->prev_closing_date, &info->closing_date))
- {
- const char *msg = _("You must select closing date that "
- "is greater than the closing date "
- "of the previous book.");
- gnc_error_dialog (info->window, "%s", msg);
- return TRUE;
- }
-
- g_date_clear (&date_now, 1);
- g_date_set_time_t (&date_now, time(NULL));
- if (0 < g_date_compare(&info->closing_date, &date_now))
- {
- const char *msg = _("You must select closing date "
- "that is not in the future.");
- gnc_error_dialog (info->window, "%s", msg);
- return TRUE;
- }
- return FALSE;
-}
-
-/* =============================================================== */
-
-static void
-ap_show_book (GnomeDruidPage *druidpage,
- GtkWidget *druid,
- gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
-
- ENTER ("info=%p", info);
- show_book_details (info);
-}
-
-/* =============================================================== */
-
-static void
-scrub_all(void)
-{
- Account *root = gnc_get_current_root_account ();
- xaccAccountTreeScrubOrphans (root);
- xaccAccountTreeScrubImbalance (root);
- // XXX: Lots are disabled
- // xaccAccountTreeScrubLots (root);
-}
-
-/* =============================================================== */
-
-static gboolean
-ap_close_period (GnomeDruidPage *druidpage,
- GtkWidget *druid,
- gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
- QofBook *closed_book = NULL, *current_book;
- const char *btitle;
- char *bnotes;
- Timespec closing_date;
- KvpFrame *book_frame;
- gboolean really_do_close_books = FALSE;
-
- ENTER("info=%p", info);
-
- current_book = gnc_get_current_book ();
-
- btitle = gtk_entry_get_text (info->book_title);
- bnotes = xxxgtk_textview_get_text (info->book_notes);
- PINFO("book title=%s\n", btitle);
-
- timespecFromTime_t (&closing_date,
- gnc_timet_get_day_end_gdate (&info->closing_date));
-
-#define REALLY_DO_CLOSE_BOOKS
-#ifdef REALLY_DO_CLOSE_BOOKS
- really_do_close_books = TRUE;
-#endif /* REALLY_DO_CLOSE_BOOKS */
-
- if (really_do_close_books)
- {
- /* Close the books ! */
- qof_event_suspend ();
- gnc_suspend_gui_refresh ();
-
- scrub_all();
- closed_book = gnc_book_close_period (current_book, closing_date, NULL, btitle);
-
- book_frame = qof_book_get_slots(closed_book);
- kvp_frame_set_str (book_frame, "/book/title", btitle);
- kvp_frame_set_str (book_frame, "/book/notes", bnotes);
-
- qof_session_add_book (gnc_get_current_session(), closed_book);
-
- /* We must save now; if we don't, and the user bails without saving,
- * then opening account balances will be incorrect, and this can only
- * lead to unhappiness.
- */
- gnc_file_save ();
- gnc_resume_gui_refresh ();
- qof_event_resume ();
- gnc_gui_refresh_all (); /* resume above should have been enough ??? */
- }
- g_free(bnotes);
-
- /* Report the status back to the user. */
- info->close_status = 0; /* XXX fixme success or failure? */
-
- /* Find the next closing date ... */
- info->prev_closing_date = info->closing_date;
- recurrenceListNextInstance(info->period, &info->prev_closing_date, &info->closing_date);
-
- /* If the next closing date is in the future, then we are done. */
- if (time(NULL) < gnc_timet_get_day_end_gdate (&info->closing_date))
- {
- return FALSE;
- }
-
- /* Load up the GUI for the next closing period. */
- gnc_frequency_setup_recurrence(info->period_menu, NULL, &info->closing_date);
-
- show_book_details (info);
- return TRUE;
-}
-
-/* =============================================================== */
-
-static void
-ap_show_done (GnomeDruidPageEdge *druidpage,
- GtkWidget *druid,
- gpointer user_data)
-{
- const char *msg;
- char *str;
- AcctPeriodInfo *info = user_data;
- ENTER ("info=%p", info);
-
- /* Translation FIXME: Can this %s-containing message please be
- replaced by one single message? Either this closing went
- successfully ("success", "congratulations") or something else
- should be displayed anyway. */
- msg = _("%s\nCongratulations! You are done closing books!");
-
- str = g_strdup_printf (msg, get_close_status_str (info));
- gnome_druid_page_edge_set_text (druidpage, str);
- g_free (str);
-}
-
-/* =============================================================== */
-
-static void
-ap_druid_create (AcctPeriodInfo *info)
-{
- GladeXML *xml;
- GtkWidget *w;
-
- xml = gnc_glade_xml_new ("acctperiod.glade", "Acct Period Druid");
-
- info->window = glade_xml_get_widget (xml, "Acct Period Druid");
-
- info->druid = GNOME_DRUID (glade_xml_get_widget (xml, "acct_period_druid"));
- gnc_druid_set_colors (info->druid);
-
- info->start_page =
- GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "start page"));
- info->menu_page =
- GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "menu page"));
- info->book_page =
- GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "book page"));
- info->finish_page =
- GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "finish page"));
-
- info->close_status = -1;
-
- /* Find the date of the earliest transaction in the book.
- * Add a year minus a day as the first guess for book closing,
- * and use that to set up the freq spec widget. */
- info->earliest = get_earliest_in_book (gnc_get_current_book());
- info->earliest_str = qof_print_date(info->earliest);
- PINFO ("date of earliest transaction is %ld %s",
- info->earliest, ctime (&info->earliest));
-
- g_date_clear (&info->closing_date, 1);
- g_date_set_time_t (&info->closing_date, info->earliest);
- g_date_clear (&info->prev_closing_date, 1);
- info->prev_closing_date = info->closing_date;
- g_date_add_years (&info->closing_date, 1);
-
- {
- Recurrence *r = g_new0(Recurrence, 1);
- recurrenceSet(r, 1, PERIOD_MONTH, &info->closing_date, WEEKEND_ADJ_NONE);
- info->period = NULL;
- info->period = g_list_append(info->period, r);
- }
-
- info->period_menu = GNC_FREQUENCY(
- gnc_frequency_new_from_recurrence(info->period, &info->closing_date));
-
- /* Change the text so that its more mainingful for this druid */
- gnc_frequency_set_frequency_label_text(info->period_menu, _("Period:"));
- gnc_frequency_set_date_label_text(info->period_menu, _("Closing Date:"));
-
- /* Reparent to the correct location */
- w = glade_xml_get_widget (xml, "period box");
- gtk_box_pack_start (GTK_BOX (w), GTK_WIDGET (info->period_menu),
- TRUE, TRUE, 0);
-
- /* Get handles to all of the other widgets we'll need */
- info->period_remarks =
- GTK_LABEL (glade_xml_get_widget (xml, "remarks label"));
-
- info->close_results =
- GTK_LABEL (glade_xml_get_widget (xml, "results label"));
-
- info->book_details =
- GTK_LABEL (glade_xml_get_widget (xml, "book label"));
-
- info->book_title =
- GTK_ENTRY (glade_xml_get_widget (xml, "book title entry"));
-
- info->book_notes =
- GTK_TEXT_VIEW (glade_xml_get_widget (xml, "book notes text"));
-
- /* generic finished/close/abort signals */
- g_signal_connect (info->window, "destroy",
- G_CALLBACK (ap_window_destroy_cb), info);
-
- g_signal_connect (info->druid, "cancel",
- G_CALLBACK (ap_druid_cancel), info);
-
- g_signal_connect (info->menu_page, "prepare",
- G_CALLBACK (ap_show_menu), info);
-
- g_signal_connect (info->menu_page, "next",
- G_CALLBACK (ap_validate_menu), info);
-
- g_signal_connect (info->book_page, "prepare",
- G_CALLBACK (ap_show_book), info);
-
- g_signal_connect (info->book_page, "next",
- G_CALLBACK (ap_close_period), info);
-
- g_signal_connect (info->finish_page, "prepare",
- G_CALLBACK (ap_show_done), info);
-
- g_signal_connect (info->finish_page, "finish",
- G_CALLBACK (ap_finish), info);
-
- /* User changes the accouting period or date signals */
- g_signal_connect (info->period_menu, "changed",
- G_CALLBACK (ap_changed), info);
-}
-
-
-static void
-ap_close_handler (gpointer user_data)
-{
- AcctPeriodInfo *info = user_data;
-
- gtk_widget_destroy (info->window);
-}
-
-/********************************************************************\
- * gnc_acct_period_dialog *
- * opens up a druid to configure accounting periods *
- * *
- * Args: none *
- * Return: nothing *
-\********************************************************************/
-
-void
-gnc_acct_period_dialog (void)
-{
- AcctPeriodInfo *info;
- gint component_id;
-
- info = g_new0 (AcctPeriodInfo, 1);
-
- ap_druid_create (info);
-
- component_id = gnc_register_gui_component (DRUID_ACCT_PERIOD_CM_CLASS,
- NULL, ap_close_handler,
- info);
-
- gtk_widget_show_all (info->window);
-
- gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
-}
Deleted: gnucash/trunk/src/gnome/druid-acct-period.h
===================================================================
--- gnucash/trunk/src/gnome/druid-acct-period.h 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/druid-acct-period.h 2011-06-01 17:34:51 UTC (rev 20730)
@@ -1,35 +0,0 @@
-/********************************************************************\
- * druid-acct-period.h -- accounting period druid for GnuCash *
- * Copyright (C) 2003 Linas Vepstas <linas at linas.org> *
- * *
- * 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 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
-\********************************************************************/
-
-#ifndef GNC_DRUID_ACCT_PERIOD_H
-#define GNC_DRUID_ACCT_PERIOD_H
-
-/********************************************************************\
- * gnc_acct_period_dialog *
- * opens up a window to set up accounting period *
- * *
- * Args: none *
- * Return: nothing *
-\********************************************************************/
-void gnc_acct_period_dialog (void);
-
-#endif
Deleted: gnucash/trunk/src/gnome/glade/Makefile.am
===================================================================
--- gnucash/trunk/src/gnome/glade/Makefile.am 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/glade/Makefile.am 2011-06-01 17:34:51 UTC (rev 20730)
@@ -1,19 +0,0 @@
-gladedir = $(GNC_GLADE_DIR)
-glade_DATA = \
- acctperiod.glade \
- autoclear.glade \
- budget.glade \
- commodities.glade \
- fincalc.glade \
- lots.glade \
- newuser.glade \
- price.glade \
- print.glade \
- progress.glade \
- reconcile.glade \
- register.glade \
- tax.glade \
- userpass.glade \
- sched-xact.glade
-
-EXTRA_DIST = $(glade_DATA)
Deleted: gnucash/trunk/src/gnome/glade/acctperiod.glade
===================================================================
--- gnucash/trunk/src/gnome/glade/acctperiod.glade 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/glade/acctperiod.glade 2011-06-01 17:34:51 UTC (rev 20730)
@@ -1,208 +0,0 @@
-<?xml version="1.0"?>
-<glade-interface>
- <requires lib="gnome"/>
- <!-- interface-requires gnome 2430.49384 -->
- <!-- interface-requires gtk+ 2.10 -->
- <!-- interface-naming-policy toplevel-contextual -->
- <widget class="GtkWindow" id="Acct Period Druid">
- <property name="visible">True</property>
- <property name="title" translatable="yes">Setup Accounting Periods</property>
- <child>
- <widget class="GnomeDruid" id="acct_period_druid">
- <property name="visible">True</property>
- <property name="border_width">4</property>
- <child>
- <widget class="GnomeDruidPageEdge" id="start page">
- <property name="visible">True</property>
- <property name="position">Edge Start</property>
- <property name="title" translatable="yes">Setup Accounting Periods</property>
- <property name="text" translatable="yes">This assistant will help you setup and use accounting periods.
-
-Danger: this feature does not work correctly at this time; it is still under development. It will probably damage your data in such a way that it cannot be repaired!</property>
- </widget>
- </child>
- <child>
- <widget class="GnomeDruidPageStandard" id="menu page">
- <property name="visible">True</property>
- <property name="title" translatable="yes">Book Closing Dates</property>
- <property name="title_foreground_gdk">#ffffffffffff</property>
- <property name="background_gdk">#666666669998</property>
- <property name="logo_background_gdk">#666666669998</property>
- <child internal-child="vbox">
- <widget class="GtkVBox" id="druid-vbox-xx">
- <property name="visible">True</property>
- <property name="border_width">5</property>
- <property name="orientation">vertical</property>
- <property name="spacing">10</property>
- <child>
- <widget class="GtkLabel" id="label847720">
- <property name="visible">True</property>
- <property name="label" translatable="yes">Select an accounting period and the closing date for the period. Books will be closed on midnight of the selected date.</property>
- <property name="justify">center</property>
- <property name="wrap">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkHBox" id="period box">
- <property name="visible">True</property>
- <property name="border_width">12</property>
- <child>
- <placeholder/>
- </child>
- </widget>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="remarks label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">xxx</property>
- <property name="justify">center</property>
- <property name="wrap">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
- <child>
- <widget class="GnomeDruidPageStandard" id="book page">
- <property name="visible">True</property>
- <property name="title" translatable="yes">Close Book</property>
- <property name="title_foreground_gdk">#ffffffffffff</property>
- <property name="background_gdk">#666666669998</property>
- <property name="logo_background_gdk">#666666669998</property>
- <property name="contents_background_gdk">#e6e6e6e6e6e6</property>
- <child internal-child="vbox">
- <widget class="GtkVBox" id="druid-vbox-yy">
- <property name="visible">True</property>
- <property name="border_width">5</property>
- <property name="orientation">vertical</property>
- <property name="spacing">10</property>
- <child>
- <widget class="GtkLabel" id="results label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">xxx</property>
- <property name="justify">center</property>
- <property name="wrap">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="book label">
- <property name="visible">True</property>
- <property name="label" translatable="yes">xxx</property>
- <property name="justify">center</property>
- <property name="wrap">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
- <widget class="GtkTable" id="table1">
- <property name="visible">True</property>
- <property name="n_rows">2</property>
- <property name="n_columns">2</property>
- <child>
- <widget class="GtkLabel" id="label847723">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Title:</property>
- <property name="justify">center</property>
- </widget>
- <packing>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label847724">
- <property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">Notes:</property>
- <property name="justify">center</property>
- </widget>
- <packing>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options"></property>
- </packing>
- </child>
- <child>
- <widget class="GtkScrolledWindow" id="scrolledwindow1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="hscrollbar_policy">never</property>
- <property name="shadow_type">in</property>
- <child>
- <widget class="GtkTextView" id="book notes text">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="tooltip" translatable="yes">Enter notes that describe this book.</property>
- <property name="wrap_mode">word</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">1</property>
- <property name="bottom_attach">2</property>
- <property name="x_options">GTK_FILL</property>
- <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
- <property name="x_padding">5</property>
- </packing>
- </child>
- <child>
- <widget class="GtkEntry" id="book title entry">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="tooltip" translatable="yes">Enter a title for this book.</property>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="y_options"></property>
- <property name="x_padding">5</property>
- </packing>
- </child>
- </widget>
- <packing>
- <property name="position">2</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
- <child>
- <widget class="GnomeDruidPageEdge" id="finish page">
- <property name="visible">True</property>
- <property name="position">GNOME_EDGE_FINISH</property>
- <property name="title" translatable="yes">Finish Closing Books</property>
- <property name="text" translatable="yes">xxx</property>
- </widget>
- </child>
- </widget>
- </child>
- </widget>
-</glade-interface>
Modified: gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c
===================================================================
--- gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/gnc-plugin-basic-commands.c 2011-06-01 17:34:51 UTC (rev 20730)
@@ -45,7 +45,7 @@
#include "dialog-find-transactions.h"
#include "dialog-sx-since-last-run.h"
#include "dialog-totd.h"
-#include "druid-acct-period.h"
+#include "assistant-acct-period.h"
#include "druid-loan.h"
#include "gnc-engine.h"
#include "gnc-file.h"
Modified: gnucash/trunk/src/gnome/gtkbuilder/acctperiod.glade
===================================================================
--- gnucash/trunk/src/gnome/gtkbuilder/acctperiod.glade 2011-06-01 16:55:22 UTC (rev 20729)
+++ gnucash/trunk/src/gnome/gtkbuilder/acctperiod.glade 2011-06-01 17:34:51 UTC (rev 20730)
@@ -1,11 +1,247 @@
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
- <!-- interface-naming-policy toplevel-contextual -->
- <object class="GtkWindow" id="Acct Period Druid">
- <property name="visible">True</property>
- <property name="title" translatable="yes">Setup Accounting Periods</property>
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkAssistant" id="Account Period Assistant">
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <signal name="close" handler="ap_assistant_close" swapped="no"/>
+ <signal name="apply" handler="ap_assistant_finish" swapped="no"/>
+ <signal name="prepare" handler="ap_assistant_prepare" swapped="no"/>
+ <signal name="cancel" handler="ap_assistant_cancel" swapped="no"/>
<child>
+ <object class="GtkLabel" id="start_page">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">This assistant will help you setup and use accounting periods.
+
+Danger: this feature does not work correctly at this time; it is still under development. It will probably damage your data in such a way that it cannot be repaired!</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="page_type">intro</property>
+ <property name="title" translatable="yes">Setup Account Period</property>
+ <property name="complete">True</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="menu_page">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="menu_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">
+Select an accounting period and the closing date which must not be in the furure and is greater than the closing date of the previous book.
+
+Books will be closed at midnight on the selected date.</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="period_hbox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="remarks_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">xxx</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="title" translatable="yes">Book Closing Dates</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="book_page">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="book_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">xxx</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="results_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">xxx</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkTable" id="book_table">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">12</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">2</property>
+ <child>
+ <object class="GtkLabel" id="book_title">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Title:</property>
+ </object>
+ <packing>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="book_notes">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Notes:</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">automatic</property>
+ <property name="vscrollbar_policy">automatic</property>
+ <child>
+ <object class="GtkTextView" id="book_notes_view">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="wrap_mode">word</property>
+ <property name="accepts_tab">False</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="book_title_entry">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="title" translatable="yes">Close Book</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="finish_page">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">xxx</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="page_type">confirm</property>
+ <property name="title" translatable="yes">Account Period Finish</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="summary_page">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkLabel" id="summary_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">xxx</property>
+ <property name="justify">center</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Press 'Close' to Exit.</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="page_type">summary</property>
+ <property name="title" translatable="yes">Summary Page</property>
+ <property name="complete">True</property>
+ </packing>
+ </child>
+ <child>
<placeholder/>
</child>
</object>
More information about the gnucash-changes
mailing list