[file-roller] FrCommand: set the filename before each call to fr_command_* functions



commit 5e48592fb49d1f5ce713fcd77d44acd664de4b6a
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Jun 18 11:20:55 2012 +0200

    FrCommand: set the filename before each call to fr_command_* functions
    
    this change will allow the command to use a different filename from
    the one pointed to by the local_copy attribute.

 src/fr-archive.c     |   24 +++++++++++++++---------
 src/fr-command-7z.c  |    8 ++++++--
 src/fr-command-rar.c |    8 ++++++--
 src/fr-command.c     |   41 +++++++++++++++++++++++++++--------------
 src/fr-command.h     |    6 +++---
 src/rar-utils.c      |   11 ++++-------
 6 files changed, 61 insertions(+), 37 deletions(-)
---
diff --git a/src/fr-archive.c b/src/fr-archive.c
index d7cb0f3..ef6d3cb 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -622,18 +622,13 @@ create_command_from_type (FrArchive     *archive,
 		          GType          command_type,
 		          FrCommandCaps  requested_capabilities)
 {
-	char *filename;
-
 	if (command_type == 0)
 		return FALSE;
 
-	filename = g_file_get_path (archive->local_copy);
 	archive->command = FR_COMMAND (g_object_new (command_type,
 					             "process", archive->process,
-					             "filename", filename,
 					             "mime-type", mime_type,
 					             NULL));
-	g_free (filename);
 
 	if (! fr_command_is_capable_of (archive->command, requested_capabilities)) {
 		g_object_unref (archive->command);
@@ -1201,9 +1196,11 @@ load_local_archive (FrArchive  *archive,
 	/**/
 
 	fr_process_clear (archive->process);
-	g_object_set (archive->command, "password", password, NULL);
+	g_object_set (archive->command,
+		      "file", archive->local_copy,
+		      "password", password,
+		      NULL);
 	fr_command_list (archive->command);
-	fr_process_start (archive->process);
 }
 
 
@@ -1575,6 +1572,7 @@ fr_archive_add (FrArchive     *archive,
 		return;
 
 	g_object_set (archive->command,
+		      "file", archive->local_copy,
 		      "password", password,
 		      "encrypt_header", encrypt_header,
 		      "compression", compression,
@@ -2354,6 +2352,7 @@ add_dropped_items (DroppedItemsData *data)
 
 	fr_archive_stoppable (archive, FALSE);
 	g_object_set (archive->command,
+		      "file", archive->local_copy,
 		      "password", data->password,
 		      "encrypt_header", data->encrypt_header,
 		      "compression", data->compression,
@@ -2585,7 +2584,10 @@ fr_archive_remove (FrArchive     *archive,
 		return;
 
 	fr_archive_stoppable (archive, FALSE);
-	g_object_set (archive->command, "compression", compression, NULL);
+	g_object_set (archive->command,
+		      "file", archive->local_copy,
+		      "compression", compression,
+		      NULL);
 	fr_command_uncompress (archive->command);
 	delete_from_archive (archive, file_list);
 	fr_command_recompress (archive->command);
@@ -2954,6 +2956,7 @@ fr_archive_extract_to_local (FrArchive  *archive,
 	g_return_if_fail (archive != NULL);
 
 	fr_archive_stoppable (archive, TRUE);
+	g_object_set (archive->command, "file", archive->local_copy, NULL);
 
 	/* if a command supports all the requested options use
 	 * fr_command_extract directly. */
@@ -3307,7 +3310,10 @@ fr_archive_test (FrArchive  *archive,
 {
 	fr_archive_stoppable (archive, TRUE);
 
-	g_object_set (archive->command, "password", password, NULL);
+	g_object_set (archive->command,
+		      "file", archive->local_copy,
+		      "password", password,
+		      NULL);
 	fr_process_clear (archive->process);
 	fr_command_set_n_files (archive->command, 0);
 	fr_command_test (archive->command);
diff --git a/src/fr-command-7z.c b/src/fr-command-7z.c
index 9aa904c..675651c 100644
--- a/src/fr-command-7z.c
+++ b/src/fr-command-7z.c
@@ -286,10 +286,14 @@ process_line__add (char     *line,
 	FrCommand *comm = FR_COMMAND (data);
 
 	if ((comm->volume_size > 0) && (strncmp (line, "Creating archive ", 17) == 0)) {
-		char *volume_filename;
+		char  *volume_filename;
+		GFile *volume_file;
 
 		volume_filename = g_strconcat (comm->filename, ".001", NULL);
-		fr_command_set_multi_volume (comm, volume_filename);
+		volume_file = g_file_new_for_path (volume_filename);
+		fr_command_set_multi_volume (comm, volume_file);
+
+		g_object_unref (volume_file);
 		g_free (volume_filename);
 	}
 
diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c
index 4f850bf..36238e4 100644
--- a/src/fr-command-rar.c
+++ b/src/fr-command-rar.c
@@ -307,11 +307,15 @@ process_line__add (char     *line,
 		if ((comm->volume_size > 0)
 		    && g_regex_match_simple ("^.*\\.part(0)*2\\.rar$", uri, G_REGEX_CASELESS, 0))
 		{
-			char *volume_filename;
+			char  *volume_filename;
+			GFile *volume_file;
 
 			volume_filename = g_strdup (archive_filename);
 			volume_filename[strlen (volume_filename) - 5] = '1';
-			fr_command_set_multi_volume (comm, volume_filename);
+			volume_file = g_file_new_for_path (volume_filename);
+			fr_command_set_multi_volume (comm, volume_file);
+
+			g_object_unref (volume_file);
 			g_free (volume_filename);
 		}
 		fr_command_working_archive (comm, uri);
diff --git a/src/fr-command.c b/src/fr-command.c
index f42b461..cee582e 100644
--- a/src/fr-command.c
+++ b/src/fr-command.c
@@ -47,7 +47,7 @@ enum {
 /* Properties */
 enum {
         PROP_0,
-        PROP_FILENAME,
+        PROP_FILE,
         PROP_MIME_TYPE,
         PROP_PROCESS,
         PROP_PASSWORD,
@@ -288,8 +288,8 @@ fr_command_set_property (GObject      *object,
 	case PROP_PROCESS:
 		fr_command_set_process (comm, g_value_get_object (value));
 		break;
-	case PROP_FILENAME:
-		fr_command_set_filename (comm, g_value_get_string (value));
+	case PROP_FILE:
+		fr_command_set_file (comm, g_value_get_object (value));
 		break;
 	case PROP_MIME_TYPE:
 		fr_command_set_mime_type (comm, g_value_get_string (value));
@@ -327,8 +327,8 @@ fr_command_get_property (GObject    *object,
 	case PROP_PROCESS:
 		g_value_set_object (value, comm->process);
 		break;
-	case PROP_FILENAME:
-		g_value_set_string (value, comm->filename);
+	case PROP_FILE:
+		g_value_take_object (value, g_file_new_for_path (comm->filename));
 		break;
 	case PROP_MIME_TYPE:
 		g_value_set_static_string (value, comm->mime_type);
@@ -443,11 +443,11 @@ fr_command_class_init (FrCommandClass *class)
 							      FR_TYPE_PROCESS,
 							      G_PARAM_READWRITE));
 	g_object_class_install_property (gobject_class,
-					 PROP_FILENAME,
-					 g_param_spec_string ("filename",
-							      "Filename",
-							      "The archive filename",
-							      NULL,
+					 PROP_FILE,
+					 g_param_spec_object ("file",
+							      "File",
+							      "The archive local file",
+							      G_TYPE_FILE,
 							      G_PARAM_READWRITE));
 	g_object_class_install_property (gobject_class,
 					 PROP_MIME_TYPE,
@@ -541,7 +541,7 @@ fr_command_finalize (GObject *object)
 }
 
 
-void
+static void
 fr_command_set_filename (FrCommand  *comm,
 			 const char *filename)
 {
@@ -582,11 +582,24 @@ fr_command_set_filename (FrCommand  *comm,
 
 
 void
-fr_command_set_multi_volume (FrCommand  *comm,
-			     const char *filename)
+fr_command_set_file (FrCommand *comm,
+		     GFile     *file)
 {
-	comm->multi_volume = TRUE;
+	char *filename;
+
+	filename = g_file_get_path (file);
 	fr_command_set_filename (comm, filename);
+
+	g_free (filename);
+}
+
+
+void
+fr_command_set_multi_volume (FrCommand *comm,
+			     GFile     *file)
+{
+	comm->multi_volume = TRUE;
+	fr_command_set_file (comm, file);
 }
 
 
diff --git a/src/fr-command.h b/src/fr-command.h
index e3dd15e..a4e5b3f 100644
--- a/src/fr-command.h
+++ b/src/fr-command.h
@@ -168,10 +168,10 @@ struct _FrCommandClass
 };
 
 GType          fr_command_get_type            (void);
-void           fr_command_set_filename        (FrCommand     *comm,
-					       const char    *filename);
+void           fr_command_set_file            (FrCommand     *comm,
+					       GFile         *file);
 void           fr_command_set_multi_volume    (FrCommand     *comm,
-					       const char    *filename);
+					       GFile         *file);
 void           fr_command_list                (FrCommand     *comm);
 void           fr_command_add                 (FrCommand     *comm,
 					       const char    *from_file,
diff --git a/src/rar-utils.c b/src/rar-utils.c
index 0cb34e2..fb67ef9 100644
--- a/src/rar-utils.c
+++ b/src/rar-utils.c
@@ -119,16 +119,13 @@ rar_check_multi_vomule (FrCommand *comm)
 
 		if (volume_name != NULL) {
 			GFile *parent;
-			GFile *child;
-			char  *volume_filename;
+			GFile *volume_file;
 
 			parent = g_file_get_parent (file);
-			child = g_file_get_child (parent, volume_name);
-			volume_filename = g_file_get_path (child);
-			fr_command_set_multi_volume (comm, volume_filename);
+			volume_file = g_file_get_child (parent, volume_name);
+			fr_command_set_multi_volume (comm, volume_file);
 
-			g_free (volume_filename);
-			g_object_unref (child);
+			g_object_unref (volume_file);
 			g_object_unref (parent);
 		}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]