[Xfce4-commits] r26276 - xarchiver/trunk/src
Giuseppe Torelli
colossus at xfce.org
Thu Nov 8 16:26:16 CET 2007
Author: colossus
Date: 2007-11-08 15:26:16 +0000 (Thu, 08 Nov 2007)
New Revision: 26276
Modified:
xarchiver/trunk/src/7zip.c
xarchiver/trunk/src/archive.c
xarchiver/trunk/src/archive.h
xarchiver/trunk/src/arj.c
xarchiver/trunk/src/bzip2.c
xarchiver/trunk/src/deb.c
xarchiver/trunk/src/gzip.c
xarchiver/trunk/src/lha.c
xarchiver/trunk/src/lzma.c
xarchiver/trunk/src/rar.c
xarchiver/trunk/src/rpm.c
xarchiver/trunk/src/tar.c
xarchiver/trunk/src/window.c
xarchiver/trunk/src/window.h
xarchiver/trunk/src/zip.c
Log:
Restyling a lot of code in window.c and archive.c and consequently in the other sources.
Modified: xarchiver/trunk/src/7zip.c
===================================================================
--- xarchiver/trunk/src/7zip.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/7zip.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -43,7 +43,7 @@
archive->format ="7-ZIP";
archive->nc = 6;
archive->parse_output = xa_get_7zip_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free ( command );
if ( archive->child_pid == 0 )
return;
Modified: xarchiver/trunk/src/archive.c
===================================================================
--- xarchiver/trunk/src/archive.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/archive.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -38,7 +38,7 @@
return archive;
}
-void xa_spawn_async_process (XArchive *archive , gchar *command , gboolean input)
+void xa_spawn_async_process (XArchive *archive , gchar *command)
{
GIOChannel *ioc,*err_ioc;
gchar **argv;
@@ -54,7 +54,7 @@
NULL,
NULL,
&archive->child_pid,
- input ? &archive->input_fd : NULL,
+ NULL,
&archive->output_fd,
&archive->error_fd,
&error) )
@@ -233,15 +233,16 @@
chdir (archive->tmp);
command = g_strconcat ("rm -rf ",archive->tmp,NULL);
- result = xa_run_command (archive,command,flag );
+ result = xa_run_command (archive,command,flag);
g_free (command);
return result;
}
gboolean xa_create_temp_directory (gchar tmp_dir[])
{
+ //TODO user the user set tmp dir in the pref dialog
strcpy (tmp_dir,"/tmp/xa-XXXXXX");
- if ( mkdtemp ( tmp_dir ) == 0)
+ if (mkdtemp (tmp_dir) == 0)
{
response = xa_show_message_dialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't create temporary directory in /tmp:"),g_strerror(errno) );
gtk_widget_set_sensitive (Stop_button, FALSE);
@@ -251,14 +252,15 @@
return TRUE;
}
-gboolean xa_run_command (XArchive *archive,gchar *command,gboolean watch_child_flag)
+gboolean xa_run_command (XArchive *archive,gchar *command,gboolean set_gui)
{
int status;
gboolean waiting = TRUE;
+ gboolean result;
int ps;
archive->parse_output = 0;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
if (archive->child_pid == 0)
return FALSE;
@@ -271,16 +273,14 @@
else
gtk_main_iteration_do (FALSE);
}
+ result = xa_check_child_for_error_on_exit(archive,status);
+ if (set_gui)
+ xa_archive_operation_finished(archive,result);
- if (watch_child_flag)
- {
- xa_watch_child (archive->child_pid, status, archive);
- return TRUE;
- }
- return TRUE;
+ return result;
}
-gint xa_find_archive_index ( gint page_num )
+gint xa_find_archive_index (gint page_num)
{
GtkWidget *scrollwindow;
gint i;
@@ -543,14 +543,9 @@
GString *dummy = g_string_new("");
while (entry)
{
- if (strlen(entry->filename) == 0)
- break;
- else
- {
- if (entry->is_dir)
- dummy = g_string_prepend_c(dummy,'/');
- dummy = g_string_prepend(dummy,entry->filename);
- }
+ if (entry->is_dir)
+ dummy = g_string_prepend_c(dummy,'/');
+ dummy = g_string_prepend(dummy,entry->filename);
entry = entry->prev;
}
fullpathname = g_strdup(dummy->str);
Modified: xarchiver/trunk/src/archive.h
===================================================================
--- xarchiver/trunk/src/archive.h 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/archive.h 2007-11-08 15:26:16 UTC (rev 26276)
@@ -108,7 +108,6 @@
unsigned short int nc;
gint nr_of_files;
gint nr_of_dirs;
- gint input_fd;
gint output_fd;
gint error_fd;
guint pb_source;
@@ -117,13 +116,13 @@
void (*parse_output) (gchar *line, gpointer data);
};
-void xa_spawn_async_process (XArchive *archive, gchar *command , gboolean input);
+void xa_spawn_async_process (XArchive *archive, gchar *command);
XArchive *xa_init_archive_structure ();
void xa_clean_archive_structure ( XArchive *archive);
gboolean xa_dump_child_error_messages (GIOChannel *ioc, GIOCondition cond, gpointer data);
gboolean xa_create_temp_directory (gchar tmp_dir[]);
gboolean xa_delete_temp_directory (XArchive *archive,gboolean flag);
-gboolean xa_run_command (XArchive *archive,gchar *command , gboolean watch_child_flag);
+gboolean xa_run_command (XArchive *archive,gchar *command,gboolean set_gui);
gint xa_find_archive_index (gint page_num);
gint xa_get_new_archive_idx();
XEntry *xa_alloc_memory_for_each_row ( guint nc,GType column_types[]);
Modified: xarchiver/trunk/src/arj.c
===================================================================
--- xarchiver/trunk/src/arj.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/arj.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -36,7 +36,7 @@
archive->nc = 9;
archive->format ="ARJ";
archive->parse_output = xa_get_arj_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
if (archive->child_pid == 0)
return;
Modified: xarchiver/trunk/src/bzip2.c
===================================================================
--- xarchiver/trunk/src/bzip2.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/bzip2.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -59,7 +59,7 @@
archive->format = "TAR.BZIP2";
archive->nc = 7;
archive->parse_output = xa_get_tar_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
g_free (tar);
Modified: xarchiver/trunk/src/deb.c
===================================================================
--- xarchiver/trunk/src/deb.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/deb.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -82,7 +82,7 @@
archive->nc = 7;
archive->format = "DEB";
archive->parse_output = xa_get_tar_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
if (archive->child_pid == 0)
Modified: xarchiver/trunk/src/gzip.c
===================================================================
--- xarchiver/trunk/src/gzip.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/gzip.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -44,7 +44,7 @@
archive->format ="TAR.GZIP";
archive->nc = 7;
archive->parse_output = xa_get_tar_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
g_free (tar);
@@ -79,7 +79,7 @@
xa_create_liststore (archive,names);
command = g_strconcat ("gzip -l ",archive->escaped_path,NULL);
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
if (archive->child_pid == 0)
Modified: xarchiver/trunk/src/lha.c
===================================================================
--- xarchiver/trunk/src/lha.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/lha.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -36,7 +36,7 @@
archive->format ="LHA";
archive->nc = 5;
archive->parse_output = xa_get_lha_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free ( command );
if ( archive->child_pid == 0 )
Modified: xarchiver/trunk/src/lzma.c
===================================================================
--- xarchiver/trunk/src/lzma.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/lzma.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -52,7 +52,7 @@
archive->format ="TAR.LZMA";
archive->parse_output = xa_get_tar_line_content;
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
g_free (tar);
Modified: xarchiver/trunk/src/rar.c
===================================================================
--- xarchiver/trunk/src/rar.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/rar.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -49,7 +49,7 @@
archive->nc = 10;
archive->parse_output = xa_get_rar_line_content;
archive->format = "RAR";
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free ( command );
if ( archive->child_pid == 0 )
Modified: xarchiver/trunk/src/rpm.c
===================================================================
--- xarchiver/trunk/src/rpm.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/rpm.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -152,7 +152,7 @@
command = g_strconcat ("cpio -tv --file ",gzip,NULL);
g_free(gzip);
archive[idx]->parse_output = xa_get_cpio_line_content;
- xa_spawn_async_process ( archive[idx],command,1);
+ xa_spawn_async_process ( archive[idx],command);
g_free(command);
if ( archive[idx]->child_pid == 0 )
{
@@ -278,7 +278,7 @@
command = g_strconcat ("bzip2 -dc ",temp_path,NULL);
archive[idx]->parse_output = 0;
- xa_spawn_async_process (archive[idx],command,0);
+ xa_spawn_async_process (archive[idx],command);
g_free (command);
if (archive[idx]->child_pid == 0)
{
Modified: xarchiver/trunk/src/tar.c
===================================================================
--- xarchiver/trunk/src/tar.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/tar.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -41,7 +41,7 @@
archive->nc = 7;
archive->parse_output = xa_get_tar_line_content;
archive->format ="TAR";
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free (command);
g_free (tar);
Modified: xarchiver/trunk/src/window.c
===================================================================
--- xarchiver/trunk/src/window.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/window.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -40,35 +40,10 @@
gchar *current_open_directory = NULL;
GtkFileFilter *open_file_filter = NULL;
-GList *Suffix , *Name;
+GList *Suffix, *Name;
-void xa_watch_child ( GPid pid, gint status, gpointer data)
+gboolean xa_check_child_for_error_on_exit(XArchive *archive,gint status)
{
- XArchive *archive = data;
- gboolean waiting = TRUE;
- int ps;
-
- gtk_widget_hide(viewport2);
- gtk_widget_set_sensitive(Stop_button,FALSE);
-
- if ( WIFSIGNALED (status) )
- {
- Update_StatusBar ( _("Operation canceled."));
- if (archive->status == XA_ARCHIVESTATUS_EXTRACT)
- {
- gchar *msg = g_strdup_printf(_("Please check \"%s\" since some files could have been already extracted."),archive->extraction_path);
-
- response = xa_show_message_dialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO, GTK_BUTTONS_OK,"",msg );
- g_free (msg);
- }
- else if (archive->status == XA_ARCHIVESTATUS_OPEN)
- gtk_widget_set_sensitive ( check_menu , FALSE );
-
- xa_set_button_state (1,1,1,archive->can_add,archive->can_extract,archive->has_sfx,archive->has_test,archive->has_properties);
- archive->status = XA_ARCHIVESTATUS_IDLE;
- return;
- }
- /* Check if the child exits with an error code */
if ( WIFEXITED (status) )
{
if ( WEXITSTATUS (status) )
@@ -85,24 +60,14 @@
archive->passwd = NULL;
}
archive->status = XA_ARCHIVESTATUS_IDLE;
- return;
+ return FALSE;
}
}
+ return TRUE;
+}
- if (archive->has_comment)
- gtk_widget_set_sensitive (comment_menu,TRUE);
- else
- gtk_widget_set_sensitive (comment_menu,FALSE);
-
- if (archive->has_comment && archive->status == XA_ARCHIVESTATUS_OPEN)
- xa_show_archive_comment ( NULL, NULL);
-
- if (archive->status == XA_ARCHIVESTATUS_SFX && archive->type == XARCHIVETYPE_RAR)
- {
- gtk_widget_set_sensitive ( exe_menu, FALSE);
- response = xa_show_message_dialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,GTK_BUTTONS_OK,_("The sfx archive was saved as:"),archive->tmp );
- }
-
+void xa_reload_archive_content(XArchive *archive)
+{
if ( ! cli )
{
/* This to automatically reload the content of the archive after adding or deleting */
@@ -156,36 +121,91 @@
default:
break;
}
- while (waiting)
+ /*while (waiting)
{
ps = waitpid ( archive->child_pid, &status, WNOHANG);
if (ps < 0)
waiting = FALSE;
else
gtk_main_iteration_do (FALSE);
- }
+ }*/
archive->status = XA_ARCHIVESTATUS_IDLE;
}
}
+}
- if (! cli && archive != NULL)
+void xa_archive_operation_finished(XArchive *archive,gboolean error)
+{
+ gtk_widget_hide(viewport2);
+ gtk_widget_set_sensitive(Stop_button,FALSE);
+
+ if (archive->has_comment)
+ gtk_widget_set_sensitive (comment_menu,TRUE);
+ else
+ gtk_widget_set_sensitive (comment_menu,FALSE);
+
+ if (archive->has_comment && archive->status == XA_ARCHIVESTATUS_OPEN)
+ xa_show_archive_comment ( NULL, NULL);
+
+ if (archive->status == XA_ARCHIVESTATUS_SFX && archive->type == XARCHIVETYPE_RAR)
{
- if ( archive->has_passwd == FALSE && archive->passwd == NULL)
- gtk_widget_set_sensitive ( password_entry , FALSE);
- else
- gtk_widget_set_sensitive ( password_entry , TRUE);
+ gtk_widget_set_sensitive ( exe_menu, FALSE);
+ response = xa_show_message_dialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,GTK_BUTTONS_OK,_("The sfx archive was saved as:"),archive->tmp );
}
xa_set_button_state (1,1,1,archive->can_add,archive->can_extract,archive->has_sfx,archive->has_test,archive->has_properties);
- Update_StatusBar ( _("Operation completed."));
+ if (error)
+ Update_StatusBar ( _("Operation completed."));
+ else
+ Update_StatusBar ( _("Operation failed!"));
if (archive->status == XA_ARCHIVESTATUS_TEST)
xa_show_cmd_line_output (NULL);
gtk_widget_grab_focus (GTK_WIDGET(archive->treeview));
archive->status = XA_ARCHIVESTATUS_IDLE;
- return;
}
+void xa_watch_child (GPid pid,gint status,gpointer data)
+{
+ gboolean result;
+ XArchive *archive = data;
+
+ if (WIFSIGNALED (status) )
+ {
+ Update_StatusBar (_("Operation canceled."));
+ if (archive->status == XA_ARCHIVESTATUS_EXTRACT)
+ {
+ gchar *msg = g_strdup_printf(_("Please check \"%s\" since some files could have been already extracted."),archive->extraction_path);
+
+ response = xa_show_message_dialog (GTK_WINDOW (MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_INFO,GTK_BUTTONS_OK,"",msg );
+ g_free (msg);
+ }
+ else if (archive->status == XA_ARCHIVESTATUS_OPEN)
+ gtk_widget_set_sensitive (check_menu,FALSE );
+
+ xa_set_button_state (1,1,1,archive->can_add,archive->can_extract,archive->has_sfx,archive->has_test,archive->has_properties);
+ archive->status = XA_ARCHIVESTATUS_IDLE;
+ return;
+ }
+ result = xa_check_child_for_error_on_exit (archive,status);
+ if (result)
+ {
+ xa_archive_operation_finished(archive,result);
+ return;
+ }
+ else
+ xa_archive_operation_finished(archive,result);
+
+ //xa_reload_archuve_content
+ if (! cli && archive != NULL)
+ {
+ if (archive->has_passwd == FALSE && archive->passwd == NULL)
+ gtk_widget_set_sensitive (password_entry,FALSE);
+ else
+ gtk_widget_set_sensitive (password_entry,TRUE);
+ }
+}
+
void xa_new_archive (GtkMenuItem *menuitem, gpointer user_data)
{
gint current_page;
@@ -771,7 +791,7 @@
fclose (sfx_archive);
command = g_strconcat ("chmod 755 ", archive_name_escaped , NULL);
- result = xa_run_command (archive[idx],command,0);
+ result = xa_run_command (archive[idx],command,1);
g_free (command);
command = g_strconcat ("zip -A ",archive_name_escaped,NULL);
@@ -1272,7 +1292,6 @@
gboolean result = FALSE;
gint current_page;
gint idx;
- GtkWidget *message;
GString *names = g_string_new (" ");
current_page = gtk_notebook_get_current_page (notebook);
@@ -1319,7 +1338,6 @@
names = g_string_append(names,full_pathname);
g_free(full_pathname);
command = xa_extract_single_files(archive[idx],names,archive[idx]->tmp);
- g_print ("%s\n",command);
g_string_free (names,TRUE);
archive[idx]->full_path = full_path;
@@ -1329,22 +1347,21 @@
result = xa_run_command (archive[idx],command,0);
g_free (command);
if (result == 0)
- {
- /*unlink (dummy_name);
- g_free (dummy_name);*/
return;
- }
}
full_pathname = gtk_combo_box_get_active_text (GTK_COMBO_BOX(prefs_window->combo_prefered_editor));
command = g_strconcat(archive[idx]->tmp,"/",entry->filename,NULL);
if (xa_launch_external_program(full_pathname,command))
- Update_StatusBar (_("Operation completed."));
+ xa_archive_operation_finished(archive[idx],1);
else
- Update_StatusBar (_("Operation failed."));
+ xa_archive_operation_finished(archive[idx],0);
+
+ g_free(full_pathname);
+ g_free(command);
}
-void xa_archive_properties ( GtkMenuItem *menuitem , gpointer user_data )
+void xa_archive_properties (GtkMenuItem *menuitem,gpointer user_data)
{
struct stat my_stat;
gchar *utf8_string , *measure, *text, *dummy_string;
@@ -1655,7 +1672,7 @@
if ( row_list == NULL)
return;
- if ( archive[idx]->status == XA_ARCHIVESTATUS_EXTRACT )
+ if (archive[idx]->status == XA_ARCHIVESTATUS_EXTRACT)
{
response = xa_show_message_dialog (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!") );
return;
@@ -1705,6 +1722,7 @@
if ( command != NULL )
{
archive[idx]->status = XA_ARCHIVESTATUS_EXTRACT;
+ //TODO if 1 or 0?
xa_run_command (archive[idx],command,1);
g_free (command);
}
@@ -1837,19 +1855,20 @@
gboolean key_press_function (GtkWidget *widget, GdkEventKey *event, gpointer data)
{
- if (event == NULL) return FALSE;
+ if (event == NULL)
+ return FALSE;
switch (event->keyval)
- {
- case GDK_Escape:
- if ( GTK_WIDGET_VISIBLE (viewport2) )
+ {
+ case GDK_Escape:
+ if ( GTK_WIDGET_VISIBLE (viewport2) )
xa_cancel_archive (NULL, NULL);
- break;
+ break;
- case GDK_Delete:
- if ( GTK_WIDGET_STATE (delete_menu) != GTK_STATE_INSENSITIVE )
+ case GDK_Delete:
+ if ( GTK_WIDGET_STATE (delete_menu) != GTK_STATE_INSENSITIVE )
xa_delete_archive ( NULL , NULL );
break;
- }
+ }
return FALSE;
}
Modified: xarchiver/trunk/src/window.h
===================================================================
--- xarchiver/trunk/src/window.h 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/window.h 2007-11-08 15:26:16 UTC (rev 26276)
@@ -90,6 +90,9 @@
int xa_detect_archive_type ( gchar *filename );
gboolean key_press_function ( GtkWidget* widget, GdkEventKey* event,gpointer data);
gboolean treeview_select_search (GtkTreeModel *model,gint column,const gchar *key,GtkTreeIter *iter,gpointer search_data);
+gboolean xa_check_child_for_error_on_exit(XArchive *archive,gint status);
+void xa_archive_operation_finished(XArchive *archive,gboolean error);
+void xa_reload_archive_content(XArchive *archive);
void xa_watch_child ( GPid pid, gint status, gpointer data);
void xa_remove_columns();
void xa_create_liststore ( XArchive *archive, gchar *columns_names[]);
Modified: xarchiver/trunk/src/zip.c
===================================================================
--- xarchiver/trunk/src/zip.c 2007-11-07 22:33:07 UTC (rev 26275)
+++ xarchiver/trunk/src/zip.c 2007-11-08 15:26:16 UTC (rev 26276)
@@ -36,7 +36,7 @@
archive->nc = 9;
archive->parse_output = xa_get_zip_line_content;
archive->format ="ZIP";
- xa_spawn_async_process (archive,command,0);
+ xa_spawn_async_process (archive,command);
g_free ( command );
if (archive->child_pid == 0)
More information about the Xfce4-commits
mailing list