[grisbi-devel] [PATCH 2/2] Fixes a bug of updating when creating a report as payee of a gtk_combofix

pbiava pierre.biava at nerim.net
Sun Apr 14 21:21:16 CEST 2013


---
 src/etats_config.c    |   3 +-
 src/etats_onglet.c    |   5 +-
 src/gsb_form_widget.c |  19 +++--
 src/gsb_form_widget.h |   3 +-
 src/gtk_combofix.c    | 219 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gtk_combofix.h    |   4 +
 src/import.c          |   6 --
 src/navigation.c      |   8 +-
 8 files changed, 244 insertions(+), 23 deletions(-)

diff --git a/src/etats_config.c b/src/etats_config.c
index 23e61ae..6962bfe 100644
--- a/src/etats_config.c
+++ b/src/etats_config.c
@@ -1901,7 +1901,8 @@ void recuperation_info_perso_etat ( void )
     }
 
     /* update the payee combofix in the form, to add that report if asked */
-    gsb_form_widget_update_payee_combofix ();
+    if ( gsb_data_report_get_append_in_payee ( current_report_number ) )
+        gsb_form_widget_update_payee_combofix ( current_report_number, TRUE );
 
     gsb_file_set_modified ( TRUE );
     /* on réaffiche l'état */
diff --git a/src/etats_onglet.c b/src/etats_onglet.c
index 13fd88b..c832bbf 100644
--- a/src/etats_onglet.c
+++ b/src/etats_onglet.c
@@ -967,12 +967,11 @@ void efface_etat ( void )
         return;
 
    /* remove the report */
+    /* First update reports list in navigation. */
+    gsb_gui_navigation_remove_report ( current_report_number);
 
     gsb_data_report_remove ( current_report_number );
 
-    /* Update reports list in navigation. */
-    gsb_gui_navigation_remove_report ( current_report_number);
-
     gsb_gui_unsensitive_report_widgets ();
 
     gsb_file_set_modified ( TRUE );
diff --git a/src/gsb_form_widget.c b/src/gsb_form_widget.c
index 3e4aa95..d506060 100644
--- a/src/gsb_form_widget.c
+++ b/src/gsb_form_widget.c
@@ -44,6 +44,7 @@
 #include "gsb_data_category.h"
 #include "gsb_data_form.h"
 #include "gsb_data_payee.h"
+#include "gsb_data_report.h"
 #include "gsb_form.h"
 #include "gsb_form_transaction.h"
 #include "gsb_fyear.h"
@@ -1263,18 +1264,24 @@ gboolean gsb_form_widget_amount_entry_validate ( gint element_number )
 
 
 /**
- * update the payee combofix in the form with the current list of payee
+ * update the payee combofix in the form with the current current report
  *
- * \param
+ * \param report_number
+ * \param sens              FALSE remove report TRUE add report
  *
  * \return FALSE
  * */
