/**
 * called by a click on the "remove link" in the configuration
 * remove the link
 * there is no warning message, perhaps sould be better, but i don't
 * think re-creating the deleted link is too difficult...
 *
 * \param tree_view the tree view of the links list
 *
 * \return FALSE
 * */
gboolean gsb_currency_link_config_remove_link ( GtkWidget *tree_view )
{
    GtkTreeModel *model;
    GtkTreeIter iter;

    if ( gtk_tree_selection_get_selected ( gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
					   &model,
					   &iter ))
    {
    GtkWidget *label;
	gint link_number;

	gtk_tree_model_get ( GTK_TREE_MODEL (model),
			     &iter,
			     LINK_NUMBER_COLUMN, &link_number,
			     -1 );
	gtk_list_store_remove ( GTK_LIST_STORE (model),
				&iter );
	gsb_data_currency_link_remove (link_number);
	gtk_widget_set_sensitive ( GTK_WIDGET ( g_object_get_data ( G_OBJECT (model),
								    "hbox_line")),
				   FALSE );

    /* hide the warning label */
    label = g_object_get_data (G_OBJECT (model),
			       "warning_label");
    if ( GTK_WIDGET_VISIBLE ( label ) )
        gtk_widget_hide (label);

        gsb_file_set_modified ( TRUE );
    }
    return FALSE;
}
/**
 * Callback called when toggle the default payment method
 *
 * \param cell
 * \param path_str
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_payment_method_config_toggled ( GtkCellRendererToggle *cell,
					     gchar *path_str,
					     GtkTreeView *tree_view )
{
    GtkTreePath *path = gtk_tree_path_new_from_string (path_str);
    GtkTreeIter iter, parent, child;
    gboolean toggle_item;
    gint payment_number;
    GtkTreeModel *model;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));

    /* get toggled iter */
    gtk_tree_model_get_iter (GTK_TREE_MODEL(model), &iter, path);
    gtk_tree_model_get (GTK_TREE_MODEL(model), &iter,
			PAYMENT_METHODS_DEFAULT_COLUMN, &toggle_item,
			PAYMENT_METHODS_NUMBER_COLUMN, &payment_number,
			-1);

    if (gsb_data_payment_get_sign (payment_number) == GSB_PAYMENT_DEBIT)
	gsb_data_account_set_default_debit ( gsb_data_payment_get_account_number (payment_number),
					     payment_number );
    else
    {
	if (gsb_data_payment_get_sign (payment_number) == GSB_PAYMENT_CREDIT)
	    gsb_data_account_set_default_credit (gsb_data_payment_get_account_number (payment_number),
						 payment_number );
    }

    if (! toggle_item)
    {
	gtk_tree_model_iter_parent ( GTK_TREE_MODEL(model), &parent, &iter );

	if ( gtk_tree_model_iter_children (GTK_TREE_MODEL(model), &child, &parent) )
	{
	    do
	    {
		gtk_tree_store_set (GTK_TREE_STORE (model), &child,
				    PAYMENT_METHODS_DEFAULT_COLUMN, FALSE,
				    -1);
	    }
	    while ( gtk_tree_model_iter_next (GTK_TREE_MODEL(model), &child) );
	}
	else
	{
	    /* Should not happen theorically */
	    dialogue_error_brain_damage () ;
	}

	/* set new value */
	gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
			    PAYMENT_METHODS_DEFAULT_COLUMN, 1,
			    -1);
    }

    /* clean up */
    gtk_tree_path_free (path);
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
/**
 * Callback called when toggle the check button to split the neutral method of payments
 *
 * \param cell
 * \param path_str
 * \param tree_view
 *
 * \return FALSE
 */
gboolean gsb_reconcile_sort_config_neutral_toggled ( GtkCellRendererToggle *cell,
						     gchar *path_str,
						     GtkWidget *tree_view )
{
    GtkTreePath * treepath;
    GtkTreeIter iter;
    gboolean toggle;
    gint account_number;
    GSList *sorted_list_copy;
    GSList *tmp_list;
    GtkTreeModel *model;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));

    /* invert the toggle */
    treepath = gtk_tree_path_new_from_string ( path_str );
    gtk_tree_model_get_iter ( GTK_TREE_MODEL (model),
			      &iter, treepath );

    gtk_tree_model_get (GTK_TREE_MODEL(model), &iter,
			RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, &toggle,
			RECONCILIATION_SORT_ACCOUNT_COLUMN, &account_number,
			-1);
    toggle ^= 1;
    gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
			RECONCILIATION_SORT_SPLIT_NEUTRAL_COLUMN, toggle,
			-1);

    /* and save it */
    gsb_data_account_set_split_neutral_payment ( account_number,
						 toggle );

    /* need to copy the sorted_list to avoid an infinite loop when add a negative payment neutral later */
    sorted_list_copy = g_slist_copy (gsb_data_account_get_sort_list (account_number));
    tmp_list = sorted_list_copy;

    while (tmp_list)
    {
	gint payment_number;

	payment_number = GPOINTER_TO_INT (tmp_list -> data);

	/* payment_number can be negative, so do for it abs */
	if ( gsb_data_payment_get_sign (abs (payment_number)) == GSB_PAYMENT_NEUTRAL )
	{
	    if (toggle)
		gsb_data_account_sort_list_add ( account_number,
						 -payment_number );
	    else
		if (payment_number < 0 )
		    gsb_data_account_sort_list_remove ( account_number,
							payment_number );
	}
	tmp_list = tmp_list -> next;
    }
    g_slist_free (sorted_list_copy);
    gsb_reconcile_sort_config_fill ();
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Example #4
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;
}
/**
 * called by a click on the "add link" in the configuration
 * add a new link and set the selection on it
 *
 * \param tree_view the tree view of the links list
 *
 * \return FALSE
 * */
