~ubuntu-branches/ubuntu/jaunty/xarchiver/jaunty

« back to all changes in this revision

Viewing changes to src/callbacks.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-11-07 14:54:00 UTC
  • mfrom: (1.1.7 upstream) (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20081107145400-z0j3jmgads8coae2
Tags: 0.5.1-1
MergingĀ upstreamĀ versionĀ 0.5.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  Copyright (C) 2006 Giuseppe Torelli - <colossus73@gmail.com>
3
 
 *  Copyright (C) 2006 Benedikt Meurer - <benny@xfce.org>
4
 
 *
5
 
 *  This program is free software; you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation; either version 2 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program; if not, write to the Free Software
17
 
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
18
 
 */
19
 
 
20
 
#ifdef HAVE_CONFIG_H
21
 
#include "config.h"
22
 
#endif
23
 
 
24
 
#include "callbacks.h"
25
 
#include "string_utils.h"
26
 
#include "interface.h"
27
 
#include "support.h"
28
 
#include "main.h"
29
 
#include "socket.h"
30
 
#include "new_dialog.h"
31
 
 
32
 
extern GList *ArchiveType;
33
 
extern GList *ArchiveSuffix;
34
 
extern gboolean cli;
35
 
extern gboolean stop_flag;
36
 
extern gboolean unrar;
37
 
 
38
 
gchar *current_open_directory = NULL;
39
 
GtkFileFilter *open_file_filter = NULL;
40
 
GList *Suffix , *Name;
41
 
 
42
 
void xa_watch_child ( GPid pid, gint status, gpointer data)
43
 
{
44
 
        XArchive *archive = data;
45
 
        gboolean new    = FALSE;
46
 
        gboolean open   = FALSE;
47
 
        gboolean add    = FALSE;
48
 
        gboolean extract= FALSE;
49
 
        gboolean exe    = FALSE;
50
 
        gboolean select = FALSE;
51
 
        gboolean check  = FALSE;
52
 
        gboolean info   = FALSE;
53
 
        gboolean waiting = TRUE;
54
 
        int ps;
55
 
 
56
 
        if (archive->has_comment)
57
 
                gtk_widget_set_sensitive (comment_menu,TRUE);
58
 
        else
59
 
                gtk_widget_set_sensitive (comment_menu,FALSE);
60
 
 
61
 
        if (archive->has_comment && archive->status == XA_ARCHIVESTATUS_OPEN)
62
 
                xa_show_archive_comment ( NULL, NULL);
63
 
 
64
 
        gtk_widget_set_sensitive (close1,TRUE);
65
 
        if ( archive->type == XARCHIVETYPE_BZIP2 || archive->type == XARCHIVETYPE_GZIP )
66
 
        {
67
 
                new = open = TRUE;
68
 
                info = exe = FALSE;
69
 
        }
70
 
        else if (archive->type == XARCHIVETYPE_RPM || archive->type == XARCHIVETYPE_DEB)
71
 
        {
72
 
                new = open = extract = select = info = TRUE;
73
 
                exe = FALSE;
74
 
        }
75
 
        else if (archive->type == XARCHIVETYPE_TAR_BZ2 || archive->type == XARCHIVETYPE_TAR_GZ || archive->type == XARCHIVETYPE_TAR )
76
 
        {
77
 
                new = open = add = extract = select = info = TRUE;
78
 
                check = exe = FALSE;
79
 
        }
80
 
        else if (archive->type == XARCHIVETYPE_LHA)
81
 
        {
82
 
                new = open = add = extract = select = info = TRUE;
83
 
                check = TRUE;
84
 
                exe = FALSE;
85
 
        }
86
 
        else if (archive->type == XARCHIVETYPE_RAR && unrar)
87
 
        {
88
 
                check = TRUE;
89
 
                add = exe = FALSE;
90
 
                new = open = extract = select = info = TRUE;
91
 
        }
92
 
        else
93
 
        {
94
 
                check = TRUE;
95
 
                new = open = add = extract = exe = select = info = TRUE;
96
 
        }
97
 
        if ( WIFSIGNALED (status) )
98
 
        {
99
 
                Update_StatusBar ( _("Operation canceled."));
100
 
                if (archive->status == XA_ARCHIVESTATUS_EXTRACT)
101
 
                {
102
 
                        gchar *msg = g_strdup_printf(_("Please check \"%s\" since some files could have been already extracted."),archive->extraction_path);
103
 
 
104
 
            response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO, GTK_BUTTONS_OK,"",msg );
105
 
            g_free (msg);
106
 
                }
107
 
                else if (archive->status == XA_ARCHIVESTATUS_OPEN)
108
 
                        gtk_widget_set_sensitive ( check_menu , FALSE );
109
 
 
110
 
                xa_hide_progress_bar_stop_button(archive);
111
 
                xa_set_button_state (new,open,add,extract,exe,select);
112
 
                gtk_widget_set_sensitive ( check_menu , check);
113
 
                gtk_widget_set_sensitive ( properties , info);
114
 
                return;
115
 
        }
116
 
 
117
 
        if ( WIFEXITED (status) )
118
 
        {
119
 
                if ( WEXITSTATUS (status) )
120
 
                {
121
 
                        gtk_widget_set_sensitive ( check_menu , check);
122
 
                        gtk_widget_set_sensitive ( properties , info);
123
 
                        xa_hide_progress_bar_stop_button(archive);
124
 
                        xa_set_button_state (new,open,add,extract,exe,select);
125
 
                        Update_StatusBar ( _("Operation failed."));
126
 
                        response = ShowGtkMessageDialog (GTK_WINDOW     (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,_("An error occurred while accessing the archive."),_("Do you want to view the command line output?") );
127
 
                        if (response == GTK_RESPONSE_YES)
128
 
                                xa_show_cmd_line_output (NULL);
129
 
                        /* In case the user supplies a wrong password we reset it so he can try again */
130
 
                        if ( (archive->status == XA_ARCHIVESTATUS_TEST || archive->status == XA_ARCHIVESTATUS_SFX) && archive->passwd != NULL)
131
 
                        {
132
 
                                g_free (archive->passwd);
133
 
                                archive->passwd = NULL;
134
 
                        }
135
 
                        return;
136
 
                }
137
 
        }
138
 
 
139
 
        if (archive->status == XA_ARCHIVESTATUS_SFX && archive->type == XARCHIVETYPE_RAR)
140
 
        {
141
 
                xa_hide_progress_bar_stop_button(archive);
142
 
                gtk_widget_set_sensitive ( exe_menu, FALSE);
143
 
                gtk_widget_set_sensitive ( Exe_button, FALSE);
144
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,     GTK_BUTTONS_OK,_("The sfx archive was saved as:"),archive->tmp );
145
 
        }
146
 
        if (archive->status == XA_ARCHIVESTATUS_TEST)
147
 
                xa_show_cmd_line_output (NULL);
148
 
        if ( ! cli )
149
 
        {
150
 
                /* This to automatically reload the content of the archive after adding or deleting */
151
 
                if (archive->status == XA_ARCHIVESTATUS_DELETE || archive->status == XA_ARCHIVESTATUS_ADD)
152
 
                {
153
 
                    if (archive->type == XARCHIVETYPE_BZIP2 || archive->type == XARCHIVETYPE_GZIP)
154
 
                                Update_StatusBar ( _("Operation completed."));
155
 
                        else
156
 
                        {
157
 
                                Update_StatusBar ( _("Please wait while the content of the archive is being updated..."));
158
 
                                xa_remove_columns();
159
 
                        }
160
 
                        switch ( archive->type )
161
 
                        {
162
 
                                case XARCHIVETYPE_RAR:
163
 
                            OpenRar ( archive );
164
 
                                break;
165
 
 
166
 
                                case XARCHIVETYPE_TAR:
167
 
                                OpenTar ( archive );
168
 
                                break;
169
 
 
170
 
                                case XARCHIVETYPE_TAR_BZ2:
171
 
                                OpenBzip2 ( archive );
172
 
                                break;
173
 
 
174
 
                                case XARCHIVETYPE_TAR_GZ:
175
 
                                OpenGzip ( archive );
176
 
                                break;
177
 
 
178
 
                                case XARCHIVETYPE_ZIP:
179
 
                                OpenZip ( archive );
180
 
                                break;
181
 
 
182
 
                                case XARCHIVETYPE_7ZIP:
183
 
                                Open7Zip ( archive );
184
 
                                break;
185
 
 
186
 
                                case XARCHIVETYPE_ARJ:
187
 
                                OpenArj ( archive );
188
 
                                break;
189
 
 
190
 
                                case XARCHIVETYPE_LHA:
191
 
                                OpenLha ( archive );
192
 
                                break;
193
 
 
194
 
                                default:
195
 
                                break;
196
 
                        }
197
 
                        archive->status = XA_ARCHIVESTATUS_IDLE;
198
 
                        while (waiting)
199
 
                        {
200
 
                                ps = waitpid ( archive->child_pid, &status, WNOHANG);
201
 
                                if (ps < 0)
202
 
                                        waiting = FALSE;
203
 
                                else
204
 
                                        gtk_main_iteration_do (FALSE);
205
 
                        }
206
 
                }
207
 
        }
208
 
 
209
 
        if (! cli && archive != NULL)
210
 
        {
211
 
                if ( archive->has_passwd == FALSE && archive->passwd == NULL)
212
 
                {
213
 
                        gtk_widget_hide ( viewport3 );
214
 
                        gtk_widget_set_sensitive ( password_entry , FALSE);
215
 
                }
216
 
                else
217
 
                {
218
 
                        gtk_widget_show ( pad_image );
219
 
                        gtk_widget_show ( viewport3 );
220
 
                        gtk_widget_set_sensitive ( password_entry , TRUE);
221
 
                }
222
 
        }
223
 
        gtk_widget_set_sensitive ( check_menu , check);
224
 
        gtk_widget_set_sensitive ( properties , info);
225
 
        xa_set_button_state (new,open,add,extract,exe,select);
226
 
        xa_hide_progress_bar_stop_button(archive);
227
 
 
228
 
        gtk_widget_grab_focus (GTK_WIDGET(archive->treeview));
229
 
        Update_StatusBar ( _("Operation completed."));
230
 
}
231
 
 
232
 
void xa_new_archive (GtkMenuItem *menuitem, gpointer user_data)
233
 
{
234
 
        gint current_page;
235
 
 
236
 
        current_page = xa_get_new_archive_idx();
237
 
        if (current_page == -1)
238
 
                return;
239
 
 
240
 
        archive[current_page] = xa_new_archive_dialog ( NULL );
241
 
 
242
 
        if (archive[current_page]  == NULL)
243
 
                return;
244
 
 
245
 
        xa_add_page (archive[current_page]);
246
 
 
247
 
        xa_set_button_state (1,1,1,0,0,0 );
248
 
    EmptyTextBuffer();
249
 
    archive[current_page]->has_passwd = FALSE;
250
 
    gtk_widget_set_sensitive ( iso_info , FALSE );
251
 
    gtk_widget_set_sensitive ( view_shell_output1 , TRUE );
252
 
    gtk_widget_set_sensitive ( check_menu , FALSE);
253
 
    gtk_widget_set_sensitive ( properties , FALSE );
254
 
    /* Let's off the delete and view buttons and the menu entries to avoid strange behaviours */
255
 
    OffDeleteandViewButtons ();
256
 
 
257
 
        Update_StatusBar ( _("Choose Add to begin creating the archive."));
258
 
    gtk_tooltips_disable ( pad_tooltip );
259
 
    gtk_widget_hide ( pad_image );
260
 
 
261
 
    archive[current_page]->passwd = NULL;
262
 
    archive[current_page]->dummy_size = 0;
263
 
    archive[current_page]->nr_of_files = 0;
264
 
    archive[current_page]->nr_of_dirs = 0;
265
 
        xa_set_window_title (MainWindow , archive[current_page]->path );
266
 
        gtk_widget_set_sensitive ( close1 , TRUE );
267
 
}
268
 
 
269
 
int ShowGtkMessageDialog ( GtkWindow *window, int mode,int type,int button, const gchar *message1,const gchar *message2)
270
 
{
271
 
        dialog = gtk_message_dialog_new (window, mode, type, button,message1);
272
 
        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
273
 
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), message2);
274
 
        response = gtk_dialog_run (GTK_DIALOG (dialog) );
275
 
        gtk_widget_destroy (GTK_WIDGET (dialog) );
276
 
        return response;
277
 
}
278
 
 
279
 
void xa_open_archive (GtkMenuItem *menuitem, gpointer data)
280
 
{
281
 
        gchar *path = NULL;
282
 
        gint current_page;
283
 
        gint x;
284
 
        path = (gchar *)data;
285
 
        if ( path == NULL)
286
 
    {
287
 
                path = xa_open_file_dialog ();
288
 
                if (path == NULL)
289
 
                        return;
290
 
        }
291
 
 
292
 
        /* Let's check if the archive is already opened */
293
 
        for (x = 0; x < gtk_notebook_get_n_pages ( notebook) ; x++)
294
 
        {
295
 
                current_page = xa_find_archive_index ( x );
296
 
                if (current_page == -1)
297
 
                        break;
298
 
                if (strcmp (path,archive[current_page]->path) == 0)
299
 
                        return;
300
 
        }
301
 
 
302
 
        current_page = xa_get_new_archive_idx();
303
 
        if (current_page == -1)
304
 
                return;
305
 
 
306
 
        archive[current_page] = xa_init_archive_structure();
307
 
        if (archive[current_page] == NULL)
308
 
        {
309
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't allocate memory for the archive structure:"),"Operation aborted!");
310
 
                g_free (path);
311
 
                return;
312
 
        }
313
 
 
314
 
        archive[current_page]->path = g_strdup (path);
315
 
        archive[current_page]->escaped_path = EscapeBadChars ( archive[current_page]->path , "$\'`\"\\!?* ()&|@#:;" );
316
 
 
317
 
        xa_add_page (archive[current_page]);
318
 
 
319
 
        OffDeleteandViewButtons();
320
 
        gtk_widget_set_sensitive ( iso_info , FALSE );
321
 
        gtk_widget_set_sensitive ( view_shell_output1 , TRUE );
322
 
 
323
 
        archive[current_page]->type = xa_detect_archive_type ( archive[current_page] , NULL );
324
 
        if ( archive[current_page]->type == -2 )
325
 
        {
326
 
                xa_close_archive ( NULL, NULL);
327
 
                xa_set_button_state (1,1,0,0,0,0);
328
 
                return;
329
 
        }
330
 
        if ( archive[current_page]->type == -1 )
331
 
        {
332
 
                xa_close_archive ( NULL, NULL);
333
 
                gchar *utf8_path,*msg;
334
 
                utf8_path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
335
 
                msg = g_strdup_printf (_("Can't open file \"%s\":"), utf8_path);
336
 
                xa_set_window_title (MainWindow , NULL);
337
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,msg,
338
 
                _("Archive format is not recognized!"));
339
 
                xa_set_button_state ( 1,1,0,0,0,0);
340
 
                gtk_widget_set_sensitive ( check_menu , FALSE );
341
 
                gtk_widget_set_sensitive ( properties , FALSE );
342
 
                g_free (utf8_path);
343
 
                g_free (msg);
344
 
                g_free (path);
345
 
                return;
346
 
        }