-gboolean gsb_form_widget_update_payee_combofix ( void )
+gboolean gsb_form_widget_update_payee_combofix ( gint report_number,
+                        gint sens )
 {
-    if ( gsb_data_form_check_for_value ( TRANSACTION_FORM_PARTY ))
-    gtk_combofix_set_list ( GTK_COMBOFIX ( gsb_form_widget_get_widget
+    if ( sens )
+        gtk_combofix_append_report (  GTK_COMBOFIX ( gsb_form_widget_get_widget
+                        (TRANSACTION_FORM_PARTY)),
+                        gsb_data_report_get_report_name ( report_number ) );
+    else
+        gtk_combofix_remove_report ( GTK_COMBOFIX ( gsb_form_widget_get_widget
                         (TRANSACTION_FORM_PARTY)),
-                        gsb_data_payee_get_name_and_report_list ());
+                        gsb_data_report_get_report_name ( report_number ) );
 
     return FALSE;
 }
diff --git a/src/gsb_form_widget.h b/src/gsb_form_widget.h
index 8998516..7693d82 100644
--- a/src/gsb_form_widget.h
+++ b/src/gsb_form_widget.h
@@ -45,6 +45,7 @@ gint gsb_form_widget_next_element ( gint account_number,
 void gsb_form_widget_set_empty ( GtkWidget *entry,
                     gboolean empty );
 void gsb_form_widget_set_focus ( gint element_number );
-gboolean gsb_form_widget_update_payee_combofix ( void );
+gboolean gsb_form_widget_update_payee_combofix ( gint report_number,
+                        gint sens );
 /* END_DECLARATION */
 #endif
diff --git a/src/gtk_combofix.c b/src/gtk_combofix.c
index e3cb602..3cd8de7 100644
--- a/src/gtk_combofix.c
+++ b/src/gtk_combofix.c
@@ -153,7 +153,7 @@ enum combofix_columns {
     COMBOFIX_COL_VISIBLE_STRING = 0,    /* string : what we see in the combofix */
     COMBOFIX_COL_REAL_STRING,           /* string : what we set in the entry when selecting something */
     COMBOFIX_COL_VISIBLE,               /* boolean : if that line has to be showed */
-    COMBOFIX_COL_LIST_NUMBER,           /* int : the number of the list 1, 2 ou 3 (CREDIT DEBIT SPECIAL) */
+    COMBOFIX_COL_LIST_NUMBER,           /* int : the number of the list 0, 1 ou 2 (CREDIT DEBIT SPECIAL) */
     COMBOFIX_COL_SEPARATOR,             /* TRUE : if this is a separator */
     COMBOFIX_N_COLUMNS,
 };
@@ -168,8 +168,94 @@ enum combofix_key_direction {
 /*START_EXTERN*/
 /*END_EXTERN*/
 
+/* *********************** the first part contains the static functions ******************************************** */
+/**
+* supprime le séparateur pour les états comme tiers
+*
+* \param model
+* \param iter_parent
+*
+* \return the position of parent_iter
+* */
+static void gtk_combofix_remove_for_report ( GtkTreeModel *model,
+                        GtkTreeIter *iter_parent )
+{
+    GtkTreeIter iter;
+    gboolean separator;
+
+    gtk_tree_model_get_iter_first (  GTK_TREE_MODEL( model ), &iter );
+    do
+    {
+        gtk_tree_model_get ( GTK_TREE_MODEL( model ), &iter,
+                        COMBOFIX_COL_SEPARATOR, &separator,
+			            -1 );
+        if ( separator )
+        {
+            break;
+        }
+    }
+    while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL( model ), &iter ) );
+
+    gtk_tree_store_remove ( GTK_TREE_STORE ( model ), iter_parent );
+    gtk_tree_store_remove ( GTK_TREE_STORE ( model ), &iter );
+}
+
+
+/**
+* vérifie si il existe un séparateur, l'ajoute si nécessaire
+*
+* \param model
+* \param iter_parent
+*
+* \return the position of parent_iter
+* */
+static gboolean gtk_combofix_search_for_report ( GtkTreeModel *model,
+                        GtkTreeIter *iter_parent )
+{
+    GtkTreeIter iter;
+    gchar *tmp_str;
+    gboolean separator;
+
+    gtk_tree_model_get_iter_first (  GTK_TREE_MODEL( model ), &iter );
+    do
+    {
+        gtk_tree_model_get ( GTK_TREE_MODEL( model ), &iter,
+                        COMBOFIX_COL_SEPARATOR, &separator,
+			            -1 );
+
+        if ( separator )
+        {
+            gtk_tree_model_iter_next ( GTK_TREE_MODEL( model ), &iter );
+            iter_parent = &iter;
+
+            return FALSE;
+        }
+    }
+    while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL( model ), &iter ) );
+
+    gtk_tree_store_append ( GTK_TREE_STORE ( model ), &iter, NULL );
+    gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+                        &iter,
+                        COMBOFIX_COL_LIST_NUMBER, 0,
+                        COMBOFIX_COL_SEPARATOR, TRUE,
+                        -1 );
+
+    tmp_str = g_strdup ( _("Report") );
+    gtk_tree_store_append ( GTK_TREE_STORE ( model ), &iter, NULL );
+    gtk_tree_store_set ( GTK_TREE_STORE ( model ),
+                        &iter,
+                        COMBOFIX_COL_VISIBLE_STRING, tmp_str,
+                        COMBOFIX_COL_REAL_STRING, tmp_str,
+                        COMBOFIX_COL_VISIBLE, TRUE,
+                        COMBOFIX_COL_LIST_NUMBER, 1,
+                        -1 );
+    g_free ( tmp_str );
+
+    return TRUE;
+}
 
