~ubuntu-branches/debian/experimental/thunar/experimental

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2006-01-02 23:42:32 UTC
  • Revision ID: james.westby@ubuntu.com-20060102234232-8xeq0lqhyn70syr0
Tags: upstream-0.1.4svn+r18850
ImportĀ upstreamĀ versionĀ 0.1.4svn+r18850

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: thunar-vfs.c 18843 2005-11-14 14:25:58Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2005 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
#include <thunar-vfs/thunar-vfs.h>
 
26
#include <thunar-vfs/thunar-vfs-link-job.h>
 
27
#include <thunar-vfs/thunar-vfs-listdir-job.h>
 
28
#include <thunar-vfs/thunar-vfs-mkdir-job.h>
 
29
#include <thunar-vfs/thunar-vfs-transfer-job.h>
 
30
#include <thunar-vfs/thunar-vfs-unlink-job.h>
 
31
#include <thunar-vfs/thunar-vfs-xfer.h>
 
32
#include <thunar-vfs/thunar-vfs-alias.h>
 
33
 
 
34
 
 
35
 
 
36
static gint thunar_vfs_ref_count = 0;
 
37
 
 
38
 
 
39
 
 
40
/**
 
41
 * thunar_vfs_init:
 
42
 *
 
43
 * Initializes the ThunarVFS library.
 
44
 **/
 
45
void
 
46
thunar_vfs_init (void)
 
47
{
 
48
  if (g_atomic_int_exchange_and_add (&thunar_vfs_ref_count, 1) == 0)
 
49
    {
 
50
      /* initialize the path module */
 
51
      _thunar_vfs_path_init ();
 
52
 
 
53
      /* initialize the xfer module */
 
54
      _thunar_vfs_xfer_init ();
 
55
 
 
56
      /* initialize the info module */
 
57
      _thunar_vfs_info_init ();
 
58
 
 
59
      /* initialize the jobs framework */
 
60
      _thunar_vfs_job_init ();
 
61
    }
 
62
}
 
63
 
 
64
 
 
65
 
 
66
/**
 
67
 * thunar_vfs_shutdown:
 
68
 *
 
69
 * Shuts down the ThunarVFS library.
 
70
 **/
 
71
void
 
72
thunar_vfs_shutdown (void)
 
73
{
 
74
  if (g_atomic_int_dec_and_test (&thunar_vfs_ref_count))
 
75
    {
 
76
      /* shutdown the jobs framework */
 
77
      _thunar_vfs_job_shutdown ();
 
78
 
 
79
      /* release the info module */
 
80
      _thunar_vfs_info_shutdown ();
 
81
 
 
82
      /* shutdown the xfer module */
 
83
      _thunar_vfs_xfer_shutdown ();
 
84
 
 
85
      /* shutdown the path module */
 
86
      _thunar_vfs_path_shutdown ();
 
87
    }
 
88
}
 
89
 
 
90
 
 
91
 
 
92
/**
 
93
 * thunar_vfs_listdir:
 
94
 * @path  : the #ThunarVfsPath for the folder that should be listed.
 
95
 * @error : return location for errors or %NULL.
 
96
 *
 
97
 * Generates a #ThunarVfsListdirJob, which can be used to list the
 
98
 * contents of a directory (as specified by @path). If the creation
 
99
 * of the job failes for some reason, %NULL will be returned and
 
100
 * @error will be set to point to a #GError describing the cause.
 
101
 * Else the newly allocated #ThunarVfsListdirJob will be returned
 
102
 * and the caller is responsible to call g_object_unref().
 
103
 *
 
104
 * Note, that the returned job is launched right away, so you
 
105
 * don't need to call thunar_vfs_job_launch() on it.
 
106
 *
 
107
 * Return value: the newly allocated #ThunarVfsListdirJob or %NULL
 
108
 *               if an error occurs while creating the job.
 
109
 **/
 
110
ThunarVfsJob*
 
111
thunar_vfs_listdir (ThunarVfsPath *path,
 
112
                    GError       **error)
 
113
{
 
114
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
115
 
 
116
  /* allocate the job */
 
117
  return thunar_vfs_job_launch (thunar_vfs_listdir_job_new (path));
 
118
}
 
