[grisbi-cvs] grisbi/src balance_estimate_tab.c, 1.29, 1.30 gsb_fyear.c, 1.10, 1.11 gsb_fyear.h, 1.7, 1.8

Pierre Biava pbiava at users.sourceforge.net
Mon Jan 18 23:33:54 CET 2010


Update of /cvsroot/grisbi/grisbi/src
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv5527/src

Modified Files:
	balance_estimate_tab.c gsb_fyear.c gsb_fyear.h 
Log Message:
modifications of the Balance estimate module

Index: gsb_fyear.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_fyear.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- gsb_fyear.h	3 Oct 2009 22:14:56 -0000	1.7
+++ gsb_fyear.h	18 Jan 2010 22:33:52 -0000	1.8
@@ -1,6 +1,12 @@
 #ifndef _GSB_FYEAR_H
 #define _GSB_FYEAR_H (1)
 
+enum fyear_list_columns {
+    FYEAR_COL_NAME = 0,
+    FYEAR_COL_NUMBER,
+    FYEAR_COL_VIEW,
+};
+
 
 /* START_INCLUDE_H */
 /* END_INCLUDE_H */
@@ -14,5 +20,11 @@
 gboolean gsb_fyear_set_combobox_history ( GtkWidget *combo_box,
                         gint fyear_number );
 gboolean gsb_fyear_update_fyear_list ( void );
+gboolean gsb_fyear_hide_iter_by_name ( GtkTreeModel *model, gchar *name );
+GtkWidget *gsb_fyear_make_combobox_new ( GtkTreeModel *model,
+                        gboolean set_automatic );
+gboolean gsb_fyear_update_fyear_list_new ( GtkTreeModel *model,
+                        GtkTreeModel *model_filter,
+                        gchar *title );
 /* END_DECLARATION */
 #endif

Index: gsb_fyear.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_fyear.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- gsb_fyear.c	3 Oct 2009 22:14:56 -0000	1.10
+++ gsb_fyear.c	18 Jan 2010 22:33:52 -0000	1.11
@@ -48,13 +48,6 @@
 static GtkTreeModel *fyear_model_filter;
 
 
-enum fyear_list_columns {
-    FYEAR_COL_NAME = 0,
-    FYEAR_COL_NUMBER,
-    FYEAR_COL_VIEW,
-};
-
-
 /*START_STATIC*/
 static gboolean gsb_fyear_create_combobox_store ( void );
 /*END_STATIC*/
@@ -92,13 +85,32 @@
  * */
 GtkWidget *gsb_fyear_make_combobox ( gboolean set_automatic )
 {
-    GtkCellRenderer *renderer;
     GtkWidget *combo_box;
 
     if (!fyear_model_filter)
         gsb_fyear_create_combobox_store ();
 
-    combo_box = gtk_combo_box_new_with_model ( GTK_TREE_MODEL ( fyear_model_filter ) );
+    combo_box = gsb_fyear_make_combobox_new ( fyear_model_filter, set_automatic );
+
+    return (combo_box);
+}
+
+
+/**
+ * create and return a combobox with the financial years
+ *
+ * \param model for the combobox
+ * \param set_automatic if TRUE, will show the choice "Automatic"
+ *
+ * \return a widget combobox or NULL
+ * */
+GtkWidget *gsb_fyear_make_combobox_new ( GtkTreeModel *model,
+                        gboolean set_automatic )
+{
+    GtkCellRenderer *renderer;
+    GtkWidget *combo_box;
+
+    combo_box = gtk_combo_box_new_with_model ( GTK_TREE_MODEL ( model ) );
 
     renderer = gtk_cell_renderer_text_new ();
     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
@@ -107,15 +119,14 @@
                         "text", FYEAR_COL_NAME,
                         NULL);
 
-    gtk_combo_box_set_active ( GTK_COMBO_BOX (combo_box), 0 );
     /* show or hide the automatic line */
     gsb_fyear_set_automatic ( set_automatic );
+    gtk_combo_box_set_active ( GTK_COMBO_BOX (combo_box), 0 );
 
     return (combo_box);
 }
 
 