gboolean gsb_currency_link_config_add_link ( GtkWidget *tree_view )
{
    gint link_number;
    GtkTreeModel *model;
    GtkTreeIter iter;

    model = gtk_tree_view_get_model ( GTK_TREE_VIEW (tree_view));

    link_number = gsb_data_currency_link_new (0);

    /* we are sure that at least there is a currency with the number 1,
     * so we set the 2 currencies on the number 1, even if it makes that link
     * invalid, but it's not a problem because i think the user will change
     * it quickly... */
    gsb_data_currency_link_set_first_currency ( link_number,
						1 );
    gsb_data_currency_link_set_second_currency ( link_number,
						 1 );
    gsb_currency_link_config_append_line ( model,
					   link_number,
					   &iter );
    gtk_tree_selection_select_iter ( gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
				     &iter );
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Example #6
0
/**
 * called when something change for a fyear
 * update the list and the invalid
 *
 * \param entry the entry wich change
 * \param tree_view the tree_view
 *
 * \return FALSE
 * */
gboolean gsb_fyear_config_modify_fyear ( GtkWidget *entry,
					 GtkWidget *tree_view)
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    gint fyear_number;
    GtkWidget *widget;
    gchar *invalid;

    if (!gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view))),
					   &model,
					   &iter ))
	return FALSE;

    gtk_tree_model_get ( GTK_TREE_MODEL (model),
			 &iter,
			 FYEAR_NUMBER_COLUMN, &fyear_number,
			 -1 );

    /* normally should not happen */
    if (!fyear_number)
	return FALSE;

    /* check the invalid and show the message if needed */
    widget = g_object_get_data ( G_OBJECT (model),
				 "invalid_label" );

     /* check all the fyear to set them invalid if need */
     gsb_fyear_update_invalid (tree_view);

     /* and check if the current fyear was set as invalid */
     if (gsb_data_fyear_get_invalid (fyear_number))
     {
	 /* and now focus on the current fyear */
	 invalid = GTK_STOCK_DIALOG_WARNING;
	 gtk_label_set_markup ( GTK_LABEL (widget),
				gsb_data_fyear_get_invalid_message (fyear_number));
	 gtk_widget_show (widget);
     }
     else
     {
	 invalid = NULL;
	 gtk_widget_hide (widget);
     }

     gtk_list_store_set ( GTK_LIST_STORE (model),
			  &iter,
			  FYEAR_NAME_COLUMN, gsb_data_fyear_get_name (fyear_number),
			  FYEAR_BEGIN_DATE_COLUMN, gsb_format_gdate (gsb_data_fyear_get_beginning_date (fyear_number)),
			  FYEAR_END_DATE_COLUMN, gsb_format_gdate (gsb_data_fyear_get_end_date (fyear_number)) ,
			  FYEAR_INVALID_COLUMN, invalid,
			  FYEAR_NUMBER_COLUMN, fyear_number,
			  -1 );
     gsb_file_set_modified ( TRUE );
     return FALSE;
}
Example #7
0
/**
 * callback called when the user click on 'Delete the reconciliation'
 * this will delete the selected reconciliation and will mark all the concerned
 * transactions as P
 *
 * \param button
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_reconcile_config_delete ( GtkWidget *button,
				       GtkWidget *tree_view )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    gboolean good;

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

    if (good)
    {
	gint reconcile_number;
	gint account_number;

	gtk_tree_model_get (model, &iter,
			    RECONCILIATION_RECONCILE_COLUMN, &reconcile_number,
			    -1 );

	if (reconcile_number)
	{
	    /* we are on a reconcile,
	     * we ask if the user want to continue and warn him */
	    gchar* tmpstr = g_strdup_printf (_("Caution, you are about to delete a reconciliation.\nIf you continue, the reconciliation %s will be erased and all the transactions marked by this reconciliation will be un-reconciled and marked P.\nAre you sure you want to continue?"),
							 gsb_data_reconcile_get_name (reconcile_number));
	    if (!question_yes_no (tmpstr, _("Delete reconciliation"),
					GTK_RESPONSE_NO ))
	    {
		g_free ( tmpstr );
		return FALSE;
	    }

	    /* ok we delete the reconcile
	     * this will automatickly remove it from the marked transactions */
	    gtk_tree_store_remove ( GTK_TREE_STORE (model),
				    &iter );
	    gsb_data_reconcile_remove (reconcile_number);

	    /* if we are on an account, we update the list */
	    account_number = gsb_gui_navigation_get_current_account ();
	    if (account_number != -1)
	    {
		gsb_transactions_list_update_tree_view (account_number, TRUE);

		/* update the last statement for that account */
		gsb_gui_navigation_update_statement_label (account_number);
	    }
            gsb_file_set_modified ( TRUE );
	}
    }

    return FALSE;
}
Example #8
0
/**
 * Show or hide closed accounts.
 *
 * \return FALSE
 */
gboolean gsb_gui_toggle_show_closed_accounts ( void )
{
    conf.show_closed_accounts = !conf.show_closed_accounts;

    gsb_gui_navigation_create_account_list ( gsb_gui_navigation_get_model ( ) );
    gsb_gui_navigation_update_home_page ( );

    gsb_file_set_modified ( TRUE );

    return FALSE;
}
Example #9
0
gboolean gsb_reconcile_config_end_date_changed ( GtkWidget *checkbutton,
                        GdkEventButton *event,
                        gpointer data )
{
	GrisbiWinEtat *w_etat;

	w_etat = (GrisbiWinEtat *) grisbi_win_get_w_etat ();
    w_etat->reconcile_end_date = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( checkbutton ), "pointer" ) );

    gsb_file_set_modified ( TRUE );

    return FALSE;
}
Example #10
0
/* ********************************************************************** */
gboolean change_choix_utilise_logo ( GtkWidget *check_button,
                        GtkWidget *hbox )
{

    etat.utilise_logo = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON 
                            ( check_button ));
    gtk_widget_set_sensitive ( hbox, etat.utilise_logo );

    if ( etat.utilise_logo )
    {
        /* 	on recharge l'ancien logo */

        if ( GTK_IS_WIDGET ( logo_accueil ) )
            gtk_widget_hide ( logo_accueil );
        else
        {
            GdkPixbuf *pixbuf = NULL;

            /* Update homepage logo */
            pixbuf = gsb_select_icon_get_logo_pixbuf ( );
            if ( pixbuf == NULL )
            {
                pixbuf = gsb_select_icon_get_default_logo_pixbuf ( );
                etat.is_pixmaps_dir = TRUE;
            }
            logo_accueil =  gtk_image_new_from_pixbuf ( pixbuf );
            if ( logo_accueil )
            {
                gtk_box_pack_start ( GTK_BOX ( hbox_title ), logo_accueil, FALSE, FALSE, 0 );
                gtk_widget_set_size_request ( hbox_title, -1, -1 );
                gtk_widget_show ( logo_accueil );
            }
        }
    }
    else
    {
        gtk_widget_destroy ( logo_accueil );
        gtk_widget_set_size_request ( hbox_title, -1, -1 );
        if ( etat.name_logo && strlen ( etat.name_logo ) )
            g_free ( etat.name_logo );
        etat.name_logo = NULL;
        etat.is_pixmaps_dir = 0;
    }

    gsb_file_set_modified ( TRUE );

    return ( FALSE );
}
Example #11
0
/**
 * Update the label that contain main title in homepage.
 *
 * \param entry Widget that triggered this handled.  Not used.
 * \param value Not used handler parameter.
 * \param length Not used handler parameter.
 * \param position Not used handler parameter.
 */
