~ubuntu-branches/ubuntu/karmic/glib2.0/karmic-updates

« back to all changes in this revision

Viewing changes to gio/gfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-07 08:55:47 UTC
  • mfrom: (1.2.49 upstream)
  • Revision ID: james.westby@ubuntu.com-20090707085547-oma0yur1uaq4zmop
Tags: 2.21.3-0ubuntu1
* New upstream version:
  - GMappedFile is refcounted now
  - Mainloop: It is now possible to set per-thread default contexts,
    with g_main_context_push_thread_default.
  - glib-mkenums supports a @basename@ substitution, in addition
    to @filename@.
  - GIO:
    + Vfs implementations can support storing of per-file metadata.
    + GCancellable can now be subclassed.
    + Unmount and eject methods now optionally allow interaction, via
      variants that take a GMountOperation object.
  - Bugs fixed:
   556706 Inconsistent help arguments -h, -?
   579449 FileChoosers no longer work if an idle handler is active
   579933 mainloop FD_CLOEXEC has a race condition
   579984 alternate GMainContext support
   585937 gio/gsocket.c (glib 2.21.2) does not compile (Windows/mingw)
   586675 Runtime library location
   586797 Add GCancellables to GSocket ops
   586868 g_filename_complete_get_completions doesn't always return...
   587415 g_resolver_lookup_by_name_finish returns a freed list
   587434 regression tests fail, at least on x86_64
   586928 Avoid g++ warning in g_error()
  - Updated translations: Estonian, Hebrew
* Drop 00git_file_attr_stringv.patch, in upstream release now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
 * take a very long time to finish, and blocking may leave an application
110
110
 * unusable. Notable cases include:
111
111
 * g_file_mount_mountable() to mount a mountable file.
112
 
 * g_file_unmount_mountable() to unmount a mountable file.
113
 
 * g_file_eject_mountable() to eject a mountable file.
 
112
 * g_file_unmount_mountable_with_operation() to unmount a mountable file.
 
113
 * g_file_eject_mountable_with_operation() to eject a mountable file.
114
114
 * 
115
115
 * <para id="gfile-etag"><indexterm><primary>entity tag</primary></indexterm>
116
116
 * One notable feature of #GFile<!-- -->s are entity tags, or "etags" for 
2544
2544
                g_string_append_c (s, ',');
2545
2545
                
2546
2546
              g_string_append (s, namespaces->infos[i].name);
2547
 
              g_string_append (s, ":*");
 
2547
              g_string_append (s, "::*");
2548
2548
            }
2549
2549
        }
2550
2550
    }
4164
4164
 *
4165
4165
 * When the operation is finished, @callback will be called. You can then call
4166
4166
 * g_file_unmount_mountable_finish() to get the result of the operation.
 
4167
 *
 
4168
 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation() instead.
4167
4169
 **/
