Exemplo n.º 1
0
/**
 * called once the window is realized,
 * fill the form and size the columns according to the configuration
 *
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_form_config_realized ( GtkWidget *tree_view,
				    gpointer null )
{
    gint column;
    gint account_number;
    gint width;

    if ( !assert_account_loaded())
      return FALSE;

    account_number = gsb_account_get_combo_account_number ( accounts_combobox );
    width = tree_view -> allocation.width;

    /* fill and update the form list and buttons */
    gsb_form_config_update_form_config(account_number);

    for ( column=0 ; column < gsb_data_form_get_nb_columns (account_number) ; column++ )
    {
	gtk_tree_view_column_set_fixed_width ( gtk_tree_view_get_column ( GTK_TREE_VIEW ( tree_view ),
									  column ),
					       gsb_data_form_get_width_column ( account_number,
										column ) * width / 100 );
    }

    gdk_window_set_cursor ( tree_view -> window,
			    gdk_cursor_new ( GDK_FLEUR ) );

    return FALSE;
}
Exemplo n.º 2
0
/**
 * called when the user click on "add column"
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_form_config_add_column ( void )
{
    gint account_number;
    gint nb_columns;
    gint new_size;

    account_number = gsb_account_get_combo_account_number ( accounts_combobox );
    nb_columns = gsb_data_form_get_nb_columns (account_number);

    if ( nb_columns == MAX_WIDTH )
	return FALSE;

    /* split by 2 the size of the current last column to add the new column */
    new_size = gsb_data_form_get_width_column ( account_number,
						nb_columns - 1) / 2;
    gsb_data_form_set_width_column ( account_number,
				     nb_columns - 1,
				     new_size );
    gsb_data_form_set_width_column ( account_number,
				     nb_columns,
				     new_size );
    gsb_data_form_set_nb_columns ( account_number,
				   nb_columns + 1 );

    /* show the result */
    gsb_form_config_realized ( form_config_tree_view, NULL );
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Exemplo n.º 3
0
/**
 * called if we change the account in the option menu of the accounts
 *
 * \param combobox the combobox of the list of accounts
 *
 * \return FALSE
 * */
gboolean gsb_form_config_change_account_choice ( GtkWidget *combobox,
						 gpointer null )
{
    gint account_number;

    account_number = gsb_account_get_combo_account_number (combobox);
    gsb_form_config_update_form_config ( account_number );

    return FALSE;
}
Exemplo n.º 4
0
/**
 * get the account number from the scheduled button and return it
 *
 * \param
 *
 * \return the account number or -2 if problem
 * */
gint gsb_form_scheduler_get_account ( void )
{
    gint account_number;
    GtkWidget *button;

    button = gsb_form_scheduler_get_element_widget(SCHEDULED_FORM_ACCOUNT);
    /* if no account button, go away... */
    if (!button)
	return -2;

    account_number = gsb_account_get_combo_account_number (button);

    if (account_number == -1)
	return -2;
    return account_number;
}
Exemplo n.º 5
0
/**
 * called when the user click on "add line"
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_form_config_add_line ( void )
{
    gint account_number;

    account_number = gsb_account_get_combo_account_number ( accounts_combobox );

    if ( gsb_data_form_get_nb_rows (account_number) == MAX_HEIGHT )
	return FALSE;

    gsb_data_form_set_nb_rows ( account_number,
				gsb_data_form_get_nb_rows (account_number) + 1 );

    /* update the form */
    gsb_form_config_fill_store (account_number);
    gsb_form_create_widgets ();

    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Exemplo n.º 6
0
/**
 * called when change the size of the columns,
 * save the percent and change the size of the form according the new size
 *
 * \param tree_view
 * \param allocation
 *
 * \return FALSE
 * */
