[grisbi-cvs] grisbi/src categories_onglet.c, 1.199, 1.200 gsb_currency.c, 1.42, 1.43 gsb_currency.h, 1.8, 1.9 gsb_data_transaction.c, 1.73, 1.74 gsb_form.c, 1.134, 1.135 gsb_form_transaction.c, 1.48, 1.49 gsb_form_transaction.h, 1.12, 1.13 gsb_real.c, 1.51, 1.52 gsb_transactions_list.c, 1.184, 1.185 import.c, 1.299, 1.300 qif.c, 1.139, 1.140 traitement_variables.c, 1.181, 1.182 utils_files.c, 1.43, 1.44 utils_operations.c, 1.32, 1.33

Pierre Biava pbiava at users.sourceforge.net
Mon Nov 2 20:56:39 CET 2009


Update of /cvsroot/grisbi/grisbi/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv1410/src

Modified Files:
	categories_onglet.c gsb_currency.c gsb_currency.h 
	gsb_data_transaction.c gsb_form.c gsb_form_transaction.c 
	gsb_form_transaction.h gsb_real.c gsb_transactions_list.c 
	import.c qif.c traitement_variables.c utils_files.c 
	utils_operations.c 
Log Message:
change of management of multi-currency accounts and minor corrections

Index: gsb_data_transaction.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_transaction.c,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- gsb_data_transaction.c	26 Oct 2009 22:38:21 -0000	1.73
+++ gsb_data_transaction.c	2 Nov 2009 19:56:37 -0000	1.74
@@ -100,8 +100,6 @@
 
 /*START_STATIC*/
 static void gsb_data_transaction_delete_all_transactions ( void );
-static gint gsb_data_transaction_find_by_payment_content ( const gchar *string,
-                        gint account_number );
 static  void gsb_data_transaction_free ( struct_transaction *transaction);
 static gint gsb_data_transaction_get_last_white_number (void);
 static struct_transaction *gsb_data_transaction_get_transaction_by_no ( gint transaction_number );
@@ -736,17 +734,14 @@
 
     transaction = gsb_data_transaction_get_transaction_by_no ( transaction_number);
 
-    if ( ! (transaction
-	    &&
-	    return_currency_number ))
-	return gsb_real_adjust_exponent  ( null_real,
-					   return_exponent );
+    if ( ! (transaction && return_currency_number ) )
+        return gsb_real_adjust_exponent  ( null_real, return_exponent );
 
     /* if the transaction currency is the same of the account's one,
      * we just return the transaction's amount */
 
     if ( transaction -> currency_number == return_currency_number )
-	return gsb_real_adjust_exponent  ( transaction -> transaction_amount,
+        return gsb_real_adjust_exponent  ( transaction -> transaction_amount,
 					   return_exponent );
 
     /* now we can adjust the amount */
@@ -2393,44 +2388,6 @@
 }
 
 
-
-
-/**
- * find a transaction by the method of payment content in a given account
- *
- * \param string
- * \param account_number
- *
- * \return the number of the transaction or 0 if not found
- * */
-gint gsb_data_transaction_find_by_payment_content ( const gchar *string,
-                        gint account_number )
-{
-    GSList *tmp_list;
-
-    if (!string)
-	return 0;
-
-    tmp_list = transactions_list;
-    while (tmp_list)
-    {
-	struct_transaction *transaction;
-
-	transaction = tmp_list -> data;
-
-	if ( transaction -> method_of_payment_content
-	     &&
-	     transaction -> account_number == account_number
-	     &&
-	     !strcmp ( string,
-		       transaction -> method_of_payment_content ))
-	    return transaction -> transaction_number;
-	tmp_list = tmp_list -> next;
-    }
-    return 0;
-}
-
-
 /**
  * find a transaction by its id
  *

Index: qif.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/qif.c,v
retrieving revision 1.139
retrieving revision 1.140
diff -u -d -r1.139 -r1.140
--- qif.c	14 Oct 2009 20:09:14 -0000	1.139
+++ qif.c	2 Nov 2009 19:56:37 -0000	1.140
@@ -193,6 +193,8 @@
 				      _("oth l)")))
 					  returned_value = -2;
 	    }
+        else  
+            break;
 	}
 	while ( returned_value != EOF
 		&&

Index: gsb_form_transaction.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_form_transaction.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- gsb_form_transaction.c	18 Oct 2009 17:46:21 -0000	1.48
+++ gsb_form_transaction.c	2 Nov 2009 19:56:37 -0000	1.49
@@ -62,6 +62,7 @@
 
 /*START_EXTERN*/
 extern GtkWidget *form_button_recover_split;
+extern gsb_real null_real;
 /*END_EXTERN*/
 
 
