dialog-tax-info.c

00001 /********************************************************************\
00002  * dialog-tax-info.c -- tax information dialog                      *
00003  * Copyright (C) 2001 Gnumatic, Inc.                                *
00004  * Author: Dave Peticolas <dave@krondo.com>                         *
00005  *                                                                  *
00006  * This program is free software; you can redistribute it and/or    *
00007  * modify it under the terms of the GNU General Public License as   *
00008  * published by the Free Software Foundation; either version 2 of   *
00009  * the License, or (at your option) any later version.              *
00010  *                                                                  *
00011  * This program is distributed in the hope that it will be useful,  *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00014  * GNU General Public License for more details.                     *
00015  *                                                                  *
00016  * You should have received a copy of the GNU General Public License*
00017  * along with this program; if not, contact:                        *
00018  *                                                                  *
00019  * Free Software Foundation           Voice:  +1-617-542-5942       *
00020  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00021  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00022 \********************************************************************/
00023 
00024 #include "config.h"
00025 
00026 #include <gtk/gtk.h>
00027 #include <glib/gi18n.h>
00028 #include <libguile.h>
00029 #include "guile-mappings.h"
00030 
00031 #include "Account.h"
00032 #include "gnc-ui-util.h"
00033 #include "dialog-utils.h"
00034 #include "gnc-gconf-utils.h"
00035 #include "gnc-tree-view-account.h"
00036 #include "gnc-component-manager.h"
00037 #include "gnc-session.h"
00038 #include "qof.h"
00039 #include "gnc-ui.h"
00040 
00041 
00042 #define DIALOG_TAX_INFO_CM_CLASS "dialog-tax-info"
00043 #define GCONF_SECTION "dialogs/tax_info"
00044 #define PANED_POSITION "paned_position"
00045 
00046 /* This static indicates the debugging module that this .o belongs to.  */
00047 /* static short module = MOD_GUI; */
00048 
00049 static struct
00050 {
00051   SCM payer_name_source;
00052   SCM form;
00053   SCM description;
00054   SCM help;
00055 
00056   SCM codes;
00057 } getters;
00058 
00059 typedef struct
00060 {
00061   char *code;
00062   char *payer_name_source;
00063   char *form;
00064   char *description;
00065   char *help;
00066 } TXFInfo;
00067 
00068 typedef struct
00069 {
00070   GtkWidget * dialog;
00071 
00072   GtkWidget * account_treeview;
00073   GtkWidget * select_button;
00074 
00075   GtkWidget * tax_related_button;
00076   GtkWidget * txf_category_view;
00077   GtkWidget * txf_help_text;
00078   GtkWidget * current_account_button;
00079   GtkWidget * parent_account_button;
00080 
00081   GList * income_txf_infos;
00082   GList * expense_txf_infos;
00083 
00084   gboolean income;
00085   gboolean changed;
00086 
00087   GNCAccountType account_type;
00088 } TaxInfoDialog;
00089 
00090 
00091 static gboolean getters_initialized = FALSE;
00092 
00093 
00094 static void
00095 initialize_getters (void)
00096 {
00097   if (getters_initialized)
00098     return;
00099 
00100   getters.payer_name_source = scm_c_eval_string ("gnc:txf-get-payer-name-source");
00101   getters.form              = scm_c_eval_string ("gnc:txf-get-form");
00102   getters.description       = scm_c_eval_string ("gnc:txf-get-description");
00103   getters.help              = scm_c_eval_string ("gnc:txf-get-help");
00104 
00105   getters.codes             = scm_c_eval_string ("gnc:txf-get-codes");
00106 
00107   getters_initialized = TRUE;
00108 }
00109 
00110 static void
00111 destroy_txf_info (gpointer data, gpointer user_data)
00112 {
00113   TXFInfo *txf_info = data;
00114 
00115   g_free (txf_info->code);
00116   txf_info->code = NULL;
00117 
00118   g_free (txf_info->payer_name_source);
00119   txf_info->payer_name_source = NULL;
00120 
00121   g_free (txf_info->form);
00122   txf_info->form = NULL;
00123 
00124   g_free (txf_info->description);
00125   txf_info->description = NULL;
00126 
00127   g_free (txf_info->help);
00128   txf_info->help = NULL;
00129 
00130   g_free (txf_info);
00131 }
00132 
00133 static void
00134 destroy_txf_infos (GList *infos)
00135 {
00136   g_list_foreach (infos, destroy_txf_info, NULL);
00137   g_list_free (infos);
00138 }
00139 
00140 static void
00141 gnc_tax_info_set_changed (TaxInfoDialog *ti_dialog, gboolean changed)
00142 {
00143   ti_dialog->changed = changed;
00144 }
00145 
00146 static GList *
00147 load_txf_info (gboolean income)
00148 {
00149   GList *infos = NULL;
00150   SCM category;
00151   SCM codes;
00152 
00153   initialize_getters ();
00154 
00155   category = scm_c_eval_string (income ?
00156                                 "txf-income-categories" :
00157                                 "txf-expense-categories");
00158   if (category == SCM_UNDEFINED)
00159   {
00160     destroy_txf_infos (infos);
00161     return NULL;
00162   }
00163 
00164   codes = scm_call_1 (getters.codes, category);
00165   if (!SCM_LISTP (codes))
00166   {
00167     destroy_txf_infos (infos);
00168     return NULL;
00169   }
00170 
00171   while (!SCM_NULLP (codes))
00172   {
00173     TXFInfo *txf_info;
00174     SCM code_scm;
00175     const gchar *str;
00176     SCM scm;
00177 
00178     code_scm  = SCM_CAR (codes);
00179     codes     = SCM_CDR (codes);
00180 
00181     scm = scm_call_2 (getters.payer_name_source, category, code_scm);
00182     str = SCM_SYMBOL_CHARS (scm);
00183     if (safe_strcmp (str, "not-impl") == 0)
00184     {
00185       continue;
00186     }
00187 
00188     txf_info = g_new0 (TXFInfo, 1);
00189 
00190     if (safe_strcmp (str, "none") == 0)
00191       txf_info->payer_name_source = NULL;
00192     else
00193       txf_info->payer_name_source = g_strdup (str);
00194 
00195     str = SCM_SYMBOLP(code_scm) ? SCM_SYMBOL_CHARS(code_scm) : "";
00196     txf_info->code = g_strdup (str);
00197 
00198     scm = scm_call_2 (getters.form, category, code_scm);
00199     str = SCM_STRINGP(scm) ? SCM_STRING_CHARS(scm) : "";
00200     txf_info->form = g_strdup (str);
00201 
00202     scm = scm_call_2 (getters.description, category, code_scm);
00203     str = SCM_STRINGP(scm) ? SCM_STRING_CHARS(scm) : "";
00204     txf_info->description = g_strdup (str);
00205 
00206     scm = scm_call_2 (getters.help, category, code_scm);
00207     str = SCM_STRINGP(scm) ? SCM_STRING_CHARS(scm) : "";
00208     txf_info->help = g_strdup (str);
00209 
00210     infos = g_list_prepend (infos, txf_info);
00211   }
00212 
00213   return g_list_reverse (infos);
00214 }
00215 
00216 static GList *
00217 tax_infos (TaxInfoDialog *ti_dialog)
00218 {
00219   return
00220     ti_dialog->income ?
00221     ti_dialog->income_txf_infos : ti_dialog->expense_txf_infos;
00222 }
00223 
00224 static void
00225 load_category_list (TaxInfoDialog *ti_dialog)
00226 {
00227   GtkTreeView *view;
00228   GtkListStore *store;
00229   GtkTreeIter iter;
00230   GList *codes;
00231 
00232   view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
00233   store = GTK_LIST_STORE(gtk_tree_view_get_model(view));
00234   g_object_ref(store);
00235   gtk_tree_view_set_model(view, NULL);
00236 
00237   gtk_list_store_clear(store);
00238 
00239   codes = tax_infos (ti_dialog);
00240   for ( ; codes; codes = codes->next)
00241   {
00242     TXFInfo *txf_info = codes->data;
00243 
00244     gtk_list_store_append(store, &iter);
00245     gtk_list_store_set(store, &iter,
00246                        0, txf_info->form,
00247                        1, txf_info->description,
00248                        -1);
00249   }
00250 
00251   gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
00252   g_object_unref(store);
00253 }
00254 
00255 static void
00256 clear_gui (TaxInfoDialog *ti_dialog)
00257 {
00258   GtkTreeView *view;
00259   GtkTreeSelection *selection;
00260 
00261   gtk_toggle_button_set_active
00262     (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button), FALSE);
00263 
00264   view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
00265   selection = gtk_tree_view_get_selection(view);
00266   gtk_tree_selection_unselect_all(selection);
00267 
00268   gtk_toggle_button_set_active
00269     (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
00270 }
00271 
00272 static gboolean
00273 gnc_tax_info_dialog_account_filter_func (Account *account,
00274                                          gpointer data)
00275 {
00276   TaxInfoDialog *dialog = data;
00277 
00278   return xaccAccountGetType (account) == dialog->account_type;
00279 }
00280 
00281 static TXFInfo *
00282 txf_infos_find_code (GList *infos, const char *code)
00283 {
00284   for (; infos; infos = infos->next)
00285   {
00286     TXFInfo *info = infos->data;
00287 
00288     if (safe_strcmp (code, info->code) == 0)
00289       return info;
00290   }
00291 
00292   return NULL;
00293 }
00294 
00295 static void
00296 account_to_gui (TaxInfoDialog *ti_dialog, Account *account)
00297 {
00298   GtkTreeView *view;
00299   GtkTreeSelection *selection;
00300   GtkTreePath *path;
00301   gboolean tax_related;
00302   const char *str;
00303   TXFInfo *info;
00304   GList *infos;
00305   gint index;
00306 
00307   if (!account)
00308   {
00309     clear_gui (ti_dialog);
00310     return;
00311   }
00312 
00313   tax_related = xaccAccountGetTaxRelated (account);
00314   gtk_toggle_button_set_active
00315     (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button), tax_related);
00316 
00317   infos = tax_infos (ti_dialog);
00318 
00319   str = xaccAccountGetTaxUSCode (account);
00320   info = txf_infos_find_code (infos, str);
00321   if (info)
00322     index = g_list_index (infos, info);
00323   else
00324     index = 0;
00325   if (index < 0)
00326     index = 0;
00327 
00328   view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
00329   selection = gtk_tree_view_get_selection(view);
00330   path =  gtk_tree_path_new_from_indices(index, -1);
00331   gtk_tree_selection_select_path(selection, path);
00332   gtk_tree_view_scroll_to_cell(view, path, NULL, FALSE, 0, 0);
00333   gtk_tree_path_free(path);
00334 
00335   str = xaccAccountGetTaxUSPayerNameSource (account);
00336   if (safe_strcmp (str, "parent") == 0)
00337     gtk_toggle_button_set_active
00338       (GTK_TOGGLE_BUTTON (ti_dialog->parent_account_button), TRUE);
00339   else
00340     gtk_toggle_button_set_active
00341       (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
00342 }
00343 
00344 static void
00345 gui_to_accounts (TaxInfoDialog *ti_dialog)
00346 {
00347   GtkTreeView *view;
00348   GtkTreeModel *model;
00349   GtkTreeSelection *selection;
00350   GtkTreePath *path;
00351   GtkTreeIter iter;
00352   gint *indices;
00353   gboolean tax_related;
00354   const char *code;
00355   const char *pns;
00356   GList *accounts;
00357   TXFInfo *info;
00358   GList *infos;
00359   GList *node;
00360 
00361   tax_related = gtk_toggle_button_get_active
00362     (GTK_TOGGLE_BUTTON (ti_dialog->tax_related_button));
00363 
00364   infos = tax_infos (ti_dialog);
00365 
00366   view = GTK_TREE_VIEW(ti_dialog->txf_category_view);
00367   selection = gtk_tree_view_get_selection(view);
00368   if (!gtk_tree_selection_get_selected(selection, &model, &iter))
00369     return;
00370   path = gtk_tree_model_get_path(model, &iter);
00371   indices = gtk_tree_path_get_indices(path);
00372   info = g_list_nth_data (infos, indices[0]);
00373   gtk_tree_path_free(path);
00374   g_return_if_fail (info != NULL);
00375 
00376   code = tax_related ? info->code : NULL;
00377 
00378   if (tax_related && info->payer_name_source)
00379   {
00380     gboolean current;
00381 
00382     current = gtk_toggle_button_get_active
00383       (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button));
00384 
00385     pns = current ? "current" : "parent";
00386   }
00387   else
00388     pns = NULL;
00389 
00390   accounts = gnc_tree_view_account_get_selected_accounts
00391     (GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview));
00392 
00393   for (node = accounts; node; node = node->next)
00394   {
00395     Account *account = node->data;
00396 
00397     xaccAccountBeginEdit (account);
00398 
00399     xaccAccountSetTaxRelated (account, tax_related);
00400     xaccAccountSetTaxUSCode (account, code);
00401     xaccAccountSetTaxUSPayerNameSource (account, pns);
00402 
00403     xaccAccountCommitEdit (account);
00404   }
00405 }
00406 
00407 static void
00408 window_destroy_cb (GtkObject *object, gpointer data)
00409 {
00410   TaxInfoDialog *ti_dialog = data;
00411 
00412   gnc_unregister_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog);
00413 
00414   destroy_txf_infos (ti_dialog->income_txf_infos);
00415   ti_dialog->income_txf_infos = NULL;
00416 
00417   destroy_txf_infos (ti_dialog->expense_txf_infos);
00418   ti_dialog->expense_txf_infos = NULL;
00419 
00420   g_free (ti_dialog);
00421 }
00422 
00423 static void
00424 cursor_changed_cb (GtkWidget *widget, gpointer data)
00425 {
00426   TaxInfoDialog *ti_dialog = data;
00427   GncTreeViewAccount *account_tree;
00428   Account *account;
00429   gint num_children;
00430 
00431   account_tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
00432   account = gnc_tree_view_account_get_cursor_account (account_tree);
00433   if (!account) {
00434     gtk_widget_set_sensitive(ti_dialog->select_button, FALSE);
00435     return;
00436   }
00437 
00438   num_children = gnc_tree_view_account_count_children(account_tree, account);
00439   gtk_widget_set_sensitive(ti_dialog->select_button, num_children > 0);
00440 }
00441 
00442 static void
00443 select_subaccounts_clicked (GtkWidget *widget, gpointer data)
00444 {
00445   TaxInfoDialog *ti_dialog = data;
00446   GncTreeViewAccount *account_tree;
00447   Account *account;
00448 
00449   account_tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
00450   account = gnc_tree_view_account_get_cursor_account (account_tree);
00451   if (!account)
00452     return;
00453 
00454   gnc_tree_view_account_select_subaccounts (account_tree, account);
00455 
00456   gtk_widget_grab_focus (ti_dialog->account_treeview);
00457 }
00458 
00459 static void
00460 gnc_tax_info_dialog_response (GtkDialog *dialog, gint response, gpointer data)
00461 {
00462   TaxInfoDialog *ti_dialog = data;
00463 
00464   if (response == GTK_RESPONSE_OK && ti_dialog->changed)
00465       gui_to_accounts (ti_dialog);
00466 
00467   gnc_close_gui_component_by_data (DIALOG_TAX_INFO_CM_CLASS, ti_dialog);
00468 }
00469 
00470 static void
00471 tax_info_show_income_accounts (TaxInfoDialog *ti_dialog, gboolean show_income)
00472 {
00473   GncTreeViewAccount *tree;
00474   AccountViewInfo info;
00475   GNCAccountType type;
00476   GNCAccountType show_type;
00477 
00478   ti_dialog->income = show_income;
00479 
00480   tree = GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview);
00481   show_type = show_income ? ACCT_TYPE_INCOME : ACCT_TYPE_EXPENSE;
00482 
00483   gnc_tree_view_account_get_view_info (tree, &info);
00484 
00485   for (type = 0; type < NUM_ACCOUNT_TYPES; type++)
00486     info.include_type[type] = (type == show_type);
00487 
00488   gnc_tree_view_account_set_view_info (tree, &info);
00489 
00490   load_category_list (ti_dialog);
00491   cursor_changed_cb(GTK_WIDGET(tree), ti_dialog);
00492 }
00493 
00494 static int
00495 gnc_tax_info_update_accounts (TaxInfoDialog *ti_dialog)
00496 {
00497   GncTreeViewAccount *tree;
00498   GtkTreeSelection* selection;
00499   GtkWidget *label;
00500   GtkWidget *vbox;
00501   int num_accounts;
00502   char *string;
00503 
00504   tree = GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview);
00505   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
00506   num_accounts = gtk_tree_selection_count_selected_rows (selection);
00507 
00508   label = gnc_glade_lookup_widget (ti_dialog->dialog, "num_accounts_label");
00509   vbox = gnc_glade_lookup_widget (ti_dialog->dialog, "tax_info_vbox");
00510 
00511   string = g_strdup_printf ("%d", num_accounts);
00512   gtk_label_set_text (GTK_LABEL (label), string);
00513   g_free (string);
00514 
00515   gtk_widget_set_sensitive (vbox, num_accounts > 0);
00516 
00517   return num_accounts;
00518 }
00519 
00520 static void
00521 gnc_tax_info_income_cb (GtkWidget *w, gpointer data)
00522 {
00523   TaxInfoDialog *ti_dialog = data;
00524   gboolean show_income;
00525 
00526   show_income = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
00527 
00528   tax_info_show_income_accounts (ti_dialog, show_income);
00529 
00530   ti_dialog->account_type = show_income ? ACCT_TYPE_INCOME : ACCT_TYPE_EXPENSE;
00531   gnc_tree_view_account_refilter (GNC_TREE_VIEW_ACCOUNT (ti_dialog->account_treeview));
00532 
00533   gnc_tax_info_update_accounts (ti_dialog);
00534 
00535   clear_gui (ti_dialog);
00536 }
00537 
00538 static void
00539 gnc_tax_info_account_changed_cb (GtkTreeSelection *selection,
00540                                  gpointer data)
00541 {
00542   TaxInfoDialog *ti_dialog = data;
00543   GncTreeViewAccount *view;
00544   GList *accounts;
00545   int num_accounts;
00546 
00547   g_return_if_fail(GTK_IS_TREE_SELECTION(selection));
00548 
00549   num_accounts = gnc_tax_info_update_accounts (ti_dialog);
00550   switch (num_accounts) {
00551    case 0:
00552     clear_gui (ti_dialog);
00553     gnc_tax_info_set_changed (ti_dialog, FALSE);
00554     return;
00555 
00556    case 1:
00557     /* Get the account. This view is set for multiple selection, so we
00558        can only get a list of accounts. */
00559     view = GNC_TREE_VIEW_ACCOUNT(ti_dialog->account_treeview);
00560     accounts = gnc_tree_view_account_get_selected_accounts (view);
00561     account_to_gui (ti_dialog, accounts->data);
00562     g_list_free(accounts);
00563 
00564     gnc_tax_info_set_changed (ti_dialog, FALSE);
00565     break;
00566 
00567    default:
00568     gnc_tax_info_set_changed (ti_dialog, TRUE);
00569     return;
00570   }
00571 }
00572 
00573 static void
00574 txf_code_select_row_cb (GtkTreeSelection *selection,
00575                         gpointer user_data)
00576 {
00577   TaxInfoDialog *ti_dialog = user_data;
00578   GtkTreeModel *model;
00579   GtkTreePath *path;
00580   GtkTreeIter iter;
00581   gint *indices;
00582   TXFInfo *txf_info;
00583   GtkAdjustment *adj;
00584   GtkWidget *scroll;
00585   GtkWidget *vbox;
00586   GtkTextBuffer *tb;
00587   const char *text;
00588 
00589   if (!gtk_tree_selection_get_selected(selection, &model, &iter))
00590     return;
00591   path = gtk_tree_model_get_path(model, &iter);
00592   indices = gtk_tree_path_get_indices(path);
00593   txf_info = g_list_nth_data (tax_infos (ti_dialog), indices[0]);
00594   gtk_tree_path_free(path);
00595 
00596   tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ti_dialog->txf_help_text));
00597 
00598   text = (txf_info && txf_info->help) ? txf_info->help : "";
00599   gtk_text_buffer_set_text (tb, text, -1);
00600 
00601   scroll = gnc_glade_lookup_widget (GTK_WIDGET (ti_dialog->dialog),
00602                                     "help_scroll");
00603 
00604   adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (scroll));
00605   gtk_adjustment_set_value (adj, 0.0);
00606 
00607   vbox = gnc_glade_lookup_widget (GTK_WIDGET (ti_dialog->dialog),
00608                                    "payer_name_source_vbox");
00609 
00610   if (txf_info && txf_info->payer_name_source)
00611   {
00612     gboolean current;
00613 
00614     gtk_widget_set_sensitive (vbox, TRUE);
00615 
00616     current = (strcmp ("current", txf_info->payer_name_source) == 0);
00617 
00618     if (current)
00619       gtk_toggle_button_set_active
00620         (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
00621     else
00622       gtk_toggle_button_set_active
00623         (GTK_TOGGLE_BUTTON (ti_dialog->parent_account_button), TRUE);
00624   }
00625   else
00626   {
00627     gtk_widget_set_sensitive (vbox, FALSE);
00628     gtk_toggle_button_set_active
00629       (GTK_TOGGLE_BUTTON (ti_dialog->current_account_button), TRUE);
00630   }
00631 
00632   gnc_tax_info_set_changed (ti_dialog, TRUE);
00633 }
00634 
00635 static void
00636 tax_related_toggled_cb (GtkToggleButton *togglebutton,
00637                         gpointer user_data)
00638 {
00639   TaxInfoDialog *ti_dialog = user_data;
00640   GtkWidget *vbox;
00641   gboolean on;
00642 
00643   on = gtk_toggle_button_get_active (togglebutton);
00644 
00645   vbox = gnc_glade_lookup_widget (GTK_WIDGET (togglebutton),
00646                                    "txf_categories_vbox");
00647   gtk_widget_set_sensitive (vbox, on);
00648 
00649   gnc_tax_info_set_changed (ti_dialog, TRUE);
00650 }
00651 
00652 static void
00653 current_account_toggled_cb (GtkToggleButton *togglebutton,
00654                             gpointer user_data)
00655 {
00656   TaxInfoDialog *ti_dialog = user_data;
00657 
00658   gnc_tax_info_set_changed (ti_dialog, TRUE);
00659 }
00660 
00661 static void
00662 gnc_tax_info_dialog_create (GtkWidget * parent, TaxInfoDialog *ti_dialog)
00663 {
00664   GtkWidget *dialog;
00665   GtkObject *tido;
00666   GladeXML  *xml;
00667   GtkTreeView *tree_view;
00668   GtkTreeSelection *selection;
00669   GtkWidget *label;
00670 
00671   xml = gnc_glade_xml_new ("tax.glade", "Tax Information Dialog");
00672 
00673   dialog = glade_xml_get_widget (xml, "Tax Information Dialog");
00674   ti_dialog->dialog = dialog;
00675   tido = GTK_OBJECT (dialog);
00676 
00677   ti_dialog->account_type = ACCT_TYPE_EXPENSE;
00678   ti_dialog->income_txf_infos = load_txf_info (TRUE);
00679   ti_dialog->expense_txf_infos = load_txf_info (FALSE);
00680 
00681   g_signal_connect (G_OBJECT (dialog), "response",
00682                     G_CALLBACK (gnc_tax_info_dialog_response), ti_dialog);
00683 
00684   g_signal_connect (G_OBJECT (dialog), "destroy",
00685                     G_CALLBACK (window_destroy_cb), ti_dialog);
00686 
00687   /* parent */
00688   if (parent != NULL)
00689     gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
00690 
00691   /* default to ok */
00692   gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
00693 
00694   /* tax information */
00695   {
00696     GtkListStore *store;
00697     GtkTreeViewColumn *column;
00698     GtkCellRenderer *renderer; 
00699     GtkWidget *button;
00700     GtkWidget *text;
00701 
00702     button = glade_xml_get_widget (xml, "tax_related_button");
00703     ti_dialog->tax_related_button = button;
00704 
00705     g_signal_connect (G_OBJECT (button), "toggled",
00706                       G_CALLBACK  (tax_related_toggled_cb), ti_dialog);
00707 
00708     text = glade_xml_get_widget (xml, "txf_help_text");
00709     gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD);
00710     ti_dialog->txf_help_text = text;
00711 
00712     tree_view = GTK_TREE_VIEW(glade_xml_get_widget(xml, "txf_category_view"));
00713     store =  gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
00714     gtk_tree_view_set_model(tree_view, GTK_TREE_MODEL(store));
00715     g_object_unref(store);
00716     renderer = gtk_cell_renderer_text_new();
00717     column = gtk_tree_view_column_new_with_attributes
00718       (_("Form"), renderer, "text", 0, NULL);
00719     gtk_tree_view_append_column(tree_view, GTK_TREE_VIEW_COLUMN(column));
00720     renderer = gtk_cell_renderer_text_new();
00721     column = gtk_tree_view_column_new_with_attributes
00722       (_("Description"), renderer, "text", 1, NULL);
00723     gtk_tree_view_append_column(tree_view, GTK_TREE_VIEW_COLUMN(column));
00724     ti_dialog->txf_category_view = GTK_WIDGET(tree_view);
00725 
00726     selection = gtk_tree_view_get_selection(tree_view);
00727     g_signal_connect (G_OBJECT (selection), "changed",
00728                       G_CALLBACK  (txf_code_select_row_cb), ti_dialog);
00729 
00730     label = glade_xml_get_widget(xml, "txf_category_label");
00731     gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));
00732 
00733     button = glade_xml_get_widget (xml, "current_account_button");
00734     ti_dialog->current_account_button = button;
00735 
00736     button = glade_xml_get_widget (xml, "parent_account_button");
00737     ti_dialog->parent_account_button = button;
00738 
00739     g_signal_connect (G_OBJECT (button), "toggled",
00740                       G_CALLBACK  (current_account_toggled_cb),
00741                         ti_dialog);
00742   }
00743 
00744   /* account tree */
00745   {
00746     GtkWidget *income_radio, *expense_radio, *box;
00747 
00748     box = glade_xml_get_widget (xml, "account_scroll");
00749     tree_view = gnc_tree_view_account_new (FALSE);
00750     gnc_tree_view_account_set_filter (GNC_TREE_VIEW_ACCOUNT(tree_view), 
00751                                       gnc_tax_info_dialog_account_filter_func,
00752                                       ti_dialog, NULL);
00753     ti_dialog->account_treeview = GTK_WIDGET(tree_view);
00754 
00755     selection = gtk_tree_view_get_selection (tree_view);
00756     gtk_tree_selection_set_mode (selection, GTK_SELECTION_EXTENDED);
00757     g_signal_connect (G_OBJECT (selection), "changed",
00758                       G_CALLBACK (gnc_tax_info_account_changed_cb),
00759                       ti_dialog);
00760 
00761     gtk_widget_show (ti_dialog->account_treeview);
00762     gtk_container_add (GTK_CONTAINER (box), ti_dialog->account_treeview);
00763 
00764     label = glade_xml_get_widget(xml, "accounts_label");
00765     gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(tree_view));
00766 
00767     income_radio = glade_xml_get_widget (xml, "income_radio");
00768     expense_radio = glade_xml_get_widget (xml, "expense_radio");
00769     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(expense_radio), TRUE);
00770     g_signal_connect (G_OBJECT (income_radio), "toggled",
00771                       G_CALLBACK  (gnc_tax_info_income_cb),
00772                         ti_dialog);
00773     //   gtk_button_clicked (GtkButton *button);
00774  }
00775 
00776   /* select subaccounts button */
00777   {
00778     GtkWidget *button;
00779 
00780     button = glade_xml_get_widget (xml, "select_subaccounts_button");
00781     ti_dialog->select_button = button;
00782 
00783     g_signal_connect (G_OBJECT (button), "clicked",
00784                       G_CALLBACK  (select_subaccounts_clicked),
00785                       ti_dialog);
00786     g_signal_connect (G_OBJECT (ti_dialog->account_treeview), "cursor_changed",
00787                       G_CALLBACK  (cursor_changed_cb),
00788                       ti_dialog);
00789   }
00790 
00791   tax_info_show_income_accounts (ti_dialog, FALSE);
00792   gnc_tax_info_update_accounts (ti_dialog);
00793   clear_gui (ti_dialog);
00794   gnc_tax_info_set_changed (ti_dialog, FALSE);
00795 
00796   gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(ti_dialog->dialog));
00797 
00798   if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_SAVE_GEOMETRY, NULL)) {
00799     GtkWidget *paned = glade_xml_get_widget(xml, "paned");
00800     gint position = gnc_gconf_get_int(GCONF_SECTION, PANED_POSITION, NULL);
00801     gtk_paned_set_position(GTK_PANED(paned), position);
00802   }
00803 }
00804 
00805 static void
00806 close_handler (gpointer user_data)
00807 {
00808   TaxInfoDialog *ti_dialog = user_data;
00809 
00810   if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_SAVE_GEOMETRY, NULL)) {
00811     GtkWidget *paned = gnc_glade_lookup_widget(ti_dialog->dialog, "paned");
00812     gnc_gconf_set_int(GCONF_SECTION, PANED_POSITION,
00813                       gtk_paned_get_position(GTK_PANED(paned)), NULL);
00814   }
00815 
00816   gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(ti_dialog->dialog));
00817   gtk_widget_destroy (ti_dialog->dialog);
00818 }
00819 
00820 static void
00821 refresh_handler (GHashTable *changes, gpointer user_data)
00822 {
00823   TaxInfoDialog *ti_dialog = user_data;
00824 
00825 /*  gnc_account_tree_refresh (GNC_ACCOUNT_TREE (ti_dialog->account_tree));*/
00826 
00827   gnc_tax_info_update_accounts (ti_dialog);
00828 }
00829 
00830 /********************************************************************\
00831  * gnc_tax_info_dialog                                              *
00832  *   opens up a window to set account tax information               *
00833  *                                                                  * 
00834  * Args:   parent  - the parent of the window to be created         *
00835  * Return: nothing                                                  *
00836 \********************************************************************/
00837 void
00838 gnc_tax_info_dialog (GtkWidget * parent)
00839 {
00840   TaxInfoDialog *ti_dialog;
00841   gint component_id;
00842 
00843   ti_dialog = g_new0 (TaxInfoDialog, 1);
00844 
00845   gnc_tax_info_dialog_create (parent, ti_dialog);
00846 
00847   component_id = gnc_register_gui_component (DIALOG_TAX_INFO_CM_CLASS,
00848                                              refresh_handler, close_handler,
00849                                              ti_dialog);
00850   gnc_gui_component_set_session (component_id, gnc_get_current_session ());
00851 
00852   gnc_gui_component_watch_entity_type (component_id,
00853                                        GNC_ID_ACCOUNT,
00854                                        QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
00855 
00856   gtk_widget_grab_focus (ti_dialog->account_treeview);
00857 
00858   gtk_widget_show (ti_dialog->dialog);
00859 }

Generated on Sun Sep 7 05:07:06 2008 for GnuCash by  doxygen 1.5.2