gboolean update_homepage_title (GtkEntry *entry, gchar *value,
                        gint length, gint * position)
{
    if ( titre_fichier && strlen ( titre_fichier ) )
        g_free ( titre_fichier );

    titre_fichier = my_strdup ( gtk_entry_get_text ( GTK_ENTRY ( entry ) ) );

    /* set Grisbi title */
    gsb_main_set_grisbi_title ( -1 );

    /* Mark file as modified */
    gsb_file_set_modified ( TRUE );

    return FALSE;
}
Example #12
0
/**
 * called for add a new financial year
 *
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_fyear_config_add_fyear ( GtkWidget *tree_view )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    GtkWidget *entry;
    gint fyear_number;
    GDate *date;

    fyear_number = gsb_data_fyear_new (_("New financial year"));

    /* if bad things will append soon ... */
    if (!fyear_number)
	return FALSE;

    gsb_data_fyear_set_form_show ( fyear_number,
				   TRUE );
    gsb_data_fyear_set_beginning_date ( fyear_number,
				       date = gdate_today());
    gsb_data_fyear_set_end_date ( fyear_number,
				  date );
    g_date_free (date);

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));

    /* append to the list and get back the iter */
    gsb_fyear_config_append_line ( model,
				   fyear_number,
				   &iter );

    /* select it */
    gtk_tree_selection_select_iter ( GTK_TREE_SELECTION (selection),
				     &iter );

    /* select the new name and give it the focus */
    entry = g_object_get_data ( G_OBJECT (model),
				"fyear_name_entry");
    gtk_editable_select_region ( GTK_EDITABLE (entry), 0, -1 );
    gtk_widget_grab_focus (entry);

    /* Update various menus */
    gsb_fyear_update_fyear_list ();
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Example #13
0
/**
 * associate all transactions without fyear to the corresponding
 * fyear
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_fyear_config_associate_transactions ( void )
{
    GSList *list_tmp;
    gint modification_number = 0;

    if (!question_yes_no_hint ( _("Automatic association of financial years?"),
				_("This function assigns each transaction without a financial year to the one related to its transaction date.  If no financial year matches, the transaction will not be changed."),
				GTK_RESPONSE_NO ))
	return FALSE;

    list_tmp = gsb_data_transaction_get_complete_transactions_list ();

    while ( list_tmp )
    {
	gint transaction_number;

	transaction_number = gsb_data_transaction_get_transaction_number (list_tmp -> data);

	if (!gsb_data_transaction_get_financial_year_number (transaction_number))
	{
	    gint fyear_number;

	    fyear_number = gsb_data_fyear_get_from_date (gsb_data_transaction_get_date (transaction_number));
	    if (fyear_number)
	    {
		gsb_data_transaction_set_financial_year_number ( transaction_number,
								 fyear_number );
		modification_number++;
	    }
	}
	list_tmp = list_tmp -> next;
    }

    if (modification_number)
    {
	gchar* tmpstr = g_strdup_printf (_("%d transactions associated"),
				    modification_number);
	dialogue (  tmpstr );
	g_free ( tmpstr );
	transaction_list_update_element (ELEMENT_EXERCICE);
        gsb_file_set_modified ( TRUE );
    }
    else
	dialogue ( _("no transaction to associate"));
    return FALSE;
}
Example #14
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;
}
/**
 * Callback called when toggle the check button to sort by method of payment
 *
 * \param cell
 * \param path_str
 * \param tree_view
 *
 * \return FALSE
 */
gboolean gsb_reconcile_sort_config_payment_toggled ( GtkCellRendererToggle *cell,
						     gchar *path_str,
						     GtkWidget *tree_view )
{
    GtkTreePath * treepath;
    GtkTreeIter iter;
    gboolean toggle;
    gint account_number;
    GtkTreeModel *model;

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view));

    treepath = gtk_tree_path_new_from_string ( path_str );
    gtk_tree_model_get_iter ( GTK_TREE_MODEL (model),
			      &iter, treepath );

    gtk_tree_model_get (GTK_TREE_MODEL(model), &iter,
			RECONCILIATION_SORT_SORT_COLUMN, &toggle,
			RECONCILIATION_SORT_ACCOUNT_COLUMN, &account_number,
			-1);

    toggle ^= 1;

    /* set new value */
    gtk_tree_store_set (GTK_TREE_STORE (model), &iter,
			RECONCILIATION_SORT_SORT_COLUMN, toggle,
			-1);

    /* Set to 1 (sort by types) if toggle is selected */
    gsb_data_account_set_reconcile_sort_type ( account_number,
					       toggle );

    if (toggle)
	gtk_tree_view_expand_row ( GTK_TREE_VIEW(tree_view), treepath, FALSE );
    else
	gtk_tree_view_collapse_row ( GTK_TREE_VIEW(tree_view), treepath );

    gtk_tree_path_free ( treepath );
    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Example #16
0
/**
 * come here to finish to create the new file
 * at this time, categories and currencies must created
 * this part will just launch the assistant to create a new account
 * a finish the initialisation to lauch grisbi
 *
 * \param
 *
 * \return FALSE
 * */
gboolean gsb_file_new_finish ( void )
{
    /* create the first account */
    if (! gsb_assistant_account_run ())
    {
        init_variables ();
        return FALSE;
    }

    /* the the name in the last opened files */
    gsb_file_append_name_to_opened_list ( nom_fichier_comptes );

    /* init the gui */
    gsb_file_new_gui ();

    mise_a_jour_accueil ( TRUE );
    gsb_gui_navigation_set_selection ( GSB_HOME_PAGE, -1, NULL );

    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Example #17
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;
}
Example #18
0
/**
 * called to remove a financial year, check before if
 * some transactions are associated with it and warn if yes
 *
 * \param tree_view
 *
 * \return FALSE
 * */
