[grisbi-cvs] grisbi/src gsb_currency_config.c, 1.55, 1.56 gsb_currency_config.h, 1.14, 1.15 import.c, 1.285, 1.286

Pierre Biava pbiava at users.sourceforge.net
Sat Aug 29 22:26:04 CEST 2009


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

Modified Files:
	gsb_currency_config.c gsb_currency_config.h import.c 
Log Message:
Fixed a bug creating currency when you are importing a file gnucash

Index: gsb_currency_config.h
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_currency_config.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- gsb_currency_config.h	16 Dec 2008 20:40:21 -0000	1.14
+++ gsb_currency_config.h	29 Aug 2009 20:26:02 -0000	1.15
@@ -52,6 +52,8 @@
 
 
 /* START_DECLARATION */
+gboolean gsb_currency_config_add_currency ( GtkWidget *button,
+					    GtkTreeModel *currency_tree_model );
 gboolean gsb_currency_config_add_currency_set_combobox ( GtkWidget * button,
 							 GtkWidget * combobox );
 GtkWidget *gsb_currency_config_create_box_popup ( GCallback select_callback );

Index: import.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/import.c,v
retrieving revision 1.285
retrieving revision 1.286
diff -u -d -r1.285 -r1.286
--- import.c	24 Aug 2009 13:56:59 -0000	1.285
+++ import.c	29 Aug 2009 20:26:02 -0000	1.286
@@ -39,6 +39,7 @@
 #include "./utils_buttons.h"
 #include "./gsb_combo_box.h"
 #include "./gsb_currency.h"
+#include "gsb_currency_config.h"
 #include "./gsb_data_account.h"
 #include "./gsb_data_category.h"
 #include "./gsb_data_currency.h"
@@ -93,6 +94,7 @@
 static void confirmation_enregistrement_ope_import ( struct struct_compte_importation *imported_account );
 static void cree_liens_virements_ope_import ( void );
 static GtkWidget * cree_ligne_recapitulatif ( struct struct_compte_importation * compte );
+static gint gsb_import_add_currency ( struct struct_compte_importation * compte );
 static void gsb_import_add_imported_transactions ( struct struct_compte_importation *imported_account,
                         gint account_number );
 static void gsb_import_associations_add_assoc ( GtkWidget *button, GtkWidget *main_widget );
@@ -142,6 +144,9 @@
 extern GtkWidget *menu_import_rules;
 extern gint mise_a_jour_liste_comptes_accueil;
 extern gint mise_a_jour_soldes_minimaux;
+extern gint no_devise_totaux_categ;
+extern gint no_devise_totaux_ib;
+extern gint no_devise_totaux_tiers;
 extern GtkWidget *window;
 /*END_EXTERN*/
 
@@ -190,7 +195,7 @@
 GSList *liste_comptes_importes_error;
 static gint virements_a_chercher;
 
-gchar   * charmap_imported;
+gchar   *charmap_imported;
 
 /* gestion des associations entre un tiers et sa chaine de recherche */
 GSList *liste_associations_tiers = NULL;
@@ -331,7 +336,7 @@
  *
  *
  */