@@ -268,32 +269,6 @@
 
 
 /**
- * check if the currency given in param is the same of the account currency
- * or if there is a link between them
- * if not, show the change button
- *
- * \param currency_number the currency of the transaction
- * \param account_number 
- *
- * \return
- * */
-void gsb_form_transaction_check_change_button ( gint currency_number,
-                        gint account_number )
-{
-    gint account_currency_number;
-
-    account_currency_number = gsb_data_account_get_currency (account_number);
-
-    if ( gsb_data_currency_link_search ( account_currency_number,
-					 currency_number ))
-	gtk_widget_hide ( gsb_form_widget_get_widget (TRANSACTION_FORM_CHANGE));
-    else
-	gtk_widget_show ( gsb_form_widget_get_widget (TRANSACTION_FORM_CHANGE));
-}
-
-
-
-/**
  * Clone the children of a split transaction to add the to the new split
  * 
  * \param new_transaction_number	the number of the new mother of the cloned transaction
@@ -553,40 +528,49 @@
     gint account_number;
     gint currency_number;
     gint account_currency_number;
-    gsb_real exchange, exchange_fees;
-
-    account_number = gsb_form_get_account_number ();
-    gtk_widget_grab_focus ( gsb_form_widget_get_widget (TRANSACTION_FORM_DATE));
-
-    transaction_number = GPOINTER_TO_INT (g_object_get_data ( G_OBJECT ( gsb_form_get_form_widget () ),
-								"transaction_number_in_form" ));
 
-    account_currency_number = gsb_data_account_get_currency (account_number);
-    currency_number = gsb_data_transaction_get_currency_number (transaction_number);
-
-    gsb_currency_exchange_dialog ( account_currency_number, currency_number,
-				   gsb_data_transaction_get_change_between (transaction_number),
-				   gsb_data_transaction_get_exchange_rate (transaction_number),
-				   gsb_data_transaction_get_exchange_fees (transaction_number), 
-				   TRUE );
+    account_number = gsb_form_get_account_number ( );
+    account_currency_number = gsb_data_account_get_currency ( account_number );
+    gtk_widget_grab_focus ( gsb_form_widget_get_widget ( TRANSACTION_FORM_DATE ));
 
-    exchange = gsb_currency_get_current_exchange ();
-    exchange_fees = gsb_currency_get_current_exchange_fees ();
+    transaction_number = GPOINTER_TO_INT (g_object_get_data (
+                        G_OBJECT ( gsb_form_get_form_widget ( ) ),
+                        "transaction_number_in_form" ));
 
-    if ( exchange.mantissa || exchange_fees.mantissa )
+    if ( transaction_number == -1 )
     {
-	gsb_data_transaction_set_exchange_rate (transaction_number,
-						 gsb_real_abs (exchange));
-	gsb_data_transaction_set_exchange_fees (transaction_number,
-						exchange_fees );
+        gint link_number;
 
-	if ( exchange.mantissa < 0 )
-	    gsb_data_transaction_set_change_between (transaction_number,
-						     1 );
-	else
-	    gsb_data_transaction_set_change_between (transaction_number,
-						     0 );
+        currency_number = gsb_currency_get_currency_from_combobox (
+                        gsb_form_widget_get_widget ( TRANSACTION_FORM_DEVISE ) );
+        link_number = gsb_data_currency_link_search ( account_currency_number,
+                        currency_number );
+        if ( link_number 
+         && 
+         gsb_data_currency_link_get_first_currency ( link_number )
+         == account_currency_number )
+            gsb_currency_exchange_dialog ( account_currency_number, currency_number,
+                        1,
+                        gsb_data_currency_link_get_change_rate ( link_number ),
+                        null_real, 
+                        TRUE );
+        else
+            gsb_currency_exchange_dialog ( account_currency_number, currency_number,
+                        0,
+                        gsb_data_currency_link_get_change_rate ( link_number ),
+                        null_real, 
+                        TRUE );
     }
+    else
+    {
+        currency_number = gsb_data_transaction_get_currency_number ( transaction_number );
+        gsb_currency_exchange_dialog ( account_currency_number, currency_number,
+                        gsb_data_transaction_get_change_between ( transaction_number ),
+                        gsb_data_transaction_get_exchange_rate ( transaction_number ),
+                        gsb_data_transaction_get_exchange_fees ( transaction_number ), 
+                        TRUE );
+    }
+
     return FALSE;
 }
 
@@ -597,17 +581,16 @@
     gint currency_number;
     gint account_currency_number;
 
-    devel_debug ("gsb_form_transaction_currency_changed");
-    account_number = gsb_form_get_account_number ();
-    gtk_widget_grab_focus ( gsb_form_widget_get_widget (TRANSACTION_FORM_DATE));
+    account_number = gsb_form_get_account_number ( );
+    gtk_widget_grab_focus ( gsb_form_widget_get_widget ( TRANSACTION_FORM_DATE ) );
 
-    account_currency_number = gsb_data_account_get_currency (account_number);
-    currency_number = gsb_currency_get_currency_from_combobox ( widget );
+    account_currency_number = gsb_data_account_get_currency ( account_number );
 
+    currency_number = gsb_currency_get_currency_from_combobox ( widget );
     if ( account_currency_number == currency_number )
-        gtk_widget_hide ( gsb_form_widget_get_widget (TRANSACTION_FORM_CHANGE));
+        gtk_widget_hide ( gsb_form_widget_get_widget ( TRANSACTION_FORM_CHANGE ) );
     else
-        gtk_widget_show ( gsb_form_widget_get_widget (TRANSACTION_FORM_CHANGE));
+        gtk_widget_show ( gsb_form_widget_get_widget ( TRANSACTION_FORM_CHANGE ) );
 }
 /* Local Variables: */
 /* c-basic-offset: 4 */

Index: traitement_variables.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/traitement_variables.c,v
retrieving revision 1.181
retrieving revision 1.182
diff -u -d -r1.181 -r1.182
--- traitement_variables.c	25 Oct 2009 18:46:19 -0000	1.181
+++ traitement_variables.c	2 Nov 2009 19:56:37 -0000	1.182
@@ -144,6 +144,7 @@
 extern GtkTreeModel *bank_list_model;
 extern GtkTreeStore *categ_tree_model;
 extern gint current_tree_view_width;
+extern GtkWidget *detail_devise_compte;
 extern gint display_one_line;
 extern gint display_three_lines;
 extern gint display_two_lines;
@@ -332,7 +333,11 @@
     etat.combofix_enter_select_completion = FALSE;
     etat.combofix_force_payee = FALSE;
     etat.combofix_force_category = FALSE;
-    
+
+    /* mis à NULL prévient un plantage aléatoire dans 
+     * gsb_currency_update_combobox_currency_list */
+    detail_devise_compte = NULL;
+
     /* defaut value for width of columns */
     for ( i = 0 ; i < CUSTOM_MODEL_VISIBLE_COLUMNS ; i++ )
     transaction_col_width[i] = transaction_col_width_init[i];

Index: gsb_transactions_list.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_transactions_list.c,v
retrieving revision 1.184
retrieving revision 1.185
diff -u -d -r1.184 -r1.185
--- gsb_transactions_list.c	23 Sep 2009 20:28:21 -0000	1.184
+++ gsb_transactions_list.c	2 Nov 2009 19:56:37 -0000	1.185
@@ -717,21 +717,27 @@
 
 	case ELEMENT_AMOUNT:
 	    /* give the amount of the transaction in the currency of the account */
-	    account_currency = gsb_data_account_get_currency (gsb_data_transaction_get_account_number (transaction_number));
-	    if ( account_currency != gsb_data_transaction_get_currency_number (transaction_number))
+	    account_currency = gsb_data_account_get_currency (
+                        gsb_data_transaction_get_account_number ( transaction_number ) );
+	    if ( account_currency != gsb_data_transaction_get_currency_number (
+         transaction_number ) )
 	    {
-		gchar* tmpstr = gsb_real_get_string (gsb_data_transaction_get_adjusted_amount (transaction_number,
-											       gsb_data_currency_get_floating_point (account_currency)));
-		gchar* result = g_strconcat ( "(",
-					      tmpstr,
-					      gsb_data_currency_get_code (account_currency),
-					      ")",
-					      NULL );
-		g_free ( tmpstr );
-		return result;
+            gchar* tmpstr;
+            gchar* result;
+
+            tmpstr = gsb_real_get_string ( gsb_data_transaction_get_adjusted_amount (
+                        transaction_number,
+                        gsb_data_currency_get_floating_point ( account_currency ) ) );
+            result = g_strconcat ( "(",
+                        tmpstr,
+                        gsb_data_currency_get_code_or_isocode ( account_currency ),
+					    ")",
+					    NULL );
+            g_free ( tmpstr );
+            return result;
 	    }
 	    else
-		return NULL;
+            return NULL;
 	    break;
 
 	    /* mise en forme du moyen de paiement */