119
 
 
120
 
 
121
 
 
122
/**
 
123
 * thunar_vfs_copy_file:
 
124
 * @source_path : the source #ThunarVfsPath.
 
125
 * @target_path : the target #ThunarVfsPath.
 
126
 * @error       : return location for errors or %NULL.
 
127
 *
 
128
 * Allocates a new #ThunarVfsTransferJob, which copies the file
 
129
 * from @source_path to @target_path. That said, the file or directory
 
130
 * located at @source_path will be placed at @target_path, NOT INTO
 
131
 * @target_path.
 
132
 *
 
133
 * The caller is responsible to free the returned job using
 
134
 * g_object_unref() when no longer needed.
 
135
 *
 
136
 * Note, that the returned job is launched right away, so you don't
 
137
 * need to call thunar_vfs_job_launch() on it.
 
138
 *
 
139
 * Return value: the newly allocated #ThunarVfsTransferJob or %NULL
 
140
 *               if an error occurs while creating the job.
 
141
 **/
 
142
ThunarVfsJob*
 
143
thunar_vfs_copy_file (ThunarVfsPath *source_path,
 
144
                      ThunarVfsPath *target_path,
 
145
                      GError       **error)
 
146
{
 
147
  GList source_path_list;
 
148
  GList target_path_list;
 
149
 
 
150
  g_return_val_if_fail (source_path != NULL, NULL);
 
151
  g_return_val_if_fail (target_path != NULL, NULL);
 
152
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
153
 
 
154
  /* fake a source path list */
 
155
  source_path_list.data = source_path;
 
156
  source_path_list.next = NULL;
 
157
  source_path_list.prev = NULL;
 
158
 
 
159
  /* fake a target path list */
 
160
  target_path_list.data = target_path;
 
161
  target_path_list.next = NULL;
 
162
  target_path_list.prev = NULL;
 
163
 
 
164
  /* allocate the job */
 
165
  return thunar_vfs_copy_files (&source_path_list, &target_path_list, error);
 
166
}
 
167
 
 
168
 
 
169
 
 
170
/**
 
171
 * thunar_vfs_copy_files:
 
172
 * @source_path_list : the list of #ThunarVfsPath<!---->s that should be copied.
 
173
 * @target_path_list : the list of #ThunarVfsPath<!---->s for the targets.
 
174
 * @error            : return location for errors or %NULL.
 
175
 *
 
176
 * Similar to thunar_vfs_copy_file(), but takes a bunch of files. The
 
177
 * @source_path_list and @target_path_list must be of the same size.
 
178
 *
 
179
 * Note, that the returned job is launched right away, so you don't
 
180
 * need to call thunar_vfs_job_launch() on it. The caller is responsible
 
181
 * to free the returned object using g_object_unref() when no longer
 
182
 * needed.
 
183
 *
 
184
 * Return value: the newly allocated #ThunarVfsTransferJob or %NULL
 
185
 *               if an error occurs while creating the job.
 
186
 **/
 
187
ThunarVfsJob*
 
188
thunar_vfs_copy_files (GList   *source_path_list,
 
189
                       GList   *target_path_list,
 
190
                       GError **error)
 
191
{
 
192
  ThunarVfsJob *job;
 
193
 
 
194
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
195
 
 
196
  /* allocate/launch the job */
 
197
  job = thunar_vfs_transfer_job_new (source_path_list, target_path_list, FALSE, error);
 
198
  if (G_LIKELY (job != NULL))
 
199
    thunar_vfs_job_launch (job);
 
200
 
 
201
  return job;
 
202
}
 
203
 
 
204
 
 
205
 
 
206
/**
 
207
 * thunar_vfs_link_file:
 
208
 * @source_path : the source #ThunarVfsPath.
 
209
 * @target_path : the target #ThunarVfsPath.
 
210
 * @error       : return location for errors or %NULL.
 
211
 *
 
212
 * Allocates a new #ThunarVfsLinkJob, which creates a symbolic
 
213
 * link from @source_path to @target_path.
 
214
 *
 
215
 * If @source_path and @target_path refer to the same file,
 
216
 * a new unique target filename will be choosen automatically.
 
217
 *
 
218
 * The caller is responsible to free the returned job using
 
219
 * g_object_unref() when no longer needed.
 
220
 *
 
221
 * Note, that the returned job is launched right away, so you don't
 
222
 * need to call thunar_vfs_job_launch() on it.
 
223
 *
 
224
 * Return value: the newly allocated #ThunarVfsLinkJob or %NULL
 
225
 *               if an error occurs while creating the job.
 
226
 **/
 
