lot-viewer.c

00001 /*******************************************************************\
00002  * lot-viewer.c -- a basic lot viewer for GnuCash                   *
00003  * Copyright (C) 2003 Linas Vepstas <linas@linas.org>               *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00020  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00021  *                                                                  *
00022 \********************************************************************/
00023 
00024 /* XXX todo: The button "view lot in register" is not implemented.
00025  *   it needs to open register window showing only the splits in the 
00026  *     given lot ... 
00027  *
00028  * XXX clist should be probably be removed and replaced by the gnc_query_list
00029  */
00030 
00031 #include "config.h"
00032 
00033 #include <gtk/gtk.h>
00034 #include <glib/gi18n.h>
00035 
00036 #include "Account.h"
00037 #include "cap-gains.h"
00038 #include "gnc-commodity.h"
00039 #include "qof.h"
00040 #include "gnc-lot.h"
00041 #include "Scrub3.h"
00042 #include "Transaction.h"
00043 
00044 #include "dialog-utils.h"
00045 #include "lot-viewer.h"
00046 #include "gnc-component-manager.h"
00047 #include "gnc-ui-util.h"
00048 #include "gnc-gconf-utils.h"
00049 #include "misc-gnome-utils.h"
00050 
00051 #define LOT_VIEWER_CM_CLASS "lot-viewer"
00052 
00053 enum lot_cols {
00054   LOT_COL_OPEN = 0,
00055   LOT_COL_CLOSE,
00056   LOT_COL_TITLE,
00057   LOT_COL_BALN,
00058   LOT_COL_GAINS,
00059   LOT_COL_PNTR,
00060   NUM_LOT_COLS
00061 };
00062 
00063 #define RESPONSE_VIEW          1
00064 #define RESPONSE_DELETE        2
00065 #define RESPONSE_SCRUB_LOT     3
00066 #define RESPONSE_SCRUB_ACCOUNT 4
00067 #define RESPONSE_NEW_LOT       5
00068 
00069 #define GCONF_SECTION "dialogs/lot_viewer"
00070 #define GCONF_KEY_HPOSITION "hpane_position"
00071 #define GCONF_KEY_VPOSITION "vpane_position"
00072 
00073 struct _GNCLotViewer 
00074 {
00075    GtkWidget     * window;
00076 #ifdef LOTS_READY_FOR_SHOWTIME
00077    GtkButton     * regview_button;
00078 #endif
00079    GtkButton     * delete_button;
00080    GtkButton     * scrub_lot_button;
00081    GtkButton     * new_lot_button;
00082    GtkPaned      * lot_hpaned;
00083    GtkPaned      * lot_vpaned;
00084    GtkTreeView   * lot_view;
00085    GtkListStore  * lot_store;
00086    GtkTextView   * lot_notes;
00087    GtkEntry      * title_entry;
00088    GtkCList      * mini_clist;
00089 
00090    Account       * account;
00091    GNCLot        * selected_lot;
00092 };
00093 
00094 static void gnc_lot_viewer_fill (GNCLotViewer *lv);
00095 
00096 /* ======================================================================== */
00097 /* Callback prototypes */
00098 
00099 void lv_title_entry_changed_cb (GtkEntry *ent, gpointer user_data);
00100 void lv_response_cb (GtkDialog *dialog, gint response, gpointer data);
00101 void lv_window_destroy_cb (GtkObject *object, gpointer user_data);
00102 void lv_paned_notify_cb (GObject *gobject,
00103                          GParamSpec *pspec,
00104                          gpointer user_data);
00105 
00106 /* ======================================================================== */
00107 /* Put the splits into the split clist */
00108 
00109 #define MINI_DATE_COL 0 
00110 #define MINI_NUM_COL  1
00111 #define MINI_DESC_COL 2 
00112 #define MINI_AMNT_COL 3 
00113 #define MINI_VALU_COL 4 
00114 #define MINI_GAIN_COL 5
00115 #define MINI_BALN_COL 6 
00116 #define MINI_NUM_COLS 7
00117 
00118 static void
00119 lv_show_splits (GNCLotViewer *lv)
00120 {
00121    GNCLot *lot = lv->selected_lot;
00122    SplitList *split_list, *node;
00123    gnc_numeric baln = gnc_numeric_zero();
00124 
00125    if (NULL == lot) return;
00126 
00127 /* qof_event_suspend();  XXX remove when xaccSplitGetCapGains() fixed */
00128    gtk_clist_freeze (lv->mini_clist);
00129    gtk_clist_clear (lv->mini_clist);
00130    split_list = gnc_lot_get_split_list (lot);
00131    for (node = split_list; node; node=node->next)
00132    {
00133       Split *split = node->data;
00134       char dbuff[MAX_DATE_LENGTH];
00135       char amtbuff[200];
00136       char valbuff[200];
00137       char gainbuff[200];
00138       char balnbuff[200];
00139       gnc_commodity *currency;
00140       Transaction *trans = xaccSplitGetParent (split);
00141       time_t date = xaccTransGetDate (trans);
00142       gnc_numeric amnt, valu, gains;
00143       const char *row_vals[MINI_NUM_COLS];
00144       int row;
00145 
00146       /* Do not show gains splits */
00147       if (gnc_numeric_zero_p (xaccSplitGetAmount(split))) continue;
00148 
00149       /* Opening date */
00150       qof_print_date_buff (dbuff, MAX_DATE_LENGTH, date);
00151       row_vals[MINI_DATE_COL] = dbuff;
00152 
00153       row_vals[MINI_NUM_COL]  = xaccTransGetNum (trans);
00154       row_vals[MINI_DESC_COL] = xaccTransGetDescription (trans);
00155 
00156       /* Amount */
00157       amnt = xaccSplitGetAmount (split);
00158       xaccSPrintAmount (amtbuff, amnt,
00159                  gnc_account_print_info (lv->account, TRUE));
00160       row_vals[MINI_AMNT_COL] = amtbuff;
00161 
00162       /* Value. Invert the sign on the first, opening entry. */
00163       currency = xaccTransGetCurrency (trans);
00164       valu = xaccSplitGetValue (split);
00165       if (node != split_list)
00166       {
00167          valu = gnc_numeric_neg (valu);
00168       }
00169       xaccSPrintAmount (valbuff, valu,
00170                  gnc_commodity_print_info (currency, TRUE));
00171       row_vals[MINI_VALU_COL] = valbuff;
00172 
00173       /* Gains. Blank if none. */
00174       gains = xaccSplitGetCapGains (split);
00175       if (gnc_numeric_zero_p(gains))
00176       {
00177          gainbuff[0] = 0;
00178       }
00179       else
00180       {
00181          xaccSPrintAmount (gainbuff, gains,
00182                  gnc_commodity_print_info (currency, TRUE));
00183       }
00184       row_vals[MINI_GAIN_COL] = gainbuff;
00185 
00186       /* Balance of Gains */
00187       baln = gnc_numeric_add_fixed (baln, amnt);
00188       if (gnc_numeric_zero_p(baln))
00189       {
00190          balnbuff[0] = 0;
00191       }
00192       else
00193       {
00194          xaccSPrintAmount (balnbuff, baln,
00195                  gnc_account_print_info (lv->account, TRUE));
00196       }
00197       row_vals[MINI_BALN_COL] = balnbuff;
00198 
00199       /* Self-reference */
00200       row = gtk_clist_append (lv->mini_clist, (char **)row_vals);
00201       gtk_clist_set_selectable (lv->mini_clist, row, FALSE);
00202    }
00203    gtk_clist_thaw (lv->mini_clist);
00204 /* qof_event_resume();  XXX remove when xaccSplitGetCapGains() fixed */
00205 }
00206 
00207 /* ======================================================================== */
00208 
00209 static void
00210 lv_clear_splits (GNCLotViewer *lv)
00211 {
00212    gtk_clist_clear (lv->mini_clist);
00213 }
00214 
00215 static void 
00216 lv_save_current_row (GNCLotViewer *lv)
00217 {
00218    GNCLot *lot = lv->selected_lot;
00219    const char * str;
00220    char * notes;
00221 
00222    if (lot)
00223    {
00224       /* Get the title, save_the_title */
00225       str = gtk_entry_get_text (lv->title_entry);
00226       gnc_lot_set_title (lot, str);
00227 
00228       /* Get the notes, save the notes */
00229       notes = xxxgtk_textview_get_text (lv->lot_notes);
00230       gnc_lot_set_notes (lot, notes);
00231       g_free(notes);
00232    }
00233 }
00234 
00235 /* ======================================================================== */
00236 /* Callback for selecting a row the the list-of-list clist */
00237 
00238 static void 
00239 lv_select_row (GNCLotViewer *lv,
00240                GNCLot       *lot)
00241 {
00242    const char * str;
00243 
00244    lv_save_current_row (lv);
00245 
00246    str = gnc_lot_get_title (lot);
00247    if (!str) str = "";
00248    gtk_entry_set_text (lv->title_entry, str);
00249    gtk_editable_set_editable (GTK_EDITABLE(lv->title_entry), TRUE);
00250    
00251    /* Set the notes field */
00252    str = gnc_lot_get_notes (lot);
00253    if (!str) str = "";
00254    xxxgtk_textview_set_text (lv->lot_notes, str);
00255    gtk_text_view_set_editable (lv->lot_notes, TRUE);
00256 
00257    /* Don't set until end, to avoid recursion in gtkentry "changed" cb. */
00258    lv->selected_lot = lot;
00259    lv_show_splits (lv);
00260 
00261 #ifdef LOTS_READY_FOR_SHOWTIME
00262    gtk_widget_set_sensitive(GTK_WIDGET(lv->regview_button), TRUE);
00263 #endif
00264    gtk_widget_set_sensitive(GTK_WIDGET(lv->delete_button), TRUE);
00265    gtk_widget_set_sensitive(GTK_WIDGET(lv->scrub_lot_button), TRUE);
00266 }
00267 
00268 /* ======================================================================== */
00269 
00270 static void 
00271 lv_unset_lot (GNCLotViewer *lv)
00272 {
00273    /* Set immediately, to avoid recursion in gtkentry "changed" cb. */
00274    lv->selected_lot = NULL;
00275 
00276    /* Blank the title widget */
00277    gtk_entry_set_text (lv->title_entry, "");
00278    gtk_editable_set_editable (GTK_EDITABLE(lv->title_entry), FALSE);
00279 
00280    /* Blank the notes area */
00281    xxxgtk_textview_set_text (lv->lot_notes, "");
00282    gtk_text_view_set_editable (lv->lot_notes, FALSE);
00283 
00284    /* Erase the mini-view area */
00285    lv_clear_splits (lv);
00286 
00287 #ifdef LOTS_READY_FOR_SHOWTIME
00288    gtk_widget_set_sensitive(GTK_WIDGET(lv->regview_button), FALSE);
00289 #endif
00290    gtk_widget_set_sensitive(GTK_WIDGET(lv->delete_button), FALSE);
00291    gtk_widget_set_sensitive(GTK_WIDGET(lv->scrub_lot_button), FALSE);
00292 }
00293 
00294 /* ======================================================================== */
00295 /* Callback for un-selecting a row the the list-of-list clist */
00296 
00297 static void 
00298 lv_unselect_row (GNCLotViewer *lv)
00299 {
00300    lv_save_current_row (lv);
00301 
00302    lv_unset_lot (lv);
00303 }
00304 
00305 static void
00306 lv_selection_changed_cb (GtkTreeSelection *selection,
00307                          GNCLotViewer *lv)  
00308 {
00309    GNCLot *lot;
00310    GtkTreeModel *model;
00311    GtkTreeIter iter;
00312 
00313    if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
00314      gtk_tree_model_get(model, &iter, LOT_COL_PNTR, &lot, -1);
00315      lv_select_row(lv, lot);
00316    } else {
00317      lv_unselect_row(lv);
00318    }
00319 }
00320 
00321 
00322 /* ======================================================================== */
00323 /* Callback when user types a new lot title into the entry widget */
00324 
00325 void
00326 lv_title_entry_changed_cb (GtkEntry *ent, gpointer user_data)
00327 {
00328    GNCLotViewer *lv = user_data;
00329    GtkTreeModel *model;
00330    GtkTreeIter iter;
00331    GtkTreeSelection *selection;
00332    const char * title;
00333    title = gtk_entry_get_text (lv->title_entry);
00334 
00335    selection = gtk_tree_view_get_selection(lv->lot_view);
00336    if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
00337      gtk_list_store_set(GTK_LIST_STORE(model), &iter, LOT_COL_TITLE, title, -1);
00338    }
00339 }
00340 
00341 /* ======================================================================== */
00342 /* Get the realized gains for this lot.  This routine or a varient of it
00343  * should probably be moved to gnc-lot.c. 
00344  * The conceptual difficulty here is that this works only if all of the 
00345  * realized gains in the lot are of the 
00346  */
00347 
00348 static gnc_commodity *
00349 find_first_currency (GNCLot *lot)
00350 {
00351    SplitList *split_list, *node;
00352 
00353    split_list = gnc_lot_get_split_list(lot); 
00354    for (node = split_list; node; node=node->next)
00355    {
00356       Split *s = node->data;
00357       Transaction *trans;
00358       if (FALSE == gnc_numeric_zero_p(xaccSplitGetAmount(s))) continue;
00359       trans = xaccSplitGetParent (s);
00360       return xaccTransGetCurrency (trans);
00361    }
00362    return NULL;
00363 }
00364 
00365 static gnc_numeric
00366 get_realized_gains (GNCLot *lot, gnc_commodity *currency)
00367 {
00368    gnc_numeric zero = gnc_numeric_zero();
00369    gnc_numeric gains = zero;
00370    SplitList *split_list, *node;
00371 
00372    if (!currency) return zero;
00373 
00374    split_list = gnc_lot_get_split_list(lot); 
00375    for (node = split_list; node; node=node->next)
00376    {
00377       Split *s = node->data;
00378       Transaction *trans;
00379 
00380       if (FALSE == gnc_numeric_zero_p(xaccSplitGetAmount(s))) continue;
00381       trans = xaccSplitGetParent (s);
00382       if (FALSE == gnc_commodity_equal (xaccTransGetCurrency(trans), currency)) continue;
00383 
00384       gains = gnc_numeric_add (gains, xaccSplitGetValue (s), GNC_DENOM_AUTO, GNC_DENOM_FIXED);
00385    }
00386    return gains;
00387 }
00388 
00389 /* ======================================================================== */
00390 
00391 static void
00392 gnc_lot_viewer_fill (GNCLotViewer *lv)
00393 {
00394    LotList *lot_list, *node;
00395    GNCLot *this_lot, *selected_lot = NULL;
00396    GtkListStore *store;
00397    GtkTreeModel *model;
00398    GtkTreeIter iter;
00399    GtkTreeSelection *selection;
00400    gboolean found = FALSE;
00401 
00402    lot_list = xaccAccountGetLotList (lv->account);
00403 
00404    selection = gtk_tree_view_get_selection(lv->lot_view);
00405    if (gtk_tree_selection_get_selected (selection, &model, &iter))
00406      gtk_tree_model_get(model, &iter, LOT_COL_PNTR, &selected_lot, -1);
00407 
00408    /* Crazy. Should update in place if possible. */
00409    gtk_list_store_clear (lv->lot_store);
00410 
00411    for (node = lot_list; node; node=node->next)
00412    {
00413       char obuff[MAX_DATE_LENGTH];
00414       char cbuff[MAX_DATE_LENGTH];
00415       char baln_buff[200];
00416       char gain_buff[200];
00417       GNCLot *lot = node->data;
00418       Split *esplit = gnc_lot_get_earliest_split (lot);
00419       Transaction *etrans = xaccSplitGetParent (esplit);
00420       time_t open_date = xaccTransGetDate (etrans);
00421       gnc_numeric amt_baln = gnc_lot_get_balance (lot);
00422       gnc_commodity *currency = find_first_currency (lot);
00423       gnc_numeric gains_baln = get_realized_gains (lot, currency);
00424 
00425       store = lv->lot_store;
00426       gtk_list_store_append(store, &iter);
00427 
00428       /* Opening date */
00429       qof_print_date_buff (obuff, MAX_DATE_LENGTH, open_date);
00430       gtk_list_store_set(store, &iter, LOT_COL_OPEN, obuff, -1);
00431 
00432       /* Closing date */
00433       if (gnc_lot_is_closed (lot))
00434       {
00435          Split *fsplit = gnc_lot_get_latest_split (lot);
00436          Transaction *ftrans = xaccSplitGetParent (fsplit);
00437          time_t close_date = xaccTransGetDate (ftrans);
00438    
00439          qof_print_date_buff (cbuff, MAX_DATE_LENGTH, close_date);
00440          gtk_list_store_set(store, &iter, LOT_COL_CLOSE, cbuff, -1);
00441       }
00442       else
00443       {
00444         gtk_list_store_set(store, &iter, LOT_COL_CLOSE, _("Open"), -1);
00445       }
00446 
00447       /* Title */
00448       gtk_list_store_set(store, &iter, LOT_COL_TITLE, gnc_lot_get_title(lot), -1);
00449       
00450       /* Amount */
00451       xaccSPrintAmount (baln_buff, amt_baln, 
00452                  gnc_account_print_info (lv->account, TRUE));
00453       gtk_list_store_set(store, &iter, LOT_COL_BALN, baln_buff, -1);
00454 
00455       /* Capital Gains/Losses Appreciation/Depreciation */
00456       xaccSPrintAmount (gain_buff, gains_baln, 
00457                  gnc_commodity_print_info (currency, TRUE));
00458       gtk_list_store_set(store, &iter, LOT_COL_GAINS, gain_buff, -1);
00459 
00460       /* Self-reference */
00461       gtk_list_store_set(store, &iter, LOT_COL_PNTR, lot, -1);
00462    }
00463    g_list_free(lot_list);
00464 
00465    /* re-select the row that the user had previously selected, 
00466     * if possible. */
00467    if (selected_lot) {
00468      model = GTK_TREE_MODEL(lv->lot_store);
00469      if (gtk_tree_model_get_iter_first(model, &iter)) {
00470        do {
00471          gtk_tree_model_get(model, &iter, LOT_COL_PNTR, &this_lot, -1);
00472          if (this_lot == selected_lot) {
00473            gtk_tree_selection_select_iter(selection, &iter);
00474            found = TRUE;
00475            break;
00476          }
00477        } while (gtk_tree_model_iter_next(model, &iter));
00478      }
00479    }
00480 
00481    if (!found)
00482      gtk_tree_selection_unselect_all(selection);
00483 }
00484 
00485 /* ======================================================================== */
00486 
00487 static void
00488 lv_refresh_handler (GHashTable *changes, gpointer user_data)
00489 {
00490    GNCLotViewer *lv = user_data;
00491    gnc_lot_viewer_fill (lv);
00492    lv_show_splits (lv);
00493 }
00494 
00495 static void
00496 lv_close_handler (gpointer user_data)
00497 {
00498    GNCLotViewer *lv = user_data;
00499    GNCLot *lot = lv->selected_lot;
00500 
00501    lv_save_current_row (lv);
00502 
00503    gnc_save_window_size(GCONF_SECTION, GTK_WINDOW(lv->window));
00504    gtk_widget_destroy (lv->window);
00505 }
00506 
00507 void
00508 lv_window_destroy_cb (GtkObject *object, gpointer user_data)
00509 {
00510    GNCLotViewer *lv = user_data;
00511    gnc_close_gui_component_by_data (LOT_VIEWER_CM_CLASS, lv);
00512    gnc_unregister_gui_component_by_data (LOT_VIEWER_CM_CLASS, lv);
00513    g_free (lv);
00514 }
00515                                                                                 
00516 
00517 /* ======================================================================== */
00518 /* Divider moved */
00519 
00520 void
00521 lv_paned_notify_cb (GObject *gobject,
00522                      GParamSpec *pspec,
00523                      gpointer user_data)
00524 {
00525    const gchar *param_name;
00526    gint value;
00527 
00528    param_name = g_param_spec_get_name(pspec);
00529    if (strcmp(param_name, "position") != 0)
00530      return;
00531    g_object_get(gobject, "position", &value, NULL);
00532 
00533    if (GTK_IS_HPANED(gobject)) {
00534      gnc_gconf_set_int(GCONF_SECTION, GCONF_KEY_HPOSITION, value, NULL);
00535    } else {
00536      gnc_gconf_set_int(GCONF_SECTION, GCONF_KEY_VPOSITION, value, NULL);
00537    }
00538 }
00539 
00540 /* ======================================================================== */
00541 /* Any button was pressed */
00542 
00543 void
00544 lv_response_cb (GtkDialog *dialog, gint response, gpointer data)
00545 {
00546    GNCLotViewer *lv = data;
00547    GNCLot *lot = lv->selected_lot;
00548 
00549    switch (response) {
00550    case GTK_RESPONSE_CLOSE:
00551      lv_close_handler(lv);
00552      return;
00553 
00554    case RESPONSE_VIEW:
00555      if (NULL == lot)
00556        return; 
00557      printf ("duude UNIMPLEMENTED: need to disply register showing only this one lot \n");
00558      break;
00559 
00560    case RESPONSE_DELETE:
00561      if (NULL == lot)
00562        return; 
00563      xaccAccountRemoveLot (gnc_lot_get_account(lot), lot);
00564      gnc_lot_destroy (lot);
00565      lv_unset_lot (lv);
00566      gnc_lot_viewer_fill (lv);
00567      break;
00568 
00569    case RESPONSE_SCRUB_LOT:
00570      if (NULL == lot)
00571        return; 
00572      xaccScrubLot (lot);
00573      gnc_lot_viewer_fill (lv);
00574      lv_show_splits (lv);
00575      break;
00576 
00577    case RESPONSE_SCRUB_ACCOUNT:
00578      xaccAccountScrubLots (lv->account);
00579      gnc_lot_viewer_fill (lv);
00580      lv_show_splits (lv);
00581      break;
00582 
00583    case RESPONSE_NEW_LOT:
00584      lv_save_current_row (lv);
00585      lot = gnc_lot_make_default (lv->account);
00586      xaccAccountInsertLot (lv->account, lot);
00587      break;
00588    }
00589 }
00590 
00591 /* ======================================================================== */
00592 
00593 static void
00594 lv_init_lot_view (GNCLotViewer *lv)
00595 {
00596   GtkTreeView *view;
00597   GtkListStore *store;
00598   GtkTreeViewColumn *column;
00599   GtkTreeSelection *selection;
00600   GtkCellRenderer *renderer;
00601 
00602   g_return_if_fail(GTK_IS_TREE_VIEW(lv->lot_view));
00603 
00604   view = lv->lot_view;
00605   store = gtk_list_store_new(NUM_LOT_COLS, G_TYPE_STRING, G_TYPE_STRING,
00606                              G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
00607                              G_TYPE_POINTER);
00608   gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
00609   g_object_unref(store);
00610   lv->lot_store = store;
00611 
00612   /* Set up the columns */
00613   renderer = gtk_cell_renderer_text_new();
00614   column = gtk_tree_view_column_new_with_attributes(_("Opened"), renderer,
00615                                                     "text", LOT_COL_OPEN, NULL);
00616   gtk_tree_view_append_column(view, column);
00617 
00618   renderer = gtk_cell_renderer_text_new();
00619   column = gtk_tree_view_column_new_with_attributes(_("Closed"), renderer,
00620                                                     "text", LOT_COL_CLOSE, NULL);
00621   gtk_tree_view_append_column(view, column);
00622 
00623   renderer = gtk_cell_renderer_text_new();
00624   column = gtk_tree_view_column_new_with_attributes(_("Title"), renderer,
00625                                                     "text", LOT_COL_TITLE, NULL);
00626   gtk_tree_view_append_column(view, column);
00627 
00628   renderer = gtk_cell_renderer_text_new();
00629   column = gtk_tree_view_column_new_with_attributes(_("Balance"), renderer,
00630                                                     "text", LOT_COL_BALN, NULL);
00631   gtk_tree_view_append_column(view, column);
00632 
00633   renderer = gtk_cell_renderer_text_new();
00634   column = gtk_tree_view_column_new_with_attributes(_("Gains"), renderer,
00635                                                     "text", LOT_COL_GAINS, NULL);
00636   gtk_tree_view_append_column(view, column);
00637 
00638   /* Set up the selection callbacks */
00639   selection =  gtk_tree_view_get_selection(view);
00640   g_signal_connect(selection, "changed",
00641                    G_CALLBACK(lv_selection_changed_cb), lv);
00642 }
00643 
00644 /* ======================================================================== */
00645 
00646 static void
00647 lv_create (GNCLotViewer *lv)
00648 {
00649    GladeXML *xml;
00650    char win_title[251];
00651    gint position;
00652 
00653    xml = gnc_glade_xml_new ("lots.glade", "Lot Viewer Window");
00654    lv->window = glade_xml_get_widget (xml, "Lot Viewer Window");
00655 
00656    snprintf (win_title, 250, _("Lots in Account %s"),
00657                   xaccAccountGetName(lv->account));
00658    gtk_window_set_title (GTK_WINDOW (lv->window), win_title);
00659 
00660 #ifdef LOTS_READY_FOR_SHOWTIME
00661    lv->regview_button = GTK_BUTTON(glade_xml_get_widget (xml, "regview button"));
00662 #endif
00663    lv->delete_button = GTK_BUTTON(glade_xml_get_widget (xml, "delete button"));
00664    lv->scrub_lot_button = GTK_BUTTON(glade_xml_get_widget (xml, "scrub lot button"));
00665    lv->new_lot_button = GTK_BUTTON(glade_xml_get_widget (xml, "new lot button"));
00666 
00667    lv->lot_view = GTK_TREE_VIEW(glade_xml_get_widget (xml, "lot view"));
00668    lv_init_lot_view(lv);
00669    lv->lot_notes = GTK_TEXT_VIEW(glade_xml_get_widget (xml, "lot notes text"));
00670    lv->title_entry = GTK_ENTRY (glade_xml_get_widget (xml, "lot title entry"));
00671 
00672    lv->lot_vpaned = GTK_PANED (glade_xml_get_widget (xml, "lot vpaned"));
00673    position = gnc_gconf_get_int(GCONF_SECTION, GCONF_KEY_VPOSITION, NULL);
00674    if (position)
00675      gtk_paned_set_position (lv->lot_vpaned, position);
00676 
00677    lv->lot_hpaned = GTK_PANED (glade_xml_get_widget (xml, "lot hpaned"));
00678    position = gnc_gconf_get_int(GCONF_SECTION, GCONF_KEY_HPOSITION, NULL);
00679    if (position)
00680      gtk_paned_set_position (lv->lot_hpaned, position);
00681 
00682    lv->mini_clist = GTK_CLIST(glade_xml_get_widget (xml, "mini clist"));
00683 
00684    lv->selected_lot = NULL;
00685     
00686    /* Setup signals */
00687    glade_xml_signal_autoconnect_full( xml,
00688                                      gnc_glade_autoconnect_full_func,
00689                                      lv);
00690 
00691    gnc_restore_window_size(GCONF_SECTION, GTK_WINDOW(lv->window));
00692 }
00693 
00694 /* ======================================================================== */
00695 
00696 GNCLotViewer * 
00697 gnc_lot_viewer_dialog (Account *account)
00698 {
00699    GNCLotViewer *lv;
00700    gint component_id;
00701 
00702    if (!account) return NULL;
00703 
00704    lv = g_new0 (GNCLotViewer, 1);
00705    lv->account = account;
00706    lv_create (lv);
00707    gnc_lot_viewer_fill (lv);
00708 
00709    component_id = gnc_register_gui_component (LOT_VIEWER_CM_CLASS,
00710                                               lv_refresh_handler,
00711                                               lv_close_handler,
00712                                               lv);
00713 
00714    gnc_gui_component_watch_entity_type (component_id,
00715                GNC_ID_LOT,
00716                QOF_EVENT_CREATE | QOF_EVENT_ADD | QOF_EVENT_REMOVE | QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
00717 
00718    gtk_widget_show_all (lv->window);
00719    gnc_window_adjust_for_screen (GTK_WINDOW(lv->window));
00720 
00721    return lv;
00722 }
00723 
00724 /* ============================ END OF FILE =============================== */

Generated on Fri Jul 25 05:05:41 2008 for GnuCash by  doxygen 1.5.2