/** * initialise la largeur des colonnes du tableau d'affichage des opérations. * ou des opérations planifiées. * * */ void initialise_largeur_colonnes_tab_affichage_ope ( gint type_operation, const gchar *description ) { gchar **pointeur_char; gint j; if ( description == NULL ) { if ( type_operation == GSB_ACCOUNT_PAGE ) description = transaction_col_width_init; else if ( type_operation == GSB_SCHEDULER_PAGE ) description = scheduler_col_width_init; } /* the transactions columns are xx-xx-xx-xx and we want to set in transaction_col_width[1-2-3...] */ pointeur_char = g_strsplit ( description, "-", 0 ); if ( type_operation == GSB_ACCOUNT_PAGE ) { for ( j = 0 ; j < CUSTOM_MODEL_VISIBLE_COLUMNS ; j++ ) transaction_col_width[j] = utils_str_atoi ( pointeur_char[j] ); } else if ( type_operation == GSB_SCHEDULER_PAGE ) { for ( j = 0 ; j < SCHEDULER_COL_VISIBLE_COLUMNS ; j++ ) scheduler_col_width[j] = utils_str_atoi ( pointeur_char[j] ); } g_strfreev ( pointeur_char ); }
/** * Parse a gnucash value representation and construct a numeric * representation of it. Gnucash values are always of the form: * "integer/number". Integer value is to be divided by another * integer, which eliminates float approximations. * * \param value Number textual representation to parse. * * \return Numeric value of argument 'value'. */ GsbReal gnucash_value ( gchar * value ) { gchar **tab_value; gdouble number, mantisse; tab_value = g_strsplit ( value, "/", 2 ); number = utils_str_atoi ( tab_value[0] ); mantisse = utils_str_atoi ( tab_value[1] ); return gsb_real_double_to_real (number / mantisse); }
/** * adapte l'utilisation de : en fonction de la langue de l'utilisateur * * * * */ gchar *utils_str_incremente_number_from_str ( const gchar *str_number, gint increment ) { gchar *new_str_number; gchar *prefix = NULL; gint number = 0; gint i = 0; if ( str_number && strlen ( str_number ) > 0 ) { while ( str_number[i] == '0' ) { i++; } if ( i > 0 ) prefix = g_strndup ( str_number, i ); number = utils_str_atoi ( str_number ); } number += increment; new_str_number = utils_str_itoa ( number ); if ( prefix && strlen ( prefix ) > 0 ) { new_str_number = g_strconcat ( prefix, new_str_number, NULL ); g_free ( prefix ); } return new_str_number; }
/** * return a gslist of struct_categ_budget_sel * from a string as no_categ/no_sub_categ/no_sub_categ/no_sub_categ-no_categ/no_sub_categ... * (or idem with budget) * * \param string the string we want to change to a list * * \return a g_slist or NULL * */ GSList *gsb_string_get_categ_budget_struct_list_from_string ( const gchar *string ) { GSList *list_tmp = NULL; gchar **tab; gint i=0; if ( !string || !strlen (string)) return NULL; tab = g_strsplit ( string, "-", 0 ); while ( tab[i] ) { struct_categ_budget_sel *categ_budget_struct = NULL; gchar **sub_tab; gint j=0; sub_tab = g_strsplit (tab[i], "/", 0); while (sub_tab[j]) { if (!categ_budget_struct) { /* no categ_budget_struct created, so we are on the category */ categ_budget_struct = g_malloc0 (sizeof (struct_categ_budget_sel)); categ_budget_struct -> div_number = utils_str_atoi(sub_tab[j]); } else { /* categ_budget_struct is created, so we are on sub-category */ categ_budget_struct -> sub_div_numbers = g_slist_append (categ_budget_struct -> sub_div_numbers, GINT_TO_POINTER (utils_str_atoi (sub_tab[j]))); } j++; } g_strfreev (sub_tab); list_tmp = g_slist_append (list_tmp, categ_budget_struct); i++; } g_strfreev ( tab ); return list_tmp; }
/** * get the user frequency from the form's scheduled part * * \param * * \return a gint contains the user frequency * */ gint gsb_form_scheduler_get_frequency_user ( void ) { GtkWidget *entry; entry = gsb_form_scheduler_get_element_widget(SCHEDULED_FORM_FREQUENCY_USER_ENTRY); /* if no entry, go away... */ if (!entry || gsb_form_widget_check_empty (entry)) return 0; return utils_str_atoi (gtk_entry_get_text (GTK_ENTRY (entry))); }
/** * called when we begin a drag, * find what cell was under the cursor and change it * * \param tree_view * \param drag_context * \param null * * \return FALSE * */ gboolean gsb_form_config_drag_begin ( GtkWidget *tree_view, GdkDragContext *drag_context, gpointer null ) { gint x, y; GtkTreePath *path; GtkTreeViewColumn *tree_column; GdkWindow *drawable; GdkRectangle rectangle; GdkPixbuf *pixbuf_cursor; /* get the cell coord */ gdk_window_get_pointer ( gtk_tree_view_get_bin_window ( GTK_TREE_VIEW ( tree_view )), &x, &y, FALSE ); gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW ( tree_view ), x, y, &path, &tree_column, NULL, NULL ); if ( !path || !tree_column ) return FALSE; start_drag_column = g_list_index ( gtk_tree_view_get_columns ( GTK_TREE_VIEW ( tree_view )), tree_column ); start_drag_row = utils_str_atoi ( gtk_tree_path_to_string ( path )); /* draw the new cursor */ drawable = gtk_tree_view_get_bin_window (GTK_TREE_VIEW ( tree_view )); gtk_tree_view_get_cell_area ( GTK_TREE_VIEW ( tree_view ), path, tree_column, &rectangle ); pixbuf_cursor = gdk_pixbuf_get_from_drawable ( NULL, GDK_DRAWABLE (drawable), gdk_colormap_get_system (), rectangle.x, rectangle.y, 0, 0, rectangle.width, rectangle.height ); gtk_drag_source_set_icon_pixbuf ( tree_view, pixbuf_cursor ); g_object_unref (pixbuf_cursor); return FALSE; }
void initialize_debugging ( void ) { /* un int pour stocker le level de debug et une chaine qui contient sa version texte */ gint debug_variable=0; gchar *debug_level=""; gchar* tmpstr1; gchar* tmpstr2; if (getenv ("DEBUG_GRISBI")) { /* on choppe la variable d'environnement */ debug_variable=utils_str_atoi (getenv ("DEBUG_GRISBI")); /* on verifie que la variable est cohérente */ if (debug_variable > 0 && debug_variable <= MAX_DEBUG_LEVEL) { /* on renseigne le texte du level de debug */ debugging_grisbi = debug_variable; switch(debug_variable) { case DEBUG_LEVEL_ALERT: { debug_level="Alert"; break; } case DEBUG_LEVEL_IMPORTANT: { debug_level="Important"; break; } case DEBUG_LEVEL_NOTICE: { debug_level="Notice"; break; } case DEBUG_LEVEL_INFO: { debug_level="Info"; break; } case DEBUG_LEVEL_DEBUG: { debug_level="Debug"; break; } } /* on affiche un message de debug pour indiquer que le debug est actif */ tmpstr1 = g_strdup_printf(_("GRISBI %s Debug"),VERSION); tmpstr2 = g_strdup_printf(_("Debug enabled, level is '%s'"),debug_level); debug_message_string ( tmpstr1 , __FILE__, __LINE__, __PRETTY_FUNCTION__, tmpstr2, DEBUG_LEVEL_INFO, TRUE); g_free ( tmpstr1 ); g_free ( tmpstr2 ); } else { /* on affiche un message de debug pour indiquer que le debug est actif */ gchar* tmpstr = g_strdup_printf(_("GRISBI %s Debug"),VERSION); debug_message_string (tmpstr , __FILE__, __LINE__, __PRETTY_FUNCTION__, _("Wrong debug level, please check DEBUG_GRISBI environnement variable"), DEBUG_LEVEL_INFO, TRUE); g_free ( tmpstr ); } } }
/** * Build the new label for the reconciliation, given the old one. * The expected format is NAME+NUMBER, so this function returns * a newly allocated string whose format is NAME+(NUMBER+1). It * preserves leading '0' for the NUMBER string. * * If this is the first label building (first reconciliation for * this account), then the function returns a standard string * of the account name (lower case) + '-1'. * * \param reconcile_number * * \return the new string label */ gchar *gsb_reconcile_build_label ( int reconcile_number ) { gchar *tmp; gchar *old_label; gchar *new_label; gchar format[6] = "%s%0d"; int __reconcile_number; int __size; int __expand; /* old_label = NAME + NUMBER */ old_label = g_strdup ( gsb_data_reconcile_get_name ( reconcile_number ) ); /* return account NAME + '1' */ if ( !old_label ) { tmp = gsb_data_account_get_name ( gsb_gui_navigation_get_current_account () ); new_label = g_strconcat ( tmp, "-1", NULL ); tmp = new_label; while ( *tmp != '\0' ) { if ( *tmp == ' ' ) *tmp = '-'; else *tmp = tolower ( *tmp ); tmp ++; } return new_label; } /* we try to find some digits at the end of the name, * if found, get the biggest number until we find a non digit character */ __expand = 1; tmp = old_label + ( strlen ( old_label ) - 1 ) * sizeof ( gchar ); while ( isdigit ( *tmp ) && tmp >= old_label ) { if ( *tmp != '9' ) __expand = 0; tmp--; } tmp ++; /* step forward to the first digit */ __reconcile_number = utils_str_atoi ( tmp ) + 1; /* if stage 99 -> 100 for example, * then we have to allocate one more byte */ __size = strlen ( tmp ) + __expand; /* format string for the output (according NUMBER string length) */ format[3] = 48 + __size; /* close the NAME string */ *tmp = 0; /* NAME + NUMBER + '\0' */ __size += strlen ( old_label ) * sizeof ( gchar ) + 1; new_label = g_malloc0 ( __size * sizeof ( gchar ) ); sprintf ( new_label, format, old_label, __reconcile_number ); /* replace ' ' by '0' in number */ tmp = new_label + strlen ( old_label ) * sizeof ( gchar ); while ( *tmp == ' ' ) *tmp++ = '0'; g_free ( old_label ); return new_label; }
/** * called for each new element in the last xml config file * see the g_lib doc for the description of param * * \param context * \param text * \param text_len * \param user_data * \param error * * \return * */ static void gsb_file_config_get_xml_text_element ( GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error) { const gchar *element_name; gint i; element_name = g_markup_parse_context_get_element ( context ); if ( !strcmp ( element_name, "Width" )) { conf.main_width = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Height" )) { conf.main_height = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Modification_operations_rapprochees" )) { conf.r_modifiable = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Dernier_chemin_de_travail" )) { gsb_file_update_last_path (text); if ( !gsb_file_get_last_path () || !strlen (gsb_file_get_last_path ())) gsb_file_update_last_path (g_get_home_dir ()); return; } if ( !strcmp ( element_name, "Affichage_alerte_permission" )) { conf.alerte_permission = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Force_enregistrement" )) { conf.force_enregistrement = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Fonction_touche_entree" )) { conf.entree = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Affichage_messages_alertes" )) { conf.alerte_mini = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Utilise_fonte_des_listes" )) { conf.utilise_fonte_listes = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Fonte_des_listes" )) { conf.font_string = my_strdup (text); return; } if ( !strcmp ( element_name, "Navigateur_web" )) { if ( conf.browser_command ) g_free ( conf.browser_command ); conf.browser_command = my_strdelimit (text, "\\e", "&" ); return; } if ( !strcmp ( element_name, "Largeur_colonne_echeancier" )) { etat.largeur_colonne_echeancier = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Largeur_colonne_comptes_comptes" )) { etat.largeur_colonne_comptes_comptes = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Largeur_colonne_etats" )) { etat.largeur_colonne_etat = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Chargement_auto_dernier_fichier" )) { conf.dernier_fichier_auto = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Nom_dernier_fichier" )) { nom_fichier_comptes = my_strdup (text); return; } if ( !strcmp ( element_name, "Enregistrement_automatique" )) { conf.sauvegarde_auto = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Enregistrement_au_demarrage" )) { conf.sauvegarde_demarrage = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Nb_max_derniers_fichiers_ouverts" )) { conf.nb_max_derniers_fichiers_ouverts = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Compression_fichier" )) { conf.compress_file = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Compression_backup" )) { conf.compress_backup = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "fichier" )) { if (!tab_noms_derniers_fichiers_ouverts) tab_noms_derniers_fichiers_ouverts = g_malloc0 ( conf.nb_max_derniers_fichiers_ouverts * sizeof(gchar *) ); tab_noms_derniers_fichiers_ouverts[conf.nb_derniers_fichiers_ouverts] = my_strdup (text); conf.nb_derniers_fichiers_ouverts++; return; } if ( !strcmp ( element_name, "Delai_rappel_echeances" )) { nb_days_before_scheduled = utils_str_atoi (text); conf.execute_scheduled_of_month = FALSE; return; } if ( !strcmp ( element_name, "Affichage_formulaire" )) { conf.formulaire_toujours_affiche = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "Affichage_exercice_automatique" )) { conf.affichage_exercice_automatique = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "display_toolbar" )) { conf.display_toolbar = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "show_closed_accounts" )) { conf.show_closed_accounts = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "show_tip" )) { conf.show_tip = utils_str_atoi (text); return; } if ( !strcmp ( element_name, "last_tip" )) { conf.last_tip = utils_str_atoi (text); return; } for ( i = 0; messages[i].name; i++ ) { if ( !strcmp ( element_name, messages[i].name ) ) { messages[i].hidden = utils_str_atoi (text); } } }
/** * called when we end a drag, * find what cell was under the cursor and do the split between the 2 cells * * \param tree_view * \param drag_context * \param null * * \return FALSE * */ gboolean gsb_form_config_drag_end ( GtkWidget *tree_view, GdkDragContext *drag_context, gpointer null ) { gint x, y; GtkTreePath *path; GtkTreeViewColumn *tree_column; gint end_drag_row; gint end_drag_column; gint buffer; gint account_number; /* get the cell position */ gdk_window_get_pointer ( gtk_tree_view_get_bin_window ( GTK_TREE_VIEW ( tree_view )), &x, &y, FALSE ); gtk_tree_view_get_path_at_pos ( GTK_TREE_VIEW ( tree_view ), x, y, &path, &tree_column, NULL, NULL ); if ( !path || !tree_column ) return FALSE; end_drag_column = g_list_index ( gtk_tree_view_get_columns ( GTK_TREE_VIEW ( tree_view )), tree_column ); end_drag_row = utils_str_atoi ( gtk_tree_path_to_string ( path )); /* if we are on the same cell, go away */ if ( start_drag_row == end_drag_row && start_drag_column == end_drag_column ) return ( FALSE ); /* swap the cells in the tab */ account_number = gsb_account_get_combo_account_number ( accounts_combobox ); buffer = gsb_data_form_get_value ( account_number, start_drag_column, start_drag_row ); gsb_data_form_set_value ( account_number, start_drag_column, start_drag_row, gsb_data_form_get_value ( account_number, end_drag_column, end_drag_row )); gsb_data_form_set_value ( account_number, end_drag_column, end_drag_row, buffer ); /* fill the list */ gsb_form_config_fill_store (account_number); gsb_form_fill_from_account (account_number); gsb_file_set_modified ( TRUE ); return (FALSE); }