-GtkWidget * import_create_file_selection_page ( GtkWidget * assistant )
+GtkWidget *import_create_file_selection_page ( GtkWidget * assistant )
 {
     GtkWidget * vbox, * paddingbox, * chooser, * tree_view, * sw;
     GtkTreeViewColumn *column;
@@ -756,7 +761,7 @@
  *
  *
  */
-GtkWidget * import_create_resume_page ( GtkWidget * assistant )
+GtkWidget *import_create_resume_page ( GtkWidget * assistant )
 {
     GtkWidget * view;
     GtkTextBuffer * buffer;
@@ -921,12 +926,11 @@
 }
 
 
-
 /**
  *
  *
  */
-GtkWidget * import_create_final_page ( GtkWidget * assistant )
+GtkWidget *import_create_final_page ( GtkWidget * assistant )
 {
     GtkWidget * view;
     GtkTextBuffer * buffer;
@@ -960,13 +964,12 @@
 }
 
 
-
 /**
  *
  *
  *
  */
-GSList * import_selected_files ( GtkWidget * assistant )
+GSList *import_selected_files ( GtkWidget * assistant )
 {
     GSList * list = NULL;
     GtkTreeModel * model;
@@ -1001,7 +1004,6 @@
 }
 
 
-
 /**
  * this is the summary page of the import assistant
  * show what accounts will be imported in grisbi
@@ -1053,7 +1055,7 @@
  *
  *
  */
-GtkWidget * cree_ligne_recapitulatif ( struct struct_compte_importation * compte )
+GtkWidget *cree_ligne_recapitulatif ( struct struct_compte_importation * compte )
 {
     GtkWidget * vbox, * hbox, * label, * radio, * radiogroup;
     GtkWidget * alignement;
@@ -1061,7 +1063,7 @@
     gint size = 0, spacing = 0;
     gint account_number;
     GtkWidget *button;
-	gchar* tmpstr;
+    gchar* tmpstr;
 
     vbox = gtk_vbox_new ( FALSE, 6 );
     gtk_container_set_border_width ( GTK_CONTAINER(vbox), 12 );
@@ -1130,13 +1132,11 @@
                         GSB_TYPE_BANK );
     }
 
-
     g_object_set_data ( G_OBJECT ( radio ), "associated", compte -> hbox1 );
     g_object_set_data ( G_OBJECT ( radio ), "account", compte );
     g_signal_connect ( G_OBJECT ( radio ), "toggled",
                         G_CALLBACK ( import_account_action_activated ), IMPORT_CREATE_ACCOUNT );
 
-
     /* Add to account */
     radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radiogroup ),
                         _("Add transactions to an account") );
@@ -1211,37 +1211,23 @@
     /* create the currency if doesn't exist */
     if ( compte -> devise )
     {
-    gint currency_number;
+        gint currency_number;
 
-    /* First, we search currency from ISO4217 code for existing currencies */
-    currency_number = gsb_data_currency_get_number_by_code_iso4217 ( compte -> devise );
-    /* Then, by nickname for existing currencies */
-    if ( !currency_number )
-        currency_number = gsb_data_currency_get_number_by_name ( compte -> devise );
+        /* First, we search currency from ISO4217 code for existing currencies */
+        currency_number = gsb_data_currency_get_number_by_code_iso4217 ( compte -> devise );
+        /* Then, by nickname for existing currencies */
+        if ( !currency_number )
+        {
+            currency_number = gsb_import_add_currency ( compte );
+            if ( currency_number == 0 )
+                currency_number = gsb_data_currency_get_number_by_name ( compte -> devise );
+        }
 
-    if (currency_number)
-        gsb_currency_set_combobox_history ( compte -> bouton_devise,
-                        currency_number);
-    else
-    {
-        /* la devise avait un nom mais n'a pas été retrouvée; 2 possibilités :
-         *      - soit elle n'est pas cree (l'utilisateur
-         *           la créera une fois la fenetre affichée)
-         *      - soit elle est créé mais pas avec le bon code */
-        gchar* tmpstr1 = g_strdup_printf ( 
-                        _( "Currency of imported account '%s' is %s.  Either this currency "
-                          "doesn't exist so you have to create it in next window, or this "
-                          "currency already exists but the ISO code is wrong.\nTo avoid this "
-                          "message, please set its ISO code in configuration."),
-                        compte -> nom_de_compte,
-                        compte -> devise );
-        gchar* tmpstr2 = g_strdup_printf ( 
-                        _("Can't associate ISO 4217 code for currency '%s'."),
-                        compte -> devise );
-        dialogue_warning_hint ( tmpstr1, tmpstr2);
-        g_free ( tmpstr1 );
-        g_free ( tmpstr2 );
-    }
+        if ( currency_number )
+            gsb_currency_set_combobox_history ( compte -> bouton_devise,
+                        currency_number );
+        else
+            currency_number = gsb_import_add_currency ( compte );
     }
 
     gtk_box_pack_start ( GTK_BOX ( hbox ), compte -> bouton_devise, FALSE, FALSE, 0 );
@@ -1272,6 +1258,73 @@
     return vbox;
 }
 