-/* *********************** the first part contains all the extern functions ******************************************** */
+
+/* *********************** the second part contains all the extern functions ******************************************** */
 
 /**
  * create a combofix, with several list set one after the others
@@ -497,6 +583,45 @@ void gtk_combofix_append_text ( GtkComboFix *combofix, const gchar *text )
 
 
 /**
+* append a report as payee in a combofix
+*
+* \param combofix
+* \param report_name    the name of report
+*
+* \return
+* */
+void gtk_combofix_append_report ( GtkComboFix *combofix,
+                        const gchar *report_name )
+{
+    GtkComboFixPrivate *priv;
+    GtkTreeIter iter_parent;
+    gchar *tmp_str;
+    gchar *tmp_str2;
+
+    g_return_if_fail ( combofix );
+    g_return_if_fail ( GTK_IS_COMBOFIX ( combofix ) );
+
+    if ( !report_name && strlen ( report_name ) == 0 )
+        return;
+
+    priv = combofix->priv;
+
+    /* on cherche la partie etats on l'ajoute si nécessaire */
+    if ( gtk_combofix_search_for_report ( GTK_TREE_MODEL ( priv->store ), &iter_parent ) )
+        priv -> visible_items++;
+
+    /* on ajoute l'état dans la liste des tiers */
+    tmp_str = g_strdup ( _("Report") );
+    tmp_str2 = g_strconcat ( tmp_str, " : ", report_name, NULL );
+    gtk_combofix_fill_iter_child ( priv->store, &iter_parent, report_name, tmp_str2, 1 );
+    priv -> visible_items++;
+
+    g_free ( tmp_str );
+    g_free ( tmp_str2 );
+}
+
+
+/**
 * remove a line in a combofix
 *
 * \param combofix text
@@ -550,6 +675,92 @@ void gtk_combofix_remove_text ( GtkComboFix *combofix, const gchar *text )
 
 
 /**
+* remove a report in a payee combofix
+*
+* \param combofix
+* \param report_number
+*
+* \return
+* */
+void gtk_combofix_remove_report ( GtkComboFix *combofix,
+                        const gchar *report_name )
+{
+    GtkComboFixPrivate *priv;
+    GtkTreeIter iter;
+    gchar *tmp_str;
+    gchar *tmp_str2;
+    gboolean valid;
+
+    /* on récupère le nom de l'état */
+    tmp_str = g_strdup ( _("Report") );
+    tmp_str2 = g_strconcat ( tmp_str, " : ", report_name, NULL );
+    g_free ( tmp_str );
+
+    priv = combofix->priv;
+    valid = gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( priv->store ), &iter);
+
+    while ( valid )
+    {
+        gboolean separator;
+
+        gtk_tree_model_get ( GTK_TREE_MODEL ( priv->store ), &iter,
+                    COMBOFIX_COL_SEPARATOR, &separator,
+                    -1 );
+
+        valid = gtk_tree_model_iter_next ( GTK_TREE_MODEL ( priv->store ), &iter );
+
+        if ( separator )
+        {
+            break;
+        }
+    }
+
+    if ( valid )
+    {
+        if ( gtk_tree_model_iter_has_child ( GTK_TREE_MODEL ( priv->store ), &iter ) )
+        {
+            gint children;
+            GtkTreeIter child;
+
+            children = gtk_tree_model_iter_n_children ( GTK_TREE_MODEL ( priv->store ), &iter );
+            valid = FALSE;
+
+            if ( gtk_tree_model_iter_children ( GTK_TREE_MODEL ( priv->store ), &child, &iter ) )
+            {
+                do
+                {
+                    gtk_tree_model_get ( GTK_TREE_MODEL ( priv->store ), &child,
+                                COMBOFIX_COL_REAL_STRING, &tmp_str,
+                                -1 );
+
+                    if ( strcmp ( tmp_str, tmp_str2 ) == 0 )
+                    {
+                        g_free ( tmp_str );
+                        valid = TRUE;
+                        children --;
+                        break;
+                    }
+
+                    g_free ( tmp_str );
+                }
+                while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( priv->store ), &child ) );
+
+                if ( valid )
+                    gtk_tree_store_remove ( priv->store, &child );
+            }
+            if ( children == 0 )
+            {
+                gtk_combofix_remove_for_report ( GTK_TREE_MODEL ( priv->store ), &iter );
+            }
+        }
+        else
+            gtk_combofix_remove_for_report ( GTK_TREE_MODEL ( priv->store ), &iter );
+    }
+    g_free ( tmp_str2 );
+}
+
+
+/**
 *
 *
 * \param combofix text
@@ -570,7 +781,7 @@ void gtk_combofix_set_selection_callback ( GtkComboFix *combofix,
 }
 
 
-/* *********************** the second part contains the construct object functions ******************************************** */
+/* *********************** the third part contains the construct object functions ******************************************** */
 
 /**
 * called when create a new combofix
@@ -800,7 +1011,7 @@ static void gtk_combofix_finalize ( GObject *combofix )
 }
 
 
-/* *********************** the third part contains all the static functions ******************************************** */
+/* *********************** the fourth part contains all the static functions ******************************************** */
 
 /**
 * fill the model of the combofix given in param
diff --git a/src/gtk_combofix.h b/src/gtk_combofix.h
index 75bf5f6..dc575df 100644
--- a/src/gtk_combofix.h
+++ b/src/gtk_combofix.h
@@ -68,7 +68,11 @@ gboolean gtk_combofix_show_popup ( GtkComboFix *combofix );
 gboolean gtk_combofix_hide_popup ( GtkComboFix *combofix );
 
 /* list of items */