227
ThunarVfsJob*
 
228
thunar_vfs_link_file (ThunarVfsPath *source_path,
 
229
                      ThunarVfsPath *target_path,
 
230
                      GError       **error)
 
231
{
 
232
  GList source_path_list;
 
233
  GList target_path_list;
 
234
 
 
235
  g_return_val_if_fail (!thunar_vfs_path_is_root (source_path), NULL);
 
236
  g_return_val_if_fail (!thunar_vfs_path_is_root (target_path), NULL);
 
237
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
238
 
 
239
  /* fake a source path list */
 
240
  source_path_list.data = source_path;
 
241
  source_path_list.next = NULL;
 
242
  source_path_list.prev = NULL;
 
243
 
 
244
  /* fake a target path list */
 
245
  target_path_list.data = target_path;
 
246
  target_path_list.next = NULL;
 
247
  target_path_list.prev = NULL;
 
248
 
 
249
  return thunar_vfs_link_files (&source_path_list, &target_path_list, error);
 
250
}
 
251
 
 
252
 
 
253
 
 
254
/**
 
255
 * thunar_vfs_link_files:
 
256
 * @source_path_list : list of #ThunarVfsPath<!---->s to the source files.
 
257
 * @target_path_list : list of #ThunarVfsPath<!---->s to the target files.
 
258
 * @error            : return location for errors or %NULL.
 
259
 *
 
260
 * Like thunar_vfs_link_file(), but works on path lists, rather than
 
261
 * a single path.
 
262
 *
 
263
 * The caller is responsible to free the returned job using
 
264
 * g_object_unref() when no longer needed.
 
265
 *
 
266
 * Note, that the returned job is launched right away, so you don't
 
267
 * need to call thunar_vfs_job_launch() on it.
 
268
 *
 
269
 * Return value: the newly allocated #ThunarVfsLinkJob or %NULL
 
270
 *               if an error occurs while creating the job.
 
271
 **/
 
272
ThunarVfsJob*
 
273
thunar_vfs_link_files (GList   *source_path_list,
 
274
                       GList   *target_path_list,
 
275
                       GError **error)
 
276
{
 
277
  ThunarVfsJob *job;
 
278
 
 
279
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
280
 
 
281
  /* allocate/launch the job */
 
282
  job = thunar_vfs_link_job_new (source_path_list, target_path_list, error);
 
283
  if (G_LIKELY (job != NULL))
 
284
    thunar_vfs_job_launch (job);
 
285
 
 
286
  return job;
 
287
}
 
288
 
 
289
 
 
290
 
 
291
/**
 
292
 * thunar_vfs_move_file:
 
293
 * @source_path : the source #ThunarVfsPath.
 
294
 * @target_path : the target #ThunarVfsPath.
 
295
 * @error       : return location for errors or %NULL.
 
296
 *
 
297
 * Allocates a new #ThunarVfsTransferJob, which moves the file
 
298
 * from @source_path to @target_path. That said, the file or directory
 
299
 * located at @source_path will be placed at @target_path, NOT INTO
 
300
 * @target_path.
 
301
 *
 
302
 * The caller is responsible to free the returned job using
 
303
 * g_object_unref() when no longer needed.
 
304
 *
 
305
 * Note, that the returned job is launched right away, so you don't
 
306
 * need to call thunar_vfs_job_launch() on it.
 
307
 *
 
308
 * Return value: the newly allocated #ThunarVfsTransferJob or %NULL
 
309
 *               if an error occurs while creating the job.
 
310
 **/
 
311
ThunarVfsJob*
 
312
thunar_vfs_move_file (ThunarVfsPath *source_path,
 
313
                      ThunarVfsPath *target_path,
 
314
                      GError       **error)
 