+
+/**
+ *
+ *
+ *
+ */
+gint gsb_import_add_currency ( struct struct_compte_importation * compte )
+{
+    GtkWidget *vbox, *checkbox, *dialog;
+    gint response;
+    gchar *tmpstr;
+    gchar *tmpstr2;
+    gchar *text;
+    gint currency_number = 0;
+
+    tmpstr = g_strdup_printf ( 
+                        _("The account currency imported %s is %s.\nThis currency "
+                        "doesn't exist so you have to create it by selecting OK.\n"
+                        "\n"
+                        "Do you create it ?"),
+                        compte -> nom_de_compte,
+                        compte -> devise );
+    tmpstr2 = g_strdup_printf ( 
+                        _("Can't associate ISO 4217 code for currency '%s'."),
+                        compte -> devise );
+    text = make_hint ( tmpstr2, tmpstr );
+    g_free ( tmpstr );
+    g_free ( tmpstr2 );
+
+    dialog = gtk_message_dialog_new ( GTK_WINDOW ( window ),
+                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                        GTK_MESSAGE_QUESTION,
+                        GTK_BUTTONS_YES_NO,
+                        text );
+    gtk_label_set_markup ( GTK_LABEL ( GTK_MESSAGE_DIALOG ( dialog ) ->label ), text );
+
+    vbox = GTK_DIALOG(dialog) -> vbox;
+
+    checkbox = gtk_check_button_new_with_label ( 
+                        _("Use this currency for totals for the payees categories\n"
+                        "and budgetary lines") );
+    gtk_box_pack_start ( GTK_BOX ( vbox ), checkbox, TRUE, TRUE, 6 );
+
+    gtk_widget_show_all ( checkbox );
+    gtk_window_set_modal ( GTK_WINDOW ( dialog ), TRUE );
+
+    response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+    if ( response == GTK_RESPONSE_YES
+     &&
+     gsb_currency_config_add_currency ( NULL, NULL ) )
+    {
+        currency_number = gsb_data_currency_get_number_by_code_iso4217 (
+                        compte -> devise );
+        if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( checkbox ) ) )
+        {
+            no_devise_totaux_tiers = currency_number;
+            no_devise_totaux_categ = currency_number;
+            no_devise_totaux_ib = currency_number;
+        }
+    }
+    gtk_widget_destroy ( dialog );
+
+    return currency_number;
+}
+
+
 /**
  *
  *
@@ -1298,7 +1351,6 @@
 }
 
 
-
 /**
  * finish the import
  * go throw all the imported accounts and does what the user asked with

Index: gsb_currency_config.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_currency_config.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- gsb_currency_config.c	24 Aug 2009 13:11:48 -0000	1.55
+++ gsb_currency_config.c	29 Aug 2009 20:26:02 -0000	1.56
@@ -1,8 +1,8 @@
 /* ************************************************************************** */
 /*                                                                            */
-/*     Copyright (C)	2000-2007 Cédric Auger (cedric at grisbi.org)	          */
-/*			2006-2009 Benjamin Drieu (bdrieu at april.org)	                      */
-/* 			http://www.grisbi.org				                              */
+/*     Copyright (C)    2000-2007 Cédric Auger (cedric at grisbi.org)            */
+/*          2006-2009 Benjamin Drieu (bdrieu at april.org)                       */
+/*          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      */
@@ -52,8 +52,6 @@
 /*START_STATIC*/
 static void gsb_currency_append_currency_to_list ( GtkListStore *model,
 					    gint currency_number );
-static gboolean gsb_currency_config_add_currency ( GtkWidget *button,
-					    GtkTreeModel *currency_tree_model );
 static GtkWidget *gsb_currency_config_create_list ();
 static gboolean gsb_currency_config_entry_changed ( GtkWidget *entry,
 					     GtkWidget *tree_view );
