/** * called when toggle a button of the form configuration, append or remove * the value from the tree view * * \param toggle_button the button we click * * \return FALSE * */ gboolean gsb_form_config_toggle_element_button ( GtkWidget *toggle_button ) { gint element_number; gint no_second_element; gint i, j; gint account_number; /* get the element number */ element_number = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( toggle_button ), "element_number" )); /* set the second element number if necessary */ switch ( element_number ) { case TRANSACTION_FORM_TYPE: /* c'est le mode de paiement, on met le chq */ no_second_element = TRANSACTION_FORM_CHEQUE; break; case TRANSACTION_FORM_CHEQUE: /* c'est le chq, on met mode de paiement */ no_second_element = TRANSACTION_FORM_TYPE; break; case TRANSACTION_FORM_DEVISE: /* c'est la devise, on met le button de change */ no_second_element = TRANSACTION_FORM_CHANGE; break; case TRANSACTION_FORM_CHANGE: /* c'est le button de change, on met la devise */ no_second_element = TRANSACTION_FORM_DEVISE; break; default: no_second_element = -1; } account_number = gsb_account_get_combo_account_number ( accounts_combobox ); /* update the table */ if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON ( toggle_button ))) { /* button is on, append the element */ gint place_trouvee = 0; gint ligne_premier_elt = -1; gint colonne_premier_elt = -1; for ( i=0 ; i < gsb_data_form_get_nb_rows (account_number) ; i++) for ( j=0 ; j < gsb_data_form_get_nb_columns (account_number) ; j++ ) if ( !gsb_data_form_get_value ( account_number, j, i ) ) { /* if only 1 element, end here, else continue to look after the second one */ if ( no_second_element == -1 ) { /* il n'y a qu'un elt */ gsb_data_form_set_value ( account_number, j, i, element_number ); place_trouvee = 1; i = gsb_data_form_get_nb_rows (account_number); j = gsb_data_form_get_nb_columns (account_number); } else { /* there are 2 elements */ if ( ligne_premier_elt == -1 ) { /* found the place for the first element */ ligne_premier_elt = i; colonne_premier_elt = j; } else { /* found the place for the second element */ gsb_data_form_set_value ( account_number, colonne_premier_elt, ligne_premier_elt, element_number ); gsb_data_form_set_value ( account_number, j, i, no_second_element ); place_trouvee = 1; i = gsb_data_form_get_nb_rows (account_number); j = gsb_data_form_get_nb_columns (account_number); } } } if ( place_trouvee ) { /* there is a place for the element, active if necessary an associated element */ if ( no_second_element != -1 ) { g_signal_handlers_block_by_func ( G_OBJECT ( form_config_buttons[no_second_element-4] ), G_CALLBACK ( gsb_form_config_toggle_element_button ), NULL ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( form_config_buttons[no_second_element-4] ), TRUE ); g_signal_handlers_unblock_by_func ( G_OBJECT ( form_config_buttons[no_second_element-4] ), G_CALLBACK ( gsb_form_config_toggle_element_button ), NULL ); } } else { /* there is no place to add an element */ g_signal_handlers_block_by_func ( G_OBJECT ( toggle_button ), G_CALLBACK ( gsb_form_config_toggle_element_button ), NULL ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( toggle_button ), FALSE ); g_signal_handlers_unblock_by_func ( G_OBJECT ( toggle_button ), G_CALLBACK ( gsb_form_config_toggle_element_button ), NULL ); if ( no_second_element == -1 ) dialogue_hint ( _("There is no place enough to put the element. You need to increase " "the number of rows or columns to add an element."), _("The table is full")); else dialogue_hint ( _("There is no place enough to put the two elements (you have clicked on " "an element which contains two). You need to increase the number of rows " "or columns to add the elements."), _("The table is full")); return TRUE; } } else { /* un-toggle the button */ if ( no_second_element != -1 ) { g_signal_handlers_block_by_func ( G_OBJECT ( form_config_buttons[no_second_element-4] ), G_CALLBACK ( gsb_form_config_toggle_element_button ), NULL ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON ( form_config_buttons[no_second_element-4] ), FALSE ); g_signal_handlers_unblock_by_func ( G_OBJECT ( form_config_buttons[no_second_element-4] ), G_CALLBACK ( gsb_form_config_toggle_element_button ), NULL ); } for ( i=0 ; i < gsb_data_form_get_nb_rows (account_number) ; i++ ) for ( j=0 ; j < gsb_data_form_get_nb_columns (account_number) ; j++ ) if ( gsb_data_form_get_value (account_number, j, i ) == element_number ) { gsb_data_form_set_value ( account_number, j, i, 0 ); if ( no_second_element == -1 ) { i = gsb_data_form_get_nb_rows (account_number); j = gsb_data_form_get_nb_columns (account_number); } else { element_number = no_second_element; no_second_element = -1; i = 0; j = 0; } } } /* fill the list */ gsb_form_config_fill_store (account_number); gsb_form_fill_from_account (account_number); gsb_form_config_update_from_account ( gsb_account_get_combo_account_number ( accounts_combobox ) ); /* update the form */ gsb_form_config_fill_store (account_number); gsb_form_create_widgets (); gsb_file_set_modified ( TRUE ); return FALSE; }
/** * 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; }
/** * called by menubar to obfuscate the file * * \param * * \return TRUE * */ gboolean file_obfuscate_run ( void ) { GtkWidget *assistant; gint result; gsb_status_message ( _("Obfuscating file...") ); assistant = gsb_assistant_new ( _("Grisbi file obfuscation"), _("This assistant produces anonymized copies of account files, with " "all personal data replaced with harmless random data, in order to " "attach an anonimized copy of your Grisbi file with any bug report " "you submit." "\n\n" "That said, please check that bugs you submit are still valid with " "anonymized version of your files.\n" "\n" "To avoid any problems in your file, after saving the modified file, " "Grisbi will close without letting you saving anything. " "So if you didn't save your changes, please stop this assistant, " "save your work and restart the obfuscation process.\n\n" "In next page, you will be able to select individual features to " "obfuscate or to keep depending on the level of privacy needed."), "bug.png", NULL ); gsb_assistant_add_page ( assistant, file_obfuscate_page_1 (), 1, 0, 2, NULL ); gsb_assistant_add_page ( assistant, file_obfuscate_page_2 (), 2, 1, -1, NULL ); result = gsb_assistant_run ( assistant ); if (result == GTK_RESPONSE_APPLY) { /* obfuscate the file */ GSList *tmp_list; gchar *filename; /* remove the swp file */ gsb_file_util_modify_lock (FALSE); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_accounts_details))) { /* hide the details of account but not the names */ tmp_list = gsb_data_account_get_list_accounts (); while (tmp_list) { gint account_number = gsb_data_account_get_no_account (tmp_list -> data); gsb_data_account_set_id (account_number, g_strdup_printf ("id account %d", account_number)); gsb_data_account_set_comment (account_number, NULL); gsb_data_account_set_holder_name (account_number, NULL); gsb_data_account_set_holder_address (account_number, NULL); gsb_data_account_set_init_balance (account_number, null_real); gsb_data_account_set_mini_balance_wanted (account_number, null_real); gsb_data_account_set_mini_balance_authorized (account_number, null_real); gsb_data_account_set_bank_branch_code (account_number, NULL); gsb_data_account_set_bank_account_number (account_number, NULL); gsb_data_account_set_bank_account_key (account_number, NULL); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_amount))) { /* hide the amounts of transactions */ tmp_list = gsb_data_transaction_get_complete_transactions_list (); while (tmp_list) { gint transaction_number = gsb_data_transaction_get_transaction_number (tmp_list -> data); gsb_data_transaction_set_amount (transaction_number, null_real); gsb_data_transaction_set_voucher (transaction_number, NULL); gsb_data_transaction_set_bank_references (transaction_number, NULL); tmp_list = tmp_list -> next; } /* hide the amounts of scheduled transactions */ tmp_list = gsb_data_scheduled_get_scheduled_list (); while (tmp_list) { gint scheduled_number = gsb_data_scheduled_get_scheduled_number (tmp_list -> data); gsb_data_scheduled_set_amount (scheduled_number, null_real); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_accounts_names))) { /* hide the accounts names */ tmp_list = gsb_data_account_get_list_accounts (); while (tmp_list) { gint account_number = gsb_data_account_get_no_account (tmp_list -> data); gsb_data_account_set_name (account_number, g_strdup_printf ("Account n°%d", account_number)); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_payee))) { /* hide the payees names */ tmp_list = gsb_data_payee_get_payees_list (); while (tmp_list) { gint payee_number = gsb_data_payee_get_no_payee (tmp_list -> data); gsb_data_payee_set_name (payee_number, g_strdup_printf ( "Payee n°%d", payee_number)); gsb_data_payee_set_description (payee_number, NULL); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_categories))) { /* hide the categories */ tmp_list = gsb_data_category_get_categories_list (); while (tmp_list) { GSList *list_sub_categ; gint category_number = gsb_data_category_get_no_category (tmp_list -> data); gsb_data_category_set_name (category_number, g_strdup_printf ( "Category n°%d", category_number)); list_sub_categ = gsb_data_category_get_sub_category_list (category_number); while (list_sub_categ) { gint sub_categ_number = gsb_data_category_get_no_sub_category (list_sub_categ -> data); gsb_data_category_set_sub_category_name (category_number, sub_categ_number, g_strdup_printf ("Sub-category n°%d", sub_categ_number)); list_sub_categ = list_sub_categ -> next; } tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_budgets))) { /* hide the budgets */ tmp_list = gsb_data_budget_get_budgets_list (); while (tmp_list) { GSList *list_sub_budget; gint budget_number = gsb_data_budget_get_no_budget (tmp_list -> data); gsb_data_budget_set_name (budget_number, g_strdup_printf ( "Budget n°%d", budget_number)); list_sub_budget = gsb_data_budget_get_sub_budget_list (budget_number); while (list_sub_budget) { gint sub_budget_number = gsb_data_budget_get_no_sub_budget (list_sub_budget -> data); gsb_data_budget_set_sub_budget_name (budget_number, sub_budget_number, g_strdup_printf ("Sub-budget n°%d", sub_budget_number)); list_sub_budget = list_sub_budget -> next; } tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_notes))) { /* hide the notes */ tmp_list = gsb_data_transaction_get_complete_transactions_list (); while (tmp_list) { gint transaction_number = gsb_data_transaction_get_transaction_number (tmp_list -> data); gsb_data_transaction_set_notes (transaction_number, NULL); tmp_list = tmp_list -> next; } /* hide the notes of scheduled transactions */ tmp_list = gsb_data_scheduled_get_scheduled_list (); while (tmp_list) { gint scheduled_number = gsb_data_scheduled_get_scheduled_number (tmp_list -> data); gsb_data_scheduled_set_notes (scheduled_number, NULL); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_banks))) { /* hide the banks */ tmp_list = gsb_data_bank_get_bank_list (); while (tmp_list) { gint bank_number = gsb_data_bank_get_no_bank (tmp_list -> data); gsb_data_bank_set_name (bank_number, g_strdup_printf ("Bank n°%d", bank_number)); gsb_data_bank_set_code (bank_number, NULL); gsb_data_bank_set_bank_address (bank_number, NULL); gsb_data_bank_set_bank_tel (bank_number, NULL); gsb_data_bank_set_bank_mail (bank_number, NULL); gsb_data_bank_set_bank_web (bank_number, NULL); gsb_data_bank_set_bank_note (bank_number, NULL); gsb_data_bank_set_correspondent_name (bank_number, NULL); gsb_data_bank_set_correspondent_tel (bank_number, NULL); gsb_data_bank_set_correspondent_mail (bank_number, NULL); gsb_data_bank_set_correspondent_fax (bank_number, NULL); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_reports))) { /* hide the reports names*/ tmp_list = gsb_data_report_get_report_list (); while (tmp_list) { gint report_number = gsb_data_report_get_report_number (tmp_list -> data); gsb_data_report_set_report_name ( report_number, g_strdup_printf ( "Report n°%d", report_number)); tmp_list = tmp_list -> next; } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_reconcile))) { /* hide the reconciles */ GList *reconcile_list; reconcile_list = gsb_data_reconcile_get_reconcile_list (); while (reconcile_list) { gint reconcile_number = gsb_data_reconcile_get_no_reconcile (reconcile_list -> data); gsb_data_reconcile_set_init_balance (reconcile_number, null_real); gsb_data_reconcile_set_final_balance (reconcile_number, null_real); reconcile_list = reconcile_list -> next; } } if (nom_fichier_comptes) { /* remove the .gsb */ nom_fichier_comptes[strlen(nom_fichier_comptes) -4] = 0; filename = g_strconcat ( nom_fichier_comptes, "-obfuscated.gsb", NULL); } else filename = g_strconcat ( my_get_gsb_file_default_dir (), "No_name-obfuscated.gsb", NULL); if (gsb_file_save_save_file (filename, FALSE, FALSE)) dialogue_hint ( g_strdup_printf ( _("Obfuscated file saved as\n'%s'"), filename ), _("Obfuscation succeeded") ); else dialogue_error_hint (g_strdup_printf (_("Grisbi couldn't save the file\n'%s'"), filename ), _("Obfuscation failed") ); /* bye bye */ exit (0); } gtk_widget_destroy ( assistant ); gsb_status_message ( _("Done.") ); return FALSE; }