-
 /**
  * set the combobox on the fyear given in param
  * if the fyear exists but is not showed normally, we show it because it's for
@@ -252,22 +263,43 @@
  */
 gboolean gsb_fyear_update_fyear_list ( void )
 {
+    gsb_fyear_update_fyear_list_new ( fyear_model, fyear_model_filter, "Automatic" );
+
+    return FALSE;
+}
+
+
+/**
+ * update the list of the financial years, wich change all
+ * the current combobox content
+ * set the first row with title with 0 as number
+ *
+ * \param model
+ * \param model_filter
+ * \param title
+ *
+ * \return FALSE
+ */
+gboolean gsb_fyear_update_fyear_list_new ( GtkTreeModel *model,
+                        GtkTreeModel *model_filter,
+                        gchar *title )
+{
     GSList *list_tmp;
     GtkTreeIter iter;
 
     /* if no filter, thats because not created, but don't create here
      * because we can come here without needed of fyear button */
-    if ( !fyear_model_filter )
+    if ( !model_filter )
         return FALSE;
 
-    gtk_list_store_clear (GTK_LIST_STORE ( fyear_model ) );
+    gtk_list_store_clear (GTK_LIST_STORE ( model ) );
 
     /* put at the beginning 'Automatic' wich mean at the validation of
      * the transaction, the fyear will take the value of the date */
-    gtk_list_store_append ( GTK_LIST_STORE (fyear_model), &iter );
-    gtk_list_store_set ( GTK_LIST_STORE (fyear_model),
+    gtk_list_store_append ( GTK_LIST_STORE ( model ), &iter );
+    gtk_list_store_set ( GTK_LIST_STORE ( model ),
                         &iter,
-                        FYEAR_COL_NAME, _("Automatic"),
+                        FYEAR_COL_NAME, _(title),
                         FYEAR_COL_NUMBER, 0,
                         FYEAR_COL_VIEW, TRUE,
                         -1 );
@@ -282,12 +314,12 @@
 
         fyear_number = gsb_data_fyear_get_no_fyear (list_tmp -> data);
 
-        gtk_list_store_append ( GTK_LIST_STORE (fyear_model), &iter );
-        gtk_list_store_set ( GTK_LIST_STORE (fyear_model),
+        gtk_list_store_append ( GTK_LIST_STORE ( model ), &iter );
+        gtk_list_store_set ( GTK_LIST_STORE ( model ),
                             &iter,
                             FYEAR_COL_NAME, gsb_data_fyear_get_name ( fyear_number ),
                             FYEAR_COL_NUMBER, fyear_number,
-                            FYEAR_COL_VIEW, gsb_data_fyear_get_form_show (fyear_number),
+                            FYEAR_COL_VIEW, gsb_data_fyear_get_form_show ( fyear_number ),
                             -1 );
         list_tmp = list_tmp -> next;
     }
@@ -322,6 +354,47 @@
 
     return TRUE;
 }
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gboolean gsb_fyear_hide_iter_by_name ( GtkTreeModel *model, gchar *name )
+{
+    GtkTreeIter iter;
+    gint result;
+
+    result = gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ),
+					     &iter );
+    while (result)
+    {
+        gchar *value;
+        gboolean show;
+
+        gtk_tree_model_get ( GTK_TREE_MODEL ( model ),
+                        &iter,
+                        FYEAR_COL_NAME, &value,
+                        FYEAR_COL_VIEW, &show,
+                        -1 );
+
+        if ( g_utf8_collate ( value, name ) == 0 )
+        {
+            if ( show )
+                gtk_list_store_set ( GTK_LIST_STORE ( model ),
+                        &iter,
+                        FYEAR_COL_VIEW, FALSE,
+                        -1 );
+            return TRUE;
+        }
+        result = gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ),
+                            &iter );
+    }
+    return FALSE;
+}
+
 /* Local Variables: */
 /* c-basic-offset: 4 */
 /* End: */

