[Xfce4-commits] r23325 - xarchiver/trunk/src
Giuseppe Torelli
colossus at xfce.org
Mon Oct 9 12:33:23 UTC 2006
Author: colossus
Date: 2006-10-09 12:33:22 +0000 (Mon, 09 Oct 2006)
New Revision: 23325
Modified:
xarchiver/trunk/src/rar.c
xarchiver/trunk/src/tar.c
xarchiver/trunk/src/zip.c
Log:
Removed GValue code from zip.c, tar.c and rar.c.
Modified: xarchiver/trunk/src/rar.c
===================================================================
--- xarchiver/trunk/src/rar.c 2006-10-09 12:27:49 UTC (rev 23324)
+++ xarchiver/trunk/src/rar.c 2006-10-09 12:33:22 UTC (rev 23325)
@@ -15,12 +15,14 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
-
+
#include "config.h"
#include "rar.h"
#include "string_utils.h"
extern gboolean unrar;
+static gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data);
+GtkTreeIter iter;
void OpenRar ( XArchive *archive )
{
@@ -43,173 +45,103 @@
g_free ( command );
if ( archive->child_pid == 0 )
return;
-
+
char *names[] = {(_("Filename")),(_("Original")),(_("Compressed")),(_("Ratio")),(_("Date")),(_("Time")),(_("Permissions")),(_("Checksum")),(_("Method")),(_("Version"))};
GType types[]= {G_TYPE_STRING,G_TYPE_UINT64,G_TYPE_UINT64,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING};
archive->has_passwd = FALSE;
xa_create_liststore ( 10, names , (GType *)types );
}
-gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
+static gboolean RarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
{
XArchive *archive = data;
+ gchar **fields = NULL;
gchar *line = NULL;
- gchar *start = NULL;
- gchar *end = NULL;
- GValue *filename = NULL;
- GValue *original = NULL;
- gchar *_original = NULL;
- GValue *compressed = NULL;
- gchar *_compressed = NULL;
- GValue *ratio = NULL;
- GValue *date = NULL;
- GValue *time = NULL;
- GValue *permissions = NULL;
- GValue *crc = NULL;
- GValue *method = NULL;
- GValue *version = NULL;
+ GIOStatus status = G_IO_STATUS_NORMAL;
if (cond & (G_IO_IN | G_IO_PRI) )
{
- /* This to avoid inserting in the list RAR's copyright message */
- if (jump_header == FALSE )
- {
- g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
- if (line == NULL)
- return TRUE;
- if (strncmp (line , "--------" , 8) == 0)
- {
- jump_header = TRUE;
- odd_line = TRUE;
- }
- g_free (line);
- return TRUE;
- }
- if ( jump_header && odd_line )
+ do
{
- /* Now read the filename */
- g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
- if ( line == NULL )
- return TRUE;
+ /* This to avoid inserting in the list RAR's copyright message */
+ if (jump_header == FALSE )
{
- /* This to avoid inserting in the liststore the last line of Rar output */
- if (strncmp (line, "--------", 8) == 0 || strncmp (line, "\x0a",1) == 0)
- {
- g_free (line);
g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
+ if (line == NULL)
+ break;
+ if (strncmp (line , "--------" , 8) == 0)
+ {
+ jump_header = TRUE;
+ odd_line = TRUE;
+ }
g_free (line);
- return TRUE;
+ break;
}
- if (line[0] == '*') archive->has_passwd = TRUE;
+ if ( jump_header && odd_line )
+ {
+ /* Now read the filename */
+ g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
+ if ( line == NULL )
+ break;
+ /* This to avoid inserting in the liststore the last line of Rar output */
+ if (strncmp (line, "--------", 8) == 0 || strncmp (line, "\x0a",1) == 0)
+ {
+ g_free (line);
+ g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
+ g_free (line);
+ break;
+ }
+ gtk_list_store_append (liststore, &iter);
+ line[ strlen(line) - 1 ] = '\000';
+ if (line[0] == '*')
+ archive->has_passwd = TRUE;
/* This to avoid the white space or the * before the first char of the filename */
line++;
- filename = g_new0(GValue, 1);
- filename = g_value_init (filename, G_TYPE_STRING);
- g_value_set_string (filename, g_strndup (line , strlen (line) -1 ) );
- archive->row = g_list_prepend (archive->row , filename);
+ gtk_list_store_set (liststore, &iter,0,line,-1);
/* Restore the pointer before freeing it */
line--;
g_free (line);
odd_line = ! odd_line;
+ break;
}
- }
- else
- {
- /* Now let's parse the rest of the info */
- g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
- if (line == NULL)
- return TRUE;
- archive->row_cnt++;
- start = eat_spaces (line);
- end = strchr (start, ' ');
- original = g_new0(GValue, 1);
- original = g_value_init(original, G_TYPE_UINT64);
- _original = g_strndup ( start , end - start);
- g_value_set_uint64 ( original , atoll ( _original ) );
- g_free (_original);
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- compressed = g_new0 (GValue, 1);
- compressed = g_value_init(compressed, G_TYPE_UINT64);
- _compressed = g_strndup ( start , end - start);
- g_value_set_uint64 ( compressed , atoll ( _compressed ) );
- g_free (_compressed);
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- ratio = g_new0(GValue, 1);
- ratio = g_value_init(ratio, G_TYPE_STRING);
- g_value_set_string (ratio , g_strndup ( start , end - start));
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- date = g_new0(GValue, 1);
- date = g_value_init(date, G_TYPE_STRING);
- g_value_set_string (date , g_strndup ( start , end - start));
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- time = g_new0(GValue, 1);
- time = g_value_init(time, G_TYPE_STRING);
- g_value_set_string (time , g_strndup ( start , end - start));
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- permissions = g_new0(GValue, 1);
- permissions = g_value_init(permissions, G_TYPE_STRING);
- g_value_set_string (permissions , g_strndup ( start , end - start));
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- crc = g_new0(GValue, 1);
- crc = g_value_init(crc, G_TYPE_STRING);
- g_value_set_string (crc , g_strndup ( start , end - start));
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- method = g_new0(GValue, 1);
- method = g_value_init(method, G_TYPE_STRING);
- g_value_set_string (method , g_strndup ( start , end - start));
-
- start = eat_spaces (end);
- end = strchr (start, '\n');
- version = g_new0(GValue, 1);
- version = g_value_init(version, G_TYPE_STRING);
- g_value_set_string (version , g_strndup ( start , end - start));
-
- archive->row = g_list_prepend (archive->row , original) ;
- archive->row = g_list_prepend (archive->row , compressed );
- archive->row = g_list_prepend (archive->row , ratio );
- archive->row = g_list_prepend (archive->row , date );
- archive->row = g_list_prepend (archive->row , time );
- archive->row = g_list_prepend (archive->row , permissions );
- archive->row = g_list_prepend (archive->row , crc );
- archive->row = g_list_prepend (archive->row , method );
- archive->row = g_list_prepend (archive->row , version );
-
- if ( strstr (g_value_get_string ( permissions) , "d") == NULL && strstr (g_value_get_string ( permissions) , "D") == NULL )
- archive->nr_of_files++;
else
- archive->nr_of_dirs++;
-
- archive->dummy_size += g_value_get_uint64 (original);
- odd_line = ! odd_line;
- g_free (line);
- if (archive->row_cnt > 99)
{
- xa_append_rows (archive , 10 );
- archive->row_cnt = 0;
+ /* Now read the rest of the data */
+ g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
+ if ( line == NULL)
+ break;
+ fields = split_line (line,9);
+ if ( strstr (fields[5] , "d") == NULL && strstr (fields[5] , "D") == NULL )
+ archive->nr_of_files++;
+ else
+ archive->nr_of_dirs++;
+ for (x = 0; x < 9; x++)
+ {
+ if (x == 0 || x == 1)
+ gtk_list_store_set (liststore, &iter,x+1,atoll (fields[x]),-1);
+ else
+ gtk_list_store_set (liststore, &iter,x+1,fields[x],-1);
+ }
+ while ( gtk_events_pending() )
+ gtk_main_iteration();
+ archive->dummy_size += atoll (fields[0]);
+ g_strfreev ( fields );
+ g_free (line);
+ odd_line = ! odd_line;
}
}
+ while (status == G_IO_STATUS_NORMAL);
+
+ if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
+ goto done;
}
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
{
- g_io_channel_shutdown ( ioc,TRUE,NULL );
+done: g_io_channel_shutdown ( ioc,TRUE,NULL );
g_io_channel_unref (ioc);
- xa_append_rows (archive , 10 );
- return FALSE;
+ gtk_tree_view_set_model (GTK_TREE_VIEW(treeview1), model);
+ g_object_unref (model);
+ return FALSE;
}
return TRUE;
}
-
Modified: xarchiver/trunk/src/tar.c
===================================================================
--- xarchiver/trunk/src/tar.c 2006-10-09 12:27:49 UTC (rev 23324)
+++ xarchiver/trunk/src/tar.c 2006-10-09 12:33:22 UTC (rev 23325)
@@ -1,6 +1,5 @@
/*
* Copyright (C) 2006 Giuseppe Torelli - <colossus73 at gmail.com>
- * Copyright (C) 2006 Stephan Arts - <psybsd at gmail.com>
* Copyright (C) 2006 Benedikt Meurer - <benny at xfce.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -17,15 +16,16 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
-
+
#include "config.h"
#include "tar.h"
-
+#include "string_utils.h"
+
void OpenTar ( XArchive *archive )
{
gchar *command;
gchar *tar;
-
+
tar = g_find_program_in_path ("gtar");
if (tar == NULL)
tar = g_strdup ("tar");
@@ -53,118 +53,70 @@
gboolean TarOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
{
XArchive *archive = data;
- gchar *line = NULL;
- GValue *filename = NULL;
- GValue *symlink = NULL;
- GValue *permissions = NULL;
- GValue *owner = NULL;
- GValue *size = NULL;
- GValue *date = NULL;
- GValue *time = NULL;
+ gchar **fields;
+ gchar *filename;
+ gchar *line = NULL;
+ gchar *temp = NULL;
+ GtkTreeIter iter;
GIOStatus status = G_IO_STATUS_NORMAL;
- gchar *_size = NULL;
- gchar *temp_filename = NULL;
- unsigned short int a = 0, n = 0;
-
+
if (cond & (G_IO_IN | G_IO_PRI) )
{
- do
- {
- status = g_io_channel_read_line(ioc, &line, NULL,NULL,NULL);
- if (line == NULL)
- break;
+ do
+ {
+ g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
+ if ( line == NULL )
+ break;
- filename = g_new0(GValue, 1);
- symlink = g_new0(GValue, 1);
- permissions = g_new0(GValue, 1);
- owner = g_new0(GValue, 1);
- size = g_new0(GValue, 1);
- date = g_new0(GValue, 1);
- time = g_new0(GValue, 1);
+ fields = split_line (line,5);
+ filename = get_last_field (line,6);
+ gtk_list_store_append (liststore, &iter);
- for(n = 13; n < strlen(line); n++)
- if(line[n] == ' ') break;
- permissions = g_value_init(permissions, G_TYPE_STRING);
- g_value_set_string(permissions, g_strndup(line, 10));
-
- owner = g_value_init(owner , G_TYPE_STRING);
- g_value_set_string(owner, g_strndup(&line[11], n-11));
+ if ( strstr(fields[0] , "d") == NULL )
+ archive->nr_of_files++;
+ else
+ archive->nr_of_dirs++;
- for(; n < strlen(line); n++)
- if(line[n] >= '0' && line[n] <= '9')
- break;
- a = n;
- for(; n < strlen(line); n++)
- if(line[n] == ' ')
- break;
+ temp = g_strrstr (filename,"->");
+ if (temp)
+ {
+ gtk_list_store_set (liststore, &iter,2,g_strstrip(&temp[3]),-1);
+ temp = g_strstrip(g_strndup(filename, strlen(filename) - strlen(temp) ));
+ gtk_list_store_set (liststore, &iter,0,temp,-1);
+ g_free (temp);
+ }
+ else
+ {
+ gtk_list_store_set (liststore, &iter,2,NULL,-1);
+ gtk_list_store_set (liststore, &iter,0,filename,-1);
+ }
- size = g_value_init(size, G_TYPE_UINT64);
- _size = g_strndup(&line[a], n-a);
- g_value_set_uint64(size, atoll ( _size ));
- g_free (_size);
- a = n++;
- for(; n < strlen(line); n++) // DATE
- if(line[n] == ' ')
- break;
- date = g_value_init(date, G_TYPE_STRING);
- g_value_set_string ( date, g_strndup (&line[n-10], 10) );
+ gtk_list_store_set (liststore, &iter,1,fields[0],-1);
+ gtk_list_store_set (liststore, &iter,3,fields[1],-1);
+ gtk_list_store_set (liststore, &iter,4,atoll(fields[2]),-1);
+ gtk_list_store_set (liststore, &iter,5,fields[3],-1);
+ gtk_list_store_set (liststore, &iter,6,fields[4],-1);
- a = n++;
- for (; n < strlen(line); n++) // TIME
- if (line[n] == ' ') break;
- time = g_value_init(time, G_TYPE_STRING);
- g_value_set_string ( time, g_strndup (&line[n-8], 8) );
+ while (gtk_events_pending() )
+ gtk_main_iteration();
- symlink = g_value_init(symlink, G_TYPE_STRING);
- filename = g_value_init(filename, G_TYPE_STRING);
-
- gchar *temp = g_strrstr (&line[n],"->");
- if (temp )
- {
- temp_filename = g_strstrip(g_strndup(&line[n], strlen(line) - strlen(temp) - n ));
- g_value_set_string (symlink, g_strstrip(g_strndup (&temp[3] , strlen(temp))) );
+ archive->dummy_size += atoll(fields[2]);
+ g_strfreev ( fields );
+ g_free (line);
}
- else
- {
- temp_filename = g_strstrip(g_strndup(&line[n], strlen(line)-n-1));
- g_value_set_string (symlink, g_strdup(" ") );
- }
-
- g_value_set_string (filename, temp_filename );
-
- archive->row = g_list_prepend(archive->row, filename);
- archive->row = g_list_prepend(archive->row, permissions);
- archive->row = g_list_prepend(archive->row, symlink);
- archive->row = g_list_prepend(archive->row, owner);
- archive->row = g_list_prepend(archive->row, size);
- archive->row = g_list_prepend(archive->row, date);
- archive->row = g_list_prepend(archive->row, time);
-
- archive->dummy_size += g_value_get_uint64 (size);
- if ( strstr (g_value_get_string (permissions) , "d") == NULL )
- archive->nr_of_files++;
- else
- archive->nr_of_dirs++;
- g_free(line);
- archive->row_cnt++;
- if (archive->row_cnt > 99)
- {
- xa_append_rows ( archive , 7 );
- archive->row_cnt = 0;
- }
- }
while (status == G_IO_STATUS_NORMAL);
- if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
- goto done;
+ if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
+ goto done;
}
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
{
-done:
- g_io_channel_shutdown ( ioc,TRUE,NULL );
+done: g_io_channel_shutdown ( ioc,TRUE,NULL );
g_io_channel_unref (ioc);
- xa_append_rows ( archive , 7 );
+ gtk_tree_view_set_model (GTK_TREE_VIEW(treeview1), model);
+ g_object_unref (model);
return FALSE;
}
return TRUE;
}
+
Modified: xarchiver/trunk/src/zip.c
===================================================================
--- xarchiver/trunk/src/zip.c 2006-10-09 12:27:49 UTC (rev 23324)
+++ xarchiver/trunk/src/zip.c 2006-10-09 12:33:22 UTC (rev 23325)
@@ -16,14 +16,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
-
+
#include "config.h"
#include "zip.h"
#include "string_utils.h"
+static gboolean ZipOpen (GIOChannel *ioc, GIOCondition cond, gpointer data);
void OpenZip ( XArchive *archive )
{
- gchar *command = g_strconcat ("unzip -vl -qq " , archive->escaped_path, NULL );
+ gchar *command = g_strconcat ( "unzip -vl -qq " , archive->escaped_path, NULL );
archive->dummy_size = 0;
archive->nr_of_files = 0;
archive->nr_of_dirs = 0;
@@ -39,121 +40,59 @@
xa_create_liststore ( 8, names , (GType *)types );
}
-gboolean ZipOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
+static gboolean ZipOpen (GIOChannel *ioc, GIOCondition cond, gpointer data)
{
XArchive *archive = data;
+ gchar **fields = NULL;
+ gchar *filename = NULL;
gchar *line = NULL;
- gchar *start = NULL;
- gchar *end = NULL;
- GValue *filename = NULL;
- GValue *original = NULL;
- gchar *_original = NULL;
- GValue *method = NULL;
- GValue *compressed = NULL;
- gchar *_compressed = NULL;
- GValue *ratio = NULL;
- GValue *date = NULL;
- GValue *time = NULL;
- GValue *crc32 = NULL;
- GIOStatus status;
+ GtkTreeIter iter;
+ GIOStatus status = G_IO_STATUS_NORMAL;
if (cond & (G_IO_IN | G_IO_PRI) )
{
- do
- {
- status = g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL);
- if (line == NULL)
- break;
+ do
+ {
+ g_io_channel_read_line ( ioc, &line, NULL, NULL, NULL );
+ if ( line == NULL )
+ break;
+ fields = split_line (line , 7);
+ filename = get_last_field (line , 8);
+ if ( g_str_has_suffix(filename , "/") == TRUE)
+ archive->nr_of_dirs++;
+ else
+ archive->nr_of_files++;
+ if ( filename != NULL )
+ {
+ gtk_list_store_append (liststore, &iter);
+ for ( x = 0; x < 7; x++)
+ {
+ if (x == 0 || x == 2)
+ gtk_list_store_set (liststore, &iter,x+1, atoll (fields[x]), -1);
+ else
+ gtk_list_store_set (liststore, &iter,x+1,fields[x], -1);
+ }
+ archive->dummy_size += atoll (fields[0]);
+ gtk_list_store_set (liststore, &iter,0,filename,-1);
+ }
- filename = g_new0(GValue, 1);
- original = g_new0(GValue, 1);
- method = g_new0(GValue, 1);
- compressed = g_new0(GValue, 1);
- ratio = g_new0(GValue, 1);
- date = g_new0(GValue, 1);
- time = g_new0(GValue, 1);
- crc32 = g_new0(GValue, 1);
- archive->row_cnt++;
+ while (gtk_events_pending() )
+ gtk_main_iteration();
+ g_strfreev ( fields );
+ g_free (line);
+ }
+ while (status == G_IO_STATUS_NORMAL);
- start = eat_spaces (line);
- end = strchr (start, ' ');
- original = g_value_init(original, G_TYPE_UINT64);
- _original = g_strndup ( start , end - start);
- g_value_set_uint64 ( original , atoll (_original) );
- g_free (_original);
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- method = g_value_init(method, G_TYPE_STRING);
- g_value_set_string ( method , g_strndup ( start , end - start) );
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- compressed = g_value_init(compressed, G_TYPE_UINT64);
- _compressed = g_strndup ( start , end - start);
- g_value_set_uint64 (compressed , atoll (_compressed) );
- g_free (_compressed);
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- ratio = g_value_init(ratio, G_TYPE_STRING);
- g_value_set_string ( ratio , g_strndup ( start , end - start) );
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- date = g_value_init(date, G_TYPE_STRING);
- g_value_set_string ( date , g_strndup ( start , end - start) );
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- time = g_value_init(time, G_TYPE_STRING);
- g_value_set_string ( time , g_strndup ( start , end - start) );
-
- start = eat_spaces (end);
- end = strchr (start, ' ');
- crc32 = g_value_init(crc32, G_TYPE_STRING);
- g_value_set_string ( crc32 , g_strndup ( start , end - start) );
-
- start = eat_spaces (end);
- end = strchr (start, '\n');
- filename = g_value_init(filename, G_TYPE_STRING);
- g_value_set_string ( filename , g_strndup ( start , end - start) );
-
- archive->row = g_list_prepend(archive->row, filename);
- archive->row = g_list_prepend(archive->row, original);
- archive->row = g_list_prepend(archive->row, method);
- archive->row = g_list_prepend(archive->row, compressed);
- archive->row = g_list_prepend(archive->row, ratio);
- archive->row = g_list_prepend(archive->row, date);
- archive->row = g_list_prepend(archive->row, time);
- archive->row = g_list_prepend(archive->row, crc32);
-
- if ( g_str_has_suffix (g_value_get_string (filename) , "/") == TRUE)
- archive->nr_of_dirs++;
- else
- archive->nr_of_files++;
- archive->dummy_size += g_value_get_uint64 (original);
- g_free(line);
-
- if (archive->row_cnt > 99)
- {
- xa_append_rows ( archive , 8 );
- archive->row_cnt = 0;
- }
- }
- while (status == G_IO_STATUS_NORMAL);
-
- if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
- goto done;
+ if (status == G_IO_STATUS_ERROR || status == G_IO_STATUS_EOF)
+ goto done;
}
else if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
{
-done:
- g_io_channel_shutdown ( ioc,TRUE,NULL );
+done: g_io_channel_shutdown ( ioc,TRUE,NULL );
g_io_channel_unref (ioc);
- xa_append_rows ( archive , 8 );
+ gtk_tree_view_set_model (GTK_TREE_VIEW(treeview1), model);
+ g_object_unref (model);
return FALSE;
}
return TRUE;
}
-
More information about the Xfce4-commits
mailing list