~ubuntu-branches/debian/sid/glib2.0/sid

« back to all changes in this revision

Viewing changes to gio/gfileicon.c

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2013-05-08 06:25:57 UTC
  • mfrom: (1.27.14) (3.1.181 experimental)
  • Revision ID: package-import@ubuntu.com-20130508062557-i7gbku66mls70gi2
Tags: 2.36.1-2
Merge experimental branch, upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include "glibintl.h"
29
29
#include "gloadableicon.h"
30
30
#include "ginputstream.h"
31
 
#include "gsimpleasyncresult.h"
 
31
#include "gtask.h"
32
32
#include "gioerror.h"
33
33
 
34
34
 
283
283
  return G_INPUT_STREAM (stream);
284
284
}
285
285
 
286
 
typedef struct {
287
 
  GLoadableIcon *icon;
288
 
  GAsyncReadyCallback callback;
289
 
  gpointer user_data;
290
 
} LoadData;
291
 
 
292
 
static void
293
 
load_data_free (LoadData *data)
294
 
{
295
 
  g_object_unref (data->icon);
296
 
  g_free (data);
297
 
}
298
 
 
299
286
static void
300
287
load_async_callback (GObject      *source_object,
301
288
                     GAsyncResult *res,
303
290
{
304
291
  GFileInputStream *stream;
305
292
  GError *error = NULL;
306
 
  GSimpleAsyncResult *simple;
307
 
  LoadData *data = user_data;
 
293
  GTask *task = user_data;
308
294
 
309
295
  stream = g_file_read_finish (G_FILE (source_object), res, &error);
310
 
  
311
296
  if (stream == NULL)
312
 
    {
313
 
      simple = g_simple_async_result_new_take_error (G_OBJECT (data->icon),
314
 
                                                     data->callback,
315
 
                                                     data->user_data,
316
 
                                                     error);
317
 
    }
 
297
    g_task_return_error (task, error);
318
298
  else
319
 
    {
320
 
      simple = g_simple_async_result_new (G_OBJECT (data->icon),
321
 
                                          data->callback,
322
 
                                          data->user_data,
323
 
                                          g_file_icon_load_async);
324
 
      
325
 
      g_simple_async_result_set_op_res_gpointer (simple,
326
 
                                                 stream,
327
 
                                                 g_object_unref);
328
 
  }
329
 
 
330
 
 
331
 
  g_simple_async_result_complete (simple);
332
 
  
333
 
  load_data_free (data);
334
 
  g_object_unref (simple);
 
299
    g_task_return_pointer (task, stream, g_object_unref);
 
300
  g_object_unref (task);
335
301
}
336
302
 
337
303
static void
342
308
                        gpointer             user_data)
343
309
{
344
310
  GFileIcon *file_icon = G_FILE_ICON (icon);
345
 
  LoadData *data;
 
311
  GTask *task;
346
312
 
347
 
  data = g_new0 (LoadData, 1);
348
 
  data->icon = g_object_ref (icon);
349
 
  data->callback = callback;
350
 
  data->user_data = user_data;
 
313
  task = g_task_new (icon, cancellable, callback, user_data);
351
314
  
352
315
  g_file_read_async (file_icon->file, 0,
353
 
                     cancellable,
354
 
                     load_async_callback, data);
355
 
  
 
316
                     cancellable,
 
317
                     load_async_callback, task);
356
318
}
357
319
 
358
320
static GInputStream *
361
323
                         char          **type,
362
324
                         GError        **error)
363
325
{
364
 
  GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
365
 
  gpointer op;
366
 
 
367
 
  g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == g_file_icon_load_async);
 
326
  g_return_val_if_fail (g_task_is_valid (res, icon), NULL);
368
327
 
369
328
  if (type)
370
329
    *type = NULL;
371
330
  
372
 
  op = g_simple_async_result_get_op_res_gpointer (simple);
373
 
  if (op)
374
 
    return g_object_ref (op);
375
 
  
376
 
  return NULL;
 
331
  return g_task_propagate_pointer (G_TASK (res), error);
377
332
}
378
333
 
379
334
static void