Index: balance_estimate_tab.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/balance_estimate_tab.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- balance_estimate_tab.c	18 Jan 2010 19:13:40 -0000	1.29
+++ balance_estimate_tab.c	18 Jan 2010 22:33:52 -0000	1.30
@@ -44,9 +44,11 @@
 #include "./gsb_data_account.h"
 #include "./gsb_data_budget.h"
 #include "./gsb_data_category.h"
+#include "./gsb_data_fyear.h"
 #include "./gsb_data_payee.h"
 #include "./gsb_data_scheduled.h"
 #include "./gsb_data_transaction.h"
+#include "./gsb_fyear.h"
 #include "./gsb_real.h"
 #include "./gsb_scheduler.h"
 #include "./gsb_transactions_list_sort.h"
@@ -105,6 +107,8 @@
 static void bet_estimate_populate_div_model ( gpointer key,
                         gpointer value,
                         gpointer user_data);
+static gboolean bet_fyear_create_combobox_store ( void );
+static gint bet_fyear_get_fyear_from_combobox ( GtkWidget *combo_box );
 static SBR *initialise_struct_bet_range ( void );
 static SH *initialise_struct_historical ( void );
 static void free_struct_bet_range ( SBR *sbr );
@@ -160,9 +164,23 @@
 };
 
 
-/* the notebook of the bet */
+/**
+ * the notebook of the bet 
+ * */
 static GtkWidget *bet_container = NULL;
 
+/**
+ * this is a tree model filter with 3 columns :
+ * the name, the number and a boolean to show it or not
+ * */
+static GtkTreeModel *bet_fyear_model;
+
+/**
+ * this is a tree model filter from fyear_model_filter wich
+ * show only the financial years wich must be showed
+ * */
+static GtkTreeModel *bet_fyear_model_filter;
+
 
 /*
  * bet_create_balance_estimate_tab
@@ -893,34 +911,6 @@
  * */
 void bet_historical_fyear_clicked ( GtkWidget *combo, gpointer data )
 {
-    //~ GtkTreeViewColumn *column;
-    //~ const gchar *name;
-    //~ gchar *title;
-
-    //~ name = gtk_widget_get_name ( GTK_WIDGET ( togglebutton ) );
-
-    //~ if ( g_strcmp0 ( name, "button_1" ) == 0 )
-    //~ {
-        //~ ptr_div = &gsb_data_transaction_get_category_number;
-        //~ ptr_sub_div = &gsb_data_transaction_get_sub_category_number;
-        //~ ptr_div_name = &gsb_data_category_get_name;
-        //~ title = g_strdup ( _("Category") );
-    //~ }
-    //~ else
-    //~ {
-        //~ ptr_div = &gsb_data_transaction_get_budgetary_number;
-        //~ ptr_sub_div = &gsb_data_transaction_get_sub_budgetary_number;
-        //~ ptr_div_name = gsb_data_budget_get_name;
-        //~ title = g_strdup ( _("Budgetary line") );
-    //~ }
-
-    //~ column = g_object_get_data ( G_OBJECT ( bet_container ),
-                        //~ "historical_column_source" );
-    //~ gtk_tree_view_column_set_title ( GTK_TREE_VIEW_COLUMN ( column ), title );
-
-    if ( etat.modification_fichier == 0 )
-        modification_fichier ( TRUE );
-
     bet_estimate_populate_historical_data ( );
 }
 
@@ -1192,6 +1182,8 @@
     GtkWidget *hbox;
     GtkWidget *button_1, *button_2;
     GtkWidget *tree_view;
+    gchar *str_year;
+    gint year;
 
     widget = gtk_label_new(_("Historical data"));
     page = gtk_vbox_new ( FALSE, 5 );
@@ -1241,21 +1233,28 @@
     ptr_sub_div = &gsb_data_transaction_get_sub_category_number;
     ptr_div_name = &gsb_data_category_get_name;
 
