[glide] Slide backgrounds are now packed in archive
- From: Robert Carr <racarr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glide] Slide backgrounds are now packed in archive
- Date: Tue, 27 Apr 2010 04:12:03 +0000 (UTC)
commit 5ccbcbb0b1ecbe74baee841d9067b120f3b6c7c2
Author: Robert Carr <racarr Valentine localdomain>
Date: Tue Apr 27 00:00:22 2010 -0400
Slide backgrounds are now packed in archive
src/glide-actor.c | 12 ++++++++
src/glide-actor.h | 3 ++
src/glide-document.c | 65 ++++++++++++++++++++++++++++++--------------
src/glide-document.h | 3 ++
src/glide-slide.c | 10 +++++-
src/glide-stage-manager.c | 6 ++++
6 files changed, 76 insertions(+), 23 deletions(-)
---
diff --git a/src/glide-actor.c b/src/glide-actor.c
index cd3734c..dfb603e 100644
--- a/src/glide-actor.c
+++ b/src/glide-actor.c
@@ -272,3 +272,15 @@ glide_actor_get_undo_manager (GlideActor *actor)
{
return glide_stage_manager_get_undo_manager (actor->priv->manager);
}
+
+gchar *
+glide_actor_add_resource (GlideActor *actor, const gchar *filename)
+{
+ return glide_document_add_resource (glide_stage_manager_get_document (glide_actor_get_stage_manager (actor)), filename);
+}
+
+gchar *
+glide_actor_get_resource_path (GlideActor *actor, const gchar *resource_name)
+{
+ return glide_document_get_resource_path (glide_stage_manager_get_document (glide_actor_get_stage_manager (actor)), resource_name);
+}
diff --git a/src/glide-actor.h b/src/glide-actor.h
index aa4117f..85129a0 100644
--- a/src/glide-actor.h
+++ b/src/glide-actor.h
@@ -95,6 +95,9 @@ GlideUndoManager *glide_actor_get_undo_manager (GlideActor *actor);
void glide_actor_print (GlideActor *actor, cairo_t *cr);
+gchar *glide_actor_add_resource (GlideActor *actor, const gchar *filename);
+gchar *glide_actor_get_resource_path (GlideActor *actor, const gchar *resource_name);
+
G_END_DECLS
diff --git a/src/glide-document.c b/src/glide-document.c
index a1c712f..7555f7e 100644
--- a/src/glide-document.c
+++ b/src/glide-document.c
@@ -24,6 +24,8 @@
#include <girepository.h>
#include <glib/gstdio.h>
+#include <gio/gio.h>
+
#include "glide-debug.h"
#include "glide-slide.h"
@@ -40,8 +42,7 @@ enum {
PROP_PATH,
PROP_WIDTH,
PROP_HEIGHT,
- PROP_DIRTY,
- PROP_WORKING_PATH
+ PROP_DIRTY
};
#define DEFAULT_PRESENTATION_WIDTH 800
@@ -86,9 +87,6 @@ glide_document_get_property (GObject *object,
case PROP_PATH:
g_value_set_string (value, document->priv->path);
break;
- case PROP_WORKING_PATH:
- g_value_set_string (value, document->priv->working_path);
- break;
case PROP_WIDTH:
g_value_set_int (value, document->priv->width);
break;
@@ -134,11 +132,6 @@ glide_document_set_property (GObject *object,
case PROP_DIRTY:
glide_document_set_dirty (document, g_value_get_boolean (value));
break;
- case PROP_WORKING_PATH:
- if (document->priv->working_path)
- g_free (document->priv->working_path);
- document->priv->working_path = g_value_dup_string (value);
- break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -171,16 +164,6 @@ glide_document_class_init (GlideDocumentClass *klass)
G_PARAM_STATIC_STRINGS |
G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class, PROP_WORKING_PATH,
- g_param_spec_string ("working-path",
- "Working Path",
- "The working path containing the extracted"
- " document",
- NULL,
- G_PARAM_READWRITE |
- G_PARAM_STATIC_STRINGS |
- G_PARAM_CONSTRUCT_ONLY));
-
g_object_class_install_property (object_class, PROP_WIDTH,
g_param_spec_int ("width",
"Width",
@@ -242,9 +225,11 @@ glide_document_class_init (GlideDocumentClass *klass)
static void
glide_document_make_working_dir (GlideDocument *d)
{
- gchar *wdir;
+ gchar *wdir, *rdir;
wdir = g_strdup_printf("%s/glide-%ld", g_get_tmp_dir(), time(NULL));
+ rdir = g_strdup_printf("%s/resources", wdir);
g_mkdir(wdir, 0700);
+ g_mkdir(rdir, 0700);
if (d->priv->working_path)
g_free (d->priv->working_path);
@@ -252,6 +237,7 @@ glide_document_make_working_dir (GlideDocument *d)
d->priv->working_path = g_strdup (wdir);
g_free (wdir);
+ g_free (rdir);
}
@@ -259,6 +245,8 @@ static void
glide_document_init (GlideDocument *d)
{
d->priv = GLIDE_DOCUMENT_GET_PRIVATE (d);
+
+ glide_document_make_working_dir (d);
}
GlideDocument *
@@ -513,3 +501,38 @@ glide_document_load_archive (GlideDocument *d,
return p;
}
+//TODO: Name sanitization
+gchar *
+glide_document_add_resource (GlideDocument *d, const gchar *filename)
+{
+ GFile *from, *to;
+ gchar *basename, *to_path;
+
+ if (!g_path_is_absolute (filename))
+ return g_strdup (filename);
+
+ basename = g_path_get_basename (filename);
+ to_path = g_strdup_printf("%s/resources/%s", d->priv->working_path,
+ basename);
+
+ from = g_file_new_for_path (filename);
+ to = g_file_new_for_path (to_path);
+
+ // TODO: Error
+ g_file_copy (from, to, 0, NULL, NULL, NULL, NULL);
+
+ g_free (to_path);
+
+ g_object_unref (G_OBJECT (from));
+ g_object_unref (G_OBJECT (to));
+
+ return basename;
+}
+
+gchar *
+glide_document_get_resource_path (GlideDocument *d,
+ const gchar *resource_name)
+{
+ return g_strdup_printf("%s/resources/%s",d->priv->working_path,
+ resource_name);
+}
diff --git a/src/glide-document.h b/src/glide-document.h
index b9cedde..1eaa71b 100644
--- a/src/glide-document.h
+++ b/src/glide-document.h
@@ -101,6 +101,9 @@ void glide_document_write_json (GlideDocument *d);
JsonParser *glide_document_load_archive (GlideDocument *d,
const gchar *filename);
+gchar *glide_document_add_resource (GlideDocument *d, const gchar *filename);
+gchar *glide_document_get_resource_path (GlideDocument *d, const gchar *resource_name);
+
G_END_DECLS
#endif /* __GLIDE_DOCUMENT_H__ */
diff --git a/src/glide-slide.c b/src/glide-slide.c
index fe4df92..53c20b3 100644
--- a/src/glide-slide.c
+++ b/src/glide-slide.c
@@ -693,17 +693,23 @@ glide_slide_material_for_file (const gchar *filename)
void
glide_slide_set_background (GlideSlide *slide, const gchar *background)
{
+ gchar *resource, *resource_file;
if (!background)
return;
if (slide->priv->background)
g_free (slide->priv->background);
- slide->priv->background = g_strdup (background);
+ resource = glide_actor_add_resource (GLIDE_ACTOR (slide), background);
+ slide->priv->background = resource;
+
+ resource_file = glide_actor_get_resource_path (GLIDE_ACTOR (slide), resource);
if (slide->priv->background_material)
cogl_handle_unref (slide->priv->background_material);
- slide->priv->background_material = glide_slide_material_for_file (background);
+ slide->priv->background_material = glide_slide_material_for_file (resource_file);
+
+ g_free (resource_file);
g_object_notify (G_OBJECT (slide), "background");
diff --git a/src/glide-stage-manager.c b/src/glide-stage-manager.c
index b45cae0..9c95eee 100644
--- a/src/glide-stage-manager.c
+++ b/src/glide-stage-manager.c
@@ -898,3 +898,9 @@ glide_stage_manager_get_undo_manager (GlideStageManager *manager)
{
return manager->priv->undo_manager;
}
+
+GlideDocument *
+glide_stage_manager_get_document (GlideStageManager *manager)
+{
+ return manager->priv->document;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]