[glide] .glide files are now archives...



commit 6d919fcce9feedbe6e24f7affc2627865d5653cb
Author: Robert Carr <racarr Valentine localdomain>
Date:   Mon Apr 26 22:43:57 2010 -0400

    .glide files are now archives...

 configure.ac              |    1 +
 src/Makefile.am           |    5 +-
 src/glide-document-priv.h |    1 +
 src/glide-document.c      |  129 +++++++++++++++++++++++++++++++++++++++++++-
 src/glide-document.h      |    6 ++
 src/glide-window.c        |   52 ++++++------------
 6 files changed, 153 insertions(+), 41 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 9d4718c..4d121ec 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,6 +36,7 @@ PKG_CHECK_MODULES(GTK, [gtk+-2.0 >= 2.12    ])
 PKG_CHECK_MODULES(CLUTTER, [clutter-1.0 >= 1.2])
 PKG_CHECK_MODULES(CLUTTER_GTK, [clutter-gtk-0.90])
 PKG_CHECK_MODULES(JSON_GLIB, json-glib-1.0)
+PKG_CHECK_MODULES(GOBJECT_INTROSPECTION, gobject-introspection-1.0)
 PKG_CHECK_MODULES(GMODULE, gmodule-2.0)
 
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 1748277..532faf1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,9 +55,8 @@ glide_SOURCES = \
 	glide-pdf-exporter.c \
 	glide-pdf-exporter.h \
 	glide-cairo-util.c \
-	glide-cairo-util.h \
-	glide-png-exporter.c \
-	glide-png-exporter.h
+	glide-cairo-util.h 
+
 
 glide_LDFLAGS = \
 	-Wl,--export-dynamic
diff --git a/src/glide-document-priv.h b/src/glide-document-priv.h
index e281696..1b8588b 100644
--- a/src/glide-document-priv.h
+++ b/src/glide-document-priv.h
@@ -30,6 +30,7 @@ struct _GlideDocumentPrivate
 
   gchar *name;
   gchar *path;
+  gchar *working_path;
   
   gint width, height;
   gboolean dirty;
diff --git a/src/glide-document.c b/src/glide-document.c
index 80d08b2..a1c712f 100644
--- a/src/glide-document.c
+++ b/src/glide-document.c
@@ -16,16 +16,20 @@
  * with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <stdlib.h>
  
 #include "glide-document.h"
 #include "glide-document-priv.h"
 
 #include <girepository.h>
+#include <glib/gstdio.h>
 
 #include "glide-debug.h"
 
 #include "glide-slide.h"
 
+#include "glide-gtk-util.h"
+
 G_DEFINE_TYPE(GlideDocument, glide_document, G_TYPE_OBJECT)
 
 #define GLIDE_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GLIDE_TYPE_DOCUMENT, GlideDocumentPrivate))
@@ -36,7 +40,8 @@ enum {
   PROP_PATH,
   PROP_WIDTH,
   PROP_HEIGHT,
-  PROP_DIRTY
+  PROP_DIRTY,
+  PROP_WORKING_PATH
 };
 
 #define DEFAULT_PRESENTATION_WIDTH 800
@@ -81,6 +86,9 @@ 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;
@@ -126,6 +134,11 @@ 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;
@@ -158,6 +171,16 @@ 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",
@@ -217,11 +240,25 @@ glide_document_class_init (GlideDocumentClass *klass)
 }
 
 static void
+glide_document_make_working_dir (GlideDocument *d)
+{
+  gchar *wdir;
+  wdir = g_strdup_printf("%s/glide-%ld", g_get_tmp_dir(), time(NULL));
+  g_mkdir(wdir, 0700);
+ 
+  if (d->priv->working_path)
+    g_free (d->priv->working_path);
+
+  d->priv->working_path = g_strdup (wdir);
+
+  g_free (wdir);
+}
+
+
+static void
 glide_document_init (GlideDocument *d)
 {
   d->priv = GLIDE_DOCUMENT_GET_PRIVATE (d);
-  
-  //  glide_document_add_slide (d);
 }
 
 GlideDocument *
@@ -244,6 +281,12 @@ glide_document_get_path (GlideDocument *document)
   return document->priv->path;
 }
 
+const gchar *
+glide_document_get_working_path (GlideDocument *document)
+{
+  return document->priv->working_path;
+}
+
 void
 glide_document_set_path (GlideDocument *document, const gchar *path)
 {
@@ -390,3 +433,83 @@ glide_document_set_dirty (GlideDocument *d, gboolean dirty)
   d->priv->dirty = dirty;
   g_object_notify (G_OBJECT (d), "dirty");
 }
