~noskcaj/ubuntu/vivid/thunar/1.6.4

« back to all changes in this revision

Viewing changes to thunar-vfs/thunar-vfs-simple-job.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-04 16:46:20 UTC
  • mto: (2.1.3 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: james.westby@ubuntu.com-20101204164620-h7p4t2e9z6hfhz6l
Tags: upstream-1.1.4
ImportĀ upstreamĀ versionĀ 1.1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id$ */
2
 
/*-
3
 
 * Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
19
 
 */
20
 
 
21
 
#ifdef HAVE_CONFIG_H
22
 
#include <config.h>
23
 
#endif
24
 
 
25
 
#ifdef HAVE_MEMORY_H
26
 
#include <memory.h>
27
 
#endif
28
 
#ifdef HAVE_STDARG_H
29
 
#include <stdarg.h>
30
 
#endif
31
 
#ifdef HAVE_STRING_H
32
 
#include <string.h>
33
 
#endif
34
 
 
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>
39
 
 
40
 
#include <gobject/gvaluecollector.h>
41
 
 
42
 
 
43
 
 
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);
47
 
 
48
 
 
49
 
 
50
 
struct _ThunarVfsSimpleJobClass
51
 
{
52
 
  ThunarVfsInteractiveJobClass __parent__;
53
 
};
54
 
 
55
 
struct _ThunarVfsSimpleJob
56
 
{
57
 
  ThunarVfsInteractiveJob __parent__;
58
 
  ThunarVfsSimpleJobFunc  func;
59
 
  GValue                 *param_values;
60
 
  guint                   n_param_values;
61
 
};
62
 
 
63
 
 
64
 
 
65
 
static GObjectClass *thunar_vfs_simple_job_parent_class;
66
 
 
67
 
 
68
 
 
69
 
GType
70
 
thunar_vfs_simple_job_get_type (void)
71
 
{
72
 
  static GType type = G_TYPE_INVALID;
73
 
 
74
 
  if (G_UNLIKELY (type == G_TYPE_INVALID))
75
 
    {
76
 
      type = _thunar_vfs_g_type_register_simple (THUNAR_VFS_TYPE_INTERACTIVE_JOB, 
77
 
                                                 "ThunarVfsSimpleJob",
78
 
                                                 sizeof (ThunarVfsSimpleJobClass),
79
 
                                                 thunar_vfs_simple_job_class_init,
80
 
                                                 sizeof (ThunarVfsSimpleJob),
81
 
                                                 NULL, 0);
82
 
    }
83
 
 
84
 
  return type;
85
 
}
86
 
 
87
 
 
88
 
 
89
 
static void
90
 
thunar_vfs_simple_job_class_init (ThunarVfsSimpleJobClass *klass)
91
 
{
92
 
  ThunarVfsJobClass *thunarvfs_job_class;
93
 
  GObjectClass      *gobject_class;
94
 
 
95
 
  /* determine the parent type class */
96
 
  thunar_vfs_simple_job_parent_class = g_type_class_peek_parent (klass);
97
 
 
98
 
  gobject_class = G_OBJECT_CLASS (klass);
99
 
  gobject_class->finalize = thunar_vfs_simple_job_finalize;
100
 
 
101
 
  thunarvfs_job_class = THUNAR_VFS_JOB_CLASS (klass);
102
 
  thunarvfs_job_class->execute = thunar_vfs_simple_job_execute;
103
 
}
104
 
 
105
 
 
106
 
 
107
 
static void
108
 
thunar_vfs_simple_job_finalize (GObject *object)
109
 
{
110
 
  ThunarVfsSimpleJob *simple_job = THUNAR_VFS_SIMPLE_JOB (object);
111
 
 
112
 
  /* release the param values */
113
 
  _thunar_vfs_g_value_array_free (simple_job->param_values, simple_job->n_param_values);
114
 
 
115
 
  (*G_OBJECT_CLASS (thunar_vfs_simple_job_parent_class)->finalize) (object);
116
 
}
117
 
 
118
 
 
119
 
 
120
 
static void
121
 
thunar_vfs_simple_job_execute (ThunarVfsJob *job)
122
 
{
123
 
  ThunarVfsSimpleJob *simple_job = THUNAR_VFS_SIMPLE_JOB (job);
124
 
  GError             *error = NULL;
125
 
 
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))
128
 
    {
129
 
      /* forward the error to the client */
130
 
      _thunar_vfs_job_error (job, error);
131
 
      g_error_free (error);
132
 
    }
133
 
}
134
 
 
135
 
 
136
 
 
137
 
/**
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.
143
 
 *
144
 
 * Allocates a new #ThunarVfsSimpleJob, which executes the specified
145
 
 * @func with the specified parameters.
146
 
 *
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:
150
 
 *
151
 
 * <informalexample><programlisting>
152
 
 * thunar_vfs_simple_job_launch (_thunar_vfs_io_jobs_listdir, 1,
153
 
 *                               THUNAR_VFS_TYPE_PATH, path);
154
 
 * </programlisting></informalexample>
155
 
 *
156
 
 * The caller is responsible to release the returned object using
157
 
 * thunar_vfs_job_unref() when no longer needed.
158
 
 *
159
 
 * Return value: the launched #ThunarVfsJob.
160
 
 **/
161
 
ThunarVfsJob*
162
 
thunar_vfs_simple_job_launch (ThunarVfsSimpleJobFunc func,
163
 
                              guint                  n_param_values,
164
 
                              ...)
165
 
{
166
 
  ThunarVfsSimpleJob *simple_job;
167
 
  va_list             var_args;
168
 
  GValue             *value;
169
 
  gchar              *error_message;
170
 
 
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;
176
 
 
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)
180
 
    {
181
 
      /* initialize the value to hold the next parameter */
182
 
      g_value_init (value, va_arg (var_args, GType));
183
 
 
184
 
      /* collect the value from the stack */
185
 
      G_VALUE_COLLECT (value, var_args, 0, &error_message);
186
 
 
187
 
      /* check if an error occurred */
188
 
      if (G_UNLIKELY (error_message != NULL))
189
 
        {
190
 
          g_error ("%s: %s", G_STRLOC, error_message);
191
 
          g_free (error_message);
192
 
        }
193
 
    }
194
 
  va_end (var_args);
195
 
 
196
 
  /* launch the job */
197
 
  return thunar_vfs_job_launch (THUNAR_VFS_JOB (simple_job));
198
 
}
199
 
 
200
 
 
201
 
 
202
 
#define __THUNAR_VFS_SIMPLE_JOB_C__
203
 
#include <thunar-vfs/thunar-vfs-aliasdef.c>