[Xfce4-commits] r24714 - in squeeze/trunk: . docs/reference/libsqueeze libsqueeze
Stephan Arts
stephan at xfce.org
Wed Jan 24 00:25:57 CET 2007
Author: stephan
Date: 2007-01-23 23:25:57 +0000 (Tue, 23 Jan 2007)
New Revision: 24714
Added:
squeeze/trunk/docs/reference/libsqueeze/libsqueeze-overrides.txt
squeeze/trunk/libsqueeze/archive-support-compr.c
squeeze/trunk/libsqueeze/archive-support-compr.h
Modified:
squeeze/trunk/configure.in.in
squeeze/trunk/libsqueeze/Makefile.am
squeeze/trunk/libsqueeze/archive.h
squeeze/trunk/libsqueeze/libsqueeze.c
Log:
add extract support for bare gzip and bzip compressed files
Modified: squeeze/trunk/configure.in.in
===================================================================
--- squeeze/trunk/configure.in.in 2007-01-23 18:23:09 UTC (rev 24713)
+++ squeeze/trunk/configure.in.in 2007-01-23 23:25:57 UTC (rev 24714)
@@ -33,7 +33,7 @@
AC_PREREQ([2.50])
SQUEEZE_VERSION=squeeze_version
-AM_INIT_AUTOMAKE([squeeze], [$SQUEEZE_VERSION])
+AM_INIT_AUTOMAKE([1.8 dist-bzip2 tar-ustar])
AM_CONFIG_HEADER([config.h])
AM_MAINTAINER_MODE
Added: squeeze/trunk/docs/reference/libsqueeze/libsqueeze-overrides.txt
===================================================================
Modified: squeeze/trunk/libsqueeze/Makefile.am
===================================================================
--- squeeze/trunk/libsqueeze/Makefile.am 2007-01-23 18:23:09 UTC (rev 24713)
+++ squeeze/trunk/libsqueeze/Makefile.am 2007-01-23 23:25:57 UTC (rev 24714)
@@ -9,6 +9,7 @@
archive-support.c archive-support.h \
archive-support-zip.c archive-support-zip.h \
archive-support-rar.c archive-support-rar.h \
+ archive-support-compr.c archive-support-compr.h \
archive-support-gnu-tar.c archive-support-gnu-tar.h
libsqueeze_1_la_CFLAGS = \
Added: squeeze/trunk/libsqueeze/archive-support-compr.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-compr.c (rev 0)
+++ squeeze/trunk/libsqueeze/archive-support-compr.c 2007-01-23 23:25:57 UTC (rev 24714)
@@ -0,0 +1,286 @@
+/*
+ * Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <glib.h>
+#include <glib/gstdio.h>
+#include <glib-object.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "archive.h"
+#include "archive-support.h"
+#include "archive-support-compr.h"
+
+#include "internals.h"
+
+#define LSQ_ARCHIVE_DEST_FILE "compr_dest_file"
+
+static void
+lsq_archive_support_compr_init(LSQArchiveSupportCompr *support);
+static void
+lsq_archive_support_compr_class_init(LSQArchiveSupportComprClass *supportclass);
+
+void
+lsq_archive_support_compr_passive_watch(GPid pid, gint status, gpointer data);
+
+gboolean
+lsq_archive_support_compr_refresh_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data);
+
+static void
+lsq_archive_support_compr_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static void
+lsq_archive_support_compr_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+
+static gint lsq_archive_support_compr_extract(LSQArchive *, const gchar *, GSList *);
+static gint lsq_archive_support_compr_refresh(LSQArchive *);
+
+static gboolean
+lsq_archive_support_compr_decompress_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data);
+
+GType
+lsq_archive_support_compr_get_type ()
+{
+ static GType lsq_archive_support_compr_type = 0;
+
+ if (!lsq_archive_support_compr_type)
+ {
+ static const GTypeInfo lsq_archive_support_compr_info =
+ {
+ sizeof (LSQArchiveSupportComprClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_archive_support_compr_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQArchiveSupportCompr),
+ 0,
+ (GInstanceInitFunc) lsq_archive_support_compr_init,
+ };
+
+ lsq_archive_support_compr_type = g_type_register_static (LSQ_TYPE_ARCHIVE_SUPPORT, "LSQArchiveSupportCompr", &lsq_archive_support_compr_info, 0);
+ }
+ return lsq_archive_support_compr_type;
+}
+
+static void
+lsq_archive_support_compr_init(LSQArchiveSupportCompr *support)
+{
+ LSQArchiveSupport *archive_support = LSQ_ARCHIVE_SUPPORT(support);
+
+ archive_support->id = "Compr";
+ archive_support->max_n_files = 1;
+
+ lsq_archive_support_add_mime(archive_support, "application/x-gzip");
+ lsq_archive_support_add_mime(archive_support, "application/x-bzip");
+
+ archive_support->extract = lsq_archive_support_compr_extract;
+ archive_support->refresh = lsq_archive_support_compr_refresh;
+}
+
+static void
+lsq_archive_support_compr_class_init(LSQArchiveSupportComprClass *supportclass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (supportclass);
+
+ object_class->set_property = lsq_archive_support_compr_set_property;
+ object_class->get_property = lsq_archive_support_compr_get_property;
+}
+
+LSQArchiveSupport*
+lsq_archive_support_compr_new()
+{
+ LSQArchiveSupportCompr *support;
+
+ support = g_object_new(LSQ_TYPE_ARCHIVE_SUPPORT_COMPR,
+ NULL);
+
+ return LSQ_ARCHIVE_SUPPORT(support);
+}
+
+/*
+static gint
+lsq_archive_support_compr_add(LSQArchive *archive, GSList *filenames)
+{
+ gchar *command = NULL;
+
+ if(!LSQ_IS_ARCHIVE_SUPPORT_COMPR(archive->support))
+ {
+ g_critical("Support is not compr");
+ return -1;
+ }
+
+ if(!lsq_archive_support_mime_supported(archive->support, thunar_vfs_mime_info_get_name(archive->mime_info)))
+ {
+ return 1;
+ }
+ else
+ {
+ gchar *file_path = g_shell_quote(filenames->data);
+
+ if(!g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-gzip"))
+ command = g_strconcat("gzip -c ", file_path, NULL);
+ if(!g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-bzip"))
+ command = g_strconcat("bzip2 -c ", file_path, NULL);
+
+ lsq_execute(command, archive, NULL, NULL, lsq_archive_support_compr_compress_parse_output, NULL);
+
+ g_free(file_path);
+ }
+ return 0;
+}
+*/
+
+static gint
+lsq_archive_support_compr_extract(LSQArchive *archive, const gchar *extract_path, GSList *filenames)
+{
+ gchar *command = NULL;
+
+ if(!LSQ_IS_ARCHIVE_SUPPORT_COMPR(archive->support))
+ {
+ g_critical("Support is not Compr");
+ return -1;
+ }
+
+ if(!lsq_archive_support_mime_supported(archive->support, thunar_vfs_mime_info_get_name(archive->mime_info)))
+ {
+ return 1;
+ }
+ else
+ {
+ gchar *archive_path = g_shell_quote(archive->path);
+ gchar *file_path = g_strconcat(extract_path, "/", filenames->data, NULL);
+
+ if(!g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-gzip"))
+ command = g_strconcat("gunzip -c ", archive_path, NULL);
+ if(!g_strcasecmp(thunar_vfs_mime_info_get_name(archive->mime_info), "application/x-bzip"))
+ command = g_strconcat("bunzip2 -c ", archive_path, NULL);
+
+ g_unlink(file_path);
+ g_object_set_data(G_OBJECT(archive), LSQ_ARCHIVE_DEST_FILE, file_path);
+ lsq_execute(command, archive, lsq_archive_support_compr_passive_watch, NULL, lsq_archive_support_compr_decompress_parse_output, NULL);
+
+ g_free(archive_path);
+ }
+ return 0;
+}
+
+void
+lsq_archive_support_compr_passive_watch(GPid pid, gint status, gpointer data)
+{
+ LSQArchive *archive = data;
+ archive->child_pid = 0;
+}
+
+static gint
+lsq_archive_support_compr_refresh(LSQArchive *archive)
+{
+ if(!LSQ_IS_ARCHIVE_SUPPORT_COMPR(archive->support))
+ {
+ g_critical("Support is not Compr");
+ return -1;
+ }
+
+ if(!lsq_archive_support_mime_supported(archive->support, thunar_vfs_mime_info_get_name(archive->mime_info)))
+ {
+ return 1;
+ }
+ else
+ {
+ gchar *filename = g_strdup(lsq_archive_get_filename(archive));
+ gint len = strlen(filename);
+ if(g_str_has_suffix(lsq_archive_get_filename(archive), ".gz"))
+ {
+ filename[len-3] = '\0';
+ }
+ if(g_str_has_suffix(lsq_archive_get_filename(archive), ".bz"))
+ {
+ filename[len-3] = '\0';
+ }
+ if(g_str_has_suffix(lsq_archive_get_filename(archive), ".bz2"))
+ {
+ filename[len-4] = '\0';
+ }
+ lsq_archive_add_file(archive, filename);
+ g_free(filename);
+ lsq_archive_set_status(archive, LSQ_ARCHIVESTATUS_IDLE);
+ }
+ return 0;
+}
+
+static gboolean
+lsq_archive_support_compr_decompress_parse_output(GIOChannel *ioc, GIOCondition cond, gpointer data)
+{
+ FILE *out_file = NULL;
+ LSQArchive *archive = data;
+ gchar *buf = g_new0(gchar, 1024);
+ guint read = 0;
+ GError *error = NULL;
+
+ if(cond & (G_IO_PRI | G_IO_IN))
+ {
+ out_file = fopen(g_object_get_data(G_OBJECT(archive), LSQ_ARCHIVE_DEST_FILE), "ab");
+ if(!out_file)
+ g_critical("Could not open file");
+
+ while(g_io_channel_read_chars(ioc, buf, 1024, &read, &error) == G_IO_STATUS_NORMAL)
+ {
+ if(read)
+ {
+ fwrite(buf, 1, read, out_file);
+ }
+ read = 0;
+ }
+ fclose(out_file);
+ }
+ g_free(buf);
+ if(cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
+ {
+ g_io_channel_shutdown ( ioc,TRUE,NULL );
+ g_io_channel_unref (ioc);
+
+ if(!(cond & G_IO_ERR))
+ lsq_archive_set_status(archive, LSQ_ARCHIVESTATUS_IDLE);
+ else
+ lsq_archive_set_status(archive, LSQ_ARCHIVESTATUS_ERROR);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static void
+lsq_archive_support_compr_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ switch(prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
+ break;
+ }
+}
+
+static void
+lsq_archive_support_compr_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ switch(prop_id)
+ {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object,prop_id,pspec);
+ break;
+ }
+}
Added: squeeze/trunk/libsqueeze/archive-support-compr.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-compr.h (rev 0)
+++ squeeze/trunk/libsqueeze/archive-support-compr.h 2007-01-23 23:25:57 UTC (rev 24714)
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2006 Stephan Arts <stephan at xfce.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#ifndef __LIBSQUEEZE_ARCHIVE_SUPPORT_COMPR_H__
+#define __LIBSQUEEZE_ARCHIVE_SUPPORT_COMPR_H__
+
+G_BEGIN_DECLS
+
+
+#define LSQ_TYPE_ARCHIVE_SUPPORT_COMPR lsq_archive_support_compr_get_type()
+
+#define LSQ_ARCHIVE_SUPPORT_COMPR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_ARCHIVE_SUPPORT_COMPR, \
+ LSQArchiveSupportCompr))
+
+#define LSQ_IS_ARCHIVE_SUPPORT_COMPR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_ARCHIVE_SUPPORT_COMPR))
+
+#define LSQ_ARCHIVE_SUPPORT_COMPR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ LSQ_TYPE_ARCHIVE_SUPPORT_COMPR, \
+ LSQArchiveSupportComprClass))
+
+#define LSQ_IS_ARCHIVE_SUPPORT_COMPR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ LSQ_TYPE_ARCHIVE_SUPPORT_COMPR))
+
+typedef struct _LSQArchiveSupportCompr LSQArchiveSupportCompr;
+
+struct _LSQArchiveSupportCompr
+{
+ LSQArchiveSupport parent;
+};
+
+typedef struct _LSQArchiveSupportComprClass LSQArchiveSupportComprClass;
+
+struct _LSQArchiveSupportComprClass
+{
+ LSQArchiveSupportClass parent;
+};
+
+GType lsq_archive_support_compr_get_type(void) G_GNUC_INTERNAL;
+LSQArchiveSupport * lsq_archive_support_compr_new() G_GNUC_INTERNAL;
+
+G_END_DECLS
+
+#endif /* __LIBSQUEEZE_ARCHIVE_SUPPORT_COMPR_H__ */
Modified: squeeze/trunk/libsqueeze/archive.h
===================================================================
--- squeeze/trunk/libsqueeze/archive.h 2007-01-23 18:23:09 UTC (rev 24713)
+++ squeeze/trunk/libsqueeze/archive.h 2007-01-23 23:25:57 UTC (rev 24714)
@@ -135,7 +135,6 @@
gboolean lsq_archive_iter_get_prop_value(const LSQArchive *archive, const LSQArchiveIter *iter, guint n, GValue *value);
void lsq_archive_iter_get_icon_name(const LSQArchive *archive, const LSQArchiveIter *iter, GValue *value, GtkIconTheme *icon_theme);
-
LSQArchiveIter *lsq_archive_add_file(LSQArchive *archive, const gchar *path) G_GNUC_INTERNAL;
gboolean lsq_archive_del_file(LSQArchive *archive, const gchar *path);
LSQArchiveIter *lsq_archive_get_iter(const LSQArchive *archive, const gchar *path);
Modified: squeeze/trunk/libsqueeze/libsqueeze.c
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze.c 2007-01-23 18:23:09 UTC (rev 24713)
+++ squeeze/trunk/libsqueeze/libsqueeze.c 2007-01-23 23:25:57 UTC (rev 24714)
@@ -26,6 +26,7 @@
#include "libsqueeze.h"
#include "libsqueeze/archive-support-zip.h"
#include "libsqueeze/archive-support-rar.h"
+#include "libsqueeze/archive-support-compr.h"
#include "libsqueeze/archive-support-gnu-tar.h"
#include "internals.h"
@@ -41,6 +42,7 @@
lsq_register_support(lsq_archive_support_zip_new());
lsq_register_support(lsq_archive_support_rar_new());
+ lsq_register_support(lsq_archive_support_compr_new());
/*
TODO: Implement right commands in unrar
lsq_register_support(lsq_archive_support_unrar_new());
More information about the Xfce4-commits
mailing list