Index: gsb_form.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_form.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -d -r1.134 -r1.135
--- gsb_form.c	31 Oct 2009 17:45:36 -0000	1.134
+++ gsb_form.c	2 Nov 2009 19:56:37 -0000	1.135
@@ -2,6 +2,7 @@
 /*                                                                            */
 /*     copyright (c)    2000-2008 Cédric Auger (cedric at grisbi.org)            */
 /*          2004-2008 Benjamin Drieu (bdrieu at april.org)                       */
+/*                      2009 Pierre Biava (grisbi at pierre.biava.name)          */
 /*          http://www.grisbi.org                                             */
 /*                                                                            */
 /*  This program is free software; you can redistribute it and/or modify      */
@@ -835,12 +836,11 @@
 	    number = gsb_data_mix_get_currency_number (transaction_number, is_transaction);
 
 	    gsb_currency_set_combobox_history ( widget, number);
+        gsb_currency_init_exchanges ( );
 	    if (is_transaction)
         {
             if ( gsb_data_transaction_get_marked_transaction ( transaction_number ) == 3 )
                 gtk_widget_set_sensitive ( widget, FALSE );
-            else
-                gsb_form_transaction_check_change_button ( number, account_number );
         }
 	    break;
 

Index: gsb_form_transaction.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_form_transaction.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- gsb_form_transaction.h	18 Oct 2009 17:46:21 -0000	1.12
+++ gsb_form_transaction.h	2 Nov 2009 19:56:37 -0000	1.13
@@ -9,8 +9,6 @@
 /* START_DECLARATION */
 gboolean gsb_form_transaction_change_clicked ( GtkWidget *button,
                         gpointer null );
-void gsb_form_transaction_check_change_button ( gint currency_number,
-                        gint account_number );
 gboolean gsb_form_transaction_complete_form_by_payee ( const gchar *payee_name );
 void gsb_form_transaction_currency_changed ( GtkWidget *widget, gpointer null );
 GSList *gsb_form_transaction_get_parties_list_from_report ( void );

Index: categories_onglet.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/categories_onglet.c,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- categories_onglet.c	3 Oct 2009 22:14:56 -0000	1.199
+++ categories_onglet.c	2 Nov 2009 19:56:37 -0000	1.200
@@ -59,7 +59,7 @@
 
 
 /* Category tree model & view */
-GtkTreeStore * categ_tree_model = NULL;
+GtkTreeStore *categ_tree_model = NULL;
 GtkWidget *arbre_categ = NULL;
 gint no_devise_totaux_categ;
 

Index: gsb_real.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- gsb_real.c	24 Oct 2009 19:18:49 -0000	1.51
+++ gsb_real.c	2 Nov 2009 19:56:37 -0000	1.52
@@ -274,7 +274,7 @@
     gint floating_point;
 
     const gchar *currency_symbol = (currency_number && show_symbol)
-                                   ? gsb_data_currency_get_code (currency_number)
+                                   ? gsb_data_currency_get_code_or_isocode (currency_number)
                                    : NULL;
 
     /* First of all if number = 0 I return 0 with the symbol of the currency if necessary */
@@ -736,7 +736,7 @@
  * \param number_1
  * \param number_2
  *
- * \return the multiplication between the 2
+ * \return the div between the 2
  * */
 gsb_real gsb_real_div ( gsb_real number_1,
                         gsb_real number_2 )
@@ -828,3 +828,8 @@
     return FALSE;
 }
 
+
+/* Local Variables: */
+/* c-basic-offset: 4 */
+/* End: */
+

Index: import.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/import.c,v
retrieving revision 1.299
retrieving revision 1.300
diff -u -d -r1.299 -r1.300
--- import.c	26 Oct 2009 22:38:21 -0000	1.299
+++ import.c	2 Nov 2009 19:56:37 -0000	1.300
@@ -131,6 +131,7 @@
 static gboolean gsb_import_set_id_compte ( gint account_nb, gchar *imported_id );
 static gboolean gsb_import_set_tmp_file ( gchar *filename,
                         gchar * pointeur_char );
+static void gsb_import_show_orphan_transactions ( GSList *orphan_list );
 static gboolean import_account_action_activated ( GtkWidget * radio, gint action );
 static gboolean import_active_toggled ( GtkCellRendererToggle * cell, gchar *path_str,
                         gpointer model );
@@ -1979,16 +1980,8 @@
             /* no id, no cheque, try to find the transaction */
             if ( imported_transaction -> action != IMPORT_TRANSACTION_LEAVE_TRANSACTION )
             {
-                GDate *date_debut_comparaison;
                 GDate *date_fin_comparaison;
 
-                date_debut_comparaison = g_date_new_dmy ( g_date_get_day (
-                        imported_transaction -> date ),
-                        g_date_get_month ( imported_transaction -> date ),
-                        g_date_get_year ( imported_transaction -> date ));
-                        g_date_subtract_days ( date_debut_comparaison,
-                        valeur_echelle_recherche_date_import );
-
                 date_fin_comparaison = g_date_new_dmy ( g_date_get_day (
                         imported_transaction -> date ),
                         g_date_get_month ( imported_transaction -> date ),
@@ -2000,9 +1993,6 @@
                         imported_transaction -> montant )
                  &&
                  ( g_date_compare ( gsb_data_transaction_get_date ( transaction_number ),
-                        date_debut_comparaison ) >= 0 )
-                 &&
-                 ( g_date_compare ( gsb_data_transaction_get_date ( transaction_number ),
                         date_fin_comparaison ) <= 0 )
                  &&
                  !imported_transaction -> ope_de_ventilation
@@ -2939,19 +2929,33 @@
      * on les affiche dans une liste en proposant de les ajouter à la liste */
 
     if ( liste_opes_import_celibataires )
-    {
+        gsb_import_show_orphan_transactions ( liste_opes_import_celibataires );
+}
+
+
+/**
+ * 
+ * 
+ *
+ * \param 
+ *
+ * return 
+ */
+void gsb_import_show_orphan_transactions ( GSList *orphan_list )
+{
 	GtkWidget *liste_ope_celibataires, *dialog, *label, *scrolled_window;
 	GtkListStore *store;
 	GtkCellRenderer *renderer;
 	GtkTreeViewColumn *column;
-
+    GSList *list_tmp;
 
     dialog = gtk_dialog_new_with_buttons ( _("Orphaned transactions"),
-					   GTK_WINDOW ( window ),
-					   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-					   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-					   GTK_STOCK_OK, GTK_RESPONSE_OK,
-					   NULL );
+                        GTK_WINDOW ( window ),
+                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                        GTK_STOCK_SELECT_ALL, GTK_RESPONSE_ACCEPT,
+                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                        GTK_STOCK_OK, GTK_RESPONSE_OK,
+                        NULL );
 
     gtk_window_set_default_size ( GTK_WINDOW ( dialog ), 770, 412 );
     gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
@@ -2962,21 +2966,22 @@
                               "OK button"));
     gtk_misc_set_alignment ( GTK_MISC ( label ), 0.0, 0.0 );
 	gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( dialog ) -> vbox ),
