diff --git a/po/POTFILES.in b/po/POTFILES.in
index 8998a9d006..42656d837a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -21,6 +21,7 @@ src/gnome/dialog-transfer.c
src/gnome/dialog-utils.c
src/gnome/druid-commodity.c
src/gnome/druid-qif-import.c
+src/gnome/druid-stock-split.c
src/gnome/file-history.c
src/gnome/glade-gnc-dialogs.c
src/gnome/gnc-commodity-edit.c
diff --git a/src/gnome/druid-stock-split.c b/src/gnome/druid-stock-split.c
index a0faac35c6..68faea4b92 100644
--- a/src/gnome/druid-stock-split.c
+++ b/src/gnome/druid-stock-split.c
@@ -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
diff --git a/src/gnome/glade-gnc-dialogs.c b/src/gnome/glade-gnc-dialogs.c
index 85c68539a1..dcac3267dd 100644
--- a/src/gnome/glade-gnc-dialogs.c
+++ b/src/gnome/glade-gnc-dialogs.c
@@ -5879,9 +5879,11 @@ create_Stock_Split_Druid (void)
GtkWidget *vbox100;
GtkWidget *label847683;
GtkWidget *label847684;
+ GtkWidget *label847693;
GtkWidget *vbox101;
GtkWidget *date_box;
GtkWidget *distribution_box;
+ GtkWidget *description_entry;
GtkWidget *hseparator2;
GtkWidget *label847691;
GtkWidget *hbox93;
@@ -5900,7 +5902,7 @@ create_Stock_Split_Druid (void)
GtkWidget *label847689;
GtkWidget *vbox104;
GtkWidget *cash_box;
- GtkWidget *description_entry;
+ GtkWidget *memo_entry;
GtkWidget *hbox88;
GtkWidget *frame43;
GtkWidget *income_scroll;
@@ -6027,7 +6029,7 @@ create_Stock_Split_Druid (void)
gtk_widget_show (druid_vbox32);
gtk_container_set_border_width (GTK_CONTAINER (druid_vbox32), 5);
- label847681 = gtk_label_new (_("Enter the date and the number of shares you gained or lost from the stock split or merger.\nFor stock mergers (negative splits) use a negative value for the share distribution."));
+ label847681 = gtk_label_new (_("Enter the date and the number of shares you gained or lost from the stock split or merger.\nFor stock mergers (negative splits) use a negative value for the share distribution.\nYou can also enter a description of the transaction, or accept the default one."));
gtk_widget_ref (label847681);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "label847681", label847681,
(GtkDestroyNotify) gtk_widget_unref);
@@ -6048,6 +6050,7 @@ create_Stock_Split_Druid (void)
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (vbox100);
gtk_box_pack_start (GTK_BOX (hbox86), vbox100, FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox100), 2);
label847683 = gtk_label_new (_("Date:"));
gtk_widget_ref (label847683);
@@ -6065,6 +6068,14 @@ create_Stock_Split_Druid (void)
gtk_box_pack_start (GTK_BOX (vbox100), label847684, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label847684), 1, 0.5);
+ label847693 = gtk_label_new (_("Description:"));
+ gtk_widget_ref (label847693);
+ gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "label847693", label847693,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (label847693);
+ gtk_box_pack_start (GTK_BOX (vbox100), label847693, FALSE, FALSE, 0);
+ gtk_misc_set_alignment (GTK_MISC (label847693), 1, 0.5);
+
vbox101 = gtk_vbox_new (TRUE, 4);
gtk_widget_ref (vbox101);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "vbox101", vbox101,
@@ -6086,6 +6097,14 @@ create_Stock_Split_Druid (void)
gtk_widget_show (distribution_box);
gtk_box_pack_start (GTK_BOX (vbox101), distribution_box, FALSE, FALSE, 0);
+ description_entry = gtk_entry_new ();
+ gtk_widget_ref (description_entry);
+ gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "description_entry", description_entry,
+ (GtkDestroyNotify) gtk_widget_unref);
+ gtk_widget_show (description_entry);
+ gtk_box_pack_start (GTK_BOX (vbox101), description_entry, FALSE, FALSE, 0);
+ gtk_entry_set_text (GTK_ENTRY (description_entry), _("Stock Split"));
+
hseparator2 = gtk_hseparator_new ();
gtk_widget_ref (hseparator2);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "hseparator2", hseparator2,
@@ -6149,7 +6168,7 @@ create_Stock_Split_Druid (void)
gtk_box_pack_start (GTK_BOX (druid_vbox33), label847687, FALSE, FALSE, 0);
gtk_label_set_justify (GTK_LABEL (label847687), GTK_JUSTIFY_LEFT);
- vbox102 = gtk_vbox_new (FALSE, 8);
+ vbox102 = gtk_vbox_new (FALSE, 10);
gtk_widget_ref (vbox102);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "vbox102", vbox102,
(GtkDestroyNotify) gtk_widget_unref);
@@ -6179,7 +6198,7 @@ create_Stock_Split_Druid (void)
gtk_box_pack_start (GTK_BOX (vbox103), label847688, FALSE, FALSE, 0);
gtk_misc_set_alignment (GTK_MISC (label847688), 1, 0.5);
- label847689 = gtk_label_new (_("Description:"));
+ label847689 = gtk_label_new (_("Memo:"));
gtk_widget_ref (label847689);
gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "label847689", label847689,
(GtkDestroyNotify) gtk_widget_unref);
@@ -6201,12 +6220,13 @@ create_Stock_Split_Druid (void)
gtk_widget_show (cash_box);
gtk_box_pack_start (GTK_BOX (vbox104), cash_box, FALSE, FALSE, 0);
- description_entry = gtk_entry_new ();
- gtk_widget_ref (description_entry);
- gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "description_entry", description_entry,
+ memo_entry = gtk_entry_new ();
+ gtk_widget_ref (memo_entry);
+ gtk_object_set_data_full (GTK_OBJECT (Stock_Split_Druid), "memo_entry", memo_entry,
(GtkDestroyNotify) gtk_widget_unref);
- gtk_widget_show (description_entry);
- gtk_box_pack_start (GTK_BOX (vbox104), description_entry, FALSE, FALSE, 0);
+ gtk_widget_show (memo_entry);
+ gtk_box_pack_start (GTK_BOX (vbox104), memo_entry, FALSE, FALSE, 0);
+ gtk_entry_set_text (GTK_ENTRY (memo_entry), _("Cash In Lieu"));
hbox88 = gtk_hbox_new (TRUE, 2);
gtk_widget_ref (hbox88);
@@ -6228,6 +6248,7 @@ create_Stock_Split_Druid (void)
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (income_scroll);
gtk_container_add (GTK_CONTAINER (frame43), income_scroll);
+ gtk_container_set_border_width (GTK_CONTAINER (income_scroll), 3);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (income_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
frame44 = gtk_frame_new (_("Asset Account"));
@@ -6243,6 +6264,7 @@ create_Stock_Split_Druid (void)
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (asset_scroll);
gtk_container_add (GTK_CONTAINER (frame44), asset_scroll);
+ gtk_container_set_border_width (GTK_CONTAINER (asset_scroll), 3);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (asset_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
finish_page = gnome_druid_page_finish_new ();
diff --git a/src/gnome/gnc-dialogs.glade b/src/gnome/gnc-dialogs.glade
index c7526c3dec..4374cfd1af 100644
--- a/src/gnome/gnc-dialogs.glade
+++ b/src/gnome/gnc-dialogs.glade
@@ -8742,7 +8742,8 @@ words.
GtkLabel
label847681
+For stock mergers (negative splits) use a negative value for the share distribution.
+You can also enter a description of the transaction, or accept the default one.
GTK_JUSTIFY_CENTER
False
0.5
@@ -8771,6 +8772,7 @@ For stock mergers (negative splits) use a negative value for the share distribut
GtkVBox
vbox100
+ 2
True
4
@@ -8812,6 +8814,23 @@ For stock mergers (negative splits) use a negative value for the share distribut
False
+
+
+ GtkLabel
+ label847693
+
+ GTK_JUSTIFY_CENTER
+ False
+ 1
+ 0.5
+ 0
+ 0
+
+ 0
+ False
+ False
+
+
@@ -8856,6 +8875,21 @@ For stock mergers (negative splits) use a negative value for the share distribut
Placeholder
+
+
+ GtkEntry
+ description_entry
+ True
+ True
+ True
+ 0
+ Stock Split
+
+ 0
+ False
+ False
+
+
@@ -8979,7 +9013,7 @@ enter the details of that payment here. Otherwise, just click `Next'.
vbox102
5
False
- 8
+ 10
0
True
@@ -9028,7 +9062,7 @@ enter the details of that payment here. Otherwise, just click `Next'.
GtkLabel
label847689
-
+
GTK_JUSTIFY_CENTER
False
1
@@ -9072,12 +9106,12 @@ enter the details of that payment here. Otherwise, just click `Next'.
GtkEntry
- description_entry
+ memo_entry
True
True
True
0
-
+ Cash In Lieu
0
False
@@ -9113,6 +9147,7 @@ enter the details of that payment here. Otherwise, just click `Next'.
GtkScrolledWindow
income_scroll
+ 3
GTK_POLICY_AUTOMATIC
GTK_POLICY_AUTOMATIC
GTK_UPDATE_CONTINUOUS
@@ -9139,6 +9174,7 @@ enter the details of that payment here. Otherwise, just click `Next'.
GtkScrolledWindow
asset_scroll
+ 3
GTK_POLICY_AUTOMATIC
GTK_POLICY_AUTOMATIC
GTK_UPDATE_CONTINUOUS