[Xfce4-commits] r25321 - in squeeze/trunk: libsqueeze po

Stephan Arts stephan at xfce.org
Wed Mar 28 12:48:50 CEST 2007


Author: stephan
Date: 2007-03-28 10:48:50 +0000 (Wed, 28 Mar 2007)
New Revision: 25321

Modified:
   squeeze/trunk/libsqueeze/archive-command.c
   squeeze/trunk/libsqueeze/archive-command.h
   squeeze/trunk/libsqueeze/command-builder-compr.c
   squeeze/trunk/libsqueeze/command-builder-compr.h
   squeeze/trunk/libsqueeze/spawn-command.c
   squeeze/trunk/po/POTFILES.in
   squeeze/trunk/po/en_GB.po
Log:
fixed compressed file support

Modified: squeeze/trunk/libsqueeze/archive-command.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.c	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/libsqueeze/archive-command.c	2007-03-28 10:48:50 UTC (rev 25321)
@@ -175,6 +175,8 @@
 	return command->archive;
 }
 
+
+
 /**
  * lsq_archive_command_get_comment
  * @command:
@@ -186,3 +188,26 @@
 {
 	return archive_command->comment;
 }
+
+LSQArchiveCommand *
+lsq_archive_command_new(const gchar *comment,
+                        LSQArchive *archive,
+                        LSQCommandFunc exec_command)
+{
+	LSQArchiveCommand *archive_command;
+
+#ifdef DEBUG
+	g_return_val_if_fail(archive, NULL);
+	g_return_val_if_fail(LSQ_IS_ARCHIVE(archive), NULL);
+#endif
+
+	archive_command = g_object_new(LSQ_TYPE_ARCHIVE_COMMAND, NULL);
+
+	archive_command->archive = archive;
+	if(comment)
+		archive_command->comment = g_strdup(comment);
+
+	archive_command->execute = exec_command;
+
+	return archive_command;
+}

Modified: squeeze/trunk/libsqueeze/archive-command.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.h	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/libsqueeze/archive-command.h	2007-03-28 10:48:50 UTC (rev 25321)
@@ -15,20 +15,23 @@
 
 #ifndef __LIBSQUEEZE_ARCHIVE_COMMAND_H__
 #define __LIBSQUEEZE_ARCHIVE_COMMAND_H__ 
+
+typedef gboolean (*LSQCommandFunc)(LSQArchiveCommand *);
+
 G_BEGIN_DECLS
 
 struct _LSQArchiveCommand
 {
-	GObject      parent;
-	GQuark       domain;
-	gchar       *comment;
-	LSQArchive  *archive;
-	GError      *error;
-	gboolean     running;
-	gboolean     safe;
-	gpointer     user_data;
-	gboolean   (*execute)(LSQArchiveCommand *);
-	gboolean   (*stop)(LSQArchiveCommand *);
+	GObject        parent;
+	GQuark         domain;
+	gchar         *comment;
+	LSQArchive    *archive;
+	GError        *error;
+	gboolean       running;
+	gboolean       safe;
+	gpointer       user_data;
+	LSQCommandFunc execute;
+	LSQCommandFunc stop;
 };
 
 struct _LSQArchiveCommandClass
@@ -43,5 +46,10 @@
 const gchar *
 lsq_archive_command_get_comment(LSQArchiveCommand *archive_command);
 
+LSQArchiveCommand *
+lsq_archive_command_new(const gchar *comment,
+                        LSQArchive *archive,
+                        LSQCommandFunc exec_command);
+
 G_END_DECLS
 #endif /* __LIBSQUEEZE_ARCHIVE_COMMAND_H__ */

Modified: squeeze/trunk/libsqueeze/command-builder-compr.c
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-compr.c	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/libsqueeze/command-builder-compr.c	2007-03-28 10:48:50 UTC (rev 25321)
@@ -27,6 +27,8 @@
 #include "libsqueeze-module.h"
 #include "command-builder-compr.h"
 
+#define LSQ_ARCHIVE_DEST_FILE "compr_dest_file"
+
 static void
 lsq_command_builder_compr_class_init(LSQCommandBuilderComprClass *);
 static void
@@ -45,6 +47,13 @@
 static LSQArchiveCommand *
 lsq_command_builder_compr_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
 
+static gboolean
+lsq_command_builder_compr_refresh(LSQArchiveCommand *command);
+static gboolean
+lsq_command_builder_compr_compress_parse_output(LSQSpawnCommand *, gpointer);
+static gboolean
+lsq_command_builder_compr_decompress_parse_output(LSQSpawnCommand *, gpointer);
+
 static GObjectClass *parent_class;
 
 GType
@@ -127,14 +136,61 @@
 	parent_class->finalize(object);
 }
 