347
 
        g_free (path);
348
 
        EmptyTextBuffer();
349
 
 
350
 
        //Does the user open an archive from the command line whose archiver is not installed ?
351
 
        gchar *ext = NULL;
352
 
        if ( archive[current_page]->type == XARCHIVETYPE_RAR )
353
 
                ext = ".rar";
354
 
        else if ( archive[current_page]->type == XARCHIVETYPE_7ZIP )
355
 
                ext = ".7z";
356
 
        else if ( archive[current_page]->type == XARCHIVETYPE_ARJ )
357
 
                ext = ".arj";
358
 
        else if ( archive[current_page]->type == XARCHIVETYPE_LHA )
359
 
                ext = ".lzh";
360
 
        if ( ext != NULL )
361
 
                if ( ! g_list_find ( ArchiveType , ext ) )
362
 
                {
363
 
                        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,_("Sorry, this archive format is not supported:"),_("the proper archiver is not installed!") );
364
 
                        return;
365
 
                }
366
 
 
367
 
        gtk_widget_set_sensitive (Stop_button,TRUE);
368
 
        gtk_widget_show ( viewport2 );
369
 
 
370
 
        if ( archive[current_page]->type == XARCHIVETYPE_ISO )
371
 
                Update_StatusBar ( _("Please wait while the content of the ISO image is being read..."));
372
 
        else
373
 
                Update_StatusBar ( _("Please wait while the content of the archive is being read..."));
374
 
 
375
 
        archive[current_page]->status = XA_ARCHIVESTATUS_OPEN;
376
 
        gtk_widget_set_sensitive ( close1 ,     FALSE);
377
 
        gtk_widget_set_sensitive ( check_menu , FALSE);
378
 
        gtk_widget_set_sensitive ( properties , FALSE);
379
 
        xa_set_button_state ( 0,0,0,0,0,0);
380
 
        switch ( archive[current_page]->type )
381
 
        {
382
 
                case XARCHIVETYPE_ARJ:
383
 
                OpenArj (archive[current_page]);
384
 
                break;
385
 
 
386
 
                case XARCHIVETYPE_DEB:
387
 
                OpenDeb (archive[current_page]);
388
 
                break;
389
 
 
390
 
                case XARCHIVETYPE_BZIP2:
391
 
                OpenBzip2 (archive[current_page]);
392
 
                break;
393
 
 
394
 
                case XARCHIVETYPE_GZIP:
395
 
                OpenGzip ( archive[current_page] );
396
 
                break;
397
 
 
398
 
                case XARCHIVETYPE_ISO:
399
 
                OpenISO (archive[current_page]);
400
 
                break;
401
 
 
402
 
                case XARCHIVETYPE_RAR:
403
 
                OpenRar (archive[current_page]);
404
 
                break;
405
 
 
406
 
                case XARCHIVETYPE_RPM:
407
 
                OpenRPM (archive[current_page]);
408
 
                break;
409
 
 
410
 
                case XARCHIVETYPE_TAR:
411
 
                OpenTar (archive[current_page]);
412
 
                break;
413
 
 
414
 
                case XARCHIVETYPE_ZIP:
415
 
                OpenZip (archive[current_page]);
416
 
                break;
417
 
 
418
 
                case XARCHIVETYPE_7ZIP:
419
 
                Open7Zip (archive[current_page]);
420
 
                break;
421
 
 
422
 
                case XARCHIVETYPE_LHA:
423
 
                OpenLha (archive[current_page]);
424
 
                break;
425
 
 
426
 
                default:
427
 
                break;
428
 
        }
429
 
        archive[current_page]->passwd = NULL;
430
 
}
431
 
 
432
 
void xa_test_archive (GtkMenuItem *menuitem, gpointer user_data)
433
 
{
434
 
        gchar *command;
435
 
        gchar *rar;
436
 
        gint current_page;
437
 
        gint id;
438
 
 
439
 
        current_page = gtk_notebook_get_current_page (notebook);
440
 
        id = xa_find_archive_index ( current_page );
441
 
        if (unrar)
442
 
                rar = "unrar";
443
 
        else
444
 
                rar = "rar";
445
 
        if ( archive[id]->has_passwd )
446
 
        {
447
 
                if ( archive[id]->passwd == NULL)
448
 
                {
449
 
                        archive[id]->passwd = password_dialog ();
450
 
                        if ( archive[id]->passwd == NULL)
451
 
                                return;
452
 
                }
453
 
        }
454
 
    Update_StatusBar ( _("Testing archive integrity, please wait..."));
455
 
    gtk_widget_set_sensitive (Stop_button,TRUE);
456
 
    gtk_widget_set_sensitive ( check_menu , FALSE );
457
 
    xa_set_button_state (0,0,0,0,0,0);
458
 
    switch ( archive[id]->type )
459
 
        {
460
 
                case XARCHIVETYPE_RAR:
461
 
                if (archive[id]->passwd != NULL)
462
 
                        command = g_strconcat (rar," t -idp -p" , archive[id]->passwd ," " , archive[id]->escaped_path, NULL);
463
 
                else
464
 
                        command = g_strconcat (rar," t -idp " , archive[id]->escaped_path, NULL);
465
 
        break;
466
 
 
467
 
        case XARCHIVETYPE_ZIP:
468
 
        if (archive[id]->passwd != NULL)
469
 
                        command = g_strconcat ("unzip -P ", archive[id]->passwd, " -t " , archive[id]->escaped_path, NULL);
470
 
        else
471
 
                        command = g_strconcat ("unzip -t " , archive[id]->escaped_path, NULL);
472
 
        break;
473
 
 
474
 
        case XARCHIVETYPE_7ZIP:
475
 
        if (archive[id]->passwd != NULL)
476
 
                        command = g_strconcat ( "7za t -p" , archive[id]->passwd , " " , archive[id]->escaped_path, NULL);
477
 
                else
478
 
                        command = g_strconcat ("7za t " , archive[id]->escaped_path, NULL);
479
 
                break;
480
 
 
481
 
                case XARCHIVETYPE_ARJ:
482
 
        if (archive[id]->passwd != NULL)
483
 
                        command = g_strconcat ("arj t -g" , archive[id]->passwd , " -i " , archive[id]->escaped_path, NULL);
484
 
                else
485
 
                        command = g_strconcat ("arj t -i " , archive[id]->escaped_path, NULL);
486
 
                break;
487
 
 
488
 
                case XARCHIVETYPE_LHA:
489
 
                        command = g_strconcat ("lha t " , archive[id]->escaped_path, NULL);
490
 
                break;
491
 
 
492
 
                default:
493
 
                command = NULL;
494
 
        }
495
 
        archive[id]->status = XA_ARCHIVESTATUS_TEST;
496
 
    xa_run_command ( command , 1);
497
 
    g_free (command);
498
 
}
499
 
 
500
 
void xa_close_archive (GtkMenuItem *menuitem, gpointer user_data)
501
 
{
502
 
        gint current_page;
503
 
        gint idx;
504
 
        GtkWidget *scrollwindow = user_data;
505
 
 
506
 
        current_page = gtk_notebook_page_num(notebook, scrollwindow);
507
 
        idx = xa_find_archive_index (current_page);
508
 
        gtk_notebook_remove_page ( notebook , current_page);
509
 
 
510
 
        current_page = gtk_notebook_get_n_pages(notebook);
511
 
        if ( current_page == 0)
512
 
        {
513
 
                gtk_widget_set_sensitive (check_menu,FALSE);
514
 
                gtk_widget_set_sensitive (properties,FALSE);
515
 
                gtk_widget_set_sensitive (close1,FALSE);
516
 
                OffDeleteandViewButtons();
517
 
                xa_set_button_state (1,1,0,0,0,0);
518
 
                xa_set_window_title (MainWindow,NULL);
519
 
        }
520
 
        else if ( current_page == 1)
521
 
                gtk_notebook_set_show_tabs (notebook,FALSE);
522
 
        else
523
 
                gtk_notebook_set_show_tabs (notebook,TRUE);
524
 
 
525
 
        EmptyTextBuffer();
526
 
        xa_clean_archive_structure (archive[idx]);
527
 
 
528
 
        gtk_widget_hide ( viewport3 );
529
 
        Update_StatusBar (_("Ready."));
530
 
}
531
 
 
532
 
void xa_quit_application (GtkMenuItem *menuitem, gpointer user_data)
533
 
{
534
 
        gint i;
535
 
        gint idx;
536
 
 
537
 
        if ( GTK_WIDGET_VISIBLE (viewport2 ) )
538
 
        {
539
 
                Update_StatusBar ( _("Please hit the Stop button first!"));
540
 
                return;
541
 
        }
542
 
        g_list_free ( Suffix );
543
 
        g_list_free ( Name );
544
 
 
545
 
        for (i = 0; i < gtk_notebook_get_n_pages(notebook) ; i++)
546
 
        {
547
 
                idx = xa_find_archive_index ( i );
548
 
                if (archive[idx] != NULL)
549
 
                        xa_clean_archive_structure (archive[idx]);
550
 
        }
551
 
 
552
 
        if (current_open_directory != NULL)
553
 
                g_free (current_open_directory);
554
 
 
555
 
#ifdef HAVE_SOCKET
556
 
        socket_finalize();
557
 
#endif
558
 
        gtk_main_quit();
559
 
}
560
 
 
561
 
void xa_delete_archive (GtkMenuItem *menuitem, gpointer user_data)
562
 
{
563
 
        gchar *command = NULL;
564
 
        gchar *tar;
565
 
        gint x;
566
 
        GString *names;
567
 
        gint current_page;
568
 
        gint id;
569
 
 
570
 
        current_page = gtk_notebook_get_current_page ( notebook);
571
 
        id = xa_find_archive_index ( current_page);
572
 
 
573
 
        GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (archive[id]->treeview) );
574
 
        names = g_string_new ( " " );
575
 
        gtk_tree_selection_selected_foreach (selection, (GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );
576
 
 
577
 
        x = gtk_tree_selection_count_selected_rows (selection);
578
 
        gchar *msg = g_strdup_printf (_("You are about to delete %d file(s) from the archive."),x);
579
 
        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,msg,_( "Are you sure you want to do this?") );
580
 
        g_free (msg);
581
 
 
582
 
        if ( response == GTK_RESPONSE_NO)
583
 
                return;
584
 
 
585
 
        Update_StatusBar ( _("Deleting files from the archive, please wait..."));
586
 
        archive[id]->status = XA_ARCHIVESTATUS_DELETE;
587
 
 
588
 
        tar = g_find_program_in_path ("gtar");
589
 
        if (tar == NULL)
590
 
                tar = g_strdup ("tar");
591
 
 
592
 
        switch (archive[id]->type)
593
 
        {
594
 
                case XARCHIVETYPE_RAR:
595
 
                command = g_strconcat ( "rar d " , archive[id]->escaped_path , names->str , NULL );
596
 
                break;
597
 
 
598
 
        case XARCHIVETYPE_TAR:
599
 
                command = g_strconcat (tar, " --delete -vf " , archive[id]->escaped_path , names->str , NULL );
600
 
                break;
601
 
 
602
 
        case XARCHIVETYPE_TAR_BZ2:
603
 
        xa_add_delete_tar_bzip2_gzip ( names , archive[id] , 0 , 0 );
604
 
        break;
605
 
 
606
 
        case XARCHIVETYPE_TAR_GZ:
607
 
        xa_add_delete_tar_bzip2_gzip ( names , archive[id] , 1 , 0 );
608
 
                break;
609
 
 
610
 
        case XARCHIVETYPE_ZIP:
611
 
                command = g_strconcat ( "zip -d " , archive[id]->escaped_path , names->str , NULL );
612
 
                break;
613
 
 
614
 
        case XARCHIVETYPE_7ZIP:
615
 
        command = g_strconcat ( "7za d " , archive[id]->escaped_path , names->str , NULL );
616
 
        break;
617
 
 
618
 
        case XARCHIVETYPE_ARJ:
619
 
        command = g_strconcat ( "arj d " , archive[id]->escaped_path , names->str, NULL);
620
 
        break;
621
 
 
622
 
                case XARCHIVETYPE_LHA:
623
 
                command = g_strconcat("lha d ", archive[id]->escaped_path, names->str, NULL);
624
 
                break;
625
 
 
626
 
        default:
627
 
        break;
628
 
        }
629
 
        if (command != NULL)
630
 
    {
631
 
        xa_set_button_state (0,0,0,0,0,0);
632
 
        gtk_widget_set_sensitive (Stop_button,TRUE);
633
 
        xa_run_command ( command , 1);
634
 
        g_free (command);
635
 
    }
636
 
    g_string_free (names , TRUE );
637
 
    g_free (tar);
638
 
}
639
 
 
640
 
void xa_add_files_archive ( GtkMenuItem *menuitem, gpointer data )
641
 
{
642
 
        gchar *command = NULL;
643
 
        gint current_page;
644
 
        gint idx;
645
 
 
646
 
        current_page = gtk_notebook_get_current_page (notebook);
647
 
        idx = xa_find_archive_index ( current_page );
648
 
 
649
 
        add_window = xa_create_add_dialog (archive[idx]);
650
 
        command = xa_parse_add_dialog_options ( archive[idx], add_window );
651
 
        gtk_widget_destroy ( add_window->dialog1 );
652
 
        if (command != NULL)
653
 
        {
654
 
                xa_run_command (command , 1);
655
 
                g_free (command);
656
 
        }
657
 
        g_free ( add_window );
658
 
        add_window = NULL;
659
 
}
660
 
 
661
 
void xa_extract_archive ( GtkMenuItem *menuitem , gpointer user_data )
662
 
{
663
 
        gchar *command = NULL;
664
 
        gint current_page;
665
 
        gint idx;
666
 
 
667
 
        current_page = gtk_notebook_get_current_page (notebook);
668
 
        idx = xa_find_archive_index ( current_page );
669
 
 
670
 
        GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (archive[idx]->treeview) );
