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

« back to all changes in this revision

Viewing changes to .pc/taglib.patch/src/easytag.c

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2011-06-09 01:03:44 UTC
  • Revision ID: james.westby@ubuntu.com-20110609010344-ybldr7th761wyquz
Tags: 2.1.6+git20110423-3ubuntu1
* Merge from Debian unstable, remaining Ubuntu changes:
  + debian/control:
    - Add easytag-aac transitional package.
  + debian/install:
    - Install upstream files to easytag binary package.
  + debian/rules:
    - Do not fail on deleting ChangeLog file if it doesn't exist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* easytag.c - 2000/04/28 */
 
2
/*
 
3
 *  EasyTAG - Tag editor for MP3 and Ogg Vorbis files
 
4
 *  Copyright (C) 2000-2003  Jerome Couderc <easytag@gmail.com>
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
 
 
22
#include <config.h> // For definition of ENABLE_OGG
 
23
#include <gtk/gtk.h>
 
24
#include <stdio.h>
 
25
#include <string.h>
 
26
#include <gdk/gdkkeysyms.h>
 
27
#include <glib/gi18n-lib.h>
 
28
#include <stdlib.h>
 
29
#include <sys/stat.h>
 
30
#include <unistd.h>
 
31
#include <errno.h>
 
32
#include <signal.h>
 
33
#ifdef ENABLE_MP3
 
34
#   include <id3tag.h>
 
35
#endif
 
36
#if defined ENABLE_MP3 && defined ENABLE_ID3LIB
 
37
#   include <id3.h>
 
38
#endif
 
39
#include <sys/types.h>
 
40
#include <utime.h>
 
41
 
 
42
#include "easytag.h"
 
43
#include "browser.h"
 
44
#include "log.h"
 
45
#include "misc.h"
 
46
#include "bar.h"
 
47
#include "prefs.h"
 
48
#include "setting.h"
 
49
#include "scan.h"
 
50
#include "mpeg_header.h"
 
51
#include "id3_tag.h"
 
52
#include "ogg_tag.h"
 
53
#include "msgbox.h"
 
54
#include "et_core.h"
 
55
#include "cddb.h"
 
56
#include "picture.h"
 
57
#include "charset.h"
 
58
 
 
59
#ifdef WIN32
 
60
#   include "win32/win32dep.h"
 
61
#endif
 
62
 
 
63
#include "../pixmaps/EasyTAG_icon.xpm"
 
64
 
 
65
 
 
66
/****************
 
67
 * Declarations *
 
68
 ****************/
 
69
guint idle_handler_id;
 
70
guint progressbar_index;  /* An integer to set the value of progress bar into the recurse fonction */
 
71
 
 
72
GtkWidget *QuitRecursionWindow = NULL;
 
73
 
 
74
/* Used to force to hide the msgbox when saving tag */
 
75
gboolean SF_HideMsgbox_Write_Tag;
 
76
/* To remember which button was pressed when saving tag */
 
77
gint     SF_ButtonPressed_Write_Tag;
 
78
/* Used to force to hide the msgbox when renaming file */
 
79
gboolean SF_HideMsgbox_Rename_File;
 
80
/* To remember which button was pressed when renaming file */
 
81
gint     SF_ButtonPressed_Rename_File;
 
82
/* Used to force to hide the msgbox when deleting file */
 
83
gboolean SF_HideMsgbox_Delete_File;
 
84
/* To remember which button was pressed when deleting file */
 
85
gint     SF_ButtonPressed_Delete_File;
 
86
 
 
87
#ifdef ENABLE_FLAC
 
88
    #include <FLAC/metadata.h>
 
89
 
 
90
    /* Patch from Josh Coalson
 
91
     * FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 *
 
92
     * by LEGACY_FLAC we mean pre-FLAC 1.1.3; in FLAC 1.1.3 the FLAC__FileDecoder was merged into the FLAC__StreamDecoder */
 
93
    #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8
 
94
    #define LEGACY_FLAC // For FLAC version < 1.1.3
 
95
    #else
 
96
    #undef LEGACY_FLAC
 
97
    #endif
 
98
#endif
 
99
 
 
100
 
 
101
/**************
 
102
 * Prototypes *
 
103
 **************/
 
104
void     Handle_Crash     (gint signal_id);
 
105
gchar   *signal_to_string (gint signal);
 
106
 
 
107
GtkWidget *Create_Browser_Area (void);
 
108
GtkWidget *Create_File_Area    (void);
 
109
GtkWidget *Create_Tag_Area     (void);
 
110
 
 
111
void Menu_Mini_Button_Clicked (GtkEntry *entry);
 
112
void Mini_Button_Clicked      (GObject *object);
 
113
void Disable_Command_Buttons (void);
 
114
void Clear_Tag_Entry_Fields  (void);
 
115
void Clear_File_Entry_Field  (void);
 
116
void Clear_Header_Fields     (void);
 
117
 
 
118
gint Make_Dir         (const gchar *dirname_old, const gchar *dirname_new);
 
119
gint Remove_Dir       (const gchar *dirname_old, const gchar *dirname_new);
 
120
gboolean Write_File_Tag   (ET_File *ETFile, gboolean hide_msgbox);
 
121
gboolean Rename_File      (ET_File *ETFile, gboolean hide_msgbox);
 
122
gint Save_File        (ET_File *ETFile, gboolean multiple_files, gboolean force_saving_files);
 
123
gint Delete_File      (ET_File *ETFile, gboolean multiple_files);
 
124
gint Save_All_Files_With_Answer        (gboolean force_saving_files);
 
125
gint Save_Selected_Files_With_Answer   (gboolean force_saving_files);
 
126
gint Save_List_Of_Files                (GList *etfilelist, gboolean force_saving_files);
 
127
gint Delete_Selected_Files_With_Answer (void);
 
128
gint Copy_File (gchar const *fileold, gchar const *filenew);
 
129
 
 
130
void Display_Usage (void);
 
131
 
 
132
void Init_Load_Default_Dir (void);
 
133
void EasyTAG_Exit (void);
 
134
void Quit_MainWindow_Ok_Button (void);
 
135
 
 
136
GList *Read_Directory_Recursively (GList *file_list, gchar *path, gint recurse);
 
137
void Open_Quit_Recursion_Function_Window    (void);
 
138
void Destroy_Quit_Recursion_Function_Window (void);
 
139
void Quit_Recursion_Function_Button_Pressed (void);
 
140
void Quit_Recursion_Window_Key_Press (GtkWidget *window, GdkEvent *event);
 
141
 
 
142
 
 
143
 
 
144
/********
 
145
 * Main *
 
146
 ********/
 
147
#ifdef WIN32
 
148
int easytag_main (struct HINSTANCE__ *hInstance, int argc, char *argv[]) /* entry point of DLL */
 
149
#else
 
150
int main (int argc, char *argv[])
 
151
#endif
 
152
{
 
153
    GtkWidget *MainVBox;
 
154
    GtkWidget *HBox, *VBox;
 
155
    gboolean created_settings;
 
156
    struct stat statbuf;
 
157
    //GError *error = NULL;
 
158
    //GdkPixbuf *pixbuf;
 
159
    GdkPixmap *pixmap;
 
160
    GdkBitmap *mask;
 
161
 
 
162
 
 
163
#ifdef WIN32
 
164
    weasytag_init();
 
165
    //ET_Win32_Init(hInstance);
 
166
#else
 
167
    /* Signal handling to display a message(SIGSEGV, ...) */
 
168
    signal(SIGBUS,Handle_Crash);
 
169
    signal(SIGFPE,Handle_Crash);
 
170
    signal(SIGSEGV,Handle_Crash);
 
171
    // Must handle this signal to avoid zombie of applications executed (ex: xmms)
 
172
    signal(SIGCHLD,SIG_IGN); // Fix me! : can't run nautilus 1.0.6 with "Browse Directory With"
 
173
#endif
 
174
 
 
175
#ifdef ENABLE_NLS
 
176
    bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
 
177
    bind_textdomain_codeset(PACKAGE, "UTF-8");
 
178
    textdomain(GETTEXT_PACKAGE);
 
179
    /* Initialize i18n support */
 
180
    //gtk_set_locale();
 
181
#endif
 
182
    Charset_Insert_Locales_Init();
 
183
 
 
184
    /* Initialize GTK */
 
185
    gtk_init(&argc, &argv);
 
186
 
 
187
    /* Get home variable */
 
188
#ifdef WIN32
 
189
        HOME_VARIABLE = (gchar *)weasytag_data_dir();
 
190
#else
 
191
        HOME_VARIABLE = g_get_home_dir();
 
192
    //HOME_VARIABLE = (gchar *)g_getenv("HOME");
 
193
#endif
 
194
 
 
195
    INIT_DIRECTORY = NULL;
 
196
 
 
197
    /* Starting messages */
 
198
    Log_Print(LOG_OK,_("Starting EasyTAG %s (PId: %d) ..."),VERSION,getpid());
 
199
#ifdef ENABLE_MP3
 
200
    Log_Print(LOG_OK,_("Currently using libid3tag version %s ..."), ID3_VERSION);
 
201
#endif
 
202
#if defined ENABLE_MP3 && defined ENABLE_ID3LIB
 
203
    Log_Print(LOG_OK,_("Currently using id3lib version %d.%d.%d ..."),ID3LIB_MAJOR_VERSION,
 
204
                                                               ID3LIB_MINOR_VERSION,
 
205
                                                               ID3LIB_PATCH_VERSION);
 
206
#endif
 
207
 
 
208
#ifdef WIN32
 
209
    if (g_getenv("EASYTAGLANG"))
 
210
        Log_Print(LOG_OK,_("Variable EASYTAGLANG defined. Setting locale : '%s'"),g_getenv("EASYTAGLANG"));
 
211
    else
 
212
        Log_Print(LOG_OK,_("Setting locale : '%s'"),g_getenv("LANG"));
 
213
#endif
 
214
 
 
215
    if (get_locale())
 
216
        Log_Print(LOG_OK,_("Currently using locale '%s' (and eventually '%s')..."),
 
217
                get_locale(),get_encoding_from_locale(get_locale()));
 
218
 
 
219
 
 
220
    /* Create all config files */
 
221
    created_settings = Setting_Create_Files();
 
222
    /* Load Config */
 
223
    Init_Config_Variables();
 
224
    Read_Config();
 
225
    /* Display_Config(); // <- for debugging */
 
226
 
 
227
    /* Check given arguments */
 
228
    if (argc>1)
 
229
    {
 
230
        if ( (strcmp(argv[1],"--version")==0) || (strcmp(argv[1],"-v")==0) ) // Query version
 
231
        {
 
232
            g_print(_("%s %s by %s (compiled %s, %s)\n"),APPNAME,VERSION,AUTHOR,__TIME__,__DATE__);
 
233
            g_print(_("E-mail: %s"),EMAIL"\n");
 
234
            g_print(_("Web Page: %s"),WEBPAGE"\n");
 
235
            exit (0);
 
236
        }else if ( (strcmp(argv[1],"--help")==0) || (strcmp(argv[1],"-h")==0) ) // Query help
 
237
        {
 
238
            Display_Usage();
 
239
        }else
 
240
        {
 
241
            gchar *path2check = NULL, *path2check_tmp = NULL;
 
242
            gint resultstat;
 
243
            gchar **pathsplit;
 
244
            gint ps_index = 0;
 
245
 
 
246
            // Check if relative or absolute path
 
247
            if (g_path_is_absolute(argv[1])) // Passed an absolute path
 
248
            {
 
249
                path2check = g_strdup(argv[1]);
 
250
            }else                            // Passed a relative path
 
251
            {
 
252
                gchar *curdir = g_get_current_dir();
 
253
                path2check = g_strconcat(g_get_current_dir(),G_DIR_SEPARATOR_S,argv[1],NULL);
 
254
                g_free(curdir);
 
255
            }
 
256
 
 
257
#ifdef WIN32
 
258
            ET_Win32_Path_Replace_Slashes(path2check);
 
259
#endif
 
260
            // Check if contains hidden directories
 
261
            pathsplit = g_strsplit(path2check,G_DIR_SEPARATOR_S,0);
 
262
            g_free(path2check);
 
263
            path2check = NULL;
 
264
 
 
265
            // Browse the list to build again the path
 
266
            //FIX ME : Should manage directory ".." in path
 
267
            while (pathsplit[ps_index])
 
268
            {
 
269
                // Activate hidden directories in browser if path contains a dir like ".hidden_dir"
 
270
                if ( (g_ascii_strcasecmp (pathsplit[ps_index],"..")   != 0)
 
271
                &&   (g_ascii_strncasecmp(pathsplit[ps_index],".", 1) == 0)
 
272
                &&   (strlen(pathsplit[ps_index]) > 1) )
 
273
                    BROWSE_HIDDEN_DIR = 1; // If user saves the config for this session, this value will be saved to 1
 
274
 
 
275
                if (pathsplit[ps_index]
 
276
                && g_ascii_strcasecmp(pathsplit[ps_index],".") != 0
 
277
                && g_ascii_strcasecmp(pathsplit[ps_index],"")  != 0)
 
278
                {
 
279
                    if (path2check)
 
280
                    {
 
281
                        path2check_tmp = g_strconcat(path2check,G_DIR_SEPARATOR_S,pathsplit[ps_index],NULL);
 
282
                    }else
 
283
                    {
 
284
#ifdef WIN32
 
285
                        // Build a path starting with the drive letter
 
286
                        path2check_tmp = g_strdup(pathsplit[ps_index]);
 
287
#else
 
288
                        path2check_tmp = g_strconcat(G_DIR_SEPARATOR_S,pathsplit[ps_index],NULL);
 
289
#endif
 
290
                    }
 
291
 
 
292
                    path2check = g_strdup(path2check_tmp);
 
293
                    g_free(path2check_tmp);
 
294
                }
 
295
                ps_index++;
 
296
            }
 
297
 
 
298
            // Check if file or directory
 
299
            resultstat = stat(path2check,&statbuf);
 
300
            if (resultstat==0 && S_ISDIR(statbuf.st_mode))       // Directory
 
301
            {
 
302
                INIT_DIRECTORY = g_strdup(path2check);
 
303
            }else if (resultstat==0 && S_ISREG(statbuf.st_mode)) // File
 
304
            {
 
305
                // When passing a file, we load only the directory
 
306
                INIT_DIRECTORY = g_path_get_dirname(path2check);
 
307
            }else
 
308
            {
 
309
                g_print(_("Unknown parameter or path '%s'\n"),argv[1]);
 
310
                Display_Usage();
 
311
            }
 
312
            g_free(path2check);
 
313
        }
 
314
    }
 
315
 
 
316
 
 
317
    /* Initialization */
 
318
    ET_Core_Create();
 
319
    Main_Stop_Button_Pressed = 0;
 
320
    Init_Custom_Icons();
 
321
    Init_Mouse_Cursor();
 
322
    Init_OptionsWindow();
 
323
    Init_ScannerWindow();
 
324
    Init_CddbWindow();
 
325
    BrowserEntryModel    = NULL;
 
326
    TrackEntryComboModel = NULL;
 
327
    GenreComboModel      = NULL;
 
328
 
 
329
    /* The main window */
 
330
    MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
331
    gtk_window_set_title(GTK_WINDOW(MainWindow),APPNAME" "VERSION);
 
332
    // This part is needed to set correctly the position of handle panes
 
333
    gtk_window_set_default_size(GTK_WINDOW(MainWindow),MAIN_WINDOW_WIDTH,MAIN_WINDOW_HEIGHT);
 
334
 
 
335
    g_signal_connect(G_OBJECT(MainWindow),"delete_event",G_CALLBACK(Quit_MainWindow),NULL);
 
336
    g_signal_connect(G_OBJECT(MainWindow),"destroy",G_CALLBACK(Quit_MainWindow),NULL);
 
337
 
 
338
    /* Minimised window icon */
 
339
    gtk_widget_realize(MainWindow);
 
340
 
 
341
    pixmap = gdk_pixmap_create_from_xpm_d(MainWindow->window,&mask,NULL,EasyTAG_icon_xpm);
 
342
    gdk_window_set_icon(MainWindow->window,(GdkWindow *)NULL,pixmap,mask);
 
343
    /*pixbuf = gdk_pixbuf_new_from_file(PACKAGE_DATA_DIR"/EasyTAG_icon.png",&error);
 
344
    if (pixbuf)
 
345
    {
 
346
        gtk_window_set_icon(GTK_WINDOW(MainWindow),pixbuf);
 
347
        g_object_unref(G_OBJECT(pixbuf));
 
348
    }else
 
349
    {
 
350
        Log_Print(LOG_ERROR,error->message);
 
351
        g_error_free(error);
 
352
    }*/
 
353
 
 
354
    /* MainVBox for Menu bar + Tool bar + "Browser Area & FileArea & TagArea" + Log Area + "Status bar & Progress bar" */
 
355
    MainVBox = gtk_vbox_new(FALSE,0);
 
356
    gtk_container_add (GTK_CONTAINER(MainWindow),MainVBox);
 
357
    gtk_widget_show(MainVBox);
 
358
 
 
359
    /* Menu bar and tool bar */
 
360
    Create_UI(&MenuArea, &ToolArea);
 
361
    gtk_box_pack_start(GTK_BOX(MainVBox),MenuArea,FALSE,FALSE,0);
 
362
    gtk_box_pack_start(GTK_BOX(MainVBox),ToolArea,FALSE,FALSE,0);
 
363
 
 
364
 
 
365
    /* The two panes: BrowserArea on the left, FileArea+TagArea on the right */
 
366
    MainWindowHPaned = gtk_hpaned_new();
 
367
    //gtk_box_pack_start(GTK_BOX(MainVBox),MainWindowHPaned,TRUE,TRUE,0);
 
368
    gtk_paned_set_position(GTK_PANED(MainWindowHPaned),PANE_HANDLE_POSITION1);
 
369
    gtk_widget_show(MainWindowHPaned);
 
370
 
 
371
    /* Browser (Tree + File list + Entry) */
 
372
    BrowseArea = Create_Browser_Area();
 
373
    gtk_paned_pack1(GTK_PANED(MainWindowHPaned),BrowseArea,TRUE,TRUE);
 
374
 
 
375
    /* Vertical box for FileArea + TagArea */
 
376
    VBox = gtk_vbox_new(FALSE,0);
 
377
    gtk_paned_pack2(GTK_PANED(MainWindowHPaned),VBox,FALSE,FALSE);
 
378
    gtk_widget_show(VBox);
 
379
 
 
380
    /* File */
 
381
    FileArea = Create_File_Area();
 
382
    gtk_box_pack_start(GTK_BOX(VBox),FileArea,FALSE,FALSE,0);
 
383
 
 
384
    /* Tag */
 
385
    TagArea = Create_Tag_Area();
 
386
    gtk_box_pack_start(GTK_BOX(VBox),TagArea,FALSE,FALSE,0);
 
387
 
 
388
    /* Vertical pane for Browser Area + FileArea + TagArea */
 
389
    MainWindowVPaned = gtk_vpaned_new();
 
390
    gtk_box_pack_start(GTK_BOX(MainVBox),MainWindowVPaned,TRUE,TRUE,0);
 
391
    gtk_paned_pack1(GTK_PANED(MainWindowVPaned),MainWindowHPaned,TRUE,FALSE);
 
392
    gtk_paned_set_position(GTK_PANED(MainWindowVPaned),PANE_HANDLE_POSITION4);
 
393
    gtk_widget_show(MainWindowVPaned);
 
394
 
 
395
 
 
396
    /* Log */
 
397
    LogArea = Create_Log_Area();
 
398
    gtk_paned_pack2(GTK_PANED(MainWindowVPaned),LogArea,FALSE,TRUE);
 
399
 
 
400
    /* Horizontal box for Status bar + Progress bar */
 
401
    HBox = gtk_hbox_new(FALSE,0);
 
402
    gtk_box_pack_start(GTK_BOX(MainVBox),HBox,FALSE,FALSE,0);
 
403
    gtk_widget_show(HBox);
 
404
 
 
405
    /* Status bar */
 
406
    StatusArea = Create_Status_Bar();
 
407
    gtk_box_pack_start(GTK_BOX(HBox),StatusArea,TRUE,TRUE,0);
 
408
 
 
409
    /* Progress bar */
 
410
    ProgressArea = Create_Progress_Bar();
 
411
    gtk_box_pack_end(GTK_BOX(HBox),ProgressArea,FALSE,FALSE,0);
 
412
 
 
413
    gtk_widget_show(MainWindow);
 
414
 
 
415
    if (SET_MAIN_WINDOW_POSITION)
 
416
        gdk_window_move(MainWindow->window, MAIN_WINDOW_X, MAIN_WINDOW_Y);
 
417
 
 
418
    /* Load the default dir when the UI is created and displayed
 
419
     * to the screen and open also the scanner window */
 
420
    idle_handler_id = g_idle_add((GtkFunction)Init_Load_Default_Dir,NULL);
 
421
 
 
422
    /* Enter the event loop */
 
423
    gtk_main ();
 
424
    return 0;
 
425
}
 
426
 
 
427
 
 
428
GtkWidget *Create_Browser_Area (void)
 
429
{
 
430
    GtkWidget *Frame;
 
431
    GtkWidget *Tree;
 
432
 
 
433
    Frame = gtk_frame_new(_("Browser"));
 
434
    gtk_container_set_border_width(GTK_CONTAINER(Frame), 2);
 
435
 
 
436
    Tree = Create_Browser_Items(MainWindow);
 
437
    gtk_container_add(GTK_CONTAINER(Frame),Tree);
 
438
 
 
439
    /* Don't load init dir here because Tag area hasn't been yet created!.
 
440
     * It will be load at the end of the main function */
 
441
    //Browser_Tree_Select_Dir(DEFAULT_PATH_TO_MP3);
 
442
 
 
443
    gtk_widget_show(Frame);
 
444
    return Frame;
 
445
}
 
446
 
 
447
 
 
448
GtkWidget *Create_File_Area (void)
 
449
{
 
450
    GtkWidget *VBox, *HBox;
 
451
    GtkWidget *Separator;
 
452
    GtkTooltips *Tips;
 
453
 
 
454
 
 
455
    FileFrame = gtk_frame_new(_("File"));
 
456
    gtk_container_set_border_width(GTK_CONTAINER(FileFrame),2);
 
457
 
 
458
    VBox = gtk_vbox_new(FALSE,0);
 
459
    gtk_container_add(GTK_CONTAINER(FileFrame),VBox);
 
460
    gtk_container_set_border_width(GTK_CONTAINER(VBox),2);
 
461
 
 
462
    /* Tips */
 
463
    Tips = gtk_tooltips_new();
 
464
 
 
465
    /* HBox for FileEntry and IconBox */
 
466
    HBox = gtk_hbox_new(FALSE,2);
 
467
    gtk_box_pack_start(GTK_BOX(VBox),HBox,TRUE,TRUE,0);
 
468
 
 
469
    /* File index (position in list + list length) */
 
470
    FileIndex = gtk_label_new("0/0:");
 
471
    gtk_box_pack_start(GTK_BOX(HBox),FileIndex,FALSE,FALSE,0);
 
472
 
 
473
    /* File name */
 
474
    FileEntry = gtk_entry_new();
 
475
    gtk_editable_set_editable(GTK_EDITABLE(FileEntry), TRUE);
 
476
    gtk_box_pack_start(GTK_BOX(HBox),FileEntry,TRUE,TRUE,2);
 
477
 
 
478
    /* Access status icon */
 
479
    ReadOnlyStatusIconBox = Create_Pixmap_Icon_With_Event_Box("easytag-read-only");
 
480
    gtk_box_pack_start(GTK_BOX(HBox),ReadOnlyStatusIconBox,FALSE,FALSE,0);
 
481
    gtk_tooltips_set_tip(Tips,ReadOnlyStatusIconBox,_("Read Only File"),NULL);
 
482
    BrokenStatusIconBox = Create_Pixmap_Icon_With_Event_Box(GTK_STOCK_MISSING_IMAGE);
 
483
    gtk_box_pack_start(GTK_BOX(HBox),BrokenStatusIconBox,FALSE,FALSE,0);
 
484
    gtk_tooltips_set_tip(Tips,BrokenStatusIconBox,_("File Link Broken"),NULL);
 
485
 
 
486
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(FileEntry));
 
487
 
 
488
 
 
489
    /*
 
490
     *  File Infos
 
491
     */
 
492
    HeaderInfosTable = gtk_table_new(3,5,FALSE);
 
493
    gtk_container_add(GTK_CONTAINER(VBox),HeaderInfosTable);
 
494
    gtk_container_set_border_width(GTK_CONTAINER(HeaderInfosTable),2);
 
495
    gtk_table_set_row_spacings(GTK_TABLE(HeaderInfosTable),1);
 
496
    gtk_table_set_col_spacings(GTK_TABLE(HeaderInfosTable),2);
 
497
 
 
498
    VersionLabel = gtk_label_new(_("MPEG"));
 
499
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),VersionLabel,0,1,0,1);
 
500
    VersionValueLabel = gtk_label_new(_("?, Layer ?"));
 
501
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),VersionValueLabel,1,2,0,1);
 
502
    gtk_misc_set_alignment(GTK_MISC(VersionLabel),1,0.5);
 
503
    gtk_misc_set_alignment(GTK_MISC(VersionValueLabel),0,0.5);
 
504
 
 
505
    BitrateLabel = gtk_label_new(_("Bitrate:"));
 
506
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),BitrateLabel,0,1,1,2);
 
507
    BitrateValueLabel = gtk_label_new(_("? kb/s"));
 
508
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),BitrateValueLabel,1,2,1,2);
 
509
    gtk_misc_set_alignment(GTK_MISC(BitrateLabel),1,0.5);
 
510
    gtk_misc_set_alignment(GTK_MISC(BitrateValueLabel),0,0.5);
 
511
 
 
512
    SampleRateLabel = gtk_label_new(_("Freq:"));
 
513
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),SampleRateLabel,0,1,2,3);
 
514
    SampleRateValueLabel = gtk_label_new(_("? Hz"));
 
515
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),SampleRateValueLabel,1,2,2,3);
 
516
    gtk_misc_set_alignment(GTK_MISC(SampleRateLabel),1,0.5);
 
517
    gtk_misc_set_alignment(GTK_MISC(SampleRateValueLabel),0,0.5);
 
518
 
 
519
    Separator = gtk_vseparator_new();
 
520
    gtk_table_attach(GTK_TABLE(HeaderInfosTable),Separator,2,3,0,4,GTK_FILL,GTK_FILL,0,0);
 
521
 
 
522
    ModeLabel = gtk_label_new(_("Mode:"));
 
523
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),ModeLabel,3,4,0,1);
 
524
    ModeValueLabel = gtk_label_new(_("?"));
 
525
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),ModeValueLabel,4,5,0,1);
 
526
    gtk_misc_set_alignment(GTK_MISC(ModeLabel),1,0.5);
 
527
    gtk_misc_set_alignment(GTK_MISC(ModeValueLabel),0,0.5);
 
528
 
 
529
    SizeLabel = gtk_label_new(_("Size:"));
 
530
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),SizeLabel,3,4,1,2);
 
531
    SizeValueLabel = gtk_label_new(_("? kb"));
 
532
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),SizeValueLabel,4,5,1,2);
 
533
    gtk_misc_set_alignment(GTK_MISC(SizeLabel),1,0.5);
 
534
    gtk_misc_set_alignment(GTK_MISC(SizeValueLabel),0,0.5);
 
535
 
 
536
    DurationLabel = gtk_label_new(_("Time:"));
 
537
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),DurationLabel,3,4,2,3);
 
538
    DurationValueLabel = gtk_label_new(_("?"));
 
539
    gtk_table_attach_defaults(GTK_TABLE(HeaderInfosTable),DurationValueLabel,4,5,2,3);
 
540
    gtk_misc_set_alignment(GTK_MISC(DurationLabel),1,0.5);
 
541
    gtk_misc_set_alignment(GTK_MISC(DurationValueLabel),0,0.5);
 
542
 
 
543
    gtk_widget_show(FileFrame);
 
544
    gtk_widget_show(VBox);
 
545
    gtk_widget_show(HBox);
 
546
    gtk_widget_show(FileIndex);
 
547
    gtk_widget_show(FileEntry);
 
548
    if (SHOW_HEADER_INFO)
 
549
        gtk_widget_show_all(HeaderInfosTable);
 
550
    return FileFrame;
 
551
}
 
552
 
 
553
#include "../pixmaps/sequence_track.xpm"
 
554
GtkWidget *Create_Tag_Area (void)
 
