| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | /* GIO - GLib Input, Output and Streaming Library
 | 
					
						
							|  |  |  |  |  *  | 
					
						
							|  |  |  |  |  * Copyright (C) 2006-2007 Red Hat, Inc. | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2022-05-18 09:12:45 +01:00
										 |  |  |  |  * SPDX-License-Identifier: LGPL-2.1-or-later | 
					
						
							|  |  |  |  |  * | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * This library is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  |  * modify it under the terms of the GNU Lesser General Public | 
					
						
							|  |  |  |  |  * License as published by the Free Software Foundation; either | 
					
						
							| 
									
										
										
										
											2017-05-27 18:21:30 +02:00
										 |  |  |  |  * version 2.1 of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * This library is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
					
						
							|  |  |  |  |  * Lesser General Public License for more details. | 
					
						
							|  |  |  |  |  * | 
					
						
							|  |  |  |  |  * You should have received a copy of the GNU Lesser General | 
					
						
							| 
									
										
										
										
											2014-01-23 12:58:29 +01:00
										 |  |  |  |  * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  * | 
					
						
							|  |  |  |  |  * Author: Alexander Larsson <alexl@redhat.com> | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-22 15:10:51 +00:00
										 |  |  |  | #include "config.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | #include "gfileicon.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-01 06:32:35 +00:00
										 |  |  |  | #include "gfile.h"
 | 
					
						
							|  |  |  |  | #include "gicon.h"
 | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  | #include "glibintl.h"
 | 
					
						
							| 
									
										
										
										
											2008-07-01 06:32:35 +00:00
										 |  |  |  | #include "gloadableicon.h"
 | 
					
						
							|  |  |  |  | #include "ginputstream.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  | #include "gtask.h"
 | 
					
						
							| 
									
										
										
										
											2008-10-21 11:51:48 +00:00
										 |  |  |  | #include "gioerror.h"
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-28 12:39:07 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2023-10-23 13:41:09 +01:00
										 |  |  |  |  * GFileIcon: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2023-10-23 13:41:09 +01:00
										 |  |  |  |  * `GFileIcon` specifies an icon by pointing to an image file | 
					
						
							| 
									
										
										
										
											2007-12-12 12:19:02 +00:00
										 |  |  |  |  * to be used as icon. | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2023-10-23 13:41:09 +01:00
										 |  |  |  |  * It implements [iface@Gio.LoadableIcon]. | 
					
						
							|  |  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | static void g_file_icon_icon_iface_init          (GIconIface          *iface); | 
					
						
							|  |  |  |  | static void g_file_icon_loadable_icon_iface_init (GLoadableIconIface  *iface); | 
					
						
							|  |  |  |  | static void g_file_icon_load_async               (GLoadableIcon       *icon, | 
					
						
							|  |  |  |  | 						  int                  size, | 
					
						
							|  |  |  |  | 						  GCancellable        *cancellable, | 
					
						
							|  |  |  |  | 						  GAsyncReadyCallback  callback, | 
					
						
							|  |  |  |  | 						  gpointer             user_data); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | struct _GFileIcon | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GObject parent_instance; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   GFile *file; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | struct _GFileIconClass | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GObjectClass parent_class; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  | enum | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   PROP_0, | 
					
						
							|  |  |  |  |   PROP_FILE | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | G_DEFINE_TYPE_WITH_CODE (GFileIcon, g_file_icon, G_TYPE_OBJECT, | 
					
						
							| 
									
										
										
										
											2008-06-28 20:53:02 +00:00
										 |  |  |  |                          G_IMPLEMENT_INTERFACE (G_TYPE_ICON, | 
					
						
							|  |  |  |  |                                                 g_file_icon_icon_iface_init) | 
					
						
							|  |  |  |  |                          G_IMPLEMENT_INTERFACE (G_TYPE_LOADABLE_ICON, | 
					
						
							|  |  |  |  |                                                 g_file_icon_loadable_icon_iface_init)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_get_property (GObject    *object, | 
					
						
							|  |  |  |  |                           guint       prop_id, | 
					
						
							|  |  |  |  |                           GValue     *value, | 
					
						
							|  |  |  |  |                           GParamSpec *pspec) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *icon = G_FILE_ICON (object); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   switch (prop_id) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       case PROP_FILE: | 
					
						
							|  |  |  |  |         g_value_set_object (value, icon->file); | 
					
						
							|  |  |  |  |         break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       default: | 
					
						
							|  |  |  |  |         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_set_property (GObject      *object, | 
					
						
							|  |  |  |  |                           guint         prop_id, | 
					
						
							|  |  |  |  |                           const GValue *value, | 
					
						
							|  |  |  |  |                           GParamSpec   *pspec) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *icon = G_FILE_ICON (object); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   switch (prop_id) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       case PROP_FILE: | 
					
						
							|  |  |  |  |         icon->file = G_FILE (g_value_dup_object (value)); | 
					
						
							|  |  |  |  |         break; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |       default: | 
					
						
							|  |  |  |  |         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 19:43:41 +02:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_constructed (GObject *object) | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-24 08:55:58 +00:00
										 |  |  |  | #ifndef G_DISABLE_ASSERT
 | 
					
						
							|  |  |  |  |   GFileIcon *icon = G_FILE_ICON (object); | 
					
						
							|  |  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2020-11-10 19:43:41 +02:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_OBJECT_CLASS (g_file_icon_parent_class)->constructed (object); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   /* Must have be set during construction */ | 
					
						
							|  |  |  |  |   g_assert (icon->file != NULL); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_finalize (GObject *object) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *icon; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   icon = G_FILE_ICON (object); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-23 15:00:55 -05:00
										 |  |  |  |   if (icon->file) | 
					
						
							|  |  |  |  |     g_object_unref (icon->file); | 
					
						
							| 
									
										
										
										
											2008-06-16 09:54:04 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   G_OBJECT_CLASS (g_file_icon_parent_class)->finalize (object); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_class_init (GFileIconClass *klass) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GObjectClass *gobject_class = G_OBJECT_CLASS (klass); | 
					
						
							|  |  |  |  |    | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  |   gobject_class->get_property = g_file_icon_get_property; | 
					
						
							|  |  |  |  |   gobject_class->set_property = g_file_icon_set_property; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   gobject_class->finalize = g_file_icon_finalize; | 
					
						
							| 
									
										
										
										
											2020-11-10 19:43:41 +02:00
										 |  |  |  |   gobject_class->constructed = g_file_icon_constructed; | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   /**
 | 
					
						
							|  |  |  |  |    * GFileIcon:file: | 
					
						
							|  |  |  |  |    * | 
					
						
							|  |  |  |  |    * The file containing the icon. | 
					
						
							|  |  |  |  |    */ | 
					
						
							|  |  |  |  |   g_object_class_install_property (gobject_class, PROP_FILE, | 
					
						
							| 
									
										
										
										
											2023-04-28 01:59:26 +02:00
										 |  |  |  |                                    g_param_spec_object ("file", NULL, NULL, | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  |                                                         G_TYPE_FILE, | 
					
						
							|  |  |  |  |                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB | G_PARAM_STATIC_NICK)); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_init (GFileIcon *file) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_file_icon_new: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  |  * @file: a #GFile. | 
					
						
							|  |  |  |  |  *  | 
					
						
							|  |  |  |  |  * Creates a new icon for a file. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2012-01-07 09:54:53 -08:00
										 |  |  |  |  * Returns: (transfer full) (type GFileIcon): a #GIcon for the given | 
					
						
							|  |  |  |  |  *   @file, or %NULL on error. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  **/ | 
					
						
							|  |  |  |  | GIcon * | 
					
						
							|  |  |  |  | g_file_icon_new (GFile *file) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (G_IS_FILE (file), NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-07 19:44:53 +00:00
										 |  |  |  |   return G_ICON (g_object_new (G_TYPE_FILE_ICON, "file", file, NULL)); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * g_file_icon_get_file: | 
					
						
							| 
									
										
										
										
											2007-11-27 14:00:13 +00:00
										 |  |  |  |  * @icon: a #GIcon. | 
					
						
							|  |  |  |  |  *  | 
					
						
							|  |  |  |  |  * Gets the #GFile associated with the given @icon. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2020-10-18 11:15:54 +03:00
										 |  |  |  |  * Returns: (transfer none): a #GFile. | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |  **/ | 
					
						
							|  |  |  |  | GFile * | 
					
						
							|  |  |  |  | g_file_icon_get_file (GFileIcon *icon) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   g_return_val_if_fail (G_IS_FILE_ICON (icon), NULL); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return icon->file; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static guint | 
					
						
							|  |  |  |  | g_file_icon_hash (GIcon *icon) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *file_icon = G_FILE_ICON (icon); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_file_hash (file_icon->file); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static gboolean | 
					
						
							|  |  |  |  | g_file_icon_equal (GIcon *icon1, | 
					
						
							|  |  |  |  | 		   GIcon *icon2) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *file1 = G_FILE_ICON (icon1); | 
					
						
							|  |  |  |  |   GFileIcon *file2 = G_FILE_ICON (icon2); | 
					
						
							|  |  |  |  |    | 
					
						
							|  |  |  |  |   return g_file_equal (file1->file, file2->file); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-21 11:51:48 +00:00
										 |  |  |  | static gboolean | 
					
						
							|  |  |  |  | g_file_icon_to_tokens (GIcon *icon, | 
					
						
							|  |  |  |  | 		       GPtrArray *tokens, | 
					
						
							|  |  |  |  |                        gint  *out_version) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *file_icon = G_FILE_ICON (icon); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_return_val_if_fail (out_version != NULL, FALSE); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   *out_version = 0; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   g_ptr_array_add (tokens, g_file_get_uri (file_icon->file)); | 
					
						
							|  |  |  |  |   return TRUE; | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static GIcon * | 
					
						
							|  |  |  |  | g_file_icon_from_tokens (gchar  **tokens, | 
					
						
							|  |  |  |  |                          gint     num_tokens, | 
					
						
							|  |  |  |  |                          gint     version, | 
					
						
							|  |  |  |  |                          GError **error) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GIcon *icon; | 
					
						
							|  |  |  |  |   GFile *file; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   icon = NULL; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (version != 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_set_error (error, | 
					
						
							|  |  |  |  |                    G_IO_ERROR, | 
					
						
							|  |  |  |  |                    G_IO_ERROR_INVALID_ARGUMENT, | 
					
						
							| 
									
										
										
										
											2016-09-30 05:47:15 +02:00
										 |  |  |  |                    _("Can’t handle version %d of GFileIcon encoding"), | 
					
						
							| 
									
										
										
										
											2008-10-21 11:51:48 +00:00
										 |  |  |  |                    version); | 
					
						
							|  |  |  |  |       goto out; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (num_tokens != 1) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |       g_set_error_literal (error, | 
					
						
							|  |  |  |  |                            G_IO_ERROR, | 
					
						
							|  |  |  |  |                            G_IO_ERROR_INVALID_ARGUMENT, | 
					
						
							|  |  |  |  |                            _("Malformed input data for GFileIcon")); | 
					
						
							|  |  |  |  |       goto out; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   file = g_file_new_for_uri (tokens[0]); | 
					
						
							|  |  |  |  |   icon = g_file_icon_new (file); | 
					
						
							|  |  |  |  |   g_object_unref (file); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |  out: | 
					
						
							|  |  |  |  |   return icon; | 
					
						
							|  |  |  |  | } | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-20 18:50:21 -04:00
										 |  |  |  | static GVariant * | 
					
						
							|  |  |  |  | g_file_icon_serialize (GIcon *icon) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *file_icon = G_FILE_ICON (icon); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   return g_variant_new ("(sv)", "file", g_variant_new_take_string (g_file_get_uri (file_icon->file))); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_icon_iface_init (GIconIface *iface) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   iface->hash = g_file_icon_hash; | 
					
						
							|  |  |  |  |   iface->equal = g_file_icon_equal; | 
					
						
							| 
									
										
										
										
											2008-10-21 11:51:48 +00:00
										 |  |  |  |   iface->to_tokens = g_file_icon_to_tokens; | 
					
						
							|  |  |  |  |   iface->from_tokens = g_file_icon_from_tokens; | 
					
						
							| 
									
										
										
										
											2013-04-20 18:50:21 -04:00
										 |  |  |  |   iface->serialize = g_file_icon_serialize; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static GInputStream * | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | g_file_icon_load (GLoadableIcon  *icon, | 
					
						
							|  |  |  |  | 		  int            size, | 
					
						
							|  |  |  |  | 		  char          **type, | 
					
						
							|  |  |  |  | 		  GCancellable   *cancellable, | 
					
						
							|  |  |  |  | 		  GError        **error) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   GFileInputStream *stream; | 
					
						
							|  |  |  |  |   GFileIcon *file_icon = G_FILE_ICON (icon); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   stream = g_file_read (file_icon->file, | 
					
						
							|  |  |  |  | 			cancellable, | 
					
						
							|  |  |  |  | 			error); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:53:40 +01:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (stream && type) | 
					
						
							|  |  |  |  |     *type = NULL; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |    | 
					
						
							|  |  |  |  |   return G_INPUT_STREAM (stream); | 
					
						
							|  |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | load_async_callback (GObject      *source_object, | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 		     GAsyncResult *res, | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | 		     gpointer      user_data) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   GFileInputStream *stream; | 
					
						
							|  |  |  |  |   GError *error = NULL; | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |   GTask *task = user_data; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   stream = g_file_read_finish (G_FILE (source_object), res, &error); | 
					
						
							|  |  |  |  |   if (stream == NULL) | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |     g_task_return_error (task, error); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |   else | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |     g_task_return_pointer (task, stream, g_object_unref); | 
					
						
							|  |  |  |  |   g_object_unref (task); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | g_file_icon_load_async (GLoadableIcon       *icon, | 
					
						
							|  |  |  |  |                         int                  size, | 
					
						
							|  |  |  |  |                         GCancellable        *cancellable, | 
					
						
							|  |  |  |  |                         GAsyncReadyCallback  callback, | 
					
						
							|  |  |  |  |                         gpointer             user_data) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							|  |  |  |  |   GFileIcon *file_icon = G_FILE_ICON (icon); | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |   GTask *task; | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |   task = g_task_new (icon, cancellable, callback, user_data); | 
					
						
							| 
									
										
										
										
											2016-06-16 19:39:38 -04:00
										 |  |  |  |   g_task_set_source_tag (task, g_file_icon_load_async); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  |    | 
					
						
							|  |  |  |  |   g_file_read_async (file_icon->file, 0, | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |                      cancellable, | 
					
						
							|  |  |  |  |                      load_async_callback, task); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static GInputStream * | 
					
						
							| 
									
										
										
										
											2007-11-29 07:17:59 +00:00
										 |  |  |  | g_file_icon_load_finish (GLoadableIcon  *icon, | 
					
						
							|  |  |  |  | 			 GAsyncResult   *res, | 
					
						
							|  |  |  |  | 			 char          **type, | 
					
						
							|  |  |  |  | 			 GError        **error) | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |   g_return_val_if_fail (g_task_is_valid (res, icon), NULL); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |   if (type) | 
					
						
							|  |  |  |  |     *type = NULL; | 
					
						
							|  |  |  |  |    | 
					
						
							| 
									
										
										
										
											2012-08-02 15:50:35 -04:00
										 |  |  |  |   return g_task_propagate_pointer (G_TASK (res), error); | 
					
						
							| 
									
										
										
										
											2007-11-26 16:13:05 +00:00
										 |  |  |  | } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | static void | 
					
						
							|  |  |  |  | g_file_icon_loadable_icon_iface_init (GLoadableIconIface *iface) | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |   iface->load = g_file_icon_load; | 
					
						
							|  |  |  |  |   iface->load_async = g_file_icon_load_async; | 
					
						
							|  |  |  |  |   iface->load_finish = g_file_icon_load_finish; | 
					
						
							|  |  |  |  | } |