4168
4170
void
4169
4171
g_file_unmount_mountable (GFile               *file,
4209
4211
 *
4210
4212
 * Returns: %TRUE if the operation finished successfully. %FALSE
4211
4213
 * otherwise.
 
4214
 *
 
4215
 * Deprecated: 2.22: Use g_file_unmount_mountable_with_operation_finish() instead.
4212
4216
 **/
4213
4217
gboolean
4214
4218
g_file_unmount_mountable_finish (GFile         *file,
4232
4236
}
4233
4237
 
4234
4238
/**
 
4239
 * g_file_unmount_mountable_with_operation:
 
4240
 * @file: input #GFile.
 
4241
 * @flags: flags affecting the operation
 
4242
 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
 
4243
 * @cancellable: optional #GCancellable object, %NULL to ignore.
 
4244
 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
 
4245
 * @user_data: the data to pass to callback function
 
4246
 *
 
4247
 * Unmounts a file of type G_FILE_TYPE_MOUNTABLE.
 
4248
 *
 
4249
 * If @cancellable is not %NULL, then the operation can be cancelled by
 
4250
 * triggering the cancellable object from another thread. If the operation
 
4251
 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
 
4252
 *
 
4253
 * When the operation is finished, @callback will be called. You can then call
 
4254
 * g_file_unmount_mountable_finish() to get the result of the operation.
 
4255
 *
 
4256
 * Since: 2.22
 
4257
 **/
 
4258
void
 
4259
g_file_unmount_mountable_with_operation (GFile               *file,
 
4260
                                         GMountUnmountFlags   flags,
 
4261
                                         GMountOperation     *mount_operation,
 
4262
                                         GCancellable        *cancellable,
 
4263
                                         GAsyncReadyCallback  callback,
 
4264
                                         gpointer             user_data)
 
4265
{
 
4266
  GFileIface *iface;
 
4267
 
 
4268
  g_return_if_fail (G_IS_FILE (file));
 
4269
 
 
4270
  iface = G_FILE_GET_IFACE (file);
 
4271
 
 
4272
  if (iface->unmount_mountable == NULL && iface->unmount_mountable_with_operation == NULL)
 
4273
    {
 
4274
      g_simple_async_report_error_in_idle (G_OBJECT (file),
 
4275
                                           callback,
 
4276
                                           user_data,
 
4277
                                           G_IO_ERROR,
 
4278
                                           G_IO_ERROR_NOT_SUPPORTED,
 
4279
                                           _("Operation not supported"));
 
4280
      return;
 
4281
    }
 
4282
 
 
4283
  if (iface->unmount_mountable_with_operation != NULL)
 
4284
    (* iface->unmount_mountable_with_operation) (file,
 
4285
                                                 flags,
 
4286
                                                 mount_operation,
 
4287
                                                 cancellable,
 
4288
                                                 callback,
 
4289
                                                 user_data);
 
4290
  else
 
4291
    (* iface->unmount_mountable) (file,
 
4292
                                  flags,
 
4293
                                  cancellable,
 
4294
                                  callback,
 
4295
                                  user_data);
 
4296
}
 
4297
 
 
4298
/**
 
4299
 * g_file_unmount_mountable_with_operation_finish:
 
4300
 * @file: input #GFile.
 
4301
 * @result: a #GAsyncResult.
 
4302
 * @error: a #GError, or %NULL
 
4303
 *
 
4304
 * Finishes an unmount operation, see g_file_unmount_mountable_with_operation() for details.
 
4305
 *
 
4306
 * Finish an asynchronous unmount operation that was started
 
4307
 * with g_file_unmount_mountable_with_operation().
 
4308
 *
 
4309
 * Returns: %TRUE if the operation finished successfully. %FALSE
 
4310
 * otherwise.
 
4311
 *
 
4312
 * Since: 2.22
 
4313
 **/
 
4314
gboolean
 
4315
g_file_unmount_mountable_with_operation_finish (GFile         *file,
 
4316
                                                GAsyncResult  *result,
 
4317
                                                GError       **error)
 
4318
{
 
4319
  GFileIface *iface;
 
4320
 
 
4321
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
4322
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
 
4323
 
 
4324
  if (G_IS_SIMPLE_ASYNC_RESULT (result))
 
4325
    {
 
4326
      GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
 
4327
      if (g_simple_async_result_propagate_error (simple, error))
 
4328
        return FALSE;
 
4329
    }
 
4330
 
 
4331
  iface = G_FILE_GET_IFACE (file);
 
4332
  if (iface->unmount_mountable_with_operation_finish != NULL)
 
4333
    return (* iface->unmount_mountable_with_operation_finish) (file, result, error);
 
4334
  else
 
4335
    return (* iface->unmount_mountable_finish) (file, result, error);
 
4336
}
 
4337
 
 
4338
/**
4235
4339
 * g_file_eject_mountable:
4236
4340
 * @file: input #GFile.
4237
4341
 * @flags: flags affecting the operation
4247
4351
 * If @cancellable is not %NULL, then the operation can be cancelled by
4248
4352
 * triggering the cancellable object from another thread. If the operation
4249
4353
 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. 
 
4354
 *
 
4355
 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation() instead.
4250
4356
 **/
4251
4357
void
4252
4358
g_file_eject_mountable (GFile               *file,
4290
4396
 * 
4291
4397
 * Returns: %TRUE if the @file was ejected successfully. %FALSE 
4292
4398
 * otherwise.
 
4399
 *
 
4400
 * Deprecated: 2.22: Use g_file_eject_mountable_with_operation_finish() instead.
4293
4401
 **/
4294
4402
gboolean
4295
4403
g_file_eject_mountable_finish (GFile         *file,
4313
4421
}
4314
4422
 
4315
4423
/**
 
4424
 * g_file_eject_mountable_with_operation:
 
4425
 * @file: input #GFile.
 
4426
 * @flags: flags affecting the operation
 
4427
 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
 
4428
 * @cancellable: optional #GCancellable object, %NULL to ignore.
 
4429
 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
 
4430
 * @user_data: the data to pass to callback function
 
4431
 *
 
4432
 * Starts an asynchronous eject on a mountable.
 
4433
 * When this operation has completed, @callback will be called with
 
4434
 * @user_user data, and the operation can be finalized with
 
4435
 * g_file_eject_mountable_with_operation_finish().
 
4436
 *
 
4437
 * If @cancellable is not %NULL, then the operation can be cancelled by
 
4438
 * triggering the cancellable object from another thread. If the operation
 
4439
 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
 
4440
 *
 
4441
 * Since: 2.22
 
4442
 **/
 
4443
void
 
4444
g_file_eject_mountable_with_operation (GFile               *file,
 
4445
                                       GMountUnmountFlags   flags,
 
4446
                                       GMountOperation     *mount_operation,
 
4447
                                       GCancellable        *cancellable,
 
4448
                                       GAsyncReadyCallback  callback,
 
4449
                                       gpointer             user_data)
 
4450
{
 
4451
  GFileIface *iface;
 
4452
 
 
4453
  g_return_if_fail (G_IS_FILE (file));
 
4454
 
 
4455
  iface = G_FILE_GET_IFACE (file);
 
4456
 
 
4457
  if (iface->eject_mountable == NULL && iface->eject_mountable_with_operation == NULL)
 
4458
    {
 
4459
      g_simple_async_report_error_in_idle (G_OBJECT (file),
 
4460
                                           callback,
 
4461
                                           user_data,
 
4462
                                           G_IO_ERROR,
 
4463
                                           G_IO_ERROR_NOT_SUPPORTED,
 
4464
                                           _("Operation not supported"));
 
4465
      return;
 
4466
    }
 
4467
 
 
4468
  if (iface->eject_mountable_with_operation != NULL)
 
4469
    (* iface->eject_mountable_with_operation) (file,
 
4470
                                               flags,
 
4471
                                               mount_operation,
 
4472
                                               cancellable,
 
4473
                                               callback,
 
4474
                                               user_data);
 
4475
  else
 
4476
    (* iface->eject_mountable) (file,
 
4477
                                flags,
 
4478
                                cancellable,
 
4479
                                callback,
 
4480
                                user_data);
 
4481
}
 
4482
 
 
4483
/**
 
4484
 * g_file_eject_mountable_with_operation_finish:
 
4485
 * @file: input #GFile.
 
4486
 * @result: a #GAsyncResult.
 
4487
 * @error: a #GError, or %NULL
 
4488
 *
 
4489
 * Finishes an asynchronous eject operation started by
 
4490
 * g_file_eject_mountable_with_operation().
 
4491
 *
 
4492
 * Returns: %TRUE if the @file was ejected successfully. %FALSE
 
4493
 * otherwise.
 
4494
 *
 
4495
 * Since: 2.22
 
4496
 **/
 
4497
gboolean
 
4498
g_file_eject_mountable_with_operation_finish (GFile         *file,
 
4499
                                              GAsyncResult  *result,
 
4500
                                              GError       **error)
 
4501
{
 
4502
  GFileIface *iface;
 
4503
 
 
4504
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
4505
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
 
4506
 
 
4507
  if (G_IS_SIMPLE_ASYNC_RESULT (result))
 
4508
    {
 
4509
      GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
 
4510
      if (g_simple_async_result_propagate_error (simple, error))
 
4511
        return FALSE;
 
4512
    }
 
4513
 
 
4514
  iface = G_FILE_GET_IFACE (file);
 
4515
  if (iface->eject_mountable_with_operation_finish != NULL)
 
4516
    return (* iface->eject_mountable_with_operation_finish) (file, result, error);
 
4517
  else
 
4518
    return (* iface->eject_mountable_finish) (file, result, error);
 
4519
}
 
4520
 
 
4521
/**
4316
4522
 * g_file_monitor_directory:
4317
4523
 * @file: input #GFile.
4318
4524
 * @flags: a set of #GFileMonitorFlags.
6668
6874
 * g_file_stop_mountable:
6669
6875
 * @file: input #GFile.
6670
6876
 * @flags: flags affecting the operation
 
6877
 * @mount_operation: a #GMountOperation, or %NULL to avoid user interaction.
6671
6878
 * @cancellable: optional #GCancellable object, %NULL to ignore.
6672
6879
 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
6673
6880
 * @user_data: the data to pass to callback function
6686
6893
void
6687
6894
g_file_stop_mountable (GFile                      *file,
6688
6895
                       GMountUnmountFlags          flags,
 
6896
                       GMountOperation            *mount_operation,
6689
6897
                       GCancellable               *cancellable,
6690
6898
                       GAsyncReadyCallback         callback,
6691
6899
                       gpointer                    user_data)
6709
6917
 
6710
6918
  (* iface->stop_mountable) (file,
6711
6919
                             flags,
 
6920
                             mount_operation,
6712
6921
                             cancellable,
6713
6922
                             callback,
6714
6923
                             user_data);
6751
6960
  return (* iface->stop_mountable_finish) (file, result, error);
6752
6961
}
6753
6962
 
 
6963
/**
 
6964
 * g_file_poll_mountable:
 
6965
 * @file: input #GFile.
 
6966
 * @cancellable: optional #GCancellable object, %NULL to ignore.
 
6967
 * @callback: a #GAsyncReadyCallback to call when the request is satisfied, or %NULL.
 
6968
 * @user_data: the data to pass to callback function
 
6969
 *
 
6970
 * Polls a file of type G_FILE_TYPE_MOUNTABLE.
 
6971
 *
 
6972
 * If @cancellable is not %NULL, then the operation can be cancelled by
 
6973
 * triggering the cancellable object from another thread. If the operation
 
6974
 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
 
6975
 *
 
6976
 * When the operation is finished, @callback will be called. You can then call
 
6977
 * g_file_mount_mountable_finish() to get the result of the operation.
 
6978
 *
 
6979
 * Since: 2.22
 
6980
 */
 
6981
void
 
6982
g_file_poll_mountable (GFile                      *file,
 
6983
                       GCancellable               *cancellable,
 
6984
                       GAsyncReadyCallback         callback,
 
6985
                       gpointer                    user_data)
 
6986
{
 
6987
  GFileIface *iface;
 
6988
 
 
6989
  g_return_if_fail (G_IS_FILE (file));
 
6990
 
 
6991
  iface = G_FILE_GET_IFACE (file);
 
6992
 
 
6993
  if (iface->poll_mountable == NULL)
 
6994
    {
 
6995
      g_simple_async_report_error_in_idle (G_OBJECT (file),
 
6996
                                           callback,
 
6997
                                           user_data,
 
6998
                                           G_IO_ERROR,
 
6999
                                           G_IO_ERROR_NOT_SUPPORTED,
 
7000
                                           _("Operation not supported"));
 
7001
      return;
 
7002
    }
 
7003
 
 
7004
  (* iface->poll_mountable) (file,
 
7005
                             cancellable,
 
7006
                             callback,
 
7007
                             user_data);
 
7008
}
 
7009
 
 
7010
/**
 
7011
 * g_file_poll_mountable_finish:
 
7012
 * @file: input #GFile.
 
7013
 * @result: a #GAsyncResult.
 
7014
 * @error: a #GError, or %NULL
 
7015
 *
 
7016
 * Finishes a poll operation. See g_file_poll_mountable() for details.
 
7017
 *
 
7018
 * Finish an asynchronous poll operation that was polled
 
7019
 * with g_file_poll_mountable().
 
7020
 *
 
7021
 * Returns: %TRUE if the operation finished successfully. %FALSE
 
7022
 * otherwise.
 
7023
 *
 
7024
 * Since: 2.22
 
7025
 */
 
7026
gboolean
 
7027
g_file_poll_mountable_finish (GFile                      *file,
 
7028
                              GAsyncResult               *result,
 
7029
                              GError                    **error)
 
7030
{
 
7031
  GFileIface *iface;
 
7032
 
 
7033
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
7034
  g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
 
7035
 
 
7036
  if (G_IS_SIMPLE_ASYNC_RESULT (result))
 
7037
    {
 
7038
      GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
 
7039
      if (g_simple_async_result_propagate_error (simple, error))
 
7040
        return FALSE;
 
7041
    }
 
7042
 
 
7043
  iface = G_FILE_GET_IFACE (file);
 
7044
  return (* iface->poll_mountable_finish) (file, result, error);
 
7045
}
 
7046
 
 
7047
/**
 
7048
 * g_file_supports_thread_contexts:
 
7049
 * @file: a #GFile.
 
7050
 *
 
7051
 * Checks if @file supports <link
 
7052
 * linkend="g-main-context-push-thread-default-context">thread-default
 
7053
 * contexts</link>. If this returns %FALSE, you cannot perform
 
7054
 * asynchronous operations on @file in a thread that has a
 
7055
 * thread-default context.
 
7056
 *
 
7057
 * Returns: Whether or not @file supports thread-default contexts.
 
7058
 *
 
7059
 * Since: 2.22
 
7060
 */
 
7061
gboolean
 
7062
g_file_supports_thread_contexts (GFile *file)
 
7063
{
 
7064
 GFileIface *iface;
 
7065
 
 
7066
 g_return_val_if_fail (G_IS_FILE (file), FALSE);
 
7067
 
 
7068
 iface = G_FILE_GET_IFACE (file);
 
7069
 return iface->supports_thread_contexts;
 
7070
}
 
7071
 
6754
7072
#define __G_FILE_C__
6755
7073
#include "gioaliasdef.c"