Re-indentation of source code, next batch.

This also strips trailing whitespaces from lines where they existed.
This re-indentation was done using astyle-1.24 using the following options:

astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header --suffix=none

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18746 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming
2010-02-27 16:32:01 +00:00
parent a3ca714396
commit 59f780f575
50 changed files with 16028 additions and 15001 deletions

View File

@@ -23,7 +23,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
@@ -48,242 +48,253 @@ void chart_export_response_cb (GtkDialog *dialog, gint response, gpointer user_d
typedef struct chart_data_s
{
GladeXML *xml;
GtkWidget *dialog;
GtkWidget *calendar;
time_t chart_time_t;
QofSession *chart_session;
Account *equity_account;
GList *param_ref_list;
}chart_data;
GladeXML *xml;
GtkWidget *dialog;
GtkWidget *calendar;
time_t chart_time_t;
QofSession *chart_session;
Account *equity_account;
GList *param_ref_list;
} chart_data;
static void
chart_collection_cb(QofInstance *ent, gpointer user_data)
{
chart_data *data;
Account *acc;
gboolean success;
const GUID *guid;
QofCollection *copy_coll;
QofBook *book;
chart_data *data;
Account *acc;
gboolean success;
const GUID *guid;
QofCollection *copy_coll;
QofBook *book;
g_return_if_fail(user_data != NULL);
data = (chart_data*)user_data;
acc = (Account*)ent;
if(0 == safe_strcmp(EQUITY_ACCOUNT_NAME, xaccAccountGetName(acc))
&& (xaccAccountGetType(acc) == ACCT_TYPE_EQUITY))
{
success = qof_instance_copy_to_session(data->chart_session, ent);
if(!success) { return; }
guid = qof_entity_get_guid(ent);
book = qof_session_get_book(data->chart_session);
copy_coll = qof_book_get_collection(book, GNC_ID_ACCOUNT);
data->equity_account = (Account*)qof_collection_lookup_entity(copy_coll, guid);
return;
}
g_return_if_fail(user_data != NULL);
data = (chart_data*)user_data;
acc = (Account*)ent;
if (0 == safe_strcmp(EQUITY_ACCOUNT_NAME, xaccAccountGetName(acc))
&& (xaccAccountGetType(acc) == ACCT_TYPE_EQUITY))
{
success = qof_instance_copy_to_session(data->chart_session, ent);
if (!success)
{
return;
}
guid = qof_entity_get_guid(ent);
book = qof_session_get_book(data->chart_session);
copy_coll = qof_book_get_collection(book, GNC_ID_ACCOUNT);
data->equity_account = (Account*)qof_collection_lookup_entity(copy_coll, guid);
return;
}
}
static void
chart_reference_cb(QofInstance *ent, gpointer user_data)
{
QofInstanceReference *reference;
QofParam *ref_param;
chart_data *data;
QofInstanceReference *reference;
QofParam *ref_param;
chart_data *data;
g_return_if_fail(user_data != NULL);
data = (chart_data*)user_data;
while(data->param_ref_list != NULL) {
ref_param = data->param_ref_list->data;
reference = qof_instance_get_reference_from(ent, ref_param);
qof_session_update_reference_list(data->chart_session, reference);
data->param_ref_list = data->param_ref_list->next;
}
g_return_if_fail(user_data != NULL);
data = (chart_data*)user_data;
while (data->param_ref_list != NULL)
{
ref_param = data->param_ref_list->data;
reference = qof_instance_get_reference_from(ent, ref_param);
qof_session_update_reference_list(data->chart_session, reference);
data->param_ref_list = data->param_ref_list->next;
}
}
static void
chart_entity_cb(QofInstance *ent, gpointer user_data)
{
chart_data *data;
Account *acc_ent, *equity_account;
Transaction *trans;
Split *split;
gnc_numeric balance;
QofBook *book;
QofCollection *coll;
const GUID *guid;
time_t trans_time;
GList *ref;
QofInstanceReference *ent_ref;
g_return_if_fail(user_data != NULL);
data = (chart_data*)user_data;
trans_time = data->chart_time_t;
data->param_ref_list = NULL;
guid = qof_entity_get_guid(ent);
acc_ent = (Account*)ent;
ref = NULL;
equity_account = data->equity_account;
g_return_if_fail(equity_account != NULL);
balance = xaccAccountGetBalanceAsOfDate(acc_ent, data->chart_time_t);
qof_instance_copy_to_session(data->chart_session, ent);
book = qof_session_get_book(data->chart_session);
coll = qof_book_get_collection(book, GNC_ID_ACCOUNT);
acc_ent = (Account*)qof_collection_lookup_entity(coll, guid);
if(xaccAccountGetCommodity(acc_ent) == NULL)
{
xaccAccountSetCommodity(acc_ent, gnc_default_currency());
}
/* can't use gnc_account_create_opening_balance directly - the partial
QofBook doesn't have an AccountGroup that is used to locate the Equity Account. */
xaccAccountBeginEdit (acc_ent);
xaccAccountBeginEdit (equity_account);
trans = xaccMallocTransaction (book);
xaccTransBeginEdit (trans);
xaccTransSetCurrency (trans, xaccAccountGetCommodity (acc_ent));
xaccTransSetDateSecs (trans, trans_time);
xaccTransSetDateEnteredSecs (trans, trans_time);
xaccTransSetDescription (trans, OPENING_BALANCE_DESC);
/* User account split */
split = xaccMallocSplit (book);
xaccTransAppendSplit (trans, split);
xaccAccountInsertSplit (acc_ent, split);
xaccSplitSetAmount (split, balance);
xaccSplitSetValue (split, balance);
ref = qof_class_get_referenceList(GNC_ID_SPLIT);
while(ref != NULL) {
ent_ref = qof_instance_get_reference_from(QOF_INSTANCE(split), ref->data);
qof_session_update_reference_list(data->chart_session, ent_ref);
ref = g_list_next(ref);
}
g_list_free(ref);
balance = gnc_numeric_neg (balance);
/* Equity account split */
split = xaccMallocSplit (book);
xaccTransAppendSplit (trans, split);
xaccAccountInsertSplit (equity_account, split);
xaccSplitSetAmount (split, balance);
xaccSplitSetValue (split, balance);
xaccTransCommitEdit (trans);
xaccAccountCommitEdit (equity_account);
xaccAccountCommitEdit (acc_ent);
ref = qof_class_get_referenceList(GNC_ID_TRANS);
while(ref != NULL) {
ent_ref = qof_instance_get_reference_from(QOF_INSTANCE(trans), ref->data);
qof_session_update_reference_list(data->chart_session, ent_ref);
ref = g_list_next(ref);
}
g_list_free(ref);
ref = qof_class_get_referenceList(GNC_ID_SPLIT);
while(ref != NULL) {
ent_ref = qof_instance_get_reference_from(QOF_INSTANCE(split), ref->data);
qof_session_update_reference_list(data->chart_session, ent_ref);
ref = g_list_next(ref);
}
g_list_free(ref);
chart_data *data;
Account *acc_ent, *equity_account;
Transaction *trans;
Split *split;
gnc_numeric balance;
QofBook *book;
QofCollection *coll;
const GUID *guid;
time_t trans_time;
GList *ref;
QofInstanceReference *ent_ref;
g_return_if_fail(user_data != NULL);
data = (chart_data*)user_data;
trans_time = data->chart_time_t;
data->param_ref_list = NULL;
guid = qof_entity_get_guid(ent);
acc_ent = (Account*)ent;
ref = NULL;
equity_account = data->equity_account;
g_return_if_fail(equity_account != NULL);
balance = xaccAccountGetBalanceAsOfDate(acc_ent, data->chart_time_t);
qof_instance_copy_to_session(data->chart_session, ent);
book = qof_session_get_book(data->chart_session);
coll = qof_book_get_collection(book, GNC_ID_ACCOUNT);
acc_ent = (Account*)qof_collection_lookup_entity(coll, guid);
if (xaccAccountGetCommodity(acc_ent) == NULL)
{
xaccAccountSetCommodity(acc_ent, gnc_default_currency());
}
/* can't use gnc_account_create_opening_balance directly - the partial
QofBook doesn't have an AccountGroup that is used to locate the Equity Account. */
xaccAccountBeginEdit (acc_ent);
xaccAccountBeginEdit (equity_account);
trans = xaccMallocTransaction (book);
xaccTransBeginEdit (trans);
xaccTransSetCurrency (trans, xaccAccountGetCommodity (acc_ent));
xaccTransSetDateSecs (trans, trans_time);
xaccTransSetDateEnteredSecs (trans, trans_time);
xaccTransSetDescription (trans, OPENING_BALANCE_DESC);
/* User account split */
split = xaccMallocSplit (book);
xaccTransAppendSplit (trans, split);
xaccAccountInsertSplit (acc_ent, split);
xaccSplitSetAmount (split, balance);
xaccSplitSetValue (split, balance);
ref = qof_class_get_referenceList(GNC_ID_SPLIT);
while (ref != NULL)
{
ent_ref = qof_instance_get_reference_from(QOF_INSTANCE(split), ref->data);
qof_session_update_reference_list(data->chart_session, ent_ref);
ref = g_list_next(ref);
}
g_list_free(ref);
balance = gnc_numeric_neg (balance);
/* Equity account split */
split = xaccMallocSplit (book);
xaccTransAppendSplit (trans, split);
xaccAccountInsertSplit (equity_account, split);
xaccSplitSetAmount (split, balance);
xaccSplitSetValue (split, balance);
xaccTransCommitEdit (trans);
xaccAccountCommitEdit (equity_account);
xaccAccountCommitEdit (acc_ent);
ref = qof_class_get_referenceList(GNC_ID_TRANS);
while (ref != NULL)
{
ent_ref = qof_instance_get_reference_from(QOF_INSTANCE(trans), ref->data);
qof_session_update_reference_list(data->chart_session, ent_ref);
ref = g_list_next(ref);
}
g_list_free(ref);
ref = qof_class_get_referenceList(GNC_ID_SPLIT);
while (ref != NULL)
{
ent_ref = qof_instance_get_reference_from(QOF_INSTANCE(split), ref->data);
qof_session_update_reference_list(data->chart_session, ent_ref);
ref = g_list_next(ref);
}
g_list_free(ref);
}
void
gnc_main_window_chart_export(void)
{
GladeXML *xml;
chart_data *data;
GladeXML *xml;
chart_data *data;
xml = gnc_glade_xml_new ("chart-export.glade", "chart-export");
data = g_new0(chart_data, 1);
data->xml = xml;
data->dialog = glade_xml_get_widget(xml, "chart-export");
data->calendar = glade_xml_get_widget(xml, "chart-calendar");
glade_xml_signal_autoconnect_full(xml,
gnc_glade_autoconnect_full_func,
data);
gtk_widget_show(data->dialog);
xml = gnc_glade_xml_new ("chart-export.glade", "chart-export");
data = g_new0(chart_data, 1);
data->xml = xml;
data->dialog = glade_xml_get_widget(xml, "chart-export");
data->calendar = glade_xml_get_widget(xml, "chart-calendar");
glade_xml_signal_autoconnect_full(xml,
gnc_glade_autoconnect_full_func,
data);
gtk_widget_show(data->dialog);
}
static void
on_dateok_clicked (chart_data *data)
{
guint year, month, day;
struct tm *chart_tm;
gchar *filename;
QofSession *current_session, *chart_session;
QofBook *book;
QofCollection *coll;
guint year, month, day;
struct tm *chart_tm;
gchar *filename;
QofSession *current_session, *chart_session;
QofBook *book;
QofCollection *coll;
data->chart_time_t = time(NULL);
chart_tm = gmtime(&data->chart_time_t);
/* set today - calendar will omit any zero/NULL values */
year = chart_tm->tm_year + 1900;
month = chart_tm->tm_mon + 1;
day = chart_tm->tm_mday;
gtk_calendar_get_date(GTK_CALENDAR(data->calendar),
&year, &month, &day);
if((year + 1900) != chart_tm->tm_year) {
chart_tm->tm_year = year - 1900;
}
if(month != chart_tm->tm_mon) {
chart_tm->tm_mon = month;
}
if(day != chart_tm->tm_yday) {
chart_tm->tm_mday = day;
}
data->chart_time_t = mktime(chart_tm);
current_session = gnc_get_current_session();
book = qof_session_get_book(current_session);
chart_session = qof_session_new();
filename = gnc_file_dialog(_("Export Chart of Accounts to QSF XML"),
NULL, NULL, GNC_FILE_DIALOG_EXPORT);
if (filename)
{
gnc_set_busy_cursor(NULL, TRUE);
qof_event_suspend();
qof_session_begin(chart_session, filename, TRUE, TRUE);
data->chart_session = chart_session;
data->equity_account = NULL;
coll = qof_book_get_collection(book, GNC_ID_ACCOUNT);
qof_collection_foreach(coll, chart_collection_cb, data);
if(data->equity_account == NULL)
{
data->equity_account = xaccMallocAccount (qof_session_get_book(chart_session));
xaccAccountBeginEdit (data->equity_account);
xaccAccountSetName (data->equity_account, EQUITY_ACCOUNT_NAME);
xaccAccountSetDescription(data->equity_account, EQUITY_ACCOUNT_NAME);
xaccAccountSetType (data->equity_account, ACCT_TYPE_EQUITY);
xaccAccountSetCommodity (data->equity_account, gnc_default_currency());
}
qof_object_foreach(GNC_ID_ACCOUNT, book, chart_entity_cb, data);
data->param_ref_list = qof_class_get_referenceList(GNC_ID_TRANS);
qof_object_foreach(GNC_ID_TRANS, book, chart_reference_cb, data);
g_list_free(data->param_ref_list);
data->param_ref_list = qof_class_get_referenceList(GNC_ID_SPLIT);
qof_object_foreach(GNC_ID_SPLIT, book, chart_reference_cb, data);
g_list_free(data->param_ref_list);
qof_session_save(chart_session, NULL);
show_session_error(qof_session_get_error(chart_session),
filename, GNC_FILE_DIALOG_EXPORT);
qof_event_resume();
gnc_unset_busy_cursor(NULL);
}
qof_session_end(chart_session);
gnc_set_current_session(current_session);
data->chart_time_t = time(NULL);
chart_tm = gmtime(&data->chart_time_t);
/* set today - calendar will omit any zero/NULL values */
year = chart_tm->tm_year + 1900;
month = chart_tm->tm_mon + 1;
day = chart_tm->tm_mday;
gtk_calendar_get_date(GTK_CALENDAR(data->calendar),
&year, &month, &day);
if ((year + 1900) != chart_tm->tm_year)
{
chart_tm->tm_year = year - 1900;
}
if (month != chart_tm->tm_mon)
{
chart_tm->tm_mon = month;
}
if (day != chart_tm->tm_yday)
{
chart_tm->tm_mday = day;
}
data->chart_time_t = mktime(chart_tm);
current_session = gnc_get_current_session();
book = qof_session_get_book(current_session);
chart_session = qof_session_new();
filename = gnc_file_dialog(_("Export Chart of Accounts to QSF XML"),
NULL, NULL, GNC_FILE_DIALOG_EXPORT);
if (filename)
{
gnc_set_busy_cursor(NULL, TRUE);
qof_event_suspend();
qof_session_begin(chart_session, filename, TRUE, TRUE);
data->chart_session = chart_session;
data->equity_account = NULL;
coll = qof_book_get_collection(book, GNC_ID_ACCOUNT);
qof_collection_foreach(coll, chart_collection_cb, data);
if (data->equity_account == NULL)
{
data->equity_account = xaccMallocAccount (qof_session_get_book(chart_session));
xaccAccountBeginEdit (data->equity_account);
xaccAccountSetName (data->equity_account, EQUITY_ACCOUNT_NAME);
xaccAccountSetDescription(data->equity_account, EQUITY_ACCOUNT_NAME);
xaccAccountSetType (data->equity_account, ACCT_TYPE_EQUITY);
xaccAccountSetCommodity (data->equity_account, gnc_default_currency());
}
qof_object_foreach(GNC_ID_ACCOUNT, book, chart_entity_cb, data);
data->param_ref_list = qof_class_get_referenceList(GNC_ID_TRANS);
qof_object_foreach(GNC_ID_TRANS, book, chart_reference_cb, data);
g_list_free(data->param_ref_list);
data->param_ref_list = qof_class_get_referenceList(GNC_ID_SPLIT);
qof_object_foreach(GNC_ID_SPLIT, book, chart_reference_cb, data);
g_list_free(data->param_ref_list);
qof_session_save(chart_session, NULL);
show_session_error(qof_session_get_error(chart_session),
filename, GNC_FILE_DIALOG_EXPORT);
qof_event_resume();
gnc_unset_busy_cursor(NULL);
}
qof_session_end(chart_session);
gnc_set_current_session(current_session);
}
void
chart_export_response_cb (GtkDialog *dialog, gint response, gpointer user_data)
{
chart_data *data;
data = (chart_data*)user_data;
switch (response) {
case GTK_RESPONSE_OK:
gtk_widget_hide(data->dialog);
on_dateok_clicked(data);
break;
chart_data *data;
data = (chart_data*)user_data;
switch (response)
{
case GTK_RESPONSE_OK:
gtk_widget_hide(data->dialog);
on_dateok_clicked(data);
break;
default:
/* do nothing */
break;
}
default:
/* do nothing */
break;
}
gtk_widget_destroy(data->dialog);
g_object_unref(data->xml);
g_free(data);
gtk_widget_destroy(data->dialog);
g_object_unref(data->xml);
g_free(data);
}

View File

@@ -22,7 +22,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#ifndef _DIALOG_CHART_EXPORT_H
#define _DIALOG_CHART_EXPORT_H
@@ -33,7 +33,7 @@
Remember to use qof_instance_copy routines
like ::qof_instance_copy_to_session so that the QofBook is marked
as \a partial.
as \a partial.
\par guidelines Guidelines for partial book export
-# When exporting GnuCash accounts into QSF, remember that there is no
@@ -45,7 +45,7 @@ as \a partial.
-# Remember that just because the function does not use books or AccountGroup
itself, it does \b not follow that other functions called by the routine
are also suitable. You may have to reimplement the body of certain functions.
-# Commodities are \b not supported. Most Account functions will use the
-# Commodities are \b not supported. Most Account functions will use the
commodity of the account, so be sure to set at least the ::gnc_default_currency().
@{
@@ -60,7 +60,7 @@ as \a partial.
Write out the Chart of Accounts \b with balances as of a
specific date, as QSF.
The function iterates over each account in the current book and
The function iterates over each account in the current book and
gets the balance as of the specified date. The account is copied to
the export session, setting the export session book as partial.
The function then looks up the new entity in the export session

View File

@@ -48,16 +48,16 @@
typedef struct
{
GtkWidget * dialog;
QofSession *session;
QofBook *book;
GtkWidget * dialog;
QofSession *session;
QofBook *book;
GncTreeViewCommodity * commodity_tree;
GtkWidget * edit_button;
GtkWidget * remove_button;
gboolean show_currencies;
GncTreeViewCommodity * commodity_tree;
GtkWidget * edit_button;
GtkWidget * remove_button;
gboolean show_currencies;
gboolean new;
gboolean new;
} CommoditiesDialog;
@@ -70,355 +70,358 @@ void gnc_commodities_show_currencies_toggled (GtkToggleButton *toggle, Commoditi
void
gnc_commodities_window_destroy_cb (GtkObject *object, CommoditiesDialog *cd)
{
gnc_unregister_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
gnc_unregister_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
g_free (cd);
g_free (cd);
}
static void
edit_clicked (CommoditiesDialog *cd)
{
gnc_commodity *commodity;
gnc_commodity *commodity;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
if (commodity == NULL)
return;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
if (commodity == NULL)
return;
if (gnc_ui_edit_commodity_modal (commodity, cd->dialog))
gnc_gui_refresh_all ();
if (gnc_ui_edit_commodity_modal (commodity, cd->dialog))
gnc_gui_refresh_all ();
}
static void
row_activated_cb (GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *column, CommoditiesDialog *cd)
{
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeIter iter;
g_return_if_fail(view);
g_return_if_fail(view);
model = gtk_tree_view_get_model(view);
if (gtk_tree_model_get_iter(model, &iter, path))
{
if (gtk_tree_model_iter_has_child(model, &iter))
model = gtk_tree_view_get_model(view);
if (gtk_tree_model_get_iter(model, &iter, path))
{
/* There are children, so it's not a commodity.
* Just expand or collapse the row. */
if (gtk_tree_view_row_expanded(view, path))
gtk_tree_view_collapse_row(view, path);
else
gtk_tree_view_expand_row(view, path, FALSE);
if (gtk_tree_model_iter_has_child(model, &iter))
{
/* There are children, so it's not a commodity.
* Just expand or collapse the row. */
if (gtk_tree_view_row_expanded(view, path))
gtk_tree_view_collapse_row(view, path);
else
gtk_tree_view_expand_row(view, path, FALSE);
}
else
/* It's a commodity, so click the Edit button. */
edit_clicked(cd);
}
else
/* It's a commodity, so click the Edit button. */
edit_clicked(cd);
}
}
static void
remove_clicked (CommoditiesDialog *cd)
{
GNCPriceDB *pdb;
GList *node;
GList *prices;
GList *accounts;
gboolean do_delete;
gboolean can_delete;
gnc_commodity *commodity;
GtkWidget *dialog;
const gchar *message, *warning;
gint response;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
if (commodity == NULL)
return;
GNCPriceDB *pdb;
GList *node;
GList *prices;
GList *accounts;
gboolean do_delete;
gboolean can_delete;
gnc_commodity *commodity;
GtkWidget *dialog;
const gchar *message, *warning;
gint response;
accounts = gnc_account_get_descendants (gnc_book_get_root_account(cd->book));
can_delete = TRUE;
do_delete = FALSE;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
if (commodity == NULL)
return;
for (node = accounts; node; node = node->next)
{
Account *account = node->data;
accounts = gnc_account_get_descendants (gnc_book_get_root_account(cd->book));
can_delete = TRUE;
do_delete = FALSE;
if (commodity == xaccAccountGetCommodity (account))
for (node = accounts; node; node = node->next)
{
can_delete = FALSE;
break;
Account *account = node->data;
if (commodity == xaccAccountGetCommodity (account))
{
can_delete = FALSE;
break;
}
}
}
/* FIXME check for transaction references */
/* FIXME check for transaction references */
if (!can_delete)
{
const char *message = _("That commodity is currently used by "
"at least one of your accounts. You may "
"not delete it.");
if (!can_delete)
{
const char *message = _("That commodity is currently used by "
"at least one of your accounts. You may "
"not delete it.");
gnc_warning_dialog (cd->dialog, "%s", message);
gnc_warning_dialog (cd->dialog, "%s", message);
g_list_free (accounts);
return;
}
g_list_free (accounts);
return;
}
g_list_free (accounts);
pdb = gnc_pricedb_get_db (cd->book);
prices = gnc_pricedb_get_prices(pdb, commodity, NULL);
if (prices)
{
message = _("This commodity has price quotes. Are "
"you sure you want to delete the selected "
"commodity and its price quotes?");
warning = "delete_commodity2";
} else {
message = _("Are you sure you want to delete the "
"selected commodity?");
warning = "delete_commodity";
}
pdb = gnc_pricedb_get_db (cd->book);
prices = gnc_pricedb_get_prices(pdb, commodity, NULL);
if (prices)
{
message = _("This commodity has price quotes. Are "
"you sure you want to delete the selected "
"commodity and its price quotes?");
warning = "delete_commodity2";
}
else
{
message = _("Are you sure you want to delete the "
"selected commodity?");
warning = "delete_commodity";
}
dialog = gtk_message_dialog_new(GTK_WINDOW(cd->dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s", _("Delete commodity?"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", message);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_DELETE, GTK_RESPONSE_OK,
(gchar *)NULL);
response = gnc_dialog_run(GTK_DIALOG(dialog), warning);
gtk_widget_destroy(dialog);
dialog = gtk_message_dialog_new(GTK_WINDOW(cd->dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s", _("Delete commodity?"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", message);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_DELETE, GTK_RESPONSE_OK,
(gchar *)NULL);
response = gnc_dialog_run(GTK_DIALOG(dialog), warning);
gtk_widget_destroy(dialog);
if (response == GTK_RESPONSE_OK)
{
gnc_commodity_table *ct;
if (response == GTK_RESPONSE_OK)
{
gnc_commodity_table *ct;
ct = gnc_book_get_commodity_table (cd->book);
for (node = prices; node; node = node->next)
gnc_pricedb_remove_price(pdb, node->data);
ct = gnc_book_get_commodity_table (cd->book);
for (node = prices; node; node = node->next)
gnc_pricedb_remove_price(pdb, node->data);
gnc_commodity_table_remove (ct, commodity);
gnc_commodity_destroy (commodity);
commodity = NULL;
}
gnc_commodity_table_remove (ct, commodity);
gnc_commodity_destroy (commodity);
commodity = NULL;
}
gnc_price_list_destroy(prices);
gnc_gui_refresh_all ();
gnc_price_list_destroy(prices);
gnc_gui_refresh_all ();
}
static void
add_clicked (CommoditiesDialog *cd)
{
gnc_commodity *commodity;
const char *namespace;
gnc_commodity *commodity;
const char *namespace;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
if (commodity)
namespace = gnc_commodity_get_namespace (commodity);
else
namespace = NULL;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
if (commodity)
namespace = gnc_commodity_get_namespace (commodity);
else
namespace = NULL;
commodity = gnc_ui_new_commodity_modal (namespace, cd->dialog);
commodity = gnc_ui_new_commodity_modal (namespace, cd->dialog);
}
void
gnc_commodities_dialog_response (GtkDialog *dialog,
gint response,
CommoditiesDialog *cd)
gint response,
CommoditiesDialog *cd)
{
switch (response) {
case GNC_RESPONSE_NEW:
add_clicked (cd);
return;
switch (response)
{
case GNC_RESPONSE_NEW:
add_clicked (cd);
return;
case GNC_RESPONSE_DELETE:
remove_clicked (cd);
return;
case GNC_RESPONSE_DELETE:
remove_clicked (cd);
return;
case GNC_RESPONSE_EDIT:
edit_clicked (cd);
return;
case GNC_RESPONSE_EDIT:
edit_clicked (cd);
return;
case GTK_RESPONSE_CLOSE:
default:
gnc_close_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
return;
}
case GTK_RESPONSE_CLOSE:
default:
gnc_close_gui_component_by_data (DIALOG_COMMODITIES_CM_CLASS, cd);
return;
}
}
static void
gnc_commodities_dialog_selection_changed (GtkTreeSelection *selection,
CommoditiesDialog *cd)
CommoditiesDialog *cd)
{
gboolean remove_ok;
gnc_commodity *commodity;
gboolean remove_ok;
gnc_commodity *commodity;
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
remove_ok = commodity && !gnc_commodity_is_iso(commodity);
gtk_widget_set_sensitive (cd->edit_button, commodity != NULL);
gtk_widget_set_sensitive (cd->remove_button, remove_ok);
commodity = gnc_tree_view_commodity_get_selected_commodity (cd->commodity_tree);
remove_ok = commodity && !gnc_commodity_is_iso(commodity);
gtk_widget_set_sensitive (cd->edit_button, commodity != NULL);
gtk_widget_set_sensitive (cd->remove_button, remove_ok);
}
void
gnc_commodities_show_currencies_toggled (GtkToggleButton *toggle,
CommoditiesDialog *cd)
CommoditiesDialog *cd)
{
cd->show_currencies = gtk_toggle_button_get_active (toggle);
gnc_tree_view_commodity_refilter (cd->commodity_tree);
cd->show_currencies = gtk_toggle_button_get_active (toggle);
gnc_tree_view_commodity_refilter (cd->commodity_tree);
}
static gboolean
gnc_commodities_dialog_filter_ns_func (gnc_commodity_namespace *namespace,
gpointer data)
gpointer data)
{
CommoditiesDialog *cd = data;
const gchar *name;
GList *list;
CommoditiesDialog *cd = data;
const gchar *name;
GList *list;
/* Never show the template list */
name = gnc_commodity_namespace_get_name (namespace);
if (safe_strcmp (name, "template") == 0)
return FALSE;
/* Never show the template list */
name = gnc_commodity_namespace_get_name (namespace);
if (safe_strcmp (name, "template") == 0)
return FALSE;
/* Check whether or not to show commodities */
if (!cd->show_currencies && gnc_commodity_namespace_is_iso(name))
return FALSE;
/* Check whether or not to show commodities */
if (!cd->show_currencies && gnc_commodity_namespace_is_iso(name))
return FALSE;
/* Show any other namespace that has commodities */
list = gnc_commodity_namespace_get_commodity_list(namespace);
return (list != NULL);
/* Show any other namespace that has commodities */
list = gnc_commodity_namespace_get_commodity_list(namespace);
return (list != NULL);
}
static gboolean
gnc_commodities_dialog_filter_cm_func (gnc_commodity *commodity,
gpointer data)
gpointer data)
{
CommoditiesDialog *cd = data;
CommoditiesDialog *cd = data;
if (cd->show_currencies)
return TRUE;
return !gnc_commodity_is_iso(commodity);
if (cd->show_currencies)
return TRUE;
return !gnc_commodity_is_iso(commodity);
}
static void
gnc_commodities_dialog_create (GtkWidget * parent, CommoditiesDialog *cd)
{
GtkWidget *dialog;
GtkWidget *button;
GtkWidget *scrolled_window;
GladeXML *xml;
GtkTreeView *view;
GtkTreeSelection *selection;
xml = gnc_glade_xml_new ("commodities.glade", "Securities Dialog");
dialog = glade_xml_get_widget (xml, "Securities Dialog");
GtkWidget *dialog;
GtkWidget *button;
GtkWidget *scrolled_window;
GladeXML *xml;
GtkTreeView *view;
GtkTreeSelection *selection;
cd->dialog = dialog;
cd->session = gnc_get_current_session();
cd->book = qof_session_get_book(cd->session);
cd->show_currencies = gnc_gconf_get_bool(GCONF_SECTION, "include_iso", NULL);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, cd);
xml = gnc_glade_xml_new ("commodities.glade", "Securities Dialog");
dialog = glade_xml_get_widget (xml, "Securities Dialog");
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
cd->dialog = dialog;
cd->session = gnc_get_current_session();
cd->book = qof_session_get_book(cd->session);
cd->show_currencies = gnc_gconf_get_bool(GCONF_SECTION, "include_iso", NULL);
/* buttons */
cd->remove_button = glade_xml_get_widget (xml, "remove_button");
cd->edit_button = glade_xml_get_widget (xml, "edit_button");
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, cd);
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
/* buttons */
cd->remove_button = glade_xml_get_widget (xml, "remove_button");
cd->edit_button = glade_xml_get_widget (xml, "edit_button");
/* commodity tree */
/* commodity tree */
scrolled_window = glade_xml_get_widget (xml, "commodity_list_window");
view = gnc_tree_view_commodity_new(cd->book,
"gconf-section", GCONF_SECTION,
"show-column-menu", TRUE,
NULL);
"gconf-section", GCONF_SECTION,
"show-column-menu", TRUE,
NULL);
cd->commodity_tree = GNC_TREE_VIEW_COMMODITY(view);
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(cd->commodity_tree), TRUE);
gnc_tree_view_commodity_set_filter (cd->commodity_tree,
gnc_commodities_dialog_filter_ns_func,
gnc_commodities_dialog_filter_cm_func,
cd, NULL);
gnc_commodities_dialog_filter_ns_func,
gnc_commodities_dialog_filter_cm_func,
cd, NULL);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_commodities_dialog_selection_changed), cd);
G_CALLBACK (gnc_commodities_dialog_selection_changed), cd);
g_signal_connect (G_OBJECT (cd->commodity_tree), "row-activated",
G_CALLBACK (row_activated_cb), cd);
G_CALLBACK (row_activated_cb), cd);
/* Show currency button */
button = glade_xml_get_widget (xml, "show_currencies_button");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(button), cd->show_currencies);
gnc_restore_window_size (GCONF_SECTION, GTK_WINDOW(cd->dialog));
gnc_restore_window_size (GCONF_SECTION, GTK_WINDOW(cd->dialog));
}
static void
close_handler (gpointer user_data)
{
CommoditiesDialog *cd = user_data;
CommoditiesDialog *cd = user_data;
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(cd->dialog));
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(cd->dialog));
gnc_gconf_set_bool(GCONF_SECTION, "include_iso", cd->show_currencies, NULL);
gnc_gconf_set_bool(GCONF_SECTION, "include_iso", cd->show_currencies, NULL);
gtk_widget_destroy(cd->dialog);
gtk_widget_destroy(cd->dialog);
}
static void
refresh_handler (GHashTable *changes, gpointer user_data)
{
CommoditiesDialog *cd = user_data;
CommoditiesDialog *cd = user_data;
g_return_if_fail(cd != NULL);
g_return_if_fail(cd != NULL);
gnc_tree_view_commodity_refilter (cd->commodity_tree);
gnc_tree_view_commodity_refilter (cd->commodity_tree);
}
static gboolean
show_handler (const char *class, gint component_id,
gpointer user_data, gpointer iter_data)
gpointer user_data, gpointer iter_data)
{
CommoditiesDialog *cd = user_data;
CommoditiesDialog *cd = user_data;
if (!cd)
return(FALSE);
gtk_window_present (GTK_WINDOW(cd->dialog));
return(TRUE);
if (!cd)
return(FALSE);
gtk_window_present (GTK_WINDOW(cd->dialog));
return(TRUE);
}
/********************************************************************\
* gnc_commodities_dialog *
* opens up a window to edit price information *
* *
* *
* Args: parent - the parent of the window to be created *
* Return: nothing *
\********************************************************************/
void
gnc_commodities_dialog (GtkWidget * parent)
{
CommoditiesDialog *cd;
gint component_id;
CommoditiesDialog *cd;
gint component_id;
if (gnc_forall_gui_components (DIALOG_COMMODITIES_CM_CLASS,
show_handler, NULL))
return;
if (gnc_forall_gui_components (DIALOG_COMMODITIES_CM_CLASS,
show_handler, NULL))
return;
cd = g_new0 (CommoditiesDialog, 1);
cd = g_new0 (CommoditiesDialog, 1);
gnc_commodities_dialog_create (parent, cd);
gnc_commodities_dialog_create (parent, cd);
component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS,
refresh_handler, close_handler,
cd);
gnc_gui_component_set_session (component_id, cd->session);
component_id = gnc_register_gui_component (DIALOG_COMMODITIES_CM_CLASS,
refresh_handler, close_handler,
cd);
gnc_gui_component_set_session (component_id, cd->session);
gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree));
gtk_widget_grab_focus (GTK_WIDGET(cd->commodity_tree));
gtk_widget_show (cd->dialog);
gtk_widget_show (cd->dialog);
}

View File

@@ -45,34 +45,34 @@
typedef enum
{
PAYMENT_PERIODS = 0,
INTEREST_RATE,
PRESENT_VALUE,
PERIODIC_PAYMENT,
FUTURE_VALUE,
NUM_FIN_CALC_VALUES
PAYMENT_PERIODS = 0,
INTEREST_RATE,
PRESENT_VALUE,
PERIODIC_PAYMENT,
FUTURE_VALUE,
NUM_FIN_CALC_VALUES
} FinCalcValue;
/** Datatypes ***********************************************************/
struct _FinCalcDialog
{
GladeXML *xml;
GtkWidget *dialog;
GladeXML *xml;
GtkWidget *dialog;
GtkWidget *amounts[NUM_FIN_CALC_VALUES];
GtkWidget *amounts[NUM_FIN_CALC_VALUES];
GtkWidget *calc_button;
GtkWidget *calc_button;
GtkWidget *compounding_combo;
GtkWidget *payment_combo;
GtkWidget *compounding_combo;
GtkWidget *payment_combo;
GtkWidget *end_of_period_radio;
GtkWidget *discrete_compounding_radio;
GtkWidget *end_of_period_radio;
GtkWidget *discrete_compounding_radio;
GtkWidget *payment_total_label;
GtkWidget *payment_total_label;
financial_info financial_info;
financial_info financial_info;
};
static unsigned int periods[] =
@@ -82,12 +82,12 @@ static unsigned int periods[] =
3, /* tri-annual */
4, /* quarterly */
6, /* bi-monthly */
12, /* monthly */
24, /* semi-monthly */
26, /* bi-weekly */
52, /* weekly */
360, /* daily (360) */
365, /* daily (365) */
12, /* monthly */
24, /* semi-monthly */
26, /* bi-weekly */
52, /* weekly */
360, /* daily (360) */
365, /* daily (365) */
};
/* This static indicates the debugging module that this .o belongs to. */
@@ -108,69 +108,69 @@ void fincalc_response_cb (GtkDialog *dialog, gint response, FinCalcDialog *fcd);
static int
normalize_period(unsigned int *period)
{
int i;
int i;
g_return_val_if_fail (period, 0);
g_return_val_if_fail (period, 0);
for (i = (sizeof(periods) / sizeof(unsigned int)) - 1; i >= 0; i--)
if (*period >= periods[i])
{
*period = periods[i];
return i;
}
for (i = (sizeof(periods) / sizeof(unsigned int)) - 1; i >= 0; i--)
if (*period >= periods[i])
{
*period = periods[i];
return i;
}
*period = periods[0];
*period = periods[0];
return 0;
return 0;
}
/* Copy the values in the financial_info structure to the GUI */
static void
fi_to_gui(FinCalcDialog *fcd)
{
const gnc_commodity *commodity;
static char string[64];
gnc_numeric total;
gnc_numeric npp;
gnc_numeric pmt;
int i;
const gnc_commodity *commodity;
static char string[64];
gnc_numeric total;
gnc_numeric npp;
gnc_numeric pmt;
int i;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
npp = gnc_numeric_create (fcd->financial_info.npp, 1);
npp = gnc_numeric_create (fcd->financial_info.npp, 1);
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]),
npp);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[INTEREST_RATE]),
fcd->financial_info.ir);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PRESENT_VALUE]),
fcd->financial_info.pv);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PERIODIC_PAYMENT]),
fcd->financial_info.pmt);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[FUTURE_VALUE]),
-fcd->financial_info.fv);
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]),
npp);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[INTEREST_RATE]),
fcd->financial_info.ir);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PRESENT_VALUE]),
fcd->financial_info.pv);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[PERIODIC_PAYMENT]),
fcd->financial_info.pmt);
gnc_amount_edit_set_damount (GNC_AMOUNT_EDIT(fcd->amounts[FUTURE_VALUE]),
-fcd->financial_info.fv);
pmt = double_to_gnc_numeric (fcd->financial_info.pmt, 100000, GNC_RND_ROUND);
pmt = double_to_gnc_numeric (fcd->financial_info.pmt, 100000, GNC_RND_ROUND);
commodity = gnc_default_currency ();
commodity = gnc_default_currency ();
total = gnc_numeric_mul (npp, pmt, gnc_commodity_get_fraction (commodity),
GNC_RND_ROUND);
total = gnc_numeric_mul (npp, pmt, gnc_commodity_get_fraction (commodity),
GNC_RND_ROUND);
xaccSPrintAmount (string, total, gnc_default_print_info (FALSE));
gtk_label_set_text (GTK_LABEL(fcd->payment_total_label), string);
xaccSPrintAmount (string, total, gnc_default_print_info (FALSE));
gtk_label_set_text (GTK_LABEL(fcd->payment_total_label), string);
i = normalize_period(&fcd->financial_info.CF);
gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->compounding_combo), i);
i = normalize_period(&fcd->financial_info.CF);
gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->compounding_combo), i);
i = normalize_period(&fcd->financial_info.PF);
gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->payment_combo), i);
i = normalize_period(&fcd->financial_info.PF);
gtk_combo_box_set_active(GTK_COMBO_BOX(fcd->payment_combo), i);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fcd->end_of_period_radio),
!fcd->financial_info.bep);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fcd->end_of_period_radio),
!fcd->financial_info.bep);
gtk_toggle_button_set_active
gtk_toggle_button_set_active
(GTK_TOGGLE_BUTTON(fcd->discrete_compounding_radio),
fcd->financial_info.disc);
}
@@ -179,124 +179,126 @@ fi_to_gui(FinCalcDialog *fcd)
static void
gui_to_fi(FinCalcDialog *fcd)
{
GtkToggleButton *toggle;
gnc_numeric npp;
int i;
GtkToggleButton *toggle;
gnc_numeric npp;
int i;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
npp =
gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]));
fcd->financial_info.npp = npp.num;
npp =
gnc_amount_edit_get_amount(GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]));
fcd->financial_info.npp = npp.num;
fcd->financial_info.ir =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[INTEREST_RATE]));
fcd->financial_info.ir =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[INTEREST_RATE]));
fcd->financial_info.pv =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[PRESENT_VALUE]));
fcd->financial_info.pv =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[PRESENT_VALUE]));
fcd->financial_info.pmt =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[PERIODIC_PAYMENT]));
fcd->financial_info.pmt =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[PERIODIC_PAYMENT]));
fcd->financial_info.fv =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[FUTURE_VALUE]));
fcd->financial_info.fv = -fcd->financial_info.fv;
fcd->financial_info.fv =
gnc_amount_edit_get_damount(GNC_AMOUNT_EDIT(fcd->amounts[FUTURE_VALUE]));
fcd->financial_info.fv = -fcd->financial_info.fv;
i = gtk_combo_box_get_active(GTK_COMBO_BOX(fcd->compounding_combo));
fcd->financial_info.CF = periods[i];
i = gtk_combo_box_get_active(GTK_COMBO_BOX(fcd->compounding_combo));
fcd->financial_info.CF = periods[i];
i = gtk_combo_box_get_active(GTK_COMBO_BOX(fcd->payment_combo));
fcd->financial_info.PF = periods[i];
i = gtk_combo_box_get_active(GTK_COMBO_BOX(fcd->payment_combo));
fcd->financial_info.PF = periods[i];
toggle = GTK_TOGGLE_BUTTON(fcd->end_of_period_radio);
fcd->financial_info.bep = !gtk_toggle_button_get_active(toggle);
toggle = GTK_TOGGLE_BUTTON(fcd->end_of_period_radio);
fcd->financial_info.bep = !gtk_toggle_button_get_active(toggle);
toggle = GTK_TOGGLE_BUTTON(fcd->discrete_compounding_radio);
fcd->financial_info.disc = gtk_toggle_button_get_active(toggle);
toggle = GTK_TOGGLE_BUTTON(fcd->discrete_compounding_radio);
fcd->financial_info.disc = gtk_toggle_button_get_active(toggle);
fcd->financial_info.prec = gnc_locale_decimal_places ();
fcd->financial_info.prec = gnc_locale_decimal_places ();
}
/* Set the sensitivity of the calculation buttons based on the argument. */
void
fincalc_update_calc_button_cb(GtkWidget *unused, FinCalcDialog *fcd)
{
const gchar *text;
gint i;
const gchar *text;
gint i;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
for (i = 0; i < NUM_FIN_CALC_VALUES; i++) {
text = gtk_entry_get_text(GTK_ENTRY(fcd->amounts[i]));
if ((text == NULL) || (*text == '\0')) {
gtk_widget_set_sensitive(GTK_WIDGET(fcd->calc_button), TRUE);
return;
for (i = 0; i < NUM_FIN_CALC_VALUES; i++)
{
text = gtk_entry_get_text(GTK_ENTRY(fcd->amounts[i]));
if ((text == NULL) || (*text == '\0'))
{
gtk_widget_set_sensitive(GTK_WIDGET(fcd->calc_button), TRUE);
return;
}
}
}
gtk_widget_set_sensitive(GTK_WIDGET(fcd->calc_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(fcd->calc_button), FALSE);
}
/* Free the calc button list and free the FinCalcDialog structure. */
static void
fincalc_dialog_destroy(GtkObject *object, gpointer data)
{
FinCalcDialog *fcd = data;
FinCalcDialog *fcd = data;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
gnc_unregister_gui_component_by_data (DIALOG_FINCALC_CM_CLASS, fcd);
gnc_unregister_gui_component_by_data (DIALOG_FINCALC_CM_CLASS, fcd);
g_object_unref(fcd->xml);
g_free(fcd);
g_object_unref(fcd->xml);
g_free(fcd);
}
void
fincalc_compounding_radio_toggled(GtkToggleButton *togglebutton, gpointer data)
{
FinCalcDialog *fcd = data;
gboolean sensitive;
FinCalcDialog *fcd = data;
gboolean sensitive;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
fincalc_update_calc_button_cb(GTK_WIDGET(togglebutton), fcd);
fincalc_update_calc_button_cb(GTK_WIDGET(togglebutton), fcd);
sensitive = gtk_toggle_button_get_active (togglebutton);
sensitive = gtk_toggle_button_get_active (togglebutton);
gtk_widget_set_sensitive (fcd->compounding_combo, sensitive);
gtk_widget_set_sensitive (fcd->compounding_combo, sensitive);
}
void
fincalc_amount_clear_clicked_cb(GtkButton *button, GNCAmountEdit *edit)
{
gtk_entry_set_text(GTK_ENTRY (edit), "");
gtk_entry_set_text(GTK_ENTRY (edit), "");
}
static void
init_fi(FinCalcDialog *fcd)
{
struct lconv *lc;
struct lconv *lc;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
lc = gnc_localeconv();
lc = gnc_localeconv();
fcd->financial_info.npp = 12;
fcd->financial_info.ir = 8.5;
fcd->financial_info.pv = 15000.0;
fcd->financial_info.pmt = -400.0;
fcd->financial_info.CF = 12;
fcd->financial_info.PF = 12;
fcd->financial_info.bep = FALSE;
fcd->financial_info.disc = TRUE;
fcd->financial_info.prec = lc->frac_digits;
fcd->financial_info.npp = 12;
fcd->financial_info.ir = 8.5;
fcd->financial_info.pv = 15000.0;
fcd->financial_info.pmt = -400.0;
fcd->financial_info.CF = 12;
fcd->financial_info.PF = 12;
fcd->financial_info.bep = FALSE;
fcd->financial_info.disc = TRUE;
fcd->financial_info.prec = lc->frac_digits;
fi_calc_future_value(&fcd->financial_info);
fi_calc_future_value(&fcd->financial_info);
}
/* Determine whether the value can be calculated. If it can, return
@@ -305,188 +307,190 @@ init_fi(FinCalcDialog *fcd)
static const char *
can_calc_value(FinCalcDialog *fcd, FinCalcValue value, int *error_item)
{
const char *missing = _("This program can only calculate one value at a time. "
"You must enter values for all but one quantity.");
const char *bad_exp = _("GnuCash cannot determine the value in one of the fields. "
"You must enter a valid expression.");
const char *string;
gnc_numeric nvalue;
unsigned int i;
const char *missing = _("This program can only calculate one value at a time. "
"You must enter values for all but one quantity.");
const char *bad_exp = _("GnuCash cannot determine the value in one of the fields. "
"You must enter a valid expression.");
const char *string;
gnc_numeric nvalue;
unsigned int i;
if (fcd == NULL)
return NULL;
if (fcd == NULL)
return NULL;
/* Check for missing values */
for (i = 0; i < NUM_FIN_CALC_VALUES; i++)
if (i != value)
/* Check for missing values */
for (i = 0; i < NUM_FIN_CALC_VALUES; i++)
if (i != value)
{
string = gtk_entry_get_text(GTK_ENTRY(fcd->amounts[i]));
if ((string == NULL) || (*string == '\0'))
{
*error_item = i;
return missing;
}
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (fcd->amounts[i])))
{
*error_item = i;
return bad_exp;
}
}
/* Check for zero interest */
switch (value)
{
string = gtk_entry_get_text(GTK_ENTRY(fcd->amounts[i]));
if ((string == NULL) || (*string == '\0'))
{
*error_item = i;
return missing;
}
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (fcd->amounts[i])))
{
*error_item = i;
return bad_exp;
}
}
/* Check for zero interest */
switch (value)
{
case PAYMENT_PERIODS:
case PRESENT_VALUE:
case PERIODIC_PAYMENT:
case FUTURE_VALUE:
nvalue = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT (fcd->amounts[INTEREST_RATE]));
if (gnc_numeric_zero_p (nvalue))
{
*error_item = INTEREST_RATE;
return _("The interest rate cannot be zero.");
}
break;
nvalue = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT (fcd->amounts[INTEREST_RATE]));
if (gnc_numeric_zero_p (nvalue))
{
*error_item = INTEREST_RATE;
return _("The interest rate cannot be zero.");
}
break;
default:
break;
}
break;
}
/* Check for zero payment periods */
switch (value)
{
/* Check for zero payment periods */
switch (value)
{
case INTEREST_RATE:
case PRESENT_VALUE:
case PERIODIC_PAYMENT:
case FUTURE_VALUE:
nvalue = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]));
if (gnc_numeric_zero_p (nvalue))
{
*error_item = PAYMENT_PERIODS;
return _("The number of payments cannot be zero.");
}
if (gnc_numeric_negative_p (nvalue))
{
*error_item = PAYMENT_PERIODS;
return _("The number of payments cannot be negative.");
}
break;
nvalue = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT(fcd->amounts[PAYMENT_PERIODS]));
if (gnc_numeric_zero_p (nvalue))
{
*error_item = PAYMENT_PERIODS;
return _("The number of payments cannot be zero.");
}
if (gnc_numeric_negative_p (nvalue))
{
*error_item = PAYMENT_PERIODS;
return _("The number of payments cannot be negative.");
}
break;
default:
break;
}
break;
}
return NULL;
return NULL;
}
static void
calc_value(FinCalcDialog *fcd, FinCalcValue value)
{
const char *string;
int error_item = 0;
const char *string;
int error_item = 0;
if (fcd == NULL)
return;
if (fcd == NULL)
return;
string = can_calc_value(fcd, value, &error_item);
if (string != NULL)
{
GtkWidget *entry;
string = can_calc_value(fcd, value, &error_item);
if (string != NULL)
{
GtkWidget *entry;
gnc_error_dialog(fcd->dialog, "%s", string);
if (error_item == 0)
entry = fcd->amounts[0];
else
entry = fcd->amounts[error_item];
gtk_widget_grab_focus (entry);
return;
}
gnc_error_dialog(fcd->dialog, "%s", string);
if (error_item == 0)
entry = fcd->amounts[0];
else
entry = fcd->amounts[error_item];
gtk_widget_grab_focus (entry);
return;
}
gui_to_fi(fcd);
gui_to_fi(fcd);
switch (value)
{
switch (value)
{
case PAYMENT_PERIODS:
fi_calc_num_payments(&fcd->financial_info);
break;
fi_calc_num_payments(&fcd->financial_info);
break;
case INTEREST_RATE:
fi_calc_interest(&fcd->financial_info);
break;
fi_calc_interest(&fcd->financial_info);
break;
case PRESENT_VALUE:
fi_calc_present_value(&fcd->financial_info);
break;
fi_calc_present_value(&fcd->financial_info);
break;
case PERIODIC_PAYMENT:
fi_calc_payment(&fcd->financial_info);
break;
fi_calc_payment(&fcd->financial_info);
break;
case FUTURE_VALUE:
fi_calc_future_value(&fcd->financial_info);
break;
fi_calc_future_value(&fcd->financial_info);
break;
default:
PERR("Unknown financial variable");
break;
}
PERR("Unknown financial variable");
break;
}
fi_to_gui(fcd);
fi_to_gui(fcd);
gtk_widget_set_sensitive(GTK_WIDGET(fcd->calc_button), FALSE);
gtk_widget_set_sensitive(GTK_WIDGET(fcd->calc_button), FALSE);
}
void
fincalc_calc_clicked_cb(GtkButton *button, FinCalcDialog *fcd)
{
const gchar *text;
gint i;
const gchar *text;
gint i;
for (i = 0; i < NUM_FIN_CALC_VALUES; i++) {
text = gtk_entry_get_text(GTK_ENTRY(fcd->amounts[i]));
if ((text != NULL) && (*text != '\0'))
continue;
calc_value(fcd, i);
return;
}
for (i = 0; i < NUM_FIN_CALC_VALUES; i++)
{
text = gtk_entry_get_text(GTK_ENTRY(fcd->amounts[i]));
if ((text != NULL) && (*text != '\0'))
continue;
calc_value(fcd, i);
return;
}
}
void fincalc_response_cb (GtkDialog *dialog,
gint response,
FinCalcDialog *fcd)
gint response,
FinCalcDialog *fcd)
{
switch (response) {
switch (response)
{
case GTK_RESPONSE_OK:
/* Do something here whenever the hidden schedule button is clicked. */
/* Fall through */
/* Do something here whenever the hidden schedule button is clicked. */
/* Fall through */
case GTK_RESPONSE_CLOSE:
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(dialog));
break;
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(dialog));
break;
default:
/* Cancel, destroy, etc. Do nothing. */
break;
}
/* Cancel, destroy, etc. Do nothing. */
break;
}
gnc_close_gui_component_by_data (DIALOG_FINCALC_CM_CLASS, fcd);
gnc_close_gui_component_by_data (DIALOG_FINCALC_CM_CLASS, fcd);
}
static void
close_handler (gpointer user_data)
{
FinCalcDialog *fcd = user_data;
FinCalcDialog *fcd = user_data;
gtk_widget_destroy (fcd->dialog);
gtk_widget_destroy (fcd->dialog);
}
static gboolean
show_handler (const char *class, gint component_id,
gpointer user_data, gpointer iter_data)
gpointer user_data, gpointer iter_data)
{
FinCalcDialog *fcd = user_data;
FinCalcDialog *fcd = user_data;
if (!fcd)
return(FALSE);
gtk_window_present (GTK_WINDOW(fcd->dialog));
return(TRUE);
if (!fcd)
return(FALSE);
gtk_window_present (GTK_WINDOW(fcd->dialog));
return(TRUE);
}
@@ -504,20 +508,20 @@ show_handler (const char *class, gint component_id,
*/
static void
fincalc_init_gae (GNCAmountEdit *edit,
gint min_places,
gint max_places,
gint fraction)
gint min_places,
gint max_places,
gint fraction)
{
GNCPrintAmountInfo print_info;
GNCPrintAmountInfo print_info;
print_info = gnc_integral_print_info ();
print_info.min_decimal_places = min_places;
print_info.max_decimal_places = max_places;
print_info = gnc_integral_print_info ();
print_info.min_decimal_places = min_places;
print_info.max_decimal_places = max_places;
gnc_amount_edit_set_print_info (edit, print_info);
gnc_amount_edit_set_fraction (edit, fraction);
gnc_amount_edit_set_evaluate_on_enter (edit, TRUE);
gtk_entry_set_alignment (GTK_ENTRY(edit), 1.0);
gnc_amount_edit_set_print_info (edit, print_info);
gnc_amount_edit_set_fraction (edit, fraction);
gnc_amount_edit_set_evaluate_on_enter (edit, TRUE);
gtk_entry_set_alignment (GTK_ENTRY(edit), 1.0);
}
/** Initialize an edit field that will display a number in the users
@@ -528,113 +532,113 @@ fincalc_init_gae (GNCAmountEdit *edit,
static void
fincalc_init_commodity_gae (GNCAmountEdit *edit)
{
GNCPrintAmountInfo print_info;
gnc_commodity *commodity;
gint fraction;
GNCPrintAmountInfo print_info;
gnc_commodity *commodity;
gint fraction;
commodity = gnc_default_currency();
fraction = gnc_commodity_get_fraction(commodity);
print_info = gnc_commodity_print_info (commodity, FALSE);
commodity = gnc_default_currency();
fraction = gnc_commodity_get_fraction(commodity);
print_info = gnc_commodity_print_info (commodity, FALSE);
gnc_amount_edit_set_print_info (edit, print_info);
gnc_amount_edit_set_fraction (edit, fraction);
gnc_amount_edit_set_evaluate_on_enter (edit, TRUE);
gtk_entry_set_alignment (GTK_ENTRY(edit), 1.0);
gnc_amount_edit_set_print_info (edit, print_info);
gnc_amount_edit_set_fraction (edit, fraction);
gnc_amount_edit_set_evaluate_on_enter (edit, TRUE);
gtk_entry_set_alignment (GTK_ENTRY(edit), 1.0);
}
void
gnc_ui_fincalc_dialog_create(void)
{
FinCalcDialog *fcd;
GtkWidget *button;
GtkWidget *combo;
GtkWidget *edit;
GladeXML *xml;
FinCalcDialog *fcd;
GtkWidget *button;
GtkWidget *combo;
GtkWidget *edit;
GladeXML *xml;
if (gnc_forall_gui_components (DIALOG_FINCALC_CM_CLASS,
show_handler, NULL))
return;
if (gnc_forall_gui_components (DIALOG_FINCALC_CM_CLASS,
show_handler, NULL))
return;
fcd = g_new0(FinCalcDialog, 1);
fcd = g_new0(FinCalcDialog, 1);
xml = gnc_glade_xml_new ("fincalc.glade", "Financial Calculator Dialog");
xml = gnc_glade_xml_new ("fincalc.glade", "Financial Calculator Dialog");
fcd->xml = xml;
fcd->dialog = glade_xml_get_widget (xml, "Financial Calculator Dialog");
fcd->xml = xml;
fcd->dialog = glade_xml_get_widget (xml, "Financial Calculator Dialog");
gnc_register_gui_component (DIALOG_FINCALC_CM_CLASS,
NULL, close_handler, fcd);
gnc_register_gui_component (DIALOG_FINCALC_CM_CLASS,
NULL, close_handler, fcd);
g_signal_connect (G_OBJECT (fcd->dialog), "destroy",
G_CALLBACK (fincalc_dialog_destroy), fcd);
g_signal_connect (G_OBJECT (fcd->dialog), "destroy",
G_CALLBACK (fincalc_dialog_destroy), fcd);
edit = glade_xml_get_widget (xml, "payment_periods_edit");
fincalc_init_gae (GNC_AMOUNT_EDIT (edit), 0, 0, 1);
fcd->amounts[PAYMENT_PERIODS] = edit;
edit = glade_xml_get_widget (xml, "payment_periods_edit");
fincalc_init_gae (GNC_AMOUNT_EDIT (edit), 0, 0, 1);
fcd->amounts[PAYMENT_PERIODS] = edit;
edit = glade_xml_get_widget (xml, "interest_rate_edit");
fincalc_init_gae (GNC_AMOUNT_EDIT (edit), 2, 5, 100000);
fcd->amounts[INTEREST_RATE] = edit;
edit = glade_xml_get_widget (xml, "interest_rate_edit");
fincalc_init_gae (GNC_AMOUNT_EDIT (edit), 2, 5, 100000);
fcd->amounts[INTEREST_RATE] = edit;
edit = glade_xml_get_widget (xml, "present_value_edit");
fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
fcd->amounts[PRESENT_VALUE] = edit;
edit = glade_xml_get_widget (xml, "present_value_edit");
fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
fcd->amounts[PRESENT_VALUE] = edit;
edit = glade_xml_get_widget (xml, "period_payment_edit");
fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
fcd->amounts[PERIODIC_PAYMENT] = edit;
edit = glade_xml_get_widget (xml, "period_payment_edit");
fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
fcd->amounts[PERIODIC_PAYMENT] = edit;
edit = glade_xml_get_widget (xml, "future_value_edit");
fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
fcd->amounts[FUTURE_VALUE] = edit;
edit = glade_xml_get_widget (xml, "future_value_edit");
fincalc_init_commodity_gae (GNC_AMOUNT_EDIT (edit));
fcd->amounts[FUTURE_VALUE] = edit;
fcd->calc_button = glade_xml_get_widget (xml, "calc_button");
fcd->calc_button = glade_xml_get_widget (xml, "calc_button");
combo = glade_xml_get_widget (xml, "compounding_combo");
fcd->compounding_combo = combo;
g_signal_connect(fcd->compounding_combo, "changed",
G_CALLBACK (fincalc_update_calc_button_cb), fcd);
combo = glade_xml_get_widget (xml, "compounding_combo");
fcd->compounding_combo = combo;
g_signal_connect(fcd->compounding_combo, "changed",
G_CALLBACK (fincalc_update_calc_button_cb), fcd);
combo = glade_xml_get_widget (xml, "payment_combo");
fcd->payment_combo = combo;
g_signal_connect(fcd->compounding_combo, "changed",
G_CALLBACK (fincalc_update_calc_button_cb), fcd);
combo = glade_xml_get_widget (xml, "payment_combo");
fcd->payment_combo = combo;
g_signal_connect(fcd->compounding_combo, "changed",
G_CALLBACK (fincalc_update_calc_button_cb), fcd);
button = glade_xml_get_widget (xml, "period_payment_radio");
fcd->end_of_period_radio = button;
button = glade_xml_get_widget (xml, "period_payment_radio");
fcd->end_of_period_radio = button;
button = glade_xml_get_widget (xml, "discrete_compounding_radio");
fcd->discrete_compounding_radio = button;
button = glade_xml_get_widget (xml, "discrete_compounding_radio");
fcd->discrete_compounding_radio = button;
fcd->payment_total_label = glade_xml_get_widget (xml, "payment_total_label");
fcd->payment_total_label = glade_xml_get_widget (xml, "payment_total_label");
button = glade_xml_get_widget (xml, "schedule_button");
gtk_widget_hide (button);
button = glade_xml_get_widget (xml, "schedule_button");
gtk_widget_hide (button);
init_fi(fcd);
init_fi(fcd);
fi_to_gui(fcd);
fi_to_gui(fcd);
gtk_widget_grab_focus(fcd->amounts[PAYMENT_PERIODS]);
gtk_widget_grab_focus(fcd->amounts[PAYMENT_PERIODS]);
/* Connect all signals specified in glade. */
glade_xml_signal_autoconnect_full( xml,
gnc_glade_autoconnect_full_func,
fcd);
/* Connect all signals specified in glade. */
glade_xml_signal_autoconnect_full( xml,
gnc_glade_autoconnect_full_func,
fcd);
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(fcd->dialog));
gtk_widget_show(fcd->dialog);
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(fcd->dialog));
gtk_widget_show(fcd->dialog);
}
void
gnc_ui_fincalc_dialog_destroy(FinCalcDialog *fcd)
{
if (fcd == NULL)
return;
if (fcd == NULL)
return;
gnc_close_gui_component_by_data (DIALOG_FINCALC_CM_CLASS, fcd);
gnc_close_gui_component_by_data (DIALOG_FINCALC_CM_CLASS, fcd);
}

View File

@@ -40,141 +40,149 @@
#define GCONF_SECTION "dialogs/find"
struct _ftd_data {
QueryNew * q;
QueryNew * ledger_q;
GNCSearchWindow * sw;
struct _ftd_data
{
QueryNew * q;
QueryNew * ledger_q;
GNCSearchWindow * sw;
};
static void
do_find_cb (QueryNew *query, gpointer user_data, gpointer *result)
{
struct _ftd_data *ftd = user_data;
GNCLedgerDisplay *ledger;
gboolean new_ledger = FALSE;
GncPluginPage *page;
struct _ftd_data *ftd = user_data;
GNCLedgerDisplay *ledger;
gboolean new_ledger = FALSE;
GncPluginPage *page;
ledger = gnc_ledger_display_find_by_query (ftd->ledger_q);
if(!ledger) {
new_ledger = TRUE;
ledger = gnc_ledger_display_query (query, SEARCH_LEDGER,
REG_STYLE_JOURNAL);
}
else
gnc_ledger_display_set_query (ledger, query);
ledger = gnc_ledger_display_find_by_query (ftd->ledger_q);
if (!ledger)
{
new_ledger = TRUE;
ledger = gnc_ledger_display_query (query, SEARCH_LEDGER,
REG_STYLE_JOURNAL);
}
else
gnc_ledger_display_set_query (ledger, query);
gnc_ledger_display_refresh (ledger);
gnc_ledger_display_refresh (ledger);
if (new_ledger) {
page = gnc_plugin_page_register_new_ledger (ledger);
gnc_main_window_open_page (NULL, page);
}
if (new_ledger)
{
page = gnc_plugin_page_register_new_ledger (ledger);
gnc_main_window_open_page (NULL, page);
}
gncQueryDestroy (ftd->q);
gncQueryDestroy (ftd->q);
gnc_search_dialog_destroy (ftd->sw);
gnc_search_dialog_destroy (ftd->sw);
}
static void
free_ftd_cb (gpointer user_data)
{
struct _ftd_data *ftd = user_data;
struct _ftd_data *ftd = user_data;
if (!ftd)
return;
if (!ftd)
return;
g_free (ftd);
g_free (ftd);
}
GNCSearchWindow *
GNCSearchWindow *
gnc_ui_find_transactions_dialog_create(GNCLedgerDisplay * orig_ledg)
{
GNCIdType type = GNC_ID_SPLIT;
struct _ftd_data *ftd;
static GList *params = NULL;
QueryNew *start_q, *show_q = NULL;
GNCIdType type = GNC_ID_SPLIT;
struct _ftd_data *ftd;
static GList *params = NULL;
QueryNew *start_q, *show_q = NULL;
/* Build parameter list in reverse order */
if (params == NULL) {
params = gnc_search_param_prepend (params, N_("All Accounts"),
ACCOUNT_MATCH_ALL_TYPE,
type, SPLIT_TRANS, TRANS_SPLITLIST,
SPLIT_ACCOUNT_GUID, NULL);
params = gnc_search_param_prepend (params, N_("Account"), GNC_ID_ACCOUNT,
type, SPLIT_ACCOUNT, QUERY_PARAM_GUID,
NULL);
params = gnc_search_param_prepend (params, N_("Balanced"), NULL,
type, SPLIT_TRANS, TRANS_IS_BALANCED,
NULL);
params = gnc_search_param_prepend (params, N_("Reconcile"), RECONCILED_MATCH_TYPE,
type, SPLIT_RECONCILE, NULL);
params = gnc_search_param_prepend (params, N_("Share Price"), NULL,
type, SPLIT_SHARE_PRICE, NULL);
params = gnc_search_param_prepend (params, N_("Shares"), NULL,
type, SPLIT_AMOUNT, NULL);
params = gnc_search_param_prepend (params, N_("Value"), NULL,
type, SPLIT_VALUE, NULL);
params = gnc_search_param_prepend (params, N_("Date Posted"), NULL,
type, SPLIT_TRANS, TRANS_DATE_POSTED,
NULL);
params = gnc_search_param_prepend (params, N_("Notes"), NULL,
type, SPLIT_TRANS, TRANS_NOTES, NULL);
params = gnc_search_param_prepend (params, N_("Action"), NULL,
type, SPLIT_ACTION, NULL);
params = gnc_search_param_prepend (params, N_("Number"), NULL,
type, SPLIT_TRANS, TRANS_NUM, NULL);
params = gnc_search_param_prepend (params, N_("Memo"), NULL,
type, SPLIT_MEMO, NULL);
params = gnc_search_param_prepend (params, N_("Description"), NULL,
type, SPLIT_TRANS, TRANS_DESCRIPTION,
NULL);
}
ftd = g_new0 (struct _ftd_data, 1);
if(orig_ledg) {
ftd->ledger_q = gnc_ledger_display_get_query (orig_ledg);
start_q = show_q = gncQueryCopy (ftd->ledger_q);
} else {
start_q = gncQueryCreate ();
gncQuerySetBook (start_q, gnc_get_current_book ());
/* In lieu of not "mis-using" some portion of the infrastructure by writing
* a bunch of new code, we just filter out the accounts of the template
* transactions. While these are in a seperate Account trees just for this
* reason, the query engine makes no distinction between Account trees.
* See Gnome Bug 86302.
* -- jsled
*
* copied from gnc-ledger-display.c:gnc_ledger_display_gl() -- warlord
*
* <jsled> Alternatively, you could look for a GNC_SX_ACCOUNT [SchedAction.h]
* key in the KVP frame of the split.
*/
/* Build parameter list in reverse order */
if (params == NULL)
{
Account *tRoot;
GList *al;
tRoot = gnc_book_get_template_root( gnc_get_current_book() );
al = gnc_account_get_descendants( tRoot );
xaccQueryAddAccountMatch( start_q, al, GUID_MATCH_NONE, QUERY_AND );
g_list_free (al);
al = NULL;
tRoot = NULL;
params = gnc_search_param_prepend (params, N_("All Accounts"),
ACCOUNT_MATCH_ALL_TYPE,
type, SPLIT_TRANS, TRANS_SPLITLIST,
SPLIT_ACCOUNT_GUID, NULL);
params = gnc_search_param_prepend (params, N_("Account"), GNC_ID_ACCOUNT,
type, SPLIT_ACCOUNT, QUERY_PARAM_GUID,
NULL);
params = gnc_search_param_prepend (params, N_("Balanced"), NULL,
type, SPLIT_TRANS, TRANS_IS_BALANCED,
NULL);
params = gnc_search_param_prepend (params, N_("Reconcile"), RECONCILED_MATCH_TYPE,
type, SPLIT_RECONCILE, NULL);
params = gnc_search_param_prepend (params, N_("Share Price"), NULL,
type, SPLIT_SHARE_PRICE, NULL);
params = gnc_search_param_prepend (params, N_("Shares"), NULL,
type, SPLIT_AMOUNT, NULL);
params = gnc_search_param_prepend (params, N_("Value"), NULL,
type, SPLIT_VALUE, NULL);
params = gnc_search_param_prepend (params, N_("Date Posted"), NULL,
type, SPLIT_TRANS, TRANS_DATE_POSTED,
NULL);
params = gnc_search_param_prepend (params, N_("Notes"), NULL,
type, SPLIT_TRANS, TRANS_NOTES, NULL);
params = gnc_search_param_prepend (params, N_("Action"), NULL,
type, SPLIT_ACTION, NULL);
params = gnc_search_param_prepend (params, N_("Number"), NULL,
type, SPLIT_TRANS, TRANS_NUM, NULL);
params = gnc_search_param_prepend (params, N_("Memo"), NULL,
type, SPLIT_MEMO, NULL);
params = gnc_search_param_prepend (params, N_("Description"), NULL,
type, SPLIT_TRANS, TRANS_DESCRIPTION,
NULL);
}
ftd->q = start_q; /* save this to destroy it later */
}
ftd = g_new0 (struct _ftd_data, 1);
ftd->sw = gnc_search_dialog_create (type, _("Find Transaction"),
params, NULL, start_q, show_q,
NULL, do_find_cb, NULL,
ftd, free_ftd_cb, GCONF_SECTION, NULL);
if (orig_ledg)
{
ftd->ledger_q = gnc_ledger_display_get_query (orig_ledg);
start_q = show_q = gncQueryCopy (ftd->ledger_q);
}
else
{
start_q = gncQueryCreate ();
gncQuerySetBook (start_q, gnc_get_current_book ());
if (!ftd->sw) {
free_ftd_cb (ftd);
return NULL;
}
/* In lieu of not "mis-using" some portion of the infrastructure by writing
* a bunch of new code, we just filter out the accounts of the template
* transactions. While these are in a seperate Account trees just for this
* reason, the query engine makes no distinction between Account trees.
* See Gnome Bug 86302.
* -- jsled
*
* copied from gnc-ledger-display.c:gnc_ledger_display_gl() -- warlord
*
* <jsled> Alternatively, you could look for a GNC_SX_ACCOUNT [SchedAction.h]
* key in the KVP frame of the split.
*/
{
Account *tRoot;
GList *al;
return ftd->sw;
tRoot = gnc_book_get_template_root( gnc_get_current_book() );
al = gnc_account_get_descendants( tRoot );
xaccQueryAddAccountMatch( start_q, al, GUID_MATCH_NONE, QUERY_AND );
g_list_free (al);
al = NULL;
tRoot = NULL;
}
ftd->q = start_q; /* save this to destroy it later */
}
ftd->sw = gnc_search_dialog_create (type, _("Find Transaction"),
params, NULL, start_q, show_q,
NULL, do_find_cb, NULL,
ftd, free_ftd_cb, GCONF_SECTION, NULL);
if (!ftd->sw)
{
free_ftd_cb (ftd);
return NULL;
}
return ftd->sw;
}

View File

@@ -51,104 +51,110 @@ static void gnc_ui_new_user_cancel_dialog (void);
void
gnc_new_user_dialog_register_qif_druid (void (*cb_fcn)(void))
{
g_return_if_fail (qifImportDruidFcn == NULL);
qifImportDruidFcn = cb_fcn;
g_return_if_fail (qifImportDruidFcn == NULL);
qifImportDruidFcn = cb_fcn;
}
void
gnc_set_first_startup (gboolean first_startup)
{
gnc_gconf_set_bool(GCONF_SECTION, FIRST_STARTUP, first_startup, NULL);
gnc_gconf_set_bool(GCONF_SECTION, FIRST_STARTUP, first_startup, NULL);
}
static void
after_hierarchy_druid(void)
{
GncPluginPage *page;
GncPluginPage *page;
gncp_new_user_finish ();
gnc_set_first_startup (FALSE);
page = gnc_plugin_page_account_tree_new();
gnc_main_window_open_page(NULL, page);
gncp_new_user_finish ();
gnc_set_first_startup (FALSE);
page = gnc_plugin_page_account_tree_new();
gnc_main_window_open_page(NULL, page);
}
void
gnc_ui_new_user_dialog (void)
{
GtkWidget *dialog;
GtkWidget *new_accounts_button;
GtkWidget *import_qif_button;
GtkWidget *tutorial_button;
GladeXML *xml;
gint result;
GtkWidget *dialog;
GtkWidget *new_accounts_button;
GtkWidget *import_qif_button;
GtkWidget *tutorial_button;
GladeXML *xml;
gint result;
ENTER(" ");
xml = gnc_glade_xml_new ("newuser.glade", "New User Dialog");
ENTER(" ");
xml = gnc_glade_xml_new ("newuser.glade", "New User Dialog");
dialog = glade_xml_get_widget (xml, "New User Dialog");
dialog = glade_xml_get_widget (xml, "New User Dialog");
new_accounts_button = glade_xml_get_widget (xml, "new_accounts_button");
import_qif_button = glade_xml_get_widget (xml, "import_qif_button");
tutorial_button = glade_xml_get_widget (xml, "tutorial_button");
new_accounts_button = glade_xml_get_widget (xml, "new_accounts_button");
import_qif_button = glade_xml_get_widget (xml, "import_qif_button");
tutorial_button = glade_xml_get_widget (xml, "tutorial_button");
/* Set the sensitivity of the qif-import button based on the availability
* of the qif-import druid.
*/
gtk_widget_set_sensitive (import_qif_button, (qifImportDruidFcn != NULL));
/* Set the sensitivity of the qif-import button based on the availability
* of the qif-import druid.
*/
gtk_widget_set_sensitive (import_qif_button, (qifImportDruidFcn != NULL));
result = gtk_dialog_run (GTK_DIALOG (dialog));
switch (result) {
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
gnc_ui_new_user_cancel_dialog ();
break;
case GTK_RESPONSE_OK:
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (new_accounts_button))) {
gnc_ui_hierarchy_druid_with_callback(TRUE, after_hierarchy_druid);
break;
} else if ((qifImportDruidFcn != NULL)
&& gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import_qif_button))) {
qifImportDruidFcn();
gncp_new_user_finish ();
break;
} else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tutorial_button))) {
gnc_gnome_help (HF_GUIDE, NULL);
gncp_new_user_finish ();
break;
}
default:
g_print ("DEBUG: Response: %d", result);
g_assert_not_reached ();
}
result = gtk_dialog_run (GTK_DIALOG (dialog));
switch (result)
{
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
gnc_ui_new_user_cancel_dialog ();
break;
case GTK_RESPONSE_OK:
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (new_accounts_button)))
{
gnc_ui_hierarchy_druid_with_callback(TRUE, after_hierarchy_druid);
break;
}
else if ((qifImportDruidFcn != NULL)
&& gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (import_qif_button)))
{
qifImportDruidFcn();
gncp_new_user_finish ();
break;
}
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tutorial_button)))
{
gnc_gnome_help (HF_GUIDE, NULL);
gncp_new_user_finish ();
break;
}
default:
g_print ("DEBUG: Response: %d", result);
g_assert_not_reached ();
}
gtk_widget_destroy (dialog);
LEAVE(" ");
gtk_widget_destroy (dialog);
LEAVE(" ");
}
static void
gnc_ui_new_user_cancel_dialog (void)
{
GtkWidget *dialog;
GladeXML *xml;
gint result;
gboolean keepshowing;
GtkWidget *dialog;
GladeXML *xml;
gint result;
gboolean keepshowing;
xml = gnc_glade_xml_new ("newuser.glade", "New User Cancel Dialog");
xml = gnc_glade_xml_new ("newuser.glade", "New User Cancel Dialog");
dialog = glade_xml_get_widget (xml, "New User Cancel Dialog");
dialog = glade_xml_get_widget (xml, "New User Cancel Dialog");
result = gtk_dialog_run (GTK_DIALOG (dialog));
keepshowing = (result == GTK_RESPONSE_YES);
result = gtk_dialog_run (GTK_DIALOG (dialog));
keepshowing = (result == GTK_RESPONSE_YES);
gnc_set_first_startup (keepshowing);
gncp_new_user_finish ();
gnc_set_first_startup (keepshowing);
gncp_new_user_finish ();
gtk_widget_destroy(dialog);
gtk_widget_destroy(dialog);
}
void
gncp_new_user_finish (void)
{
gnc_hook_run(HOOK_BOOK_OPENED, gnc_get_current_session());
gnc_hook_run(HOOK_BOOK_OPENED, gnc_get_current_session());
}

View File

@@ -68,451 +68,467 @@ void gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data);
typedef struct
{
GtkWidget * dialog;
QofSession *session;
QofBook *book;
GNCPriceDB *price_db;
GtkWidget * dialog;
QofSession *session;
QofBook *book;
GNCPriceDB *price_db;
GncTreeViewPrice * price_tree;
GncTreeViewPrice * price_tree;
GtkWidget * edit_button;
GtkWidget * remove_button;
GtkWidget * edit_button;
GtkWidget * remove_button;
} PricesDialog;
void
gnc_prices_dialog_window_destroy_cb (GtkObject *object, gpointer data)
{
PricesDialog *pdb_dialog = data;
PricesDialog *pdb_dialog = data;
ENTER(" ");
gnc_unregister_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
ENTER(" ");
gnc_unregister_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
if (pdb_dialog->dialog) {
gtk_widget_destroy(pdb_dialog->dialog);
pdb_dialog->dialog = NULL;
}
if (pdb_dialog->dialog)
{
gtk_widget_destroy(pdb_dialog->dialog);
pdb_dialog->dialog = NULL;
}
g_free (pdb_dialog);
LEAVE(" ");
g_free (pdb_dialog);
LEAVE(" ");
}
void
gnc_prices_dialog_close_cb (GtkDialog *dialog, gpointer data)
{
PricesDialog *pdb_dialog = data;
PricesDialog *pdb_dialog = data;
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
LEAVE(" ");
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
LEAVE(" ");
}
void
gnc_prices_dialog_response (GtkDialog *dialog, gint response_id, gpointer data)
{
PricesDialog *pdb_dialog = data;
PricesDialog *pdb_dialog = data;
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
LEAVE(" ");
ENTER(" ");
gnc_close_gui_component_by_data (DIALOG_PRICE_DB_CM_CLASS, pdb_dialog);
LEAVE(" ");
}
void
gnc_prices_dialog_edit_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
GList *price_list;
PricesDialog *pdb_dialog = data;
GList *price_list;
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (!price_list) {
LEAVE("no price selected");
return;
}
if (g_list_next(price_list)) {
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (!price_list)
{
LEAVE("no price selected");
return;
}
if (g_list_next(price_list))
{
g_list_free(price_list);
LEAVE("too many prices selected");
return;
}
gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
price_list->data, GNC_PRICE_EDIT);
g_list_free(price_list);
LEAVE("too many prices selected");
return;
}
gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
price_list->data, GNC_PRICE_EDIT);
g_list_free(price_list);
LEAVE(" ");
LEAVE(" ");
}
static void
remove_helper(GNCPrice *price, GNCPriceDB *pdb)
{
gnc_pricedb_remove_price (pdb, price);
gnc_pricedb_remove_price (pdb, price);
}
void
gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
GList *price_list;
gint length, response;
GtkWidget *dialog;
PricesDialog *pdb_dialog = data;
GList *price_list;
gint length, response;
GtkWidget *dialog;
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (!price_list) {
LEAVE("no price selected");
return;
}
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (!price_list)
{
LEAVE("no price selected");
return;
}
length = g_list_length(price_list);
if (length > 1) {
gchar *message;
length = g_list_length(price_list);
if (length > 1)
{
gchar *message;
message = g_strdup_printf
(/* Translators: %d is the number of prices. This
message = g_strdup_printf
(/* Translators: %d is the number of prices. This
is a ngettext(3) message. */
ngettext("Are you sure you want to delete the %d selected price?",
"Are you sure you want to delete the %d selected prices?",
length),
length);
dialog = gtk_message_dialog_new(GTK_WINDOW(pdb_dialog->dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s", _("Delete prices?"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", message);
g_free(message);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_DELETE, GTK_RESPONSE_YES,
(gchar *)NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
response = gnc_dialog_run(GTK_DIALOG(dialog), "pricedb_remove_multiple");
gtk_widget_destroy(dialog);
} else {
response = GTK_RESPONSE_YES;
}
ngettext("Are you sure you want to delete the %d selected price?",
"Are you sure you want to delete the %d selected prices?",
length),
length);
dialog = gtk_message_dialog_new(GTK_WINDOW(pdb_dialog->dialog),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s", _("Delete prices?"));
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
"%s", message);
g_free(message);
gtk_dialog_add_buttons(GTK_DIALOG(dialog),
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_DELETE, GTK_RESPONSE_YES,
(gchar *)NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_YES);
response = gnc_dialog_run(GTK_DIALOG(dialog), "pricedb_remove_multiple");
gtk_widget_destroy(dialog);
}
else
{
response = GTK_RESPONSE_YES;
}
if (response == GTK_RESPONSE_YES) {
g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db);
}
g_list_free(price_list);
LEAVE(" ");
if (response == GTK_RESPONSE_YES)
{
g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db);
}
g_list_free(price_list);
LEAVE(" ");
}
void
gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
GladeXML *xml;
GtkWidget *dialog, *button, *date, *label;
gint result;
gboolean delete_user, delete_last;
PricesDialog *pdb_dialog = data;
GladeXML *xml;
GtkWidget *dialog, *button, *date, *label;
gint result;
gboolean delete_user, delete_last;
ENTER(" ");
xml = gnc_glade_xml_new ("price.glade", "Deletion Date");
dialog = glade_xml_get_widget (xml, "Deletion Date");
date = glade_xml_get_widget (xml, "date");
label = glade_xml_get_widget (xml, "date_label");
gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (pdb_dialog->dialog));
ENTER(" ");
xml = gnc_glade_xml_new ("price.glade", "Deletion Date");
dialog = glade_xml_get_widget (xml, "Deletion Date");
date = glade_xml_get_widget (xml, "date");
label = glade_xml_get_widget (xml, "date_label");
gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date), label);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (pdb_dialog->dialog));
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_OK)
{
Timespec ts;
result = gtk_dialog_run (GTK_DIALOG (dialog));
if (result == GTK_RESPONSE_OK)
{
Timespec ts;
DEBUG("deleting prices");
ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
ts.tv_nsec = 0;
DEBUG("deleting prices");
ts.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (date));
ts.tv_nsec = 0;
button = glade_xml_get_widget (xml, "delete_manual");
delete_user = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
button = glade_xml_get_widget (xml, "delete_last");
delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
button = glade_xml_get_widget (xml, "delete_manual");
delete_user = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
button = glade_xml_get_widget (xml, "delete_last");
delete_last = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
gnc_pricedb_remove_old_prices(pdb_dialog->price_db, ts,
delete_user, delete_last);
}
gnc_pricedb_remove_old_prices(pdb_dialog->price_db, ts,
delete_user, delete_last);
}
gtk_widget_destroy(dialog);
LEAVE(" ");
gtk_widget_destroy(dialog);
LEAVE(" ");
}
void
gnc_prices_dialog_add_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
GNCPrice *price = NULL;
GList *price_list;
PricesDialog *pdb_dialog = data;
GNCPrice *price = NULL;
GList *price_list;
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (price_list) {
price = price_list->data;
g_list_free(price_list);
}
gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
price, GNC_PRICE_NEW);
LEAVE(" ");
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
if (price_list)
{
price = price_list->data;
g_list_free(price_list);
}
gnc_price_edit_dialog (pdb_dialog->dialog, pdb_dialog->session,
price, GNC_PRICE_NEW);
LEAVE(" ");
}
void
gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
{
PricesDialog *pdb_dialog = data;
SCM quotes_func;
SCM book_scm;
SCM scm_window;
PricesDialog *pdb_dialog = data;
SCM quotes_func;
SCM book_scm;
SCM scm_window;
ENTER(" ");
quotes_func = scm_c_eval_string ("gnc:book-add-quotes");
if (!scm_is_procedure (quotes_func)) {
LEAVE(" no procedure");
return;
}
ENTER(" ");
quotes_func = scm_c_eval_string ("gnc:book-add-quotes");
if (!scm_is_procedure (quotes_func))
{
LEAVE(" no procedure");
return;
}
book_scm = gnc_book_to_scm (pdb_dialog->book);
if (scm_is_true (scm_not (book_scm))) {
LEAVE("no book");
return;
}
book_scm = gnc_book_to_scm (pdb_dialog->book);
if (scm_is_true (scm_not (book_scm)))
{
LEAVE("no book");
return;
}
scm_window = SWIG_NewPointerObj(pdb_dialog->dialog,
SWIG_TypeQuery("_p_GtkWidget"), 0);
scm_window = SWIG_NewPointerObj(pdb_dialog->dialog,
SWIG_TypeQuery("_p_GtkWidget"), 0);
gnc_set_busy_cursor (NULL, TRUE);
scm_call_2 (quotes_func, scm_window, book_scm);
gnc_unset_busy_cursor (NULL);
gnc_set_busy_cursor (NULL, TRUE);
scm_call_2 (quotes_func, scm_window, book_scm);
gnc_unset_busy_cursor (NULL);
/* Without this, the summary bar on the accounts tab
* won't reflect the new prices (bug #522095). */
gnc_gui_refresh_all ();
/* Without this, the summary bar on the accounts tab
* won't reflect the new prices (bug #522095). */
gnc_gui_refresh_all ();
LEAVE(" ");
LEAVE(" ");
}
static void
gnc_prices_dialog_selection_changed (GtkTreeSelection *treeselection,
gpointer data)
gpointer data)
{
PricesDialog *pdb_dialog = data;
GList *price_list;
gint length;
PricesDialog *pdb_dialog = data;
GList *price_list;
gint length;
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
length = g_list_length(price_list);
ENTER(" ");
price_list = gnc_tree_view_price_get_selected_prices(pdb_dialog->price_tree);
length = g_list_length(price_list);
gtk_widget_set_sensitive (pdb_dialog->edit_button,
length == 1);
gtk_widget_set_sensitive (pdb_dialog->remove_button,
length >= 1);
LEAVE("%d prices selected", length);
gtk_widget_set_sensitive (pdb_dialog->edit_button,
length == 1);
gtk_widget_set_sensitive (pdb_dialog->remove_button,
length >= 1);
LEAVE("%d prices selected", length);
}
static gboolean
gnc_price_dialog_filter_ns_func (gnc_commodity_namespace *namespace,
gpointer data)
gpointer data)
{
PricesDialog *pdb_dialog = data;
const gchar *name;
static GList *cm_list;
GList *item;
PricesDialog *pdb_dialog = data;
const gchar *name;
static GList *cm_list;
GList *item;
/* Never show the template list */
name = gnc_commodity_namespace_get_name (namespace);
if (safe_strcmp (name, "template") == 0)
return FALSE;
/* Never show the template list */
name = gnc_commodity_namespace_get_name (namespace);
if (safe_strcmp (name, "template") == 0)
return FALSE;
/* See if this namespace has commodities */
cm_list = gnc_commodity_namespace_get_commodity_list(namespace);
for (item = cm_list; item; item = g_list_next(item)) {
/* See if this namespace has commodities */
cm_list = gnc_commodity_namespace_get_commodity_list(namespace);
for (item = cm_list; item; item = g_list_next(item))
{
/* For each commodity, see if there are prices */
if (gnc_pricedb_has_prices(pdb_dialog->price_db, item->data, NULL)) {
return TRUE;
/* For each commodity, see if there are prices */
if (gnc_pricedb_has_prices(pdb_dialog->price_db, item->data, NULL))
{
return TRUE;
}
}
}
// printf("Namespace %s not visible\n", name);
return FALSE;
// printf("Namespace %s not visible\n", name);
return FALSE;
}
static gboolean
gnc_price_dialog_filter_cm_func (gnc_commodity *commodity,
gpointer data)
gpointer data)
{
PricesDialog *pdb_dialog = data;
PricesDialog *pdb_dialog = data;
/* Show any commodity that has prices */
return gnc_pricedb_has_prices(pdb_dialog->price_db, commodity, NULL);
/* Show any commodity that has prices */
return gnc_pricedb_has_prices(pdb_dialog->price_db, commodity, NULL);
}
static void
row_activated_cb (GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *column, gpointer data)
GtkTreeViewColumn *column, gpointer data)
{
GtkTreeModel *model;
GtkTreeIter iter;
GtkTreeModel *model;
GtkTreeIter iter;
g_return_if_fail(view);
g_return_if_fail(view);
model = gtk_tree_view_get_model(view);
if (gtk_tree_model_get_iter(model, &iter, path))
{
if (gtk_tree_model_iter_has_child(model, &iter))
model = gtk_tree_view_get_model(view);
if (gtk_tree_model_get_iter(model, &iter, path))
{
/* There are children, so it's not a price.
* Just expand or collapse the row. */
if (gtk_tree_view_row_expanded(view, path))
gtk_tree_view_collapse_row(view, path);
else
gtk_tree_view_expand_row(view, path, FALSE);
if (gtk_tree_model_iter_has_child(model, &iter))
{
/* There are children, so it's not a price.
* Just expand or collapse the row. */
if (gtk_tree_view_row_expanded(view, path))
gtk_tree_view_collapse_row(view, path);
else
gtk_tree_view_expand_row(view, path, FALSE);
}
else
/* It's a price, so click the Edit button. */
gnc_prices_dialog_edit_clicked(GTK_WIDGET(view), data);
}
else
/* It's a price, so click the Edit button. */
gnc_prices_dialog_edit_clicked(GTK_WIDGET(view), data);
}
}
static void
gnc_prices_dialog_create (GtkWidget * parent, PricesDialog *pdb_dialog)
{
GtkWidget *dialog, *scrolled_window;
GladeXML *xml;
GtkTreeView *view;
GtkTreeSelection *selection;
GtkWidget *dialog, *scrolled_window;
GladeXML *xml;
GtkTreeView *view;
GtkTreeSelection *selection;
ENTER(" ");
xml = gnc_glade_xml_new ("price.glade", "Prices Dialog");
ENTER(" ");
xml = gnc_glade_xml_new ("price.glade", "Prices Dialog");
dialog = glade_xml_get_widget (xml, "Prices Dialog");
pdb_dialog->dialog = dialog;
dialog = glade_xml_get_widget (xml, "Prices Dialog");
pdb_dialog->dialog = dialog;
pdb_dialog->session = gnc_get_current_session();
pdb_dialog->book = qof_session_get_book(pdb_dialog->session);
pdb_dialog->price_db = gnc_pricedb_get_db(pdb_dialog->book);
pdb_dialog->session = gnc_get_current_session();
pdb_dialog->book = qof_session_get_book(pdb_dialog->session);
pdb_dialog->price_db = gnc_pricedb_get_db(pdb_dialog->book);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog);
glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func, pdb_dialog);
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
/* default to 'close' button */
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
/* default to 'close' button */
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE);
/* price tree */
scrolled_window = glade_xml_get_widget (xml, "price_list_window");
view = gnc_tree_view_price_new(pdb_dialog->book,
"gconf-section", GCONF_SECTION,
"show-column-menu", TRUE,
NULL);
pdb_dialog->price_tree = GNC_TREE_VIEW_PRICE(view);
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
gnc_tree_view_price_set_filter (pdb_dialog->price_tree,
gnc_price_dialog_filter_ns_func,
gnc_price_dialog_filter_cm_func,
NULL,
pdb_dialog, NULL);
/* price tree */
scrolled_window = glade_xml_get_widget (xml, "price_list_window");
view = gnc_tree_view_price_new(pdb_dialog->book,
"gconf-section", GCONF_SECTION,
"show-column-menu", TRUE,
NULL);
pdb_dialog->price_tree = GNC_TREE_VIEW_PRICE(view);
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET(view));
gnc_tree_view_price_set_filter (pdb_dialog->price_tree,
gnc_price_dialog_filter_ns_func,
gnc_price_dialog_filter_cm_func,
NULL,
pdb_dialog, NULL);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_prices_dialog_selection_changed), pdb_dialog);
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_prices_dialog_selection_changed), pdb_dialog);
g_signal_connect (G_OBJECT (view), "row-activated",
G_CALLBACK (row_activated_cb), pdb_dialog);
g_signal_connect (G_OBJECT (view), "row-activated",
G_CALLBACK (row_activated_cb), pdb_dialog);
/* buttons */
{
GtkWidget *button;
/* buttons */
{
GtkWidget *button;
button = glade_xml_get_widget (xml, "edit_button");
pdb_dialog->edit_button = button;
button = glade_xml_get_widget (xml, "edit_button");
pdb_dialog->edit_button = button;
button = glade_xml_get_widget (xml, "remove_button");
pdb_dialog->remove_button = button;
button = glade_xml_get_widget (xml, "remove_button");
pdb_dialog->remove_button = button;
if (!gnc_quote_source_fq_installed()) {
button = glade_xml_get_widget (xml, "get_quotes_button");
gtk_widget_set_sensitive(button, FALSE);
if (!gnc_quote_source_fq_installed())
{
button = glade_xml_get_widget (xml, "get_quotes_button");
gtk_widget_set_sensitive(button, FALSE);
}
}
}
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pdb_dialog->dialog));
LEAVE(" ");
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pdb_dialog->dialog));
LEAVE(" ");
}
static void
close_handler (gpointer user_data)
{
PricesDialog *pdb_dialog = user_data;
PricesDialog *pdb_dialog = user_data;
ENTER(" ");
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(pdb_dialog->dialog));
ENTER(" ");
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(pdb_dialog->dialog));
gtk_widget_destroy (GTK_WIDGET (pdb_dialog->dialog));
LEAVE(" ");
gtk_widget_destroy (GTK_WIDGET (pdb_dialog->dialog));
LEAVE(" ");
}
static void
refresh_handler (GHashTable *changes, gpointer user_data)
{
ENTER(" ");
LEAVE(" ");
ENTER(" ");
LEAVE(" ");
}
static gboolean
show_handler (const char *class, gint component_id,
gpointer user_data, gpointer iter_data)
gpointer user_data, gpointer iter_data)
{
PricesDialog *pdb_dialog = user_data;
PricesDialog *pdb_dialog = user_data;
ENTER(" ");
if (!pdb_dialog) {
LEAVE("no data strucure");
return(FALSE);
}
ENTER(" ");
if (!pdb_dialog)
{
LEAVE("no data strucure");
return(FALSE);
}
gtk_window_present (GTK_WINDOW(pdb_dialog->dialog));
LEAVE(" ");
return(TRUE);
gtk_window_present (GTK_WINDOW(pdb_dialog->dialog));
LEAVE(" ");
return(TRUE);
}
/********************************************************************\
* gnc_prices_dialog *
* opens up a window showing all price information *
* *
* *
* Args: parent - the parent of the window to be created *
* Return: nothing *
\********************************************************************/
void
gnc_prices_dialog (GtkWidget * parent)
{
PricesDialog *pdb_dialog;
gint component_id;
PricesDialog *pdb_dialog;
gint component_id;
ENTER(" ");
if (gnc_forall_gui_components (DIALOG_PRICE_DB_CM_CLASS, show_handler, NULL)) {
LEAVE("existing dialog raised");
return;
}
ENTER(" ");
if (gnc_forall_gui_components (DIALOG_PRICE_DB_CM_CLASS, show_handler, NULL))
{
LEAVE("existing dialog raised");
return;
}
pdb_dialog = g_new0 (PricesDialog, 1);
pdb_dialog = g_new0 (PricesDialog, 1);
gnc_prices_dialog_create (parent, pdb_dialog);
gnc_prices_dialog_create (parent, pdb_dialog);
component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS,
refresh_handler, close_handler,
pdb_dialog);
gnc_gui_component_set_session (component_id, pdb_dialog->session);
component_id = gnc_register_gui_component (DIALOG_PRICE_DB_CM_CLASS,
refresh_handler, close_handler,
pdb_dialog);
gnc_gui_component_set_session (component_id, pdb_dialog->session);
gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree));
gtk_widget_grab_focus (GTK_WIDGET(pdb_dialog->price_tree));
gtk_widget_show (pdb_dialog->dialog);
LEAVE(" ");
gtk_widget_show (pdb_dialog->dialog);
LEAVE(" ");
}

View File

@@ -56,27 +56,27 @@
typedef struct
{
GtkWidget * dialog;
QofSession *session;
QofBook *book;
GNCPriceDB *price_db;
GNCPriceEditType type;
GtkWidget * dialog;
QofSession *session;
QofBook *book;
GNCPriceDB *price_db;
GNCPriceEditType type;
GtkWidget * namespace_cbe;
GtkWidget * commodity_cbe;
GtkWidget * currency_edit;
GtkWidget * date_edit;
GtkWidget * source_entry;
GtkWidget * type_combobox;
GtkWidget * price_edit;
GtkWidget * namespace_cbe;
GtkWidget * commodity_cbe;
GtkWidget * currency_edit;
GtkWidget * date_edit;
GtkWidget * source_entry;
GtkWidget * type_combobox;
GtkWidget * price_edit;
GtkWidget * cancel_button;
GtkWidget * apply_button;
GtkWidget * ok_button;
GtkWidget * cancel_button;
GtkWidget * apply_button;
GtkWidget * ok_button;
GNCPrice *price;
gboolean changed;
gboolean new;
GNCPrice *price;
gboolean changed;
gboolean new;
} PriceEditDialog;
@@ -89,398 +89,412 @@ void pedit_commodity_changed_cb (GtkComboBoxEntry *cbe, gpointer data);
static void
gnc_prices_set_changed (PriceEditDialog *pedit_dialog, gboolean changed)
{
pedit_dialog->changed = changed;
pedit_dialog->changed = changed;
gtk_widget_set_sensitive (pedit_dialog->apply_button, changed);
gtk_widget_set_sensitive (pedit_dialog->apply_button, changed);
}
static int
type_string_to_index (const char *type)
{
if (safe_strcmp (type, "bid") == 0)
return 0;
if (safe_strcmp (type, "bid") == 0)
return 0;
if (safe_strcmp (type, "ask") == 0)
return 1;
if (safe_strcmp (type, "ask") == 0)
return 1;
if (safe_strcmp (type, "last") == 0)
return 2;
if (safe_strcmp (type, "last") == 0)
return 2;
if (safe_strcmp (type, "nav") == 0)
return 3;
if (safe_strcmp (type, "nav") == 0)
return 3;
return 4;
return 4;
}
static const char *
type_index_to_string (int index)
{
switch (index)
{
case 0: return "bid";
case 1: return "ask";
case 2: return "last";
case 3: return "nav";
default: return "unknown";
}
switch (index)
{
case 0:
return "bid";
case 1:
return "ask";
case 2:
return "last";
case 3:
return "nav";
default:
return "unknown";
}
}
static void
price_to_gui (PriceEditDialog *pedit_dialog)
{
gnc_commodity *commodity = NULL;
gnc_commodity *currency = NULL;
const gchar *namespace, *fullname;
const char *source;
const char *type;
gnc_numeric value;
Timespec date;
gnc_commodity *commodity = NULL;
gnc_commodity *currency = NULL;
const gchar *namespace, *fullname;
const char *source;
const char *type;
gnc_numeric value;
Timespec date;
if (pedit_dialog->price) {
commodity = gnc_price_get_commodity (pedit_dialog->price);
}
if (pedit_dialog->price)
{
commodity = gnc_price_get_commodity (pedit_dialog->price);
}
if (commodity) {
namespace = gnc_commodity_get_namespace(commodity);
fullname = gnc_commodity_get_printname(commodity);
gnc_ui_update_namespace_picker(pedit_dialog->namespace_cbe,
namespace, DIAG_COMM_NON_CURRENCY);
gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbe,
namespace, fullname);
if (commodity)
{
namespace = gnc_commodity_get_namespace(commodity);
fullname = gnc_commodity_get_printname(commodity);
gnc_ui_update_namespace_picker(pedit_dialog->namespace_cbe,
namespace, DIAG_COMM_NON_CURRENCY);
gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbe,
namespace, fullname);
currency = gnc_price_get_currency (pedit_dialog->price);
date = gnc_price_get_time (pedit_dialog->price);
source = gnc_price_get_source (pedit_dialog->price);
type = gnc_price_get_typestr (pedit_dialog->price);
value = gnc_price_get_value (pedit_dialog->price);
}
else {
currency = gnc_default_currency ();
date.tv_sec = time (NULL);
date.tv_nsec = 0;
source = DIALOG_PRICE_EDIT_SOURCE;
type = "";
value = gnc_numeric_zero ();
}
currency = gnc_price_get_currency (pedit_dialog->price);
date = gnc_price_get_time (pedit_dialog->price);
source = gnc_price_get_source (pedit_dialog->price);
type = gnc_price_get_typestr (pedit_dialog->price);
value = gnc_price_get_value (pedit_dialog->price);
}
else
{
currency = gnc_default_currency ();
date.tv_sec = time (NULL);
date.tv_nsec = 0;
source = DIALOG_PRICE_EDIT_SOURCE;
type = "";
value = gnc_numeric_zero ();
}
if (currency) {
gnc_currency_edit_set_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
}
if (currency)
{
gnc_currency_edit_set_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
}
gnc_date_edit_set_time (GNC_DATE_EDIT (pedit_dialog->date_edit), date.tv_sec);
gnc_date_edit_set_time (GNC_DATE_EDIT (pedit_dialog->date_edit), date.tv_sec);
gtk_entry_set_text (GTK_ENTRY (pedit_dialog->source_entry), source);
gtk_entry_set_text (GTK_ENTRY (pedit_dialog->source_entry), source);
gtk_combo_box_set_active (GTK_COMBO_BOX(pedit_dialog->type_combobox),
type_string_to_index (type));
gtk_combo_box_set_active (GTK_COMBO_BOX(pedit_dialog->type_combobox),
type_string_to_index (type));
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), value);
gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (pedit_dialog->price_edit), value);
}
static const char *
gui_to_price (PriceEditDialog *pedit_dialog)
{
gnc_commodity *commodity;
gnc_commodity *currency;
gchar *namespace, *fullname;
const char *source;
const char *type;
gnc_numeric value;
Timespec date;
gnc_commodity *commodity;
gnc_commodity *currency;
gchar *namespace, *fullname;
const char *source;
const char *type;
gnc_numeric value;
Timespec date;
namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe);
fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe));
commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), namespace, fullname);
if (!commodity)
return _("You must select a commodity.");
namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe);
fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe));
commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), namespace, fullname);
if (!commodity)
return _("You must select a commodity.");
currency = gnc_currency_edit_get_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit));
if (!currency)
return _("You must select a currency.");
currency = gnc_currency_edit_get_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit));
if (!currency)
return _("You must select a currency.");
date.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (pedit_dialog->date_edit));
date.tv_nsec = 0;
date.tv_sec = gnc_date_edit_get_date (GNC_DATE_EDIT (pedit_dialog->date_edit));
date.tv_nsec = 0;
source = gtk_entry_get_text (GTK_ENTRY (pedit_dialog->source_entry));
source = gtk_entry_get_text (GTK_ENTRY (pedit_dialog->source_entry));
type = type_index_to_string
(gtk_combo_box_get_active (GTK_COMBO_BOX (pedit_dialog->type_combobox)));
type = type_index_to_string
(gtk_combo_box_get_active (GTK_COMBO_BOX (pedit_dialog->type_combobox)));
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (pedit_dialog->price_edit)))
return _("You must enter a valid amount.");
if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (pedit_dialog->price_edit)))
return _("You must enter a valid amount.");
value = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT (pedit_dialog->price_edit));
value = gnc_amount_edit_get_amount
(GNC_AMOUNT_EDIT (pedit_dialog->price_edit));
if (!pedit_dialog->price)
pedit_dialog->price = gnc_price_create (pedit_dialog->book);
gnc_price_begin_edit (pedit_dialog->price);
gnc_price_set_commodity (pedit_dialog->price, commodity);
gnc_price_set_currency (pedit_dialog->price, currency);
gnc_price_set_time (pedit_dialog->price, date);
gnc_price_set_source (pedit_dialog->price, source);
gnc_price_set_typestr (pedit_dialog->price, type);
gnc_price_set_value (pedit_dialog->price, value);
gnc_price_commit_edit (pedit_dialog->price);
if (!pedit_dialog->price)
pedit_dialog->price = gnc_price_create (pedit_dialog->book);
gnc_price_begin_edit (pedit_dialog->price);
gnc_price_set_commodity (pedit_dialog->price, commodity);
gnc_price_set_currency (pedit_dialog->price, currency);
gnc_price_set_time (pedit_dialog->price, date);
gnc_price_set_source (pedit_dialog->price, source);
gnc_price_set_typestr (pedit_dialog->price, type);
gnc_price_set_value (pedit_dialog->price, value);
gnc_price_commit_edit (pedit_dialog->price);
g_free(namespace);
g_free(fullname);
g_free(namespace);
g_free(fullname);
return NULL;
return NULL;
}
static void
pedit_dialog_destroy_cb (GtkWidget *widget, gpointer data)
{
PriceEditDialog *pedit_dialog = data;
PriceEditDialog *pedit_dialog = data;
gnc_unregister_gui_component_by_data (DIALOG_PRICE_EDIT_CM_CLASS,
pedit_dialog);
gnc_unregister_gui_component_by_data (DIALOG_PRICE_EDIT_CM_CLASS,
pedit_dialog);
if (pedit_dialog->price)
{
gnc_price_unref (pedit_dialog->price);
pedit_dialog->price = NULL;
pedit_dialog->new = FALSE;
}
if (pedit_dialog->price)
{
gnc_price_unref (pedit_dialog->price);
pedit_dialog->price = NULL;
pedit_dialog->new = FALSE;
}
g_free (pedit_dialog);
g_free (pedit_dialog);
}
void
pedit_dialog_response_cb (GtkDialog *dialog, gint response, gpointer data)
{
PriceEditDialog *pedit_dialog = data;
GNCPrice *new_price = NULL;
const char *error_str;
PriceEditDialog *pedit_dialog = data;
GNCPrice *new_price = NULL;
const char *error_str;
if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY)) {
error_str = gui_to_price (pedit_dialog);
if (error_str) {
gnc_warning_dialog (pedit_dialog->dialog, "%s", error_str);
return;
if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY))
{
error_str = gui_to_price (pedit_dialog);
if (error_str)
{
gnc_warning_dialog (pedit_dialog->dialog, "%s", error_str);
return;
}
gnc_prices_set_changed (pedit_dialog, FALSE);
if (TRUE == pedit_dialog->new)
{
gnc_pricedb_add_price (pedit_dialog->price_db, pedit_dialog->price);
}
gnc_gui_refresh_all ();
}
gnc_prices_set_changed (pedit_dialog, FALSE);
if (TRUE == pedit_dialog->new) {
gnc_pricedb_add_price (pedit_dialog->price_db, pedit_dialog->price);
if (response == GTK_RESPONSE_APPLY)
{
new_price = gnc_price_clone (pedit_dialog->price, pedit_dialog->book);
pedit_dialog->new = TRUE;
gnc_price_unref (pedit_dialog->price);
pedit_dialog->price = new_price;
}
else
{
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog));
gtk_widget_destroy (GTK_WIDGET (pedit_dialog->dialog));
pedit_dialog_destroy_cb (NULL, pedit_dialog);
}
gnc_gui_refresh_all ();
}
if(response == GTK_RESPONSE_APPLY) {
new_price = gnc_price_clone (pedit_dialog->price, pedit_dialog->book);
pedit_dialog->new = TRUE;
gnc_price_unref (pedit_dialog->price);
pedit_dialog->price = new_price;
}
else {
gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog));
gtk_widget_destroy (GTK_WIDGET (pedit_dialog->dialog));
pedit_dialog_destroy_cb (NULL, pedit_dialog);
}
}
void
pedit_commodity_ns_changed_cb (GtkComboBoxEntry *cbe, gpointer data)
{
PriceEditDialog *pedit_dialog = data;
gchar *namespace;
PriceEditDialog *pedit_dialog = data;
gchar *namespace;
gnc_prices_set_changed (pedit_dialog, TRUE);
gnc_prices_set_changed (pedit_dialog, TRUE);
namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe);
gnc_ui_update_commodity_picker (pedit_dialog->commodity_cbe, namespace, NULL);
namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe);
gnc_ui_update_commodity_picker (pedit_dialog->commodity_cbe, namespace, NULL);
g_free(namespace);
g_free(namespace);
}
void
pedit_commodity_changed_cb (GtkComboBoxEntry *cbe, gpointer data)
{
gnc_commodity *commodity = NULL;
gnc_commodity *currency = NULL;
gchar *namespace, *fullname;
GList *price_list;
PriceEditDialog *pedit_dialog = data;
gnc_commodity *commodity = NULL;
gnc_commodity *currency = NULL;
gchar *namespace, *fullname;
GList *price_list;
PriceEditDialog *pedit_dialog = data;
gnc_prices_set_changed (pedit_dialog, TRUE);
gnc_prices_set_changed (pedit_dialog, TRUE);
namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe);
fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe));
commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), namespace, fullname);
namespace = gnc_ui_namespace_picker_ns (pedit_dialog->namespace_cbe);
fullname = gtk_combo_box_get_active_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe));
commodity = gnc_commodity_table_find_full(gnc_get_current_commodities(), namespace, fullname);
if(commodity)
{
price_list = gnc_pricedb_lookup_latest_any_currency
(pedit_dialog->price_db, commodity);
if(price_list)
if (commodity)
{
currency = gnc_price_get_currency((GNCPrice *)price_list->data);
price_list = gnc_pricedb_lookup_latest_any_currency
(pedit_dialog->price_db, commodity);
if (price_list)
{
currency = gnc_price_get_currency((GNCPrice *)price_list->data);
if (currency)
gnc_currency_edit_set_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
if (currency)
gnc_currency_edit_set_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), currency);
gnc_price_list_destroy(price_list);
gnc_price_list_destroy(price_list);
}
else
{
gnc_currency_edit_set_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), gnc_default_currency());
}
}
else
{
gnc_currency_edit_set_currency
(GNC_CURRENCY_EDIT (pedit_dialog->currency_edit), gnc_default_currency());
}
}
g_free(namespace);
g_free(fullname);
g_free(namespace);
g_free(fullname);
}
void
pedit_data_changed_cb (GtkWidget *w, gpointer data)
{
PriceEditDialog *pedit_dialog = data;
PriceEditDialog *pedit_dialog = data;
gnc_prices_set_changed (pedit_dialog, TRUE);
gnc_prices_set_changed (pedit_dialog, TRUE);
}
static void
gnc_price_pedit_dialog_create (GtkWidget *parent,
PriceEditDialog *pedit_dialog,
QofSession *session)
PriceEditDialog *pedit_dialog,
QofSession *session)
{
GladeXML *xml;
GNCPrintAmountInfo print_info;
GtkWidget *dialog;
GtkWidget *entry;
GtkWidget *box;
GtkWidget *w;
GtkWidget *label;
gchar *namespace;
GladeXML *xml;
GNCPrintAmountInfo print_info;
GtkWidget *dialog;
GtkWidget *entry;
GtkWidget *box;
GtkWidget *w;
GtkWidget *label;
gchar *namespace;
xml = gnc_glade_xml_new ("price.glade", "Price Dialog");
xml = gnc_glade_xml_new ("price.glade", "Price Dialog");
pedit_dialog->session = session;
pedit_dialog->book = qof_session_get_book(pedit_dialog->session);
pedit_dialog->price_db = gnc_pricedb_get_db(pedit_dialog->book);
pedit_dialog->session = session;
pedit_dialog->book = qof_session_get_book(pedit_dialog->session);
pedit_dialog->price_db = gnc_pricedb_get_db(pedit_dialog->book);
dialog = glade_xml_get_widget (xml, "Price Dialog");
pedit_dialog->dialog = dialog;
dialog = glade_xml_get_widget (xml, "Price Dialog");
pedit_dialog->dialog = dialog;
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
/* parent */
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
w = glade_xml_get_widget (xml, "namespace_cbe");
pedit_dialog->namespace_cbe = w;
gtk_combo_box_remove_text(GTK_COMBO_BOX(pedit_dialog->namespace_cbe), 0);
gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pedit_dialog->namespace_cbe));
gnc_ui_update_namespace_picker(w, NULL, DIAG_COMM_ALL);
w = glade_xml_get_widget (xml, "namespace_cbe");
pedit_dialog->namespace_cbe = w;
gtk_combo_box_remove_text(GTK_COMBO_BOX(pedit_dialog->namespace_cbe), 0);
gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pedit_dialog->namespace_cbe));
gnc_ui_update_namespace_picker(w, NULL, DIAG_COMM_ALL);
w = glade_xml_get_widget (xml, "commodity_cbe");
pedit_dialog->commodity_cbe = w;
gtk_combo_box_remove_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe), 0);
gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pedit_dialog->commodity_cbe));
namespace = gnc_ui_namespace_picker_ns(pedit_dialog->namespace_cbe);
gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbe, namespace, NULL);
g_free(namespace);
w = glade_xml_get_widget (xml, "commodity_cbe");
pedit_dialog->commodity_cbe = w;
gtk_combo_box_remove_text(GTK_COMBO_BOX(pedit_dialog->commodity_cbe), 0);
gnc_cbe_require_list_item(GTK_COMBO_BOX_ENTRY(pedit_dialog->commodity_cbe));
namespace = gnc_ui_namespace_picker_ns(pedit_dialog->namespace_cbe);
gnc_ui_update_commodity_picker(pedit_dialog->commodity_cbe, namespace, NULL);
g_free(namespace);
box = glade_xml_get_widget (xml, "currency_box");
w = gnc_currency_edit_new ();
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT (w),
gnc_default_currency ());
pedit_dialog->currency_edit = w;
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
gtk_widget_show (w);
g_signal_connect (G_OBJECT (GTK_COMBO_BOX(w)), "changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
label = glade_xml_get_widget (xml, "currency_label");
gtk_label_set_mnemonic_widget (GTK_LABEL(label), w);
box = glade_xml_get_widget (xml, "currency_box");
w = gnc_currency_edit_new ();
gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT (w),
gnc_default_currency ());
pedit_dialog->currency_edit = w;
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
gtk_widget_show (w);
g_signal_connect (G_OBJECT (GTK_COMBO_BOX(w)), "changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
label = glade_xml_get_widget (xml, "currency_label");
gtk_label_set_mnemonic_widget (GTK_LABEL(label), w);
box = glade_xml_get_widget (xml, "date_box");
w = gnc_date_edit_new (time (NULL), FALSE, FALSE);
pedit_dialog->date_edit = w;
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
gtk_widget_show (w);
g_signal_connect (G_OBJECT (w), "date_changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
g_signal_connect (G_OBJECT (GNC_DATE_EDIT (w)->date_entry), "changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(w)->date_entry), TRUE);
label = glade_xml_get_widget (xml, "date_label");
gnc_date_make_mnemonic_target (GNC_DATE_EDIT(w), label);
box = glade_xml_get_widget (xml, "date_box");
w = gnc_date_edit_new (time (NULL), FALSE, FALSE);
pedit_dialog->date_edit = w;
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
gtk_widget_show (w);
g_signal_connect (G_OBJECT (w), "date_changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
g_signal_connect (G_OBJECT (GNC_DATE_EDIT (w)->date_entry), "changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
gtk_entry_set_activates_default(GTK_ENTRY(GNC_DATE_EDIT(w)->date_entry), TRUE);
label = glade_xml_get_widget (xml, "date_label");
gnc_date_make_mnemonic_target (GNC_DATE_EDIT(w), label);
w = glade_xml_get_widget (xml, "source_entry");
pedit_dialog->source_entry = w;
w = glade_xml_get_widget (xml, "source_entry");
pedit_dialog->source_entry = w;
w = glade_xml_get_widget (xml, "type_combobox");
pedit_dialog->type_combobox = w;
w = glade_xml_get_widget (xml, "type_combobox");
pedit_dialog->type_combobox = w;
box = glade_xml_get_widget (xml, "price_box");
w = gnc_amount_edit_new ();
pedit_dialog->price_edit = w;
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (w), TRUE);
print_info = gnc_default_price_print_info ();
gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (w), print_info);
gtk_entry_set_activates_default(GTK_ENTRY(w), TRUE);
gtk_widget_show (w);
label = glade_xml_get_widget (xml, "price_label");
gtk_label_set_mnemonic_widget (GTK_LABEL(label), w);
box = glade_xml_get_widget (xml, "price_box");
w = gnc_amount_edit_new ();
pedit_dialog->price_edit = w;
gtk_box_pack_start (GTK_BOX (box), w, TRUE, TRUE, 0);
gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (w), TRUE);
print_info = gnc_default_price_print_info ();
gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (w), print_info);
gtk_entry_set_activates_default(GTK_ENTRY(w), TRUE);
gtk_widget_show (w);
label = glade_xml_get_widget (xml, "price_label");
gtk_label_set_mnemonic_widget (GTK_LABEL(label), w);
entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (w));
g_signal_connect (G_OBJECT (entry), "changed",
entry = gnc_amount_edit_gtk_entry (GNC_AMOUNT_EDIT (w));
g_signal_connect (G_OBJECT (entry), "changed",
G_CALLBACK (pedit_data_changed_cb), pedit_dialog);
w = glade_xml_get_widget (xml, "cancel_button");
pedit_dialog->cancel_button = w;
w = glade_xml_get_widget (xml, "cancel_button");
pedit_dialog->cancel_button = w;
w = glade_xml_get_widget (xml, "apply_button");
pedit_dialog->apply_button = w;
gnc_prices_set_changed (pedit_dialog, FALSE);
w = glade_xml_get_widget (xml, "apply_button");
pedit_dialog->apply_button = w;
gnc_prices_set_changed (pedit_dialog, FALSE);
w = glade_xml_get_widget (xml, "ok_button");
pedit_dialog->ok_button = w;
w = glade_xml_get_widget (xml, "ok_button");
pedit_dialog->ok_button = w;
glade_xml_signal_autoconnect_full( xml,
gnc_glade_autoconnect_full_func,
pedit_dialog );
glade_xml_signal_autoconnect_full( xml,
gnc_glade_autoconnect_full_func,
pedit_dialog );
}
static void
close_handler (gpointer user_data)
{
PriceEditDialog *pedit_dialog = user_data;
PriceEditDialog *pedit_dialog = user_data;
gtk_dialog_response(GTK_DIALOG(pedit_dialog->dialog), GTK_RESPONSE_CANCEL);
gtk_dialog_response(GTK_DIALOG(pedit_dialog->dialog), GTK_RESPONSE_CANCEL);
}
static void
refresh_handler (GHashTable *changes, gpointer user_data)
{
// PriceEditDialog *pedit_dialog = user_data;
// PriceEditDialog *pedit_dialog = user_data;
// gnc_prices_load_prices (pedit_dialog);
// gnc_prices_load_prices (pedit_dialog);
}
static gboolean
show_handler (const char *class, gint component_id,
gpointer user_data, gpointer iter_data)
gpointer user_data, gpointer iter_data)
{
PriceEditDialog *pedit_dialog = user_data;
GNCPrice * price = iter_data;
PriceEditDialog *pedit_dialog = user_data;
GNCPrice * price = iter_data;
if (!pedit_dialog || (pedit_dialog->price != price))
return(FALSE);
if (!pedit_dialog || (pedit_dialog->price != price))
return(FALSE);
gtk_window_present (GTK_WINDOW(pedit_dialog->dialog));
return(TRUE);
gtk_window_present (GTK_WINDOW(pedit_dialog->dialog));
return(TRUE);
}
/********************************************************************\
@@ -492,50 +506,52 @@ show_handler (const char *class, gint component_id,
\********************************************************************/
void
gnc_price_edit_dialog (GtkWidget * parent,
QofSession *session,
GNCPrice * price,
GNCPriceEditType type)
QofSession *session,
GNCPrice * price,
GNCPriceEditType type)
{
PriceEditDialog *pedit_dialog;
gint component_id;
PriceEditDialog *pedit_dialog;
gint component_id;
if ((type == GNC_PRICE_EDIT) &&
(gnc_forall_gui_components (DIALOG_PRICE_EDIT_CM_CLASS,
show_handler, price)))
return;
if ((type == GNC_PRICE_EDIT) &&
(gnc_forall_gui_components (DIALOG_PRICE_EDIT_CM_CLASS,
show_handler, price)))
return;
pedit_dialog = g_new0 (PriceEditDialog, 1);
gnc_price_pedit_dialog_create (parent, pedit_dialog, session);
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog));
pedit_dialog->type = type;
pedit_dialog = g_new0 (PriceEditDialog, 1);
gnc_price_pedit_dialog_create (parent, pedit_dialog, session);
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(pedit_dialog->dialog));
pedit_dialog->type = type;
switch (type) {
case GNC_PRICE_NEW:
if (price) {
price = gnc_price_clone(price, pedit_dialog->book);
switch (type)
{
case GNC_PRICE_NEW:
if (price)
{
price = gnc_price_clone(price, pedit_dialog->book);
// } else {
// price = gnc_price_create (pedit_dialog->book);
gnc_price_set_source (price, DIALOG_PRICE_EDIT_SOURCE);
gnc_price_set_source (price, DIALOG_PRICE_EDIT_SOURCE);
}
pedit_dialog->new = TRUE;
/* New price will only have one ref, this dialog. */
break;
case GNC_PRICE_EDIT:
gnc_price_ref(price); /* Add ref from this dialog */
pedit_dialog->new = FALSE;
break;
}
pedit_dialog->new = TRUE;
/* New price will only have one ref, this dialog. */
break;
case GNC_PRICE_EDIT:
gnc_price_ref(price); /* Add ref from this dialog */
pedit_dialog->new = FALSE;
break;
}
pedit_dialog->price = price;
price_to_gui(pedit_dialog);
gnc_prices_set_changed (pedit_dialog, FALSE);
component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS,
refresh_handler, close_handler,
pedit_dialog);
gnc_gui_component_set_session (component_id, pedit_dialog->session);
gtk_widget_grab_focus (pedit_dialog->commodity_cbe);
gtk_widget_show (pedit_dialog->dialog);
pedit_dialog->price = price;
price_to_gui(pedit_dialog);
gnc_prices_set_changed (pedit_dialog, FALSE);
component_id = gnc_register_gui_component (DIALOG_PRICE_EDIT_CM_CLASS,
refresh_handler, close_handler,
pedit_dialog);
gnc_gui_component_set_session (component_id, pedit_dialog->session);
gtk_widget_grab_focus (pedit_dialog->commodity_cbe);
gtk_widget_show (pedit_dialog->dialog);
}
/********************************************************************\
@@ -548,14 +564,14 @@ gnc_price_edit_dialog (GtkWidget * parent,
GNCPrice *
gnc_price_edit_by_guid (GtkWidget * parent, const GUID * guid)
{
GNCPrice *price;
QofSession *session;
GNCPrice *price;
QofSession *session;
session = gnc_get_current_session ();
price = gnc_price_lookup (guid, qof_session_get_book(session));
if (price == NULL)
return(NULL);
session = gnc_get_current_session ();
price = gnc_price_lookup (guid, qof_session_get_book(session));
if (price == NULL)
return(NULL);
gnc_price_edit_dialog(parent, session, price, GNC_PRICE_EDIT);
return price;
gnc_price_edit_dialog(parent, session, price, GNC_PRICE_EDIT);
return price;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -63,17 +63,17 @@ typedef gboolean (*GNCProgressCancelFunc) (gpointer user_data);
* additional visual elements such as a Cancel button, text
* log, and additional labels can be activated by following
* with calls to some of the other API functions.
*
*
* @param parent The parent window for which the progress dialog
* becomes modal.
*
*
* @param use_ok_button If @c TRUE, an OK button is shown and must be
* clicked when progress is completed.
*
* @return A ::GNCProgressDialog that identifies the dialog and
* is needed when making subsequent API calls. */
GNCProgressDialog * gnc_progress_dialog_new(GtkWidget *parent,
gboolean use_ok_button);
gboolean use_ok_button);
/** Creates a dialog for displaying the progress of an activity using
* existing widgets. This allows long-running operations to update the
@@ -95,10 +95,10 @@ GNCProgressDialog * gnc_progress_dialog_new(GtkWidget *parent,
* @return A ::GNCProgressDialog that identifies the dialog and
* is needed when making subsequent API calls. */
GNCProgressDialog * gnc_progress_dialog_custom(GtkLabel *primary,
GtkLabel *secondary,
GtkProgressBar *bar,
GtkLabel *suboperation,
GtkTextView *log);
GtkLabel *secondary,
GtkProgressBar *bar,
GtkLabel *suboperation,
GtkTextView *log);
/** Set the title of a pop-up progress dialog. This function has no effect
* on dialogs registered using gnc_progress_dialog_custom().
@@ -190,8 +190,8 @@ void gnc_progress_dialog_resume(GNCProgressDialog *progress);
*
* @param user_data user data to be passed to @a cancel_func */
void gnc_progress_dialog_set_cancel_func(GNCProgressDialog *progress,
GNCProgressCancelFunc cancel_func,
gpointer user_data);
GNCProgressCancelFunc cancel_func,
gpointer user_data);
/** Show a Cancel button and set the Guile procedure that will be called
* when it is pressed by the user. It will be called after any C function
@@ -203,7 +203,7 @@ void gnc_progress_dialog_set_cancel_func(GNCProgressDialog *progress,
*
* @param cancel_scm_func the Guile callback procedure */
void gnc_progress_dialog_set_cancel_scm_func(GNCProgressDialog *progress,
SCM cancel_scm_func);
SCM cancel_scm_func);
/** Set the fraction of the progress bar to fill, where 0 is empty and
* 1 is full. If @a value is over 1, the bar will pulse instead of fill.
@@ -214,7 +214,7 @@ void gnc_progress_dialog_set_cancel_scm_func(GNCProgressDialog *progress,
void gnc_progress_dialog_set_value(GNCProgressDialog *progress, gdouble value);
/** Create a new "virtual" progress bar that, as it becomes full, will fill
* the current bar by the fraction specified by @a weight. All calls to
* the current bar by the fraction specified by @a weight. All calls to
* gnc_progress_dialog_set_value() will operate on the new bar until
* gnc_progress_dialog_pop() is called.
*
@@ -232,7 +232,7 @@ void gnc_progress_dialog_set_value(GNCProgressDialog *progress, gdouble value);
*
* @param weight the requested fraction of the current bar that the new bar
* will represent (The fraction actually assigned will be the lesser of the
* requested amount and the amount of the bar that is unfilled.)
* requested amount and the amount of the bar that is unfilled.)
*
* @return the number of times that gnc_progress_dialog_pop() would have to
* be called to return to the top level. */

View File

@@ -106,7 +106,8 @@ static gint _sx_engine_event_handler_id = -1;
/** Datatypes ***********************************************************/
typedef enum _EndTypeEnum {
typedef enum _EndTypeEnum
{
END_NEVER,
END_DATE,
END_OCCUR,
@@ -177,7 +178,7 @@ static gboolean sxed_delete_event( GtkWidget *widget, GdkEvent *event, gpointer
static gboolean sxed_confirmed_cancel( GncSxEditorDialog *sxed );
static gboolean editor_component_sx_equality( gpointer find_data,
gpointer user_data );
gpointer user_data );
static GtkActionEntry gnc_sxed_menu_entries [] =
{
@@ -212,11 +213,13 @@ sxed_confirmed_cancel(GncSxEditorDialog *sxed)
reg = gnc_ledger_display_get_split_register( sxed->ledger );
/* check for changes */
if ( gnc_sxed_check_changed( sxed ) ) {
if ( gnc_sxed_check_changed( sxed ) )
{
const char *sx_changed_msg =
_( "This SX has changed; are you "
"sure you want to cancel?" );
if (!gnc_verify_dialog(sxed->dialog, FALSE, "%s", sx_changed_msg)) {
if (!gnc_verify_dialog(sxed->dialog, FALSE, "%s", sx_changed_msg))
{
return FALSE;
}
}
@@ -255,7 +258,8 @@ editor_ok_button_clicked( GtkButton *b, GncSxEditorDialog *sxed )
/* add to list */
// @@fixme -- forget 'new'-flag: check for existance of the SX [?]
if ( sxed->newsxP ) {
if ( sxed->newsxP )
{
book = gnc_get_current_book ();
sxes = gnc_book_get_schedxactions(book);
gnc_sxes_add_sx(sxes, sxed->sx);
@@ -284,13 +288,15 @@ gnc_sxed_check_changed( GncSxEditorDialog *sxed )
char *name;
name = gtk_editable_get_chars( GTK_EDITABLE(sxed->nameEntry), 0, -1 );
if ( strlen(name) == 0 ) {
if ( strlen(name) == 0 )
{
return TRUE;
}
if ( (xaccSchedXactionGetName(sxed->sx) == NULL)
|| (strcmp( xaccSchedXactionGetName(sxed->sx),
name ) != 0) ) {
|| (strcmp( xaccSchedXactionGetName(sxed->sx),
name ) != 0) )
{
return TRUE;
}
}
@@ -298,35 +304,42 @@ gnc_sxed_check_changed( GncSxEditorDialog *sxed )
/* end options */
{
/* dialog says... no end */
if ( gtk_toggle_button_get_active( sxed->optEndNone ) ) {
if ( gtk_toggle_button_get_active( sxed->optEndNone ) )
{
if ( xaccSchedXactionHasEndDate(sxed->sx)
|| xaccSchedXactionHasOccurDef(sxed->sx) ) {
|| xaccSchedXactionHasOccurDef(sxed->sx) )
{
return TRUE;
}
}
/* dialog says... end date */
if ( gtk_toggle_button_get_active( sxed->optEndDate ) ) {
if ( gtk_toggle_button_get_active( sxed->optEndDate ) )
{
GDate sxEndDate, dlgEndDate;
if ( ! xaccSchedXactionHasEndDate( sxed->sx ) ) {
if ( ! xaccSchedXactionHasEndDate( sxed->sx ) )
{
return TRUE;
}
sxEndDate = *xaccSchedXactionGetEndDate( sxed->sx );
g_date_set_time_t( &dlgEndDate,
gnc_date_edit_get_date( sxed->
endDateEntry ) );
endDateEntry ) );
if ( g_date_compare( &sxEndDate, &dlgEndDate ) != 0 ) {
if ( g_date_compare( &sxEndDate, &dlgEndDate ) != 0 )
{
return TRUE;
}
}
/* dialog says... num occur */
if ( gtk_toggle_button_get_active( sxed->optEndCount ) ) {
if ( gtk_toggle_button_get_active( sxed->optEndCount ) )
{
gint sxNumOccur, sxNumRem, dlgNumOccur, dlgNumRem;
if ( ! xaccSchedXactionGetNumOccur( sxed->sx ) ) {
if ( ! xaccSchedXactionGetNumOccur( sxed->sx ) )
{
return TRUE;
}
@@ -340,7 +353,8 @@ gnc_sxed_check_changed( GncSxEditorDialog *sxed )
sxNumRem = xaccSchedXactionGetRemOccur( sxed->sx );
if ( (dlgNumOccur != sxNumOccur)
|| (dlgNumRem != sxNumRem) ) {
|| (dlgNumRem != sxNumRem) )
{
return TRUE;
}
}
@@ -349,53 +363,59 @@ gnc_sxed_check_changed( GncSxEditorDialog *sxed )
/* SX options [autocreate, notify, reminder, advance] */
{
gboolean dlgEnabled,
dlgAutoCreate,
dlgNotify,
sxEnabled,
sxAutoCreate,
sxNotify;
dlgAutoCreate,
dlgNotify,
sxEnabled,
sxAutoCreate,
sxNotify;
gint dlgAdvance, sxAdvance;
gint dlgRemind, sxRemind;
dlgEnabled =
gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->
enabledOpt) );
enabledOpt) );
dlgAutoCreate =
gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->
autocreateOpt) );
autocreateOpt) );
dlgNotify =
gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->
notifyOpt) );
notifyOpt) );
sxEnabled = xaccSchedXactionGetEnabled( sxed->sx );
if ( ! ((dlgEnabled == sxEnabled)) ) {
if ( ! ((dlgEnabled == sxEnabled)) )
{
return TRUE;
}
xaccSchedXactionGetAutoCreate( sxed->sx, &sxAutoCreate, &sxNotify );
if ( ! ((dlgAutoCreate == sxAutoCreate)
&& (dlgNotify == sxNotify)) ) {
&& (dlgNotify == sxNotify)) )
{
return TRUE;
}
dlgAdvance = 0;
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->advanceOpt) ) ) {
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->advanceOpt) ) )
{
dlgAdvance =
gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(sxed->
advanceSpin) );
advanceSpin) );
}
sxAdvance = xaccSchedXactionGetAdvanceCreation( sxed->sx );
if ( dlgAdvance != sxAdvance ) {
if ( dlgAdvance != sxAdvance )
{
return TRUE;
}
dlgRemind = 0;
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->remindOpt) ) ) {
if ( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(sxed->remindOpt) ) )
{
dlgRemind =
gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(sxed->remindSpin) );
}
sxRemind = xaccSchedXactionGetAdvanceReminder( sxed->sx );
if ( dlgRemind != sxRemind ) {
if ( dlgRemind != sxRemind )
{
return TRUE;
}
}
@@ -432,7 +452,8 @@ gnc_sxed_check_changed( GncSxEditorDialog *sxed )
SplitRegister *sr =
gnc_ledger_display_get_split_register( sxed->ledger );
if ( gnc_split_register_changed( sr ) ) {
if ( gnc_split_register_changed( sr ) )
{
return TRUE;
}
}
@@ -444,7 +465,8 @@ gnc_sxed_check_changed( GncSxEditorDialog *sxed )
* Holds the credit- and debit-sum for a given Transaction, as used in
* gnc_sxed_check_consistent.
**/
typedef struct _txnCreditDebitSums {
typedef struct _txnCreditDebitSums
{
gnc_numeric creditSum;
gnc_numeric debitSum;
} txnCreditDebitSums;
@@ -469,25 +491,28 @@ check_credit_debit_balance( gpointer key,
gboolean *unbalanced = (gboolean*)ud;
*unbalanced |= !(gnc_numeric_zero_p(
gnc_numeric_sub_fixed( tcds->debitSum,
tcds->creditSum ) ));
tcds->creditSum ) ));
if (qof_log_check(G_LOG_DOMAIN, QOF_LOG_DEBUG))
{
if ( gnc_numeric_zero_p( gnc_numeric_sub_fixed( tcds->debitSum,
tcds->creditSum ) ) ) {
tcds->creditSum ) ) )
{
g_debug( "%p | true [%s - %s = %s]",
key,
gnc_numeric_to_string( tcds->debitSum ),
gnc_numeric_to_string( tcds->creditSum ),
gnc_numeric_to_string(gnc_numeric_sub_fixed( tcds->debitSum,
tcds->creditSum )) );
} else {
tcds->creditSum )) );
}
else
{
g_debug( "%p | false [%s - %s = %s]",
key,
gnc_numeric_to_string( tcds->debitSum ),
gnc_numeric_to_string( tcds->creditSum ),
gnc_numeric_to_string(gnc_numeric_sub_fixed( tcds->debitSum,
tcds->creditSum )) );
tcds->creditSum )) );
}
}
}
@@ -561,7 +586,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
gnc_sx_get_variables( sxed->sx, vars );
ttVarCount = g_hash_table_size( vars );
if ( ttVarCount != 0 ) {
if ( ttVarCount != 0 )
{
/* balance with random variable bindings some number
* of times in an attempt to ferret out
* un-balanceable transactions.
@@ -575,7 +601,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
}
srand(time(NULL));
for ( i=0; i < numIters && !unbalanceable; i++ ) {
for ( i = 0; i < numIters && !unbalanceable; i++ )
{
gnc_sx_randomize_variables(vars);
g_hash_table_foreach( txns, set_sums_to_zero, NULL );
tmp = gnc_numeric_zero();
@@ -594,8 +621,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
t = xaccSplitGetParent( s );
if ( !(tcds =
(txnCreditDebitSums*)g_hash_table_lookup( txns,
(gpointer)t )) )
(txnCreditDebitSums*)g_hash_table_lookup( txns,
(gpointer)t )) )
{
tcds = g_new0( txnCreditDebitSums, 1 );
tcds->creditSum = gnc_numeric_zero();
@@ -624,9 +651,11 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
GNC_SX_CREDIT_FORMULA,
NULL );
if ( v
&& (str = kvp_value_get_string(v))
&& strlen( str ) != 0 ) {
if ( gnc_sx_parse_vars_from_formula( str, vars, &tmp ) < 0 ) {
&& (str = kvp_value_get_string(v))
&& strlen( str ) != 0 )
{
if ( gnc_sx_parse_vars_from_formula( str, vars, &tmp ) < 0 )
{
GString *errStr;
errStr = g_string_sized_new( 32 );
@@ -650,9 +679,11 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
GNC_SX_DEBIT_FORMULA,
NULL );
if ( v
&& (str = kvp_value_get_string(v))
&& strlen(str) != 0 ) {
if ( gnc_sx_parse_vars_from_formula( str, vars, &tmp ) < 0 ) {
&& (str = kvp_value_get_string(v))
&& strlen(str) != 0 )
{
if ( gnc_sx_parse_vars_from_formula( str, vars, &tmp ) < 0 )
{
GString *errStr;
errStr = g_string_sized_new( 32 );
@@ -689,13 +720,14 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
g_hash_table_destroy(txns);
if ( unbalanceable
&& !gnc_verify_dialog( sxed->dialog, FALSE,
"%s",
_("The Scheduled Transaction Editor "
"cannot automatically balance "
"this transaction. "
"Should it still be "
"entered?") ) ) {
&& !gnc_verify_dialog( sxed->dialog, FALSE,
"%s",
_("The Scheduled Transaction Editor "
"cannot automatically balance "
"this transaction. "
"Should it still be "
"entered?") ) )
{
return FALSE;
}
}
@@ -708,7 +740,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
GList *sxList;
name = gtk_editable_get_chars( GTK_EDITABLE(sxed->nameEntry), 0, -1 );
if ( strlen(name) == 0 ) {
if ( strlen(name) == 0 )
{
const char *sx_has_no_name_msg =
_( "Please name the Scheduled Transaction." );
gnc_error_dialog( sxed->dialog, "%s", sx_has_no_name_msg );
@@ -723,9 +756,10 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
(xaccSchedXactionGetName(sxed->sx) == NULL)
|| (strcmp( xaccSchedXactionGetName(sxed->sx), name ) != 0);
for ( sxList =
gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
nameHasChanged && !nameExists && sxList;
sxList = sxList->next ) {
gnc_book_get_schedxactions(gnc_get_current_book())->sx_list;
nameHasChanged && !nameExists && sxList;
sxList = sxList->next )
{
char *existingName, *existingNameKey;
existingName =
xaccSchedXactionGetName( (SchedXaction*)sxList->
@@ -734,7 +768,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
nameExists |= ( strcmp(nameKey, existingNameKey) == 0 );
g_free( existingNameKey );
}
if ( nameHasChanged && nameExists ) {
if ( nameHasChanged && nameExists )
{
const char *sx_has_existing_name_msg =
_( "A Scheduled Transaction with the "
"name \"%s\" already exists. "
@@ -742,7 +777,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
"this one the same?" );
if ( ! gnc_verify_dialog( sxed->dialog, FALSE,
sx_has_existing_name_msg,
name) ) {
name) )
{
g_free( nameKey );
g_free( name );
return FALSE;
@@ -763,7 +799,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
gtk_toggle_button_get_active(
GTK_TOGGLE_BUTTON(sxed->notifyOpt) );
if (((ttVarCount > 0) || multi_commodity) && autocreateState) {
if (((ttVarCount > 0) || multi_commodity) && autocreateState)
{
gnc_warning_dialog(sxed->dialog, "%s",
_("Scheduled Transactions with variables "
"cannot be automatically created."));
@@ -772,10 +809,11 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
/* Fix for part of Bug#121740 -- auto-create transactions are
* only valid if there's actually a transaction to create. */
if ( autocreateState && splitCount == 0 ) {
if ( autocreateState && splitCount == 0 )
{
gnc_warning_dialog(sxed->dialog, "%s",
_("Scheduled Transactions without a template "
"transaction cannot be automatically created.") );
_("Scheduled Transactions without a template "
"transaction cannot be automatically created.") );
return FALSE;
}
}
@@ -785,15 +823,17 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
GDate startDate, endDate, nextDate;
if ( !gtk_toggle_button_get_active(sxed->optEndDate)
&& !gtk_toggle_button_get_active(sxed->optEndCount)
&& !gtk_toggle_button_get_active(sxed->optEndNone) ) {
&& !gtk_toggle_button_get_active(sxed->optEndCount)
&& !gtk_toggle_button_get_active(sxed->optEndNone) )
{
const char *sx_end_spec_msg =
_( "Please provide a valid end selection." );
gnc_error_dialog( sxed->dialog, "%s", sx_end_spec_msg );
return FALSE;
}
if ( gtk_toggle_button_get_active(sxed->optEndCount)) {
if ( gtk_toggle_button_get_active(sxed->optEndCount))
{
gint occur, rem;
occur =
@@ -802,7 +842,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
rem =
gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(sxed->endRemainSpin) );
if ( occur == 0 ) {
if ( occur == 0 )
{
const char *sx_occur_count_zero_msg =
_( "There must be some number of occurrences." );
gnc_error_dialog( sxed->dialog, "%s",
@@ -810,7 +851,8 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
return FALSE;
}
if ( rem > occur ) {
if ( rem > occur )
{
const char *sx_occur_counts_wrong_msg =
_( "The number of remaining occurrences "
"(%d) is greater than the number of "
@@ -824,10 +866,11 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
}
g_date_clear( &endDate, 1 );
if ( gtk_toggle_button_get_active(sxed->optEndDate) ) {
if ( gtk_toggle_button_get_active(sxed->optEndDate) )
{
g_date_set_time_t( &endDate,
gnc_date_edit_get_date( sxed->
endDateEntry ) );
endDateEntry ) );
}
g_date_clear(&nextDate, 1);
@@ -840,7 +883,7 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
recurrenceListFree(&schedule);
if (!g_date_valid(&nextDate)
|| (g_date_valid(&endDate) && (g_date_compare(&nextDate, &endDate) > 0)))
|| (g_date_valid(&endDate) && (g_date_compare(&nextDate, &endDate) > 0)))
{
const char *invalid_sx_check_msg =
_("You have attempted to create a Scheduled "
@@ -861,7 +904,7 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed )
static void
gnc_sxed_save_sx( GncSxEditorDialog *sxed )
{
gnc_sx_begin_edit( sxed->sx );
gnc_sx_begin_edit( sxed->sx );
/* name */
{
@@ -876,7 +919,8 @@ gnc_sxed_save_sx( GncSxEditorDialog *sxed )
{
GDate gdate;
if ( gtk_toggle_button_get_active(sxed->optEndDate) ) {
if ( gtk_toggle_button_get_active(sxed->optEndDate) )
{
/* get the end date data */
g_date_set_time_t( &gdate,
gnc_date_edit_get_date(
@@ -884,7 +928,9 @@ gnc_sxed_save_sx( GncSxEditorDialog *sxed )
xaccSchedXactionSetEndDate( sxed->sx, &gdate );
/* set the num occurances data */
xaccSchedXactionSetNumOccur( sxed->sx, 0 );
} else if ( gtk_toggle_button_get_active(sxed->optEndCount) ) {
}
else if ( gtk_toggle_button_get_active(sxed->optEndCount) )
{
gint num;
/* get the occurances data */
@@ -898,11 +944,15 @@ gnc_sxed_save_sx( GncSxEditorDialog *sxed )
g_date_clear( &gdate, 1 );
xaccSchedXactionSetEndDate( sxed->sx, &gdate );
} else if ( gtk_toggle_button_get_active( sxed->optEndNone ) ) {
}
else if ( gtk_toggle_button_get_active( sxed->optEndNone ) )
{
xaccSchedXactionSetNumOccur( sxed->sx, 0 );
g_date_clear( &gdate, 1 );
xaccSchedXactionSetEndDate( sxed->sx, &gdate );
} else {
}
else
{
g_critical("no valid end specified\n");
}
}
@@ -933,14 +983,16 @@ gnc_sxed_save_sx( GncSxEditorDialog *sxed )
int daysInAdvance;
daysInAdvance = 0;
if ( gtk_toggle_button_get_active( sxed->advanceOpt ) ) {
if ( gtk_toggle_button_get_active( sxed->advanceOpt ) )
{
daysInAdvance =
gtk_spin_button_get_value_as_int( sxed->advanceSpin );
}
xaccSchedXactionSetAdvanceCreation( sxed->sx, daysInAdvance );
daysInAdvance = 0;
if ( gtk_toggle_button_get_active( sxed->remindOpt ) ) {
if ( gtk_toggle_button_get_active( sxed->remindOpt ) )
{
daysInAdvance =
gtk_spin_button_get_value_as_int( sxed->remindSpin );
}
@@ -965,7 +1017,7 @@ gnc_sxed_save_sx( GncSxEditorDialog *sxed )
xaccSchedXactionSetStartDate( sxed->sx, &gdate );
}
gnc_sx_commit_edit( sxed->sx );
gnc_sx_commit_edit( sxed->sx );
}
static void
@@ -977,7 +1029,8 @@ enabled_toggled( GtkObject *o, GncSxEditorDialog *sxed )
static void
autocreate_toggled( GtkObject *o, GncSxEditorDialog *sxed )
{
if ( !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(o)) ) {
if ( !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(o)) )
{
gtk_toggle_button_set_active( sxed->notifyOpt, FALSE );
}
gtk_widget_set_sensitive( GTK_WIDGET(sxed->notifyOpt),
@@ -992,7 +1045,8 @@ advance_toggle( GtkButton *o, GncSxEditorDialog *sxed )
spinName = (gchar*)g_object_get_data( G_OBJECT(o), "whichOneAmI" );
spin = glade_xml_get_widget( sxed->gxml, spinName );
if ( !spin ) {
if ( !spin )
{
g_critical("Error getting widget with name \"%s\"", spinName);
return;
}
@@ -1012,7 +1066,7 @@ scheduledxaction_editor_dialog_destroy(GtkObject *object, gpointer data)
return;
gnc_unregister_gui_component_by_data
(DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, sxed);
(DIALOG_SCHEDXACTION_EDITOR_CM_CLASS, sxed);
gnc_embedded_window_close_page(sxed->embed_window, sxed->plugin_page);
gtk_widget_destroy(GTK_WIDGET(sxed->embed_window));
@@ -1023,7 +1077,8 @@ scheduledxaction_editor_dialog_destroy(GtkObject *object, gpointer data)
g_free (sxed->sxGUIDstr);
sxed->sxGUIDstr = NULL;
if ( sxed->newsxP ) {
if ( sxed->newsxP )
{
/* FIXME: WTF???
*
* "WTF" explaination: in the "new" click from the caller, we
@@ -1032,7 +1087,7 @@ scheduledxaction_editor_dialog_destroy(GtkObject *object, gpointer data)
* "Cancel" is clicked, the flag will still be true, and this
* SX will be cleaned, here. -- jsled
*/
gnc_sx_begin_edit( sxed->sx );
gnc_sx_begin_edit( sxed->sx );
xaccSchedXactionDestroy( sxed->sx );
}
sxed->sx = NULL;
@@ -1048,11 +1103,13 @@ sxed_delete_event( GtkWidget *widget, GdkEvent *event, gpointer ud )
/* We've already processed the SX, likely because of "ok" being
* clicked. */
if ( sxed->sx == NULL ) {
if ( sxed->sx == NULL )
{
return FALSE;
}
if ( ! sxed_confirmed_cancel( sxed ) ) {
if ( ! sxed_confirmed_cancel( sxed ) )
{
return TRUE;
}
return FALSE;
@@ -1102,19 +1159,21 @@ gnc_sxed_get_widgets( GncSxEditorDialog *sxed )
GncSxEditorDialog *
gnc_ui_scheduled_xaction_editor_dialog_create(SchedXaction *sx,
gboolean newSX)
gboolean newSX)
{
GncSxEditorDialog *sxed;
GtkWidget *button;
int i;
GList *dlgExists = NULL;
static struct widgetSignalCallback {
static struct widgetSignalCallback
{
char *name;
char *signal;
void (*fn)();
gpointer objectData;
} widgets[] = {
} widgets[] =
{
{ "ok_button", "clicked", editor_ok_button_clicked, NULL },
{ "cancel_button", "clicked", editor_cancel_button_clicked, NULL },
{ "help_button", "clicked", editor_help_button_clicked, NULL },
@@ -1136,7 +1195,8 @@ gnc_ui_scheduled_xaction_editor_dialog_create(SchedXaction *sx,
dlgExists = gnc_find_gui_components( DIALOG_SCHEDXACTION_EDITOR_CM_CLASS,
editor_component_sx_equality,
sx );
if ( dlgExists != NULL ) {
if ( dlgExists != NULL )
{
g_debug( "dialog already exists; using that one." );
sxed = (GncSxEditorDialog*)dlgExists->data;
gtk_window_present( GTK_WINDOW(sxed->dialog) );
@@ -1184,9 +1244,11 @@ gnc_ui_scheduled_xaction_editor_dialog_create(SchedXaction *sx,
G_CALLBACK(scheduledxaction_editor_dialog_destroy),
sxed );
for ( i=0; widgets[i].name != NULL; i++ ) {
for ( i = 0; widgets[i].name != NULL; i++ )
{
button = glade_xml_get_widget( sxed->gxml, widgets[i].name );
if ( widgets[i].objectData != NULL ) {
if ( widgets[i].objectData != NULL )
{
g_object_set_data( G_OBJECT(button), "whichOneAmI",
widgets[i].objectData );
}
@@ -1250,7 +1312,7 @@ schedXact_editor_create_freq_sel( GncSxEditorDialog *sxed )
b = GTK_BOX(glade_xml_get_widget( sxed->gxml, "gncfreq_hbox" ));
sxed->gncfreq =
GNC_FREQUENCY(gnc_frequency_new_from_recurrence(gnc_sx_get_schedule(sxed->sx),
xaccSchedXactionGetStartDate(sxed->sx)));
xaccSchedXactionGetStartDate(sxed->sx)));
g_assert(sxed->gncfreq);
g_signal_connect( sxed->gncfreq, "changed",
G_CALLBACK(gnc_sxed_freq_changed),
@@ -1258,7 +1320,7 @@ schedXact_editor_create_freq_sel( GncSxEditorDialog *sxed )
gtk_container_add( GTK_CONTAINER(b), GTK_WIDGET(sxed->gncfreq) );
b = GTK_BOX(glade_xml_get_widget( sxed->gxml, "example_cal_hbox" ));
sxed->dense_cal_model = gnc_dense_cal_store_new(EX_CAL_NUM_MONTHS*31);
sxed->dense_cal_model = gnc_dense_cal_store_new(EX_CAL_NUM_MONTHS * 31);
sxed->example_cal = GNC_DENSE_CAL(gnc_dense_cal_new_with_model(GNC_DENSE_CAL_MODEL(sxed->dense_cal_model)));
g_assert(sxed->example_cal);
gnc_dense_cal_set_num_months( sxed->example_cal, EX_CAL_NUM_MONTHS );
@@ -1327,23 +1389,28 @@ schedXact_editor_populate( GncSxEditorDialog *sxed )
gboolean enabledState, autoCreateState, notifyState;
name = xaccSchedXactionGetName(sxed->sx);
if ( name != NULL ) {
if ( name != NULL )
{
gtk_entry_set_text( GTK_ENTRY(sxed->nameEntry), name );
}
{
gd = xaccSchedXactionGetLastOccurDate( sxed->sx );
if ( g_date_valid( gd ) ) {
if ( g_date_valid( gd ) )
{
gchar dateBuf[ MAX_DATE_LENGTH+1 ];
qof_print_gdate( dateBuf,MAX_DATE_LENGTH, gd );
qof_print_gdate( dateBuf, MAX_DATE_LENGTH, gd );
gtk_label_set_text( sxed->lastOccurLabel, dateBuf );
} else {
}
else
{
gtk_label_set_text( sxed->lastOccurLabel, _( "(never)" ) );
}
gd = NULL;
}
gd = xaccSchedXactionGetEndDate( sxed->sx );
if ( g_date_valid( gd ) ) {
if ( g_date_valid( gd ) )
{
gtk_toggle_button_set_active( sxed->optEndDate, TRUE );
/* fill in date data. */
tmpTm = g_new0( struct tm, 1 );
@@ -1353,7 +1420,9 @@ schedXact_editor_populate( GncSxEditorDialog *sxed )
gnc_date_edit_set_time( sxed->endDateEntry, tmpDate );
set_endgroup_toggle_states( sxed, END_DATE );
} else if ( xaccSchedXactionHasOccurDef( sxed->sx ) ) {
}
else if ( xaccSchedXactionHasOccurDef( sxed->sx ) )
{
gint numOccur = xaccSchedXactionGetNumOccur( sxed->sx );
gint numRemain = xaccSchedXactionGetRemOccur( sxed->sx );
@@ -1363,7 +1432,9 @@ schedXact_editor_populate( GncSxEditorDialog *sxed )
gtk_spin_button_set_value ( GTK_SPIN_BUTTON(sxed->endRemainSpin), numRemain );
set_endgroup_toggle_states( sxed, END_OCCUR );
} else {
}
else
{
gtk_toggle_button_set_active( sxed->optEndNone, TRUE );
set_endgroup_toggle_states( sxed, END_NEVER );
}
@@ -1372,52 +1443,65 @@ schedXact_editor_populate( GncSxEditorDialog *sxed )
gtk_toggle_button_set_active( sxed->enabledOpt, enabledState );
/* Do auto-create/notify setup */
if ( sxed->newsxP ) {
if ( sxed->newsxP )
{
autoCreateState =
gnc_gconf_get_bool( SXED_GCONF_SECTION, KEY_CREATE_AUTO, NULL );
notifyState =
gnc_gconf_get_bool( SXED_GCONF_SECTION, KEY_NOTIFY, NULL );
} else {
}
else
{
xaccSchedXactionGetAutoCreate( sxed->sx,
&autoCreateState,
&notifyState );
}
gtk_toggle_button_set_active( sxed->autocreateOpt, autoCreateState );
if ( ! autoCreateState ) {
if ( ! autoCreateState )
{
notifyState = FALSE;
}
gtk_toggle_button_set_active( sxed->notifyOpt, notifyState );
/* Do days-in-advance-to-create widget[s] setup. */
if ( sxed->newsxP ) {
if ( sxed->newsxP )
{
daysInAdvance =
gnc_gconf_get_float( SXED_GCONF_SECTION, KEY_CREATE_DAYS, NULL );
} else {
}
else
{
daysInAdvance =
xaccSchedXactionGetAdvanceCreation( sxed->sx );
}
if ( daysInAdvance != 0 ) {
if ( daysInAdvance != 0 )
{
gtk_toggle_button_set_active( sxed->advanceOpt, TRUE );
gtk_spin_button_set_value( sxed->advanceSpin,
(gfloat)daysInAdvance );
}
/* Do days-in-advance-to-remind widget[s] setup. */
if ( sxed->newsxP ) {
if ( sxed->newsxP )
{
daysInAdvance =
gnc_gconf_get_float( SXED_GCONF_SECTION, KEY_REMIND_DAYS, NULL );
} else {
}
else
{
daysInAdvance =
xaccSchedXactionGetAdvanceReminder( sxed->sx );
}
if ( daysInAdvance != 0 ) {
if ( daysInAdvance != 0 )
{
gtk_toggle_button_set_active( sxed->remindOpt, TRUE );
gtk_spin_button_set_value( sxed->remindSpin,
(gfloat)daysInAdvance );
}
if ( sxed->newsxP ) {
if ( sxed->newsxP )
{
gnc_sx_set_instance_count( sxed->sx, 1 );
}
@@ -1427,9 +1511,10 @@ schedXact_editor_populate( GncSxEditorDialog *sxed )
GList *splitList;
splitList = xaccSchedXactionGetSplits( sxed->sx );
if ( splitList != NULL ) {
if ( splitList != NULL )
{
splitReg = gnc_ledger_display_get_split_register
( sxed->ledger );
( sxed->ledger );
gnc_split_register_load(splitReg, splitList, NULL );
} /* otherwise, use the existing stuff. */
}
@@ -1458,7 +1543,8 @@ endgroup_rb_toggled( GtkButton *b, gpointer d )
sxed = (GncSxEditorDialog*)d;
id = GPOINTER_TO_INT(g_object_get_data( G_OBJECT(b), "whichOneAmI" ));
switch (id) {
switch (id)
{
case END_NEVER_OPTION:
set_endgroup_toggle_states( sxed, END_NEVER );
break;
@@ -1494,18 +1580,22 @@ gnc_sxed_reg_check_close(GncSxEditorDialog *sxed)
reg = gnc_ledger_display_get_split_register (sxed->ledger);
pending_changes = gnc_split_register_changed (reg);
if (!pending_changes) {
if (!pending_changes)
{
return;
}
if (gnc_verify_dialog(sxed->dialog, TRUE, "%s", message)) {
if (gnc_verify_dialog(sxed->dialog, TRUE, "%s", message))
{
Transaction *trans;
trans = gnc_split_register_get_current_trans( reg );
if ( !gnc_split_register_save( reg, TRUE ) )
return;
gnc_split_register_redraw( reg );
} else {
}
else
{
gnc_split_register_cancel_cursor_trans_changes (reg);
}
}
@@ -1539,8 +1629,8 @@ gnc_sxed_update_cal(GncSxEditorDialog *sxed)
last_sx_inst = xaccSchedXactionGetLastOccurDate(sxed->sx);
if (g_date_valid(last_sx_inst)
&& g_date_valid(&first_date)
&& g_date_compare(last_sx_inst, &first_date) != 0)
&& g_date_valid(&first_date)
&& g_date_compare(last_sx_inst, &first_date) != 0)
{
start_date = *last_sx_inst;
recurrenceListNextInstance(recurrences, &start_date, &first_date);
@@ -1578,7 +1668,7 @@ gnc_sxed_update_cal(GncSxEditorDialog *sxed)
else if (gtk_toggle_button_get_active(sxed->optEndCount))
{
gint num_remain
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sxed->endRemainSpin));
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(sxed->endRemainSpin));
gnc_dense_cal_store_update_recurrences_count_end(sxed->dense_cal_model, &first_date, recurrences, num_remain);
}
else
@@ -1641,7 +1731,7 @@ _open_editors(GtkDialog *dialog, gint response_code, gpointer data)
for (sx_iter = adhd->affected_sxes; sx_iter; sx_iter = sx_iter->next)
{
gnc_ui_scheduled_xaction_editor_dialog_create((SchedXaction*)sx_iter->data,
FALSE);
FALSE);
}
}
g_list_free(adhd->affected_sxes);
@@ -1701,8 +1791,8 @@ _sx_engine_event_handler(QofInstance *ent, QofEventId event_type, gpointer user_
renderer = gtk_cell_renderer_text_new();
name_column = gtk_tree_view_column_new_with_attributes(_("Name"),
renderer,
"text", 0, NULL);
renderer,
"text", 0, NULL);
gtk_tree_view_append_column(list, name_column);
g_signal_connect(G_OBJECT(dialog), "response",

View File

@@ -36,7 +36,7 @@
typedef struct _GncSxEditorDialog GncSxEditorDialog;
GncSxEditorDialog* gnc_ui_scheduled_xaction_editor_dialog_create(SchedXaction *sx,
gboolean newSX);
gboolean newSX);
void gnc_ui_scheduled_xaction_editor_dialog_destroy(GncSxEditorDialog *sxd);

File diff suppressed because it is too large Load Diff

View File

@@ -140,8 +140,10 @@ GType
gnc_sx_slr_tree_model_adapter_get_type(void)
{
static GType gsstma_type = 0;
if (gsstma_type == 0) {
static const GTypeInfo info = {
if (gsstma_type == 0)
{
static const GTypeInfo info =
{
sizeof (GncSxSlrTreeModelAdapterClass),
NULL, /* base_init */
NULL, /* base_finalize */
@@ -152,7 +154,8 @@ gnc_sx_slr_tree_model_adapter_get_type(void)
0, /* n_preallocs */
(GInstanceInitFunc)gnc_sx_slr_tree_model_adapter_init /* instance_init */
};
static const GInterfaceInfo itreeModel_info = {
static const GInterfaceInfo itreeModel_info =
{
(GInterfaceInitFunc) gnc_sx_slr_tree_model_adapter_interface_init, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
@@ -349,7 +352,8 @@ gsslrtma_proxy_rows_reordered(GtkTreeModel *treemodel,
}
// model columns
enum {
enum
{
SLR_MODEL_COL_NAME = 0,
SLR_MODEL_COL_INSTANCE_STATE,
SLR_MODEL_COL_VARAIBLE_VALUE,
@@ -375,7 +379,8 @@ gnc_sx_slr_tree_model_adapter_init(GTypeInstance *instance, gpointer klass)
g_signal_connect(adapter->real, "rows-reordered", G_CALLBACK(gsslrtma_proxy_rows_reordered), adapter);
}
static char* gnc_sx_instance_state_names[] = {
static char* gnc_sx_instance_state_names[] =
{
N_("Ignored"),
N_("Postponed"),
N_("To-Create"),
@@ -529,7 +534,7 @@ gsslrtma_populate_tree_store(GncSxSlrTreeModelAdapter *model)
SLR_MODEL_COL_INSTANCE_VISIBILITY, FALSE,
SLR_MODEL_COL_VARIABLE_VISIBILITY, TRUE,
SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY, FALSE
-1);
- 1);
g_string_free(tmp_str, TRUE);
}
g_list_free(vars);
@@ -537,7 +542,7 @@ gsslrtma_populate_tree_store(GncSxSlrTreeModelAdapter *model)
_consume_excess_rows(model->real, visible_variable_index, &inst_tree_iter, &var_tree_iter);
}
}
// if there are more instance iters, remove
_consume_excess_rows(model->real, instance_index, &sx_tree_iter, &inst_tree_iter);
}
@@ -708,7 +713,7 @@ _get_path_for_variable(GncSxSlrTreeModelAdapter *model, GncSxInstance *instance,
static void
gsslrtma_added_cb(GncSxInstanceModel *instances, SchedXaction *added_sx, gpointer user_data)
{
GncSxSlrTreeModelAdapter *model = GNC_SX_SLR_TREE_MODEL_ADAPTER(user_data);
GncSxSlrTreeModelAdapter *model = GNC_SX_SLR_TREE_MODEL_ADAPTER(user_data);
// this is wasteful, but fine.
gsslrtma_populate_tree_store(model);
}
@@ -716,7 +721,7 @@ gsslrtma_added_cb(GncSxInstanceModel *instances, SchedXaction *added_sx, gpointe
static void
gsslrtma_updated_cb(GncSxInstanceModel *instances, SchedXaction *updated_sx, gpointer user_data)
{
GncSxSlrTreeModelAdapter *model = GNC_SX_SLR_TREE_MODEL_ADAPTER(user_data);
GncSxSlrTreeModelAdapter *model = GNC_SX_SLR_TREE_MODEL_ADAPTER(user_data);
gnc_sx_instance_model_update_sx_instances(instances, updated_sx);
gsslrtma_populate_tree_store(model);
}
@@ -724,7 +729,7 @@ gsslrtma_updated_cb(GncSxInstanceModel *instances, SchedXaction *updated_sx, gpo
static void
gsslrtma_removing_cb(GncSxInstanceModel *instances, SchedXaction *to_remove_sx, gpointer user_data)
{
GncSxSlrTreeModelAdapter *model = GNC_SX_SLR_TREE_MODEL_ADAPTER(user_data);
GncSxSlrTreeModelAdapter *model = GNC_SX_SLR_TREE_MODEL_ADAPTER(user_data);
GtkTreeIter tree_iter;
GList *iter;
int index = 0;
@@ -752,7 +757,7 @@ gnc_sx_slr_tree_model_adapter_dispose(GObject *obj)
adapter = GNC_SX_SLR_TREE_MODEL_ADAPTER(obj);
g_return_if_fail(!adapter->disposed);
adapter->disposed = TRUE;
g_object_unref(G_OBJECT(adapter->instances));
adapter->instances = NULL;
g_object_unref(G_OBJECT(adapter->real));
@@ -807,14 +812,14 @@ gnc_sx_sxsincelast_book_opened(void)
if (summary.num_auto_create_no_notify_instances != 0)
{
gnc_info_dialog
(NULL,
ngettext
("There are no Scheduled Transactions to be entered at this time. "
"(%d transaction automatically created)",
"There are no Scheduled Transactions to be entered at this time. "
"(%d transactions automatically created)",
summary.num_auto_create_no_notify_instances),
summary.num_auto_create_no_notify_instances);
(NULL,
ngettext
("There are no Scheduled Transactions to be entered at this time. "
"(%d transaction automatically created)",
"There are no Scheduled Transactions to be entered at this time. "
"(%d transactions automatically created)",
summary.num_auto_create_no_notify_instances),
summary.num_auto_create_no_notify_instances);
}
}
g_list_free(auto_created_txns);
@@ -831,7 +836,7 @@ instance_state_changed_cb(GtkCellRendererText *cell,
GncSxInstance *inst;
int i;
GncSxInstanceState new_state;
for (i = 0; i < SX_INSTANCE_STATE_CREATED; i++)
{
if (strcmp(value, _(gnc_sx_instance_state_names[i])) == 0)
@@ -886,7 +891,7 @@ variable_value_changed_cb(GtkCellRendererText *cell,
}
if (!xaccParseAmount(value, TRUE, &parsed_num, &endStr)
|| gnc_numeric_check(parsed_num) != GNC_ERROR_OK)
|| gnc_numeric_check(parsed_num) != GNC_ERROR_OK)
{
gchar *value_copy = g_strdup(value);
g_debug("value=[%s] endStr[%s]", value, endStr);
@@ -919,18 +924,18 @@ gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances, GList *auto_cr
dialog->review_created_txns_toggle = GTK_TOGGLE_BUTTON(glade_xml_get_widget(glade, "review_txn_toggle"));
dialog->created_txns = auto_created_txn_guids;
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *col;
dialog->instance_view = GTK_TREE_VIEW(glade_xml_get_widget(glade, "instance_view"));
gtk_tree_view_set_model(dialog->instance_view, GTK_TREE_MODEL(dialog->editing_model));
renderer = gtk_cell_renderer_text_new();
col = gtk_tree_view_column_new_with_attributes(_("Transaction"), renderer,
"text", SLR_MODEL_COL_NAME,
NULL);
"text", SLR_MODEL_COL_NAME,
NULL);
gtk_tree_view_append_column(dialog->instance_view, col);
renderer = gtk_cell_renderer_combo_new();
@@ -945,14 +950,14 @@ gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances, GList *auto_cr
G_CALLBACK(instance_state_changed_cb),
dialog);
col = gtk_tree_view_column_new_with_attributes(_("Status"), renderer,
"text", SLR_MODEL_COL_INSTANCE_STATE,
"visible", SLR_MODEL_COL_INSTANCE_VISIBILITY,
// you might think only "sensitive" is required to
// control the ability of the combo box to select
// a new state, but you'd be wrong.
"editable", SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY,
"sensitive", SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY,
NULL);
"text", SLR_MODEL_COL_INSTANCE_STATE,
"visible", SLR_MODEL_COL_INSTANCE_VISIBILITY,
// you might think only "sensitive" is required to
// control the ability of the combo box to select
// a new state, but you'd be wrong.
"editable", SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY,
"sensitive", SLR_MODEL_COL_INSTANCE_STATE_SENSITIVITY,
NULL);
gtk_tree_view_append_column(dialog->instance_view, col);
renderer = gtk_cell_renderer_text_new();
@@ -964,9 +969,9 @@ gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances, GList *auto_cr
G_CALLBACK(variable_value_changed_cb),
dialog);
col = gtk_tree_view_column_new_with_attributes(_("Value"), renderer,
"text", SLR_MODEL_COL_VARAIBLE_VALUE,
"visible", SLR_MODEL_COL_VARIABLE_VISIBILITY,
NULL);
"text", SLR_MODEL_COL_VARAIBLE_VALUE,
"visible", SLR_MODEL_COL_VARIABLE_VISIBILITY,
NULL);
gtk_tree_view_append_column(dialog->instance_view, col);
gtk_tree_view_expand_all(dialog->instance_view);
@@ -978,7 +983,7 @@ gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances, GList *auto_cr
gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(dialog->dialog));
dialog->component_id = gnc_register_gui_component
(DIALOG_SX_SINCE_LAST_RUN_CM_CLASS, NULL, close_handler, dialog);
(DIALOG_SX_SINCE_LAST_RUN_CM_CLASS, NULL, close_handler, dialog);
gnc_gui_component_set_session(dialog->component_id,
gnc_get_current_session());
@@ -1044,41 +1049,41 @@ dialog_response_cb(GtkDialog *dialog, gint response_id, GncSxSinceLastRunDialog
// - [ ] instance state constraints
// - [x] required variable binding
// - [?] ability to create transactions
{
GList *unbound_variables;
unbound_variables = gnc_sx_instance_model_check_variables(app_dialog->editing_model->instances);
g_message("%d variables unbound", g_list_length(unbound_variables));
if (g_list_length(unbound_variables) > 0)
{
GList *unbound_variables;
unbound_variables = gnc_sx_instance_model_check_variables(app_dialog->editing_model->instances);
g_message("%d variables unbound", g_list_length(unbound_variables));
if (g_list_length(unbound_variables) > 0)
{
// focus first variable
GncSxVariableNeeded *first_unbound;
GtkTreePath *variable_path;
GtkTreeViewColumn *variable_col;
gint variable_view_column = 2;
gboolean start_editing = TRUE;
// focus first variable
GncSxVariableNeeded *first_unbound;
GtkTreePath *variable_path;
GtkTreeViewColumn *variable_col;
gint variable_view_column = 2;
gboolean start_editing = TRUE;
first_unbound = (GncSxVariableNeeded*)unbound_variables->data;
variable_path = _get_path_for_variable(app_dialog->editing_model, first_unbound->instance, first_unbound->variable);
variable_col = gtk_tree_view_get_column(app_dialog->instance_view, variable_view_column);
first_unbound = (GncSxVariableNeeded*)unbound_variables->data;
variable_path = _get_path_for_variable(app_dialog->editing_model, first_unbound->instance, first_unbound->variable);
variable_col = gtk_tree_view_get_column(app_dialog->instance_view, variable_view_column);
gtk_tree_view_set_cursor(app_dialog->instance_view, variable_path, variable_col, start_editing);
gtk_tree_view_set_cursor(app_dialog->instance_view, variable_path, variable_col, start_editing);
gtk_tree_path_free(variable_path);
g_list_foreach(unbound_variables, (GFunc)g_free, NULL);
g_list_free(unbound_variables);
return;
}
gtk_tree_path_free(variable_path);
g_list_foreach(unbound_variables, (GFunc)g_free, NULL);
g_list_free(unbound_variables);
return;
}
gnc_suspend_gui_refresh();
gnc_sx_slr_model_effect_change(app_dialog->editing_model, FALSE, &app_dialog->created_txns, NULL);
gnc_resume_gui_refresh();
if (gtk_toggle_button_get_active(app_dialog->review_created_txns_toggle)
}
gnc_suspend_gui_refresh();
gnc_sx_slr_model_effect_change(app_dialog->editing_model, FALSE, &app_dialog->created_txns, NULL);
gnc_resume_gui_refresh();
if (gtk_toggle_button_get_active(app_dialog->review_created_txns_toggle)
&& g_list_length(app_dialog->created_txns) > 0)
{
_show_created_transactions(app_dialog, app_dialog->created_txns);
}
g_list_free(app_dialog->created_txns);
app_dialog->created_txns = NULL;
{
_show_created_transactions(app_dialog, app_dialog->created_txns);
}
g_list_free(app_dialog->created_txns);
app_dialog->created_txns = NULL;
/* FALLTHROUGH */
case GTK_RESPONSE_CANCEL:

View File

@@ -43,6 +43,6 @@ void gnc_sx_sxsincelast_book_opened(void);
* Create the since-last-run dialog.
**/
GncSxSinceLastRunDialog* gnc_ui_sx_since_last_run_dialog(GncSxInstanceModel *sx_instances,
GList *auto_created_txn_guids);
GList *auto_created_txn_guids);
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -37,52 +37,52 @@ gnc_get_username_password (GtkWidget *parent,
char **username,
char **password)
{
GtkWidget *dialog;
GtkWidget *heading_label;
GtkWidget *username_entry;
GtkWidget *password_entry;
GladeXML *xml;
gint result;
GtkWidget *dialog;
GtkWidget *heading_label;
GtkWidget *username_entry;
GtkWidget *password_entry;
GladeXML *xml;
gint result;
g_return_val_if_fail (username != NULL, FALSE);
g_return_val_if_fail (password != NULL, FALSE);
g_return_val_if_fail (username != NULL, FALSE);
g_return_val_if_fail (password != NULL, FALSE);
xml = gnc_glade_xml_new ("userpass.glade", "Username Password Dialog");
xml = gnc_glade_xml_new ("userpass.glade", "Username Password Dialog");
dialog = glade_xml_get_widget (xml, "Username Password Dialog");
dialog = glade_xml_get_widget (xml, "Username Password Dialog");
if (parent)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
if (parent)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
heading_label = glade_xml_get_widget (xml, "heading_label");
username_entry = glade_xml_get_widget (xml, "username_entry");
password_entry = glade_xml_get_widget (xml, "password_entry");
heading_label = glade_xml_get_widget (xml, "heading_label");
username_entry = glade_xml_get_widget (xml, "username_entry");
password_entry = glade_xml_get_widget (xml, "password_entry");
if (heading)
gtk_label_set_text (GTK_LABEL (heading_label), heading);
if (heading)
gtk_label_set_text (GTK_LABEL (heading_label), heading);
if (initial_username)
gtk_entry_set_text (GTK_ENTRY (username_entry), initial_username);
gtk_editable_select_region (GTK_EDITABLE (username_entry), 0, -1);
if (initial_username)
gtk_entry_set_text (GTK_ENTRY (username_entry), initial_username);
gtk_editable_select_region (GTK_EDITABLE (username_entry), 0, -1);
if (initial_password)
gtk_entry_set_text (GTK_ENTRY (password_entry), initial_password);
if (initial_password)
gtk_entry_set_text (GTK_ENTRY (password_entry), initial_password);
result = gtk_dialog_run(GTK_DIALOG (dialog));
gtk_widget_hide(dialog);
result = gtk_dialog_run(GTK_DIALOG (dialog));
gtk_widget_hide(dialog);
if (result == GTK_RESPONSE_OK)
{
*username = gtk_editable_get_chars (GTK_EDITABLE (username_entry), 0, -1);
*password = gtk_editable_get_chars (GTK_EDITABLE (password_entry), 0, -1);
if (result == GTK_RESPONSE_OK)
{
*username = gtk_editable_get_chars (GTK_EDITABLE (username_entry), 0, -1);
*password = gtk_editable_get_chars (GTK_EDITABLE (password_entry), 0, -1);
gtk_widget_destroy(dialog);
return TRUE;
}
*username = NULL;
*password = NULL;
gtk_widget_destroy(dialog);
return TRUE;
}
*username = NULL;
*password = NULL;
gtk_widget_destroy(dialog);
return FALSE;
return FALSE;
}

View File

@@ -53,25 +53,25 @@ 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;
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;
time_t earliest;
char * earliest_str;
GDate closing_date;
GDate prev_closing_date;
GList *period;
int close_status;
} AcctPeriodInfo;
@@ -84,39 +84,39 @@ typedef struct
static time_t
get_earliest_in_book (QofBook *book)
{
QofQuery *q;
GSList *p1, *p2;
GList *res;
time_t earliest;
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);
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);
/* 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);
/* 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);
/* 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);
}
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;
qof_query_destroy (q);
return earliest;
}
/* =============================================================== */
@@ -127,31 +127,31 @@ get_earliest_in_book (QofBook *book)
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;
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);
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);
/* 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);
/* Run the query, find how many transactions there are */
res = qof_query_run (q);
cnt = 0;
for (n=res; n; n=n->next) cnt ++;
cnt = 0;
for (n = res; n; n = n->next) cnt ++;
qof_query_destroy (q);
return cnt;
qof_query_destroy (q);
return cnt;
}
/* =============================================================== */
@@ -159,16 +159,21 @@ get_num_xactions_before_date(QofBook *book, time_t close_date)
static const char *
get_close_status_str (AcctPeriodInfo *info)
{
const char * str;
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;
/* 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;
}
/* =============================================================== */
@@ -176,30 +181,30 @@ get_close_status_str (AcctPeriodInfo *info)
static void
ap_window_destroy_cb (GtkObject *object, gpointer data)
{
AcctPeriodInfo *info = data;
AcctPeriodInfo *info = data;
gnc_unregister_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info);
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);
// 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)
GtkWidget *druid,
gpointer user_data)
{
AcctPeriodInfo *info = user_data;
gnc_close_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info);
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);
AcctPeriodInfo *info = user_data;
gnc_close_gui_component_by_data (DRUID_ACCT_PERIOD_CM_CLASS, info);
}
/* =============================================================== */
@@ -207,45 +212,45 @@ ap_druid_cancel (GnomeDruid *druid, gpointer user_data)
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);
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);
/* 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));
/* 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);
}
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);
/* 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);
}
/* =============================================================== */
@@ -253,61 +258,61 @@ prepare_remarks (AcctPeriodInfo *info)
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;
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);
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;
/* 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);
/* 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));
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));
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));
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);
/* 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));
/* 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));
/* 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);
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);
}
@@ -316,77 +321,77 @@ show_book_details (AcctPeriodInfo *info)
static void
ap_changed (GtkWidget *widget, gpointer user_data)
{
AcctPeriodInfo *info = user_data;
AcctPeriodInfo *info = user_data;
ENTER ("info=%p", info);
prepare_remarks (info);
ENTER ("info=%p", info);
prepare_remarks (info);
}
static void
ap_show_menu (GnomeDruidPage *druidpage,
GtkWidget *druid,
gpointer user_data)
GtkWidget *druid,
gpointer user_data)
{
AcctPeriodInfo *info = user_data;
ENTER("info=%p", info);
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));
/* 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);
prepare_remarks (info);
}
static gboolean
ap_validate_menu (GnomeDruidPage *druidpage,
GtkWidget *druid,
gpointer user_data)
GtkWidget *druid,
gpointer user_data)
{
GDate date_now;
AcctPeriodInfo *info = user_data;
ENTER("info=%p", info);
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);
/* 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;
}
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;
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)
GtkWidget *druid,
gpointer user_data)
{
AcctPeriodInfo *info = user_data;
AcctPeriodInfo *info = user_data;
ENTER ("info=%p", info);
show_book_details (info);
ENTER ("info=%p", info);
show_book_details (info);
}
/* =============================================================== */
@@ -394,111 +399,111 @@ ap_show_book (GnomeDruidPage *druidpage,
static void
scrub_all(void)
{
Account *root = gnc_get_current_root_account ();
xaccAccountTreeScrubOrphans (root);
xaccAccountTreeScrubImbalance (root);
// XXX: Lots are disabled
// xaccAccountTreeScrubLots (root);
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)
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;
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);
ENTER("info=%p", info);
current_book = gnc_get_current_book ();
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);
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));
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;
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 ();
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);
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);
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);
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);
/* 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? */
/* 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);
/* 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;
}
/* 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);
/* 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;
show_book_details (info);
return TRUE;
}
/* =============================================================== */
static void
ap_show_done (GnomeDruidPageEdge *druidpage,
GtkWidget *druid,
gpointer user_data)
GtkWidget *druid,
gpointer user_data)
{
const char *msg;
char *str;
AcctPeriodInfo *info = user_data;
ENTER ("info=%p", info);
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!");
/* 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);
str = g_strdup_printf (msg, get_close_status_str (info));
gnome_druid_page_edge_set_text (druidpage, str);
g_free (str);
}
/* =============================================================== */
@@ -506,113 +511,113 @@ ap_show_done (GnomeDruidPageEdge *druidpage,
static void
ap_druid_create (AcctPeriodInfo *info)
{
GladeXML *xml;
GtkWidget *w;
GladeXML *xml;
GtkWidget *w;
xml = gnc_glade_xml_new ("acctperiod.glade", "Acct Period Druid");
xml = gnc_glade_xml_new ("acctperiod.glade", "Acct Period Druid");
info->window = glade_xml_get_widget (xml, "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->druid = GNOME_DRUID (glade_xml_get_widget (xml, "acct_period_druid"));
gnc_druid_set_colors (info->druid);
info->start_page =
info->start_page =
GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "start page"));
info->menu_page =
info->menu_page =
GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "menu page"));
info->book_page =
info->book_page =
GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "book page"));
info->finish_page =
info->finish_page =
GNOME_DRUID_PAGE(glade_xml_get_widget (xml, "finish page"));
info->close_status = -1;
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));
/* 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);
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);
}
{
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));
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:"));
/* 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);
/* 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 =
/* 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 =
info->close_results =
GTK_LABEL (glade_xml_get_widget (xml, "results label"));
info->book_details =
info->book_details =
GTK_LABEL (glade_xml_get_widget (xml, "book label"));
info->book_title =
info->book_title =
GTK_ENTRY (glade_xml_get_widget (xml, "book title entry"));
info->book_notes =
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);
/* 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->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, "prepare",
G_CALLBACK (ap_show_menu), info);
g_signal_connect (info->menu_page, "next",
G_CALLBACK (ap_validate_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, "prepare",
G_CALLBACK (ap_show_book), info);
g_signal_connect (info->book_page, "next",
G_CALLBACK (ap_close_period), 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, "prepare",
G_CALLBACK (ap_show_done), info);
g_signal_connect (info->finish_page, "finish",
G_CALLBACK (ap_finish), 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);
/* 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;
AcctPeriodInfo *info = user_data;
gtk_widget_destroy (info->window);
gtk_widget_destroy (info->window);
}
/********************************************************************\
@@ -626,18 +631,18 @@ ap_close_handler (gpointer user_data)
void
gnc_acct_period_dialog (void)
{
AcctPeriodInfo *info;
gint component_id;
AcctPeriodInfo *info;
gint component_id;
info = g_new0 (AcctPeriodInfo, 1);
info = g_new0 (AcctPeriodInfo, 1);
ap_druid_create (info);
ap_druid_create (info);
component_id = gnc_register_gui_component (DRUID_ACCT_PERIOD_CM_CLASS,
NULL, ap_close_handler,
info);
component_id = gnc_register_gui_component (DRUID_ACCT_PERIOD_CM_CLASS,
NULL, ap_close_handler,
info);
gtk_widget_show_all (info->window);
gtk_widget_show_all (info->window);
gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
gnc_window_adjust_for_screen (GTK_WINDOW(info->window));
}

View File

@@ -26,7 +26,7 @@
/********************************************************************\
* gnc_acct_period_dialog *
* opens up a window to set up accounting period *
* *
* *
* Args: none *
* Return: nothing *
\********************************************************************/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -55,18 +55,18 @@ void collision_rule_loop (QofBookMergeData*, QofBookMergeRule*, guint );
static GtkWidget*
merge_get_widget (const char *name)
{
if (!qsf_import_merge_window) return NULL;
if (!qsf_import_merge_window) return NULL;
return gnc_glade_lookup_widget (qsf_import_merge_window, name);
return gnc_glade_lookup_widget (qsf_import_merge_window, name);
}
static void
delete_merge_window (void)
{
if (!qsf_import_merge_window) return;
gtk_widget_destroy (qsf_import_merge_window);
qsf_import_merge_window = NULL;
if (!qsf_import_merge_window) return;
gtk_widget_destroy (qsf_import_merge_window);
qsf_import_merge_window = NULL;
}
static void
@@ -76,312 +76,325 @@ qof_book_merge_destroy_cb (GtkObject *obj, gpointer user_data)
static gboolean
on_import_start_page_next(GnomeDruidPage *gnomedruidpage,
gpointer arg1,
gpointer user_data)
gpointer arg1,
gpointer user_data)
{
return FALSE;
return FALSE;
}
static void
on_MergeUpdate_clicked (GtkButton *button,
gpointer user_data)
gpointer user_data)
{
GtkLabel *output;
GtkLabel *output;
g_return_if_fail(mergeData != NULL);
ENTER (" ");
mergeData = qof_book_merge_update_result(mergeData, MERGE_UPDATE);
count = 0;
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if(count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output,_("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
LEAVE (" ");
g_return_if_fail(mergeData != NULL);
ENTER (" ");
mergeData = qof_book_merge_update_result(mergeData, MERGE_UPDATE);
count = 0;
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if (count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output, _("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
LEAVE (" ");
}
static void
on_MergeDuplicate_clicked (GtkButton *button,
gpointer user_data)
gpointer user_data)
{
QofBookMergeRule *currentRule;
GtkLabel *output;
g_return_if_fail(mergeData != NULL);
ENTER (" ");
currentRule = mergeData->currentRule;
if(currentRule->mergeAbsolute == FALSE) {
mergeData = qof_book_merge_update_result(mergeData, MERGE_DUPLICATE);
count = 0;
}
if(currentRule->mergeAbsolute == TRUE) {
mergeData = qof_book_merge_update_result(mergeData, MERGE_ABSOLUTE);
count = 0;
}
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if(count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output,_("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
LEAVE (" ");
QofBookMergeRule *currentRule;
GtkLabel *output;
g_return_if_fail(mergeData != NULL);
ENTER (" ");
currentRule = mergeData->currentRule;
if (currentRule->mergeAbsolute == FALSE)
{
mergeData = qof_book_merge_update_result(mergeData, MERGE_DUPLICATE);
count = 0;
}
if (currentRule->mergeAbsolute == TRUE)
{
mergeData = qof_book_merge_update_result(mergeData, MERGE_ABSOLUTE);
count = 0;
}
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if (count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output, _("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
LEAVE (" ");
}
static void
on_MergeNew_clicked (GtkButton *button,
gpointer user_data)
gpointer user_data)
{
QofBookMergeRule *currentRule;
GtkLabel *output;
QofBookMergeRule *currentRule;
GtkLabel *output;
g_return_if_fail(mergeData != NULL);
currentRule = mergeData->currentRule;
g_return_if_fail(currentRule != NULL);
ENTER (" ");
if(currentRule->mergeAbsolute == FALSE) {
mergeData = qof_book_merge_update_result(mergeData, MERGE_NEW);
}
count = 0;
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if(count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output,_("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
LEAVE (" ");
g_return_if_fail(mergeData != NULL);
currentRule = mergeData->currentRule;
g_return_if_fail(currentRule != NULL);
ENTER (" ");
if (currentRule->mergeAbsolute == FALSE)
{
mergeData = qof_book_merge_update_result(mergeData, MERGE_NEW);
}
count = 0;
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if (count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output, _("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
LEAVE (" ");
}
static gboolean
on_import_next (GnomeDruidPage *gnomedruidpage,
gpointer arg1,
gpointer user_data)
gpointer arg1,
gpointer user_data)
{
GtkWidget *top;
gchar *message;
GtkWidget *top;
gchar *message;
if(count > 0)
{
message = g_strdup_printf(_("Error: Please resolve all %d "
"conflicts before trying to commit the data."), count);
top = gtk_widget_get_toplevel (GTK_WIDGET (gnomedruidpage));
gnc_error_dialog(top, "%s", message);
g_free(message);
return TRUE;
}
return FALSE;
if (count > 0)
{
message = g_strdup_printf(_("Error: Please resolve all %d "
"conflicts before trying to commit the data."), count);
top = gtk_widget_get_toplevel (GTK_WIDGET (gnomedruidpage));
gnc_error_dialog(top, "%s", message);
g_free(message);
return TRUE;
}
return FALSE;
}
static void
on_merge_cancel (GnomeDruid *gnomedruid, gpointer user_data)
{
g_return_if_fail(mergeBook != NULL);
gnc_suspend_gui_refresh ();
delete_merge_window();
qof_book_destroy(mergeBook);
qof_session_end(merge_session);
gnc_resume_gui_refresh ();
g_return_if_fail(mergeBook != NULL);
gnc_suspend_gui_refresh ();
delete_merge_window();
qof_book_destroy(mergeBook);
qof_session_end(merge_session);
gnc_resume_gui_refresh ();
}
void currency_transfer_cb ( QofInstance* ent, gpointer user_data)
{
if(!ent) return;
if(xaccAccountGetCommodity((Account*)ent) == NULL) {
xaccAccountSetCommodity((Account*)ent, gnc_default_currency());
}
if (!ent) return;
if (xaccAccountGetCommodity((Account*)ent) == NULL)
{
xaccAccountSetCommodity((Account*)ent, gnc_default_currency());
}
}
/* If the account has no parent, shove it into the top level under the root. */
void reference_parent_cb ( QofInstance* ent, gpointer user_data)
{
Account *root;
Account *root;
if(!ent) return;
if(gnc_account_get_parent((Account*)ent) == NULL) {
root = gnc_book_get_root_account(targetBook);
gnc_account_append_child(root, (Account*)ent);
}
if (!ent) return;
if (gnc_account_get_parent((Account*)ent) == NULL)
{
root = gnc_book_get_root_account(targetBook);
gnc_account_append_child(root, (Account*)ent);
}
}
static void
on_merge_finish (GnomeDruidPage *gnomedruidpage,
gpointer arg1,
gpointer user_data)
gpointer arg1,
gpointer user_data)
{
gint result;
GtkWidget *top;
const char *message;
gint result;
GtkWidget *top;
const char *message;
ENTER (" ");
g_return_if_fail(mergeData != NULL);
gnc_suspend_gui_refresh ();
result = qof_book_merge_commit(mergeData);
if(result != 0) {
message = g_strdup_printf(_("Error: the Commit operation failed, error code %d."), result);
top = gtk_widget_get_toplevel (GTK_WIDGET (gnomedruidpage));
gnc_error_dialog(top, "%s", message);
}
g_return_if_fail(result == 0);
delete_merge_window ();
qof_object_foreach(GNC_ID_ACCOUNT, targetBook, currency_transfer_cb, NULL);
qof_object_foreach(GNC_ID_ACCOUNT, targetBook, reference_parent_cb, NULL);
qof_book_destroy(mergeBook);
qof_session_end(merge_session);
gnc_resume_gui_refresh ();
LEAVE (" ");
ENTER (" ");
g_return_if_fail(mergeData != NULL);
gnc_suspend_gui_refresh ();
result = qof_book_merge_commit(mergeData);
if (result != 0)
{
message = g_strdup_printf(_("Error: the Commit operation failed, error code %d."), result);
top = gtk_widget_get_toplevel (GTK_WIDGET (gnomedruidpage));
gnc_error_dialog(top, "%s", message);
}
g_return_if_fail(result == 0);
delete_merge_window ();
qof_object_foreach(GNC_ID_ACCOUNT, targetBook, currency_transfer_cb, NULL);
qof_object_foreach(GNC_ID_ACCOUNT, targetBook, reference_parent_cb, NULL);
qof_book_destroy(mergeBook);
qof_session_end(merge_session);
gnc_resume_gui_refresh ();
LEAVE (" ");
}
static void
on_merge_prepare (GnomeDruidPage *gnomedruidpage,
gpointer arg1,
gpointer user_data)
gpointer arg1,
gpointer user_data)
{
GtkLabel *progress, *output;
GtkLabel *progress, *output;
gnc_suspend_gui_refresh ();
ENTER (" ");
progress = GTK_LABEL (merge_get_widget("ResultsBox"));
/* blank out old data */
gtk_label_set_text(progress, "");
g_return_if_fail(mergeBook || targetBook);
mergeData = qof_book_merge_init(mergeBook, targetBook);
g_return_if_fail(mergeData != NULL);
count = 0;
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if(count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output,_("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
gnc_resume_gui_refresh ();
LEAVE (" ");
gnc_suspend_gui_refresh ();
ENTER (" ");
progress = GTK_LABEL (merge_get_widget("ResultsBox"));
/* blank out old data */
gtk_label_set_text(progress, "");
g_return_if_fail(mergeBook || targetBook);
mergeData = qof_book_merge_init(mergeBook, targetBook);
g_return_if_fail(mergeData != NULL);
count = 0;
qof_book_merge_rule_foreach(mergeData, collision_rule_loop, MERGE_REPORT);
if (count == 0)
{
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output, _("No conflicts to be resolved."));
gtk_widget_show(GTK_WIDGET(output));
}
gnc_resume_gui_refresh ();
LEAVE (" ");
}
static GtkWidget *
gnc_create_import_druid ( void )
{
GtkWidget *dialog, *druid, *start_page;
GladeXML *xml;
GtkWidget *dialog, *druid, *start_page;
GladeXML *xml;
xml = gnc_glade_xml_new ("merge.glade", "Merge Druid");
xml = gnc_glade_xml_new ("merge.glade", "Merge Druid");
dialog = glade_xml_get_widget (xml, "Merge Druid");
druid = glade_xml_get_widget (xml, "merge_druid");
gnc_druid_set_colors (GNOME_DRUID (druid));
start_page = glade_xml_get_widget (xml, "start_page");
gtk_widget_show (start_page);
gtk_widget_show (glade_xml_get_widget (xml, "MergeDruidFinishPage"));
dialog = glade_xml_get_widget (xml, "Merge Druid");
druid = glade_xml_get_widget (xml, "merge_druid");
gnc_druid_set_colors (GNOME_DRUID (druid));
start_page = glade_xml_get_widget (xml, "start_page");
gtk_widget_show (start_page);
gtk_widget_show (glade_xml_get_widget (xml, "MergeDruidFinishPage"));
glade_xml_signal_connect(xml, "on_start_page_next",
G_CALLBACK (on_import_start_page_next));
glade_xml_signal_connect(xml, "on_qof_book_merge_prepare",
G_CALLBACK (on_merge_prepare));
glade_xml_signal_connect(xml, "on_start_page_next",
G_CALLBACK (on_import_start_page_next));
glade_xml_signal_connect(xml, "on_qof_book_merge_next",
G_CALLBACK (on_import_next));
glade_xml_signal_connect(xml, "on_qof_book_merge_prepare",
G_CALLBACK (on_merge_prepare));
glade_xml_signal_connect (xml, "on_finish",
G_CALLBACK (on_merge_finish));
glade_xml_signal_connect(xml, "on_qof_book_merge_next",
G_CALLBACK (on_import_next));
glade_xml_signal_connect (xml, "on_cancel",
G_CALLBACK (on_merge_cancel));
glade_xml_signal_connect (xml, "on_MergeUpdate_clicked",
G_CALLBACK (on_MergeUpdate_clicked));
glade_xml_signal_connect (xml, "on_MergeDuplicate_clicked",
G_CALLBACK (on_MergeDuplicate_clicked));
glade_xml_signal_connect (xml, "on_MergeNew_clicked",
G_CALLBACK (on_MergeNew_clicked));
glade_xml_signal_connect (xml, "on_finish",
G_CALLBACK (on_merge_finish));
g_signal_connect (dialog, "destroy",
G_CALLBACK(qof_book_merge_destroy_cb), NULL);
return dialog;
glade_xml_signal_connect (xml, "on_cancel",
G_CALLBACK (on_merge_cancel));
glade_xml_signal_connect (xml, "on_MergeUpdate_clicked",
G_CALLBACK (on_MergeUpdate_clicked));
glade_xml_signal_connect (xml, "on_MergeDuplicate_clicked",
G_CALLBACK (on_MergeDuplicate_clicked));
glade_xml_signal_connect (xml, "on_MergeNew_clicked",
G_CALLBACK (on_MergeNew_clicked));
g_signal_connect (dialog, "destroy",
G_CALLBACK(qof_book_merge_destroy_cb), NULL);
return dialog;
}
void collision_rule_loop(QofBookMergeData *mergeData, QofBookMergeRule *rule,
guint remainder)
void collision_rule_loop(QofBookMergeData *mergeData, QofBookMergeRule *rule,
guint remainder)
{
GSList *user_reports;
QofParam *one_param;
gchar *importstring, *targetstring;
GtkLabel *output;
gchar *buffer, *buffer2, *buffer3;
g_return_if_fail(rule != NULL);
buffer = "";
/* there is a rule awaiting resolution, don't print any more */
if(count > 0) { return; }
ENTER (" remainder=%d", remainder);
gnc_suspend_gui_refresh ();
user_reports = rule->mergeParam;
mergeData->currentRule = rule;
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output, buffer);
gtk_widget_show(GTK_WIDGET(output));
gnc_resume_gui_refresh ();
count = 1; /* user display text counts from 1, not zero */
importstring = targetstring = NULL;
gnc_suspend_gui_refresh ();
/* Translators: %i is the number of conflicts. This is a
ngettext(3) message. */
buffer2 = g_strdup_printf(ngettext("%i conflict needs to be resolved.",
"%i conflicts need to be resolved.",
remainder),
remainder);
/* Translators: %i is the number of values. This is a
ngettext(3) message. */
buffer3 = g_strdup_printf(ngettext("%i parameter value for this \"%s\" object.",
"%i parameter values for this \"%s\" object.",
g_slist_length(user_reports)),
g_slist_length(user_reports), rule->targetEnt->e_type);
buffer = g_strconcat("\n", buffer2, "\n", "\n", buffer3, "\n", NULL);
g_free(buffer2);
g_free(buffer3);
while(user_reports != NULL) {
one_param = user_reports->data;
/* FIXME: each g_strdup_printf as well as g_strconcat
will allocate a new string; all of these need to be
freed later. Currently this causes a lot of memory
leaks. */
buffer = g_strconcat(buffer, g_strdup_printf(_("%i: Parameter name: %s "),
count, one_param->param_name), NULL);
importstring = qof_book_merge_param_as_string(one_param, rule->importEnt);
buffer = g_strconcat(buffer,
g_strdup_printf(_("Import data : %s "), importstring), NULL);
targetstring = qof_book_merge_param_as_string(one_param, rule->targetEnt);
buffer = g_strconcat(buffer,
g_strdup_printf(_("Original data : %s\n"), targetstring), NULL);
user_reports = g_slist_next(user_reports);
count++;
}
gtk_label_set_text(output,buffer);
gtk_widget_show(GTK_WIDGET(output));
gnc_resume_gui_refresh ();
g_free(buffer);
g_free(importstring);
g_free(targetstring);
LEAVE (" ");
GSList *user_reports;
QofParam *one_param;
gchar *importstring, *targetstring;
GtkLabel *output;
gchar *buffer, *buffer2, *buffer3;
g_return_if_fail(rule != NULL);
buffer = "";
/* there is a rule awaiting resolution, don't print any more */
if (count > 0)
{
return;
}
ENTER (" remainder=%d", remainder);
gnc_suspend_gui_refresh ();
user_reports = rule->mergeParam;
mergeData->currentRule = rule;
output = GTK_LABEL(merge_get_widget("OutPut"));
gtk_label_set_text(output, buffer);
gtk_widget_show(GTK_WIDGET(output));
gnc_resume_gui_refresh ();
count = 1; /* user display text counts from 1, not zero */
importstring = targetstring = NULL;
gnc_suspend_gui_refresh ();
/* Translators: %i is the number of conflicts. This is a
ngettext(3) message. */
buffer2 = g_strdup_printf(ngettext("%i conflict needs to be resolved.",
"%i conflicts need to be resolved.",
remainder),
remainder);
/* Translators: %i is the number of values. This is a
ngettext(3) message. */
buffer3 = g_strdup_printf(ngettext("%i parameter value for this \"%s\" object.",
"%i parameter values for this \"%s\" object.",
g_slist_length(user_reports)),
g_slist_length(user_reports), rule->targetEnt->e_type);
buffer = g_strconcat("\n", buffer2, "\n", "\n", buffer3, "\n", NULL);
g_free(buffer2);
g_free(buffer3);
while (user_reports != NULL)
{
one_param = user_reports->data;
/* FIXME: each g_strdup_printf as well as g_strconcat
will allocate a new string; all of these need to be
freed later. Currently this causes a lot of memory
leaks. */
buffer = g_strconcat(buffer, g_strdup_printf(_("%i: Parameter name: %s "),
count, one_param->param_name), NULL);
importstring = qof_book_merge_param_as_string(one_param, rule->importEnt);
buffer = g_strconcat(buffer,
g_strdup_printf(_("Import data : %s "), importstring), NULL);
targetstring = qof_book_merge_param_as_string(one_param, rule->targetEnt);
buffer = g_strconcat(buffer,
g_strdup_printf(_("Original data : %s\n"), targetstring), NULL);
user_reports = g_slist_next(user_reports);
count++;
}
gtk_label_set_text(output, buffer);
gtk_widget_show(GTK_WIDGET(output));
gnc_resume_gui_refresh ();
g_free(buffer);
g_free(importstring);
g_free(targetstring);
LEAVE (" ");
}
void
gnc_ui_qsf_import_merge_druid (QofSession *original, QofSession *import)
{
if (qsf_import_merge_window) { return; }
qof_event_suspend ();
qsf_import_merge_window = gnc_create_import_druid();
g_return_if_fail(qsf_import_merge_window != NULL);
previous_session = original;
targetBook = qof_session_get_book(previous_session);
merge_session = import;
mergeBook = qof_session_get_book(merge_session);
gtk_widget_show(qsf_import_merge_window);
if (qsf_import_merge_window)
{
return;
}
qof_event_suspend ();
qsf_import_merge_window = gnc_create_import_druid();
g_return_if_fail(qsf_import_merge_window != NULL);
previous_session = original;
targetBook = qof_session_get_book(previous_session);
merge_session = import;
mergeBook = qof_session_get_book(merge_session);
gtk_widget_show(qsf_import_merge_window);
}

View File

@@ -33,7 +33,7 @@
\n
This druid builds a second ::QofBook in memory using ::QofSession and
populates the book with accounts created using the usual New Account Tree
code. The druid then uses ::qof_book_merge_init to begin the merge
code. The druid then uses ::qof_book_merge_init to begin the merge
of the new book (created with QofSession) with the existing QofBook
(loaded by the user), with user intervention and collision handling.
@@ -45,28 +45,28 @@ of the new book (created with QofSession) with the existing QofBook
be ::MERGE_NEW - parameter values must be checked.
- If a GUID match exists, set QofBookMergeRule::mergeAbsolute to \a TRUE.
-# If ALL parameters in the import object match the target object with the same \a GUID,
-# If ALL parameters in the import object match the target object with the same \a GUID,
set ::QofBookMergeResult to \a MERGE_ABSOLUTE.
-# If any parameters differ, set ::MERGE_UPDATE.
- If the import object \a GUID does not match an existing object,
mergeAbsolute is unchanged from the default \a FALSE
The parameter values of the object are compared to other objects of the same
type in the target book.
-# If the same data exists in the target book with a different GUID, the object
-# If the same data exists in the target book with a different GUID, the object
is tagged as DUPLICATE.
-# If the data has changed, the object is tagged as REPORT.
-# If the data has changed, the object is tagged as REPORT.
-# If the data does not match, the object is tagged as NEW
More information is at http://code.neil.williamsleesmill.me.uk/
Each foreach function uses g_return_if_fail checks to protect the target book. If
any essential data is missing, the loop returns without changing the target book.
Note that this will not set or return an error value. However, g_return is only
used for critical errors that arise from programming errors, not for invalid import data
Note that this will not set or return an error value. However, g_return is only
used for critical errors that arise from programming errors, not for invalid import data
which should be cleaned up before creating the import QofBook.
Only ::qof_book_merge_init, ::qof_book_merge_update_result and ::qof_book_merge_commit return
any error values to the calling process.
Only ::qof_book_merge_init, ::qof_book_merge_update_result and ::qof_book_merge_commit return
any error values to the calling process.
@{ */
/** @file druid-merge.h

File diff suppressed because it is too large Load Diff

View File

@@ -30,7 +30,7 @@
/********************************************************************\
* gnc_stock_split_dialog *
* opens up a window to record a stock split *
* *
* *
* Args: parent - the parent ofthis window *
* initial - the initial account to use *
* Return: nothing *

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-account-tree.c --
/*
* gnc-plugin-account-tree.c --
*
* Copyright (C) 2003 Jan Arne Petersen
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
@@ -53,10 +53,13 @@ static void gnc_plugin_account_tree_cmd_new_account_tree (GtkAction *action, Gnc
/** An array of all of the actions provided by the account tree
* plugin. */
static GtkActionEntry gnc_plugin_actions [] = {
{ "ViewAccountTreeAction", NULL, N_("New Accounts _Page"), NULL,
N_("Open a new Account Tree page"),
G_CALLBACK (gnc_plugin_account_tree_cmd_new_account_tree) },
static GtkActionEntry gnc_plugin_actions [] =
{
{
"ViewAccountTreeAction", NULL, N_("New Accounts _Page"), NULL,
N_("Open a new Account Tree page"),
G_CALLBACK (gnc_plugin_account_tree_cmd_new_account_tree)
},
};
/** The number of actions provided by this plugin. */
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
@@ -65,7 +68,7 @@ static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
/** The instance private data structure for an account tree plugin. */
typedef struct GncPluginAccountTreePrivate
{
gpointer dummy;
gpointer dummy;
} GncPluginAccountTreePrivate;
#define GNC_PLUGIN_ACCOUNT_TREE_GET_PRIVATE(o) \
@@ -79,27 +82,29 @@ static GObjectClass *parent_class = NULL;
GType
gnc_plugin_account_tree_get_type (void)
{
static GType gnc_plugin_account_tree_type = 0;
static GType gnc_plugin_account_tree_type = 0;
if (gnc_plugin_account_tree_type == 0) {
static const GTypeInfo our_info = {
sizeof (GncPluginAccountTreeClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnc_plugin_account_tree_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GncPluginAccountTree),
0, /* n_preallocs */
(GInstanceInitFunc) gnc_plugin_account_tree_init
};
gnc_plugin_account_tree_type = g_type_register_static (GNC_TYPE_PLUGIN,
"GncPluginAccountTree",
&our_info, 0);
}
if (gnc_plugin_account_tree_type == 0)
{
static const GTypeInfo our_info =
{
sizeof (GncPluginAccountTreeClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnc_plugin_account_tree_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GncPluginAccountTree),
0, /* n_preallocs */
(GInstanceInitFunc) gnc_plugin_account_tree_init
};
return gnc_plugin_account_tree_type;
gnc_plugin_account_tree_type = g_type_register_static (GNC_TYPE_PLUGIN,
"GncPluginAccountTree",
&our_info, 0);
}
return gnc_plugin_account_tree_type;
}
@@ -107,16 +112,16 @@ gnc_plugin_account_tree_get_type (void)
GncPlugin *
gnc_plugin_account_tree_new (void)
{
GncPluginAccountTree *plugin;
GncPluginAccountTree *plugin;
/* Reference the account tree page plugin to ensure it exists
* in the gtk type system. */
GNC_TYPE_PLUGIN_PAGE_ACCOUNT_TREE;
/* Reference the account tree page plugin to ensure it exists
* in the gtk type system. */
GNC_TYPE_PLUGIN_PAGE_ACCOUNT_TREE;
plugin = g_object_new (GNC_TYPE_PLUGIN_ACCOUNT_TREE,
NULL);
plugin = g_object_new (GNC_TYPE_PLUGIN_ACCOUNT_TREE,
NULL);
return GNC_PLUGIN (plugin);
return GNC_PLUGIN (plugin);
}
@@ -130,23 +135,23 @@ gnc_plugin_account_tree_new (void)
static void
gnc_plugin_account_tree_class_init (GncPluginAccountTreeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_plugin_account_tree_finalize;
object_class->finalize = gnc_plugin_account_tree_finalize;
/* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_ACCOUNT_TREE_NAME;
/* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_ACCOUNT_TREE_NAME;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
g_type_class_add_private(klass, sizeof(GncPluginAccountTreePrivate));
g_type_class_add_private(klass, sizeof(GncPluginAccountTreePrivate));
}
@@ -172,15 +177,15 @@ gnc_plugin_account_tree_init (GncPluginAccountTree *plugin)
static void
gnc_plugin_account_tree_finalize (GObject *object)
{
GncPluginAccountTree *plugin;
GncPluginAccountTreePrivate *priv;
GncPluginAccountTree *plugin;
GncPluginAccountTreePrivate *priv;
g_return_if_fail (GNC_IS_PLUGIN_ACCOUNT_TREE (object));
g_return_if_fail (GNC_IS_PLUGIN_ACCOUNT_TREE (object));
plugin = GNC_PLUGIN_ACCOUNT_TREE (object);
priv = GNC_PLUGIN_ACCOUNT_TREE_GET_PRIVATE (object);
plugin = GNC_PLUGIN_ACCOUNT_TREE (object);
priv = GNC_PLUGIN_ACCOUNT_TREE_GET_PRIVATE (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/************************************************************
@@ -189,14 +194,14 @@ gnc_plugin_account_tree_finalize (GObject *object)
static void
gnc_plugin_account_tree_cmd_new_account_tree (GtkAction *action,
GncMainWindowActionData *data)
GncMainWindowActionData *data)
{
GncPluginPage *page;
GncPluginPage *page;
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
page = gnc_plugin_page_account_tree_new ();
gnc_main_window_open_page (data->window, page);
page = gnc_plugin_page_account_tree_new ();
gnc_main_window_open_page (data->window, page);
}
/** @} */

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-account-tree.h --
/*
* gnc-plugin-account-tree.h --
*
* Copyright (C) 2003 Jan Arne Petersen
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
@@ -53,15 +53,17 @@ G_BEGIN_DECLS
/* typedefs & structures */
/** The instance data structure for an account tree menu plugin. */
typedef struct {
/** The parent object for this widget */
GncPlugin gnc_plugin;
typedef struct
{
/** The parent object for this widget */
GncPlugin gnc_plugin;
} GncPluginAccountTree;
/** The class data structure for an account tree menu plugin. */
typedef struct {
/** The parent class for this widget. */
GncPluginClass gnc_plugin;
typedef struct
{
/** The parent class for this widget. */
GncPluginClass gnc_plugin;
} GncPluginAccountTreeClass;

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-basic-commands.c --
/*
* gnc-plugin-basic-commands.c --
*
* Copyright (C) 2005 David Hampton <hampton@employees.org>
*
@@ -94,89 +94,126 @@ static void gnc_main_window_cmd_help_totd (GtkAction *action, GncMainWindowActio
/** An array of all of the actions provided by the basic commands
* plugin. */
static GtkActionEntry gnc_plugin_actions [] = {
static GtkActionEntry gnc_plugin_actions [] =
{
/* File menu */
/* File menu */
{ "FileNewAction", GTK_STOCK_NEW, N_("New _File"), NULL,
N_("Create a new file"),
G_CALLBACK (gnc_main_window_cmd_file_new) },
{ "FileOpenAction", GTK_STOCK_OPEN, N_("_Open..."), NULL,
N_("Open an existing GnuCash file"),
G_CALLBACK (gnc_main_window_cmd_file_open) },
{ "FileSaveAction", GTK_STOCK_SAVE, N_("_Save"), "<control>s",
N_("Save the current file"),
G_CALLBACK (gnc_main_window_cmd_file_save) },
{ "FileSaveAsAction", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<shift><control>s",
NULL,
G_CALLBACK (gnc_main_window_cmd_file_save_as) },
{
"FileNewAction", GTK_STOCK_NEW, N_("New _File"), NULL,
N_("Create a new file"),
G_CALLBACK (gnc_main_window_cmd_file_new)
},
{
"FileOpenAction", GTK_STOCK_OPEN, N_("_Open..."), NULL,
N_("Open an existing GnuCash file"),
G_CALLBACK (gnc_main_window_cmd_file_open)
},
{
"FileSaveAction", GTK_STOCK_SAVE, N_("_Save"), "<control>s",
N_("Save the current file"),
G_CALLBACK (gnc_main_window_cmd_file_save)
},
{
"FileSaveAsAction", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<shift><control>s",
NULL,
G_CALLBACK (gnc_main_window_cmd_file_save_as)
},
#ifdef QSF_IMPORT_WORKS
{ "FileImportQSFAction", GTK_STOCK_CONVERT,
N_("_QSF Import"), NULL,
N_("Import a QSF object file"),
G_CALLBACK (gnc_main_window_cmd_file_qsf_import) },
{
"FileImportQSFAction", GTK_STOCK_CONVERT,
N_("_QSF Import"), NULL,
N_("Import a QSF object file"),
G_CALLBACK (gnc_main_window_cmd_file_qsf_import)
},
#endif // QSF_IMPORT_WORKS
{ "FileExportAccountsAction", GTK_STOCK_CONVERT,
N_("Export _Accounts"), NULL,
N_("Export the account hierarchy to a new GnuCash datafile"),
G_CALLBACK (gnc_main_window_cmd_file_export_accounts) },
{ "FileExportChartAction", GTK_STOCK_CONVERT,
N_("Export _Chart of Accounts to QSF"), NULL,
N_("Export the chart of accounts for a date with balances as QSF"),
G_CALLBACK (gnc_main_window_cmd_file_chart_export) },
{
"FileExportAccountsAction", GTK_STOCK_CONVERT,
N_("Export _Accounts"), NULL,
N_("Export the account hierarchy to a new GnuCash datafile"),
G_CALLBACK (gnc_main_window_cmd_file_export_accounts)
},
{
"FileExportChartAction", GTK_STOCK_CONVERT,
N_("Export _Chart of Accounts to QSF"), NULL,
N_("Export the chart of accounts for a date with balances as QSF"),
G_CALLBACK (gnc_main_window_cmd_file_chart_export)
},
/* Edit menu */
/* Edit menu */
{ "EditFindTransactionsAction", GTK_STOCK_FIND, N_("_Find..."), "<control>f",
N_("Find transactions with a search"),
G_CALLBACK (gnc_main_window_cmd_tools_find_transactions) },
{ "EditTaxOptionsAction", NULL,
N_("Ta_x Report Options"), NULL,
/* Translators: currently implemented are *
* US: income tax and *
* DE: VAT *
* So adjust this string */
N_("Setup relevant accounts for tax reports, e.g. US income tax"),
G_CALLBACK (gnc_main_window_cmd_edit_tax_options) },
{
"EditFindTransactionsAction", GTK_STOCK_FIND, N_("_Find..."), "<control>f",
N_("Find transactions with a search"),
G_CALLBACK (gnc_main_window_cmd_tools_find_transactions)
},
{
"EditTaxOptionsAction", NULL,
N_("Ta_x Report Options"), NULL,
/* Translators: currently implemented are *
* US: income tax and *
* DE: VAT *
* So adjust this string */
N_("Setup relevant accounts for tax reports, e.g. US income tax"),
G_CALLBACK (gnc_main_window_cmd_edit_tax_options)
},
/* Actions menu */
/* Actions menu */
{ "ActionsScheduledTransactionsAction", NULL, N_("_Scheduled Transactions"), NULL, NULL, NULL },
{ "ActionsScheduledTransactionEditorAction", NULL, N_("_Scheduled Transaction Editor"), NULL,
N_("The list of Scheduled Transactions"),
G_CALLBACK (gnc_main_window_cmd_actions_scheduled_transaction_editor) },
{ "ActionsSinceLastRunAction", NULL, N_("Since _Last Run..."), NULL,
N_("Create Scheduled Transactions since the last time run"),
G_CALLBACK (gnc_main_window_cmd_actions_since_last_run) },
{ "ActionsMortgageLoanAction", NULL, N_("_Mortgage & Loan Repayment..."), NULL,
N_("Setup scheduled transactions for repayment of a loan"),
G_CALLBACK (gnc_main_window_cmd_actions_mortgage_loan) },
{ "ActionsScheduledTransactionsAction", NULL, N_("_Scheduled Transactions"), NULL, NULL, NULL },
{
"ActionsScheduledTransactionEditorAction", NULL, N_("_Scheduled Transaction Editor"), NULL,
N_("The list of Scheduled Transactions"),
G_CALLBACK (gnc_main_window_cmd_actions_scheduled_transaction_editor)
},
{
"ActionsSinceLastRunAction", NULL, N_("Since _Last Run..."), NULL,
N_("Create Scheduled Transactions since the last time run"),
G_CALLBACK (gnc_main_window_cmd_actions_since_last_run)
},
{
"ActionsMortgageLoanAction", NULL, N_("_Mortgage & Loan Repayment..."), NULL,
N_("Setup scheduled transactions for repayment of a loan"),
G_CALLBACK (gnc_main_window_cmd_actions_mortgage_loan)
},
#ifdef CLOSE_BOOKS_ACTUALLY_WORKS
{ "ActionsCloseBooksAction", NULL, N_("Close _Books"), NULL,
N_("Archive old data using accounting periods"),
G_CALLBACK (gnc_main_window_cmd_actions_close_books) },
{
"ActionsCloseBooksAction", NULL, N_("Close _Books"), NULL,
N_("Archive old data using accounting periods"),
G_CALLBACK (gnc_main_window_cmd_actions_close_books)
},
#endif // CLOSE_BOOKS_ACTUALLY_WORKS
/* Tools menu */
/* Tools menu */
{ "ToolsPriceEditorAction", NULL, N_("_Price Editor"), NULL,
N_("View and edit the prices for stocks and mutual funds"),
G_CALLBACK (gnc_main_window_cmd_tools_price_editor) },
{ "ToolsCommodityEditorAction", NULL, N_("_Security Editor"), NULL,
N_("View and edit the commodities for stocks and mutual funds"),
G_CALLBACK (gnc_main_window_cmd_tools_commodity_editor) },
{ "ToolsFinancialCalculatorAction", NULL, N_("_Financial Calculator"), NULL,
N_("Use the financial calculator"),
G_CALLBACK (gnc_main_window_cmd_tools_financial_calculator) },
{ "ToolsBookCloseAction", NULL, N_("_Close Book"), NULL,
N_("Close the Book at the end of the Period"),
G_CALLBACK (gnc_main_window_cmd_tools_close_book) },
{
"ToolsPriceEditorAction", NULL, N_("_Price Editor"), NULL,
N_("View and edit the prices for stocks and mutual funds"),
G_CALLBACK (gnc_main_window_cmd_tools_price_editor)
},
{
"ToolsCommodityEditorAction", NULL, N_("_Security Editor"), NULL,
N_("View and edit the commodities for stocks and mutual funds"),
G_CALLBACK (gnc_main_window_cmd_tools_commodity_editor)
},
{
"ToolsFinancialCalculatorAction", NULL, N_("_Financial Calculator"), NULL,
N_("Use the financial calculator"),
G_CALLBACK (gnc_main_window_cmd_tools_financial_calculator)
},
{
"ToolsBookCloseAction", NULL, N_("_Close Book"), NULL,
N_("Close the Book at the end of the Period"),
G_CALLBACK (gnc_main_window_cmd_tools_close_book)
},
/* Help menu */
/* Help menu */
{ "HelpTipsOfTheDayAction", NULL, N_("_Tips Of The Day"), NULL,
N_("View the Tips of the Day"),
G_CALLBACK (gnc_main_window_cmd_help_totd) },
{
"HelpTipsOfTheDayAction", NULL, N_("_Tips Of The Day"), NULL,
N_("View the Tips of the Day"),
G_CALLBACK (gnc_main_window_cmd_help_totd)
},
};
/** The number of actions provided by this plugin. */
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
@@ -185,9 +222,10 @@ static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
/** These are the "important" actions provided by the basic commands
* plugin. Their labels will appear when the toolbar is set to
* "Icons and important text" (e.g. GTK_TOOLBAR_BOTH_HORIZ) mode. */
static const gchar *gnc_plugin_important_actions[] = {
"FileSaveAction",
NULL,
static const gchar *gnc_plugin_important_actions[] =
{
"FileSaveAction",
NULL,
};
@@ -195,7 +233,7 @@ static const gchar *gnc_plugin_important_actions[] = {
* plugin. */
typedef struct GncPluginBasicCommandsPrivate
{
gpointer dummy;
gpointer dummy;
} GncPluginBasicCommandsPrivate;
#define GNC_PLUGIN_BASIC_COMMANDS_GET_PRIVATE(o) \
@@ -209,27 +247,29 @@ static GObjectClass *parent_class = NULL;
GType
gnc_plugin_basic_commands_get_type (void)
{
static GType gnc_plugin_basic_commands_type = 0;
static GType gnc_plugin_basic_commands_type = 0;
if (gnc_plugin_basic_commands_type == 0) {
static const GTypeInfo our_info = {
sizeof (GncPluginBasicCommandsClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnc_plugin_basic_commands_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GncPluginBasicCommands),
0, /* n_preallocs */
(GInstanceInitFunc) gnc_plugin_basic_commands_init
};
gnc_plugin_basic_commands_type = g_type_register_static (GNC_TYPE_PLUGIN,
"GncPluginBasicCommands",
&our_info, 0);
}
if (gnc_plugin_basic_commands_type == 0)
{
static const GTypeInfo our_info =
{
sizeof (GncPluginBasicCommandsClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnc_plugin_basic_commands_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GncPluginBasicCommands),
0, /* n_preallocs */
(GInstanceInitFunc) gnc_plugin_basic_commands_init
};
return gnc_plugin_basic_commands_type;
gnc_plugin_basic_commands_type = g_type_register_static (GNC_TYPE_PLUGIN,
"GncPluginBasicCommands",
&our_info, 0);
}
return gnc_plugin_basic_commands_type;
}
@@ -237,15 +277,15 @@ gnc_plugin_basic_commands_get_type (void)
GncPlugin *
gnc_plugin_basic_commands_new (void)
{
GncPluginBasicCommands *plugin;
GncPluginBasicCommands *plugin;
/* We just need to mention it, so the GType is registered and will be
* reflected during plugin-page restore. */
GNC_TYPE_PLUGIN_PAGE_SX_LIST;
/* We just need to mention it, so the GType is registered and will be
* reflected during plugin-page restore. */
GNC_TYPE_PLUGIN_PAGE_SX_LIST;
plugin = g_object_new (GNC_TYPE_PLUGIN_BASIC_COMMANDS, NULL);
plugin = g_object_new (GNC_TYPE_PLUGIN_BASIC_COMMANDS, NULL);
return GNC_PLUGIN (plugin);
return GNC_PLUGIN (plugin);
}
/** Initialize the basic commands menu for a window. This function is
@@ -264,8 +304,8 @@ gnc_plugin_basic_commands_new (void)
*/
static void
gnc_plugin_basic_commands_add_to_window (GncPlugin *plugin,
GncMainWindow *window,
GQuark type)
GncMainWindow *window,
GQuark type)
{
}
@@ -279,27 +319,27 @@ gnc_plugin_basic_commands_add_to_window (GncPlugin *plugin,
static void
gnc_plugin_basic_commands_class_init (GncPluginBasicCommandsClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_plugin_basic_commands_finalize;
object_class->finalize = gnc_plugin_basic_commands_finalize;
/* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_BASIC_COMMANDS_NAME;
/* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_BASIC_COMMANDS_NAME;
/* function overrides */
plugin_class->add_to_window = gnc_plugin_basic_commands_add_to_window;
/* function overrides */
plugin_class->add_to_window = gnc_plugin_basic_commands_add_to_window;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->important_actions = gnc_plugin_important_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->important_actions = gnc_plugin_important_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
g_type_class_add_private(klass, sizeof(GncPluginBasicCommandsPrivate));
g_type_class_add_private(klass, sizeof(GncPluginBasicCommandsPrivate));
}
@@ -325,15 +365,15 @@ gnc_plugin_basic_commands_init (GncPluginBasicCommands *plugin)
static void
gnc_plugin_basic_commands_finalize (GObject *object)
{
GncPluginBasicCommands *plugin;
GncPluginBasicCommandsPrivate *priv;
GncPluginBasicCommands *plugin;
GncPluginBasicCommandsPrivate *priv;
g_return_if_fail (GNC_IS_PLUGIN_BASIC_COMMANDS (object));
g_return_if_fail (GNC_IS_PLUGIN_BASIC_COMMANDS (object));
plugin = GNC_PLUGIN_BASIC_COMMANDS (object);
priv= GNC_PLUGIN_BASIC_COMMANDS_GET_PRIVATE (plugin);
plugin = GNC_PLUGIN_BASIC_COMMANDS (object);
priv = GNC_PLUGIN_BASIC_COMMANDS_GET_PRIVATE (plugin);
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/************************************************************
@@ -343,253 +383,254 @@ gnc_plugin_basic_commands_finalize (GObject *object)
static void
gnc_main_window_cmd_file_new (GtkAction *action, GncMainWindowActionData *data)
{
if (!gnc_main_window_all_finish_pending())
return;
if (!gnc_main_window_all_finish_pending())
return;
gnc_file_new ();
/* FIXME GNOME 2 Port (update the title etc.) */
gnc_file_new ();
/* FIXME GNOME 2 Port (update the title etc.) */
}
static void
gnc_main_window_cmd_file_open (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
if (!gnc_main_window_all_finish_pending())
return;
if (!gnc_main_window_all_finish_pending())
return;
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
#ifdef HAVE_DBI_DBI_H
gnc_ui_file_access_for_open();
gnc_ui_file_access_for_open();
#else
gnc_file_open ();
gnc_file_open ();
#endif
gnc_window_set_progressbar_window (NULL);
gnc_window_set_progressbar_window (NULL);
}
static void
gnc_main_window_cmd_file_save (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
if (!gnc_main_window_all_finish_pending())
return;
if (!gnc_main_window_all_finish_pending())
return;
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_file_save ();
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_file_save ();
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
}
static void
gnc_main_window_cmd_file_save_as (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
if (!gnc_main_window_all_finish_pending())
return;
if (!gnc_main_window_all_finish_pending())
return;
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
#ifdef HAVE_DBI_DBI_H
gnc_ui_file_access_for_save_as();
gnc_ui_file_access_for_save_as();
#else
gnc_file_save_as ();
gnc_file_save_as ();
#endif
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
}
static void
qsf_file_select_ok(GtkWidget *w, GtkFileSelection *fs )
{
QofSession *qsf_session, *first_session;
const gchar *filename, *message, *error_message;
QofBook *original;
QofBackendError err;
QofSession *qsf_session, *first_session;
const gchar *filename, *message, *error_message;
QofBook *original;
QofBackendError err;
ENTER (" ");
qof_event_suspend();
filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (fs));
gtk_widget_destroy((GtkWidget*) fs);
first_session = gnc_get_current_session();
original = qof_session_get_book(first_session);
qsf_session = qof_session_new();
qof_session_begin(qsf_session, filename, TRUE, FALSE);
qof_session_load(qsf_session, NULL);
err = qof_session_get_error(qsf_session);
if (err != ERR_BACKEND_NO_ERR)
{
error_message = qof_session_get_error_message(qsf_session);
if (!error_message)
error_message = "";
/* Translators: %d is the error number; %s is the error message as
text. */
message = g_strdup_printf(_("Error: Loading failed, error code %d - %s."), err, error_message);
PERR("%s", message);
qof_session_destroy(qsf_session);
qof_event_resume();
gnc_error_dialog(gnc_ui_get_toplevel(), "%s", message);
LEAVE (" ");
return;
}
ENTER (" ");
qof_event_suspend();
filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION (fs));
gtk_widget_destroy((GtkWidget*) fs);
first_session = gnc_get_current_session();
original = qof_session_get_book(first_session);
qsf_session = qof_session_new();
qof_session_begin(qsf_session, filename, TRUE, FALSE);
qof_session_load(qsf_session, NULL);
err = qof_session_get_error(qsf_session);
if (err != ERR_BACKEND_NO_ERR) {
error_message = qof_session_get_error_message(qsf_session);
if (!error_message)
error_message = "";
/* Translators: %d is the error number; %s is the error message as
text. */
message = g_strdup_printf(_("Error: Loading failed, error code %d - %s."), err, error_message);
PERR("%s", message);
qof_session_destroy(qsf_session);
qof_event_resume();
gnc_error_dialog(gnc_ui_get_toplevel(), "%s", message);
gnc_ui_qsf_import_merge_druid(first_session, qsf_session);
LEAVE (" ");
return;
}
qof_event_resume();
gnc_ui_qsf_import_merge_druid(first_session, qsf_session);
LEAVE (" ");
}
static void
gnc_main_window_cmd_file_qsf_import (GtkAction *action, GncMainWindowActionData *data)
{
GtkWidget *file_select;
GtkWidget *file_select;
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
gnc_window_set_progressbar_window(GNC_WINDOW(data->window));
file_select = gtk_file_selection_new(_("Select the QSF file to import into GnuCash"));
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (file_select)->ok_button),
"clicked", G_CALLBACK (qsf_file_select_ok), (gpointer) file_select);
g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (file_select)->cancel_button),
"clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (file_select));
gtk_widget_show (file_select);
gnc_window_set_progressbar_window(NULL);
gnc_window_set_progressbar_window(GNC_WINDOW(data->window));
file_select = gtk_file_selection_new(_("Select the QSF file to import into GnuCash"));
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (file_select)->ok_button),
"clicked", G_CALLBACK (qsf_file_select_ok), (gpointer) file_select);
g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (file_select)->cancel_button),
"clicked", G_CALLBACK (gtk_widget_destroy), G_OBJECT (file_select));
gtk_widget_show (file_select);
gnc_window_set_progressbar_window(NULL);
}
static void
gnc_main_window_cmd_file_export_accounts (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_file_export_file (NULL);
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
/* gnc_refresh_main_window_info (); */
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_file_export_file (NULL);
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
/* gnc_refresh_main_window_info (); */
}
static void
gnc_main_window_cmd_file_chart_export (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_main_window_chart_export();
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
/* gnc_refresh_main_window_info (); */
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
gnc_main_window_chart_export();
gnc_window_set_progressbar_window (NULL);
/* FIXME GNOME 2 Port (update the title etc.) */
/* gnc_refresh_main_window_info (); */
}
static void
gnc_main_window_cmd_edit_tax_options (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
gnc_tax_info_dialog (GTK_WIDGET (data->window));
gnc_tax_info_dialog (GTK_WIDGET (data->window));
}
static void
gnc_main_window_cmd_actions_scheduled_transaction_editor (GtkAction *action, GncMainWindowActionData *data)
{
GncPluginPage *page = gnc_plugin_page_sx_list_new();
gnc_main_window_open_page(NULL, page);
GncPluginPage *page = gnc_plugin_page_sx_list_new();
gnc_main_window_open_page(NULL, page);
}
static void
gnc_main_window_cmd_actions_since_last_run (GtkAction *action, GncMainWindowActionData *data)
{
GncMainWindow *window;
GncSxInstanceModel *sx_instances;
GncSxSummary summary;
GList *auto_created_txns = NULL;
const char *nothing_to_do_msg =
_( "There are no Scheduled Transactions to be entered at this time." );
g_return_if_fail (data != NULL);
GncMainWindow *window;
GncSxInstanceModel *sx_instances;
GncSxSummary summary;
GList *auto_created_txns = NULL;
const char *nothing_to_do_msg =
_( "There are no Scheduled Transactions to be entered at this time." );
window = data->window;
g_return_if_fail (data != NULL);
sx_instances = gnc_sx_get_current_instances();
gnc_sx_instance_model_summarize(sx_instances, &summary);
gnc_sx_instance_model_effect_change(sx_instances, TRUE, &auto_created_txns, NULL);
if (summary.need_dialog)
{
gnc_ui_sx_since_last_run_dialog(sx_instances, auto_created_txns);
auto_created_txns = NULL;
}
else
{
if (summary.num_auto_create_no_notify_instances == 0)
window = data->window;
sx_instances = gnc_sx_get_current_instances();
gnc_sx_instance_model_summarize(sx_instances, &summary);
gnc_sx_instance_model_effect_change(sx_instances, TRUE, &auto_created_txns, NULL);
if (summary.need_dialog)
{
gnc_info_dialog(GTK_WIDGET(&window->gtk_window), "%s", nothing_to_do_msg);
gnc_ui_sx_since_last_run_dialog(sx_instances, auto_created_txns);
auto_created_txns = NULL;
}
else
{
gnc_info_dialog(GTK_WIDGET(&window->gtk_window), ngettext
/* Translators: %d is the number of transactions. This is a
ngettext(3) message. */
("There are no Scheduled Transactions to be entered at this time. "
"(%d transaction automatically created)",
"There are no Scheduled Transactions to be entered at this time. "
"(%d transactions automatically created)",
summary.num_auto_create_no_notify_instances),
summary.num_auto_create_no_notify_instances);
if (summary.num_auto_create_no_notify_instances == 0)
{
gnc_info_dialog(GTK_WIDGET(&window->gtk_window), "%s", nothing_to_do_msg);
}
else
{
gnc_info_dialog(GTK_WIDGET(&window->gtk_window), ngettext
/* Translators: %d is the number of transactions. This is a
ngettext(3) message. */
("There are no Scheduled Transactions to be entered at this time. "
"(%d transaction automatically created)",
"There are no Scheduled Transactions to be entered at this time. "
"(%d transactions automatically created)",
summary.num_auto_create_no_notify_instances),
summary.num_auto_create_no_notify_instances);
}
}
}
g_list_free(auto_created_txns);
g_object_unref(G_OBJECT(sx_instances));
g_list_free(auto_created_txns);
g_object_unref(G_OBJECT(sx_instances));
}
static void
gnc_main_window_cmd_actions_mortgage_loan (GtkAction *action, GncMainWindowActionData *data)
{
gnc_ui_sx_loan_druid_create ();
gnc_ui_sx_loan_druid_create ();
}
static void
gnc_main_window_cmd_actions_close_books (GtkAction *action, GncMainWindowActionData *data)
{
gnc_acct_period_dialog();
gnc_acct_period_dialog();
}
static void
gnc_main_window_cmd_tools_price_editor (GtkAction *action, GncMainWindowActionData *data)
{
gnc_set_busy_cursor(NULL, TRUE);
gnc_prices_dialog (NULL);
gnc_unset_busy_cursor(NULL);
gnc_set_busy_cursor(NULL, TRUE);
gnc_prices_dialog (NULL);
gnc_unset_busy_cursor(NULL);
}
static void
gnc_main_window_cmd_tools_commodity_editor (GtkAction *action, GncMainWindowActionData *data)
{
gnc_set_busy_cursor(NULL, TRUE);
gnc_commodities_dialog (NULL);
gnc_unset_busy_cursor(NULL);
gnc_set_busy_cursor(NULL, TRUE);
gnc_commodities_dialog (NULL);
gnc_unset_busy_cursor(NULL);
}
static void
gnc_main_window_cmd_tools_financial_calculator (GtkAction *action, GncMainWindowActionData *data)
{
gnc_ui_fincalc_dialog_create();
gnc_ui_fincalc_dialog_create();
}
static void
gnc_main_window_cmd_tools_close_book (GtkAction *action, GncMainWindowActionData *data)
{
gnc_ui_close_book(gnc_get_current_book());
gnc_ui_close_book(gnc_get_current_book());
}
static void
gnc_main_window_cmd_tools_find_transactions (GtkAction *action, GncMainWindowActionData *data)
{
gnc_ui_find_transactions_dialog_create (NULL);
gnc_ui_find_transactions_dialog_create (NULL);
}
static void
gnc_main_window_cmd_help_totd (GtkAction *action, GncMainWindowActionData *data)
{
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
gnc_totd_dialog(GTK_WINDOW(data->window), FALSE);
gnc_totd_dialog(GTK_WINDOW(data->window), FALSE);
}
/** @} */

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-basic-commands.h --
/*
* gnc-plugin-basic-commands.h --
*
* Copyright (C) 2005 David Hampton <hampton@employees.org>
*
@@ -52,16 +52,18 @@ G_BEGIN_DECLS
/* typedefs & structures */
/** The instance data structure for an basic commands menu plugin. */
typedef struct {
/** The parent object for this widget */
GncPlugin gnc_plugin;
typedef struct
{
/** The parent object for this widget */
GncPlugin gnc_plugin;
} GncPluginBasicCommands;
/** The class data structure for a basic commands menu plugin. */
typedef struct {
/** The parent class for this widget. */
GncPluginClass gnc_plugin;
typedef struct
{
/** The parent class for this widget. */
GncPluginClass gnc_plugin;
} GncPluginBasicCommandsClass;

View File

@@ -47,22 +47,28 @@ static void gnc_plugin_budget_finalize (GObject *object);
/* Command Callbacks */
static void gnc_plugin_budget_cmd_new_budget (GtkAction *action,
GncMainWindowActionData *data);
GncMainWindowActionData *data);
static void gnc_plugin_budget_cmd_open_budget (GtkAction *action,
GncMainWindowActionData *data);
GncMainWindowActionData *data);
static GtkActionEntry gnc_plugin_actions [] = {
{ "NewBudgetAction", NULL, N_("New Budget"), NULL,
N_("Create a new Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_new_budget) },
static GtkActionEntry gnc_plugin_actions [] =
{
{
"NewBudgetAction", NULL, N_("New Budget"), NULL,
N_("Create a new Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_new_budget)
},
{ "OpenBudgetAction", NULL, N_("Open Budget"), NULL,
N_("Open an existing Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_open_budget) },
{
"OpenBudgetAction", NULL, N_("Open Budget"), NULL,
N_("Open an existing Budget"),
G_CALLBACK (gnc_plugin_budget_cmd_open_budget)
},
};
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
typedef struct GncPluginBudgetPrivate {
typedef struct GncPluginBudgetPrivate
{
gpointer dummy;
} GncPluginBudgetPrivate;
@@ -76,8 +82,10 @@ gnc_plugin_budget_get_type (void)
{
static GType gnc_plugin_budget_type = 0;
if (!gnc_plugin_budget_type) {
static const GTypeInfo our_info = {
if (!gnc_plugin_budget_type)
{
static const GTypeInfo our_info =
{
sizeof (GncPluginBudgetClass),
NULL, /* base_init */
NULL, /* base_finalize */
@@ -90,7 +98,7 @@ gnc_plugin_budget_get_type (void)
};
gnc_plugin_budget_type = g_type_register_static(
GNC_TYPE_PLUGIN, "GncPluginBudget", &our_info, 0);
GNC_TYPE_PLUGIN, "GncPluginBudget", &our_info, 0);
}
return gnc_plugin_budget_type;
@@ -159,7 +167,7 @@ gnc_plugin_budget_finalize(GObject *object)
/* Make a new budget; put it in a page; open the page. */
static void
gnc_plugin_budget_cmd_new_budget (GtkAction *action,
GncMainWindowActionData *data)
GncMainWindowActionData *data)
{
GncBudget *budget;
GncPluginPage *page;
@@ -185,16 +193,22 @@ gnc_plugin_budget_cmd_open_budget (GtkAction *action,
book = gnc_get_current_book();
col = qof_book_get_collection(book, GNC_ID_BUDGET);
count = qof_collection_count(col);
if (count > 0) {
if (count == 1) {
if (count > 0)
{
if (count == 1)
{
bgt = gnc_budget_get_default(book);
} else {
}
else
{
bgt = gnc_budget_gui_select_budget(book);
}
if (bgt) gnc_main_window_open_page(
data->window, gnc_plugin_page_budget_new(bgt));
} else { /* if no budgets exist yet, just open a new budget */
data->window, gnc_plugin_page_budget_new(bgt));
}
else /* if no budgets exist yet, just open a new budget */
{
gnc_plugin_budget_cmd_new_budget(action, data);
}
}
@@ -239,10 +253,12 @@ gnc_budget_gui_select_budget(QofBook *book)
bgt = NULL;
response = gtk_dialog_run(dlg);
switch (response) {
switch (response)
{
case GTK_RESPONSE_OK:
ok = gtk_tree_selection_get_selected(sel, &tm, &iter);
if (ok) {
if (ok)
{
bgt = gnc_tree_model_budget_get_budget(tm, &iter);
}
break;

View File

@@ -45,12 +45,14 @@ G_BEGIN_DECLS
#define GNC_BUDGET_GUI_FILE "budget.glade"
/* typedefs & structures */
typedef struct {
GncPlugin gnc_plugin;
typedef struct
{
GncPlugin gnc_plugin;
} GncPluginBudget;
typedef struct {
GncPluginClass gnc_plugin;
typedef struct
{
GncPluginClass gnc_plugin;
} GncPluginBudgetClass;
/* function prototypes */

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin_page-account-tree.h --
/*
* gnc-plugin_page-account-tree.h --
*
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2003 David Hampton <hampton@employees.org>
@@ -26,7 +26,7 @@
@{ */
/** @addtogroup GncPluginPageAccountTree An Account Tree Plugin
@{ */
/** @file gnc-plugin-page-account-tree.h
/** @file gnc-plugin-page-account-tree.h
@brief Functions providing a chart of account page.
@author Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
@author Copyright (C) 2003,2005,2006 David Hampton <hampton@employees.org>
@@ -53,16 +53,18 @@ G_BEGIN_DECLS
#define GNC_PLUGIN_PAGE_ACCOUNT_TREE_NAME "GncPluginPageAccountTree"
/* typedefs & structures */
typedef struct {
GncPluginPage gnc_plugin_page;
typedef struct
{
GncPluginPage gnc_plugin_page;
} GncPluginPageAccountTree;
typedef struct {
GncPluginPageClass gnc_plugin_page;
typedef struct
{
GncPluginPageClass gnc_plugin_page;
/* callbacks */
void (*account_selected) (GncPluginPage *page,
Account *account);
/* callbacks */
void (*account_selected) (GncPluginPage *page,
Account *account);
} GncPluginPageAccountTreeClass;

View File

@@ -118,53 +118,68 @@ static void gnc_plugin_page_budget_cmd_estimate_budget(
static GtkActionEntry gnc_plugin_page_budget_actions [] = {
static GtkActionEntry gnc_plugin_page_budget_actions [] =
{
/* Toplevel */
{ "FakeToplevel", "", NULL, NULL, NULL, NULL },
/* File menu */
{ "OpenAccountAction", GNC_STOCK_OPEN_ACCOUNT, N_("Open _Account"), NULL,
N_("Open the selected account"),
G_CALLBACK (gnc_plugin_page_budget_cmd_open_account) },
{ "OpenSubaccountsAction", GNC_STOCK_OPEN_ACCOUNT,
N_("Open _Subaccounts"), NULL,
N_("Open the selected account and all its subaccounts"),
G_CALLBACK (gnc_plugin_page_budget_cmd_open_subaccounts) },
{
"OpenAccountAction", GNC_STOCK_OPEN_ACCOUNT, N_("Open _Account"), NULL,
N_("Open the selected account"),
G_CALLBACK (gnc_plugin_page_budget_cmd_open_account)
},
{
"OpenSubaccountsAction", GNC_STOCK_OPEN_ACCOUNT,
N_("Open _Subaccounts"), NULL,
N_("Open the selected account and all its subaccounts"),
G_CALLBACK (gnc_plugin_page_budget_cmd_open_subaccounts)
},
/* Edit menu */
{ "DeleteBudgetAction", GNC_STOCK_DELETE_BUDGET, N_("_Delete Budget"),
NULL, N_("Delete this budget"),
G_CALLBACK (gnc_plugin_page_budget_cmd_delete_budget) },
{ "OptionsBudgetAction", GTK_STOCK_PROPERTIES, N_("Budget Options"),
NULL, N_("Edit this budget's options"),
G_CALLBACK (gnc_plugin_page_budget_cmd_view_options) },
{ "EstimateBudgetAction", GTK_STOCK_EXECUTE, N_("Estimate Budget"),
NULL,
N_("Estimate a budget value for the selected accounts from past transactions"),
G_CALLBACK (gnc_plugin_page_budget_cmd_estimate_budget) },
{
"DeleteBudgetAction", GNC_STOCK_DELETE_BUDGET, N_("_Delete Budget"),
NULL, N_("Delete this budget"),
G_CALLBACK (gnc_plugin_page_budget_cmd_delete_budget)
},
{
"OptionsBudgetAction", GTK_STOCK_PROPERTIES, N_("Budget Options"),
NULL, N_("Edit this budget's options"),
G_CALLBACK (gnc_plugin_page_budget_cmd_view_options)
},
{
"EstimateBudgetAction", GTK_STOCK_EXECUTE, N_("Estimate Budget"),
NULL,
N_("Estimate a budget value for the selected accounts from past transactions"),
G_CALLBACK (gnc_plugin_page_budget_cmd_estimate_budget)
},
/* View menu */
{ "ViewFilterByAction", NULL, N_("_Filter By..."), NULL, NULL,
G_CALLBACK (gnc_plugin_page_budget_cmd_view_filter_by) },
{
"ViewFilterByAction", NULL, N_("_Filter By..."), NULL, NULL,
G_CALLBACK (gnc_plugin_page_budget_cmd_view_filter_by)
},
};
static guint gnc_plugin_page_budget_n_actions =
G_N_ELEMENTS (gnc_plugin_page_budget_actions);
static const gchar *actions_requiring_account[] = {
"OpenAccountAction",
"OpenSubaccountsAction",
NULL
static const gchar *actions_requiring_account[] =
{
"OpenAccountAction",
"OpenSubaccountsAction",
NULL
};
/** Short labels for use on the toolbar buttons. */
static action_toolbar_labels toolbar_labels[] = {
{ "OpenAccountAction", N_("Open") },
{ "DeleteBudgetAction", N_("Delete") },
{ "OptionsBudgetAction", N_("Options") },
{ "EstimateBudgetAction", N_("Estimate") },
{ NULL, NULL },
static action_toolbar_labels toolbar_labels[] =
{
{ "OpenAccountAction", N_("Open") },
{ "DeleteBudgetAction", N_("Delete") },
{ "OptionsBudgetAction", N_("Options") },
{ "EstimateBudgetAction", N_("Estimate") },
{ NULL, NULL },
};
typedef struct GncPluginPageBudgetPrivate
@@ -200,8 +215,10 @@ gnc_plugin_page_budget_get_type (void)
{
static GType gnc_plugin_page_budget_type = 0;
if (gnc_plugin_page_budget_type == 0) {
static const GTypeInfo our_info = {
if (gnc_plugin_page_budget_type == 0)
{
static const GTypeInfo our_info =
{
sizeof (GncPluginPageBudgetClass),
NULL,
NULL,
@@ -271,18 +288,18 @@ gnc_plugin_page_budget_init (GncPluginPageBudget *plugin_page)
/* Init parent declared variables */
parent = GNC_PLUGIN_PAGE(plugin_page);
g_object_set(G_OBJECT(plugin_page),
"page-name", _("Budget"),
"page-uri", "default:",
"ui-description", "gnc-plugin-page-budget-ui.xml",
NULL);
"page-name", _("Budget"),
"page-uri", "default:",
"ui-description", "gnc-plugin-page-budget-ui.xml",
NULL);
/* change me when the system supports multiple books */
gnc_plugin_page_add_book(parent, gnc_get_current_book());
/* Create menu and toolbar information */
action_group =
gnc_plugin_page_create_action_group(parent,
"GncPluginPageBudgetActions");
gnc_plugin_page_create_action_group(parent,
"GncPluginPageBudgetActions");
gtk_action_group_add_actions (action_group,
gnc_plugin_page_budget_actions,
gnc_plugin_page_budget_n_actions,
@@ -295,7 +312,7 @@ gnc_plugin_page_budget_init (GncPluginPageBudget *plugin_page)
priv->fd.show_zero_total = TRUE;
priv->sigFigs = 1;
recurrenceSet(&priv->r, 1, PERIOD_MONTH, NULL, WEEKEND_ADJ_NONE);
recurrenceSet(&priv->r, 1, PERIOD_MONTH, NULL, WEEKEND_ADJ_NONE);
LEAVE("page %p, priv %p, action group %p",
plugin_page, priv, action_group);
@@ -336,14 +353,18 @@ gnc_plugin_page_budget_refresh_cb(GHashTable *changes, gpointer user_data)
page = GNC_PLUGIN_PAGE_BUDGET(user_data);
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
if (changes) {
if (changes)
{
ei = gnc_gui_get_entity_events(changes, &priv->key);
if (ei) {
if (ei->event_mask & QOF_EVENT_DESTROY) {
if (ei)
{
if (ei->event_mask & QOF_EVENT_DESTROY)
{
gnc_plugin_page_budget_close_cb(user_data);
return;
}
if (ei->event_mask & QOF_EVENT_MODIFY) {
if (ei->event_mask & QOF_EVENT_MODIFY)
{
DEBUG("refreshing budget view because budget was modified");
gnc_plugin_page_budget_view_refresh(page);
}
@@ -367,7 +388,8 @@ gnc_plugin_page_budget_create_widget (GncPluginPage *plugin_page)
ENTER("page %p", plugin_page);
page = GNC_PLUGIN_PAGE_BUDGET (plugin_page);
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
if (priv->widget != NULL) {
if (priv->widget != NULL)
{
LEAVE("widget = %p", priv->widget);
return priv->widget;
}
@@ -439,14 +461,16 @@ gnc_plugin_page_budget_destroy_widget (GncPluginPage *plugin_page)
ENTER("page %p", plugin_page);
page = GNC_PLUGIN_PAGE_BUDGET (plugin_page);
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(plugin_page);
if (priv->widget) {
if (priv->widget)
{
g_object_unref(G_OBJECT(priv->widget));
priv->widget = NULL;
}
gnc_gui_component_clear_watches (priv->component_id);
if (priv->component_id != NO_COMPONENT) {
if (priv->component_id != NO_COMPONENT)
{
gnc_unregister_gui_component(priv->component_id);
priv->component_id = NO_COMPONENT;
}
@@ -472,7 +496,7 @@ gnc_plugin_page_budget_save_page (GncPluginPage *plugin_page,
GncPluginPageBudget *budget_page;
GncPluginPageBudgetPrivate *priv;
char guid_str[GUID_ENCODING_LENGTH+1];
g_return_if_fail (GNC_IS_PLUGIN_PAGE_BUDGET(plugin_page));
g_return_if_fail (key_file != NULL);
g_return_if_fail (group_name != NULL);
@@ -482,12 +506,12 @@ gnc_plugin_page_budget_save_page (GncPluginPage *plugin_page,
budget_page = GNC_PLUGIN_PAGE_BUDGET(plugin_page);
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(budget_page);
guid_to_string_buff(gnc_budget_get_guid(priv->budget), guid_str);
g_key_file_set_string(key_file, group_name, BUDGET_GUID, guid_str);
//FIXME
gnc_tree_view_account_save(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
gnc_tree_view_account_save(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
&priv->fd, key_file, group_name);
LEAVE(" ");
}
@@ -504,7 +528,7 @@ gnc_plugin_page_budget_save_page (GncPluginPage *plugin_page,
*
* @param group_name The group name to use when restoring data. */
static GncPluginPage *
gnc_plugin_page_budget_recreate_page (GtkWidget *window, GKeyFile *key_file,
gnc_plugin_page_budget_recreate_page (GtkWidget *window, GKeyFile *key_file,
const gchar *group_name)
{
GncPluginPageBudget *budget_page;
@@ -520,21 +544,22 @@ gnc_plugin_page_budget_recreate_page (GtkWidget *window, GKeyFile *key_file,
g_return_val_if_fail(group_name, NULL);
ENTER("key_file %p, group_name %s", key_file, group_name);
guid_str = g_key_file_get_string(key_file, group_name, BUDGET_GUID,
guid_str = g_key_file_get_string(key_file, group_name, BUDGET_GUID,
&error);
if (error) {
if (error)
{
g_warning("error reading group %s key %s: %s",
group_name, BUDGET_GUID, error->message);
g_error_free(error);
error = NULL;
return NULL;
}
if (!string_to_guid(guid_str, &guid))
if (!string_to_guid(guid_str, &guid))
return NULL;
book = qof_session_get_book(gnc_get_current_session());
bgt = gnc_budget_lookup(&guid, book);
if (!bgt)
if (!bgt)
return NULL;
/* Create the new page. */
@@ -546,7 +571,7 @@ gnc_plugin_page_budget_recreate_page (GtkWidget *window, GKeyFile *key_file,
gnc_main_window_open_page(GNC_MAIN_WINDOW(window), page);
//FIXME
gnc_tree_view_account_restore(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
gnc_tree_view_account_restore(GNC_TREE_VIEW_ACCOUNT(priv->tree_view),
&priv->fd, key_file, group_name);
LEAVE(" ");
return page;
@@ -563,14 +588,14 @@ static gboolean
gppb_button_press_cb(GtkWidget *widget, GdkEventButton *event,
GncPluginPage *page)
{
gboolean result;
gboolean result;
g_return_val_if_fail(GNC_IS_PLUGIN_PAGE(page), FALSE);
g_return_val_if_fail(GNC_IS_PLUGIN_PAGE(page), FALSE);
ENTER("widget %p, event %p, page %p", widget, event, page);
result = gnc_main_window_button_press_cb(widget, event, page);
LEAVE(" ");
return result;
ENTER("widget %p, event %p, page %p", widget, event, page);
result = gnc_main_window_button_press_cb(widget, event, page);
LEAVE(" ");
return result;
}
static gboolean
@@ -582,7 +607,8 @@ gppb_key_press_cb(GtkWidget *treeview, GdkEventKey *event, gpointer userdata)
if (event->type != GDK_KEY_PRESS) return TRUE;
switch (event->keyval) {
switch (event->keyval)
{
case GDK_Tab:
case GDK_ISO_Left_Tab:
case GDK_KP_Tab:
@@ -592,10 +618,11 @@ gppb_key_press_cb(GtkWidget *treeview, GdkEventKey *event, gpointer userdata)
if (!path) return TRUE;
//finish_edit(col);
break;
default: return TRUE;
default:
return TRUE;
}
gnc_tree_view_keynav(GNC_TREE_VIEW(tv), &col, path, event);
if (path && gnc_tree_view_path_is_valid(GNC_TREE_VIEW(tv), path))
gtk_tree_view_set_cursor(tv, path, col, TRUE);
return TRUE;
@@ -611,7 +638,7 @@ gppb_double_click_cb(GtkTreeView *treeview, GtkTreePath *path,
g_return_if_fail(GNC_IS_PLUGIN_PAGE_BUDGET (page));
account = gnc_tree_view_account_get_account_from_path(
GNC_TREE_VIEW_ACCOUNT(treeview), path);
GNC_TREE_VIEW_ACCOUNT(treeview), path);
if (account == NULL)
return;
@@ -631,29 +658,32 @@ gppb_selection_changed_cb(GtkTreeSelection *selection,
g_return_if_fail(GNC_IS_PLUGIN_PAGE_BUDGET(page));
if (!selection) {
if (!selection)
{
sensitive = FALSE;
} else {
}
else
{
g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
view = gtk_tree_selection_get_tree_view (selection);
acct_list = gnc_tree_view_account_get_selected_accounts(
GNC_TREE_VIEW_ACCOUNT(view));
view = gtk_tree_selection_get_tree_view (selection);
acct_list = gnc_tree_view_account_get_selected_accounts(
GNC_TREE_VIEW_ACCOUNT(view));
/* Check here for placeholder accounts, etc. */
sensitive = (g_list_length(acct_list) > 0);
g_list_free(acct_list);
/* Check here for placeholder accounts, etc. */
sensitive = (g_list_length(acct_list) > 0);
g_list_free(acct_list);
}
action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(page));
gnc_plugin_update_actions (action_group, actions_requiring_account,
"sensitive", sensitive);
"sensitive", sensitive);
}
/* Command callbacks */
static void
gnc_plugin_page_budget_cmd_open_account (GtkAction *action,
GncPluginPageBudget *page)
GncPluginPageBudget *page)
{
GncPluginPageBudgetPrivate *priv;
GtkWidget *window;
@@ -664,20 +694,21 @@ gnc_plugin_page_budget_cmd_open_account (GtkAction *action,
g_return_if_fail (GNC_IS_PLUGIN_PAGE_BUDGET (page));
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
acct_list = gnc_tree_view_account_get_selected_accounts(
GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
window = GNC_PLUGIN_PAGE (page)->window;
for (tmp = acct_list; tmp; tmp = g_list_next(tmp)) {
for (tmp = acct_list; tmp; tmp = g_list_next(tmp))
{
account = tmp->data;
new_page = gnc_plugin_page_register_new (account, FALSE);
gnc_main_window_open_page (GNC_MAIN_WINDOW(window), new_page);
new_page = gnc_plugin_page_register_new (account, FALSE);
gnc_main_window_open_page (GNC_MAIN_WINDOW(window), new_page);
}
g_list_free(acct_list);
}
static void
gnc_plugin_page_budget_cmd_open_subaccounts (GtkAction *action,
GncPluginPageBudget *page)
GncPluginPageBudget *page)
{
GncPluginPageBudgetPrivate *priv;
GtkWidget *window;
@@ -688,28 +719,29 @@ gnc_plugin_page_budget_cmd_open_subaccounts (GtkAction *action,
g_return_if_fail (GNC_IS_PLUGIN_PAGE_BUDGET (page));
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
acct_list = gnc_tree_view_account_get_selected_accounts(
GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
GNC_TREE_VIEW_ACCOUNT(priv->tree_view));
window = GNC_PLUGIN_PAGE (page)->window;
for (tmp = acct_list; tmp; tmp = g_list_next(tmp)) {
for (tmp = acct_list; tmp; tmp = g_list_next(tmp))
{
account = tmp->data;
new_page = gnc_plugin_page_register_new (account, TRUE);
gnc_main_window_open_page (GNC_MAIN_WINDOW(window), new_page);
new_page = gnc_plugin_page_register_new (account, TRUE);
gnc_main_window_open_page (GNC_MAIN_WINDOW(window), new_page);
}
g_list_free(acct_list);
}
static void
gnc_plugin_page_budget_cmd_delete_budget (GtkAction *action,
GncPluginPageBudget *page)
GncPluginPageBudget *page)
{
GncPluginPageBudgetPrivate *priv;
GncBudget *budget;
GncPluginPageBudgetPrivate *priv;
GncBudget *budget;
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
budget = priv->budget;
g_return_if_fail (GNC_IS_BUDGET(budget));
gnc_budget_gui_delete_budget(budget);
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
budget = priv->budget;
g_return_if_fail (GNC_IS_BUDGET(budget));
gnc_budget_gui_delete_budget(budget);
}
@@ -719,7 +751,7 @@ gnc_plugin_page_budget_cmd_delete_budget (GtkAction *action,
static gboolean
gnc_plugin_page_budget_options_apply_cb (GncDialog * d,
gpointer user_data)
gpointer user_data)
{
GncPluginPageBudgetPrivate *priv = user_data;
gchar *name;
@@ -728,12 +760,13 @@ gnc_plugin_page_budget_options_apply_cb (GncDialog * d,
GncRecurrence *gr;
const Recurrence *r;
if(!priv)
if (!priv)
return TRUE;
ENTER(" ");
name = gnc_dialog_get_string(d, "BudgetName");
if (name) {
if (name)
{
gnc_budget_set_name(priv->budget, name);
DEBUG("%s", name);
g_free(name);
@@ -756,33 +789,33 @@ gnc_plugin_page_budget_options_apply_cb (GncDialog * d,
static gboolean
gnc_plugin_page_budget_options_help_cb (GncDialog *d,
gpointer user_data)
gpointer user_data)
{
GtkWidget *dialog;
GtkWidget *dialog;
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s",
_("Set the budget options using this dialog."));
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s",
_("Set the budget options using this dialog."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return TRUE;
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return TRUE;
}
static gboolean
gnc_plugin_page_budget_options_close_cb (GncDialog *d,
gpointer user_data)
gpointer user_data)
{
GncPluginPageBudgetPrivate *priv = user_data;
GncPluginPageBudgetPrivate *priv = user_data;
g_return_val_if_fail(priv, TRUE);
g_return_val_if_fail(priv, TRUE);
gtk_widget_destroy(GTK_WIDGET(d));
priv->d = NULL;
return TRUE;
gtk_widget_destroy(GTK_WIDGET(d));
priv->d = NULL;
return TRUE;
}
@@ -811,14 +844,15 @@ gnc_budget_gui_show_options(GncDialog *pw, GncBudget *budget,
static void
gnc_plugin_page_budget_cmd_view_options (GtkAction *action,
GncPluginPageBudget *page)
GncPluginPageBudget *page)
{
GncPluginPageBudgetPrivate *priv;
g_return_if_fail (GNC_IS_PLUGIN_PAGE_BUDGET (page));
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
if (!priv->d) {
if (!priv->d)
{
priv->d = gnc_dialog_new(GNC_BUDGET_GUI_FILE, "BudgetOptions");
gtk_window_set_title(GTK_WINDOW(priv->d), _("Budget Options"));
gnc_dialog_set_cb(priv->d,
@@ -841,10 +875,11 @@ gnc_budget_gui_delete_budget(GncBudget *budget)
g_return_if_fail(GNC_IS_BUDGET(budget));
name = gnc_budget_get_name (budget);
if (!name)
name = _("Unnamed Budget");
name = _("Unnamed Budget");
if (gnc_verify_dialog (NULL, FALSE, _("Delete %s?"), name)) {
if (gnc_verify_dialog (NULL, FALSE, _("Delete %s?"), name))
{
gnc_suspend_gui_refresh ();
gnc_budget_destroy(budget);
// Views should close themselves because the CM will notify them.
@@ -867,19 +902,21 @@ estimate_budget_helper(GtkTreeModel *model, GtkTreePath *path,
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
acct = gnc_tree_view_account_get_account_from_path(
GNC_TREE_VIEW_ACCOUNT(priv->tree_view), path);
GNC_TREE_VIEW_ACCOUNT(priv->tree_view), path);
num_periods = g_list_length(priv->period_col_list);
for (i = 0; i < num_periods; i++) {
for (i = 0; i < num_periods; i++)
{
num = recurrenceGetAccountPeriodValue(&priv->r, acct, i);
if (!gnc_numeric_check(num)) {
if (!gnc_numeric_check(num))
{
if (gnc_reverse_balance (acct))
num = gnc_numeric_neg (num);
num = gnc_numeric_convert(num, GNC_DENOM_AUTO,
GNC_HOW_DENOM_SIGFIGS(priv->sigFigs) | GNC_HOW_RND_ROUND);
num = gnc_numeric_convert(num, GNC_DENOM_AUTO,
GNC_HOW_DENOM_SIGFIGS(priv->sigFigs) | GNC_HOW_RND_ROUND);
gnc_budget_set_account_period_value(
priv->budget, acct, i, num);
}
@@ -888,7 +925,7 @@ estimate_budget_helper(GtkTreeModel *model, GtkTreePath *path,
static void
gnc_plugin_page_budget_cmd_estimate_budget(GtkAction *action,
GncPluginPageBudget *page)
GncPluginPageBudget *page)
{
GncPluginPageBudgetPrivate *priv;
GtkTreeSelection *sel;
@@ -903,12 +940,13 @@ gnc_plugin_page_budget_cmd_estimate_budget(GtkAction *action,
sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(priv->tree_view));
if (gtk_tree_selection_count_selected_rows(sel) <= 0) {
if (gtk_tree_selection_count_selected_rows(sel) <= 0)
{
dialog = gtk_message_dialog_new (
GTK_WINDOW(gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page))),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s",
_("You must select at least one account to estimate."));
GTK_WINDOW(gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page))),
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, "%s",
_("You must select at least one account to estimate."));
gtk_dialog_run (GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return;
@@ -917,26 +955,27 @@ gnc_plugin_page_budget_cmd_estimate_budget(GtkAction *action,
xml = gnc_glade_xml_new ("budget.glade", "BudgetEstimate");
dialog = glade_xml_get_widget (xml, "BudgetEstimate");
gtk_window_set_transient_for(
GTK_WINDOW(dialog),
GTK_WINDOW(dialog),
GTK_WINDOW(gnc_plugin_page_get_window(GNC_PLUGIN_PAGE(page))));
gde = glade_xml_get_widget(xml, "StartDate");
date = recurrenceGetDate(&priv->r);
gnc_date_edit_set_gdate(GNC_DATE_EDIT(gde), &date);
dtr = glade_xml_get_widget(xml, "DigitsToRound");
gtk_spin_button_set_value(GTK_SPIN_BUTTON(dtr),
gtk_spin_button_set_value(GTK_SPIN_BUTTON(dtr),
(gdouble)priv->sigFigs);
gtk_widget_show_all (dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));
switch (result) {
switch (result)
{
case GTK_RESPONSE_OK:
r = gnc_budget_get_recurrence(priv->budget);
gnc_date_edit_get_gdate(GNC_DATE_EDIT(gde), &date);
recurrenceSet(&priv->r, recurrenceGetMultiplier(r),
recurrenceSet(&priv->r, recurrenceGetMultiplier(r),
recurrenceGetPeriodType(r), &date,
recurrenceGetWeekendAdjust(r));
priv->sigFigs =
priv->sigFigs =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(dtr));
gtk_tree_selection_selected_foreach(sel, estimate_budget_helper, page);
@@ -958,19 +997,25 @@ budget_col_source(Account *account, GtkTreeViewColumn *col,
budget = GNC_BUDGET(g_object_get_data(G_OBJECT(col), "budget"));
period_num = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(col),
"period_num"));
"period_num"));
if (!gnc_budget_is_account_period_value_set(budget, account, period_num)) {
if (!gnc_budget_is_account_period_value_set(budget, account, period_num))
{
amtbuff[0] = '\0';
} else {
numeric = gnc_budget_get_account_period_value(budget, account,
period_num);
if (gnc_numeric_check(numeric)) {
strcpy(amtbuff, "error");
} else {
xaccSPrintAmount(amtbuff, numeric,
gnc_account_print_info(account, FALSE));
}
}
else
{
numeric = gnc_budget_get_account_period_value(budget, account,
period_num);
if (gnc_numeric_check(numeric))
{
strcpy(amtbuff, "error");
}
else
{
xaccSPrintAmount(amtbuff, numeric,
gnc_account_print_info(account, FALSE));
}
}
return g_strdup(amtbuff);
@@ -985,18 +1030,18 @@ budget_col_edited(Account *account, GtkTreeViewColumn *col,
gnc_numeric numeric = gnc_numeric_error(GNC_ERROR_ARG);
if (!xaccParseAmount (new_text, TRUE, &numeric, NULL) &&
!(new_text && *new_text == '\0'))
!(new_text && *new_text == '\0'))
return;
period_num = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(col),
"period_num"));
"period_num"));
budget = GNC_BUDGET(g_object_get_data(G_OBJECT(col), "budget"));
if (new_text && *new_text == '\0')
gnc_budget_unset_account_period_value(budget, account, period_num);
else
gnc_budget_set_account_period_value(budget, account, period_num,
gnc_budget_set_account_period_value(budget, account, period_num,
numeric);
}
@@ -1019,10 +1064,11 @@ gnc_plugin_page_budget_refresh_col_titles(GncPluginPageBudget *page)
col_list = priv->period_col_list;
num_periods_visible = g_list_length(col_list);
/* Show the dates in column titles */
/* Show the dates in column titles */
r = gnc_budget_get_recurrence(priv->budget);
date = r->start;
for (i = 0; i < num_periods_visible; i++) {
for (i = 0; i < num_periods_visible; i++)
{
col = GTK_TREE_VIEW_COLUMN(g_list_nth_data(col_list, i));
titlelen = qof_print_gdate(title, MAX_DATE_LENGTH, &date);
if (titlelen > 0)
@@ -1049,7 +1095,8 @@ gnc_plugin_page_budget_view_refresh (GncPluginPageBudget *page)
num_periods_visible = g_list_length(col_list);
/* Hide any unneeded extra columns */
while (num_periods_visible > num_periods) {
while (num_periods_visible > num_periods)
{
col = GTK_TREE_VIEW_COLUMN((g_list_last(col_list))->data);
gtk_tree_view_remove_column(GTK_TREE_VIEW(priv->tree_view), col);
col_list = g_list_delete_link(col_list, g_list_last(col_list));
@@ -1059,12 +1106,13 @@ gnc_plugin_page_budget_view_refresh (GncPluginPageBudget *page)
gnc_tree_view_configure_columns(GNC_TREE_VIEW(priv->tree_view));
/* Create any needed columns */
while (num_periods_visible < num_periods) {
while (num_periods_visible < num_periods)
{
col = gnc_tree_view_account_add_custom_column(
GNC_TREE_VIEW_ACCOUNT(priv->tree_view), "",
budget_col_source, budget_col_edited);
GNC_TREE_VIEW_ACCOUNT(priv->tree_view), "",
budget_col_source, budget_col_edited);
g_object_set_data(G_OBJECT(col), "budget", priv->budget);
g_object_set_data(G_OBJECT(col), "period_num",
g_object_set_data(G_OBJECT(col), "period_num",
GUINT_TO_POINTER(num_periods_visible));
col_list = g_list_append(col_list, col);
num_periods_visible = g_list_length(col_list);
@@ -1076,13 +1124,13 @@ gnc_plugin_page_budget_view_refresh (GncPluginPageBudget *page)
static void
gnc_plugin_page_budget_cmd_view_filter_by (GtkAction *action,
GncPluginPageBudget *page)
GncPluginPageBudget *page)
{
GncPluginPageBudgetPrivate *priv;
g_return_if_fail(GNC_IS_PLUGIN_PAGE_BUDGET(page));
ENTER("(action %p, page %p)", action, page);
priv = GNC_PLUGIN_PAGE_BUDGET_GET_PRIVATE(page);
account_filter_dialog_create(&priv->fd, GNC_PLUGIN_PAGE(page));

View File

@@ -48,11 +48,13 @@ G_BEGIN_DECLS
#define GNC_PLUGIN_PAGE_BUDGET_NAME "GncPluginPageBudget"
/* typedefs & structures */
typedef struct {
GncPluginPage gnc_plugin_page;
typedef struct
{
GncPluginPage gnc_plugin_page;
} GncPluginPageBudget;
typedef struct {
typedef struct
{
GncPluginPageClass gnc_plugin_page;
} GncPluginPageBudgetClass;

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-page-register.h --
/*
* gnc-plugin-page-register.h --
*
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2003 David Hampton <hampton@employees.org>
@@ -26,7 +26,7 @@
@{ */
/** @addtogroup RegisterPlugin Register Page
@{ */
/** @file gnc-plugin-page-register.h
/** @file gnc-plugin-page-register.h
@brief Functions providing a register page for the GnuCash UI
@author Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
@author Copyright (C) 2003 David Hampton <hampton@employees.org>
@@ -54,12 +54,14 @@ G_BEGIN_DECLS
#define GNC_PLUGIN_PAGE_REGISTER_NAME "GncPluginPageRegister"
/* typedefs & structures */
typedef struct {
GncPluginPage gnc_plugin_page;
typedef struct
{
GncPluginPage gnc_plugin_page;
} GncPluginPageRegister;
typedef struct {
GncPluginPageClass gnc_plugin_page;
typedef struct
{
GncPluginPageClass gnc_plugin_page;
} GncPluginPageRegisterClass;
/* function prototypes */
@@ -125,9 +127,9 @@ gnc_plugin_page_register_new_gl (void);
*/
void
gnc_plugin_page_register_set_options (GncPluginPage *plugin_page,
const char *lines_opt_page,
const char *lines_opt_name,
gint lines_default,
const char *lines_opt_page,
const char *lines_opt_name,
gint lines_default,
gboolean read_only);

View File

@@ -114,14 +114,21 @@ static void gnc_plugin_page_sx_list_cmd_edit(GtkAction *action, GncPluginPageSxL
static void gnc_plugin_page_sx_list_cmd_delete(GtkAction *action, GncPluginPageSxList *page);
/* Command callbacks */
static GtkActionEntry gnc_plugin_page_sx_list_actions [] = {
static GtkActionEntry gnc_plugin_page_sx_list_actions [] =
{
{ "SxListAction", NULL, N_("_Scheduled"), NULL, NULL, NULL },
{ "SxListNewAction", GNC_STOCK_NEW_ACCOUNT, N_("_New"), NULL,
N_("Create a new scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new) },
{ "SxListEditAction", GNC_STOCK_EDIT_ACCOUNT, N_("_Edit"), NULL,
N_("Edit the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit) },
{ "SxListDeleteAction", GNC_STOCK_DELETE_ACCOUNT, N_("_Delete"), NULL,
N_("Delete the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_delete) },
{
"SxListNewAction", GNC_STOCK_NEW_ACCOUNT, N_("_New"), NULL,
N_("Create a new scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_new)
},
{
"SxListEditAction", GNC_STOCK_EDIT_ACCOUNT, N_("_Edit"), NULL,
N_("Edit the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_edit)
},
{
"SxListDeleteAction", GNC_STOCK_DELETE_ACCOUNT, N_("_Delete"), NULL,
N_("Delete the selected scheduled transaction"), G_CALLBACK(gnc_plugin_page_sx_list_cmd_delete)
},
};
/** The number of actions provided by this plugin. */
static guint gnc_plugin_page_sx_list_n_actions = G_N_ELEMENTS (gnc_plugin_page_sx_list_actions);
@@ -131,8 +138,10 @@ gnc_plugin_page_sx_list_get_type (void)
{
static GType gnc_plugin_page_sx_list_type = 0;
if (gnc_plugin_page_sx_list_type == 0) {
static const GTypeInfo our_info = {
if (gnc_plugin_page_sx_list_type == 0)
{
static const GTypeInfo our_info =
{
sizeof (GncPluginPageSxListClass),
NULL,
NULL,
@@ -145,8 +154,8 @@ gnc_plugin_page_sx_list_get_type (void)
};
gnc_plugin_page_sx_list_type = g_type_register_static (GNC_TYPE_PLUGIN_PAGE,
GNC_PLUGIN_PAGE_SX_LIST_NAME,
&our_info, 0);
GNC_PLUGIN_PAGE_SX_LIST_NAME,
&our_info, 0);
}
return gnc_plugin_page_sx_list_type;
@@ -286,9 +295,9 @@ gppsl_selection_changed_cb(GtkTreeSelection *selection, gpointer user_data)
edit_action = gnc_plugin_page_get_action(page, "SxListEditAction");
delete_action = gnc_plugin_page_get_action(page, "SxListDeleteAction");
selection_state
= gtk_tree_selection_count_selected_rows(selection) == 0
? FALSE
: TRUE;
= gtk_tree_selection_count_selected_rows(selection) == 0
? FALSE
: TRUE;
gtk_action_set_sensitive(edit_action, selection_state);
gtk_action_set_sensitive(delete_action, selection_state);
}
@@ -364,9 +373,9 @@ gnc_plugin_page_sx_list_create_widget (GncPluginPage *plugin_page)
}
priv->gnc_component_id = gnc_register_gui_component("plugin-page-sx-list",
gnc_plugin_page_sx_list_refresh_cb,
gnc_plugin_page_sx_list_close_cb,
page);
gnc_plugin_page_sx_list_refresh_cb,
gnc_plugin_page_sx_list_close_cb,
page);
return priv->widget;
}
@@ -380,12 +389,14 @@ gnc_plugin_page_sx_list_destroy_widget (GncPluginPage *plugin_page)
page = GNC_PLUGIN_PAGE_SX_LIST (plugin_page);
priv = GNC_PLUGIN_PAGE_SX_LIST_GET_PRIVATE(page);
if (priv->widget) {
if (priv->widget)
{
g_object_unref(G_OBJECT(priv->widget));
priv->widget = NULL;
}
if (priv->gnc_component_id) {
if (priv->gnc_component_id)
{
gnc_unregister_gui_component(priv->gnc_component_id);
priv->gnc_component_id = 0;
}
@@ -459,7 +470,7 @@ gnc_plugin_page_sx_list_recreate_page (GtkWidget *window,
{
GError *err = NULL;
gint paned_position = g_key_file_get_integer(key_file, group_name,
"paned_position", &err);
"paned_position", &err);
if (err == NULL)
gtk_paned_set_position(GTK_PANED(priv->widget), paned_position);
else
@@ -551,7 +562,7 @@ _destroy_sx(gpointer data, gpointer user_data)
book = gnc_get_current_book();
sxes = gnc_book_get_schedxactions(book);
gnc_sxes_del_sx(sxes, sx);
gnc_sx_begin_edit(sx);
gnc_sx_begin_edit(sx);
xaccSchedXactionDestroy(sx);
}

View File

@@ -1,4 +1,4 @@
/*
/*
* gnc-plugin-page-sx-list.h
*
* Copyright (C) 2006 Josh Sled <jsled@asynchronous.org>

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-register.c --
/*
* gnc-plugin-register.c --
*
* Copyright (C) 2003 Jan Arne Petersen
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
@@ -44,16 +44,19 @@ static void gnc_plugin_register_cmd_general_ledger (GtkAction *action, GncMainWi
#define PLUGIN_UI_FILENAME "gnc-plugin-register-ui.xml"
#define GCONF_REGISTER_SECTION "general/register"
static GtkActionEntry gnc_plugin_actions [] = {
{ "ToolsGeneralLedgerAction", NULL, N_("_General Ledger"), NULL,
N_("Open a general ledger window"),
G_CALLBACK (gnc_plugin_register_cmd_general_ledger) },
static GtkActionEntry gnc_plugin_actions [] =
{
{
"ToolsGeneralLedgerAction", NULL, N_("_General Ledger"), NULL,
N_("Open a general ledger window"),
G_CALLBACK (gnc_plugin_register_cmd_general_ledger)
},
};
static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
typedef struct GncPluginRegisterPrivate
{
gpointer dummy;
gpointer dummy;
} GncPluginRegisterPrivate;
#define GNC_PLUGIN_REGISTER_GET_PRIVATE(o) \
@@ -82,13 +85,13 @@ static QofLogModule log_module = GNC_MOD_GUI;
*/
static void
gnc_plugin_register_gconf_changed (GConfClient *client,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data)
guint cnxn_id,
GConfEntry *entry,
gpointer user_data)
{
ENTER("");
gnc_gui_refresh_all ();
LEAVE("");
ENTER("");
gnc_gui_refresh_all ();
LEAVE("");
}
/************************************************************
@@ -98,67 +101,69 @@ gnc_plugin_register_gconf_changed (GConfClient *client,
GType
gnc_plugin_register_get_type (void)
{
static GType gnc_plugin_register_type = 0;
static GType gnc_plugin_register_type = 0;
if (gnc_plugin_register_type == 0) {
static const GTypeInfo our_info = {
sizeof (GncPluginRegisterClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnc_plugin_register_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GncPluginRegister),
0, /* n_preallocs */
(GInstanceInitFunc) gnc_plugin_register_init
};
gnc_plugin_register_type = g_type_register_static (GNC_TYPE_PLUGIN,
"GncPluginRegister",
&our_info, 0);
}
if (gnc_plugin_register_type == 0)
{
static const GTypeInfo our_info =
{
sizeof (GncPluginRegisterClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gnc_plugin_register_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GncPluginRegister),
0, /* n_preallocs */
(GInstanceInitFunc) gnc_plugin_register_init
};
return gnc_plugin_register_type;
gnc_plugin_register_type = g_type_register_static (GNC_TYPE_PLUGIN,
"GncPluginRegister",
&our_info, 0);
}
return gnc_plugin_register_type;
}
GncPlugin *
gnc_plugin_register_new (void)
{
GncPluginRegister *plugin;
GncPluginRegister *plugin;
/* Reference the register page plugin to ensure it exists in
* the gtk type system. */
GNC_TYPE_PLUGIN_PAGE_REGISTER;
/* Reference the register page plugin to ensure it exists in
* the gtk type system. */
GNC_TYPE_PLUGIN_PAGE_REGISTER;
plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER,
NULL);
plugin = g_object_new (GNC_TYPE_PLUGIN_REGISTER,
NULL);
return GNC_PLUGIN (plugin);
return GNC_PLUGIN (plugin);
}
static void
gnc_plugin_register_class_init (GncPluginRegisterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gnc_plugin_register_finalize;
object_class->finalize = gnc_plugin_register_finalize;
/* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
/* plugin info */
plugin_class->plugin_name = GNC_PLUGIN_REGISTER_NAME;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
/* widget addition/removal */
plugin_class->actions_name = PLUGIN_ACTIONS_NAME;
plugin_class->actions = gnc_plugin_actions;
plugin_class->n_actions = gnc_plugin_n_actions;
plugin_class->ui_filename = PLUGIN_UI_FILENAME;
plugin_class->gconf_section = GCONF_REGISTER_SECTION;
plugin_class->gconf_notifications = gnc_plugin_register_gconf_changed;
plugin_class->gconf_section = GCONF_REGISTER_SECTION;
plugin_class->gconf_notifications = gnc_plugin_register_gconf_changed;
g_type_class_add_private(klass, sizeof(GncPluginRegisterPrivate));
g_type_class_add_private(klass, sizeof(GncPluginRegisterPrivate));
}
static void
@@ -169,15 +174,15 @@ gnc_plugin_register_init (GncPluginRegister *plugin)
static void
gnc_plugin_register_finalize (GObject *object)
{
GncPluginRegister *plugin;
GncPluginRegisterPrivate *priv;
GncPluginRegister *plugin;
GncPluginRegisterPrivate *priv;
g_return_if_fail (GNC_IS_PLUGIN_REGISTER (object));
g_return_if_fail (GNC_IS_PLUGIN_REGISTER (object));
plugin = GNC_PLUGIN_REGISTER (object);
priv = GNC_PLUGIN_REGISTER_GET_PRIVATE(plugin);
plugin = GNC_PLUGIN_REGISTER (object);
priv = GNC_PLUGIN_REGISTER_GET_PRIVATE(plugin);
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/************************************************************
@@ -186,12 +191,12 @@ gnc_plugin_register_finalize (GObject *object)
static void
gnc_plugin_register_cmd_general_ledger (GtkAction *action,
GncMainWindowActionData *data)
GncMainWindowActionData *data)
{
GncPluginPage *page;
GncPluginPage *page;
g_return_if_fail (data != NULL);
g_return_if_fail (data != NULL);
page = gnc_plugin_page_register_new_gl ();
gnc_main_window_open_page (data->window, page);
page = gnc_plugin_page_register_new_gl ();
gnc_main_window_open_page (data->window, page);
}

View File

@@ -1,5 +1,5 @@
/*
* gnc-plugin-register.h --
/*
* gnc-plugin-register.h --
*
* Copyright (C) 2003 Jan Arne Petersen
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
@@ -40,12 +40,14 @@ G_BEGIN_DECLS
#define GNC_PLUGIN_REGISTER_NAME "gnc-plugin-register"
/* typedefs & structures */
typedef struct {
GncPlugin gnc_plugin;
typedef struct
{
GncPlugin gnc_plugin;
} GncPluginRegister;
typedef struct {
GncPluginClass gnc_plugin;
typedef struct
{
GncPluginClass gnc_plugin;
} GncPluginRegisterClass;
/* function prototypes */

File diff suppressed because it is too large Load Diff

View File

@@ -41,100 +41,103 @@
typedef struct _GNCSplitReg GNCSplitReg;
typedef struct _GNCSplitRegClass GNCSplitRegClass;
struct _GNCSplitReg {
/* The "parent" widget. */
GtkVBox vbox;
struct _GNCSplitReg
{
/* The "parent" widget. */
GtkVBox vbox;
/* The containing window. */
GtkWidget *window;
gint width;
gint height;
/* The containing window. */
GtkWidget *window;
gint width;
gint height;
GtkWidget *toolbar;
GtkWidget *summarybar;
GtkWidget *toolbar;
GtkWidget *summarybar;
GtkWidget *popup_menu;
GtkWidget *popup_menu;
GtkWidget *edit_menu;
GtkWidget *view_menu;
GtkWidget *style_submenu;
GtkWidget *sort_submenu;
GtkWidget *action_menu;
GtkWidget *edit_menu;
GtkWidget *view_menu;
GtkWidget *style_submenu;
GtkWidget *sort_submenu;
GtkWidget *action_menu;
GtkWidget * double_line_check;
GtkWidget * double_line_check;
GtkWidget *split_button;
GtkWidget *split_menu_check;
GtkWidget *split_popup_check;
GtkWidget *split_button;
GtkWidget *split_menu_check;
GtkWidget *split_popup_check;
/* Summary Bar Labels */
GtkWidget *balance_label;
GtkWidget *cleared_label;
GtkWidget *reconciled_label;
GtkWidget *future_label;
GtkWidget *projectedminimum_label;
GtkWidget *shares_label;
GtkWidget *value_label;
/* Summary Bar Labels */
GtkWidget *balance_label;
GtkWidget *cleared_label;
GtkWidget *reconciled_label;
GtkWidget *future_label;
GtkWidget *projectedminimum_label;
GtkWidget *shares_label;
GtkWidget *value_label;
/** The current ledger display. **/
GNCLedgerDisplay *ledger;
/** The actual sheet widget. **/
GnucashRegister *reg;
/** The current ledger display. **/
GNCLedgerDisplay *ledger;
/** The actual sheet widget. **/
GnucashRegister *reg;
gint numRows;
gint numRows;
guint sort_type;
guint sort_type;
gboolean read_only;
gboolean read_only;
};
struct _GNCSplitRegClass {
GtkVBoxClass parent_class;
struct _GNCSplitRegClass
{
GtkVBoxClass parent_class;
/* Signal defaults */
void (*enter_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*cancel_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*delete_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*reinit_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*dup_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*schedule_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*expand_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*blank_cb) ( GNCSplitReg *w, gpointer user_data );
void (*jump_cb) ( GNCSplitReg *w, gpointer user_data );
void (*cut_cb) ( GNCSplitReg *w, gpointer user_data );
void (*cut_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*copy_cb) ( GNCSplitReg *w, gpointer user_data );
void (*copy_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*paste_cb) ( GNCSplitReg *w, gpointer user_data );
void (*paste_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*void_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*unvoid_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*reverse_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*help_changed_cb) ( GNCSplitReg *w, gpointer user_data );
void (*include_date_cb) ( GNCSplitReg *w, time_t date, gpointer user_data );
/* Signal defaults */
void (*enter_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*cancel_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*delete_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*reinit_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*dup_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*schedule_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*expand_ent_cb) ( GNCSplitReg *w, gpointer user_data );
void (*blank_cb) ( GNCSplitReg *w, gpointer user_data );
void (*jump_cb) ( GNCSplitReg *w, gpointer user_data );
void (*cut_cb) ( GNCSplitReg *w, gpointer user_data );
void (*cut_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*copy_cb) ( GNCSplitReg *w, gpointer user_data );
void (*copy_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*paste_cb) ( GNCSplitReg *w, gpointer user_data );
void (*paste_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*void_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*unvoid_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*reverse_txn_cb) ( GNCSplitReg *w, gpointer user_data );
void (*help_changed_cb) ( GNCSplitReg *w, gpointer user_data );
void (*include_date_cb) ( GNCSplitReg *w, time_t date, gpointer user_data );
};
typedef enum {
ENTER,
CANCEL,
DELETE,
REINIT,
DUPLICATE,
SCHEDULE,
SPLIT,
BLANK,
JUMP,
CUT,
CUT_TXN,
COPY,
COPY_TXN,
PASTE,
PASTE_TXN,
SORT_ORDER_SUBMENU,
STYLE_SUBMENU,
typedef enum
{
ENTER,
CANCEL,
DELETE,
REINIT,
DUPLICATE,
SCHEDULE,
SPLIT,
BLANK,
JUMP,
CUT,
CUT_TXN,
COPY,
COPY_TXN,
PASTE,
PASTE_TXN,
SORT_ORDER_SUBMENU,
STYLE_SUBMENU,
} GNC_SPLIT_REG_ITEM;
/* Easy way to pass the sort-type
/* Easy way to pass the sort-type
* Note that this is STUPID -- we should be using parameter lists,
* but this provides a simple case statement internally. This should
* probably not actually be exposed in the external interface....
@@ -223,14 +226,14 @@ void gnc_split_reg_jump_to_split(GNCSplitReg *gsr, Split *split);
void gnc_split_reg_jump_to_split_amount(GNCSplitReg *gsr, Split *split);
/*
* Create a transaction entry with given amount and date. One account is
* specified, the other is undefined i.e. it defaults to orphan account.
* Create a transaction entry with given amount and date. One account is
* specified, the other is undefined i.e. it defaults to orphan account.
* Jump to the transaction entry in the register.
* The purpose of this function to create an adjustment entry from the reconcile
* window.
* window.
*/
void gnc_split_reg_balancing_entry (GNCSplitReg *gsr, Account *account,
time_t statement_date, gnc_numeric balancing_amount);
void gnc_split_reg_balancing_entry (GNCSplitReg *gsr, Account *account,
time_t statement_date, gnc_numeric balancing_amount);
void gsr_default_delete_handler( GNCSplitReg *gsr, gpointer data );
void gnc_split_reg_enter( GNCSplitReg *gsr, gboolean next_transaction );

File diff suppressed because it is too large Load Diff

View File

@@ -40,9 +40,9 @@
/* Signal codes */
enum
{
TOGGLE_RECONCILED,
DOUBLE_CLICK_SPLIT,
LAST_SIGNAL
TOGGLE_RECONCILED,
DOUBLE_CLICK_SPLIT,
LAST_SIGNAL
};
@@ -57,37 +57,38 @@ static void gnc_reconcile_list_class_init(GNCReconcileListClass *klass);
static void gnc_reconcile_list_finalize (GObject *object);
static gpointer gnc_reconcile_list_is_reconciled(gpointer item, gpointer user_data);
static void gnc_reconcile_list_line_toggled (GNCQueryList *list, gpointer item,
gpointer user_data);
gpointer user_data);
static void gnc_reconcile_list_double_click_entry (GNCQueryList *list,
gpointer item,
gpointer user_data);
gpointer item,
gpointer user_data);
GType
gnc_reconcile_list_get_type (void)
{
static GType gnc_reconcile_list_type = 0;
static GType gnc_reconcile_list_type = 0;
if (gnc_reconcile_list_type == 0)
{
static const GTypeInfo gnc_reconcile_list_info = {
sizeof (GNCReconcileListClass),
NULL,
NULL,
(GClassInitFunc) gnc_reconcile_list_class_init,
NULL,
NULL,
sizeof (GNCReconcileList),
0,
(GInstanceInitFunc) gnc_reconcile_list_init
};
if (gnc_reconcile_list_type == 0)
{
static const GTypeInfo gnc_reconcile_list_info =
{
sizeof (GNCReconcileListClass),
NULL,
NULL,
(GClassInitFunc) gnc_reconcile_list_class_init,
NULL,
NULL,
sizeof (GNCReconcileList),
0,
(GInstanceInitFunc) gnc_reconcile_list_init
};
gnc_reconcile_list_type = g_type_register_static (GNC_TYPE_QUERY_LIST,
"GncReconcileList",
&gnc_reconcile_list_info, 0);
}
gnc_reconcile_list_type = g_type_register_static (GNC_TYPE_QUERY_LIST,
"GncReconcileList",
&gnc_reconcile_list_info, 0);
}
return gnc_reconcile_list_type;
return gnc_reconcile_list_type;
}
@@ -102,323 +103,327 @@ gnc_reconcile_list_get_type (void)
static void
gnc_reconcile_list_construct(GNCReconcileList *list, Query *query)
{
GNCQueryList *qlist = GNC_QUERY_LIST (list);
gboolean inv_sort = FALSE;
GNCQueryList *qlist = GNC_QUERY_LIST (list);
gboolean inv_sort = FALSE;
if (list->list_type == RECLIST_CREDIT)
inv_sort = TRUE;
if (list->list_type == RECLIST_CREDIT)
inv_sort = TRUE;
gnc_query_list_construct (qlist, list->column_list, query);
gnc_query_list_set_numerics (qlist, TRUE, inv_sort);
gnc_query_list_construct (qlist, list->column_list, query);
gnc_query_list_set_numerics (qlist, TRUE, inv_sort);
/* Now set up the signals for the QueryList */
g_signal_connect (G_OBJECT (qlist), "line_toggled",
G_CALLBACK(gnc_reconcile_list_line_toggled), list);
g_signal_connect (G_OBJECT (qlist), "double_click_entry",
G_CALLBACK(gnc_reconcile_list_double_click_entry), list);
/* Now set up the signals for the QueryList */
g_signal_connect (G_OBJECT (qlist), "line_toggled",
G_CALLBACK(gnc_reconcile_list_line_toggled), list);
g_signal_connect (G_OBJECT (qlist), "double_click_entry",
G_CALLBACK(gnc_reconcile_list_double_click_entry), list);
}
GtkWidget *
gnc_reconcile_list_new(Account *account, GNCReconcileListType type,
time_t statement_date)
{
GNCReconcileList *list;
gboolean include_children, auto_check;
GList *accounts = NULL;
GList *splits;
Query *query;
GNCReconcileList *list;
gboolean include_children, auto_check;
GList *accounts = NULL;
GList *splits;
Query *query;
g_return_val_if_fail(account, NULL);
g_return_val_if_fail((type == RECLIST_DEBIT) ||
(type == RECLIST_CREDIT), NULL);
g_return_val_if_fail(account, NULL);
g_return_val_if_fail((type == RECLIST_DEBIT) ||
(type == RECLIST_CREDIT), NULL);
list = g_object_new (GNC_TYPE_RECONCILE_LIST,
"n-columns", 5,
NULL);
list = g_object_new (GNC_TYPE_RECONCILE_LIST,
"n-columns", 5,
NULL);
list->account = account;
list->list_type = type;
list->statement_date = statement_date;
list->account = account;
list->list_type = type;
list->statement_date = statement_date;
query = xaccMallocQuery();
xaccQuerySetBook(query, gnc_get_current_book ());
query = xaccMallocQuery();
xaccQuerySetBook(query, gnc_get_current_book ());
include_children = xaccAccountGetReconcileChildrenStatus(account);
if (include_children)
accounts = gnc_account_get_descendants(account);
include_children = xaccAccountGetReconcileChildrenStatus(account);
if (include_children)
accounts = gnc_account_get_descendants(account);
/* match the account */
accounts = g_list_prepend (accounts, account);
/* match the account */
accounts = g_list_prepend (accounts, account);
xaccQueryAddAccountMatch (query, accounts, GUID_MATCH_ANY, QUERY_AND);
xaccQueryAddAccountMatch (query, accounts, GUID_MATCH_ANY, QUERY_AND);
g_list_free (accounts);
g_list_free (accounts);
/* limit the matches to CREDITs and DEBITs only, depending on the type */
if (type == RECLIST_CREDIT)
xaccQueryAddValueMatch(query, gnc_numeric_zero (),
NUMERIC_MATCH_CREDIT,
COMPARE_GTE, QUERY_AND);
else
xaccQueryAddValueMatch(query, gnc_numeric_zero (),
NUMERIC_MATCH_DEBIT,
COMPARE_GTE, QUERY_AND);
/* limit the matches to CREDITs and DEBITs only, depending on the type */
if (type == RECLIST_CREDIT)
xaccQueryAddValueMatch(query, gnc_numeric_zero (),
NUMERIC_MATCH_CREDIT,
COMPARE_GTE, QUERY_AND);
else
xaccQueryAddValueMatch(query, gnc_numeric_zero (),
NUMERIC_MATCH_DEBIT,
COMPARE_GTE, QUERY_AND);
/* limit the matches only to Cleared and Non-reconciled splits */
xaccQueryAddClearedMatch(query, CLEARED_NO | CLEARED_CLEARED, QUERY_AND);
/* limit the matches only to Cleared and Non-reconciled splits */
xaccQueryAddClearedMatch(query, CLEARED_NO | CLEARED_CLEARED, QUERY_AND);
/* initialize the QueryList */
gnc_reconcile_list_construct (list, query);
/* initialize the QueryList */
gnc_reconcile_list_construct (list, query);
/* find the list of splits to auto-reconcile */
auto_check = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
"check_cleared", NULL);
/* find the list of splits to auto-reconcile */
auto_check = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
"check_cleared", NULL);
if (auto_check) {
for (splits = xaccQueryGetSplits(query); splits; splits = splits->next) {
Split *split = splits->data;
char recn = xaccSplitGetReconcile(split);
time_t trans_date = xaccTransGetDate(xaccSplitGetParent(split));
/* Just an extra verification that our query is correct ;) */
g_assert (recn == NREC || recn == CREC);
if (auto_check)
{
for (splits = xaccQueryGetSplits(query); splits; splits = splits->next)
{
Split *split = splits->data;
char recn = xaccSplitGetReconcile(split);
time_t trans_date = xaccTransGetDate(xaccSplitGetParent(split));
if (recn == CREC &&
difftime(trans_date, statement_date) <= 0)
g_hash_table_insert (list->reconciled, split, split);
/* Just an extra verification that our query is correct ;) */
g_assert (recn == NREC || recn == CREC);
if (recn == CREC &&
difftime(trans_date, statement_date) <= 0)
g_hash_table_insert (list->reconciled, split, split);
}
}
}
/* Free the query -- we don't need it anymore */
xaccFreeQuery(query);
/* Free the query -- we don't need it anymore */
xaccFreeQuery(query);
return GTK_WIDGET(list);
return GTK_WIDGET(list);
}
static void
gnc_reconcile_list_init (GNCReconcileList *list)
{
GNCSearchParam *param;
GList *columns = NULL;
GNCSearchParam *param;
GList *columns = NULL;
list->reconciled = g_hash_table_new (NULL, NULL);
list->account = NULL;
list->sibling = NULL;
list->reconciled = g_hash_table_new (NULL, NULL);
list->account = NULL;
list->sibling = NULL;
param = gnc_search_param_new();
gnc_search_param_set_param_fcn (param, QUERYCORE_BOOLEAN,
gnc_reconcile_list_is_reconciled, list);
gnc_search_param_set_title (param, _("Reconciled:R")+11);
gnc_search_param_set_justify (param, GTK_JUSTIFY_CENTER);
gnc_search_param_set_passive (param, TRUE);
gnc_search_param_set_non_resizeable (param, TRUE);
columns = g_list_prepend (columns, param);
columns = gnc_search_param_prepend_with_justify (columns, _("Amount"),
GTK_JUSTIFY_RIGHT,
NULL, GNC_ID_SPLIT,
SPLIT_AMOUNT, NULL);
columns = gnc_search_param_prepend (columns, _("Description"), NULL,
GNC_ID_SPLIT, SPLIT_TRANS,
TRANS_DESCRIPTION, NULL);
columns = gnc_search_param_prepend_with_justify (columns, _("Num"),
GTK_JUSTIFY_CENTER,
NULL, GNC_ID_SPLIT,
SPLIT_TRANS, TRANS_NUM, NULL);
columns = gnc_search_param_prepend (columns, _("Date"), NULL, GNC_ID_SPLIT,
SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
param = gnc_search_param_new();
gnc_search_param_set_param_fcn (param, QUERYCORE_BOOLEAN,
gnc_reconcile_list_is_reconciled, list);
gnc_search_param_set_title (param, _("Reconciled:R") + 11);
gnc_search_param_set_justify (param, GTK_JUSTIFY_CENTER);
gnc_search_param_set_passive (param, TRUE);
gnc_search_param_set_non_resizeable (param, TRUE);
columns = g_list_prepend (columns, param);
columns = gnc_search_param_prepend_with_justify (columns, _("Amount"),
GTK_JUSTIFY_RIGHT,
NULL, GNC_ID_SPLIT,
SPLIT_AMOUNT, NULL);
columns = gnc_search_param_prepend (columns, _("Description"), NULL,
GNC_ID_SPLIT, SPLIT_TRANS,
TRANS_DESCRIPTION, NULL);
columns = gnc_search_param_prepend_with_justify (columns, _("Num"),
GTK_JUSTIFY_CENTER,
NULL, GNC_ID_SPLIT,
SPLIT_TRANS, TRANS_NUM, NULL);
columns = gnc_search_param_prepend (columns, _("Date"), NULL, GNC_ID_SPLIT,
SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
list->column_list = columns;
list->column_list = columns;
}
static void
gnc_reconcile_list_class_init (GNCReconcileListClass *klass)
{
GObjectClass *object_class;
GtkCListClass *clist_class;
GObjectClass *object_class;
GtkCListClass *clist_class;
object_class = G_OBJECT_CLASS (klass);
clist_class = GTK_CLIST_CLASS (klass);
object_class = G_OBJECT_CLASS (klass);
clist_class = GTK_CLIST_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
parent_class = g_type_class_peek_parent (klass);
reconcile_list_signals[TOGGLE_RECONCILED] =
g_signal_new("toggle_reconciled",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GNCReconcileListClass,
toggle_reconciled),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
reconcile_list_signals[TOGGLE_RECONCILED] =
g_signal_new("toggle_reconciled",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GNCReconcileListClass,
toggle_reconciled),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
reconcile_list_signals[DOUBLE_CLICK_SPLIT] =
g_signal_new("double_click_split",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GNCReconcileListClass,
double_click_split),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
reconcile_list_signals[DOUBLE_CLICK_SPLIT] =
g_signal_new("double_click_split",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GNCReconcileListClass,
double_click_split),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
object_class->finalize = gnc_reconcile_list_finalize;
object_class->finalize = gnc_reconcile_list_finalize;
klass->toggle_reconciled = NULL;
klass->double_click_split = NULL;
klass->toggle_reconciled = NULL;
klass->double_click_split = NULL;
}
static void
gnc_reconcile_list_toggle_split(GNCReconcileList *list, Split *split)
{
Split *current;
Split *current;
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list->reconciled != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list->reconciled != NULL);
current = g_hash_table_lookup (list->reconciled, split);
current = g_hash_table_lookup (list->reconciled, split);
if (current == NULL)
g_hash_table_insert (list->reconciled, split, split);
else
g_hash_table_remove (list->reconciled, split);
if (current == NULL)
g_hash_table_insert (list->reconciled, split, split);
else
g_hash_table_remove (list->reconciled, split);
gnc_query_list_refresh_item (GNC_QUERY_LIST(list), split);
gnc_query_list_refresh_item (GNC_QUERY_LIST(list), split);
}
static void
gnc_reconcile_list_toggle_children(Account *account, GNCReconcileList *list, Split *split)
{
GList *child_accounts, *node;
Transaction *transaction;
GList *child_accounts, *node;
Transaction *transaction;
/*
* Need to get all splits in this transaction and identify any that are
* in the same heirarchy as the account being reconciled (not necessarily
* the account this split is from.)
*
* For each of these splits toggle them all to the same state.
*/
child_accounts = gnc_account_get_descendants(account);
child_accounts = g_list_prepend(child_accounts, account);
transaction = xaccSplitGetParent(split);
for(node = xaccTransGetSplitList(transaction); node; node = node->next)
{
Split *other_split;
Account *other_account;
GNCReconcileList *current_list;
other_split = node->data;
other_account = xaccSplitGetAccount(other_split);
if(other_split == split)
continue;
/* Check this 'other' account in in the same heirarchy */
if(!g_list_find(child_accounts,other_account))
continue;
/* Search our sibling list for this split first. We search the
* sibling list first because that it where it is most likely to be.
/*
* Need to get all splits in this transaction and identify any that are
* in the same heirarchy as the account being reconciled (not necessarily
* the account this split is from.)
*
* For each of these splits toggle them all to the same state.
*/
current_list = list->sibling;
if (!gnc_query_list_item_in_list (GNC_QUERY_LIST(current_list), other_split)) {
/* Not in the sibling list, try this list */
current_list = list;
if (!gnc_query_list_item_in_list (GNC_QUERY_LIST(current_list), other_split))
/* We can't find it, nothing more I can do about it */
continue;
child_accounts = gnc_account_get_descendants(account);
child_accounts = g_list_prepend(child_accounts, account);
transaction = xaccSplitGetParent(split);
for (node = xaccTransGetSplitList(transaction); node; node = node->next)
{
Split *other_split;
Account *other_account;
GNCReconcileList *current_list;
other_split = node->data;
other_account = xaccSplitGetAccount(other_split);
if (other_split == split)
continue;
/* Check this 'other' account in in the same heirarchy */
if (!g_list_find(child_accounts, other_account))
continue;
/* Search our sibling list for this split first. We search the
* sibling list first because that it where it is most likely to be.
*/
current_list = list->sibling;
if (!gnc_query_list_item_in_list (GNC_QUERY_LIST(current_list), other_split))
{
/* Not in the sibling list, try this list */
current_list = list;
if (!gnc_query_list_item_in_list (GNC_QUERY_LIST(current_list), other_split))
/* We can't find it, nothing more I can do about it */
continue;
}
gnc_reconcile_list_toggle_split(current_list, other_split);
}
gnc_reconcile_list_toggle_split(current_list, other_split);
}
g_list_free(child_accounts);
g_list_free(child_accounts);
}
static void
gnc_reconcile_list_toggle (GNCReconcileList *list, Split *split)
{
gboolean include_children;
gboolean include_children;
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list->reconciled != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list->reconciled != NULL);
gnc_reconcile_list_toggle_split(list, split);
gnc_reconcile_list_toggle_split(list, split);
include_children = xaccAccountGetReconcileChildrenStatus(list->account);
if(include_children)
gnc_reconcile_list_toggle_children(list->account, list, split);
include_children = xaccAccountGetReconcileChildrenStatus(list->account);
if (include_children)
gnc_reconcile_list_toggle_children(list->account, list, split);
g_signal_emit (G_OBJECT (list),
reconcile_list_signals[TOGGLE_RECONCILED], 0, split);
g_signal_emit (G_OBJECT (list),
reconcile_list_signals[TOGGLE_RECONCILED], 0, split);
}
static void
gnc_reconcile_list_line_toggled (GNCQueryList *list, gpointer item,
gpointer user_data)
gpointer user_data)
{
GNCReconcileList *rlist = user_data;
GNCReconcileList *rlist = user_data;
g_return_if_fail(item);
g_return_if_fail(user_data);
g_return_if_fail(GNC_IS_RECONCILE_LIST(rlist));
g_return_if_fail(item);
g_return_if_fail(user_data);
g_return_if_fail(GNC_IS_RECONCILE_LIST(rlist));
gnc_reconcile_list_toggle (rlist, item);
gnc_reconcile_list_toggle (rlist, item);
}
static void gnc_reconcile_list_double_click_entry (GNCQueryList *list,
gpointer item,
gpointer user_data)
gpointer item,
gpointer user_data)
{
GNCReconcileList *rlist = user_data;
GNCReconcileList *rlist = user_data;
g_return_if_fail(item);
g_return_if_fail(user_data);
g_return_if_fail(GNC_IS_RECONCILE_LIST(rlist));
g_return_if_fail(item);
g_return_if_fail(user_data);
g_return_if_fail(GNC_IS_RECONCILE_LIST(rlist));
g_signal_emit(G_OBJECT(rlist),
reconcile_list_signals[DOUBLE_CLICK_SPLIT], 0, item);
g_signal_emit(G_OBJECT(rlist),
reconcile_list_signals[DOUBLE_CLICK_SPLIT], 0, item);
}
static void
gnc_reconcile_list_finalize (GObject *object)
{
GNCReconcileList *list = GNC_RECONCILE_LIST(object);
GNCReconcileList *list = GNC_RECONCILE_LIST(object);
if (list->reconciled != NULL) {
g_hash_table_destroy(list->reconciled);
list->reconciled = NULL;
}
if (list->reconciled != NULL)
{
g_hash_table_destroy(list->reconciled);
list->reconciled = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
gint
gnc_reconcile_list_get_needed_height (GNCReconcileList *list, gint num_rows)
{
g_return_val_if_fail (list != NULL, 0);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), 0);
g_return_val_if_fail (list != NULL, 0);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), 0);
if (!GTK_WIDGET_REALIZED (list))
return 0;
if (!GTK_WIDGET_REALIZED (list))
return 0;
return gnc_query_list_get_needed_height (GNC_QUERY_LIST(list), num_rows);
return gnc_query_list_get_needed_height (GNC_QUERY_LIST(list), num_rows);
}
gint
gnc_reconcile_list_get_num_splits (GNCReconcileList *list)
{
g_return_val_if_fail (list != NULL, 0);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), 0);
g_return_val_if_fail (list != NULL, 0);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), 0);
return gnc_query_list_get_num_entries(GNC_QUERY_LIST(list));
return gnc_query_list_get_num_entries(GNC_QUERY_LIST(list));
}
Split *
gnc_reconcile_list_get_current_split (GNCReconcileList *list)
{
g_return_val_if_fail (list != NULL, NULL);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), NULL);
g_return_val_if_fail (list != NULL, NULL);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), NULL);
return gnc_query_list_get_current_entry(GNC_QUERY_LIST(list));
return gnc_query_list_get_current_entry(GNC_QUERY_LIST(list));
}
/********************************************************************\
@@ -432,28 +437,28 @@ gnc_reconcile_list_get_current_split (GNCReconcileList *list)
static gpointer
gnc_reconcile_list_is_reconciled(gpointer item, gpointer user_data)
{
GNCReconcileList *list = user_data;
Split *current;
GNCReconcileList *list = user_data;
Split *current;
g_return_val_if_fail(item, NULL);
g_return_val_if_fail(list, NULL);
g_return_val_if_fail(GNC_IS_RECONCILE_LIST(list), NULL);
g_return_val_if_fail(item, NULL);
g_return_val_if_fail(list, NULL);
g_return_val_if_fail(GNC_IS_RECONCILE_LIST(list), NULL);
if (!list->reconciled)
return NULL;
if (!list->reconciled)
return NULL;
current = g_hash_table_lookup(list->reconciled, item);
return GINT_TO_POINTER(current != NULL);
current = g_hash_table_lookup(list->reconciled, item);
return GINT_TO_POINTER(current != NULL);
}
static void
grl_refresh_helper (gpointer key, gpointer value, gpointer user_data)
{
GNCReconcileList *list = user_data;
GNCQueryList *qlist = GNC_QUERY_LIST(list);
GNCReconcileList *list = user_data;
GNCQueryList *qlist = GNC_QUERY_LIST(list);
if (!gnc_query_list_item_in_list(qlist, key))
g_hash_table_remove(list->reconciled, key);
if (!gnc_query_list_item_in_list(qlist, key))
g_hash_table_remove(list->reconciled, key);
}
/********************************************************************\
@@ -466,17 +471,17 @@ grl_refresh_helper (gpointer key, gpointer value, gpointer user_data)
void
gnc_reconcile_list_refresh (GNCReconcileList *list)
{
GNCQueryList *qlist;
GNCQueryList *qlist;
g_return_if_fail (list != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
qlist = GNC_QUERY_LIST(list);
gnc_query_list_refresh(qlist);
qlist = GNC_QUERY_LIST(list);
gnc_query_list_refresh(qlist);
/* Now verify that everything in the reconcile hash is still in qlist */
if (list->reconciled)
g_hash_table_foreach(list->reconciled, grl_refresh_helper, list);
/* Now verify that everything in the reconcile hash is still in qlist */
if (list->reconciled)
g_hash_table_foreach(list->reconciled, grl_refresh_helper, list);
}
@@ -490,26 +495,26 @@ gnc_reconcile_list_refresh (GNCReconcileList *list)
static void
grl_balance_hash_helper (gpointer key, gpointer value, gpointer user_data)
{
Split *split = key;
gnc_numeric *total = user_data;
Split *split = key;
gnc_numeric *total = user_data;
*total = gnc_numeric_add_fixed (*total, xaccSplitGetAmount (split));
*total = gnc_numeric_add_fixed (*total, xaccSplitGetAmount (split));
}
gnc_numeric
gnc_reconcile_list_reconciled_balance (GNCReconcileList *list)
{
gnc_numeric total = gnc_numeric_zero ();
gnc_numeric total = gnc_numeric_zero ();
g_return_val_if_fail (list != NULL, total);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), total);
g_return_val_if_fail (list != NULL, total);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), total);
if (list->reconciled == NULL)
return total;
if (list->reconciled == NULL)
return total;
g_hash_table_foreach (list->reconciled, grl_balance_hash_helper, &total);
g_hash_table_foreach (list->reconciled, grl_balance_hash_helper, &total);
return gnc_numeric_abs (total);
return gnc_numeric_abs (total);
}
@@ -526,25 +531,25 @@ gnc_reconcile_list_reconciled_balance (GNCReconcileList *list)
static void
grl_commit_hash_helper (gpointer key, gpointer value, gpointer user_data)
{
Split *split = key;
time_t *date = user_data;
Split *split = key;
time_t *date = user_data;
xaccSplitSetReconcile (split, YREC);
xaccSplitSetDateReconciledSecs (split, *date);
xaccSplitSetReconcile (split, YREC);
xaccSplitSetDateReconciledSecs (split, *date);
}
void
gnc_reconcile_list_commit (GNCReconcileList *list, time_t date)
{
g_return_if_fail (list != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
if (list->reconciled == NULL)
return;
if (list->reconciled == NULL)
return;
gnc_suspend_gui_refresh();
g_hash_table_foreach (list->reconciled, grl_commit_hash_helper, &date);
gnc_resume_gui_refresh();
gnc_suspend_gui_refresh();
g_hash_table_foreach (list->reconciled, grl_commit_hash_helper, &date);
gnc_resume_gui_refresh();
}
@@ -559,37 +564,37 @@ gnc_reconcile_list_commit (GNCReconcileList *list, time_t date)
void
gnc_reconcile_list_postpone (GNCReconcileList *list)
{
GtkCList *clist = GTK_CLIST(list); /* This is cheating! */
Split *split;
int num_splits;
int i;
GtkCList *clist = GTK_CLIST(list); /* This is cheating! */
Split *split;
int num_splits;
int i;
g_return_if_fail(list != NULL);
g_return_if_fail(GNC_IS_RECONCILE_LIST(list));
g_return_if_fail(list != NULL);
g_return_if_fail(GNC_IS_RECONCILE_LIST(list));
if (list->reconciled == NULL)
return;
if (list->reconciled == NULL)
return;
num_splits = gnc_query_list_get_num_entries(GNC_QUERY_LIST(list));
gnc_suspend_gui_refresh();
for (i = 0; i < num_splits; i++)
{
char recn;
split = gtk_clist_get_row_data (clist, i);
// Don't change splits past reconciliation date that haven't been
// set to be reconciled
if ( difftime(list->statement_date,
xaccTransGetDate(xaccSplitGetParent(split))) >= 0 ||
g_hash_table_lookup(list->reconciled, split))
num_splits = gnc_query_list_get_num_entries(GNC_QUERY_LIST(list));
gnc_suspend_gui_refresh();
for (i = 0; i < num_splits; i++)
{
recn = g_hash_table_lookup (list->reconciled, split) ? CREC : NREC;
char recn;
xaccSplitSetReconcile (split, recn);
split = gtk_clist_get_row_data (clist, i);
// Don't change splits past reconciliation date that haven't been
// set to be reconciled
if ( difftime(list->statement_date,
xaccTransGetDate(xaccSplitGetParent(split))) >= 0 ||
g_hash_table_lookup(list->reconciled, split))
{
recn = g_hash_table_lookup (list->reconciled, split) ? CREC : NREC;
xaccSplitSetReconcile (split, recn);
}
}
}
gnc_resume_gui_refresh();
gnc_resume_gui_refresh();
}
@@ -603,10 +608,10 @@ gnc_reconcile_list_postpone (GNCReconcileList *list)
void
gnc_reconcile_list_unselect_all(GNCReconcileList *list)
{
g_return_if_fail (list != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
g_return_if_fail (list != NULL);
g_return_if_fail (GNC_IS_RECONCILE_LIST(list));
gnc_query_list_unselect_all (GNC_QUERY_LIST(list));
gnc_query_list_unselect_all (GNC_QUERY_LIST(list));
}
@@ -620,82 +625,89 @@ gnc_reconcile_list_unselect_all(GNCReconcileList *list)
gboolean
gnc_reconcile_list_changed (GNCReconcileList *list)
{
g_return_val_if_fail (list != NULL, FALSE);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), FALSE);
g_return_val_if_fail (list != NULL, FALSE);
g_return_val_if_fail (GNC_IS_RECONCILE_LIST(list), FALSE);
return g_hash_table_size (list->reconciled) != 0;
return g_hash_table_size (list->reconciled) != 0;
}
#if 0
static void
gnc_reconcile_list_fill(GNCReconcileList *list)
{
const gchar *strings[list->num_columns + 1];
GNCPrintAmountInfo print_info;
Transaction *trans;
gboolean auto_check;
GList *splits;
Split *split;
const gchar *strings[list->num_columns + 1];
GNCPrintAmountInfo print_info;
Transaction *trans;
gboolean auto_check;
GList *splits;
Split *split;
auto_check = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
"check_cleared", NULL);
auto_check = gnc_gconf_get_bool(GCONF_RECONCILE_SECTION,
"check_cleared", NULL);
strings[5] = NULL;
strings[5] = NULL;
print_info = gnc_account_print_info (list->account, FALSE);
print_info = gnc_account_print_info (list->account, FALSE);
for (splits = xaccQueryGetSplits (list->query); splits; splits=splits->next)
{
gnc_numeric amount;
Timespec ts;
const gchar *trans_num;
char recn;
int row, len;
for (splits = xaccQueryGetSplits (list->query); splits; splits = splits->next)
{
gnc_numeric amount;
Timespec ts;
const gchar *trans_num;
char recn;
int row, len;
split = splits->data;
trans = xaccSplitGetParent (split);
trans_num = xaccTransGetNum (trans);
split = splits->data;
trans = xaccSplitGetParent (split);
trans_num = xaccTransGetNum (trans);
recn = xaccSplitGetReconcile(split);
if ((recn != NREC) && (recn != CREC))
continue;
recn = xaccSplitGetReconcile(split);
if ((recn != NREC) && (recn != CREC))
continue;
amount = xaccSplitGetAmount (split);
amount = xaccSplitGetAmount (split);
if (gnc_numeric_negative_p (amount)) {
if (list->list_type == RECLIST_DEBIT) {
continue;
}
} else if (gnc_numeric_positive_p (amount)) {
if (list->list_type == RECLIST_CREDIT) {
continue;
}
} else {
len = trans_num ? strlen(trans_num) : 0;
if ((len && (list->list_type == RECLIST_DEBIT)) ||
(!len && (list->list_type == RECLIST_CREDIT)))
continue;
if (gnc_numeric_negative_p (amount))
{
if (list->list_type == RECLIST_DEBIT)
{
continue;
}
}
else if (gnc_numeric_positive_p (amount))
{
if (list->list_type == RECLIST_CREDIT)
{
continue;
}
}
else
{
len = trans_num ? strlen(trans_num) : 0;
if ((len && (list->list_type == RECLIST_DEBIT)) ||
(!len && (list->list_type == RECLIST_CREDIT)))
continue;
}
xaccTransGetDatePostedTS (trans, &ts);
strings[0] = gnc_print_date (ts);
strings[1] = trans_num;
strings[2] = xaccTransGetDescription (trans);
strings[3] = xaccPrintAmount (gnc_numeric_abs (amount), print_info);
strings[4] = "";
if (list->first_fill && auto_check && recn == CREC)
g_hash_table_insert (list->reconciled, split, split);
row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings);
gtk_clist_set_row_data (GTK_CLIST(list), row, split);
update_toggle (GTK_CLIST (list), row);
list->num_splits++;
}
xaccTransGetDatePostedTS (trans, &ts);
strings[0] = gnc_print_date (ts);
strings[1] = trans_num;
strings[2] = xaccTransGetDescription (trans);
strings[3] = xaccPrintAmount (gnc_numeric_abs (amount), print_info);
strings[4] = "";
if (list->first_fill && auto_check && recn == CREC)
g_hash_table_insert (list->reconciled, split, split);
row = gtk_clist_append (GTK_CLIST(list), (gchar **) strings);
gtk_clist_set_row_data (GTK_CLIST(list), row, split);
update_toggle (GTK_CLIST (list), row);
list->num_splits++;
}
list->first_fill = FALSE;
list->first_fill = FALSE;
}
#endif

View File

@@ -37,32 +37,35 @@ G_BEGIN_DECLS
typedef struct GNCReconcileList GNCReconcileList;
typedef enum {
RECLIST_DEBIT,
RECLIST_CREDIT
typedef enum
{
RECLIST_DEBIT,
RECLIST_CREDIT
} GNCReconcileListType;
struct GNCReconcileList {
GNCQueryList qlist;
struct GNCReconcileList
{
GNCQueryList qlist;
GHashTable *reconciled;
Account *account;
GList *column_list;
GHashTable *reconciled;
Account *account;
GList *column_list;
time_t statement_date;
time_t statement_date;
GNCReconcileList *sibling;
GNCReconcileListType list_type;
gboolean no_toggle;
GNCReconcileList *sibling;
GNCReconcileListType list_type;
gboolean no_toggle;
};
typedef struct {
GtkCListClass parent_class;
typedef struct
{
GtkCListClass parent_class;
void (*toggle_reconciled) (GNCReconcileList *list,
Split *split);
void (*double_click_split) (GNCReconcileList *list,
Split *split);
void (*toggle_reconciled) (GNCReconcileList *list,
Split *split);
void (*double_click_split) (GNCReconcileList *list,
Split *split);
} GNCReconcileListClass;
#define GCONF_RECONCILE_SECTION "dialogs/reconcile"
@@ -74,11 +77,11 @@ typedef struct {
GType gnc_reconcile_list_get_type (void);
GtkWidget * gnc_reconcile_list_new (Account * account,
GNCReconcileListType type,
GNCReconcileListType type,
time_t date);
gint gnc_reconcile_list_get_needed_height(GNCReconcileList *list,
gint num_rows);
gint num_rows);
gint gnc_reconcile_list_get_num_splits(GNCReconcileList *list);

View File

@@ -97,152 +97,155 @@ static QofLogModule log_module = GNC_MOD_GUI;
location); \
return FALSE; \
} \
static gboolean
gnc_html_register_url_cb (const char *location, const char *label,
gboolean new_window, GNCURLResult *result)
{
GncPluginPage *page = NULL;
GNCSplitReg * gsr = NULL;
Split * split = NULL;
Account * account = NULL;
Transaction * trans;
GList * node;
QofBook * book = gnc_get_current_book();
GncPluginPage *page = NULL;
GNCSplitReg * gsr = NULL;
Split * split = NULL;
Account * account = NULL;
Transaction * trans;
GList * node;
QofBook * book = gnc_get_current_book();
g_return_val_if_fail (location != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE);
g_return_val_if_fail (location != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE);
result->load_to_stream = FALSE;
result->load_to_stream = FALSE;
/* href="gnc-register:account=My Bank Account" */
if (strncmp("account=", location, 8) == 0)
{
account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (),
location + 8);
}
/* href="gnc-register:account=My Bank Account" */
if (strncmp("account=", location, 8) == 0)
{
account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (),
location + 8);
}
/* href="gnc-register:guid=12345678901234567890123456789012" */
else IF_TYPE ("acct-guid=", GNC_ID_ACCOUNT)
account = GNC_ACCOUNT(entity);
}
/* href="gnc-register:guid=12345678901234567890123456789012" */
else IF_TYPE ("acct-guid=", GNC_ID_ACCOUNT)
account = GNC_ACCOUNT(entity);
}
else IF_TYPE ("trans-guid=", GNC_ID_TRANS)
else IF_TYPE ("trans-guid=", GNC_ID_TRANS)
trans = (Transaction *) entity;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
split = node->data;
account = xaccSplitGetAccount(split);
if (account) break;
}
if (!account)
{
result->error_message =
g_strdup_printf (_("Transaction with no Accounts: %s"), location);
return FALSE;
}
}
else IF_TYPE ("split-guid=", GNC_ID_SPLIT)
split = (Split *) entity;
for (node = xaccTransGetSplitList (trans); node; node = node->next)
{
split = node->data;
account = xaccSplitGetAccount(split);
}
else
{
result->error_message =
g_strdup_printf (_("Unsupported entity type: %s"), location);
return FALSE;
}
page = gnc_plugin_page_register_new (account, FALSE);
gnc_main_window_open_page (NULL, page);
if (split) {
gsr = gnc_plugin_page_register_get_gsr(page);
gnc_split_reg_jump_to_split( gsr, split );
}
return TRUE;
if (account) break;
}
/* ============================================================== */
static gboolean
gnc_html_price_url_cb (const char *location, const char *label,
gboolean new_window, GNCURLResult *result)
if (!account)
{
QofBook * book = gnc_get_current_book();
g_return_val_if_fail (location != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE);
result->error_message =
g_strdup_printf (_("Transaction with no Accounts: %s"), location);
return FALSE;
}
}
else IF_TYPE ("split-guid=", GNC_ID_SPLIT)
split = (Split *) entity;
account = xaccSplitGetAccount(split);
}
else
{
result->error_message =
g_strdup_printf (_("Unsupported entity type: %s"), location);
return FALSE;
}
result->load_to_stream = FALSE;
page = gnc_plugin_page_register_new (account, FALSE);
gnc_main_window_open_page (NULL, page);
if (split)
{
gsr = gnc_plugin_page_register_get_gsr(page);
gnc_split_reg_jump_to_split( gsr, split );
}
/* href="gnc-register:guid=12345678901234567890123456789012" */
IF_TYPE ("price-guid=", GNC_ID_PRICE)
if (!gnc_price_edit_by_guid (NULL, &guid))
return TRUE;
}
/* ============================================================== */
static gboolean
gnc_html_price_url_cb (const char *location, const char *label,
gboolean new_window, GNCURLResult *result)
{
QofBook * book = gnc_get_current_book();
g_return_val_if_fail (location != NULL, FALSE);
g_return_val_if_fail (result != NULL, FALSE);
result->load_to_stream = FALSE;
/* href="gnc-register:guid=12345678901234567890123456789012" */
IF_TYPE ("price-guid=", GNC_ID_PRICE)
if (!gnc_price_edit_by_guid (NULL, &guid))
{
result->error_message = g_strdup_printf (_("No such price: %s"),
location);
location);
return FALSE;
}
}
else
{
result->error_message = g_strdup_printf (_("Badly formed URL %s"),
location);
return FALSE;
}
return TRUE;
}
else
{
result->error_message = g_strdup_printf (_("Badly formed URL %s"),
location);
return FALSE;
}
/** Restore all persistent program state. This function finds the
* "new" state file associated with a specific book guid. It then
* iterates through this state information, calling a helper function
* to recreate each open window.
*
* @note The name of the state file is based on the name of the data
* file, not the path name of the data file. If there are multiple
* data files with the same name, the state files will be suffixed
* with a number. E.G. test_account, test_account_2, test_account_3,
* etc.
*
* @param session A pointer to the current session.
*
* @param unused An unused pointer. */
static void
gnc_restore_all_state (gpointer session, gpointer unused)
return TRUE;
}
/** Restore all persistent program state. This function finds the
* "new" state file associated with a specific book guid. It then
* iterates through this state information, calling a helper function
* to recreate each open window.
*
* @note The name of the state file is based on the name of the data
* file, not the path name of the data file. If there are multiple
* data files with the same name, the state files will be suffixed
* with a number. E.G. test_account, test_account_2, test_account_3,
* etc.
*
* @param session A pointer to the current session.
*
* @param unused An unused pointer. */
static void
gnc_restore_all_state (gpointer session, gpointer unused)
{
GKeyFile *keyfile = NULL;
QofBook *book;
const GUID *guid;
const gchar *url, *guid_string;
const gchar *url, *guid_string;
gchar *file_guid, *filename = NULL;
GError *error = NULL;
url = qof_session_get_url(session);
ENTER("session %p (%s)", session, url ? url : "(null)");
if (!url) {
if (!url)
{
LEAVE("no url, nothing to do");
return;
}
/* Get the book GUID */
book = qof_session_get_book(session);
guid = qof_entity_get_guid(QOF_INSTANCE(book));
guid_string = guid_to_string(guid);
keyfile = gnc_find_state_file(url, guid_string, &filename);
if (filename)
g_free(filename);
if (!keyfile) {
if (!keyfile)
{
gnc_main_window_restore_default_state();
LEAVE("no state file");
return;
}
#ifdef DEBUG
/* Debugging: dump a copy to stdout and the trace log */
{
@@ -253,28 +256,30 @@ gnc_restore_all_state (gpointer session, gpointer unused)
g_free(file_data);
}
#endif
/* validate top level info */
file_guid = g_key_file_get_string(keyfile, STATE_FILE_TOP,
file_guid = g_key_file_get_string(keyfile, STATE_FILE_TOP,
STATE_FILE_BOOK_GUID, &error);
if (error) {
if (error)
{
g_warning("error reading group %s key %s: %s",
STATE_FILE_TOP, STATE_FILE_BOOK_GUID, error->message);
LEAVE("can't read guid");
goto cleanup;
}
if (!file_guid || strcmp(guid_string, file_guid)) {
if (!file_guid || strcmp(guid_string, file_guid))
{
g_warning("guid mismatch: book guid %s, state file guid %s",
guid_string, file_guid);
LEAVE("guid values do not match");
goto cleanup;
}
gnc_main_window_restore_all_windows(keyfile);
/* Clean up */
LEAVE("ok");
cleanup:
cleanup:
if (error)
g_error_free(error);
if (file_guid)
@@ -306,11 +311,12 @@ gnc_save_all_state (gpointer session, gpointer unused)
const GUID *guid;
GError *error = NULL;
GKeyFile *keyfile = NULL;
url = qof_session_get_url(session);
ENTER("session %p (%s)", session, url ? url : "(null)");
if (!url) {
if (!url)
{
LEAVE("no url, nothing to do");
return;
}
@@ -335,7 +341,7 @@ gnc_save_all_state (gpointer session, gpointer unused)
guid_string);
gnc_main_window_save_all_windows(keyfile);
#ifdef DEBUG
/* Debugging: dump a copy to the trace log */
{
@@ -349,13 +355,14 @@ gnc_save_all_state (gpointer session, gpointer unused)
/* Write it all out to disk */
gnc_key_file_save_to_file(filename, keyfile, &error);
if (error) {
g_critical(_("Error: Failure saving state file.\n %s"),
if (error)
{
g_critical(_("Error: Failure saving state file.\n %s"),
error->message);
g_error_free(error);
}
g_free(filename);
/* Clean up */
g_key_file_free(keyfile);
LEAVE("");
@@ -367,7 +374,7 @@ gnc_main_gui_init (void)
ENTER(" ");
if (!gnucash_style_init())
gnc_shutdown(1);
gnc_shutdown(1);
gnucash_color_init();
gnc_html_register_url_handler (URL_TYPE_REGISTER,

View File

@@ -48,15 +48,15 @@
/** STRUCTS *********************************************************/
struct _AutoClearWindow
{
Account *account; /* The account that we are auto-clearing */
Account *account; /* The account that we are auto-clearing */
gint component_id; /* id of component */
gint component_id; /* id of component */
GtkWidget *window; /* The auto-clear window */
GNCAmountEdit *end_value;/* The ending value */
GtkWidget *ok_button;
GtkWidget *cancel_button;
GtkLabel *status_label;
GtkWidget *window; /* The auto-clear window */
GNCAmountEdit *end_value;/* The ending value */
GtkWidget *ok_button;
GtkWidget *cancel_button;
GtkLabel *status_label;
};
/********************************************************************\
@@ -68,209 +68,209 @@ struct _AutoClearWindow
void
gnc_ui_autoclear_window_raise(AutoClearWindow * autoClearData)
{
if (autoClearData == NULL)
return;
if (autoClearData == NULL)
return;
if (autoClearData->window == NULL)
return;
if (autoClearData->window == NULL)
return;
gtk_window_present(GTK_WINDOW(autoClearData->window));
gtk_window_present(GTK_WINDOW(autoClearData->window));
}
static char *
gnc_autoclear_make_window_name(Account *account)
{
char *fullname;
char *title;
char *fullname;
char *title;
fullname = gnc_account_get_full_name(account);
title = g_strconcat(fullname, " - ", _("Auto-clear"), NULL);
fullname = gnc_account_get_full_name(account);
title = g_strconcat(fullname, " - ", _("Auto-clear"), NULL);
g_free(fullname);
g_free(fullname);
return title;
return title;
}
static gboolean
ght_gnc_numeric_equal(gconstpointer v1, gconstpointer v2)
{
gnc_numeric n1 = *(gnc_numeric *)v1, n2 = *(gnc_numeric *)v2;
return gnc_numeric_equal(n1, n2);
gnc_numeric n1 = *(gnc_numeric *)v1, n2 = *(gnc_numeric *)v2;
return gnc_numeric_equal(n1, n2);
}
static guint
ght_gnc_numeric_hash(gconstpointer v1)
{
gnc_numeric n1 = *(gnc_numeric *)v1;
gdouble d1 = gnc_numeric_to_double(n1);
return g_str_hash(&d1);
gnc_numeric n1 = *(gnc_numeric *)v1;
gdouble d1 = gnc_numeric_to_double(n1);
return g_str_hash(&d1);
}
static void
gnc_autoclear_window_ok_cb (GtkWidget *widget,
AutoClearWindow *data)
AutoClearWindow *data)
{
GList *node, *nc_list = 0, *toclear_list = 0;
gnc_numeric toclear_value;
GHashTable *sack;
GList *node, *nc_list = 0, *toclear_list = 0;
gnc_numeric toclear_value;
GHashTable *sack;
gtk_label_set_text(data->status_label, "Searching for splits to clear ...");
gtk_label_set_text(data->status_label, "Searching for splits to clear ...");
/* Value we have to reach */
toclear_value = gnc_amount_edit_get_amount(data->end_value);
toclear_value = gnc_numeric_convert(toclear_value, xaccAccountGetCommoditySCU(data->account), GNC_RND_NEVER);
/* Value we have to reach */
toclear_value = gnc_amount_edit_get_amount(data->end_value);
toclear_value = gnc_numeric_convert(toclear_value, xaccAccountGetCommoditySCU(data->account), GNC_RND_NEVER);
/* Extract which splits are not cleared and compute the amount we have to clear */
for (node = xaccAccountGetSplitList(data->account); node; node = node->next)
{
Split *split = (Split *)node->data;
char recn;
gnc_numeric value;
recn = xaccSplitGetReconcile (split);
value = xaccSplitGetAmount (split);
if (recn == NREC)
nc_list = g_list_append(nc_list, split);
else
toclear_value = gnc_numeric_sub_fixed(toclear_value, value);
}
/* Pretty print information */
printf("Amount to clear: %s\n", gnc_numeric_to_string(toclear_value));
printf("Available splits:\n");
for (node = nc_list; node; node = node->next)
{
Split *split = (Split *)node->data;
gnc_numeric value = xaccSplitGetAmount (split);
printf(" %s\n", gnc_numeric_to_string(value));
}
/* Run knapsack */
/* Entries in the hash table are:
* - key = amount to which we know how to clear (freed by GHashTable)
* - value = last split we used to clear this amount (not managed by GHashTable)
*/
printf("Knapsacking ...\n");
sack = g_hash_table_new_full (ght_gnc_numeric_hash, ght_gnc_numeric_equal, g_free, NULL);
for (node = nc_list; node; node = node->next)
{
Split *split = (Split *)node->data;
gnc_numeric split_value = xaccSplitGetAmount(split);
GHashTableIter iter;
gpointer pkey = NULL;
GList *reachable_list = 0, *node;
printf(" Split value: %s\n", gnc_numeric_to_string(split_value));
/* For each value in the sack */
g_hash_table_iter_init (&iter, sack);
while (g_hash_table_iter_next (&iter, &pkey, NULL))
/* Extract which splits are not cleared and compute the amount we have to clear */
for (node = xaccAccountGetSplitList(data->account); node; node = node->next)
{
/* Cast the gpointer to the kind of pointer we actually need. */
gnc_numeric *key = (gnc_numeric *)pkey;
/* Compute a new reachable value */
gnc_numeric reachable_value = gnc_numeric_add_fixed(*key, split_value);
reachable_list = g_list_append(reachable_list, g_memdup(&reachable_value, sizeof(gnc_numeric)));
printf(" Sack: found %s, added %s\n", gnc_numeric_to_string(*key), gnc_numeric_to_string(reachable_value));
Split *split = (Split *)node->data;
char recn;
gnc_numeric value;
recn = xaccSplitGetReconcile (split);
value = xaccSplitGetAmount (split);
if (recn == NREC)
nc_list = g_list_append(nc_list, split);
else
toclear_value = gnc_numeric_sub_fixed(toclear_value, value);
}
/* Add the value of the split itself to the reachable_list */
reachable_list = g_list_append(reachable_list, g_memdup(&split_value, sizeof(gnc_numeric)));
/* Add everything to the sack, looking out for duplicates */
for (node = reachable_list; node; node = node->next)
/* Pretty print information */
printf("Amount to clear: %s\n", gnc_numeric_to_string(toclear_value));
printf("Available splits:\n");
for (node = nc_list; node; node = node->next)
{
gnc_numeric *reachable_value = node->data;
Split *toinsert_split = split;
printf(" Reachable value: %s ", gnc_numeric_to_string(*reachable_value));
/* Check if it already exists */
if (g_hash_table_lookup_extended(sack, reachable_value, NULL, NULL))
{
/* If yes, we are in trouble, we reached an amount using two solutions */
toinsert_split = NULL;
printf("dup");
}
g_hash_table_insert (sack, reachable_value, toinsert_split);
printf("\n");
Split *split = (Split *)node->data;
gnc_numeric value = xaccSplitGetAmount (split);
printf(" %s\n", gnc_numeric_to_string(value));
}
g_list_free(reachable_list);
}
/* Check solution */
printf("Rebuilding solution ...\n");
while (!gnc_numeric_zero_p(toclear_value))
{
gpointer psplit = NULL;
printf(" Left to clear: %s\n", gnc_numeric_to_string(toclear_value));
if (g_hash_table_lookup_extended(sack, &toclear_value, NULL, &psplit))
/* Run knapsack */
/* Entries in the hash table are:
* - key = amount to which we know how to clear (freed by GHashTable)
* - value = last split we used to clear this amount (not managed by GHashTable)
*/
printf("Knapsacking ...\n");
sack = g_hash_table_new_full (ght_gnc_numeric_hash, ght_gnc_numeric_equal, g_free, NULL);
for (node = nc_list; node; node = node->next)
{
if (psplit != NULL)
{
/* Cast the gpointer to the kind of pointer we actually need */
Split *split = (Split *)psplit;
toclear_list = g_list_prepend(toclear_list, split);
toclear_value = gnc_numeric_sub_fixed(toclear_value,
xaccSplitGetAmount(split));
printf(" Cleared: %s -> %s\n",
gnc_numeric_to_string(xaccSplitGetAmount(split)),
gnc_numeric_to_string(toclear_value));
}
else
{
/* We couldn't reconstruct the solution */
printf(" Solution not unique.\n");
gtk_label_set_text(data->status_label, "Cannot uniquely clear splits. Found multiple possibilities.");
return;
}
Split *split = (Split *)node->data;
gnc_numeric split_value = xaccSplitGetAmount(split);
GHashTableIter iter;
gpointer pkey = NULL;
GList *reachable_list = 0, *node;
printf(" Split value: %s\n", gnc_numeric_to_string(split_value));
/* For each value in the sack */
g_hash_table_iter_init (&iter, sack);
while (g_hash_table_iter_next (&iter, &pkey, NULL))
{
/* Cast the gpointer to the kind of pointer we actually need. */
gnc_numeric *key = (gnc_numeric *)pkey;
/* Compute a new reachable value */
gnc_numeric reachable_value = gnc_numeric_add_fixed(*key, split_value);
reachable_list = g_list_append(reachable_list, g_memdup(&reachable_value, sizeof(gnc_numeric)));
printf(" Sack: found %s, added %s\n", gnc_numeric_to_string(*key), gnc_numeric_to_string(reachable_value));
}
/* Add the value of the split itself to the reachable_list */
reachable_list = g_list_append(reachable_list, g_memdup(&split_value, sizeof(gnc_numeric)));
/* Add everything to the sack, looking out for duplicates */
for (node = reachable_list; node; node = node->next)
{
gnc_numeric *reachable_value = node->data;
Split *toinsert_split = split;
printf(" Reachable value: %s ", gnc_numeric_to_string(*reachable_value));
/* Check if it already exists */
if (g_hash_table_lookup_extended(sack, reachable_value, NULL, NULL))
{
/* If yes, we are in trouble, we reached an amount using two solutions */
toinsert_split = NULL;
printf("dup");
}
g_hash_table_insert (sack, reachable_value, toinsert_split);
printf("\n");
}
g_list_free(reachable_list);
}
else
/* Check solution */
printf("Rebuilding solution ...\n");
while (!gnc_numeric_zero_p(toclear_value))
{
printf(" No solution found.\n");
gtk_label_set_text(data->status_label, "The selected amount cannot be cleared.");
return;
gpointer psplit = NULL;
printf(" Left to clear: %s\n", gnc_numeric_to_string(toclear_value));
if (g_hash_table_lookup_extended(sack, &toclear_value, NULL, &psplit))
{
if (psplit != NULL)
{
/* Cast the gpointer to the kind of pointer we actually need */
Split *split = (Split *)psplit;
toclear_list = g_list_prepend(toclear_list, split);
toclear_value = gnc_numeric_sub_fixed(toclear_value,
xaccSplitGetAmount(split));
printf(" Cleared: %s -> %s\n",
gnc_numeric_to_string(xaccSplitGetAmount(split)),
gnc_numeric_to_string(toclear_value));
}
else
{
/* We couldn't reconstruct the solution */
printf(" Solution not unique.\n");
gtk_label_set_text(data->status_label, "Cannot uniquely clear splits. Found multiple possibilities.");
return;
}
}
else
{
printf(" No solution found.\n");
gtk_label_set_text(data->status_label, "The selected amount cannot be cleared.");
return;
}
}
}
g_hash_table_destroy (sack);
g_hash_table_destroy (sack);
/* Show solution */
printf("Clearing splits:\n");
for (node = toclear_list; node; node = node->next)
{
Split *split = node->data;
char recn;
gnc_numeric value;
/* Show solution */
printf("Clearing splits:\n");
for (node = toclear_list; node; node = node->next)
{
Split *split = node->data;
char recn;
gnc_numeric value;
recn = xaccSplitGetReconcile (split);
value = xaccSplitGetAmount (split);
recn = xaccSplitGetReconcile (split);
value = xaccSplitGetAmount (split);
printf(" %c %s\n", recn, gnc_numeric_to_string(value));
printf(" %c %s\n", recn, gnc_numeric_to_string(value));
xaccSplitSetReconcile (split, CREC);
}
if (toclear_list == 0)
printf(" None\n");
}
if (toclear_list == 0)
printf(" None\n");
/* Free lists */
g_list_free(nc_list);
g_list_free(toclear_list);
/* Free lists */
g_list_free(nc_list);
g_list_free(toclear_list);
/* Close window */
gtk_widget_destroy(data->window);
g_free(data);
/* Close window */
gtk_widget_destroy(data->window);
g_free(data);
}
static void
gnc_autoclear_window_cancel_cb (GtkWidget *widget,
AutoClearWindow *data)
AutoClearWindow *data)
{
/* Close window */
gtk_widget_destroy(data->window);
g_free(data);
/* Close window */
gtk_widget_destroy(data->window);
g_free(data);
}
/********************************************************************\
@@ -284,45 +284,45 @@ gnc_autoclear_window_cancel_cb (GtkWidget *widget,
AutoClearWindow *
autoClearWindow (GtkWidget *parent, Account *account)
{
GtkWidget *dialog, *box, *label, *end_value;
GladeXML *xml;
AutoClearWindow *data;
char *title;
GtkWidget *dialog, *box, *label, *end_value;
GladeXML *xml;
AutoClearWindow *data;
char *title;
data = g_new0 (AutoClearWindow, 1);
data->account = account;
data = g_new0 (AutoClearWindow, 1);
data->account = account;
/* Create the dialog box */
xml = gnc_glade_xml_new ("autoclear.glade", "Auto-clear Start Dialog");
dialog = glade_xml_get_widget (xml, "Auto-clear Start Dialog");
title = gnc_autoclear_make_window_name (account);
gtk_window_set_title(GTK_WINDOW(dialog), title);
g_free (title);
/* Create the dialog box */
xml = gnc_glade_xml_new ("autoclear.glade", "Auto-clear Start Dialog");
dialog = glade_xml_get_widget (xml, "Auto-clear Start Dialog");
title = gnc_autoclear_make_window_name (account);
gtk_window_set_title(GTK_WINDOW(dialog), title);
g_free (title);
/* Add amount edit box */
end_value = gnc_amount_edit_new();
data->end_value = GNC_AMOUNT_EDIT(end_value);
box = glade_xml_get_widget(xml, "end_value_box");
gtk_box_pack_start(GTK_BOX(box), end_value, TRUE, TRUE, 0);
label = glade_xml_get_widget(xml, "end_label");
gtk_label_set_mnemonic_widget(GTK_LABEL(label), end_value);
gtk_widget_grab_focus(GTK_WIDGET(end_value));
/* Add amount edit box */
end_value = gnc_amount_edit_new();
data->end_value = GNC_AMOUNT_EDIT(end_value);
box = glade_xml_get_widget(xml, "end_value_box");
gtk_box_pack_start(GTK_BOX(box), end_value, TRUE, TRUE, 0);
label = glade_xml_get_widget(xml, "end_label");
gtk_label_set_mnemonic_widget(GTK_LABEL(label), end_value);
gtk_widget_grab_focus(GTK_WIDGET(end_value));
data->window = GTK_WIDGET(dialog);
data->window = GTK_WIDGET(dialog);
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
data->ok_button = glade_xml_get_widget(xml, "ok_button");
data->cancel_button = glade_xml_get_widget(xml, "cancel_button");
data->status_label = GTK_LABEL(glade_xml_get_widget(xml, "status_label"));
if (parent != NULL)
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
data->ok_button = glade_xml_get_widget(xml, "ok_button");
data->cancel_button = glade_xml_get_widget(xml, "cancel_button");
data->status_label = GTK_LABEL(glade_xml_get_widget(xml, "status_label"));
g_signal_connect(data->ok_button, "clicked",
G_CALLBACK(gnc_autoclear_window_ok_cb), data);
g_signal_connect(data->end_value, "activate",
G_CALLBACK(gnc_autoclear_window_ok_cb), data);
g_signal_connect(data->cancel_button, "clicked",
G_CALLBACK(gnc_autoclear_window_cancel_cb), data);
g_signal_connect(data->ok_button, "clicked",
G_CALLBACK(gnc_autoclear_window_ok_cb), data);
g_signal_connect(data->end_value, "activate",
G_CALLBACK(gnc_autoclear_window_ok_cb), data);
g_signal_connect(data->cancel_button, "clicked",
G_CALLBACK(gnc_autoclear_window_cancel_cb), data);
return data;
return data;
}

File diff suppressed because it is too large Load Diff