~jcowgill/ubuntu/trusty/easytag/bug-1295882

« back to all changes in this revision

Viewing changes to src/picture.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-04-15 15:47:47 UTC
  • mfrom: (1.2.2 upstream) (3.1.1 dapper)
  • Revision ID: james.westby@ubuntu.com-20060415154747-vr4eqoxwcrgs2ps1
* New upstream version:
  - New logo and icons,
  - Added ability to display all albums of an artist in the 'Artist / Album'
    view,
  - Added detection of the bugged version of id3lib when writting ID3 tag to 
    Unicode to inform the user (a patch for id3lib is supplied in package
    source),
  - For Ogg files, the field DESCRIPTION is also used for the comment,
  - Fixed stack corruption bugs in Fill Tag scanner,
  - Fixed loading disk number for FLAC tag,
  - Fixed error that displays MP3 files in red when no tag is present,
  - Fixed a crash in the CDDB window when getting tracks of a album,
  - Fixed playlist name bug when creating it in the parent directory,
  - Fixed manual CDDB search when using Squid,
  - Little fix for FLAC tags,
  - Fixed various bugs,
  - Russian translation updated,
  - Greek translation updated,
  - Spanish translation updated,
  - Japanese translation updated,
  - Czech translation updated,
  - Brazilian Portuguese translation updated
  - Danish translation updated,
  - Italian translation updated,
  - Hungarian translation updated,
  - German translation updated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* picture.c - 2004/11/21 */
2
2
/*
3
3
 *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
4
 
 *  Copyright (C) 2000-2003  Jerome Couderc <j.couderc@ifrance.com>
 
4
 *  Copyright (C) 2000-2003  Jerome Couderc <easytag@gmail.com>
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
25
25
#include <gdk/gdk.h>
26
26
#include <glib/gi18n-lib.h>
27
27
#include <sys/types.h>
 
28
#include <sys/stat.h>
28
29
#include <fcntl.h>
29
30
#include <string.h>
30
31
#include <stdio.h>
36
37
#include "misc.h"
37
38
#include "setting.h"
38
39
#include "msgbox.h"
 
40
#include "bar.h"
39
41
#include "charset.h"
40
42
 
 
43
#ifdef WIN32
 
44
#   include "win32dep.h"
 
45
#endif
 
46
 
41
47
 
42
48
/****************
43
49
 * Declarations *
68
74
 
69
75
Picture *Picture_Allocate (void);
70
76
Picture *Picture_Copy_One (const Picture *pic);
71
 
Picture *Picture_Copy (const Picture *pic);
72
 
void     Picture_Free (Picture *pic);
 
77
Picture *Picture_Copy     (const Picture *pic);
 
78
void     Picture_Free     (Picture *pic);
73
79
Picture *Picture_Load_File_Data (const gchar *filename);
74
80
gboolean Picture_Save_File_Data (const Picture *pic, const gchar *filename);
75
81
 
77
83
gboolean Picture_Entry_View_Key_Pressed    (GtkTreeView *treeview, GdkEvent *event, gpointer data);
78
84
 
79
85
 
 
86
/*
 
87
 * Note :
 
88
 * -> MP4_TAG :
 
89
 *      Just has one picture (PICTURE_TYPE_FRONT_COVER).
 
90
 *      The format's don't matter to the MP4 side.
 
91
 *
 
92
 */
 
93
 
80
94
/*************
81
95
 * Functions *
82
96
 *************/
90
104
 
91
105
    gtk_drag_finish(dc, TRUE, FALSE, t);
92
106
 
93
 
    if (info != TARGET_URI_LIST)
94
 
        return;
95
 
    if (!selection_data)
 
107
    if (info != TARGET_URI_LIST
 
108
    ||  !selection_data
 
109
    ||  !PictureEntryView)
96
110
        return;
97
111
 
98
112
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
99
113
    gtk_tree_selection_unselect_all(selection);
100
114
    
101
 
    uri = uri_list = g_strsplit(selection_data->data, "\r\n", 0);
 
115
    uri = uri_list = g_strsplit((const gchar *)selection_data->data, "\r\n", 0);
102
116
    while (*uri && strlen(*uri))