gboolean gsb_fyear_config_remove_fyear ( GtkWidget *tree_view )
{
    GtkTreeIter iter;
    GtkTreeModel *model;
    GtkTreeSelection *selection;
    gint fyear_number;
    gboolean warning_showed = FALSE;
    GSList *tmp_list;

    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
    gtk_tree_selection_get_selected ( GTK_TREE_SELECTION (selection),
				      &model,
				      &iter );
    gtk_tree_model_get ( GTK_TREE_MODEL (model),
			 &iter,
			 FYEAR_NUMBER_COLUMN, &fyear_number,
			 -1 );
    if (!fyear_number)
	return FALSE;

    /* first, we check if one transaction uses that financial year */
    tmp_list = gsb_data_transaction_get_complete_transactions_list ();

    while (tmp_list)
    {
	gint transaction_number;

	transaction_number = gsb_data_transaction_get_transaction_number (tmp_list -> data);

	if ( fyear_number
	     ==
	     gsb_data_transaction_get_financial_year_number (transaction_number))
	{
	    /* at the beginning warning_showed is FALSE and we show a warning,
	     * if the user doesn't want to continue, we go out of the while so cannot come
	     * here again ; but if he wants to continue, warning_showed is set to TRUE, we delete
	     * the financial year and continue to come here to set the fyear of the
	     * transactions to 0 */
	    if (warning_showed)
		gsb_data_transaction_set_financial_year_number (transaction_number, 0);
	    else
	    {
		gint result;

		result = question_yes_no_hint ( _("The selected financial year is used in the file"),
						_("If you really remove it, all the associated transactions will be without financial year.\nAre you sure?"),
						GTK_RESPONSE_NO );
		if (result)
		{
		    gsb_data_transaction_set_financial_year_number (transaction_number, 0);
		    warning_showed = TRUE;
		}
		else
		    break;
	    }
	}
	tmp_list = tmp_list -> next;
    }

    /* if warning_showed is FALSE, it's because none transaction have that fyear,
     * or we answer NO to the warning but in that case, tmp_list is non NULL */
    if (warning_showed
	||
	!tmp_list )
    {
	gsb_data_fyear_remove (fyear_number);

	gtk_list_store_remove ( GTK_LIST_STORE (model),
				&iter );
	gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (model),
						       "paddingbox_details" ),
				   FALSE );
	gtk_widget_set_sensitive ( g_object_get_data ( G_OBJECT (model),
						       "remove_fyear_button" ),
				   FALSE );

	/* Update various menus */
	gsb_fyear_update_fyear_list ();
        gsb_file_set_modified ( TRUE );
    }
    return FALSE;
}
Example #19
0
/* **************************************************************************************************************************** */
void change_logo_accueil ( GtkWidget * file_selector )
{
    GdkPixbuf * pixbuf;

    const gchar *selected_filename;

    selected_filename = file_selection_get_filename ( GTK_FILE_CHOOSER ( file_selector ) );

    if ( gsb_data_account_get_accounts_amount () )
    {
        /* on change le logo */
        gchar * chemin_logo;

        gtk_container_remove ( GTK_CONTAINER ( logo_button ), preview );
        chemin_logo = g_strstrip ( g_strdup ( selected_filename ) );
        if ( !strlen ( chemin_logo ) )
        {
            if ( logo_accueil && GTK_IS_WIDGET ( logo_accueil ) )
                gtk_widget_hide ( logo_accueil );
            preview = gtk_image_new_from_stock ( GTK_STOCK_MISSING_IMAGE,
                             GTK_ICON_SIZE_BUTTON );
        }
        else
        {
            /* Update preview */
            pixbuf = gdk_pixbuf_new_from_file ( chemin_logo, NULL );
            if (!pixbuf)
            {
                if ( logo_accueil && GTK_IS_WIDGET ( logo_accueil ))
                    gtk_widget_hide ( logo_accueil );
                preview = gtk_image_new_from_stock ( GTK_STOCK_MISSING_IMAGE,
                                    GTK_ICON_SIZE_BUTTON );
            }
            else
            {
                if ( g_strcmp0 ( g_path_get_dirname ( chemin_logo ), gsb_dirs_get_pixmaps_dir ( ) ) == 0 )
                {
                    gchar *name_logo;

                    etat.is_pixmaps_dir = TRUE;

                    name_logo = g_path_get_basename ( chemin_logo );
                    if ( g_strcmp0 ( name_logo, "grisbi-logo.png" ) != 0 )
                        etat.name_logo = name_logo;
                    else
                        etat.name_logo = NULL;
                }
                else
                {
                    etat.is_pixmaps_dir = FALSE;
                    if ( etat.name_logo && strlen ( etat.name_logo ) )
                        g_free ( etat.name_logo );
                    etat.name_logo = NULL;
                }

                gsb_select_icon_set_logo_pixbuf ( pixbuf );
                preview = gtk_image_new_from_pixbuf ( 
                        gdk_pixbuf_scale_simple ( 
                        pixbuf, 48, 48, GDK_INTERP_BILINEAR ) );
                
                /* Update homepage logo */
                gtk_widget_destroy ( logo_accueil );
                
                logo_accueil =  gtk_image_new_from_pixbuf ( 
                                    gsb_select_icon_get_logo_pixbuf ( ) );
                gtk_box_pack_start ( GTK_BOX ( hbox_title ), logo_accueil, FALSE, FALSE, 0 );
                gtk_widget_show ( logo_accueil );
                /* modify the icon of grisbi (set in the panel of gnome or other) */
                gtk_window_set_default_icon ( 
                            gsb_select_icon_get_logo_pixbuf ( ) );
            }

            g_free ( chemin_logo );
        }
        gtk_widget_show ( preview );
        gtk_container_add ( GTK_CONTAINER ( logo_button ), preview );
        
        /* Mark file as modified */
        gsb_file_set_modified ( TRUE );
    }
}
Example #20
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;
}
Example #21
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;
}
Example #22
0
/**
 * save the file
 *
 * \param origine 0 from gsb_file_save (menu), -1 from gsb_file_close, -2 from gsb_file_save_as
 *
 * \return TRUE if ok, FALSE if problem
 * */
gboolean gsb_file_save_file ( gint origine )
{
    gint etat_force, result;
    gchar *nouveau_nom_enregistrement;

    devel_debug_int (origine);

    etat_force = 0;

    if ( ( !gsb_file_get_modified ( ) && origine != -2 ) ||
	 !gsb_data_account_get_accounts_amount () )
    {
	notice_debug ( "nothing done in gsb_file_save_file" );
	return ( TRUE );
    }

    /* si le fichier de comptes n'a pas de nom ou si on enregistre sous un nouveau nom */
    /*     c'est ici */

    if ( !nom_fichier_comptes || origine == -2 )
	nouveau_nom_enregistrement = gsb_file_dialog_ask_name ();
    else
	nouveau_nom_enregistrement = nom_fichier_comptes;

    if ( !nouveau_nom_enregistrement )
	return FALSE;

    /*     on vérifie que le fichier n'est pas locké */
    if ( etat.fichier_deja_ouvert
	 &&
	 !conf.force_enregistrement
	 &&
	 origine != -2 )
    {
        gchar* tmpstr1 = g_strdup_printf( _("Grisbi was unable to save this file because it is locked.  Please save it with another name or activate the \"%s\" option in preferences."),
					       _("Force saving of locked files" ) );
	gchar* tmpstr2 = g_strdup_printf( _("Can not save file \"%s\""),
					       nom_fichier_comptes );
	dialogue_error_hint ( tmpstr1,
			      tmpstr2 );
	g_free ( tmpstr1 );
	g_free ( tmpstr2 );
	return ( FALSE );
    }

        /* Si le fichier est un d'une version précédente de grisbi on demande si on l'efface */
    if ( copy_old_filename && strlen ( copy_old_filename ) > 0 )
    {
        gsb_file_save_remove_old_file ( copy_old_filename );
        g_free ( copy_old_filename );
        copy_old_filename = NULL;
    }

    /* make backup before saving if asked */
    if (conf.make_backup)
	gsb_file_save_backup();

    /*   on a maintenant un nom de fichier */
    /*     et on sait qu'on peut sauvegarder */
    gsb_status_message ( _("Saving file") );

    result = gsb_file_save_save_file ( nouveau_nom_enregistrement,
				       conf.compress_file,
				       FALSE );

    if ( result )
    {
	/* saving was right, so unlock the last name */
	gsb_file_util_modify_lock ( FALSE );

	nom_fichier_comptes = nouveau_nom_enregistrement;

	/* and lock the new name */
	gsb_file_util_modify_lock ( TRUE );

	/* update variables */
	etat.fichier_deja_ouvert = 0;
        gsb_file_set_modified ( FALSE );
	gsb_main_set_grisbi_title ( gsb_gui_navigation_get_current_account ( ) );
	gsb_file_append_name_to_opened_list ( nom_fichier_comptes );
    }

    gsb_status_message ( _("Done") );

    return ( result );
}
Example #23
0
/**
 * finish the reconciliation,
 * called by a click on the finish button
 *
 * \param button
 * \param null
 *
 * \return FALSE
 */
