/** * called to load the category/budget/report file given in param * * \filename the filename to load with full path * * \return TRUE if ok * */ gboolean gsb_file_others_load ( gchar *filename, gint origin ) { gchar *file_content; GSList *import_list = NULL; GError *error = NULL; devel_debug (filename); /* general check */ if ( !g_file_test ( filename, G_FILE_TEST_EXISTS )) { gchar* tmpstr = g_strdup_printf (_("Cannot open file '%s': %s"), filename, g_strerror(errno)); dialogue_error ( tmpstr ); g_free ( tmpstr ); return FALSE; } /* check here if it's not a regular file */ if ( !g_file_test ( filename, G_FILE_TEST_IS_REGULAR )) { gchar* tmpstr = g_strdup_printf ( _("%s doesn't seem to be a regular file,\nplease check it and try again."), filename ); dialogue_error ( tmpstr ); g_free ( tmpstr ); return ( FALSE ); } /* load the file */ if ( g_file_get_contents ( filename, &file_content, NULL, NULL )) { GMarkupParser *markup_parser; GMarkupParseContext *context; /* check if it's a good file */ if ( !gsb_file_others_check_file ( file_content, origin )) { g_free (file_content); return FALSE; } /* we load only after 0.6 files, * there is very few people who will want to upgrade previous categories, budgets... * and i'm too lazy to create an import for old files */ /* fill the GMarkupParser for a new xml structure */ markup_parser = g_malloc0 ( sizeof ( GMarkupParser ) ); markup_parser -> start_element = ( void * ) gsb_file_others_start_element; markup_parser -> error = ( void * ) gsb_file_load_error; context = g_markup_parse_context_new ( markup_parser, 0, &import_list, NULL ); if ( !g_markup_parse_context_parse ( context, file_content, strlen ( file_content ), &error ) ) { gchar* tmpstr; tmpstr = g_strdup_printf (_("Error parsing file '%s': %s"), filename, error->message ); dialogue_error ( tmpstr ); g_free ( tmpstr ); g_markup_parse_context_free ( context ); g_free ( markup_parser ); g_free ( file_content ); return FALSE; } gint report_number; /* now, import_list contains the list of categories/budget or report */ switch ( origin ) { case 0: /* comes for category */ categories_fill_list (); break; case 1: /* comes for budget */ budgetary_lines_fill_list (); break; case 2: /* comes for report, * as we cannot have the same things between differents grisbi files, * we cannot export/import currencies, financial years, accounts names, * categories, budgetaries and parties * so we erase them here because perhaps they doesn't exist and show * a warning : the user has to do it by himself (untill a druid to help him ?) */ /* we import only 1 report, so it's the last one */ report_number = gsb_data_report_max_number (); if (report_number) { /* set the currencies */ gsb_data_report_set_currency_general ( report_number, 1 ); gsb_data_report_set_category_currency ( report_number, 1 ); gsb_data_report_set_budget_currency ( report_number, 1 ); gsb_data_report_set_payee_currency ( report_number, 1 ); gsb_data_report_set_amount_comparison_currency ( report_number, 1 ); /* erase the financials years */ gsb_data_report_set_financial_year_list ( report_number, NULL ); /* erase the accounts */ gsb_data_report_set_account_numbers_list ( report_number, NULL); /* erase the transferts accounts */ gsb_data_report_set_transfer_account_numbers_list ( report_number, NULL ); /* erase the categories */ gsb_data_report_set_category_struct_list ( report_number, NULL ); /* erase the parties */ gsb_data_report_set_payee_numbers_list ( report_number, NULL ); /* erase the kinds of payment */ gsb_data_report_set_method_of_payment_list ( report_number, NULL ); gsb_gui_navigation_add_report ( report_number ); /* inform the user of that */ dialogue_hint ( _("Some things in a report cannot be imported:\n" "The selected lists of financial years, accounts, transfer accounts, " "categories, budgetaries, parties and kind of payments.\nSo that lists " "have been erased while the import.\nThe currencies have been set too " "on the first currency of this Grisbi file.\nYou should check and modify " "that in the property box of that account."), _("Importing a report")); } break; } g_markup_parse_context_free (context); g_free (markup_parser); g_free (file_content); gsb_file_set_modified ( TRUE ); } else { gchar* tmpstr = g_strdup_printf (_("Cannot open file '%s': %s"), filename, g_strerror(errno)); dialogue_error ( tmpstr ); g_free ( tmpstr ); return FALSE; } return TRUE; }
/** that function delete the current account selected in the account properties * \param none * \return FALSE FALSE * */ gboolean gsb_account_delete ( void ) { gint deleted_account; gint page_number; GSList *list_tmp; gchar* tmpstr; deleted_account = gsb_gui_navigation_get_current_account (); tmpstr = g_strdup_printf (_("Delete account \"%s\"?"), gsb_data_account_get_name ( deleted_account ) ) ; if ( !question_yes_no_hint ( tmpstr, _("This will irreversibly remove this account and all operations " "that were previously contained. There is no undo for this. " "Usually it's a better way to close an account."), GTK_RESPONSE_NO )) { g_free ( tmpstr ); return FALSE; } g_free ( tmpstr ); /* if the last account, close the file */ if ( gsb_data_account_get_accounts_amount () == 1 ) { gsb_file_set_modified ( FALSE ); gsb_file_close (); return FALSE; } /* delete the schedules transactions on that account */ list_tmp = gsb_data_scheduled_get_scheduled_list (); while (list_tmp) { gint scheduled_number; scheduled_number = gsb_data_scheduled_get_scheduled_number ( list_tmp -> data ); if ( gsb_data_scheduled_get_account_number (scheduled_number) == deleted_account ) gsb_data_scheduled_remove_scheduled (scheduled_number); list_tmp = list_tmp -> next; } /* remove all the transactions of that account */ list_tmp = gsb_data_transaction_get_complete_transactions_list (); while (list_tmp) { gint transaction_number; transaction_number = gsb_data_transaction_get_transaction_number ( list_tmp -> data ); /* better to go to the next transaction now */ list_tmp = list_tmp -> next; if (gsb_data_transaction_get_account_number (transaction_number) == deleted_account) { gint contra_transaction_number; /* we are on a transaction on the deleted account, we delete that transaction, * but if it's a transfer, modify the contra-transaction to set transfer to deleted account */ contra_transaction_number = gsb_data_transaction_get_contra_transaction_number ( transaction_number); if (contra_transaction_number > 0) /* it's a transfer, modify the contra-transaction */ gsb_data_transaction_set_contra_transaction_number ( contra_transaction_number, -1); /* now can remove the transaction */ gsb_data_transaction_remove_transaction_without_check ( transaction_number ); } } /* delete the payment_number */ list_tmp = gsb_data_account_get_sort_list ( deleted_account ); while (list_tmp) { gpointer ptr; gint payment_number; ptr = list_tmp -> data; payment_number = GPOINTER_TO_INT ( ptr ); gsb_data_payment_remove ( payment_number ); list_tmp = list_tmp -> next; } /* delete the account */ gsb_data_account_delete ( deleted_account ); /* check gsb_gui_navigation_get_current_account () and gsb_gui_navigation_get_current_account ()_onglet and put them * on the first account if they are on the deleted account */ if ( gsb_gui_navigation_get_current_account () == deleted_account ) { GtkWidget *notebook_general; /* update the transaction list */ notebook_general = gsb_gui_get_general_notebook ( ); page_number = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( notebook_general ) ); navigation_change_account ( gsb_data_account_first_number () ); gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook_general ), page_number ); } /* update the buttons lists */ gsb_menu_update_accounts_in_menus(); /* Replace trees contents. */ categories_fill_list (); budgetary_lines_fill_list (); payees_fill_list (); /* update the categories in lists */ transaction_list_update_element (ELEMENT_CATEGORY); /* update the name of accounts in form */ gsb_account_update_combo_list ( gsb_form_scheduler_get_element_widget (SCHEDULED_FORM_ACCOUNT), FALSE ); gsb_scheduler_list_fill_list (gsb_scheduler_list_get_tree_view ()); mise_a_jour_liste_echeances_manuelles_accueil = 1; mise_a_jour_liste_comptes_accueil = 1; mise_a_jour_soldes_minimaux = 1; mise_a_jour_fin_comptes_passifs = 1; /* Update navigation pane. */ gsb_gui_navigation_remove_account ( deleted_account ); gsb_file_set_modified ( TRUE ); return FALSE; }