555
{
 
556
    GtkWidget *Separator;
 
557
    GtkWidget *Frame;
 
558
    GtkWidget *Table;
 
559
    GtkWidget *Label;
 
560
    GtkWidget *Icon;
 
561
    GtkWidget *VBox;
 
562
    GtkWidget *hbox;
 
563
    GList *focusable_widgets_list = NULL;
 
564
    //GtkWidget *ScrollWindow;
 
565
    //GtkTextBuffer *TextBuffer;
 
566
    GtkEntryCompletion *completion;
 
567
    GtkTooltips *Tips;
 
568
    gint MButtonSize = 13;
 
569
    gint TablePadding = 2;
 
570
 
 
571
    // For Picture
 
572
    static const GtkTargetEntry drops[] = { { "text/uri-list", 0, TARGET_URI_LIST } };
 
573
    GtkCellRenderer *renderer;
 
574
    GtkTreeViewColumn *column;
 
575
    GtkTreeSelection *selection;
 
576
 
 
577
 
 
578
    /* Tips */
 
579
    Tips = gtk_tooltips_new();
 
580
 
 
581
    /* Main Frame */
 
582
    TagFrame = gtk_frame_new(_("Tag"));
 
583
    gtk_container_set_border_width(GTK_CONTAINER(TagFrame),2);
 
584
 
 
585
    /* Box for the notebook (only for setting a border) */
 
586
    VBox = gtk_vbox_new(FALSE,0);
 
587
    gtk_container_add(GTK_CONTAINER(TagFrame),VBox);
 
588
    gtk_container_set_border_width(GTK_CONTAINER(VBox),2);
 
589
 
 
590
    /*
 
591
     * Note book
 
592
     */
 
593
    TagNoteBook = gtk_notebook_new();
 
594
    gtk_notebook_popup_enable(GTK_NOTEBOOK(TagNoteBook));
 
595
    //gtk_container_add(GTK_CONTAINER(TagFrame),TagNoteBook);
 
596
    gtk_box_pack_start(GTK_BOX(VBox),TagNoteBook,TRUE,TRUE,0);
 
597
    gtk_notebook_set_tab_pos(GTK_NOTEBOOK(TagNoteBook),GTK_POS_TOP);
 
598
    gtk_notebook_set_show_border(GTK_NOTEBOOK(TagNoteBook),FALSE);
 
599
    gtk_notebook_popup_enable(GTK_NOTEBOOK(TagNoteBook));
 
600
 
 
601
    /*
 
602
     * 1 - Page for common tag fields
 
603
     */
 
604
    Label = gtk_label_new(_("Common"));
 
605
    Frame = gtk_frame_new(NULL);
 
606
    gtk_notebook_append_page(GTK_NOTEBOOK(TagNoteBook),Frame,Label);
 
607
    gtk_container_set_border_width(GTK_CONTAINER(Frame), 0);
 
608
    gtk_frame_set_shadow_type(GTK_FRAME(Frame),GTK_SHADOW_NONE); // Hide the Frame
 
609
 
 
610
 
 
611
    Table = gtk_table_new(11,11,FALSE);
 
612
    gtk_container_add(GTK_CONTAINER(Frame),Table);
 
613
    gtk_container_set_border_width(GTK_CONTAINER(Table),2);
 
614
 
 
615
    /* Title */
 
616
    TitleLabel = gtk_label_new(_("Title:"));
 
617
    gtk_table_attach(GTK_TABLE(Table),TitleLabel,0,1,0,1,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
618
    gtk_misc_set_alignment(GTK_MISC(TitleLabel),1,0.5);
 
619
 
 
620
    TitleEntry = gtk_entry_new();
 
621
    gtk_table_attach(GTK_TABLE(Table),TitleEntry,1,10,0,1,
 
622
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
623
    gtk_widget_set_size_request(TitleEntry, 150, -1);
 
624
 
 
625
    TitleMButton = gtk_button_new();
 
626
    gtk_widget_set_size_request(TitleMButton,MButtonSize,MButtonSize);
 
627
    gtk_table_attach(GTK_TABLE(Table),TitleMButton,10,11,0,1,0,0,TablePadding,TablePadding);
 
628
    g_signal_connect(G_OBJECT(TitleMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
629
    gtk_tooltips_set_tip(Tips,TitleMButton,_("Tag selected files with this title"),NULL);
 
630
 
 
631
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(TitleEntry));
 
632
    g_object_set_data(G_OBJECT(TitleEntry),"MButtonName",TitleMButton);
 
633
 
 
634
 
 
635
    /* Artist */
 
636
    ArtistLabel = gtk_label_new(_("Artist:"));
 
637
    gtk_table_attach(GTK_TABLE(Table),ArtistLabel,0,1,1,2,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
638
    gtk_misc_set_alignment(GTK_MISC(ArtistLabel),1,0.5);
 
639
 
 
640
    ArtistEntry = gtk_entry_new();
 
641
    gtk_table_attach(GTK_TABLE(Table),ArtistEntry,1,10,1,2,
 
642
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
643
 
 
644
    ArtistMButton = gtk_button_new();
 
645
    gtk_widget_set_size_request(ArtistMButton,MButtonSize,MButtonSize);
 
646
    gtk_table_attach(GTK_TABLE(Table),ArtistMButton,10,11,1,2,0,0,TablePadding,TablePadding);
 
647
    g_signal_connect(G_OBJECT(ArtistMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
648
    gtk_tooltips_set_tip(Tips,ArtistMButton,_("Tag selected files with this artist"),NULL);
 
649
 
 
650
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(ArtistEntry));
 
651
    g_object_set_data(G_OBJECT(ArtistEntry),"MButtonName",ArtistMButton);
 
652
 
 
653
    /* Album Artist */
 
654
    AlbumArtistLabel = gtk_label_new(_("Album Artist:"));
 
655
    gtk_table_attach(GTK_TABLE(Table),AlbumArtistLabel,0,1,2,3,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
656
    gtk_misc_set_alignment(GTK_MISC(AlbumArtistLabel),1,0.5);
 
657
 
 
658
    AlbumArtistEntry = gtk_entry_new();
 
659
    gtk_table_attach(GTK_TABLE(Table),AlbumArtistEntry,1,10,2,3,
 
660
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
661
 
 
662
    AlbumArtistMButton = gtk_button_new();
 
663
    gtk_widget_set_size_request(AlbumArtistMButton,MButtonSize,MButtonSize);
 
664
    gtk_table_attach(GTK_TABLE(Table),AlbumArtistMButton,10,11,2,3,0,0,TablePadding,TablePadding);
 
665
    g_signal_connect(G_OBJECT(AlbumArtistMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
666
    gtk_tooltips_set_tip(Tips,AlbumArtistMButton,_("Tag selected files with this album artist"),NULL);
 
667
 
 
668
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(AlbumArtistEntry));
 
669
    g_object_set_data(G_OBJECT(AlbumArtistEntry),"MButtonName",AlbumArtistMButton);
 
670
 
 
671
    /* Album */
 
672
    AlbumLabel = gtk_label_new(_("Album:"));
 
673
    gtk_table_attach(GTK_TABLE(Table),AlbumLabel,0,1,3,4,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
674
    gtk_misc_set_alignment(GTK_MISC(AlbumLabel),1,0.5);
 
675
 
 
676
    AlbumEntry = gtk_entry_new();
 
677
    gtk_table_attach(GTK_TABLE(Table),AlbumEntry,1,7,3,4,
 
678
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
679
 
 
680
    AlbumMButton = gtk_button_new();
 
681
    //gtk_widget_set_size_request(AlbumMButton, 10, 10);
 
682
    gtk_widget_set_size_request(AlbumMButton,MButtonSize,MButtonSize);
 
683
    gtk_table_attach(GTK_TABLE(Table),AlbumMButton,7,8,3,4,0,0,TablePadding,TablePadding);
 
684
    g_signal_connect(G_OBJECT(AlbumMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
685
    gtk_tooltips_set_tip(Tips,AlbumMButton,_("Tag selected files with this album name"),NULL);
 
686
 
 
687
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(AlbumEntry));
 
688
    g_object_set_data(G_OBJECT(AlbumEntry),"MButtonName",AlbumMButton);
 
689
 
 
690
    /* Disc Number */
 
691
    DiscNumberLabel = gtk_label_new(_("CD:"));
 
692
    gtk_table_attach(GTK_TABLE(Table),DiscNumberLabel,8,9,3,4,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
693
    gtk_misc_set_alignment(GTK_MISC(DiscNumberLabel),1,0.5);
 
694
 
 
695
    DiscNumberEntry = gtk_entry_new();
 
696
    gtk_table_attach(GTK_TABLE(Table),DiscNumberEntry,9,10,3,4,
 
697
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
698
    gtk_widget_set_size_request(DiscNumberEntry,30,-1);
 
699
    // FIX ME should allow to type only something like : 1/3
 
700
    //g_signal_connect(G_OBJECT(GTK_ENTRY(DiscNumberEntry)),"insert_text",G_CALLBACK(Insert_Only_Digit),NULL);
 
701
 
 
702
    DiscNumberMButton = gtk_button_new();
 
703
    //gtk_widget_set_size_request(DiscNumberMButton, 10, 10);
 
704
    gtk_widget_set_size_request(DiscNumberMButton,MButtonSize,MButtonSize);
 
705
    gtk_table_attach(GTK_TABLE(Table),DiscNumberMButton,10,11,3,4,0,0,TablePadding,TablePadding);
 
706
    g_signal_connect(G_OBJECT(DiscNumberMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
707
    gtk_tooltips_set_tip(Tips,DiscNumberMButton,_("Tag selected files with this disc number"),NULL);
 
708
 
 
709
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(DiscNumberEntry));
 
710
    g_object_set_data(G_OBJECT(DiscNumberEntry),"MButtonName",DiscNumberMButton);
 
711
 
 
712
    /* Year */
 
713
    YearLabel = gtk_label_new(_("Year:"));
 
714
    gtk_table_attach(GTK_TABLE(Table),YearLabel,0,1,4,5,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
715
    gtk_misc_set_alignment(GTK_MISC(YearLabel),1,0.5);
 
716
 
 
717
    YearEntry = gtk_entry_new();
 
718
    gtk_entry_set_max_length(GTK_ENTRY(YearEntry), 4);
 
719
    gtk_table_attach(GTK_TABLE(Table),YearEntry,1,2,4,5,
 
720
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
721
    gtk_widget_set_size_request(YearEntry,37,-1);
 
722
    g_signal_connect(G_OBJECT(YearEntry),"insert_text",G_CALLBACK(Insert_Only_Digit),NULL);
 
723
    g_signal_connect(G_OBJECT(YearEntry),"activate",G_CALLBACK(Parse_Date),NULL);
 
724
    g_signal_connect(G_OBJECT(YearEntry),"focus-out-event",G_CALLBACK(Parse_Date),NULL);
 
725
 
 
726
    YearMButton = gtk_button_new();
 
727
    gtk_widget_set_size_request(YearMButton,MButtonSize,MButtonSize);
 
728
    gtk_table_attach(GTK_TABLE(Table),YearMButton,2,3,4,5,0,0,TablePadding,TablePadding);
 
729
    g_signal_connect(G_OBJECT(YearMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
730
    gtk_tooltips_set_tip(Tips,YearMButton,_("Tag selected files with this year"),NULL);
 
731
 
 
732
    /* Small vertical separator */
 
733
    Separator = gtk_vseparator_new();
 
734
    gtk_table_attach(GTK_TABLE(Table),Separator,3,4,4,5,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
735
 
 
736
 
 
737
    /* Track and Track total */
 
738
    TrackMButtonSequence = gtk_button_new();
 
739
    gtk_widget_set_size_request(TrackMButtonSequence,MButtonSize,MButtonSize);
 
740
    gtk_table_attach(GTK_TABLE(Table),TrackMButtonSequence,4,5,4,5,0,0,TablePadding,TablePadding);
 
741
    g_signal_connect(G_OBJECT(TrackMButtonSequence),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
742
    gtk_tooltips_set_tip(Tips,TrackMButtonSequence,_("Number selected tracks sequentially. "
 
743
                                                     "Starts at 01 in each subdirectory."), NULL);
 
744
    // Pixmap into TrackMButtonSequence button
 
745
    //Icon = gtk_image_new_from_stock("easytag-sequence-track", GTK_ICON_SIZE_BUTTON); // FIX ME : it doesn't display the good size of the '#'
 
746
    Icon = Create_Xpm_Image((const char **)sequence_track_xpm);
 
747
    gtk_container_add(GTK_CONTAINER(TrackMButtonSequence),Icon);
 
748
    GTK_WIDGET_UNSET_FLAGS(TrackMButtonSequence,GTK_CAN_DEFAULT); // To have enought space to display the icon
 
749
    GTK_WIDGET_UNSET_FLAGS(TrackMButtonSequence,GTK_CAN_FOCUS);   // To have enought space to display the icon
 
750
 
 
751
    TrackLabel = gtk_label_new(_("Track #:"));
 
752
    gtk_table_attach(GTK_TABLE(Table),TrackLabel,5,6,4,5,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
753
    gtk_misc_set_alignment(GTK_MISC(TrackLabel),1,0.5);
 
754
 
 
755
    if (TrackEntryComboModel != NULL)
 
756
        gtk_list_store_clear(TrackEntryComboModel);
 
757
    else
 
758
        TrackEntryComboModel = gtk_list_store_new(MISC_COMBO_COUNT, G_TYPE_STRING);
 
759
 
 
760
    TrackEntryCombo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(TrackEntryComboModel), MISC_COMBO_TEXT);
 
761
    gtk_table_attach(GTK_TABLE(Table),TrackEntryCombo,6,7,4,5,
 
762
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
763
    gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(TrackEntryCombo),3); // Three columns to display track numbers list
 
764
 
 
765
    gtk_widget_set_size_request(TrackEntryCombo,50,-1);
 
766
    g_signal_connect(G_OBJECT(GTK_ENTRY(GTK_BIN(TrackEntryCombo)->child)),"insert_text",
 
767
        G_CALLBACK(Insert_Only_Digit),NULL);
 
768
 
 
769
    Label = gtk_label_new("/");
 
770
    gtk_table_attach(GTK_TABLE(Table),Label,7,8,4,5,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
771
    gtk_misc_set_alignment(GTK_MISC(Label),0.5,0.5);
 
772
 
 
773
    TrackMButtonNbrFiles = gtk_button_new();
 
774
    gtk_widget_set_size_request(TrackMButtonNbrFiles,MButtonSize,MButtonSize);
 
775
    gtk_table_attach(GTK_TABLE(Table),TrackMButtonNbrFiles,8,9,4,5,0,0,TablePadding,TablePadding);
 
776
    g_signal_connect(G_OBJECT(TrackMButtonNbrFiles),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
777
    gtk_tooltips_set_tip(Tips,TrackMButtonNbrFiles,_("Set the number of files, in the same directory of the displayed file, to the selected tracks."), NULL);
 
778
    // Pixmap into TrackMButtonNbrFiles button
 
779
    //Icon = gtk_image_new_from_stock("easytag-sequence-track", GTK_ICON_SIZE_BUTTON);
 
780
    Icon = Create_Xpm_Image((const char **)sequence_track_xpm);
 
781
    gtk_container_add(GTK_CONTAINER(TrackMButtonNbrFiles),Icon);
 
782
    GTK_WIDGET_UNSET_FLAGS(TrackMButtonNbrFiles,GTK_CAN_DEFAULT); // To have enought space to display the icon
 
783
    GTK_WIDGET_UNSET_FLAGS(TrackMButtonNbrFiles,GTK_CAN_FOCUS);   // To have enought space to display the icon
 
784
 
 
785
    TrackTotalEntry = gtk_entry_new();
 
786
    gtk_table_attach(GTK_TABLE(Table),TrackTotalEntry,9,10,4,5,
 
787
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
788
    gtk_widget_set_size_request(TrackTotalEntry,30,-1);
 
789
    g_signal_connect(G_OBJECT(GTK_ENTRY(TrackTotalEntry)),"insert_text",
 
790
        G_CALLBACK(Insert_Only_Digit),NULL);
 
791
 
 
792
    TrackMButton = gtk_button_new();
 
793
    gtk_widget_set_size_request(TrackMButton,MButtonSize,MButtonSize);
 
794
    gtk_table_attach(GTK_TABLE(Table),TrackMButton,10,11,4,5,0,0,TablePadding,TablePadding);
 
795
    g_signal_connect(G_OBJECT(TrackMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
796
    gtk_tooltips_set_tip(Tips,TrackMButton,_("Tag selected files with this number of tracks"),NULL);
 
797
 
 
798
    g_object_set_data(G_OBJECT(GTK_ENTRY(GTK_BIN(TrackEntryCombo)->child)),"MButtonName",TrackMButton);
 
799
    g_object_set_data(G_OBJECT(TrackTotalEntry),"MButtonName",TrackMButton);
 
800
 
 
801
    /* Genre */
 
802
    GenreLabel = gtk_label_new(_("Genre:"));
 
803
    gtk_table_attach(GTK_TABLE(Table),GenreLabel,0,1,5,6,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
804
    gtk_misc_set_alignment(GTK_MISC(GenreLabel),1,0.5);
 
805
 
 
806
    if (GenreComboModel != NULL)
 
807
        gtk_list_store_clear(GenreComboModel);
 
808
    else
 
809
        GenreComboModel = gtk_list_store_new(MISC_COMBO_COUNT, G_TYPE_STRING);
 
810
    GenreCombo = gtk_combo_box_entry_new_with_model(GTK_TREE_MODEL(GenreComboModel), MISC_COMBO_TEXT);
 
811
    completion = gtk_entry_completion_new();
 
812
    gtk_entry_set_completion(GTK_ENTRY(GTK_BIN(GenreCombo)->child), completion);
 
813
    g_object_unref(completion);
 
814
    gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(GenreComboModel));
 
815
    gtk_entry_completion_set_text_column(completion, 0);
 
816
    gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(GenreComboModel), MISC_COMBO_TEXT, Combo_Alphabetic_Sort, NULL, NULL);
 
817
    gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(GenreComboModel), MISC_COMBO_TEXT, GTK_SORT_ASCENDING);
 
818
    gtk_table_attach(GTK_TABLE(Table),GenreCombo,1,10,5,6,
 
819
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
820
    Load_Genres_List_To_UI();
 
821
    gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(GenreCombo),2); // Two columns to display genres list
 
822
 
 
823
    GenreMButton = gtk_button_new();
 
824
    gtk_widget_set_size_request(GenreMButton,MButtonSize,MButtonSize);
 
825
    gtk_table_attach(GTK_TABLE(Table),GenreMButton,10,11,5,6,0,0,TablePadding,TablePadding);
 
826
    g_signal_connect(G_OBJECT(GenreMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
827
    gtk_tooltips_set_tip(Tips,GenreMButton,_("Tag selected files with this genre"),NULL);
 
828
 
 
829
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(GTK_BIN(GenreCombo)->child));
 
830
    g_object_set_data(G_OBJECT(GTK_BIN(GenreCombo)->child),"MButtonName",GenreMButton);
 
831
 
 
832
    /* Comment */
 
833
    CommentLabel = gtk_label_new(_("Comment:"));
 
834
    gtk_table_attach(GTK_TABLE(Table),CommentLabel,0,1,6,7,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
835
    gtk_misc_set_alignment(GTK_MISC(CommentLabel),1,0.5);
 
836
 
 
837
    CommentEntry = gtk_entry_new();
 
838
    gtk_table_attach(GTK_TABLE(Table),CommentEntry,1,10,6,7,
 
839
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
840
 
 
841
        // Use of a text view instead of an entry...
 
842
    /******ScrollWindow = gtk_scrolled_window_new(NULL,NULL);
 
843
    gtk_table_attach(GTK_TABLE(Table),ScrollWindow,1,10,5,6,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
844
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ScrollWindow), GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
 
845
    gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(ScrollWindow), GTK_SHADOW_IN);
 
846
    gtk_widget_set_size_request(ScrollWindow,-1,52); // Display ~3 lines...
 
847
    TextBuffer = gtk_text_buffer_new(NULL);
 
848
    CommentView = gtk_text_view_new_with_buffer(TextBuffer);
 
849
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(CommentView), GTK_WRAP_WORD); // To not display the horizontal scrollbar
 
850
    gtk_container_add(GTK_CONTAINER(ScrollWindow),CommentView);
 
851
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(CommentView));
 
852
    *******/
 
853
 
 
854
    CommentMButton = gtk_button_new();
 
855
    gtk_widget_set_size_request(CommentMButton,MButtonSize,MButtonSize);
 
856
    gtk_table_attach(GTK_TABLE(Table),CommentMButton,10,11,6,7,0,0,TablePadding,TablePadding);
 
857
    g_signal_connect(G_OBJECT(CommentMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
858
    gtk_tooltips_set_tip(Tips,CommentMButton,_("Tag selected files with this comment"),NULL);
 
859
 
 
860
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(CommentEntry));
 
861
    g_object_set_data(G_OBJECT(CommentEntry),"MButtonName",CommentMButton);
 
862
    //Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(CommentView));
 
863
    //g_object_set_data(G_OBJECT(CommentView),"MButtonName",CommentMButton);
 
864
 
 
865
 
 
866
    /* Composer (name of the composers) */
 
867
    ComposerLabel = gtk_label_new(_("Composer:"));
 
868
    gtk_table_attach(GTK_TABLE(Table),ComposerLabel,0,1,7,8,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
869
    gtk_misc_set_alignment(GTK_MISC(ComposerLabel),1,0.5);
 
870
 
 
871
    ComposerEntry = gtk_entry_new();
 
872
    gtk_table_attach(GTK_TABLE(Table),ComposerEntry,1,10,7,8,
 
873
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
874
 
 
875
    ComposerMButton = gtk_button_new();
 
876
    gtk_widget_set_size_request(ComposerMButton,MButtonSize,MButtonSize);
 
877
    gtk_table_attach(GTK_TABLE(Table),ComposerMButton,10,11,7,8,0,0,TablePadding,TablePadding);
 
878
    g_signal_connect(G_OBJECT(ComposerMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
879
    gtk_tooltips_set_tip(Tips,ComposerMButton,_("Tag selected files with this composer"),NULL);
 
880
 
 
881
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(ComposerEntry));
 
882
    g_object_set_data(G_OBJECT(ComposerEntry),"MButtonName",ComposerMButton);
 
883
 
 
884
 
 
885
    /* Original Artist / Performer */
 
886
    OrigArtistLabel = gtk_label_new(_("Orig. Artist:"));
 
887
    gtk_table_attach(GTK_TABLE(Table),OrigArtistLabel,0,1,8,9,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
888
    gtk_misc_set_alignment(GTK_MISC(OrigArtistLabel),1,0.5);
 
889
 
 
890
    OrigArtistEntry = gtk_entry_new();
 
891
    gtk_table_attach(GTK_TABLE(Table),OrigArtistEntry,1,10,8,9,
 
892
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
893
 
 
894
    OrigArtistMButton = gtk_button_new();
 
895
    gtk_widget_set_size_request(OrigArtistMButton,MButtonSize,MButtonSize);
 
896
    gtk_table_attach(GTK_TABLE(Table),OrigArtistMButton,10,11,8,9,0,0,TablePadding,TablePadding);
 
897
    g_signal_connect(G_OBJECT(OrigArtistMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
898
    gtk_tooltips_set_tip(Tips,OrigArtistMButton,_("Tag selected files with this original artist"),NULL);
 
899
 
 
900
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(OrigArtistEntry));
 
901
    g_object_set_data(G_OBJECT(OrigArtistEntry),"MButtonName",OrigArtistMButton);
 
902
 
 
903
 
 
904
    /* Copyright */
 
905
    CopyrightLabel = gtk_label_new(_("Copyright:"));
 
906
    gtk_table_attach(GTK_TABLE(Table),CopyrightLabel,0,1,9,10,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
907
    gtk_misc_set_alignment(GTK_MISC(CopyrightLabel),1,0.5);
 
908
 
 
909
    CopyrightEntry = gtk_entry_new();
 
910
    gtk_table_attach(GTK_TABLE(Table),CopyrightEntry,1,10,9,10,
 
911
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
912
 
 
913
    CopyrightMButton = gtk_button_new();
 
914
    gtk_widget_set_size_request(CopyrightMButton,MButtonSize,MButtonSize);
 
915
    gtk_table_attach(GTK_TABLE(Table),CopyrightMButton,10,11,9,10,0,0,TablePadding,TablePadding);
 
916
    g_signal_connect(G_OBJECT(CopyrightMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
917
    gtk_tooltips_set_tip(Tips,CopyrightMButton,_("Tag selected files with this copyright"),NULL);
 
918
 
 
919
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(CopyrightEntry));
 
920
    g_object_set_data(G_OBJECT(CopyrightEntry),"MButtonName",CopyrightMButton);
 
921
 
 
922
 
 
923
    /* URL */
 
924
    URLLabel = gtk_label_new(_("URL:"));
 
925
    gtk_table_attach(GTK_TABLE(Table),URLLabel,0,1,10,11,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
926
    gtk_misc_set_alignment(GTK_MISC(URLLabel),1,0.5);
 
927
 
 
928
    URLEntry = gtk_entry_new();
 
929
    gtk_table_attach(GTK_TABLE(Table),URLEntry,1,10,10,11,
 
930
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
931
 
 
932
    URLMButton = gtk_button_new();
 
933
    gtk_widget_set_size_request(URLMButton,MButtonSize,MButtonSize);
 
934
    gtk_table_attach(GTK_TABLE(Table),URLMButton,10,11,10,11,0,0,TablePadding,TablePadding);
 
935
    g_signal_connect(G_OBJECT(URLMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
936
    gtk_tooltips_set_tip(Tips,URLMButton,_("Tag selected files with this URL"),NULL);
 
937
 
 
938
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(URLEntry));
 
939
    g_object_set_data(G_OBJECT(URLEntry),"MButtonName",URLMButton);
 
940
 
 
941
 
 
942
    /* Encoded by */
 
943
    EncodedByLabel = gtk_label_new(_("Encoded by:"));
 
944
    gtk_table_attach(GTK_TABLE(Table),EncodedByLabel,0,1,11,12,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
945
    gtk_misc_set_alignment(GTK_MISC(EncodedByLabel),1,0.5);
 
946
 
 
947
    EncodedByEntry = gtk_entry_new();
 
948
    gtk_table_attach(GTK_TABLE(Table),EncodedByEntry,1,10,11,12,
 
949
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
950
 
 
951
    EncodedByMButton = gtk_button_new();
 
952
    gtk_widget_set_size_request(EncodedByMButton,MButtonSize,MButtonSize);
 
953
    gtk_table_attach(GTK_TABLE(Table),EncodedByMButton,10,11,11,12,0,0,TablePadding,TablePadding);
 
954
    g_signal_connect(G_OBJECT(EncodedByMButton),"clicked", G_CALLBACK(Mini_Button_Clicked),NULL);
 
955
    gtk_tooltips_set_tip(Tips,EncodedByMButton,_("Tag selected files with this encoder name"),NULL);
 
956
 
 
957
    Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(EncodedByEntry));
 
958
    g_object_set_data(G_OBJECT(EncodedByEntry),"MButtonName",EncodedByMButton);
 
959
 
 
960
 
 
961
    // Managing of entries when pressing the Enter key
 
962
    g_signal_connect_swapped(G_OBJECT(TitleEntry),      "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(ArtistEntry));
 
963
    g_signal_connect_swapped(G_OBJECT(ArtistEntry),     "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(AlbumEntry));
 
964
    g_signal_connect_swapped(G_OBJECT(AlbumEntry),      "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(DiscNumberEntry));
 
965
    g_signal_connect_swapped(G_OBJECT(DiscNumberEntry), "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(YearEntry));
 
966
    g_signal_connect_swapped(G_OBJECT(YearEntry),       "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(GTK_ENTRY(GTK_BIN(TrackEntryCombo)->child)));
 
967
    g_signal_connect_swapped(G_OBJECT(GTK_ENTRY(GTK_BIN(TrackEntryCombo)->child)),"activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(TrackTotalEntry));
 
968
    g_signal_connect_swapped(G_OBJECT(TrackTotalEntry), "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(GTK_BIN(GenreCombo)->child));
 
969
    g_signal_connect_swapped(G_OBJECT(GTK_BIN(GenreCombo)->child),"activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(CommentEntry));
 
970
    g_signal_connect_swapped(G_OBJECT(CommentEntry),    "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(ComposerEntry));
 
971
    g_signal_connect_swapped(G_OBJECT(ComposerEntry),   "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(OrigArtistEntry));
 
972
    g_signal_connect_swapped(G_OBJECT(OrigArtistEntry), "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(CopyrightEntry));
 
973
    g_signal_connect_swapped(G_OBJECT(CopyrightEntry),  "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(URLEntry));
 
974
    g_signal_connect_swapped(G_OBJECT(URLEntry),        "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(EncodedByEntry));
 
975
    g_signal_connect_swapped(G_OBJECT(EncodedByEntry),  "activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(AlbumArtistEntry));
 
976
        g_signal_connect_swapped(G_OBJECT(AlbumArtistEntry),"activate",G_CALLBACK(gtk_widget_grab_focus),G_OBJECT(TitleEntry));
 
977
 
 
978
    // Set focus chain
 
979
    focusable_widgets_list = g_list_append(focusable_widgets_list,TitleEntry);
 
980
    focusable_widgets_list = g_list_append(focusable_widgets_list,TitleMButton);
 
981
    focusable_widgets_list = g_list_append(focusable_widgets_list,ArtistEntry);
 
982
    focusable_widgets_list = g_list_append(focusable_widgets_list,ArtistMButton);
 
983
    focusable_widgets_list = g_list_append(focusable_widgets_list,AlbumEntry);
 
984
    focusable_widgets_list = g_list_append(focusable_widgets_list,AlbumMButton);
 
985
    focusable_widgets_list = g_list_append(focusable_widgets_list,DiscNumberEntry);
 
986
    focusable_widgets_list = g_list_append(focusable_widgets_list,DiscNumberMButton);
 
987
    focusable_widgets_list = g_list_append(focusable_widgets_list,YearEntry);
 
988
    focusable_widgets_list = g_list_append(focusable_widgets_list,YearMButton);
 
989
    //focusable_widgets_list = g_list_append(focusable_widgets_list,TrackMButtonSequence); // Doesn't work as focus disabled for this widget to have enought space to display icon
 
990
    focusable_widgets_list = g_list_append(focusable_widgets_list,TrackEntryCombo);
 
991
    //focusable_widgets_list = g_list_append(focusable_widgets_list,TrackMButtonNbrFiles);
 
992
    focusable_widgets_list = g_list_append(focusable_widgets_list,TrackTotalEntry);
 
993
    focusable_widgets_list = g_list_append(focusable_widgets_list,TrackMButton);
 
994
    focusable_widgets_list = g_list_append(focusable_widgets_list,GenreCombo);
 
995
    focusable_widgets_list = g_list_append(focusable_widgets_list,GenreMButton);
 
996
    focusable_widgets_list = g_list_append(focusable_widgets_list,CommentEntry);
 
997
    focusable_widgets_list = g_list_append(focusable_widgets_list,CommentMButton);
 
998
    focusable_widgets_list = g_list_append(focusable_widgets_list,ComposerEntry);
 
999
    focusable_widgets_list = g_list_append(focusable_widgets_list,ComposerMButton);
 
1000
    focusable_widgets_list = g_list_append(focusable_widgets_list,OrigArtistEntry);
 
1001
    focusable_widgets_list = g_list_append(focusable_widgets_list,OrigArtistMButton);
 
1002
    focusable_widgets_list = g_list_append(focusable_widgets_list,CopyrightEntry);
 
1003
    focusable_widgets_list = g_list_append(focusable_widgets_list,CopyrightMButton);
 
1004
    focusable_widgets_list = g_list_append(focusable_widgets_list,URLEntry);
 
1005
    focusable_widgets_list = g_list_append(focusable_widgets_list,URLMButton);
 
1006
    focusable_widgets_list = g_list_append(focusable_widgets_list,EncodedByEntry);
 
1007
    focusable_widgets_list = g_list_append(focusable_widgets_list,EncodedByMButton);
 
1008
        focusable_widgets_list = g_list_append(focusable_widgets_list,AlbumArtistEntry);
 
1009
    focusable_widgets_list = g_list_append(focusable_widgets_list,AlbumArtistMButton);
 
1010
    focusable_widgets_list = g_list_append(focusable_widgets_list,TitleEntry); // To loop to the beginning
 
1011
    gtk_container_set_focus_chain(GTK_CONTAINER(Table),focusable_widgets_list);
 
1012
 
 
1013
 
 
1014
 
 
1015
    /*
 
1016
     * 2 - Page for extra tag fields
 
1017
     */
 
1018
    Label = gtk_label_new(_("Pictures")); // As there is only the picture field... - also used in ET_Display_File_Tag_To_UI
 
1019
    Frame = gtk_frame_new(NULL);
 
1020
    gtk_notebook_append_page(GTK_NOTEBOOK(TagNoteBook),Frame,Label);
 
1021
    gtk_container_set_border_width(GTK_CONTAINER(Frame), 0);
 
1022
    gtk_frame_set_shadow_type(GTK_FRAME(Frame),GTK_SHADOW_NONE); // Hide the Frame
 
1023
 
 
1024
    Table = gtk_table_new(3,5,FALSE);
 
1025
    gtk_container_add(GTK_CONTAINER(Frame),Table);
 
1026
    gtk_container_set_border_width(GTK_CONTAINER(Table),2);
 
1027
 
 
1028
    /* Picture */
 
1029
    PictureLabel = gtk_label_new(_("Pictures:"));
 
1030
    gtk_table_attach(GTK_TABLE(Table),PictureLabel,0,1,0,1,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
1031
    gtk_misc_set_alignment(GTK_MISC(PictureLabel),1,0.5);
 
1032
 
 
1033
    // Scroll window for PictureEntryView
 
1034
    PictureScrollWindow = gtk_scrolled_window_new(NULL, NULL);
 
1035
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(PictureScrollWindow),
 
1036
                                   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
1037
    gtk_table_attach(GTK_TABLE(Table), PictureScrollWindow, 1,4,0,1,
 
1038
                     GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,TablePadding,TablePadding);
 
1039
 
 
1040
    PictureEntryModel = gtk_list_store_new(PICTURE_COLUMN_COUNT,
 
1041
                                           GDK_TYPE_PIXBUF,
 
1042
                                           G_TYPE_STRING,
 
1043
                                           G_TYPE_POINTER);
 
1044
    PictureEntryView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(PictureEntryModel));
 
1045
    //gtk_tree_view_set_reorderable(GTK_TREE_VIEW(PictureEntryView),TRUE);
 
1046
    gtk_container_add(GTK_CONTAINER(PictureScrollWindow), PictureEntryView);
 
1047
    gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(PictureEntryView), FALSE);
 
1048
    gtk_widget_set_size_request(PictureEntryView, -1, 200);
 
1049
    gtk_tooltips_set_tip(Tips,PictureEntryView,_("You can use drag and drop to add picture."),NULL);
 
1050
 
 
1051
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(PictureEntryView));
 
1052
    gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
 
1053
 
 
1054
    renderer = gtk_cell_renderer_pixbuf_new();
 
1055
    column = gtk_tree_view_column_new();
 
1056
    gtk_tree_view_column_pack_start(column, renderer, FALSE);
 
1057
    gtk_tree_view_column_set_attributes(column, renderer,
 
1058
                                        "pixbuf", PICTURE_COLUMN_PIC,
 
1059
                                        NULL);
 
1060
    gtk_tree_view_append_column(GTK_TREE_VIEW(PictureEntryView), column);
 
1061
    gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
 
1062
 
 
1063
    renderer = gtk_cell_renderer_text_new();
 
1064
    column = gtk_tree_view_column_new();
 
1065
    gtk_tree_view_column_pack_start(column, renderer, FALSE);
 
1066
    gtk_tree_view_column_set_attributes(column, renderer,
 
1067
                                        "text", PICTURE_COLUMN_TEXT,
 
1068
                                        NULL);
 
1069
    gtk_tree_view_append_column(GTK_TREE_VIEW(PictureEntryView), column);
 
1070
    gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
 
1071
 
 
1072
    // Activate Drag'n'Drop for the PictureEntryView (and PictureAddButton)
 
1073
    gtk_drag_dest_set(GTK_WIDGET(PictureEntryView),
 
1074
                      GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
 
1075
                      drops, sizeof(drops) / sizeof(GtkTargetEntry),
 
1076
                      GDK_ACTION_COPY);
 
1077
    g_signal_connect(G_OBJECT(PictureEntryView),"drag_data_received", G_CALLBACK(Tag_Area_Picture_Drag_Data), 0);
 
1078
    g_signal_connect(G_OBJECT(selection), "changed", G_CALLBACK(Picture_Selection_Changed_cb), NULL);
 
1079
    g_signal_connect(G_OBJECT(PictureEntryView), "button_press_event",G_CALLBACK(Picture_Entry_View_Button_Pressed),NULL);
 
1080
    g_signal_connect(G_OBJECT(PictureEntryView),"key_press_event", G_CALLBACK(Picture_Entry_View_Key_Pressed),NULL);
 
1081
 
 
1082
    // The mini button for picture
 
1083
    PictureMButton = gtk_button_new();
 
1084
    gtk_table_attach(GTK_TABLE(Table),PictureMButton,4,5,0,1,0,0,TablePadding,TablePadding);
 
1085
    gtk_widget_set_usize(PictureMButton,MButtonSize,MButtonSize);
 
1086
    g_signal_connect(G_OBJECT(PictureMButton),"clicked",G_CALLBACK(Mini_Button_Clicked),NULL);
 
1087
    gtk_tooltips_set_tip(Tips,PictureMButton,_("Tag selected files with these pictures"),NULL);
 
1088
 
 
1089
    // Picture action buttons
 
1090
    hbox = gtk_hbox_new(FALSE, 4);
 
1091
    gtk_table_attach(GTK_TABLE(Table),hbox,1,4,1,2,GTK_FILL,GTK_FILL,TablePadding,TablePadding);
 
1092
 
 
1093
    PictureAddButton = gtk_button_new();
 
1094
    Icon = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_SMALL_TOOLBAR);
 
1095
    gtk_container_add(GTK_CONTAINER(PictureAddButton),Icon);
 
1096
    gtk_box_pack_start(GTK_BOX(hbox),PictureAddButton,FALSE,FALSE,0);
 
1097
    gtk_tooltips_set_tip(Tips,PictureAddButton,_("Add pictures to the tag (drag and drop is also available)."),NULL);
 
1098
 
 
1099
    PictureClearButton = gtk_button_new();
 
1100
    Icon = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_SMALL_TOOLBAR);
 
1101
    gtk_container_add(GTK_CONTAINER(PictureClearButton),Icon);
 
1102
    gtk_box_pack_start(GTK_BOX(hbox),PictureClearButton,FALSE,FALSE,0);
 
1103
    gtk_tooltips_set_tip(Tips,PictureClearButton,_("Remove selected pictures, else all pictures."),NULL);
 
1104
 
 
1105
    Label = gtk_label_new("   ");
 
1106
    gtk_box_pack_start(GTK_BOX(hbox),Label,FALSE,FALSE,0);
 
1107
 
 
1108
    PictureSaveButton = gtk_button_new();
 
1109
    Icon = gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_SMALL_TOOLBAR);
 
1110
    gtk_container_add(GTK_CONTAINER(PictureSaveButton),Icon);
 
1111
    gtk_box_pack_start(GTK_BOX(hbox),PictureSaveButton,FALSE,FALSE,0);
 
1112
    gtk_widget_set_sensitive(GTK_WIDGET(PictureSaveButton), FALSE);
 
1113
    gtk_tooltips_set_tip(Tips,PictureSaveButton,_("Save the selected pictures on the hard disk."),NULL);
 
1114
 
 
1115
    PicturePropertiesButton = gtk_button_new();
 
1116
    Icon = gtk_image_new_from_stock(GTK_STOCK_PROPERTIES, GTK_ICON_SIZE_SMALL_TOOLBAR);
 
1117
    gtk_container_add(GTK_CONTAINER(PicturePropertiesButton),Icon);
 
1118
    gtk_box_pack_start(GTK_BOX(hbox),PicturePropertiesButton,FALSE,FALSE,0);
 
1119
    gtk_widget_set_sensitive(GTK_WIDGET(PicturePropertiesButton), FALSE);
 
1120
    gtk_tooltips_set_tip(Tips,PicturePropertiesButton,_("Set properties of the selected pictures."),NULL);
 
1121
 
 
1122
    g_signal_connect(G_OBJECT(PictureClearButton),      "clicked", G_CALLBACK(Picture_Clear_Button_Clicked), NULL);
 
1123
    g_signal_connect(G_OBJECT(PictureAddButton),        "clicked", G_CALLBACK(Picture_Add_Button_Clicked), NULL);
 
1124
    g_signal_connect(G_OBJECT(PictureSaveButton),       "clicked", G_CALLBACK(Picture_Save_Button_Clicked), NULL);
 
1125
    g_signal_connect(G_OBJECT(PicturePropertiesButton), "clicked", G_CALLBACK(Picture_Properties_Button_Clicked), NULL);
 
1126
 
 
1127
    // Activate Drag'n'Drop for the PictureAddButton (and PictureEntryView)
 
1128
    gtk_drag_dest_set(GTK_WIDGET(PictureAddButton),
 
1129
                    GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP,
 
1130
                    drops, sizeof(drops) / sizeof(GtkTargetEntry),
 
1131
                    GDK_ACTION_COPY);
 
1132
    g_signal_connect(G_OBJECT(PictureAddButton),"drag_data_received", G_CALLBACK(Tag_Area_Picture_Drag_Data), 0);
 
1133
 
 
1134
 
 
1135
    //Attach_Popup_Menu_To_Tag_Entries(GTK_ENTRY(PictureEntryView));
 
1136
    gtk_object_set_data(GTK_OBJECT(PictureEntryView),"MButtonName",PictureMButton);
 
1137
 
 
1138
    gtk_widget_show_all(TagFrame);
 
1139
    return TagFrame;
 
1140
}
 
1141
 
 
1142
 
 
1143
 
 
1144
/*
 
1145
 * Actions when mini buttons are pressed: apply the field to all others files
 
1146
 */
 
1147
void Menu_Mini_Button_Clicked (GtkEntry *entry)
 
1148
{
 
1149
    if ( g_object_get_data(G_OBJECT(entry),"MButtonName") )
 
1150
        Mini_Button_Clicked((GObject *)g_object_get_data(G_OBJECT(entry),"MButtonName"));
 
1151
}
 
1152
void Mini_Button_Clicked (GObject *object)
 
1153
{
 
1154
    GList *etfilelist = NULL;
 
1155
    GList *selection_filelist = NULL;
 
1156
    gchar *string_to_set = NULL;
 
1157
    gchar *string_to_set1 = NULL;
 
1158
    gchar *msg = NULL;
 
1159
    ET_File *etfile;
 
1160
    File_Tag *FileTag;
 
1161
    GtkTreeSelection *selection;
 
1162
 
 
1163
 
 
1164
    if (!ETCore->ETFileDisplayedList || !BrowserList) return;
 
1165
 
 
1166
    // Save the current displayed data
 
1167
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1168
 
 
1169
    // Warning : 'selection_filelist' is not a list of 'ETFile' items!
 
1170
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
1171
    selection_filelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
1172
    // Create an 'ETFile' list from 'selection_filelist'
 
1173
    while (selection_filelist)
 
1174
    {
 
1175
        etfile = Browser_List_Get_ETFile_From_Path(selection_filelist->data);
 
1176
        etfilelist = g_list_append(etfilelist,etfile);
 
1177
 
 
1178
        if (!selection_filelist->next) break;
 
1179
        selection_filelist = g_list_next(selection_filelist);
 
1180
    }
 
1181
    g_list_foreach(selection_filelist, (GFunc)gtk_tree_path_free, NULL);
 
1182
    g_list_free(selection_filelist);
 
1183
 
 
1184
 
 
1185
    if (object==G_OBJECT(TitleMButton))
 
1186
    {
 
1187
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(TitleEntry),0,-1); // The string to apply to all other files
 
1188
        while (etfilelist)
 
1189
        {
 
1190
            etfile = (ET_File *)etfilelist->data;
 
1191
            FileTag = ET_File_Tag_Item_New();
 
1192
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1193
            ET_Set_Field_File_Tag_Item(&FileTag->title,string_to_set);
 
1194
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1195
 
 
1196
            if (!etfilelist->next) break;
 
1197
            etfilelist = g_list_next(etfilelist);
 
1198
        }
 
1199
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1200
            msg = g_strdup_printf(_("Selected files tagged with title '%s'."),string_to_set);
 
1201
        else
 
1202
            msg = g_strdup(_("Removed title from selected files."));
 
1203
    }
 
1204
    else if (object==G_OBJECT(ArtistMButton))
 
1205
    {
 
1206
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(ArtistEntry),0,-1);
 
1207
        while (etfilelist)
 
1208
        {
 
1209
            etfile = (ET_File *)etfilelist->data;
 
1210
            FileTag = ET_File_Tag_Item_New();
 
1211
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1212
            ET_Set_Field_File_Tag_Item(&FileTag->artist,string_to_set);
 
1213
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1214
 
 
1215
            if (!etfilelist->next) break;
 
1216
            etfilelist = g_list_next(etfilelist);
 
1217
        }
 
1218
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1219
            msg = g_strdup_printf(_("Selected files tagged with artist '%s'."),string_to_set);
 
1220
        else
 
1221
            msg = g_strdup(_("Removed artist from selected files."));
 
1222
    }
 
1223
    else if (object==G_OBJECT(AlbumArtistMButton))
 
1224
    {
 
1225
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(AlbumArtistEntry),0,-1);
 
1226
        while (etfilelist)
 
1227
        {
 
1228
            etfile = (ET_File *)etfilelist->data;
 
1229
            FileTag = ET_File_Tag_Item_New();
 
1230
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1231
            ET_Set_Field_File_Tag_Item(&FileTag->album_artist,string_to_set);
 
1232
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1233
 
 
1234
            if (!etfilelist->next) break;
 
1235
            etfilelist = g_list_next(etfilelist);
 
1236
        }
 
1237
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1238
            msg = g_strdup_printf(_("Selected files tagged with album artist '%s'."),string_to_set);
 
1239
        else
 
1240
            msg = g_strdup(_("Removed album artist from selected files."));
 
1241
    }
 
1242
    else if (object==G_OBJECT(AlbumMButton))
 
1243
    {
 
1244
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(AlbumEntry),0,-1);
 
1245
        while (etfilelist)
 
1246
        {
 
1247
            etfile = (ET_File *)etfilelist->data;
 
1248
            FileTag = ET_File_Tag_Item_New();
 
1249
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1250
            ET_Set_Field_File_Tag_Item(&FileTag->album,string_to_set);
 
1251
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1252
 
 
1253
            if (!etfilelist->next) break;
 
1254
            etfilelist = g_list_next(etfilelist);
 
1255
        }
 
1256
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1257
            msg = g_strdup_printf(_("Selected files tagged with album '%s'."),string_to_set);
 
1258
        else
 
1259
            msg = g_strdup(_("Removed album name from selected files."));
 
1260
    }
 
1261
    else if (object==G_OBJECT(DiscNumberMButton))
 
1262
    {
 
1263
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(DiscNumberEntry),0,-1);
 
1264
        while (etfilelist)
 
1265
        {
 
1266
            etfile = (ET_File *)etfilelist->data;
 
1267
            FileTag = ET_File_Tag_Item_New();
 
1268
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1269
            ET_Set_Field_File_Tag_Item(&FileTag->disc_number,string_to_set);
 
1270
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1271
 
 
1272
            if (!etfilelist->next) break;
 
1273
            etfilelist = g_list_next(etfilelist);
 
1274
        }
 
1275
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1276
            msg = g_strdup_printf(_("Selected files tagged with disc number '%s'."),string_to_set);
 
1277
        else
 
1278
            msg = g_strdup(_("Removed disc number from selected files."));
 
1279
    }
 
1280
    else if (object==G_OBJECT(YearMButton))
 
1281
    {
 
1282
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(YearEntry),0,-1);
 
1283
        while (etfilelist)
 
1284
        {
 
1285
            etfile = (ET_File *)etfilelist->data;
 
1286
            FileTag = ET_File_Tag_Item_New();
 
1287
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1288
            ET_Set_Field_File_Tag_Item(&FileTag->year,string_to_set);
 
1289
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1290
 
 
1291
            if (!etfilelist->next) break;
 
1292
            etfilelist = g_list_next(etfilelist);
 
1293
        }
 
1294
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1295
            msg = g_strdup_printf(_("Selected files tagged with year '%s'."),string_to_set);
 
1296
        else
 
1297
            msg = g_strdup(_("Removed year from selected files."));
 
1298
    }
 
1299
    else if (object==G_OBJECT(TrackMButton))
 
1300
    {
 
1301
        /* Used of Track and Total Track values */
 
1302
        string_to_set = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_BIN(TrackEntryCombo)->child)));
 
1303
        string_to_set1 = gtk_editable_get_chars(GTK_EDITABLE(TrackTotalEntry),0,-1);
 
1304
        while (etfilelist)
 
1305
        {
 
1306
            etfile = (ET_File *)etfilelist->data;
 
1307
            FileTag = ET_File_Tag_Item_New();
 
1308
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1309
 
 
1310
            // We apply the TrackEntry field to all others files only if it is to delete
 
1311
            // the field (string=""). Else we don't overwrite the track number
 
1312
            if (!string_to_set || g_utf8_strlen(string_to_set, -1) == 0)
 
1313
                ET_Set_Field_File_Tag_Item(&FileTag->track,string_to_set);
 
1314
            ET_Set_Field_File_Tag_Item(&FileTag->track_total,string_to_set1);
 
1315
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1316
 
 
1317
            if (!etfilelist->next) break;
 
1318
            etfilelist = g_list_next(etfilelist);
 
1319
        }
 
1320
 
 
1321
        if ( string_to_set && g_utf8_strlen(string_to_set, -1) > 0 ) //&& atoi(string_to_set)>0 )
 
1322
        {
 
1323
            if ( string_to_set1 != NULL && g_utf8_strlen(string_to_set1, -1)>0 ) //&& atoi(string_to_set1)>0 )
 
1324
            {
 
1325
                msg = g_strdup_printf(_("Selected files tagged with track like 'xx/%s'."),string_to_set1);
 
1326
            }else
 
1327
            {
 
1328
                msg = g_strdup_printf(_("Selected files tagged with track like 'xx'."));
 
1329
            }
 
1330
        }else
 
1331
        {
 
1332
            msg = g_strdup(_("Removed track number from selected files."));
 
1333
        }
 
1334
    }
 
1335
    else if (object==G_OBJECT(TrackMButtonSequence))
 
1336
    {
 
1337
        /* This part doesn't set the same track number to all files, but sequence the tracks.
 
1338
         * So we must browse the whole 'etfilelistfull' to get position of each selected file.
 
1339
         * Note : 'etfilelistfull' and 'etfilelist' must be sorted in the same order */
 
1340
        GList *etfilelistfull = NULL;
 
1341
        gchar *path = NULL;
 
1342
        gchar *path1 = NULL;
 
1343
        gint i = 0;
 
1344
 
 
1345
        /* FIX ME!: see to fill also the Total Track (it's a good idea?) */
 
1346
        etfilelistfull = g_list_first(ETCore->ETFileList);
 
1347
 
 
1348
        // Sort 'etfilelistfull' and 'etfilelist' in the same order
 
1349
        etfilelist     = ET_Sort_File_List(etfilelist,SORTING_FILE_MODE);
 
1350
        etfilelistfull = ET_Sort_File_List(etfilelistfull,SORTING_FILE_MODE);
 
1351
 
 
1352
        while (etfilelist && etfilelistfull)
 
1353
        {
 
1354
            // To get the path of the file
 
1355
            File_Name *FileNameCur = (File_Name *)((ET_File *)etfilelistfull->data)->FileNameCur->data;
 
1356
            // The ETFile in the selected file list
 
1357
            etfile = etfilelist->data;
 
1358
 
 
1359
            // Restart counter when entering a new directory
 
1360
            g_free(path1);
 
1361
            path1 = g_path_get_dirname(FileNameCur->value);
 
1362
            if ( path && path1 && strcmp(path,path1)!=0 )
 
1363
                i = 0;
 
1364
            if (NUMBER_TRACK_FORMATED)
 
1365
                string_to_set = g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,++i);
 
1366
            else
 
1367
                string_to_set = g_strdup_printf("%d",++i);
 
1368
 
 
1369
            // The file is in the selection?
 
1370
            if ( (ET_File *)etfilelistfull->data == etfile )
 
1371
            {
 
1372
                FileTag = ET_File_Tag_Item_New();
 
1373
                ET_Copy_File_Tag_Item(etfile,FileTag);
 
1374
                ET_Set_Field_File_Tag_Item(&FileTag->track,string_to_set);
 
1375
                ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1376
 
 
1377
                if (!etfilelist->next) break;
 
1378
                etfilelist = g_list_next(etfilelist);
 
1379
            }
 
1380
 
 
1381
            g_free(string_to_set);
 
1382
            g_free(path);
 
1383
            path = g_strdup(path1);
 
1384
 
 
1385
            etfilelistfull = g_list_next(etfilelistfull);
 
1386
        }
 
1387
        g_free(path);
 
1388
        g_free(path1);
 
1389
        //msg = g_strdup_printf(_("All %d tracks numbered sequentially."), ETCore->ETFileSelectionList_Length);
 
1390
        msg = g_strdup_printf(_("Selected tracks numbered sequentially."));
 
1391
    }
 
1392
    else if (object==G_OBJECT(TrackMButtonNbrFiles))
 
1393
    {
 
1394
        /* Used of Track and Total Track values */
 
1395
        while (etfilelist)
 
1396
        {
 
1397
            gchar *path_utf8, *filename_utf8;
 
1398
 
 
1399
            etfile        = (ET_File *)etfilelist->data;
 
1400
            filename_utf8 = ((File_Name *)etfile->FileNameNew->data)->value_utf8;
 
1401
            path_utf8     = g_path_get_dirname(filename_utf8);
 
1402
            if (NUMBER_TRACK_FORMATED)
 
1403
                string_to_set = g_strdup_printf("%.*d",NUMBER_TRACK_FORMATED_SPIN_BUTTON,ET_Get_Number_Of_Files_In_Directory(path_utf8));
 
1404
            else
 
1405
                string_to_set = g_strdup_printf("%d",ET_Get_Number_Of_Files_In_Directory(path_utf8));
 
1406
            g_free(path_utf8);
 
1407
            if (!string_to_set1)
 
1408
                string_to_set1 = g_strdup(string_to_set); // Just for the message below...
 
1409
 
 
1410
            FileTag = ET_File_Tag_Item_New();
 
1411
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1412
            ET_Set_Field_File_Tag_Item(&FileTag->track_total,string_to_set);
 
1413
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1414
 
 
1415
            if (!etfilelist->next) break;
 
1416
            etfilelist = g_list_next(etfilelist);
 
1417
        }
 
1418
 
 
1419
        if ( string_to_set1 != NULL && g_utf8_strlen(string_to_set1, -1)>0 ) //&& atoi(string_to_set1)>0 )
 
1420
        {
 
1421
            msg = g_strdup_printf(_("Selected files tagged with track like 'xx/%s'."),string_to_set1);
 
1422
        }else
 
1423
        {
 
1424
            msg = g_strdup(_("Removed track number from selected files."));
 
1425
        }
 
1426
    }
 
1427
    else if (object==G_OBJECT(GenreMButton))
 
1428
    {
 
1429
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(GenreCombo)->child),0,-1);
 
1430
        while (etfilelist)
 
1431
        {
 
1432
            etfile = (ET_File *)etfilelist->data;
 
1433
            FileTag = ET_File_Tag_Item_New();
 
1434
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1435
            ET_Set_Field_File_Tag_Item(&FileTag->genre,string_to_set);
 
1436
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1437
 
 
1438
            if (!etfilelist->next) break;
 
1439
            etfilelist = g_list_next(etfilelist);
 
1440
        }
 
1441
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1442
            msg = g_strdup_printf(_("Selected files tagged with genre '%s'."),string_to_set);
 
1443
        else
 
1444
            msg = g_strdup(_("Removed genre from selected files."));
 
1445
    }
 
1446
    else if (object==G_OBJECT(CommentMButton))
 
1447
    {
 
1448
        //GtkTextBuffer *textbuffer;
 
1449
        //GtkTextIter    start_iter;
 
1450
        //GtkTextIter    end_iter;
 
1451
        //textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(CommentView));
 
1452
        //gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(textbuffer),&start_iter,&end_iter);
 
1453
        //string_to_set = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(textbuffer),&start_iter,&end_iter,TRUE);
 
1454
 
 
1455
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(CommentEntry),0,-1);
 
1456
        while (etfilelist)
 
1457
        {
 
1458
            etfile = (ET_File *)etfilelist->data;
 
1459
            FileTag = ET_File_Tag_Item_New();
 
1460
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1461
            ET_Set_Field_File_Tag_Item(&FileTag->comment,string_to_set);
 
1462
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1463
 
 
1464
            if (!etfilelist->next) break;
 
1465
            etfilelist = g_list_next(etfilelist);
 
1466
        }
 
1467
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1468
            msg = g_strdup_printf(_("Selected files tagged with comment '%s'."),string_to_set);
 
1469
        else
 
1470
            msg = g_strdup(_("Removed comment from selected files."));
 
1471
    }
 
1472
    else if (object==G_OBJECT(ComposerMButton))
 
1473
    {
 
1474
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(ComposerEntry),0,-1);
 
1475
        while (etfilelist)
 
1476
        {
 
1477
            etfile = (ET_File *)etfilelist->data;
 
1478
            FileTag = ET_File_Tag_Item_New();
 
1479
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1480
            ET_Set_Field_File_Tag_Item(&FileTag->composer,string_to_set);
 
1481
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1482
 
 
1483
            if (!etfilelist->next) break;
 
1484
            etfilelist = g_list_next(etfilelist);
 
1485
        }
 
1486
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1487
            msg = g_strdup_printf(_("Selected files tagged with composer '%s'."),string_to_set);
 
1488
        else
 
1489
            msg = g_strdup(_("Removed composer from selected files."));
 
1490
    }
 
1491
    else if (object==G_OBJECT(OrigArtistMButton))
 
1492
    {
 
1493
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(OrigArtistEntry),0,-1);
 
1494
        while (etfilelist)
 
1495
        {
 
1496
            etfile = (ET_File *)etfilelist->data;
 
1497
            FileTag = ET_File_Tag_Item_New();
 
1498
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1499
            ET_Set_Field_File_Tag_Item(&FileTag->orig_artist,string_to_set);
 
1500
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1501
 
 
1502
            if (!etfilelist->next) break;
 
1503
            etfilelist = g_list_next(etfilelist);
 
1504
        }
 
1505
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1506
            msg = g_strdup_printf(_("Selected files tagged with original artist '%s'."),string_to_set);
 
1507
        else
 
1508
            msg = g_strdup(_("Removed original artist from selected files."));
 
1509
    }
 
1510
    else if (object==G_OBJECT(CopyrightMButton))
 
1511
    {
 
1512
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(CopyrightEntry),0,-1);
 
1513
        while (etfilelist)
 
1514
        {
 
1515
            etfile = (ET_File *)etfilelist->data;
 
1516
            FileTag = ET_File_Tag_Item_New();
 
1517
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1518
            ET_Set_Field_File_Tag_Item(&FileTag->copyright,string_to_set);
 
1519
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1520
 
 
1521
            if (!etfilelist->next) break;
 
1522
            etfilelist = g_list_next(etfilelist);
 
1523
        }
 
1524
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1525
            msg = g_strdup_printf(_("Selected files tagged with copyright '%s'."),string_to_set);
 
1526
        else
 
1527
            msg = g_strdup(_("Removed copyright from selected files."));
 
1528
    }
 
1529
    else if (object==G_OBJECT(URLMButton))
 
1530
    {
 
1531
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(URLEntry),0,-1);
 
1532
        while (etfilelist)
 
1533
        {
 
1534
            etfile = (ET_File *)etfilelist->data;
 
1535
            FileTag = ET_File_Tag_Item_New();
 
1536
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1537
            ET_Set_Field_File_Tag_Item(&FileTag->url,string_to_set);
 
1538
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1539
 
 
1540
            if (!etfilelist->next) break;
 
1541
            etfilelist = g_list_next(etfilelist);
 
1542
        }
 
1543
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1544
            msg = g_strdup_printf(_("Selected files tagged with URL '%s'."),string_to_set);
 
1545
        else
 
1546
            msg = g_strdup(_("Removed URL from selected files."));
 
1547
    }
 
1548
    else if (object==G_OBJECT(EncodedByMButton))
 
1549
    {
 
1550
        string_to_set = gtk_editable_get_chars(GTK_EDITABLE(EncodedByEntry),0,-1);
 
1551
        while (etfilelist)
 
1552
        {
 
1553
            etfile = (ET_File *)etfilelist->data;
 
1554
            FileTag = ET_File_Tag_Item_New();
 
1555
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1556
            ET_Set_Field_File_Tag_Item(&FileTag->encoded_by,string_to_set);
 
1557
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1558
 
 
1559
            if (!etfilelist->next) break;
 
1560
            etfilelist = g_list_next(etfilelist);
 
1561
        }
 
1562
        if (string_to_set != NULL && g_utf8_strlen(string_to_set, -1)>0)
 
1563
            msg = g_strdup_printf(_("Selected files tagged with encoder name '%s'."),string_to_set);
 
1564
        else
 
1565
            msg = g_strdup(_("Removed encoder name from selected files."));
 
1566
    }
 
1567
    else if (object==G_OBJECT(PictureMButton))
 
1568
    {
 
1569
        Picture *res = NULL, *pic, *prev_pic = NULL;
 
1570
        GtkTreeModel *model;
 
1571
        GtkTreeIter iter;
 
1572
 
 
1573
        model = gtk_tree_view_get_model(GTK_TREE_VIEW(PictureEntryView));
 
1574
        if (gtk_tree_model_get_iter_first(model, &iter))
 
1575
        {
 
1576
            do
 
1577
            {
 
1578
                gtk_tree_model_get(model, &iter, PICTURE_COLUMN_DATA, &pic, -1);
 
1579
                pic = Picture_Copy_One(pic);
 
1580
                if (!res)
 
1581
                    res = pic;
 
1582
                else
 
1583
                    prev_pic->next = pic;
 
1584
                prev_pic = pic;
 
1585
            } while (gtk_tree_model_iter_next(model, &iter));
 
1586
        }
 
1587
 
 
1588
        while (etfilelist)
 
1589
        {
 
1590
            etfile = (ET_File *)etfilelist->data;
 
1591
            FileTag = ET_File_Tag_Item_New();
 
1592
            ET_Copy_File_Tag_Item(etfile,FileTag);
 
1593
            ET_Set_Field_File_Tag_Picture((Picture **)&FileTag->picture, res);
 
1594
            ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1595
 
 
1596
            if (!etfilelist->next) break;
 
1597
            etfilelist = g_list_next(etfilelist);
 
1598
        }
 
1599
        if (res)
 
1600
            msg = g_strdup(_("Selected files tagged with pictures."));
 
1601
        else
 
1602
            msg = g_strdup(_("Removed pictures from selected files."));
 
1603
        Picture_Free(res);
 
1604
    }
 
1605
 
 
1606
    g_list_free(etfilelist);
 
1607
 
 
1608
    // Refresh the whole list (faster than file by file) to show changes
 
1609
    Browser_List_Refresh_Whole_List();
 
1610
 
 
1611
    /* Display the current file (Needed when sequencing tracks) */
 
1612
    ET_Display_File_Data_To_UI(ETCore->ETFileDisplayed);
 
1613
 
 
1614
    if (msg)
 
1615
    {
 
1616
        Log_Print(LOG_OK,"%s",msg);
 
1617
        Statusbar_Message(msg,TRUE);
 
1618
        g_free(msg);
 
1619
    }
 
1620
    g_free(string_to_set);
 
1621
    g_free(string_to_set1);
 
1622
 
 
1623
    /* To update state of Undo button */
 
1624
    Update_Command_Buttons_Sensivity();
 
1625
}
 
1626
 
 
1627
 
 
1628
 
 
1629
 
 
1630
/*
 
1631
 * Action when selecting all files
 
1632
 */
 
1633
void Action_Select_All_Files (void)
 
1634
{
 
1635
    /* Save the current displayed data */
 
1636
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1637
 
 
1638
    Browser_List_Select_All_Files();
 
1639
    Update_Command_Buttons_Sensivity();
 
1640
}
 
1641
 
 
1642
 
 
1643
/*
 
1644
 * Action when unselecting all files
 
1645
 */
 
1646
void Action_Unselect_All_Files (void)
 
1647
{
 
1648
    /* Save the current displayed data */
 
1649
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1650
 
 
1651
    Browser_List_Unselect_All_Files();
 
1652
    ETCore->ETFileDisplayed = NULL;
 
1653
}
 
1654
 
 
1655
 
 
1656
/*
 
1657
 * Action when inverting files selection
 
1658
 */
 
1659
void Action_Invert_Files_Selection (void)
 
1660
{
 
1661
    /* Save the current displayed data */
 
1662
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1663
 
 
1664
    Browser_List_Invert_File_Selection();
 
1665
    Update_Command_Buttons_Sensivity();
 
1666
}
 
1667
 
 
1668
 
 
1669
 
 
1670
/*
 
1671
 * Action when First button is selected
 
1672
 */
 
1673
void Action_Select_First_File (void)
 
1674
{
 
1675
    GList *etfilelist;
 
1676
 
 
1677
    if (!ETCore->ETFileDisplayedList)
 
1678
        return;
 
1679
 
 
1680
    /* Save the current displayed data */
 
1681
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1682
 
 
1683
    /* Go to the first item of the list */
 
1684
    etfilelist = ET_Displayed_File_List_First();
 
1685
    if (etfilelist)
 
1686
    {
 
1687
        Browser_List_Unselect_All_Files(); // To avoid the last line still selected
 
1688
        Browser_List_Select_File_By_Etfile((ET_File *)etfilelist->data,TRUE);
 
1689
        ET_Display_File_Data_To_UI((ET_File *)etfilelist->data);
 
1690
    }
 
1691
 
 
1692
    Update_Command_Buttons_Sensivity();
 
1693
    Scan_Rename_File_Generate_Preview();
 
1694
    Scan_Fill_Tag_Generate_Preview();
 
1695
 
 
1696
    if (SET_FOCUS_TO_FIRST_TAG_FIELD)
 
1697
        gtk_widget_grab_focus(GTK_WIDGET(TitleEntry));
 
1698
}
 
1699
 
 
1700
 
 
1701
/*
 
1702
 * Action when Prev button is selected
 
1703
 */
 
1704
void Action_Select_Prev_File (void)
 
1705
{
 
1706
    GList *etfilelist;
 
1707
 
 
1708
    if (!ETCore->ETFileDisplayedList || !ETCore->ETFileDisplayedList->prev)
 
1709
        return;
 
1710
 
 
1711
    /* Save the current displayed data */
 
1712
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1713
 
 
1714
    /* Go to the prev item of the list */
 
1715
    etfilelist = ET_Displayed_File_List_Previous();
 
1716
    if (etfilelist)
 
1717
    {
 
1718
        Browser_List_Unselect_All_Files();
 
1719
        Browser_List_Select_File_By_Etfile((ET_File *)etfilelist->data,TRUE);
 
1720
        ET_Display_File_Data_To_UI((ET_File *)etfilelist->data);
 
1721
    }
 
1722
 
 
1723
//    if (!ETFileList->prev)
 
1724
//        gdk_beep(); // Warm the user
 
1725
 
 
1726
    Update_Command_Buttons_Sensivity();
 
1727
    Scan_Rename_File_Generate_Preview();
 
1728
    Scan_Fill_Tag_Generate_Preview();
 
1729
 
 
1730
    if (SET_FOCUS_TO_FIRST_TAG_FIELD)
 
1731
        gtk_widget_grab_focus(GTK_WIDGET(TitleEntry));
 
1732
}
 
1733
 
 
1734
 
 
1735
/*
 
1736
 * Action when Next button is selected
 
1737
 */
 
1738
void Action_Select_Next_File (void)
 
1739
{
 
1740
    GList *etfilelist;
 
1741
 
 
1742
    if (!ETCore->ETFileDisplayedList || !ETCore->ETFileDisplayedList->next)
 
1743
        return;
 
1744
 
 
1745
    /* Save the current displayed data */
 
1746
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1747
 
 
1748
    /* Go to the next item of the list */
 
1749
    etfilelist = ET_Displayed_File_List_Next();
 
1750
    if (etfilelist)
 
1751
    {
 
1752
        Browser_List_Unselect_All_Files();
 
1753
        Browser_List_Select_File_By_Etfile((ET_File *)etfilelist->data,TRUE);
 
1754
        ET_Display_File_Data_To_UI((ET_File *)etfilelist->data);
 
1755
    }
 
1756
 
 
1757
//    if (!ETFileList->next)
 
1758
//        gdk_beep(); // Warm the user
 
1759
 
 
1760
    Update_Command_Buttons_Sensivity();
 
1761
    Scan_Rename_File_Generate_Preview();
 
1762
    Scan_Fill_Tag_Generate_Preview();
 
1763
 
 
1764
    if (SET_FOCUS_TO_FIRST_TAG_FIELD)
 
1765
        gtk_widget_grab_focus(GTK_WIDGET(TitleEntry));
 
1766
}
 
1767
 
 
1768
 
 
1769
/*
 
1770
 * Action when Last button is selected
 
1771
 */
 
1772
void Action_Select_Last_File (void)
 
1773
{
 
1774
    GList *etfilelist;
 
1775
 
 
1776
    if (!ETCore->ETFileDisplayedList || !ETCore->ETFileDisplayedList->next)
 
1777
        return;
 
1778
 
 
1779
    /* Save the current displayed data */
 
1780
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1781
 
 
1782
    /* Go to the last item of the list */
 
1783
    etfilelist = ET_Displayed_File_List_Last();
 
1784
    if (etfilelist)
 
1785
    {
 
1786
        Browser_List_Unselect_All_Files();
 
1787
        Browser_List_Select_File_By_Etfile((ET_File *)etfilelist->data,TRUE);
 
1788
        ET_Display_File_Data_To_UI((ET_File *)etfilelist->data);
 
1789
    }
 
1790
 
 
1791
    Update_Command_Buttons_Sensivity();
 
1792
    Scan_Rename_File_Generate_Preview();
 
1793
    Scan_Fill_Tag_Generate_Preview();
 
1794
 
 
1795
    if (SET_FOCUS_TO_FIRST_TAG_FIELD)
 
1796
        gtk_widget_grab_focus(GTK_WIDGET(TitleEntry));
 
1797
}
 
1798
 
 
1799
 
 
1800
/*
 
1801
 * Select a file in the "main list" using the ETFile adress of each item.
 
1802
 */
 
1803
void Action_Select_Nth_File_By_Etfile (ET_File *ETFile)
 
1804
{
 
1805
    if (!ETCore->ETFileDisplayedList)
 
1806
        return;
 
1807
 
 
1808
    /* Save the current displayed data */
 
1809
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1810
 
 
1811
    /* Display the item */
 
1812
    Browser_List_Select_File_By_Etfile(ETFile,TRUE);
 
1813
    ET_Displayed_File_List_By_Etfile(ETFile); // Just to update 'ETFileDisplayedList'
 
1814
    ET_Display_File_Data_To_UI(ETFile);
 
1815
 
 
1816
    Update_Command_Buttons_Sensivity();
 
1817
    Scan_Rename_File_Generate_Preview();
 
1818
    Scan_Fill_Tag_Generate_Preview();
 
1819
}
 
1820
 
 
1821
 
 
1822
/*
 
1823
 * Action when Scan button is pressed
 
1824
 */
 
1825
void Action_Scan_Selected_Files (void)
 
1826
{
 
1827
    gint progress_bar_index;
 
1828
    gint selectcount;
 
1829
    gchar progress_bar_text[30];
 
1830
    double fraction;
 
1831
    GList *selfilelist = NULL;
 
1832
    ET_File *etfile;
 
1833
    GtkTreeSelection *selection;
 
1834
 
 
1835
    if (!ETCore->ETFileDisplayedList || !BrowserList) return;
 
1836
 
 
1837
    /* Check if scanner window is opened */
 
1838
    if (!ScannerWindow)
 
1839
    {
 
1840
        Open_ScannerWindow(SCANNER_TYPE);
 
1841
        Statusbar_Message(_("Select Mode and Mask, and redo the same action"),TRUE);
 
1842
        return;
 
1843
    }
 
1844
 
 
1845
    /* Save the current displayed data */
 
1846
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1847
 
 
1848
    /* Initialize status bar */
 
1849
    selectcount = gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)));
 
1850
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar),0);
 
1851
    progress_bar_index = 0;
 
1852
    g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, selectcount);
 
1853
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
1854
 
 
1855
    /* Set to unsensitive all command buttons (except Quit button) */
 
1856
    Disable_Command_Buttons();
 
1857
 
 
1858
    progress_bar_index = 0;
 
1859
 
 
1860
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
1861
    selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
1862
    while (selfilelist)
 
1863
    {
 
1864
        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
 
1865
 
 
1866
        // Run the current scanner
 
1867
        Scan_Select_Mode_And_Run_Scanner(etfile);
 
1868
 
 
1869
        fraction = (++progress_bar_index) / (double) selectcount;
 
1870
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), fraction);
 
1871
        g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, selectcount);
 
1872
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
1873
 
 
1874
        /* Needed to refresh status bar */
 
1875
        while (gtk_events_pending())
 
1876
            gtk_main_iteration();
 
1877
 
 
1878
        if (!selfilelist->next) break;
 
1879
        selfilelist = g_list_next(selfilelist);
 
1880
    }
 
1881
 
 
1882
    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
1883
    g_list_free(selfilelist);
 
1884
 
 
1885
    // Refresh the whole list (faster than file by file) to show changes
 
1886
    Browser_List_Refresh_Whole_List();
 
1887
 
 
1888
    /* Display the current file */
 
1889
    ET_Display_File_Data_To_UI(ETCore->ETFileDisplayed);
 
1890
 
 
1891
    /* To update state of command buttons */
 
1892
    Update_Command_Buttons_Sensivity();
 
1893
 
 
1894
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), "");
 
1895
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0);
 
1896
    Statusbar_Message(_("All tags have been scanned"),TRUE);
 
1897
}
 
1898
 
 
1899
 
 
1900
 
 
1901
/*
 
1902
 * Action when Remove button is pressed
 
1903
 */
 
1904
void Action_Remove_Selected_Tags (void)
 
1905
{
 
1906
    GList *selfilelist = NULL;
 
1907
    ET_File *etfile;
 
1908
    File_Tag *FileTag;
 
1909
    gint progress_bar_index;
 
1910
    gint selectcount;
 
1911
    double fraction;
 
1912
    GtkTreeSelection *selection;
 
1913
 
 
1914
    if (!ETCore->ETFileDisplayedList || !BrowserList) return;
 
1915
 
 
1916
    /* Save the current displayed data */
 
1917
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1918
 
 
1919
    /* Initialize status bar */
 
1920
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0.0);
 
1921
    selectcount = gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)));
 
1922
    progress_bar_index = 0;
 
1923
 
 
1924
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
1925
    selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
1926
    while (selfilelist)
 
1927
    {
 
1928
        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
 
1929
        FileTag = ET_File_Tag_Item_New();
 
1930
        ET_Manage_Changes_Of_File_Data(etfile,NULL,FileTag);
 
1931
 
 
1932
        fraction = (++progress_bar_index) / (double) selectcount;
 
1933
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), fraction);
 
1934
        /* Needed to refresh status bar */
 
1935
        while (gtk_events_pending())
 
1936
            gtk_main_iteration();
 
1937
 
 
1938
        if (!selfilelist->next) break;
 
1939
        selfilelist = g_list_next(selfilelist);
 
1940
    }
 
1941
 
 
1942
    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
1943
    g_list_free(selfilelist);
 
1944
 
 
1945
    // Refresh the whole list (faster than file by file) to show changes
 
1946
    Browser_List_Refresh_Whole_List();
 
1947
 
 
1948
    /* Display the current file */
 
1949
    ET_Display_File_Data_To_UI(ETCore->ETFileDisplayed);
 
1950
    Update_Command_Buttons_Sensivity();
 
1951
 
 
1952
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0.0);
 
1953
    Statusbar_Message(_("All tags have been removed"),TRUE);
 
1954
}
 
1955
 
 
1956
 
 
1957
 
 
1958
/*
 
1959
 * Action when Undo button is pressed.
 
1960
 * Action_Undo_Selected_Files: Undo the last changes for the selected files.
 
1961
 * Action_Undo_From_History_List: Undo the changes of the last modified file of the list.
 
1962
 */
 
1963
gint Action_Undo_Selected_Files (void)
 
1964
{
 
1965
    GList *selfilelist = NULL;
 
1966
    gboolean state = FALSE;
 
1967
    ET_File *etfile;
 
1968
    GtkTreeSelection *selection;
 
1969
 
 
1970
    if (!ETCore->ETFileDisplayedList || !BrowserList) return FALSE;
 
1971
 
 
1972
    /* Save the current displayed data */
 
1973
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
1974
 
 
1975
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
1976
    selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
1977
    while (selfilelist)
 
1978
    {
 
1979
        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
 
1980
        state |= ET_Undo_File_Data(etfile);
 
1981
 
 
1982
        if (!selfilelist->next) break;
 
1983
        selfilelist = g_list_next(selfilelist);
 
1984
    }
 
1985
 
 
1986
    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
1987
    g_list_free(selfilelist);
 
1988
 
 
1989
    // Refresh the whole list (faster than file by file) to show changes
 
1990
    Browser_List_Refresh_Whole_List();
 
1991
 
 
1992
    /* Display the current file */
 
1993
    ET_Display_File_Data_To_UI(ETCore->ETFileDisplayed);
 
1994
    Update_Command_Buttons_Sensivity();
 
1995
 
 
1996
    //ET_Debug_Print_File_List(ETCore->ETFileList,__FILE__,__LINE__,__FUNCTION__);
 
1997
 
 
1998
    return state;
 
1999
}
 
2000
 
 
2001
 
 
2002
void Action_Undo_From_History_List (void)
 
2003
{
 
2004
    ET_File *ETFile;
 
2005
 
 
2006
    if (!ETCore->ETFileList) return;
 
2007
 
 
2008
    /* Save the current displayed data */
 
2009
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
2010
 
 
2011
    ETFile = ET_Undo_History_File_Data();
 
2012
    if (ETFile)
 
2013
    {
 
2014
        ET_Display_File_Data_To_UI(ETFile);
 
2015
        Browser_List_Select_File_By_Etfile(ETFile,TRUE);
 
2016
        Browser_List_Refresh_File_In_List(ETFile);
 
2017
    }
 
2018
 
 
2019
    Update_Command_Buttons_Sensivity();
 
2020
}
 
2021
 
 
2022
 
 
2023
 
 
2024
/*
 
2025
 * Action when Redo button is pressed.
 
2026
 * Action_Redo_Selected_Files: Redo the last changes for the selected files.
 
2027
 * Action_Redo_From_History_List: Redo the changes of the last modified file of the list.
 
2028
 */
 
2029
gint Action_Redo_Selected_File (void)
 
2030
{
 
2031
    GList *selfilelist = NULL;
 
2032
    gboolean state = FALSE;
 
2033
    ET_File *etfile;
 
2034
    GtkTreeSelection *selection;
 
2035
 
 
2036
    if (!ETCore->ETFileDisplayedList || !BrowserList) return FALSE;
 
2037
 
 
2038
    /* Save the current displayed data */
 
2039
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
2040
 
 
2041
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
2042
    selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
2043
    while (selfilelist)
 
2044
    {
 
2045
        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
 
2046
        state |= ET_Redo_File_Data(etfile);
 
2047
 
 
2048
        if (!selfilelist->next) break;
 
2049
        selfilelist = g_list_next(selfilelist);
 
2050
    }
 
2051
 
 
2052
    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
2053
    g_list_free(selfilelist);
 
2054
 
 
2055
    // Refresh the whole list (faster than file by file) to show changes
 
2056
    Browser_List_Refresh_Whole_List();
 
2057
 
 
2058
    /* Display the current file */
 
2059
    ET_Display_File_Data_To_UI(ETCore->ETFileDisplayed);
 
2060
    Update_Command_Buttons_Sensivity();
 
2061
 
 
2062
    return state;
 
2063
}
 
2064
 
 
2065
 
 
2066
void Action_Redo_From_History_List (void)
 
2067
{
 
2068
    ET_File *ETFile;
 
2069
 
 
2070
    if (!ETCore->ETFileDisplayedList) return;
 
2071
 
 
2072
    /* Save the current displayed data */
 
2073
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
2074
 
 
2075
    ETFile = ET_Redo_History_File_Data();
 
2076
    if (ETFile)
 
2077
    {
 
2078
        ET_Display_File_Data_To_UI(ETFile);
 
2079
        Browser_List_Select_File_By_Etfile(ETFile,TRUE);
 
2080
        Browser_List_Refresh_File_In_List(ETFile);
 
2081
    }
 
2082
 
 
2083
    Update_Command_Buttons_Sensivity();
 
2084
}
 
2085
 
 
2086
 
 
2087
 
 
2088
 
 
2089
/*
 
2090
 * Action when Save button is pressed
 
2091
 */
 
2092
void Action_Save_Selected_Files (void)
 
2093
{
 
2094
    Save_Selected_Files_With_Answer(FALSE);
 
2095
}
 
2096
 
 
2097
void Action_Force_Saving_Selected_Files (void)
 
2098
{
 
2099
    Save_Selected_Files_With_Answer(TRUE);
 
2100
}
 
2101
 
 
2102
 
 
2103
/*
 
2104
 * Will save the full list of file (not only the selected files in list)
 
2105
 * and check if we must save also only the changed files or all files
 
2106
 * (force_saving_files==TRUE)
 
2107
 */
 
2108
gint Save_All_Files_With_Answer (gboolean force_saving_files)
 
2109
{
 
2110
    GList *etfilelist;
 
2111
 
 
2112
    if (!ETCore || !ETCore->ETFileList) return FALSE;
 
2113
    etfilelist = g_list_first(ETCore->ETFileList);
 
2114
    return Save_List_Of_Files(etfilelist,force_saving_files);
 
2115
}
 
2116
 
 
2117
/*
 
2118
 * Will save only the selected files in the file list
 
2119
 */
 
2120
gint Save_Selected_Files_With_Answer (gboolean force_saving_files)
 
2121
{
 
2122
    gint toreturn;
 
2123
    GList *etfilelist = NULL;
 
2124
    GList *selfilelist = NULL;
 
2125
    ET_File *etfile;
 
2126
    GtkTreeSelection *selection;
 
2127
 
 
2128
    if (!BrowserList) return FALSE;
 
2129
 
 
2130
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
2131
    selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
2132
    while (selfilelist)
 
2133
    {
 
2134
        etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
 
2135
        etfilelist = g_list_append(etfilelist, etfile);
 
2136
 
 
2137
        if (!selfilelist->next) break;
 
2138
        selfilelist = selfilelist->next;
 
2139
    }
 
2140
    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
2141
    g_list_free(selfilelist);
 
2142
 
 
2143
    toreturn = Save_List_Of_Files(etfilelist, force_saving_files);
 
2144
    g_list_free(etfilelist);
 
2145
    return toreturn;
 
2146
}
 
2147
 
 
2148
/*
 
2149
 * Save_List_Of_Files: Function to save a list of files.
 
2150
 *  - force_saving_files = TRUE => force saving the file even if it wasn't changed
 
2151
 *  - force_saving_files = FALSE => force saving only the changed files
 
2152
 */
 
2153
gint Save_List_Of_Files (GList *etfilelist, gboolean force_saving_files)
 
2154
{
 
2155
    gint       progress_bar_index;
 
2156
    gint       saving_answer;
 
2157
    gint       nb_files_to_save;
 
2158
    gint       nb_files_changed_by_ext_program;
 
2159
    gchar     *msg;
 
2160
    gchar      progress_bar_text[30];
 
2161
    GList     *etfilelist_tmp;
 
2162
    ET_File   *etfile_save_position = NULL;
 
2163
    File_Tag  *FileTag;
 
2164
    File_Name *FileNameNew;
 
2165
    double     fraction;
 
2166
    GtkAction *uiaction;
 
2167
    GtkWidget *TBViewMode;
 
2168
    GtkWidget *widget_focused;
 
2169
    GtkTreePath *currentPath = NULL;
 
2170
 
 
2171
    if (!ETCore) return FALSE;
 
2172
 
 
2173
    /* Save the current position in the list */
 
2174
    etfile_save_position = ETCore->ETFileDisplayed;
 
2175
 
 
2176
    /* Save the current displayed data */
 
2177
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
2178
 
 
2179
    /* Save widget that has current focus, to give it again the focus after saving */
 
2180
    widget_focused = gtk_window_get_focus(GTK_WINDOW(MainWindow));
 
2181
 
 
2182
    /* Count the number of files to save */
 
2183
    /* Count the number of files changed by an external program */
 
2184
    nb_files_to_save = 0;
 
2185
    nb_files_changed_by_ext_program = 0;
 
2186
    etfilelist_tmp = etfilelist;
 
2187
    while (etfilelist_tmp)
 
2188
    {
 
2189
        struct stat   statbuf;
 
2190
        ET_File   *ETFile   = (ET_File *)etfilelist_tmp->data;
 
2191
        File_Tag  *FileTag  = (File_Tag *)ETFile->FileTag->data;
 
2192
        File_Name *FileName = (File_Name *)ETFile->FileNameNew->data;
 
2193
        gchar *filename_cur = ((File_Name *)ETFile->FileNameCur->data)->value;
 
2194
        gchar *filename_cur_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;
 
2195
        gchar *basename_cur_utf8 = g_path_get_basename(filename_cur_utf8);
 
2196
 
 
2197
        // Count only the changed files or all files if force_saving_files==TRUE
 
2198
        if ( force_saving_files
 
2199
        || (FileName && FileName->saved==FALSE) || (FileTag && FileTag->saved==FALSE) )
 
2200
            nb_files_to_save++;
 
2201
 
 
2202
        stat(filename_cur,&statbuf);
 
2203
        if (ETFile->FileModificationTime != statbuf.st_mtime)
 
2204
            nb_files_changed_by_ext_program++;
 
2205
        g_free(basename_cur_utf8);
 
2206
 
 
2207
        etfilelist_tmp = etfilelist_tmp->next;
 
2208
    }
 
2209
 
 
2210
    /* Initialize status bar */
 
2211
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar),0);
 
2212
    progress_bar_index = 0;
 
2213
    g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nb_files_to_save);
 
2214
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
2215
 
 
2216
    /* Set to unsensitive all command buttons (except Quit button) */
 
2217
    Disable_Command_Buttons();
 
2218
    Browser_Area_Set_Sensitive(FALSE);
 
2219
    Tag_Area_Set_Sensitive(FALSE);
 
2220
    File_Area_Set_Sensitive(FALSE);
 
2221
 
 
2222
    /* Show msgbox (if needed) to ask confirmation ('SF' for Save File) */
 
2223
    SF_HideMsgbox_Write_Tag = 0;
 
2224
    SF_HideMsgbox_Rename_File = 0;
 
2225
 
 
2226
    Main_Stop_Button_Pressed = 0;
 
2227
    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop"); // Activate the stop button
 
2228
    g_object_set(uiaction, "sensitive", FALSE, NULL);
 
2229
 
 
2230
    /*
 
2231
     * Check if file was changed by an external program
 
2232
     */
 
2233
    if (nb_files_changed_by_ext_program > 0)
 
2234
    {
 
2235
        // Some files were changed by other program than EasyTAG
 
2236
        GtkWidget *msgbox = NULL;
 
2237
        gchar *msg;
 
2238
        gint response;
 
2239
 
 
2240
        msg = g_strdup_printf(_("Be careful, several files (%d file(s)) were changed by an external program.\n"
 
2241
                                "Do you want to continue anyway?"),nb_files_changed_by_ext_program);
 
2242
        msgbox = msg_box_new(_("Saving File(s)..."),
 
2243
                             GTK_WINDOW(MainWindow),
 
2244
                             NULL,
 
2245
                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2246
                             msg,
 
2247
                             GTK_STOCK_DIALOG_WARNING,
 
2248
                             GTK_STOCK_NO,  GTK_RESPONSE_NO,
 
2249
                                                         GTK_STOCK_YES, GTK_RESPONSE_YES,
 
2250
                             NULL);
 
2251
        g_free(msg);
 
2252
 
 
2253
        response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
2254
        gtk_widget_destroy(msgbox);
 
2255
 
 
2256
        switch (response)
 
2257
        {
 
2258
            case GTK_RESPONSE_YES:
 
2259
                break;
 
2260
            case GTK_RESPONSE_NO:
 
2261
            case GTK_RESPONSE_NONE:
 
2262
                Main_Stop_Button_Pressed = 1; // To don't enter to following loop
 
2263
                break;
 
2264
        }
 
2265
    }
 
2266
 
 
2267
    etfilelist_tmp = etfilelist;
 
2268
    while (etfilelist_tmp && !Main_Stop_Button_Pressed)
 
2269
    {
 
2270
        FileTag     = ((ET_File *)etfilelist_tmp->data)->FileTag->data;
 
2271
        FileNameNew = ((ET_File *)etfilelist_tmp->data)->FileNameNew->data;
 
2272
 
 
2273
        /* We process only the files changed and not saved, or we force to save all
 
2274
         * files if force_saving_files==TRUE */
 
2275
        if ( force_saving_files
 
2276
        || FileTag->saved == FALSE || FileNameNew->saved == FALSE )
 
2277
        {
 
2278
            ET_Display_File_Data_To_UI((ET_File *)etfilelist_tmp->data);
 
2279
            // Use of 'currentPath' to try to increase speed. Indeed, in many
 
2280
            // cases, the next file to select, is the next in the list
 
2281
            currentPath = Browser_List_Select_File_By_Etfile2((ET_File *)etfilelist_tmp->data,FALSE,currentPath);
 
2282
 
 
2283
            fraction = (++progress_bar_index) / (double) nb_files_to_save;
 
2284
            gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), fraction);
 
2285
            g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nb_files_to_save);
 
2286
            gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
2287
 
 
2288
            /* Needed to refresh status bar */
 
2289
            while (gtk_events_pending())
 
2290
                gtk_main_iteration();
 
2291
 
 
2292
            // Save tag and rename file
 
2293
            saving_answer = Save_File((ET_File *)etfilelist_tmp->data, (nb_files_to_save>1) ? TRUE : FALSE, force_saving_files);
 
2294
 
 
2295
            if (saving_answer == -1)
 
2296
            {
 
2297
                /* Stop saving files + reinit progress bar */
 
2298
                gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), "");
 
2299
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0.0);
 
2300
                Statusbar_Message(_("Saving files was stopped..."),TRUE);
 
2301
                /* To update state of command buttons */
 
2302
                Update_Command_Buttons_Sensivity();
 
2303
                Browser_Area_Set_Sensitive(TRUE);
 
2304
                Tag_Area_Set_Sensitive(TRUE);
 
2305
                File_Area_Set_Sensitive(TRUE);
 
2306
 
 
2307
                return -1; /* We stop all actions */
 
2308
            }
 
2309
        }
 
2310
 
 
2311
        etfilelist_tmp = etfilelist_tmp->next;
 
2312
        if (Main_Stop_Button_Pressed == 1 )
 
2313
            break;
 
2314
 
 
2315
    }
 
2316
 
 
2317
    if (currentPath)
 
2318
        gtk_tree_path_free(currentPath);
 
2319
 
 
2320
    if (Main_Stop_Button_Pressed)
 
2321
        msg = g_strdup(_("Saving files was stopped..."));
 
2322
    else
 
2323
        msg = g_strdup(_("All files have been saved..."));
 
2324
 
 
2325
    Main_Stop_Button_Pressed = 0;
 
2326
    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
 
2327
    g_object_set(uiaction, "sensitive", FALSE, NULL);
 
2328
 
 
2329
    /* Return to the saved position in the list */
 
2330
    ET_Display_File_Data_To_UI(etfile_save_position);
 
2331
    Browser_List_Select_File_By_Etfile(etfile_save_position,TRUE);
 
2332
 
 
2333
    /* Browser is on mode : Artist + Album list */
 
2334
    TBViewMode = gtk_ui_manager_get_widget(UIManager, "/ToolBar/ViewModeToggle");
 
2335
    if ( gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(TBViewMode)) )
 
2336
        Browser_Display_Tree_Or_Artist_Album_List();
 
2337
 
 
2338
    /* To update state of command buttons */
 
2339
    Update_Command_Buttons_Sensivity();
 
2340
    Browser_Area_Set_Sensitive(TRUE);
 
2341
    Tag_Area_Set_Sensitive(TRUE);
 
2342
    File_Area_Set_Sensitive(TRUE);
 
2343
 
 
2344
    /* Give again focus to the first entry, else the focus is passed to an other */
 
2345
    gtk_widget_grab_focus(GTK_WIDGET(widget_focused));
 
2346
 
 
2347
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), "");
 
2348
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0);
 
2349
    Statusbar_Message(msg,TRUE);
 
2350
    g_free(msg);
 
2351
 
 
2352
    return TRUE;
 
2353
}
 
2354
 
 
2355
 
 
2356
 
 
2357
/*
 
2358
 * Delete a file on the hard disk
 
2359
 */
 
2360
void Action_Delete_Selected_Files (void)
 
2361
{
 
2362
    Delete_Selected_Files_With_Answer();
 
2363
}
 
2364
 
 
2365
 
 
2366
gint Delete_Selected_Files_With_Answer (void)
 
2367
{
 
2368
    GList *selfilelist;
 
2369
    GList *rowreflist = NULL;
 
2370
    gint   progress_bar_index;
 
2371
    gint   saving_answer;
 
2372
    gint   nb_files_to_delete;
 
2373
    gint   nb_files_deleted = 0;
 
2374
    gchar *msg;
 
2375
    gchar progress_bar_text[30];
 
2376
    double fraction;
 
2377
    GtkTreeModel *treemodel;
 
2378
    GtkTreeRowReference *rowref;
 
2379
    GtkTreeSelection *selection;
 
2380
 
 
2381
    if (!ETCore->ETFileDisplayedList || !BrowserList) return FALSE;
 
2382
 
 
2383
    /* Save the current displayed data */
 
2384
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
2385
 
 
2386
    /* Number of files to save */
 
2387
    nb_files_to_delete = gtk_tree_selection_count_selected_rows(gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList)));
 