-			     label,
-			     FALSE,
-			     FALSE,
-			     10 );
+                        label,
+                        FALSE,
+                        FALSE,
+                        10 );
 	gtk_widget_show ( label );
 
+    /* on crée le model et on y associe le dialogue */
 	store = gtk_list_store_new ( 4,
-				     G_TYPE_BOOLEAN,
-				     G_TYPE_STRING,
-				     G_TYPE_STRING,
-				     G_TYPE_STRING );
+                        G_TYPE_BOOLEAN,
+                        G_TYPE_STRING,
+                        G_TYPE_STRING,
+                        G_TYPE_STRING );
+    g_object_set_data ( G_OBJECT ( store ), "dialog", dialog );
 
 	/* on remplit la liste */
-
-	list_tmp = liste_opes_import_celibataires;
+	list_tmp = orphan_list;
 
 	while ( list_tmp )
 	{
@@ -2985,89 +2990,78 @@
 
 	    ope_import = list_tmp -> data;
 
-	    gtk_list_store_append ( store,
-				    &iter );
-
+	    gtk_list_store_append ( store, &iter );
 	    gtk_list_store_set ( store,
-				 &iter,
-				 0, FALSE,
-				 1, gsb_format_gdate ( ope_import -> date ),
-				 2, ope_import -> tiers,
-				 3, gsb_real_get_string_with_currency ( ope_import -> montant,
-                                    ope_import -> devise, TRUE ),
-				 -1 );
+                        &iter,
+                        0, FALSE,
+                        1, gsb_format_gdate ( ope_import -> date ),
+                        2, ope_import -> tiers,
+                        3, gsb_real_get_string_with_currency ( ope_import -> montant,
+                        ope_import -> devise, TRUE ),
+                        -1 );
 
 	    list_tmp = list_tmp -> next;
 	}
 
-	/* on crée la liste des opés célibataires
-	   et on y associe la gslist */
-
+	/* on crée la liste des opés célibataires et on y associe la gslist */
 	liste_ope_celibataires = gtk_tree_view_new_with_model ( GTK_TREE_MODEL (store));
-	g_object_set_data ( G_OBJECT ( liste_ope_celibataires ),
-			    "liste_ope",
-			    liste_opes_import_celibataires );
+	g_object_set_data ( G_OBJECT ( liste_ope_celibataires ), "liste_ope", orphan_list );
+
 	scrolled_window = gtk_scrolled_window_new ( FALSE, FALSE );
 	gtk_widget_set_size_request ( scrolled_window, -1, 300 );
 	gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( dialog ) -> vbox ),
-			     scrolled_window,
-			     TRUE,
-			     TRUE,
-			     0 );
+                        scrolled_window,
+                        TRUE,
+                        TRUE,
+                        0 );
 	gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( scrolled_window ),
-					 GTK_POLICY_AUTOMATIC,
-					 GTK_POLICY_AUTOMATIC );
+                        GTK_POLICY_AUTOMATIC,
+                        GTK_POLICY_AUTOMATIC );
 	gtk_scrolled_window_add_with_viewport ( GTK_SCROLLED_WINDOW ( scrolled_window ),
 						liste_ope_celibataires );
     gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (liste_ope_celibataires), TRUE);
 	gtk_widget_show_all ( scrolled_window );
 
 	/* on affiche les colonnes */
-
 	renderer = gtk_cell_renderer_toggle_new ();
 	g_signal_connect ( renderer,
-			   "toggled",
-			   G_CALLBACK (click_sur_liste_opes_orphelines ),
-			   store );
+                        "toggled",
+                        G_CALLBACK (click_sur_liste_opes_orphelines ),
+                        store );
 	column = gtk_tree_view_column_new_with_attributes ( _("Mark"),
-							    renderer,
-							    "active", 0,
-
-							    NULL);
+                        renderer,
+                        "active", 0,
+                        NULL);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (liste_ope_celibataires), column);
 
 	renderer = gtk_cell_renderer_text_new ();
 	column = gtk_tree_view_column_new_with_attributes ( _("Date"),
-							    renderer,
-							    "text", 1,
-							    NULL);
+                        renderer,
+                        "text", 1,
+                        NULL);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (liste_ope_celibataires), column);
 
 	renderer = gtk_cell_renderer_text_new ();
 	column = gtk_tree_view_column_new_with_attributes ( _("Payee"),
-							    renderer,
-							    "text", 2,
-							    NULL);
+                        renderer,
+                        "text", 2,
+                        NULL);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (liste_ope_celibataires), column);
 
-
 	renderer = gtk_cell_renderer_text_new ();
 	column = gtk_tree_view_column_new_with_attributes ( _("Amount"),
-							    renderer,
-							    "text", 3,
-							    NULL);
+                        renderer,
+                        "text", 3,
+                        NULL);
 	gtk_tree_view_append_column (GTK_TREE_VIEW (liste_ope_celibataires), column);
 
 	g_signal_connect ( G_OBJECT ( dialog ),
-			   "response",
-			   G_CALLBACK ( click_dialog_ope_orphelines ),
-			   liste_ope_celibataires );
+                        "response",
+                        G_CALLBACK ( click_dialog_ope_orphelines ),
+                        liste_ope_celibataires );
 
 	gtk_widget_show ( dialog );
-    }
 }
