/** * crée le GtkComboBox pour l'entrée d'un nom de fichier ou de répertoire * mémorise la liste des répertoires utilisés * * \param nom de l'icône * * \return le GtkComboBox * */ GtkWidget * gsb_select_icon_create_entry_text ( gchar * name_icon ) { GtkWidget *combo; GtkTreeIter iter; if ( store ) { devel_debug ( "combo existe" ); } else { devel_debug ( "combo n'existe pas" ); store = gtk_list_store_new ( 2, G_TYPE_STRING, G_TYPE_INT ); gtk_list_store_append (store, &iter); if ( g_strcmp0 ( gsb_dirs_get_pixmaps_dir ( ), path_icon ) != 0 ) { gtk_list_store_set (store, &iter, 0, gsb_dirs_get_pixmaps_dir ( ), -1); gtk_list_store_prepend (store, &iter); } gtk_list_store_set (store, &iter, 0, path_icon, -1); } combo = gtk_combo_box_entry_new_with_model ( GTK_TREE_MODEL ( store ), 0 ); gtk_entry_set_text ( GTK_ENTRY (GTK_BIN (combo)->child), name_icon ); return combo; }
/** * destroy all the elements in scheduled_element_list * and free the list * * \param * * \return FALSE * */ gboolean gsb_form_scheduler_free_list ( void ) { GSList *list_tmp; devel_debug (NULL); if (!scheduled_element_list) return FALSE; list_tmp = scheduled_element_list; while (list_tmp) { struct_element *element; element = list_tmp -> data; if (element -> element_widget && GTK_IS_WIDGET (element -> element_widget)) gtk_widget_destroy (element -> element_widget); g_free (element); list_tmp = list_tmp -> next; } g_slist_free (scheduled_element_list); scheduled_element_list =NULL; return FALSE; }
/** * ajoute le nouveau path. S'il existe déjà dans la liste on le supprime * de telle façon qu'il n'existe qu'une fois et apparaisse en premier dans * la liste * * \param néant * * \return TRUE * */ gboolean gsb_select_icon_add_path ( void ) { GtkTreeIter iter; gboolean result = FALSE; result = gtk_tree_model_get_iter_first ( GTK_TREE_MODEL ( store ), &iter ); while (result) { gchar * rep; gtk_tree_model_get ( GTK_TREE_MODEL ( store ), &iter, 0, &rep, -1 ); if ( strcmp ( path_icon, rep ) == 0) { gtk_list_store_remove ( store, &iter ); break; } result = gtk_tree_model_iter_next ( GTK_TREE_MODEL ( store ), &iter); } gtk_list_store_prepend (store, &iter); gtk_list_store_set (store, &iter, 0, path_icon, -1); devel_debug ( g_strconcat ( "path ajouté ", path_icon, NULL ) ); return TRUE; }
/** * callback pour traiter les changements de sélection dans le GtkIconView * * \param le GtkIconView appellant * * \return * * */ void gsb_select_icon_selection_changed ( GtkIconView *icon_view, gpointer user_data ) { GList * liste; GtkTreePath *path; GtkTreeModel *model; GtkTreeIter iter; gchar *name_icon = NULL; liste = gtk_icon_view_get_selected_items ( GTK_ICON_VIEW ( icon_view ) ); /* Could happen if selection is unset, exiting then. */ if ( ! liste ) return; path = liste -> data; model = gtk_icon_view_get_model ( GTK_ICON_VIEW ( icon_view ) ); if (gtk_tree_model_get_iter ( GTK_TREE_MODEL (model), &iter, path )) gtk_tree_model_get (model, &iter, TEXT_COLUMN, &name_icon, -1); name_icon = my_strdelimit ( name_icon, "\n", "" ); devel_debug ( name_icon ); if ( name_icon && strlen ( name_icon ) > 0 ) { new_icon = g_strconcat ( path_icon, G_DIR_SEPARATOR_S, name_icon, NULL ); gtk_entry_set_text ( GTK_ENTRY (GTK_BIN (entry_text)->child ), new_icon ); gtk_widget_set_sensitive (bouton_OK, TRUE ); } }
/** * \brief permet de pallier au bug de l'annulation du * gtk_file_chooser_button_new * * \param bouton appellant et chooser */ void utils_files_file_chooser_cancel ( GtkWidget *bouton, GtkWidget *chooser) { gchar *path; path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser)); devel_debug ( path); gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (chooser), path ); if (path && strlen (path) > 0) g_free (path); }
/** * Set sensitiveness of all menu items that work on the selected scheduled. * \param sensitive Sensitiveness (FALSE for unsensitive, TRUE for * sensitive). * * \return FALSE */ gboolean gsb_menu_set_menus_select_scheduled_sensitive ( gboolean sensitive ) { devel_debug ( sensitive ? "item sensitive" : "item unsensitive" ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/EditTransaction", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/RemoveTransaction", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/CloneTransaction", sensitive ); return FALSE; }
/** * Show or hide the transactions form. * * \return FALSE */ gboolean gsb_gui_toggle_show_form ( void ) { devel_debug (NULL); /* FIXME benj: ugly but I cannot find a way to block this ... */ if ( block_menu_cb ) return FALSE; gsb_form_switch_expander ( ); return FALSE; }
/** * update the variable last_path_used with the path given in param * * \param last_path * * \return * */ void gsb_file_update_last_path ( const gchar *last_path ) { devel_debug ( last_path ); if (last_path && strlen (last_path)) { if (last_path_used) g_free (last_path_used); last_path_used = my_strdup (last_path); } }
/** * clean the scheduled form part * and set the default values * * \param account number * * \return FALSE * */ gboolean gsb_form_scheduler_clean ( void ) { gint column; GtkWidget *widget; devel_debug (NULL); /* set to NULL the execute flag */ g_object_set_data ( G_OBJECT (gsb_form_get_form_widget ()), "execute_scheduled", NULL ); /* first we show it, becaus hidden when execute a scheduled transaction */ if (gsb_form_get_origin () == ORIGIN_VALUE_SCHEDULED) gtk_widget_show (gsb_form_get_scheduler_part ()); /* clean the scheduled widget */ for ( column = 0 ; column < SCHEDULED_FORM_MAX_WIDGETS ; column++ ) { widget = gsb_form_scheduler_get_element_widget (column); /* some widgets can be set unsensitive because of the children of splits, * so resensitive all to be sure */ if (widget) { switch (column) { case SCHEDULED_FORM_ACCOUNT: case SCHEDULED_FORM_AUTO: case SCHEDULED_FORM_FREQUENCY_BUTTON: case SCHEDULED_FORM_FREQUENCY_USER_BUTTON: gtk_combo_box_set_active ( GTK_COMBO_BOX (widget), 0 ); gtk_widget_set_sensitive ( widget, FALSE ); break; case SCHEDULED_FORM_LIMIT_DATE: gsb_form_widget_set_empty ( widget, TRUE ); gtk_entry_set_text ( GTK_ENTRY ( widget ), _("Limit date") ); gtk_widget_set_sensitive ( widget, TRUE ); break; case SCHEDULED_FORM_FREQUENCY_USER_ENTRY: gsb_form_widget_set_empty ( widget, TRUE ); gtk_entry_set_text ( GTK_ENTRY ( widget ), _("Own frequency") ); gtk_widget_set_sensitive ( widget, TRUE ); break; } } } return FALSE; }
/** * ajoute une nouvelle icone pour le compte passé en paramètre * * /param la chaine codée de l'icone * return TRUE if OK else FALSE * */ gboolean gsb_select_icon_new_account_icon_from_file ( gint account_number, const gchar *filename ) { struct_account_icon *icon; GdkPixbuf *pixbuf; GError *error = NULL; if ( !filename || !strlen ( filename ) ) return FALSE; else { if ( !g_file_test ( filename, G_FILE_TEST_EXISTS ) ) return FALSE; } icon = g_malloc0 ( sizeof ( struct_account_icon ) ); icon_buffer = icon; if ( !icon ) { dialogue_error_memory (); return FALSE; } icon -> account_number = account_number; pixbuf = gdk_pixbuf_new_from_file_at_size ( filename , 32, 32, &error ); if ( pixbuf ) { icon -> pixbuf = pixbuf; list_accounts_icon = g_slist_prepend ( list_accounts_icon, icon ); return TRUE; } else { gchar* tmp_str; tmp_str = g_strconcat( "Erreur de pixbuf : ", error -> message, " image ", filename, NULL ); devel_debug ( tmp_str ); dialogue_error ( tmp_str ); g_error_free ( error ); g_free ( tmp_str ); g_free ( icon ); return FALSE; } }
/** * Set sensitiveness of all menu items that work on the selected transaction. * \param sensitive Sensitiveness (FALSE for unsensitive, TRUE for * sensitive). * * \return FALSE */ gboolean gsb_menu_set_menus_select_transaction_sensitive ( gboolean sensitive ) { devel_debug ( sensitive ? "item sensitive" : "item unsensitive" ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/EditTransaction", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/RemoveTransaction", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/TemplateTransaction", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/CloneTransaction", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/ConvertToScheduled", sensitive ); gsb_gui_sensitive_menu_item ( "/menubar/EditMenu/MoveToAnotherAccount", sensitive ); return FALSE; }
/** * called every x minutes defined by user * to save a backup of the file * * \param null * * \return TRUE to continue the timeout, FALSE to stop the timeout * */ gboolean gsb_file_automatic_backup ( gpointer null ) { devel_debug (NULL); if (!conf.make_backup_every_minutes) /* stop the timeout */ return FALSE; /* we save only if there is a nb of minutes, but don't stop the timer if not */ if (conf.make_backup_nb_minutes) gsb_file_save_backup (); return TRUE; }
void print_tree_view_list_init_tree_view_data ( GtkTreeView *tree_view ) { GList *list; GList *list_tmp; gint col_width = 0; gint i = 0; devel_debug (NULL); /* get the number of columns */ list = gtk_tree_view_get_columns ( tree_view ); nbre_cols = g_list_length ( list ); tree_view_cols_width = g_malloc0 ( nbre_cols * sizeof ( gint ) ); alignment = g_malloc0 ( nbre_cols * sizeof ( gint ) ); list_tmp = list; while ( list_tmp ) { GtkTreeViewColumn *col; col = list_tmp -> data; col_width += gtk_tree_view_column_get_width ( col ); list_tmp = list_tmp -> next; } list_tmp = list; while ( list_tmp ) { GtkTreeViewColumn *col; gfloat number; col = ( GtkTreeViewColumn * ) list_tmp -> data; tree_view_cols_width[i] = ( gtk_tree_view_column_get_width ( col ) * 100 ) / col_width + 1; number = gtk_tree_view_column_get_alignment ( col ); if ( number == 0.0 ) alignment[i] = PANGO_ALIGN_LEFT; else if ( number == 1.0 ) alignment[i] = PANGO_ALIGN_RIGHT; else alignment[i] = PANGO_ALIGN_CENTER; list_tmp = list_tmp -> next; i++; } g_list_free ( list ); }
/** * close the file * if no file loaded or no change, directly return TRUE * * \param * * \return FALSE if problem, TRUE if ok * */ gboolean gsb_file_close ( void ) { gint result; devel_debug (NULL); if ( !assert_account_loaded () ) return ( TRUE ); /* ask for saving */ result = gsb_file_dialog_save(); switch ( result ) { case GTK_RESPONSE_OK: /* try to save */ if ( !gsb_file_save_file (-1) ) return ( FALSE ); case GTK_RESPONSE_NO : /* remove the lock */ if ( !etat.fichier_deja_ouvert && gsb_data_account_get_accounts_amount () && nom_fichier_comptes ) gsb_file_util_modify_lock ( FALSE ); gsb_gui_init_general_vbox ( ); /* free all the variables */ init_variables (); gsb_account_property_clear_config ( ); gsb_main_set_grisbi_title ( -1 ); /* unsensitive the necessaries menus */ gsb_menu_set_menus_with_file_sensitive ( FALSE ); table_etat = NULL; return ( TRUE ); default : return FALSE; } }
/** * update the font in all the transactions in the list * * \param * * \return * */ void update_fonte_listes ( gchar *fontname, gpointer null) { GValue value = {0,}; gchar *font; devel_debug (NULL); if ( conf.utilise_fonte_listes ) font = fontname; else font = NULL; g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, font); transaction_list_update_column (CUSTOM_MODEL_FONT, &value); }
/** * close grisbi by destroying the main window * This function is called by the Quit menu option. * * \param * * \return FALSE * */ gboolean gsb_main_grisbi_close ( void ) { devel_debug (NULL); /* sauvegarde la position de la fenetre principale */ if ( conf.full_screen == 0 && conf.maximize_screen == 0 ) gtk_window_get_position ( GTK_WINDOW ( run.window ), &conf.root_x, &conf.root_y ); /* sauvegarde de la taille de la fenêtre si nécessaire */ if ( conf.full_screen == 0 && conf.maximize_screen == 0 ) gtk_window_get_size ( GTK_WINDOW ( run.window ), &conf.main_width, &conf.main_height ); if ( !main_window_delete_event ( run.window, NULL ) ) gtk_widget_destroy ( run.window ); /* clean finish of the debug file */ if ( etat.debug_mode ) gsb_debug_finish_log ( ); return FALSE; }
/** * remove the filename from the list of recently opened file * * \param filename * * \return * */ void gsb_file_remove_name_from_opened_list ( gchar *filename ) { gint i, j; devel_debug ( filename ); efface_derniers_fichiers_ouverts(); devel_debug_int ( conf.nb_derniers_fichiers_ouverts ); for ( i = 0 ; i < conf.nb_derniers_fichiers_ouverts; i++ ) { if ( strcmp (filename, tab_noms_derniers_fichiers_ouverts[i]) == 0 ) { for ( j = i; ( j + 1 ) < conf.nb_derniers_fichiers_ouverts; j++ ) { tab_noms_derniers_fichiers_ouverts[j] = tab_noms_derniers_fichiers_ouverts[j+1]; } conf.nb_derniers_fichiers_ouverts--; } } affiche_derniers_fichiers_ouverts(); }
/** * initialise le contenu du tableau d'affichage des opérations. * * */ void initialise_tab_affichage_ope ( void ) { gint tab[TRANSACTION_LIST_ROWS_NB][CUSTOM_MODEL_VISIBLE_COLUMNS] = { { ELEMENT_CHQ, ELEMENT_DATE, ELEMENT_PARTY, ELEMENT_MARK, ELEMENT_DEBIT, ELEMENT_CREDIT, ELEMENT_BALANCE }, {0, 0, ELEMENT_CATEGORY, 0, ELEMENT_PAYMENT_TYPE, ELEMENT_AMOUNT, 0 }, {0, 0, ELEMENT_NOTES, 0, 0, 0, 0 }, {0, 0, 0, 0, 0, 0, 0 } }; gint i, j; devel_debug (NULL); for ( i = 0 ; i<TRANSACTION_LIST_ROWS_NB ; i++ ) for ( j = 0 ; j<CUSTOM_MODEL_VISIBLE_COLUMNS ; j++ ) tab_affichage_ope[i][j] = tab[i][j]; /* by default, the display of lines is 1, 1-2, 1-2-3 */ display_one_line = 0; display_two_lines = 0; display_three_lines = 0; }
/** * callback pour traiter les changements dans le GtkComboBoxEntry * * \param le GtkComboBoxEntry appellant * * \return void * * */ void gsb_select_icon_entry_text_changed ( GtkComboBoxEntry *entry, gpointer user_data ) { GtkTreePath *path; const gchar *tmpstr; gchar *ptr; tmpstr = gtk_entry_get_text ( GTK_ENTRY (GTK_BIN (entry_text)->child ) ); devel_debug ( tmpstr ); ptr = g_strstr_len ( tmpstr, -1, path_icon ); if ( ptr == NULL ) { if ( g_file_test ( tmpstr, G_FILE_TEST_IS_DIR ) ) { path_icon = g_strdup ( tmpstr ); path = gsb_select_icon_fill_icon_view ( NULL ); gtk_icon_view_scroll_to_path (GTK_ICON_VIEW ( icon_view ), path, TRUE, 0.5, 0 ); gtk_widget_set_sensitive (bouton_OK, FALSE ); } } }
/** * retourne le logo par défaut de grisbi * * * return a new pixbuf * */ GdkPixbuf *gsb_select_icon_get_default_logo_pixbuf ( void ) { GdkPixbuf *pixbuf = NULL; GError *error = NULL; pixbuf = gdk_pixbuf_new_from_file ( g_build_filename (gsb_dirs_get_pixmaps_dir ( ), "grisbi-logo.png", NULL), &error ); if ( ! pixbuf ) { devel_debug ( error -> message ); g_error_free ( error ); } if ( gdk_pixbuf_get_width (pixbuf) > LOGO_WIDTH || gdk_pixbuf_get_height (pixbuf) > LOGO_HEIGHT ) { return gsb_select_icon_resize_logo_pixbuf ( pixbuf ); } else return pixbuf; }
/** * Crée le dialogue pour le choix du nouveau répertoire et entre le choix * dans le GtkComboBoxEntry * * \param bouton appelant * * \return void * * */ void gsb_select_icon_create_file_chooser ( GtkWidget * button, gpointer user_data ) { GtkWidget *chooser; GtkFileFilter *filter; chooser = gtk_file_chooser_dialog_new ( _("Select icon directory"), GTK_WINDOW (dialog), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gtk_window_set_position ( GTK_WINDOW (chooser), GTK_WIN_POS_CENTER_ON_PARENT ); gtk_window_set_transient_for (GTK_WINDOW (chooser), GTK_WINDOW (dialog)); gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE); gtk_widget_set_size_request ( chooser, 600, 750 ); filter = gtk_file_filter_new (); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser), filter); gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER ( chooser ), path_icon ); if (gtk_dialog_run (GTK_DIALOG ( chooser ) ) == GTK_RESPONSE_ACCEPT ) { GtkTreePath *path; path_icon = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER ( chooser ) ); devel_debug ( path_icon ); path = gsb_select_icon_fill_icon_view ( NULL ); gtk_icon_view_scroll_to_path (GTK_ICON_VIEW ( icon_view ), path, TRUE, 0.5, 0 ); gsb_select_icon_add_path ( ); gtk_entry_set_text ( GTK_ENTRY (GTK_BIN (entry_text)->child ), path_icon ); gtk_widget_set_sensitive (bouton_OK, FALSE ); } gtk_widget_destroy ( chooser ); }
gboolean print_tree_view_list ( GtkWidget *menu_item, GtkTreeView *tree_view ) { GtkWidget *label_title; GtkTreeSelection *tree_selection; devel_debug (NULL); tree_selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW ( tree_view ) ); if ( !gtk_tree_selection_get_selected ( GTK_TREE_SELECTION ( tree_selection ), NULL, NULL ) ) return FALSE; label_title = g_object_get_data ( G_OBJECT ( tree_view ), "label_title" ); title_string = g_strdup ( gtk_label_get_text ( GTK_LABEL ( label_title ) ) ); print_dialog_config ( G_CALLBACK ( print_tree_view_list_begin ), G_CALLBACK ( print_tree_view_list_draw_page ), _("Fonts & layout"), G_CALLBACK ( print_tree_view_list_layout_config ), G_CALLBACK ( print_transactions_list_apply ), ( gpointer ) tree_view ); return TRUE; }
/** * called by menu : begin the debug mode * show a message to say where the log will be saved * * \param * * \return FALSE * */ gboolean gsb_debug_start_log ( void ) { gchar *tmp_str; gchar *debug_filename; devel_debug ( NULL ); if ( nom_fichier_comptes ) { gchar *base_filename = g_strdup ( nom_fichier_comptes ); gchar *complete_filename; gchar *basename; base_filename [strlen ( base_filename ) - 4] = 0; complete_filename = g_strconcat ( base_filename, "-log.txt", NULL); basename = g_path_get_basename ( complete_filename ); debug_filename = g_build_filename ( my_get_gsb_file_default_dir (), basename, NULL); g_free ( basename); g_free ( complete_filename ); g_free ( base_filename ); } else { debug_filename = g_build_filename ( my_get_gsb_file_default_dir (), "No_name-log.txt", NULL); } tmp_str = g_strdup_printf (_("The debug-mode is starting. Grisbi will write a log into %s. " "Please send that file with the obfuscated file into the bug report."), debug_filename ); dialogue ( tmp_str ); g_free (tmp_str); debug_file = g_fopen ( debug_filename, "w" ); g_free ( debug_filename ); if ( debug_file ) { GtkWidget *widget; gchar *tmp_str_2; GtkUIManager *ui_manager = gsb_menu_get_ui_manager ( ); widget = gtk_ui_manager_get_widget ( ui_manager, "/menubar/FileMenu/DebugMode" ); etat.debug_mode = TRUE; /* unsensitive the menu, we cannot reverse the debug mode */ if ( widget && GTK_IS_WIDGET ( widget ) ) gtk_widget_set_sensitive ( widget, FALSE ); /* début du mode débogage */ tmp_str = g_strdup_printf(_("%s, %2f : Debug - %s:%d:%s\n\n"), get_debug_time ( ), (double ) clock ( )/ CLOCKS_PER_SEC, __FILE__, __LINE__, __PRETTY_FUNCTION__ ); fwrite ( tmp_str, sizeof (gchar), strlen ( tmp_str ), debug_file ); fflush ( debug_file ); g_free ( tmp_str ); /* write locales */ tmp_str = gsb_main_get_print_locale_var ( ); fwrite ( tmp_str, sizeof (gchar), strlen ( tmp_str ), debug_file ); fflush ( debug_file ); g_free ( tmp_str ); tmp_str = g_strdup_printf ( "gint64\n" "\tG_GINT64_MODIFIER = \"%s\"\n" "\t%"G_GINT64_MODIFIER"d\n\n", G_GINT64_MODIFIER, G_MAXINT64 ); fwrite ( tmp_str, sizeof (gchar), strlen ( tmp_str ), debug_file ); fflush ( debug_file ); g_free ( tmp_str ); tmp_str = gsb_main_get_print_dir_var ( ); fwrite ( tmp_str, sizeof (gchar), strlen ( tmp_str ), debug_file ); fflush ( debug_file ); g_free ( tmp_str ); tmp_str = g_strdup ( "Formats importés\n" ); fwrite ( tmp_str, sizeof (gchar), strlen ( tmp_str ), debug_file ); fflush ( debug_file ); g_free ( tmp_str ); tmp_str = gsb_import_formats_get_list_formats_to_string ( ); tmp_str_2 = g_strconcat ( tmp_str, "\n", NULL ); fwrite ( tmp_str_2, sizeof (gchar), strlen ( tmp_str_2 ), debug_file ); fflush ( debug_file ); g_free ( tmp_str ); g_free ( tmp_str_2 ); } else dialogue_error (_("Grisbi failed to create the log file...") ); return FALSE; }
/** * open a new grisbi file, don't check anything about another opened file that must * have been done before * * \para filename the name of the file * * \return TRUE ok, FALSE problem * */ gboolean gsb_file_open_file ( gchar *filename ) { GSList *list_tmp; devel_debug (filename); if ( !filename || !strlen (filename)) return FALSE; gsb_status_wait ( TRUE ); gsb_status_message ( _("Loading accounts") ); /* try to load the file */ /* FIXME:BUG under Windows: for unknwon reason yet filename is cleared * when returning from gsb_file_load_open_file! * making application crashes! */ if ( gsb_file_load_open_file (filename)) { /* the file has been opened succesfully */ /* we make a backup if necessary */ if ( conf.sauvegarde_demarrage ) { gsb_file_save_backup (); gsb_file_set_modified ( FALSE ); } } else { /* Loading failed. */ gsb_status_message ( _("Failed to load accounts") ); if ( conf.sauvegarde_demarrage || conf.make_backup || conf.make_backup_every_minutes ) { gchar *tmpstr = g_strdup_printf ( _("Error loading file '%s'"), filename); gchar *tmpstr2 = g_strdup_printf ( _("Grisbi was unable to load file. You should find the last " "backups in '%s', they are saved with date and time into " "their name so you should find easily the last backup " "saved.\n" "Please contact the Grisbi's team on [email protected] " "to find what happened to you current file."), gsb_file_get_backup_path ()); dialogue_error_hint ( tmpstr2, tmpstr ); g_free ( tmpstr ); g_free ( tmpstr2 ); gsb_status_stop_wait ( TRUE ); return FALSE; } else { gchar *tmpstr = g_strdup_printf ( _("Error loading file '%s'"), filename); gchar *tmpstr2; if (gsb_file_get_backup_path ()) tmpstr2 = g_strdup_printf ( _("Grisbi was unable to load file and the backups seem not to " "be activated... This is a bad thing.\nYour backup path is '%s', " "try to find if earlier you had some backups in there ?\n" "Please contact the Grisbi's team on [email protected] " "to find what happened to you current file."), gsb_file_get_backup_path ()); else tmpstr2 = my_strdup ( _("Grisbi was unable to load file and the backups seem not " "to be activated... This is a bad thing.\n" "Please contact the Grisbi's team on " "[email protected] to find what happened to you " "current file.")); dialogue_error_hint ( tmpstr2, tmpstr ); g_free ( tmpstr ); g_free ( tmpstr2 ); gsb_status_stop_wait ( TRUE ); return FALSE; } } /* ok, here the file or backup is loaded */ gsb_status_message ( _("Checking schedulers")); /* the the name in the last opened files */ gsb_file_append_name_to_opened_list ( filename ); /* create the archives store data, ie the transaction wich will replace the archive in * the list of transactions */ gsb_data_archive_store_create_list (); /* create all the gui */ gsb_file_new_gui (); /* check the amounts of all the accounts */ gsb_status_message ( _("Checking amounts")); list_tmp = gsb_data_account_get_list_accounts (); while ( list_tmp ) { gint account_number; volatile gint value; account_number = gsb_data_account_get_no_account ( list_tmp -> data ); /* set the minimum balances to be shown or not */ value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number), gsb_data_account_get_mini_balance_authorized (account_number) ) == -1; gsb_data_account_set_mini_balance_authorized_message ( account_number, value); value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number), gsb_data_account_get_mini_balance_wanted (account_number) ) == -1; gsb_data_account_set_mini_balance_wanted_message ( account_number, value); list_tmp = list_tmp -> next; } /* set Grisbi title */ gsb_main_set_grisbi_title ( -1 ); /* update the main page */ mise_a_jour_accueil (TRUE); /* for now, the flag for modification of the file is ok, but the menu couldn't be set * as sensitive/unsensitive so do it now */ gsb_file_set_modified ( gsb_file_get_modified ( ) ); gsb_status_message ( _("Done") ); gsb_status_stop_wait ( TRUE ); /* go to the home page */ gsb_gui_navigation_set_selection ( GSB_HOME_PAGE, -1, NULL ); /* set the focus to the selection tree at left */ gtk_widget_grab_focus ( gsb_gui_navigation_get_tree_view ( ) ); return TRUE; }
/** * append a new name to the list of recently opened file * * \param path_fichier * * \return * */ void gsb_file_append_name_to_opened_list ( gchar * path_fichier ) { gint i, position; gchar * dernier, * real_name; devel_debug (path_fichier); if ( !path_fichier ) return; if ( conf.nb_max_derniers_fichiers_ouverts == 0 ) return; if ( conf.nb_derniers_fichiers_ouverts < 0 ) conf.nb_derniers_fichiers_ouverts = 0; if ( !g_path_is_absolute ( nom_fichier_comptes ) ) { real_name = g_strdup( (gchar*)realpath ( nom_fichier_comptes, NULL )); if ( ! real_name ) { notice_debug ( "could not resolve relative file name" ); return; } devel_debug ( real_name ); } else { real_name = g_strdup ( path_fichier ); } /* on commence par vérifier si ce fichier n'est pas dans les nb_derniers_fichiers_ouverts * noms */ position = 0; if ( conf.nb_derniers_fichiers_ouverts ) { for ( i = 0; i < conf.nb_derniers_fichiers_ouverts; i++ ) { if ( !strcmp ( real_name, tab_noms_derniers_fichiers_ouverts[i] ) ) { /* si ce fichier est déjà le dernier ouvert, on laisse tomber */ if ( !i ) { g_free ( real_name ); return; } position = i; } } efface_derniers_fichiers_ouverts ( ); if ( position ) { /* le fichier a été trouvé, on fait juste une rotation */ for ( i = position; i > 0 ; i-- ) tab_noms_derniers_fichiers_ouverts[i] = tab_noms_derniers_fichiers_ouverts[i-1]; if ( real_name ) tab_noms_derniers_fichiers_ouverts[0] = my_strdup ( real_name ); else tab_noms_derniers_fichiers_ouverts[0] = my_strdup ( "<no file>" ); affiche_derniers_fichiers_ouverts ( ); g_free ( real_name ); return; } /* le fichier est nouveau, on décale tout d'un cran et on met le nouveau à 0 */ /* si on est déjà au max, c'est juste un décalage avec perte du dernier */ /* on garde le ptit dernier dans le cas contraire */ dernier = tab_noms_derniers_fichiers_ouverts[conf.nb_derniers_fichiers_ouverts-1]; for ( i = conf.nb_derniers_fichiers_ouverts - 1 ; i > 0 ; i-- ) tab_noms_derniers_fichiers_ouverts[i] = tab_noms_derniers_fichiers_ouverts[i-1]; } else dernier = NULL; if ( conf.nb_derniers_fichiers_ouverts < conf.nb_max_derniers_fichiers_ouverts ) { tab_noms_derniers_fichiers_ouverts = g_realloc ( tab_noms_derniers_fichiers_ouverts, ( ++conf.nb_derniers_fichiers_ouverts ) * sizeof ( gpointer ) ); tab_noms_derniers_fichiers_ouverts[conf.nb_derniers_fichiers_ouverts-1] = dernier; } tab_noms_derniers_fichiers_ouverts[0] = my_strdup ( real_name ); affiche_derniers_fichiers_ouverts(); g_free ( real_name ); }
/** * Set all the config variables to their default values. * called before loading the config * or for a new opening */ static void gsb_file_config_clean_config ( void ) { devel_debug (NULL); conf.main_width = 0; conf.main_height = 0; conf.prefs_width = 600; conf.force_enregistrement = 1; conf.r_modifiable = 0; /* we can not change the reconciled transaction */ conf.dernier_fichier_auto = 1; /* on n'ouvre pas directement le dernier fichier */ conf.sauvegarde_auto = 0; /* on NE sauvegarde PAS * automatiquement par défaut */ conf.entree = 1; /* la touche entree provoque l'enregistrement de l'opération */ nb_days_before_scheduled = 0; /* nb de jours avant l'échéance pour prévenir */ conf.execute_scheduled_of_month = FALSE; conf.balances_with_scheduled = TRUE; conf.formulaire_toujours_affiche = 0; /* le formulaire ne s'affiche que lors de l'edition d'1 opé */ conf.affichage_exercice_automatique = 0; /* l'exercice est choisi en fonction de la date */ conf.automatic_completion_payee = 1; /* by default automatic completion */ conf.limit_completion_to_current_account = 0; /* By default, do full search */ conf.automatic_recover_splits = 1; conf.automatic_erase_credit_debit = 0; conf.display_grisbi_title = GSB_ACCOUNTS_TITLE; /* show Accounts file title par défaut */ conf.display_toolbar = GSB_BUTTON_BOTH; /* How to display toolbar icons. */ conf.active_scrolling_left_pane = FALSE; /* Active_scrolling_left_pane or not. */ conf.show_headings_bar = TRUE; /* Show toolbar or not. */ conf.show_transaction_selected_in_form = 1; /* show selected transaction in form */ conf.show_transaction_gives_balance = 1; /* show transaction that gives the balance of the day */ conf.transactions_list_primary_sorting = 1; /* Primary sorting option for the transactions */ conf.transactions_list_secondary_sorting = 0; /* Secondary sorting option for the transactions */ conf.show_closed_accounts = FALSE; if ( conf.font_string ) { g_free ( conf.font_string ); conf.font_string = NULL; } conf.force_enregistrement = 1; /* par défaut, on force l'enregistrement */ gsb_file_update_last_path (g_get_home_dir ()); gsb_file_set_backup_path ( gsb_dirs_get_user_data_dir () ); conf.make_backup = 1; conf.make_backup_every_minutes = FALSE; conf.make_backup_nb_minutes = 0; #if IS_DEVELOPMENT_VERSION == 1 conf.stable_config_file_model = 0; #endif conf.nb_derniers_fichiers_ouverts = 0; conf.nb_max_derniers_fichiers_ouverts = 3; tab_noms_derniers_fichiers_ouverts = NULL; /* no compress by default */ conf.compress_file = 0; conf.compress_backup = 0; /* archive data */ conf.check_for_archival = TRUE; conf.max_non_archived_transactions_for_check = 3000; conf.last_tip = -1; conf.show_tip = FALSE; /* mise en conformité avec les recommandations FreeDesktop. */ if ( conf.browser_command ) g_free ( conf.browser_command ); conf.browser_command = g_strdup ( ETAT_WWW_BROWSER ); conf.metatree_action_2button_press = 0; /* action par défaut pour le double clic sur division */ memset ( etat.csv_skipped_lines, '\0', sizeof(gboolean) * CSV_MAX_TOP_LINES ); }
/** * save the config file * it uses the glib config utils after 0.6.0 * if cannot load, try the xml file before that version * * \param * * \return TRUE if ok * */ gboolean gsb_file_config_save_config ( void ) { GKeyFile *config; const gchar *filename; gchar *file_content; gchar *name; gsize length; FILE *conf_file; gint i; devel_debug (NULL); filename = gsb_dirs_get_grisbirc_filename (); config = g_key_file_new (); #if IS_DEVELOPMENT_VERSION == 1 /* set config model */ g_key_file_set_integer ( config, "Model", "Stable_config_file_model", conf.stable_config_file_model ); #endif g_key_file_set_integer ( config, "Geometry", "Root_x", conf.root_x ); g_key_file_set_integer ( config, "Geometry", "Root_y", conf.root_y ); g_key_file_set_integer ( config, "Geometry", "Width", conf.main_width ); g_key_file_set_integer ( config, "Geometry", "Height", conf.main_height ); g_key_file_set_integer ( config, "Geometry", "Full_screen", conf.full_screen ); g_key_file_set_integer ( config, "Geometry", "Maximize_screen", conf.maximize_screen ); /* Remember size of main panel */ g_key_file_set_integer ( config, "Geometry", "Panel_width", conf.panel_width ); /* preferences size */ g_key_file_set_integer ( config, "Geometry", "Prefs_width", conf.prefs_width ); /* save general */ g_key_file_set_integer ( config, "General", "Can modify R", conf.r_modifiable ); g_key_file_set_string ( config, "General", "Path", gsb_file_get_last_path () ); g_key_file_set_integer ( config, "General", "Show permission alert", conf.alerte_permission ); g_key_file_set_integer ( config, "General", "Function of enter", conf.entree ); g_key_file_set_integer ( config, "General", "Show alert messages", conf.alerte_mini ); g_key_file_set_integer ( config, "General", "Use user font", conf.utilise_fonte_listes ); if ( conf.font_string ) g_key_file_set_string ( config, "General", "Font name", conf.font_string ); if ( conf.browser_command ) { gchar *string; string = my_strdelimit ( conf.browser_command, "&", "\\e" ); if ( string ) g_key_file_set_string ( config, "General", "Web", string ); g_free (string); } g_key_file_set_integer ( config, "General", "Pluriel_final", conf.pluriel_final ); g_key_file_set_integer ( config, "General", "Metatree_action_2button_press", conf.metatree_action_2button_press ); /* save backup part */ g_key_file_set_integer ( config, "Backup", "Make backup", conf.make_backup ); g_key_file_set_integer ( config, "Backup", "Make backup single file", conf.make_bakup_single_file ); g_key_file_set_integer ( config, "Backup", "Make backup every x minutes", conf.make_backup_every_minutes ); g_key_file_set_integer ( config, "Backup", "Compress backup", conf.compress_backup ); g_key_file_set_integer ( config, "Backup", "Make backup nb minutes", conf.make_backup_nb_minutes ); if (gsb_file_get_backup_path ()) g_key_file_set_string ( config, "Backup", "Backup path", gsb_file_get_backup_path ()); /* save input/output */ g_key_file_set_integer ( config, "IO", "Load last file", conf.dernier_fichier_auto ); g_key_file_set_integer ( config, "IO", "Save at closing", conf.sauvegarde_auto ); g_key_file_set_integer ( config, "IO", "Save at opening", conf.sauvegarde_demarrage ); g_key_file_set_integer ( config, "IO", "Nb last opened files", conf.nb_max_derniers_fichiers_ouverts ); g_key_file_set_integer ( config, "IO", "Compress file", conf.compress_file ); g_key_file_set_integer ( config, "IO", "Force saving", conf.force_enregistrement ); if ( conf.nb_derniers_fichiers_ouverts > 0 && tab_noms_derniers_fichiers_ouverts) g_key_file_set_string_list ( config, "IO", "Names last files", (const gchar **) tab_noms_derniers_fichiers_ouverts, conf.nb_derniers_fichiers_ouverts); g_key_file_set_integer ( config, "IO", "Check_archival_at_opening", conf.check_for_archival ); g_key_file_set_integer ( config, "IO", "Max_transactions_before_warn_archival", conf.max_non_archived_transactions_for_check ); /* save scheduled section */ g_key_file_set_integer ( config, "Scheduled", "Days before remind", nb_days_before_scheduled ); g_key_file_set_integer ( config, "Scheduled", "Execute scheduled of month", conf.execute_scheduled_of_month ); g_key_file_set_integer ( config, "Scheduled", "Balances with scheduled", conf.balances_with_scheduled ); g_key_file_set_integer ( config, "Scheduled", "Group_partial_balance", conf.group_partial_balance_under_accounts ); /* save shown section */ g_key_file_set_integer ( config, "Display", "Show transaction form", conf.formulaire_toujours_affiche ); g_key_file_set_integer ( config, "Display", "Show selected transaction in form", conf.show_transaction_selected_in_form ); g_key_file_set_integer ( config, "Display", "Show transaction gives balance", conf.show_transaction_gives_balance ); g_key_file_set_integer ( config, "Display", "Transactions_list_primary_sorting", conf.transactions_list_primary_sorting ); g_key_file_set_integer ( config, "Display", "Transactions_list_secondary_sorting", conf.transactions_list_secondary_sorting ); g_key_file_set_integer ( config, "Display", "Show automatic financial year", conf.affichage_exercice_automatique ); g_key_file_set_integer ( config, "Display", "Automatic completion payee", conf.automatic_completion_payee ); g_key_file_set_integer ( config, "Display", "Limit payee completion", conf.limit_completion_to_current_account ); g_key_file_set_integer ( config, "Display", "Automatic_recover_splits", conf.automatic_recover_splits ); g_key_file_set_integer ( config, "Display", "Automatic_erase_credit_debit", conf.automatic_erase_credit_debit ); g_key_file_set_integer ( config, "Display", "Display toolbar", conf.display_toolbar ); g_key_file_set_integer ( config, "Display", "Active_scrolling_left_pane", conf.active_scrolling_left_pane ); g_key_file_set_integer ( config, "Display", "Show headings bar", conf.show_headings_bar ); g_key_file_set_integer ( config, "Display", "Show closed accounts", conf.show_closed_accounts ); g_key_file_set_integer ( config, "Display", "Display grisbi title", conf.display_grisbi_title ); /* save messages */ for ( i = 0; messages[i].name; i ++ ) { name = g_strconcat ( messages[i].name , "-answer", NULL ); g_key_file_set_integer ( config, "Messages", messages[i].name, messages[i].hidden ); g_key_file_set_integer ( config, "Messages", name, messages[i].default_answer ); g_free ( name ); } for ( i = 0; delete_msg[i].name; i ++ ) { g_key_file_set_integer ( config, "Messages", delete_msg[i].name, delete_msg[i].hidden ); } g_key_file_set_integer ( config, "Messages", "Last tip", conf.last_tip ); g_key_file_set_integer ( config, "Messages", "Show tip", conf.show_tip ); /* save into a file */ file_content = g_key_file_to_data ( config, &length, NULL ); conf_file = fopen ( filename, "w" ); #ifndef _WIN32 if ( !conf_file ) { utils_files_create_XDG_dir ( ); conf_file = fopen ( filename, "w" ); } #endif if ( !conf_file || !fwrite ( file_content, sizeof ( gchar ), length, conf_file ) ) { gchar* tmpstr = g_strdup_printf ( _("Cannot save configuration file '%s': %s"), filename, g_strerror ( errno ) ); dialogue_error ( tmpstr ); g_free ( tmpstr ); g_free ( file_content); g_key_file_free (config); return ( FALSE ); } fclose ( conf_file ); g_free ( file_content); g_key_file_free (config); return TRUE; }
/* get the line af the file, * convert it in UTF8 and fill string with that line * * \param fichier * \param string * \param coding_system the orig coding system of the string * * \return EOF, 1 if ok, 0 if problem * */ gint get_utf8_line_from_file ( FILE *fichier, gchar **string, const gchar *coding_system ) { gchar c = 0; gint i = 0; gint j = 0; gchar *pointeur_char = NULL; gchar *tmp_string; if ( !fichier ) return 0; /* allocate 30 characters, and increase it 30 by 30 */ pointeur_char = (gchar*)g_realloc(pointeur_char,30*sizeof(gchar)); if ( !pointeur_char ) { /* ouch, not enough memory */ dialogue_error ( _("Memory allocation error" )); return 0; } /* get the string untill \n or \r (windows format) */ c =(gchar)fgetc(fichier); while ( ( c != '\n' ) && (c != '\r') && !feof (fichier)) { pointeur_char[j++] = c; if ( ++i == 29 ) { pointeur_char = (gchar*)g_realloc(pointeur_char, j + 1 + 30*sizeof(gchar)); if ( !pointeur_char ) { /* ouch, not enough memory */ dialogue_error ( _("Memory allocation error" )); return 0; } i = 0; } c =(gchar)fgetc(fichier); } pointeur_char[j] = 0; /* if we finished on \r, jump the \n after it */ if ( c == '\r' ) { c =(gchar)fgetc(fichier); if ( c != '\n' ) { ungetc ( c, fichier ); } } tmp_string = g_convert ( pointeur_char, -1, "UTF-8", coding_system, NULL, NULL, NULL ); if (!tmp_string) { devel_debug ("convert to utf8 failed, will use latin2utf8"); tmp_string = latin2utf8 (pointeur_char); if ( tmp_string == NULL ) { dialogue_special ( GTK_MESSAGE_ERROR, make_hint ( _("Convert to utf8 failed."), _("If the result is not correct, try again by selecting the " "correct character set in the window for selecting files.") ) ); return 0; } } *string = tmp_string; g_free (pointeur_char); if ( feof(fichier)) return EOF; else return 1; }
/** * initialisation of all the variables of grisbi * if some are not empty, free them before set it to NULL * * \param * * \return * */ void init_variables ( void ) { gint bet_array_col_width_init[BET_ARRAY_COLUMNS] = {15, 40, 15, 15, 15 }; gint transaction_col_align_init[CUSTOM_MODEL_VISIBLE_COLUMNS] = { 1, 1, 0, 1, 2, 2, 2 }; gint i; /* xxx on devrait séparer ça en 2 : les variables liées au fichier de compte, qui doivent être remises à 0, * et les variables liées à grisbi (ex sauvegarde auto...) qui doivent rester */ devel_debug (NULL); /* init the new crypted file */ run.new_crypted_file = FALSE; /* init the format date */ initialise_format_date ( ); /* init the decimal point and the thousands separator. */ initialise_number_separators ( ); /* initialise l'ordre des pages du panneau de gauche */ gsb_gui_navigation_init_pages_list ( ); /* if ever there is still something from the previous list, * erase now */ transaction_model_initialize(); gsb_data_account_init_variables (); gsb_data_transaction_init_variables (); gsb_data_payee_init_variables (); payees_init_variables_list (); gsb_data_category_init_variables (); categories_init_variables_list (); gsb_data_budget_init_variables (); budgetary_lines_init_variables_list (); gsb_data_report_init_variables (); gsb_data_report_amount_comparison_init_variables (); gsb_data_report_text_comparison_init_variables (); gsb_data_scheduled_init_variables (); gsb_scheduler_list_init_variables (); gsb_data_currency_init_variables (); gsb_data_currency_link_init_variables (); gsb_data_fyear_init_variables (); gsb_data_bank_init_variables (); gsb_data_reconcile_init_variables (); gsb_data_payment_init_variables (); gsb_data_archive_init_variables (); gsb_data_archive_store_init_variables (); gsb_data_import_rule_init_variables (); gsb_import_associations_init_variables ( ); gsb_data_partial_balance_init_variables ( ); gsb_currency_init_variables (); gsb_fyear_init_variables (); gsb_report_init_variables (); gsb_regex_init_variables (); gsb_data_print_config_init (); /* no bank in memory for now */ bank_list_model = NULL; run.mise_a_jour_liste_comptes_accueil = FALSE; run.mise_a_jour_liste_echeances_manuelles_accueil = FALSE; run.mise_a_jour_liste_echeances_auto_accueil = FALSE; run.mise_a_jour_soldes_minimaux = FALSE; run.mise_a_jour_fin_comptes_passifs = FALSE; orphan_child_transactions = NULL; /* the main notebook is set to NULL, * important because it's the checked variable in a new file * to know if the widgets are created or not */ gsb_gui_init_general_notebook ( ); if ( nom_fichier_comptes ) g_free ( nom_fichier_comptes ); nom_fichier_comptes = NULL; affichage_echeances = SCHEDULER_PERIODICITY_ONCE_VIEW; affichage_echeances_perso_nb_libre = 0; affichage_echeances_perso_j_m_a = PERIODICITY_DAYS; /* initialization of titles and logo part */ if ( titre_fichier && strlen ( titre_fichier ) ) g_free ( titre_fichier ); titre_fichier = g_strdup( _("My accounts") ); etat.is_pixmaps_dir = TRUE; if ( etat.name_logo && strlen ( etat.name_logo ) ) g_free ( etat.name_logo ); etat.name_logo = NULL; etat.utilise_logo = 1; gsb_select_icon_init_logo_variables (); etat.retient_affichage_par_compte = 0; /* reconcile (etat) */ run.reconcile_account_number = -1; g_free ( run.reconcile_final_balance ); if ( run.reconcile_new_date ) g_date_free ( run.reconcile_new_date ); run.reconcile_final_balance = NULL; run.reconcile_new_date = NULL; adresse_commune = NULL; adresse_secondaire = NULL; current_tree_view_width = 0; scheduler_current_tree_view_width = 0; initialise_tab_affichage_ope(); valeur_echelle_recherche_date_import = 2; etat.get_fyear_by_value_date = FALSE; /* init default combofix values */ etat.combofix_mixed_sort = FALSE; etat.combofix_max_item = 0; etat.combofix_case_sensitive = FALSE; etat.combofix_enter_select_completion = FALSE; etat.combofix_force_payee = FALSE; etat.combofix_force_category = FALSE; /* mis à NULL prévient un plantage aléatoire dans * gsb_currency_update_combobox_currency_list */ detail_devise_compte = NULL; /* defaut value for width and align of columns */ initialise_largeur_colonnes_tab_affichage_ope ( GSB_ACCOUNT_PAGE, transaction_col_width_init ); initialise_largeur_colonnes_tab_affichage_ope ( GSB_SCHEDULER_PAGE, scheduler_col_width_init ); for ( i = 0 ; i < CUSTOM_MODEL_VISIBLE_COLUMNS ; i++ ) transaction_col_align[i] = transaction_col_align_init[i]; if ( etat.transaction_column_width && strlen ( etat.transaction_column_width ) ) { g_free ( etat.transaction_column_width ); etat.transaction_column_width = NULL; } if ( etat.scheduler_column_width && strlen ( etat.scheduler_column_width ) ) { g_free ( etat.scheduler_column_width ); etat.scheduler_column_width = NULL; } gsb_gui_navigation_init_tree_view ( ); /* free the form */ gsb_form_widget_free_list (); gsb_form_scheduler_free_list (); /* set colors to default */ gsb_color_set_colors_to_default ( ); /* divers */ etat.add_archive_in_total_balance = TRUE; /* add the archived transactions by default */ etat.get_fyear_by_value_date = 0; /* By default use transaction-date */ /* remove the timeout if necessary */ if (id_timeout) { g_source_remove (id_timeout); id_timeout = 0; } /* initializes the variables for the estimate balance module */ /* création de la liste des données à utiliser dans le tableau de résultats */ bet_data_init_variables ( ); /* initialisation des boites de dialogue */ bet_future_initialise_dialog ( ); etat.bet_deb_period = 1; /* defaut value for width of columns */ for ( i = 0 ; i < BET_ARRAY_COLUMNS ; i++ ) bet_array_col_width[i] = bet_array_col_width_init[i]; bet_data_finance_data_simulator_init ( ); bet_graph_set_configuration_variables ( NULL ); }
/** * save the category file * we don't check anything here, all must be done before, here we just write * the file * use the same method as gsb_file_save_save_file * * \param filename the name of the file * * \return TRUE : ok, FALSE : problem * */ gboolean gsb_file_others_save_category ( gchar *filename ) { gchar *file_content; gchar *tmp_str; FILE *file; gulong iterator; gulong length_calculated; gulong length_part; devel_debug (filename); /* we begin to try to reserve enough memory to make the entire file * if not enough, we will make it growth later * the data below are about the memory to take for each part and for 1 of this part * with that i think we will allocate enough memory in one time but not too much */ length_part = 500; length_calculated = length_part * g_slist_length (gsb_data_category_get_categories_list()); if ( length_calculated == 0 ) { tmp_str = g_strdup ( _("There is no category to record. Back.") ); dialogue_error ( tmp_str ); g_free ( tmp_str ); return ( TRUE ); } iterator = 0; file_content = g_malloc0 ( length_calculated ); /* begin the file whit xml markup */ iterator = gsb_file_save_append_part ( iterator, &length_calculated, &file_content, my_strdup ("<?xml version=\"1.0\"?>\n<Grisbi_categ>\n")); iterator = gsb_file_others_save_general_part ( iterator, &length_calculated, &file_content, VERSION_FICHIER_CATEG ); iterator = gsb_file_save_category_part ( iterator, &length_calculated, &file_content ); /* finish the file */ iterator = gsb_file_save_append_part ( iterator, &length_calculated, &file_content, my_strdup ("</Grisbi_categ>")); /* the file is in memory, we can save it */ file = utils_files_utf8_fopen ( filename, "w" ); if ( !file || !fwrite ( file_content, sizeof (gchar), iterator, file )) { tmp_str = g_strdup_printf ( _("Cannot save file '%s': %s"), filename, g_strerror ( errno ) ); dialogue_error ( tmp_str ); g_free ( tmp_str ); g_free ( file_content ); if (file) fclose(file); return ( FALSE ); } fclose (file); g_free ( file_content); return ( TRUE ); }