Exemplo n.º 1
0
/**
 * adapte l'utilisation de : en fonction de la langue de l'utilisateur
 *
 *
 *
 * */
gchar *utils_str_incremente_number_from_str ( const gchar *str_number, gint increment )
{
    gchar *new_str_number;
    gchar *prefix = NULL;
    gint number = 0;
    gint i = 0;

    if ( str_number && strlen ( str_number ) > 0 )
    {
        while ( str_number[i] == '0' )
        {
            i++;
        }
        if ( i > 0 )
            prefix = g_strndup ( str_number, i );

        number = utils_str_atoi ( str_number );
    }

    number += increment;

    new_str_number = utils_str_itoa ( number );

    if ( prefix && strlen ( prefix ) > 0 )
    {
        new_str_number = g_strconcat ( prefix, new_str_number, NULL );
        g_free ( prefix );
    }

    return new_str_number;
}
Exemplo n.º 2
0
static gboolean gsb_csv_export_tree_view_list_foreach_callback ( GtkTreeModel *model,
                        GtkTreePath *path,
                        GtkTreeIter *iter,
                        FILE *csv_file )
{
    GtkTreeView *tree_view;
    GList *list;
    GList *list_tmp;
    gint depth;

    /* on n'exporte que les lignes de plus haut niveau */
    depth = gtk_tree_path_get_depth ( path );
    if ( depth > 1 )
        return FALSE;

    tree_view = g_object_get_data ( G_OBJECT ( model ), "tree_view" );
    list = gtk_tree_view_get_columns ( tree_view );
    list_tmp = list;

    while ( list_tmp )
    {
        GtkTreeViewColumn *col;
        gchar *text;
        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 );

        /* 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;

        CSV_STR_FIELD ( csv_file, text );
        CSV_CLEAR_FIELD ( text );

        list_tmp  = list_tmp -> next;
    }

    CSV_END_RECORD( csv_file );

    return FALSE;
}
Exemplo n.º 3
0
/**
 * set the user frequency in the form's scheduled part
 *
 * \param user_freq the user frequency number
 *
 * \return TRUE if ok, FALSE else
 * */
gboolean gsb_form_scheduler_set_frequency_user ( gint user_freq )
{
    GtkWidget *entry;
    gchar *string;

    entry = gsb_form_scheduler_get_element_widget(SCHEDULED_FORM_FREQUENCY_USER_ENTRY);
    /* if no entry, go away... */
    if (!entry
	||
	!GTK_WIDGET_VISIBLE (entry))
	return FALSE;

    string = utils_str_itoa (user_freq);
    if (!string)
	return FALSE;

    gsb_form_widget_set_empty (entry, FALSE);
    gtk_entry_set_text ( GTK_ENTRY (entry), string);
    g_free ( string ) ;

    return TRUE;
}
Exemplo n.º 4
0
gchar *utils_str_dtostr ( gdouble number, gint nbre_decimal, gboolean canonical )
{
    gchar buffer[G_ASCII_DTOSTR_BUF_SIZE];
    gchar *str_number;
    gchar *decimal;
    gchar *format;
    gint nbre_char;

    decimal = utils_str_itoa ( nbre_decimal );
    format = g_strconcat ( "%.", decimal, "f", NULL );
    nbre_char = g_sprintf ( buffer, format, number );
    g_free ( decimal );
    g_free ( format );

    if ( nbre_char > G_ASCII_DTOSTR_BUF_SIZE )
        return NULL;

    str_number = g_strndup ( buffer, nbre_char );

    if ( canonical && g_strrstr ( str_number, "," ) )
        str_number = my_strdelimit ( str_number, ",", "." );

    return str_number;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
/**
 * remplit le modèle qu'il crée et attache au GtkIconView
 *
 * \param nom de l'icône initiale ou NULL
 *
 * \return un GtkTreePath qui donne la position de l'icône passée
 * en paramètre
 * */
GtkTreePath * gsb_select_icon_fill_icon_view (  gchar * name_icon )

{
    GDir *dir;
    GError *error = NULL;
    GtkTreePath *tree_path = NULL;


    devel_debug ( path_icon );

    dir = g_dir_open ( path_icon, 0, &error );
    if ( dir )
    {
        GtkListStore *store;
        GtkTreeIter iter;
        GdkPixbuf *pixbuf;
        GSList *liste = NULL;
        gint i = 0;
        const gchar *name = NULL;

        while ( (name = g_dir_read_name ( dir ) ) )
        {
            liste = g_slist_append ( liste, g_strdup ( name ) );
        }
        liste = g_slist_sort ( liste, (GCompareFunc) my_strcasecmp );
        store = gtk_list_store_new (3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_POINTER);
        while ( liste )
        {
            gchar *tmpstr = g_strconcat ( path_icon, G_DIR_SEPARATOR_S,
                            liste -> data, NULL );
            if ( g_strcmp0 ( tmpstr, name_icon ) == 0 )
            {
                gchar *tmpstr = utils_str_itoa ( i );
                tree_path = gtk_tree_path_new_from_string ( tmpstr );
                g_free ( tmpstr );
            }
            pixbuf = gdk_pixbuf_new_from_file_at_size ( tmpstr, 32, 32, NULL);
            if ( pixbuf )
            {
                gchar *tmpstr;

                gtk_list_store_append ( store, &iter );
                tmpstr = gsb_select_icon_troncate_name_icon ( liste -> data, 10 );
                gtk_list_store_set (store, &iter, PIXBUF_COLUMN, pixbuf,
                            TEXT_COLUMN, tmpstr, -1);
                g_free ( tmpstr );
                g_object_unref (pixbuf);
            }

            g_free ( tmpstr );
            liste = liste -> next;
            i++;
        }
        gtk_icon_view_set_model (GTK_ICON_VIEW ( icon_view ), GTK_TREE_MODEL (store));
        g_dir_close ( dir );
    }
    else
    {
        dialogue_error ( error -> message );
        g_error_free ( error );
    }

    if ( tree_path == NULL )
        tree_path = gtk_tree_path_new_from_string ( "0" );
    return tree_path;
}