671
 
        gint selected = gtk_tree_selection_count_selected_rows ( selection );
672
 
    extract_window = xa_create_extract_dialog (selected , archive[idx]);
673
 
        if (archive[idx]->extraction_path != NULL)
674
 
                gtk_entry_set_text (GTK_ENTRY(extract_window->destination_path_entry),archive[idx]->extraction_path);
675
 
    command = xa_parse_extract_dialog_options ( archive[idx] , extract_window, selection );
676
 
        if (extract_window->dialog1 != NULL)
677
 
        {
678
 
                gtk_widget_destroy ( extract_window->dialog1 );
679
 
                extract_window->dialog1 = NULL;
680
 
        }
681
 
 
682
 
        if (command != NULL)
683
 
        {
684
 
                gtk_widget_set_sensitive ( check_menu , FALSE);
685
 
                gtk_widget_set_sensitive ( close1 ,     FALSE);
686
 
                gtk_widget_set_sensitive ( properties , FALSE);
687
 
                xa_set_button_state (0,0,0,0,0,0);
688
 
                xa_run_command (command , 1);
689
 
                g_free (command);
690
 
        }
691
 
        g_free (extract_window);
692
 
        extract_window = NULL;
693
 
}
694
 
 
695
 
void xa_convert_sfx ( GtkMenuItem *menuitem , gpointer user_data )
696
 
{
697
 
        gchar *command = NULL;
698
 
        gboolean result;
699
 
        unsigned short int l = 0;
700
 
        gint current_page;
701
 
        gint idx;
702
 
 
703
 
        current_page = gtk_notebook_get_current_page (notebook);
704
 
        idx = xa_find_archive_index ( current_page );
705
 
 
706
 
        Update_StatusBar ( _("Converting archive to self-extracting, please wait..."));
707
 
    gtk_widget_set_sensitive (Stop_button,TRUE);
708
 
    archive[idx]->status = XA_ARCHIVESTATUS_SFX;
709
 
    switch ( archive[idx]->type )
710
 
        {
711
 
                case XARCHIVETYPE_RAR:
712
 
                {
713
 
                        command = g_strconcat ("rar s -o+ " , archive[idx]->escaped_path , NULL);
714
 
                        if (strstr(archive[idx]->escaped_path,".rar") )
715
 
                        {
716
 
                                archive[idx]->tmp = g_strdup (archive[idx]->escaped_path);
717
 
                                archive[idx]->tmp[strlen(archive[idx]->tmp) - 3] = 's';
718
 
                                archive[idx]->tmp[strlen(archive[idx]->tmp) - 2] = 'f';
719
 
                                archive[idx]->tmp[strlen(archive[idx]->tmp) - 1] = 'x';
720
 
                        }
721
 
                        else
722
 
                        {
723
 
                                archive[idx]->tmp = (gchar *) g_malloc ( strlen(archive[idx]->escaped_path) + 4 );
724
 
                                l = strlen (archive[idx]->escaped_path);
725
 
                                strncpy ( archive[idx]->tmp, archive[idx]->escaped_path , l);
726
 
                                archive[idx]->tmp[l]    = '.';
727
 
                                archive[idx]->tmp[l + 1] = 's';
728
 
                                archive[idx]->tmp[l + 2] = 'f';
729
 
                                archive[idx]->tmp[l + 3] = 'x';
730
 
                                archive[idx]->tmp[l + 4] = 0;
731
 
                        }
732
 
                }
733
 
                break;
734
 
 
735
 
        case XARCHIVETYPE_ZIP:
736
 
        {
737
 
                gchar *archive_name = NULL;
738
 
                gchar *archive_name_escaped = NULL;
739
 
                        FILE *sfx_archive;
740
 
                        FILE *archive_not_sfx;
741
 
                        gchar *content;
742
 
            gsize length;
743
 
            GError *error = NULL;
744
 
                        gchar *unzipsfx_path = NULL;
745
 
                        gchar buffer[1024];
746
 
 
747
 
                        archive_name = xa_open_sfx_file_selector ();
748
 
 
749
 
                        if (archive_name == NULL)
750
 
                        {
751
 
                                gtk_widget_set_sensitive (Stop_button,FALSE);
752
 
                                Update_StatusBar ( _("Operation canceled."));
753
 
                                return;
754
 
                        }
755
 
                        archive_name_escaped = EscapeBadChars ( archive_name ,"$\'`\"\\!?* ()[]&|@#:;" );
756
 
                        unzipsfx_path = g_find_program_in_path ( "unzipsfx" );
757
 
                        if ( unzipsfx_path != NULL )
758
 
                        {
759
 
                                /* Load the unzipsfx executable in memory, about 50 KB */
760
 
                                result = g_file_get_contents (unzipsfx_path,&content,&length,&error);
761
 
                                if ( ! result)
762
 
                                {
763
 
                                        Update_StatusBar (_("Operation failed."));
764
 
                                        gtk_widget_set_sensitive (Stop_button,FALSE);
765
 
                                        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't convert the archive to self-extracting:"),error->message);
766
 
                                        g_error_free (error);
767
 
                                        g_free (unzipsfx_path);
768
 
                                        return;
769
 
                                }
770
 
                                g_free (unzipsfx_path);
771
 
 
772
 
                                /* Write unzipsfx to a new file */
773
 
                                sfx_archive = g_fopen ( archive_name ,"w" );
774
 
                                if (sfx_archive == NULL)
775
 
                                {
776
 
                                        Update_StatusBar (_("Operation failed."));
777
 
                                        gtk_widget_set_sensitive (Stop_button,FALSE);
778
 
                                        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't write the unzipsfx module to the archive:"),g_strerror(errno) );
779
 
                                        return;
780
 
                                }
781
 
                                archive_not_sfx = g_fopen ( archive[idx]->path ,"r" );
782
 
                                fwrite (content, 1, length, sfx_archive);
783
 
                                g_free (content);
784
 
 
785
 
                                /* Read archive data and write it after the sfx module in the new file */
786
 
                                while ( ! feof(archive_not_sfx) )
787
 
                                {
788
 
                                        fread (&buffer, 1, 1024, archive_not_sfx);
789
 
                                        fwrite (&buffer, 1, 1024, sfx_archive);
790
 
                                }
791
 
                                fclose (archive_not_sfx);
792
 
                                fclose (sfx_archive);
793
 
 
794
 
                                command = g_strconcat ("chmod 755 ", archive_name_escaped , NULL);
795
 
                                result = xa_run_command (command , 0);
796
 
                                g_free (command);
797
 
 
798
 
                                command = g_strconcat ("zip -A ",archive_name_escaped,NULL);
799
 
                                result = xa_run_command (command , 1);
800
 
                                g_free (command);
801
 
                                command = NULL;
802
 
                        }
803
 
                        g_free (archive_name);
804
 
                        g_free (archive_name_escaped);
805
 
        }
806
 
        break;
807
 
 
808
 
        case XARCHIVETYPE_7ZIP:
809
 
        {
810
 
                gchar *archive_name = NULL;
811
 
                gchar *archive_name_escaped = NULL;
812
 
                        FILE *sfx_archive;
813
 
                        FILE *archive_not_sfx;
814
 
                        gchar *content;
815
 
            gsize length;
816
 
            GError *error = NULL;
817
 
                        gchar *sfx_path = NULL;
818
 
                        gchar buffer[1024];
819
 
                        gboolean response;
820
 
                        GtkWidget *locate_7zcon = NULL;
821
 
                        GtkFileFilter *sfx_filter;
822
 
 
823
 
                archive_name = xa_open_sfx_file_selector ();
824
 
 
825
 
                        if (archive_name == NULL)
826
 
                        {
827
 
                                gtk_widget_set_sensitive (Stop_button,FALSE);
828
 
                                Update_StatusBar ( _("Operation canceled."));
829
 
                                return;
830
 
                        }
831
 
                        archive_name_escaped = EscapeBadChars ( archive_name ,"$\'`\"\\!?* ()[]&|@#:;" );
832
 
 
833
 
                        if (g_file_test ( "/usr/lib/p7zip/7zCon.sfx" , G_FILE_TEST_EXISTS) )
834
 
                                sfx_path = g_strdup("/usr/lib/p7zip/7zCon.sfx");
835
 
                        else if (g_file_test ( "/usr/local/lib/p7zip/7zCon.sfx" , G_FILE_TEST_EXISTS) )
836
 
                                sfx_path = g_strdup ("/usr/local/lib/p7zip/7zCon.sfx");
837
 
                        else if (g_file_test ( "/usr/libexec/p7zip/7zCon.sfx" , G_FILE_TEST_EXISTS) )
838
 
                                sfx_path = g_strdup ("/usr/libexec/p7zip/7zCon.sfx");
839
 
                        else
840
 
                        {
841
 
                                sfx_filter = gtk_file_filter_new ();
842
 
                                gtk_file_filter_set_name (sfx_filter, "" );
843
 
                                gtk_file_filter_add_pattern (sfx_filter, "*.sfx" );
844
 
 
845
 
                                locate_7zcon = gtk_file_chooser_dialog_new ( _("Please select the 7zCon.sfx module"),
846
 
                                                GTK_WINDOW (MainWindow),
847
 
                                                GTK_FILE_CHOOSER_ACTION_OPEN,
848
 
                                                GTK_STOCK_CANCEL,
849
 
                                                GTK_RESPONSE_CANCEL,
850
 
                                                "gtk-open",
851
 
                                                GTK_RESPONSE_ACCEPT,
852
 
                                                NULL);
853
 
 
854
 
                                gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (locate_7zcon), sfx_filter);
855
 
                                gtk_dialog_set_default_response (GTK_DIALOG (locate_7zcon), GTK_RESPONSE_ACCEPT);
856
 
                                response = gtk_dialog_run (GTK_DIALOG(locate_7zcon) );
857
 
                                if (response == GTK_RESPONSE_ACCEPT)
858
 
                                {
859
 
                                        sfx_path = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (locate_7zcon) );
860
 
                                        gtk_widget_destroy ( locate_7zcon );
861
 
                                }
862
 
                                else
863
 
                                {
864
 
                                        gtk_widget_destroy ( locate_7zcon );
865
 
                                        Update_StatusBar (_("Operation canceled."));
866
 
                                        xa_hide_progress_bar_stop_button (archive[idx]);
867
 
                                        return;
868
 
                                }
869
 
                        }
870
 
                        if ( sfx_path != NULL )
871
 
                        {
872
 
                                /* Load the 7zCon.sfx executable in memory ~ 500 KB; is it too much for 128 MB equipped PCs ? */
873
 
                                result = g_file_get_contents (sfx_path,&content,&length,&error);
874
 
                                if ( ! result)
875
 
                                {
876
 
                                        Update_StatusBar (_("Operation failed."));
877
 
                                        xa_hide_progress_bar_stop_button (archive[idx]);
878
 
                                        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't convert the archive to self-extracting:"),error->message);
879
 
                                        g_error_free (error);
880
 
                                        g_free (sfx_path);
881
 
                                        return;
882
 
                                }
883
 
                                g_free (sfx_path);
884
 
 
885
 
                                /* Write 7zCon.sfx to a new file */
886
 
                                sfx_archive = g_fopen ( archive_name ,"w" );
887
 
                                if (sfx_archive == NULL)
888
 
                                {
889
 
                                        Update_StatusBar (_("Operation failed."));
890
 
                                        xa_hide_progress_bar_stop_button (archive[idx]);
891
 
                                        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't write the unzipsfx module to the archive:"),g_strerror(errno) );
892
 
                                        return;
893
 
                                }
894
 
                                archive_not_sfx = g_fopen ( archive[idx]->path ,"r" );
895
 
                                fwrite (content, 1, length, sfx_archive);
896
 
                                g_free (content);
897
 
 
898
 
                                /* Read archive data and write it after the sfx module in the new file */
899
 
                                while ( ! feof(archive_not_sfx) )
900
 
                                {
901
 
                                        fread (&buffer, 1, 1024, archive_not_sfx);
902
 
                                        fwrite (&buffer, 1, 1024, sfx_archive);
903
 
                                }
904
 
                                fclose (archive_not_sfx);
905
 
                                fclose (sfx_archive);
906
 
 
907
 
                                command = g_strconcat ("chmod 755 ", archive_name_escaped , NULL);
908
 
                                result = xa_run_command (command , 1);
909
 
                                g_free (command);
910
 
                                command = NULL;
911
 
                        }
912
 
                        g_free (archive_name);
913
 
                        g_free (archive_name_escaped);
914
 
        }
915
 
                break;
916
 
 
917
 
                case XARCHIVETYPE_ARJ:
918
 
        command = g_strconcat ("arj y -je1 " , archive[idx]->escaped_path, NULL);
919
 
                break;
920
 
 
921
 
                default:
922
 
                command = NULL;
923
 
        }
924
 
        if (command != NULL)
925
 
        {
926
 
                xa_run_command ( command , 1);
927
 
                g_free (command);
928
 
        }
929
 
}
930
 
 
931
 
void xa_about (GtkMenuItem *menuitem, gpointer user_data)
932
 
{
933
 
    static GtkWidget *about = NULL;
934
 
    const char *authors[] = {"\nMain developer: Giuseppe Torelli <colossus73@gmail.com>\nISO support: Salvatore Santagati <salvatore.santagati@gmail.com>\nLHA and DEB support: Åukasz Zemczak <sil2100@vexillium.org>",NULL};
935
 
    const char *documenters[] = {"\nSpecial thanks to Bjoern Martensen for discovering\nmany bugs in the Xarchiver development code.\n\nThanks to:\nBenedikt Meurer\nStephan Arts\nEnrico Trƶger\nUracile for the stunning logo\nThe people of gtk-app-devel-list.", NULL};
936
 
 
937
 
        if (about == NULL)
938
 
        {
939
 
                about = gtk_about_dialog_new ();
940
 
                gtk_about_dialog_set_email_hook (xa_activate_link, NULL, NULL);
941
 
                gtk_about_dialog_set_url_hook (xa_activate_link, NULL, NULL);
942
 
                gtk_window_set_destroy_with_parent (GTK_WINDOW (about) , TRUE);
943
 
                g_object_set (about,
944
 
                                "name",  "Xarchiver",
945
 
                                "version", PACKAGE_VERSION,
946
 
                                "copyright", "Copyright \xC2\xA9 2005-2006 Giuseppe Torelli",
947
 
                                "comments", "A lightweight GTK+2 archive manager",
948
 
                                "authors", authors,
949
 
                                "documenters",documenters,
950
 
                                "translator_credits", _("translator-credits"),
951
 
                                "logo_icon_name", "xarchiver",
952
 
                                "website", "http://xarchiver.xfce.org",
953
 
                                "license",    "Copyright \xC2\xA9 2005-2006 Giuseppe Torelli - Colossus <colossus73@gmail.com>\n\n"
954
 
                                        "This is free software; you can redistribute it and/or\n"
955
 
                                        "modify it under the terms of the GNU Library General Public License as\n"
956
 
                                        "published by the Free Software Foundation; either version 2 of the\n"
957
 
                                        "License, or (at your option) any later version.\n"
958
 
                                        "\n"
959
 
                                        "This software is distributed in the hope that it will be useful,\n"
960
 
                                        "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
961
 
                                        "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n"
962
 
                                        "Library General Public License for more details.\n"
963
 
                                        "\n"
964
 
                                        "You should have received a copy of the GNU Library General Public\n"
965
 
                                        "License along with the Gnome Library; see the file COPYING.LIB.  If not,\n"
966
 
                                        "write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,\n"
967
 
                                        "Boston, MA 02111-1307, USA.\n",
968
 
                      NULL);
969
 
                gtk_window_set_position (GTK_WINDOW (about), GTK_WIN_POS_CENTER);
970
 
        }
971
 
        gtk_dialog_run ( GTK_DIALOG(about) );
972
 
        gtk_widget_hide (about);
973
 
}
974
 
 
975
 