+
+void
+glide_document_write_archive (GlideDocument *d)
+{
+  gchar *command = g_strdup_printf("tar -cjspf %s %s",
+				   d->priv->path,
+				   d->priv->working_path);
+  g_message("command %s", command);
+  
+  system (command);
+}
+
+void
+glide_document_write_json (GlideDocument *d)
+{
+  JsonNode *node;
+  JsonGenerator *gen;
+  gchar *json_path;
+  
+  node = glide_document_serialize (d);
+  gen = json_generator_new ();
+  g_object_set (gen, "pretty", TRUE, NULL);
+  
+  json_generator_set_root (gen, node);
+  
+  if (!d->priv->working_path)
+    glide_document_make_working_dir (d);
+  json_path = g_strdup_printf("%s/document.json",d->priv->working_path);
+  
+  // TODO: Error
+  json_generator_to_file (gen, json_path, NULL);
+  
+  g_free (json_path);
+}
+
+static void
+glide_document_extract_archive (GlideDocument *d,
+				const gchar *filename)
+{
+  gchar *command = g_strdup_printf ("tar --strip-components=2 -xjf %s -C %s",
+				    filename, d->priv->working_path);
+  
+  system(command);
+  g_free (command);
+}
+
+JsonParser *
+glide_document_load_archive (GlideDocument *d,
+			     const gchar *filename)
+{
+  JsonParser *p = json_parser_new ();
+  GError *e = NULL;
+  gchar *json_file;
+
+  glide_document_make_working_dir (d);
+  glide_document_extract_archive (d, filename);
+  
+  json_file = g_strdup_printf("%s/document.json",d->priv->working_path);
+
+  json_parser_load_from_file (p, json_file, &e);
+  if (e)
+    {
+      gchar *sec = g_strdup_printf ("Failed to load the document: %s", filename);
+      g_warning("Error loading file: %s", e->message);
+
+      glide_gtk_util_show_error_dialog ("Failed to load document", sec);
+					
+      g_error_free (e);
+      g_object_unref (G_OBJECT (p));
+      g_free (json_file);
+      
+      return NULL;
+    }
+  g_free (json_file);
+  
+  glide_document_set_path (d, filename);
+  
+  return p;
+}
+
diff --git a/src/glide-document.h b/src/glide-document.h
index 43f9da5..b9cedde 100644
--- a/src/glide-document.h
+++ b/src/glide-document.h
@@ -95,6 +95,12 @@ void glide_document_resize (GlideDocument *document, gint width, gint height);
 gboolean glide_document_get_dirty (GlideDocument *d);
 void glide_document_set_dirty (GlideDocument *d, gboolean dirty);
 
+void glide_document_write_archive (GlideDocument *d);
+void glide_document_write_json (GlideDocument *d);
+
+JsonParser *glide_document_load_archive (GlideDocument *d,
+					 const gchar *filename);
+
 G_END_DECLS
 
 #endif  /* __GLIDE_DOCUMENT_H__  */
diff --git a/src/glide-window.c b/src/glide-window.c
index 3742d35..ca19ab8 100644
--- a/src/glide-window.c
+++ b/src/glide-window.c
@@ -39,7 +39,7 @@
 #include "glide-dirs.h"
 
 #include "glide-pdf-exporter.h"
-#include "glide-png-exporter.h"
+//#include "glide-png-exporter.h"
 
 #define GLIDE_WINDOW_UI_OBJECT(w, obj) (gtk_builder_get_object (w->priv->builder, obj))
 
@@ -493,33 +493,24 @@ void
 glide_window_open_document (GlideWindow *window,
 			    const gchar *filename)
 {
-  JsonParser *p = json_parser_new ();
-  GError *e = NULL;
+  JsonParser *p;
   JsonNode *root, *slide_n;
   JsonArray *slide_array;
   JsonObject *root_obj;
 
-  json_parser_load_from_file (p, filename, &e);
-  if (e)
-    {
-      gchar *sec = g_strdup_printf ("Failed to load the document: %s", filename);
-      g_warning("Error loading file: %s", e->message);
-
-      glide_gtk_util_show_error_dialog ("Failed to load document", sec);
-					
-      g_error_free (e);
-      g_free (sec);
-      g_object_unref (G_OBJECT (p));
-      
-      return;
-    }
+  glide_window_set_document (window, 
+			     glide_document_new (filename));
+
+  p = glide_document_load_archive (window->priv->document,
+				   filename);
+  
+  // TODO: Free document..
+  if (!p)
+    return;
+
   root = json_parser_get_root (p);
   root_obj = json_node_get_object (root);
 
-  glide_window_set_document (window, glide_document_new (glide_json_object_get_string (root_obj, "name")));
-  glide_document_set_path (window->priv->document, filename);
-
-  
   slide_n = json_object_get_member (root_obj, "slides");
   slide_array = json_node_get_array (slide_n);
   
@@ -1172,22 +1163,13 @@ static void
 glide_window_save_document_real (GlideWindow *w,
 				 const gchar *filename)
 {
-  JsonNode *node;
-  JsonGenerator *gen;
-  
-  node = glide_document_serialize (w->priv->document);
-  
-  gen = json_generator_new ();
-  g_object_set (gen, "pretty", TRUE, NULL);
-  
-  json_generator_set_root (gen, node);
-  
-  // TODO: Error
-  json_generator_to_file (gen, filename, NULL);
+  glide_document_write_json (w->priv->document);
 
   glide_document_set_dirty (w->priv->document, FALSE);
   glide_document_set_path (w->priv->document, filename);
   
+  glide_document_write_archive (w->priv->document);
+  
   // Maybe gets called twice?
   glide_window_update_title (w);
 }
@@ -1391,9 +1373,9 @@ void
 glide_window_export_png_action_activate (GtkAction *action,
 					 gpointer user_data)
 {
-  GlideWindow *w = (GlideWindow *)user_data;
+  //  GlideWindow *w = (GlideWindow *)user_data;
   
-  glide_png_exporter_export (w->priv->document);
+  //  glide_png_exporter_export (w->priv->document);
 }
 
 



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