gboolean gsb_reconcile_finish_reconciliation ( GtkWidget *button,
					    gpointer null )
{
    GSList *list_tmp_transactions;
    GDate *date;
    gint account_number;
    gint reconcile_number;
    gsb_real real;
	gchar* tmpstr;

    account_number = gsb_gui_navigation_get_current_account ();

    if ( gsb_real_sub ( gsb_real_add ( utils_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( reconcile_initial_balance_entry ))),
				       gsb_data_account_calculate_waiting_marked_balance (account_number)),
			utils_real_get_from_string (gtk_entry_get_text ( GTK_ENTRY ( reconcile_final_balance_entry )))).mantissa != 0 )
    {
	dialogue_warning_hint ( _("There is a variance in balances, check that both final balance and initial balance minus marked transactions are equal."),
				_("Reconciliation can't be completed.") );
	return FALSE;
    }

    /* get and check the reconcile name */
    reconcile_number = gsb_data_reconcile_get_number_by_name (gtk_entry_get_text ( GTK_ENTRY ( reconcile_number_entry )));
    if (reconcile_number)
    {
	dialogue_warning_hint ( _("There is already a reconcile with that name, you must use another name or let it free.\nIf the reconcile name is ending by a number,\nit will be automatically incremented."),
				_("Reconciliation can't be completed.") );
	return FALSE;
    }


    /* get and save the date */
    date = gsb_calendar_entry_get_date (reconcile_new_date_entry);
    if (!date)
    {
	gchar* tmpstr = g_strdup_printf ( _("Invalid date: '%s'"),
						  gtk_entry_get_text ( GTK_ENTRY ( reconcile_new_date_entry )));
	dialogue_warning_hint ( tmpstr,
				_("Reconciliation can't be completed.") );
	g_free ( tmpstr );
	return FALSE;
    }

    if (!strlen (gtk_entry_get_text ( GTK_ENTRY ( reconcile_number_entry ))))
    {
	dialogue_warning_hint ( _("You need to set a name to the reconciliation ; at least, set a number,\nit will be automatically incremented later"),
				_("Reconciliation can't be completed.") );
	return FALSE;
    }

    /* restore the good sort of the list */
    if (transaction_list_sort_get_reconcile_sort ())
    {
	gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON (reconcile_sort_list_button),
				       FALSE );
	gsb_reconcile_list_button_clicked (reconcile_sort_list_button, NULL);
    }

    tmpstr = g_strdup_printf ( _("Last statement: %s"), gsb_format_gdate (date));
    gtk_label_set_text ( GTK_LABEL ( label_last_statement ),
			 tmpstr);
    g_free ( tmpstr );

    /* create the new reconcile structure */
    reconcile_number = gsb_data_reconcile_new (gtk_entry_get_text (GTK_ENTRY (reconcile_number_entry)));
    gsb_data_reconcile_set_account ( reconcile_number, account_number );

    /* set the variables of the reconcile */
    gsb_data_reconcile_set_final_date ( reconcile_number, date );
    g_date_free (date);

    date = gsb_parse_date_string (gtk_label_get_text (GTK_LABEL (reconcile_last_date_label)));
    gsb_data_reconcile_set_init_date ( reconcile_number, date );
    g_free (date);

    real = utils_real_get_from_string ( gtk_entry_get_text (
                        GTK_ENTRY ( reconcile_initial_balance_entry ) ) );
    gsb_data_reconcile_set_init_balance ( reconcile_number, real );

    real = utils_real_get_from_string ( gtk_entry_get_text (
                        GTK_ENTRY ( reconcile_final_balance_entry ) ) );
    gsb_data_reconcile_set_final_balance ( reconcile_number,
					   real );

    /* modify the reconciled transactions */
    list_tmp_transactions = gsb_data_transaction_get_transactions_list ();

    while ( list_tmp_transactions )
    {
	gint transaction_number_tmp;
	transaction_number_tmp = gsb_data_transaction_get_transaction_number (
                        list_tmp_transactions -> data);

	if ( gsb_data_transaction_get_account_number (transaction_number_tmp) == account_number
	     &&
	     ( gsb_data_transaction_get_marked_transaction (transaction_number_tmp) == OPERATION_POINTEE
	       ||
	       gsb_data_transaction_get_marked_transaction (transaction_number_tmp) == OPERATION_TELERAPPROCHEE ))
	{
	    gsb_data_transaction_set_marked_transaction ( transaction_number_tmp,
							  OPERATION_RAPPROCHEE );
	    gsb_data_transaction_set_reconcile_number ( transaction_number_tmp,
							reconcile_number );
	}
	list_tmp_transactions = list_tmp_transactions -> next;
    }

    /* update the P and T to R in the list */
    transaction_list_update_element (ELEMENT_MARK);

    run.mise_a_jour_liste_comptes_accueil = TRUE;

    /* go back to the normal transactions list */
    gsb_reconcile_cancel (NULL, NULL);

    /* reset records in run: to do after gsb_reconcile_cancel */
    g_free (run.reconcile_final_balance);
    if (run.reconcile_new_date)
        g_date_free (run.reconcile_new_date);
    run.reconcile_final_balance = NULL;
    run.reconcile_new_date = NULL;
    run.reconcile_account_number = -1;

    gsb_file_set_modified ( TRUE );

    if ( reconcile_save_last_scheduled_convert )
    {
        gsb_gui_navigation_set_selection ( GSB_SCHEDULER_PAGE, 0, NULL );
        gsb_scheduler_list_select ( reconcile_save_last_scheduled_convert );
        gsb_scheduler_list_edit_transaction ( reconcile_save_last_scheduled_convert );
        reconcile_save_last_scheduled_convert = 0;
    }

    return FALSE;
}
Example #24
0
/** that function delete the current account selected in the account properties
 * \param none
 * \return FALSE FALSE
 * */