-
-
 /**
  * 
  * 
@@ -3132,6 +3126,8 @@
 
         list_tmp = list_tmp -> next;
     }
+
+    first_date = gsb_date_copy ( first_date );
     g_date_subtract_days ( first_date, valeur_echelle_recherche_date_import );
 
     return first_date;
@@ -3152,6 +3148,22 @@
 
     switch ( result )
     {
+        case GTK_RESPONSE_ACCEPT:
+        /* on coche toutes les cases des opérations */
+        liste_opes_import_celibataires = g_object_get_data (
+                        G_OBJECT ( liste_ope_celibataires ),
+                        "liste_ope" );
+	    model = gtk_tree_view_get_model ( GTK_TREE_VIEW ( liste_ope_celibataires ));
+	    if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( model ), &iter ) )
+        {
+            do
+            {
+                gtk_list_store_set ( GTK_LIST_STORE ( model ), &iter, 0, TRUE, -1 );
+            }
+            while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( model ), &iter ) );
+        }
+        gtk_dialog_set_response_sensitive ( GTK_DIALOG ( dialog ),GTK_RESPONSE_ACCEPT, FALSE );
+        break;
 	case GTK_RESPONSE_OK:
 	    /* on ajoute la ou les opés marquées à la liste d'opés en les pointant d'un T
 	       puis on les retire de la liste des orphelines
@@ -3239,7 +3251,6 @@
 		 &&
 		 g_slist_length ( liste_opes_import_celibataires ))
 		break;
-
 	default:
 	    gtk_widget_destroy ( dialog );
 	    break;
@@ -3256,21 +3267,31 @@
                         GtkTreeModel *store )
 {
     GtkTreeIter iter;
+    gboolean valeur;
 
-    if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( store ),
-					       &iter,
-					       ligne ))
+    if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( store ), &iter, ligne ) )
     {
-	gboolean valeur;
+        gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &iter, 0, &valeur, -1 );
+        gtk_list_store_set ( GTK_LIST_STORE ( store ), &iter, 0, 1 - valeur, -1 );
+    }
+    if ( gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( store ), &iter ) )
+    {
+        gboolean all_true = TRUE;
+        GtkDialog *dialog;
 
-	gtk_tree_model_get ( GTK_TREE_MODEL ( store ),
-			     &iter,
-			     0, &valeur,
-			     -1 );
-	gtk_list_store_set ( GTK_LIST_STORE ( store ),
-			     &iter,
-			     0, 1 - valeur,
-			     -1 );
+        dialog = g_object_get_data ( G_OBJECT ( store ), "dialog" );
+        do
+        {
+            gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &iter, 0, &valeur, -1 );
+            if ( valeur == FALSE )
+                all_true = FALSE;
+        }
+        while ( gtk_tree_model_iter_next ( GTK_TREE_MODEL ( store ), &iter ) );
+
+        if ( all_true == TRUE )
+            gtk_dialog_set_response_sensitive ( dialog,GTK_RESPONSE_ACCEPT, FALSE );
+        else
+            gtk_dialog_set_response_sensitive ( dialog,GTK_RESPONSE_ACCEPT, TRUE );
     }
     return ( FALSE );
 }

Index: utils_operations.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_operations.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- utils_operations.c	27 Apr 2009 19:41:03 -0000	1.32
+++ utils_operations.c	2 Nov 2009 19:56:37 -0000	1.33
@@ -49,7 +49,7 @@
 extern MetatreeInterface * budgetary_interface;
 extern GtkWidget *budgetary_line_tree;
 extern GtkTreeStore *budgetary_line_tree_model;
-extern GtkTreeStore * categ_tree_model;
+extern GtkTreeStore *categ_tree_model;
 extern MetatreeInterface * category_interface;
 extern MetatreeInterface * payee_interface;
 extern GtkWidget *payee_tree;

Index: gsb_currency.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_currency.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- gsb_currency.h	25 Oct 2008 13:07:53 -0000	1.8
+++ gsb_currency.h	2 Nov 2009 19:56:37 -0000	1.9
@@ -10,18 +10,19 @@
 /* START_DECLARATION */
 void gsb_currency_check_for_change ( gint transaction_number );
 void gsb_currency_exchange_dialog ( gint account_currency_number,
-				    gint transaction_currency_number ,
-				    gint link_currency,
-				    gsb_real exchange_rate,
-				    gsb_real exchange_fees,
-				    gboolean force );
+                        gint transaction_currency_number ,
+                        gboolean link_currency,
+                        gsb_real exchange_rate,
+                        gsb_real exchange_fees,
+                        gboolean force );
 gint gsb_currency_get_currency_from_combobox ( GtkWidget *combo_box );
 gsb_real gsb_currency_get_current_exchange (void);
 gsb_real gsb_currency_get_current_exchange_fees (void);
+void gsb_currency_init_exchanges ( void );
 void gsb_currency_init_variables ( void );
 GtkWidget *gsb_currency_make_combobox ( gboolean set_name );
 gboolean gsb_currency_set_combobox_history ( GtkWidget *combo_box,
-					     gint currency_number );
+                        gint currency_number );
 gboolean gsb_currency_update_combobox_currency_list ( void );
 /* END_DECLARATION */
 #endif

Index: utils_files.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/utils_files.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- utils_files.c	24 Aug 2009 19:45:09 -0000	1.43
+++ utils_files.c	2 Nov 2009 19:56:37 -0000	1.44
@@ -220,16 +220,24 @@
 			     NULL );
     if (!tmp_string)
     {
-	devel_debug ("convert to utf8 failed, will use latin2utf8");
-	tmp_string = latin2utf8 (pointeur_char);
+        devel_debug ("convert to utf8 failed, will use latin2utf8");
+        tmp_string = latin2utf8 (pointeur_char);
+        if ( tmp_string == NULL )
+        {
+            dialogue_special ( GTK_MESSAGE_ERROR, make_hint (
+                            _("Convert to utf8 failed."),
+                            _("If the result is not correct, try again by selecting the "
+                            "correct character set in the window for selecting files.") ) );
+            return 0;
+        }
     }
     *string = tmp_string;
     g_free (pointeur_char);
 
     if ( feof(fichier))
-	return EOF;
+        return EOF;
     else
-	return 1;
+        return 1;
 }
 
 

Index: gsb_currency.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_currency.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- gsb_currency.c	26 Oct 2009 22:38:21 -0000	1.42
+++ gsb_currency.c	2 Nov 2009 19:56:37 -0000	1.43
@@ -1,8 +1,9 @@
 /* ************************************************************************** */
 /*                                                                            */
-/*     Copyright (C)	2000-2007 Cédric Auger (cedric at grisbi.org)	      */
-/*			2003-2009 Benjamin Drieu (bdrieu at april.org)	      */
-/* 			http://www.grisbi.org				      */
+/*     Copyright (C)    2000-2007 Cédric Auger (cedric at grisbi.org)            */
+/*          2003-2009 Benjamin Drieu (bdrieu at april.org)                       */
+/*                      2009 Pierre Biava (grisbi at pierre.biava.name)          */
+/*          http://www.grisbi.org                                             */
 /*                                                                            */
 /*  This program is free software; you can redistribute it and/or modify      */
 /*  it under the terms of the GNU General Public License as published by      */
@@ -35,6 +36,7 @@
 #include "./gsb_data_currency.h"
 #include "./gsb_data_currency_link.h"
 #include "./gsb_data_transaction.h"
+#include "./gsb_form.h"
 #include "./gsb_real.h"
 #include "./utils.h"
 #include "./structures.h"