-    /* vréation du sélecteur de périod */
-    widget = gsb_fyear_make_combobox ( TRUE );
-	gtk_widget_set_tooltip_text ( GTK_WIDGET ( widget ),
-					  SPACIFY(_("Choose the financial year or 12 months rolling") ) );
-    g_signal_connect ( G_OBJECT ( widget ),
-                        "changed",
-                        G_CALLBACK (bet_historical_fyear_clicked),
-                        NULL );
-    g_object_set_data ( G_OBJECT ( notebook ), "bet_historical_fyear", widget );
-    gtk_box_pack_start ( GTK_BOX ( hbox ), widget, FALSE, FALSE, 5) ;
+    /* création du sélecteur de périod */
+    if ( bet_fyear_create_combobox_store ( ) )
+    {
+        widget = gsb_fyear_make_combobox_new ( bet_fyear_model_filter, TRUE );
+        gtk_widget_set_tooltip_text ( GTK_WIDGET ( widget ),
+                          SPACIFY(_("Choose the financial year or 12 months rolling") ) );
+        g_signal_connect ( G_OBJECT ( widget ),
+                            "changed",
+                            G_CALLBACK (bet_historical_fyear_clicked),
+                            NULL );
+        g_object_set_data ( G_OBJECT ( notebook ), "bet_historical_fyear", widget );
+        gtk_box_pack_start ( GTK_BOX ( hbox ), widget, FALSE, FALSE, 5);
 
+        /* hide the present financial year */
+        year = g_date_get_year ( gdate_today ( ) );
+        str_year = utils_str_itoa ( year );
+        gsb_fyear_hide_iter_by_name ( bet_fyear_model, str_year );
+        g_free ( str_year );
+    }
     /* création de la liste des données */
     tree_view = bet_estimate_get_historical_data ( page );
     g_object_set_data ( G_OBJECT ( notebook ), "bet_historical_treeview", tree_view );
-    bet_estimate_populate_historical_data ( );
 
     gtk_widget_show_all ( page );
 }
@@ -1519,6 +1518,8 @@
                         _("Period"), cell,
                         "text", SPP_HISTORICAL_PERIOD_COLUMN,
                         NULL);
+    g_object_set (cell, "xalign", 0.5, NULL);
+
     gtk_tree_view_column_set_alignment ( column, 0.5 );
     gtk_tree_view_append_column ( GTK_TREE_VIEW ( tree_view ),
                         GTK_TREE_VIEW_COLUMN ( column ) );
