Author: colossus
Date: 2006-06-23 05:57:29 +0000 (Fri, 23 Jun 2006)
New Revision: 22187

Modified:
   xarchiver/trunk/TODO
   xarchiver/trunk/src/callbacks.c
   xarchiver/trunk/src/main.c
Log:
Fixed seg fault when using the -a switch. Thanks to Olivier and JP for 
reporting this. Added -n switch for allowing archive creation. 
Updated TODO file.


Modified: xarchiver/trunk/TODO
===================================================================
--- xarchiver/trunk/TODO        2006-06-23 02:25:25 UTC (rev 22186)
+++ xarchiver/trunk/TODO        2006-06-23 05:57:29 UTC (rev 22187)
@@ -2,7 +2,6 @@
   - add display of ID's inside the ISO plus image type [PARTIALLY DONE]
   - add view function
   - fix extraction routine since the files inside the directories are not 
extracted
-  - fix drag from Xarchiver window since the dragged files is not extracted
 
 - polish the code in main.c regarding the cmd-line switches; -d do not work 
with TAR_GZ and TAR_BZ2.
-- fix bugs #1736, #1849, #1879, #1937, #1938
+- fix bugs #1736, #1849, #1879, #1937

Modified: xarchiver/trunk/src/callbacks.c
===================================================================
--- xarchiver/trunk/src/callbacks.c     2006-06-23 02:25:25 UTC (rev 22186)
+++ xarchiver/trunk/src/callbacks.c     2006-06-23 05:57:29 UTC (rev 22187)
@@ -27,6 +27,7 @@
 
 extern GList *ArchiveType;
 extern GList *ArchiveSuffix;
+extern gchar *new_archive;
 
 #ifndef HAVE_STRCASESTR
 /*
@@ -737,6 +738,8 @@
                                gtk_combo_box_append_text (GTK_COMBO_BOX 
(combo_box), Name->data );
                        Name = g_list_next ( Name );
                }
+               if (new_archive)
+                       gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER 
(File_Selector),new_archive);
                gtk_combo_box_set_active (GTK_COMBO_BOX (combo_box), 0);
                gtk_box_pack_start (GTK_BOX (hbox), combo_box, TRUE, TRUE, 0);
                check_button = gtk_check_button_new_with_label (_("Add the 
archive extension to the filename"));
@@ -1538,9 +1541,11 @@
 {
     gchar *local_path;
     gchar *local_escaped_path;
+       gchar *no_path = StripPathFromFilename(filename);
+       no_path++;
 
     unsigned short int x;
-    x = strlen (path) - strlen ( filename );
+    x = strlen (path) - strlen ( no_path );
     //g_print ("%d\t%d\t%d\n",x,strlen (path),strlen (filename));
     local_path = (gchar *) g_malloc ( x + 1);
     strncpy ( local_path, path, x );
@@ -1553,33 +1558,33 @@
 void drag_begin (GtkWidget *treeview1,GdkDragContext *context, gpointer data)
 {
     GtkTreeSelection *selection;
-    GtkTreeModel     *model;
     GtkTreeIter       iter;
     gchar            *name;
-    GList            *row_list = NULL;
+    GList            *row_list, *_row_list;
 
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview1));
 
-    /* if no or more than one rows selected, do nothing, just for sanity */
-    if ( gtk_tree_selection_count_selected_rows (selection) != 1)
-               return;
-
-    row_list = gtk_tree_selection_get_selected_rows (selection, &model);
+       row_list = _row_list = gtk_tree_selection_get_selected_rows (selection, 
NULL);
        if ( row_list == NULL )
                return;
 
-       gtk_tree_model_get_iter(model, &iter, row_list->data);
+       while (_row_list != NULL)
+       {
+               gtk_tree_model_get_iter(model, &iter, 
(GtkTreePath*)(_row_list->data));
+           gtk_tree_model_get (model, &iter, 0, &name, -1);
+               gchar *no_slashes = StripPathFromFilename ( name );
+               g_free (name);
+               no_slashes++;
 
-    gtk_tree_path_free(row_list->data);
-    g_list_free (row_list);
+               gdk_property_change (context->source_window,
+                                      gdk_atom_intern ("XdndDirectSave0", 
FALSE),
+                                          gdk_atom_intern ("text/plain", 
FALSE), 8,
+                                              GDK_PROP_MODE_REPLACE, (guchar 
*)no_slashes, strlen (no_slashes) );
 
-    gtk_tree_model_get (model, &iter, 0, &name, -1);
-       //TODO: fix bug 1879, name must be without path.
-    gdk_property_change (context->source_window,
-                       gdk_atom_intern ("XdndDirectSave0", FALSE),
-                       gdk_atom_intern ("text/plain", FALSE), 8,
-                       GDK_PROP_MODE_REPLACE, (guchar *)name, strlen (name) );
-    g_free (name);
+               _row_list = _row_list->next;
+       }
+       g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
+       g_list_free (row_list);
 }
 
 void drag_end (GtkWidget *treeview1,GdkDragContext *context, gpointer data)
