/**
 * Callback called when the payment method name is changed in the
 * GtkEntry associated.  It updates the GtkTreeView list of payment
 * methods as well as it updates transaction form.
 *
 * \param entry the entry changed (payment method name)
 * \param tree_view
 *
 * \return FALSE
 */
gboolean gsb_payment_method_config_name_changed ( GtkWidget *entry,
						  GtkWidget *tree_view )
{
    GtkTreeSelection *selection;
    GtkTreeIter iter;
    gboolean good;

    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
    good = gtk_tree_selection_get_selected (selection, NULL, &iter);

    if (good)
    {
	GtkTreeModel *model;
	gint payment_number;

	model = gtk_tree_view_get_model ( GTK_TREE_VIEW (tree_view));
	gtk_tree_model_get ( GTK_TREE_MODEL(model), &iter,
			     PAYMENT_METHODS_NUMBER_COLUMN, &payment_number,
			     -1 );

	if (payment_number)
	{
	    /* update the tree view */
	    gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
				PAYMENT_METHODS_NAME_COLUMN, gsb_data_payment_get_name (payment_number),
				-1);
	    gsb_reconcile_sort_config_fill ();


	    if ( gsb_data_form_check_for_value ( TRANSACTION_FORM_TYPE ))
	    {
		GtkWidget *widget;
		gint account_number;

		account_number = gsb_form_get_account_number ();
		widget = gsb_form_widget_get_widget (TRANSACTION_FORM_TYPE);

		if (widget)
		{
		    gsb_payment_method_create_combo_list ( widget,
							   GSB_PAYMENT_DEBIT,
							   account_number, 0, FALSE );

		    if (GTK_WIDGET_VISIBLE (widget))
		    {
			gsb_payment_method_set_combobox_history ( widget,
								  gsb_data_account_get_default_debit (account_number), TRUE );
		    }
		    else
		    {
			gtk_widget_hide ( gsb_form_widget_get_widget (TRANSACTION_FORM_CHEQUE));
		    }
		}
	    }
	    /* update the transactions list */
	    transaction_list_update_element (ELEMENT_PAYMENT_TYPE);
	}
    }
    return FALSE;
}
/**
 * called when an entry lose the focus in the scheduled part
 *
 * \param entry
 * \param ev
 * \param ptr_origin a pointer gint wich is the number of the element
 *
 * \return FALSE
 * */
gboolean gsb_form_scheduler_entry_lose_focus ( GtkWidget *entry,
                        GdkEventFocus *ev,
                        gint *ptr_origin )
{
    gchar *string;
    gint element_number;
    gint account_number;

    /* remove the selection */

    gtk_editable_select_region ( GTK_EDITABLE ( entry ), 0, 0 );
    element_number = GPOINTER_TO_INT ( ptr_origin );
    account_number = gsb_form_get_account_number ();

    /* string will be filled only if the field is empty */
    string = NULL;

    switch ( element_number )
    {
	case  SCHEDULED_FORM_LIMIT_DATE:
	    if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
        {
            gsb_form_widget_set_empty ( entry, TRUE );
            string = _("Limit date");
        }
	    break;

	case  SCHEDULED_FORM_FREQUENCY_USER_ENTRY:
	    if ( !strlen ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) ) )
            string = _("Own frequency");
	    break;

	default :
	    break;
    }

    /* if string is not NULL, the entry is empty so set the empty field to TRUE */

    if ( string )
    {
        gtk_entry_set_text ( GTK_ENTRY ( entry ), string );
        gsb_form_widget_set_empty ( entry, TRUE );
    }
    return FALSE;
}
/**
 * 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;
}
Beispiel #4
0
/**
 * check if the given value exists in the form of the CURRENT account
 *
 * \param value
 *
 * \return FALSE or TRUE
 * */
gboolean gsb_data_form_check_for_value ( gint value )
{
    return gsb_data_form_look_for_value ( gsb_form_get_account_number (),
					  value,
					  NULL, NULL );
}