/** * create the config widget for the reconcile * to modify/delete a reconcile * * \param * * \return a GtkWidget containing the config widget */ GtkWidget *gsb_reconcile_config_create ( void ) { GtkWidget *scrolled_window; GtkWidget *vbox_pref; GtkWidget *paddinggrid; GtkTreeViewColumn *column; GtkCellRenderer *cell; GtkTreeStore *reconcile_model; GtkTreeSelection *reconcile_selection; GtkWidget *label; gint i; gfloat alignment[] = { COLUMN_LEFT, COLUMN_CENTER, COLUMN_CENTER, COLUMN_RIGHT, COLUMN_RIGHT }; gchar *titles[] = { _("Account"), _("Init date"), _("Final date"), _("Init balance"), _("Final balance") }; GtkWidget *table_selection; GtkWidget *button; gint width_entry = 80; GrisbiWinEtat *w_etat; w_etat = (GrisbiWinEtat *) grisbi_win_get_w_etat (); vbox_pref = new_vbox_with_title_and_icon ( _("Reconciliation"), "gsb-reconciliation-32.png" ); gsb_automem_radiobutton3_new_with_title ( vbox_pref, _("Select the end date of reconciliation: "), _("Start Date + one month"), _("Today's date"), NULL, &w_etat->reconcile_end_date, G_CALLBACK ( gsb_reconcile_config_end_date_changed ), NULL, GTK_ORIENTATION_HORIZONTAL ); paddinggrid = utils_prefs_paddinggrid_new_with_title (vbox_pref, _("List of reconciliations")); gtk_widget_set_vexpand (paddinggrid, TRUE); /* set the list */ scrolled_window = utils_prefs_scrolled_window_new ( NULL, GTK_SHADOW_IN, SW_COEFF_UTIL_PG, 200); gtk_grid_attach (GTK_GRID (paddinggrid), scrolled_window, 0, 0, 3, 3); /* need to create first the table to set it in the arg of the changed signal of selection */ table_selection = gtk_grid_new (); gtk_grid_set_row_spacing (GTK_GRID (table_selection), 6); gtk_grid_set_column_spacing (GTK_GRID (table_selection), 6); /* create the model */ reconcile_model = gtk_tree_store_new ( NUM_RECONCILIATION_COLUMNS, G_TYPE_STRING, /* Name account or reconciliation */ G_TYPE_STRING, /* init date */ G_TYPE_STRING, /* final date */ G_TYPE_STRING, /* init balance */ G_TYPE_STRING, /* final balance */ G_TYPE_INT, /* Account number */ G_TYPE_INT, /* Bold or regular text */ G_TYPE_INT, /* reconciliation number */ GDK_TYPE_RGBA); reconcile_treeview = gtk_tree_view_new_with_model ( GTK_TREE_MODEL (reconcile_model) ); gtk_widget_set_name (reconcile_treeview, "tree_view"); g_object_unref (G_OBJECT(reconcile_model)); gtk_tree_selection_set_mode ( gtk_tree_view_get_selection (GTK_TREE_VIEW (reconcile_treeview)), GTK_SELECTION_SINGLE ); gtk_container_add ( GTK_CONTAINER (scrolled_window), reconcile_treeview ); reconcile_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (reconcile_treeview)); g_signal_connect (reconcile_selection, "changed", G_CALLBACK (gsb_reconcile_config_select), table_selection); /* Name */ for (i=RECONCILIATION_NAME_COLUMN ; i<RECONCILIATION_ACCOUNT_COLUMN ; i++) { cell = gtk_cell_renderer_text_new (); g_object_set ( G_OBJECT (cell), "xalign", alignment[i], NULL ); column = gtk_tree_view_column_new (); gtk_tree_view_column_set_sizing ( column, GTK_TREE_VIEW_COLUMN_AUTOSIZE ); gtk_tree_view_column_set_alignment ( column, alignment[i] ); gtk_tree_view_column_pack_end ( column, cell, TRUE ); gtk_tree_view_column_set_title ( column, titles[i] ); gtk_tree_view_column_set_attributes (column, cell, "text", i, "weight", RECONCILIATION_WEIGHT_COLUMN, "cell-background-rgba", RECONCILIATION_BACKGROUND_COLOR, NULL); gtk_tree_view_column_set_expand ( column, TRUE ); gtk_tree_view_column_set_resizable ( column, TRUE ); gtk_tree_view_append_column ( GTK_TREE_VIEW(reconcile_treeview), column); } /* Various remaining settings */ gsb_reconcile_config_fill(); /* Set the reconcile_sort */ button = gsb_automem_checkbutton_new (_("Sort by descending date the reconciliations"), &w_etat->reconcile_sort, G_CALLBACK (gsb_reconcile_config_sort_reconcile), NULL); gtk_widget_set_margin_top (button, MARGIN_TOP); gtk_grid_attach (GTK_GRID (paddinggrid), button, 0, 3, 1, 1); button = gtk_button_new_with_label (_("Collapse row")); gtk_widget_set_sensitive (button, FALSE); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gsb_reconcile_button_collapse_row_clicked), reconcile_selection); gtk_grid_attach (GTK_GRID (paddinggrid), button, 1, 3, 1, 1); /* set signal here because data is button */ g_signal_connect (reconcile_treeview, "row-expanded", G_CALLBACK (gsb_reconcile_treeview_row_expanded), button); g_signal_connect (reconcile_treeview, "row-collapsed", G_CALLBACK (gsb_reconcile_treeview_row_collapsed), button); /* set the modifying part under the list */ paddinggrid = utils_prefs_paddinggrid_new_with_title (vbox_pref,_("Selected reconcile") ); /* for that we make a table 2x3 but with the names 4x3, * the table has been set before to accept as arg on the changed selection */ gtk_grid_attach (GTK_GRID (paddinggrid), table_selection, 0, 0, 1, 1); /* set the name */ label = gtk_label_new ( _("Reconciliation reference: ") ); utils_labels_set_alignment ( GTK_LABEL (label), 0, 0.5); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_grid_attach (GTK_GRID (table_selection), label, 0, 0, 1, 1); reconcile_name_entry = gsb_autofunc_entry_new ( NULL, G_CALLBACK (gsb_reconcile_config_update_line), reconcile_treeview, G_CALLBACK (gsb_data_reconcile_set_name), 0 ); gtk_widget_set_size_request ( reconcile_name_entry, width_entry, -1 ); gtk_grid_attach (GTK_GRID (table_selection), reconcile_name_entry, 1, 0, 1, 1); /* set the initial date */ label = gtk_label_new ( _("Initial date: ") ); utils_labels_set_alignment ( GTK_LABEL (label), 0, 0.5); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_grid_attach (GTK_GRID (table_selection), label, 0, 1, 1, 1); reconcile_init_date_entry = gsb_autofunc_date_new ( NULL, G_CALLBACK (gsb_reconcile_config_update_line), reconcile_treeview, G_CALLBACK (gsb_data_reconcile_set_init_date), 0 ); gtk_widget_set_size_request ( reconcile_init_date_entry, width_entry, -1 ); gtk_grid_attach (GTK_GRID (table_selection), reconcile_init_date_entry, 1, 1, 1, 1); /* set the final date */ label = gtk_label_new ( _("Final date: ") ); utils_labels_set_alignment ( GTK_LABEL (label), 0, 0.5); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_grid_attach (GTK_GRID (table_selection), label, 0, 2, 1, 1); reconcile_final_date_entry = gsb_autofunc_date_new ( NULL, G_CALLBACK (gsb_reconcile_config_update_line), reconcile_treeview, G_CALLBACK (gsb_data_reconcile_set_final_date), 0 ); gtk_widget_set_size_request ( reconcile_final_date_entry, width_entry, -1 ); gtk_grid_attach (GTK_GRID (table_selection), reconcile_final_date_entry, 1, 2, 1, 1); /* set the delete button */ delete_reconcile_button = gtk_button_new_with_label (_("Delete the reconcile")); gtk_button_set_relief ( GTK_BUTTON (delete_reconcile_button), GTK_RELIEF_NORMAL); g_signal_connect ( G_OBJECT (delete_reconcile_button), "clicked", G_CALLBACK (gsb_reconcile_config_delete), reconcile_treeview ); gtk_grid_attach (GTK_GRID (table_selection), delete_reconcile_button, 2, 0, 2, 1); /* set the initial balance */ label = gtk_label_new ( _("Initial balance: ") ); utils_labels_set_alignment ( GTK_LABEL (label), 0, 0.5); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_grid_attach (GTK_GRID (table_selection), label, 2, 1, 1, 1); reconcile_init_balance_entry = gsb_autofunc_real_new ( null_real, G_CALLBACK (gsb_reconcile_config_update_line), reconcile_treeview, G_CALLBACK (gsb_data_reconcile_set_init_balance), 0 ); gtk_widget_set_size_request ( reconcile_init_balance_entry, width_entry, -1 ); gtk_grid_attach (GTK_GRID (table_selection), reconcile_init_balance_entry, 3, 1, 1, 1); /* set the final balance */ label = gtk_label_new ( _("Final balance: ") ); utils_labels_set_alignment ( GTK_LABEL (label), 0, 0.5); gtk_label_set_justify ( GTK_LABEL (label), GTK_JUSTIFY_LEFT ); gtk_grid_attach (GTK_GRID (table_selection), label, 2, 2, 1, 1); reconcile_final_balance_entry = gsb_autofunc_real_new ( null_real, G_CALLBACK (gsb_reconcile_config_update_line), reconcile_treeview, G_CALLBACK (gsb_data_reconcile_set_final_balance), 0 ); gtk_widget_set_size_request ( reconcile_final_balance_entry, width_entry, -1 ); gtk_grid_attach (GTK_GRID (table_selection), reconcile_final_balance_entry, 3, 2, 1, 1); /* at the beginning, the table is unsensitive */ gtk_widget_set_sensitive ( table_selection, FALSE ); /* set the button to find non-associated transactions */ button = gtk_button_new_with_label ( _("Find all marked transactions not associated with a reconciliation")); gtk_button_set_relief ( GTK_BUTTON (button), GTK_RELIEF_NORMAL ); utils_widget_set_padding (button, 0, MARGIN_TOP); g_signal_connect ( G_OBJECT (button), "clicked", G_CALLBACK (gsb_reconcile_config_find_alone_transactions), NULL ); gtk_grid_attach (GTK_GRID (paddinggrid), button, 0, 1, 1, 1); gtk_widget_show_all (vbox_pref); utils_set_tree_store_background_color (reconcile_treeview, RECONCILIATION_BACKGROUND_COLOR); if ( !gsb_data_account_get_accounts_amount () ) { gtk_widget_set_sensitive ( vbox_pref, FALSE ); } return vbox_pref; }
/** * called when the user click on the button 'create the new reconciliation' * check the entries and create the corresponding reconciliation * * \param button * \param label a message label, hidden at the beginning, that will say ok the reconciliation is created * or if there is a problem... * * \return FALSE * */ static gboolean gsb_assistant_reconcile_config_page_add_new_reconcile ( GtkWidget *button, GtkWidget *label ) { gint reconcile_number; gchar *string; /* first, we check the date are valid */ if ( !gsb_date_check_entry ( reconcile_init_date_entry ) ) { string = make_red ( _("The initial date is not valid, please check it.") ); gtk_label_set_markup ( GTK_LABEL ( label) , string ); gtk_widget_grab_focus (reconcile_init_date_entry); g_free ( string ); return FALSE; } if ( !gsb_date_check_entry ( reconcile_final_date_entry ) ) { string = make_red ( _("The final date is not valid, please check it.") ); gtk_label_set_markup ( GTK_LABEL ( label) , string ); gtk_widget_grab_focus ( reconcile_final_date_entry ); g_free ( string ); return FALSE; } /* check there is a name */ if ( !strlen (gtk_entry_get_text ( GTK_ENTRY ( reconcile_name_entry ) ) ) ) { string = make_red ( _("Please give a name to the new reconciliation.") ); gtk_label_set_markup ( GTK_LABEL ( label) , string ); gtk_widget_grab_focus ( reconcile_name_entry ); g_free ( string ); return FALSE; } /* check if already exist the name */ if ( gsb_data_reconcile_get_number_by_name ( gtk_entry_get_text (GTK_ENTRY (reconcile_name_entry) ) ) ) { string = make_red ( _("That name already exists, please find another one.") ); gtk_label_set_markup ( GTK_LABEL ( label) , string ); gtk_widget_grab_focus ( reconcile_name_entry ); g_free ( string ); return FALSE; } /* ok, now we can create the reconcile */ reconcile_number = gsb_data_reconcile_new ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_name_entry ) ) ); if ( !reconcile_number ) if (gsb_data_reconcile_get_number_by_name ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_name_entry ) ) ) ) { string = make_red ( _("Cannot allocate memory : Bad things will happen soon.") ); gtk_label_set_markup ( GTK_LABEL ( label) , string ); gtk_widget_grab_focus ( reconcile_name_entry ); g_free ( string ); return FALSE; } gsb_data_reconcile_set_init_date ( reconcile_number, gsb_calendar_entry_get_date ( reconcile_init_date_entry ) ); gsb_data_reconcile_set_final_date ( reconcile_number, gsb_calendar_entry_get_date ( reconcile_final_date_entry ) ); gsb_data_reconcile_set_init_balance ( reconcile_number, utils_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY (reconcile_init_balance_entry ) ) ) ); gsb_data_reconcile_set_final_balance ( reconcile_number, utils_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY ( reconcile_final_balance_entry ) ) ) ); gsb_data_reconcile_set_account ( reconcile_number, gsb_account_get_combo_account_number ( reconcile_account_button ) ); /* erase the entries but not the account wich can be used again */ gtk_entry_set_text ( GTK_ENTRY (reconcile_name_entry), "" ); gtk_entry_set_text ( GTK_ENTRY (reconcile_init_date_entry), "" ); gtk_entry_set_text ( GTK_ENTRY (reconcile_final_date_entry), "" ); gtk_entry_set_text ( GTK_ENTRY (reconcile_init_balance_entry), "" ); gtk_entry_set_text ( GTK_ENTRY (reconcile_final_balance_entry), "" ); string = make_blue ( g_strdup_printf ( _("Reconciliation %s successfully appended!"), gsb_data_reconcile_get_name ( reconcile_number ) ) ); gtk_label_set_markup ( GTK_LABEL ( label ), string ); g_free ( string ); /* update the list of reconcile in the configuration list */ gsb_reconcile_config_fill ( ); gtk_widget_grab_focus ( reconcile_name_entry ); return FALSE; }
/** * * * \param * \param * * \return * */ static void gsb_reconcile_config_sort_reconcile (GtkToggleButton *togglebutton, gpointer user_data) { gsb_reconcile_config_fill (); }