PageRenderTime 69ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 1ms

/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

  1. /* ************************************************************************** */
  2. /* */
  3. /* Copyright (C) 2000-2008 Cédric Auger (cedric@grisbi.org) */
  4. /* 2004-2008 Benjamin Drieu (bdrieu@april.org) */
  5. /* 2008-2009 Pierre Biava (grisbi@pierre.biava.name) */
  6. /* http://www.grisbi.org */
  7. /* */
  8. /* This program is free software; you can redistribute it and/or modify */
  9. /* it under the terms of the GNU General Public License as published by */
  10. /* the Free Software Foundation; either version 2 of the License, or */
  11. /* (at your option) any later version. */
  12. /* */
  13. /* This program is distributed in the hope that it will be useful, */
  14. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  15. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  16. /* GNU General Public License for more details. */
  17. /* */
  18. /* You should have received a copy of the GNU General Public License */
  19. /* along with this program; if not, write to the Free Software */
  20. /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  21. /* */
  22. /* ************************************************************************** */
  23. #ifdef HAVE_CONFIG_H
  24. #include <config.h>
  25. #endif
  26. #include "include.h"
  27. /*START_INCLUDE*/
  28. #include "import.h"
  29. #include "utils.h"
  30. #include "bet_data.h"
  31. #include "import_csv.h"
  32. #include "dialog.h"
  33. #include "utils_file_selection.h"
  34. #include "go-charmap-sel.h"
  35. #include "gsb_account.h"
  36. #include "gsb_account_property.h"
  37. #include "gsb_assistant.h"
  38. #include "gsb_assistant_file.h"
  39. #include "gsb_automem.h"
  40. #include "utils_buttons.h"
  41. #include "gsb_combo_box.h"
  42. #include "gsb_currency_config.h"
  43. #include "gsb_currency.h"
  44. #include "gsb_data_account.h"
  45. #include "gsb_data_budget.h"
  46. #include "gsb_data_category.h"
  47. #include "gsb_data_currency.h"
  48. #include "gsb_data_form.h"
  49. #include "gsb_data_fyear.h"
  50. #include "gsb_data_import_rule.h"
  51. #include "gsb_data_payee.h"
  52. #include "gsb_data_payment.h"
  53. #include "gsb_data_transaction.h"
  54. #include "utils_dates.h"
  55. #include "gsb_file.h"
  56. #include "gsb_file_util.h"
  57. #include "gsb_form_scheduler.h"
  58. #include "gsb_form_transaction.h"
  59. #include "navigation.h"
  60. #include "menu.h"
  61. #include "tiers_onglet.h"
  62. #include "gsb_real.h"
  63. #include "gsb_status.h"
  64. #include "utils_str.h"
  65. #include "gsb_transactions_list.h"
  66. #include "gtk_combofix.h"
  67. #include "traitement_variables.h"
  68. #include "main.h"
  69. #include "accueil.h"
  70. #include "parametres.h"
  71. #include "qif.h"
  72. #include "transaction_list.h"
  73. #include "utils_files.h"
  74. #include "structures.h"
  75. #include "erreur.h"
  76. /*END_INCLUDE*/
  77. /*START_STATIC*/
  78. static gboolean affichage_recapitulatif_importation ( GtkWidget * assistant );
  79. static const gchar * autodetect_file_type ( gchar * filename,
  80. gchar * pointeur_char );
  81. static gboolean changement_valeur_echelle_recherche_date_import ( GtkWidget *spin_button );
  82. static gboolean click_dialog_ope_orphelines ( GtkWidget *dialog,
  83. gint result,
  84. GtkWidget *liste_ope_celibataires );
  85. static gboolean click_sur_liste_opes_orphelines ( GtkCellRendererToggle *renderer,
  86. gchar *ligne,
  87. GtkTreeModel *store );
  88. static void confirmation_enregistrement_ope_import ( struct struct_compte_importation *imported_account,
  89. gint account_number );
  90. static void cree_liens_virements_ope_import ( void );
  91. static GtkWidget *cree_ligne_recapitulatif ( struct struct_compte_importation * compte );
  92. static gint gsb_import_add_currency ( struct struct_compte_importation * compte );
  93. static void gsb_import_add_imported_transactions ( struct struct_compte_importation *imported_account,
  94. gint account_number );
  95. static void gsb_import_associations_add_assoc ( GtkWidget *button, GtkWidget *main_widget );
  96. static void gsb_import_associations_cell_edited (GtkCellRendererText *cell,
  97. const gchar *path_string,
  98. const gchar *new_text,
  99. GObject * main_widget );
  100. static gboolean gsb_import_associations_check_add_button ( GObject * main_widget );
  101. static void gsb_import_associations_combo_changed ( GtkEditable *editable,
  102. GObject * main_widget );
  103. static void gsb_import_associations_del_assoc ( GtkWidget *button, GtkWidget *main_widget );
  104. static void gsb_import_associations_fill_model ( GtkListStore *list_store );
  105. static gint gsb_import_associations_find_payee ( gchar *imported_tiers);
  106. static gboolean gsb_import_associations_select_func ( GtkTreeSelection *selection,
  107. GtkTreeModel *model,
  108. GtkTreePath *path,
  109. gboolean path_currently_selected,
  110. GObject *main_widget );
  111. static gchar **gsb_import_by_rule_ask_filename ( gint rule );
  112. static gboolean gsb_import_by_rule_get_file ( GtkWidget *button,
  113. GtkWidget *entry );
  114. static void gsb_import_check_ope_import ( GtkWidget *widget, gpointer data );
  115. static gboolean gsb_import_check_transaction_link ( gint transaction_number,
  116. gint tested_transaction );
  117. static GSList *gsb_import_create_file_chooser ( const char *enc, GtkWidget *parent );
  118. static gint gsb_import_create_imported_account ( struct struct_compte_importation *imported_account );
  119. void gsb_import_create_imported_transactions ( struct struct_compte_importation *imported_account,
  120. gint account_number );
  121. static gint gsb_import_create_transaction ( struct struct_ope_importation *imported_transaction,
  122. gint account_number, gchar * origine );
  123. static gboolean gsb_import_define_action ( struct struct_compte_importation *imported_account,
  124. gint account_number,
  125. GDate *first_date_import );
  126. static GDate *gsb_import_get_first_date ( GSList *import_list );
  127. static gboolean gsb_import_gunzip_file ( gchar *filename );
  128. static void gsb_import_lookup_budget ( struct struct_ope_importation *imported_transaction,
  129. gint transaction_number);
  130. static GtkWidget *gsb_import_progress_bar_affiche ( struct struct_compte_importation *imported_account );
  131. static void gsb_import_progress_bar_pulse ( GtkWidget *progress, gint nbre_transaction );
  132. static gboolean gsb_import_ope_import_test_toggled ( GtkWidget *vbox , gboolean test );
  133. static void gsb_import_ope_import_toggled ( GtkWidget *button, GtkWidget *vbox );
  134. static gboolean gsb_import_set_id_compte ( gint account_nb, gchar *imported_id );
  135. static gboolean gsb_import_set_tmp_file ( gchar *filename,
  136. gchar * pointeur_char );
  137. static void gsb_import_show_orphan_transactions ( GSList *orphan_list,
  138. gint account_number );
  139. static gboolean import_account_action_activated ( GtkWidget * radio, gint action );
  140. static gboolean import_active_toggled ( GtkCellRendererToggle * cell, gchar *path_str,
  141. gpointer model );
  142. static GtkWidget *import_create_file_selection_page ( GtkWidget * assistant );
  143. static GtkWidget *import_create_final_page ( GtkWidget * assistant );
  144. static GtkWidget *import_create_resume_page ( GtkWidget * assistant );
  145. static gboolean import_enter_file_selection_page ( GtkWidget * assistant );
  146. static gboolean import_enter_resume_page ( GtkWidget * assistant );
  147. static void import_preview_maybe_sensitive_next ( GtkWidget * assistant, GtkTreeModel * model );
  148. static gboolean import_select_file ( GtkWidget * button, GtkWidget * assistant );
  149. static gboolean import_switch_type ( GtkCellRendererText *cell, const gchar *path,
  150. const gchar *value, GtkListStore * model );
  151. static void pointe_opes_importees ( struct struct_compte_importation *imported_account,
  152. gint account_number );
  153. static void traitement_operations_importees ( void );
  154. /*END_STATIC*/
  155. /*START_EXTERN*/
  156. extern GtkWidget *menu_import_rules;
  157. extern gint mise_a_jour_liste_comptes_accueil;
  158. extern gint mise_a_jour_soldes_minimaux;
  159. extern gint no_devise_totaux_categ;
  160. extern gint no_devise_totaux_ib;
  161. extern gint no_devise_totaux_tiers;
  162. extern GtkWidget *window;
  163. /*END_EXTERN*/
  164. /* recopie des types de transaction de la libofx en attendant une version propre */
  165. typedef enum
  166. {
  167. OFX_CREDIT, /**< Generic credit */
  168. OFX_DEBIT, /**< Generic debit */
  169. OFX_INT, /**< Interest earned or paid (Note: Depends on signage of amount) */
  170. OFX_DIV, /**< Dividend */
  171. OFX_FEE, /**< FI fee */
  172. OFX_SRVCHG, /**< Service charge */
  173. OFX_DEP, /**< Deposit */
  174. OFX_ATM, /**< ATM debit or credit (Note: Depends on signage of amount) */
  175. OFX_POS, /**< Point of sale debit or credit (Note: Depends on signage of amount) */
  176. OFX_XFER, /**< Transfer */
  177. OFX_CHECK, /**< Check */
  178. OFX_PAYMENT, /**< Electronic payment */
  179. OFX_CASH, /**< Cash withdrawal */
  180. OFX_DIRECTDEP, /**< Direct deposit */
  181. OFX_DIRECTDEBIT,/**< Merchant initiated debit */
  182. OFX_REPEATPMT, /**< Repeating payment/standing order */
  183. OFX_OTHER /**< Somer other type of transaction */
  184. } OFXTransactionType;
  185. /** Suppported import formats. Plugins may register themselves. */
  186. static GSList *import_formats = NULL;
  187. /* set to TRUE if we import some marked R transactions
  188. * grisbi cannot associate them to a reconcile number, so if TRUE,
  189. * grisbi will show a dialog to tell people to manually associate them */
  190. static gboolean marked_r_transactions_imported;
  191. /** Known built-in import formats. Others are plugins. */
  192. struct import_format builtin_formats[] =
  193. {
  194. { "CSV", N_("Comma Separated Values"), "csv", (import_function) csv_import_csv_account },
  195. { "QIF", N_("Quicken Interchange Format"), "qif", (import_function) recuperation_donnees_qif },
  196. { NULL, NULL, NULL, NULL },
  197. };
  198. /** used to keep the number of the mother transaction while importing split transactions */
  199. static gint mother_transaction_number;
  200. gint valeur_echelle_recherche_date_import;
  201. GSList *liste_comptes_importes;
  202. GSList *liste_comptes_importes_error;
  203. static gint virements_a_chercher;
  204. gchar *charmap_imported;
  205. /* gestion des associations entre un tiers et sa chaine de recherche */
  206. GSList *liste_associations_tiers = NULL;
  207. /* nombre de transaction ŕ importer qui affiche une barre de progression */
  208. #define NBRE_TRANSACTION_FOR_PROGRESS_BAR 250
  209. enum import_filesel_columns
  210. {
  211. IMPORT_FILESEL_SELECTED = 0,
  212. IMPORT_FILESEL_TYPENAME,
  213. IMPORT_FILESEL_FILENAME,
  214. IMPORT_FILESEL_REALNAME,
  215. IMPORT_FILESEL_TYPE,
  216. IMPORT_FILESEL_CODING,
  217. IMPORT_FILESEL_NUM_COLS,
  218. };
  219. /** Page numbering for the import wizard. */
  220. enum import_pages
  221. {
  222. IMPORT_STARTUP_PAGE,
  223. IMPORT_FILESEL_PAGE,
  224. IMPORT_CSV_PAGE,
  225. IMPORT_RESUME_PAGE,
  226. IMPORT_FIRST_ACCOUNT_PAGE,
  227. };
  228. /**
  229. * Register built-in import formats as known.
  230. */
  231. void register_import_formats ( void )
  232. {
  233. gint i;
  234. for ( i = 0; builtin_formats [ i ] . name != NULL ; i ++ )
  235. {
  236. register_import_format ( &builtin_formats [ i ] );
  237. }
  238. }
  239. /**
  240. * Register a known import format as known.
  241. *
  242. * \param format A pointer to a structure describing
  243. * this import format.
  244. *
  245. */
  246. G_MODULE_EXPORT void register_import_format ( struct import_format *format )
  247. {
  248. gchar *tmp_str;
  249. tmp_str = g_strdup_printf ( _("Adding '%s' as an import format"), format -> name );
  250. devel_debug ( tmp_str );
  251. g_free ( tmp_str );
  252. import_formats = g_slist_append ( import_formats, format );
  253. }
  254. /**
  255. *
  256. *
  257. *
  258. */
  259. void importer_fichier ( void )
  260. {
  261. GtkWidget *assistant;
  262. gchar* tmp_str;
  263. gchar *format_str;
  264. /* if nothing opened, we need to create a new file to set up all the variables */
  265. if (!gsb_data_currency_get_currency_list ())
  266. {
  267. init_variables ();
  268. gsb_assistant_file_run (FALSE, TRUE);
  269. return;
  270. }
  271. liste_comptes_importes = NULL;
  272. liste_comptes_importes_error = NULL;
  273. virements_a_chercher = 0;
  274. format_str = gsb_import_formats_get_list_formats_to_string ( );
  275. tmp_str = g_strconcat ( _("This assistant will help you import one or several "
  276. "files into Grisbi."
  277. "\n\n"
  278. "Grisbi will try to do its best to guess which format are imported, "
  279. "but you may have to manually set them in the list of next page. "
  280. "So far, the following formats are supported:"
  281. "\n\n"),
  282. format_str, NULL );
  283. assistant = gsb_assistant_new ( _("Importing transactions into Grisbi"),
  284. tmp_str,
  285. "impexp.png",
  286. NULL );
  287. g_free ( format_str );
  288. g_free ( tmp_str );
  289. gsb_assistant_add_page ( assistant,
  290. import_create_file_selection_page ( assistant ),
  291. IMPORT_FILESEL_PAGE,
  292. IMPORT_STARTUP_PAGE,
  293. IMPORT_RESUME_PAGE,
  294. G_CALLBACK ( import_enter_file_selection_page ) );
  295. gsb_assistant_add_page ( assistant,
  296. import_create_csv_preview_page ( assistant ),
  297. IMPORT_CSV_PAGE,
  298. IMPORT_FILESEL_PAGE,
  299. IMPORT_RESUME_PAGE,
  300. G_CALLBACK ( import_enter_csv_preview_page ) );
  301. gsb_assistant_add_page ( assistant,
  302. import_create_resume_page ( assistant ),
  303. IMPORT_RESUME_PAGE,
  304. IMPORT_FILESEL_PAGE,
  305. IMPORT_FIRST_ACCOUNT_PAGE,
  306. G_CALLBACK ( import_enter_resume_page ) );
  307. if ( gsb_assistant_run ( assistant ) == GTK_RESPONSE_APPLY )
  308. {
  309. gsb_status_wait ( TRUE );
  310. traitement_operations_importees ();
  311. gtk_widget_destroy ( assistant );
  312. gsb_status_stop_wait ( TRUE );
  313. }
  314. else
  315. {
  316. gtk_widget_destroy ( assistant );
  317. }
  318. }
  319. /**
  320. *
  321. *
  322. *
  323. */
  324. gchar *gsb_import_formats_get_list_formats_to_string ( void )
  325. {
  326. GSList *tmp_list = import_formats;
  327. gchar *format_str = NULL;
  328. while ( tmp_list )
  329. {
  330. gchar* tmp_str;
  331. struct import_format *format;
  332. format = (struct import_format *) tmp_list -> data;
  333. tmp_str = g_strdup_printf (" • %s (%s)\n", _(format -> complete_name), format -> name );
  334. if ( format_str == NULL )
  335. format_str = tmp_str;
  336. else
  337. {
  338. gchar* old_str = format_str;
  339. format_str = g_strconcat ( format_str, tmp_str, NULL );
  340. g_free ( tmp_str );
  341. g_free ( old_str );
  342. }
  343. tmp_list = tmp_list -> next;
  344. }
  345. return format_str;
  346. }
  347. /**
  348. *
  349. *
  350. *
  351. */
  352. GtkWidget *import_create_file_selection_page ( GtkWidget * assistant )
  353. {
  354. GtkWidget * vbox, * paddingbox, * chooser, * tree_view, * sw;
  355. GtkTreeViewColumn *column;
  356. GtkCellRenderer *renderer;
  357. GtkTreeModel * model, * list_acc;
  358. GSList * tmp;
  359. gchar* tmpstr;
  360. vbox = gtk_vbox_new ( FALSE, 6 );
  361. gtk_container_set_border_width ( GTK_CONTAINER(vbox), 12 );
  362. paddingbox = new_paddingbox_with_title ( vbox, TRUE, _("Choose file to import"));
  363. chooser = gtk_button_new_with_label ( _("Add file to import..." ));
  364. tmpstr = g_build_filename ( GRISBI_PIXMAPS_DIR, "import.png", NULL );
  365. gtk_button_set_image ( GTK_BUTTON(chooser),
  366. gtk_image_new_from_file ( tmpstr ) );
  367. g_free ( tmpstr );
  368. gtk_box_pack_start ( GTK_BOX(paddingbox), chooser, FALSE, FALSE, 6 );
  369. g_signal_connect ( G_OBJECT ( chooser ), "clicked", G_CALLBACK ( import_select_file ),
  370. assistant );
  371. /* Scroll for tree view. */
  372. sw = gtk_scrolled_window_new (NULL, NULL);
  373. gtk_widget_set_size_request ( sw, 480, 120 );
  374. gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN);
  375. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC,
  376. GTK_POLICY_AUTOMATIC);
  377. gtk_box_pack_start ( GTK_BOX(paddingbox), sw, TRUE, TRUE, 6 );
  378. /* Tree view and model. */
  379. model = GTK_TREE_MODEL ( gtk_tree_store_new ( IMPORT_FILESEL_NUM_COLS, G_TYPE_BOOLEAN,
  380. G_TYPE_STRING, G_TYPE_STRING,
  381. G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING));
  382. tree_view = gtk_tree_view_new_with_model ( GTK_TREE_MODEL ( model ) );
  383. gtk_container_add ( GTK_CONTAINER ( sw ), tree_view );
  384. /* Toggle column. */
  385. renderer = gtk_cell_renderer_toggle_new ();
  386. g_signal_connect ( renderer, "toggled", G_CALLBACK (import_active_toggled), model);
  387. column = gtk_tree_view_column_new_with_attributes ( _("Import"), renderer,
  388. "active", IMPORT_FILESEL_SELECTED,
  389. NULL);
  390. gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ), column );
  391. /* Type column. */
  392. renderer = gtk_cell_renderer_combo_new ();
  393. g_signal_connect ( G_OBJECT (renderer), "edited", G_CALLBACK ( import_switch_type),
  394. model );
  395. list_acc = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
  396. tmp = import_formats;
  397. while ( tmp )
  398. {
  399. GtkTreeIter iter;
  400. struct import_format *format = (struct import_format *) tmp -> data;
  401. gtk_list_store_append (GTK_LIST_STORE (list_acc), &iter);
  402. gtk_list_store_set (GTK_LIST_STORE (list_acc), &iter, 0, format -> name, -1);
  403. tmp = tmp -> next;
  404. }
  405. g_object_set ( renderer,
  406. "model", list_acc,
  407. "text-column", 0,
  408. "editable", TRUE,
  409. "editable-set", FALSE,
  410. "has-entry", FALSE,
  411. NULL );
  412. column = gtk_tree_view_column_new_with_attributes ( _("Type"), renderer,
  413. "text", IMPORT_FILESEL_TYPENAME,
  414. NULL);
  415. gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ), column );
  416. /* Name column. */
  417. renderer = gtk_cell_renderer_text_new ();
  418. column = gtk_tree_view_column_new_with_attributes ( _("File name"), renderer,
  419. "text", IMPORT_FILESEL_FILENAME,
  420. NULL);
  421. gtk_tree_view_append_column (GTK_TREE_VIEW ( tree_view ), column );
  422. g_object_set_data ( G_OBJECT(assistant), "tree_view", tree_view );
  423. g_object_set_data ( G_OBJECT(assistant), "model", model );
  424. g_object_set_data ( G_OBJECT(model), "assistant", assistant );
  425. return vbox;
  426. }
  427. /**
  428. *
  429. *
  430. */
  431. gboolean import_switch_type ( GtkCellRendererText *cell, const gchar *path,
  432. const gchar *value, GtkListStore * model )
  433. {
  434. GtkTreeIter iter;
  435. GtkWidget * assistant;
  436. assistant = g_object_get_data ( G_OBJECT (model), "assistant" );
  437. if ( gtk_tree_model_get_iter_from_string ( GTK_TREE_MODEL ( model ), &iter, path ))
  438. {
  439. GSList * tmp = import_formats;
  440. while ( tmp )
  441. {
  442. gchar *contents;
  443. gchar *nom_fichier;
  444. gchar *tmp_str;
  445. GError *error = NULL;
  446. struct import_format * format;
  447. format = (struct import_format *) tmp -> data;
  448. if ( ! strcmp ( value, format -> name ) )
  449. {
  450. gtk_tree_store_set ( GTK_TREE_STORE (model), &iter,
  451. IMPORT_FILESEL_TYPENAME, value,
  452. IMPORT_FILESEL_TYPE, format -> name,
  453. -1 );
  454. /* CSV is special because it needs configuration, so
  455. * we add a conditional jump there. */
  456. if ( ! strcmp ( value, "CSV" ) )
  457. {
  458. gsb_assistant_set_next ( assistant, IMPORT_FILESEL_PAGE,
  459. IMPORT_CSV_PAGE );
  460. gsb_assistant_set_prev ( assistant, IMPORT_RESUME_PAGE,
  461. IMPORT_CSV_PAGE );
  462. }
  463. gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
  464. IMPORT_FILESEL_REALNAME, &nom_fichier,
  465. -1 );
  466. /* get contents of file */
  467. if ( ! g_file_get_contents ( nom_fichier, &tmp_str, NULL, &error ) )
  468. {
  469. g_print ( _("Unable to read file: %s\n"), error -> message);
  470. g_error_free ( error );
  471. return FALSE;
  472. }
  473. /* Convert in UTF8 */
  474. contents = g_convert ( tmp_str, -1, "UTF-8", charmap_imported, NULL, NULL, NULL );
  475. if ( contents == NULL )
  476. {
  477. charmap_imported = utils_files_create_sel_charset ( assistant, tmp_str,
  478. charmap_imported,
  479. g_path_get_basename ( nom_fichier ) );
  480. gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
  481. IMPORT_FILESEL_CODING, charmap_imported,
  482. -1 );
  483. g_free ( contents );
  484. }
  485. g_free ( tmp_str );
  486. import_preview_maybe_sensitive_next ( assistant, GTK_TREE_MODEL ( model ));
  487. }
  488. tmp = tmp -> next;
  489. }
  490. }
  491. return FALSE;
  492. }
  493. /**
  494. *
  495. *
  496. */
  497. gboolean import_enter_file_selection_page ( GtkWidget * assistant )
  498. {
  499. GtkTreeModel * model;
  500. model = g_object_get_data ( G_OBJECT ( assistant ), "model" );
  501. import_preview_maybe_sensitive_next ( assistant, model );
  502. return FALSE;
  503. }
  504. /**
  505. *
  506. *
  507. *
  508. */
  509. gboolean import_active_toggled ( GtkCellRendererToggle * cell, gchar *path_str,
  510. gpointer model )
  511. {
  512. GtkWidget * assistant;
  513. GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
  514. GtkTreeIter iter;
  515. gboolean toggle_item;
  516. assistant = g_object_get_data ( G_OBJECT ( model ), "assistant" );
  517. gtk_tree_model_get_iter ( GTK_TREE_MODEL ( model ), &iter, path);
  518. gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
  519. IMPORT_FILESEL_SELECTED, &toggle_item, -1 );
  520. gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
  521. IMPORT_FILESEL_SELECTED, !toggle_item, -1 );
  522. import_preview_maybe_sensitive_next ( assistant, model );
  523. return FALSE;
  524. }
  525. /**
  526. *
  527. *
  528. *
  529. */
  530. void import_preview_maybe_sensitive_next ( GtkWidget * assistant, GtkTreeModel * model )
  531. {
  532. GtkTreeIter iter;
  533. /* Don't allow going to next page if no file is selected yet. */
  534. gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (assistant), "button_next" ), FALSE );
  535. gtk_tree_model_get_iter_first ( model, &iter );
  536. if ( ! gtk_tree_store_iter_is_valid ( GTK_TREE_STORE (model), &iter ))
  537. {
  538. return;
  539. }
  540. /* Iterate over lines so we check if some are checked. */
  541. do
  542. {
  543. gboolean selected;
  544. gchar * type;
  545. gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
  546. IMPORT_FILESEL_SELECTED, &selected,
  547. IMPORT_FILESEL_TYPE, &type,
  548. - 1 );
  549. if ( selected && strcmp ( type, _("Unknown") ) )
  550. {
  551. gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (assistant),
  552. "button_next" ),
  553. TRUE );
  554. return;
  555. }
  556. }
  557. while ( gtk_tree_model_iter_next ( model, &iter ) );
  558. }
  559. /**
  560. *
  561. *
  562. *
  563. */
  564. gboolean import_select_file ( GtkWidget * button, GtkWidget * assistant )
  565. {
  566. GSList * filenames, * iterator;
  567. GtkTreeModel * model;
  568. filenames = gsb_import_create_file_chooser ( NULL, assistant );
  569. if (!filenames)
  570. return FALSE;
  571. iterator = filenames;
  572. model = g_object_get_data ( G_OBJECT ( assistant ), "model" );
  573. while ( iterator && model )
  574. {
  575. GtkTreeIter iter;
  576. const gchar *type;
  577. gchar *nom_fichier;
  578. gchar *tmp_str;
  579. gchar *contents;
  580. gchar *charmap;
  581. GError *error = NULL;
  582. gchar * extension;
  583. /* Open file */
  584. extension = strrchr ( iterator -> data, '.' );
  585. /* unzip Gnucash file if necessary */
  586. if ( extension && strcmp ( extension, ".gnc" ) == 0 )
  587. gsb_import_gunzip_file ( iterator -> data );
  588. /* get contents of file */
  589. if ( ! g_file_get_contents ( iterator -> data, &tmp_str, NULL, &error ) )
  590. {
  591. g_print ( _("Unable to read file: %s\n"), error -> message);
  592. g_error_free ( error );
  593. return FALSE;
  594. }
  595. type = autodetect_file_type ( iterator -> data, tmp_str );
  596. /* passe par un fichier temporaire pour bipasser le bug libofx */
  597. if ( strcmp ( type, "OFX" ) == 0 )
  598. {
  599. nom_fichier = g_strconcat (g_get_tmp_dir (),G_DIR_SEPARATOR_S,
  600. g_path_get_basename ( iterator -> data ), NULL);
  601. if (! gsb_import_set_tmp_file (nom_fichier, tmp_str ) )
  602. {
  603. g_free ( tmp_str );
  604. return FALSE;
  605. }
  606. if ( ( charmap = utils_files_get_ofx_charset ( tmp_str ) ) != NULL )
  607. {
  608. if ( charmap_imported && strlen ( charmap_imported ) > 0 )
  609. g_free ( charmap_imported );
  610. charmap_imported = charmap;
  611. }
  612. }
  613. else
  614. nom_fichier = my_strdup (iterator -> data);
  615. /* CSV is special because it needs configuration, so we
  616. * add a conditional jump there. */
  617. if ( ! strcmp ( type, "CSV" ) )
  618. {
  619. gsb_assistant_set_next ( assistant, IMPORT_FILESEL_PAGE, IMPORT_CSV_PAGE );
  620. gsb_assistant_set_prev ( assistant, IMPORT_RESUME_PAGE, IMPORT_CSV_PAGE );
  621. }
  622. /* Convert to UTF8 */
  623. contents = g_convert ( tmp_str, -1, "UTF-8", charmap_imported, NULL, NULL, NULL );
  624. if ( contents == NULL )
  625. charmap_imported = utils_files_create_sel_charset ( assistant, tmp_str,
  626. charmap_imported,
  627. g_path_get_basename ( iterator -> data ) );
  628. else
  629. g_free ( contents );
  630. gtk_tree_store_append ( GTK_TREE_STORE ( model ), &iter, NULL );
  631. gtk_tree_store_set ( GTK_TREE_STORE ( model ), &iter,
  632. IMPORT_FILESEL_SELECTED, TRUE,
  633. IMPORT_FILESEL_TYPENAME, type,
  634. IMPORT_FILESEL_FILENAME, g_path_get_basename ( iterator -> data ),
  635. IMPORT_FILESEL_REALNAME, nom_fichier,
  636. IMPORT_FILESEL_TYPE, type,
  637. IMPORT_FILESEL_CODING, charmap_imported,
  638. -1 );
  639. g_free ( nom_fichier );
  640. g_free ( tmp_str );
  641. if ( strcmp ( type, _("Unknown") ) )
  642. {
  643. /* A valid file was selected, so we can now go ahead. */
  644. gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (assistant), "button_next" ),
  645. TRUE );
  646. }
  647. iterator = iterator -> next;
  648. }
  649. if ( filenames )
  650. g_slist_free ( filenames );
  651. return FALSE;
  652. }
  653. /**
  654. * create an appropriate dialog file chooser
  655. * for importing files to grisbi and return the selected files
  656. *
  657. * \param
  658. *
  659. * \return a GtkFileChooser
  660. * */
  661. GSList *gsb_import_create_file_chooser ( const char *enc, GtkWidget *parent )
  662. {
  663. GtkWidget * dialog, * hbox, * go_charmap_sel;
  664. GtkFileFilter * filter, * default_filter;
  665. gchar * files;
  666. GSList * tmp;
  667. struct import_format * format;
  668. GSList *filenames = NULL;
  669. gchar* old_str;
  670. gchar* tmpstr;
  671. gchar* tmpchar;
  672. dialog = gtk_file_chooser_dialog_new ( _("Choose files to import."),
  673. GTK_WINDOW ( parent ),
  674. GTK_FILE_CHOOSER_ACTION_OPEN,
  675. GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  676. GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
  677. NULL);
  678. gtk_file_chooser_set_select_multiple ( GTK_FILE_CHOOSER ( dialog ), TRUE );
  679. gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( dialog ), gsb_file_get_last_path () );
  680. /* Import filters */
  681. tmp = import_formats;
  682. format = (struct import_format *) tmp -> data;
  683. files = g_strconcat ( "*.", format -> extension, NULL );
  684. tmp = tmp -> next;
  685. while ( tmp )
  686. {
  687. format = (struct import_format *) tmp -> data;
  688. old_str = files;
  689. files = g_strconcat ( files, ", *.", format -> extension, NULL );
  690. g_free ( old_str );
  691. tmp = tmp -> next;
  692. }
  693. default_filter = gtk_file_filter_new ();
  694. tmpstr = g_strdup_printf ( _("Known files (%s)"), files );
  695. gtk_file_filter_set_name ( default_filter, tmpstr );
  696. g_free ( tmpstr );
  697. tmp = import_formats;
  698. while ( tmp )
  699. {
  700. GtkFileFilter * format_filter;
  701. format = (struct import_format *) tmp -> data;
  702. format_filter = gtk_file_filter_new ();
  703. tmpstr = g_strdup_printf ( _("%s files (*.%s)"),
  704. format -> name,
  705. format -> extension );
  706. gtk_file_filter_set_name ( format_filter, tmpstr );
  707. g_free ( tmpstr );
  708. /* Make it case insensitive */
  709. tmpstr = g_strdup ( "*." );
  710. tmpchar = format -> extension;
  711. while(*tmpchar != '\0' )
  712. {
  713. old_str=tmpstr;
  714. tmpstr = g_strdup_printf ( "%s[%c%c]",
  715. tmpstr,
  716. (int)g_ascii_toupper(*tmpchar),
  717. (int)*tmpchar );
  718. tmpchar++;
  719. g_free ( old_str );
  720. }
  721. gtk_file_filter_add_pattern ( format_filter, tmpstr );
  722. /* Add this pattern to the global filter as well*/
  723. gtk_file_filter_add_pattern ( default_filter, tmpstr );
  724. g_free ( tmpstr );
  725. gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), format_filter );
  726. tmp = tmp -> next;
  727. }
  728. gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), default_filter );
  729. gtk_file_chooser_set_filter ( GTK_FILE_CHOOSER ( dialog ), default_filter );
  730. filter = gtk_file_filter_new ();
  731. gtk_file_filter_set_name ( filter, _("All files") );
  732. gtk_file_filter_add_pattern ( filter, "*" );
  733. gtk_file_chooser_add_filter ( GTK_FILE_CHOOSER ( dialog ), filter );
  734. /* Add encoding preview */
  735. hbox = gtk_hbox_new ( FALSE, 6 );
  736. gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER ( dialog ), hbox );
  737. gtk_box_pack_start ( GTK_BOX ( hbox ), gtk_label_new ( _("Encoding: ") ),
  738. FALSE, FALSE, 0 );
  739. go_charmap_sel = go_charmap_sel_new (GO_CHARMAP_SEL_TO_UTF8);
  740. if (enc && strlen (enc))
  741. go_charmap_sel_set_encoding ((GOCharmapSel *) go_charmap_sel, enc);
  742. gtk_box_pack_start ( GTK_BOX ( hbox ), go_charmap_sel, TRUE, TRUE, 0 );
  743. gtk_widget_show_all ( hbox );
  744. if ( gtk_dialog_run ( GTK_DIALOG (dialog ) ) == GTK_RESPONSE_ACCEPT )
  745. filenames = gtk_file_chooser_get_filenames ( GTK_FILE_CHOOSER (dialog));
  746. /* save charmap */
  747. charmap_imported = g_strdup (go_charmap_sel_get_encoding ( (GOCharmapSel * )go_charmap_sel ));
  748. gsb_file_update_last_path (file_selection_get_last_directory (GTK_FILE_CHOOSER (dialog), TRUE));
  749. gtk_widget_destroy (dialog);
  750. return filenames;
  751. }
  752. /**
  753. *
  754. *
  755. */
  756. GtkWidget *import_create_resume_page ( GtkWidget * assistant )
  757. {
  758. GtkWidget *sw;
  759. GtkWidget *view;
  760. GtkTextBuffer *buffer;
  761. sw = gtk_scrolled_window_new (NULL, NULL);
  762. gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW ( sw ),
  763. GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
  764. view = gtk_text_view_new ();
  765. gtk_container_add (GTK_CONTAINER (sw), view);
  766. gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
  767. gtk_text_view_set_editable ( GTK_TEXT_VIEW (view), FALSE );
  768. gtk_text_view_set_cursor_visible ( GTK_TEXT_VIEW (view), FALSE );
  769. gtk_text_view_set_left_margin ( GTK_TEXT_VIEW (view), 12 );
  770. gtk_text_view_set_right_margin ( GTK_TEXT_VIEW (view), 12 );
  771. buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  772. gtk_text_buffer_create_tag ( buffer, "bold",
  773. "weight", PANGO_WEIGHT_BOLD, NULL);
  774. gtk_text_buffer_create_tag ( buffer, "x-large",
  775. "scale", PANGO_SCALE_X_LARGE, NULL);
  776. gtk_text_buffer_create_tag (buffer, "indented",
  777. "left-margin", 24, NULL);
  778. g_object_set_data ( G_OBJECT ( assistant ), "text-buffer", buffer );
  779. return sw;
  780. }
  781. /**
  782. *
  783. *
  784. *
  785. */
  786. gboolean import_enter_resume_page ( GtkWidget * assistant )
  787. {
  788. GSList *files;
  789. GSList *list;
  790. GtkTextBuffer * buffer;
  791. GtkTextIter iter;
  792. gchar * error_message = "";
  793. gchar* tmpstr;
  794. liste_comptes_importes_error = NULL;
  795. liste_comptes_importes = NULL;
  796. /* fichiers sélectionnés dans legestionnaire de fichiers */
  797. files = import_selected_files ( assistant );
  798. while ( files )
  799. {
  800. struct imported_file *imported = files -> data;
  801. GSList * tmp = import_formats;
  802. while ( tmp )
  803. {
  804. struct import_format *format = (struct import_format *) tmp -> data;
  805. if ( !strcmp ( imported -> type, format -> name ) )
  806. {
  807. devel_print_str ( imported -> type );
  808. format -> import ( assistant, imported );
  809. tmp = tmp -> next;
  810. continue;
  811. }
  812. tmp = tmp -> next;
  813. }
  814. files = files -> next;
  815. }
  816. buffer = g_object_get_data ( G_OBJECT ( assistant ), "text-buffer" );
  817. gtk_text_buffer_set_text (buffer, "\n", -1 );
  818. gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1);
  819. if ( liste_comptes_importes )
  820. {
  821. gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  822. _("Congratulations !"), -1,
  823. "x-large", NULL);
  824. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  825. gtk_text_buffer_insert (buffer, &iter,
  826. _("You successfully imported files into Grisbi. The "
  827. "following pages will help you set up imported data for "
  828. "the following files"),
  829. -1 );
  830. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  831. list = liste_comptes_importes;
  832. while ( list )
  833. {
  834. struct struct_compte_importation * compte;
  835. compte = list -> data;
  836. /* Fix account name if needed. */
  837. if ( ! compte -> nom_de_compte )
  838. {
  839. compte -> nom_de_compte = _("Unnamed Imported account");
  840. }
  841. devel_print_str ( compte -> nom_de_compte );
  842. tmpstr = g_strconcat ( "• ", compte -> nom_de_compte,
  843. " (",
  844. compte -> origine,
  845. ")\n\n",
  846. NULL );
  847. gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  848. tmpstr ,
  849. -1, "indented", NULL );
  850. g_free ( tmpstr );
  851. list = list -> next;
  852. }
  853. while ( gtk_notebook_get_n_pages ( g_object_get_data ( G_OBJECT (assistant),
  854. "notebook" ) ) > IMPORT_FIRST_ACCOUNT_PAGE )
  855. {
  856. gtk_notebook_remove_page ( g_object_get_data ( G_OBJECT (assistant), "notebook" ), -1 );
  857. }
  858. affichage_recapitulatif_importation ( assistant );
  859. }
  860. else
  861. {
  862. gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  863. _("Error !"), -1,
  864. "x-large", NULL);
  865. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  866. gtk_text_buffer_insert (buffer, &iter,
  867. _("No file has been imported, please double check that they are "
  868. "valid files. Please make sure that they are not compressed and "
  869. "that their format is valid."),
  870. -1 );
  871. if ( strlen ( error_message ) )
  872. {
  873. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  874. gtk_text_buffer_insert (buffer, &iter, error_message, -1 );
  875. }
  876. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  877. }
  878. if ( liste_comptes_importes_error )
  879. {
  880. gtk_text_buffer_insert (buffer, &iter, _("The following files are in error: "), -1 );
  881. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  882. list = liste_comptes_importes_error;
  883. while ( list )
  884. {
  885. struct struct_compte_importation * compte;
  886. compte = list -> data;
  887. tmpstr = g_strconcat ( "• ", compte -> nom_de_compte,
  888. " (",
  889. compte -> origine,
  890. ")\n\n",
  891. NULL );
  892. gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  893. tmpstr,
  894. -1, "indented", NULL );
  895. g_free ( tmpstr );
  896. list = list -> next;
  897. }
  898. }
  899. return FALSE;
  900. }
  901. /**
  902. *
  903. *
  904. */
  905. GtkWidget *import_create_final_page ( GtkWidget *assistant )
  906. {
  907. GtkWidget * view;
  908. GtkTextBuffer * buffer;
  909. GtkTextIter iter;
  910. view = gtk_text_view_new ();
  911. gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD);
  912. gtk_text_view_set_editable ( GTK_TEXT_VIEW (view), FALSE );
  913. gtk_text_view_set_cursor_visible ( GTK_TEXT_VIEW (view), FALSE );
  914. gtk_text_view_set_left_margin ( GTK_TEXT_VIEW (view), 12 );
  915. gtk_text_view_set_right_margin ( GTK_TEXT_VIEW (view), 12 );
  916. buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  917. gtk_text_buffer_create_tag ( buffer, "x-large",
  918. "scale", PANGO_SCALE_X_LARGE, NULL);
  919. gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1);
  920. gtk_text_buffer_insert (buffer, &iter, "\n", -1 );
  921. gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
  922. _("Import terminated"), -1,
  923. "x-large", NULL);
  924. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  925. gtk_text_buffer_insert (buffer, &iter,
  926. _("You have successfully set up transactions import into Grisbi. "
  927. "Press the 'Close' button to terminate import."),
  928. -1 );
  929. gtk_text_buffer_insert (buffer, &iter, "\n\n", -1 );
  930. return view;
  931. }
  932. /**
  933. *
  934. *
  935. *
  936. */
  937. GSList *import_selected_files ( GtkWidget *assistant )
  938. {
  939. GSList *list = NULL;
  940. GtkTreeModel *model;
  941. GtkTreeIter iter;
  942. model = g_object_get_data ( G_OBJECT ( assistant ), "model" );
  943. g_return_val_if_fail ( model, NULL );
  944. gtk_tree_model_get_iter_first ( model, &iter );
  945. do
  946. {
  947. struct imported_file *imported;
  948. gboolean selected;
  949. imported = g_malloc0 ( sizeof ( struct imported_file ) );
  950. gtk_tree_model_get ( GTK_TREE_MODEL ( model ), &iter,
  951. IMPORT_FILESEL_SELECTED, &selected,
  952. IMPORT_FILESEL_REALNAME, &(imported -> name),
  953. IMPORT_FILESEL_TYPE, &(imported -> type),
  954. IMPORT_FILESEL_CODING, &(imported -> coding_system),
  955. -1 );
  956. if ( selected )
  957. {
  958. list = g_slist_append ( list, imported );
  959. }
  960. }
  961. while ( gtk_tree_model_iter_next ( model, &iter ) );
  962. return list;
  963. }
  964. /**
  965. * this is the summary page of the import assistant
  966. * show what accounts will be imported in grisbi
  967. * and create the next pages of the assistant, one per account
  968. *
  969. * \param assistant
  970. *
  971. * \return FALSE
  972. */
  973. gboolean affichage_recapitulatif_importation ( GtkWidget * assistant )
  974. {
  975. gint page;
  976. GSList *list_tmp;
  977. if (!assistant)
  978. return FALSE;
  979. /* Initial page is fourth. */
  980. page = IMPORT_FIRST_ACCOUNT_PAGE;
  981. /* First, iter to see if we need to create currencies */
  982. list_tmp = liste_comptes_importes;
  983. while ( list_tmp )
  984. {
  985. struct struct_compte_importation * compte;
  986. compte = list_tmp -> data;
  987. /* add one page per account */
  988. gsb_assistant_add_page ( assistant, cree_ligne_recapitulatif ( list_tmp -> data ),
  989. page, page - 1, page + 1, G_CALLBACK ( NULL ) );
  990. page ++;
  991. list_tmp = list_tmp -> next;
  992. }
  993. /* And final page */
  994. gsb_assistant_add_page ( assistant, import_create_final_page ( assistant ),
  995. page, page - 1, -1, G_CALLBACK ( NULL ) );
  996. /* Replace button. */
  997. gsb_assistant_change_button_next ( assistant, GTK_STOCK_GO_FORWARD, GTK_RESPONSE_YES );
  998. return ( FALSE );
  999. }
  1000. /**
  1001. *
  1002. *
  1003. *
  1004. */
  1005. GtkWidget *cree_ligne_recapitulatif ( struct struct_compte_importation * compte )
  1006. {
  1007. GtkWidget * vbox, * hbox, * label, * radio, * radio_add_account,* radiogroup;
  1008. GtkWidget * alignement;
  1009. gchar * short_filename;
  1010. gint size = 0, spacing = 0;
  1011. gint account_number;
  1012. GtkWidget *button;
  1013. gchar* tmpstr;
  1014. vbox = gtk_vbox_new ( FALSE, 6 );
  1015. gtk_container_set_border_width ( GTK_CONTAINER(vbox), 12 );
  1016. if ( compte -> filename )
  1017. short_filename = g_path_get_basename (compte -> filename);
  1018. else
  1019. {
  1020. if (compte -> real_filename)
  1021. short_filename = g_path_get_basename (compte -> real_filename);
  1022. else
  1023. short_filename = g_strdup (_("file"));
  1024. }
  1025. label = gtk_label_new ( NULL );
  1026. gtk_misc_set_alignment ( GTK_MISC ( label ), 0, 0.5);
  1027. gtk_label_set_justify ( GTK_LABEL ( label ), GTK_JUSTIFY_LEFT );
  1028. tmpstr = g_markup_printf_escaped ( _("<span size=\"x-large\">%s</span>\n\n"
  1029. "What do you want to do with contents from <span "
  1030. "foreground=\"blue\">%s</span> ?\n"),
  1031. compte -> nom_de_compte, short_filename );
  1032. gtk_label_set_markup ( GTK_LABEL ( label ), tmpstr );
  1033. g_free ( tmpstr );
  1034. g_free (short_filename);
  1035. gtk_box_pack_start ( GTK_BOX ( vbox ), label, FALSE, FALSE, 0 );
  1036. /* New account */
  1037. radio = gtk_radio_button_new_with_label ( NULL, _("Create a new account") );
  1038. radiogroup = radio;
  1039. gtk_box_pack_start ( GTK_BOX ( vbox ), radio, FALSE, FALSE, 0 );
  1040. gtk_widget_style_get (radio, "indicator_size", &size, NULL);
  1041. gtk_widget_style_get (radio, "indicator_spacing", &spacing, NULL);
  1042. compte -> hbox1 = gtk_hbox_new ( FALSE, 6 );
  1043. gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox1, FALSE, FALSE, 0 );
  1044. label = gtk_label_new ( _("Account type: ") );
  1045. alignement = gtk_alignment_new ( 0.5, 0.5, 1, 1 );
  1046. gtk_container_set_border_width ( GTK_CONTAINER ( alignement ), 2 );
  1047. gtk_alignment_set_padding ( GTK_ALIGNMENT ( alignement ), 0, 0, 2 * spacing + size, 0 );
  1048. gtk_container_add ( GTK_CONTAINER ( alignement ), label );
  1049. gtk_box_pack_start ( GTK_BOX ( compte -> hbox1 ), alignement, FALSE, FALSE, 0 );
  1050. compte -> bouton_type_compte = gsb_combo_box_new_with_index_by_list (
  1051. gsb_account_property_create_combobox_list (),
  1052. NULL, NULL );
  1053. gtk_box_pack_start ( GTK_BOX ( compte -> hbox1 ), compte -> bouton_type_compte,
  1054. TRUE, TRUE, 0 );
  1055. /* at this level imported_account -> type_de_compte was filled while importing transactions,
  1056. * in qif.c or ofx.c ; but we have only 4 kind of account for now, so try to place the combobox correctly
  1057. * and it's the user who will choose the kind of account */
  1058. switch (compte -> type_de_compte)
  1059. {
  1060. case 3:
  1061. gsb_combo_box_set_index ( compte -> bouton_type_compte,
  1062. GSB_TYPE_LIABILITIES );
  1063. break;
  1064. case 7:
  1065. gsb_combo_box_set_index ( compte -> bouton_type_compte,
  1066. GSB_TYPE_CASH );
  1067. break;
  1068. default:
  1069. gsb_combo_box_set_index ( compte -> bouton_type_compte,
  1070. GSB_TYPE_BANK );
  1071. }
  1072. g_object_set_data ( G_OBJECT ( radio ), "associated", compte -> hbox1 );
  1073. g_object_set_data ( G_OBJECT ( radio ), "account", compte );
  1074. g_signal_connect ( G_OBJECT ( radio ), "toggled",
  1075. G_CALLBACK ( import_account_action_activated ), IMPORT_CREATE_ACCOUNT );
  1076. /* Add to account */
  1077. radio_add_account = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radiogroup ),
  1078. _("Add transactions to an account") );
  1079. gtk_box_pack_start ( GTK_BOX ( vbox ), radio_add_account, FALSE, FALSE, 0 );
  1080. if (radio_add_account && GTK_WIDGET_VISIBLE (radio_add_account))
  1081. gtk_widget_set_sensitive ( radio_add_account, assert_account_loaded ( ) );
  1082. compte -> hbox2 = gtk_hbox_new ( FALSE, 6 );
  1083. gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox2, FALSE, FALSE, 0 );
  1084. label = gtk_label_new ( _("Account name: ") );
  1085. alignement = gtk_alignment_new ( 0.5, 0.5, 1, 1 );
  1086. gtk_container_set_border_width ( GTK_CONTAINER ( alignement ), 2 );
  1087. gtk_alignment_set_padding ( GTK_ALIGNMENT ( alignement ), 0, 0, 2 * spacing + size, 0 );
  1088. gtk_container_add ( GTK_CONTAINER ( alignement ), label );
  1089. gtk_box_pack_start ( GTK_BOX ( compte -> hbox2 ), alignement, FALSE, FALSE, 0 );
  1090. compte -> bouton_compte_add = gsb_account_create_combo_list (NULL, NULL, FALSE);
  1091. gtk_box_pack_start ( GTK_BOX ( compte -> hbox2 ), compte -> bouton_compte_add, TRUE, TRUE, 0 );
  1092. gtk_widget_set_sensitive ( compte -> hbox2, FALSE );
  1093. g_object_set_data ( G_OBJECT ( radio_add_account ), "associated", compte -> hbox2 );
  1094. g_object_set_data ( G_OBJECT ( radio_add_account ), "account", compte );
  1095. g_signal_connect ( G_OBJECT ( radio_add_account ), "toggled",
  1096. G_CALLBACK ( import_account_action_activated ),
  1097. GINT_TO_POINTER (IMPORT_ADD_TRANSACTIONS));
  1098. /* Mark account */
  1099. radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON ( radiogroup ),
  1100. _("Mark transactions of an account") );
  1101. gtk_box_pack_start ( GTK_BOX ( vbox ), radio, FALSE, FALSE, 0 );
  1102. gtk_widget_set_sensitive ( radio, assert_account_loaded ( ) );
  1103. compte -> hbox3 = gtk_hbox_new ( FALSE, 6 );
  1104. gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox3, FALSE, FALSE, 0 );
  1105. label = gtk_label_new ( _("Account name: ") );
  1106. alignement = gtk_alignment_new ( 0.5, 0.5, 1, 1 );
  1107. gtk_container_set_border_width ( GTK_CONTAINER ( alignement ), 2 );
  1108. gtk_alignment_set_padding ( GTK_ALIGNMENT ( alignement ), 0, 0, 2 * spacing + size, 0 );
  1109. gtk_container_add ( GTK_CONTAINER ( alignement ), label );
  1110. gtk_box_pack_start ( GTK_BOX ( compte -> hbox3 ), alignement, FALSE, FALSE, 0 );
  1111. compte -> bouton_compte_mark = gsb_account_create_combo_list (NULL, NULL, FALSE);
  1112. gtk_box_pack_start ( GTK_BOX ( compte -> hbox3 ), compte -> bouton_compte_mark, TRUE, TRUE, 0 );
  1113. gtk_widget_set_sensitive ( compte -> hbox3, FALSE );
  1114. g_object_set_data ( G_OBJECT ( radio ), "associated", compte -> hbox3 );
  1115. g_object_set_data ( G_OBJECT ( radio ), "account", compte );
  1116. g_signal_connect ( G_OBJECT ( radio ), "toggled",
  1117. G_CALLBACK ( import_account_action_activated ),
  1118. GINT_TO_POINTER (IMPORT_MARK_TRANSACTIONS));
  1119. /* set on the right account */
  1120. account_number = gsb_data_account_get_account_by_id ( compte->id_compte );
  1121. if ( account_number >= 0 )
  1122. {
  1123. import_account_action_activated ( radio_add_account,IMPORT_ADD_TRANSACTIONS );
  1124. gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( radio_add_account ), TRUE );
  1125. gsb_account_set_combo_account_number ( compte -> bouton_compte_add, account_number );
  1126. gsb_account_set_combo_account_number ( compte -> bouton_compte_mark, account_number );
  1127. }
  1128. /* Currency */
  1129. hbox = gtk_hbox_new ( FALSE, 6 );
  1130. label = gtk_label_new ( _("Account currency: ") );
  1131. gtk_box_pack_start ( GTK_BOX ( hbox ), label, FALSE, FALSE, 0 );
  1132. gtk_box_pack_start ( GTK_BOX ( vbox ), hbox, FALSE, FALSE, 0 );
  1133. compte -> bouton_devise = gsb_currency_make_combobox ( TRUE );
  1134. /* create the currency if doesn't exist */
  1135. if ( compte -> devise )
  1136. {
  1137. gint currency_number;
  1138. /* First, we search currency from ISO4217 code for existing currencies */
  1139. currency_number = gsb_data_currency_get_number_by_code_iso4217 ( compte -> devise );
  1140. /* Then, by nickname for existing currencies */
  1141. if ( !currency_number )
  1142. {
  1143. currency_number = gsb_import_add_currency ( compte );
  1144. if ( currency_number == 0 )
  1145. currency_number = gsb_data_currency_get_number_by_name ( compte -> devise );
  1146. }
  1147. if ( currency_number )
  1148. gsb_currency_set_combobox_history ( compte -> bouton_devise,
  1149. currency_number );
  1150. else
  1151. currency_number = gsb_import_add_currency ( compte );
  1152. }
  1153. gtk_box_pack_start ( GTK_BOX ( hbox ), compte -> bouton_devise, FALSE, FALSE, 0 );
  1154. /* invert amount of transactions */
  1155. button = gsb_automem_checkbutton_new (_("Invert the amount of the imported transactions"),
  1156. &compte -> invert_transaction_amount, NULL, NULL);
  1157. gtk_box_pack_start ( GTK_BOX ( vbox ), button, FALSE, FALSE, 0 );
  1158. /* propose to create a rule */
  1159. compte -> hbox_rule = gtk_hbox_new (FALSE, 5);
  1160. gtk_box_pack_start ( GTK_BOX ( vbox ), compte -> hbox_rule, FALSE, FALSE, 0 );
  1161. compte -> entry_name_rule = gtk_entry_new ();
  1162. button = gsb_automem_checkbutton_new (_("Create a rule for this import. Name of the rule : "),
  1163. &compte -> create_rule, G_CALLBACK (
  1164. gsb_button_sensitive_by_checkbutton),
  1165. compte -> entry_name_rule);
  1166. gtk_box_pack_start ( GTK_BOX (compte -> hbox_rule), button, FALSE, FALSE, 0 );
  1167. /* we can create a rule only for qif or ofx */
  1168. if (st

Large files files are truncated, but you can click here to view the full file