/grisbi-0.8.8/src/import.c
C | 4950 lines | 3489 code | 784 blank | 677 comment | 404 complexity | 6cde808f4aec59a0b9161b996d6d121e MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- /* ************************************************************************** */
- /* */
- /* Copyright (C) 2000-2008 Cédric Auger (cedric@grisbi.org) */
- /* 2004-2008 Benjamin Drieu (bdrieu@april.org) */
- /* 2008-2009 Pierre Biava (grisbi@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 */
- /* the Free Software Foundation; either version 2 of the License, or */
- /* (at your option) any later version. */
- /* */
- /* This program is distributed in the hope that it will be useful, */
- /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
- /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
- /* GNU General Public License for more details. */
- /* */
- /* You should have received a copy of the GNU General Public License */
- /* along with this program; if not, write to the Free Software */
- /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
- /* */
- /* ************************************************************************** */
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include "include.h"
- /*START_INCLUDE*/
- #include "import.h"
- #include "utils.h"
- #include "bet_data.h"
- #include "import_csv.h"
- #include "dialog.h"
- #include "utils_file_selection.h"
- #include "go-charmap-sel.h"
- #include "gsb_account.h"
- #include "gsb_account_property.h"
- #include "gsb_assistant.h"
- #include "gsb_assistant_file.h"
- #include "gsb_automem.h"
- #include "utils_buttons.h"
- #include "gsb_combo_box.h"
- #include "gsb_currency_config.h"
- #include "gsb_currency.h"
- #include "gsb_data_account.h"
- #include "gsb_data_budget.h"
- #include "gsb_data_category.h"
- #include "gsb_data_currency.h"
- #include "gsb_data_form.h"
- #include "gsb_data_fyear.h"
- #include "gsb_data_import_rule.h"
- #include "gsb_data_payee.h"
- #include "gsb_data_payment.h"
- #include "gsb_data_transaction.h"
- #include "utils_dates.h"
- #include "gsb_file.h"
- #include "gsb_file_util.h"
- #include "gsb_form_scheduler.h"
- #include "gsb_form_transaction.h"
- #include "navigation.h"
- #include "menu.h"
- #include "tiers_onglet.h"
- #include "gsb_real.h"
- #include "gsb_status.h"
- #include "utils_str.h"
- #include "gsb_transactions_list.h"
- #include "gtk_combofix.h"
- #include "traitement_variables.h"
- #include "main.h"
- #include "accueil.h"
- #include "parametres.h"
- #include "qif.h"
- #include "transaction_list.h"
- #include "utils_files.h"
- #include "structures.h"
- #include "erreur.h"
- /*END_INCLUDE*/
- /*START_STATIC*/
- static gboolean affichage_recapitulatif_importation ( GtkWidget * assistant );
- static const gchar * autodetect_file_type ( gchar * filename,
- gchar * pointeur_char );
- static gboolean changement_valeur_echelle_recherche_date_import ( GtkWidget *spin_button );
- static gboolean click_dialog_ope_orphelines ( GtkWidget *dialog,
- gint result,
- GtkWidget *liste_ope_celibataires );
- static gboolean click_sur_liste_opes_orphelines ( GtkCellRendererToggle *renderer,
- gchar *ligne,
- GtkTreeModel *store );
- static void confirmation_enregistrement_ope_import ( struct struct_compte_importation *imported_account,
- gint account_number );
- 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 );
- static void gsb_import_associations_cell_edited (GtkCellRendererText *cell,
- const gchar *path_string,
- const gchar *new_text,
- GObject * main_widget );
- static gboolean gsb_import_associations_check_add_button ( GObject * main_widget );
- static void gsb_import_associations_combo_changed ( GtkEditable *editable,
- GObject * main_widget );
- static void gsb_import_associations_del_assoc ( GtkWidget *button, GtkWidget *main_widget );
- static void gsb_import_associations_fill_model ( GtkListStore *list_store );
- static gint gsb_import_associations_find_payee ( gchar *imported_tiers);
- static gboolean gsb_import_associations_select_func ( GtkTreeSelection *selection,
- GtkTreeModel *model,
- GtkTreePath *path,
- gboolean path_currently_selected,
- GObject *main_widget );
- static gchar **gsb_import_by_rule_ask_filename ( gint rule );
- static gboolean gsb_import_by_rule_get_file ( GtkWidget *button,
- GtkWidget *entry );
- static void gsb_import_check_ope_import ( GtkWidget *widget, gpointer data );
- static gboolean gsb_import_check_transaction_link ( gint transaction_number,
- gint tested_transaction );
- static GSList *gsb_import_create_file_chooser ( const char *enc, GtkWidget *parent );
- static gint gsb_import_create_imported_account ( struct struct_compte_importation *imported_account );
- void gsb_import_create_imported_transactions ( struct struct_compte_importation *imported_account,
- gint account_number );
- static gint gsb_import_create_transaction ( struct struct_ope_importation *imported_transaction,
- gint account_number, gchar * origine );
- static gboolean gsb_import_define_action ( struct struct_compte_importation *imported_account,
- gint account_number,
- GDate *first_date_import );
- static GDate *gsb_import_get_first_date ( GSList *import_list );
- static gboolean gsb_import_gunzip_file ( gchar *filename );
- static void gsb_import_lookup_budget ( struct struct_ope_importation *imported_transaction,
- gint transaction_number);
- static GtkWidget *gsb_import_progress_bar_affiche ( struct struct_compte_importation *imported_account );
- static void gsb_import_progress_bar_pulse ( GtkWidget *progress, gint nbre_transaction );
- static gboolean gsb_import_ope_import_test_toggled ( GtkWidget *vbox , gboolean test );
- static void gsb_import_ope_import_toggled ( GtkWidget *button, GtkWidget *vbox );
- 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,
- gint account_number );
- static gboolean import_account_action_activated ( GtkWidget * radio, gint action );
- static gboolean import_active_toggled ( GtkCellRendererToggle * cell, gchar *path_str,
- gpointer model );
- static GtkWidget *import_create_file_selection_page ( GtkWidget * assistant );
- static GtkWidget *import_create_final_page ( GtkWidget * assistant );
- static GtkWidget *import_create_resume_page ( GtkWidget * assistant );
- static gboolean import_enter_file_selection_page ( GtkWidget * assistant );
- static gboolean import_enter_resume_page ( GtkWidget * assistant );
- static void import_preview_maybe_sensitive_next ( GtkWidget * assistant, GtkTreeModel * model );
- static gboolean import_select_file ( GtkWidget * button, GtkWidget * assistant );
- static gboolean import_switch_type ( GtkCellRendererText *cell, const gchar *path,
- const gchar *value, GtkListStore * model );
- static void pointe_opes_importees ( struct struct_compte_importation *imported_account,
- gint account_number );
- static void traitement_operations_importees ( void );
- /*END_STATIC*/
- /*START_EXTERN*/
- 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*/
- /* recopie des types de transaction de la libofx en attendant une version propre */
- typedef enum
- {
- OFX_CREDIT, /**< Generic credit */
- OFX_DEBIT, /**< Generic debit */
- OFX_INT, /**< Interest earned or paid (Note: Depends on signage of amount) */
- OFX_DIV, /**< Dividend */
- OFX_FEE, /**< FI fee */
- OFX_SRVCHG, /**< Service charge */
- OFX_DEP, /**< Deposit */
- OFX_ATM, /**< ATM debit or credit (Note: Depends on signage of amount) */
- OFX_POS, /**< Point of sale debit or credit (Note: Depends on signage of amount) */
- OFX_XFER, /**< Transfer */
- OFX_CHECK, /**< Check */
- OFX_PAYMENT, /**< Electronic payment */
- OFX_CASH, /**< Cash withdrawal */
- OFX_DIRECTDEP, /**< Direct deposit */
- OFX_DIRECTDEBIT,/**< Merchant initiated debit */
- OFX_REPEATPMT, /**< Repeating payment/standing order */
- OFX_OTHER /**< Somer other type of transaction */
- } OFXTransactionType;
- /** Suppported import formats. Plugins may register themselves. */
- static GSList *import_formats = NULL;
- /* set to TRUE if we import some marked R transactions
- * grisbi cannot associate them to a reconcile number, so if TRUE,
- * grisbi will show a dialog to tell people to manually associate them */
- static gboolean marked_r_transactions_imported;
- /** Known built-in import formats. Others are plugins. */
- struct import_format builtin_formats[] =
- {
- { "CSV", N_("Comma Separated Values"), "csv", (import_function) csv_import_csv_account },
- { "QIF", N_("Quicken Interchange Format"), "qif", (import_function) recuperation_donnees_qif },
- { NULL, NULL, NULL, NULL },
- };
- /** used to keep the number of the mother transaction while importing split transactions */
- static gint mother_transaction_number;
- gint valeur_echelle_recherche_date_import;
- GSList *liste_comptes_importes;
- GSList *liste_comptes_importes_error;
- static gint virements_a_chercher;
- gchar *charmap_imported;
- /* gestion des associations entre un tiers et sa chaine de recherche */
- GSList *liste_associations_tiers = NULL;
- /* nombre de transaction ŕ importer qui affiche une barre de progression */
- #define NBRE_TRANSACTION_FOR_PROGRESS_BAR 250
- enum import_filesel_columns
- {
- IMPORT_FILESEL_SELECTED = 0,
- IMPORT_FILESEL_TYPENAME,
- IMPORT_FILESEL_FILENAME,
- IMPORT_FILESEL_REALNAME,
- IMPORT_FILESEL_TYPE,
- IMPORT_FILESEL_CODING,
- IMPORT_FILESEL_NUM_COLS,
- };
- /** Page numbering for the import wizard. */
- enum import_pages
- {
- IMPORT_STARTUP_PAGE,
- IMPORT_FILESEL_PAGE,
- IMPORT_CSV_PAGE,
- IMPORT_RESUME_PAGE,
- IMPORT_FIRST_ACCOUNT_PAGE,
- };
- /**
- * Register built-in import formats as known.
- */
- void register_import_formats ( void )
- {
- gint i;
- for ( i = 0; builtin_formats [ i ] . name != NULL ; i ++ )
- {
- register_import_format ( &builtin_formats [ i ] );
- }
- }
- /**
- * Register a known import format as known.
- *
- * \param format A pointer to a structure describing
- * this import format.
- *
- */
- G_MODULE_EXPORT void register_import_format ( struct import_format *format )
- {
- gchar *tmp_str;
- tmp_str = g_strdup_printf ( _("Adding '%s' as an import format"), format -> name );
- devel_debug ( tmp_str );
- g_free ( tmp_str );
- import_formats = g_slist_append ( import_formats, format );
- }
- /**
- *
- *
- *
- */
- void importer_fichier ( void )
- {
- GtkWidget *assistant;
- gchar* tmp_str;
- gchar *format_str;
- /* if nothing opened, we need to create a new file to set up all the variables */
- if (!gsb_data_currency_get_currency_list ())
- {
- init_variables ();
- gsb_assistant_file_run (FALSE, TRUE);
- return;
- }
- liste_comptes_importes = NULL;
- liste_comptes_importes_error = NULL;
- virements_a_chercher = 0;
- format_str = gsb_import_formats_get_list_formats_to_string ( );
- tmp_str = g_strconcat ( _("This assistant will help you import one or several "
- "files into Grisbi."
- "\n\n"
- "Grisbi will try to do its best to guess which format are imported, "
- "but you may have to manually set them in the list of next page. "
- "So far, the following formats are supported:"
- "\n\n"),
- format_str, NULL );
- assistant = gsb_assistant_new ( _("Importing transactions into Grisbi"),
- tmp_str,
- "impexp.png",
- NULL );
- g_free ( format_str );
- g_free ( tmp_str );
- gsb_assistant_add_page ( assistant,
- import_create_file_selection_page ( assistant ),
- IMPORT_FILESEL_PAGE,
- IMPORT_STARTUP_PAGE,
- IMPORT_RESUME_PAGE,
- G_CALLBACK ( import_enter_file_selection_page ) );
- gsb_assistant_add_page ( assistant,
- import_create_csv_preview_page ( assistant ),
- IMPORT_CSV_PAGE,
- IMPORT_FILESEL_PAGE,
- IMPORT_RESUME_PAGE,
- G_CALLBACK ( import_enter_csv_preview_page ) );
- gsb_assistant_add_page ( assistant,
- import_create_resume_page ( assistant ),
- IMPORT_RESUME_PAGE,
- IMPORT_FILESEL_PAGE,
- IMPORT_FIRST_ACCOUNT_PAGE,
- G_CALLBACK ( import_enter_resume_page ) );
- if ( gsb_assistant_run ( assistant ) == GTK_RESPONSE_APPLY )
- {
- gsb_status_wait ( TRUE );
- traitement_operations_importees ();
- gtk_widget_destroy ( assistant );
- gsb_status_stop_wait ( TRUE );
- }
- else
- {
- gtk_widget_destroy ( assistant );
- }
- }
- /**
- *
- *
- *
- */
- gchar *gsb_import_formats_get_list_formats_to_string ( void )
- {
- GSList *tmp_list = import_formats;
- gchar *format_str = NULL;
- while ( tmp_list )
- {
- gchar* tmp_str;
- struct import_format *format;
- format = (struct import_format *) tmp_list -> data;
- tmp_str = g_strdup_printf (" %s (%s)\n", _(format -> complete_name), format -> name );
-
- if ( format_str == NULL )
- format_str = tmp_str;
- else
- {
- gchar* old_str = format_str;
- format_str = g_strconcat ( format_str, tmp_str, NULL );
- g_free ( tmp_str );
- g_free ( old_str );
- }
- tmp_list = tmp_list -> next;
- }
- return format_str;
- }
- /**
- *
- *
- *
- */
- GtkWidget *import_create_file_selection_page ( GtkWidget * assistant )
- {
- GtkWidget * vbox, * paddingbox, * chooser, * tree_view, * sw;
- GtkTreeViewColumn *column;
- GtkCellRenderer *renderer;
- GtkTreeModel * model, * list_acc;
- GSList * tmp;
- gchar* tmpstr;
- vbox = gtk_vbox_new ( FALSE, 6 );
- gtk_container_set_border_width ( GTK_CONTAINER(vbox), 12 );
- paddingbox = new_paddingbox_with_title ( vbox, TRUE, _("Choose file to import"));
- chooser = gtk_button_new_with_label ( _("Add file to import..." ));
- tmpstr = g_build_filename ( GRISBI_PIXMAPS_DIR, "import.png", NULL );
- gtk_button_set_image ( GTK_BUTTON(chooser),
- gtk_image_new_from_file ( tmpstr ) );
- g_free ( tmpstr );
- gtk_box_pack_start ( GTK_BOX(paddingbox), chooser, FALSE, FALSE, 6 );
- g_signal_connect ( G_OBJECT ( chooser ), "clicked", G_CALLBACK ( import_select_file ),
- assistant );
- /* Scroll for tree view. */
- sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_widget_set_size_request ( sw, 480, 120 );
- gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
- gtk_box_pack_start ( GTK_BOX(paddingbox), sw, TRUE, TRUE, 6 );
- /* Tree view and model. */
- model = GTK_TREE_MODEL ( gtk_tree_store_new ( IMPORT_FILESEL_NUM_COLS, G_TYPE_BOOLEAN,
- G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
- tree_view = gtk_tree_view_new_with_model ( GTK_TREE_MODEL ( model ) );
- gtk_container_add ( GTK_CONTAINER ( sw ), tree_view );
- /* Toggle column. */
- renderer = gtk_cell_renderer_toggle_new ();
- g_signal_connect ( renderer, "toggled", G_CALLBACK (import_active_toggled), model);
- column = gtk_tree_view_column_new_with_attributes ( _("Import"), renderer,
- "active", IMPORT_FILESEL_SELECTED,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ), column );
- /* Type column. */
- renderer = gtk_cell_renderer_combo_new ();
- g_signal_connect ( G_OBJECT (renderer), "edited", G_CALLBACK ( import_switch_type),
- model );
- list_acc = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
- tmp = import_formats;
- while ( tmp )
- {
- GtkTreeIter iter;
- struct import_format *format = (struct import_format *) tmp -> data;
- gtk_list_store_append (GTK_LIST_STORE (list_acc), &iter);
- gtk_list_store_set (GTK_LIST_STORE (list_acc), &iter, 0, format -> name, -1);
- tmp = tmp -> next;
- }
- g_object_set ( renderer,
- "model", list_acc,
- "text-column", 0,
- "editable", TRUE,
- "editable-set", FALSE,
- "has-entry", FALSE,
- NULL );
- column = gtk_tree_view_column_new_with_attributes ( _("Type"), renderer,
- "text", IMPORT_FILESEL_TYPENAME,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ), column );
- /* Name column. */
- renderer = gtk_cell_renderer_text_new ();
- column = gtk_tree_view_column_new_with_attributes ( _("File name"), renderer,
- "text", IMPORT_FILESEL_FILENAME,
- NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ), column );
- g_object_set_data ( G_OBJECT(assistant), "tree_view", tree_view );
- g_object_set_data ( G_OBJECT(assistant), "model", model );
- g_object_set_data ( G_OBJECT(model), "assistant", assistant );
- return vbox;
- }
- /**
- *
- *
- */
- gboolean import_switch_type ( GtkCellRendererText *cell, const gchar *path,
- const gchar *value, GtkListStore * model )
- {
- GtkTreeIter iter;
- GtkWidget * assistant;
- assistant = g_object_get_data ( G_OBJECT (model), "assistant" );
- if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( model ), &iter, path ))
- {
- GSList * tmp = import_formats;
- while ( tmp )
- {
- gchar *contents;
- gchar *nom_fichier;
- gchar *tmp_str;
- GError *error = NULL;
- struct import_format * format;
- format = (struct import_format *) tmp -> data;
- if ( ! strcmp ( value, format -> name ) )
- {
- gtk_tree_store_set ( GTK_TREE_STORE (model), &iter,
- IMPORT_FILESEL_TYPENAME, value,
- IMPORT_FILESEL_TYPE, format -> name,
- -1 );
- /* CSV is special because it needs configuration, so
- * we add a conditional jump there. */
- if ( ! strcmp ( value, "CSV" ) )
- {
- gsb_assistant_set_next ( assistant, IMPORT_FILESEL_PAGE,
- IMPORT_CSV_PAGE );
- gsb_assistant_set_prev ( assistant, IMPORT_RESUME_PAGE,
- IMPORT_CSV_PAGE );
- }
- gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
- IMPORT_FILESEL_REALNAME, &nom_fichier,
- -1 );
- /* get contents of file */
- if ( ! g_file_get_contents ( nom_fichier, &tmp_str, NULL, &error ) )
- {
- g_print ( _("Unable to read file: %s\n"), error -> message);
- g_error_free ( error );
- return FALSE;
- }
- /* Convert in UTF8 */
- contents = g_convert ( tmp_str, -1, "UTF-8", charmap_imported, NULL, NULL, NULL );
- if ( contents == NULL )
- {
- charmap_imported = utils_files_create_sel_charset ( assistant, tmp_str,
- charmap_imported,
- g_path_get_basename ( nom_fichier ) );
- gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
- IMPORT_FILESEL_CODING, charmap_imported,
- -1 );
- g_free ( contents );
- }
- g_free ( tmp_str );
- import_preview_maybe_sensitive_next ( assistant, GTK_TREE_MODEL ( model ));
- }
- tmp = tmp -> next;
- }
- }
- return FALSE;
- }
- /**
- *
- *
- */
- gboolean import_enter_file_selection_page ( GtkWidget * assistant )
- {
- GtkTreeModel * model;
- model = g_object_get_data ( G_OBJECT ( assistant ), "model" );
- import_preview_maybe_sensitive_next ( assistant, model );
- return FALSE;
- }
- /**
- *
- *
- *
- */
- gboolean import_active_toggled ( GtkCellRendererToggle * cell, gchar *path_str,
- gpointer model )
- {
- GtkWidget * assistant;
- GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
- GtkTreeIter iter;
- gboolean toggle_item;
- assistant = g_object_get_data ( G_OBJECT ( model ), "assistant" );
- gtk_tree_model_get_iter ( GTK_TREE_MODEL ( model ), &iter, path);
- gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
- IMPORT_FILESEL_SELECTED, &toggle_item, -1 );
- gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
- IMPORT_FILESEL_SELECTED, !toggle_item, -1 );
- import_preview_maybe_sensitive_next ( assistant, model );
- return FALSE;
- }
- /**
- *
- *
- *
- */
- void import_preview_maybe_sensitive_next ( GtkWidget * assistant, GtkTreeModel * model )
- {
- GtkTreeIter iter;
- /* Don't allow going to next page if no file is selected yet. */
- gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (assistant), "button_next" ), FALSE );
- gtk_tree_model_get_iter_first ( model, &iter );
- if ( ! gtk_tree_store_iter_is_valid ( GTK_TREE_STORE (model), &iter ))
- {
- return;
- }
- /* Iterate over lines so we check if some are checked. */
- do
- {
- gboolean selected;
- gchar * type;
- gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
- IMPORT_FILESEL_SELECTED, &selected,
- IMPORT_FILESEL_TYPE, &type,
- - 1 );
- if ( selected && strcmp ( type, _("Unknown") ) )
- {
- gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (assistant),
- "button_next" ),
- TRUE );
- return;
- }
- }
- while ( gtk_tree_model_iter_next ( model, &iter ) );
- }
- /**
- *
- *
- *
- */
- gboolean import_select_file ( GtkWidget * button, GtkWidget * assistant )
- {
- GSList * filenames, * iterator;
- GtkTreeModel * model;
- filenames = gsb_import_create_file_chooser ( NULL, assistant );
- if (!filenames)
- return FALSE;
- iterator = filenames;
- model = g_object_get_data ( G_OBJECT ( assistant ), "model" );
- while ( iterator && model )
- {
- GtkTreeIter iter;
- const gchar *type;
- gchar *nom_fichier;
- gchar *tmp_str;
- gchar *contents;
- gchar *charmap;
- GError *error = NULL;
- gchar * extension;
- /* Open file */
- extension = strrchr ( iterator -> data, '.' );
- /* unzip Gnucash file if necessary */
- if ( extension && strcmp ( extension, ".gnc" ) == 0 )
- gsb_import_gunzip_file ( iterator -> data );
- /* get contents of file */
- if ( ! g_file_get_contents ( iterator -> data, &tmp_str, NULL, &error ) )
- {
- g_print ( _("Unable to read file: %s\n"), error -> message);
- g_error_free ( error );
- return FALSE;
- }
- type = autodetect_file_type ( iterator -> data, tmp_str );
- /* passe par un fichier temporaire pour bipasser le bug libofx */
- if ( strcmp ( type, "OFX" ) == 0 )
- {
- nom_fichier = g_strconcat (g_get_tmp_dir (),G_DIR_SEPARATOR_S,
- g_path_get_basename ( iterator -> data ), NULL);
- if (! gsb_import_set_tmp_file (nom_fichier, tmp_str ) )
- {
- g_free ( tmp_str );
- return FALSE;
- }
- if ( ( charmap = utils_files_get_ofx_charset ( tmp_str ) ) != NULL )
- {
- if ( charmap_imported && strlen ( charmap_imported ) > 0 )
- g_free ( charmap_imported );
- charmap_imported = charmap;
- }
- }
- else
- nom_fichier = my_strdup (iterator -> data);
- /* CSV is special because it needs configuration, so we
- * add a conditional jump there. */
- if ( ! strcmp ( type, "CSV" ) )
- {
- gsb_assistant_set_next ( assistant, IMPORT_FILESEL_PAGE, IMPORT_CSV_PAGE );
- gsb_assistant_set_prev ( assistant, IMPORT_RESUME_PAGE, IMPORT_CSV_PAGE );
- }
- /* Convert to UTF8 */
- contents = g_convert ( tmp_str, -1, "UTF-8", charmap_imported, NULL, NULL, NULL );
- if ( contents == NULL )
- charmap_imported = utils_files_create_sel_charset ( assistant, tmp_str,
- charmap_imported,
- g_path_get_basename ( iterator -> data ) );
- else
- g_free ( contents );
- gtk_tree_store_append ( GTK_TREE_STORE ( model ), &iter, NULL );
- gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
- IMPORT_FILESEL_SELECTED, TRUE,
- IMPORT_FILESEL_TYPENAME, type,
- IMPORT_FILESEL_FILENAME, g_path_get_basename ( iterator -> data ),
- IMPORT_FILESEL_REALNAME, nom_fichier,
- IMPORT_FILESEL_TYPE, type,
- IMPORT_FILESEL_CODING, charmap_imported,
- -1 );
- g_free ( nom_fichier );
- g_free ( tmp_str );
- if ( strcmp ( type, _("Unknown") ) )
- {
- /* A valid file was selected, so we can now go ahead. */
- gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (assistant), "button_next" ),
- TRUE );
- }
- iterator = iterator -> next;
- }
- if ( filenames )
- g_slist_free ( filenames );
- return FALSE;
- }
- /**
- * create an appropriate dialog file chooser
- * for importing files to grisbi and return the selected files
- *
- * \param
- *
- * \return a GtkFileChooser
- * */
- GSList *gsb_import_create_file_chooser ( const char *enc, GtkWidget *parent )
- {
- GtkWidget * dialog, * hbox, * go_charmap_sel;
- GtkFileFilter * filter, * default_filter;
- gchar * files;
- GSList * tmp;
- struct import_format * format;
- GSList *filenames = NULL;
- gchar* old_str;
- gchar* tmpstr;
- gchar* tmpchar;
- dialog = gtk_file_chooser_dialog_new ( _("Choose files to import."),
- GTK_WINDOW ( parent ),
- GTK_FILE_CHOOSER_ACTION_OPEN,
- GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
- GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER ( dialog ), TRUE );
- gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( dialog ), gsb_file_get_last_path () );
- /* Import filters */
- tmp = import_formats;
- format = (struct import_format *) tmp -> data;
- files = g_strconcat ( "*.", format -> extension, NULL );
- tmp = tmp -> next;
- while ( tmp )
- {
- format = (struct import_format *) tmp -> data;
- old_str = files;
- files = g_strconcat ( files, ", *.", format -> extension, NULL );
- g_free ( old_str );
- tmp = tmp -> next;
- }
- default_filter = gtk_file_filter_new ();
- tmpstr = g_strdup_printf ( _("Known files (%s)"), files );
- gtk_file_filter_set_name ( default_filter, tmpstr );
- g_free ( tmpstr );
- tmp = import_formats;
- while ( tmp )
- {
- GtkFileFilter * format_filter;
- format = (struct import_format *) tmp -> data;
- format_filter = gtk_file_filter_new ();
- tmpstr = g_strdup_printf ( _("%s files (*.%s)"),
- format -> name,
- format -> extension );
- gtk_file_filter_set_name ( format_filter, tmpstr );
- g_free ( tmpstr );
- /* Make it case insensitive */
- tmpstr = g_strdup ( "*." );
- tmpchar = format -> extension;
- while(*tmpchar != '\0' )
- {
- old_str=tmpstr;
- tmpstr = g_strdup_printf ( "%s[%c%c]",
- tmpstr,
- (int)g_ascii_toupper(*tmpchar),
- (int)*tmpchar );
- tmpchar++;
- g_free ( old_str );
- }
- gtk_file_filter_add_pattern ( format_filter, tmpstr );
- /* Add this pattern to the global filter as well*/
- gtk_file_filter_add_pattern ( default_filter, tmpstr );
- g_free ( tmpstr );
- gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), format_filter );
- tmp = tmp -> next;
- }
- gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), default_filter );
- gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( dialog ), default_filter );
- filter = gtk_file_filter_new ();
- gtk_file_filter_set_name ( filter, _("All files") );
- gtk_file_filter_add_pattern ( filter, "*" );
- gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), filter );
- /* Add encoding preview */
- hbox = gtk_hbox_new ( FALSE, 6 );
- gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( dialog ), hbox );
- gtk_box_pack_start ( GTK_BOX ( hbox ), gtk_label_new ( _("Encoding: ") ),
- FALSE, FALSE, 0 );
- go_charmap_sel = go_charmap_sel_new (GO_CHARMAP_SEL_TO_UTF8);
- if (enc && strlen (enc))
- go_charmap_sel_set_encoding ((GOCharmapSel *) go_charmap_sel, enc);
- gtk_box_pack_start ( GTK_BOX ( hbox ), go_charmap_sel, TRUE, TRUE, 0 );
- gtk_widget_show_all ( hbox );
- if ( gtk_dialog_run ( GTK_DIALOG (dialog ) ) == GTK_RESPONSE_ACCEPT )
- filenames = gtk_file_chooser_get_filenames ( GTK_FILE_CHOOSER (dialog));
- /* save charmap */
- charmap_imported = g_strdup (go_charmap_sel_get_encoding ( (GOCharmapSel * )go_charmap_sel ));
- gsb_file_update_last_path (file_selection_get_last_directory (GTK_FILE_CHOOSER (dialog), TRUE));
- gtk_widget_destroy (dialog);
- return filenames;
- }
- /**
- *
- *
- */
- GtkWidget *import_create_resume_page ( GtkWidget * assistant )
- {
- GtkWidget *sw;
- GtkWidget *view;
- GtkTextBuffer *buffer;
- sw = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( sw ),
- GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
- view = gtk_text_view_new ();
- gtk_container_add (GTK_CONTAINER (sw), view);
- gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
- gtk_text_view_set_editable ( GTK_TEXT_VIEW (view), FALSE );
- gtk_text_view_set_cursor_visible ( GTK_TEXT_VIEW (view), FALSE );
- gtk_text_view_set_left_margin ( GTK_TEXT_VIEW (view), 12 );
- gtk_text_view_set_right_margin ( GTK_TEXT_VIEW (view), 12 );
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- gtk_text_buffer_create_tag ( buffer, "bold",
- "weight", PANGO_WEIGHT_BOLD, NULL);
- gtk_text_buffer_create_tag ( buffer, "x-large",
- "scale", PANGO_SCALE_X_LARGE, NULL);
- gtk_text_buffer_create_tag (buffer, "indented",
- "left-margin", 24, NULL);
- g_object_set_data ( G_OBJECT ( assistant ), "text-buffer", buffer );
- return sw;
- }
- /**
- *
- *
- *
- */
- gboolean import_enter_resume_page ( GtkWidget * assistant )
- {
- GSList *files;
- GSList *list;
- GtkTextBuffer * buffer;
- GtkTextIter iter;
- gchar * error_message = "";
- gchar* tmpstr;
- liste_comptes_importes_error = NULL;
- liste_comptes_importes = NULL;
- /* fichiers sélectionnés dans legestionnaire de fichiers */
- files = import_selected_files ( assistant );
- while ( files )
- {
- struct imported_file *imported = files -> data;
- GSList * tmp = import_formats;
- while ( tmp )
- {
- struct import_format *format = (struct import_format *) tmp -> data;
-
- if ( !strcmp ( imported -> type, format -> name ) )
- {
- devel_print_str ( imported -> type );
- format -> import ( assistant, imported );
- tmp = tmp -> next;
- continue;
- }
- tmp = tmp -> next;
- }
- files = files -> next;
- }
- buffer = g_object_get_data ( G_OBJECT ( assistant ), "text-buffer" );
- gtk_text_buffer_set_text (buffer, "\n", -1 );
- gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1);
- if ( liste_comptes_importes )
- {
- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
- _("Congratulations !"), -1,
- "x-large", NULL);
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- gtk_text_buffer_insert (buffer, &iter,
- _("You successfully imported files into Grisbi. The "
- "following pages will help you set up imported data for "
- "the following files"),
- -1 );
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- list = liste_comptes_importes;
- while ( list )
- {
- struct struct_compte_importation * compte;
- compte = list -> data;
- /* Fix account name if needed. */
- if ( ! compte -> nom_de_compte )
- {
- compte -> nom_de_compte = _("Unnamed Imported account");
- }
- devel_print_str ( compte -> nom_de_compte );
- tmpstr = g_strconcat ( " ", compte -> nom_de_compte,
- " (",
- compte -> origine,
- ")\n\n",
- NULL );
- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
- tmpstr ,
- -1, "indented", NULL );
- g_free ( tmpstr );
- list = list -> next;
- }
- while ( gtk_notebook_get_n_pages ( g_object_get_data ( G_OBJECT (assistant),
- "notebook" ) ) > IMPORT_FIRST_ACCOUNT_PAGE )
- {
- gtk_notebook_remove_page ( g_object_get_data ( G_OBJECT (assistant), "notebook" ), -1 );
- }
- affichage_recapitulatif_importation ( assistant );
- }
- else
- {
- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
- _("Error !"), -1,
- "x-large", NULL);
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- gtk_text_buffer_insert (buffer, &iter,
- _("No file has been imported, please double check that they are "
- "valid files. Please make sure that they are not compressed and "
- "that their format is valid."),
- -1 );
- if ( strlen ( error_message ) )
- {
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- gtk_text_buffer_insert (buffer, &iter, error_message, -1 );
- }
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- }
- if ( liste_comptes_importes_error )
- {
- gtk_text_buffer_insert (buffer, &iter, _("The following files are in error: "), -1 );
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- list = liste_comptes_importes_error;
- while ( list )
- {
- struct struct_compte_importation * compte;
- compte = list -> data;
- tmpstr = g_strconcat ( " ", compte -> nom_de_compte,
- " (",
- compte -> origine,
- ")\n\n",
- NULL );
- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
- tmpstr,
- -1, "indented", NULL );
- g_free ( tmpstr );
- list = list -> next;
- }
- }
- return FALSE;
- }
- /**
- *
- *
- */
- GtkWidget *import_create_final_page ( GtkWidget *assistant )
- {
- GtkWidget * view;
- GtkTextBuffer * buffer;
- GtkTextIter iter;
- view = gtk_text_view_new ();
- gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
- gtk_text_view_set_editable ( GTK_TEXT_VIEW (view), FALSE );
- gtk_text_view_set_cursor_visible ( GTK_TEXT_VIEW (view), FALSE );
- gtk_text_view_set_left_margin ( GTK_TEXT_VIEW (view), 12 );
- gtk_text_view_set_right_margin ( GTK_TEXT_VIEW (view), 12 );
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
- gtk_text_buffer_create_tag ( buffer, "x-large",
- "scale", PANGO_SCALE_X_LARGE, NULL);
- gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1);
- gtk_text_buffer_insert (buffer, &iter, "\n", -1 );
- gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
- _("Import terminated"), -1,
- "x-large", NULL);
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- gtk_text_buffer_insert (buffer, &iter,
- _("You have successfully set up transactions import into Grisbi. "
- "Press the 'Close' button to terminate import."),
- -1 );
- gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
- return view;
- }
- /**
- *
- *
- *
- */
- GSList *import_selected_files ( GtkWidget *assistant )
- {
- GSList *list = NULL;
- GtkTreeModel *model;
- GtkTreeIter iter;
- model = g_object_get_data ( G_OBJECT ( assistant ), "model" );
- g_return_val_if_fail ( model, NULL );
- gtk_tree_model_get_iter_first ( model, &iter );
- do
- {
- struct imported_file *imported;
- gboolean selected;
- imported = g_malloc0 ( sizeof ( struct imported_file ) );
- gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
- IMPORT_FILESEL_SELECTED, &selected,
- IMPORT_FILESEL_REALNAME, &(imported -> name),
- IMPORT_FILESEL_TYPE, &(imported -> type),
- IMPORT_FILESEL_CODING, &(imported -> coding_system),
- -1 );
- if ( selected )
- {
- list = g_slist_append ( list, imported );
- }
- }
- while ( gtk_tree_model_iter_next ( model, &iter ) );
- return list;
- }
- /**
- * this is the summary page of the import assistant
- * show what accounts will be imported in grisbi
- * and create the next pages of the assistant, one per account
- *
- * \param assistant
- *
- * \return FALSE
- */
- gboolean affichage_recapitulatif_importation ( GtkWidget * assistant )
- {
- gint page;
- GSList *list_tmp;
- if (!assistant)
- return FALSE;
- /* Initial page is fourth. */
- page = IMPORT_FIRST_ACCOUNT_PAGE;
- /* First, iter to see if we need to create currencies */
- list_tmp = liste_comptes_importes;
- while ( list_tmp )
- {
- struct struct_compte_importation * compte;
- compte = list_tmp -> data;
- /* add one page per account */
- gsb_assistant_add_page ( assistant, cree_ligne_recapitulatif ( list_tmp -> data ),
- page, page - 1, page + 1, G_CALLBACK ( NULL ) );
- page ++;
- list_tmp = list_tmp -> next;
- }
- /* And final page */
- gsb_assistant_add_page ( assistant, import_create_final_page ( assistant ),
- page, page - 1, -1, G_CALLBACK ( NULL ) );
- /* Replace button. */
- gsb_assistant_change_button_next ( assistant, GTK_STOCK_GO_FORWARD, GTK_RESPONSE_YES );
- return ( FALSE );
- }
- /**
- *
- *
- *
- */
- GtkWidget *cree_ligne_recapitulatif ( struct struct_compte_importation * compte )
- {
- GtkWidget * vbox, * hbox, * label, * radio, * radio_add_account,* radiogroup;
- GtkWidget * alignement;
- gchar * short_filename;
- gint size = 0, spacing = 0;
- gint account_number;
- GtkWidget *button;
- gchar* tmpstr;
- vbox = gtk_vbox_new ( FALSE, 6 );
- gtk_container_set_border_width ( GTK_CONTAINER(vbox), 12 );
- if ( compte -> filename )
- short_filename = g_path_get_basename (compte -> filename);
- else
- {
- if (compte -> real_filename)
- short_filename = g_path_get_basename (compte -> real_filename);
- else
- short_filename = g_strdup (_("file"));
- }
- label = gtk_label_new ( NULL );
- gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
- gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
- tmpstr = g_markup_printf_escaped ( _("<span size=\"x-large\">%s</span>\n\n"
- "What do you want to do with contents from <span "
- "foreground=\"blue\">%s</span> ?\n"),
- compte -> nom_de_compte, short_filename );
- gtk_label_set_markup ( GTK_LABEL ( label ), tmpstr );
- g_free ( tmpstr );
- g_free (short_filename);
- gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 0 );
- /* New account */
- radio = gtk_radio_button_new_with_label ( NULL, _("Create a new account") );
- radiogroup = radio;
- gtk_box_pack_start ( GTK_BOX ( vbox ), radio, FALSE, FALSE, 0 );
- gtk_widget_style_get (radio, "indicator_size", &size, NULL);
- gtk_widget_style_get (radio, "indicator_spacing", &spacing, NULL);
- compte -> hbox1 = gtk_hbox_new ( FALSE, 6 );
- gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox1, FALSE, FALSE, 0 );
- label = gtk_label_new ( _("Account type: ") );
- alignement = gtk_alignment_new ( 0.5, 0.5, 1, 1 );
- gtk_container_set_border_width ( GTK_CONTAINER ( alignement ), 2 );
- gtk_alignment_set_padding ( GTK_ALIGNMENT ( alignement ), 0, 0, 2 * spacing + size, 0 );
- gtk_container_add ( GTK_CONTAINER ( alignement ), label );
- gtk_box_pack_start ( GTK_BOX ( compte -> hbox1 ), alignement, FALSE, FALSE, 0 );
- compte -> bouton_type_compte = gsb_combo_box_new_with_index_by_list (
- gsb_account_property_create_combobox_list (),
- NULL, NULL );
- gtk_box_pack_start ( GTK_BOX ( compte -> hbox1 ), compte -> bouton_type_compte,
- TRUE, TRUE, 0 );
- /* at this level imported_account -> type_de_compte was filled while importing transactions,
- * in qif.c or ofx.c ; but we have only 4 kind of account for now, so try to place the combobox correctly
- * and it's the user who will choose the kind of account */
- switch (compte -> type_de_compte)
- {
- case 3:
- gsb_combo_box_set_index ( compte -> bouton_type_compte,
- GSB_TYPE_LIABILITIES );
- break;
- case 7:
- gsb_combo_box_set_index ( compte -> bouton_type_compte,
- GSB_TYPE_CASH );
- break;
- default:
- gsb_combo_box_set_index ( compte -> bouton_type_compte,
- 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_add_account = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radiogroup ),
- _("Add transactions to an account") );
- gtk_box_pack_start ( GTK_BOX ( vbox ), radio_add_account, FALSE, FALSE, 0 );
- if (radio_add_account && GTK_WIDGET_VISIBLE (radio_add_account))
- gtk_widget_set_sensitive ( radio_add_account, assert_account_loaded ( ) );
- compte -> hbox2 = gtk_hbox_new ( FALSE, 6 );
- gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox2, FALSE, FALSE, 0 );
- label = gtk_label_new ( _("Account name: ") );
- alignement = gtk_alignment_new ( 0.5, 0.5, 1, 1 );
- gtk_container_set_border_width ( GTK_CONTAINER ( alignement ), 2 );
- gtk_alignment_set_padding ( GTK_ALIGNMENT ( alignement ), 0, 0, 2 * spacing + size, 0 );
- gtk_container_add ( GTK_CONTAINER ( alignement ), label );
- gtk_box_pack_start ( GTK_BOX ( compte -> hbox2 ), alignement, FALSE, FALSE, 0 );
- compte -> bouton_compte_add = gsb_account_create_combo_list (NULL, NULL, FALSE);
- gtk_box_pack_start ( GTK_BOX ( compte -> hbox2 ), compte -> bouton_compte_add, TRUE, TRUE, 0 );
- gtk_widget_set_sensitive ( compte -> hbox2, FALSE );
- g_object_set_data ( G_OBJECT ( radio_add_account ), "associated", compte -> hbox2 );
- g_object_set_data ( G_OBJECT ( radio_add_account ), "account", compte );
- g_signal_connect ( G_OBJECT ( radio_add_account ), "toggled",
- G_CALLBACK ( import_account_action_activated ),
- GINT_TO_POINTER (IMPORT_ADD_TRANSACTIONS));
- /* Mark account */
- radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radiogroup ),
- _("Mark transactions of an account") );
- gtk_box_pack_start ( GTK_BOX ( vbox ), radio, FALSE, FALSE, 0 );
- gtk_widget_set_sensitive ( radio, assert_account_loaded ( ) );
- compte -> hbox3 = gtk_hbox_new ( FALSE, 6 );
- gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox3, FALSE, FALSE, 0 );
- label = gtk_label_new ( _("Account name: ") );
- alignement = gtk_alignment_new ( 0.5, 0.5, 1, 1 );
- gtk_container_set_border_width ( GTK_CONTAINER ( alignement ), 2 );
- gtk_alignment_set_padding ( GTK_ALIGNMENT ( alignement ), 0, 0, 2 * spacing + size, 0 );
- gtk_container_add ( GTK_CONTAINER ( alignement ), label );
- gtk_box_pack_start ( GTK_BOX ( compte -> hbox3 ), alignement, FALSE, FALSE, 0 );
- compte -> bouton_compte_mark = gsb_account_create_combo_list (NULL, NULL, FALSE);
- gtk_box_pack_start ( GTK_BOX ( compte -> hbox3 ), compte -> bouton_compte_mark, TRUE, TRUE, 0 );
- gtk_widget_set_sensitive ( compte -> hbox3, FALSE );
- g_object_set_data ( G_OBJECT ( radio ), "associated", compte -> hbox3 );
- g_object_set_data ( G_OBJECT ( radio ), "account", compte );
- g_signal_connect ( G_OBJECT ( radio ), "toggled",
- G_CALLBACK ( import_account_action_activated ),
- GINT_TO_POINTER (IMPORT_MARK_TRANSACTIONS));
- /* set on the right account */
- account_number = gsb_data_account_get_account_by_id ( compte->id_compte );
- if ( account_number >= 0 )
- {
- import_account_action_activated ( radio_add_account,IMPORT_ADD_TRANSACTIONS );
- gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( radio_add_account ), TRUE );
- gsb_account_set_combo_account_number ( compte -> bouton_compte_add, account_number );
- gsb_account_set_combo_account_number ( compte -> bouton_compte_mark, account_number );
- }
- /* Currency */
- hbox = gtk_hbox_new ( FALSE, 6 );
- label = gtk_label_new ( _("Account currency: ") );
- gtk_box_pack_start ( GTK_BOX ( hbox ), label, FALSE, FALSE, 0 );
- gtk_box_pack_start ( GTK_BOX ( vbox ), hbox, FALSE, FALSE, 0 );
- compte -> bouton_devise = gsb_currency_make_combobox ( TRUE );
- /* create the currency if doesn't exist */
- if ( compte -> devise )
- {
- 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_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
- currency_number = gsb_import_add_currency ( compte );
- }
- gtk_box_pack_start ( GTK_BOX ( hbox ), compte -> bouton_devise, FALSE, FALSE, 0 );
- /* invert amount of transactions */
- button = gsb_automem_checkbutton_new (_("Invert the amount of the imported transactions"),
- &compte -> invert_transaction_amount, NULL, NULL);
- gtk_box_pack_start ( GTK_BOX ( vbox ), button, FALSE, FALSE, 0 );
- /* propose to create a rule */
- compte -> hbox_rule = gtk_hbox_new (FALSE, 5);
- gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox_rule, FALSE, FALSE, 0 );
- compte -> entry_name_rule = gtk_entry_new ();
- button = gsb_automem_checkbutton_new (_("Create a rule for this import. Name of the rule : "),
- &compte -> create_rule, G_CALLBACK (
- gsb_button_sensitive_by_checkbutton),
- compte -> entry_name_rule);
- gtk_box_pack_start ( GTK_BOX (compte -> hbox_rule), button, FALSE, FALSE, 0 );
- /* we can create a rule only for qif or ofx */
- if (st…
Large files files are truncated, but you can click here to view the full file