@@ -47,13 +49,13 @@
 
 /*START_STATIC*/
 static struct cached_exchange_rate *gsb_currency_config_get_cached_exchange ( gint currency1_number,
-								       gint currency2_number );
+                        gint currency2_number );
 static void gsb_currency_config_set_cached_exchange ( gint currency1_number,
-					       gint currency2_number,
-					       gsb_real change, gsb_real fees );
+                        gint currency2_number,
+                        gsb_real change, gsb_real fees );
 static gboolean gsb_currency_create_combobox_store ( void );
 static gboolean gsb_currency_select_change_currency ( GtkWidget *combobox_1,
-					       GtkWidget *combobox_2 );
+                        GtkWidget *combobox_2 );
 /*END_STATIC*/
 
 /**
@@ -112,9 +114,9 @@
 void gsb_currency_init_variables ( void )
 {
     if (combobox_currency_store
-	&&
-	GTK_IS_LIST_STORE (combobox_currency_store))
-	gtk_list_store_clear (combobox_currency_store);
+    &&
+    GTK_IS_LIST_STORE (combobox_currency_store))
+    gtk_list_store_clear (combobox_currency_store);
 
     combobox_currency_store = NULL;
     current_exchange = null_real;
@@ -161,12 +163,12 @@
     GtkCellRenderer *text_renderer, *flag_renderer;
     GtkWidget *combo_box;
 devel_debug ("gsb_currency_make_combobox");
-    if (!combobox_currency_store)
+    if ( !combobox_currency_store )
         gsb_currency_create_combobox_store ();
-printf ("phase 1\n");
+
     combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL 
                         (combobox_currency_store));
-printf ("phase 2\n");
+
     /* Flag renderer */
     flag_renderer = gtk_cell_renderer_pixbuf_new ();
     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), flag_renderer, FALSE);
@@ -174,10 +176,10 @@
 				    "pixbuf", CURRENCY_COL_FLAG, NULL );
 
     GTK_CELL_RENDERER(flag_renderer) -> xpad = 3; /* Ugly but how to set it otherwise ?*/
-printf ("phase 3\n");
+
     text_renderer = gtk_cell_renderer_text_new ();
     gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), text_renderer, FALSE);
-printf ("phase 4\n");
+
     if (set_name)
 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), text_renderer,
 					"text", CURRENCY_COL_NAME,
@@ -186,10 +188,10 @@
 	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), text_renderer,
 					"text", CURRENCY_COL_CODE,
 					NULL);
-printf ("phase 5\n");
+
     gtk_combo_box_set_active ( GTK_COMBO_BOX (combo_box),
 			       0 );
-printf ("phase 6\n");
+
     return (combo_box);
 }
 
@@ -203,7 +205,7 @@
  * \return TRUE currency found, FALSE currency not found, nothing change
  * */
 gboolean gsb_currency_set_combobox_history ( GtkWidget *combo_box,
-					     gint currency_number )
+                        gint currency_number )
 {
     GtkTreeIter iter;
     gint result;
@@ -286,11 +288,11 @@
      * try to find why. */
     if ( detail_devise_compte )
     {
-	g_signal_handler_block ( (gpointer *) detail_devise_compte,
-                        (gulong) g_object_get_data ( G_OBJECT 
-                        (detail_devise_compte), "changed-hook" ) );
-    old_currency_number = gtk_combo_box_get_active (GTK_COMBO_BOX 
-                        (detail_devise_compte));
+        g_signal_handler_block ( (gpointer *) detail_devise_compte,
+                            (gulong) g_object_get_data ( G_OBJECT 
+                            (detail_devise_compte), "changed-hook" ) );
+        old_currency_number = gtk_combo_box_get_active (GTK_COMBO_BOX 
+                            (detail_devise_compte));
     }
     if ( combo_devise_totaux_tiers )
         g_signal_handler_block ( (gpointer *) combo_devise_totaux_tiers,
@@ -346,11 +348,11 @@
 
     if ( detail_devise_compte )
     {
-    gtk_combo_box_set_active ( GTK_COMBO_BOX (detail_devise_compte), 
-                    old_currency_number );
-	g_signal_handler_unblock ( detail_devise_compte,
-                        (gulong) g_object_get_data ( G_OBJECT 
-                        (detail_devise_compte), "changed-hook" ) );
+        gtk_combo_box_set_active ( GTK_COMBO_BOX (detail_devise_compte), 
+                        old_currency_number );
+        g_signal_handler_unblock ( detail_devise_compte,
+                            (gulong) g_object_get_data ( G_OBJECT 
+                            (detail_devise_compte), "changed-hook" ) );
     }
     if ( combo_devise_totaux_tiers )
     {
@@ -393,30 +395,70 @@
 {
     gint transaction_currency_number;
     gint account_currency_number;
+    gint link_number;
 
-    account_currency_number = gsb_data_account_get_currency (gsb_data_transaction_get_account_number (transaction_number));
-    transaction_currency_number = gsb_data_transaction_get_currency_number (transaction_number);
+   account_currency_number = gsb_data_account_get_currency (
+                        gsb_data_transaction_get_account_number ( transaction_number ) );
+    transaction_currency_number = gsb_data_transaction_get_currency_number (
+                        transaction_number );
+    link_number = gsb_data_currency_link_search ( account_currency_number,
+                        transaction_currency_number );
 
-    if ( !gsb_data_currency_link_search ( account_currency_number,
-					  transaction_currency_number ))
+    if ( link_number )
     {
-	/* it's a foreign currency, ask for the exchange rate and fees */
-
-	gsb_currency_exchange_dialog ( account_currency_number,
-				       transaction_currency_number,
-				       1,
-				       null_real,
-				       null_real,
-				       FALSE );
+        if ( current_exchange_fees.mantissa )
+            gsb_data_transaction_set_exchange_fees ( transaction_number,
+                        current_exchange_fees );
 
-	gsb_data_transaction_set_exchange_rate ( transaction_number,
-						 gsb_real_abs (current_exchange));
-	gsb_data_transaction_set_exchange_fees ( transaction_number,
-						 current_exchange_fees);
-	if ( current_exchange.mantissa < 0 )
-	    gsb_data_transaction_set_change_between ( transaction_number,
-						      1 );
+        if ( gsb_data_currency_link_get_first_currency (
+         link_number) == account_currency_number )
+        {
+            if ( current_exchange.mantissa == 0 )
+            {
+                gsb_data_transaction_set_exchange_rate ( transaction_number,
+                        gsb_real_abs (
+                        gsb_data_currency_link_get_change_rate (
+                        link_number ) ) );
+            }
+            else
+            {
+                gsb_data_transaction_set_exchange_rate ( transaction_number,
+                        current_exchange );
+            }
+            gsb_data_transaction_set_change_between (transaction_number, 1 );
+        }
+        else
+        {
+            if ( current_exchange.mantissa == 0 )
+            {
+                 gsb_data_transaction_set_exchange_rate ( transaction_number,
+                        gsb_real_abs ( gsb_data_currency_link_get_change_rate (
+                        link_number ) ) );
+            }
+            else
+            {
+               gsb_data_transaction_set_exchange_rate ( transaction_number,
+                        current_exchange );
+            }
+            gsb_data_transaction_set_change_between (transaction_number, 0 );
+        }
+        return;
     }
+
+    if ( current_exchange.mantissa == 0 )
+        gsb_currency_exchange_dialog ( account_currency_number,
+                        transaction_currency_number,
+                        0,
+                        null_real,
+                        null_real,
+                        TRUE );
+
+    gsb_data_transaction_set_exchange_rate ( transaction_number,
+                        gsb_real_abs (current_exchange));
+    if ( current_exchange_fees.mantissa )
+        gsb_data_transaction_set_exchange_fees ( transaction_number,
+                        current_exchange_fees );
+    gsb_data_transaction_set_change_between (transaction_number, 0 );
 }
 
 
@@ -429,7 +471,7 @@
  *
  * \param account_currency_number
  * \param transaction_currency_number
- * \param link_currency si = 1 : 1 nom_devise = "change" devise_en_rapport
+ * \param link_currency si = TRUE : 1 nom_devise = "change" devise_en_rapport
  * \param exchange_rate
  * \param exchange_fees
  * \param force if TRUE will not get the cached exchange rate and will really ask to the user
@@ -437,40 +479,43 @@
  * \return
  * */
 void gsb_currency_exchange_dialog ( gint account_currency_number,
-				    gint transaction_currency_number ,
-				    gint link_currency,
-				    gsb_real exchange_rate,
-				    gsb_real exchange_fees,
-				    gboolean force )
+                        gint transaction_currency_number ,
+                        gboolean link_currency,
+                        gsb_real exchange_rate,
+                        gsb_real exchange_fees,
+                        gboolean force )
 {
     GtkWidget *dialog, *label, *entry, *hbox, *fees_entry, *paddingbox, *table;
-    struct cached_exchange_rate *cache;
-    gint result;
     GtkWidget *combobox_1;
     GtkWidget *combobox_2;
-	gchar* tmpstr;
+    struct cached_exchange_rate *cache;
+    gint link_number;
+    gint result;
+    gchar* tmpstr;
 
     if ( !force
-	 &&
-	 (cache = gsb_currency_config_get_cached_exchange ( account_currency_number, transaction_currency_number )) )
+     &&
+     ( cache = gsb_currency_config_get_cached_exchange (
+     account_currency_number, transaction_currency_number ) ) )
     {
-	current_exchange = cache -> rate;
-	current_exchange_fees = cache -> fees;
-	return;
+        current_exchange = cache -> rate;
+        current_exchange_fees = cache -> fees;
+        return;
     }
 
     dialog = gtk_dialog_new_with_buttons ( _("Enter exchange rate"),
-					   GTK_WINDOW ( window ),
-					   GTK_DIALOG_MODAL,
-					   GTK_STOCK_OK, 0,
-					   NULL );
+                        GTK_WINDOW ( window ),
+                        GTK_DIALOG_MODAL,
+                        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+                        GTK_STOCK_OK, GTK_RESPONSE_OK,
+                        NULL );
 
     gtk_window_set_position ( GTK_WINDOW ( dialog ), GTK_WIN_POS_CENTER_ON_PARENT );
     gtk_window_set_resizable ( GTK_WINDOW ( dialog ), FALSE );
 
     /* text for paddingbox */
     tmpstr = g_strdup_printf( _("Please enter exchange rate for %s"),
-				     gsb_data_currency_get_name (transaction_currency_number));
+                        gsb_data_currency_get_name (transaction_currency_number));
 
     /* Ugly dance to avoid side effects on dialog's vbox. */
     hbox = gtk_hbox_new ( FALSE, 0 );
