Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
/**
 * callback called when changing the account from the form's button
 * re-fill the form but keep the values
 *
 * \param button
 * \param null
 *
 * \return FALSE
 * */
gboolean gsb_form_scheduler_change_account ( GtkWidget *button,
                        gpointer null )
{
    gint save_transaction;
    gint save_execute;
    GSList *content_list;
    gboolean is_split = FALSE;
    GtkWidget *category_entry;
    const gchar *tmp_str;
    gint new_account_number;

    devel_debug (NULL);

    new_account_number = gsb_form_get_account_number ();

    /* need to check first if split (see later) */
    category_entry = gsb_form_widget_get_widget (TRANSACTION_FORM_CATEGORY);
    if ( category_entry )
    {
        tmp_str = gtk_combofix_get_text ( GTK_COMBOFIX ( category_entry) );
        if ( gsb_form_widget_check_empty (GTK_COMBOFIX (category_entry) -> entry)
         &&
         tmp_str
         && strlen ( tmp_str ) > 0
         &&
         !strcmp ( tmp_str, _("Split of transaction") ) )
            /* ok it's a split */
            is_split = TRUE;
    }

    /* problem here : when change account, the form can be changed, with new or less widgets
     * so we fill again de form
     * but il the user fill the form and want to change after the account, it's annoying because
     * filling again the form will lose all the data
     * so first save the data and after filling the form, set back the data
     * may still a problem : if for example we set a note, go to an account without notes, and
     * go back to an account with a note, the first content of the note will be lost but it should
     * be very rare to do that and i think very difficult to code something to keep that... */
    save_transaction = GPOINTER_TO_INT (g_object_get_data ( G_OBJECT ( gsb_form_get_form_widget () ),
							    "transaction_number_in_form" ));
    save_execute = GPOINTER_TO_INT (g_object_get_data ( G_OBJECT (gsb_form_get_form_widget ()),
							"execute_scheduled"));
    content_list = gsb_form_scheduler_get_content_list ();

    gsb_form_fill_from_account (new_account_number);

    /* a problem now, fill_from_account will clean the form,
     * and make unsensitive some part of the form (method of payment...)
     * and make sensitive some other part wich could be unsensitive (for split for example)
     * so we call gsb_form_set_sensitive, but 2 args, split or child.
     * cannot be a child because child cannot access to the account button, so just to check
     * if it's a split (done before)
     */
    gsb_form_change_sensitive_buttons (TRUE);
    gsb_form_set_sensitive (is_split, FALSE);

    gsb_form_scheduler_set_content_list (content_list);
    gsb_form_scheduler_free_content_list (content_list);

    g_object_set_data ( G_OBJECT ( gsb_form_get_form_widget () ),
			"transaction_number_in_form",
			GINT_TO_POINTER (save_transaction));
    g_object_set_data ( G_OBJECT ( gsb_form_get_form_widget () ),
			"execute_scheduled",
			GINT_TO_POINTER (save_execute));

    last_account_number = new_account_number;
    return FALSE;
}
Ejemplo n.º 3
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);
}