From 6c4b3c40b73a1c5712219f4f2876e920552bf677 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 13 Jul 2003 04:16:51 +0000 Subject: [PATCH] misc hacking git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8863 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome/druid-acct-period.c | 88 +++++++++++++++++++++++++------- src/gnome/glade/acctperiod.glade | 71 +++++++++++++------------- 2 files changed, 105 insertions(+), 54 deletions(-) diff --git a/src/gnome/druid-acct-period.c b/src/gnome/druid-acct-period.c index 4fbb1968c1..a92bf1b751 100644 --- a/src/gnome/druid-acct-period.c +++ b/src/gnome/druid-acct-period.c @@ -28,13 +28,16 @@ #include #include "FreqSpec.h" +#include "Query.h" +#include "Transaction.h" #include "dialog-utils.h" #include "druid-acct-period.h" #include "druid-utils.h" -#include "global-options.h" -#include "qofbook.h" #include "gnc-component-manager.h" +#include "gnc-frequency.h" +#include "gnc-ui-util.h" #include "messages.h" +#include "qofbook.h" #define DRUID_ACCT_PERIOD_CM_CLASS "druid-acct-period" @@ -45,10 +48,14 @@ typedef struct { GtkWidget * window; GtkWidget * druid; - GtkOptionMenu *period_menu; - GnomeDateEdit *closing_date_edit; + GNCFrequency *period_menu; + // GnomeDateEdit *closing_date_edit; GtkLabel * earliest_date; + time_t earliest; + GDate *start_date; + FreqSpec *period; + } AcctPeriodInfo; @@ -60,6 +67,9 @@ ap_window_destroy_cb (GtkObject *object, gpointer data) gnc_unregister_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info); + // gnc_frequency_destory ?? + xaccFreqSpecFree (info->period); + g_free (info->start_date); g_free (info); } @@ -86,27 +96,53 @@ ap_changed (GtkWidget *widget, gpointer arg1, gpointer user_data) { - AcctPeriodInfo *info = user_data; + // AcctPeriodInfo *info = user_data; time_t closing_date = 0; - GtkMenuItem *item; + GtkMenuItem *item = NULL; /* closing_date = gnome_date_edit_get_date (info->closing_date_edit); */ - item = GTK_MENU_ITEM (gtk_menu_get_active (GTK_MENU(info->period_menu->menu))); + // item = GTK_MENU_ITEM (gtk_menu_get_active (GTK_MENU(info->period_menu->menu))); printf ("something changed, time=%ld item=%p\n", closing_date, item); } +/* =============================================================== */ +/* Find the earliest date occuring in the book. Do this by making + * a query and sorting by date. + */ +static time_t +get_earliest_in_book (QofBook *book) +{ + QofQuery *q; + GSList *p1, *p2; + time_t earliest; + + q = qof_query_create_for(GNC_ID_SPLIT); + qof_query_set_max_results(q, 5); + + 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); + + qof_query_set_sort_increasing (q, TRUE, TRUE, TRUE); + + earliest = xaccQueryGetEarliestDateFound (q); + + return earliest; +} + /* =============================================================== */ static void ap_druid_create (AcctPeriodInfo *info) { GladeXML *xml; - GtkWidget *page; + GtkWidget *w, *page; xml = gnc_glade_xml_new ("acctperiod.glade", "Acct Period Druid"); @@ -114,13 +150,30 @@ ap_druid_create (AcctPeriodInfo *info) info->druid = glade_xml_get_widget (xml, "acct_period_druid"); - info->period_menu = - GTK_OPTION_MENU (glade_xml_get_widget (xml, "period menu")); - info->closing_date_edit = - GNOME_DATE_EDIT (glade_xml_get_widget (xml, "closing date edit")); + /* Set up the freq spec widget */ + + info->earliest = get_earliest_in_book (gnc_get_current_book()); +printf ("the earliest is %ld %s\n", info->earliest, ctime (&info->earliest)); + info->start_date = g_date_new_dmy(5,5,1988); + + info->period = xaccFreqSpecMalloc( gnc_get_current_book() ); + xaccFreqSpecSetMonthly (info->period, info->start_date, 12); + xaccFreqSpecSetUIType (info->period, UIFREQ_YEARLY); + + info->period_menu = GNC_FREQUENCY ( + gnc_frequency_new (info->period, info->start_date)); + w = glade_xml_get_widget (xml, "period box"); + gtk_box_pack_start (GTK_BOX (w), GTK_WIDGET (info->period_menu), + TRUE, TRUE, 0); +printf ("postbox\n"); + + // info->closing_date_edit = + // GNOME_DATE_EDIT (glade_xml_get_widget (xml, "closing date edit")); info->earliest_date = GTK_LABEL (glade_xml_get_widget (xml, "earliest trans label")); +// "closing date box" + /* generic finished/close/abort signals */ gtk_signal_connect (GTK_OBJECT (info->window), "destroy", GTK_SIGNAL_FUNC (ap_window_destroy_cb), info); @@ -132,16 +185,15 @@ ap_druid_create (AcctPeriodInfo *info) gtk_signal_connect (GTK_OBJECT (page), "finish", GTK_SIGNAL_FUNC (ap_finish), info); +printf ("presig\n"); /* User changes the accouting period or date signals */ -// XXX doesn't work ... - gtk_signal_connect (GTK_OBJECT (info->period_menu), "clicked", + gtk_signal_connect (GTK_OBJECT (info->period_menu), "changed", GTK_SIGNAL_FUNC (ap_changed), info); - - gtk_signal_connect (GTK_OBJECT (info->period_menu->menu), "selection_done", - GTK_SIGNAL_FUNC (ap_changed), info); - +printf ("postsig\n"); +/* gtk_signal_connect (GTK_OBJECT (info->closing_date_edit), "date_changed", GTK_SIGNAL_FUNC (ap_changed), info); +*/ } diff --git a/src/gnome/glade/acctperiod.glade b/src/gnome/glade/acctperiod.glade index ddfae8da0b..4ce76c1e15 100644 --- a/src/gnome/glade/acctperiod.glade +++ b/src/gnome/glade/acctperiod.glade @@ -106,33 +106,6 @@ it is still under development. - - GtkOptionMenu - period menu - True - Weekly -Monthly -Quarterly -Bi-annual -Annual - - 0 - - 1 - 2 - 0 - 1 - 0 - 0 - False - False - False - False - True - False - - - GtkLabel label847716 @@ -160,13 +133,35 @@ Annual - GnomeDateEdit - closing date edit - False - True - False - 7 - 19 + GtkHBox + period box + False + 0 + + 1 + 2 + 0 + 1 + 0 + 0 + False + False + False + False + True + True + + + + Placeholder + + + + + GtkHBox + closing date box + False + 0 1 2 @@ -174,13 +169,17 @@ Annual 2 0 0 - True + False False False False True - False + True + + + Placeholder +