2388
 
 
2389
    /* Initialize status bar */
 
2390
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar),0);
 
2391
    progress_bar_index = 0;
 
2392
    g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nb_files_to_delete);
 
2393
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
2394
 
 
2395
    /* Set to unsensitive all command buttons (except Quit button) */
 
2396
    Disable_Command_Buttons();
 
2397
    Browser_Area_Set_Sensitive(FALSE);
 
2398
    Tag_Area_Set_Sensitive(FALSE);
 
2399
    File_Area_Set_Sensitive(FALSE);
 
2400
 
 
2401
    /* Show msgbox (if needed) to ask confirmation */
 
2402
    SF_HideMsgbox_Delete_File = 0;
 
2403
 
 
2404
    selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
2405
    selfilelist = gtk_tree_selection_get_selected_rows(selection, &treemodel);
 
2406
    while (selfilelist)
 
2407
    {
 
2408
        rowref = gtk_tree_row_reference_new(treemodel, selfilelist->data);
 
2409
        rowreflist = g_list_append(rowreflist, rowref);
 
2410
 
 
2411
        if (!selfilelist->next) break;
 
2412
        selfilelist = selfilelist->next;
 
2413
    }
 
2414
 
 
2415
    while (rowreflist)
 
2416
    {
 
2417
        GtkTreePath *path;
 
2418
        ET_File *ETFile;
 
2419
 
 
2420
        path = gtk_tree_row_reference_get_path(rowreflist->data);
 
2421
        ETFile = Browser_List_Get_ETFile_From_Path(path);
 
2422
        gtk_tree_path_free(path);
 
2423
 
 
2424
        ET_Display_File_Data_To_UI(ETFile);
 
2425
        Browser_List_Select_File_By_Etfile(ETFile,FALSE);
 
2426
        fraction = (++progress_bar_index) / (double) nb_files_to_delete;
 
2427
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), fraction);
 