gchar *xa_open_sfx_file_selector ()
976
 
{
977
 
        gchar *sfx_name = NULL;
978
 
        GtkWidget *sfx_file_selector = NULL;
979
 
        gboolean response;
980
 
 
981
 
        sfx_file_selector = gtk_file_chooser_dialog_new ( _("Save the self-extracting archive as"),
982
 
                                                GTK_WINDOW (MainWindow),
983
 
                                                GTK_FILE_CHOOSER_ACTION_SAVE,
984
 
                                                GTK_STOCK_CANCEL,
985
 
                                                GTK_RESPONSE_CANCEL,
986
 
                                                "gtk-save",
987
 
                                                GTK_RESPONSE_ACCEPT,
988
 
                                                NULL);
989
 
 
990
 
        gtk_dialog_set_default_response (GTK_DIALOG (sfx_file_selector), GTK_RESPONSE_ACCEPT);
991
 
        response = gtk_dialog_run ( GTK_DIALOG(sfx_file_selector) );
992
 
 
993
 
        if (response == GTK_RESPONSE_ACCEPT)
994
 
                sfx_name = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (sfx_file_selector) );
995
 
 
996
 
        gtk_widget_destroy (sfx_file_selector);
997
 
        return sfx_name;
998
 
}
999
 
 
1000
 
gchar *xa_open_file_dialog ()
1001
 
{
1002
 
        static GtkWidget *File_Selector = NULL;
1003
 
        GtkFileFilter *filter;
1004
 
        gchar *path = NULL;
1005
 
 
1006
 
        if (File_Selector == NULL)
1007
 
        {
1008
 
                File_Selector = gtk_file_chooser_dialog_new ( _("Open an archive"),
1009
 
                                                GTK_WINDOW (MainWindow),
1010
 
                                                GTK_FILE_CHOOSER_ACTION_OPEN,
1011
 
                                                GTK_STOCK_CANCEL,
1012
 
                                                GTK_RESPONSE_CANCEL,
1013
 
                                                "gtk-open",
1014
 
                                                GTK_RESPONSE_ACCEPT,
1015
 
                                                NULL);
1016
 
 
1017
 
                gtk_dialog_set_default_response (GTK_DIALOG (File_Selector), GTK_RESPONSE_ACCEPT);
1018
 
                gtk_window_set_destroy_with_parent (GTK_WINDOW (File_Selector) , TRUE);
1019
 
 
1020
 
                filter = gtk_file_filter_new ();
1021
 
                gtk_file_filter_set_name ( filter , _("All files") );
1022
 
                gtk_file_filter_add_pattern ( filter, "*" );
1023
 
                gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (File_Selector), filter);
1024
 
 
1025
 
                filter = gtk_file_filter_new ();
1026
 
                gtk_file_filter_set_name ( filter , _("Only archives") );
1027
 
                Suffix = g_list_first ( ArchiveSuffix );
1028
 
                while ( Suffix != NULL )
1029
 
                {
1030
 
                        gtk_file_filter_add_pattern (filter, Suffix->data);
1031
 
                        Suffix = g_list_next ( Suffix );
1032
 
                }
1033
 
                gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (File_Selector), filter);
1034
 
 
1035
 
                Suffix = g_list_first ( ArchiveSuffix );
1036
 
                while ( Suffix != NULL )
1037
 
                {
1038
 
                        if ( Suffix->data != "" )       /* To avoid double filtering when opening the archive */
1039
 
                        {
1040
 
                                filter = gtk_file_filter_new ();
1041
 
                                gtk_file_filter_set_name (filter, Suffix->data );
1042
 
                                gtk_file_filter_add_pattern (filter, Suffix->data );
1043
 
                                gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (File_Selector), filter);
1044
 
                        }
1045
 
                        Suffix = g_list_next ( Suffix );
1046
 
                }
1047
 
                gtk_window_set_modal (GTK_WINDOW (File_Selector),TRUE);
1048
 
        }
1049
 
        if (open_file_filter != NULL)
1050
 
                gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (File_Selector) , open_file_filter );
1051
 
 
1052
 
        if (current_open_directory != NULL)
1053
 
                gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (File_Selector) , current_open_directory );
1054
 
 
1055
 
        response = gtk_dialog_run (GTK_DIALOG (File_Selector));
1056
 
 
1057
 
        if (current_open_directory != NULL)
1058
 
                g_free (current_open_directory);
1059
 
 
1060
 
        current_open_directory = gtk_file_chooser_get_current_folder ( GTK_FILE_CHOOSER (File_Selector) );
1061
 
        open_file_filter = gtk_file_chooser_get_filter ( GTK_FILE_CHOOSER (File_Selector) );
1062
 
 
1063
 
        if (response == GTK_RESPONSE_ACCEPT)
1064
 
                path = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (File_Selector) );
1065
 
        else if ( (response == GTK_RESPONSE_CANCEL) || (response == GTK_RESPONSE_DELETE_EVENT) )
1066
 
                path = NULL;
1067
 
 
1068
 
        /* Hiding the window instead of destroying it will preserve the pointers to the file chooser stuff */
1069
 
        gtk_widget_hide (File_Selector);
1070
 
        return path;
1071
 
}
1072
 
 
1073
 
gboolean isISO ( FILE *ptr )
1074
 
{
1075
 
        int offset_image;
1076
 
        if ((offset_image = DetectImage(ptr)) > 0 )
1077
 
        {
1078
 
                fseek ( ptr , offset_image, SEEK_SET );
1079
 
                fread ( &ipd, 1, sizeof(ipd), ptr );
1080
 
                system_id = g_strndup ( ipd.system_id, 30);
1081
 
                volume_id = g_strndup ( ipd.volume_id, 30);
1082
 
                application_id = g_strndup ( ipd.application_id, 126);
1083
 
                publisher_id = g_strndup ( ipd.publisher_id, 126);
1084
 
                preparer_id = g_strndup ( ipd.preparer_id, 126);
1085
 
 
1086
 
                creation_date = g_strdup_printf ("%4.4s %2.2s %2.2s %2.2s:%2.2s:%2.2s.%2.2s",&ipd.creation_date[0],&ipd.creation_date[4],&ipd.creation_date[6],&ipd.creation_date[8],&ipd.creation_date[10],&ipd.creation_date[12],&ipd.creation_date[14]);
1087
 
 
1088
 
                modified_date = g_strdup_printf ("%4.4s %2.2s %2.2s %2.2s:%2.2s:%2.2s.%2.2s",&ipd.modification_date[0],&ipd.modification_date[4],&ipd.modification_date[6],&ipd.modification_date[8],&ipd.modification_date[10],&ipd.modification_date[12],&ipd.modification_date[14]);
1089
 
 
1090
 
                expiration_date = g_strdup_printf ("%4.4s %2.2s %2.2s %2.2s:%2.2s:%2.2s.%2.2s",&ipd.expiration_date[0],&ipd.expiration_date[4],&ipd.expiration_date[6],&ipd.expiration_date[8],&ipd.expiration_date[10],&ipd.expiration_date[12],&ipd.expiration_date[14]);
1091
 
 
1092
 
                effective_date = g_strdup_printf ("%4.4s %2.2s %2.2s %2.2s:%2.2s:%2.2s.%2.2s",&ipd.effective_date[0],&ipd.effective_date[4],&ipd.effective_date[6],&ipd.effective_date[8],&ipd.effective_date[10],&ipd.effective_date[12],&ipd.effective_date[14]);
1093
 
        return TRUE;
1094
 
        }
1095
 
    else
1096
 
                return FALSE;
1097
 
}
1098
 
 
1099
 
gboolean isTar ( FILE *ptr )
1100
 
{
1101
 
        unsigned char magic[7];
1102
 
        fseek ( ptr, 0 , SEEK_SET );
1103
 
    if ( fseek ( ptr , 257 , SEEK_CUR) < 0 )
1104
 
                return FALSE;
1105
 
    if ( fread ( magic, 1, 7, ptr ) == 0 )
1106
 
                return FALSE;
1107
 
    if ( memcmp ( magic,"\x75\x73\x74\x61\x72\x00\x30",7 ) == 0 || memcmp (magic,"\x75\x73\x74\x61\x72\x20\x20",7 ) == 0)
1108
 
                return TRUE;
1109
 
    else
1110
 
                return FALSE;
1111
 
}
1112
 
 
1113
 
gboolean isLha ( FILE *ptr )
1114
 
{
1115
 
        unsigned char magic[2];
1116
 
        fseek(ptr, 0, SEEK_SET);
1117
 
        if(fseek(ptr, 19, SEEK_CUR) < 0)
1118
 
                return FALSE;
1119
 
        if(fread(magic, 1, 2, ptr) == 0)
1120
 
                return FALSE;
1121
 
 
1122
 
        if(magic[0] == 0x20 && magic[1] <= 0x03)
1123
 
        {
1124
 
                return TRUE;
1125
 
        }
1126
 
        else
1127
 
        {
1128
 
                return FALSE;
1129
 
        }
1130
 
}
1131
 
 
1132
 
int xa_detect_archive_type ( XArchive *archive , gchar *filename )
1133
 
{
1134
 
        FILE *dummy_ptr = NULL;
1135
 
    int xx = -1;
1136
 
        unsigned char magic[12];
1137
 
        if (filename != NULL)
1138
 
                dummy_ptr = fopen ( filename , "r" );
1139
 
        else
1140
 
                dummy_ptr = fopen ( archive->path , "r" );
1141
 
 
1142
 
        if (dummy_ptr == NULL)
1143
 
        {
1144
 
                if ( !cli )
1145
 
                {
1146
 
                        gchar *utf8_path,*msg;
1147
 
                        utf8_path = g_filename_to_utf8 (archive->path, -1, NULL, NULL, NULL);
1148
 
                        msg = g_strdup_printf (_("Can't open archive \"%s\":") , utf8_path );
1149
 
                        response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow) , GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,
1150
 
                        msg,g_strerror (errno));
1151
 
                        g_free (msg);
1152
 
                        g_free (utf8_path);
1153
 
                        return -2;
1154
 
                }
1155
 
                else
1156
 
                        return -2;
1157
 
        }
1158
 
        if ( fread ( magic, 1, 12, dummy_ptr ) == 0 )
1159
 
        {
1160
 
                fclose ( dummy_ptr);
1161
 
                return -2;
1162
 
        }
1163
 
 
1164
 
        if ( memcmp ( magic,"\x50\x4b\x03\x04",4 ) == 0 || memcmp ( magic,"\x50\x4b\x05\x06",4 ) == 0 )
1165
 
        {
1166
 
                if (archive != NULL)
1167
 
                {
1168
 
                        archive->has_passwd = xa_detect_encrypted_archive ( XARCHIVETYPE_ZIP , dummy_ptr , magic );
1169
 
                        archive->has_comment = xa_detect_archive_comment ( XARCHIVETYPE_ZIP , dummy_ptr, archive );
1170
 
                }
1171
 
                xx = XARCHIVETYPE_ZIP;
1172
 
        }
1173
 
        else if ( memcmp ( magic,"\x60\xea",2 ) == 0 )
1174
 
        {
1175
 
                if (archive != NULL)
1176
 
                {
1177
 
                        archive->has_passwd = xa_detect_encrypted_archive ( XARCHIVETYPE_ARJ , dummy_ptr, magic );
1178
 
                        archive->has_comment = xa_detect_archive_comment ( XARCHIVETYPE_ARJ , dummy_ptr, archive );
1179
 
                }
1180
 
                xx = XARCHIVETYPE_ARJ;
1181
 
        }
1182
 
        else if ( memcmp ( magic,"\x52\x61\x72\x21",4 ) == 0 )
1183
 
        {
1184
 
                if (archive != NULL)
1185
 
                        archive->has_comment = xa_detect_archive_comment ( XARCHIVETYPE_RAR , dummy_ptr, archive );
1186
 
                 xx = XARCHIVETYPE_RAR;
1187
 
        }
1188
 
        else if ( memcmp ( magic,"\x42\x5a\x68",3 ) == 0 ) xx = XARCHIVETYPE_BZIP2;
1189
 
        else if ( memcmp ( magic,"\x1f\x8b",2) == 0 || memcmp ( magic,"\x1f\x9d",2 ) == 0 )  xx = XARCHIVETYPE_GZIP;
1190
 
        else if ( memcmp ( magic,"\xed\xab\xee\xdb",4 ) == 0) xx = XARCHIVETYPE_RPM;
1191
 
        else if ( memcmp ( magic,"\x37\x7a\xbc\xaf\x27\x1c",6 ) == 0 ) xx = XARCHIVETYPE_7ZIP;
1192
 
        else if ( isTar ( dummy_ptr ) ) xx = XARCHIVETYPE_TAR;
1193
 
        else if ( isISO ( dummy_ptr ) ) xx = XARCHIVETYPE_ISO;
1194
 
        else if ( isLha ( dummy_ptr ) ) xx = XARCHIVETYPE_LHA;
1195
 
        else if ( memcmp ( magic,"!<arch>\n", 8 ) == 0) xx = XARCHIVETYPE_DEB;
1196
 
        //else if ( memcmp (magic,"\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00",12) == 0 ) xx = XARCHIVETYPE_BIN;
1197
 
        fclose ( dummy_ptr );
1198
 
        return xx;
1199
 
}
1200
 
 
1201
 
gboolean xa_detect_archive_comment ( int type, FILE *stream, XArchive *archive )
1202
 