@@ -1590,60 +1595,60 @@
 void drag_data_get (GtkWidget *widget, GdkDragContext *dc, GtkSelectionData 
*selection_data, guint info, guint t, gpointer data)
 {
     GtkTreeSelection *selection;
-    GtkTreeModel *model;
     GtkTreeIter iter;
     guchar *fm_path;
     int fm_path_len;
     gchar *command , *dummy_path , *name;
     gchar *to_send = "E";
-    GList *row_list = NULL;
+    GList *row_list, *_row_list;
 
     selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview1));
-    /* if no or more than one rows selected, do nothing, just for sanity */
-    if ( gtk_tree_selection_count_selected_rows (selection) != 1)
-               return;
-
-    row_list = gtk_tree_selection_get_selected_rows (selection, &model);
+    row_list = _row_list = gtk_tree_selection_get_selected_rows (selection, 
NULL);
        if ( row_list == NULL )
                return;
 
-       gtk_tree_model_get_iter(model, &iter, row_list->data);
-
-    gtk_tree_path_free(row_list->data);
-    g_list_free (row_list);
-
-    gtk_tree_model_get (model, &iter, 0, &name, -1);
-    if ( gdk_property_get (dc->source_window,
+       while (_row_list != NULL)
+       {
+               gtk_tree_model_get_iter(model, &iter, 
(GtkTreePath*)(_row_list->data));
+           gtk_tree_model_get (model, &iter, 0, &name, -1);
+               if ( gdk_property_get (dc->source_window,
                             gdk_atom_intern ("XdndDirectSave0", FALSE),
                             gdk_atom_intern ("text/plain", FALSE),
                             0, 1024, FALSE, NULL, NULL, &fm_path_len, &fm_path)
                             && fm_path != NULL)
-    {
-        /* Zero-Terminate the string */
-        fm_path = g_realloc (fm_path, fm_path_len + 1);
-        fm_path[fm_path_len] = '\000';
-        dummy_path = g_filename_from_uri ( (gchar*)fm_path, NULL, NULL );
-        g_free ( fm_path );
-        extract_path = extract_local_path ( dummy_path,name );
-        g_free ( dummy_path );
-        if (extract_path != NULL)
-                       to_send = "S";
-        names = g_string_new ("");
-        gtk_tree_selection_selected_foreach (selection, 
(GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );
-        command = xa_extract_single_files ( archive , names, extract_path );
-               g_string_free (names, TRUE);
-        if ( command != NULL )
-        {
-            ExtractAddDelete ( command );
-            g_free (command);
-        }
-        //g_dataset_set_data (dc, "XDS-sent", to_send);
-        gtk_selection_data_set (selection_data, gdk_atom_intern ("XA_STRING", 
FALSE), 8, (guchar*)to_send, 1);
-    }
-    if (extract_path != NULL)
-               g_free (extract_path);
-    extract_path = NULL;
-    g_free (name);
+           {
+                   /* Zero-Terminate the string */
+               fm_path = g_realloc (fm_path, fm_path_len + 1);
+                       fm_path[fm_path_len] = '\000';
+                       dummy_path = g_filename_from_uri ( (gchar*)fm_path, 
NULL, NULL );
+                       g_free ( fm_path );
+                       extract_path = extract_local_path ( dummy_path,name );
+                       //g_message ("%s -- %s -- 
%s",dummy_path,name,extract_path);
+                       g_free ( dummy_path );
+                       if (extract_path != NULL)
+                               to_send = "S";
+                   names = g_string_new ("");
+               gtk_tree_selection_selected_foreach (selection, 
(GtkTreeSelectionForeachFunc) ConcatenateFileNames, names );
+                       archive->full_path = 0;
+                       archive->tar_strip_value = 0;
+                       command = xa_extract_single_files ( archive , names, 
extract_path );
+                       g_string_free (names, TRUE);
+                       if ( command != NULL )
+               {
+                       ExtractAddDelete ( command );
+                           g_free (command);
+               }
+                   //g_dataset_set_data (dc, "XDS-sent", to_send);
+               gtk_selection_data_set (selection_data, gdk_atom_intern 
("XA_STRING", FALSE), 8, (guchar*)to_send, 1);
+           }
+               if (extract_path != NULL)
+                       g_free (extract_path);
+               extract_path = NULL;
+               g_free (name);
+               _row_list = _row_list->next;
+       }
+       g_list_foreach (row_list, (GFunc) gtk_tree_path_free, NULL);
+       g_list_free (row_list);
 }
 
 void on_drag_data_received (GtkWidget *widget,GdkDragContext *context, int 
x,int y,GtkSelectionData *data, unsigned int info, unsigned int time, gpointer 
user_data)

Modified: xarchiver/trunk/src/main.c
===================================================================
--- xarchiver/trunk/src/main.c  2006-06-23 02:25:25 UTC (rev 22186)
+++ xarchiver/trunk/src/main.c  2006-06-23 05:57:29 UTC (rev 22187)
@@ -22,6 +22,8 @@
 extern XArchive *archive;
 
 gchar *cli_command = NULL;
+gchar *archive_name;
+gchar *new_archive;
 gchar *absolute_path = NULL;
 GError *cli_error = NULL;
 gboolean error_output, file_to_open, ask_and_extract, ask_and_add;
@@ -31,8 +33,9 @@
 {
        { "extract-to=[FOLDER] [archive name]", 'x', 0, G_OPTION_ARG_FILENAME, 
&extract_path, N_("Extract the archive to the specified folder and quits."), 
NULL },
        { "extract [archive name]", 'e', 0, G_OPTION_ARG_NONE, 
&ask_and_extract, N_("Extract the archive by asking the destination folder and 
quits."), NULL },
-       { "add-to=[archive name] [file1] [file2] ... [fileX]", 'd', 0, 
G_OPTION_ARG_FILENAME, &path, N_("Add files to the specified archive and 
quits."), NULL },
+       { "add-to=[archive name] [file1] [file2] ... [fileN]", 'd', 0, 
G_OPTION_ARG_FILENAME, &archive_name, N_("Add files to the specified archive 
and quits."), NULL },
        { "add [archive name]", 'a', 0, G_OPTION_ARG_NONE, &ask_and_add, 
N_("Add files to the specified archive by asking their filenames and quits."), 
NULL },
+       { "new [archive name] [file1] [file2] ... [fileN]", 'n', 0, 
G_OPTION_ARG_FILENAME, &new_archive, N_("Ask for the archive name to be 
created, add files to this new archive and quits."), NULL },
        { NULL }
 };
 
@@ -50,7 +53,7 @@
                g_error_free (cli_error);
                return 0;
        }
-       if (ask_and_extract || ask_and_add || path != NULL || extract_path != 
NULL)
+       if (ask_and_extract || ask_and_add || archive_name != NULL || 
new_archive != NULL || extract_path != NULL)
                cli = TRUE;
 
        if (cli == TRUE)
@@ -105,12 +108,12 @@
                        }
                }
                //Switch -d
-               else if (path != NULL)
+               else if (archive_name != NULL)
                {
-                       GString *string = g_string_new ( "" );
-                       archive = xa_init_structure_from_cmd_line ( path );
+                       archive = xa_init_structure_from_cmd_line ( 
archive_name );
                        if (archive != NULL)
                        {
+                               GString *string = g_string_new ( "" );
                                for ( x = 1; x < argc; x++)
                                        ConcatenateFileNames2 ( argv[x] , 
string );
 
@@ -123,6 +126,11 @@
                //Switch -a
                else if (ask_and_add)
                {
+                       if (argv[1] == NULL)
+                       {
+                               g_print (_("xarchiver: You missed the archive 
name!\n"));
+                               return 0;
+                       }
                        archive = xa_init_structure_from_cmd_line ( argv[1] );
                        if (archive != NULL)
                        {
@@ -134,12 +142,33 @@
                                g_free (add_window);
                        }
                }
-               if (cli_command != NULL)
-                       g_free (cli_command);
+               //Switch -n
+               else if (new_archive)
+               {
+                       if (argv[1] == NULL)
+                       {
+                               g_print (_("xarchiver: You missed the files to 
be added!\n"));
+                               return 0;
+                       }
+                       xa_new_archive ( NULL , NULL );
+                       if (archive->path != NULL)
+                       {
+                               GString *string = g_string_new ( "" );
+                               for ( x = 1; x < argc; x++)
+                                       ConcatenateFileNames2 ( argv[x] , 
string );
 
+                               cli_command = xa_add_single_files ( archive , 
string, NULL);
+                               if (cli_command != NULL)
+                                       error_output = SpawnSyncCommand ( 
cli_command );
+                               g_string_free (string, TRUE);
+                       }
+                       if (cli_command != NULL)
+                               g_free (cli_command);
+               }
                g_list_free ( ArchiveSuffix);
                g_list_free ( ArchiveType);
-               xa_clean_archive_structure ( archive );
+               if (archive != NULL)
+                       xa_clean_archive_structure ( archive );
                return 0;
        }
        else

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to