2428
        g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nb_files_to_delete);
 
2429
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
2430
         /* Needed to refresh status bar */
 
2431
        while (gtk_events_pending())
 
2432
            gtk_main_iteration();
 
2433
 
 
2434
        saving_answer = Delete_File(ETFile,(nb_files_to_delete>1)?TRUE:FALSE);
 
2435
 
 
2436
        switch (saving_answer)
 
2437
        {
 
2438
            case 1:
 
2439
                nb_files_deleted += saving_answer;
 
2440
                // Remove file in the browser (corresponding line in the clist)
 
2441
                Browser_List_Remove_File(ETFile);
 
2442
                // Remove file from file list
 
2443
                ET_Remove_File_From_File_List(ETFile);
 
2444
                break;
 
2445
            case 0:
 
2446
                break;
 
2447
            case -1:
 
2448
                // Stop deleting files + reinit progress bar
 
2449
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar),0.0);
 
2450
                // To update state of command buttons
 
2451
                Update_Command_Buttons_Sensivity();
 
2452
                Browser_Area_Set_Sensitive(TRUE);
 
2453
                Tag_Area_Set_Sensitive(TRUE);
 
2454
                File_Area_Set_Sensitive(TRUE);
 
2455
 
 
2456
                g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
2457
                g_list_free(selfilelist);
 
2458
                return -1; // We stop all actions
 
2459
        }
 
2460
 
 
2461
        if (!rowreflist->next) break;
 
2462
        rowreflist = rowreflist->next;
 
2463
    }
 
2464
 
 
2465
    g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
2466
    g_list_free(selfilelist);
 
2467
    g_list_foreach(rowreflist, (GFunc) gtk_tree_row_reference_free, NULL);
 
2468
    g_list_free(rowreflist);
 
2469
 
 
2470
    if (nb_files_deleted < nb_files_to_delete)
 
2471
        msg = g_strdup(_("Files have been partially deleted..."));
 
2472
    else
 
2473
        msg = g_strdup(_("All files have been deleted..."));
 
2474
 
 
2475
    // It's important to displayed the new item, as it'll check the changes in Browser_Display_Tree_Or_Artist_Album_List
 
2476
    if (ETCore->ETFileDisplayed)
 
2477
        ET_Display_File_Data_To_UI(ETCore->ETFileDisplayed);
 
2478
    /*else if (ET_Displayed_File_List_Current())
 
2479
        ET_Display_File_Data_To_UI((ET_File *)ET_Displayed_File_List_Current()->data);*/
 
2480
 
 
2481
    // Load list...
 
2482
    Browser_List_Load_File_List(ETCore->ETFileDisplayedList, NULL);
 
2483
    // Rebuild the list...
 
2484
    Browser_Display_Tree_Or_Artist_Album_List();
 
2485
 
 
2486
    /* To update state of command buttons */
 
2487
    Update_Command_Buttons_Sensivity();
 
2488
    Browser_Area_Set_Sensitive(TRUE);
 
2489
    Tag_Area_Set_Sensitive(TRUE);
 
2490
    File_Area_Set_Sensitive(TRUE);
 
2491
 
 
2492
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), "");
 
2493
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0);
 
2494
    Statusbar_Message(msg,TRUE);
 
2495
    g_free(msg);
 
2496
 
 
2497
    return TRUE;
 
2498
}
 
2499
 
 
2500
 
 
2501
 
 
2502
/*
 
2503
 * Save changes of the ETFile (write tag and rename file)
 
2504
 *  - multiple_files = TRUE  : when saving files, a msgbox appears with ability
 
2505
 *                             to do the same action for all files.
 
2506
 *  - multiple_files = FALSE : appears only a msgbox to ask confirmation.
 
2507
 */
 
2508
gint Save_File (ET_File *ETFile, gboolean multiple_files, gboolean force_saving_files)
 