gboolean gsb_account_delete ( void )
{
    gint deleted_account;
    gint page_number;
    GSList *list_tmp;
	gchar* tmpstr;

    deleted_account = gsb_gui_navigation_get_current_account ();

    tmpstr = g_strdup_printf (_("Delete account \"%s\"?"),
				     gsb_data_account_get_name ( deleted_account ) ) ;

    if ( !question_yes_no_hint ( tmpstr,
				        _("This will irreversibly remove this account and all operations "
                        "that were previously contained.  There is no undo for this. "
                        "Usually it's a better way to close an account."),
				        GTK_RESPONSE_NO ))
    {
        g_free ( tmpstr );
	    return FALSE;
    }
    g_free ( tmpstr );

    /* if the last account, close the file */
    if ( gsb_data_account_get_accounts_amount () == 1 )
    {
        gsb_file_set_modified ( FALSE );
        gsb_file_close ();
        return FALSE;
    }

    /* delete the schedules transactions on that account */
    list_tmp = gsb_data_scheduled_get_scheduled_list ();
    while (list_tmp)
    {
        gint scheduled_number;

        scheduled_number = gsb_data_scheduled_get_scheduled_number ( list_tmp -> data );

        if ( gsb_data_scheduled_get_account_number (scheduled_number) == deleted_account )
            gsb_data_scheduled_remove_scheduled (scheduled_number);

        list_tmp = list_tmp -> next;
    }


    /* remove all the transactions of that account */
    list_tmp = gsb_data_transaction_get_complete_transactions_list ();
    while (list_tmp)
    {
        gint transaction_number;

        transaction_number = gsb_data_transaction_get_transaction_number ( list_tmp -> data );

        /* better to go to the next transaction now */
        list_tmp = list_tmp -> next;

        if (gsb_data_transaction_get_account_number (transaction_number) == deleted_account)
        {
            gint contra_transaction_number;

            /* we are on a transaction on the deleted account, we delete that transaction,
             * but if it's a transfer, modify the contra-transaction to set transfer to deleted account */
            contra_transaction_number = gsb_data_transaction_get_contra_transaction_number (
                                        transaction_number);
            if (contra_transaction_number > 0)
            /* it's a transfer, modify the contra-transaction */
                gsb_data_transaction_set_contra_transaction_number ( contra_transaction_number, -1);

            /* now can remove the transaction */
            gsb_data_transaction_remove_transaction_without_check ( transaction_number );
        }
    }

    /* delete the payment_number */
    list_tmp = gsb_data_account_get_sort_list ( deleted_account );
    while (list_tmp)
    {
        gpointer ptr;
        gint payment_number;

        ptr = list_tmp -> data;
        payment_number = GPOINTER_TO_INT ( ptr );
        gsb_data_payment_remove ( payment_number );

        list_tmp = list_tmp -> next;
    }

    /* delete the account */
    gsb_data_account_delete ( deleted_account );

    /* check gsb_gui_navigation_get_current_account () and gsb_gui_navigation_get_current_account ()_onglet and put them
     * on the first account if they are on the deleted account */

    if ( gsb_gui_navigation_get_current_account () == deleted_account )
    {
        GtkWidget *notebook_general;

	/* update the transaction list */
    notebook_general = gsb_gui_get_general_notebook ( );
	page_number = gtk_notebook_get_current_page ( GTK_NOTEBOOK ( notebook_general ) );

	navigation_change_account ( gsb_data_account_first_number () );

	gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook_general ), page_number );
    }

    /* update the buttons lists */
    gsb_menu_update_accounts_in_menus();

    /* Replace trees contents. */
    categories_fill_list ();
    budgetary_lines_fill_list ();
    payees_fill_list ();

    /* update the categories in lists */
    transaction_list_update_element (ELEMENT_CATEGORY);

    /* update the name of accounts in form */
    gsb_account_update_combo_list ( gsb_form_scheduler_get_element_widget (SCHEDULED_FORM_ACCOUNT),
				    FALSE );

    gsb_scheduler_list_fill_list (gsb_scheduler_list_get_tree_view ());
    mise_a_jour_liste_echeances_manuelles_accueil = 1;
    mise_a_jour_liste_comptes_accueil = 1;
    mise_a_jour_soldes_minimaux = 1;
    mise_a_jour_fin_comptes_passifs = 1;

    /* Update navigation pane. */
    gsb_gui_navigation_remove_account ( deleted_account );

    gsb_file_set_modified ( TRUE );
    return FALSE;
}
Example #25
0
/**
 * open a new grisbi file, don't check anything about another opened file that must
 * have been done before
 *
 * \para filename the name of the file
 *
 * \return TRUE ok, FALSE problem
 * */
gboolean gsb_file_open_file ( gchar *filename )
{
    GSList *list_tmp;

    devel_debug (filename);

    if ( !filename
	 ||
	 !strlen (filename))
	return FALSE;

    gsb_status_wait ( TRUE );
    gsb_status_message ( _("Loading accounts") );

    /* try to load the file */
    /* FIXME:BUG under Windows: for unknwon reason yet filename is cleared
     * when returning from gsb_file_load_open_file!
     * making application crashes! */

    if ( gsb_file_load_open_file (filename))
    {
        /* the file has been opened succesfully */
        /* we make a backup if necessary */
        if ( conf.sauvegarde_demarrage )
        {
            gsb_file_save_backup ();
            gsb_file_set_modified ( FALSE );
        }
    }
    else
    {
        /* Loading failed. */
        gsb_status_message ( _("Failed to load accounts") );

        if ( conf.sauvegarde_demarrage || conf.make_backup || conf.make_backup_every_minutes )
        {
            gchar *tmpstr = g_strdup_printf ( _("Error loading file '%s'"), filename);
            gchar *tmpstr2 = g_strdup_printf (
                                _("Grisbi was unable to load file. You should find the last "
                                  "backups in '%s', they are saved with date and time into "
                                  "their name so you should find easily the last backup "
                                  "saved.\n"
                                  "Please contact the Grisbi's team on [email protected] "
                                  "to find what happened to you current file."),
                                gsb_file_get_backup_path ());
            dialogue_error_hint ( tmpstr2, tmpstr );
            g_free ( tmpstr );
            g_free ( tmpstr2 );
            gsb_status_stop_wait ( TRUE );
            return FALSE;
        }
        else
        {
            gchar *tmpstr = g_strdup_printf ( _("Error loading file '%s'"), filename);
            gchar *tmpstr2;

            if (gsb_file_get_backup_path ())
            tmpstr2 = g_strdup_printf (
                            _("Grisbi was unable to load file and the backups seem not to "
                              "be activated... This is a bad thing.\nYour backup path is '%s', "
                              "try to find if earlier you had some backups in there ?\n"
                              "Please contact the Grisbi's team on [email protected] "
                              "to find what happened to you current file."),
                            gsb_file_get_backup_path ());
            else
            tmpstr2 = my_strdup ( _("Grisbi was unable to load file and the backups seem not "
                                    "to be activated... This is a bad thing.\n"
                                    "Please contact the Grisbi's team on "
                                    "[email protected] to find what happened to you "
                                    "current file."));

            dialogue_error_hint ( tmpstr2, tmpstr );
            g_free ( tmpstr );
            g_free ( tmpstr2 );
            gsb_status_stop_wait ( TRUE );
            return FALSE;
        }
    }

    /* ok, here the file or backup is loaded */
    gsb_status_message ( _("Checking schedulers"));

    /* the the name in the last opened files */
    gsb_file_append_name_to_opened_list ( filename );

    /* create the archives store data, ie the transaction wich will replace the archive in
     * the list of transactions */
    gsb_data_archive_store_create_list ();

    /* create all the gui */
    gsb_file_new_gui ();

    /* check the amounts of all the accounts */
    gsb_status_message ( _("Checking amounts"));
    list_tmp = gsb_data_account_get_list_accounts ();

    while ( list_tmp )
    {
	gint account_number;
	volatile gint value;

	account_number = gsb_data_account_get_no_account ( list_tmp -> data );

	/* set the minimum balances to be shown or not */
	value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number),
                          gsb_data_account_get_mini_balance_authorized (account_number) ) == -1;
    gsb_data_account_set_mini_balance_authorized_message ( account_number, value);
    value = gsb_real_cmp ( gsb_data_account_get_current_balance (account_number),
                          gsb_data_account_get_mini_balance_wanted (account_number) ) == -1;
    gsb_data_account_set_mini_balance_wanted_message ( account_number, value);
	list_tmp = list_tmp -> next;
    }

    /* set Grisbi title */
    gsb_main_set_grisbi_title ( -1 );

    /* update the main page */
    mise_a_jour_accueil (TRUE);

    /* for now, the flag for modification of the file is ok, but the menu couldn't be set
     * as sensitive/unsensitive so do it now */
    gsb_file_set_modified ( gsb_file_get_modified ( ) );

    gsb_status_message ( _("Done") );
    gsb_status_stop_wait ( TRUE );

    /* go to the home page */
    gsb_gui_navigation_set_selection ( GSB_HOME_PAGE, -1, NULL );

    /* set the focus to the selection tree at left */
    gtk_widget_grab_focus ( gsb_gui_navigation_get_tree_view ( ) );

    return TRUE;
}
Example #26
0
gboolean gsb_file_others_load_budget_from_category ( const gchar *filename )
{
    gchar *file_content;
    gchar* tmp_str;
    GSList *import_list = NULL;

    devel_debug (filename);

    /* general check */
    if ( !g_file_test ( filename, G_FILE_TEST_EXISTS ) )
    {
        tmp_str = g_strdup_printf (_("Cannot open file '%s': %s"),
					 filename,
					 g_strerror ( errno ) );
        dialogue_error ( tmp_str );
        g_free ( tmp_str );
        return FALSE;
    }

    /* check here if it's not a regular file */
    if ( !g_file_test ( filename, G_FILE_TEST_IS_REGULAR ) )
    {
        tmp_str = g_strdup_printf (
                        _("%s doesn't seem to be a regular file,\nplease check it and try again."),
					   filename );
        dialogue_error ( tmp_str );
        g_free ( tmp_str );
        return ( FALSE );
    }

    /* load the file */
    if ( g_file_get_contents ( filename, &file_content, NULL, NULL ) )
    {
        GMarkupParser *markup_parser;
        GMarkupParseContext *context;

        /* check if it's a good file */
        if ( !gsb_file_others_check_file ( file_content, 5 ) )
        {
            g_free ( file_content );
            return FALSE;
        }

        /* we load only after 0.6 files,
         * there is very few people who will want to upgrade previous categories, budgets...
         * and i'm too lazy to create an import for old files */
        /* fill the GMarkupParser for a new xml structure */
        markup_parser = g_malloc0 (sizeof (GMarkupParser));
        markup_parser -> start_element = (void *) gsb_file_others_start_budget_from_category;
        markup_parser -> error = (void *) gsb_file_load_error;

        context = g_markup_parse_context_new ( markup_parser,
                               0,
                               &import_list,
                               NULL );
        g_markup_parse_context_parse ( context,
                           file_content,
                           strlen ( file_content ),
                           NULL );

        /* on remplit l'arbre des imputation */
        budgetary_lines_fill_list ( );

        g_markup_parse_context_free ( context );
        g_free ( markup_parser );
        g_free ( file_content );

        gsb_file_set_modified ( TRUE );
    }
    else
    {
        tmp_str = g_strdup_printf (_("Cannot open file '%s': %s"),
					 filename,
					 g_strerror ( errno ) );
        dialogue_error ( tmp_str );
        g_free ( tmp_str );
        return FALSE;
    }

    return TRUE;
}
Example #27
0
/**
 * called to load the category/budget/report file given in param
 *
 * \filename the filename to load with full path
 *
 * \return TRUE if ok
 * */