315
{
 
316
  GList source_path_list;
 
317
  GList target_path_list;
 
318
 
 
319
  g_return_val_if_fail (source_path != NULL, NULL);
 
320
  g_return_val_if_fail (target_path != NULL, NULL);
 
321
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
322
 
 
323
  /* fake a source path list */
 
324
  source_path_list.data = source_path;
 
325
  source_path_list.next = NULL;
 
326
  source_path_list.prev = NULL;
 
327
 
 
328
  /* fake a target path list */
 
329
  target_path_list.data = target_path;
 
330
  target_path_list.next = NULL;
 
331
  target_path_list.prev = NULL;
 
332
 
 
333
  /* allocate and launch the job */
 
334
  return thunar_vfs_move_files (&source_path_list, &target_path_list, error);
 
335
}
 
336
 
 
337
 
 
338
 
 
339
/**
 
340
 * thunar_vfs_move_into:
 
341
 * @source_path_list : the list of #ThunarVfsPath<!---->s that should be moved.
 
342
 * @target_path_list : the list of #ThunarVfsPath<!---->s to the targets.
 
343
 * @error            : return location for errors or %NULL.
 
344
 *
 
345
 * Similar to thunar_vfs_move_file(), but takes a bunch of files. The
 
346
 * @source_path_list and @target_path_list must be of the same size.
 
347
 *
 
348
 * Note, that the returned job is launched right away, so you don't
 
349
 * need to call thunar_vfs_job_launch() on it. The caller is responsible
 
350
 * to free the returned object using g_object_unref() when no longer
 
351
 * needed.
 
352
 *
 
353
 * Return value: the newly allocated #ThunarVfsTransferJob or %NULL
 
354
 *               if an error occurs while creating the job.
 
355
 **/
 
356
ThunarVfsJob*
 
357
thunar_vfs_move_files (GList   *source_path_list,
 
358
                       GList   *target_path_list,
 
359
                       GError **error)
 
360
{
 
361
  ThunarVfsJob *job;
 
362
 
 
363
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
364
 
 
365
  /* allocate/launch the job */
 
366
  job = thunar_vfs_transfer_job_new (source_path_list, target_path_list, TRUE, error);
 
367
  if (G_LIKELY (job != NULL))
 
368
    thunar_vfs_job_launch (job);
 
369
 
 
370
  return job;
 
371
}
 
372
 
 
373
 
 
374
 
 
375
/**
 
376
 * thunar_vfs_unlink_file:
 
377
 * @path  : a #ThunarVfsPath, that should be unlinked.
 
378
 * @error : return location for errors or %NULL.
 
379
 *
 
380
 * Simple wrapper to thunar_vfs_unlink_files(), which takes
 
381
 * only a single path.
 
382
 *
 
383
 * Note, that the returned job is launched right away, so you
 
384
 * don't need to call thunar_vfs_job_launch() on it. The caller
 
385
 * is responsible to free the returned object using g_object_unref()
 
386
 * when no longer needed.
 
387
 *
 
388
 * Return value: the newly allocated #ThunarVfsUnlinkJob or %NULL
 
389
 *               if an error occurs while creating the job.
 
390
 **/
 
391
ThunarVfsJob*
 
392
thunar_vfs_unlink_file (ThunarVfsPath *path,
 
393
                        GError       **error)
 
394
{
 
395
  GList path_list;
 
396
 
 
397
  g_return_val_if_fail (path != NULL, NULL);
 
398
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
399
 
 
400
  /* fake a path list */
 
401
  path_list.data = path;
 
402
  path_list.next = NULL;
 
403
  path_list.prev = NULL;
 
404
 
 
405
  /* allocate and launch the job */
 
406
  return thunar_vfs_unlink_files (&path_list, error);
 
407
}
 
408
 
 
409
 
 
410
 
 
411
/**
 
412
 * thunar_vfs_unlink_files:
 
413
 * @path_list : a list of #ThunarVfsPath<!---->s, that should be unlinked.
 
414
 * @error     : return location for errors or %NULL.
 
415
 *
 
416
 * Generates a #ThunarVfsInteractiveJob, which can be used to unlink
 
417
 * all files referenced by the @path_list. If the creation of the job
 
418
 * failes for some reason, %NULL will be returned and @error will
 
419
 * be set to point to a #GError describing the cause. Else, the
 
420
 * newly allocated #ThunarVfsUnlinkJob will be returned, and the
 
421
 * caller is responsible to call g_object_unref().
 
422
 *
 
423
 * Note, that the returned job is launched right away, so you
 
424
 * don't need to call thunar_vfs_job_launch() on it.
 
425
 *
 
426
 * Return value: the newly allocated #ThunarVfsUnlinkJob or %NULL
 
427
 *               if an error occurs while creating the job.
 
428
 **/
 