2509
{
 
2510
    File_Tag  *FileTag;
 
2511
    File_Name *FileNameNew;
 
2512
    gchar *msg = NULL;
 
2513
    gchar *msg_title = NULL;
 
2514
    gint stop_loop = 0;
 
2515
    //struct stat   statbuf;
 
2516
    //gchar *filename_cur = ((File_Name *)ETFile->FileNameCur->data)->value;
 
2517
    gchar *filename_cur_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;
 
2518
    gchar *filename_new_utf8 = ((File_Name *)ETFile->FileNameNew->data)->value_utf8;
 
2519
    gchar *basename_cur_utf8, *basename_new_utf8;
 
2520
    gchar *dirname_cur_utf8, *dirname_new_utf8;
 
2521
 
 
2522
 
 
2523
    if (!ETFile) return 0;
 
2524
 
 
2525
    basename_cur_utf8 = g_path_get_basename(filename_cur_utf8);
 
2526
    basename_new_utf8 = g_path_get_basename(filename_new_utf8);
 
2527
 
 
2528
    /* Save the current displayed data */
 
2529
    //ET_Save_File_Data_From_UI((ET_File *)ETFileList->data); // Not needed, because it was done before
 
2530
    FileTag     = ETFile->FileTag->data;
 
2531
    FileNameNew = ETFile->FileNameNew->data;
 
2532
 
 
2533
    /*
 
2534
     * Check if file was changed by an external program
 
2535
     */
 
2536
    /*stat(filename_cur,&statbuf);
 
2537
    if (ETFile->FileModificationTime != statbuf.st_mtime)
 
2538
    {
 
2539
        // File was changed
 
2540
        GtkWidget *msgbox = NULL;
 
2541
        gint response;
 
2542
 
 
2543
        msg = g_strdup_printf(_("The file '%s' was changed by an external program.\nDo you want to continue?"),basename_cur_utf8);
 
2544
        msgbox = msg_box_new(_("Write File..."),
 
2545
                             GTK_WINDOW(MainWindow),
 
2546
                             NULL,
 
2547
                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2548
                             msg,
 
2549
                             GTK_STOCK_DIALOG_WARNING,
 
2550
                             GTK_STOCK_NO,  GTK_RESPONSE_NO,
 
2551
                                                         GTK_STOCK_YES, GTK_RESPONSE_YES,
 
2552
                             NULL);
 
2553
        g_free(msg);
 
2554
 
 
2555
        response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
2556
        gtk_widget_destroy(msgbox);
 
2557
 
 
2558
        switch (response)
 
2559
        {
 
2560
            case GTK_RESPONSE_YES:
 
2561
                break;
 
2562
            case GTK_RESPONSE_NO:
 
2563
            case GTK_RESPONSE_NONE:
 
2564
                stop_loop = -1;
 
2565
                return stop_loop;
 
2566
                break;
 
2567
        }
 
2568
    }*/
 
2569
 
 
2570
 
 
2571
    /*
 
2572
     * First part: write tag informations (artist, title,...)
 
2573
     */
 
2574
    // Note : the option 'force_saving_files' is only used to save tags
 
2575
    if ( force_saving_files
 
2576
    || FileTag->saved == FALSE ) // This tag had been already saved ?
 
2577
    {
 
2578
        GtkWidget *msgbox = NULL;
 
2579
        GtkWidget *msgbox_check_button = NULL;
 
2580
        gint response;
 
2581
 
 
2582
        if (CONFIRM_WRITE_TAG && !SF_HideMsgbox_Write_Tag)
 
2583
        {
 
2584
            ET_Display_File_Data_To_UI(ETFile);
 
2585
 
 
2586
            msg = g_strdup_printf(_("Do you want to write the tag of file\n'%s' ?"),basename_cur_utf8);
 
2587
 
 
2588
            if (multiple_files)
 
2589
            {
 
2590
                msgbox = msg_box_new(_("Write Tag..."),
 
2591
                                     GTK_WINDOW(MainWindow),
 
2592
                                     &msgbox_check_button,
 
2593
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2594
                                     msg,
 
2595
                                     GTK_STOCK_DIALOG_QUESTION,
 
2596
                                     GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
 
2597
                                     GTK_STOCK_NO,    GTK_RESPONSE_NO,
 
2598
                                                                         GTK_STOCK_YES,   GTK_RESPONSE_YES,
 
2599
                                     NULL);
 
2600
                GTK_TOGGLE_BUTTON(msgbox_check_button)->active = TRUE; // Checked by default
 
2601
            }else
 
2602
            {
 
2603
                msgbox = msg_box_new(_("Write Tag..."),
 
2604
                                     GTK_WINDOW(MainWindow),
 
2605
                                     NULL,
 
2606
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2607
                                     msg,
 
2608
                                     GTK_STOCK_DIALOG_QUESTION,
 
2609
                                     GTK_STOCK_NO,  GTK_RESPONSE_NO,
 
2610
                                                                         GTK_STOCK_YES, GTK_RESPONSE_YES,
 
2611
                                     NULL);
 
2612
            }
 
2613
            g_free(msg);
 
2614
 
 
2615
            SF_ButtonPressed_Write_Tag = response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
2616
            // When check button in msgbox was activated : do not display the message again
 
2617
            if (msgbox_check_button && GTK_TOGGLE_BUTTON(msgbox_check_button)->active)
 
2618
                SF_HideMsgbox_Write_Tag = GTK_TOGGLE_BUTTON(msgbox_check_button)->active;
 
2619
            gtk_widget_destroy(msgbox);
 
2620
        }else
 
2621
        {
 
2622
            if (SF_HideMsgbox_Write_Tag)
 
2623
                response = SF_ButtonPressed_Write_Tag;
 
2624
            else
 
2625
                response = GTK_RESPONSE_YES;
 
2626
        }
 
2627
 
 
2628
        switch (response)
 
2629
        {
 
2630
            case GTK_RESPONSE_YES:
 
2631
            {
 
2632
                gboolean rc;
 
2633
 
 
2634
                // if 'SF_HideMsgbox_Write_Tag is TRUE', then errors are displayed only in log
 
2635
                rc = Write_File_Tag(ETFile,SF_HideMsgbox_Write_Tag);
 
2636
                // if an error occurs when 'SF_HideMsgbox_Write_Tag is TRUE', we don't stop saving...
 
2637
                if (rc != TRUE && !SF_HideMsgbox_Write_Tag)
 
2638
                {
 
2639
                    stop_loop = -1;
 
2640
                    return stop_loop;
 
2641
                }
 
2642
                break;
 
2643
            }
 
2644
            case GTK_RESPONSE_NO:
 
2645
                break;
 
2646
            case GTK_RESPONSE_CANCEL:
 
2647
            case GTK_RESPONSE_NONE:
 
2648
                stop_loop = -1;
 
2649
                return stop_loop;
 
2650
                break;
 
2651
        }
 
2652
    }
 
2653
 
 
2654
 
 
2655
    /*
 
2656
     * Second part: rename the file
 
2657
     */
 
2658
    // Do only if changed! (don't take force_saving_files into account)
 
2659
    if ( FileNameNew->saved == FALSE ) // This filename had been already saved ?
 
2660
    {
 
2661
        GtkWidget *msgbox = NULL;
 
2662
        GtkWidget *msgbox_check_button = NULL;
 
2663
        gint response;
 
2664
 
 
2665
        if (CONFIRM_RENAME_FILE && !SF_HideMsgbox_Rename_File)
 
2666
        {
 
2667
            ET_Display_File_Data_To_UI(ETFile);
 
2668
 
 
2669
            dirname_cur_utf8 = g_path_get_dirname(filename_cur_utf8);
 
2670
            dirname_new_utf8 = g_path_get_dirname(filename_new_utf8);
 
2671
 
 
2672
            // Directories were renamed? or only filename?
 
2673
            if (g_utf8_collate(dirname_cur_utf8,dirname_new_utf8) != 0)
 
2674
            {
 
2675
                if (g_utf8_collate(basename_cur_utf8,basename_new_utf8) != 0)
 
2676
                {
 
2677
                    // Directories and filename changed
 
2678
                    msg_title = g_strdup(_("Rename File and Directory..."));
 
2679
                    msg = g_strdup_printf(_("Do you want to rename the file and directory \n'%s'\nto \n'%s' ?"),
 
2680
                                          filename_cur_utf8, filename_new_utf8);
 
2681
                }else
 
2682
                {
 
2683
                    // Only directories changed
 
2684
                    msg_title = g_strdup(_("Rename Directory..."));
 
2685
                    msg = g_strdup_printf(_("Do you want to rename the directory \n'%s'\nto \n'%s' ?"),
 
2686
                                          dirname_cur_utf8, dirname_new_utf8);
 
2687
                }
 
2688
            }else
 
2689
            {
 
2690
                // Only filename changed
 
2691
                msg_title = g_strdup(_("Rename File..."));
 
2692
                msg = g_strdup_printf(_("Do you want to rename the file \n'%s'\nto \n'%s' ?"),
 
2693
                                      basename_cur_utf8, basename_new_utf8);
 
2694
            }
 
2695
 
 
2696
            g_free(dirname_cur_utf8);
 
2697
            g_free(dirname_new_utf8);
 
2698
 
 
2699
            if (multiple_files)
 
2700
            {
 
2701
                // Allow to cancel for all other files
 
2702
                msgbox = msg_box_new(msg_title,
 
2703
                                     GTK_WINDOW(MainWindow),
 
2704
                                     &msgbox_check_button,
 
2705
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2706
                                     msg,
 
2707
                                     GTK_STOCK_DIALOG_QUESTION,
 
2708
                                     GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
 
2709
                                     GTK_STOCK_NO,    GTK_RESPONSE_NO,
 
2710
                                                                         GTK_STOCK_YES,   GTK_RESPONSE_YES,
 
2711
                                     NULL);
 
2712
                GTK_TOGGLE_BUTTON(msgbox_check_button)->active = TRUE; // Checked by default
 
2713
            }else
 
2714
            {
 
2715
                msgbox = msg_box_new(msg_title,
 
2716
                                     GTK_WINDOW(MainWindow),
 
2717
                                     NULL,
 
2718
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2719
                                     msg,
 
2720
                                     GTK_STOCK_DIALOG_QUESTION,
 
2721
                                     GTK_STOCK_NO,  GTK_RESPONSE_NO,
 
2722
                                                                         GTK_STOCK_YES, GTK_RESPONSE_YES,
 
2723
                                     NULL);
 
2724
            }
 
2725
            g_free(msg);
 
2726
            g_free(msg_title);
 
2727
            SF_ButtonPressed_Rename_File = response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
2728
            if (msgbox_check_button && GTK_TOGGLE_BUTTON(msgbox_check_button)->active)
 
2729
                SF_HideMsgbox_Rename_File = GTK_TOGGLE_BUTTON(msgbox_check_button)->active;
 
2730
            gtk_widget_destroy(msgbox);
 
2731
        }else
 
2732
        {
 
2733
            if (SF_HideMsgbox_Rename_File)
 
2734
                response = SF_ButtonPressed_Rename_File;
 
2735
            else
 
2736
                response = GTK_RESPONSE_YES;
 
2737
        }
 
2738
 
 
2739
        switch(response)
 
2740
        {
 
2741
            case GTK_RESPONSE_YES:
 
2742
            {
 
2743
                gboolean rc;
 
2744
 
 
2745
                // if 'SF_HideMsgbox_Rename_File is TRUE', then errors are displayed only in log
 
2746
                rc = Rename_File(ETFile,SF_HideMsgbox_Rename_File);
 
2747
                // if an error occurs when 'SF_HideMsgbox_Rename_File is TRUE', we don't stop saving...
 
2748
                if (rc != TRUE && !SF_HideMsgbox_Rename_File)
 
2749
                {
 
2750
                    stop_loop = -1;
 
2751
                    return stop_loop;
 
2752
                }
 
2753
                break;
 
2754
            }
 
2755
            case GTK_RESPONSE_NO:
 
2756
                break;
 
2757
            case GTK_RESPONSE_CANCEL:
 
2758
            case GTK_RESPONSE_NONE:
 
2759
                stop_loop = -1;
 
2760
                return stop_loop;
 
2761
                break;
 
2762
        }
 
2763
    }
 
2764
 
 
2765
    g_free(basename_cur_utf8);
 
2766
    g_free(basename_new_utf8);
 
2767
 
 
2768
    /* Refresh file into browser list */
 
2769
    Browser_List_Refresh_File_In_List(ETFile);
 
2770
 
 
2771
    return 1;
 
2772
}
 
2773
 
 
2774
 
 
2775
/*
 
2776
 * Write tag of the ETFile
 
2777
 * Return TRUE => OK
 
2778
 *        FALSE => error
 
2779
 */
 
2780
gboolean Write_File_Tag (ET_File *ETFile, gboolean hide_msgbox)
 
2781
{
 
2782
    gchar *cur_filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;
 
2783
    gchar *msg;
 
2784
    gchar *msg1;
 
2785
    gchar *basename_utf8;
 
2786
    GtkWidget *msgbox;
 
2787
 
 
2788
    basename_utf8 = g_path_get_basename(cur_filename_utf8);
 
2789
    msg = g_strdup_printf(_("Writing tag of '%s'"),basename_utf8);
 
2790
    Statusbar_Message(msg,TRUE);
 
2791
    g_free(msg);
 
2792
 
 
2793
    if (ET_Save_File_Tag_To_HD(ETFile))
 
2794
    {
 
2795
        Statusbar_Message(_("Tag(s) written"),TRUE);
 
2796
        return TRUE;
 
2797
    }
 
2798
 
 
2799
    switch ( ((ET_File_Description *)ETFile->ETFileDescription)->TagType)
 
2800
    {
 
2801
#ifdef ENABLE_OGG
 
2802
        case OGG_TAG:
 
2803
            // Special for Ogg Vorbis because the error is defined into 'vcedit_error(state)'
 
2804
            msg = g_strdup_printf(_("Can't write tag in file '%s'!\n(%s)"),
 
2805
                                  basename_utf8,ogg_error_msg);
 
2806
            msg1 = g_strdup_printf(_("Can't write tag in file '%s'! (%s)"),
 
2807
                                  basename_utf8,ogg_error_msg);
 
2808
            break;
 
2809
#endif
 
2810
        default:
 
2811
            msg = g_strdup_printf(_("Can't write tag in file '%s'!\n(%s)"),
 
2812
                                  basename_utf8,g_strerror(errno));
 
2813
            msg1 = g_strdup_printf(_("Can't write tag in file '%s'! (%s)"),
 
2814
                                  basename_utf8,g_strerror(errno));
 
2815
    }
 
2816
 
 
2817
    Log_Print(LOG_ERROR,"%s", msg1);
 
2818
    g_free(msg1);
 
2819
 
 
2820
    if (!hide_msgbox)
 
2821
    {
 
2822
        msgbox = msg_box_new(_("Error..."),
 
2823
                             GTK_WINDOW(MainWindow),
 
2824
                             NULL,
 
2825
                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2826
                             msg,
 
2827
                             GTK_STOCK_DIALOG_ERROR,
 
2828
                             GTK_STOCK_OK, GTK_RESPONSE_OK,
 
2829
                             NULL);
 
2830
        gtk_dialog_run(GTK_DIALOG(msgbox));
 
2831
        gtk_widget_destroy(msgbox);
 
2832
    }
 
2833
    g_free(msg);
 
2834
    g_free(basename_utf8);
 
2835
 
 
2836
    return FALSE;
 
2837
}
 
2838
 
 
2839
 
 
2840
/*
 
2841
 * Make dir and all parents with permission mode
 
2842
 */
 
2843
gint Make_Dir (const gchar *dirname_old, const gchar *dirname_new)
 
2844
{
 
2845
    gchar *parent, *temp;
 
2846
    struct stat dirstat;
 
2847
#ifdef WIN32
 
2848
    gboolean first = TRUE;
 
2849
#endif
 
2850
 
 
2851
    // Use same permissions as the old directory
 
2852
    stat(dirname_old,&dirstat);
 
2853
 
 
2854
    temp = parent = g_strdup(dirname_new);
 
2855
    for (temp++;*temp;temp++)
 
2856
    {
 
2857
        if (*temp!=G_DIR_SEPARATOR)
 
2858
            continue;
 
2859
 
 
2860
#ifdef WIN32
 
2861
        if (first)
 
2862
        {
 
2863
            first = FALSE;
 
2864
            continue;
 
2865
        }
 
2866
#endif
 
2867
 
 
2868
        *temp=0; // To truncate temporarly dirname_new
 
2869
 
 
2870
        if (mkdir(parent,dirstat.st_mode)==-1 && errno!=EEXIST)
 
2871
        {
 
2872
            g_free(parent);
 
2873
            return(-1);
 
2874
        }
 
2875
        *temp=G_DIR_SEPARATOR; // To cancel the '*temp=0;'
 
2876
    }
 
2877
    g_free(parent);
 
2878
 
 
2879
    if (mkdir(dirname_new,dirstat.st_mode)==-1 && errno!=EEXIST)
 
2880
        return(-1);
 
2881
 
 
2882
    return(0);
 
2883
}
 
2884
 
 
2885
/*
 
2886
 * Remove old directories after renaming the file
 
2887
 * Badly coded, but works....
 
2888
 */
 
2889
gint Remove_Dir (const gchar *dirname_old, const gchar *dirname_new)
 
2890
{
 
2891
    gchar *temp_old, *temp_new;
 
2892
    gchar *temp_end_old, *temp_end_new;
 
2893
 
 
2894
    temp_old = g_strdup(dirname_old);
 
2895
    temp_new = g_strdup(dirname_new);
 
2896
 
 
2897
    while (temp_old && temp_new && strcmp(temp_old,temp_new)!=0 )
 
2898
    {
 
2899
        if (rmdir(temp_old)==-1)
 
2900
        {
 
2901
            // Patch from vdaghan : ENOTEMPTY & EEXIST are synonymous and used by some systems
 
2902
            if (errno != ENOTEMPTY
 
2903
            &&  errno != EEXIST)
 
2904
            {
 
2905
                g_free(temp_old);
 
2906
                g_free(temp_new);
 
2907
                return(-1);
 
2908
            }else
 
2909
            {
 
2910
                break;
 
2911
            }
 
2912
        }
 
2913
 
 
2914
        temp_end_old = temp_old + strlen(temp_old) - 1;
 
2915
        temp_end_new = temp_new + strlen(temp_new) - 1;
 
2916
 
 
2917
        while (*temp_end_old && *temp_end_old!=G_DIR_SEPARATOR)
 
2918
        {
 
2919
            temp_end_old--;
 
2920
        }
 
2921
        *temp_end_old=0;
 
2922
        while (*temp_end_new && *temp_end_new!=G_DIR_SEPARATOR)
 
2923
        {
 
2924
            temp_end_new--;
 
2925
        }
 
2926
        *temp_end_new=0;
 
2927
    }
 
2928
    g_free(temp_old);
 
2929
    g_free(temp_new);
 
2930
 
 
2931
    return(0);
 
2932
}
 
2933
 
 
2934
 
 
2935
/*
 
2936
 * Rename the file ETFile
 
2937
 * Return TRUE => OK
 
2938
 *        FALSE => error
 
2939
 */
 
2940
gboolean Rename_File (ET_File *ETFile, gboolean hide_msgbox)
 
2941
{
 
2942
    FILE  *file;
 
2943
    gchar *tmp_filename = NULL;
 
2944
    gchar *cur_filename = ((File_Name *)ETFile->FileNameCur->data)->value;
 
2945
    gchar *new_filename = ((File_Name *)ETFile->FileNameNew->data)->value;
 
2946
    gchar *cur_filename_utf8 = ((File_Name *)ETFile->FileNameCur->data)->value_utf8;      // Filename + path
 
2947
    gchar *new_filename_utf8 = ((File_Name *)ETFile->FileNameNew->data)->value_utf8;
 
2948
    gchar *cur_basename_utf8 = g_path_get_basename(cur_filename_utf8); // Only filename
 
2949
    gchar *new_basename_utf8 = g_path_get_basename(new_filename_utf8);
 
2950
    gint   fd_tmp;
 
2951
    gchar *msg, *msg1;
 
2952
    gchar *dirname_cur;
 
2953
    gchar *dirname_new;
 
2954
    gchar *dirname_cur_utf8;
 
2955
    gchar *dirname_new_utf8;
 
2956
 
 
2957
    msg = g_strdup_printf(_("Renaming file '%s'"),cur_filename_utf8);
 
2958
    Statusbar_Message(msg,TRUE);
 
2959
    g_free(msg);
 
2960
 
 
2961
    /* We use two stages to rename file, to avoid problem with some system
 
2962
     * that doesn't allow to rename the file if only the case has changed. */
 
2963
    tmp_filename = g_strdup_printf("%s.XXXXXX",cur_filename);
 
2964
    if ( (fd_tmp = mkstemp(tmp_filename)) >= 0 )
 
2965
    {
 
2966
        close(fd_tmp);
 
2967
        unlink(tmp_filename);
 
2968
    }
 
2969
 
 
2970
    // Rename to the temporary name
 
2971
    if ( rename(cur_filename,tmp_filename)!=0 ) // => rename() fails
 
2972
    {
 
2973
        gchar *msg, *msg1;
 
2974
        GtkWidget *msgbox;
 
2975
 
 
2976
        /* Renaming file to the temporary filename has failed */
 
2977
        msg = g_strdup_printf(_("Can't rename file '%s'\n to \n'%s'!\n(%s)"),
 
2978
                                cur_basename_utf8,new_basename_utf8,g_strerror(errno));
 
2979
        msg1 = g_strdup_printf(_("Can't rename file '%s' to '%s'! (%s)"),
 
2980
                                cur_basename_utf8,new_basename_utf8,g_strerror(errno));
 
2981
        if (!hide_msgbox)
 
2982
        {
 
2983
            msgbox = msg_box_new(_("Error..."),
 
2984
                                 GTK_WINDOW(MainWindow),
 
2985
                                 NULL,
 
2986
                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
2987
                                 msg,
 
2988
                                 GTK_STOCK_DIALOG_ERROR,
 
2989
                                 GTK_STOCK_OK, GTK_RESPONSE_OK,
 
2990
                                 NULL);
 
2991
            gtk_dialog_run(GTK_DIALOG(msgbox));
 
2992
            gtk_widget_destroy(msgbox);
 
2993
        }
 
2994
        g_free(msg);
 
2995
 
 
2996
        Log_Print(LOG_ERROR,"%s", msg1);
 
2997
        g_free(msg1);
 
2998
 
 
2999
        Statusbar_Message(_("File(s) not renamed..."),TRUE);
 
3000
        g_free(tmp_filename);
 
3001
        g_free(cur_basename_utf8);
 
3002
        g_free(new_basename_utf8);
 
3003
        return FALSE;
 
3004
    }
 
3005
 
 
3006
    /* Check if the new file name already exists. Must be done after changing
 
3007
     * filename to the temporary name, else we can't detect the problem under
 
3008
     * Linux when renaming a file 'aa.mp3' to 'AA.mp3' and if the last one
 
3009
     * already exists */
 
3010
    if ( (file=fopen(new_filename,"r"))!=NULL )
 
3011
    {
 
3012
        GtkWidget *msgbox;
 
3013
 
 
3014
        fclose(file);
 
3015
 
 
3016
        // Restore the initial name
 
3017
        if ( rename(tmp_filename,cur_filename)!=0 ) // => rename() fails
 
3018
        {
 
3019
            gchar *msg, *msg1;
 
3020
            GtkWidget *msgbox;
 
3021
 
 
3022
            /* Renaming file from the temporary filename has failed */
 
3023
            msg = g_strdup_printf(_("Can't rename file '%s'\n to \n'%s'!\n(%s)"),
 
3024
                                    new_basename_utf8,cur_basename_utf8,g_strerror(errno));
 
3025
            msg1 = g_strdup_printf(_("Can't rename file '%s' to '%s'! (%s)"),
 
3026
                                    new_basename_utf8,cur_basename_utf8,g_strerror(errno));
 
3027
            if (!hide_msgbox)
 
3028
            {
 
3029
                msgbox = msg_box_new(_("Error..."),
 
3030
                                     GTK_WINDOW(MainWindow),
 
3031
                                     NULL,
 
3032
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3033
                                     msg,
 
3034
                                     GTK_STOCK_DIALOG_ERROR,
 
3035
                                     GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3036
                                     NULL);
 
3037
                gtk_dialog_run(GTK_DIALOG(msgbox));
 
3038
                gtk_widget_destroy(msgbox);
 
3039
            }
 
3040
            g_free(msg);
 
3041
 
 
3042
            Log_Print(LOG_ERROR,"%s", msg1);
 
3043
            g_free(msg1);
 
3044
 
 
3045
            Statusbar_Message(_("File(s) not renamed..."),TRUE);
 
3046
            g_free(tmp_filename);
 
3047
            g_free(cur_basename_utf8);
 
3048
            g_free(new_basename_utf8);
 
3049
            return FALSE;
 
3050
        }
 
3051
 
 
3052
        msg = g_strdup_printf(_("Can't rename file \n'%s'\nbecause the following "
 
3053
                    "file already exists:\n'%s'"),cur_basename_utf8,new_basename_utf8);
 
3054
        msg1 = g_strdup_printf(_("Can't rename file '%s' because the following "
 
3055
                    "file already exists: '%s'"),cur_basename_utf8,new_basename_utf8);
 
3056
        if (!hide_msgbox)
 
3057
        {
 
3058
            msgbox = msg_box_new(_("Error..."),
 
3059
                                 GTK_WINDOW(MainWindow),
 
3060
                                 NULL,
 
3061
                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3062
                                 msg,
 
3063
                                 GTK_STOCK_DIALOG_ERROR,
 
3064
                                 GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3065
                                 NULL);
 
3066
            gtk_dialog_run(GTK_DIALOG(msgbox));
 
3067
            gtk_widget_destroy(msgbox);
 
3068
        }
 
3069
        g_free(msg);
 
3070
 
 
3071
        Log_Print(LOG_ERROR,"%s", msg1);
 
3072
        g_free(msg1);
 
3073
 
 
3074
        Statusbar_Message(_("File(s) not renamed..."),TRUE);
 
3075
 
 
3076
        g_free(new_basename_utf8);
 
3077
        g_free(cur_basename_utf8);
 
3078
        return FALSE;
 
3079
    }
 
3080
 
 
3081
    /* If files are in different directories, we need to create the new
 
3082
     * destination directory */
 
3083
    dirname_cur = g_path_get_dirname(tmp_filename);
 
3084
    dirname_new = g_path_get_dirname(new_filename);
 
3085
 
 
3086
    if (dirname_cur && dirname_new && strcmp(dirname_cur,dirname_new)) /* Need to create target directory? */
 
3087
    {
 
3088
        if (Make_Dir(dirname_cur,dirname_new))
 
3089
        {
 
3090
            gchar *msg, *msg1;
 
3091
            GtkWidget *msgbox;
 
3092
 
 
3093
            /* Renaming file has failed, but we try to set the initial name */
 
3094
            rename(tmp_filename,cur_filename);
 
3095
 
 
3096
            dirname_new_utf8 = filename_to_display(dirname_new);
 
3097
            msg = g_strdup_printf(_("Can't create target directory\n'%s'!\n(%s)"),
 
3098
                                  dirname_new_utf8,g_strerror(errno));
 
3099
            msg1 = g_strdup_printf(_("Can't create target directory '%s'! (%s)"),
 
3100
                                  dirname_new_utf8,g_strerror(errno));
 
3101
            if (!hide_msgbox)
 
3102
            {
 
3103
                msgbox = msg_box_new(_("Error..."),
 
3104
                                     GTK_WINDOW(MainWindow),
 
3105
                                     NULL,
 
3106
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3107
                                     msg,
 
3108
                                     GTK_STOCK_DIALOG_ERROR,
 
3109
                                     GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3110
                                     NULL);
 
3111
                gtk_dialog_run(GTK_DIALOG(msgbox));
 
3112
                gtk_widget_destroy(msgbox);
 
3113
            }
 
3114
            g_free(msg);
 
3115
            g_free(dirname_new_utf8);
 
3116
 
 
3117
            Log_Print(LOG_ERROR,"%s", msg1);
 
3118
            g_free(msg1);
 
3119
 
 
3120
            g_free(tmp_filename);
 
3121
            g_free(cur_basename_utf8);
 
3122
            g_free(new_basename_utf8);
 
3123
            g_free(dirname_cur);
 
3124
            g_free(dirname_new);
 
3125
            return FALSE;
 
3126
        }
 
3127
    }
 
3128
 
 
3129
    /* Now, we rename the file to his final name */
 
3130
    if ( rename(tmp_filename,new_filename)==0 )
 
3131
    {
 
3132
        /* Renaming file has succeeded */
 
3133
        Log_Print(LOG_OK,_("Renamed file '%s' to '%s'"),cur_basename_utf8,new_basename_utf8);
 
3134
 
 
3135
        ETFile->FileNameCur = ETFile->FileNameNew;
 
3136
        /* Now the file was renamed, so mark his state */
 
3137
        ET_Mark_File_Name_As_Saved(ETFile);
 
3138
 
 
3139
        Statusbar_Message(_("File(s) renamed..."),TRUE);
 
3140
 
 
3141
        /* Remove the of directory (check automatically if it is empty) */
 
3142
        if (Remove_Dir(dirname_cur,dirname_new))
 
3143
        {
 
3144
            gchar *msg, *msg1;
 
3145
            GtkWidget *msgbox;
 
3146
 
 
3147
            /* Removing directories failed */
 
3148
            dirname_cur_utf8 = filename_to_display(dirname_cur);
 
3149
            msg = g_strdup_printf(_("Can't remove old directory\n'%s'!\n(%s)"),
 
3150
                                  dirname_cur_utf8,g_strerror(errno));
 
3151
            msg1 = g_strdup_printf(_("Can't remove old directory '%s'! (%s)"),
 
3152
                                  dirname_cur_utf8,g_strerror(errno));
 
3153
            if (!hide_msgbox)
 
3154
            {
 
3155
                msgbox = msg_box_new(_("Error..."),
 
3156
                                     GTK_WINDOW(MainWindow),
 
3157
                                     NULL,
 
3158
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3159
                                     msg,
 
3160
                                     GTK_STOCK_DIALOG_ERROR,
 
3161
                                     GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3162
                                     NULL);
 
3163
                gtk_dialog_run(GTK_DIALOG(msgbox));
 
3164
                gtk_widget_destroy(msgbox);
 
3165
            }
 
3166
            g_free(msg);
 
3167
            g_free(dirname_cur_utf8);
 
3168
 
 
3169
            Log_Print(LOG_ERROR,"%s", msg1);
 
3170
            g_free(msg1);
 
3171
 
 
3172
            g_free(tmp_filename);
 
3173
            g_free(cur_basename_utf8);
 
3174
            g_free(new_basename_utf8);
 
3175
            g_free(dirname_cur);
 
3176
            g_free(dirname_new);
 
3177
            return FALSE;
 
3178
        }
 
3179
    }else if ( errno==EXDEV )
 
3180
    {
 
3181
        /* For the error "Invalid cross-device link" during renaming, when the
 
3182
         * new filename isn't on the same device of the omd filename. In this
 
3183
         * case, we need to move the file, and not only to update the hard disk
 
3184
         * index table. For example : 'renaming' /mnt/D/file.mp3 to /mnt/E/file.mp3
 
3185
         *
 
3186
         * So, we need to copy the old file to the new location, and then to
 
3187
         * deleted the old file */
 
3188
        if ( Copy_File(tmp_filename,new_filename) )
 
3189
        {
 
3190
            /* Delete the old file */
 
3191
            unlink(tmp_filename);
 
3192
 
 
3193
            /* Renaming file has succeeded */
 
3194
            Log_Print(LOG_OK,_("Moved file '%s' to '%s'"),cur_basename_utf8,new_basename_utf8);
 
3195
 
 
3196
            ETFile->FileNameCur = ETFile->FileNameNew;
 
3197
            /* Now the file was renamed, so mark his state */
 
3198
            ET_Mark_File_Name_As_Saved(ETFile);
 
3199
 
 
3200
            Statusbar_Message(_("File(s) moved..."),TRUE);
 
3201
 
 
3202
            /* Remove the of directory (check automatically if it is empty) */
 
3203
            if (Remove_Dir(dirname_cur,dirname_new))
 
3204
            {
 
3205
                gchar *msg, *msg1;
 
3206
                GtkWidget *msgbox;
 
3207
 
 
3208
                /* Removing directories failed */
 
3209
                dirname_cur_utf8 = filename_to_display(dirname_cur);
 
3210
                msg = g_strdup_printf(_("Can't remove old directory\n'%s'!\n(%s)"),
 
3211
                                      dirname_cur_utf8,g_strerror(errno));
 
3212
                msg1 = g_strdup_printf(_("Can't remove old directory '%s'! (%s)"),
 
3213
                                      dirname_cur_utf8,g_strerror(errno));
 
3214
                if (!hide_msgbox)
 
3215
                {
 
3216
                    msgbox = msg_box_new(_("Error..."),
 
3217
                                         GTK_WINDOW(MainWindow),
 
3218
                                         NULL,
 
3219
                                         GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3220
                                         msg,
 
3221
                                         GTK_STOCK_DIALOG_ERROR,
 
3222
                                         GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3223
                                         NULL);
 
3224
                    gtk_dialog_run(GTK_DIALOG(msgbox));
 
3225
                    gtk_widget_destroy(msgbox);
 
3226
                }
 
3227
                g_free(msg);
 
3228
                g_free(dirname_cur_utf8);
 
3229
 
 
3230
                Log_Print(LOG_ERROR,"%s", msg1);
 
3231
                g_free(msg1);
 
3232
 
 
3233
                g_free(tmp_filename);
 
3234
                g_free(cur_basename_utf8);
 
3235
                g_free(new_basename_utf8);
 
3236
                g_free(dirname_cur);
 
3237
                g_free(dirname_new);
 
3238
                return FALSE;
 
3239
            }
 
3240
        }else
 
3241
        {
 
3242
            gchar *msg, *msg1;
 
3243
            GtkWidget *msgbox;
 
3244
 
 
3245
            /* Moving file has failed */
 
3246
            msg = g_strdup_printf(_("Can't move file '%s'\n to \n'%s'!\n(%s)"),
 
3247
                                  cur_basename_utf8,new_basename_utf8,g_strerror(errno));
 
3248
            msg1 = g_strdup_printf(_("Can't move file '%s' to '%s'! (%s)"),
 
3249
                                  cur_basename_utf8,new_basename_utf8,g_strerror(errno));
 
3250
            if (!hide_msgbox)
 
3251
            {
 
3252
                msgbox = msg_box_new(_("Error..."),
 
3253
                                     GTK_WINDOW(MainWindow),
 
3254
                                     NULL,
 
3255
                                     GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3256
                                     msg,
 
3257
                                     GTK_STOCK_DIALOG_ERROR,
 
3258
                                     GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3259
                                     NULL);
 
3260
                gtk_dialog_run(GTK_DIALOG(msgbox));
 
3261
                gtk_widget_destroy(msgbox);
 
3262
            }
 
3263
            g_free(msg);
 
3264
 
 
3265
            Log_Print(LOG_ERROR,"%s", msg1);
 
3266
            g_free(msg1);
 
3267
 
 
3268
            Statusbar_Message(_("File(s) not moved..."),TRUE);
 
3269
 
 
3270
            g_free(tmp_filename);
 
3271
            g_free(cur_basename_utf8);
 
3272
            g_free(new_basename_utf8);
 
3273
            g_free(dirname_cur);
 
3274
            g_free(dirname_new);
 
3275
            return FALSE;
 
3276
        }
 
3277
    }else
 
3278
    {
 
3279
        gchar *msg, *msg1;
 
3280
        GtkWidget *msgbox;
 
3281
 
 
3282
        /* Renaming file has failed, but we try to set the initial name */
 
3283
        rename(tmp_filename,cur_filename);
 
3284
 
 
3285
        msg = g_strdup_printf(_("Can't rename file '%s'\n to \n'%s'!\n(%s)"),
 
3286
                              cur_basename_utf8,new_basename_utf8,g_strerror(errno));
 
3287
        msg1 = g_strdup_printf(_("Can't rename file '%s' to '%s'! (%s)"),
 
3288
                              cur_basename_utf8,new_basename_utf8,g_strerror(errno));
 
3289
        if (!hide_msgbox)
 
3290
        {
 
3291
            msgbox = msg_box_new(_("Error..."),
 
3292
                                 GTK_WINDOW(MainWindow),
 
3293
                                 NULL,
 
3294
                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3295
                                 msg,
 
3296
                                 GTK_STOCK_DIALOG_ERROR,
 
3297
                                 GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3298
                                 NULL);
 
3299
            gtk_dialog_run(GTK_DIALOG(msgbox));
 
3300
            gtk_widget_destroy(msgbox);
 
3301
        }
 
3302
        g_free(msg);
 
3303
 
 
3304
        Log_Print(LOG_ERROR,"%s", msg1);
 
3305
        g_free(msg1);
 
3306
 
 
3307
        Statusbar_Message(_("File(s) not renamed..."),TRUE);
 
3308
 
 
3309
        g_free(tmp_filename);
 
3310
        g_free(cur_basename_utf8);
 
3311
        g_free(new_basename_utf8);
 
3312
        g_free(dirname_cur);
 
3313
        g_free(dirname_new);
 
3314
        return FALSE;
 
3315
    }
 
3316
 
 
3317
    return TRUE;
 
3318
}
 
