[glide] Glide documents are now self contained



commit 858b386fb82ec0233f130fecf321a1be6c7aaf93
Author: Robert Carr <racarr Valentine localdomain>
Date:   Tue Apr 27 00:12:24 2010 -0400

    Glide documents are now self contained

 src/glide-actor.c         |    6 ++++--
 src/glide-actor.h         |    2 +-
 src/glide-image.c         |   11 ++++++++---
 src/glide-slide.c         |    4 ++--
 src/glide-stage-manager.c |    2 ++
 src/glide-window.c        |   10 ++++++++--
 6 files changed, 25 insertions(+), 10 deletions(-)
---
diff --git a/src/glide-actor.c b/src/glide-actor.c
index dfb603e..5c90113 100644
--- a/src/glide-actor.c
+++ b/src/glide-actor.c
@@ -107,7 +107,7 @@ static void
 glide_actor_set_stage_manager_real (GlideActor *actor,
 				    GlideStageManager *manager)
 {
-  g_return_if_fail (actor->priv->manager == NULL);
+  g_return_if_fail (actor->priv->manager == NULL || actor->priv->manager == manager);
   actor->priv->manager = manager;
 
   g_signal_connect (actor->priv->manager, "selection-changed",
@@ -245,7 +245,8 @@ glide_actor_print (GlideActor *a, cairo_t *cr)
 
 
 GlideActor *
-glide_actor_construct_from_json (JsonObject *actor_obj)
+glide_actor_construct_from_json (GlideStageManager *manager, 
+				 JsonObject *actor_obj)
 {
   const gchar *a_type = glide_json_object_get_string (actor_obj, "type");
   GlideActor *ret;
@@ -262,6 +263,7 @@ glide_actor_construct_from_json (JsonObject *actor_obj)
     {
       return NULL;
     }
+  glide_actor_set_stage_manager (ret, manager);
   glide_actor_deserialize (ret, actor_obj);
 
   return ret;
diff --git a/src/glide-actor.h b/src/glide-actor.h
index 85129a0..df5a988 100644
--- a/src/glide-actor.h
+++ b/src/glide-actor.h
@@ -88,7 +88,7 @@ gboolean glide_actor_get_selected (GlideActor *actor);
 
 JsonNode *glide_actor_serialize (GlideActor *actor);
 
-GlideActor *glide_actor_construct_from_json (JsonObject *obj);
+GlideActor *glide_actor_construct_from_json (GlideStageManager *manager, JsonObject *obj);
 void glide_actor_deserialize (GlideActor *actor, JsonObject *obj);
 
 GlideUndoManager *glide_actor_get_undo_manager (GlideActor *actor);
diff --git a/src/glide-image.c b/src/glide-image.c
index 23eafb4..65a8aaf 100644
--- a/src/glide-image.c
+++ b/src/glide-image.c
@@ -366,17 +366,22 @@ glide_image_set_from_file (GlideImage *image,
   CoglHandle new_texture = COGL_INVALID_HANDLE;
   GError *internal_error = NULL;
   CoglTextureFlags flags = COGL_TEXTURE_NONE;
+  gchar *resource, *resource_file;
   
   priv = image->priv;
+  resource = glide_actor_add_resource (GLIDE_ACTOR (image), filename);
+
   if (priv->filename)
     g_free (priv->filename);
-  priv->filename = g_strdup (filename);
+  priv->filename = resource;
+  
+  resource_file = glide_actor_get_resource_path (GLIDE_ACTOR (image), resource);
   
-  new_texture = cogl_texture_new_from_file (filename,
+  new_texture = cogl_texture_new_from_file (resource_file,
 					    flags,
 					    COGL_PIXEL_FORMAT_ANY,
 					    &internal_error);
-  
+  // TODO: Work on error of resource path v. selected path..
   if (internal_error == NULL && new_texture == COGL_INVALID_HANDLE)
     {
       g_set_error (&internal_error, CLUTTER_TEXTURE_ERROR,
diff --git a/src/glide-slide.c b/src/glide-slide.c
index 53c20b3..9c8a51d 100644
--- a/src/glide-slide.c
+++ b/src/glide-slide.c
@@ -658,9 +658,9 @@ glide_slide_construct_from_json (GlideSlide *slide, JsonObject *slide_obj, Glide
       JsonNode *actor_n = a->data;
       JsonObject *actor_obj = json_node_get_object (actor_n);
       
-      actor = glide_actor_construct_from_json (actor_obj);
+      actor = glide_actor_construct_from_json (glide_actor_get_stage_manager (GLIDE_ACTOR (slide)),
+					       actor_obj);
       glide_slide_add_actor_content (slide, CLUTTER_ACTOR (actor));
-      glide_actor_set_stage_manager (actor, manager);
       clutter_actor_show (CLUTTER_ACTOR (actor));      
     }
 }
diff --git a/src/glide-stage-manager.c b/src/glide-stage-manager.c
index 9c95eee..88f6d4e 100644
--- a/src/glide-stage-manager.c
+++ b/src/glide-stage-manager.c
@@ -839,6 +839,8 @@ glide_stage_manager_load_slides (GlideStageManager *manager, JsonArray *slides)
       JsonObject *slide = json_node_get_object (n);
       GlideSlide *gs = glide_document_append_slide (manager->priv->document);
       
+      glide_actor_set_stage_manager (GLIDE_ACTOR (gs), manager);
+      
       glide_slide_construct_from_json (gs, slide, manager);
     }
 }
diff --git a/src/glide-window.c b/src/glide-window.c
index ca19ab8..5112c03 100644
--- a/src/glide-window.c
+++ b/src/glide-window.c
@@ -96,7 +96,7 @@ glide_window_construct_copy_buffer (GlideWindow *w)
 {
   JsonObject *obj = json_node_get_object (w->priv->copy_buffer);
   
-  return glide_actor_construct_from_json (obj);
+  return glide_actor_construct_from_json (w->priv->manager, obj);
 }
 
 static void
@@ -646,7 +646,12 @@ glide_window_image_open_response_callback (GtkDialog *dialog,
       // Todo: URI
       gchar *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
       
-      im =  glide_image_new_from_file (filename, &e);
+      im =  glide_image_new ();
+
+      // Needed to add resource to document
+      glide_actor_set_stage_manager (GLIDE_ACTOR (im), window->priv->manager);
+
+      glide_image_set_from_file (GLIDE_IMAGE (im), filename, &e);
       if (e)
 	{
 	  g_warning ("Failed to load image (%s): %s", filename, e->message);
@@ -656,6 +661,7 @@ glide_window_image_open_response_callback (GtkDialog *dialog,
 
 	  g_error_free (e);
 	  gtk_widget_destroy (GTK_WIDGET (dialog));
+	  g_object_unref (G_OBJECT (im));
 	  return;
 	}
       glide_stage_manager_add_actor (window->priv->manager, GLIDE_ACTOR (im));



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