3
* Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
35
#include <thunar-vfs/thunar-vfs-interactive-job.h>
36
#include <thunar-vfs/thunar-vfs-private.h>
37
#include <thunar-vfs/thunar-vfs-simple-job.h>
38
#include <thunar-vfs/thunar-vfs-alias.h>
40
#include <gobject/gvaluecollector.h>
44
static void thunar_vfs_simple_job_class_init (ThunarVfsSimpleJobClass *klass);
45
static void thunar_vfs_simple_job_finalize (GObject *object);
46
static void thunar_vfs_simple_job_execute (ThunarVfsJob *job);
50
struct _ThunarVfsSimpleJobClass
52
ThunarVfsInteractiveJobClass __parent__;
55
struct _ThunarVfsSimpleJob
57
ThunarVfsInteractiveJob __parent__;
58
ThunarVfsSimpleJobFunc func;
65
static GObjectClass *thunar_vfs_simple_job_parent_class;
70
thunar_vfs_simple_job_get_type (void)
72
static GType type = G_TYPE_INVALID;
74
if (G_UNLIKELY (type == G_TYPE_INVALID))
76
type = _thunar_vfs_g_type_register_simple (THUNAR_VFS_TYPE_INTERACTIVE_JOB,
78
sizeof (ThunarVfsSimpleJobClass),
79
thunar_vfs_simple_job_class_init,
80
sizeof (ThunarVfsSimpleJob),
90
thunar_vfs_simple_job_class_init (ThunarVfsSimpleJobClass *klass)
92
ThunarVfsJobClass *thunarvfs_job_class;
93
GObjectClass *gobject_class;
95
/* determine the parent type class */
96
thunar_vfs_simple_job_parent_class = g_type_class_peek_parent (klass);
98
gobject_class = G_OBJECT_CLASS (klass);
99
gobject_class->finalize = thunar_vfs_simple_job_finalize;
101
thunarvfs_job_class = THUNAR_VFS_JOB_CLASS (klass);
102
thunarvfs_job_class->execute = thunar_vfs_simple_job_execute;
108
thunar_vfs_simple_job_finalize (GObject *object)
110
ThunarVfsSimpleJob *simple_job = THUNAR_VFS_SIMPLE_JOB (object);
112
/* release the param values */
113
_thunar_vfs_g_value_array_free (simple_job->param_values, simple_job->n_param_values);
115
(*G_OBJECT_CLASS (thunar_vfs_simple_job_parent_class)->finalize) (object);
121
thunar_vfs_simple_job_execute (ThunarVfsJob *job)
123
ThunarVfsSimpleJob *simple_job = THUNAR_VFS_SIMPLE_JOB (job);
124
GError *error = NULL;
126
/* try to execute the job using the supplied function */
127
if (!(*simple_job->func) (job, simple_job->param_values, simple_job->n_param_values, &error))
129
/* forward the error to the client */
130
_thunar_vfs_job_error (job, error);
131
g_error_free (error);
138
* thunar_vfs_simple_job_launch:
139
* @func : the #ThunarVfsSimpleJobFunc to execute the job.
140
* @n_param_values : the number of parameters to pass to the @func.
141
* @... : a list of #GType and parameter pairs (exactly
142
* @n_param_values pairs) that are passed to @func.
144
* Allocates a new #ThunarVfsSimpleJob, which executes the specified
145
* @func with the specified parameters.
147
* For example the listdir @func expects a #ThunarVfsPath for the
148
* folder to list, so the call to thunar_vfs_simple_job_launch()
149
* would look like this:
151
* <informalexample><programlisting>
152
* thunar_vfs_simple_job_launch (_thunar_vfs_io_jobs_listdir, 1,
153
* THUNAR_VFS_TYPE_PATH, path);
154
* </programlisting></informalexample>
156
* The caller is responsible to release the returned object using
157
* thunar_vfs_job_unref() when no longer needed.
159
* Return value: the launched #ThunarVfsJob.
162
thunar_vfs_simple_job_launch (ThunarVfsSimpleJobFunc func,
163
guint n_param_values,
166
ThunarVfsSimpleJob *simple_job;
169
gchar *error_message;
171
/* allocate and initialize the simple job */
172
simple_job = g_object_new (THUNAR_VFS_TYPE_SIMPLE_JOB, NULL);
173
simple_job->func = func;
174
simple_job->param_values = g_new0 (GValue, n_param_values);
175
simple_job->n_param_values = n_param_values;
177
/* collect the parameters */
178
va_start (var_args, n_param_values);
179
for (value = simple_job->param_values; value < simple_job->param_values + n_param_values; ++value)
181
/* initialize the value to hold the next parameter */
182
g_value_init (value, va_arg (var_args, GType));
184
/* collect the value from the stack */
185
G_VALUE_COLLECT (value, var_args, 0, &error_message);
187
/* check if an error occurred */
188
if (G_UNLIKELY (error_message != NULL))
190
g_error ("%s: %s", G_STRLOC, error_message);
191
g_free (error_message);
197
return thunar_vfs_job_launch (THUNAR_VFS_JOB (simple_job));
202
#define __THUNAR_VFS_SIMPLE_JOB_C__
203
#include <thunar-vfs/thunar-vfs-aliasdef.c>