@@ -1590,11 +1591,13 @@
 void bet_estimate_populate_historical_data ( void )
 {
     GtkWidget *tree_view;
+    GtkWidget *combo;
     GtkTreeIter iter;
     GtkTreeModel *model;
     GtkTreeSelection *tree_selection;
     gchar *account_name = NULL;
     gint selected_account;
+    gint fyear_number;
     GDate *date_min;
     GDate *date_max;
     GSList* tmp_list;
@@ -1623,11 +1626,24 @@
     gtk_tree_store_clear ( GTK_TREE_STORE ( model ) );
 
     /* calculate date_min and date_max */
-    date_min = gdate_today ( );
-    g_date_subtract_years ( date_min, 1 );
-    date_max = gdate_today ( );
-    g_date_subtract_days ( date_max, 1 );
-
+    combo = g_object_get_data ( G_OBJECT ( bet_container ), "bet_historical_fyear" );
+    fyear_number = bet_fyear_get_fyear_from_combobox ( combo );
+    if ( fyear_number == 0 )
+    {
+        date_min = gdate_today ( );
+        g_date_subtract_years ( date_min, 1 );
+        date_max = gdate_today ( );
+        g_date_subtract_days ( date_max, 1 );
+        g_object_set_data ( G_OBJECT ( bet_container ), "bet_historical_period",
+                g_strdup ( _("12 months rolling") ) );
+    }
+    else
+    {
+        date_min = gsb_data_fyear_get_beginning_date ( fyear_number );
+        date_max = gsb_data_fyear_get_end_date ( fyear_number );
+        g_object_set_data ( G_OBJECT ( bet_container ), "bet_historical_period",
+                g_strdup ( gsb_data_fyear_get_name ( fyear_number ) ) );
+    }
     list_div = g_hash_table_new_full ( g_int_hash,
                         g_int_equal,
                         NULL,
@@ -1778,11 +1794,13 @@
     gchar *div_name = NULL;
     gchar *str_balance;
     gchar *str_average;
+    gchar *titre;
     gsb_real period = { 12, 0 };
 
     div = sh -> div;
     div_name = ptr_div_name ( div, 0, FALSE );
 
+    titre = g_object_get_data ( G_OBJECT ( bet_container ), "bet_historical_period" );
     str_balance = gsb_real_get_string_with_currency ( sbr -> current_balance, 
                         gsb_data_account_get_currency ( sh -> account_nb ), TRUE );
     str_average = gsb_real_get_string_with_currency (
@@ -1793,7 +1811,7 @@
     gtk_tree_store_set ( GTK_TREE_STORE ( model ),
                         &parent,
                         SPP_HISTORICAL_DESC_COLUMN, div_name,
-                        SPP_HISTORICAL_PERIOD_COLUMN, "12 months rolling",
+                        SPP_HISTORICAL_PERIOD_COLUMN, titre,
                         SPP_HISTORICAL_BALANCE_COLUMN, str_balance,
                         SPP_HISTORICAL_AVERAGE_COLUMN, str_average,
                         -1);
@@ -1832,7 +1850,7 @@
         gtk_tree_store_set ( GTK_TREE_STORE ( model ),
                         &fils,
                         SPP_HISTORICAL_DESC_COLUMN, div_name,
-                        SPP_HISTORICAL_PERIOD_COLUMN, "12 months rolling",
+                        SPP_HISTORICAL_PERIOD_COLUMN, titre,
                         SPP_HISTORICAL_BALANCE_COLUMN, str_balance,
                         SPP_HISTORICAL_AVERAGE_COLUMN, str_average,
                         -1);
@@ -1911,9 +1929,67 @@
 
 
 /**
+ * create and fill the list store of the fyear
+ * come here mean that fyear_model_filter is NULL
+ *
+ * \param
+ *
+ * \return TRUE ok, FALSE problem
+ * */
+gboolean bet_fyear_create_combobox_store ( void )
+{
+    gchar *titre;
+
+    /* the fyear list store, contains 3 columns :
+     * FYEAR_COL_NAME : the name of the fyear
+     * FYEAR_COL_NUMBER : the number of the fyear
+     * FYEAR_COL_VIEW : it tha fyear should be showed */
+
+    titre = g_strdup ( _("12 months rolling") );
+    bet_fyear_model = GTK_TREE_MODEL ( gtk_list_store_new ( 3,
+                        G_TYPE_STRING,
+                        G_TYPE_INT,
+                        G_TYPE_BOOLEAN ));
+    bet_fyear_model_filter = gtk_tree_model_filter_new ( bet_fyear_model, NULL );
+    gtk_tree_model_filter_set_visible_column ( GTK_TREE_MODEL_FILTER (
+                        bet_fyear_model_filter ),
+                        FYEAR_COL_VIEW );
+    gsb_fyear_update_fyear_list_new ( bet_fyear_model,
+                        bet_fyear_model_filter,
+                        titre );
+    g_free ( titre );
+
+    return TRUE;
+}
+
+
+/**
+ *
+ *
+ *
+ *
+ * */
+gint bet_fyear_get_fyear_from_combobox ( GtkWidget *combo_box )
+{
+    gint fyear_number = 0;
+    GtkTreeIter iter;
+
+    if ( gtk_combo_box_get_active_iter ( GTK_COMBO_BOX ( combo_box ), &iter ) )
+    {
+
+        gtk_tree_model_get ( GTK_TREE_MODEL ( bet_fyear_model_filter ),
+                        &iter,
+                        FYEAR_COL_NUMBER, &fyear_number,
+                        -1 );
+    }
+
+    return fyear_number;
+}
+/**
  *
  *
  *
  *
  * */
+
 #endif /* ENABLE_BALANCE_ESTIMATE */



More information about the cvs mailing list