[gnome-desktop] bg-slide-show: Add file construct property to init from GFile



commit ca5d61cf249113e42baafc9d7513b6eb280e9a92
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Jul 16 23:36:53 2019 +0200

    bg-slide-show: Add file construct property to init from GFile
    
    Make possible to create a Background slide-show from a GFile instead that from
    a file path. Keep a reference on the file instead that on the path.
    
    Change the new function parameter to initialize the slideshow  using a GFile

 libgnome-desktop/gnome-bg-slide-show.c | 42 +++++++++++++++-------------------
 libgnome-desktop/gnome-bg-slide-show.h |  2 +-
 2 files changed, 20 insertions(+), 24 deletions(-)
---
diff --git a/libgnome-desktop/gnome-bg-slide-show.c b/libgnome-desktop/gnome-bg-slide-show.c
index 62d2f640..6c107ba1 100644
--- a/libgnome-desktop/gnome-bg-slide-show.c
+++ b/libgnome-desktop/gnome-bg-slide-show.c
@@ -31,7 +31,7 @@
 
 struct _GnomeBGSlideShowPrivate
 {
-        char *filename;
+        GFile *file;
 
         double start_time;
         double total_duration;
@@ -67,7 +67,7 @@ struct _FileSize
 
 enum {
         PROP_0,
-        PROP_FILENAME,
+        PROP_FILE,
         PROP_START_TIME,
         PROP_TOTAL_DURATION,
         PROP_HAS_MULTIPLE_SIZES,
@@ -92,8 +92,8 @@ gnome_bg_slide_show_set_property (GObject       *object,
 
         switch (property_id)
         {
-        case PROP_FILENAME:
-                self->priv->filename = g_value_dup_string (value);
+        case PROP_FILE:
+                self->priv->file = g_object_ref (g_value_get_object (value));
                 break;
         default:
                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -115,8 +115,8 @@ gnome_bg_slide_show_get_property (GObject     *object,
 
         switch (property_id)
         {
-        case PROP_FILENAME:
-                g_value_set_string (value, self->priv->filename);
+        case PROP_FILE:
+                g_value_set_object (value, self->priv->file);
                 break;
         case PROP_START_TIME:
                 g_value_set_int (value, self->priv->start_time);
@@ -169,7 +169,7 @@ gnome_bg_slide_show_finalize (GObject *object)
 
         g_queue_free_full (self->priv->stack, g_free);
 
-        g_free (self->priv->filename);
+        g_object_unref (self->priv->file);
 }
 
 static void
@@ -184,11 +184,11 @@ gnome_bg_slide_show_class_init (GnomeBGSlideShowClass *self_class)
         gobject_class->finalize = gnome_bg_slide_show_finalize;
 
         g_object_class_install_property (gobject_class,
-                                         PROP_FILENAME,
-                                         g_param_spec_string ("filename",
-                                                              "Filename",
-                                                              "Filename",
-                                                              NULL,
+                                         PROP_FILE,
+                                         g_param_spec_object ("file",
+                                                              "File",
+                                                              "File",
+                                                              G_TYPE_FILE,
                                                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
         g_object_class_install_property (gobject_class,
@@ -229,7 +229,7 @@ gnome_bg_slide_show_init (GnomeBGSlideShow *self)
 
 /**
  * gnome_bg_slide_show_new:
- * @filename: The name of the slide show file
+ * @file: The #GFile of the slide show
  *
  * Creates a new object to manage a slide show.
  * window background between two #cairo_surface_ts.
@@ -237,10 +237,10 @@ gnome_bg_slide_show_init (GnomeBGSlideShow *self)
  * Return value: the new #GnomeBGSlideShow
  **/
 GnomeBGSlideShow *
-gnome_bg_slide_show_new (const char *filename)
+gnome_bg_slide_show_new (GFile *file)
 {
         return GNOME_BG_SLIDE_SHOW (g_object_new (GNOME_BG_TYPE_SLIDE_SHOW,
-                                                  "filename", filename,
+                                                  "file", file,
                                                   NULL));
 }
 
@@ -713,16 +713,14 @@ gboolean
 gnome_bg_slide_show_load (GnomeBGSlideShow  *self,
                           GError           **error)
 {
-        GFile *file;
         char  *contents;
         gsize  length;
         gboolean parsed;
 
-        file = g_file_new_for_path (self->priv->filename);
-        if (!g_file_load_contents (file, NULL, &contents, &length, NULL, NULL)) {
+        if (!g_file_load_contents (self->priv->file, NULL, &contents, &length,
+                                   NULL, NULL)) {
                 return FALSE;
         }
-        g_object_unref (file);
 
         parsed = parse_file_contents (self, contents, length, error);
         g_free (contents);
@@ -776,13 +774,11 @@ gnome_bg_slide_show_load_async (GnomeBGSlideShow    *self,
                                 gpointer             user_data)
 {
     GTask *task;
-    GFile *file;
 
     task = g_task_new (self, cancellable, callback, user_data);
 
-    file = g_file_new_for_path (self->priv->filename);
-    g_file_load_contents_async (file, cancellable, (GAsyncReadyCallback) on_file_loaded, task);
-    g_object_unref (file);
+    g_file_load_contents_async (self->priv->file, cancellable,
+                                (GAsyncReadyCallback) on_file_loaded, task);
 }
 
 /**
diff --git a/libgnome-desktop/gnome-bg-slide-show.h b/libgnome-desktop/gnome-bg-slide-show.h
index bcf17137..4c3be7b8 100644
--- a/libgnome-desktop/gnome-bg-slide-show.h
+++ b/libgnome-desktop/gnome-bg-slide-show.h
@@ -59,7 +59,7 @@ struct _GnomeBGSlideShowClass
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GnomeBGSlideShow, g_object_unref)
 
 GType             gnome_bg_slide_show_get_type (void);
-GnomeBGSlideShow *gnome_bg_slide_show_new (const char *filename);
+GnomeBGSlideShow *gnome_bg_slide_show_new (GFile *file);
 gboolean          gnome_bg_slide_show_load (GnomeBGSlideShow  *self,
                                             GError           **error);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]