Author: colossus
Date: 2006-12-22 12:43:23 +0000 (Fri, 22 Dec 2006)
New Revision: 24165

Modified:
   xarchiver/trunk/TODO
   xarchiver/trunk/src/callbacks.c
   xarchiver/trunk/src/callbacks.h
   xarchiver/trunk/src/main.c
   xarchiver/trunk/src/pref_dialog.c
   xarchiver/trunk/src/rpm.c
Log:
Made the archive structure to be allocated only if the archive is a valid one.
Updated TODO.


Modified: xarchiver/trunk/TODO
===================================================================
--- xarchiver/trunk/TODO        2006-12-22 07:40:13 UTC (rev 24164)
+++ xarchiver/trunk/TODO        2006-12-22 12:43:23 UTC (rev 24165)
@@ -1,5 +1,5 @@
 - fix bug #2176.
-- use of libmagic ??
+- fix missing add/extract/properties when with one archive loaded Xarchiver 
doesn't recognize another one (sudoku.tar)
 - get rid of memory leaks notified by valgrind
 - allow switching by right click on the toolbar to icons with text/ no text/ 
small icons.
 - add a small progress window when using Xarchiver cmd-line switches.

Modified: xarchiver/trunk/src/callbacks.c
===================================================================
--- xarchiver/trunk/src/callbacks.c     2006-12-22 07:40:13 UTC (rev 24164)
+++ xarchiver/trunk/src/callbacks.c     2006-12-22 12:43:23 UTC (rev 24165)
@@ -232,6 +232,8 @@
        gchar *path = NULL;
        gint current_page;
        gint x;
+       XArchiveType type;
+
        path = (gchar *)data;
        if ( path == NULL)
     {
@@ -249,10 +251,26 @@
                if (strcmp (path,archive[current_page]->path) == 0)
                        return;
        }
+       type = xa_detect_archive_type ( path );
 
+       if (type == -1)
+       {
+               gchar *utf8_path,*msg;
+               utf8_path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
+               msg = g_strdup_printf (_("Can't open file \"%s\":"), utf8_path);
+               response = ShowGtkMessageDialog (GTK_WINDOW 
(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,msg,
+               _("Archive format is not recognized!"));
+               g_free (utf8_path);
+               g_free (msg);
+               g_free (path);
+               return;
+       }
        current_page = xa_get_new_archive_idx();
        if (current_page == -1)
+       {
+               g_free (path);
                return;
+       }
 
        archive[current_page] = xa_init_archive_structure();
        if (archive[current_page] == NULL)
@@ -262,9 +280,9 @@
                return;
        }
 
+       archive[current_page]->type = type;
        archive[current_page]->path = g_strdup (path);
        archive[current_page]->escaped_path = EscapeBadChars ( 
archive[current_page]->path , "$\'`\"\\!?* ()&|@#:;" );
-
        archive[current_page]->status = XA_ARCHIVESTATUS_OPEN;
        xa_add_page (archive[current_page]);
 
@@ -272,30 +290,6 @@
        gtk_widget_set_sensitive ( iso_info , FALSE );
        gtk_widget_set_sensitive ( view_shell_output1 , TRUE );
 
-       archive[current_page]->type = xa_detect_archive_type ( 
archive[current_page] , NULL );
-       if ( archive[current_page]->type == -2 )
-       {
-               xa_close_archive ( NULL, NULL);
-               xa_set_button_state 
(1,1,GTK_WIDGET_IS_SENSITIVE(close1),0,0,0,0,0);
-               return;
-       }
-       if ( archive[current_page]->type == -1 )
-       {
-               xa_close_archive ( NULL, NULL);
-               gchar *utf8_path,*msg;
-               utf8_path = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
-               msg = g_strdup_printf (_("Can't open file \"%s\":"), utf8_path);
-               xa_set_window_title (MainWindow , NULL);
-               response = ShowGtkMessageDialog (GTK_WINDOW 
(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,msg,
-               _("Archive format is not recognized!"));
-               xa_set_button_state ( 
1,1,GTK_WIDGET_IS_SENSITIVE(close1),0,0,0,0,0);
-               gtk_widget_set_sensitive ( check_menu , FALSE );
-               gtk_widget_set_sensitive ( properties , FALSE );
-               g_free (utf8_path);
-               g_free (msg);
-               g_free (path);
-               return;
-       }
        g_free (path);
        EmptyTextBuffer();
 
@@ -1095,22 +1089,21 @@
        }
 }
 
