Beispiel #1
0
/**
 * draw the title of the columns
 *
 * \param context           the GtkPrintContext
 * \param line_position     the position to insert the titles
 *
 * \return the new line_position to continue to fill the page
 * */
static gint print_tree_view_list_draw_columns_title ( GtkPrintContext *context,
                        gint line_position,
                        GtkTreeView *tree_view )
{
    GList *list;
    GList *list_tmp;
    gint column = 0;
    gint column_position;

    devel_debug_int ( line_position );

    if ( !gsb_data_print_config_get_draw_columns_name () )
        return line_position;

    /* begin a row : fill the line before the row */
    line_position = print_tree_view_list_draw_line ( line_position );

    list = gtk_tree_view_get_columns ( tree_view );

    if ( nbre_lines_col_title == 1 )
    {
        /* draw the last column */
        print_tree_view_list_draw_column ( page_width, line_position );
        list_tmp = list;

        while ( list_tmp )
        {
            GtkTreeViewColumn *col;
            const gchar *text;

            col = ( GtkTreeViewColumn * ) list_tmp -> data;
            column_position = columns_position[column];

            /* get the text */
            text = gtk_tree_view_column_get_title ( col );
            if (!text)
            {
                list_tmp  = list_tmp -> next;
                column++;
                continue;
            }

            print_tree_view_list_draw_cell ( context, line_position, column_position, column, text );

            list_tmp  = list_tmp -> next;
            column++;
        }
        line_position = line_position + size_columns_title;
    }
    else
    {
        gchar **tab;
        gchar *str_tmp;
        gint i = 0;

        for ( i = 0; i < nbre_lines_col_title; i ++ )
        {
            /* draw the last column */
            print_tree_view_list_draw_column ( page_width, line_position );
            list_tmp = list;

            while ( list_tmp )
            {
                GtkTreeViewColumn *col;
                const gchar *text;

                col = ( GtkTreeViewColumn * ) list_tmp -> data;
                column_position = columns_position[column];

                /* get the text */
                text = gtk_tree_view_column_get_title ( col );

                if ( text == NULL || strlen ( text ) == 0 )
                {
                    print_tree_view_list_draw_column ( column_position, line_position );
                    list_tmp  = list_tmp -> next;
                    column++;
                    continue;
                }

                str_tmp = gsb_string_uniform_new_line ( text, strlen ( text ) );
                if ( str_tmp == NULL )
                {
                    if ( i == 0 )
                        print_tree_view_list_draw_cell ( context, line_position, column_position, column, text );
                    else
                        print_tree_view_list_draw_column ( column_position, line_position );
                    list_tmp  = list_tmp -> next;
                    column++;
                    continue;
                }

                tab = g_strsplit ( str_tmp, "\n", 0 );

                if ( tab[i] && strlen ( tab[i] ) )
                    print_tree_view_list_draw_cell ( context, line_position, column_position, column, tab[i] );
                else
                    print_tree_view_list_draw_column ( column_position, line_position );

                list_tmp  = list_tmp -> next;
                column++;
                g_strfreev ( tab );
                g_free ( str_tmp );
            }
            line_position = line_position + size_row + gsb_data_print_config_get_draw_lines ( );
            column = 0;
        }
    }

    return line_position;
}
Beispiel #2
0
/**
 * check if the file given in param is a good file with the origin
 *
 * \param file_content the file loaded
 * \param origin what we want (0: category, 1:budget, 2:report)
 *
 * \return TRUE ok, FALSE else
 * */
gboolean gsb_file_others_check_file ( gchar *file_content,
				      gint origin )
{
    if ( !file_content
	 ||
	 strlen (file_content) < 37 )
    {
	dialogue_error ( _("This is not a Grisbi file, loading canceled..."));
	return FALSE;
    }

    file_content = gsb_string_uniform_new_line ( file_content, 37 );
    if ( !file_content )
    {
        dialogue_error ( _("This is not a Grisbi file, loading canceled..."));
        return FALSE;
    }

    switch ( origin )
    {
	case 0:
	    if ( !strncmp ( file_content,
			    "<?xml version=\"1.0\"?>\n<Grisbi_categ>",
			    36 ) )
	    {
		/* check if not before 0.6 */
		if ( !strncmp ( file_content,
				"<?xml version=\"1.0\"?>\n<Grisbi_categ>\n	<General\n",
				47 ) )
		    return TRUE;
		else
		    dialogue_error (_("The file version is below 0.6.0, Grisbi cannot import it."));
	    }
	    else
		dialogue_error ( _("This is not a category file, loading canceled..."));
	    break;

	case 1:
	    /* check first if it's not below 0.6 */
	    if ( !strncmp ( file_content,
			    "<?xml version=\"1.0\"?>\n<Grisbi_ib>",
			    33 ) )
		    dialogue_error (_("The file version is below 0.6.0, Grisbi cannot import it."));
	    else
	    {
		if ( !strncmp ( file_content,
				"<?xml version=\"1.0\"?>\n<Grisbi_budget>",
				37 ) )
		    return TRUE;
		else
		    dialogue_error ( _("This is not a budget file, loading canceled..."));
	    }
	    break;

	case 2:
	    /* check first if it's not below 0.6 */
	    if ( !strncmp ( file_content,
			    "<?xml version=\"1.0\"?>\n<Grisbi_etat>",
			    35 ) )
		dialogue_error (_("The file version is below 0.6.0, Grisbi cannot import it."));
	    else
	    {
		if ( !strncmp ( file_content,
				"<?xml version=\"1.0\"?>\n<Grisbi_report>",
				37 ) )
		    return TRUE;
		else
		    dialogue_error ( _("This is not a report file, loading canceled..."));
	    }
	    break;

	case 5:
	    if ( !strncmp ( file_content,
			    "<?xml version=\"1.0\"?>\n<Grisbi_categ>",
			    36 ) )
	    {
		/* check if not before 0.6 */
		if ( !strncmp ( file_content,
				"<?xml version=\"1.0\"?>\n<Grisbi_categ>\n	<General\n",
				47 ) )
		    return TRUE;
		else
		    dialogue_error (_("The file version is below 0.6.0, Grisbi cannot import it."));
	    }
	    else
		dialogue_error ( _("This is not a category file, loading canceled..."));
	    break;
    }

    return FALSE;
}
Beispiel #3
0
/**
 * draw a line of a model
 *
 * \param context           the GtkPrintContext
 * \param line_position     the position to insert the titles
 * \param
 *
 * \return the new line_position
 * */