3319
 
 
3320
/*
 
3321
 * Delete the file ETFile
 
3322
 */
 
3323
gint Delete_File (ET_File *ETFile, gboolean multiple_files)
 
3324
{
 
3325
    GtkWidget *msgbox = NULL;
 
3326
    GtkWidget *msgbox_check_button = NULL;
 
3327
    gchar *cur_filename;
 
3328
    gchar *cur_filename_utf8;
 
3329
    gchar *basename_utf8;
 
3330
    gchar *msg;
 
3331
    gint response;
 
3332
    gint stop_loop;
 
3333
 
 
3334
    if (!ETFile) return FALSE;
 
3335
 
 
3336
    // Filename of the file to delete
 
3337
    cur_filename      = ((File_Name *)(ETFile->FileNameCur)->data)->value;
 
3338
    cur_filename_utf8 = ((File_Name *)(ETFile->FileNameCur)->data)->value_utf8;
 
3339
    basename_utf8 = g_path_get_basename(cur_filename);
 
3340
 
 
3341
    /*
 
3342
     * Remove the file
 
3343
     */
 
3344
    if (CONFIRM_DELETE_FILE && !SF_HideMsgbox_Delete_File)
 
3345
    {
 
3346
        msg = g_strdup_printf(_("Do you really want to delete definitively the file\n'%s' ?"),basename_utf8);
 
3347
        if (multiple_files)
 
3348
        {
 
3349
            msgbox = msg_box_new(_("Delete File..."),
 
3350
                                 GTK_WINDOW(MainWindow),
 
3351
                                 &msgbox_check_button,
 
3352
                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3353
                                 msg,
 
3354
                                 GTK_STOCK_DIALOG_QUESTION,
 
3355
                                 GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
 
3356
                                 GTK_STOCK_NO,    GTK_RESPONSE_NO,
 
3357
                                                                 GTK_STOCK_YES,   GTK_RESPONSE_YES,
 
3358
                                 NULL);
 
3359
            //GTK_TOGGLE_BUTTON(msgbox_check_button)->active = TRUE; // Checked by default
 
3360
        }else
 
3361
        {
 
3362
            msgbox = msg_box_new(_("Delete File..."),
 
3363
                                 GTK_WINDOW(MainWindow),
 
3364
                                 NULL,
 
3365
                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3366
                                 msg,
 
3367
                                 GTK_STOCK_DIALOG_QUESTION,
 
3368
                                 GTK_STOCK_NO,    GTK_RESPONSE_NO,
 
3369
                                                                 GTK_STOCK_YES,   GTK_RESPONSE_YES,
 
3370
                                 NULL);
 
3371
        }
 
3372
        g_free(msg);
 
3373
        SF_ButtonPressed_Delete_File = response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
3374
        if (msgbox_check_button && GTK_TOGGLE_BUTTON(msgbox_check_button)->active)
 
3375
            SF_HideMsgbox_Delete_File = GTK_TOGGLE_BUTTON(msgbox_check_button)->active;
 
3376
        gtk_widget_destroy(msgbox);
 
3377
    }else
 
3378
    {
 
3379
        if (SF_HideMsgbox_Delete_File)
 
3380
            response = SF_ButtonPressed_Delete_File;
 
3381
        else
 
3382
            response = GTK_RESPONSE_YES;
 
3383
    }
 
3384
 
 
3385
    switch (response)
 
3386
    {
 
3387
        case GTK_RESPONSE_YES:
 
3388
            if (remove(cur_filename)==0)
 
3389
            {
 
3390
                msg = g_strdup_printf(_("File '%s' deleted"), basename_utf8);
 
3391
                Statusbar_Message(msg,FALSE);
 
3392
                g_free(msg);
 
3393
                g_free(basename_utf8);
 
3394
                return 1;
 
3395
            }
 
3396
            break;
 
3397
        case GTK_RESPONSE_NO:
 
3398
            break;
 
3399
        case GTK_RESPONSE_CANCEL:
 
3400
        case GTK_RESPONSE_NONE:
 
3401
            stop_loop = -1;
 
3402
            g_free(basename_utf8);
 
3403
            return stop_loop;
 
3404
            break;
 
3405
    }
 
3406
 
 
3407
    g_free(basename_utf8);
 
3408
    return 0;
 
3409
}
 
3410
 
 
3411
/*
 
3412
 * Copy a file to a new location
 
3413
 */
 
3414
gint Copy_File (gchar const *fileold, gchar const *filenew)
 
3415
{
 
3416
    FILE* fOld;
 
3417
    FILE* fNew;
 
3418
    gchar buffer[512];
 
3419
    gint NbRead;
 
3420
    struct stat    statbuf;
 
3421
    struct utimbuf utimbufbuf;
 
3422
 
 
3423
    if ( (fOld=fopen(fileold, "rb")) == NULL )
 
3424
    {
 
3425
        return FALSE;
 
3426
    }
 
3427
 
 
3428
    if ( (fNew=fopen(filenew, "wb")) == NULL )
 
3429
    {
 
3430
        fclose(fOld);
 
3431
        return FALSE;
 
3432
    }
 
3433
 
 
3434
    while ( (NbRead=fread(buffer, 1, 512, fOld)) != 0 )
 
3435
    {
 
3436
        fwrite(buffer, 1, NbRead, fNew);
 
3437
    }
 
3438
 
 
3439
    fclose(fNew);
 
3440
    fclose(fOld);
 
3441
 
 
3442
    // Copy properties of the old file to the new one.
 
3443
    stat(fileold,&statbuf);
 
3444
    chmod(filenew,statbuf.st_mode & (S_IRWXU|S_IRWXG|S_IRWXO));
 
3445
    chown(filenew,statbuf.st_uid,statbuf.st_gid);
 
3446
    utimbufbuf.actime  = statbuf.st_atime; // Last access time
 
3447
    utimbufbuf.modtime = statbuf.st_mtime; // Last modification time
 
3448
    utime(filenew,&utimbufbuf);
 
3449
 
 
3450
    return TRUE;
 
3451
}
 
3452
 
 
3453
void Action_Select_Browser_Style (void)
 
3454
{
 
3455
    if (!ETCore->ETFileDisplayedList) return;
 
3456
 
 
3457
    /* Save the current displayed data */
 
3458
    ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed);
 
3459
 
 
3460
    Browser_Display_Tree_Or_Artist_Album_List();
 
3461
 
 
3462
    Update_Command_Buttons_Sensivity();
 
3463
}
 
3464
 
 
3465
 
 
3466
 
 
3467
 
 
3468
 
 
3469
/*
 
3470
 * Scans the specified directory: and load files into a list.
 
3471
 * If the path doesn't exist, we free the previous loaded list of files.
 
3472
 */
 
3473
#include <sys/types.h>
 
3474
#include <dirent.h>
 
3475
#include <sys/stat.h>
 
3476
#include <unistd.h>
 
3477
#include <string.h>
 
3478
gboolean Read_Directory (gchar *path_real)
 
3479
{
 
3480
    DIR   *dir;
 
3481
    gchar *msg;
 
3482
    gchar *tmp;
 
3483
    gchar  progress_bar_text[30];
 
3484
    guint  nbrfile = 0;
 
3485
    double fraction;
 
3486
    GList *FileList = NULL;
 
3487
    gint   progress_bar_index = 0;
 
3488
    GtkAction *uiaction;
 
3489
    GtkWidget *TBViewMode;
 
3490
 
 
3491
    if (!path_real)
 
3492
        return FALSE;
 
3493
 
 
3494
    ReadingDirectory = TRUE;    /* A flag to avoid to start an other reading */
 
3495
 
 
3496
    /* Initialize file list */
 
3497
    ET_Core_Free();
 
3498
    ET_Core_Initialize();
 
3499
    Update_Command_Buttons_Sensivity();
 
3500
 
 
3501
    /* Initialize browser list */
 
3502
    Browser_List_Clear();
 
3503
 
 
3504
    /* Clear entry boxes  */
 
3505
    Clear_File_Entry_Field();
 
3506
    Clear_Header_Fields();
 
3507
    Clear_Tag_Entry_Fields();
 
3508
    gtk_label_set_text(GTK_LABEL(FileIndex),"0/0:");
 
3509
 
 
3510
    TBViewMode = gtk_ui_manager_get_widget(UIManager, "/ToolBar/ViewModeToggle");
 
3511
    gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(TBViewMode),FALSE);
 
3512
    //Browser_Display_Tree_Or_Artist_Album_List(); // To show the corresponding lists...
 
3513
 
 
3514
    // Set to unsensitive the Browser Area, to avoid to select an other file while loading the first one
 
3515
    Browser_Area_Set_Sensitive(FALSE);
 
3516
 
 
3517
    /* Placed only here, to empty the previous list of files */
 
3518
    if ((dir=opendir(path_real)) == NULL)
 
3519
    {
 
3520
        // Message if the directory doesn't exist...
 
3521
        GtkWidget *msgbox;
 
3522
        gchar *path_utf8 = filename_to_display(path_real);
 
3523
        gchar *msg;
 
3524
 
 
3525
        msg = g_strdup_printf(_("Can't read directory :\n'%s'\n(%s)"),path_utf8,g_strerror(errno));
 
3526
        msgbox = msg_box_new(_("Error..."),
 
3527
                             GTK_WINDOW(MainWindow),
 
3528
                             NULL,
 
3529
                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
3530
                             msg,
 
3531
                             GTK_STOCK_DIALOG_ERROR,
 
3532
                             GTK_STOCK_OK, GTK_RESPONSE_OK,
 
3533
                             NULL);
 
3534
        gtk_dialog_run(GTK_DIALOG(msgbox));
 
3535
        gtk_widget_destroy(msgbox);
 
3536
        g_free(msg);
 
3537
        g_free(path_utf8);
 
3538
 
 
3539
        ReadingDirectory = FALSE; //Allow a new reading
 
3540
        Browser_Area_Set_Sensitive(TRUE);
 
3541
        return FALSE;
 
3542
    }
 
3543
    closedir(dir);
 
3544
 
 
3545
    /* Open the window to quit recursion (since 27/04/2007 : not only into recursion mode) */
 
3546
    Set_Busy_Cursor();
 
3547
    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
 
3548
    g_object_set(uiaction, "sensitive", BROWSE_SUBDIR, NULL);
 
3549
    //if (BROWSE_SUBDIR)
 
3550
        Open_Quit_Recursion_Function_Window();
 
3551
 
 
3552
    /* Read the directory recursively */
 
3553
    msg = g_strdup_printf(_("Search in progress..."));
 
3554
    Statusbar_Message(msg,FALSE);
 
3555
    g_free(msg);
 
3556
    // Search the supported files
 
3557
    FileList = Read_Directory_Recursively(FileList,path_real,BROWSE_SUBDIR);
 
3558
    nbrfile = g_list_length(FileList);
 
3559
 
 
3560
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0.0);
 
3561
    g_snprintf(progress_bar_text, 30, "%d/%d", 0, nbrfile);
 
3562
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
3563
 
 
3564
    // Load the supported files (Extension recognized)
 
3565
    while (FileList)
 
3566
    {
 
3567
        gchar *filename_real = FileList->data; // Contains real filenames
 
3568
        gchar *filename_utf8 = filename_to_display(filename_real);
 
3569
 
 
3570
        msg = g_strdup_printf(_("File: '%s'"),filename_utf8);
 
3571
        Statusbar_Message(msg,FALSE);
 
3572
        g_free(msg);
 
3573
        g_free(filename_utf8);
 
3574
 
 
3575
        // Warning: Do not free filename_real because ET_Add_File.. uses it for internal structures
 
3576
        ET_Add_File_To_File_List(filename_real);
 
3577
 
 
3578
        // Update the progress bar
 
3579
        fraction = (++progress_bar_index) / (double) nbrfile;
 
3580
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), fraction);
 
3581
        g_snprintf(progress_bar_text, 30, "%d/%d", progress_bar_index, nbrfile);
 
3582
        gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), progress_bar_text);
 
3583
        while (gtk_events_pending())
 
3584
            gtk_main_iteration();
 
3585
 
 
3586
        if ( !FileList->next || (Main_Stop_Button_Pressed==1) ) break;
 
3587
        FileList = FileList->next;
 
3588
    }
 
3589
    if (FileList) g_list_free(FileList);
 
3590
    gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ProgressBar), "");
 
3591
 
 
3592
    /* Close window to quit recursion */
 
3593
    Destroy_Quit_Recursion_Function_Window();
 
3594
    Main_Stop_Button_Pressed = 0;
 
3595
    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
 
3596
    g_object_set(uiaction, "sensitive", FALSE, NULL);
 
3597
 
 
3598
    //ET_Debug_Print_File_List(ETCore->ETFileList,__FILE__,__LINE__,__FUNCTION__);
 
3599
 
 
3600
    if (ETCore->ETFileList)
 
3601
    {
 
3602
        //GList *etfilelist;
 
3603
        /* Load the list of file into the browser list widget */
 
3604
        Browser_Display_Tree_Or_Artist_Album_List();
 
3605
 
 
3606
        /* Load the list attached to the TrackEntry */
 
3607
        Load_Track_List_To_UI();
 
3608
 
 
3609
        /* Display the first file */
 
3610
        //No need to select first item, because Browser_Display_Tree_Or_Artist_Album_List() does this
 
3611
        //etfilelist = ET_Displayed_File_List_First();
 
3612
        //if (etfilelist)
 
3613
        //{
 
3614
        //    ET_Display_File_Data_To_UI((ET_File *)etfilelist->data);
 
3615
        //    Browser_List_Select_File_By_Etfile((ET_File *)etfilelist->data,FALSE);
 
3616
        //}
 
3617
 
 
3618
        /* Prepare message for the status bar */
 
3619
        if (BROWSE_SUBDIR)
 
3620
            msg = g_strdup_printf(_("Found %d file(s) in this directory and subdirectories."),ETCore->ETFileDisplayedList_Length);
 
3621
        else
 
3622
            msg = g_strdup_printf(_("Found %d file(s) in this directory."),ETCore->ETFileDisplayedList_Length);
 
3623
 
 
3624
    }else
 
3625
    {
 
3626
        /* Clear entry boxes */
 
3627
        Clear_File_Entry_Field();
 
3628
        Clear_Header_Fields();
 
3629
        Clear_Tag_Entry_Fields();
 
3630
 
 
3631
        if (FileIndex)
 
3632
            gtk_label_set_text(GTK_LABEL(FileIndex),"0/0:");
 
3633
 
 
3634
 
 
3635
        tmp = g_strdup_printf(_("%u file(s)"),0); // See in ET_Display_Filename_To_UI
 
3636
        Browser_Label_Set_Text(tmp);
 
3637
        g_free(tmp);
 
3638
 
 
3639
        /* Prepare message for the status bar */
 
3640
        if (BROWSE_SUBDIR)
 
3641
            msg = g_strdup(_("No file found in this directory and subdirectories!"));
 
3642
        else
 
3643
            msg = g_strdup(_("No file found in this directory!"));
 
3644
    }
 
3645
 
 
3646
    /* Update sensitivity of buttons and menus */
 
3647
    Update_Command_Buttons_Sensivity();
 
3648
 
 
3649
    Browser_Area_Set_Sensitive(TRUE);
 
3650
 
 
3651
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ProgressBar), 0.0);
 
3652
    Statusbar_Message(msg,FALSE);
 
3653
    g_free(msg);
 
3654
    Set_Unbusy_Cursor();
 
3655
    ReadingDirectory = FALSE;
 
3656
 
 
3657
    return TRUE;
 
3658
}
 
3659
 
 
3660
 
 
3661
 
 
3662
/*
 
3663
 * Recurse the path to create a list of files. Return a GList of the files found.
 
3664
 */
 
3665
GList *Read_Directory_Recursively (GList *file_list, gchar *path_real, gint recurse)
 
3666
{
 
3667
    DIR *dir;
 
3668
    struct dirent *dirent;
 
3669
    struct stat statbuf;
 
3670
    gchar *filename;
 
3671
 
 
3672
    if ((dir = opendir(path_real)) == NULL)
 
3673
        return file_list;
 
3674
 
 
3675
    while ((dirent = readdir(dir)) != NULL)
 
3676
    {
 
3677
        if (Main_Stop_Button_Pressed == 1)
 
3678
        {
 
3679
            closedir(dir);
 
3680
            return file_list;
 
3681
        }
 
3682
 
 
3683
        // We don't read the directories '.' and '..', but may read hidden directories like '.mydir'
 
3684
        if ( (g_ascii_strcasecmp (dirent->d_name,"..")   != 0)
 
3685
        &&  ((g_ascii_strncasecmp(dirent->d_name,".", 1) != 0) || (BROWSE_HIDDEN_DIR && strlen(dirent->d_name) > 1)) )
 
3686
        {
 
3687
            if (path_real[strlen(path_real)-1]!=G_DIR_SEPARATOR)
 
3688
                filename = g_strconcat(path_real,G_DIR_SEPARATOR_S,dirent->d_name,NULL);
 
3689
            else
 
3690
                filename = g_strconcat(path_real,dirent->d_name,NULL);
 
3691
 
 
3692
            if (stat(filename, &statbuf) == -1)
 
3693
            {
 
3694
                g_free(filename);
 
3695
                continue;
 
3696
            }
 
3697
 
 
3698
            if (S_ISDIR(statbuf.st_mode))
 
3699
            {
 
3700
                if (recurse)
 
3701
                    file_list = Read_Directory_Recursively(file_list,filename,recurse);
 
3702
            //}else if ( (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode)) && ET_File_Is_Supported(filename))
 
3703
            }else if ( S_ISREG(statbuf.st_mode) && ET_File_Is_Supported(filename))
 
3704
            {
 
3705
                file_list = g_list_append(file_list,g_strdup(filename));
 
3706
            }
 
3707
            g_free(filename);
 
3708
 
 
3709
            // Just to not block X events
 
3710
            while (gtk_events_pending())
 
3711
                gtk_main_iteration();
 
3712
        }
 
3713
    }
 
3714
 
 
3715
    closedir(dir);
 
3716
    return file_list;
 
3717
}
 
3718
 
 
3719
 
 
3720
/*
 
3721
 * Window with the 'STOP' button to stop recursion when reading directories
 
3722
 */
 
3723
void Open_Quit_Recursion_Function_Window (void)
 
3724
{
 
3725
    GtkWidget *button;
 
3726
    GtkWidget *frame;
 
3727
 
 
3728
    if (QuitRecursionWindow != NULL)
 
3729
        return;
 
3730
    QuitRecursionWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
3731
    gtk_window_set_title(GTK_WINDOW(QuitRecursionWindow),_("Searching..."));
 
3732
    gtk_window_set_transient_for(GTK_WINDOW(QuitRecursionWindow),GTK_WINDOW(MainWindow));
 
3733
    //gtk_window_set_policy(GTK_WINDOW(QuitRecursionWindow),FALSE,FALSE,TRUE);
 
3734
 
 
3735
    // Just center on mainwindow
 
3736
    gtk_window_set_position(GTK_WINDOW(QuitRecursionWindow), GTK_WIN_POS_CENTER_ON_PARENT);
 
3737
 
 
3738
    g_signal_connect(G_OBJECT(QuitRecursionWindow),"destroy",
 
3739
                     G_CALLBACK(Quit_Recursion_Function_Button_Pressed),NULL);
 
3740
    g_signal_connect(G_OBJECT(QuitRecursionWindow),"delete_event",
 
3741
                     G_CALLBACK(Quit_Recursion_Function_Button_Pressed),NULL);
 
3742
    g_signal_connect(G_OBJECT(QuitRecursionWindow),"key_press_event",
 
3743
                     G_CALLBACK(Quit_Recursion_Window_Key_Press),NULL);
 
3744
 
 
3745
    frame = gtk_frame_new(NULL);
 
3746
    gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_IN);
 
3747
    gtk_container_add(GTK_CONTAINER(QuitRecursionWindow),frame);
 
3748
    gtk_container_set_border_width(GTK_CONTAINER(frame),2);
 
3749
 
 
3750
    // Button to stop...
 
3751
    button = Create_Button_With_Icon_And_Label(GTK_STOCK_STOP,_("  STOP the search...  "));
 
3752
    gtk_container_set_border_width(GTK_CONTAINER(button),8);
 
3753
    gtk_container_add(GTK_CONTAINER(frame),button);
 
3754
    g_signal_connect(G_OBJECT(button),"clicked",G_CALLBACK(Quit_Recursion_Function_Button_Pressed),NULL);
 
3755
 
 
3756
    gtk_widget_show_all(QuitRecursionWindow);
 
3757
}
 
3758
void Destroy_Quit_Recursion_Function_Window (void)
 
3759
{
 
3760
    if (QuitRecursionWindow)
 
3761
    {
 
3762
        gtk_widget_destroy(QuitRecursionWindow);
 
3763
        QuitRecursionWindow = (GtkWidget *)NULL;
 
3764
        /*Statusbar_Message(_("Recursive file search interrupted."),FALSE);*/
 
3765
    }
 
3766
}
 
3767
void Quit_Recursion_Function_Button_Pressed (void)
 
3768
{
 
3769
    Action_Main_Stop_Button_Pressed();
 
3770
    Destroy_Quit_Recursion_Function_Window();
 
3771
}
 
3772
void Quit_Recursion_Window_Key_Press (GtkWidget *window, GdkEvent *event)
 
3773
{
 
3774
    GdkEventKey *kevent;
 
3775
 
 
3776
    if (event && event->type == GDK_KEY_PRESS)
 
3777
    {
 
3778
        kevent = (GdkEventKey *)event;
 
3779
        switch(kevent->keyval)
 
3780
        {
 
3781
            case GDK_Escape:
 
3782
                Destroy_Quit_Recursion_Function_Window();
 
3783
                break;
 
3784
        }
 
3785
    }
 
3786
}
 
3787
 
 
3788
 
 
3789
/*
 
3790
 * To stop the recursive search within directories or saving files
 
3791
 */
 
3792
void Action_Main_Stop_Button_Pressed (void)
 
3793
{
 
3794
    GtkAction *uiaction;
 
3795
    Main_Stop_Button_Pressed = 1;
 
3796
    uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
 
3797
    g_object_set(uiaction, "sensitive", FALSE, NULL);
 
3798
}
 
3799
 
 
3800
void ui_widget_set_sensitive (const gchar *menu, const gchar *action, gboolean sensitive)
 
3801
{
 
3802
    GtkAction *uiaction;
 
3803
    gchar *path;
 
3804
 
 
3805
    path = g_strconcat("/MenuBar/", menu,"/", action, NULL);
 
3806
 
 
3807
    uiaction = gtk_ui_manager_get_action(UIManager, path);
 
3808
    if (uiaction)
 
3809
        g_object_set(uiaction, "sensitive", sensitive, NULL);
 
3810
    g_free(path);
 
3811
}
 
3812
 
 
3813
/*
 
3814
 * Update_Command_Buttons_Sensivity: Set to sensitive/unsensitive the state of each button into
 
3815
 * the commands area and menu items in function of state of the "main list".
 
3816
 */
 
3817
void Update_Command_Buttons_Sensivity (void)
 
3818
{
 
3819
    GtkAction *uiaction;
 
3820
 
 
3821
    if (!ETCore->ETFileDisplayedList)
 
3822
    {
 
3823
        /* No file found */
 
3824
 
 
3825
        /* File and Tag frames */
 
3826
        File_Area_Set_Sensitive(FALSE);
 
3827
        Tag_Area_Set_Sensitive(FALSE);
 
3828
 
 
3829
        /* Tool bar buttons (the others are covered by the menu) */
 
3830
        uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
 
3831
        g_object_set(uiaction, "sensitive", FALSE, NULL);
 
3832
 
 
3833
        /* Scanner Window */
 
3834
        if (SWScanButton)
 
3835
            gtk_widget_set_sensitive(GTK_WIDGET(SWScanButton),FALSE);
 
3836
 
 
3837
        /* Menu commands */
 
3838
        ui_widget_set_sensitive(MENU_FILE, AM_OPEN_FILE_WITH, FALSE);
 
3839
        ui_widget_set_sensitive(MENU_FILE, AM_SELECT_ALL_FILES, FALSE);
 
3840
        ui_widget_set_sensitive(MENU_FILE, AM_UNSELECT_ALL_FILES, FALSE);
 
3841
        ui_widget_set_sensitive(MENU_FILE, AM_INVERT_SELECTION, FALSE);
 
3842
        ui_widget_set_sensitive(MENU_FILE, AM_DELETE_FILE, FALSE);
 
3843
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_FILENAME, FALSE);
 
3844
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_FILENAME,FALSE);
 
3845
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_CREATION_DATE,FALSE);
 
3846
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_CREATION_DATE,FALSE);
 
3847
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_TRACK_NUMBER,FALSE);
 
3848
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_TRACK_NUMBER,FALSE);
 
3849
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_TITLE,FALSE);
 
3850
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_TITLE,FALSE);
 
3851
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_ARTIST,FALSE);
 
3852
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_ARTIST,FALSE);
 
3853
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_ALBUM,FALSE);
 
3854
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_ALBUM,FALSE);
 
3855
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_YEAR,FALSE);
 
3856
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_YEAR,FALSE);
 
3857
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_GENRE,FALSE);
 
3858
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_GENRE,FALSE);
 
3859
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_ASCENDING_COMMENT,FALSE);
 
3860
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH, AM_SORT_DESCENDING_COMMENT,FALSE);
 
3861
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_FILE_TYPE,FALSE);
 
3862
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_FILE_TYPE,FALSE);
 
3863
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_FILE_SIZE,FALSE);
 
3864
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_FILE_SIZE,FALSE);
 
3865
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_FILE_DURATION,FALSE);
 
3866
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_FILE_DURATION,FALSE);
 
3867
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_FILE_BITRATE,FALSE);
 
3868
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_FILE_BITRATE,FALSE);
 
3869
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_ASCENDING_FILE_SAMPLERATE,FALSE);
 
3870
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH, AM_SORT_DESCENDING_FILE_SAMPLERATE,FALSE);
 
3871
        ui_widget_set_sensitive(MENU_FILE, AM_PREV, FALSE);
 
3872
        ui_widget_set_sensitive(MENU_FILE, AM_NEXT, FALSE);
 
3873
        ui_widget_set_sensitive(MENU_FILE, AM_FIRST, FALSE);
 
3874
        ui_widget_set_sensitive(MENU_FILE, AM_LAST, FALSE);
 
3875
        ui_widget_set_sensitive(MENU_FILE, AM_SCAN, FALSE);
 
3876
        ui_widget_set_sensitive(MENU_FILE, AM_REMOVE, FALSE);
 
3877
        ui_widget_set_sensitive(MENU_FILE, AM_UNDO, FALSE);
 
3878
        ui_widget_set_sensitive(MENU_FILE, AM_REDO, FALSE);
 
3879
        ui_widget_set_sensitive(MENU_FILE, AM_SAVE, FALSE);
 
3880
        ui_widget_set_sensitive(MENU_FILE, AM_SAVE_FORCED, FALSE);
 
3881
        ui_widget_set_sensitive(MENU_FILE, AM_UNDO_HISTORY, FALSE);
 
3882
        ui_widget_set_sensitive(MENU_FILE, AM_REDO_HISTORY, FALSE);
 
3883
        ui_widget_set_sensitive(MENU_MISC, AM_SEARCH_FILE, FALSE);
 
3884
        ui_widget_set_sensitive(MENU_MISC, AM_FILENAME_FROM_TXT, FALSE);
 
3885
        ui_widget_set_sensitive(MENU_MISC, AM_WRITE_PLAYLIST, FALSE);
 
3886
        ui_widget_set_sensitive(MENU_MISC, AM_RUN_AUDIO_PLAYER, FALSE);
 
3887
        ui_widget_set_sensitive(MENU_SCANNER, AM_SCANNER_FILL_TAG, FALSE);
 
3888
        ui_widget_set_sensitive(MENU_SCANNER, AM_SCANNER_RENAME_FILE, FALSE);
 
3889
        ui_widget_set_sensitive(MENU_SCANNER, AM_SCANNER_PROCESS_FIELDS, FALSE);
 
3890
 
 
3891
        return;
 
3892
    }else
 