{
1203
 
        char sig;
1204
 
        guint cmt_len = 0;
1205
 
        unsigned char eocds[] = { 0x50, 0x4b, 0x05, 0x06 };
1206
 
        int byte;
1207
 
        unsigned long long int eocds_position = 0;
1208
 
 
1209
 
        unsigned short int len = 0;
1210
 
        int eof;
1211
 
        size_t seqptr = 0;
1212
 
 
1213
 
        if (type == XARCHIVETYPE_ZIP)
1214
 
        {
1215
 
                /* Let's position the file indicator to 64KB before the end of the archive */
1216
 
                fseek(stream, 0L, SEEK_END);
1217
 
        eocds_position = ftell(stream);
1218
 
        fseek(stream, eocds_position - 200, SEEK_SET);
1219
 
                /* Let's reach the end of central directory signature now */
1220
 
                while( ! feof(stream) )
1221
 
                {
1222
 
                        byte = (eof = fgetc(stream));
1223
 
                        if (eof == EOF)
1224
 
                                break;
1225
 
                        if (byte == eocds[seqptr])
1226
 
                        {
1227
 
                                if (++seqptr == sizeof(eocds))
1228
 
                                {
1229
 
                                        eocds_position = ftell(stream) + 16 ;
1230
 
                                        seqptr = 0;
1231
 
                                }
1232
 
                                continue;
1233
 
                        }
1234
 
                        else
1235
 
                        {
1236
 
                                if (seqptr)
1237
 
                                        seqptr = 0;
1238
 
                        }
1239
 
                }
1240
 
                fseek (stream,eocds_position,SEEK_SET);
1241
 
                fread (&len,1,2,stream);
1242
 
                if (len == 0)
1243
 
                        return FALSE;
1244
 
                else
1245
 
                {
1246
 
                        archive->comment = g_string_new("");
1247
 
                        while (cmt_len != len)
1248
 
                        {
1249
 
                                fread (&sig,1,1,stream);
1250
 
                                g_string_append (archive->comment,&sig);
1251
 
                                cmt_len++;
1252
 
                        }
1253
 
                        return TRUE;
1254
 
                }
1255
 
        }
1256
 
        else if (type == XARCHIVETYPE_ARJ)
1257
 
        {
1258
 
                /* Let's avoid the archive name */
1259
 
                fseek ( stream, 39 , SEEK_SET );
1260
 
                while (sig != 0)
1261
 
                {
1262
 
                        fread (&sig,1,1,stream);
1263
 
                        cmt_len++;
1264
 
                }
1265
 
                fseek ( stream, 39 + cmt_len , SEEK_SET );
1266
 
                sig = 1;
1267
 
                /* Let's read the archive comment byte after byte now */
1268
 
                archive->comment = g_string_new("");
1269
 
                while (sig != 0)
1270
 
                {
1271
 
                        fread (&sig,1,1,stream);
1272
 
 
1273
 
                        if (sig == 0 && archive->comment->len == 0)
1274
 
                        {
1275
 
                                g_string_free (archive->comment,FALSE);
1276
 
                                archive->comment = NULL;
1277
 
                                return FALSE;
1278
 
                        }
1279
 
                        else
1280
 
                                g_string_append (archive->comment,&sig);
1281
 
                }
1282
 
                return TRUE;
1283
 
        }
1284
 
        else if (type == XARCHIVETYPE_RAR)
1285
 
        {
1286
 
        }
1287
 
        return FALSE;
1288
 
}
1289
 
 
1290
 
gboolean xa_detect_encrypted_archive ( int type, FILE *stream, unsigned char magic[6] )
1291
 
{
1292
 
    unsigned int fseek_offset;
1293
 
    unsigned short int password_flag;
1294
 
    unsigned int compressed_size;
1295
 
    unsigned int uncompressed_size;
1296
 
    unsigned short int file_length;
1297
 
    unsigned short int extra_length;
1298
 
 
1299
 
        unsigned char sig[2];
1300
 
        unsigned short int basic_header_size;
1301
 
        unsigned short int extended_header_size;
1302
 
        unsigned int basic_header_CRC;
1303
 
        unsigned int extended_header_CRC;
1304
 
        unsigned char arj_flag;
1305
 
 
1306
 
        fseek ( stream, 6 , SEEK_SET );
1307
 
        if ( type == XARCHIVETYPE_ZIP )
1308
 
        {
1309
 
                while ( memcmp ( magic,"\x50\x4b\x03\x04",4 ) == 0  || memcmp ( magic,"\x50\x4b\x05\x06",4 ) == 0 )
1310
 
                {
1311
 
                        fread ( &password_flag, 1, 2, stream );
1312
 
                        if (( password_flag & ( 1<<0) ) > 0)
1313
 
                                return TRUE;
1314
 
                        fseek (stream,10,SEEK_CUR);
1315
 
                        fread (&compressed_size,1,4,stream);
1316
 
                        fread (&uncompressed_size,1,4,stream);
1317
 
                        fread (&file_length,1,2,stream);
1318
 
                        /* If the zip archive is empty (no files) it should return here */
1319
 
                        if (fread (&extra_length,1,2,stream) < 2 )
1320
 
                                return FALSE;
1321
 
                        fseek_offset = compressed_size + file_length + extra_length;
1322
 
                        fseek (stream , fseek_offset , SEEK_CUR);
1323
 
                        fread (magic , 1 , 4 , stream);
1324
 
                        fseek ( stream , 2 , SEEK_CUR);
1325
 
                }
1326
 
        }
1327
 
        else if ( type == XARCHIVETYPE_ARJ)
1328
 
        {
1329
 
                fseek (stream , magic[2]+magic[3] , SEEK_CUR);
1330
 
                fseek (stream , 2 , SEEK_CUR);
1331
 
                fread (&extended_header_size,1,2,stream);
1332
 
                if (extended_header_size != 0)
1333
 
                        fread (&extended_header_CRC,1,4,stream);
1334
 
                fread (&sig,1,2,stream);
1335
 
                while ( memcmp (sig,"\x60\xea",2) == 0)
1336
 
                {
1337
 
                        fread ( &basic_header_size , 1 , 2 , stream );
1338
 
                        if ( basic_header_size == 0 )
1339
 
                                break;
1340
 
                        fseek ( stream , 4 , SEEK_CUR);
1341
 
                        fread (&arj_flag,1,1,stream);
1342
 
                        if ((arj_flag & ( 1<<0) ) > 0)
1343
 
                                return TRUE;
1344
 
                        fseek ( stream , 7 , SEEK_CUR);
1345
 
                        fread (&compressed_size,1,4,stream);
1346
 
                        fseek ( stream , basic_header_size - 16 , SEEK_CUR);
1347
 
                        fread (&basic_header_CRC,1,4,stream);
1348
 
                        fread (&extended_header_size,1,2,stream);
1349
 
                        if (extended_header_size != 0)
1350
 
                                fread (&extended_header_CRC,1,4,stream);
1351
 
                        fseek ( stream , compressed_size , SEEK_CUR);
1352
 
                        fread (&sig,1,2,stream);
1353
 
                }
1354
 
        }
1355
 
        return FALSE;
1356
 
}
1357
 
 
1358
 
void xa_remove_columns()
1359
 
{
1360
 
        gint current_page;
1361
 
        gint idx;
1362
 
 
1363
 
        current_page = gtk_notebook_get_current_page (notebook);
1364
 
        idx = xa_find_archive_index (current_page);
1365
 
 
1366
 
        GList *columns = gtk_tree_view_get_columns ( GTK_TREE_VIEW (archive[idx]->treeview) );
1367
 
        while (columns != NULL)
1368
 
        {
1369
 
                gtk_tree_view_remove_column (GTK_TREE_VIEW (archive[idx]->treeview) , columns->data);
1370
 
                columns = columns->next;
1371
 
        }
1372
 
        g_list_free (columns);
1373
 
}
1374
 
 
1375
 
void EmptyTextBuffer ()
1376
 
{
1377
 
        if (textbuf != NULL)
1378
 
        {
1379
 
                gtk_text_buffer_get_start_iter (textbuf,&start);
1380
 
                gtk_text_buffer_get_end_iter (textbuf,&end);
1381
 
                gtk_text_buffer_delete (textbuf,&start,&end);
1382
 
                gtk_text_buffer_get_start_iter(textbuf, &enditer);
1383
 
        }
1384
 
}
1385
 
 
1386
 
void xa_create_liststore ( unsigned short int nc, gchar *columns_names[] , GType columns_types[], XArchive *archive)
1387
 
{
1388
 
        unsigned short int x;
1389
 
        GtkCellRenderer *renderer;
1390
 
        GtkTreeViewColumn *column;
1391
 
 
1392
 
        archive->liststore = gtk_list_store_newv ( nc , (GType *)columns_types);
1393
 
        gtk_tree_view_set_model ( GTK_TREE_VIEW (archive->treeview), GTK_TREE_MODEL (archive->liststore) );
1394
 
 
1395
 
        archive->model = gtk_tree_view_get_model(GTK_TREE_VIEW(archive->treeview));
1396
 
        g_object_ref(archive->model);
1397
 
        gtk_tree_view_set_model(GTK_TREE_VIEW(archive->treeview), NULL);
1398
 
 
1399
 
        for (x = 0; x <= nc-1; x++)
1400
 
        {
1401
 
                renderer = gtk_cell_renderer_text_new ();
1402
 
                column = gtk_tree_view_column_new_with_attributes ( columns_names[x],renderer,"text",x,NULL);
1403
 
                gtk_tree_view_column_set_resizable (column, TRUE);
1404
 
                gtk_tree_view_column_set_sort_column_id (column, x);
1405
 
                gtk_tree_view_append_column (GTK_TREE_VIEW (archive->treeview), column);
1406
 
        }
1407
 
}
1408
 
 
1409
 
gboolean treeview_select_search (GtkTreeModel *model,gint column,const gchar *key,GtkTreeIter *iter,gpointer search_data)
1410
 
{
1411
 
    char *filename;
1412
 
    gboolean result;
1413
 
 
1414
 
    gtk_tree_model_get (model, iter, 0, &filename, -1);
1415
 
    if ( strcasestr (filename, key) ) result = FALSE;
1416
 
        else result = TRUE;
1417
 
    g_free (filename);
1418
 
    return result;
1419
 
}
1420
 
 
1421
 
void xa_show_cmd_line_output( GtkMenuItem *menuitem )
1422
 
{
1423
 
        if (OutputWindow != NULL)
1424
 
        {
1425
 
                gtk_window_set_title (GTK_WINDOW (OutputWindow), _("Command line output") );
1426
 
                gtk_window_present ( GTK_WINDOW (OutputWindow) );
1427
 
                return;
1428
 
        }
1429
 
        OutputWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1430
 
        gtk_window_set_position (GTK_WINDOW (OutputWindow), GTK_WIN_POS_CENTER);
1431
 
        gtk_window_set_default_size(GTK_WINDOW(OutputWindow), 380, 250);
1432
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (OutputWindow), TRUE);
1433
 
        g_signal_connect (G_OBJECT (OutputWindow), "delete-event",  G_CALLBACK (gtk_widget_hide), &OutputWindow);
1434
 
 
1435
 
        vbox = gtk_vbox_new ( FALSE, 2 );
1436
 
        scrollwin = gtk_scrolled_window_new ( NULL,NULL );
1437
 
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW( scrollwin ), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1438
 
 
1439
 
        textview = gtk_text_view_new();
1440
 
        gtk_text_view_set_editable (GTK_TEXT_VIEW(textview), FALSE);
1441
 
        gtk_container_add (GTK_CONTAINER(scrollwin), textview);
1442
 
        gtk_box_pack_start (GTK_BOX(vbox), scrollwin, TRUE, TRUE, 0);
1443
 
        gtk_container_add (GTK_CONTAINER(OutputWindow), vbox);
1444
 
        textbuf = gtk_text_view_get_buffer ( GTK_TEXT_VIEW(textview) );
1445
 
        gtk_text_buffer_get_start_iter (textbuf, &enditer);
1446
 
        //gtk_text_buffer_create_tag (textbuf, "red_foreground","foreground", "red", NULL);
1447
 
 
1448
 
        gtk_widget_show (vbox);
1449
 
        gtk_widget_show (scrollwin);
1450
 
        gtk_widget_show (textview);
1451
 
}
1452
 
 
1453
 
void xa_cancel_archive ( GtkMenuItem *menuitem , gpointer data )
1454
 
{
1455
 
        gint current_page;
1456
 
        gint idx;
1457
 
 
1458
 
        current_page = gtk_notebook_get_current_page(notebook);
1459
 
        idx = xa_find_archive_index (current_page);
1460
 
 
1461
 
        if (archive[idx]->status == XA_ARCHIVESTATUS_ADD || archive[idx]->status == XA_ARCHIVESTATUS_SFX)
1462
 
        {
1463
 
                response = ShowGtkMessageDialog (GTK_WINDOW     (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,_("Doing so will probably corrupt your archive!"),_("Do you really want to cancel?") );
1464
 
                if (response == GTK_RESPONSE_NO)
1465
 
                        return;
1466
 
        }
1467
 
        xa_hide_progress_bar_stop_button (archive[idx]);
1468
 
    Update_StatusBar (_("Waiting for the process to abort..."));
1469
 
        stop_flag = TRUE;
1470
 
        if (archive[idx]->type != XARCHIVETYPE_ISO)
1471
 
        {
1472
 
                if ( kill ( archive[idx]->child_pid , SIGABRT ) < 0 )
1473
 
            {
1474
 
                    response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("An error occurred while trying to kill the process:"),g_strerror(errno));
1475
 
                        return;
1476
 
            }
1477
 
        }
1478
 
    /* This in case the user cancels the opening of a password protected archive */
1479
 
    if (archive[idx]->status != XA_ARCHIVESTATUS_ADD || archive[idx]->status != XA_ARCHIVESTATUS_DELETE)
1480
 
                if (archive[idx]->has_passwd)
1481
 
                        archive[idx]->has_passwd = FALSE;
1482
 
}
1483
 
 
1484
 
void xa_view_file_inside_archive ( GtkMenuItem *menuitem , gpointer user_data )
1485
 