gboolean gsb_file_others_load ( gchar *filename,
				gint origin )
{
    gchar *file_content;
    GSList *import_list = NULL;
    GError *error = NULL;

    devel_debug (filename);

    /* general check */

    if ( !g_file_test ( filename,
			G_FILE_TEST_EXISTS ))
    {
        gchar* tmpstr = g_strdup_printf (_("Cannot open file '%s': %s"),
					 filename,
					 g_strerror(errno));
	dialogue_error ( tmpstr );
	g_free ( tmpstr );
	return FALSE;
    }

    /* check here if it's not a regular file */
    if ( !g_file_test ( filename,
			G_FILE_TEST_IS_REGULAR ))
    {
        gchar* tmpstr = g_strdup_printf (
                        _("%s doesn't seem to be a regular file,\nplease check it and try again."),
					   filename );
	dialogue_error ( tmpstr );
	g_free ( tmpstr );
	return ( FALSE );
    }

    /* load the file */

    if ( g_file_get_contents ( filename,
			       &file_content,
			       NULL,
			       NULL ))
    {
	GMarkupParser *markup_parser;
	GMarkupParseContext *context;

	/* check if it's a good file */
	if ( !gsb_file_others_check_file ( file_content,
					   origin ))
	{
	    g_free (file_content);
	    return FALSE;
	}

	/* we load only after 0.6 files,
	 * there is very few people who will want to upgrade previous categories, budgets...
	 * and i'm too lazy to create an import for old files */
	/* fill the GMarkupParser for a new xml structure */

	markup_parser = g_malloc0 ( sizeof ( GMarkupParser ) );
	markup_parser -> start_element = ( void * ) gsb_file_others_start_element;
	markup_parser -> error = ( void * ) gsb_file_load_error;

    context = g_markup_parse_context_new ( markup_parser, 0, &import_list, NULL );

    if ( !g_markup_parse_context_parse ( context, file_content, strlen ( file_content ), &error ) )
    {
        gchar* tmpstr;

        tmpstr = g_strdup_printf (_("Error parsing file '%s': %s"), filename, error->message );
        dialogue_error ( tmpstr );

        g_free ( tmpstr );
        g_markup_parse_context_free ( context );
        g_free ( markup_parser );
        g_free ( file_content );

        return FALSE;
    }

    gint report_number;

	/* now, import_list contains the list of categories/budget or report */
	switch ( origin )
	{
	    case 0:
		/* comes for category */
		categories_fill_list ();
		break;

	    case 1:
		/* comes for budget */
		budgetary_lines_fill_list ();
		break;

	    case 2:
		/* comes for report,
		 * as we cannot have the same things between differents grisbi files,
		 * we cannot export/import currencies, financial years, accounts names,
		 * categories, budgetaries and parties
		 * so we erase them here because perhaps they doesn't exist and show
		 * a warning : the user has to do it by himself (untill a druid to help him ?) */

		/* we import only 1 report, so it's the last one */
		report_number = gsb_data_report_max_number ();

		if (report_number)
		{
		    /* set the currencies */
		    gsb_data_report_set_currency_general ( report_number,
							   1 );
		    gsb_data_report_set_category_currency ( report_number,
							    1 );
		    gsb_data_report_set_budget_currency ( report_number,
							  1 );
		    gsb_data_report_set_payee_currency ( report_number,
							 1 );
		    gsb_data_report_set_amount_comparison_currency ( report_number,
								     1 );
		    /* erase the financials years */
		    gsb_data_report_set_financial_year_list ( report_number,
							      NULL );
		    /* erase the accounts */
		    gsb_data_report_set_account_numbers_list ( report_number,
							  NULL);
		    /* erase the transferts accounts */
		    gsb_data_report_set_transfer_account_numbers_list ( report_number,
								   NULL );
		    /* erase the categories */
		    gsb_data_report_set_category_struct_list ( report_number,
							  NULL );
		    /* erase the parties */
		    gsb_data_report_set_payee_numbers_list ( report_number,
							NULL );
		    /* erase the kinds of payment */
		    gsb_data_report_set_method_of_payment_list ( report_number,
								 NULL );

		    gsb_gui_navigation_add_report ( report_number );

		    /* inform the user of that */
		    dialogue_hint ( _("Some things in a report cannot be imported:\n"
                        "The selected lists of financial years, accounts, transfer accounts, "
                        "categories, budgetaries, parties and kind of payments.\nSo that lists "
                        "have been erased while the import.\nThe currencies have been set too "
                        "on the first currency of this Grisbi file.\nYou should check and modify "
                        "that in the property box of that account."),
				        _("Importing a report"));
		}
		break;
	}

	g_markup_parse_context_free (context);
	g_free (markup_parser);
	g_free (file_content);

        gsb_file_set_modified ( TRUE );
    }
    else
    {
        gchar* tmpstr = g_strdup_printf (_("Cannot open file '%s': %s"),
					 filename,
					 g_strerror(errno));
	dialogue_error ( tmpstr );
	g_free ( tmpstr );
	return FALSE;
    }

    return TRUE;
}
Example #28
0
gboolean gsb_account_new ( kind_account account_type,
			   gint currency_number,
			   gint bank_number,
			   gsb_real init_amount,
			   const gchar *name,
               gchar *name_icon )
{
    gint account_number;
    GtkWidget *notebook_general;

    /*     create the new account */
    account_number = gsb_data_account_new (account_type);
    if ( account_number == -1 )
    {
	dialogue_error_memory ();
	return FALSE;
    }

    /* set the default method of payment */
    gsb_data_payment_create_default (account_number);

    /* set the icon_name */
    if ( name_icon )
        gsb_data_account_set_name_icon ( account_number, name_icon );

    gsb_data_account_set_currency ( account_number, currency_number);
    gsb_data_account_set_bank (account_number, bank_number);
    gsb_data_account_set_init_balance (account_number, init_amount);
    gsb_data_account_set_mini_balance_wanted ( account_number, 
					       gsb_real_new ( 0, 
							      gsb_data_currency_get_floating_point (currency_number) ) );
    gsb_data_account_set_mini_balance_authorized (account_number, 
						  gsb_real_new ( 0, 
								 gsb_data_currency_get_floating_point (currency_number) ) );
    gsb_data_account_set_name (account_number, name);

    /* update the combofix for categ */
    gsb_category_update_combofix ( FALSE );

    /* update the name of accounts in form */
    gsb_account_update_combo_list ( gsb_form_scheduler_get_element_widget (SCHEDULED_FORM_ACCOUNT),
				    FALSE );

    /* update the main page */
    mise_a_jour_liste_comptes_accueil = 1;

    /* update the accounts lists */
    gsb_menu_update_accounts_in_menus (); 

    /* do the next part only if the widgets are created
     * (can come here at the end of the new file assistant...) */
    notebook_general = gsb_gui_get_general_notebook ( );
    if (notebook_general)
    {
        /* Add an entry in navigation pane. */
        gsb_gui_navigation_add_account ( account_number, TRUE );

        /* Go to accounts properties */
        gtk_notebook_set_current_page ( GTK_NOTEBOOK ( notebook_general ), GSB_ACCOUNT_PAGE );
        gtk_notebook_set_current_page ( GTK_NOTEBOOK ( account_page ), GSB_PROPERTIES_PAGE );

        gsb_account_property_fill_page ();
    }

    gsb_file_set_modified ( TRUE );

    return TRUE;
}
/**
 * called when something change for a link
 *
 * \param tree_view the tree_view
 *
 * \return FALSE
 * */