static gint print_tree_view_list_draw_row ( GtkPrintContext *context,
                        GtkTreeView *tree_view,
                        gint line_position )
{
    GtkTreeModel *model;
    GtkTreeIter iter;
    gint column = 0;
    GList *list_tmp;

    model = gtk_tree_view_get_model ( tree_view );
    if ( !gtk_tree_model_get_iter ( model, &iter, tree_path_to_print ) )
        return line_position;

    if ( nbre_lines_col_data == 1 )
    {
        list_tmp = gtk_tree_view_get_columns ( tree_view );
        while ( list_tmp )
        {
            GtkTreeViewColumn *col;
            gchar *text;
            gint column_position;
            gint col_num_model;
            GType col_type_model;

            col = list_tmp -> data;
            col_num_model = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( col ), "num_col_model" ) );
            col_type_model = gtk_tree_model_get_column_type ( model, col_num_model );
            column_position = columns_position[column];

            /* get the text */
            if ( col_type_model == G_TYPE_STRING )
                gtk_tree_model_get ( model, &iter, col_num_model, &text, -1 );
            else if ( col_type_model == G_TYPE_INT )
            {
                gint number;

                gtk_tree_model_get ( model, &iter, col_num_model, &number, -1 );
                text = utils_str_itoa ( number );
            }
            else
                text = NULL;

            if ( !text )
            {
                /* draw first the column */
                column_position = print_tree_view_list_draw_column ( column_position, line_position );

                list_tmp  = list_tmp -> next;
                column++;
                continue;
            }

            print_tree_view_list_draw_cell ( context, line_position, column_position, column, text );
            list_tmp  = list_tmp -> next;
            column++;
            g_free ( text );
        }
        /* go to the next row */
        line_position = line_position + size_row;
    }
    else
    {
        gchar **tab;
        gchar *str_tmp;
        gint i = 0;

        for ( i = 0; i < nbre_lines_col_data; i ++ )
        {
            /* draw the last column */
            print_tree_view_list_draw_column ( page_width, line_position );
            list_tmp = gtk_tree_view_get_columns ( tree_view );

            while ( list_tmp )
            {
                GtkTreeViewColumn *col;
                gchar *text;
                gint column_position;
                gint col_num_model;
                GType col_type_model;

                col = ( GtkTreeViewColumn * ) list_tmp -> data;
                col_num_model = GPOINTER_TO_INT ( g_object_get_data ( G_OBJECT ( col ), "num_col_model" ) );
                col_type_model = gtk_tree_model_get_column_type ( model, col_num_model );
                column_position = columns_position[column];

                /* get the text */
                if ( col_type_model == G_TYPE_STRING )
                    gtk_tree_model_get ( model, &iter, col_num_model, &text, -1 );
                else if ( col_type_model == G_TYPE_INT )
                {
                    gint number;

                    gtk_tree_model_get ( model, &iter, col_num_model, &number, -1 );
                    text = utils_str_itoa ( number );
                }
                else
                    text = NULL;

                if ( text == NULL || strlen ( text ) == 0 )
                {
                    print_tree_view_list_draw_column ( column_position, line_position );
                    list_tmp  = list_tmp -> next;
                    column++;
                    continue;
                }

                str_tmp = gsb_string_uniform_new_line ( text, strlen ( text ) );
                if ( str_tmp == NULL )
                {
                    if ( i == 0 )
                        print_tree_view_list_draw_cell ( context, line_position, column_position, column, text );
                    else
                        print_tree_view_list_draw_column ( column_position, line_position );
                    list_tmp  = list_tmp -> next;
                    column++;
                    continue;
                }

                tab = g_strsplit ( str_tmp, "\n", 0 );

                if ( tab[i] && strlen ( tab[i] ) )
                    print_tree_view_list_draw_cell ( context, line_position, column_position, column, tab[i] );
                else
                    print_tree_view_list_draw_column ( column_position, line_position );

                list_tmp  = list_tmp -> next;
                column++;
                g_strfreev ( tab );
                g_free ( str_tmp );
            }
            line_position = line_position + size_row + gsb_data_print_config_get_draw_lines ( );
            column = 0;
        }
    }

    return line_position;
}