3893
    {
 
3894
        GList *selfilelist = NULL;
 
3895
        ET_File *etfile;
 
3896
        gboolean has_undo = FALSE;
 
3897
        gboolean has_redo = FALSE;
 
3898
        //gboolean has_to_save = FALSE;
 
3899
        GtkTreeSelection *selection;
 
3900
 
 
3901
        /* File and Tag frames */
 
3902
        File_Area_Set_Sensitive(TRUE);
 
3903
        Tag_Area_Set_Sensitive(TRUE);
 
3904
 
 
3905
        /* Tool bar buttons */
 
3906
        uiaction = gtk_ui_manager_get_action(UIManager, "/ToolBar/Stop");
 
3907
        g_object_set(uiaction, "sensitive", FALSE, NULL);
 
3908
 
 
3909
        /* Scanner Window */
 
3910
        if (SWScanButton)    gtk_widget_set_sensitive(GTK_WIDGET(SWScanButton),TRUE);
 
3911
 
 
3912
        /* Commands into menu */
 
3913
        ui_widget_set_sensitive(MENU_FILE, AM_OPEN_FILE_WITH,TRUE);
 
3914
        ui_widget_set_sensitive(MENU_FILE, AM_SELECT_ALL_FILES,TRUE);
 
3915
        ui_widget_set_sensitive(MENU_FILE, AM_UNSELECT_ALL_FILES,TRUE);
 
3916
        ui_widget_set_sensitive(MENU_FILE, AM_INVERT_SELECTION,TRUE);
 
3917
        ui_widget_set_sensitive(MENU_FILE, AM_DELETE_FILE,TRUE);
 
3918
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_FILENAME,TRUE);
 
3919
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_FILENAME,TRUE);
 
3920
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_CREATION_DATE,TRUE);
 
3921
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_CREATION_DATE,TRUE);
 
3922
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_TRACK_NUMBER,TRUE);
 
3923
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_TRACK_NUMBER,TRUE);
 
3924
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_TITLE,TRUE);
 
3925
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_TITLE,TRUE);
 
3926
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_ARTIST,TRUE);
 
3927
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_ARTIST,TRUE);
 
3928
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_ALBUM,TRUE);
 
3929
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_ALBUM,TRUE);
 
3930
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_YEAR,TRUE);
 
3931
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_YEAR,TRUE);
 
3932
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_GENRE,TRUE);
 
3933
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_GENRE,TRUE);
 
3934
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_ASCENDING_COMMENT,TRUE);
 
3935
        ui_widget_set_sensitive(MENU_SORT_TAG_PATH,AM_SORT_DESCENDING_COMMENT,TRUE);
 
3936
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_FILE_TYPE,TRUE);
 
3937
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_FILE_TYPE,TRUE);
 
3938
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_FILE_SIZE,TRUE);
 
3939
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_FILE_SIZE,TRUE);
 
3940
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_FILE_DURATION,TRUE);
 
3941
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_FILE_DURATION,TRUE);
 
3942
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_FILE_BITRATE,TRUE);
 
3943
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_FILE_BITRATE,TRUE);
 
3944
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_ASCENDING_FILE_SAMPLERATE,TRUE);
 
3945
        ui_widget_set_sensitive(MENU_SORT_PROP_PATH,AM_SORT_DESCENDING_FILE_SAMPLERATE,TRUE);
 
3946
        ui_widget_set_sensitive(MENU_FILE,AM_SCAN,TRUE);
 
3947
        ui_widget_set_sensitive(MENU_FILE,AM_REMOVE,TRUE);
 
3948
        ui_widget_set_sensitive(MENU_MISC,AM_SEARCH_FILE,TRUE);
 
3949
        ui_widget_set_sensitive(MENU_MISC,AM_FILENAME_FROM_TXT,TRUE);
 
3950
        ui_widget_set_sensitive(MENU_MISC,AM_WRITE_PLAYLIST,TRUE);
 
3951
        ui_widget_set_sensitive(MENU_MISC,AM_RUN_AUDIO_PLAYER,TRUE);
 
3952
        ui_widget_set_sensitive(MENU_SCANNER,AM_SCANNER_FILL_TAG,TRUE);
 
3953
        ui_widget_set_sensitive(MENU_SCANNER,AM_SCANNER_RENAME_FILE,TRUE);
 
3954
        ui_widget_set_sensitive(MENU_SCANNER,AM_SCANNER_PROCESS_FIELDS,TRUE);
 
3955
 
 
3956
        /* Check if one of the selected files has undo or redo data */
 
3957
        if (BrowserList)
 
3958
        {
 
3959
            selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(BrowserList));
 
3960
            selfilelist = gtk_tree_selection_get_selected_rows(selection, NULL);
 
3961
            while (selfilelist)
 
3962
            {
 
3963
                etfile = Browser_List_Get_ETFile_From_Path(selfilelist->data);
 
3964
                has_undo    |= ET_File_Data_Has_Undo_Data(etfile);
 
3965
                has_redo    |= ET_File_Data_Has_Redo_Data(etfile);
 
3966
                //has_to_save |= ET_Check_If_File_Is_Saved(etfile);
 
3967
                if ((has_undo && has_redo /*&& has_to_save*/) || !selfilelist->next) // Useless to check the other files
 
3968
                    break;
 
3969
                selfilelist = g_list_next(selfilelist);
 
3970
            }
 
3971
            g_list_foreach(selfilelist, (GFunc) gtk_tree_path_free, NULL);
 
3972
            g_list_free(selfilelist);
 
3973
        }
 
3974
 
 
3975
        /* Enable undo commands if there are undo data */
 
3976
        if (has_undo)
 
3977
            ui_widget_set_sensitive(MENU_FILE, AM_UNDO, TRUE);
 
3978
        else
 
3979
            ui_widget_set_sensitive(MENU_FILE, AM_UNDO, FALSE);
 
3980
 
 
3981
        /* Enable redo commands if there are redo data */
 
3982
        if (has_redo)
 
3983
            ui_widget_set_sensitive(MENU_FILE, AM_REDO, TRUE);
 
3984
        else
 
3985
            ui_widget_set_sensitive(MENU_FILE, AM_REDO, FALSE);
 
3986
 
 
3987
        /* Enable save file command if file has been changed */
 
3988
        // Desactivated because problem with only one file in the list, as we can't change the selected file => can't mark file as changed
 
3989
        /*if (has_to_save)
 
3990
            ui_widget_set_sensitive(MENU_FILE, AM_SAVE, FALSE);
 
3991
        else*/
 
3992
            ui_widget_set_sensitive(MENU_FILE, AM_SAVE, TRUE);
 
3993
        
 
3994
        ui_widget_set_sensitive(MENU_FILE, AM_SAVE_FORCED, TRUE);
 
3995
 
 
3996
        /* Enable undo command if there are data into main undo list (history list) */
 
3997
        if (ET_History_File_List_Has_Undo_Data())
 
3998
            ui_widget_set_sensitive(MENU_FILE, AM_UNDO_HISTORY, TRUE);
 
3999
        else
 
4000
            ui_widget_set_sensitive(MENU_FILE, AM_UNDO_HISTORY, FALSE);
 
4001
 
 
4002
        /* Enable redo commands if there are data into main redo list (history list) */
 
4003
        if (ET_History_File_List_Has_Redo_Data())
 
4004
            ui_widget_set_sensitive(MENU_FILE, AM_REDO_HISTORY, TRUE);
 
4005
        else
 
4006
            ui_widget_set_sensitive(MENU_FILE, AM_REDO_HISTORY, FALSE);
 
4007
    }
 
4008
 
 
4009
    if (!ETCore->ETFileDisplayedList->prev)    /* Is it the 1st item ? */
 
4010
    {
 
4011
        ui_widget_set_sensitive(MENU_FILE, AM_PREV,FALSE);
 
4012
        ui_widget_set_sensitive(MENU_FILE, AM_FIRST,FALSE);
 
4013
    }else
 
4014
    {
 
4015
        ui_widget_set_sensitive(MENU_FILE, AM_PREV,TRUE);
 
4016
        ui_widget_set_sensitive(MENU_FILE, AM_FIRST,TRUE);
 
4017
    }
 
4018
    if (!ETCore->ETFileDisplayedList->next)    /* Is it the last item ? */
 
4019
    {
 
4020
        ui_widget_set_sensitive(MENU_FILE, AM_NEXT,FALSE);
 
4021
        ui_widget_set_sensitive(MENU_FILE, AM_LAST,FALSE);
 
4022
    }else
 
4023
    {
 
4024
        ui_widget_set_sensitive(MENU_FILE, AM_NEXT,TRUE);
 
4025
        ui_widget_set_sensitive(MENU_FILE, AM_LAST,TRUE);
 
4026
    }
 
4027
}
 
4028
 
 
4029
/*
 
4030
 * Just to disable buttons when we are saving files (do not disable Quit button)
 
4031
 */
 
4032
void Disable_Command_Buttons (void)
 
4033
{
 
4034
    /* Scanner Window */
 
4035
    if (SWScanButton)
 
4036
        gtk_widget_set_sensitive(SWScanButton,FALSE);
 
4037
 
 
4038
    /* "File" menu commands */
 
4039
    ui_widget_set_sensitive(MENU_FILE,AM_OPEN_FILE_WITH,FALSE);
 
4040
    ui_widget_set_sensitive(MENU_FILE,AM_SELECT_ALL_FILES,FALSE);
 
4041
    ui_widget_set_sensitive(MENU_FILE,AM_UNSELECT_ALL_FILES,FALSE);
 
4042
    ui_widget_set_sensitive(MENU_FILE,AM_INVERT_SELECTION,FALSE);
 
4043
    ui_widget_set_sensitive(MENU_FILE,AM_DELETE_FILE,FALSE);
 
4044
    ui_widget_set_sensitive(MENU_FILE,AM_FIRST,FALSE);
 
4045
    ui_widget_set_sensitive(MENU_FILE,AM_PREV,FALSE);
 
4046
    ui_widget_set_sensitive(MENU_FILE,AM_NEXT,FALSE);
 
4047
    ui_widget_set_sensitive(MENU_FILE,AM_LAST,FALSE);
 
4048
    ui_widget_set_sensitive(MENU_FILE,AM_SCAN,FALSE);
 
4049
    ui_widget_set_sensitive(MENU_FILE,AM_REMOVE,FALSE);
 
4050
    ui_widget_set_sensitive(MENU_FILE,AM_UNDO,FALSE);
 
4051
    ui_widget_set_sensitive(MENU_FILE,AM_REDO,FALSE);
 
4052
    ui_widget_set_sensitive(MENU_FILE,AM_SAVE,FALSE);
 
4053
    ui_widget_set_sensitive(MENU_FILE,AM_SAVE_FORCED,FALSE);
 
4054
    ui_widget_set_sensitive(MENU_FILE,AM_UNDO_HISTORY,FALSE);
 
4055
    ui_widget_set_sensitive(MENU_FILE,AM_REDO_HISTORY,FALSE);
 
4056
 
 
4057
    /* "Scanner" menu commands */
 
4058
    ui_widget_set_sensitive(MENU_SCANNER,AM_SCANNER_FILL_TAG,FALSE);
 
4059
    ui_widget_set_sensitive(MENU_SCANNER,AM_SCANNER_RENAME_FILE,FALSE);
 
4060
    ui_widget_set_sensitive(MENU_SCANNER,AM_SCANNER_PROCESS_FIELDS,FALSE);
 
4061
 
 
4062
}
 
4063
 
 
4064
/*
 
4065
 * Disable (FALSE) / Enable (TRUE) all user widgets in the tag area
 
4066
 */
 
4067
void Tag_Area_Set_Sensitive (gboolean activate)
 
4068
{
 
4069
    if (!TagArea) return;
 
4070
 
 
4071
    // TAG Area (entries + buttons)
 
4072
    gtk_widget_set_sensitive(GTK_BIN(TagArea)->child,activate);
 
4073
 
 
4074
    /*// TAG Area
 
4075
    gtk_widget_set_sensitive(GTK_WIDGET(TitleEntry),            activate);
 
4076
    gtk_widget_set_sensitive(GTK_WIDGET(ArtistEntry),           activate);
 
4077
    gtk_widget_set_sensitive(GTK_WIDGET(AlbumEntry),            activate);
 
4078
    gtk_widget_set_sensitive(GTK_WIDGET(DiscNumberEntry),       activate);
 
4079
    gtk_widget_set_sensitive(GTK_WIDGET(YearEntry),             activate);
 
4080
    gtk_widget_set_sensitive(GTK_WIDGET(TrackEntryCombo),       activate);
 
4081
    gtk_widget_set_sensitive(GTK_WIDGET(TrackTotalEntry),       activate);
 
4082
    gtk_widget_set_sensitive(GTK_WIDGET(CommentEntry),          activate);
 
4083
    gtk_widget_set_sensitive(GTK_WIDGET(GenreCombo),            activate);
 
4084
    gtk_widget_set_sensitive(GTK_WIDGET(PictureScrollWindow),   activate);
 
4085
    // Mini buttons
 
4086
    gtk_widget_set_sensitive(GTK_WIDGET(TitleMButton),          activate);
 
4087
    gtk_widget_set_sensitive(GTK_WIDGET(ArtistMButton),         activate);
 
4088
    gtk_widget_set_sensitive(GTK_WIDGET(DiscNumberMButton),     activate);
 
4089
    gtk_widget_set_sensitive(GTK_WIDGET(AlbumMButton),          activate);
 
4090
    gtk_widget_set_sensitive(GTK_WIDGET(YearMButton),           activate);
 
4091
    gtk_widget_set_sensitive(GTK_WIDGET(TrackMButton),          activate);
 
4092
    gtk_widget_set_sensitive(GTK_WIDGET(TrackMButtonSequence),  activate);
 
4093
    gtk_widget_set_sensitive(GTK_WIDGET(TrackMButtonNbrFiles),  activate);
 
4094
    gtk_widget_set_sensitive(GTK_WIDGET(CommentMButton),        activate);
 
4095
    gtk_widget_set_sensitive(GTK_WIDGET(GenreMButton),          activate);
 
4096
    gtk_widget_set_sensitive(GTK_WIDGET(PictureMButton),        activate);*/
 
4097
}
 
4098
 
 
4099
/*
 
4100
 * Disable (FALSE) / Enable (TRUE) all user widgets in the file area
 
4101
 */
 
4102
void File_Area_Set_Sensitive (gboolean activate)
 
4103
{
 
4104
    if (!FileArea) return;
 
4105
 
 
4106
    // File Area
 
4107
    gtk_widget_set_sensitive(GTK_BIN(FileArea)->child,activate);
 
4108
    /*gtk_widget_set_sensitive(GTK_WIDGET(FileEntry),activate);*/
 
4109
}
 
4110
 
 
4111
/*
 
4112
 * Display controls according the kind of tag... (Hide some controls if not available for a tag type)
 
4113
 */
 
4114
void Tag_Area_Display_Controls (ET_File *ETFile)
 
4115
{
 
4116
    if (!ETFile || !ETFile->ETFileDescription || !TitleLabel)
 
4117
        return;
 
4118
 
 
4119
    // Commun controls for all tags
 
4120
    gtk_widget_show(GTK_WIDGET(TitleLabel));
 
4121
    gtk_widget_show(GTK_WIDGET(TitleEntry));
 
4122
    gtk_widget_show(GTK_WIDGET(TitleMButton));
 
4123
    gtk_widget_show(GTK_WIDGET(ArtistLabel));
 
4124
    gtk_widget_show(GTK_WIDGET(ArtistEntry));
 
4125
    gtk_widget_show(GTK_WIDGET(AlbumArtistLabel));
 
4126
    gtk_widget_show(GTK_WIDGET(AlbumArtistEntry));
 
4127
    gtk_widget_show(GTK_WIDGET(ArtistMButton));
 
4128
    gtk_widget_show(GTK_WIDGET(AlbumLabel));
 
4129
    gtk_widget_show(GTK_WIDGET(AlbumEntry));
 
4130
    gtk_widget_show(GTK_WIDGET(AlbumMButton));
 
4131
    gtk_widget_show(GTK_WIDGET(YearLabel));
 
4132
    gtk_widget_show(GTK_WIDGET(YearEntry));
 
4133
    gtk_widget_show(GTK_WIDGET(YearMButton));
 
4134
    gtk_widget_show(GTK_WIDGET(TrackLabel));
 
4135
    gtk_widget_show(GTK_WIDGET(TrackEntryCombo));
 
4136
    gtk_widget_show(GTK_WIDGET(TrackTotalEntry));
 
4137
    gtk_widget_show(GTK_WIDGET(TrackMButton));
 
4138
    gtk_widget_show(GTK_WIDGET(TrackMButtonSequence));
 
4139
    gtk_widget_show(GTK_WIDGET(TrackMButtonNbrFiles));
 
4140
    gtk_widget_show(GTK_WIDGET(GenreLabel));
 
4141
    gtk_widget_show(GTK_WIDGET(GenreCombo));
 
4142
    gtk_widget_show(GTK_WIDGET(GenreMButton));
 
4143
    gtk_widget_show(GTK_WIDGET(CommentLabel));
 
4144
    gtk_widget_show(GTK_WIDGET(CommentEntry));
 
4145
    gtk_widget_show(GTK_WIDGET(CommentMButton));
 
4146
 
 
4147
    // Special controls to display or not!
 
4148
    switch (ETFile->ETFileDescription->TagType)
 
4149
    {
 
4150
        case ID3_TAG:
 
4151
            if (!FILE_WRITING_ID3V2_WRITE_TAG)
 
4152
            {
 
4153
                // ID3v1 : Hide specifics ID3v2 fields if not activated!
 
4154
                gtk_widget_hide(GTK_WIDGET(DiscNumberLabel));
 
4155
                gtk_widget_hide(GTK_WIDGET(DiscNumberEntry));
 
4156
                gtk_widget_hide(GTK_WIDGET(DiscNumberMButton));
 
4157
                gtk_widget_hide(GTK_WIDGET(ComposerLabel));
 
4158
                gtk_widget_hide(GTK_WIDGET(ComposerEntry));
 
4159
                gtk_widget_hide(GTK_WIDGET(ComposerMButton));
 
4160
                gtk_widget_hide(GTK_WIDGET(OrigArtistLabel));
 
4161
                gtk_widget_hide(GTK_WIDGET(OrigArtistEntry));
 
4162
                gtk_widget_hide(GTK_WIDGET(OrigArtistMButton));
 
4163
                gtk_widget_hide(GTK_WIDGET(CopyrightLabel));
 
4164
                gtk_widget_hide(GTK_WIDGET(CopyrightEntry));
 
4165
                gtk_widget_hide(GTK_WIDGET(CopyrightMButton));
 
4166
                gtk_widget_hide(GTK_WIDGET(URLLabel));
 
4167
                gtk_widget_hide(GTK_WIDGET(URLEntry));
 
4168
                gtk_widget_hide(GTK_WIDGET(URLMButton));
 
4169
                gtk_widget_hide(GTK_WIDGET(EncodedByLabel));
 
4170
                gtk_widget_hide(GTK_WIDGET(EncodedByEntry));
 
4171
                gtk_widget_hide(GTK_WIDGET(EncodedByMButton));
 
4172
                gtk_widget_hide(GTK_WIDGET(PictureLabel));
 
4173
                gtk_widget_hide(GTK_WIDGET(PictureScrollWindow));
 
4174
                gtk_widget_hide(GTK_WIDGET(PictureMButton));
 
4175
                gtk_widget_hide(GTK_WIDGET(PictureClearButton));
 
4176
                gtk_widget_hide(GTK_WIDGET(PictureAddButton));
 
4177
                gtk_widget_hide(GTK_WIDGET(PictureSaveButton));
 
4178
                gtk_widget_hide(GTK_WIDGET(PicturePropertiesButton));
 
4179
            }else
 
4180
            {
 
4181
                gtk_widget_show(GTK_WIDGET(DiscNumberLabel));
 
4182
                gtk_widget_show(GTK_WIDGET(DiscNumberEntry));
 
4183
                gtk_widget_show(GTK_WIDGET(DiscNumberMButton));
 
4184
                gtk_widget_show(GTK_WIDGET(ComposerLabel));
 
4185
                gtk_widget_show(GTK_WIDGET(ComposerEntry));
 
4186
                gtk_widget_show(GTK_WIDGET(ComposerMButton));
 
4187
                gtk_widget_show(GTK_WIDGET(OrigArtistLabel));
 
4188
                gtk_widget_show(GTK_WIDGET(OrigArtistEntry));
 
4189
                gtk_widget_show(GTK_WIDGET(OrigArtistMButton));
 
4190
                gtk_widget_show(GTK_WIDGET(CopyrightLabel));
 
4191
                gtk_widget_show(GTK_WIDGET(CopyrightEntry));
 
4192
                gtk_widget_show(GTK_WIDGET(CopyrightMButton));
 
4193
                gtk_widget_show(GTK_WIDGET(URLLabel));
 
4194
                gtk_widget_show(GTK_WIDGET(URLEntry));
 
4195
                gtk_widget_show(GTK_WIDGET(URLMButton));
 
4196
                gtk_widget_show(GTK_WIDGET(EncodedByLabel));
 
4197
                gtk_widget_show(GTK_WIDGET(EncodedByEntry));
 
4198
                gtk_widget_show(GTK_WIDGET(EncodedByMButton));
 
4199
                gtk_widget_show(GTK_WIDGET(PictureLabel));
 
4200
                gtk_widget_show(GTK_WIDGET(PictureScrollWindow));
 
4201
                gtk_widget_show(GTK_WIDGET(PictureMButton));
 
4202
                gtk_widget_show(GTK_WIDGET(PictureClearButton));
 
4203
                gtk_widget_show(GTK_WIDGET(PictureAddButton));
 
4204
                gtk_widget_show(GTK_WIDGET(PictureSaveButton));
 
4205
                gtk_widget_show(GTK_WIDGET(PicturePropertiesButton));
 
4206
            }
 
4207
            break;
 
4208
 
 
4209
#ifdef ENABLE_OGG
 
4210
        case OGG_TAG:
 
4211
            gtk_widget_show(GTK_WIDGET(DiscNumberLabel));
 
4212
            gtk_widget_show(GTK_WIDGET(DiscNumberEntry));
 
4213
            gtk_widget_show(GTK_WIDGET(DiscNumberMButton));
 
4214
            gtk_widget_show(GTK_WIDGET(ComposerLabel));
 
4215
            gtk_widget_show(GTK_WIDGET(ComposerEntry));
 
4216
            gtk_widget_show(GTK_WIDGET(ComposerMButton));
 
4217
            gtk_widget_show(GTK_WIDGET(OrigArtistLabel));
 
4218
            gtk_widget_show(GTK_WIDGET(OrigArtistEntry));
 
4219
            gtk_widget_show(GTK_WIDGET(OrigArtistMButton));
 
4220
            gtk_widget_show(GTK_WIDGET(CopyrightLabel));
 
4221
            gtk_widget_show(GTK_WIDGET(CopyrightEntry));
 
4222
            gtk_widget_show(GTK_WIDGET(CopyrightMButton));
 
4223
            gtk_widget_show(GTK_WIDGET(URLLabel));
 
4224
            gtk_widget_show(GTK_WIDGET(URLEntry));
 
4225
            gtk_widget_show(GTK_WIDGET(URLMButton));
 
4226
            gtk_widget_show(GTK_WIDGET(EncodedByLabel));
 
4227
            gtk_widget_show(GTK_WIDGET(EncodedByEntry));
 
4228
            gtk_widget_show(GTK_WIDGET(EncodedByMButton));
 
4229
            gtk_widget_show(GTK_WIDGET(PictureLabel));
 
4230
            gtk_widget_show(GTK_WIDGET(PictureScrollWindow));
 
4231
            gtk_widget_show(GTK_WIDGET(PictureMButton));
 
4232
            gtk_widget_show(GTK_WIDGET(PictureClearButton));
 
4233
            gtk_widget_show(GTK_WIDGET(PictureAddButton));
 
4234
            gtk_widget_show(GTK_WIDGET(PictureSaveButton));
 
4235
            gtk_widget_show(GTK_WIDGET(PicturePropertiesButton));
 
4236
            break;
 
4237
#endif
 
4238
 
 
4239
#ifdef ENABLE_FLAC
 
4240
        case FLAC_TAG:
 
4241
            gtk_widget_show(GTK_WIDGET(DiscNumberLabel));
 
4242
            gtk_widget_show(GTK_WIDGET(DiscNumberEntry));
 
4243
            gtk_widget_show(GTK_WIDGET(DiscNumberMButton));
 
4244
            gtk_widget_show(GTK_WIDGET(ComposerLabel));
 
4245
            gtk_widget_show(GTK_WIDGET(ComposerEntry));
 
4246
            gtk_widget_show(GTK_WIDGET(ComposerMButton));
 
4247
            gtk_widget_show(GTK_WIDGET(OrigArtistLabel));
 
4248
            gtk_widget_show(GTK_WIDGET(OrigArtistEntry));
 
4249
            gtk_widget_show(GTK_WIDGET(OrigArtistMButton));
 
4250
            gtk_widget_show(GTK_WIDGET(CopyrightLabel));
 
4251
            gtk_widget_show(GTK_WIDGET(CopyrightEntry));
 
4252
            gtk_widget_show(GTK_WIDGET(CopyrightMButton));
 
4253
            gtk_widget_show(GTK_WIDGET(URLLabel));
 
4254
            gtk_widget_show(GTK_WIDGET(URLEntry));
 
4255
            gtk_widget_show(GTK_WIDGET(URLMButton));
 
4256
            gtk_widget_show(GTK_WIDGET(EncodedByLabel));
 
4257
            gtk_widget_show(GTK_WIDGET(EncodedByEntry));
 
4258
            gtk_widget_show(GTK_WIDGET(EncodedByMButton));
 
4259
            #ifndef LEGACY_FLAC // Picture supported for FLAC >= 1.1.3...
 
4260
            gtk_widget_show(GTK_WIDGET(PictureLabel));
 
4261
            gtk_widget_show(GTK_WIDGET(PictureScrollWindow));
 
4262
            gtk_widget_show(GTK_WIDGET(PictureMButton));
 
4263
            gtk_widget_show(GTK_WIDGET(PictureClearButton));
 
4264
            gtk_widget_show(GTK_WIDGET(PictureAddButton));
 
4265
            gtk_widget_show(GTK_WIDGET(PictureSaveButton));
 
4266
            gtk_widget_show(GTK_WIDGET(PicturePropertiesButton));
 
4267
            #else
 
4268
            if (WRITE_ID3_TAGS_IN_FLAC_FILE)
 
4269
            {
 
4270
                gtk_widget_show(GTK_WIDGET(PictureLabel));
 
4271
                gtk_widget_show(GTK_WIDGET(PictureScrollWindow));
 
4272
                gtk_widget_show(GTK_WIDGET(PictureMButton));
 
4273
                gtk_widget_show(GTK_WIDGET(PictureClearButton));
 
4274
                gtk_widget_show(GTK_WIDGET(PictureAddButton));
 
4275
                gtk_widget_show(GTK_WIDGET(PictureSaveButton));
 
4276
                gtk_widget_show(GTK_WIDGET(PicturePropertiesButton));
 
4277
            }else
 
4278
            {
 
4279
                gtk_widget_hide(GTK_WIDGET(PictureLabel));
 
4280
                gtk_widget_hide(GTK_WIDGET(PictureScrollWindow));
 
4281
                gtk_widget_hide(GTK_WIDGET(PictureMButton));
 
4282
                gtk_widget_hide(GTK_WIDGET(PictureClearButton));
 
4283
                gtk_widget_hide(GTK_WIDGET(PictureAddButton));
 
4284
                gtk_widget_hide(GTK_WIDGET(PictureSaveButton));
 
4285
                gtk_widget_hide(GTK_WIDGET(PicturePropertiesButton));
 
4286
            }
 
4287
            #endif
 
4288
            break;
 
4289
#endif
 
4290
 
 
4291
        case APE_TAG:
 
4292
            gtk_widget_show(GTK_WIDGET(DiscNumberLabel));
 
4293
            gtk_widget_show(GTK_WIDGET(DiscNumberEntry));
 
4294
            gtk_widget_show(GTK_WIDGET(DiscNumberMButton));
 
4295
            gtk_widget_show(GTK_WIDGET(ComposerLabel));
 
4296
            gtk_widget_show(GTK_WIDGET(ComposerEntry));
 
4297
            gtk_widget_show(GTK_WIDGET(ComposerMButton));
 
4298
            gtk_widget_show(GTK_WIDGET(OrigArtistLabel));
 
4299
            gtk_widget_show(GTK_WIDGET(OrigArtistEntry));
 
4300
            gtk_widget_show(GTK_WIDGET(OrigArtistMButton));
 
4301
            gtk_widget_show(GTK_WIDGET(CopyrightLabel));
 
4302
            gtk_widget_show(GTK_WIDGET(CopyrightEntry));
 
4303
            gtk_widget_show(GTK_WIDGET(CopyrightMButton));
 
4304
            gtk_widget_show(GTK_WIDGET(URLLabel));
 
4305
            gtk_widget_show(GTK_WIDGET(URLEntry));
 
4306
            gtk_widget_show(GTK_WIDGET(URLMButton));
 
4307
            gtk_widget_show(GTK_WIDGET(EncodedByLabel));
 
4308
            gtk_widget_show(GTK_WIDGET(EncodedByEntry));
 
4309
            gtk_widget_show(GTK_WIDGET(EncodedByMButton));
 
4310
            gtk_widget_hide(GTK_WIDGET(PictureLabel));
 
4311
            gtk_widget_hide(GTK_WIDGET(PictureScrollWindow));
 
4312
            gtk_widget_hide(GTK_WIDGET(PictureMButton));
 
4313
            gtk_widget_hide(GTK_WIDGET(PictureClearButton));
 
4314
            gtk_widget_hide(GTK_WIDGET(PictureAddButton));
 
4315
            gtk_widget_hide(GTK_WIDGET(PictureSaveButton));
 
4316
            gtk_widget_hide(GTK_WIDGET(PicturePropertiesButton));
 
4317
            break;
 
4318
 
 
4319
#ifdef ENABLE_MP4
 
4320
        case MP4_TAG:
 
4321
            gtk_widget_show(GTK_WIDGET(DiscNumberLabel));
 
4322
            gtk_widget_show(GTK_WIDGET(DiscNumberEntry));
 
4323
            gtk_widget_show(GTK_WIDGET(DiscNumberMButton));
 
4324
            gtk_widget_show(GTK_WIDGET(ComposerLabel));
 
4325
            gtk_widget_show(GTK_WIDGET(ComposerEntry));
 
4326
            gtk_widget_show(GTK_WIDGET(ComposerMButton));
 
4327
            gtk_widget_hide(GTK_WIDGET(OrigArtistLabel));
 
4328
            gtk_widget_hide(GTK_WIDGET(OrigArtistEntry));
 
4329
            gtk_widget_hide(GTK_WIDGET(OrigArtistMButton));
 
4330
            gtk_widget_hide(GTK_WIDGET(CopyrightLabel));
 
4331
            gtk_widget_hide(GTK_WIDGET(CopyrightEntry));
 
4332
            gtk_widget_hide(GTK_WIDGET(CopyrightMButton));
 
4333
            gtk_widget_hide(GTK_WIDGET(URLLabel));
 
4334
            gtk_widget_hide(GTK_WIDGET(URLEntry));
 
4335
            gtk_widget_hide(GTK_WIDGET(URLMButton));
 
4336
            gtk_widget_show(GTK_WIDGET(EncodedByLabel));
 
4337
            gtk_widget_show(GTK_WIDGET(EncodedByEntry));
 
4338
            gtk_widget_show(GTK_WIDGET(EncodedByMButton));
 
4339
            gtk_widget_show(GTK_WIDGET(PictureLabel));
 
4340
            gtk_widget_show(GTK_WIDGET(PictureScrollWindow));
 
4341
            gtk_widget_show(GTK_WIDGET(PictureMButton));
 
4342
            gtk_widget_show(GTK_WIDGET(PictureClearButton));
 
4343
            gtk_widget_show(GTK_WIDGET(PictureAddButton));
 
4344
            gtk_widget_show(GTK_WIDGET(PictureSaveButton));
 
4345
            gtk_widget_show(GTK_WIDGET(PicturePropertiesButton));
 
4346
            break;
 
4347
#endif
 
4348
 
 
4349
#ifdef ENABLE_WAVPACK
 
4350
        case WAVPACK_TAG:
 
4351
            gtk_widget_show(GTK_WIDGET(DiscNumberLabel));
 
4352
            gtk_widget_show(GTK_WIDGET(DiscNumberEntry));
 
4353
            gtk_widget_show(GTK_WIDGET(DiscNumberMButton));
 
4354
            gtk_widget_show(GTK_WIDGET(ComposerLabel));
 
4355
            gtk_widget_show(GTK_WIDGET(ComposerEntry));
 
4356
            gtk_widget_show(GTK_WIDGET(ComposerMButton));
 
4357
            gtk_widget_show(GTK_WIDGET(OrigArtistLabel));
 
4358
            gtk_widget_show(GTK_WIDGET(OrigArtistEntry));
 
4359
            gtk_widget_show(GTK_WIDGET(OrigArtistMButton));
 
4360
            gtk_widget_show(GTK_WIDGET(CopyrightLabel));
 
4361
            gtk_widget_show(GTK_WIDGET(CopyrightEntry));
 
4362
            gtk_widget_show(GTK_WIDGET(CopyrightMButton));
 
4363
            gtk_widget_show(GTK_WIDGET(URLLabel));
 
4364
            gtk_widget_show(GTK_WIDGET(URLEntry));
 
4365
            gtk_widget_show(GTK_WIDGET(URLMButton));
 
4366
            gtk_widget_show(GTK_WIDGET(EncodedByLabel));
 
4367
            gtk_widget_show(GTK_WIDGET(EncodedByEntry));
 
4368
            gtk_widget_show(GTK_WIDGET(EncodedByMButton));
 
4369
            gtk_widget_hide(GTK_WIDGET(PictureLabel));
 
4370
            gtk_widget_hide(GTK_WIDGET(PictureScrollWindow));
 
4371
            gtk_widget_hide(GTK_WIDGET(PictureMButton));
 
4372
            gtk_widget_hide(GTK_WIDGET(PictureClearButton));
 
4373
            gtk_widget_hide(GTK_WIDGET(PictureAddButton));
 
4374
            gtk_widget_hide(GTK_WIDGET(PictureSaveButton));
 
4375
            gtk_widget_hide(GTK_WIDGET(PicturePropertiesButton));
 
4376
            break;
 
4377
#endif /* ENABLE_WAVPACK */
 
4378
 
 
4379
        case UNKNOWN_TAG:
 
4380
        default:
 
4381
            gtk_widget_hide(GTK_WIDGET(DiscNumberLabel));
 
4382
            gtk_widget_hide(GTK_WIDGET(DiscNumberEntry));
 
4383
            gtk_widget_hide(GTK_WIDGET(DiscNumberMButton));
 
4384
            gtk_widget_hide(GTK_WIDGET(ComposerLabel));
 
4385
            gtk_widget_hide(GTK_WIDGET(ComposerEntry));
 
4386
            gtk_widget_hide(GTK_WIDGET(ComposerMButton));
 
4387
            gtk_widget_hide(GTK_WIDGET(OrigArtistLabel));
 
4388
            gtk_widget_hide(GTK_WIDGET(OrigArtistEntry));
 
4389
            gtk_widget_hide(GTK_WIDGET(OrigArtistMButton));
 
4390
            gtk_widget_hide(GTK_WIDGET(CopyrightLabel));
 
4391
            gtk_widget_hide(GTK_WIDGET(CopyrightEntry));
 
4392
            gtk_widget_hide(GTK_WIDGET(CopyrightMButton));
 
4393
            gtk_widget_hide(GTK_WIDGET(URLLabel));
 
4394
            gtk_widget_hide(GTK_WIDGET(URLEntry));
 
4395
            gtk_widget_hide(GTK_WIDGET(URLMButton));
 
4396
            gtk_widget_hide(GTK_WIDGET(EncodedByLabel));
 
4397
            gtk_widget_hide(GTK_WIDGET(EncodedByEntry));
 
4398
            gtk_widget_hide(GTK_WIDGET(EncodedByMButton));
 
4399
            gtk_widget_hide(GTK_WIDGET(PictureLabel));
 
4400
            gtk_widget_hide(GTK_WIDGET(PictureScrollWindow));
 
4401
            gtk_widget_hide(GTK_WIDGET(PictureMButton));
 
4402
            gtk_widget_hide(GTK_WIDGET(PictureClearButton));
 
4403
            gtk_widget_hide(GTK_WIDGET(PictureAddButton));
 
4404
            gtk_widget_hide(GTK_WIDGET(PictureSaveButton));
 
4405
            gtk_widget_hide(GTK_WIDGET(PicturePropertiesButton));
 
4406
            break;
 
4407
    }
 
4408
}
 