+const gchar *
+lsq_command_builder_compr_get_decompress_skeleton(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+	const gchar *decompress_skeleton = NULL;
 
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-compress"))
+		decompress_skeleton = "uncompress -c %1$s";
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-gzip"))
+		decompress_skeleton = "gunzip -c %1$s";
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-bzip"))
+		decompress_skeleton = "bunzip2 -c %1$s";
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-lzop"))
+		decompress_skeleton = "lzop -dc %1$s";
+
+	return decompress_skeleton;
+}
+
+const gchar *
+lsq_command_builder_compr_get_compress_skeleton(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+	const gchar *compress_skeleton = NULL;
+
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-compress"))
+		compress_skeleton = "compress -c %1$s";
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-gzip"))
+		compress_skeleton = "gzip -c %1$s";
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-bzip"))
+		compress_skeleton = "bzip2 -c %1$s";
+	if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-lzop"))
+		compress_skeleton = "lzop -c %1$s";
+
+	return compress_skeleton;
+}
+
+
 static LSQArchiveCommand *
 lsq_command_builder_compr_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
 {
-	gchar *files = lsq_concat_filenames(filenames);
-	LSQArchiveCommand *spawn = lsq_spawn_command_new("Add", archive, "compr %3$s -r %1$s %2$s", files, NULL, NULL);
-	g_free(files);
-	return spawn;
+#ifdef DEBUG
+	g_return_val_if_fail(filenames, NULL);
+#endif
+
+	const gchar *compress_skeleton = lsq_command_builder_compr_get_compress_skeleton(builder, archive);
+	LSQArchiveCommand *compress = lsq_spawn_command_new(_("Compressing"), 
+	                                                      archive,
+	                                                      compress_skeleton,
+	                                                      NULL,
+	                                                      NULL,
+	                                                      filenames->data);
+
+	if(!lsq_spawn_command_set_parse_func(LSQ_SPAWN_COMMAND(compress), 1, lsq_command_builder_compr_compress_parse_output, NULL))
+	{
+		g_critical("Could not set compress parse function");
+	}
+	return compress;
 }
 
 static LSQArchiveCommand *
@@ -146,22 +202,142 @@
 static LSQArchiveCommand *
 lsq_command_builder_compr_build_extract(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *filenames)
 {
-	gchar *files = lsq_concat_filenames(filenames);
-	gchar *options = g_strconcat(" -d ", dest_path, NULL);
+	gchar *filename = lsq_archive_get_filename(archive);
+	gint length = strlen(filename);
+	if(g_str_has_suffix(filename, ".gz"))
+		filename[length-3] = '\0';
+	if(g_str_has_suffix(filename, ".bz"))
+		filename[length-3] = '\0';
+	if(g_str_has_suffix(filename, ".bz2"))
+		filename[length-4] = '\0';
+	if(g_str_has_suffix(filename, ".lzo"))
+		filename[length-4] = '\0';
+	if(g_str_has_suffix(filename, ".Z"))
+		filename[length-2] = '\0';
 
-	LSQArchiveCommand *spawn = lsq_spawn_command_new("Extract", archive, "uncompr -o %1$s %2$s %3$s", files, options, NULL);
+	gchar *dest_file = g_strconcat(dest_path, filename, NULL);
+	g_free(filename);
 
-	g_free(options);
-	g_free(files);
-	return spawn;
+	const gchar *decompress_skeleton = lsq_command_builder_compr_get_decompress_skeleton(builder, archive);
+	LSQArchiveCommand *decompress = lsq_spawn_command_new(_("Decompressing"), 
+	                                                      archive,
+	                                                      decompress_skeleton,
+	                                                      NULL,
+	                                                      NULL,
+	                                                      NULL);
+
+	g_object_set_data(G_OBJECT(decompress), LSQ_ARCHIVE_DEST_FILE, dest_file);
+
+	if(!lsq_spawn_command_set_parse_func(LSQ_SPAWN_COMMAND(decompress), 1, lsq_command_builder_compr_decompress_parse_output, NULL))
+	{
+		g_critical("Could not set decompress parse function");
+	}
+	return decompress;
 }
 
 static LSQArchiveCommand *
 lsq_command_builder_compr_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive)
 {
-	return NULL;
+	LSQArchiveCommand *command = lsq_archive_command_new("Refresh", archive, lsq_command_builder_compr_refresh);
+
+	return command;
 }
 