{
1486
 
        gchar *filename = NULL;
1487
 
        GError *error = NULL;
1488
 
        gchar *string = NULL;
1489
 
        gchar *command = NULL;
1490
 
        GtkTreeSelection *selection;
1491
 
        GtkTreeModel *model;
1492
 
        GtkTreeIter iter;
1493
 
        gchar *dir;
1494
 
        gchar *dummy_name;
1495
 
        unsigned short int COL_NAME;
1496
 
        gboolean is_dir = FALSE;
1497
 
        gboolean tofree = FALSE;
1498
 
        gboolean result = FALSE;
1499
 
        GList *row_list = NULL;
1500
 
        GString *names;
1501
 
        gchar *content;
1502
 
        gsize length;
1503
 
        gsize new_length;
1504
 
        gchar *t;
1505
 
        gint current_page;
1506
 
        gint idx;
1507
 
 
1508
 
        current_page = gtk_notebook_get_current_page (notebook);
1509
 
        idx = xa_find_archive_index (current_page);
1510
 
 
1511
 
        if ( archive[idx]->has_passwd )
1512
 
        {
1513
 
                if ( archive[idx]->passwd == NULL)
1514
 
                {
1515
 
                        archive[idx]->passwd = password_dialog ();
1516
 
                        if ( archive[idx]->passwd == NULL)
1517
 
                                return;
1518
 
                }
1519
 
        }
1520
 
        selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (archive[idx]->treeview) );
1521
 
 
1522
 
        /* if no or more than one rows selected, do nothing, just for sanity */
1523
 
        if ( gtk_tree_selection_count_selected_rows (selection) != 1)
1524
 
                return;
1525
 
 
1526
 
        row_list = gtk_tree_selection_get_selected_rows (selection, &model);
1527
 
        if ( row_list == NULL )
1528
 
                return;
1529
 
 
1530
 
        gtk_tree_model_get_iter(model, &iter, row_list->data);
1531
 
 
1532
 
        gtk_tree_path_free(row_list->data);
1533
 
        g_list_free (row_list);
1534
 
 
1535
 
        switch (archive[idx]->type)
1536
 
        {
1537
 
                case XARCHIVETYPE_RAR:
1538
 
                case XARCHIVETYPE_ARJ:
1539
 
                COL_NAME = 6;
1540
 
                break;
1541
 
 
1542
 
                case XARCHIVETYPE_ZIP:
1543
 
                COL_NAME = 0;
1544
 
                break;
1545
 
 
1546
 
                case XARCHIVETYPE_7ZIP:
1547
 
                COL_NAME = 3;
1548
 
                break;
1549
 
 
1550
 
                default:
1551
 
                COL_NAME = 1;
1552
 
        }
1553
 
        gtk_tree_model_get (model, &iter, COL_NAME, &dir, -1);
1554
 
        if (archive[idx]->type == XARCHIVETYPE_ZIP)
1555
 
        {
1556
 
                if ( g_str_has_suffix (dir,"/") == TRUE )
1557
 
                        is_dir = TRUE;
1558
 
        }
1559
 
        else if ( strstr ( dir , "d" ) || strstr ( dir , "D" ) ) is_dir = TRUE;
1560
 
        if (is_dir)
1561
 
        {
1562
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,"Can't perform the action:",_("Please select a file, not a directory!") );
1563
 
                g_free ( dir );
1564
 
                return;
1565
 
        }
1566
 
        g_free ( dir );
1567
 
 
1568
 
        full_path = archive[idx]->full_path;
1569
 
        overwrite = archive[idx]->overwrite;
1570
 
 
1571
 
        archive[idx]->full_path = 0;
1572
 
        archive[idx]->overwrite = 1;
1573
 
 
1574
 
        names = g_string_new (" ");
1575
 
        gtk_tree_model_get (model, &iter, 0, &dummy_name, -1);
1576
 
        archive[idx]->status = XA_ARCHIVESTATUS_EXTRACT;
1577
 
        ConcatenateFileNames2 ( dummy_name , names );
1578
 
 
1579
 
        if (archive[idx]->type == XARCHIVETYPE_ISO)
1580
 
        {
1581
 
                gtk_tree_model_get (model, &iter,
1582
 
                        0, &dummy_name,
1583
 
                        1, &permissions,
1584
 
                        2, &file_size,
1585
 
                        4, &file_offset,
1586
 
                        -1);
1587
 
                xa_extract_iso_file (archive[idx], permissions, "/tmp/", dummy_name , file_size, file_offset );
1588
 
                g_free (permissions);
1589
 
        }
1590
 
        else
1591
 
                command = xa_extract_single_files ( archive[idx] , names, "/tmp");
1592
 
 
1593
 
        archive[idx]->full_path = full_path;
1594
 
        archive[idx]->overwrite = overwrite;
1595
 
        EmptyTextBuffer();
1596
 
        if (command != NULL)
1597
 
        {
1598
 
                result = xa_run_command (command , 0);
1599
 
                g_free (command);
1600
 
                if ( result == 0 )
1601
 
                {
1602
 
                        unlink (dummy_name);
1603
 
                        g_free (dummy_name);
1604
 
                        g_string_free (names,TRUE);
1605
 
                        return;
1606
 
                }
1607
 
        }
1608
 
        view_window = view_win( names->str );
1609
 
        g_string_free (names,TRUE);
1610
 
        string = g_strrstr ( dummy_name, "/" );
1611
 
        if (  string == NULL )
1612
 
                filename = g_strconcat ( "/tmp/" , dummy_name, NULL );
1613
 
        else
1614
 
        {
1615
 
                if ( strchr ( string , ' ' ) )
1616
 
                {
1617
 
                        string = RemoveBackSlashes ( string );
1618
 
                        tofree = TRUE;
1619
 
                }
1620
 
                filename = g_strconcat ( "/tmp" , string , NULL );
1621
 
                if ( tofree )
1622
 
                        g_free ( string );
1623
 
        }
1624
 
        g_free (dummy_name);
1625
 
 
1626
 
        result = g_file_get_contents (filename,&content,&length,&error);
1627
 
        if ( ! result)
1628
 
        {
1629
 
                gtk_widget_hide (viewport2);
1630
 
                unlink ( filename );
1631
 
                Update_StatusBar ( _("Operation failed."));
1632
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("An error occurred while extracting the file to be viewed:") , error->message);
1633
 
                g_error_free (error);
1634
 
                g_free (filename);
1635
 
                return;
1636
 
        }
1637
 
        t = g_locale_to_utf8 ( content, length, NULL, &new_length, &error);
1638
 
        g_free ( content );
1639
 
        if ( t == NULL)
1640
 
        {
1641
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("An error occurred while converting the file content to the UTF8 encoding:") , error->message);
1642
 
                g_free (error);
1643
 
        }
1644
 
        else
1645
 
        {
1646
 
                gtk_widget_show (view_window);
1647
 
                gtk_text_buffer_insert (viewtextbuf, &viewenditer, t, new_length );
1648
 
        }
1649
 
        unlink ( filename );
1650
 
        g_free (filename);
1651
 
        xa_hide_progress_bar_stop_button(archive[idx]);
1652
 
        Update_StatusBar (_("Operation completed."));
1653
 
}
1654
 
 
1655
 
void xa_iso_properties ( GtkMenuItem *menuitem , gpointer user_data )
1656
 
{
1657
 
        gchar *utf8_string, *text, *measure;
1658
 
        unsigned long long int file_size;
1659
 
        GtkWidget *iso_properties_win;
1660
 
        gint current_page;
1661
 
        gint idx;
1662
 
 
1663
 
        current_page = gtk_notebook_get_current_page (notebook);
1664
 
        idx = xa_find_archive_index (current_page);
1665
 
 
1666
 
        stat ( archive[idx]->path , &my_stat );
1667
 
        file_size = my_stat.st_size;
1668
 
        iso_properties_win = create_iso_properties_window();
1669
 
        //Name
1670
 
        text = g_strrstr ( archive[idx]->path, "/" );
1671
 
        if (text != NULL)
1672
 
        {
1673
 
            text++; //This to avoid the / char in the string
1674
 
            utf8_string = g_filename_display_name (text);
1675
 
        }
1676
 
        else
1677
 
                utf8_string = g_filename_display_name (archive[idx]->path);
1678
 
        gtk_entry_set_text ( GTK_ENTRY (filename_entry), utf8_string );
1679
 
        g_free (utf8_string);
1680
 
    //Size
1681
 
        if (file_size > 1024*1024*1024 )
1682
 
        {
1683
 
                content_size = (double)file_size / (1024*1024*1024);
1684
 
                measure = " GB";
1685
 
        }
1686
 
        else if (file_size > 1024*1024 )
1687
 
        {
1688
 
                content_size = (double)file_size / (1024*1024);
1689
 
                measure = " MB";
1690
 
        }
1691
 
 
1692
 
    else if (file_size > 1024 )
1693
 
        {
1694
 
                content_size = (double)file_size / 1024;
1695
 
                measure = " KB";
1696
 
        }
1697
 
        else
1698
 
        {
1699
 
                measure = _(" bytes");
1700
 
                content_size = file_size;
1701
 
        }
1702
 
 
1703
 
    text = g_strdup_printf ("%.1f %s", content_size,measure);
1704
 
    gtk_entry_set_text ( GTK_ENTRY (size_entry), text );
1705
 
    g_free (text);
1706
 
 
1707
 
        gtk_entry_set_text ( GTK_ENTRY (image_type_entry),archive[idx]->tmp);
1708
 
 
1709
 
        gtk_entry_set_text ( GTK_ENTRY (system_id_entry),system_id);
1710
 
 
1711
 
        gtk_entry_set_text ( GTK_ENTRY (volume_id_entry),volume_id);
1712
 
 
1713
 
        gtk_entry_set_text ( GTK_ENTRY (application_entry),application_id);
1714
 
 
1715
 
        gtk_entry_set_text ( GTK_ENTRY (publisher_entry),publisher_id);
1716
 
        gtk_widget_show (iso_properties_win);
1717
 
 
1718
 
        gtk_entry_set_text ( GTK_ENTRY (preparer_entry),preparer_id);
1719
 
        gtk_widget_show (iso_properties_win);
1720
 
 
1721
 
        gtk_entry_set_text ( GTK_ENTRY (creation_date_entry),creation_date);
1722
 
 
1723
 
        gtk_entry_set_text ( GTK_ENTRY (modified_date_entry),modified_date);
1724
 
        gtk_widget_show (iso_properties_win);
1725
 
 
1726
 
        gtk_entry_set_text ( GTK_ENTRY (expiration_date_entry),expiration_date);
1727
 
 
1728
 
        gtk_entry_set_text ( GTK_ENTRY (effective_date_entry),effective_date);
1729
 
        gtk_widget_show (iso_properties_win);
1730
 
}
1731
 
 
1732
 
void xa_archive_properties ( GtkMenuItem *menuitem , gpointer user_data )
1733
 
{
1734
 
    gchar *utf8_string , *measure, *text, *dummy_string;
1735
 
    char date[64];
1736
 
    gchar *t;
1737
 
    unsigned long long int file_size;
1738
 
    gint current_page;
1739
 
        gint idx;
1740
 
 
1741
 
    current_page = gtk_notebook_get_current_page (notebook);
1742
 
        idx = xa_find_archive_index (current_page);
1743
 
 
1744
 
    stat ( archive[idx]->path , &my_stat );
1745
 
    file_size = my_stat.st_size;
1746
 
    archive_properties_win = create_archive_properties_window();
1747
 
    //Name
1748
 
    text = g_strrstr ( archive[idx]->path, "/" );
1749
 
    if (text != NULL)
1750
 
    {
1751
 
        text++;
1752
 
        utf8_string = g_filename_display_name (text);
1753
 
    }
1754
 
    else
1755
 
                utf8_string = g_filename_display_name (archive[idx]->path);
1756
 
    gtk_entry_set_text ( GTK_ENTRY (name_data), utf8_string );
1757
 
    g_free (utf8_string);
1758
 
    //Path
1759
 
    dummy_string = remove_level_from_path (archive[idx]->path);
1760
 
    if ( strlen(dummy_string) != 0)
1761
 
                utf8_string = g_filename_display_name (dummy_string);
1762
 
    else
1763
 
                utf8_string = g_filename_display_name ( g_get_current_dir () );
1764
 
    gtk_entry_set_text ( GTK_ENTRY (path_data), utf8_string );
1765
 
    g_free ( utf8_string );
1766
 
    g_free ( dummy_string );
1767
 
        //Type
1768
 
        gtk_entry_set_text ( GTK_ENTRY (type_data), archive[idx]->format );
1769
 
    //Modified Date
1770
 
    strftime (date, 64, "%c", localtime (&my_stat.st_mtime) );
1771
 
    t = g_locale_to_utf8 ( date, -1, 0, 0, 0);
1772
 
    gtk_entry_set_text ( GTK_ENTRY (modified_data), t);
1773
 
    g_free (t);
1774
 
    //Archive Size
1775
 
        if (file_size > 1024*1024*1024 )
1776
 
        {
1777
 
                content_size = (double)file_size / (1024*1024*1024);
1778
 
                measure = " GB";
1779
 
        }
1780
 
        else if (file_size > 1024*1024 )
1781
 
        {
1782
 
                content_size = (double)file_size / (1024*1024);
1783
 
                measure = " MB";
1784
 
        }
1785
 
 
1786
 
    else if (file_size > 1024 )
1787
 
        {
1788
 
                content_size = (double)file_size / 1024;
1789
 
                measure = " KB";
1790
 
        }
1791
 
        else
1792
 
        {
1793
 
                measure = " Bytes";
1794
 
                content_size = file_size;
1795
 
        }
1796
 
 
1797
 
    t = g_strdup_printf ("%.1f %s", content_size,measure);
1798
 
    gtk_entry_set_text ( GTK_ENTRY (size_data), t );
1799
 
    g_free (t);
1800
 
    //content_size
1801
 
    if (archive[idx]->dummy_size > 1024*1024*1024 )
1802
 
    {
1803
 
        content_size = (double)archive[idx]->dummy_size / (1024*1024*1024);
1804
 
        measure = " GB";
1805
 
    }
1806
 
        else if (archive[idx]->dummy_size > 1024*1024 )
1807
 
        {
1808
 
            content_size = (double)archive[idx]->dummy_size / (1024*1024);
1809
 
            measure = " MB";
1810
 
        }
1811
 
 
1812
 
        else if (archive[idx]->dummy_size > 1024 )
1813
 
        {
1814
 
            content_size = (double)archive[idx]->dummy_size / 1024;
1815
 
            measure = " KB";
1816
 
        }
1817
 
        else
1818
 
        {
1819
 
            measure = " Bytes";
1820
 
            content_size = archive[idx]->dummy_size;
1821
 
        }
1822
 
    t = g_strdup_printf ( "%.1f %s", content_size,measure);
1823
 
    gtk_entry_set_text ( GTK_ENTRY (content_data), t );
1824
 
    g_free (t);
1825
 
    //Has Comment
1826
 
    if (archive[idx]->has_comment)
1827
 
                gtk_entry_set_text ( GTK_ENTRY (comment_data), _("Yes") );
1828
 
        else
1829
 
                gtk_entry_set_text ( GTK_ENTRY (comment_data), _("No") );
1830
 
 
1831
 
    //Compression_ratio
1832
 
    if (content_size != 0)
1833
 
                content_size = (double)archive[idx]->dummy_size / file_size;
1834
 
    else
1835
 
                content_size = 0.0;
1836
 
    t = g_strdup_printf ( "%.2f", content_size);
1837
 
    gtk_entry_set_text ( GTK_ENTRY (compression_data), t );
1838
 
    g_free (t);
1839
 
    //Number of files
1840
 
    t = g_strdup_printf ( "%d", archive[idx]->nr_of_files);
1841
 
    gtk_entry_set_text ( GTK_ENTRY (number_of_files_data), t );
1842
 
    g_free (t);
1843
 
    //Number of dirs
1844
 
    t = g_strdup_printf ( "%d", archive[idx]->nr_of_dirs);
1845
 
    gtk_entry_set_text ( GTK_ENTRY (number_of_dirs_data), t );
1846
 
    g_free (t);
1847
 
    gtk_widget_show_all ( archive_properties_win );
1848
 
}
1849
 
 
1850
 