103
117
    {
104
118
        //Picture *pic;
140
154
    gpointer proxy;
141
155
    gint n = 0;
142
156
    
 
157
    if (!PictureEntryView) return;
 
158
 
143
159
    model = gtk_tree_view_get_model(GTK_TREE_VIEW(PictureEntryView));
144
160
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
145
161
    paths = gtk_tree_selection_get_selected_rows(selection, 0);
146
162
    proxy = g_object_newv(G_TYPE_OBJECT, 0, NULL);
147
163
 
 
164
    // List of items to delete
148
165
    for (node = paths; node; node = node->next)
149
166
    {
150
167
        refs = g_list_append(refs, gtk_tree_row_reference_new_proxy(proxy, model, node->data));
175
192
        PictureEntry_Clear();
176
193
}
177
194
 
 
195
/*
 
196
 * - 'filename' : path + filename of picture file
 
197
 */
178
198
void Picture_Load_Filename (gchar *filename, gpointer user_data)
179
199
{
180
200
    Picture *pic;
181
201
    gchar *filename_utf8;
 
202
    gchar *filename_utf8_folded = NULL;
 
203
    gchar *front_folded = NULL;
 
204
    gchar *back_folded = NULL;
 
205
    gchar *cd_folded = NULL;
 
206
    gchar *inside_folded = NULL;
 
207
    //gchar *inlay_folded = NULL;
182
208
    
 
209
    // Filename must be passed in filesystem encoding!
 
210
    pic = Picture_Load_File_Data(filename);
 
211
 
183
212
    filename_utf8 = filename_to_display(filename);
184
 
    pic = Picture_Load_File_Data(filename_utf8);
185
 
    
186
 
    // By default, set the filename in the description
187
 
    pic->description = g_path_get_basename(filename_utf8);
 
213
 
 
214
    if (pic && filename_utf8)
 
215
    {
 
216
        // Behaviour following the tag type...
 
217
        switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
 
218
        {
 
219
            case MP4_TAG:
 
220
            {
 
221
                pic->type = PICTURE_TYPE_FRONT_COVER;
 
222
                break;
 
223
            }
 
224
            
 
225
            // Other tag types
 
226
            default:
 
227
            {
 
228
                // By default, set the filename in the description
 
229
                pic->description = g_path_get_basename(filename_utf8);
 
230
                
 
231
                // Try to identify the type of the picture from the file name
 
232
                filename_utf8_folded = g_utf8_casefold(pic->description, -1);
 
233
                front_folded         = g_utf8_casefold("Front", -1);
 
234
                back_folded          = g_utf8_casefold("Back", -1);
 
235
                cd_folded            = g_utf8_casefold("CD", -1);
 
236
                inside_folded        = g_utf8_casefold("inside", -1);
 
237
                //inlay_folded         = g_utf8_casefold("inlay", -1);
 
238
                if ( strstr(filename_utf8_folded, front_folded) != NULL )
 
239
                    pic->type = PICTURE_TYPE_FRONT_COVER;
 
240
                else if ( strstr(filename_utf8_folded, back_folded) != NULL )
 
241
                    pic->type = PICTURE_TYPE_BACK_COVER;
 
242
                else if ( strstr(filename_utf8_folded, cd_folded) != NULL )
 
243
                    pic->type = PICTURE_TYPE_MEDIA;
 
244
                else if ( strstr(filename_utf8_folded, inside_folded) != NULL )
 
245
                    pic->type = PICTURE_TYPE_LEAFLET_PAGE;
 
246
                //else if ( strstr(filename_utf8_folded, inlay_folded) != NULL )
 
247
                //    pic->type = PICTURE_TYPE_LEAFLET_PAGE;
 
248
 
 
249
                break;
 
250
            }
 
251
        }
 
252
 
 
253
        PictureEntry_Update(pic, 1);
 
254
 
 
255
        // FIXME: Call Picture_Free(pic) here? It seems PictureEntry_Update makes copies of pic.
 
256
        //Picture_Free(pic);
 
257
    }
188
258
    
189
259
    g_free(filename_utf8);
190
 
    
191
 
    if (pic)
192
 
        PictureEntry_Update(pic, 1);
 
260
    g_free(filename_utf8_folded);
 
261
    g_free(front_folded);
 
262
    g_free(back_folded);
 
263
    g_free(cd_folded);
 
264
    g_free(inside_folded);
 
265
    //g_free(inlay_folded);
193
266
}
194
267
 
195
268
/*
202
275
    GtkWindow *parent_window = NULL;
203
276
    static gchar *init_dir = NULL;
204
277
 
 
278
    if (!PictureEntryView) return;
 
279
 
205
280
    parent_window = (GtkWindow *) gtk_widget_get_toplevel(GTK_WIDGET(object));
206
281
    if (!GTK_WIDGET_TOPLEVEL(parent_window))
207
282
    {
241
316
    else if (MESSAGE_BOX_POSITION_MOUSE)
242
317
        gtk_window_set_position(GTK_WINDOW(FileSelectionWindow),GTK_WIN_POS_MOUSE);
243
318
    
244
 
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(FileSelectionWindow), TRUE);
245
 
    gtk_dialog_set_default_response(GTK_DIALOG(FileSelectionWindow), GTK_RESPONSE_CANCEL);
 
319
    // Behaviour following the tag type...
 
320
    switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
 
321
    {
 
322
        case MP4_TAG:
 
323
        {
 
324
            gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(FileSelectionWindow), FALSE);
 
325
            break;
 
326
        }
 
327
        
 
328
        // Other tag types
 
329
        default:
 
330
        {
 
331
            gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(FileSelectionWindow), TRUE);
 
332
            break;
 
333
        }
 
334
    }
 
335
 
 
336
    gtk_dialog_set_default_response(GTK_DIALOG(FileSelectionWindow), GTK_RESPONSE_OK);
246
337
    if (init_dir)
247
338
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow),init_dir);
248
339
 
306
397
        };
307
398
 
308
399
 
 
400
    if (!PictureEntryView) return;
 
401
 
309
402
    parent_window = (GtkWindow *) gtk_widget_get_toplevel(GTK_WIDGET(object));
310
403
    if (!GTK_WIDGET_TOPLEVEL(parent_window))
311
404
    {
323
416
        Picture *pic;
324
417
        GtkTreeSelection *selectiontype;
325
418
        gchar *title;
326
 
        
327
 
        
 
419
        GtkTreePath *rowPath;
 
420
 
328
421
        // Get corresponding picture
329
422
        gtk_tree_model_get_iter(GTK_TREE_MODEL(model), &iter, path);
330
423
        gtk_tree_model_get(GTK_TREE_MODEL(model), &iter, PICTURE_COLUMN_DATA, &pic, -1);
367
460
        gtk_widget_set_size_request(type, 256, 256);
368
461
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(PictureTypesWindow)->vbox),ScrollWindowPictureTypes,TRUE,TRUE,0);
369
462
    
370
 
        // Load pictures types
371
 
        for (i = 0; i < sizeof(picture_types)/sizeof(picture_types[0]); i++)
 
463
        // Behaviour following the tag type...
 
464
        switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
372
465
        {
373
 
            GtkTreeIter itertype;
374
 
            
375
 
            gtk_list_store_append(store, &itertype);
376
 
            gtk_list_store_set(store, &itertype,
377
 
                               PICTURE_TYPE_COLUMN_TEXT, _(Picture_Type_String(picture_types[i])),
378
 
                               PICTURE_TYPE_COLUMN_TYPE_CODE, picture_types[i],
379
 
                               -1);
380
 
            // Line to select by default
381
 
            if (pic->type == picture_types[i])
 
466
            case MP4_TAG:
 
467
            {
 
468
                // Load picture type (only Front Cover!)
 
469
                GtkTreeIter itertype;
 
470
                
 
471
                gtk_list_store_append(store, &itertype);
 
472
                gtk_list_store_set(store, &itertype,
 
473
                                   PICTURE_TYPE_COLUMN_TEXT, _(Picture_Type_String(PICTURE_TYPE_FRONT_COVER)),
 
474
                                   PICTURE_TYPE_COLUMN_TYPE_CODE, PICTURE_TYPE_FRONT_COVER,
 
475
                                   -1);
 
476
                // Line to select by default
382
477
                type_iter_to_select = itertype;
 
478
                break;
 
479
            }
 
480
            
 
481
            // Other tag types
 
482
            default:
 
483
            {
 
484
                // Load pictures types
 
485
                for (i = 0; i < sizeof(picture_types)/sizeof(picture_types[0]); i++)
 
486
                {
 
487
                    GtkTreeIter itertype;
 
488
                    
 
489
                    gtk_list_store_append(store, &itertype);
 
490
                    gtk_list_store_set(store, &itertype,
 
491
                                       PICTURE_TYPE_COLUMN_TEXT, _(Picture_Type_String(picture_types[i])),
 
492
                                       PICTURE_TYPE_COLUMN_TYPE_CODE, picture_types[i],
 
493
                                       -1);
 
494
                    // Line to select by default
 
495
                    if (pic->type == picture_types[i])
 
496
                        type_iter_to_select = itertype;
 
497
                }
 
498
                break;
 
499
            }
383
500
        }
 
501
        
384
502
        // Select the line by default
385
503
        selectiontype = gtk_tree_view_get_selection(GTK_TREE_VIEW(type));
386
504
        gtk_tree_selection_select_iter(selectiontype, &type_iter_to_select);
387
505
 
 
506
        // Set visible the current selected line
 
507
        rowPath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &type_iter_to_select);
 
508
        gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(type), rowPath, NULL, FALSE, 0, 0);
 
509
        gtk_tree_path_free(rowPath);
 
510
 
388
511
        // Description
389
512
        label = gtk_label_new(_("Picture Description:"));
390
513
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(PictureTypesWindow)->vbox),label,FALSE,FALSE,4);
393
516
        desc = gtk_entry_new();
394
517
        gtk_box_pack_start(GTK_BOX(GTK_DIALOG(PictureTypesWindow)->vbox),desc,FALSE,FALSE,0);
395
518
        if (pic->description)
396
 
            gtk_entry_set_text(GTK_ENTRY(desc), pic->description);
 
519
        {
 
520
            gchar *tmp = ET_Utf8_Validate_Full_String(pic->description);
 
521
            gtk_entry_set_text(GTK_ENTRY(desc), tmp);
 
522
            g_free(tmp);
 
523
        }
397
524
    
 
525
        // Behaviour following the tag type...
 
526
        switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
 
527
        {
 
528
            case MP4_TAG:
 
529
            {
 
530
                gtk_widget_set_sensitive(GTK_WIDGET(label), FALSE);
 
531
                gtk_widget_set_sensitive(GTK_WIDGET(desc), FALSE);
 
532
                break;
 
533
            }
 
534
            
 
535
            // Other tag types
 
536
            default:
 
537
            {
 
538
                break;
 
539
            }
 
540
        }
 
541
        
398
542
        gtk_widget_show_all(PictureTypesWindow);
399
543
        
400
544
        if (gtk_dialog_run(GTK_DIALOG(PictureTypesWindow)) == GTK_RESPONSE_OK)
406
550
            selectiontype = gtk_tree_view_get_selection(GTK_TREE_VIEW(type));
407
551
            if (gtk_tree_selection_get_selected(selectiontype, &modeltype, &itertype))
408
552
            {
409
 
                gchar *buffer;
 
553
                gchar *buffer, *pic_info;
410
554
                gint t;
411
555
                
412
 
                gtk_tree_model_get(modeltype, &itertype, 1, &t, -1); // Get cell 1 value
 
556
                gtk_tree_model_get(modeltype, &itertype,
 
557
                                   PICTURE_TYPE_COLUMN_TYPE_CODE, &t, -1);
413
558
                pic->type = t;
414
559
    
415
560
                buffer = g_strdup(gtk_entry_get_text(GTK_ENTRY(desc)));
425
570
                    g_free(buffer);
426
571
                }
427
572
                
428
 
                // Update value in the Picture view
 
573
                // Update value in the PictureEntryView
 
574
                pic_info = Picture_Info(pic);
429
575
                gtk_list_store_set(GTK_LIST_STORE(model), &iter,
430
 
                                   PICTURE_COLUMN_TEXT,
431
 
                                   Picture_Info(pic),
 
576
                                   PICTURE_COLUMN_TEXT, pic_info,
432
577
                                   -1);
 
578
                g_free(pic_info);
433
579
            }
434
580
        }
435
581
        gtk_widget_destroy(PictureTypesWindow);
440
586
}
441
587
 
442
588
 
443
 
/************
444
 
void save_selected_pic (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gchar *filename)
445
 
{
446
 
    Picture *pic;
447
 
    
448
 
    gtk_tree_model_get(model, iter, PICTURE_COLUMN_DATA, &pic, -1);
449
 
    Picture_Save_File_Data(pic, filename);
450
 
}
451
 
 
452
 
void get_selected_pic (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, GtkTreeIter *iter_set)
453
 
{
454
 
    *iter_set = *iter;
455
 
}
456
 
 
457
 
void Picture_Properties_Button_Clicked (GObject *object)
458
 
{
459
 
    GtkWidget *dialog, *type, *label, *desc;
460
 
    GtkWidget *ScrollWindowPictureTypes;
461
 
    GtkCellRenderer *renderer;
462
 
    GtkTreeViewColumn *column;
463
 
    GtkTreeSelection *selection;
464
 
    GtkListStore *store;
465
 
    Picture *pic;
466
 
    GtkTreeModel *model2;
467
 
    GtkTreeIter iter2, default_type_iter;
468
 
    GtkWindow *parent_window = NULL;
469
 
    
470
 
    gint picture_types[] = 
471
 
        {
472
 
            PICTURE_TYPE_OTHER,
473
 
            PICTURE_TYPE_FILE_ICON,
474
 
            PICTURE_TYPE_OTHER_FILE_ICON,
475
 
            PICTURE_TYPE_FRONT_COVER,
476
 
            PICTURE_TYPE_BACK_COVER,
477
 
            PICTURE_TYPE_LEAFLET_PAGE,
478
 
            PICTURE_TYPE_MEDIA,
479
 
            PICTURE_TYPE_LEAD_ARTIST_LEAD_PERFORMER_SOLOIST,
480
 
            PICTURE_TYPE_ARTIST_PERFORMER,
481
 
            PICTURE_TYPE_CONDUCTOR,
482
 
            PICTURE_TYPE_BAND_ORCHESTRA,
483
 
            PICTURE_TYPE_COMPOSER,
484
 
            PICTURE_TYPE_LYRICIST_TEXT_WRITER,
485
 
            PICTURE_TYPE_RECORDING_LOCATION,
486
 
            PICTURE_TYPE_DURING_RECORDING,
487
 
            PICTURE_TYPE_DURING_PERFORMANCE,
488
 
            PICTURE_TYPE_MOVIDE_VIDEO_SCREEN_CAPTURE,
489
 
            PICTURE_TYPE_A_BRIGHT_COLOURED_FISH,
490
 
            PICTURE_TYPE_ILLUSTRATION,
491
 
            PICTURE_TYPE_BAND_ARTIST_LOGOTYPE,
492
 
            PICTURE_TYPE_PUBLISHER_STUDIO_LOGOTYPE
493
 
        };
494
 
    gint i;
495
 
    
496
 
    parent_window = (GtkWindow *) gtk_widget_get_toplevel(GTK_WIDGET(object));
497
 
    if (!GTK_WIDGET_TOPLEVEL(parent_window))
498
 
    {
499
 
        g_warning("Could not get parent window\n");
500
 
        return;
501
 
    }
502
 
 
503
 
    model2 = gtk_tree_view_get_model(GTK_TREE_VIEW(PictureEntryView));
504
 
    gtk_tree_selection_selected_foreach(gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView)),
505
 
                                        (GtkTreeSelectionForeachFunc) get_selected_pic, &iter2);
506
 
    gtk_tree_model_get(model2, &iter2, PICTURE_COLUMN_DATA, &pic, -1);
507
 
    
508
 
    dialog = gtk_dialog_new_with_buttons(_("Picture Properties"),
509
 
                                         parent_window,
510
 
                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
511
 
                                         GTK_STOCK_CANCEL,
512
 
                                         GTK_RESPONSE_REJECT,
513
 
                                         GTK_STOCK_OK,
514
 
                                         GTK_RESPONSE_ACCEPT,
515
 
                                         NULL);
516
 
 
517
 
    // Set window position
518
 
    if (MESSAGE_BOX_POSITION_NONE)
519
 
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_NONE);
520
 
    else if (MESSAGE_BOX_POSITION_CENTER)
521
 
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
522
 
    else if (MESSAGE_BOX_POSITION_MOUSE)
523
 
        gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_MOUSE);
524
 
 
525
 
    ScrollWindowPictureTypes = gtk_scrolled_window_new(NULL, NULL);
526
 
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ScrollWindowPictureTypes),
527
 
                                   GTK_POLICY_AUTOMATIC,
528
 
                                   GTK_POLICY_AUTOMATIC);
529
 
    store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
530
 
    type = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
531
 
    gtk_container_add(GTK_CONTAINER(ScrollWindowPictureTypes), type);
532
 
    
533
 
    renderer = gtk_cell_renderer_text_new();
534
 
    column = gtk_tree_view_column_new();
535
 
    gtk_tree_view_column_pack_start(column, renderer, FALSE);
536
 
    gtk_tree_view_column_set_title(column, _("Picture Type"));
537
 
    gtk_tree_view_column_set_attributes(column, renderer,
538
 
                                        "text", 0,
539
 
                                        NULL);
540
 
    gtk_tree_view_append_column(GTK_TREE_VIEW(type), column);
541
 
    gtk_widget_set_size_request(type, 256, 256);
542
 
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),ScrollWindowPictureTypes,TRUE,TRUE,0);
543
 
 
544
 
    // Load pictures types
545
 
    for (i = 0; i < sizeof(picture_types)/sizeof(picture_types[0]); i++)
546
 
    {
547
 
          GtkTreeIter iter;
548
 
          
549
 
          gtk_list_store_append(store, &iter);
550
 
          gtk_list_store_set(store, &iter,
551
 
                             0, _(Picture_Type_String(picture_types[i])),
552
 
                             1, picture_types[i],
553
 
                             -1);
554
 
          if (pic->type == picture_types[i])
555
 
              default_type_iter = iter;
556
 
    }
557
 
 
558
 
    label = gtk_label_new(_("Picture Description:"));
559
 
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),label,FALSE,FALSE,4);
560
 
 
561
 
    // Entry for the description
562
 
    desc = gtk_entry_new();
563
 
    if (pic->description)
564
 
        gtk_entry_set_text(GTK_ENTRY(desc), pic->description);
565
 
    
566
 
    gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),desc,FALSE,FALSE,0);
567
 
 
568
 
    gtk_widget_show_all(dialog);
569
 
    gtk_tree_selection_select_iter(gtk_tree_view_get_selection(GTK_TREE_VIEW(type)),
570
 
                                   &default_type_iter);
571
 
    
572
 
    if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
573
 
    {
574
 
        GtkTreeModel *model;
575
 
        GtkTreeIter iter;
576
 
        
577
 
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(type));
578
 
        selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(type));
579
 
        if (gtk_tree_selection_get_selected(selection, &model, &iter))
580
 
        {
581
 
            gchar *buffer;
582
 
            gint t;
583
 
            
584
 
            gtk_tree_model_get(model, &iter, 1, &t, -1);
585
 
            pic->type = t;
586
 
 
587
 
            buffer = g_strdup(gtk_entry_get_text(GTK_ENTRY(desc)));
588
 
            Strip_String(buffer);
589
 
            if (pic->description)
590
 
                g_free(pic->description);
591
 
            if ( g_utf8_strlen(buffer, -1) > 0 )
592
 
            {
593
 
                pic->description = buffer;
594
 
            }else
595
 
            {
596
 
                pic->description = 0;
597
 
                g_free(buffer);
598
 
            }
599
 
            
600
 
            gtk_list_store_set(GTK_LIST_STORE(model2), &iter2,
601
 
                               PICTURE_TEXT_COLUMN,
602
 
                               Picture_Info(pic),
603
 
                               -1);
604
 
        }
605
 
    }
606
 
    gtk_widget_destroy(dialog);
607
 
}
608
 
 
609
 
void Picture_Save_Button_Clicked (GObject *object)
610
 
{
611
 
    GtkWidget *FileSelectionWindow;
612
 
    GtkWindow *parent_window = NULL;
613
 
    static gchar *init_dir = NULL;
614
 
 
615
 
    parent_window = (GtkWindow*) gtk_widget_get_toplevel(GTK_WIDGET(object));
616
 
    if (!GTK_WIDGET_TOPLEVEL(parent_window))
617
 
    {
618
 
        g_warning("Could not get parent window\n");
619
 
        return;
620
 
    }
621
 
 
622
 
    FileSelectionWindow = gtk_file_chooser_dialog_new(_("Save picture"),
623
 
                                                      parent_window,
624
 
                                                      GTK_FILE_CHOOSER_ACTION_SAVE,
625
 
                                                      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
626
 
                                                      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
627
 
                                                      NULL);
628
 
    // Set the default folder if defined
629
 
    if (init_dir)
630
 
        gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow),init_dir);
631
 
 
632
 
    if (gtk_dialog_run(GTK_DIALOG(FileSelectionWindow)) == GTK_RESPONSE_ACCEPT)
633
 
    {
634
 
        gchar *filename, *filename_utf8;
635
 
    
636
 
        filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(FileSelectionWindow));
637
 
        filename_utf8 = filename_to_display(filename);
638
 
        gtk_tree_selection_selected_foreach(gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView)),
639
 
            (GtkTreeSelectionForeachFunc) save_selected_pic, filename_utf8);
640
 
        g_free(filename_utf8);
641
 
 
642
 
        // Save the directory selected for initialize next time
643
 
        g_free(init_dir);
644
 
        init_dir = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(FileSelectionWindow));
645
 
    }
646
 
    gtk_widget_destroy(FileSelectionWindow);
647
 
}
648
 
*********/
649
589
void Picture_Save_Button_Clicked (GObject *object)
650
590
{
651
591
    GtkWidget *FileSelectionWindow;
659
599
    gint selection_nbr, selection_i = 1;
660
600
 
661
601
 
 
602
    if (!PictureEntryView) return;
 
603
 
662
604
    parent_window = (GtkWindow*) gtk_widget_get_toplevel(GTK_WIDGET(object));
663
605
    if (!GTK_WIDGET_TOPLEVEL(parent_window))
664
606
    {
670
612
    selection      = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
671
613
    selection_list = gtk_tree_selection_get_selected_rows(selection, NULL);
672
614
    selection_nbr  = gtk_tree_selection_count_selected_rows(GTK_TREE_SELECTION(selection));
 
615
 
673
616
    while (selection_list)
674
617
    {
675
618
        GtkTreePath *path = selection_list->data;
878
821
 
879
822
gchar *Picture_Info (Picture *pic)
880
823
{
881
 
    gchar *format, *desc, *type, *r;
 
824
    gchar *format, *desc, *type, *r, *size_str;
882
825
    GString *s;
883
826
 
884
827
    format = (gchar *)Picture_Format_String(Picture_Format(pic));
889
832
        desc = "";
890
833
 
891
834
    type = (gchar *)Picture_Type_String(pic->type);
 
835
    size_str = Convert_Size_1((gfloat)pic->size);
892
836
 
893
837
    s = g_string_new(0);
894
 
    g_string_sprintf(s, "%s (%s - %dx%d %s)\n%s: %s\n%s: %s",
895
 
                     format, 
896
 
                     Convert_Size_1((gfloat)pic->size),
897
 
                     pic->width, pic->height, _("pixels"),
898
 
                     _("Type"), type,
899
 
                     _("Description"), desc);
900
 
    r = s->str;
901
 
    g_string_free(s, FALSE);
 
838
    // Behaviour following the tag type...
 
839
    switch (ETCore->ETFileDisplayed->ETFileDescription->TagType)
 
840
    {
 
841
        case MP4_TAG:
 
842
        {
 
843
            g_string_sprintf(s, "%s (%s - %dx%d %s)\n%s: %s",
 
844
                             format, 
 
845
                             size_str,
 
846
                             pic->width, pic->height, _("pixels"),
 
847
                             _("Type"), type);
 
848
            break;
 
849
        }
 
850
        
 
851
        // Other tag types
 
852
        default:
 
853
        {
 
854
            g_string_sprintf(s, "%s (%s - %dx%d %s)\n%s: %s\n%s: %s",
 
855
                             format, 
 
856
                             size_str,
 
857
                             pic->width, pic->height, _("pixels"),
 
858
                             _("Type"), type,
 
859
                             _("Description"), desc);
 
860
            break;
 
861
        }
 
862
    }
 
863
    r = ET_Utf8_Validate_Full_String(s->str);
 
864
    g_string_free(s, TRUE); // TRUE to free also 's->str'!
 
865
    g_free(size_str);
 
866
    
902
867
    return r;
903
868
}
904
869
 
927
892
void PictureEntry_Update (Picture *pic, gint select)
928
893
{
929
894
    GdkPixbufLoader *loader = 0;
930
 
    
 
895
 
 
896
    if (!pic || !PictureEntryView) return;
 
897
 
931
898
    if (!pic->data)
932
899
    {
933
900
        PictureEntry_Clear();
952
919
                GdkPixbuf *scaled_pixbuf;
953
920
                gint scaled_pixbuf_width;
954
921
                gint scaled_pixbuf_height;
 
922
                gchar *pic_info;
955
923
                
956
924
                // Keep aspect ratio of the picture
957
 
                pic->width = gdk_pixbuf_get_width (pixbuf);
 
925
                pic->width  = gdk_pixbuf_get_width (pixbuf);
958
926
                pic->height = gdk_pixbuf_get_height (pixbuf);
959
927
                if (pic->width > pic->height)
960
928
                {
974
942
            
975
943
                picture_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(PictureEntryView)));
976
944
                gtk_list_store_append(picture_store, &iter1);
 
945
                pic_info = Picture_Info(pic);
977
946
                gtk_list_store_set(picture_store, &iter1,
978
947
                                   PICTURE_COLUMN_PIC, scaled_pixbuf,
979
 
                                   PICTURE_COLUMN_TEXT, Picture_Info(pic),
 
948
                                   PICTURE_COLUMN_TEXT, pic_info,
980
949
                                   PICTURE_COLUMN_DATA, Picture_Copy_One(pic),
981
950
                                   -1);
 
951
                g_free(pic_info);
 
952
                
982
953
                if (select)
983
954
                    gtk_tree_selection_select_iter(selection, &iter1);
984
955
                gdk_pixbuf_unref(scaled_pixbuf);
 
956
            }else
 
957
            {
 
958
                GtkWidget *msgbox = NULL;
 
959
                gchar *msg = NULL;
 
960
                
 
961
                msg = g_strdup(_("Can't display the picture, as not enough data "
 
962
                    "has been read to determine how to create the image buffer."));
 
963
                g_print("%s\n",msg);
 
964
                msgbox = msg_box_new (_("Loading Picture File..."),msg,
 
965
                    GTK_STOCK_DIALOG_ERROR,BUTTON_YES,0);
 
966
                msg_box_hide_check_button(MSG_BOX(msgbox));
 
967
                g_free(msg);
 
968
                msg_box_run(MSG_BOX(msgbox));
 
969
                gtk_widget_destroy(msgbox);
985
970
            }
986
971
        }
987
972
    }
990
975
    // Do also for next picture
991
976
    if (pic->next)
992
977
        PictureEntry_Update(pic->next, select);
 
978
    
 
979
    return;
993
980
}
994
981
 
995
982
 
1007
994
        return 0;
1008
995
    pic2 = Picture_Allocate();
1009
996
    pic2->type = pic->type;
 
997
    pic2->width  = pic->width;
 
998
    pic2->height = pic->height;
1010
999
    if (pic->description)
1011
1000
        pic2->description = g_strdup(pic->description);
1012
1001
    if (pic->data)
1037
1026
    if (pic->data)
1038
1027
        g_free(pic->data);
1039
1028
    g_free(pic);
1040
 
    pic = (Picture *)NULL;
1041
1029
}
1042
1030
 