-int xa_detect_archive_type ( XArchive *archive , gchar *filename )
+int xa_detect_archive_type ( gchar *filename )
 {
        FILE *dummy_ptr = NULL;
     int xx = -1;
        unsigned char magic[14];
+
        if (filename != NULL)
                dummy_ptr = fopen ( filename , "r" );
-       else
-               dummy_ptr = fopen ( archive->path , "r" );
 
        if (dummy_ptr == NULL)
        {
                if ( !cli )
                {
                        gchar *utf8_path,*msg;
-                       utf8_path = g_filename_to_utf8 (archive->path, -1, 
NULL, NULL, NULL);
+                       utf8_path = g_filename_to_utf8 (filename, -1, NULL, 
NULL, NULL);
                        msg = g_strdup_printf (_("Can't open archive \"%s\":") 
, utf8_path );
                        response = ShowGtkMessageDialog (GTK_WINDOW 
(MainWindow) , GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,
                        msg,g_strerror (errno));
@@ -1121,34 +1114,29 @@
                else
                        return -2;
        }
-       if ( fread ( magic, 1, 14, dummy_ptr ) == 0 )
-       {
-               fclose ( dummy_ptr);
-               return -2;
-       }
-
+       fread ( magic, 1, 14, dummy_ptr );
        if ( memcmp ( magic,"\x50\x4b\x03\x04",4 ) == 0 || memcmp ( 
magic,"\x50\x4b\x05\x06",4 ) == 0 )
        {
-               if (archive != NULL)
+               /*if (archive != NULL)
                {
                        archive->has_passwd = xa_detect_encrypted_archive ( 
XARCHIVETYPE_ZIP , dummy_ptr , magic );
                        archive->has_comment = xa_detect_archive_comment ( 
XARCHIVETYPE_ZIP , dummy_ptr, archive );
-               }
+               }*/
                xx = XARCHIVETYPE_ZIP;
        }
        else if ( memcmp ( magic,"\x60\xea",2 ) == 0 )
        {
-               if (archive != NULL)
+               /*if (archive != NULL)
                {
                        archive->has_passwd = xa_detect_encrypted_archive ( 
XARCHIVETYPE_ARJ , dummy_ptr, magic );
                        archive->has_comment = xa_detect_archive_comment ( 
XARCHIVETYPE_ARJ , dummy_ptr, archive );
-               }
+               }*/
                xx = XARCHIVETYPE_ARJ;
        }
        else if ( memcmp ( magic,"\x52\x61\x72\x21",4 ) == 0 )
        {
-               if (archive != NULL)
-                       archive->has_comment = xa_detect_archive_comment ( 
XARCHIVETYPE_RAR , dummy_ptr, archive );
+               /*if (archive != NULL)
+                       archive->has_comment = xa_detect_archive_comment ( 
XARCHIVETYPE_RAR , dummy_ptr, archive );*/
                 xx = XARCHIVETYPE_RAR;
        }
        else if ( memcmp ( magic,"\x42\x5a\x68",3 ) == 0 ) xx = 
XARCHIVETYPE_BZIP2;
@@ -2199,7 +2187,7 @@
                filename = g_filename_from_uri ( array[0] , NULL, NULL );
                if ( filename == NULL)
                        return;
-               else if ( xa_detect_archive_type ( NULL , filename ) > 0 )
+               else if ( xa_detect_archive_type ( filename ) > 0 )
                {
                        xa_open_archive ( NULL, filename );
                        g_strfreev ( array );
@@ -2334,6 +2322,7 @@
        gchar *argv[3];
        gchar *browser_path;
 
+       //TODO: retrieve the user set browser from prefs and use it
        browser_path = g_find_program_in_path ("exo-open");
        if ( browser_path == NULL)
                browser_path = g_find_program_in_path ("htmlview");

Modified: xarchiver/trunk/src/callbacks.h
===================================================================
--- xarchiver/trunk/src/callbacks.h     2006-12-22 07:40:13 UTC (rev 24164)
+++ xarchiver/trunk/src/callbacks.h     2006-12-22 12:43:23 UTC (rev 24165)
@@ -92,7 +92,7 @@
 void drag_data_get (GtkWidget *widget, GdkDragContext *dc, GtkSelectionData 
*selection_data, guint info, guint t, gpointer data);
 
 int ShowGtkMessageDialog ( GtkWindow *window, int mode,int type,int button, 
const gchar *message1,const gchar *message2);
-int xa_detect_archive_type ( XArchive *archive , gchar *filename );
+int xa_detect_archive_type ( gchar *filename );
 gboolean xa_detect_encrypted_archive ( int type, FILE *stream, unsigned char 
magic[6] );
 gboolean xa_detect_archive_comment ( int type, FILE *stream, XArchive *archive 
);
 gboolean isTar ( FILE *ptr );

Modified: xarchiver/trunk/src/main.c
===================================================================
--- xarchiver/trunk/src/main.c  2006-12-22 07:40:13 UTC (rev 24164)
+++ xarchiver/trunk/src/main.c  2006-12-22 12:43:23 UTC (rev 24165)
@@ -436,22 +436,27 @@
 XArchive *xa_init_structure_from_cmd_line (char *filename)
 {
        XArchive *archive_cmd;
+       XArchiveType type;
+
+       type = xa_detect_archive_type ( filename );
+       if (type == -2)
+               return NULL;
+
        archive_cmd = xa_init_archive_structure ();
        if (archive_cmd == NULL)
        {
                response = ShowGtkMessageDialog 
(NULL,GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,_("Can't allocate 
memory for the archive structure!"),"" );
                return NULL;
        }
-
        archive_cmd->path = g_strdup (filename);
        archive_cmd->escaped_path = EscapeBadChars(filename , "$\'`\"\\!?* 
()&|@#:;");
-       archive_cmd->type = xa_detect_archive_type ( archive_cmd , NULL );
-       if (archive_cmd->type == -2)
-               return NULL;
+       archive_cmd->type = type;
+
        if ( g_str_has_suffix ( archive_cmd->escaped_path , ".tar.bz2") || 
g_str_has_suffix ( archive_cmd->escaped_path , ".tar.bz") || g_str_has_suffix ( 
archive_cmd->escaped_path , ".tbz") || g_str_has_suffix ( 
archive_cmd->escaped_path , ".tbz2" ) )
                archive_cmd->type = XARCHIVETYPE_TAR_BZ2;
        else if ( g_str_has_suffix ( archive_cmd->escaped_path , ".tar.gz") || 
g_str_has_suffix ( archive_cmd->escaped_path , ".tgz") )
                archive_cmd->type = XARCHIVETYPE_TAR_GZ;
+
        return (archive_cmd);
 }
 

Modified: xarchiver/trunk/src/pref_dialog.c
===================================================================
--- xarchiver/trunk/src/pref_dialog.c   2006-12-22 07:40:13 UTC (rev 24164)
+++ xarchiver/trunk/src/pref_dialog.c   2006-12-22 12:43:23 UTC (rev 24165)
@@ -39,7 +39,6 @@
                                                                        
GTK_WINDOW (MainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                                        
GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL,GTK_STOCK_OK,GTK_RESPONSE_OK, NULL);
        tooltips = gtk_tooltips_new ();
-       //gtk_notebook_set_tab_pos (prefs_notebook, GTK_POS_TOP);
        gtk_dialog_set_default_response (GTK_DIALOG (prefs_data->dialog1), 
GTK_RESPONSE_OK);
 
        vbox1 = GTK_DIALOG (prefs_data->dialog1)->vbox;
@@ -55,8 +54,9 @@
        gtk_widget_show (scrolledwindow1);
 
        prefs_data->prefs_liststore = gtk_list_store_new ( 2, GDK_TYPE_PIXBUF, 
G_TYPE_STRING);
-
        prefs_iconview = 
gtk_icon_view_new_with_model(GTK_TREE_MODEL(prefs_data->prefs_liststore));
+       g_object_unref (prefs_data->prefs_liststore);
+
        gtk_widget_set_size_request(prefs_iconview, 80, -1);
        gtk_icon_view_set_orientation (GTK_ICON_VIEW (prefs_iconview), 
GTK_ORIENTATION_VERTICAL);
        gtk_icon_view_set_columns (GTK_ICON_VIEW (prefs_iconview),1);
@@ -78,7 +78,6 @@
        icon_pixbuf = gdk_pixbuf_new_from_file 
("./pixmaps/xarchiver-extract.png", NULL);
        gtk_list_store_set (prefs_data->prefs_liststore, &iter, 0, icon_pixbuf, 
1, _("Advanced"), -1);
        g_object_unref (icon_pixbuf);
-       g_object_unref (prefs_data->prefs_liststore);
        gtk_widget_show (prefs_iconview);
 
        prefs_data->prefs_notebook = gtk_notebook_new ();

Modified: xarchiver/trunk/src/rpm.c
===================================================================
--- xarchiver/trunk/src/rpm.c   2006-12-22 07:40:13 UTC (rev 24164)
+++ xarchiver/trunk/src/rpm.c   2006-12-22 12:43:23 UTC (rev 24165)
@@ -327,7 +327,7 @@
                g_free (tmp);
                return NULL;
        }
-       if (xa_detect_archive_type ( NULL , temp_path ) == XARCHIVETYPE_GZIP)
+       if (xa_detect_archive_type ( temp_path ) == XARCHIVETYPE_GZIP)
                command = g_strconcat ( "gzip -dc " , temp_path , NULL );
        else
                command = g_strconcat ( "bzip2 -dc " , temp_path , NULL );

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to