[Xfce4-commits] r25177 - squeeze/trunk/libsqueeze
Stephan Arts
stephan at xfce.org
Fri Mar 16 12:31:11 CET 2007
Author: stephan
Date: 2007-03-16 11:31:11 +0000 (Fri, 16 Mar 2007)
New Revision: 25177
Added:
squeeze/trunk/libsqueeze/command-builder-compr.c
squeeze/trunk/libsqueeze/command-builder-compr.h
squeeze/trunk/libsqueeze/command-builder-gnu-tar.c
squeeze/trunk/libsqueeze/command-builder-gnu-tar.h
squeeze/trunk/libsqueeze/command-builder-rar.c
squeeze/trunk/libsqueeze/command-builder-rar.h
squeeze/trunk/libsqueeze/command-builder-zip.c
squeeze/trunk/libsqueeze/command-builder-zip.h
squeeze/trunk/libsqueeze/command-builder.c
squeeze/trunk/libsqueeze/command-builder.h
squeeze/trunk/libsqueeze/dbus-command.c
squeeze/trunk/libsqueeze/dbus-command.h
squeeze/trunk/libsqueeze/macro-command.c
squeeze/trunk/libsqueeze/macro-command.h
squeeze/trunk/libsqueeze/spawn-command.c
squeeze/trunk/libsqueeze/spawn-command.h
Removed:
squeeze/trunk/libsqueeze/archive-support.c
squeeze/trunk/libsqueeze/archive-support.h
Modified:
squeeze/trunk/libsqueeze/Makefile.am
squeeze/trunk/libsqueeze/archive-command.c
squeeze/trunk/libsqueeze/archive-command.h
squeeze/trunk/libsqueeze/archive-support-compr.c
squeeze/trunk/libsqueeze/archive-support-gnu-tar.c
squeeze/trunk/libsqueeze/archive-support-zip.c
squeeze/trunk/libsqueeze/archive.c
squeeze/trunk/libsqueeze/archive.h
squeeze/trunk/libsqueeze/internals.c
squeeze/trunk/libsqueeze/libsqueeze-archive.h
squeeze/trunk/libsqueeze/libsqueeze-command.h
squeeze/trunk/libsqueeze/libsqueeze.c
Log:
Made ArchiveCommand an Abstract Class
Written SpawnCommand (fullfills the task of the original ArchiveCommand)
Added MacroCommand (so multiple commands can be combined)
Added DBusCommand (for 'open' support and possible other dbus-commands)
Written Abstract CommandBuilder
Added CommandBuilder for GnuTar (add / remove / extract / refresh should work, but refresh-properties have not yet been ported)
Added CommandBuilder for Zip idem...
Added CommandBuilder for Rar not much done here, but the files are in place
Added CommandBuilder for Compressed files (same as for rar)
Archive needs to be modified to work with commandbuilders instead of support-objects.
Modified: squeeze/trunk/libsqueeze/Makefile.am
===================================================================
--- squeeze/trunk/libsqueeze/Makefile.am 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/Makefile.am 2007-03-16 11:31:11 UTC (rev 25177)
@@ -11,12 +11,19 @@
archive.c archive.h \
archive-iter.c archive-iter.h \
archive-command.c archive-command.h \
+ spawn-command.c spawn-command.h \
+ macro-command.c macro-command.h \
+ dbus-command.c dbus-command.h \
archive-tempfs.c archive-tempfs.h \
- archive-support.c archive-support.h \
- archive-support-compr.c archive-support-compr.h \
- archive-support-zip.c archive-support-zip.h \
- archive-support-rar.c archive-support-rar.h \
- archive-support-gnu-tar.c archive-support-gnu-tar.h
+ command-builder.c command-builder.h \
+ command-builder-zip.c command-builder-zip.h \
+ command-builder-rar.c command-builder-rar.h \
+ command-builder-compr.c command-builder-compr.h \
+ command-builder-gnu-tar.c command-builder-gnu-tar.h
+#archive-support-compr.c archive-support-compr.h
+#archive-support-zip.c archive-support-zip.h
+#archive-support-rar.c archive-support-rar.h
+#archive-support-gnu-tar.c archive-support-gnu-tar.h
libsqueeze_1_la_CFLAGS = \
$(GLIB_CFLAGS) \
Modified: squeeze/trunk/libsqueeze/archive-command.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive-command.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -25,11 +25,10 @@
#include <thunar-vfs/thunar-vfs.h>
#include "libsqueeze-archive.h"
-#include "libsqueeze-support.h"
#include "libsqueeze-command.h"
#include "libsqueeze-module.h"
#include "archive-iter.h"
-#include "archive-command.h"
+#include "command.h"
#include "archive.h"
static void
@@ -41,14 +40,6 @@
static void
lsq_archive_command_finalize(GObject *object);
-void
-lsq_archive_command_child_watch_func(GPid pid, gint status, gpointer data);
-
-gboolean
-lsq_archive_command_parse_stdout(GIOChannel *ioc, GIOCondition cond, gpointer data);
-
-//static gint lsq_archive_command_signals[0];
-
static GObjectClass *parent_class;
GType
@@ -92,7 +83,6 @@
static void
lsq_archive_command_init(LSQArchiveCommand *archive_command)
{
- archive_command->parse_stdout = NULL;
archive_command->domain = g_quark_from_string("Command");
}
@@ -105,17 +95,8 @@
static void
lsq_archive_command_dispose(GObject *object)
{
- LSQArchiveCommand *archive_command = LSQ_ARCHIVE_COMMAND(object);
- if(archive_command->archive)
- {
- if(archive_command->refresh)
- lsq_archive_refreshed(archive_command->archive);
- lsq_archive_command_terminated(archive_command->archive, archive_command->error);
- lsq_archive_dequeue_command(archive_command->archive, archive_command);
-
- archive_command->archive = NULL;
- }
+ parent_class->dispose(object);
}
/**
@@ -134,250 +115,52 @@
/**
- * lsq_archive_command_new:
- * @comment: a description, describing what the command does
- * @archive: the archive the command modifies
- * @command: a formatted string defining the command to be executed.
- * @safe: is it safe to terminate this child premature?
- *
- *
- * %%1$s is the application to be executed.
- *
- * %%2$s are the files to be appended
- *
- * %%3$s are any additional options
- *
- * Returns: a new LSQArchiveCommand object
- */
-LSQArchiveCommand *
-lsq_archive_command_new(const gchar *comment, const gchar *command, gboolean safe, gboolean refresh)
-{
- LSQArchiveCommand *archive_command;
-
- archive_command = g_object_new(lsq_archive_command_get_type(), NULL);
- archive_command->command = g_strdup(command);
- archive_command->safe = safe;
- archive_command->refresh = refresh;
-
- return archive_command;
-}
-
-/**
* lsq_archive_command_run:
- * @archive_command: the archive_command to be run
+ * @command: the archive_command to be run
*
* Returns: true on success
*/
gboolean
-lsq_archive_command_run(LSQArchiveCommand *archive_command)
+lsq_archive_command_execute(LSQArchiveCommand *command)
{
- gchar **argvp;
- gint argcp;
- gint fd_in, fd_out, fd_err;
- gchar *escaped_archive_path;
-
- g_return_val_if_fail(archive_command->child_pid == 0, FALSE);
-
- const gchar *files = g_object_get_data(G_OBJECT(archive_command), "files");
- const gchar *options = g_object_get_data(G_OBJECT(archive_command), "options");
- const gchar *archive_path = g_object_get_data(G_OBJECT(archive_command), "archive");
-
- if(files == NULL)
- files = "";
- if(options == NULL)
- options = "";
-
- if(archive_path)
- {
- escaped_archive_path = g_shell_quote(archive_path);
- }
- else
- escaped_archive_path = g_shell_quote(archive_command->archive->path);
-
- gchar *command = g_strdup_printf(archive_command->command, escaped_archive_path, files, options);
-
#ifdef DEBUG
- g_debug("%s\n", command);
-#endif
- g_shell_parse_argv(command, &argcp, &argvp, NULL);
- if ( ! g_spawn_async_with_pipes (
- NULL,
- argvp,
- NULL,
- G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
- NULL,
- NULL,
- &(archive_command->child_pid),
- &fd_in,
- &fd_out,
- &fd_err,
- NULL) )
- {
- g_object_unref(archive_command);
- return FALSE;
- }
+ g_return_val_if_fail(command->archive, FALSE);
+ g_return_val_if_fail(LSQ_IS_ARCHIVE(command->archive), FALSE);
+#endif /* DEBUG */
- g_child_watch_add(archive_command->child_pid, lsq_archive_command_child_watch_func, archive_command);
-
- if(archive_command->parse_stdout != NULL)
- {
- g_object_ref(archive_command);
- archive_command->ioc_out = g_io_channel_unix_new(fd_out);
- g_io_channel_set_encoding (archive_command->ioc_out, NULL, NULL);
- g_io_channel_set_flags (archive_command->ioc_out , G_IO_FLAG_NONBLOCK , NULL );
- g_io_add_watch (archive_command->ioc_out, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL, lsq_archive_command_parse_stdout, archive_command);
- }
- lsq_archive_command_started(archive_command->archive, archive_command->comment);
- g_free(escaped_archive_path);
- g_free(command);
- return TRUE;
+ return command->execute(command);
}
/**
* lsq_archive_command_stop
- * @archive_command:
+ * @command:
*
- *
* Returns: TRUE on success, FALSE if the command is not running
*/
gboolean
-lsq_archive_command_stop(LSQArchiveCommand *archive_command)
+lsq_archive_command_stop(LSQArchiveCommand *command)
{
- if(archive_command->child_pid != 0)
- kill ( archive_command->child_pid , SIGHUP);
- else
- return FALSE; /* archive_command isn't running */
- return TRUE;
+ return command->stop(command);
}
/**
- * lsq_archive_command_child_watch_func:
- * @pid:
- * @status:
- * @data:
- */
-void
-lsq_archive_command_child_watch_func(GPid pid, gint status, gpointer data)
-{
- LSQArchiveCommand *command = LSQ_ARCHIVE_COMMAND(data);
- if(WIFEXITED(status))
- {
- if(WEXITSTATUS(status))
- {
- if(!command->error)
- {
- command->error = g_error_new(command->domain, status, _("Command exited with status %d."), status);
- }
- }
- }
- if(WIFSIGNALED(status))
- {
- switch(WTERMSIG(status))
- {
- case SIGHUP:
- if(!command->error)
- command->error = g_error_new_literal(command->domain, status, _("Command interrupted by user"));
- break;
- case SIGSEGV:
- if(!command->error)
- command->error = g_error_new_literal(command->domain, status, _("Command received SIGSEGV"));
- break;
- case SIGKILL:
- case SIGINT:
- if(!command->error)
- command->error = g_error_new_literal(command->domain, status, _("Command Terminated"));
- break;
- }
- }
- g_spawn_close_pid(pid);
- g_object_unref(G_OBJECT(data));
-}
-
-/**
- * lsq_archive_command_parse_stdout:
- * @ioc:
- * @cond:
- * @data:
+ * lsq_archive_command_get_archive
+ * @command:
*
- * Returns:
+ * Returns: the associated archive
*/
-gboolean
-lsq_archive_command_parse_stdout(GIOChannel *ioc, GIOCondition cond, gpointer data)
-{
- gint i = 0;
- LSQArchiveCommand *archive_command = LSQ_ARCHIVE_COMMAND(data);
-
- if(cond & (G_IO_PRI | G_IO_IN))
- {
- for(; i < 500; i++)
- {
- /* If parse_stdout returns FALSE, something seriously went wrong and we should cancel right away */
- if(archive_command->parse_stdout(archive_command, archive_command->user_data) == FALSE)
- {
- cond |= G_IO_ERR;
- }
- }
- }
- if(cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
- {
- g_io_channel_shutdown ( ioc,TRUE,NULL );
- g_io_channel_unref (ioc);
- g_object_unref(archive_command);
- return FALSE;
- }
- return TRUE;
-}
-
-gboolean
-lsq_archive_command_set_parse_func(LSQArchiveCommand *archive_command, guint fd, LSQParseFunc func, gpointer user_data)
-{
- switch(fd)
- {
- case 1:
- archive_command->parse_stdout = func;
- archive_command->user_data = user_data;
- default:
- break;
- }
- return TRUE;
-}
-
-GIOStatus
-lsq_archive_command_read_line(LSQArchiveCommand *archive_command, guint fd, gchar **line, gsize *length, GError **error)
-{
- GIOStatus status = G_IO_STATUS_EOF;
- switch(fd)
- {
- case 1:
- status = g_io_channel_read_line(archive_command->ioc_out, line, length, NULL, error);
- break;
- default:
- break;
- }
- return status;
-}
-
-GIOStatus
-lsq_archive_command_read_bytes(LSQArchiveCommand *archive_command, guint fd, gchar *buf, gsize max_length, gsize *length, GError **error)
-{
- GIOStatus status = G_IO_STATUS_EOF;
- switch(fd)
- {
- case 1:
- status = g_io_channel_read_chars(archive_command->ioc_out, buf, max_length, length, error);
- break;
- default:
- break;
- }
- return status;
-}
-
LSQArchive *
lsq_archive_command_get_archive(LSQArchiveCommand *command)
{
return command->archive;
}
+/**
+ * lsq_archive_command_get_comment
+ * @command:
+ *
+ * Returns: the command comment describing what it is actually doing
+ */
const gchar *
lsq_archive_command_get_comment(LSQArchiveCommand *archive_command)
{
Modified: squeeze/trunk/libsqueeze/archive-command.h
===================================================================
--- squeeze/trunk/libsqueeze/archive-command.h 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive-command.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -22,17 +22,13 @@
GObject parent;
GQuark domain;
gchar *comment;
- gchar *command;
LSQArchive *archive;
- GPid child_pid;
- GIOChannel *ioc_in;
- GIOChannel *ioc_out;
- GIOChannel *ioc_err;
- gboolean safe;
- gboolean refresh;
GError *error;
- LSQParseFunc parse_stdout;
+ gboolean running;
+ gboolean safe;
gpointer user_data;
+ gboolean (*execute)(LSQArchiveCommand *);
+ gboolean (*stop)(LSQArchiveCommand *);
};
struct _LSQArchiveCommandClass
@@ -40,10 +36,10 @@
GObjectClass parent;
};
-gboolean lsq_archive_command_run(LSQArchiveCommand *archive_command);
-gboolean lsq_archive_command_stop(LSQArchiveCommand *archive_command);
+gboolean
+lsq_archive_command_stop(LSQArchiveCommand *command);
+const gchar *
+lsq_archive_command_get_comment(LSQArchiveCommand *archive_command);
-const gchar *lsq_archive_command_get_comment(LSQArchiveCommand *archive_command);
-
G_END_DECLS
#endif /* __LIBSQUEEZE_ARCHIVE_COMMAND_H__ */
Modified: squeeze/trunk/libsqueeze/archive-support-compr.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-compr.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive-support-compr.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -158,31 +158,31 @@
}
else
{
- gchar *archive_path = g_shell_quote(lsq_archive_get_filename(archive));
+ gchar *archive_path = g_shell_quote(lsq_archive_get_path(archive));
gchar *file_path;
if(filenames)
file_path = g_strconcat(extract_path, "/", filenames->data, NULL);
else
{
- gchar *filename = g_path_get_basename(lsq_archive_get_filename(archive));
+ gchar *filename = g_path_get_basename(lsq_archive_get_path(archive));
gint len = strlen(filename);
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".gz"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".gz"))
{
filename[len-3] = '\0';
}
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".bz"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".bz"))
{
filename[len-3] = '\0';
}
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".bz2"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".bz2"))
{
filename[len-4] = '\0';
}
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".lzo"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".lzo"))
{
filename[len-4] = '\0';
}
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".Z"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".Z"))
{
filename[len-2] = '\0';
}
@@ -228,17 +228,17 @@
}
else
{
- gchar *filename = g_path_get_basename(lsq_archive_get_filename(archive));
+ gchar *filename = lsq_archive_get_filename(archive);
gint len = strlen(filename);
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".gz"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".gz"))
{
filename[len-3] = '\0';
}
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".bz"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".bz"))
{
filename[len-3] = '\0';
}
- if(g_str_has_suffix(lsq_archive_get_filename(archive), ".bz2"))
+ if(g_str_has_suffix(lsq_archive_get_path(archive), ".bz2"))
{
filename[len-4] = '\0';
}
Modified: squeeze/trunk/libsqueeze/archive-support-gnu-tar.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-gnu-tar.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive-support-gnu-tar.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -687,7 +687,7 @@
GError *error = NULL;
FILE *out_file;
- const gchar *out_filename = lsq_archive_get_filename(archive);
+ const gchar *out_filename = lsq_archive_get_path(archive);
gboolean remove = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(archive_command), "compressing"));
if(remove == FALSE)
{
Modified: squeeze/trunk/libsqueeze/archive-support-zip.c
===================================================================
--- squeeze/trunk/libsqueeze/archive-support-zip.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive-support-zip.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -20,6 +20,7 @@
#include <glib-object.h>
#include <thunar-vfs/thunar-vfs.h>
+#include <libsqueeze/libsqueeze-command.h>
#include <libsqueeze/libsqueeze-module.h>
#include "archive-support-zip.h"
Deleted: squeeze/trunk/libsqueeze/archive-support.c
Deleted: squeeze/trunk/libsqueeze/archive-support.h
Modified: squeeze/trunk/libsqueeze/archive.c
===================================================================
--- squeeze/trunk/libsqueeze/archive.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -29,7 +29,7 @@
#include "archive-iter.h"
#include "archive-command.h"
#include "archive.h"
-#include "archive-support.h"
+#include "command-builder.h"
#include "slist.h"
#include "archive-tempfs.h"
@@ -437,39 +437,14 @@
return archive->entry_n_property + LSQ_ARCHIVE_PROP_USER;
}
-void
-lsq_archive_enqueue_command(LSQArchive *archive, LSQArchiveCommand *command)
+gchar *
+lsq_archive_get_filename(const LSQArchive *archive)
{
- g_object_ref(command);
- archive->command_queue = g_slist_append(archive->command_queue, command);
- command->archive = archive;
- if(archive->command_queue->data == command)
- lsq_archive_command_run(command);
+ return g_path_get_basename(archive->path);
}
-void
-lsq_archive_dequeue_command(LSQArchive *archive, LSQArchiveCommand *command)
-{
- g_return_if_fail(archive->command_queue->data == command);
- archive->command_queue = g_slist_remove(archive->command_queue, command);
- LSQArchiveCommand *next_command = lsq_archive_get_front_command(archive);
- if(next_command)
- {
- lsq_archive_command_run(next_command);
- }
-}
-
-LSQArchiveCommand *
-lsq_archive_get_front_command(const LSQArchive *archive)
-{
- if(archive->command_queue)
- return archive->command_queue->data;
- else
- return NULL;
-}
-
const gchar *
-lsq_archive_get_filename(const LSQArchive *archive)
+lsq_archive_get_path(const LSQArchive *archive)
{
return archive->path;
}
@@ -499,9 +474,8 @@
gboolean
lsq_archive_can_stop(const LSQArchive *archive)
{
- LSQArchiveCommand *command = lsq_archive_get_front_command(archive);
- if(command)
- return command->safe;
+ if(archive->command)
+ return archive->command->safe;
else
return TRUE;
}
@@ -509,9 +483,8 @@
gboolean
lsq_archive_stop(const LSQArchive *archive)
{
- LSQArchiveCommand *command = lsq_archive_get_front_command(archive);
- if(command)
- return lsq_archive_command_stop(command);
+ if(archive->command)
+ return lsq_archive_command_stop(archive->command);
else
return FALSE;
}
@@ -519,9 +492,8 @@
const gchar *
lsq_archive_get_status(const LSQArchive *archive)
{
- LSQArchiveCommand *command = lsq_archive_get_front_command(archive);
- if(command)
- return lsq_archive_command_get_comment(command);
+ if(archive->command)
+ return lsq_archive_command_get_comment(archive->command);
else
return _("idle");
}
@@ -531,24 +503,3 @@
{
g_signal_emit(G_OBJECT(archive), lsq_archive_signals[LSQ_ARCHIVE_SIGNAL_REFRESHED], 0, NULL);
}
-
-void
-lsq_archive_command_terminated(const LSQArchive *archive, const GError *error)
-{
- g_signal_emit(G_OBJECT(archive), lsq_archive_signals[LSQ_ARCHIVE_SIGNAL_COMMAND_TERMINATED], 0, error, NULL);
-}
-
-void
-lsq_archive_command_started(const LSQArchive *archive, const gchar *comment)
-{
- g_signal_emit(G_OBJECT(archive), lsq_archive_signals[LSQ_ARCHIVE_SIGNAL_COMMAND_STARTED], 0, comment, NULL);
-}
-
-gboolean
-lsq_archive_has_queue(LSQArchive *archive)
-{
- if(lsq_archive_get_front_command(archive))
- return TRUE;
- else
- return FALSE;
-}
Modified: squeeze/trunk/libsqueeze/archive.h
===================================================================
--- squeeze/trunk/libsqueeze/archive.h 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/archive.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -30,7 +30,7 @@
GType *entry_property_types;
gchar **entry_property_names;
LSQArchiveEntry *root_entry;
- GSList *command_queue;
+ LSQArchiveCommand *command;
struct {
guint64 archive_size;
guint64 content_size;
@@ -44,12 +44,6 @@
LSQArchive *lsq_archive_new(gchar *, const gchar *) G_GNUC_INTERNAL;
-void lsq_archive_dequeue_command(LSQArchive *archive, LSQArchiveCommand *command) G_GNUC_INTERNAL;
-
-LSQArchiveCommand *lsq_archive_get_front_command(const LSQArchive *archive) G_GNUC_INTERNAL;
-void lsq_archive_command_terminated(const LSQArchive *archive, const GError *error) G_GNUC_INTERNAL;
-void lsq_archive_command_started(const LSQArchive *archive, const gchar *comment) G_GNUC_INTERNAL;
-
G_END_DECLS
#endif /* __ARCHIVE_H__ */
Added: squeeze/trunk/libsqueeze/command-builder-compr.c
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-compr.c (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-compr.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,168 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-command.h"
+#include "libsqueeze-module.h"
+#include "archive-iter.h"
+#include "archive-tempfs.h"
+#include "archive.h"
+#include "archive-command.h"
+#include "macro-command.h"
+#include "spawn-command.h"
+#include "dbus-command.h"
+#include "command-builder.h"
+#include "command-builder-compr.h"
+
+static void
+lsq_command_builder_compr_class_init(LSQCommandBuilderComprClass *);
+static void
+lsq_command_builder_compr_init(LSQCommandBuilderCompr *archive);
+static void
+lsq_command_builder_compr_dispose(GObject *object);
+static void
+lsq_command_builder_compr_finalize(GObject *object);
+
+static LSQArchiveCommand *
+lsq_command_builder_compr_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_compr_build_extract(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_compr_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive);
+static LSQArchiveCommand *
+lsq_command_builder_compr_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+
+static GObjectClass *parent_class;
+
+GType
+lsq_command_builder_compr_get_type ()
+{
+ static GType lsq_command_builder_compr_type = 0;
+
+ if (!lsq_command_builder_compr_type)
+ {
+ static const GTypeInfo lsq_command_builder_compr_info =
+ {
+ sizeof (LSQCommandBuilderComprClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_command_builder_compr_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQCommandBuilderCompr),
+ 0,
+ (GInstanceInitFunc) lsq_command_builder_compr_init,
+ NULL
+ };
+
+ lsq_command_builder_compr_type = g_type_register_static (G_TYPE_OBJECT, "LSQCommandBuilderCompr", &lsq_command_builder_compr_info, 0);
+ }
+ return lsq_command_builder_compr_type;
+}
+
+static void
+lsq_command_builder_compr_class_init(LSQCommandBuilderComprClass *command_builder_compr_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(command_builder_compr_class);
+
+ object_class->dispose = lsq_command_builder_compr_dispose;
+ object_class->finalize = lsq_command_builder_compr_finalize;
+
+ parent_class = g_type_class_peek(G_TYPE_OBJECT);
+
+}
+
+static void
+lsq_command_builder_compr_init(LSQCommandBuilderCompr *command_builder_compr)
+{
+ LSQCommandBuilder *command_builder = LSQ_COMMAND_BUILDER(command_builder_compr);
+
+ command_builder->build_add = lsq_command_builder_compr_build_add;
+ command_builder->build_extract = lsq_command_builder_compr_build_extract;
+ command_builder->build_remove = lsq_command_builder_compr_build_remove;
+ command_builder->build_refresh = lsq_command_builder_compr_build_refresh;
+}
+
+/**
+ * lsq_command_builder_compr_dispose:
+ *
+ * @object: LSQCommandBuilderCompr object
+ *
+ */
+static void
+lsq_command_builder_compr_dispose(GObject *object)
+{
+
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_command_builder_compr_finalize:
+ *
+ * @object: LSQCommandBuilderCompr object
+ *
+ */
+static void
+lsq_command_builder_compr_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+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;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_compr_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ return NULL;
+}
+
+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);
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Extract", archive, "uncompr -o %1$s %2$s %3$s", files, options, NULL);
+
+ g_free(options);
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_compr_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+ return NULL;
+}
+
Added: squeeze/trunk/libsqueeze/command-builder-compr.h
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-compr.h (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-compr.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,56 @@
+/*
+ * 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_COMMAND_BUILDER_COMPR_H__
+#define __LIBSQUEEZE_COMMAND_BUILDER_COMPR_H__
+
+#define LSQ_TYPE_COMMAND_BUILDER_COMPR lsq_command_builder_compr_get_type()
+
+#define LSQ_COMMAND_BUILDER_COMPR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_COMPR, \
+ LSQCommandBuilderCompr))
+
+#define LSQ_IS_COMMAND_BUILDER_COMPR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_COMPR))
+
+#define LSQ_COMMAND_BUILDER_COMPR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_COMPR, \
+ LSQCommandBuilderComprClass))
+
+#define LSQ_IS_COMMAND_BUILDER_COMPR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_COMPR))
+
+typedef struct _LSQCommandBuilderCompr LSQCommandBuilderCompr;
+
+struct _LSQCommandBuilderCompr
+{
+ LSQCommandBuilder parent;
+};
+
+typedef struct _LSQCommandBuilderComprClass LSQCommandBuilderComprClass;
+
+struct _LSQCommandBuilderComprClass
+{
+ GObjectClass parent;
+};
+
+GType lsq_command_builder_compr_get_type(void);
+
+#endif /* __LIBSQUEEZE_COMMAND_BUILDER_COMPR_H__ */
Added: squeeze/trunk/libsqueeze/command-builder-gnu-tar.c
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-gnu-tar.c (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-gnu-tar.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,512 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-command.h"
+#include "libsqueeze-module.h"
+#include "archive-iter.h"
+#include "archive-tempfs.h"
+#include "archive.h"
+#include "archive-command.h"
+#include "macro-command.h"
+#include "spawn-command.h"
+#include "dbus-command.h"
+#include "command-builder.h"
+#include "command-builder-gnu-tar.h"
+
+#define LSQ_ARCHIVE_TEMP_FILE "gnu_tar_temp_file"
+
+static void
+lsq_command_builder_gnu_tar_class_init(LSQCommandBuilderGnuTarClass *);
+static void
+lsq_command_builder_gnu_tar_init(LSQCommandBuilderGnuTar *archive);
+static void
+lsq_command_builder_gnu_tar_dispose(GObject *object);
+static void
+lsq_command_builder_gnu_tar_finalize(GObject *object);
+
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_extract(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive);
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+
+static gboolean
+lsq_command_builder_gnu_tar_refresh_parse_output(LSQArchiveCommand *archive_command, gpointer user_data);
+static gboolean
+lsq_command_builder_gnu_tar_compress_parse_output(LSQArchiveCommand *archive_command, gpointer user_data);
+static gboolean
+lsq_command_builder_gnu_tar_decompress_parse_output(LSQArchiveCommand *archive_command, gpointer user_data);
+
+static GObjectClass *parent_class;
+
+GType
+lsq_command_builder_gnu_tar_get_type ()
+{
+ static GType lsq_command_builder_gnu_tar_type = 0;
+
+ if (!lsq_command_builder_gnu_tar_type)
+ {
+ static const GTypeInfo lsq_command_builder_gnu_tar_info =
+ {
+ sizeof (LSQCommandBuilderGnuTarClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_command_builder_gnu_tar_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQCommandBuilderGnuTar),
+ 0,
+ (GInstanceInitFunc) lsq_command_builder_gnu_tar_init,
+ NULL
+ };
+
+ lsq_command_builder_gnu_tar_type = g_type_register_static (G_TYPE_OBJECT, "LSQCommandBuilderGnuTar", &lsq_command_builder_gnu_tar_info, 0);
+ }
+ return lsq_command_builder_gnu_tar_type;
+}
+
+static void
+lsq_command_builder_gnu_tar_class_init(LSQCommandBuilderGnuTarClass *command_builder_gnu_tar_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(command_builder_gnu_tar_class);
+
+ object_class->dispose = lsq_command_builder_gnu_tar_dispose;
+ object_class->finalize = lsq_command_builder_gnu_tar_finalize;
+
+ parent_class = g_type_class_peek(G_TYPE_OBJECT);
+
+}
+
+static void
+lsq_command_builder_gnu_tar_init(LSQCommandBuilderGnuTar *command_builder_gnu_tar)
+{
+ LSQCommandBuilder *command_builder = LSQ_COMMAND_BUILDER(command_builder_gnu_tar);
+
+ command_builder->build_add = lsq_command_builder_gnu_tar_build_add;
+ command_builder->build_extract = lsq_command_builder_gnu_tar_build_extract;
+ command_builder->build_remove = lsq_command_builder_gnu_tar_build_remove;
+ command_builder->build_refresh = lsq_command_builder_gnu_tar_build_refresh;
+}
+
+/**
+ * lsq_command_builder_gnu_tar_dispose:
+ *
+ * @object: LSQCommandBuilderGnuTar object
+ *
+ */
+static void
+lsq_command_builder_gnu_tar_dispose(GObject *object)
+{
+
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_command_builder_gnu_tar_finalize:
+ *
+ * @object: LSQCommandBuilderGnuTar object
+ *
+ */
+static void
+lsq_command_builder_gnu_tar_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+static const gchar *
+lsq_command_builder_gnu_tar_get_compress_skeleton(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+ const gchar *decompress_skeleton = NULL;
+
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-tarz"))
+ decompress_skeleton = "uncompress -c %1$s";
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-compressed-tar"))
+ decompress_skeleton = "gunzip -c %1$s";
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-bzip-compressed-tar"))
+ decompress_skeleton = "bunzip2 -c %1$s";
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-tzo"))
+ decompress_skeleton = "lzop -dc %1$s";
+
+ return decompress_skeleton;
+}
+
+static const gchar *
+lsq_command_builder_gnu_tar_get_decompress_skeleton(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+ const gchar *compress_skeleton = NULL;
+
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-tarz"))
+ compress_skeleton = "compress -c %1$s";
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-compressed-tar"))
+ compress_skeleton = "gzip -c %1$s";
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-bzip-compressed-tar"))
+ compress_skeleton = "bzip2 -c %1$s";
+ if(!g_strcasecmp(lsq_archive_get_mimetype(archive), "application/x-tzo"))
+ compress_skeleton = "lzop -c %1$s";
+
+ return compress_skeleton;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ gchar *options = NULL;
+ gchar *tmp_file = NULL;
+ gchar *files = lsq_concat_filenames(filenames);
+ const gchar *add_skeleton = NULL;
+ const gchar *compress_skeleton = NULL;
+ const gchar *decompress_skeleton = NULL;
+ LSQArchiveCommand *add_macro = NULL;
+
+ compress_skeleton = lsq_command_builder_gnu_tar_get_compress_skeleton(builder, archive);
+ decompress_skeleton = lsq_command_builder_gnu_tar_get_decompress_skeleton(builder, archive);
+
+ if(decompress_skeleton)
+ tmp_file = lsq_archive_request_temp_file(archive, ".tar");
+
+ if(!lsq_archive_exists(archive))
+ {
+ add_skeleton = "tar %3$s -c -f %1$s %2$s";
+ }
+ else
+ {
+ add_skeleton = "tar %3$s -r -f %1$s %2$s";
+ }
+ LSQArchiveCommand *spawn = lsq_spawn_command_new(_("Adding files"),
+ archive,
+ add_skeleton,
+ files,
+ options,
+ tmp_file);
+
+ if(decompress_skeleton)
+ {
+ LSQArchiveCommand *decompress = lsq_spawn_command_new(_("Decompressing"),
+ archive,
+ decompress_skeleton,
+ NULL,
+ NULL,
+ tmp_file);
+ LSQArchiveCommand *compress = lsq_spawn_command_new(_("Compressing"),
+ archive,
+ compress_skeleton,
+ NULL,
+ NULL,
+ tmp_file);
+ add_macro = lsq_macro_command_new(NULL, archive);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(add_macro), decompress);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(add_macro), spawn);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(add_macro), compress);
+ }
+
+ if(!add_macro)
+ add_macro = spawn;
+
+ g_free(files);
+ return NULL;
+}
+
+
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ gchar *options = NULL;
+ gchar *tmp_file = NULL;
+ gchar *files = lsq_concat_filenames(filenames);
+ const gchar *compress_skeleton = NULL;
+ const gchar *decompress_skeleton = NULL;
+ LSQArchiveCommand *remove_macro = NULL;
+
+ compress_skeleton = lsq_command_builder_gnu_tar_get_compress_skeleton(builder, archive);
+ decompress_skeleton = lsq_command_builder_gnu_tar_get_decompress_skeleton(builder, archive);
+
+ if(decompress_skeleton)
+ tmp_file = lsq_archive_request_temp_file(archive, ".tar");
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new(_("Removing files"),
+ archive,
+ "tar %3$s -f %1$s --delete %2$s",
+ files,
+ options,
+ tmp_file);
+
+ if(decompress_skeleton)
+ {
+ LSQArchiveCommand *decompress = lsq_spawn_command_new(_("Decompressing"),
+ archive,
+ decompress_skeleton,
+ NULL,
+ NULL,
+ NULL);
+
+ g_object_set_data(G_OBJECT(decompress), LSQ_ARCHIVE_TEMP_FILE, tmp_file);
+
+ LSQArchiveCommand *compress = lsq_spawn_command_new(_("Compressing"),
+ archive,
+ compress_skeleton,
+ NULL,
+ NULL,
+ tmp_file);
+ remove_macro = lsq_macro_command_new(NULL, archive);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(remove_macro), decompress);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(remove_macro), spawn);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(remove_macro), compress);
+
+ if(!lsq_spawn_command_set_parse_func(LSQ_SPAWN_COMMAND(compress), 1, lsq_command_builder_gnu_tar_compress_parse_output, NULL))
+ {
+ g_critical("Could not set compress parse function");
+ }
+
+ if(!lsq_spawn_command_set_parse_func(LSQ_SPAWN_COMMAND(decompress), 1, lsq_command_builder_gnu_tar_decompress_parse_output, NULL))
+ {
+ g_critical("Could not set decompress parse function");
+ }
+ }
+
+ if(!remove_macro)
+ remove_macro = spawn;
+
+ g_free(files);
+ return remove_macro;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_extract(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *filenames)
+{
+ gchar *files = lsq_concat_filenames(filenames);
+ gchar *options = g_strconcat(" -C ", dest_path, NULL);
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Extract", archive, "tar %3$s -x -f %1$s %2$s", files, options, NULL);
+
+ g_free(options);
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_gnu_tar_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Refresh", archive, "tar -tvvf %1$s", NULL, NULL, NULL);
+
+ if(!lsq_spawn_command_set_parse_func(LSQ_SPAWN_COMMAND(spawn), 1, lsq_command_builder_gnu_tar_refresh_parse_output, NULL))
+ {
+ g_critical("Could not set refresh parse function");
+ }
+
+ return spawn;
+}
+
+
+static gboolean
+lsq_command_builder_gnu_tar_refresh_parse_output(LSQArchiveCommand *archive_command, gpointer user_data)
+{
+ gchar *line = NULL;
+ gsize linesize = 0;
+ GIOStatus status = G_IO_STATUS_NORMAL;
+ LSQArchive *archive = lsq_archive_command_get_archive(archive_command);
+ guint64 size;
+ gpointer props[6];
+ gint n = 0, a = 0, i = 0;
+ gchar *temp_filename = NULL;
+
+ LSQArchiveIter *entry;
+
+ status = lsq_archive_command_read_line(archive_command, 1, &line, &linesize, NULL);
+ if (line == NULL)
+ {
+ if(status == G_IO_STATUS_AGAIN)
+ return TRUE;
+ else
+ return FALSE;
+ }
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_GNU_TAR(support)->_view_rights*/
+ {
+ line[10] = '\0';
+ props[i] = line;
+ i++;
+ }
+ for(n=13; n < linesize; ++n)
+ if(line[n] == ' ') break;
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_GNU_TAR(support)->_view_owner*/
+ {
+ line[n] = '\0';
+ props[i] = line+11;
+ i++;
+ }
+
+ for(++n; n < linesize; ++n)
+ if(line[n] >= '0' && line[n] <= '9') break;
+
+ a = n;
+
+ for(; n < linesize; ++n)
+ if(line[n] == ' ') break;
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_GNU_TAR(support)->_view_size*/
+ {
+ line[n] = '\0';
+ size = g_ascii_strtoull(line + a, NULL, 0);
+ props[i] = &size;
+ i++;
+ }
+
+ a = ++n;
+
+ for(; n < linesize; n++) // DATE
+ if(line[n] == ' ') break;
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_GNU_TAR(support)->_view_date*/
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+
+ a = ++n;
+ for (; n < linesize; n++) // TIME
+ if (line[n] == ' ') break;
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_GNU_TAR(support)->_view_time*/
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
+
+ props[i] = NULL;
+ gchar *temp = g_strrstr (&line[n],"->");
+ if (temp )
+ {
+ temp[0] = '\0';
+ }
+ else
+ {
+ line[linesize-1] = '\0';
+ }
+ if(line[0] == 'd')
+ {
+ /* 1: Work around for gtar, which does not output
+ * trailing slashes with directories. */
+ /* 2: The line includes the newline character, this
+ * would probably break on platforms that use
+ * more then one character to indicate a line-end (\r\n) */
+ if(line[linesize-2] != '/')
+ temp_filename = g_strconcat(line + n, "/", NULL);
+ else
+ temp_filename = g_strdup(line + n);
+
+ entry = lsq_archive_add_file(archive, temp_filename);
+ g_free(temp_filename);
+ }
+ else
+ {
+ temp_filename = line + n;
+
+ entry = lsq_archive_add_file(archive, temp_filename);
+ }
+
+ lsq_archive_iter_set_propsv(entry, (gconstpointer*)props);
+ lsq_archive_iter_unref(entry);
+ g_free(line);
+ return TRUE;
+}
+
+static gboolean
+lsq_command_builder_gnu_tar_decompress_parse_output(LSQArchiveCommand *archive_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(archive_command), LSQ_ARCHIVE_TEMP_FILE);
+
+ out_file = fopen(out_filename, "ab");
+ if(!out_file)
+ return FALSE;
+
+ status = lsq_archive_command_read_bytes(archive_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_gnu_tar_compress_parse_output(LSQArchiveCommand *archive_command, gpointer user_data)
+{
+ GIOStatus status = G_IO_STATUS_NORMAL;
+ gchar *buf = g_new0(gchar, 1024);
+ LSQArchive *archive = lsq_archive_command_get_archive(archive_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(archive_command), "compressing"));
+ if(remove == FALSE)
+ {
+ g_object_set_data(G_OBJECT(archive_command), "compressing", GUINT_TO_POINTER(TRUE));
+ g_unlink(out_filename);
+ }
+
+ out_file = fopen(out_filename, "ab");
+ if(!out_file)
+ return FALSE;
+
+ status = lsq_archive_command_read_bytes(archive_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;
+}
Added: squeeze/trunk/libsqueeze/command-builder-gnu-tar.h
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-gnu-tar.h (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-gnu-tar.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,56 @@
+/*
+ * 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_COMMAND_BUILDER_GNU_TAR_H__
+#define __LIBSQUEEZE_COMMAND_BUILDER_GNU_TAR_H__
+
+#define LSQ_TYPE_COMMAND_BUILDER_GNU_TAR lsq_command_builder_gnu_tar_get_type()
+
+#define LSQ_COMMAND_BUILDER_GNU_TAR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_GNU_TAR, \
+ LSQCommandBuilderGnuTar))
+
+#define LSQ_IS_COMMAND_BUILDER_GNU_TAR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_GNU_TAR))
+
+#define LSQ_COMMAND_BUILDER_GNU_TAR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_GNU_TAR, \
+ LSQCommandBuilderGnuTarClass))
+
+#define LSQ_IS_COMMAND_BUILDER_GNU_TAR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_GNU_TAR))
+
+typedef struct _LSQCommandBuilderGnuTar LSQCommandBuilderGnuTar;
+
+struct _LSQCommandBuilderGnuTar
+{
+ LSQCommandBuilder parent;
+};
+
+typedef struct _LSQCommandBuilderGnuTarClass LSQCommandBuilderGnuTarClass;
+
+struct _LSQCommandBuilderGnuTarClass
+{
+ GObjectClass parent;
+};
+
+GType lsq_command_builder_gnu_tar_get_type(void);
+
+#endif /* __LIBSQUEEZE_COMMAND_BUILDER_GNU_TAR_H__ */
Added: squeeze/trunk/libsqueeze/command-builder-rar.c
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-rar.c (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-rar.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,175 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-command.h"
+#include "libsqueeze-module.h"
+#include "archive-iter.h"
+#include "archive-tempfs.h"
+#include "archive.h"
+#include "archive-command.h"
+#include "macro-command.h"
+#include "spawn-command.h"
+#include "dbus-command.h"
+#include "command-builder.h"
+#include "command-builder-rar.h"
+
+static void
+lsq_command_builder_rar_class_init(LSQCommandBuilderRarClass *);
+static void
+lsq_command_builder_rar_init(LSQCommandBuilderRar *archive);
+static void
+lsq_command_builder_rar_dispose(GObject *object);
+static void
+lsq_command_builder_rar_finalize(GObject *object);
+
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_extract(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive);
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+
+static GObjectClass *parent_class;
+
+GType
+lsq_command_builder_rar_get_type ()
+{
+ static GType lsq_command_builder_rar_type = 0;
+
+ if (!lsq_command_builder_rar_type)
+ {
+ static const GTypeInfo lsq_command_builder_rar_info =
+ {
+ sizeof (LSQCommandBuilderRarClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_command_builder_rar_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQCommandBuilderRar),
+ 0,
+ (GInstanceInitFunc) lsq_command_builder_rar_init,
+ NULL
+ };
+
+ lsq_command_builder_rar_type = g_type_register_static (G_TYPE_OBJECT, "LSQCommandBuilderRar", &lsq_command_builder_rar_info, 0);
+ }
+ return lsq_command_builder_rar_type;
+}
+
+static void
+lsq_command_builder_rar_class_init(LSQCommandBuilderRarClass *command_builder_rar_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(command_builder_rar_class);
+
+ object_class->dispose = lsq_command_builder_rar_dispose;
+ object_class->finalize = lsq_command_builder_rar_finalize;
+
+ parent_class = g_type_class_peek(G_TYPE_OBJECT);
+
+}
+
+static void
+lsq_command_builder_rar_init(LSQCommandBuilderRar *command_builder_rar)
+{
+ LSQCommandBuilder *command_builder = LSQ_COMMAND_BUILDER(command_builder_rar);
+
+ command_builder->build_add = lsq_command_builder_rar_build_add;
+ command_builder->build_extract = lsq_command_builder_rar_build_extract;
+ command_builder->build_remove = lsq_command_builder_rar_build_remove;
+ command_builder->build_refresh = lsq_command_builder_rar_build_refresh;
+}
+
+/**
+ * lsq_command_builder_rar_dispose:
+ *
+ * @object: LSQCommandBuilderRar object
+ *
+ */
+static void
+lsq_command_builder_rar_dispose(GObject *object)
+{
+
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_command_builder_rar_finalize:
+ *
+ * @object: LSQCommandBuilderRar object
+ *
+ */
+static void
+lsq_command_builder_rar_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ gchar *files = lsq_concat_filenames(filenames);
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Add", archive, "rar %3$s -r %1$s %2$s", files, NULL, NULL);
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ gchar *files = lsq_concat_filenames(filenames);
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Remove", archive, "rar -d %1$s %2$s", files, NULL, NULL);
+
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_rar_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);
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Extract", archive, "unrar -o %1$s %2$s %3$s", files, options, NULL);
+
+ g_free(options);
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_rar_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Refresh", archive, "unrar -lv -qq %1$s", NULL, NULL, NULL);
+
+ return spawn;
+}
+
Added: squeeze/trunk/libsqueeze/command-builder-rar.h
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-rar.h (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-rar.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,56 @@
+/*
+ * 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_COMMAND_BUILDER_RAR_H__
+#define __LIBSQUEEZE_COMMAND_BUILDER_RAR_H__
+
+#define LSQ_TYPE_COMMAND_BUILDER_RAR lsq_command_builder_rar_get_type()
+
+#define LSQ_COMMAND_BUILDER_RAR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_RAR, \
+ LSQCommandBuilderRar))
+
+#define LSQ_IS_COMMAND_BUILDER_RAR(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_RAR))
+
+#define LSQ_COMMAND_BUILDER_RAR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_RAR, \
+ LSQCommandBuilderRarClass))
+
+#define LSQ_IS_COMMAND_BUILDER_RAR_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_RAR))
+
+typedef struct _LSQCommandBuilderRar LSQCommandBuilderRar;
+
+struct _LSQCommandBuilderRar
+{
+ LSQCommandBuilder parent;
+};
+
+typedef struct _LSQCommandBuilderRarClass LSQCommandBuilderRarClass;
+
+struct _LSQCommandBuilderRarClass
+{
+ GObjectClass parent;
+};
+
+GType lsq_command_builder_rar_get_type(void);
+
+#endif /* __LIBSQUEEZE_COMMAND_BUILDER_RAR_H__ */
Added: squeeze/trunk/libsqueeze/command-builder-zip.c
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-zip.c (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-zip.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,304 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-command.h"
+#include "libsqueeze-module.h"
+#include "archive-iter.h"
+#include "archive-tempfs.h"
+#include "archive.h"
+#include "archive-command.h"
+#include "macro-command.h"
+#include "spawn-command.h"
+#include "dbus-command.h"
+#include "command-builder.h"
+#include "command-builder-zip.h"
+
+static void
+lsq_command_builder_zip_class_init(LSQCommandBuilderZipClass *);
+static void
+lsq_command_builder_zip_init(LSQCommandBuilderZip *archive);
+static void
+lsq_command_builder_zip_dispose(GObject *object);
+static void
+lsq_command_builder_zip_finalize(GObject *object);
+
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_extract(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *files);
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive);
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+
+static gboolean
+lsq_command_builder_zip_refresh_parse_output(LSQArchiveCommand *archive_command, gpointer user_data);
+
+static GObjectClass *parent_class;
+
+GType
+lsq_command_builder_zip_get_type ()
+{
+ static GType lsq_command_builder_zip_type = 0;
+
+ if (!lsq_command_builder_zip_type)
+ {
+ static const GTypeInfo lsq_command_builder_zip_info =
+ {
+ sizeof (LSQCommandBuilderZipClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_command_builder_zip_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQCommandBuilderZip),
+ 0,
+ (GInstanceInitFunc) lsq_command_builder_zip_init,
+ NULL
+ };
+
+ lsq_command_builder_zip_type = g_type_register_static (G_TYPE_OBJECT, "LSQCommandBuilderZip", &lsq_command_builder_zip_info, 0);
+ }
+ return lsq_command_builder_zip_type;
+}
+
+static void
+lsq_command_builder_zip_class_init(LSQCommandBuilderZipClass *command_builder_zip_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(command_builder_zip_class);
+
+ object_class->dispose = lsq_command_builder_zip_dispose;
+ object_class->finalize = lsq_command_builder_zip_finalize;
+
+ parent_class = g_type_class_peek(G_TYPE_OBJECT);
+
+}
+
+static void
+lsq_command_builder_zip_init(LSQCommandBuilderZip *command_builder_zip)
+{
+ LSQCommandBuilder *command_builder = LSQ_COMMAND_BUILDER(command_builder_zip);
+
+ command_builder->build_add = lsq_command_builder_zip_build_add;
+ command_builder->build_extract = lsq_command_builder_zip_build_extract;
+ command_builder->build_remove = lsq_command_builder_zip_build_remove;
+ command_builder->build_refresh = lsq_command_builder_zip_build_refresh;
+}
+
+/**
+ * lsq_command_builder_zip_dispose:
+ *
+ * @object: LSQCommandBuilderZip object
+ *
+ */
+static void
+lsq_command_builder_zip_dispose(GObject *object)
+{
+
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_command_builder_zip_finalize:
+ *
+ * @object: LSQCommandBuilderZip object
+ *
+ */
+static void
+lsq_command_builder_zip_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_add(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ gchar *files = lsq_concat_filenames(filenames);
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Add", archive, "zip %3$s -r %1$s %2$s", files, NULL, NULL);
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_remove(LSQCommandBuilder *builder, LSQArchive *archive, GSList *filenames)
+{
+ gchar *files = lsq_concat_filenames(filenames);
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Remove", archive, "zip -d %1$s %2$s", files, NULL, NULL);
+
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_zip_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);
+
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Extract", archive, "unzip -o %1$s %2$s %3$s", files, options, NULL);
+
+ g_free(options);
+ g_free(files);
+ return spawn;
+}
+
+static LSQArchiveCommand *
+lsq_command_builder_zip_build_refresh(LSQCommandBuilder *builder, LSQArchive *archive)
+{
+ LSQArchiveCommand *spawn = lsq_spawn_command_new("Refresh", archive, "unzip -lv -qq %1$s", NULL, NULL, NULL);
+
+ if(!lsq_spawn_command_set_parse_func(LSQ_SPAWN_COMMAND(spawn), 1, lsq_command_builder_zip_refresh_parse_output, NULL))
+ {
+ g_critical("Could not set refresh parse function");
+ }
+
+ return spawn;
+}
+
+static gboolean
+lsq_command_builder_zip_refresh_parse_output(LSQArchiveCommand *archive_command, gpointer user_data)
+{
+ gchar *line = NULL;
+ gsize linesize = 0;
+ GIOStatus status = G_IO_STATUS_NORMAL;
+ LSQArchive *archive = lsq_archive_command_get_archive(archive_command);
+ guint64 size;
+ guint64 length;
+ gpointer props[8];
+ gint n = 0, a = 0, i = 0;
+ gchar *temp_filename = NULL;
+
+ LSQArchiveIter *entry;
+
+ status = lsq_archive_command_read_line(archive_command, 1, &line, &linesize, NULL);
+ if (line == NULL)
+ {
+ if(status == G_IO_STATUS_AGAIN)
+ return TRUE;
+ else
+ return FALSE;
+ }
+ /* length, method , size, ratio, date, time, crc-32, filename*/
+ for(n=0; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE)/*LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_length*/
+ {
+ line[n]='\0';
+ length = g_ascii_strtoull(line + a, NULL, 0);
+ props[i] = &length;
+ i++;
+ }
+ n++;
+
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_method*/
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
+
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_size*/
+ {
+ line[n]='\0';
+ size = g_ascii_strtoull(line + a, NULL, 0);
+ props[i] = &size;
+ i++;
+ }
+ n++;
+
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_ratio*/
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
+
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_date*/
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
+
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE) /* LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_time */
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n++;
+
+ for(; n < linesize && line[n] == ' '; n++);
+ a = n;
+ for(; n < linesize && line[n] != ' '; n++);
+
+ if(TRUE) /*LSQ_ARCHIVE_SUPPORT_ZIP(support)->_view_crc_32 */
+ {
+ line[n] = '\0';
+ props[i] = line + a;
+ i++;
+ }
+ n+=2;
+
+ line[linesize-1] = '\0';
+ temp_filename = line+n;
+ props[i] = NULL;
+
+ entry = lsq_archive_add_file(archive, temp_filename);
+ lsq_archive_iter_set_propsv(entry, (gconstpointer*)props);
+ lsq_archive_iter_unref(entry);
+ g_free(line);
+
+ return TRUE;
+}
Added: squeeze/trunk/libsqueeze/command-builder-zip.h
===================================================================
--- squeeze/trunk/libsqueeze/command-builder-zip.h (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder-zip.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,56 @@
+/*
+ * 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_COMMAND_BUILDER_ZIP_H__
+#define __LIBSQUEEZE_COMMAND_BUILDER_ZIP_H__
+
+#define LSQ_TYPE_COMMAND_BUILDER_ZIP lsq_command_builder_zip_get_type()
+
+#define LSQ_COMMAND_BUILDER_ZIP(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_ZIP, \
+ LSQCommandBuilderZip))
+
+#define LSQ_IS_COMMAND_BUILDER_ZIP(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER_ZIP))
+
+#define LSQ_COMMAND_BUILDER_ZIP_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_ZIP, \
+ LSQCommandBuilderZipClass))
+
+#define LSQ_IS_COMMAND_BUILDER_ZIP_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER_ZIP))
+
+typedef struct _LSQCommandBuilderZip LSQCommandBuilderZip;
+
+struct _LSQCommandBuilderZip
+{
+ LSQCommandBuilder parent;
+};
+
+typedef struct _LSQCommandBuilderZipClass LSQCommandBuilderZipClass;
+
+struct _LSQCommandBuilderZipClass
+{
+ GObjectClass parent;
+};
+
+GType lsq_command_builder_zip_get_type(void);
+
+#endif /* __LIBSQUEEZE_COMMAND_BUILDER_ZIP_H__ */
Added: squeeze/trunk/libsqueeze/command-builder.c
===================================================================
--- squeeze/trunk/libsqueeze/command-builder.c (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,132 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-command.h"
+#include "archive-iter.h"
+#include "archive-tempfs.h"
+#include "archive.h"
+#include "archive-command.h"
+#include "macro-command.h"
+#include "spawn-command.h"
+#include "dbus-command.h"
+#include "command-builder.h"
+
+static void
+lsq_command_builder_class_init(LSQCommandBuilderClass *);
+static void
+lsq_command_builder_init(LSQCommandBuilder *archive);
+static void
+lsq_command_builder_dispose(GObject *object);
+static void
+lsq_command_builder_finalize(GObject *object);
+
+static LSQArchiveCommand *
+lsq_command_builder_build_open(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+
+static GObjectClass *parent_class;
+
+GType
+lsq_command_builder_get_type ()
+{
+ static GType lsq_command_builder_type = 0;
+
+ if (!lsq_command_builder_type)
+ {
+ static const GTypeInfo lsq_command_builder_info =
+ {
+ sizeof (LSQCommandBuilderClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_command_builder_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQCommandBuilder),
+ 0,
+ (GInstanceInitFunc) lsq_command_builder_init,
+ NULL
+ };
+
+ lsq_command_builder_type = g_type_register_static (G_TYPE_OBJECT, "LSQCommandBuilder", &lsq_command_builder_info, 0);
+ }
+ return lsq_command_builder_type;
+}
+
+static void
+lsq_command_builder_class_init(LSQCommandBuilderClass *command_builder_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(command_builder_class);
+
+ object_class->dispose = lsq_command_builder_dispose;
+ object_class->finalize = lsq_command_builder_finalize;
+
+ parent_class = g_type_class_peek(G_TYPE_OBJECT);
+
+}
+
+static void
+lsq_command_builder_init(LSQCommandBuilder *command_builder)
+{
+ command_builder->build_open = lsq_command_builder_build_open;
+}
+
+/**
+ * lsq_command_builder_dispose:
+ *
+ * @object: LSQCommandBuilder object
+ *
+ */
+static void
+lsq_command_builder_dispose(GObject *object)
+{
+
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_command_builder_finalize:
+ *
+ * @object: LSQCommandBuilder object
+ *
+ */
+static void
+lsq_command_builder_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+static LSQArchiveCommand *
+lsq_command_builder_build_open(LSQCommandBuilder *builder, LSQArchive *archive, GSList *files)
+{
+ LSQArchiveCommand *extract = builder->build_extract(builder, archive, lsq_tempfs_get_root_dir(archive), files);
+ LSQArchiveCommand *launch = lsq_dbus_command_new("Execute", archive);
+ LSQArchiveCommand *macro = lsq_macro_command_new("Open", archive);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(macro), extract);
+ lsq_macro_command_append(LSQ_MACRO_COMMAND(macro), launch);
+
+ return macro;
+}
Added: squeeze/trunk/libsqueeze/command-builder.h
===================================================================
--- squeeze/trunk/libsqueeze/command-builder.h (rev 0)
+++ squeeze/trunk/libsqueeze/command-builder.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,47 @@
+#ifndef __LIBSQUEEZE_COMMAND_BUILDER_H__
+#define __LIBSQUEEZE_COMMAND_BUILDER_H__
+
+#define LSQ_TYPE_COMMAND_BUILDER lsq_command_builder_get_type()
+
+#define LSQ_COMMAND_BUILDER(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER, \
+ LSQCommandBuilder))
+
+#define LSQ_IS_COMMAND_BUILDER(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_COMMAND_BUILDER))
+
+#define LSQ_COMMAND_BUILDER_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_CAST ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER, \
+ LSQCommandBuilderClass))
+
+#define LSQ_IS_COMMAND_BUILDER_CLASS(klass) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ LSQ_TYPE_COMMAND_BUILDER))
+
+typedef struct _LSQCommandBuilder LSQCommandBuilder;
+
+struct _LSQCommandBuilder
+{
+ GObject parent;
+ gchar *id;
+
+ LSQArchiveCommand *(*build_add) (LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+ LSQArchiveCommand *(*build_extract)(LSQCommandBuilder *builder, LSQArchive *archive, const gchar *dest_path, GSList *files);
+ LSQArchiveCommand *(*build_remove) (LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+ LSQArchiveCommand *(*build_refresh)(LSQCommandBuilder *builder, LSQArchive *archive);
+ LSQArchiveCommand *(*build_open) (LSQCommandBuilder *builder, LSQArchive *archive, GSList *files);
+};
+
+typedef struct _LSQCommandBuilderClass LSQCommandBuilderClass;
+
+struct _LSQCommandBuilderClass
+{
+ GObjectClass parent;
+};
+
+GType lsq_command_builder_get_type(void);
+
+#endif /* __LIBSQUEEZE_COMMAND_BUILDER_H__ */
Added: squeeze/trunk/libsqueeze/dbus-command.c
===================================================================
--- squeeze/trunk/libsqueeze/dbus-command.c (rev 0)
+++ squeeze/trunk/libsqueeze/dbus-command.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,144 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-support.h"
+#include "libsqueeze-command.h"
+#include "libsqueeze-module.h"
+#include "archive-iter.h"
+#include "archive-command.h"
+#include "dbus-command.h"
+#include "archive.h"
+
+static void
+lsq_dbus_command_class_init(LSQDBusCommandClass *);
+static void
+lsq_dbus_command_init(LSQDBusCommand *);
+static void
+lsq_dbus_command_dispose(GObject *object);
+static void
+lsq_dbus_command_finalize(GObject *object);
+
+static gboolean
+lsq_dbus_command_execute(LSQArchiveCommand *command);
+
+//static gint lsq_archive_command_signals[0];
+
+static GObjectClass *parent_class;
+
+GType
+lsq_dbus_command_get_type ()
+{
+ static GType lsq_dbus_command_type = 0;
+
+ if (!lsq_dbus_command_type)
+ {
+ static const GTypeInfo lsq_dbus_command_info =
+ {
+ sizeof (LSQDBusCommandClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_dbus_command_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQDBusCommand),
+ 0,
+ (GInstanceInitFunc) lsq_dbus_command_init,
+ NULL
+ };
+
+ lsq_dbus_command_type = g_type_register_static (G_TYPE_OBJECT, "LSQDBusCommand", &lsq_dbus_command_info, 0);
+ }
+ return lsq_dbus_command_type;
+}
+
+static void
+lsq_dbus_command_class_init(LSQDBusCommandClass *dbus_command_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(dbus_command_class);
+
+ object_class->dispose = lsq_dbus_command_dispose;
+ object_class->finalize = lsq_dbus_command_finalize;
+
+ parent_class = g_type_class_peek(LSQ_TYPE_ARCHIVE_COMMAND);
+
+}
+
+static void
+lsq_dbus_command_init(LSQDBusCommand *dbus_command)
+{
+ LSQArchiveCommand *command = LSQ_ARCHIVE_COMMAND(dbus_command);
+ command->execute = lsq_dbus_command_execute;
+}
+
+/**
+ * lsq_dbus_command_dispose:
+ *
+ * @object: LSQDBusCommand object
+ *
+ */
+static void
+lsq_dbus_command_dispose(GObject *object)
+{
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_dbus_command_finalize:
+ *
+ * @object: LSQDBusCommand object
+ *
+ */
+static void
+lsq_dbus_command_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+/**
+ * lsq_dbus_command_new:
+ * @comment: a description, describing what the command does
+ * @archive: the archive the command modifies
+ *
+ * Returns: a new LSQDBusCommand object
+ */
+LSQArchiveCommand *
+lsq_dbus_command_new(const gchar *comment, LSQArchive *archive)
+{
+ LSQArchiveCommand *archive_command;
+
+ archive_command = g_object_new(lsq_dbus_command_get_type(), NULL);
+
+ return archive_command;
+}
+
+static gboolean
+lsq_dbus_command_execute(LSQArchiveCommand *command)
+{
+ g_critical("DBUS COMMAND NOT IMPLEMENTED");
+ return FALSE;
+}
Added: squeeze/trunk/libsqueeze/dbus-command.h
===================================================================
--- squeeze/trunk/libsqueeze/dbus-command.h (rev 0)
+++ squeeze/trunk/libsqueeze/dbus-command.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,59 @@
+/*
+ * 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_DBUS_COMMAND_H__
+#define __LIBSQUEEZE_DBUS_COMMAND_H__
+G_BEGIN_DECLS
+
+#define LSQ_TYPE_DBUS_COMMAND lsq_dbus_command_get_type()
+
+#define LSQ_DBUS_COMMAND(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_DBUS_COMMAND, \
+ LSQDBusCommand))
+
+#define LSQ_IS_DBUS_COMMAND(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_DBUS_COMMAND))
+
+#define LSQ_DBUS_COMMAND_CLASS(class) ( \
+ G_TYPE_CHECK_CLASS_CAST ((class), \
+ LSQ_TYPE_DBUS_COMMAND, \
+ LSQDBusCommandClass))
+
+#define LSQ_IS_DBUS_COMMAND_CLASS(class) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((class), \
+ LSQ_TYPE_DBUS_COMMAND))
+
+typedef struct _LSQDBusCommand LSQDBusCommand;
+
+struct _LSQDBusCommand
+{
+ LSQArchiveCommand parent;
+ GSList *command_queue;
+};
+
+typedef struct _LSQDBusCommandClass LSQDBusCommandClass;
+
+struct _LSQDBusCommandClass
+{
+ LSQArchiveCommandClass parent;
+};
+
+LSQArchiveCommand * lsq_dbus_command_new(const gchar *comment, LSQArchive *archive);
+void lsq_dbus_command_append(LSQDBusCommand *command, LSQArchiveCommand *sub_command);
+
+G_END_DECLS
+#endif /* __LIBSQUEEZE_DBUS_COMMAND_H__ */
Modified: squeeze/trunk/libsqueeze/internals.c
===================================================================
--- squeeze/trunk/libsqueeze/internals.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/internals.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -27,7 +27,7 @@
#include "archive-iter.h"
#include "archive-command.h"
#include "archive.h"
-#include "archive-support.h"
+#include "command-builder.h"
#include "internals.h"
Modified: squeeze/trunk/libsqueeze/libsqueeze-archive.h
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze-archive.h 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/libsqueeze-archive.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -51,7 +51,8 @@
GType lsq_archive_get_type(void);
-const gchar *lsq_archive_get_filename(const LSQArchive *archive);
+const gchar *lsq_archive_get_path(const LSQArchive *archive);
+gchar *lsq_archive_get_filename(const LSQArchive *archive);
const gchar *lsq_archive_get_mimetype(const LSQArchive *archive);
gboolean lsq_archive_exists(const LSQArchive *archive);
@@ -67,7 +68,6 @@
LSQArchiveIter *lsq_archive_iter_ref(LSQArchiveIter *iter);
void lsq_archive_iter_unref(LSQArchiveIter *iter);
-gboolean lsq_archive_has_queue(LSQArchive *archive);
G_END_DECLS
Modified: squeeze/trunk/libsqueeze/libsqueeze-command.h
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze-command.h 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/libsqueeze-command.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -65,7 +65,7 @@
gboolean lsq_archive_command_set_parse_func(LSQArchiveCommand *archive_command,
guint fd,
LSQParseFunc func,
- gpointer user_data);
+ gpointer user_data);
LSQArchive *lsq_archive_command_get_archive(LSQArchiveCommand *command);
Modified: squeeze/trunk/libsqueeze/libsqueeze.c
===================================================================
--- squeeze/trunk/libsqueeze/libsqueeze.c 2007-03-16 11:28:29 UTC (rev 25176)
+++ squeeze/trunk/libsqueeze/libsqueeze.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -26,7 +26,7 @@
#include "libsqueeze/archive-iter.h"
#include "libsqueeze/archive-command.h"
#include "libsqueeze/archive.h"
-#include "libsqueeze/archive-support.h"
+#include "libsqueeze/command-builder.h"
#include "libsqueeze/archive-support-zip.h"
#include "libsqueeze/archive-support-rar.h"
#include "libsqueeze/archive-support-compr.h"
Added: squeeze/trunk/libsqueeze/macro-command.c
===================================================================
--- squeeze/trunk/libsqueeze/macro-command.c (rev 0)
+++ squeeze/trunk/libsqueeze/macro-command.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,160 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-support.h"
+#include "libsqueeze-command.h"
+#include "libsqueeze-module.h"
+#include "archive-iter.h"
+#include "archive-command.h"
+#include "macro-command.h"
+#include "archive.h"
+
+static void
+lsq_macro_command_class_init(LSQMacroCommandClass *);
+static void
+lsq_macro_command_init(LSQMacroCommand *);
+static void
+lsq_macro_command_dispose(GObject *object);
+static void
+lsq_macro_command_finalize(GObject *object);
+
+static gboolean
+lsq_macro_command_execute(LSQArchiveCommand *command);
+static gboolean
+lsq_macro_command_stop(LSQArchiveCommand *command);
+
+static GObjectClass *parent_class;
+
+GType
+lsq_macro_command_get_type ()
+{
+ static GType lsq_macro_command_type = 0;
+
+ if (!lsq_macro_command_type)
+ {
+ static const GTypeInfo lsq_macro_command_info =
+ {
+ sizeof (LSQMacroCommandClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_macro_command_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQMacroCommand),
+ 0,
+ (GInstanceInitFunc) lsq_macro_command_init,
+ NULL
+ };
+
+ lsq_macro_command_type = g_type_register_static (G_TYPE_OBJECT, "LSQMacroCommand", &lsq_macro_command_info, 0);
+ }
+ return lsq_macro_command_type;
+}
+
+static void
+lsq_macro_command_class_init(LSQMacroCommandClass *macro_command_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(macro_command_class);
+
+ object_class->dispose = lsq_macro_command_dispose;
+ object_class->finalize = lsq_macro_command_finalize;
+
+ parent_class = g_type_class_peek(LSQ_TYPE_ARCHIVE_COMMAND);
+
+}
+
+static void
+lsq_macro_command_init(LSQMacroCommand *macro_command)
+{
+ LSQArchiveCommand *command = LSQ_ARCHIVE_COMMAND(macro_command);
+
+ command->execute = lsq_macro_command_execute;
+ command->stop = lsq_macro_command_stop;
+}
+
+/**
+ * lsq_macro_command_dispose:
+ *
+ * @object: LSQMacroCommand object
+ *
+ */
+static void
+lsq_macro_command_dispose(GObject *object)
+{
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_macro_command_finalize:
+ *
+ * @object: LSQMacroCommand object
+ *
+ */
+static void
+lsq_macro_command_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+/**
+ * lsq_macro_command_new:
+ * @comment: a description, describing what the command does
+ * @archive: the archive the command modifies
+ *
+ * Returns: a new LSQMacroCommand object
+ */
+LSQArchiveCommand *
+lsq_macro_command_new(const gchar *comment, LSQArchive *archive)
+{
+ LSQArchiveCommand *archive_command;
+
+ archive_command = g_object_new(lsq_macro_command_get_type(), NULL);
+
+ if(comment)
+ archive_command->comment = g_strdup(comment);
+
+ return archive_command;
+}
+
+static gboolean
+lsq_macro_command_execute(LSQArchiveCommand *command)
+{
+ return TRUE;
+}
+
+static gboolean
+lsq_macro_command_stop(LSQArchiveCommand *command)
+{
+ return TRUE;
+}
+
+void
+lsq_macro_command_append(LSQMacroCommand *command, LSQArchiveCommand *sub_command)
+{
+ command->command_queue = g_slist_append(command->command_queue, sub_command);
+}
Added: squeeze/trunk/libsqueeze/macro-command.h
===================================================================
--- squeeze/trunk/libsqueeze/macro-command.h (rev 0)
+++ squeeze/trunk/libsqueeze/macro-command.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,61 @@
+/*
+ * 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_MACRO_COMMAND_H__
+#define __LIBSQUEEZE_MACRO_COMMAND_H__
+G_BEGIN_DECLS
+
+#define LSQ_TYPE_MACRO_COMMAND lsq_macro_command_get_type()
+
+#define LSQ_MACRO_COMMAND(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_MACRO_COMMAND, \
+ LSQMacroCommand))
+
+#define LSQ_IS_MACRO_COMMAND(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_MACRO_COMMAND))
+
+#define LSQ_MACRO_COMMAND_CLASS(class) ( \
+ G_TYPE_CHECK_CLASS_CAST ((class), \
+ LSQ_TYPE_MACRO_COMMAND, \
+ LSQMacroCommandClass))
+
+#define LSQ_IS_MACRO_COMMAND_CLASS(class) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((class), \
+ LSQ_TYPE_MACRO_COMMAND))
+
+typedef struct _LSQMacroCommand LSQMacroCommand;
+
+struct _LSQMacroCommand
+{
+ LSQArchiveCommand parent;
+ GSList *command_queue;
+};
+
+typedef struct _LSQMacroCommandClass LSQMacroCommandClass;
+
+struct _LSQMacroCommandClass
+{
+ LSQArchiveCommandClass parent;
+};
+
+GType lsq_macro_command_get_type();
+
+LSQArchiveCommand * lsq_macro_command_new(const gchar *comment, LSQArchive *archive);
+void lsq_macro_command_append(LSQMacroCommand *command, LSQArchiveCommand *sub_command);
+
+G_END_DECLS
+#endif /* __LIBSQUEEZE_MACRO_COMMAND_H__ */
Added: squeeze/trunk/libsqueeze/spawn-command.c
===================================================================
--- squeeze/trunk/libsqueeze/spawn-command.c (rev 0)
+++ squeeze/trunk/libsqueeze/spawn-command.c 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,368 @@
+/*
+ * 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 <signal.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <thunar-vfs/thunar-vfs.h>
+
+#include "libsqueeze-archive.h"
+#include "libsqueeze-command.h"
+#include "archive-iter.h"
+#include "archive-command.h"
+#include "spawn-command.h"
+#include "archive.h"
+
+static void
+lsq_spawn_command_class_init(LSQSpawnCommandClass *);
+static void
+lsq_spawn_command_init(LSQSpawnCommand *);
+static void
+lsq_spawn_command_dispose(GObject *object);
+static void
+lsq_spawn_command_finalize(GObject *object);
+
+static gboolean
+lsq_spawn_command_execute(LSQArchiveCommand *command);
+static gboolean
+lsq_spawn_command_stop(LSQArchiveCommand *command);
+
+void
+lsq_spawn_command_child_watch_func(GPid pid, gint status, gpointer data);
+
+gboolean
+lsq_spawn_command_parse_stdout(GIOChannel *, GIOCondition , gpointer );
+
+//static gint lsq_archive_command_signals[0];
+
+static GObjectClass *parent_class;
+
+GType
+lsq_spawn_command_get_type ()
+{
+ static GType lsq_spawn_command_type = 0;
+
+ if (!lsq_spawn_command_type)
+ {
+ static const GTypeInfo lsq_spawn_command_info =
+ {
+ sizeof (LSQSpawnCommandClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) lsq_spawn_command_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (LSQSpawnCommand),
+ 0,
+ (GInstanceInitFunc) lsq_spawn_command_init,
+ NULL
+ };
+
+ lsq_spawn_command_type = g_type_register_static (G_TYPE_OBJECT, "LSQSpawnCommand", &lsq_spawn_command_info, 0);
+ }
+ return lsq_spawn_command_type;
+}
+
+static void
+lsq_spawn_command_class_init(LSQSpawnCommandClass *spawn_command_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS(spawn_command_class);
+
+ object_class->dispose = lsq_spawn_command_dispose;
+ object_class->finalize = lsq_spawn_command_finalize;
+
+ parent_class = g_type_class_peek(LSQ_TYPE_ARCHIVE_COMMAND);
+
+}
+
+static void
+lsq_spawn_command_init(LSQSpawnCommand *spawn_command)
+{
+ LSQArchiveCommand *command = LSQ_ARCHIVE_COMMAND(spawn_command);
+
+ command->execute = lsq_spawn_command_execute;
+ command->stop = lsq_spawn_command_stop;
+
+ spawn_command->parse_stdout = NULL;
+}
+
+/**
+ * lsq_spawn_command_dispose:
+ *
+ * @object: LSQSpawnCommand object
+ *
+ */
+static void
+lsq_spawn_command_dispose(GObject *object)
+{
+ parent_class->dispose(object);
+}
+
+/**
+ * lsq_spawn_command_finalize:
+ *
+ * @object: LSQSpawnCommand object
+ *
+ */
+static void
+lsq_spawn_command_finalize(GObject *object)
+{
+ parent_class->finalize(object);
+}
+
+
+/**
+ * lsq_spawn_command_new:
+ * @comment: a description, describing what the command does
+ * @archive: the archive the command modifies
+ * @command: a formatted string defining the command to be executed.
+ * @safe: is it safe to terminate this child premature?
+ *
+ *
+ * %%1$s is the application to be executed.
+ *
+ * %%2$s are the files to be appended
+ *
+ * %%3$s are any additional options
+ *
+ * Returns: a new LSQArchiveCommand object
+ */
+LSQArchiveCommand *
+lsq_spawn_command_new(const gchar *comment,
+ LSQArchive *archive,
+ const gchar *command,
+ const gchar *files,
+ const gchar *options,
+ const gchar *archive_path)
+{
+ 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_spawn_command_get_type(), NULL);
+
+ LSQ_SPAWN_COMMAND(archive_command)->command = g_strdup(command);
+ if(files)
+ LSQ_SPAWN_COMMAND(archive_command)->files = g_strdup(files);
+ if(options)
+ LSQ_SPAWN_COMMAND(archive_command)->options = g_strdup(options);
+ if(archive_path)
+ LSQ_SPAWN_COMMAND(archive_command)->archive_path = g_strdup(archive_path);
+ else
+ LSQ_SPAWN_COMMAND(archive_command)->archive_path = g_strdup(lsq_archive_get_path(archive));
+
+ archive_command->archive = archive;
+ if(comment)
+ archive_command->comment = g_strdup(comment);
+
+ return archive_command;
+}
+
+
+static gboolean
+lsq_spawn_command_execute(LSQArchiveCommand *command)
+{
+ gchar **argvp;
+ gint argcp;
+ gint fd_in, fd_out, fd_err;
+ LSQSpawnCommand *spawn_command = LSQ_SPAWN_COMMAND(command);
+
+ gchar *escaped_archive_path = g_shell_quote(spawn_command->archive_path);
+
+ gchar *cmd = g_strdup_printf(spawn_command->command, escaped_archive_path, spawn_command->files, spawn_command->options);
+
+
+ g_shell_parse_argv(cmd, &argcp, &argvp, NULL);
+ if ( ! g_spawn_async_with_pipes (
+ NULL,
+ argvp,
+ NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL,
+ NULL,
+ &(spawn_command->child_pid),
+ &fd_in,
+ &fd_out,
+ &fd_err,
+ NULL) )
+ {
+ g_object_unref(spawn_command);
+ return FALSE;
+ }
+ LSQ_ARCHIVE_COMMAND(command)->running = TRUE;
+
+ g_child_watch_add(spawn_command->child_pid, lsq_spawn_command_child_watch_func, spawn_command);
+
+ if(spawn_command->parse_stdout != NULL)
+ {
+ g_object_ref(spawn_command);
+ spawn_command->ioc_out = g_io_channel_unix_new(fd_out);
+ g_io_channel_set_encoding (spawn_command->ioc_out, NULL, NULL);
+ g_io_channel_set_flags (spawn_command->ioc_out , G_IO_FLAG_NONBLOCK , NULL );
+ g_io_add_watch (spawn_command->ioc_out, G_IO_IN|G_IO_PRI|G_IO_ERR|G_IO_HUP|G_IO_NVAL, lsq_spawn_command_parse_stdout, spawn_command);
+ }
+ g_free(escaped_archive_path);
+ g_free(cmd);
+ return TRUE;
+}
+
+static gboolean
+lsq_spawn_command_stop(LSQArchiveCommand *command)
+{
+ LSQSpawnCommand *spawn_command = LSQ_SPAWN_COMMAND(command);
+ if(command->running)
+ {
+ if(spawn_command->child_pid != 0)
+ kill ( spawn_command->child_pid , SIGHUP);
+ else
+ return FALSE; /* command isn't running */
+ }
+ else
+ return FALSE; /* command isn't running */
+ return TRUE;
+}
+
+/**
+ * lsq_spawn_command_child_watch_func:
+ * @pid:
+ * @status:
+ * @data:
+ */
+void
+lsq_spawn_command_child_watch_func(GPid pid, gint status, gpointer data)
+{
+ LSQArchiveCommand *command = LSQ_ARCHIVE_COMMAND(data);
+ if(WIFEXITED(status))
+ {
+ if(WEXITSTATUS(status))
+ {
+ if(!command->error)
+ {
+ command->error = g_error_new(command->domain, status, _("Command exited with status %d."), status);
+ }
+ }
+ }
+ if(WIFSIGNALED(status))
+ {
+ switch(WTERMSIG(status))
+ {
+ case SIGHUP:
+ if(!command->error)
+ command->error = g_error_new_literal(command->domain, status, _("Command interrupted by user"));
+ break;
+ case SIGSEGV:
+ if(!command->error)
+ command->error = g_error_new_literal(command->domain, status, _("Command received SIGSEGV"));
+ break;
+ case SIGKILL:
+ case SIGINT:
+ if(!command->error)
+ command->error = g_error_new_literal(command->domain, status, _("Command Terminated"));
+ break;
+ }
+ }
+ g_spawn_close_pid(pid);
+ g_object_unref(G_OBJECT(data));
+}
+
+/**
+ * lsq_spawn_command_parse_stdout:
+ * @ioc:
+ * @cond:
+ * @data:
+ *
+ * Returns:
+ */
+gboolean
+lsq_spawn_command_parse_stdout(GIOChannel *ioc, GIOCondition cond, gpointer data)
+{
+ gint i = 0;
+ LSQArchiveCommand *archive_command = LSQ_ARCHIVE_COMMAND(data);
+ LSQSpawnCommand *spawn_command = LSQ_SPAWN_COMMAND(data);
+
+ if(cond & (G_IO_PRI | G_IO_IN))
+ {
+ for(; i < 500; i++)
+ {
+ /* If parse_stdout returns FALSE, something seriously went wrong and we should cancel right away */
+ if(spawn_command->parse_stdout(archive_command, archive_command->user_data) == FALSE)
+ {
+ cond |= G_IO_ERR;
+ }
+ }
+ }
+ if(cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL) )
+ {
+ g_io_channel_shutdown ( ioc,TRUE,NULL );
+ g_io_channel_unref (ioc);
+ g_object_unref(spawn_command);
+ return FALSE;
+ }
+ return TRUE;
+}
+
+gboolean
+lsq_spawn_command_set_parse_func(LSQSpawnCommand *spawn_command, guint fd, LSQParseFunc func, gpointer user_data)
+{
+ LSQArchiveCommand *archive_command = LSQ_ARCHIVE_COMMAND(spawn_command);
+ switch(fd)
+ {
+ case 1:
+ spawn_command->parse_stdout = func;
+ archive_command->user_data = user_data;
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+GIOStatus
+lsq_spawn_command_read_line(LSQSpawnCommand *spawn_command, guint fd, gchar **line, gsize *length, GError **error)
+{
+ GIOStatus status = G_IO_STATUS_EOF;
+ switch(fd)
+ {
+ case 1:
+ status = g_io_channel_read_line(spawn_command->ioc_out, line, length, NULL, error);
+ break;
+ default:
+ break;
+ }
+ return status;
+}
+
+GIOStatus
+lsq_spawn_command_read_bytes(LSQSpawnCommand *spawn_command, guint fd, gchar *buf, gsize max_length, gsize *length, GError **error)
+{
+ GIOStatus status = G_IO_STATUS_EOF;
+ switch(fd)
+ {
+ case 1:
+ status = g_io_channel_read_chars(spawn_command->ioc_out, buf, max_length, length, error);
+ break;
+ default:
+ break;
+ }
+ return status;
+}
Added: squeeze/trunk/libsqueeze/spawn-command.h
===================================================================
--- squeeze/trunk/libsqueeze/spawn-command.h (rev 0)
+++ squeeze/trunk/libsqueeze/spawn-command.h 2007-03-16 11:31:11 UTC (rev 25177)
@@ -0,0 +1,80 @@
+/*
+ * 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_SPAWN_COMMAND_H__
+#define __LIBSQUEEZE_SPAWN_COMMAND_H__
+G_BEGIN_DECLS
+
+#define LSQ_TYPE_SPAWN_COMMAND lsq_spawn_command_get_type()
+
+#define LSQ_SPAWN_COMMAND(obj) ( \
+ G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ LSQ_TYPE_SPAWN_COMMAND, \
+ LSQSpawnCommand))
+
+#define LSQ_IS_SPAWN_COMMAND(obj) ( \
+ G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ LSQ_TYPE_SPAWN_COMMAND))
+
+#define LSQ_SPAWN_COMMAND_CLASS(class) ( \
+ G_TYPE_CHECK_CLASS_CAST ((class), \
+ LSQ_TYPE_SPAWN_COMMAND, \
+ LSQSpawnCommandClass))
+
+#define LSQ_IS_SPAWN_COMMAND_CLASS(class) ( \
+ G_TYPE_CHECK_CLASS_TYPE ((class), \
+ LSQ_TYPE_SPAWN_COMMAND))
+
+typedef struct _LSQSpawnCommand LSQSpawnCommand;
+
+struct _LSQSpawnCommand
+{
+ LSQArchiveCommand parent;
+ gchar *command;
+ GPid child_pid;
+ GIOChannel *ioc_in;
+ GIOChannel *ioc_out;
+ GIOChannel *ioc_err;
+
+ gchar *files;
+ gchar *options;
+ gchar *archive_path;
+
+ LSQParseFunc parse_stdout;
+ LSQParseFunc parse_stderr;
+};
+
+typedef struct _LSQSpawnCommandClass LSQSpawnCommandClass;
+
+struct _LSQSpawnCommandClass
+{
+ LSQArchiveCommandClass parent;
+};
+
+GType
+lsq_spawn_command_get_type();
+
+LSQArchiveCommand *
+lsq_spawn_command_new(const gchar *comment,
+ LSQArchive *archive,
+ const gchar *command,
+ const gchar *files,
+ const gchar *options,
+ const gchar *archive_path);
+gboolean
+lsq_spawn_command_set_parse_func(LSQSpawnCommand *spawn_command, guint fd, LSQParseFunc func, gpointer user_data);
+
+G_END_DECLS
+#endif /* __LIBSQUEEZE_ARCHIVE_COMMAND_H__ */
More information about the Xfce4-commits
mailing list