gboolean gsb_form_config_change_column_size ( GtkWidget *tree_view,
					      GtkAllocation *allocation,
					      gpointer null )
{
    gint column;
    gint account_number;
    gint i;

    if ( !GTK_WIDGET_REALIZED (tree_view))
	return FALSE;

    account_number = gsb_account_get_combo_account_number ( accounts_combobox );

    for (i=0 ; i<gsb_data_account_get_accounts_amount () ; i++)
    {
	    for ( column=0 ; column < gsb_data_form_get_nb_columns (i) ; column++ )
	    {
		gint size_column;

		size_column = gtk_tree_view_column_get_width ( gtk_tree_view_get_column ( GTK_TREE_VIEW ( tree_view ),
											  column ));
		gsb_data_form_set_width_column ( i,
						 column,
						 size_column * 100 / allocation -> width );
	    }
    }

    gsb_file_set_modified ( TRUE );

    /* update the form if needed */
	saved_allocation_size = 0;
	gsb_form_allocate_size ( NULL, &(form_transaction_part -> allocation), NULL );
    gsb_form_create_widgets ();

    return FALSE;
}
Exemplo n.º 7
0
/**
 * 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;
}
Exemplo n.º 8
0
/**
 * called when the user click on "remove line"
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_form_config_remove_line ( void )
{
    gint column;
    gint account_number;
    gint nb_rows;
    gint nb_columns;

    account_number = gsb_account_get_combo_account_number ( accounts_combobox );
    nb_rows = gsb_data_form_get_nb_rows (account_number);

    if ( nb_rows == 1 )
	return FALSE;

    /* check if it's possible */
    if ( !gsb_form_config_check_for_removing ( account_number,
					       1 ))
	return FALSE;

    nb_columns = gsb_data_form_get_nb_columns (account_number);

    /* remove the row */
    nb_rows--;
    gsb_data_form_set_nb_rows ( account_number,
				nb_rows );

    /* move automatickly the values inside the new tinier form */
    for ( column=0 ; column< nb_columns ; column++ )
    {
	if ( gsb_data_form_get_value ( account_number,
				       column,
				       nb_rows))
	{
	    /* there is something inside the part wich will be removed, so look for the first
	     * place possible to move it */

	    gint tmp_row, tmp_column;

	    for ( tmp_row=0 ; tmp_row < nb_rows ; tmp_row++ )
		for ( tmp_column=0 ; tmp_column < nb_columns ; tmp_column++ )
		    if ( !gsb_data_form_get_value ( account_number,
						    tmp_column,
						    tmp_row ))
		    {
			gsb_data_form_set_value ( account_number,
						  tmp_column,
						  tmp_row,
						  gsb_data_form_get_value ( account_number,
									    column,
									    nb_rows));
			gsb_data_form_set_value ( account_number,
						  column,
						  nb_rows,
						  0 );
			tmp_row = nb_rows;
			tmp_column = nb_columns;
		    }
	}
    }

    /* update the form */
    gsb_form_config_fill_store (account_number);
    gsb_form_create_widgets ();

    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Exemplo n.º 9
0
/**
 * 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;
}
Exemplo n.º 10
0
/**
 * 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);
}
Exemplo n.º 11
0
/**
 * called when the user click on "remove column"
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_form_config_remove_column ( void )
{
    gint row;
    gint account_number;
    gint nb_columns;

    account_number = gsb_account_get_combo_account_number ( accounts_combobox );
    nb_columns = gsb_data_form_get_nb_columns (account_number);

    if ( nb_columns == 1 )
	return FALSE;

    /* check if it's possible */
    if ( !gsb_form_config_check_for_removing ( account_number,
					       0 ))
	return FALSE;

    /* erase the last column */
    nb_columns--;
    gsb_data_form_set_nb_columns ( account_number,
				   nb_columns );

    /* move the values in the last column to another place */
    for ( row=0 ; row< gsb_data_form_get_nb_rows (account_number) ; row++ )
    {
	if ( gsb_data_form_get_value (account_number,
				      nb_columns,
				      row ))
	{
	    /* found something, look for the first place to set it */

	    gint tmp_row, tmp_column;

	    for ( tmp_row=0 ; tmp_row< gsb_data_form_get_nb_rows (account_number) ; tmp_row++ )
		for ( tmp_column=0 ; tmp_column<nb_columns ; tmp_column++ )
		    if ( !gsb_data_form_get_value ( account_number,
						    tmp_column,
						    tmp_row ))
		    {
			gsb_data_form_set_value ( account_number,
						  tmp_column,
						  tmp_row,
						  gsb_data_form_get_value ( account_number,
									    nb_columns,
									    row ));
			gsb_data_form_set_value ( account_number,
						  nb_columns,
						  row,
						  0 );
			tmp_row = gsb_data_form_get_nb_rows (account_number);
			tmp_column = nb_columns;
		    }
	}
    }

    /* change the size of the last column */
    gsb_data_form_set_width_column ( account_number,
				     nb_columns - 1,
				     gsb_data_form_get_width_column ( account_number,
								      nb_columns )
				     +
				     gsb_data_form_get_width_column ( account_number,
								      nb_columns ));
    gsb_data_form_set_width_column ( account_number,
				     nb_columns,
				     0 );

    /* fill the list */
    gsb_form_config_realized ( form_config_tree_view, NULL );
    gsb_file_set_modified ( TRUE );
    return FALSE;
}