@@ -554,7 +552,7 @@
  *
  */
 void gsb_currency_append_currency_to_list ( GtkListStore *model,
-					    gint currency_number )
+                        gint currency_number )
 {
     GdkPixbuf * pixbuf;
     GtkTreeIter iter;
@@ -590,7 +588,7 @@
  * \param tree_view		GtkTreeView that contains selected currency.
  */
 void gsb_currency_config_remove_currency ( GtkWidget *button,
-					   GtkWidget *tree_view )
+                        GtkWidget *tree_view )
 {
     GtkWidget *entry_name, *entry_iso_code, *entry_code, *entry_floating_point;
     GSList *list_tmp;
@@ -724,7 +722,7 @@
  * \return FALSE
  */
 gboolean gsb_currency_config_entry_changed ( GtkWidget *entry,
-					     GtkWidget *tree_view )
+                        GtkWidget *tree_view )
 {
     gint currency_number;
     GtkTreeSelection * selection;
@@ -760,7 +758,7 @@
  *
  */
 gboolean gsb_currency_config_select_currency ( GtkTreeSelection *selection,
-					       gpointer null )
+                        gpointer null )
 {
     gint currency_number;
     GtkWidget *entry_name, *entry_iso_code, *entry_code, *entry_floating_point;
@@ -811,12 +809,8 @@
  */
 GtkWidget *gsb_currency_config_create_totals_page ( void )
 {
-    //~ GtkWidget *vbox_pref, *table, *label;
         GtkWidget *table, *label;
 
-    //~ vbox_pref = new_vbox_with_title_and_icon ( _("Totals currencies"),
-					       //~ "currencies.png" );
-
     table = gtk_table_new ( 2, 2, FALSE );
     gtk_table_set_col_spacings ( GTK_TABLE ( table ), 5 );
     gtk_table_set_row_spacings ( GTK_TABLE ( table ), 5 );
@@ -851,8 +845,6 @@
     gtk_table_attach ( GTK_TABLE ( table ), combo_devise_totaux_ib,
 		       1, 2, 2, 3, GTK_SHRINK | GTK_FILL, 0, 0, 0 );
 
-    //~ gtk_box_pack_start ( GTK_BOX ( vbox_pref ), table, TRUE, TRUE, 0);
-
     return ( table );
 }
 
@@ -928,7 +920,7 @@
  * \return TRUE if currency has been created.
  */
 gboolean gsb_currency_config_add_currency ( GtkWidget *button,
-					    GtkTreeModel *currency_tree_model )
+                        GtkTreeModel *currency_tree_model )
 {
     GtkWidget *dialog, *label, *table, *list, *paddingbox, * main_vbox, * vbox;
     GtkWidget *entry_name, *entry_code, *entry_isocode, *entry_floating_point;
@@ -1091,7 +1083,7 @@
  *
  */
 gboolean gsb_currency_config_add_currency_set_combobox ( GtkWidget * button,
-							 GtkWidget * combobox )
+                        GtkWidget * combobox )
 {
     gsb_currency_config_add_currency ( button, FALSE );
     gsb_currency_set_combobox_history ( combobox, gsb_data_currency_max_number (  ) );
@@ -1111,9 +1103,9 @@
  * \return the number of the new currency
  * */
 gint gsb_currency_config_create_currency ( const gchar *currency_name,
-					   const gchar *currency_code,
-					   const gchar *currency_isocode,
-					   gint floating_point )
+                        const gchar *currency_code,
+                        const gchar *currency_isocode,
+                        gint floating_point )
 {
     gint currency_number;
 
@@ -1227,7 +1219,7 @@
  * \return
  */
 void gsb_currency_config_fill_popup_list ( GtkTreeView * tree_view,
-					   gboolean include_obsolete )
+                        gboolean include_obsolete )
 {
     GtkTreeModel *model;
     GtkTreeIter iter;
@@ -1285,7 +1277,7 @@
  *
  */
 gboolean gsb_currency_config_update_list ( GtkWidget * checkbox,
-					   GtkTreeView * tree_view )
+                        GtkTreeView * tree_view )
 {
     GtkTreeModel * model;
 
@@ -1368,7 +1360,7 @@
  * \return TRUE if found
  */
 gboolean gsb_currency_config_select_default ( GtkTreeModel * tree_model, GtkTreePath * path,
-					      GtkTreeIter * iter, GtkTreeView * tree_view )
+                        GtkTreeIter * iter, GtkTreeView * tree_view )
 {
     struct lconv * conv = localeconv();
     gchar * code, * symbol, * country;



More information about the cvs mailing list