gboolean gsb_currency_link_config_modify_link ( GtkWidget *tree_view )
{
    GtkWidget *combobox_1;
    GtkWidget *combobox_2;
    GtkWidget *exchange_entry;
    GtkTreeModel *model;
    GtkTreeIter iter;
    gint link_number;
    gchar *invalid;
    GtkWidget *label;
	gchar* tmpstr;
    gchar *strdate;
    gsb_real number;

    if ( !gtk_tree_selection_get_selected ( gtk_tree_view_get_selection (
                        GTK_TREE_VIEW ( tree_view ) ),
					    &model,
					    &iter ) )
	return FALSE;

    gtk_tree_model_get ( GTK_TREE_MODEL (model),
			 &iter,
			 LINK_NUMBER_COLUMN, &link_number,
			 -1 );

    /* normally should not happen */
    if (!link_number)
	return FALSE;

    combobox_1 = g_object_get_data ( G_OBJECT (model),
				     "combobox_1" );
    combobox_2 = g_object_get_data ( G_OBJECT (model),
				     "combobox_2" );
    exchange_entry = g_object_get_data ( G_OBJECT (model),
					 "exchange_entry" );

    number = utils_real_get_from_string ( gtk_entry_get_text ( GTK_ENTRY (exchange_entry) ) );
    if ( number.exponent > 8 )
        gtk_entry_set_max_length (GTK_ENTRY (exchange_entry),
                        strlen( gtk_entry_get_text ( GTK_ENTRY ( exchange_entry ) ) - 1) );

    gsb_data_currency_link_set_first_currency ( link_number,
						gsb_currency_get_currency_from_combobox (combobox_1));
    gsb_data_currency_link_set_second_currency ( link_number,
						 gsb_currency_get_currency_from_combobox (combobox_2));
    gsb_data_currency_link_set_change_rate ( link_number, number );
    gsb_data_currency_link_set_modified_date ( link_number, gdate_today ( ) );

    strdate = gsb_format_gdate ( gsb_data_currency_link_get_modified_date ( link_number ) );

    if ( gsb_data_currency_link_get_invalid_link (link_number))
	invalid = GTK_STOCK_DIALOG_WARNING;
    else
	invalid = NULL;

    tmpstr = utils_real_get_string ( gsb_data_currency_link_get_change_rate ( link_number ) );
    gtk_list_store_set ( GTK_LIST_STORE (model),
			 &iter,
			 LINK_CURRENCY1_COLUMN, gsb_data_currency_get_name (gsb_data_currency_link_get_first_currency(link_number)),
			 LINK_EXCHANGE_COLUMN, tmpstr,
			 LINK_CURRENCY2_COLUMN, gsb_data_currency_get_name (gsb_data_currency_link_get_second_currency(link_number)),
             LINK_DATE_COLUMN, strdate,
			 LINK_INVALID_COLUMN, invalid,
			 -1 );
    g_free ( tmpstr );
    g_free ( strdate );

    /* set or hide the warning label */
    label = g_object_get_data (G_OBJECT (model), "warning_label");

    if ( gsb_data_currency_link_get_invalid_link (link_number))
    {
	gtk_label_set_markup ( GTK_LABEL (label),
			       gsb_data_currency_link_get_invalid_message (link_number));
	gtk_widget_show (label);
    }
    else
	gtk_widget_hide (label);

    gsb_file_set_modified ( TRUE );
    gsb_gui_navigation_update_home_page ( );

    return FALSE;
}
Example #30
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);
}