[file-roller] use a boxed type to pass the error to the 'done' signal



commit 4b645f57c856928c508dd74c31e1bfb2132368e1
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Jun 18 20:45:46 2012 +0200

    use a boxed type to pass the error to the 'done' signal

 src/Makefile.am     |    2 +
 src/fr-archive.c    |    9 ++++---
 src/fr-command.c    |   11 ++++++---
 src/fr-marshal.list |    3 +-
 src/fr-proc-error.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/fr-proc-error.h |   31 ++++++++++++++++++++++++++++
 src/fr-process.c    |   18 +++++++++++-----
 src/fr-process.h    |    3 +-
 8 files changed, 116 insertions(+), 16 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 1925a34..853a15e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -133,6 +133,8 @@ COMMON_SOURCES = 			\
 	fr-list-model.h			\
 	fr-stock.c			\
 	fr-stock.h			\
+	fr-proc-error.c			\
+	fr-proc-error.h			\
 	fr-process.c			\
 	fr-process.h			\
 	fr-window.c			\
diff --git a/src/fr-archive.c b/src/fr-archive.c
index f0fbcea..9131bd0 100644
--- a/src/fr-archive.c
+++ b/src/fr-archive.c
@@ -37,6 +37,7 @@
 #include "fr-command.h"
 #include "fr-error.h"
 #include "fr-marshal.h"
+#include "fr-proc-error.h"
 #include "fr-process.h"
 #include "fr-init.h"
 
@@ -246,10 +247,10 @@ fr_archive_class_init (FrArchiveClass *class)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (FrArchiveClass, done),
 			      NULL, NULL,
-			      fr_marshal_VOID__INT_POINTER,
+			      fr_marshal_VOID__INT_BOXED,
 			      G_TYPE_NONE, 2,
 			      G_TYPE_INT,
-			      G_TYPE_POINTER);
+			      FR_TYPE_PROC_ERROR);
 	fr_archive_signals[PROGRESS] =
 		g_signal_new ("progress",
 			      G_TYPE_FROM_CLASS (class),
@@ -1603,7 +1604,7 @@ fr_archive_add (FrArchive     *archive,
 		archive->process->error.type = FR_PROC_ERROR_NONE;
 		g_signal_emit_by_name (G_OBJECT (archive->process),
 				       "done",
-				       FR_ACTION_ADDING_FILES);
+				       &archive->process->error);
 		return;
 	}
 
@@ -1690,7 +1691,7 @@ fr_archive_add (FrArchive     *archive,
 			archive->process->error.gerror = g_error_copy (error);
 			g_signal_emit_by_name (G_OBJECT (archive->process),
 					       "done",
-					       FR_ACTION_ADDING_FILES);
+					       &archive->process->error);
 			g_clear_error (&error);
 			error_occurred = TRUE;
 		}
diff --git a/src/fr-command.c b/src/fr-command.c
index cee582e..6d13d84 100644
--- a/src/fr-command.c
+++ b/src/fr-command.c
@@ -28,6 +28,7 @@
 #include "fr-command.h"
 #include "fr-enum-types.h"
 #include "fr-marshal.h"
+#include "fr-proc-error.h"
 #include "fr-process.h"
 #include "glib-utils.h"
 