void xa_activate_delete_and_view ()
1851
 
{
1852
 
        gint current_page;
1853
 
        gint idx;
1854
 
 
1855
 
        current_page = gtk_notebook_get_current_page (notebook);
1856
 
        idx = xa_find_archive_index (current_page);
1857
 
 
1858
 
        if ( ! GTK_WIDGET_VISIBLE (Extract_button) )
1859
 
                return;
1860
 
 
1861
 
        GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (archive[idx]->treeview) );
1862
 
        gint selected = gtk_tree_selection_count_selected_rows ( selection );
1863
 
        if (selected == 0 )
1864
 
                OffDeleteandViewButtons();
1865
 
        else
1866
 
        {
1867
 
                if ( archive[idx]->type != XARCHIVETYPE_RPM && archive[idx]->type != XARCHIVETYPE_ISO && archive[idx]->type != XARCHIVETYPE_DEB)
1868
 
                {
1869
 
                        gtk_widget_set_sensitive ( delete_menu , TRUE );
1870
 
                        gtk_widget_set_sensitive ( Delete_button , TRUE );
1871
 
                }
1872
 
                if (selected > 1 )
1873
 
                {
1874
 
                        gtk_widget_set_sensitive ( View_button , FALSE);
1875
 
                        gtk_widget_set_sensitive ( view_menu, FALSE );
1876
 
                }
1877
 
                else
1878
 
                {
1879
 
                        gtk_widget_set_sensitive ( View_button , TRUE );
1880
 
                        gtk_widget_set_sensitive ( view_menu, TRUE );
1881
 
                }
1882
 
        }
1883
 
}
1884
 
 
1885
 
void ConcatenateFileNames2 (gchar *filename , GString *data)
1886
 
{
1887
 
        gchar *esc_filename = NULL;
1888
 
        gchar *escaped = NULL;
1889
 
        gchar *escaped2 = NULL;
1890
 
        gint current_page;
1891
 
        gint idx;
1892
 
 
1893
 
        current_page = gtk_notebook_get_current_page (notebook);
1894
 
        idx = xa_find_archive_index (current_page);
1895
 
 
1896
 
        if ( strstr (filename, "[") || strstr (filename, "]"))
1897
 
        {
1898
 
                if (archive[idx]->type == XARCHIVETYPE_ZIP)
1899
 
                {
1900
 
                        if (archive[idx]->status == XA_ARCHIVESTATUS_ADD)
1901
 
                        {
1902
 
                                esc_filename = EscapeBadChars ( filename ,"$\'`\"\\!?* ()[]&|@#:;" );
1903
 
                                g_string_prepend (data, esc_filename);
1904
 
                        }
1905
 
                        else
1906
 
                        {
1907
 
                                escaped = EscapeBadChars ( filename ,"$\'`\"\\!?* ()[]&|@#:;");
1908
 
                                escaped2 = escape_str_common (escaped , "*?[]", '\\', 0);
1909
 
                                g_free (escaped);
1910
 
                                esc_filename = escaped2;
1911
 
                                g_string_prepend (data, esc_filename);
1912
 
                        }
1913
 
                }
1914
 
                else if ( archive[idx]->type == XARCHIVETYPE_TAR_BZ2 || archive[idx]->type == XARCHIVETYPE_TAR_GZ || archive[idx]->type == XARCHIVETYPE_TAR )
1915
 
                {
1916
 
                        if (archive[idx]->status == XA_ARCHIVESTATUS_ADD)
1917
 
                        {
1918
 
                                esc_filename = EscapeBadChars ( filename ,"$\'`\"\\!?* ()[]&|@#:;" );
1919
 
                                g_string_prepend (data, esc_filename);
1920
 
                        }
1921
 
                        else
1922
 
                        {
1923
 
                                escaped = EscapeBadChars ( filename ,"?*\\'& !|()@#:;");
1924
 
                                escaped2 = escape_str_common ( escaped , "[]", '[', ']');
1925
 
                                g_free (escaped);
1926
 
                                esc_filename = escaped2;
1927
 
                                g_string_prepend (data, esc_filename);
1928
 
                        }
1929
 
                }
1930
 
        }
1931
 
        else
1932
 
        {
1933
 
                esc_filename = EscapeBadChars ( filename , "$\'`\"\\!?* ()[]&|@#:;" );
1934
 
                g_string_prepend (data, esc_filename);
1935
 
        }
1936
 
        g_string_prepend_c (data, ' ');
1937
 
        g_free (esc_filename);
1938
 
}
1939
 
 
1940
 
void ConcatenateFileNames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data)
1941
 
{
1942
 
        gchar *filename = NULL;
1943
 
 
1944
 
        gtk_tree_model_get (model, iter, 0, &filename, -1);
1945
 
        ConcatenateFileNames2 ( filename , data );
1946
 
        g_free (filename);
1947
 
}
1948
 
 
1949
 
void xa_cat_filenames_basename (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data)
1950
 
{
1951
 
        gchar *fullname;
1952
 
        gchar *name;
1953
 
 
1954
 
        gtk_tree_model_get (model, iter, 1, &fullname, -1);
1955
 
        name = g_path_get_basename ( fullname );
1956
 
 
1957
 
        ConcatenateFileNames2 ( name , data );
1958
 
        g_free (fullname);
1959
 
}
1960
 
 
1961
 
void xa_cat_filenames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data)
1962
 
{
1963
 
        gchar *fullname;
1964
 
 
1965
 
        gtk_tree_model_get (model, iter, 1, &fullname, -1);
1966
 
        ConcatenateFileNames2 ( fullname , data );
1967
 
        g_free (fullname);
1968
 
}
1969
 
 
1970
 
gboolean xa_run_command ( gchar *command , gboolean watch_child_flag )
1971
 
{
1972
 
        gint current_page;
1973
 
        gint idx;
1974
 
        int status;
1975
 
        gboolean waiting = TRUE;
1976
 
        int ps;
1977
 
 
1978
 
        current_page = gtk_notebook_get_current_page (notebook);
1979
 
        idx = xa_find_archive_index ( current_page );
1980
 
 
1981
 
        if (watch_child_flag)
1982
 
                EmptyTextBuffer();
1983
 
        archive[idx]->parse_output = 0;
1984
 
        SpawnAsyncProcess ( archive[idx] , command , 0, 1);
1985
 
        if ( archive[idx]->child_pid == 0 )
1986
 
                return FALSE;
1987
 
 
1988
 
        gtk_widget_show (viewport2);
1989
 
        while (waiting)
1990
 
        {
1991
 
                ps = waitpid ( archive[idx]->child_pid, &status, WNOHANG);
1992
 
                if (ps < 0)
1993
 
                        waiting = FALSE;
1994
 
                else
1995
 
                        gtk_main_iteration_do (FALSE);
1996
 
        }
1997
 
        if (watch_child_flag)
1998
 
        {
1999
 
                xa_watch_child (archive[idx]->child_pid, status, archive[idx]);
2000
 
                return TRUE;
2001
 
        }
2002
 
        else
2003
 
        {
2004
 
                if ( WIFEXITED (status) )
2005
 
                {
2006
 
                        if ( WEXITSTATUS (status) )
2007
 
                        {
2008
 
                                gtk_tooltips_disable ( pad_tooltip );
2009
 
                                gtk_widget_hide ( pad_image );
2010
 
                                gtk_widget_hide ( viewport2 );
2011
 
                                xa_set_window_title (MainWindow , NULL);
2012
 
                                response = ShowGtkMessageDialog (GTK_WINDOW     (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_QUESTION,GTK_BUTTONS_YES_NO,_("An error occurred while accessing the archive."),_("Do you want to view the command line output?") );
2013
 
                                if (response == GTK_RESPONSE_YES)
2014
 
                                        xa_show_cmd_line_output (NULL);
2015
 
                                archive[idx]->status = XA_ARCHIVESTATUS_IDLE;
2016
 
                                gtk_widget_set_sensitive (Stop_button,FALSE);
2017
 
                                Update_StatusBar ( _("Operation failed."));
2018
 
                                return FALSE;
2019
 
                        }
2020
 
                }
2021
 
        }
2022
 
        return TRUE;
2023
 
}
2024
 
 
2025
 
void Update_StatusBar ( gchar *msg)
2026
 
{
2027
 
    gtk_label_set_text (GTK_LABEL (info_label), msg);
2028
 
}
2029
 
 
2030
 
gboolean xa_report_child_stderr (GIOChannel *ioc, GIOCondition cond, gpointer data)
2031
 
{
2032
 
        GIOStatus status;
2033
 
        gchar     buffer[4096];
2034
 
        gsize     bytes_read;
2035
 
 
2036
 
        if (cond & (G_IO_IN | G_IO_PRI))
2037
 
        {
2038
 
                do
2039
 
                {
2040
 
                        status = g_io_channel_read_chars (ioc, buffer, sizeof (buffer), &bytes_read, NULL);
2041
 
                        if (bytes_read > 0)
2042
 
                                gtk_text_buffer_insert (textbuf, &enditer, buffer, bytes_read);
2043
 
                }
2044
 
                while (status == G_IO_STATUS_NORMAL);
2045
 
                if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
2046
 
                        goto done;
2047
 
        }
2048
 
        else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
2049
 
        {
2050
 
                done:
2051
 
                        g_io_channel_shutdown (ioc, TRUE, NULL);
2052
 
                        g_io_channel_unref (ioc);
2053
 
                        return FALSE;
2054
 
        }
2055
 
        return TRUE;
2056
 
}
2057
 
 
2058
 
void OffDeleteandViewButtons()
2059
 
{
2060
 
    gtk_widget_set_sensitive ( Delete_button, FALSE);
2061
 
    gtk_widget_set_sensitive ( delete_menu, FALSE);
2062
 
    gtk_widget_set_sensitive ( View_button, FALSE);
2063
 
    gtk_widget_set_sensitive ( view_menu, FALSE);
2064
 
}
2065
 
 
2066
 
void xa_hide_progress_bar_stop_button( XArchive *archive)
2067
 
{
2068
 
        archive->status = XA_ARCHIVESTATUS_IDLE;
2069
 
    gtk_widget_set_sensitive ( Stop_button , FALSE );
2070
 
    if (archive->pb_source != 0)
2071
 
                g_source_remove (archive->pb_source);
2072
 
    archive->pb_source = 0;
2073
 
    gtk_widget_hide (viewport2);
2074
 
}
2075
 
 
2076
 
void drag_begin (GtkWidget *treeview1,GdkDragContext *context, gpointer data)
2077
 
{
2078
 
    GtkTreeSelection *selection;
2079
 
    GtkTreeIter       iter;
2080
 
    gchar            *name;
2081
 
    GList            *row_list;
2082
 
        gint current_page;
2083
 
 
2084
 
        //gtk_drag_source_set_icon_name (treeview1, DATADIR "/pixmaps/xarchiver.png" );
2085
 
        current_page = gtk_notebook_get_current_page(notebook);
2086
 
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (archive[current_page]->treeview));
2087
 
 
2088
 
        row_list = gtk_tree_selection_get_selected_rows (selection, NULL);
2089
 
        if ( row_list == NULL )
2090
 
                return;
2091
 
 
2092
 
        gtk_tree_model_get_iter (archive[current_page]->model, &iter, (GtkTreePath*) (row_list->data) );
2093
 
        gtk_tree_model_get (archive[current_page]->model, &iter, 0, &name, -1);
2094
 
        gchar *no_slashes = g_strrstr ( name, "/" );
2095
 
        if (no_slashes != NULL)
2096
 
                no_slashes++;
2097
 
        gdk_property_change (context->source_window,
2098
 
                               gdk_atom_intern ("XdndDirectSave0", FALSE),
2099
 
                                   gdk_atom_intern ("text/plain", FALSE), 8,
2100
 
                                       GDK_PROP_MODE_REPLACE,
2101
 
                                           (const guchar *) no_slashes != NULL ? no_slashes : name, no_slashes != NULL ? strlen (no_slashes) : strlen (name) );
2102
 
 
2103
 
        g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
2104
 
        g_list_free (row_list);
2105
 
        g_free (name);
2106
 
}
2107
 
 
2108
 
void drag_end (GtkWidget *treeview1,GdkDragContext *context, gpointer data)
2109
 
{
2110
 
   /* Nothing to do */
2111
 
}
2112
 
 
2113
 
void drag_data_get (GtkWidget *widget, GdkDragContext *dc, GtkSelectionData *selection_data, guint info, guint t, gpointer data)
2114
 
{
2115
 
        GtkTreeSelection *selection;
2116
 
        guchar *fm_path;
2117
 
        int fm_path_len;
2118
 
        gchar *command , *no_uri_path;
2119
 
        gchar *to_send = "E";
2120
 
        GList *row_list;
2121
 
        GString *names;
2122
 
        gint current_page;
2123
 
        gint idx;
2124
 
 
2125
 
        current_page = gtk_notebook_get_current_page(notebook);
2126
 
        idx = xa_find_archive_index (current_page);
2127
 
 
2128
 
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (archive[idx]->treeview));
2129
 
        row_list = gtk_tree_selection_get_selected_rows (selection, NULL);
2130
 
 
2131
 
        if ( row_list == NULL)
2132
 
                return;
2133
 
        if ( archive[idx]->status == XA_ARCHIVESTATUS_EXTRACT )
2134
 
        {
2135
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't perform another extraction:"),_("Please wait until the completion of the current one!") );
2136
 
                return;
2137
 
        }