+static gboolean
+lsq_command_builder_compr_refresh(LSQArchiveCommand *command)
+{
+	LSQArchiveIter *entry;
+	LSQArchive *archive = lsq_archive_command_get_archive(command);
+	gchar *filename = lsq_archive_get_filename(archive);
+	gint length = strlen(filename);
+	if(g_str_has_suffix(filename, ".gz"))
+		filename[length-3] = '\0';
+	if(g_str_has_suffix(filename, ".bz"))
+		filename[length-3] = '\0';
+	if(g_str_has_suffix(filename, ".bz2"))
+		filename[length-4] = '\0';
+	if(g_str_has_suffix(filename, ".lzo"))
+		filename[length-4] = '\0';
+	if(g_str_has_suffix(filename, ".Z"))
+		filename[length-2] = '\0';
+
+	entry = lsq_archive_add_file(archive, filename);
+	lsq_archive_iter_unref(entry);
+	g_free(filename);
+
+	return TRUE;
+}
+
+static gboolean
+lsq_command_builder_compr_decompress_parse_output(LSQSpawnCommand *spawn_command, gpointer user_data)
+{
+	GIOStatus status = G_IO_STATUS_NORMAL;
+	gchar *buf = g_new0(gchar, 1024);
+	guint read = 0;
+	GError *error = NULL;
+	FILE *out_file;
+
+	const gchar *out_filename = g_object_get_data(G_OBJECT(spawn_command), LSQ_ARCHIVE_DEST_FILE);
+
+	out_file = fopen(out_filename, "ab");
+	if(!out_file)
+		return FALSE; 
+	
+	status = lsq_spawn_command_read_bytes(spawn_command, 1, buf, 1024, (gsize *)&read, &error);
+	if(status == G_IO_STATUS_EOF)
+	{
+		fclose(out_file);
+		return TRUE;
+	}
+
+	if(read)
+	{
+		fwrite(buf, 1, read, out_file);
+	}
+	fclose(out_file);
+	g_free(buf);
+
+	return TRUE;
+}
+
+static gboolean
+lsq_command_builder_compr_compress_parse_output(LSQSpawnCommand *spawn_command, gpointer user_data)
+{
+	GIOStatus status = G_IO_STATUS_NORMAL;
+	gchar *buf = g_new0(gchar, 1024);
+	LSQArchive *archive = lsq_archive_command_get_archive(LSQ_ARCHIVE_COMMAND(spawn_command));
+	guint read = 0;
+	GError *error = NULL;
+	FILE *out_file;
+
+	const gchar *out_filename = lsq_archive_get_path(archive);
+	gboolean remove = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(spawn_command), "compressing"));
+	if(remove == FALSE)
+	{
+		g_object_set_data(G_OBJECT(spawn_command), "compressing", GUINT_TO_POINTER(TRUE));
+		g_unlink(out_filename);
+	}
+
+	out_file = fopen(out_filename, "ab");
+	if(!out_file)
+		return FALSE; 
+	
+	status = lsq_spawn_command_read_bytes(spawn_command, 1, buf, 1024, (gsize *)&read, &error);
+	if(status == G_IO_STATUS_EOF)
+	{
+		fclose(out_file);
+		return TRUE;
+	}
+
+	if(read)
+	{
+		fwrite(buf, 1, read, out_file);
+	}
+	fclose(out_file);
+	g_free(buf);
+	return TRUE;
+}
+
 LSQCommandBuilder *
 lsq_command_builder_compr_new()
 {

Modified: squeeze/trunk/libsqueeze/command-builder-compr.h
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-compr.h	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/libsqueeze/command-builder-compr.h	2007-03-28 10:48:50 UTC (rev 25321)
@@ -54,4 +54,9 @@
 GType                lsq_command_builder_compr_get_type(void);
 LSQCommandBuilder   *lsq_command_builder_compr_new();
 
+const gchar *
+lsq_command_builder_compr_get_decompress_skeleton(LSQCommandBuilder *builder, LSQArchive *archive);
+const gchar *
+lsq_command_builder_compr_get_compress_skeleton(LSQCommandBuilder *builder, LSQArchive *archive);
+
 #endif /* __LIBSQUEEZE_COMMAND_BUILDER_COMPR_H__ */

Modified: squeeze/trunk/libsqueeze/spawn-command.c
===================================================================
--- squeeze/trunk/libsqueeze/spawn-command.c	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/libsqueeze/spawn-command.c	2007-03-28 10:48:50 UTC (rev 25321)
@@ -159,7 +159,7 @@
 	g_return_val_if_fail(LSQ_IS_ARCHIVE(archive), NULL);
 #endif
 
-	archive_command = g_object_new(lsq_spawn_command_get_type(), NULL);
+	archive_command = g_object_new(LSQ_TYPE_SPAWN_COMMAND, NULL);
 
 	if(!files)
 		files = "";

Modified: squeeze/trunk/po/POTFILES.in
===================================================================
--- squeeze/trunk/po/POTFILES.in	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/po/POTFILES.in	2007-03-28 10:48:50 UTC (rev 25321)
@@ -7,7 +7,7 @@
 libsqueeze/command-builder-compr.c
 libsqueeze/archive-command.c
 libsqueeze/spawn-command.c
-libsqueeze/dbus-command.c
+libsqueeze/xfce-launch-command.c
 libsqueeze/macro-command.c
 libsqueeze/vfs-mime.c
 libsqueeze/internals.c

Modified: squeeze/trunk/po/en_GB.po
===================================================================
--- squeeze/trunk/po/en_GB.po	2007-03-28 07:02:13 UTC (rev 25320)
+++ squeeze/trunk/po/en_GB.po	2007-03-28 10:48:50 UTC (rev 25321)
@@ -15,7 +15,7 @@
 "Language-Team: English/GB\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit"
+"Content-Transfer-Encoding: 8bit\n"
 
 #: ../libsqueeze/archive.c:293
 msgid "Name"
@@ -542,4 +542,3 @@
 #: ../squeeze.desktop.in.h:2
 msgid "Xfce archive manager"
 msgstr "Xfce archive manager"
-



More information about the Xfce4-commits mailing list