4409
 
 
4410
 
 
4411
/*
 
4412
 * Clear the entries of tag area
 
4413
 */
 
4414
void Clear_Tag_Entry_Fields (void)
 
4415
{
 
4416
    //GtkTextBuffer *textbuffer;
 
4417
 
 
4418
    if (!TitleEntry) return;
 
4419
 
 
4420
    gtk_entry_set_text(GTK_ENTRY(TitleEntry),                       "");
 
4421
    gtk_entry_set_text(GTK_ENTRY(ArtistEntry),                      "");
 
4422
    gtk_entry_set_text(GTK_ENTRY(AlbumArtistEntry),                 "");
 
4423
    gtk_entry_set_text(GTK_ENTRY(AlbumEntry),                       "");
 
4424
    gtk_entry_set_text(GTK_ENTRY(DiscNumberEntry),                  "");
 
4425
    gtk_entry_set_text(GTK_ENTRY(YearEntry),                        "");
 
4426
    gtk_entry_set_text(GTK_ENTRY(GTK_BIN(TrackEntryCombo)->child),  "");
 
4427
    gtk_entry_set_text(GTK_ENTRY(TrackTotalEntry),                  "");
 
4428
    gtk_entry_set_text(GTK_ENTRY(GTK_BIN(GenreCombo)->child),       "");
 
4429
    gtk_entry_set_text(GTK_ENTRY(CommentEntry),                     "");
 
4430
    //textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(CommentView));
 
4431
    //gtk_text_buffer_set_text(GTK_TEXT_BUFFER(textbuffer),           "", -1);
 
4432
    gtk_entry_set_text(GTK_ENTRY(ComposerEntry),                    "");
 
4433
    gtk_entry_set_text(GTK_ENTRY(OrigArtistEntry),                  "");
 
4434
    gtk_entry_set_text(GTK_ENTRY(CopyrightEntry),                   "");
 
4435
    gtk_entry_set_text(GTK_ENTRY(URLEntry),                         "");
 
4436
    gtk_entry_set_text(GTK_ENTRY(EncodedByEntry),                   "");
 
4437
    PictureEntry_Clear();
 
4438
}
 
4439
 
 
4440
 
 
4441
/*
 
4442
 * Clear the entry of file area
 
4443
 */
 
4444
void Clear_File_Entry_Field (void)
 
4445
{
 
4446
    if (!FileEntry) return;
 
4447
 
 
4448
    gtk_entry_set_text(GTK_ENTRY(FileEntry),"");
 
4449
}
 
4450
 
 
4451
 
 
4452
/*
 
4453
 * Clear the header informations
 
4454
 */
 
4455
void Clear_Header_Fields (void)
 
4456
{
 
4457
    if (!VersionValueLabel) return;
 
4458
 
 
4459
    /* Default values are MPs data */
 
4460
    gtk_label_set_text(GTK_LABEL(VersionLabel),        _("MPEG"));
 
4461
    gtk_label_set_text(GTK_LABEL(VersionValueLabel),   _("?, Layer ?"));
 
4462
    gtk_label_set_text(GTK_LABEL(BitrateValueLabel),   _("? kb/s"));
 
4463
    gtk_label_set_text(GTK_LABEL(SampleRateValueLabel),_("? Hz"));
 
4464
    gtk_label_set_text(GTK_LABEL(ModeLabel),           _("Mode:"));
 
4465
    gtk_label_set_text(GTK_LABEL(ModeValueLabel),      _("?"));
 
4466
    gtk_label_set_text(GTK_LABEL(SizeValueLabel),      _("?"));
 
4467
    gtk_label_set_text(GTK_LABEL(DurationValueLabel),  _("?"));
 
4468
}
 
4469
 
 
4470
 
 
4471
 
 
4472
 
 
4473
/*
 
4474
 * Load the default directory when the user interface is completely displayed
 
4475
 * to avoid bad visualization effect at startup.
 
4476
 */
 
4477
void Init_Load_Default_Dir (void)
 
4478
{
 
4479
    //ETCore->ETFileList = (GList *)NULL;
 
4480
    ET_Core_Free();
 
4481
    ET_Core_Initialize();
 
4482
 
 
4483
    // Open the scanner window
 
4484
    if (OPEN_SCANNER_WINDOW_ON_STARTUP)
 
4485
        Open_ScannerWindow(SCANNER_TYPE); // Open the last selected scanner
 
4486
 
 
4487
    if (INIT_DIRECTORY)
 
4488
    {
 
4489
        Browser_Tree_Select_Dir(INIT_DIRECTORY);
 
4490
        Browser_Reload_Directory();
 
4491
    }else
 
4492
    {
 
4493
        Statusbar_Message(_("Select a directory to browse!"),FALSE);
 
4494
        Browser_Load_Default_Directory();
 
4495
    }
 
4496
 
 
4497
    // To set sensivity of buttons in the case if the default directory is invalid
 
4498
    Update_Command_Buttons_Sensivity();
 
4499
 
 
4500
    g_source_remove(idle_handler_id);
 
4501
}
 
4502
 
 
4503
 
 
4504
 
 
4505
void Convert_P20_And_Undescore_Into_Spaces (GtkWidget *entry)
 
4506
{
 
4507
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4508
 
 
4509
    Scan_Convert_Underscore_Into_Space(string);
 
4510
    Scan_Convert_P20_Into_Space(string);
 
4511
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4512
    g_free(string);
 
4513
}
 
4514
 
 
4515
void Convert_Space_Into_Undescore (GtkWidget *entry)
 
4516
{
 
4517
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4518
 
 
4519
    Scan_Convert_Space_Into_Undescore(string);
 
4520
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4521
    g_free(string);
 
4522
}
 
4523
 
 
4524
void Convert_All_Uppercase (GtkWidget *entry)
 
4525
{
 
4526
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4527
 
 
4528
    Scan_Process_Fields_All_Uppercase(string);
 
4529
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4530
    g_free(string);
 
4531
}
 
4532
 
 
4533
void Convert_All_Downcase (GtkWidget *entry)
 
4534
{
 
4535
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4536
 
 
4537
    Scan_Process_Fields_All_Downcase(string);
 
4538
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4539
    g_free(string);
 
4540
}
 
4541
 
 
4542
void Convert_Letter_Uppercase (GtkWidget *entry)
 
4543
{
 
4544
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4545
 
 
4546
    Scan_Process_Fields_Letter_Uppercase(string);
 
4547
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4548
    g_free(string);
 
4549
}
 
4550
 
 
4551
void Convert_First_Letters_Uppercase (GtkWidget *entry)
 
4552
{
 
4553
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4554
 
 
4555
    Scan_Process_Fields_First_Letters_Uppercase(string);
 
4556
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4557
    g_free(string);
 
4558
}
 
4559
 
 
4560
void Convert_Remove_Space (GtkWidget *entry)
 
4561
{
 
4562
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4563
 
 
4564
    Scan_Process_Fields_Remove_Space(string);
 
4565
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4566
    g_free(string);
 
4567
}
 
4568
 
 
4569
void Convert_Insert_Space (GtkWidget *entry)
 
4570
{
 
4571
    // FIX ME : we suppose that it will not grow more than 2 times its size...
 
4572
    guint string_length = 2 * strlen(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4573
    gchar *string       = g_malloc(string_length+1);
 
4574
    strncpy(string,gtk_entry_get_text(GTK_ENTRY(entry)),string_length);
 
4575
    string[string_length]='\0';
 
4576
 
 
4577
    Scan_Process_Fields_Insert_Space(&string);
 
4578
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4579
    g_free(string);
 
4580
}
 
4581
 
 
4582
void Convert_Only_One_Space (GtkWidget *entry)
 
4583
{
 
4584
    gchar *string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
 
4585
 
 
4586
    Scan_Process_Fields_Keep_One_Space(string);
 
4587
    gtk_entry_set_text(GTK_ENTRY(entry),string);
 
4588
    g_free(string);
 
4589
}
 
4590
 
 
4591
/*
 
4592
 * Entry_Popup_Menu_Handler: show the popup menu when the third mouse button is pressed.
 
4593
 */
 
4594
gboolean Entry_Popup_Menu_Handler (GtkMenu *menu, GdkEventButton *event)
 
4595
{
 
4596
    if (event && (event->type==GDK_BUTTON_PRESS) && (event->button==3))
 
4597
    {
 
4598
        /* FIX ME : this is not very clean, but if we use 'event->button' (contains value of
 
4599
         * the 3rd button) instead of '1', we need to click two times the left mouse button
 
4600
         * to activate an item of the opened popup menu (when menu is attached to an entry). */
 
4601
        //gtk_menu_popup(menu,NULL,NULL,NULL,NULL,event->button,event->time);
 
4602
        gtk_menu_popup(menu,NULL,NULL,NULL,NULL,1,event->time);
 
4603
        return TRUE;
 
4604
    }
 
4605
    return FALSE;
 
4606
}
 
4607
 
 
4608
/*
 
4609
 * Popup menu attached to all entries of tag + filename + rename combobox.
 
4610
 * Displayed when pressing the right mouse button and contains functions to process ths strings.
 
4611
 */
 
4612
void Attach_Popup_Menu_To_Tag_Entries (GtkEntry *entry)
 
4613
{
 
4614
    GtkWidget *PopupMenu;
 
4615
    GtkWidget *Image;
 
4616
    GtkWidget *MenuItem;
 
4617
 
 
4618
 
 
4619
    PopupMenu = gtk_menu_new();
 
4620
    g_signal_connect_swapped(G_OBJECT(entry),"button_press_event",
 
4621
        G_CALLBACK(Entry_Popup_Menu_Handler),G_OBJECT(PopupMenu));
 
4622
 
 
4623
    /* Menu items */
 
4624
    MenuItem = gtk_image_menu_item_new_with_label(_("Tag selected files with this field"));
 
4625
    Image = gtk_image_new_from_stock(GTK_STOCK_JUMP_TO,GTK_ICON_SIZE_MENU);
 
4626
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4627
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4628
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4629
                             G_CALLBACK(Menu_Mini_Button_Clicked),G_OBJECT(entry));
 
4630
 
 
4631
    /* Separator */
 
4632
    MenuItem = gtk_menu_item_new();
 
4633
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4634
 
 
4635
    MenuItem = gtk_image_menu_item_new_with_label(_("Convert '_' and '%20' to spaces"));
 
4636
    Image = gtk_image_new_from_stock(GTK_STOCK_CONVERT,GTK_ICON_SIZE_MENU);
 
4637
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4638
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4639
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4640
        G_CALLBACK(Convert_P20_And_Undescore_Into_Spaces),G_OBJECT(entry));
 
4641
 
 
4642
    MenuItem = gtk_image_menu_item_new_with_label(_("Convert ' ' to '_'"));
 
4643
    Image = gtk_image_new_from_stock(GTK_STOCK_CONVERT,GTK_ICON_SIZE_MENU);
 
4644
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4645
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4646
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4647
        G_CALLBACK(Convert_Space_Into_Undescore),G_OBJECT(entry));
 
4648
 
 
4649
    /* Separator */
 
4650
    MenuItem = gtk_menu_item_new();
 
4651
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4652
 
 
4653
    MenuItem = gtk_image_menu_item_new_with_label(_("All uppercase"));
 
4654
    Image = gtk_image_new_from_stock("easytag-all-uppercase",GTK_ICON_SIZE_MENU);
 
4655
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4656
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4657
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4658
        G_CALLBACK(Convert_All_Uppercase),G_OBJECT(entry));
 
4659
 
 
4660
    MenuItem = gtk_image_menu_item_new_with_label(_("All downcase"));
 
4661
    Image = gtk_image_new_from_stock("easytag-all-downcase",GTK_ICON_SIZE_MENU);
 
4662
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4663
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4664
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4665
        G_CALLBACK(Convert_All_Downcase),G_OBJECT(entry));
 
4666
 
 
4667
    MenuItem = gtk_image_menu_item_new_with_label(_("First letter uppercase"));
 
4668
    Image = gtk_image_new_from_stock("easytag-first-letter-uppercase",GTK_ICON_SIZE_MENU);
 
4669
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4670
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4671
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4672
        G_CALLBACK(Convert_Letter_Uppercase),G_OBJECT(entry));
 
4673
 
 
4674
    MenuItem = gtk_image_menu_item_new_with_label(_("First letter uppercase of each word"));
 
4675
    Image = gtk_image_new_from_stock("easytag-first-letter-uppercase-word",GTK_ICON_SIZE_MENU);
 
4676
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4677
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4678
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4679
        G_CALLBACK(Convert_First_Letters_Uppercase),G_OBJECT(entry));
 
4680
 
 
4681
    /* Separator */
 
4682
    MenuItem = gtk_menu_item_new();
 
4683
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4684
 
 
4685
    MenuItem = gtk_image_menu_item_new_with_label(_("Remove spaces"));
 
4686
    Image = gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_MENU);
 
4687
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4688
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4689
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4690
        G_CALLBACK(Convert_Remove_Space),G_OBJECT(entry));
 
4691
 
 
4692
    MenuItem = gtk_image_menu_item_new_with_label(_("Insert space before uppercase letter"));
 
4693
    Image = gtk_image_new_from_stock(GTK_STOCK_ADD,GTK_ICON_SIZE_MENU);
 
4694
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4695
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4696
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4697
        G_CALLBACK(Convert_Insert_Space),G_OBJECT(entry));
 
4698
 
 
4699
    MenuItem = gtk_image_menu_item_new_with_label(_("Remove duplicate spaces or underscores"));
 
4700
    Image = gtk_image_new_from_stock(GTK_STOCK_REMOVE,GTK_ICON_SIZE_MENU);
 
4701
    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(MenuItem),Image);
 
4702
    gtk_menu_shell_append(GTK_MENU_SHELL(PopupMenu),MenuItem);
 
4703
    g_signal_connect_swapped(G_OBJECT(MenuItem),"activate",
 
4704
        G_CALLBACK(Convert_Only_One_Space),G_OBJECT(entry));
 
4705
 
 
4706
    gtk_widget_show_all(PopupMenu);
 
4707
}
 
4708
 
 
4709
 
 
4710
 
 
4711
/*
 
4712
 * Function to manage the received signals (specially for segfaults)
 
4713
 * Handle crashs
 
4714
 */
 
4715
void Handle_Crash (gint signal_id)
 
4716
{
 
4717
    //gchar commmand[256];
 
4718
 
 
4719
    Log_Print(LOG_ERROR,_("EasyTAG %s: Abnormal exit! (PId: %d)."),VERSION,getpid());
 
4720
    Log_Print(LOG_ERROR,_("Received signal %s (%d)\a"),signal_to_string(signal_id),signal_id);
 
4721
 
 
4722
    Log_Print(LOG_ERROR,_("You have probably found a bug in EasyTAG. Please, send a bug "
 
4723
              "report with a gdb backtrace ('gdb easytag core' then 'bt' and "
 
4724
              "'l') and informations to reproduce it to easytag@gmail.com"));
 
4725
 
 
4726
    // To send messages to the console...
 
4727
    g_print(_("EasyTAG %s: Abnormal exit! (PId: %d)."),VERSION,getpid());
 
4728
    g_print("\n");
 
4729
    g_print(_("Received signal %s (%d)\a"),signal_to_string(signal_id),signal_id);
 
4730
    g_print("\n");
 
4731
    g_print(_("You have probably found a bug in EasyTAG. Please, send a bug "
 
4732
            "report with a gdb backtrace ('gdb easytag core' then 'bt' and "
 
4733
            "'l') and informations to reproduce it to easytag@gmail.com"));
 
4734
    g_print("\n");
 
4735
 
 
4736
    signal(signal_id,SIG_DFL); // Let the OS handle recursive seg faults
 
4737
    //signal(SIGTSTP, exit);
 
4738
    //snprintf(commmand,sizeof(commmand),"gdb -x /root/core.txt easytag %d", getpid());
 
4739
    //system(commmand);
 
4740
}
 
4741
 
 
4742
gchar *signal_to_string (gint signal)
 
4743
{
 
4744
#ifdef SIGHUP
 
4745
    if (signal == SIGHUP)     return ("SIGHUP");
 
4746
#endif
 
4747
#ifdef SIGINT
 
4748
    if (signal == SIGINT)     return ("SIGINT");
 
4749
#endif
 
4750
#ifdef SIGQUIT
 
4751
    if (signal == SIGQUIT)    return ("SIGQUIT");
 
4752
#endif
 
4753
#ifdef SIGILL
 
4754
    if (signal == SIGILL)     return ("SIGILL");
 
4755
#endif
 
4756
#ifdef SIGTRAP
 
4757
    if (signal == SIGTRAP)    return ("SIGTRAP");
 
4758
#endif
 
4759
#ifdef SIGABRT
 
4760
    if (signal == SIGABRT)    return ("SIGABRT");
 
4761
#endif
 
4762
#ifdef SIGIOT
 
4763
    if (signal == SIGIOT)     return ("SIGIOT");
 
4764
#endif
 
4765
#ifdef SIGEMT
 
4766
    if (signal == SIGEMT)     return ("SIGEMT");
 
4767
#endif
 
4768
#ifdef SIGFPE
 
4769
    if (signal == SIGFPE)     return ("SIGFPE");
 
4770
#endif
 
4771
#ifdef SIGKILL
 
4772
    if (signal == SIGKILL)    return ("SIGKILL");
 
4773
#endif
 
4774
#ifdef SIGBUS
 
4775
    if (signal == SIGBUS)     return ("SIGBUS");
 
4776
#endif
 
4777
#ifdef SIGSEGV
 
4778
    if (signal == SIGSEGV)    return ("SIGSEGV");
 
4779
#endif
 
4780
#ifdef SIGSYS
 
4781
    if (signal == SIGSYS)     return ("SIGSYS");
 
4782
#endif
 
4783
#ifdef SIGPIPE
 
4784
    if (signal == SIGPIPE)    return ("SIGPIPE");
 
4785
#endif
 
4786
#ifdef SIGALRM
 
4787
    if (signal == SIGALRM)    return ("SIGALRM");
 
4788
#endif
 
4789
#ifdef SIGTERM
 
4790
    if (signal == SIGTERM)    return ("SIGTERM");
 
4791
#endif
 
4792
#ifdef SIGUSR1
 
4793
    if (signal == SIGUSR1)    return ("SIGUSR1");
 
4794
#endif
 
4795
#ifdef SIGUSR2
 
4796
    if (signal == SIGUSR2)    return ("SIGUSR2");
 
4797
#endif
 
4798
#ifdef SIGCHLD
 
4799
    if (signal == SIGCHLD)    return ("SIGCHLD");
 
4800
#endif
 
4801
#ifdef SIGCLD
 
4802
    if (signal == SIGCLD)     return ("SIGCLD");
 
4803
#endif
 
4804
#ifdef SIGPWR
 
4805
    if (signal == SIGPWR)     return ("SIGPWR");
 
4806
#endif
 
4807
#ifdef SIGVTALRM
 
4808
    if (signal == SIGVTALRM)  return ("SIGVTALRM");
 
4809
#endif
 
4810
#ifdef SIGPROF
 
4811
    if (signal == SIGPROF)    return ("SIGPROF");
 
4812
#endif
 
4813
#ifdef SIGIO
 
4814
    if (signal == SIGIO)      return ("SIGIO");
 
4815
#endif
 
4816
#ifdef SIGPOLL
 
4817
    if (signal == SIGPOLL)    return ("SIGPOLL");
 
4818
#endif
 
4819
#ifdef SIGWINCH
 
4820
    if (signal == SIGWINCH)   return ("SIGWINCH");
 
4821
#endif
 
4822
#ifdef SIGWINDOW
 
4823
    if (signal == SIGWINDOW)  return ("SIGWINDOW");
 
4824
#endif
 
4825
#ifdef SIGSTOP
 
4826
    if (signal == SIGSTOP)    return ("SIGSTOP");
 
4827
#endif
 
4828
#ifdef SIGTSTP
 
4829
    if (signal == SIGTSTP)    return ("SIGTSTP");
 
4830
#endif
 
4831
#ifdef SIGCONT
 
4832
    if (signal == SIGCONT)    return ("SIGCONT");
 
4833
#endif
 
4834
#ifdef SIGTTIN
 
4835
    if (signal == SIGTTIN)    return ("SIGTTIN");
 
4836
#endif
 
4837
#ifdef SIGTTOU
 
4838
    if (signal == SIGTTOU)    return ("SIGTTOU");
 
4839
#endif
 
4840
#ifdef SIGURG
 
4841
    if (signal == SIGURG)     return ("SIGURG");
 
4842
#endif
 
4843
#ifdef SIGLOST
 
4844
    if (signal == SIGLOST)    return ("SIGLOST");
 
4845
#endif
 
4846
#ifdef SIGRESERVE
 
4847
    if (signal == SIGRESERVE) return ("SIGRESERVE");
 
4848
#endif
 
4849
#ifdef SIGDIL
 
4850
    if (signal == SIGDIL)     return ("SIGDIL");
 
4851
#endif
 
4852
#ifdef SIGXCPU
 
4853
    if (signal == SIGXCPU)    return ("SIGXCPU");
 
4854
#endif
 
4855
#ifdef SIGXFSZ
 
4856
    if (signal == SIGXFSZ)    return ("SIGXFSZ");
 
4857
#endif
 
4858
    return (_("Unknown signal"));
 
4859
}
 
4860
 
 
4861
 
 
4862
/*
 
4863
 * Display usage informations
 
4864
 */
 
4865
void Display_Usage (void)
 
4866
{
 
4867
    // Fix from Steve Ralston for gcc-3.2.2
 
4868
#ifdef WIN32
 
4869
    #define xPREFIX "c:"
 
4870
#else
 
4871
    #define xPREFIX ""
 
4872
#endif
 
4873
 
 
4874
    g_print(_("\nUsage: easytag [option] "
 
4875
              "\n   or: easytag [directory]\n"
 
4876
              "\n"
 
4877
              "Option:\n"
 
4878
              "-------\n"
 
4879
              "-h, --help        Display this text and exit.\n"
 
4880
              "-v, --version     Print basic informations and exit.\n"
 
4881
              "\n"
 
4882
              "Directory:\n"
 
4883
              "----------\n"
 
4884
              "%s/path_to/files  Use an absolute path to load,\n"
 
4885
              "path_to/files     Use a relative path.\n"
 
4886
              "\n"),xPREFIX);
 
4887
 
 
4888
    #undef xPREFIX
 
4889
 
 
4890
    exit(0);
 
4891
}
 
4892
 
 
4893
 
 
4894
 
 
4895
/*
 
4896
 * Exit the program
 
4897
 */
 
4898
void EasyTAG_Exit (void)
 
4899
{
 
4900
    ET_Core_Destroy();
 
4901
    Charset_Insert_Locales_Destroy();
 
4902
    Log_Print(LOG_OK,_("EasyTAG: Normal exit."));
 
4903
    gtk_main_quit();
 
4904
#ifdef WIN32
 
4905
    weasytag_cleanup();
 
4906
#endif
 
4907
    exit(0);
 
4908
}
 
4909
 
 
4910
void Quit_MainWindow_Confirmed (void)
 
4911
{
 
4912
    // Save the configuration when exiting...
 
4913
    Save_Changes_Of_UI();
 
4914
    
 
4915
    // Quit EasyTAG
 
4916
    EasyTAG_Exit();
 
4917
}
 
4918
 
 
4919
void Quit_MainWindow_Save_And_Quit (void)
 
4920
{
 
4921
    /* Save modified tags */
 
4922
    if (Save_All_Files_With_Answer(FALSE) == -1)
 
4923
        return;
 
4924
    Quit_MainWindow_Confirmed();
 
4925
}
 
4926
 
 
4927
void Quit_MainWindow (void)
 
4928
{
 
4929
    GtkWidget *msgbox;
 
4930
    gint response;
 
4931
 
 
4932
    /* If you change the displayed data and quit immediately */
 
4933
    if (ETCore->ETFileList)
 
4934
        ET_Save_File_Data_From_UI(ETCore->ETFileDisplayed); // To detect change before exiting
 
4935
 
 
4936
    /* Save combobox history list before exit */
 
4937
    Save_Path_Entry_List(BrowserEntryModel, MISC_COMBO_TEXT);
 
4938
 
 
4939
    /* Exit ? */
 
4940
    if (ET_Check_If_All_Files_Are_Saved() != TRUE)
 
4941
    {
 
4942
        /* Some files haven't been saved */
 
4943
        msgbox = msg_box_new(_("Confirm..."),
 
4944
                             GTK_WINDOW(MainWindow),
 
4945
                             NULL,
 
4946
                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
4947
                             _("Some files have been modified but not saved...\nDo you want to save them before exiting the program?"),
 
4948
                             GTK_STOCK_DIALOG_QUESTION,
 
4949
                             GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,
 
4950
                             GTK_STOCK_NO,    GTK_RESPONSE_NO,
 
4951
                             GTK_STOCK_YES,   GTK_RESPONSE_YES,
 
4952
                             NULL);
 
4953
        response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
4954
        gtk_widget_destroy(msgbox);
 
4955
        switch (response)
 
4956
        {
 
4957
            case GTK_RESPONSE_YES:
 
4958
                Quit_MainWindow_Save_And_Quit();
 
4959
                break;
 
4960
            case GTK_RESPONSE_NO:
 
4961
                Quit_MainWindow_Confirmed();
 
4962
                break;
 
4963
            case GTK_RESPONSE_CANCEL:
 
4964
            case GTK_RESPONSE_NONE:
 
4965
                return;
 
4966
        }
 
4967
 
 
4968
    } else if (CONFIRM_BEFORE_EXIT)
 
4969
    {
 
4970
         msgbox = msg_box_new(_("Confirm..."),
 
4971
                             GTK_WINDOW(MainWindow),
 
4972
                             NULL,
 
4973
                             GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
 
4974
                             _(" Do you really want to exit the program? "),
 
4975
                             GTK_STOCK_DIALOG_QUESTION,
 
4976
                             GTK_STOCK_NO,    GTK_RESPONSE_NO,
 
4977
                             GTK_STOCK_YES,   GTK_RESPONSE_YES,
 
4978
                             NULL);
 
4979
        response = gtk_dialog_run(GTK_DIALOG(msgbox));
 
4980
        gtk_widget_destroy(msgbox);
 
4981
        switch (response)
 
4982
        {
 
4983
            case GTK_RESPONSE_YES:
 
4984
                Quit_MainWindow_Confirmed();
 
4985
                break;
 
4986
            case GTK_RESPONSE_NO:
 
4987
            case GTK_RESPONSE_NONE:
 
4988
                return;
 
4989
                break;
 
4990
        }
 
4991
    }else
 
4992
    {
 
4993
        Quit_MainWindow_Confirmed();
 
4994
    }
 
4995
 
 
4996
}
 
4997
 
 
4998
/*
 
4999
 * For the configuration file...
 
5000
 */
 
5001
void MainWindow_Apply_Changes (void)
 
5002
{
 
5003
    if ( MainWindow && MainWindow->window && gdk_window_is_visible(MainWindow->window)
 
5004
    &&   gdk_window_get_state(MainWindow->window)!=GDK_WINDOW_STATE_MAXIMIZED )
 
5005
    {
 
5006
        gint x, y, width, height;
 
5007
 
 
5008
        // Position and Origin of the window
 
5009
        gdk_window_get_root_origin(MainWindow->window,&x,&y);
 
5010
        MAIN_WINDOW_X = x;
 
5011
        MAIN_WINDOW_Y = y;
 
5012
        gdk_window_get_size(MainWindow->window,&width,&height);
 
5013
        MAIN_WINDOW_WIDTH  = width;
 
5014
        MAIN_WINDOW_HEIGHT = height;
 
5015
 
 
5016
        // Handle panes position
 
5017
        PANE_HANDLE_POSITION1 = GTK_PANED(MainWindowHPaned)->child1_size;
 
5018
        PANE_HANDLE_POSITION2 = GTK_PANED(BrowserHPaned)->child1_size;
 
5019
        PANE_HANDLE_POSITION3 = GTK_PANED(ArtistAlbumVPaned)->child1_size;
 
5020
        PANE_HANDLE_POSITION4 = GTK_PANED(MainWindowVPaned)->child1_size;
 
5021
    }
 
5022
 
 
5023
}