1
/* $Id: thunar-vfs.c 18843 2005-11-14 14:25:58Z benny $ */
3
* Copyright (c) 2005 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.
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>
36
static gint thunar_vfs_ref_count = 0;
43
* Initializes the ThunarVFS library.
46
thunar_vfs_init (void)
48
if (g_atomic_int_exchange_and_add (&thunar_vfs_ref_count, 1) == 0)
50
/* initialize the path module */
51
_thunar_vfs_path_init ();
53
/* initialize the xfer module */
54
_thunar_vfs_xfer_init ();
56
/* initialize the info module */
57
_thunar_vfs_info_init ();
59
/* initialize the jobs framework */
60
_thunar_vfs_job_init ();
67
* thunar_vfs_shutdown:
69
* Shuts down the ThunarVFS library.
72
thunar_vfs_shutdown (void)
74
if (g_atomic_int_dec_and_test (&thunar_vfs_ref_count))
76
/* shutdown the jobs framework */
77
_thunar_vfs_job_shutdown ();
79
/* release the info module */
80
_thunar_vfs_info_shutdown ();
82
/* shutdown the xfer module */
83
_thunar_vfs_xfer_shutdown ();
85
/* shutdown the path module */
86
_thunar_vfs_path_shutdown ();
94
* @path : the #ThunarVfsPath for the folder that should be listed.
95
* @error : return location for errors or %NULL.
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().
104
* Note, that the returned job is launched right away, so you
105
* don't need to call thunar_vfs_job_launch() on it.
107
* Return value: the newly allocated #ThunarVfsListdirJob or %NULL
108
* if an error occurs while creating the job.
111
thunar_vfs_listdir (ThunarVfsPath *path,
114
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
116
/* allocate the job */
117
return thunar_vfs_job_launch (thunar_vfs_listdir_job_new (path));
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.
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
133
* The caller is responsible to free the returned job using
134
* g_object_unref() when no longer needed.
136
* Note, that the returned job is launched right away, so you don't
137
* need to call thunar_vfs_job_launch() on it.
139
* Return value: the newly allocated #ThunarVfsTransferJob or %NULL
140
* if an error occurs while creating the job.
143
thunar_vfs_copy_file (ThunarVfsPath *source_path,
144
ThunarVfsPath *target_path,
147
GList source_path_list;
148
GList target_path_list;
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);
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;
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;
164
/* allocate the job */
165
return thunar_vfs_copy_files (&source_path_list, &target_path_list, error);
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.
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.
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
184
* Return value: the newly allocated #ThunarVfsTransferJob or %NULL
185
* if an error occurs while creating the job.
188
thunar_vfs_copy_files (GList *source_path_list,
189
GList *target_path_list,
194
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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);
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.
212
* Allocates a new #ThunarVfsLinkJob, which creates a symbolic
213
* link from @source_path to @target_path.
215
* If @source_path and @target_path refer to the same file,
216
* a new unique target filename will be choosen automatically.
218
* The caller is responsible to free the returned job using
219
* g_object_unref() when no longer needed.
221
* Note, that the returned job is launched right away, so you don't
222
* need to call thunar_vfs_job_launch() on it.
224
* Return value: the newly allocated #ThunarVfsLinkJob or %NULL
225
* if an error occurs while creating the job.
228
thunar_vfs_link_file (ThunarVfsPath *source_path,
229
ThunarVfsPath *target_path,
232
GList source_path_list;
233
GList target_path_list;
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);
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;
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;
249
return thunar_vfs_link_files (&source_path_list, &target_path_list, error);
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.
260
* Like thunar_vfs_link_file(), but works on path lists, rather than
263
* The caller is responsible to free the returned job using
264
* g_object_unref() when no longer needed.
266
* Note, that the returned job is launched right away, so you don't
267
* need to call thunar_vfs_job_launch() on it.
269
* Return value: the newly allocated #ThunarVfsLinkJob or %NULL
270
* if an error occurs while creating the job.
273
thunar_vfs_link_files (GList *source_path_list,
274
GList *target_path_list,
279
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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);
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.
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
302
* The caller is responsible to free the returned job using
303
* g_object_unref() when no longer needed.
305
* Note, that the returned job is launched right away, so you don't
306
* need to call thunar_vfs_job_launch() on it.
308
* Return value: the newly allocated #ThunarVfsTransferJob or %NULL
309
* if an error occurs while creating the job.
312
thunar_vfs_move_file (ThunarVfsPath *source_path,
313
ThunarVfsPath *target_path,
316
GList source_path_list;
317
GList target_path_list;
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);
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;
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;
333
/* allocate and launch the job */
334
return thunar_vfs_move_files (&source_path_list, &target_path_list, error);
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.
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.
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
353
* Return value: the newly allocated #ThunarVfsTransferJob or %NULL
354
* if an error occurs while creating the job.
357
thunar_vfs_move_files (GList *source_path_list,
358
GList *target_path_list,
363
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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);
376
* thunar_vfs_unlink_file:
377
* @path : a #ThunarVfsPath, that should be unlinked.
378
* @error : return location for errors or %NULL.
380
* Simple wrapper to thunar_vfs_unlink_files(), which takes
381
* only a single path.
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.
388
* Return value: the newly allocated #ThunarVfsUnlinkJob or %NULL
389
* if an error occurs while creating the job.
392
thunar_vfs_unlink_file (ThunarVfsPath *path,
397
g_return_val_if_fail (path != NULL, NULL);
398
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
400
/* fake a path list */
401
path_list.data = path;
402
path_list.next = NULL;
403
path_list.prev = NULL;
405
/* allocate and launch the job */
406
return thunar_vfs_unlink_files (&path_list, error);
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.
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().
423
* Note, that the returned job is launched right away, so you
424
* don't need to call thunar_vfs_job_launch() on it.
426
* Return value: the newly allocated #ThunarVfsUnlinkJob or %NULL
427
* if an error occurs while creating the job.
430
thunar_vfs_unlink_files (GList *path_list,
435
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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);
448
* thunar_vfs_make_directory:
449
* @path : the #ThunarVfsPath to the directory to create.
450
* @error : return location for errors or %NULL.
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().
460
* Note, that the returned job is launched right away, so you
461
* don't need to call thunar_vfs_job_launch() on it.
463
* Return value: the newly allocated #ThunarVfsMkdirJob or %NULL
464
* if an error occurs while creating the job.
467
thunar_vfs_make_directory (ThunarVfsPath *path,
472
g_return_val_if_fail (path != NULL, NULL);
473
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
475
/* fake a path list */
476
path_list.data = path;
477
path_list.next = NULL;
478
path_list.prev = NULL;
480
/* allocate and launch the job */
481
return thunar_vfs_make_directories (&path_list, error);
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.
492
* Similar to thunar_vfs_make_directory(), but allows the creation
493
* of multiple directories using a single #ThunarVfsJob.
495
* The caller is responsible to free the returned job using
496
* g_object_unref() when no longer needed.
498
* Note, that the returned job is launched right away, so you don't
499
* need to call thunar_vfs_job_launch() on it.
501
* Return value: the newly allocated #ThunarVfsMkdirJob or %NULL
502
* if an error occurs while creating the job.
505
thunar_vfs_make_directories (GList *path_list,
510
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
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);
522
#define __THUNAR_VFS_C__
523
#include <thunar-vfs/thunar-vfs-aliasdef.c>