@ -47,6 +47,7 @@
typedef struct
{
GtkWidget * window ;
GtkWidget * druid ;
/* account page data */
GtkWidget * account_list ;
@ -55,11 +56,14 @@ typedef struct
/* info page data */
GtkWidget * date_edit ;
GtkWidget * distribution_edit ;
GtkWidget * description_entry ;
GtkWidget * price_edit ;
/* cash in lieu page data */
GtkWidget * cash_edit ;
GtkWidget * description_entry ;
GtkWidget * memo_entry ;
GtkWidget * income_tree ;
GtkWidget * asset_tree ;
} StockSplitInfo ;
@ -240,37 +244,227 @@ details_next (GnomeDruidPage *druidpage,
return TRUE ;
}
if ( ! gnc_amount_edit_evaluate ( GNC_AMOUNT_EDIT ( info - > price_edit ) ) )
{
gnc_parse_error_dialog ( info ,
_ ( " You must either enter a valid price \n "
" or leave it blank. " ) ) ;
return TRUE ;
}
amount = gnc_amount_edit_get_amount ( GNC_AMOUNT_EDIT ( info - > price_edit ) ) ;
if ( gnc_numeric_negative_p ( amount ) )
{
const char * message = _ ( " The price must be positive. " ) ;
gnc_error_dialog_parented ( GTK_WINDOW ( info - > window ) , message ) ;
return TRUE ;
}
return FALSE ;
}
static void
druid_cancel ( GnomeDruid * druid , gpointer user_data )
cash_prepare ( GnomeDruidPage * druidpage ,
gpointer arg1 ,
gpointer user_data )
{
StockSplitInfo * info = user_data ;
gnc_account_tree_refresh ( GNC_ACCOUNT_TREE ( info - > income_tree ) ) ;
gnc_account_tree_expand_all ( GNC_ACCOUNT_TREE ( info - > income_tree ) ) ;
gtk_clist_select_row ( GTK_CLIST ( info - > income_tree ) , 0 , 0 ) ;
gnc_account_tree_refresh ( GNC_ACCOUNT_TREE ( info - > asset_tree ) ) ;
gnc_account_tree_expand_all ( GNC_ACCOUNT_TREE ( info - > asset_tree ) ) ;
gtk_clist_select_row ( GTK_CLIST ( info - > asset_tree ) , 0 , 0 ) ;
}
static gboolean
cash_next ( GnomeDruidPage * druidpage ,
gpointer arg1 ,
gpointer user_data )
{
StockSplitInfo * info = user_data ;
gnc_numeric amount ;
if ( ! gnc_amount_edit_evaluate ( GNC_AMOUNT_EDIT ( info - > cash_edit ) ) )
{
gnc_parse_error_dialog ( info ,
_ ( " You must either enter a valid cash amount \n "
" or leave it blank. " ) ) ;
return TRUE ;
}
amount = gnc_amount_edit_get_amount ( GNC_AMOUNT_EDIT ( info - > cash_edit ) ) ;
if ( gnc_numeric_negative_p ( amount ) )
{
const char * message = _ ( " The cash distribution must be positive. " ) ;
gnc_error_dialog_parented ( GTK_WINDOW ( info - > window ) , message ) ;
return TRUE ;
}
if ( gnc_numeric_positive_p ( amount ) )
{
Account * account ;
account = gnc_account_tree_get_current_account
( GNC_ACCOUNT_TREE ( info - > income_tree ) ) ;
if ( ! account )
{
const char * message = _ ( " You must select an income account \n "
" for the cash distribution. " ) ;
gnc_error_dialog_parented ( GTK_WINDOW ( info - > window ) , message ) ;
return TRUE ;
}
account = gnc_account_tree_get_current_account
( GNC_ACCOUNT_TREE ( info - > asset_tree ) ) ;
if ( ! account )
{
const char * message = _ ( " You must select an asset account \n "
" for the cash distribution. " ) ;
gnc_error_dialog_parented ( GTK_WINDOW ( info - > window ) , message ) ;
return TRUE ;
}
}
return FALSE ;
}
static void
stock_split_finish ( GnomeDruidPage * druidpage ,
gpointer arg1 ,
gpointer user_data )
{
StockSplitInfo * info = user_data ;
gnc_numeric amount ;
Transaction * trans ;
Account * account ;
Split * split ;
account = xaccAccountLookup ( & info - > account ) ;
g_return_if_fail ( account ! = NULL ) ;
amount = gnc_amount_edit_get_amount
( GNC_AMOUNT_EDIT ( info - > distribution_edit ) ) ;
g_return_if_fail ( ! gnc_numeric_zero_p ( amount ) ) ;
gnc_suspend_gui_refresh ( ) ;
trans = xaccMallocTransaction ( ) ;
xaccTransBeginEdit ( trans ) ;
{
time_t date ;
date = gnc_date_edit_get_date ( GNC_DATE_EDIT ( info - > date_edit ) ) ;
xaccTransSetDateSecs ( trans , date ) ;
}
{
const char * description ;
description = gtk_entry_get_text ( GTK_ENTRY ( info - > description_entry ) ) ;
xaccTransSetDescription ( trans , description ) ;
}
split = xaccMallocSplit ( ) ;
xaccTransAppendSplit ( trans , split ) ;
xaccAccountBeginEdit ( account ) ;
xaccAccountInsertSplit ( account , split ) ;
xaccAccountCommitEdit ( account ) ;
xaccSplitSetShareAmount ( split , amount ) ;
xaccSplitMakeStockSplit ( split ) ;
xaccSplitSetAction ( split , _ ( " Split " ) ) ;
amount = gnc_amount_edit_get_amount ( GNC_AMOUNT_EDIT ( info - > price_edit ) ) ;
if ( gnc_numeric_positive_p ( amount ) )
{
const char * message = " FIXME: we need the pricedb to record. " ;
gnc_error_dialog_parented ( GTK_WINDOW ( info - > window ) , message ) ;
}
amount = gnc_amount_edit_get_amount ( GNC_AMOUNT_EDIT ( info - > cash_edit ) ) ;
if ( gnc_numeric_positive_p ( amount ) )
{
const char * memo ;
memo = gtk_entry_get_text ( GTK_ENTRY ( info - > memo_entry ) ) ;
/* asset split */
account = gnc_account_tree_get_current_account
( GNC_ACCOUNT_TREE ( info - > asset_tree ) ) ;
split = xaccMallocSplit ( ) ;
xaccAccountBeginEdit ( account ) ;
xaccAccountInsertSplit ( account , split ) ;
xaccAccountCommitEdit ( account ) ;
xaccTransAppendSplit ( trans , split ) ;
xaccSplitSetShareAmount ( split , amount ) ;
xaccSplitSetValue ( split , amount ) ;
xaccSplitSetMemo ( split , memo ) ;
/* income split */
account = gnc_account_tree_get_current_account
( GNC_ACCOUNT_TREE ( info - > income_tree ) ) ;
split = xaccMallocSplit ( ) ;
xaccAccountBeginEdit ( account ) ;
xaccAccountInsertSplit ( account , split ) ;
xaccAccountCommitEdit ( account ) ;
xaccTransAppendSplit ( trans , split ) ;
xaccSplitSetShareAmount ( split , gnc_numeric_neg ( amount ) ) ;
xaccSplitSetValue ( split , gnc_numeric_neg ( amount ) ) ;
xaccSplitSetMemo ( split , memo ) ;
}
xaccTransCommitEdit ( trans ) ;
gnc_resume_gui_refresh ( ) ;
gnc_close_gui_component_by_data ( DRUID_STOCK_SPLIT_CM_CLASS , info ) ;
}
static void
druid_cancel ( GnomeDruid * druid , gpointer user_data )
{
StockSplitInfo * info = user_data ;
gnc_close_gui_component_by_data ( DRUID_STOCK_SPLIT_CM_CLASS , info ) ;
}
static void
gnc_stock_split_druid_create ( StockSplitInfo * info )
{
GtkWidget * druid ;
GtkWidget * page ;
info - > window = create_Stock_Split_Druid ( ) ;
druid = lookup_widget ( info - > window , " stock_split_druid " ) ;
info- > druid = lookup_widget ( info - > window , " stock_split_druid " ) ;
gtk_signal_connect ( GTK_OBJECT ( info - > window ) , " destroy " ,
GTK_SIGNAL_FUNC ( window_destroy_cb ) , info ) ;
gtk_signal_connect ( GTK_OBJECT ( druid ) , " cancel " ,
gtk_signal_connect ( GTK_OBJECT ( info- > druid) , " cancel " ,
GTK_SIGNAL_FUNC ( druid_cancel ) , info ) ;
/* account list */
{
GtkCList * clist ;
GtkWidget * page ;
info - > account_list = lookup_widget ( info - > window , " account_clist " ) ;
@ -291,9 +485,11 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
{
GtkWidget * box ;
GtkWidget * amount ;
GtkWidget * page ;
GtkWidget * date ;
info - > description_entry =
lookup_widget ( info - > window , " description_entry " ) ;
box = lookup_widget ( info - > window , " date_box " ) ;
date = gnc_date_edit_new ( time ( NULL ) , FALSE , FALSE ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , date , TRUE , TRUE , 0 ) ;
@ -319,26 +515,101 @@ gnc_stock_split_druid_create (StockSplitInfo *info)
/* Cash in Lieu page */
{
AccountViewInfo view_info ;
GNCAccountType type ;
GtkWidget * box ;
GtkWidget * tree ;
GtkWidget * amount ;
GtkWidget * scroll ;
box = lookup_widget ( info - > window , " cash_box " ) ;
amount = gnc_amount_edit_new ( ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , amount , TRUE , TRUE , 0 ) ;
info - > cash_edit = amount ;
info - > description_entry = lookup_widget ( info - > window ,
" description_entry " ) ;
info - > memo_entry = lookup_widget ( info - > window , " memo_entry " ) ;
/* income tree */
tree = gnc_account_tree_new ( ) ;
info - > income_tree = tree ;
gtk_clist_column_titles_hide ( GTK_CLIST ( tree ) ) ;
gtk_clist_set_selection_mode ( GTK_CLIST ( tree ) , GTK_SELECTION_BROWSE ) ;
gnc_account_tree_hide_all_but_name ( GNC_ACCOUNT_TREE ( tree ) ) ;
gnc_account_tree_get_view_info ( GNC_ACCOUNT_TREE ( tree ) , & view_info ) ;
for ( type = 0 ; type < NUM_ACCOUNT_TYPES ; type + + )
view_info . include_type [ type ] = ( type = = INCOME ) ;
gnc_account_tree_set_view_info ( GNC_ACCOUNT_TREE ( tree ) , & view_info ) ;
gtk_widget_show ( tree ) ;
scroll = lookup_widget ( info - > window , " income_scroll " ) ;
gtk_container_add ( GTK_CONTAINER ( scroll ) , tree ) ;
/* asset tree */
tree = gnc_account_tree_new ( ) ;
info - > asset_tree = tree ;
gtk_clist_column_titles_hide ( GTK_CLIST ( tree ) ) ;
gtk_clist_set_selection_mode ( GTK_CLIST ( tree ) , GTK_SELECTION_BROWSE ) ;
gnc_account_tree_hide_all_but_name ( GNC_ACCOUNT_TREE ( tree ) ) ;
gnc_account_tree_get_view_info ( GNC_ACCOUNT_TREE ( tree ) , & view_info ) ;
for ( type = 0 ; type < NUM_ACCOUNT_TYPES ; type + + )
view_info . include_type [ type ] =
( type = = BANK ) | | ( type = = CASH ) | | ( type = = ASSET ) ;
gnc_account_tree_set_view_info ( GNC_ACCOUNT_TREE ( tree ) , & view_info ) ;
gtk_widget_show ( tree ) ;
scroll = lookup_widget ( info - > window , " asset_scroll " ) ;
gtk_container_add ( GTK_CONTAINER ( scroll ) , tree ) ;
page = lookup_widget ( info - > window , " cash_page " ) ;
gtk_signal_connect ( GTK_OBJECT ( page ) , " prepare " ,
GTK_SIGNAL_FUNC ( cash_prepare ) , info ) ;
gtk_signal_connect ( GTK_OBJECT ( page ) , " next " ,
GTK_SIGNAL_FUNC ( cash_next ) , info ) ;
}
page = lookup_widget ( info - > window , " finish_page " ) ;
gtk_signal_connect ( GTK_OBJECT ( page ) , " finish " ,
GTK_SIGNAL_FUNC ( stock_split_finish ) , info ) ;
}
static void
refresh_handler ( GHashTable * changes , gpointer user_data )
{
StockSplitInfo * info = user_data ;
Account * old_account ;
Account * new_account ;
GNCIdType id_type ;
GtkWidget * page ;
if ( fill_account_list ( info , xaccAccountLookup ( & info - > account ) ) = = 0 )
id_type = xaccGUIDType ( & info - > account ) ;
old_account = xaccAccountLookup ( & info - > account ) ;
if ( fill_account_list ( info , old_account ) = = 0 )
{
gnc_close_gui_component_by_data ( DRUID_STOCK_SPLIT_CM_CLASS , info ) ;
return ;
}
new_account = xaccAccountLookup ( & info - > account ) ;
if ( id_type = = GNC_ID_NULL | | old_account = = new_account )
return ;
page = lookup_widget ( info - > window , " account_page " ) ;
gnome_druid_set_page ( GNOME_DRUID ( info - > druid ) , GNOME_DRUID_PAGE ( page ) ) ;
}
static void