@@ -218,12 +219,14 @@ fr_command_start (FrProcess *process,
 
 static void
 fr_command_done (FrProcess   *process,
+		 FrProcError *error,
 		 gpointer     data)
 {
 	FrCommand *comm = FR_COMMAND (data);
 
 	comm->process->restart = FALSE;
-	fr_command_handle_error (comm, &process->error);
+	if (error->type != FR_PROC_ERROR_STOPPED)
+		fr_command_handle_error (comm, error);
 
 	if (comm->process->restart) {
 		fr_process_start (comm->process);
@@ -239,7 +242,7 @@ fr_command_done (FrProcess   *process,
 		       fr_command_signals[DONE],
 		       0,
 		       comm->action,
-		       &process->error);
+		       error);
 }
 
 
@@ -401,10 +404,10 @@ fr_command_class_init (FrCommandClass *class)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (FrCommandClass, done),
 			      NULL, NULL,
-			      fr_marshal_VOID__INT_POINTER,
+			      fr_marshal_VOID__INT_BOXED,
 			      G_TYPE_NONE, 2,
 			      G_TYPE_INT,
-			      G_TYPE_POINTER);
+			      FR_TYPE_PROC_ERROR);
 	fr_command_signals[PROGRESS] =
 		g_signal_new ("progress",
 			      G_TYPE_FROM_CLASS (class),
diff --git a/src/fr-marshal.list b/src/fr-marshal.list
index d5d5313..f3b2554 100644
--- a/src/fr-marshal.list
+++ b/src/fr-marshal.list
@@ -1,9 +1,10 @@
 VOID:INT
 VOID:INT,INT
-VOID:INT,POINTER
+VOID:INT,BOXED
 VOID:POINTER
 VOID:VOID
 VOID:DOUBLE
 VOID:DOUBLE,STRING
 VOID:STRING
 VOID:BOOL
+VOID:BOXED
diff --git a/src/fr-proc-error.c b/src/fr-proc-error.c
new file mode 100644
index 0000000..1f61613
--- /dev/null
+++ b/src/fr-proc-error.c
@@ -0,0 +1,55 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  File-Roller
+ *
+ *  Copyright (C) 2001 The Free Software Foundation, Inc.
+ *
+ *  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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include "fr-proc-error.h"
+
+
+static gpointer
+fr_proc_error_copy (gpointer boxed)
+{
+	FrProcError *old_error = boxed;
+	FrProcError *new_error;
+
+	new_error = g_new (FrProcError, 1);
+	new_error->type = old_error->type;
+	new_error->status = old_error->status;
+	new_error->gerror = (old_error->gerror != NULL) ? g_error_copy (old_error->gerror) : NULL;
+
+	return new_error;
+}
+
+
+static void
+fr_proc_error_free (gpointer boxed)
+{
+	FrProcError *error = boxed;
+
+	if (error->gerror != NULL)
+		g_error_free (error->gerror);
+	g_free (error);
+}
+
+
+G_DEFINE_BOXED_TYPE (FrProcError,
+		     fr_proc_error,
+		     fr_proc_error_copy,
+		     fr_proc_error_free)
diff --git a/src/fr-proc-error.h b/src/fr-proc-error.h
new file mode 100644
index 0000000..d7e4924
--- /dev/null
+++ b/src/fr-proc-error.h
@@ -0,0 +1,31 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  File-Roller
+ *
+ *  Copyright (C) 2001 The Free Software Foundation, Inc.
+ *
+ *  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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef FR_PROC_ERROR_H
+#define FR_PROC_ERROR_H
+
+#include "typedefs.h"
+
+#define FR_TYPE_PROC_ERROR (fr_proc_error_get_type ())
+
+GType fr_proc_error_get_type (void);
+
+#endif /* FR_PROC_ERROR_H */
diff --git a/src/fr-process.c b/src/fr-process.c
index 20671e7..193db6a 100644
--- a/src/fr-process.c
+++ b/src/fr-process.c
@@ -29,6 +29,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <glib.h>
+#include "fr-proc-error.h"
 #include "fr-process.h"
 #include "fr-marshal.h"
 #include "glib-utils.h"
@@ -275,8 +276,9 @@ fr_process_class_init (FrProcessClass *class)
 			      G_SIGNAL_RUN_LAST,
 			      G_STRUCT_OFFSET (FrProcessClass, done),
 			      NULL, NULL,
-			      fr_marshal_VOID__VOID,
-			      G_TYPE_NONE, 0);
+			      fr_marshal_VOID__BOXED,
+			      G_TYPE_NONE, 1,
+			      FR_TYPE_PROC_ERROR);
 	fr_process_signals[STICKY_ONLY] =
 		g_signal_new ("sticky_only",
 			      G_TYPE_FROM_CLASS (class),
@@ -719,7 +721,8 @@ start_current_command (FrProcess *process)
 		process->error.type = FR_PROC_ERROR_SPAWN;
 		g_signal_emit (G_OBJECT (process),
 			       fr_process_signals[DONE],
-			       0);
+			       0,
+			       &process->error);
 		g_free (argv);
 		return;
 	}
@@ -932,7 +935,8 @@ check_child (gpointer data)
 
 	g_signal_emit (G_OBJECT (process),
 		       fr_process_signals[DONE],
-		       0);
+		       0,
+		       &process->error);
 
 	return FALSE;
 }
@@ -975,7 +979,8 @@ fr_process_start (FrProcess *process)
 		process->priv->running = FALSE;
 		g_signal_emit (G_OBJECT (process),
 			       fr_process_signals[DONE],
-			       0);
+			       0,
+			       &process->error);
 	}
 	else {
 		process->priv->running = TRUE;
@@ -1020,7 +1025,8 @@ fr_process_stop_priv (FrProcess *process,
 		if (emit_signal)
 			g_signal_emit (G_OBJECT (process),
 				       fr_process_signals[DONE],
-				       0);
+				       0,
+				       &process->error);
 	}
 }
 
diff --git a/src/fr-process.h b/src/fr-process.h
index 65c3bee..857a74a 100644
--- a/src/fr-process.h
+++ b/src/fr-process.h
@@ -80,7 +80,8 @@ struct _FrProcessClass {
 	/* -- Signals -- */
 
 	void (* start)         (FrProcess   *fr_proc);
-	void (* done)          (FrProcess   *fr_proc);
+	void (* done)          (FrProcess   *fr_proc,
+				FrProcError *error);
 	void (* sticky_only)   (FrProcess   *fr_proc);
 };
 



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