@@ -490,16 +535,26 @@
     label = gtk_label_new ( _("1") );
     gtk_misc_set_alignment ( GTK_MISC ( label ), 0.0, 0.0 );
     gtk_table_attach ( GTK_TABLE(table), label, 0, 1, 0, 1,
-               GTK_SHRINK | GTK_FILL, 0, 0, 0 );
+                        GTK_SHRINK | GTK_FILL, 0, 0, 0 );
 
     /* echange line currency 1 */
     combobox_1 = gtk_combo_box_new_text ();
-    gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_1),
-				gsb_data_currency_get_name (transaction_currency_number));
-    gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_1),
-				gsb_data_currency_get_name (account_currency_number));
+    if ( link_currency )
+    {
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_1),
+                            gsb_data_currency_get_name (account_currency_number));
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_1),
+                            gsb_data_currency_get_name (transaction_currency_number));
+    }
+    else
+    {
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_1),
+                            gsb_data_currency_get_name (transaction_currency_number));
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_1),
+                            gsb_data_currency_get_name (account_currency_number));
+    }
     gtk_table_attach ( GTK_TABLE(table), combobox_1, 1, 2, 0, 1,
-               GTK_SHRINK | GTK_FILL, 0, 0, 0 );
+                        GTK_SHRINK | GTK_FILL, 0, 0, 0 );
 
     /* echange line compare sign */
     label = gtk_label_new ( _("=") );
@@ -515,22 +570,32 @@
 
     /* echange line currency 2 */
     combobox_2 = gtk_combo_box_new_text ();
-    gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_2),
-				gsb_data_currency_get_name (account_currency_number));
-    gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_2),
-				gsb_data_currency_get_name (transaction_currency_number));
+    if ( link_currency )
+    {
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_2),
+                            gsb_data_currency_get_name (transaction_currency_number));
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_2),
+                            gsb_data_currency_get_name (account_currency_number));
+    }
+    else
+    {
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_2),
+                            gsb_data_currency_get_name (account_currency_number));
+        gtk_combo_box_append_text ( GTK_COMBO_BOX (combobox_2),
+                            gsb_data_currency_get_name (transaction_currency_number));
+    }
     gtk_table_attach ( GTK_TABLE(table), combobox_2, 4, 5, 0, 1,
                GTK_SHRINK | GTK_FILL, 0, 0, 0 );
 
     /* set the connections */
     g_signal_connect ( G_OBJECT (combobox_1),
-		       "changed",
-		       G_CALLBACK ( gsb_currency_select_change_currency ),
-		       combobox_2 );
+                        "changed",
+                        G_CALLBACK ( gsb_currency_select_change_currency ),
+                        combobox_2 );
     g_signal_connect ( G_OBJECT (combobox_2),
-		       "changed",
-		       G_CALLBACK ( gsb_currency_select_change_currency ),
-		       combobox_1);
+                        "changed",
+                        G_CALLBACK ( gsb_currency_select_change_currency ),
+                        combobox_1);
 
     /* exchange fees line label */
     label = gtk_label_new ( COLON(_("Exchange fees")) );
@@ -552,37 +617,43 @@
 
     gtk_widget_show_all ( dialog );
 
+    link_number = gsb_data_currency_link_search ( account_currency_number,
+                        transaction_currency_number );
+printf ("avant current_exchange = %s\n", gsb_real_get_string (exchange_rate));
     /* if the rate or fees exist already, fill them here */