1043
 
#define LOAD_BUFFER_SIZE 4096
1044
1031
 
 
1032
/*
 
1033
 * Load the picture represented by the 'filename' (must be passed in
 
1034
 * file system encoding, not UTF-8)
 
1035
 */
1045
1036
Picture *Picture_Load_File_Data (const gchar *filename)
1046
1037
{
1047
1038
    Picture *pic;
1048
1039
    gchar *buffer = 0;
1049
1040
    size_t size = 0;
1050
 
    gint fd;
 
1041
    struct stat st;
 
1042
 
 
1043
    if (lstat(filename, &st)==-1)
 
1044
        return (Picture *)NULL;
 
1045
 
 
1046
    size = st.st_size;
 
1047
    buffer = g_malloc(size);
1051
1048
    
1052
 
    fd = open(filename, O_RDONLY);
1053
 
    if (fd == -1)
 
1049
    FILE *fd = fopen(filename, "rb");
 
1050
    if (!fd)
 
1051
    {
 
1052
        gchar *msg;
 
1053
        gchar *filename_utf8;
 
1054
        GtkWidget *msgbox;
 
1055
 
 
1056
        /* Picture file not opened */
 
1057
        filename_utf8 = filename_to_display(filename);
 
1058
        msg = g_strdup_printf(_("Can't open file :\n'%s'!\n(%s)"),
 
1059
                                filename_utf8,g_strerror(errno)); 
 
1060
        msgbox = msg_box_new (_("Error..."),msg,GTK_STOCK_DIALOG_ERROR,BUTTON_OK,0);
 
1061
        g_free(msg);
 
1062
        msg_box_hide_check_button(MSG_BOX(msgbox));
 
1063
        msg_box_run(MSG_BOX(msgbox));
 
1064
        gtk_widget_destroy(msgbox);
 
1065
 
 
1066
        Statusbar_Message(_("Picture file not loaded..."),TRUE);
 
1067
        g_free(filename_utf8);
1054
1068
        return FALSE;
 
1069
    }
1055
1070
    
1056
 
    do
1057
 
    {
1058
 
        ssize_t r;
1059
 
        gchar *p;
1060
 
        
1061
 
        p = g_realloc(buffer, size + LOAD_BUFFER_SIZE);
1062
 
        if (!p)
1063
 
            goto fail;
1064
 
        buffer = p;
1065
 
        
1066
 
        r = read(fd, buffer + size, LOAD_BUFFER_SIZE);
1067
 
        if (r == -1)
1068
 
            goto fail;
1069
 
        if (!r)
1070
 
            break;
1071
 
        
1072
 
        size += r;
1073
 
    } while (1);
1074
 
    close(fd);
 
1071
    if (fread(buffer, size, 1, fd) != 1)
 
1072
      goto fail;
 
1073
 
 
1074
    fclose(fd);
1075
1075
    
1076
1076
    pic = Picture_Allocate();
1077
1077
    pic->size = size;
1081
1081
    fail:
1082
1082
        if (buffer)
1083
1083
            g_free(buffer);
1084
 
        close(fd);
1085
 
        return 0;
 
1084
        fclose(fd);
 
1085
        return (Picture *)NULL;
1086
1086
}
1087
1087
 
1088
1088
/*