2138
 
        if ( gdk_property_get (dc->source_window,
2139
 
                                                        gdk_atom_intern ("XdndDirectSave0", FALSE),
2140
 
                                                        gdk_atom_intern ("text/plain", FALSE),
2141
 
                                                        0, 1024, FALSE, NULL, NULL, &fm_path_len, &fm_path)
2142
 
                                                        && fm_path != NULL)
2143
 
        {
2144
 
                /*  Zero-Terminate the string */
2145
 
                fm_path = g_realloc (fm_path, fm_path_len + 1);
2146
 
                fm_path[fm_path_len] = '\0';
2147
 
                no_uri_path = g_filename_from_uri ( (gchar*)fm_path, NULL, NULL );
2148
 
                /* g_message ("%s - %s",fm_path,no_uri_path); */
2149
 
                g_free ( fm_path );
2150
 
                if (no_uri_path == NULL)
2151
 
                {
2152
 
                        gtk_drag_finish (dc, FALSE, FALSE, t);
2153
 
                        return;
2154
 
                }
2155
 
                if ( archive[idx]->has_passwd )
2156
 
                {
2157
 
                        if ( archive[idx]->passwd == NULL)
2158
 
                        {
2159
 
                                archive[idx]->passwd = password_dialog ();
2160
 
                                if ( archive[idx]->passwd == NULL)
2161
 
                                {
2162
 
                                        gtk_drag_finish (dc, FALSE, FALSE, t);
2163
 
                                        return;
2164
 
                                }
2165
 
                        }
2166
 
                }
2167
 
                archive[idx]->extraction_path = extract_local_path ( no_uri_path );
2168
 
                g_free ( no_uri_path );
2169
 
                if (archive[idx]->extraction_path != NULL)
2170
 
                        to_send = "S";
2171
 
 
2172
 
                names = g_string_new ("");
2173
 
                gtk_tree_selection_selected_foreach (selection, (GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );
2174
 
                full_path = archive[idx]->full_path;
2175
 
                overwrite = archive[idx]->overwrite;
2176
 
                archive[idx]->full_path = 0;
2177
 
                archive[idx]->overwrite = 1;
2178
 
                command = xa_extract_single_files ( archive[idx] , names, archive[idx]->extraction_path );
2179
 
                g_string_free (names, TRUE);
2180
 
                if ( command != NULL )
2181
 
                {
2182
 
                        archive[idx]->status = XA_ARCHIVESTATUS_EXTRACT;
2183
 
                        xa_run_command ( command , 1);
2184
 
                        g_free (command);
2185
 
                }
2186
 
                archive[idx]->full_path = full_path;
2187
 
                archive[idx]->overwrite = overwrite;
2188
 
                gtk_selection_data_set (selection_data, selection_data->target, 8, (guchar*)to_send, 1);
2189
 
        }
2190
 
 
2191
 
        if (archive[idx]->extraction_path != NULL)
2192
 
        {
2193
 
                g_free (archive[idx]->extraction_path);
2194
 
                archive[idx]->extraction_path = NULL;
2195
 
        }
2196
 
        g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
2197
 
        g_list_free (row_list);
2198
 
        archive[idx]->status = XA_ARCHIVESTATUS_IDLE;
2199
 
}
2200
 
 
2201
 
void on_drag_data_received (GtkWidget *widget,GdkDragContext *context, int x,int y,GtkSelectionData *data, unsigned int info, unsigned int time, gpointer user_data)
2202
 
{
2203
 
        gchar **array = NULL;
2204
 
        gchar *filename = NULL;
2205
 
        gchar *command = NULL;
2206
 
        gchar *name = NULL;
2207
 
        gchar *_current_dir = NULL;
2208
 
        gchar *current_dir = NULL;
2209
 
        gboolean one_file;
2210
 
        gboolean dummy_password;
2211
 
        unsigned int len = 0;
2212
 
        gint current_page;
2213
 
        gint idx;
2214
 
 
2215
 
        current_page = gtk_notebook_get_current_page (notebook);
2216
 
        array = gtk_selection_data_get_uris ( data );
2217
 
        if (array == NULL || GTK_WIDGET_VISIBLE (viewport2) )
2218
 
        {
2219
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Sorry, I could not perform the operation!"),"" );
2220
 
                gtk_drag_finish (context, FALSE, FALSE, time);
2221
 
                return;
2222
 
        }
2223
 
        gtk_drag_finish (context, TRUE, FALSE, time);
2224
 
        one_file = (array[1] == NULL);
2225
 
 
2226
 
        if (one_file)
2227
 
        {
2228
 
                filename = g_filename_from_uri ( array[0] , NULL, NULL );
2229
 
                if ( filename == NULL)
2230
 
                        return;
2231
 
                else if ( xa_detect_archive_type ( NULL , filename ) > 0 )
2232
 
                {
2233
 
                        xa_open_archive ( NULL, filename );
2234
 
                        g_strfreev ( array );
2235
 
                        return;
2236
 
                }
2237
 
    }
2238
 
        if (current_page == -1)
2239
 
        {
2240
 
                idx = xa_get_new_archive_idx();
2241
 
                if (idx == -1)
2242
 
                        return;
2243
 
                archive[idx] = xa_new_archive_dialog ( filename );
2244
 
                if (archive[idx] == NULL)
2245
 
                        return;
2246
 
                xa_add_page (archive[idx]);
2247
 
        }
2248
 
        else
2249
 
                idx = xa_find_archive_index ( current_page );
2250
 
 
2251
 
        if (archive[idx]->type == XARCHIVETYPE_RAR && unrar)
2252
 
        {
2253
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't perform this action:"),_("unrar doesn't support archive creation!") );
2254
 
                return;
2255
 
        }
2256
 
 
2257
 
        if (archive[idx]->type == XARCHIVETYPE_DEB || archive[idx]->type == XARCHIVETYPE_RPM)
2258
 
        {
2259
 
                gchar *msg;
2260
 
                if (archive[idx]->type == XARCHIVETYPE_DEB)
2261
 
                        msg = _("You can't add content to deb packages!");
2262
 
                else
2263
 
                        msg = _("You can't add content to rpm packages!");
2264
 
                response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't perform this action:"), msg );
2265
 
                return;
2266
 
        }
2267
 
 
2268
 
        GString *names = g_string_new (" ");
2269
 
        _current_dir = g_path_get_dirname ( array[0] );
2270
 
        current_dir = g_filename_from_uri ( _current_dir, NULL, NULL );
2271
 
        g_free (_current_dir);
2272
 
        chdir ( current_dir );
2273
 
        g_free (current_dir);
2274
 
        archive[idx]->status = XA_ARCHIVESTATUS_ADD;
2275
 
 
2276
 
        while (array[len])
2277
 
        {
2278
 
                filename = g_filename_from_uri ( array[len] , NULL, NULL );
2279
 
                name = g_path_get_basename ( filename );
2280
 
                g_free (filename);
2281
 
                ConcatenateFileNames2 ( name, names );
2282
 
                g_free (name);
2283
 
                len++;
2284
 
        }
2285
 
        dummy_password = archive[idx]->has_passwd;
2286
 
        full_path = archive[idx]->full_path;
2287
 
        add_recurse = archive[idx]->add_recurse;
2288
 
 
2289
 
        archive[idx]->has_passwd = 0;
2290
 
        archive[idx]->full_path = 0;
2291
 
        archive[idx]->add_recurse = 1;
2292
 
 
2293
 
        command = xa_add_single_files ( archive[idx], names, NULL );
2294
 
 
2295
 
        archive[idx]->has_passwd = dummy_password;
2296
 
        archive[idx]->full_path = full_path;
2297
 
        archive[idx]->add_recurse = add_recurse;
2298
 
 
2299
 
        if (command != NULL)
2300
 
        {
2301
 
                gtk_widget_set_sensitive ( Stop_button , TRUE);
2302
 
                gtk_widget_set_sensitive ( check_menu , FALSE);
2303
 
                gtk_widget_set_sensitive ( close1 ,     FALSE);
2304
 
                gtk_widget_set_sensitive ( properties , FALSE);
2305
 
                xa_set_button_state (0,0,0,0,0,0);
2306
 
                xa_run_command (command , 1);
2307
 
                g_free (command);
2308
 
        }
2309
 
        g_string_free (names, TRUE);
2310
 
        g_strfreev ( array );
2311
 
 
2312
 
}
2313
 
 
2314
 
gboolean key_press_function (GtkWidget *widget, GdkEventKey *event, gpointer data)
2315
 
{
2316
 
    if (event == NULL) return FALSE;
2317
 
        switch (event->keyval)
2318
 
    {
2319
 
            case GDK_Escape:
2320
 
            if ( GTK_WIDGET_VISIBLE (viewport2) )
2321
 
                        xa_cancel_archive (NULL, NULL);
2322
 
            break;
2323
 
 
2324
 
            case GDK_Delete:
2325
 
        if ( GTK_WIDGET_STATE (Delete_button) != GTK_STATE_INSENSITIVE )
2326
 
                        xa_delete_archive ( NULL , NULL );
2327
 
                break;
2328
 
    }
2329
 
        return FALSE;
2330
 
}
2331
 
 
2332
 
void xa_select_all ( GtkMenuItem *menuitem , gpointer user_data )
2333
 
{
2334
 
        gint idx;
2335
 
        gint current_page;
2336
 
 
2337
 
        current_page = gtk_notebook_get_current_page (notebook);
2338
 
        idx = xa_find_archive_index (current_page);
2339
 
 
2340
 
        current_page = gtk_notebook_get_current_page (notebook);
2341
 
        gtk_tree_selection_select_all ( gtk_tree_view_get_selection (GTK_TREE_VIEW (archive[idx]->treeview) ) );
2342
 
        gtk_widget_set_sensitive (select_all,FALSE);
2343
 
        gtk_widget_set_sensitive (deselect_all,TRUE);
2344
 
}
2345
 
 
2346
 
void xa_deselect_all ( GtkMenuItem *menuitem , gpointer user_data )
2347
 
{
2348
 
        gint current_page;
2349
 
        gint idx;
2350
 
 
2351
 
        current_page = gtk_notebook_get_current_page (notebook);
2352
 
        idx = xa_find_archive_index (current_page);
2353
 
 
2354
 
        gtk_tree_selection_unselect_all ( gtk_tree_view_get_selection (GTK_TREE_VIEW (archive[idx]->treeview) ) );
2355
 
        gtk_widget_set_sensitive (select_all,TRUE);
2356
 
        gtk_widget_set_sensitive (deselect_all,FALSE);
2357
 
}
2358
 
 
2359
 
void xa_activate_link (GtkAboutDialog *about, const gchar *link, gpointer data)
2360
 
{
2361
 
        GdkScreen *screen;
2362
 
        GtkWidget *message;
2363
 
        GError *error = NULL;
2364
 
        gchar *argv[3];
2365
 
        gchar *browser_path;
2366
 
 
2367
 
        browser_path = g_find_program_in_path ("firefox");
2368
 
        if ( browser_path == NULL)
2369
 
                browser_path = g_find_program_in_path ("opera");
2370
 
 
2371
 
        if ( browser_path == NULL)
2372
 
                browser_path = g_find_program_in_path ("mozilla");
2373
 
 
2374
 
        argv[0] = browser_path;
2375
 
        argv[1] = (gchar *) link;
2376
 
        argv[2] = NULL;
2377
 
 
2378
 
        if (about == NULL)
2379
 
                screen = gtk_widget_get_screen (GTK_WIDGET (MainWindow));
2380
 
        else
2381
 
                screen = gtk_widget_get_screen (GTK_WIDGET (about));
2382
 
 
2383
 
        if (!gdk_spawn_on_screen (screen, NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error))
2384
 
        {
2385
 
                message = gtk_message_dialog_new (GTK_WINDOW (about),
2386
 
                                                                                GTK_DIALOG_MODAL
2387
 
                                                                                | GTK_DIALOG_DESTROY_WITH_PARENT,
2388
 
                                                                                GTK_MESSAGE_ERROR,
2389
 
                                                                                GTK_BUTTONS_CLOSE,
2390
 
                                                                                _("Failed to open link."));
2391
 
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (message), "%s.", error->message);
2392
 
                gtk_dialog_run (GTK_DIALOG (message));
2393
 
                gtk_widget_destroy (message);
2394
 
                g_error_free (error);
2395
 
        }
2396
 
        if (browser_path != NULL)
2397
 
                g_free (browser_path);
2398
 
}
2399
 
 
2400
 
void xa_show_help (GtkMenuItem *menuitem , gpointer user_data )
2401
 
{
2402
 
        gchar *uri = g_strconcat ("file://", DATADIR, "/doc/", PACKAGE, "/html/index.html", NULL);
2403
 
        xa_activate_link (NULL,uri,NULL);
2404
 
        g_free (uri);
2405
 
}
2406
 
 
2407
 
void xa_reset_password (GtkMenuItem *menuitem , gpointer user_data )
2408
 
{
2409
 
        gint current_page;
2410
 
        gint idx;
2411
 
 
2412
 
        current_page = gtk_notebook_get_current_page(notebook);
2413
 
        idx = xa_find_archive_index ( current_page );
2414
 
 
2415
 
        if (archive[idx] == NULL)
2416
 
                return;
2417
 
 
2418
 
        if (archive[idx]->passwd != NULL)
2419
 
        {
2420
 
                g_free (archive[idx]->passwd);
2421
 
                archive[idx]->passwd = NULL;
2422
 
                Update_StatusBar (_("The password has been reset."));
2423
 
        }
2424
 
        else
2425
 
                Update_StatusBar (_("Please enter the password first!"));
2426
 
}
2427
 
 
2428
 
void xa_show_archive_comment ( GtkMenuItem *menuitem , gpointer user_data )
2429
 
{
2430
 
        GtkWidget *comment_window;
2431
 
        gint current_page;
2432
 
        gint idx;
2433
 
 
2434
 
        current_page = gtk_notebook_get_current_page(notebook);
2435
 
        idx = xa_find_archive_index (current_page);
2436
 
        comment_window = view_win ( _("Archive comment window") );
2437
 
        gtk_text_buffer_create_tag (viewtextbuf, "bold","weight", PANGO_WEIGHT_BOLD, NULL);
2438
 
        gtk_text_buffer_insert (viewtextbuf, &viewenditer, "\n", 1);
2439
 
        gtk_text_buffer_insert_with_tags_by_name (viewtextbuf, &viewenditer, archive[idx]->comment->str, archive[idx]->comment->len, "bold", NULL);
2440
 
        gtk_widget_show (comment_window);
2441
 
}
2442