-    if ( exchange_rate.mantissa || exchange_fees.mantissa )
+    if ( exchange_rate.mantissa )
     {
-	if ( link_currency )
-	{
-	    gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_1),
-				       !link_currency );
-	    gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2),
-				       !link_currency );
-	}
-	else
-	{
-	    gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_1),
-				       link_currency );
-	    gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2),
-				       link_currency );
-	}
-	tmpstr = gsb_real_get_string (exchange_rate);
-	gtk_entry_set_text ( GTK_ENTRY ( entry ), tmpstr);
-	g_free ( tmpstr );
+        if ( link_currency )
+        {
+            gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_1), !link_currency );
+            gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2), !link_currency );
+            gtk_widget_set_sensitive ( GTK_WIDGET (combobox_1), FALSE );
+            gtk_widget_set_sensitive ( GTK_WIDGET (combobox_2), FALSE );
+        }
+        else
+        {
+            gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_1), link_currency );
+            gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2), link_currency );
+            if ( link_number )
+                gtk_widget_set_sensitive ( GTK_WIDGET (combobox_1), FALSE );
+                gtk_widget_set_sensitive ( GTK_WIDGET (combobox_2), FALSE );
+        }
 
-	tmpstr = gsb_real_get_string (gsb_real_abs (exchange_fees));
-	gtk_entry_set_text ( GTK_ENTRY ( fees_entry ), tmpstr);
-	g_free ( tmpstr );
+        tmpstr = gsb_real_get_string (exchange_rate );
+        gtk_entry_set_text ( GTK_ENTRY ( entry ), tmpstr);
+        g_free ( tmpstr );
     }
     else
     {
-	gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_1),
-				   0 );
-	gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2),
-				   0 );
+        gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_1), 0 );
+        gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2), 0 );
+    }
+
+    if ( exchange_fees.mantissa )
+    {
+        tmpstr = gsb_real_get_string (gsb_real_abs (exchange_fees));
+        gtk_entry_set_text ( GTK_ENTRY ( fees_entry ), tmpstr);
+        g_free ( tmpstr );
     }
 
     /* show the dialog */
@@ -590,24 +661,77 @@
 
     if ( result )
     {
-	current_exchange = null_real;
-	current_exchange_fees = null_real;
-    }
-    else
-    {
-	gint tmp_currency_number;
+        gint tmp_currency_number;
+        gint new_link_number;
 
-	current_exchange = gsb_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( entry )));
-	current_exchange_fees = gsb_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( fees_entry )));
+        current_exchange = gsb_real_get_from_string (
+                        gtk_entry_get_text ( GTK_ENTRY ( entry ) ) );
+        current_exchange_fees = gsb_real_get_from_string (
+                        gtk_entry_get_text ( GTK_ENTRY ( fees_entry ) ) );
 
-	tmp_currency_number = gsb_data_currency_get_number_by_name (gtk_combo_box_get_active_text (GTK_COMBO_BOX (combobox_1)));
+        gsb_currency_config_set_cached_exchange ( account_currency_number,
+                        transaction_currency_number,
+                        current_exchange, current_exchange_fees );
 
-	if ( tmp_currency_number != transaction_currency_number )
-	    current_exchange = gsb_real_opposite (current_exchange);
+        if ( link_currency == FALSE )
+        {
+            tmp_currency_number = gsb_data_currency_get_number_by_name (
+                        gtk_combo_box_get_active_text ( GTK_COMBO_BOX ( combobox_1 ) ) );
 
-	gsb_currency_config_set_cached_exchange ( account_currency_number, transaction_currency_number,
-						  current_exchange, current_exchange_fees );
+            if ( tmp_currency_number != transaction_currency_number )
+            {
+                if ( link_number )
+                {
+                    gsb_data_currency_link_set_first_currency ( link_number,
+                        account_currency_number );
+                    gsb_data_currency_link_set_second_currency ( link_number,
+                        transaction_currency_number );
+                    gsb_data_currency_link_set_change_rate ( link_number,
+                        current_exchange );
+                }
+                else
+                {
+                    new_link_number = gsb_data_currency_link_new ( 0 );
+                    if ( new_link_number )
+                    {
+                        gsb_data_currency_link_set_first_currency ( new_link_number,
+                                account_currency_number );
+                        gsb_data_currency_link_set_second_currency ( new_link_number,
+                                transaction_currency_number );
+                        gsb_data_currency_link_set_change_rate ( new_link_number,
+                                current_exchange );
+                    }
+                }
+                gtk_widget_destroy ( GTK_WIDGET ( dialog ));
+                return;
+            }
+        }
+
+        if ( link_number )
+        {
+            if ( gsb_real_cmp ( current_exchange,
+                        gsb_data_currency_link_get_change_rate (
+                        link_number ) ) != 0 )
+                gsb_data_currency_link_set_change_rate ( link_number,
+                        current_exchange );
+        }
+        else
+        {
+            new_link_number = gsb_data_currency_link_new ( 0 );
+            if ( new_link_number )
+            {
+                gsb_data_currency_link_set_first_currency ( new_link_number,
+                        transaction_currency_number );
+                gsb_data_currency_link_set_second_currency ( new_link_number,
+                        account_currency_number );
+                gsb_data_currency_link_set_change_rate ( new_link_number,
+                        current_exchange );
+            }
+        }
     }
+    else
+        gsb_currency_init_exchanges ( );
+
     gtk_widget_destroy ( GTK_WIDGET ( dialog ));
 }
 
@@ -625,7 +749,7 @@
  * structure on success.
  */
 struct cached_exchange_rate *gsb_currency_config_get_cached_exchange ( gint currency1_number,
-								       gint currency2_number )
+                        gint currency2_number )
 {
     GSList * tmp_list = cached_exchange_rates;
 
@@ -652,8 +776,8 @@
  * \param fees      Fees of transaction.
  */
 void gsb_currency_config_set_cached_exchange ( gint currency1_number,
-					       gint currency2_number,
-					       gsb_real change, gsb_real fees )
+                        gint currency2_number,
+                        gsb_real change, gsb_real fees )
 {
     struct cached_exchange_rate * tmp;
 
@@ -680,18 +804,12 @@
  * \return FALSE
  */
 gboolean gsb_currency_select_change_currency ( GtkWidget *combobox_1,
-					       GtkWidget *combobox_2 )
+                        GtkWidget *combobox_2 )
 {
     /* we just need to set the same active menu on the second combobox */
 
-    /*     g_signal_handlers_block_by_func ( G_OBJECT(combobox_2), */
-    /* 				      G_CALLBACK (gsb_currency_select_change_currency),  */
-    /* 				      combobox_1 ); */
     gtk_combo_box_set_active ( GTK_COMBO_BOX (combobox_2),
 			       gtk_combo_box_get_active ( GTK_COMBO_BOX (combobox_1)));
-    /*     g_signal_handlers_unblock_by_func ( G_OBJECT(combobox_2), */
-    /* 					G_CALLBACK (gsb_currency_select_change_currency),  */
-    /* 					combobox_1 ); */
 
     return FALSE;
 }
@@ -723,7 +841,11 @@
 }
 
 
-
+void gsb_currency_init_exchanges ( void )
+{
+    current_exchange = null_real;
+    current_exchange_fees = null_real;
+}
 
 /* Local Variables: */
 /* c-basic-offset: 4 */



More information about the cvs mailing list