429
ThunarVfsJob*
 
430
thunar_vfs_unlink_files (GList   *path_list,
 
431
                         GError **error)
 
432
{
 
433
  ThunarVfsJob *job;
 
434
 
 
435
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
436
 
 
437
  /* try to allocate the job */
 
438
  job = thunar_vfs_unlink_job_new (path_list, error);
 
439
  if (G_LIKELY (job != NULL))
 
440
    thunar_vfs_job_launch (job);
 
441
 
 
442
  return job;
 
443
}
 
444
 
 
445
 
 
446
 
 
447
/**
 
448
 * thunar_vfs_make_directory:
 
449
 * @path  : the #ThunarVfsPath to the directory to create.
 
450
 * @error : return location for errors or %NULL.
 
451
 *
 
452
 * Generates a #ThunarVfsMkdirJob, which can be used to
 
453
 * asynchronously create a new directory at the given @path. If
 
454
 * the creation of the job fails for some reason, %NULL will be
 
455
 * returned and @error will be set to point to a #GError
 
456
 * describing the cause of the problem. Else the newly allocated
 
457
 * #ThunarVfsMkdirJob will be returned, and the caller is responsible
 
458
 * to call g_object_unref().
 
459
 *
 
460
 * Note, that the returned job is launched right away, so you
 
461
 * don't need to call thunar_vfs_job_launch() on it.
 
462
 *
 
463
 * Return value: the newly allocated #ThunarVfsMkdirJob or %NULL
 
464
 *               if an error occurs while creating the job.
 
465
 **/
 
466
ThunarVfsJob*
 
467
thunar_vfs_make_directory (ThunarVfsPath *path,
 
468
                           GError       **error)
 
469
{
 
470
  GList path_list;
 
471
 
 
472
  g_return_val_if_fail (path != NULL, NULL);
 
473
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
474
 
 
475
  /* fake a path list */
 
476
  path_list.data = path;
 
477
  path_list.next = NULL;
 
478
  path_list.prev = NULL;
 
479
 
 
480
  /* allocate and launch the job */
 
481
  return thunar_vfs_make_directories (&path_list, error);
 
482
}
 
483
 
 
484
 
 
485
 
 
486
/**
 
487
 * thunar_vfs_make_directories:
 
488
 * @path_list : a list of #ThunarVfsPath<!--->s that contain the paths
 
489
 *              to the directories which should be created.
 
490
 * @error     : return location for errors or %NULL.
 
491
 *
 
492
 * Similar to thunar_vfs_make_directory(), but allows the creation
 
493
 * of multiple directories using a single #ThunarVfsJob.
 
494
 *
 
495
 * The caller is responsible to free the returned job using
 
496
 * g_object_unref() when no longer needed.
 
497
 *
 
498
 * Note, that the returned job is launched right away, so you don't
 
499
 * need to call thunar_vfs_job_launch() on it.
 
500
 *
 
501
 * Return value: the newly allocated #ThunarVfsMkdirJob or %NULL
 
502
 *               if an error occurs while creating the job.
 
503
 **/
 
504
ThunarVfsJob*
 
505
thunar_vfs_make_directories (GList   *path_list,
 
506
                             GError **error)
 
507
{
 
508
  ThunarVfsJob *job;
 
509
 
 
510
  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
 
511
 
 
512
  /* allocate and launch the new job */
 
513
  job = thunar_vfs_mkdir_job_new (path_list, error);
 
514
  if (G_LIKELY (job != NULL))
 
515
    thunar_vfs_job_launch (job);
 
516
 
 
517
  return job;
 
518
}
 
519
 
 
520
 
 
521
 
 
522
#define __THUNAR_VFS_C__
 
523
#include <thunar-vfs/thunar-vfs-aliasdef.c>