+void gtk_combofix_append_report ( GtkComboFix *combofix,
+                        const gchar *report_name );
 void gtk_combofix_append_text ( GtkComboFix *combofix, const gchar *text );
+void gtk_combofix_remove_report ( GtkComboFix *combofix,
+                        const gchar *report_name );
 void gtk_combofix_remove_text ( GtkComboFix *combofix, const gchar *text );
 gboolean gtk_combofix_set_list ( GtkComboFix *combofix, GSList *list );
 void gtk_combofix_set_max_items ( GtkComboFix *combofix, gint max_items );
diff --git a/src/import.c b/src/import.c
index 803d89b..a324eef 100644
--- a/src/import.c
+++ b/src/import.c
@@ -2002,9 +2002,6 @@ void gsb_import_create_imported_transactions ( struct struct_compte_importation
 
     if ( progress )
         gtk_widget_destroy ( progress );
-
-    /* some payee should have been added, so update the combofix */
-    gsb_form_widget_update_payee_combofix ();
 }
 
 
@@ -2103,9 +2100,6 @@ void gsb_import_add_imported_transactions ( struct struct_compte_importation *im
 	list_tmp = list_tmp -> next;
     }
 
-    /** some payee should have been added, so update the combofix */
-    gsb_form_widget_update_payee_combofix ();
-
     /* if we are on the current account, we need to update the tree_view */
     if (gsb_gui_navigation_get_current_account () == account_number)
     {
diff --git a/src/navigation.c b/src/navigation.c
index cf0ab68..a8afab7 100644
--- a/src/navigation.c
+++ b/src/navigation.c
@@ -50,6 +50,7 @@
 #include "gsb_file.h"
 #include "gsb_form.h"
 #include "gsb_form_scheduler.h"
+#include "gsb_form_widget.h"
 #include "gsb_real.h"
 #include "gsb_reconcile.h"
 #include "gsb_scheduler_list.h"
@@ -776,8 +777,11 @@ static gboolean gsb_gui_navigation_remove_report_iterator ( GtkTreeModel *tree_m
 
     if ( report == GPOINTER_TO_INT (data))
     {
-	gtk_tree_store_remove ( GTK_TREE_STORE(tree_model), iter );
-	return TRUE;
+        if ( gsb_data_report_get_append_in_payee ( report ) )
+            gsb_form_widget_update_payee_combofix ( report, FALSE );
+
+        gtk_tree_store_remove ( GTK_TREE_STORE(tree_model), iter );
+        return TRUE;
     }
 
     return FALSE;
-- 
1.8.1.5



More information about the devel mailing list