2
* Copyright (C) 2006 Giuseppe Torelli - <colossus73@gmail.com>
3
* Copyright (C) 2006 Benedikt Meurer - <benny@xfce.org>
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.
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.
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.
24
#include "callbacks.h"
25
#include "string_utils.h"
26
#include "interface.h"
30
#include "new_dialog.h"
32
extern GList *ArchiveType;
33
extern GList *ArchiveSuffix;
35
extern gboolean stop_flag;
36
extern gboolean unrar;
38
gchar *current_open_directory = NULL;
39
GtkFileFilter *open_file_filter = NULL;
40
GList *Suffix , *Name;
42
void xa_watch_child ( GPid pid, gint status, gpointer data)
44
XArchive *archive = data;
46
gboolean open = FALSE;
48
gboolean extract= FALSE;
50
gboolean select = FALSE;
51
gboolean check = FALSE;
52
gboolean info = FALSE;
53
gboolean waiting = TRUE;
56
if (archive->has_comment)
57
gtk_widget_set_sensitive (comment_menu,TRUE);
59
gtk_widget_set_sensitive (comment_menu,FALSE);
61
if (archive->has_comment && archive->status == XA_ARCHIVESTATUS_OPEN)
62
xa_show_archive_comment ( NULL, NULL);
64
gtk_widget_set_sensitive (close1,TRUE);
65
if ( archive->type == XARCHIVETYPE_BZIP2 || archive->type == XARCHIVETYPE_GZIP )
70
else if (archive->type == XARCHIVETYPE_RPM || archive->type == XARCHIVETYPE_DEB)
72
new = open = extract = select = info = TRUE;
75
else if (archive->type == XARCHIVETYPE_TAR_BZ2 || archive->type == XARCHIVETYPE_TAR_GZ || archive->type == XARCHIVETYPE_TAR )
77
new = open = add = extract = select = info = TRUE;
80
else if (archive->type == XARCHIVETYPE_LHA)
82
new = open = add = extract = select = info = TRUE;
86
else if (archive->type == XARCHIVETYPE_RAR && unrar)
90
new = open = extract = select = info = TRUE;
95
new = open = add = extract = exe = select = info = TRUE;
97
if ( WIFSIGNALED (status) )
99
Update_StatusBar ( _("Operation canceled."));
100
if (archive->status == XA_ARCHIVESTATUS_EXTRACT)
102
gchar *msg = g_strdup_printf(_("Please check \"%s\" since some files could have been already extracted."),archive->extraction_path);
104
response = ShowGtkMessageDialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO, GTK_BUTTONS_OK,"",msg );
107
else if (archive->status == XA_ARCHIVESTATUS_OPEN)
108
gtk_widget_set_sensitive ( check_menu , FALSE );
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);
117
if ( WIFEXITED (status) )
119
if ( WEXITSTATUS (status) )
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)
132
g_free (archive->passwd);
133
archive->passwd = NULL;
139
if (archive->status == XA_ARCHIVESTATUS_SFX && archive->type == XARCHIVETYPE_RAR)
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 );
146
if (archive->status == XA_ARCHIVESTATUS_TEST)
147
xa_show_cmd_line_output (NULL);
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)
153
if (archive->type == XARCHIVETYPE_BZIP2 || archive->type == XARCHIVETYPE_GZIP)
154
Update_StatusBar ( _("Operation completed."));
157
Update_StatusBar ( _("Please wait while the content of the archive is being updated..."));
160
switch ( archive->type )
162
case XARCHIVETYPE_RAR:
166
case XARCHIVETYPE_TAR:
170
case XARCHIVETYPE_TAR_BZ2:
171
OpenBzip2 ( archive );
174
case XARCHIVETYPE_TAR_GZ:
175
OpenGzip ( archive );
178
case XARCHIVETYPE_ZIP:
182
case XARCHIVETYPE_7ZIP:
183
Open7Zip ( archive );
186
case XARCHIVETYPE_ARJ:
190
case XARCHIVETYPE_LHA:
197
archive->status = XA_ARCHIVESTATUS_IDLE;
200
ps = waitpid ( archive->child_pid, &status, WNOHANG);
204
gtk_main_iteration_do (FALSE);
209
if (! cli && archive != NULL)
211
if ( archive->has_passwd == FALSE && archive->passwd == NULL)
213
gtk_widget_hide ( viewport3 );
214
gtk_widget_set_sensitive ( password_entry , FALSE);
218
gtk_widget_show ( pad_image );
219
gtk_widget_show ( viewport3 );
220
gtk_widget_set_sensitive ( password_entry , TRUE);
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);
228
gtk_widget_grab_focus (GTK_WIDGET(archive->treeview));
229
Update_StatusBar ( _("Operation completed."));
232
void xa_new_archive (GtkMenuItem *menuitem, gpointer user_data)
236
current_page = xa_get_new_archive_idx();
237
if (current_page == -1)
240
archive[current_page] = xa_new_archive_dialog ( NULL );
242
if (archive[current_page] == NULL)
245
xa_add_page (archive[current_page]);
247
xa_set_button_state (1,1,1,0,0,0 );
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 ();
257
Update_StatusBar ( _("Choose Add to begin creating the archive."));
258
gtk_tooltips_disable ( pad_tooltip );
259
gtk_widget_hide ( pad_image );
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 );
269
int ShowGtkMessageDialog ( GtkWindow *window, int mode,int type,int button, const gchar *message1,const gchar *message2)
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) );
279
void xa_open_archive (GtkMenuItem *menuitem, gpointer data)
284
path = (gchar *)data;
287
path = xa_open_file_dialog ();
292
/* Let's check if the archive is already opened */
293
for (x = 0; x < gtk_notebook_get_n_pages ( notebook) ; x++)
295
current_page = xa_find_archive_index ( x );
296
if (current_page == -1)
298
if (strcmp (path,archive[current_page]->path) == 0)
302
current_page = xa_get_new_archive_idx();
303
if (current_page == -1)
306
archive[current_page] = xa_init_archive_structure();
307
if (archive[current_page] == NULL)
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!");
314
archive[current_page]->path = g_strdup (path);
315
archive[current_page]->escaped_path = EscapeBadChars ( archive[current_page]->path , "$\'`\"\\!?* ()&|@#:;" );
317
xa_add_page (archive[current_page]);
319
OffDeleteandViewButtons();
320
gtk_widget_set_sensitive ( iso_info , FALSE );
321
gtk_widget_set_sensitive ( view_shell_output1 , TRUE );
323
archive[current_page]->type = xa_detect_archive_type ( archive[current_page] , NULL );
324
if ( archive[current_page]->type == -2 )
326
xa_close_archive ( NULL, NULL);
327
xa_set_button_state (1,1,0,0,0,0);
330
if ( archive[current_page]->type == -1 )
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 );
350
//Does the user open an archive from the command line whose archiver is not installed ?
352
if ( archive[current_page]->type == XARCHIVETYPE_RAR )
354
else if ( archive[current_page]->type == XARCHIVETYPE_7ZIP )
356
else if ( archive[current_page]->type == XARCHIVETYPE_ARJ )
358
else if ( archive[current_page]->type == XARCHIVETYPE_LHA )
361
if ( ! g_list_find ( ArchiveType , ext ) )
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!") );
367
gtk_widget_set_sensitive (Stop_button,TRUE);
368
gtk_widget_show ( viewport2 );
370
if ( archive[current_page]->type == XARCHIVETYPE_ISO )
371
Update_StatusBar ( _("Please wait while the content of the ISO image is being read..."));
373
Update_StatusBar ( _("Please wait while the content of the archive is being read..."));
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 )
382
case XARCHIVETYPE_ARJ:
383
OpenArj (archive[current_page]);
386
case XARCHIVETYPE_DEB:
387
OpenDeb (archive[current_page]);
390
case XARCHIVETYPE_BZIP2:
391
OpenBzip2 (archive[current_page]);
394
case XARCHIVETYPE_GZIP:
395
OpenGzip ( archive[current_page] );
398
case XARCHIVETYPE_ISO:
399
OpenISO (archive[current_page]);
402
case XARCHIVETYPE_RAR:
403
OpenRar (archive[current_page]);
406
case XARCHIVETYPE_RPM:
407
OpenRPM (archive[current_page]);
410
case XARCHIVETYPE_TAR:
411
OpenTar (archive[current_page]);
414
case XARCHIVETYPE_ZIP:
415
OpenZip (archive[current_page]);
418
case XARCHIVETYPE_7ZIP:
419
Open7Zip (archive[current_page]);
422
case XARCHIVETYPE_LHA:
423
OpenLha (archive[current_page]);
429
archive[current_page]->passwd = NULL;
432
void xa_test_archive (GtkMenuItem *menuitem, gpointer user_data)
439
current_page = gtk_notebook_get_current_page (notebook);
440
id = xa_find_archive_index ( current_page );
445
if ( archive[id]->has_passwd )
447
if ( archive[id]->passwd == NULL)
449
archive[id]->passwd = password_dialog ();
450
if ( archive[id]->passwd == NULL)
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 )
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);
464
command = g_strconcat (rar," t -idp " , archive[id]->escaped_path, NULL);
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);
471
command = g_strconcat ("unzip -t " , archive[id]->escaped_path, NULL);
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);
478
command = g_strconcat ("7za t " , archive[id]->escaped_path, NULL);
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);
485
command = g_strconcat ("arj t -i " , archive[id]->escaped_path, NULL);
488
case XARCHIVETYPE_LHA:
489
command = g_strconcat ("lha t " , archive[id]->escaped_path, NULL);
495
archive[id]->status = XA_ARCHIVESTATUS_TEST;
496
xa_run_command ( command , 1);
500
void xa_close_archive (GtkMenuItem *menuitem, gpointer user_data)
504
GtkWidget *scrollwindow = user_data;
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);
510
current_page = gtk_notebook_get_n_pages(notebook);
511
if ( current_page == 0)
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);
520
else if ( current_page == 1)
521
gtk_notebook_set_show_tabs (notebook,FALSE);
523
gtk_notebook_set_show_tabs (notebook,TRUE);
526
xa_clean_archive_structure (archive[idx]);
528
gtk_widget_hide ( viewport3 );
529
Update_StatusBar (_("Ready."));
532
void xa_quit_application (GtkMenuItem *menuitem, gpointer user_data)
537
if ( GTK_WIDGET_VISIBLE (viewport2 ) )
539
Update_StatusBar ( _("Please hit the Stop button first!"));
542
g_list_free ( Suffix );
543
g_list_free ( Name );
545
for (i = 0; i < gtk_notebook_get_n_pages(notebook) ; i++)
547
idx = xa_find_archive_index ( i );
548
if (archive[idx] != NULL)
549
xa_clean_archive_structure (archive[idx]);
552
if (current_open_directory != NULL)
553
g_free (current_open_directory);
561
void xa_delete_archive (GtkMenuItem *menuitem, gpointer user_data)
563
gchar *command = NULL;
570
current_page = gtk_notebook_get_current_page ( notebook);
571
id = xa_find_archive_index ( current_page);
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 );
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?") );
582
if ( response == GTK_RESPONSE_NO)
585
Update_StatusBar ( _("Deleting files from the archive, please wait..."));
586
archive[id]->status = XA_ARCHIVESTATUS_DELETE;
588
tar = g_find_program_in_path ("gtar");
590
tar = g_strdup ("tar");
592
switch (archive[id]->type)
594
case XARCHIVETYPE_RAR:
595
command = g_strconcat ( "rar d " , archive[id]->escaped_path , names->str , NULL );
598
case XARCHIVETYPE_TAR:
599
command = g_strconcat (tar, " --delete -vf " , archive[id]->escaped_path , names->str , NULL );
602
case XARCHIVETYPE_TAR_BZ2:
603
xa_add_delete_tar_bzip2_gzip ( names , archive[id] , 0 , 0 );
606
case XARCHIVETYPE_TAR_GZ:
607
xa_add_delete_tar_bzip2_gzip ( names , archive[id] , 1 , 0 );
610
case XARCHIVETYPE_ZIP:
611
command = g_strconcat ( "zip -d " , archive[id]->escaped_path , names->str , NULL );
614
case XARCHIVETYPE_7ZIP:
615
command = g_strconcat ( "7za d " , archive[id]->escaped_path , names->str , NULL );
618
case XARCHIVETYPE_ARJ:
619
command = g_strconcat ( "arj d " , archive[id]->escaped_path , names->str, NULL);
622
case XARCHIVETYPE_LHA:
623
command = g_strconcat("lha d ", archive[id]->escaped_path, names->str, NULL);
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);
636
g_string_free (names , TRUE );
640
void xa_add_files_archive ( GtkMenuItem *menuitem, gpointer data )
642
gchar *command = NULL;
646
current_page = gtk_notebook_get_current_page (notebook);
647
idx = xa_find_archive_index ( current_page );
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 );
654
xa_run_command (command , 1);
657
g_free ( add_window );
661
void xa_extract_archive ( GtkMenuItem *menuitem , gpointer user_data )
663
gchar *command = NULL;
667
current_page = gtk_notebook_get_current_page (notebook);
668
idx = xa_find_archive_index ( current_page );
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)
678
gtk_widget_destroy ( extract_window->dialog1 );
679
extract_window->dialog1 = NULL;
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);
691
g_free (extract_window);
692
extract_window = NULL;
695
void xa_convert_sfx ( GtkMenuItem *menuitem , gpointer user_data )
697
gchar *command = NULL;
699
unsigned short int l = 0;
703
current_page = gtk_notebook_get_current_page (notebook);
704
idx = xa_find_archive_index ( current_page );
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 )
711
case XARCHIVETYPE_RAR:
713
command = g_strconcat ("rar s -o+ " , archive[idx]->escaped_path , NULL);
714
if (strstr(archive[idx]->escaped_path,".rar") )
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';
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;
735
case XARCHIVETYPE_ZIP:
737
gchar *archive_name = NULL;
738
gchar *archive_name_escaped = NULL;
740
FILE *archive_not_sfx;
743
GError *error = NULL;
744
gchar *unzipsfx_path = NULL;
747
archive_name = xa_open_sfx_file_selector ();
749
if (archive_name == NULL)
751
gtk_widget_set_sensitive (Stop_button,FALSE);
752
Update_StatusBar ( _("Operation canceled."));
755
archive_name_escaped = EscapeBadChars ( archive_name ,"$\'`\"\\!?* ()[]&|@#:;" );
756
unzipsfx_path = g_find_program_in_path ( "unzipsfx" );
757
if ( unzipsfx_path != NULL )
759
/* Load the unzipsfx executable in memory, about 50 KB */
760
result = g_file_get_contents (unzipsfx_path,&content,&length,&error);
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);
770
g_free (unzipsfx_path);
772
/* Write unzipsfx to a new file */
773
sfx_archive = g_fopen ( archive_name ,"w" );
774
if (sfx_archive == NULL)
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) );
781
archive_not_sfx = g_fopen ( archive[idx]->path ,"r" );
782
fwrite (content, 1, length, sfx_archive);
785
/* Read archive data and write it after the sfx module in the new file */
786
while ( ! feof(archive_not_sfx) )
788
fread (&buffer, 1, 1024, archive_not_sfx);
789
fwrite (&buffer, 1, 1024, sfx_archive);
791
fclose (archive_not_sfx);
792
fclose (sfx_archive);
794
command = g_strconcat ("chmod 755 ", archive_name_escaped , NULL);
795
result = xa_run_command (command , 0);
798
command = g_strconcat ("zip -A ",archive_name_escaped,NULL);
799
result = xa_run_command (command , 1);
803
g_free (archive_name);
804
g_free (archive_name_escaped);
808
case XARCHIVETYPE_7ZIP:
810
gchar *archive_name = NULL;
811
gchar *archive_name_escaped = NULL;
813
FILE *archive_not_sfx;
816
GError *error = NULL;
817
gchar *sfx_path = NULL;
820
GtkWidget *locate_7zcon = NULL;
821
GtkFileFilter *sfx_filter;
823
archive_name = xa_open_sfx_file_selector ();
825
if (archive_name == NULL)
827
gtk_widget_set_sensitive (Stop_button,FALSE);
828
Update_StatusBar ( _("Operation canceled."));
831
archive_name_escaped = EscapeBadChars ( archive_name ,"$\'`\"\\!?* ()[]&|@#:;" );
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");
841
sfx_filter = gtk_file_filter_new ();
842
gtk_file_filter_set_name (sfx_filter, "" );
843
gtk_file_filter_add_pattern (sfx_filter, "*.sfx" );
845
locate_7zcon = gtk_file_chooser_dialog_new ( _("Please select the 7zCon.sfx module"),
846
GTK_WINDOW (MainWindow),
847
GTK_FILE_CHOOSER_ACTION_OPEN,
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)
859
sfx_path = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (locate_7zcon) );
860
gtk_widget_destroy ( locate_7zcon );
864
gtk_widget_destroy ( locate_7zcon );
865
Update_StatusBar (_("Operation canceled."));
866
xa_hide_progress_bar_stop_button (archive[idx]);
870
if ( sfx_path != NULL )
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);
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);
885
/* Write 7zCon.sfx to a new file */
886
sfx_archive = g_fopen ( archive_name ,"w" );
887
if (sfx_archive == NULL)
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) );
894
archive_not_sfx = g_fopen ( archive[idx]->path ,"r" );
895
fwrite (content, 1, length, sfx_archive);
898
/* Read archive data and write it after the sfx module in the new file */
899
while ( ! feof(archive_not_sfx) )
901
fread (&buffer, 1, 1024, archive_not_sfx);
902
fwrite (&buffer, 1, 1024, sfx_archive);
904
fclose (archive_not_sfx);
905
fclose (sfx_archive);
907
command = g_strconcat ("chmod 755 ", archive_name_escaped , NULL);
908
result = xa_run_command (command , 1);
912
g_free (archive_name);
913
g_free (archive_name_escaped);
917
case XARCHIVETYPE_ARJ:
918
command = g_strconcat ("arj y -je1 " , archive[idx]->escaped_path, NULL);
926
xa_run_command ( command , 1);
931
void xa_about (GtkMenuItem *menuitem, gpointer user_data)
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};
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);
945
"version", PACKAGE_VERSION,
946
"copyright", "Copyright \xC2\xA9 2005-2006 Giuseppe Torelli",
947
"comments", "A lightweight GTK+2 archive manager",
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"
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"
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",
969
gtk_window_set_position (GTK_WINDOW (about), GTK_WIN_POS_CENTER);
971
gtk_dialog_run ( GTK_DIALOG(about) );
972
gtk_widget_hide (about);
975
gchar *xa_open_sfx_file_selector ()
977
gchar *sfx_name = NULL;
978
GtkWidget *sfx_file_selector = NULL;
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,
990
gtk_dialog_set_default_response (GTK_DIALOG (sfx_file_selector), GTK_RESPONSE_ACCEPT);
991
response = gtk_dialog_run ( GTK_DIALOG(sfx_file_selector) );
993
if (response == GTK_RESPONSE_ACCEPT)
994
sfx_name = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER (sfx_file_selector) );
996
gtk_widget_destroy (sfx_file_selector);
1000
gchar *xa_open_file_dialog ()
1002
static GtkWidget *File_Selector = NULL;
1003
GtkFileFilter *filter;
1006
if (File_Selector == NULL)
1008
File_Selector = gtk_file_chooser_dialog_new ( _("Open an archive"),
1009
GTK_WINDOW (MainWindow),
1010
GTK_FILE_CHOOSER_ACTION_OPEN,
1012
GTK_RESPONSE_CANCEL,
1014
GTK_RESPONSE_ACCEPT,
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);
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);
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 )
1030
gtk_file_filter_add_pattern (filter, Suffix->data);
1031
Suffix = g_list_next ( Suffix );
1033
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (File_Selector), filter);
1035
Suffix = g_list_first ( ArchiveSuffix );
1036
while ( Suffix != NULL )
1038
if ( Suffix->data != "" ) /* To avoid double filtering when opening the archive */
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);
1045
Suffix = g_list_next ( Suffix );
1047
gtk_window_set_modal (GTK_WINDOW (File_Selector),TRUE);
1049
if (open_file_filter != NULL)
1050
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (File_Selector) , open_file_filter );
1052
if (current_open_directory != NULL)
1053
gtk_file_chooser_set_current_folder ( GTK_FILE_CHOOSER (File_Selector) , current_open_directory );
1055
response = gtk_dialog_run (GTK_DIALOG (File_Selector));
1057
if (current_open_directory != NULL)
1058
g_free (current_open_directory);
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) );
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) )
1068
/* Hiding the window instead of destroying it will preserve the pointers to the file chooser stuff */
1069
gtk_widget_hide (File_Selector);
1073
gboolean isISO ( FILE *ptr )
1076
if ((offset_image = DetectImage(ptr)) > 0 )
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);
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]);
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]);
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]);
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]);
1099
gboolean isTar ( FILE *ptr )
1101
unsigned char magic[7];
1102
fseek ( ptr, 0 , SEEK_SET );
1103
if ( fseek ( ptr , 257 , SEEK_CUR) < 0 )
1105
if ( fread ( magic, 1, 7, ptr ) == 0 )
1107
if ( memcmp ( magic,"\x75\x73\x74\x61\x72\x00\x30",7 ) == 0 || memcmp (magic,"\x75\x73\x74\x61\x72\x20\x20",7 ) == 0)
1113
gboolean isLha ( FILE *ptr )
1115
unsigned char magic[2];
1116
fseek(ptr, 0, SEEK_SET);
1117
if(fseek(ptr, 19, SEEK_CUR) < 0)
1119
if(fread(magic, 1, 2, ptr) == 0)
1122
if(magic[0] == 0x20 && magic[1] <= 0x03)
1132
int xa_detect_archive_type ( XArchive *archive , gchar *filename )
1134
FILE *dummy_ptr = NULL;
1136
unsigned char magic[12];
1137
if (filename != NULL)
1138
dummy_ptr = fopen ( filename , "r" );
1140
dummy_ptr = fopen ( archive->path , "r" );
1142
if (dummy_ptr == NULL)
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));
1158
if ( fread ( magic, 1, 12, dummy_ptr ) == 0 )
1160
fclose ( dummy_ptr);
1164
if ( memcmp ( magic,"\x50\x4b\x03\x04",4 ) == 0 || memcmp ( magic,"\x50\x4b\x05\x06",4 ) == 0 )
1166
if (archive != NULL)
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 );
1171
xx = XARCHIVETYPE_ZIP;
1173
else if ( memcmp ( magic,"\x60\xea",2 ) == 0 )
1175
if (archive != NULL)
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 );
1180
xx = XARCHIVETYPE_ARJ;
1182
else if ( memcmp ( magic,"\x52\x61\x72\x21",4 ) == 0 )
1184
if (archive != NULL)
1185
archive->has_comment = xa_detect_archive_comment ( XARCHIVETYPE_RAR , dummy_ptr, archive );
1186
xx = XARCHIVETYPE_RAR;
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 );
1201
gboolean xa_detect_archive_comment ( int type, FILE *stream, XArchive *archive )
1205
unsigned char eocds[] = { 0x50, 0x4b, 0x05, 0x06 };
1207
unsigned long long int eocds_position = 0;
1209
unsigned short int len = 0;
1213
if (type == XARCHIVETYPE_ZIP)
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) )
1222
byte = (eof = fgetc(stream));
1225
if (byte == eocds[seqptr])
1227
if (++seqptr == sizeof(eocds))
1229
eocds_position = ftell(stream) + 16 ;
1240
fseek (stream,eocds_position,SEEK_SET);
1241
fread (&len,1,2,stream);
1246
archive->comment = g_string_new("");
1247
while (cmt_len != len)
1249
fread (&sig,1,1,stream);
1250
g_string_append (archive->comment,&sig);
1256
else if (type == XARCHIVETYPE_ARJ)
1258
/* Let's avoid the archive name */
1259
fseek ( stream, 39 , SEEK_SET );
1262
fread (&sig,1,1,stream);
1265
fseek ( stream, 39 + cmt_len , SEEK_SET );
1267
/* Let's read the archive comment byte after byte now */
1268
archive->comment = g_string_new("");
1271
fread (&sig,1,1,stream);
1273
if (sig == 0 && archive->comment->len == 0)
1275
g_string_free (archive->comment,FALSE);
1276
archive->comment = NULL;
1280
g_string_append (archive->comment,&sig);
1284
else if (type == XARCHIVETYPE_RAR)
1290
gboolean xa_detect_encrypted_archive ( int type, FILE *stream, unsigned char magic[6] )
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;
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;
1306
fseek ( stream, 6 , SEEK_SET );
1307
if ( type == XARCHIVETYPE_ZIP )
1309
while ( memcmp ( magic,"\x50\x4b\x03\x04",4 ) == 0 || memcmp ( magic,"\x50\x4b\x05\x06",4 ) == 0 )
1311
fread ( &password_flag, 1, 2, stream );
1312
if (( password_flag & ( 1<<0) ) > 0)
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 )
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);
1327
else if ( type == XARCHIVETYPE_ARJ)
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)
1337
fread ( &basic_header_size , 1 , 2 , stream );
1338
if ( basic_header_size == 0 )
1340
fseek ( stream , 4 , SEEK_CUR);
1341
fread (&arj_flag,1,1,stream);
1342
if ((arj_flag & ( 1<<0) ) > 0)
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);
1358
void xa_remove_columns()
1363
current_page = gtk_notebook_get_current_page (notebook);
1364
idx = xa_find_archive_index (current_page);
1366
GList *columns = gtk_tree_view_get_columns ( GTK_TREE_VIEW (archive[idx]->treeview) );
1367
while (columns != NULL)
1369
gtk_tree_view_remove_column (GTK_TREE_VIEW (archive[idx]->treeview) , columns->data);
1370
columns = columns->next;
1372
g_list_free (columns);
1375
void EmptyTextBuffer ()
1377
if (textbuf != NULL)
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);
1386
void xa_create_liststore ( unsigned short int nc, gchar *columns_names[] , GType columns_types[], XArchive *archive)
1388
unsigned short int x;
1389
GtkCellRenderer *renderer;
1390
GtkTreeViewColumn *column;
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) );
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);
1399
for (x = 0; x <= nc-1; x++)
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);
1409
gboolean treeview_select_search (GtkTreeModel *model,gint column,const gchar *key,GtkTreeIter *iter,gpointer search_data)
1414
gtk_tree_model_get (model, iter, 0, &filename, -1);
1415
if ( strcasestr (filename, key) ) result = FALSE;
1421
void xa_show_cmd_line_output( GtkMenuItem *menuitem )
1423
if (OutputWindow != NULL)
1425
gtk_window_set_title (GTK_WINDOW (OutputWindow), _("Command line output") );
1426
gtk_window_present ( GTK_WINDOW (OutputWindow) );
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);
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);
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);
1448
gtk_widget_show (vbox);
1449
gtk_widget_show (scrollwin);
1450
gtk_widget_show (textview);
1453
void xa_cancel_archive ( GtkMenuItem *menuitem , gpointer data )
1458
current_page = gtk_notebook_get_current_page(notebook);
1459
idx = xa_find_archive_index (current_page);
1461
if (archive[idx]->status == XA_ARCHIVESTATUS_ADD || archive[idx]->status == XA_ARCHIVESTATUS_SFX)
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)
1467
xa_hide_progress_bar_stop_button (archive[idx]);
1468
Update_StatusBar (_("Waiting for the process to abort..."));
1470
if (archive[idx]->type != XARCHIVETYPE_ISO)
1472
if ( kill ( archive[idx]->child_pid , SIGABRT ) < 0 )
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));
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;
1484
void xa_view_file_inside_archive ( GtkMenuItem *menuitem , gpointer user_data )
1486
gchar *filename = NULL;
1487
GError *error = NULL;
1488
gchar *string = NULL;
1489
gchar *command = NULL;
1490
GtkTreeSelection *selection;
1491
GtkTreeModel *model;
1495
unsigned short int COL_NAME;
1496
gboolean is_dir = FALSE;
1497
gboolean tofree = FALSE;
1498
gboolean result = FALSE;
1499
GList *row_list = NULL;
1508
current_page = gtk_notebook_get_current_page (notebook);
1509
idx = xa_find_archive_index (current_page);
1511
if ( archive[idx]->has_passwd )
1513
if ( archive[idx]->passwd == NULL)
1515
archive[idx]->passwd = password_dialog ();
1516
if ( archive[idx]->passwd == NULL)
1520
selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (archive[idx]->treeview) );
1522
/* if no or more than one rows selected, do nothing, just for sanity */
1523
if ( gtk_tree_selection_count_selected_rows (selection) != 1)
1526
row_list = gtk_tree_selection_get_selected_rows (selection, &model);
1527
if ( row_list == NULL )
1530
gtk_tree_model_get_iter(model, &iter, row_list->data);
1532
gtk_tree_path_free(row_list->data);
1533
g_list_free (row_list);
1535
switch (archive[idx]->type)
1537
case XARCHIVETYPE_RAR:
1538
case XARCHIVETYPE_ARJ:
1542
case XARCHIVETYPE_ZIP:
1546
case XARCHIVETYPE_7ZIP:
1553
gtk_tree_model_get (model, &iter, COL_NAME, &dir, -1);
1554
if (archive[idx]->type == XARCHIVETYPE_ZIP)
1556
if ( g_str_has_suffix (dir,"/") == TRUE )
1559
else if ( strstr ( dir , "d" ) || strstr ( dir , "D" ) ) is_dir = TRUE;
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!") );
1568
full_path = archive[idx]->full_path;
1569
overwrite = archive[idx]->overwrite;
1571
archive[idx]->full_path = 0;
1572
archive[idx]->overwrite = 1;
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 );
1579
if (archive[idx]->type == XARCHIVETYPE_ISO)
1581
gtk_tree_model_get (model, &iter,
1587
xa_extract_iso_file (archive[idx], permissions, "/tmp/", dummy_name , file_size, file_offset );
1588
g_free (permissions);
1591
command = xa_extract_single_files ( archive[idx] , names, "/tmp");
1593
archive[idx]->full_path = full_path;
1594
archive[idx]->overwrite = overwrite;
1596
if (command != NULL)
1598
result = xa_run_command (command , 0);
1602
unlink (dummy_name);
1603
g_free (dummy_name);
1604
g_string_free (names,TRUE);
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 );
1615
if ( strchr ( string , ' ' ) )
1617
string = RemoveBackSlashes ( string );
1620
filename = g_strconcat ( "/tmp" , string , NULL );
1624
g_free (dummy_name);
1626
result = g_file_get_contents (filename,&content,&length,&error);
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);
1637
t = g_locale_to_utf8 ( content, length, NULL, &new_length, &error);
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);
1646
gtk_widget_show (view_window);
1647
gtk_text_buffer_insert (viewtextbuf, &viewenditer, t, new_length );
1649
unlink ( filename );
1651
xa_hide_progress_bar_stop_button(archive[idx]);
1652
Update_StatusBar (_("Operation completed."));
1655
void xa_iso_properties ( GtkMenuItem *menuitem , gpointer user_data )
1657
gchar *utf8_string, *text, *measure;
1658
unsigned long long int file_size;
1659
GtkWidget *iso_properties_win;
1663
current_page = gtk_notebook_get_current_page (notebook);
1664
idx = xa_find_archive_index (current_page);
1666
stat ( archive[idx]->path , &my_stat );
1667
file_size = my_stat.st_size;
1668
iso_properties_win = create_iso_properties_window();
1670
text = g_strrstr ( archive[idx]->path, "/" );
1673
text++; //This to avoid the / char in the string
1674
utf8_string = g_filename_display_name (text);
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);
1681
if (file_size > 1024*1024*1024 )
1683
content_size = (double)file_size / (1024*1024*1024);
1686
else if (file_size > 1024*1024 )
1688
content_size = (double)file_size / (1024*1024);
1692
else if (file_size > 1024 )
1694
content_size = (double)file_size / 1024;
1699
measure = _(" bytes");
1700
content_size = file_size;
1703
text = g_strdup_printf ("%.1f %s", content_size,measure);
1704
gtk_entry_set_text ( GTK_ENTRY (size_entry), text );
1707
gtk_entry_set_text ( GTK_ENTRY (image_type_entry),archive[idx]->tmp);
1709
gtk_entry_set_text ( GTK_ENTRY (system_id_entry),system_id);
1711
gtk_entry_set_text ( GTK_ENTRY (volume_id_entry),volume_id);
1713
gtk_entry_set_text ( GTK_ENTRY (application_entry),application_id);
1715
gtk_entry_set_text ( GTK_ENTRY (publisher_entry),publisher_id);
1716
gtk_widget_show (iso_properties_win);
1718
gtk_entry_set_text ( GTK_ENTRY (preparer_entry),preparer_id);
1719
gtk_widget_show (iso_properties_win);
1721
gtk_entry_set_text ( GTK_ENTRY (creation_date_entry),creation_date);
1723
gtk_entry_set_text ( GTK_ENTRY (modified_date_entry),modified_date);
1724
gtk_widget_show (iso_properties_win);
1726
gtk_entry_set_text ( GTK_ENTRY (expiration_date_entry),expiration_date);
1728
gtk_entry_set_text ( GTK_ENTRY (effective_date_entry),effective_date);
1729
gtk_widget_show (iso_properties_win);
1732
void xa_archive_properties ( GtkMenuItem *menuitem , gpointer user_data )
1734
gchar *utf8_string , *measure, *text, *dummy_string;
1737
unsigned long long int file_size;
1741
current_page = gtk_notebook_get_current_page (notebook);
1742
idx = xa_find_archive_index (current_page);
1744
stat ( archive[idx]->path , &my_stat );
1745
file_size = my_stat.st_size;
1746
archive_properties_win = create_archive_properties_window();
1748
text = g_strrstr ( archive[idx]->path, "/" );
1752
utf8_string = g_filename_display_name (text);
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);
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);
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 );
1768
gtk_entry_set_text ( GTK_ENTRY (type_data), archive[idx]->format );
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);
1775
if (file_size > 1024*1024*1024 )
1777
content_size = (double)file_size / (1024*1024*1024);
1780
else if (file_size > 1024*1024 )
1782
content_size = (double)file_size / (1024*1024);
1786
else if (file_size > 1024 )
1788
content_size = (double)file_size / 1024;
1794
content_size = file_size;
1797
t = g_strdup_printf ("%.1f %s", content_size,measure);
1798
gtk_entry_set_text ( GTK_ENTRY (size_data), t );
1801
if (archive[idx]->dummy_size > 1024*1024*1024 )
1803
content_size = (double)archive[idx]->dummy_size / (1024*1024*1024);
1806
else if (archive[idx]->dummy_size > 1024*1024 )
1808
content_size = (double)archive[idx]->dummy_size / (1024*1024);
1812
else if (archive[idx]->dummy_size > 1024 )
1814
content_size = (double)archive[idx]->dummy_size / 1024;
1820
content_size = archive[idx]->dummy_size;
1822
t = g_strdup_printf ( "%.1f %s", content_size,measure);
1823
gtk_entry_set_text ( GTK_ENTRY (content_data), t );
1826
if (archive[idx]->has_comment)
1827
gtk_entry_set_text ( GTK_ENTRY (comment_data), _("Yes") );
1829
gtk_entry_set_text ( GTK_ENTRY (comment_data), _("No") );
1832
if (content_size != 0)
1833
content_size = (double)archive[idx]->dummy_size / file_size;
1836
t = g_strdup_printf ( "%.2f", content_size);
1837
gtk_entry_set_text ( GTK_ENTRY (compression_data), t );
1840
t = g_strdup_printf ( "%d", archive[idx]->nr_of_files);
1841
gtk_entry_set_text ( GTK_ENTRY (number_of_files_data), t );
1844
t = g_strdup_printf ( "%d", archive[idx]->nr_of_dirs);
1845
gtk_entry_set_text ( GTK_ENTRY (number_of_dirs_data), t );
1847
gtk_widget_show_all ( archive_properties_win );
1850
void xa_activate_delete_and_view ()
1855
current_page = gtk_notebook_get_current_page (notebook);
1856
idx = xa_find_archive_index (current_page);
1858
if ( ! GTK_WIDGET_VISIBLE (Extract_button) )
1861
GtkTreeSelection *selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (archive[idx]->treeview) );
1862
gint selected = gtk_tree_selection_count_selected_rows ( selection );
1864
OffDeleteandViewButtons();
1867
if ( archive[idx]->type != XARCHIVETYPE_RPM && archive[idx]->type != XARCHIVETYPE_ISO && archive[idx]->type != XARCHIVETYPE_DEB)
1869
gtk_widget_set_sensitive ( delete_menu , TRUE );
1870
gtk_widget_set_sensitive ( Delete_button , TRUE );
1874
gtk_widget_set_sensitive ( View_button , FALSE);
1875
gtk_widget_set_sensitive ( view_menu, FALSE );
1879
gtk_widget_set_sensitive ( View_button , TRUE );
1880
gtk_widget_set_sensitive ( view_menu, TRUE );
1885
void ConcatenateFileNames2 (gchar *filename , GString *data)
1887
gchar *esc_filename = NULL;
1888
gchar *escaped = NULL;
1889
gchar *escaped2 = NULL;
1893
current_page = gtk_notebook_get_current_page (notebook);
1894
idx = xa_find_archive_index (current_page);
1896
if ( strstr (filename, "[") || strstr (filename, "]"))
1898
if (archive[idx]->type == XARCHIVETYPE_ZIP)
1900
if (archive[idx]->status == XA_ARCHIVESTATUS_ADD)
1902
esc_filename = EscapeBadChars ( filename ,"$\'`\"\\!?* ()[]&|@#:;" );
1903
g_string_prepend (data, esc_filename);
1907
escaped = EscapeBadChars ( filename ,"$\'`\"\\!?* ()[]&|@#:;");
1908
escaped2 = escape_str_common (escaped , "*?[]", '\\', 0);
1910
esc_filename = escaped2;
1911
g_string_prepend (data, esc_filename);
1914
else if ( archive[idx]->type == XARCHIVETYPE_TAR_BZ2 || archive[idx]->type == XARCHIVETYPE_TAR_GZ || archive[idx]->type == XARCHIVETYPE_TAR )
1916
if (archive[idx]->status == XA_ARCHIVESTATUS_ADD)
1918
esc_filename = EscapeBadChars ( filename ,"$\'`\"\\!?* ()[]&|@#:;" );
1919
g_string_prepend (data, esc_filename);
1923
escaped = EscapeBadChars ( filename ,"?*\\'& !|()@#:;");
1924
escaped2 = escape_str_common ( escaped , "[]", '[', ']');
1926
esc_filename = escaped2;
1927
g_string_prepend (data, esc_filename);
1933
esc_filename = EscapeBadChars ( filename , "$\'`\"\\!?* ()[]&|@#:;" );
1934
g_string_prepend (data, esc_filename);
1936
g_string_prepend_c (data, ' ');
1937
g_free (esc_filename);
1940
void ConcatenateFileNames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data)
1942
gchar *filename = NULL;
1944
gtk_tree_model_get (model, iter, 0, &filename, -1);
1945
ConcatenateFileNames2 ( filename , data );
1949
void xa_cat_filenames_basename (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data)
1954
gtk_tree_model_get (model, iter, 1, &fullname, -1);
1955
name = g_path_get_basename ( fullname );
1957
ConcatenateFileNames2 ( name , data );
1961
void xa_cat_filenames (GtkTreeModel *model, GtkTreePath *treepath, GtkTreeIter *iter, GString *data)
1965
gtk_tree_model_get (model, iter, 1, &fullname, -1);
1966
ConcatenateFileNames2 ( fullname , data );
1970
gboolean xa_run_command ( gchar *command , gboolean watch_child_flag )
1975
gboolean waiting = TRUE;
1978
current_page = gtk_notebook_get_current_page (notebook);
1979
idx = xa_find_archive_index ( current_page );
1981
if (watch_child_flag)
1983
archive[idx]->parse_output = 0;
1984
SpawnAsyncProcess ( archive[idx] , command , 0, 1);
1985
if ( archive[idx]->child_pid == 0 )
1988
gtk_widget_show (viewport2);
1991
ps = waitpid ( archive[idx]->child_pid, &status, WNOHANG);
1995
gtk_main_iteration_do (FALSE);
1997
if (watch_child_flag)
1999
xa_watch_child (archive[idx]->child_pid, status, archive[idx]);
2004
if ( WIFEXITED (status) )
2006
if ( WEXITSTATUS (status) )
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."));
2025
void Update_StatusBar ( gchar *msg)
2027
gtk_label_set_text (GTK_LABEL (info_label), msg);
2030
gboolean xa_report_child_stderr (GIOChannel *ioc, GIOCondition cond, gpointer data)
2036
if (cond & (G_IO_IN | G_IO_PRI))
2040
status = g_io_channel_read_chars (ioc, buffer, sizeof (buffer), &bytes_read, NULL);
2042
gtk_text_buffer_insert (textbuf, &enditer, buffer, bytes_read);
2044
while (status == G_IO_STATUS_NORMAL);
2045
if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
2048
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
2051
g_io_channel_shutdown (ioc, TRUE, NULL);
2052
g_io_channel_unref (ioc);
2058
void OffDeleteandViewButtons()
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);
2066
void xa_hide_progress_bar_stop_button( XArchive *archive)
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);
2076
void drag_begin (GtkWidget *treeview1,GdkDragContext *context, gpointer data)
2078
GtkTreeSelection *selection;
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));
2088
row_list = gtk_tree_selection_get_selected_rows (selection, NULL);
2089
if ( row_list == NULL )
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)
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) );
2103
g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
2104
g_list_free (row_list);
2108
void drag_end (GtkWidget *treeview1,GdkDragContext *context, gpointer data)
2113
void drag_data_get (GtkWidget *widget, GdkDragContext *dc, GtkSelectionData *selection_data, guint info, guint t, gpointer data)
2115
GtkTreeSelection *selection;
2118
gchar *command , *no_uri_path;
2119
gchar *to_send = "E";
2125
current_page = gtk_notebook_get_current_page(notebook);
2126
idx = xa_find_archive_index (current_page);
2128
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (archive[idx]->treeview));
2129
row_list = gtk_tree_selection_get_selected_rows (selection, NULL);
2131
if ( row_list == NULL)
2133
if ( archive[idx]->status == XA_ARCHIVESTATUS_EXTRACT )
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!") );
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)
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); */
2150
if (no_uri_path == NULL)
2152
gtk_drag_finish (dc, FALSE, FALSE, t);
2155
if ( archive[idx]->has_passwd )
2157
if ( archive[idx]->passwd == NULL)
2159
archive[idx]->passwd = password_dialog ();
2160
if ( archive[idx]->passwd == NULL)
2162
gtk_drag_finish (dc, FALSE, FALSE, t);
2167
archive[idx]->extraction_path = extract_local_path ( no_uri_path );
2168
g_free ( no_uri_path );
2169
if (archive[idx]->extraction_path != NULL)
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 )
2182
archive[idx]->status = XA_ARCHIVESTATUS_EXTRACT;
2183
xa_run_command ( command , 1);
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);
2191
if (archive[idx]->extraction_path != NULL)
2193
g_free (archive[idx]->extraction_path);
2194
archive[idx]->extraction_path = NULL;
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;
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)
2203
gchar **array = NULL;
2204
gchar *filename = NULL;
2205
gchar *command = NULL;
2207
gchar *_current_dir = NULL;
2208
gchar *current_dir = NULL;
2210
gboolean dummy_password;
2211
unsigned int len = 0;
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) )
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);
2223
gtk_drag_finish (context, TRUE, FALSE, time);
2224
one_file = (array[1] == NULL);
2228
filename = g_filename_from_uri ( array[0] , NULL, NULL );
2229
if ( filename == NULL)
2231
else if ( xa_detect_archive_type ( NULL , filename ) > 0 )
2233
xa_open_archive ( NULL, filename );
2234
g_strfreev ( array );
2238
if (current_page == -1)
2240
idx = xa_get_new_archive_idx();
2243
archive[idx] = xa_new_archive_dialog ( filename );
2244
if (archive[idx] == NULL)
2246
xa_add_page (archive[idx]);
2249
idx = xa_find_archive_index ( current_page );
2251
if (archive[idx]->type == XARCHIVETYPE_RAR && unrar)
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!") );
2257
if (archive[idx]->type == XARCHIVETYPE_DEB || archive[idx]->type == XARCHIVETYPE_RPM)
2260
if (archive[idx]->type == XARCHIVETYPE_DEB)
2261
msg = _("You can't add content to deb packages!");
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 );
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;
2278
filename = g_filename_from_uri ( array[len] , NULL, NULL );
2279
name = g_path_get_basename ( filename );
2281
ConcatenateFileNames2 ( name, names );
2285
dummy_password = archive[idx]->has_passwd;
2286
full_path = archive[idx]->full_path;
2287
add_recurse = archive[idx]->add_recurse;
2289
archive[idx]->has_passwd = 0;
2290
archive[idx]->full_path = 0;
2291
archive[idx]->add_recurse = 1;
2293
command = xa_add_single_files ( archive[idx], names, NULL );
2295
archive[idx]->has_passwd = dummy_password;
2296
archive[idx]->full_path = full_path;
2297
archive[idx]->add_recurse = add_recurse;
2299
if (command != NULL)
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);
2309
g_string_free (names, TRUE);
2310
g_strfreev ( array );
2314
gboolean key_press_function (GtkWidget *widget, GdkEventKey *event, gpointer data)
2316
if (event == NULL) return FALSE;
2317
switch (event->keyval)
2320
if ( GTK_WIDGET_VISIBLE (viewport2) )
2321
xa_cancel_archive (NULL, NULL);
2325
if ( GTK_WIDGET_STATE (Delete_button) != GTK_STATE_INSENSITIVE )
2326
xa_delete_archive ( NULL , NULL );
2332
void xa_select_all ( GtkMenuItem *menuitem , gpointer user_data )
2337
current_page = gtk_notebook_get_current_page (notebook);
2338
idx = xa_find_archive_index (current_page);
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);
2346
void xa_deselect_all ( GtkMenuItem *menuitem , gpointer user_data )
2351
current_page = gtk_notebook_get_current_page (notebook);
2352
idx = xa_find_archive_index (current_page);
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);
2359
void xa_activate_link (GtkAboutDialog *about, const gchar *link, gpointer data)
2363
GError *error = NULL;
2365
gchar *browser_path;
2367
browser_path = g_find_program_in_path ("firefox");
2368
if ( browser_path == NULL)
2369
browser_path = g_find_program_in_path ("opera");
2371
if ( browser_path == NULL)
2372
browser_path = g_find_program_in_path ("mozilla");
2374
argv[0] = browser_path;
2375
argv[1] = (gchar *) link;
2379
screen = gtk_widget_get_screen (GTK_WIDGET (MainWindow));
2381
screen = gtk_widget_get_screen (GTK_WIDGET (about));
2383
if (!gdk_spawn_on_screen (screen, NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error))
2385
message = gtk_message_dialog_new (GTK_WINDOW (about),
2387
| GTK_DIALOG_DESTROY_WITH_PARENT,
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);
2396
if (browser_path != NULL)
2397
g_free (browser_path);
2400
void xa_show_help (GtkMenuItem *menuitem , gpointer user_data )
2402
gchar *uri = g_strconcat ("file://", DATADIR, "/doc/", PACKAGE, "/html/index.html", NULL);
2403
xa_activate_link (NULL,uri,NULL);
2407
void xa_reset_password (GtkMenuItem *menuitem , gpointer user_data )
2412
current_page = gtk_notebook_get_current_page(notebook);
2413
idx = xa_find_archive_index ( current_page );
2415
if (archive[idx] == NULL)
2418
if (archive[idx]->passwd != NULL)
2420
g_free (archive[idx]->passwd);
2421
archive[idx]->passwd = NULL;
2422
Update_StatusBar (_("The password has been reset."));
2425
Update_StatusBar (_("Please enter the password first!"));
2428
void xa_show_archive_comment ( GtkMenuItem *menuitem , gpointer user_data )
2430
GtkWidget *comment_window;
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);