[ease/serialize: 4/52] Stopping for now, rewriting ease in python
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/serialize: 4/52] Stopping for now, rewriting ease in python
- Date: Tue, 22 Feb 2011 22:57:06 +0000 (UTC)
commit 979830f05fc60f07d67d105e0a112eeb2d44ee01
Author: Nate Stedman <natesm gmail com>
Date: Fri Nov 26 23:58:10 2010 -0500
Stopping for now, rewriting ease in python
ease-core/ease-document.vala | 56 +++++++++------------------------------
ease-core/ease-serializer.vala | 14 +++++++---
ease/ease-main.vala | 4 +-
3 files changed, 25 insertions(+), 49 deletions(-)
---
diff --git a/ease-core/ease-document.vala b/ease-core/ease-document.vala
index 7a9492f..d5ec87a 100644
--- a/ease-core/ease-document.vala
+++ b/ease-core/ease-document.vala
@@ -169,43 +169,27 @@ public class Ease.Document : GLib.Object, UndoSource, Serializable
*/
public signal void slide_added(Slide slide, int index);
- public Document.from_saved(string file_path) throws GLib.Error
+ public static Document from_saved(string file_path) throws GLib.Error
{
- this();
-
- filename = absolute_path(file_path);
- path = Archiver.extract(filename);
+ // extract the .ease archive
+ var filename = absolute_path(file_path);
+ var path = Archiver.extract(filename);
+ // load the json file
var parser = new Json.Parser();
-
- // attempt to load the file
parser.load_from_file(Path.build_filename(path, JSON_FILE));
// grab the root object
var root = parser.get_root().get_object();
- // set document properties
- width = (int)root.get_string_member("width").to_int();
- height = (int)root.get_string_member("height").to_int();
-
- // add all slides
- var json_slides = root.get_array_member("slides");
-
- for (var i = 0; i < json_slides.get_length(); i++)
- {
- var node = json_slides.get_object_element(i);
- append_slide(new Slide.from_json(node, this));
- }
+ // deserialize the document
+ var document = Serializer.read(root) as Document;
- // get the document's theme
- var theme_path = Path.build_filename(THEME_PATH, Theme.JSON_PATH);
- var theme_full_path = Path.build_filename(path, theme_path);
+ // set other properties
+ document.filename = filename;
+ document.path = path;
- if (File.new_for_path(theme_full_path).query_exists(null))
- {
- theme = new Theme.json(theme_full_path);
- theme.path = theme_full_path;
- }
+ return document;
}
/**
@@ -250,22 +234,8 @@ public class Ease.Document : GLib.Object, UndoSource, Serializable
{
// create the json base
var root = new Json.Node(Json.NodeType.OBJECT);
- var obj = new Json.Object();
-
- // set basic document properties
- obj.set_string_member("width", width.to_string());
- obj.set_string_member("height", height.to_string());
-
- // add the document's slides
- var slides_json = new Json.Array();
- Slide s;
- foreach (var itr in slides)
- {
- slides.get(itr, COL_SLIDE, out s);
- slides_json.add_element(s.to_json());
- }
- obj.set_array_member("slides", slides_json);
-
+ var obj = Serializer.write(this);
+
// set the root object
root.set_object(obj);
diff --git a/ease-core/ease-serializer.vala b/ease-core/ease-serializer.vala
index f5f83b5..f5eda33 100644
--- a/ease-core/ease-serializer.vala
+++ b/ease-core/ease-serializer.vala
@@ -198,10 +198,12 @@ public static class Ease.Serializer
{
// create the object with the type that TYPE_KEY specifies
var type = GLib.Type.from_name(json.get_string_member(TYPE_KEY));
- var object = new GLib.Object(type, null);
+ var object = GLib.Object.newv(type, {});
// deserialize all properties
json.foreach_member((jobj, property, node) => {
+ if (property == TYPE_KEY) return;
+
// if the object implements Serializable, allow custom behavior
if (object is Serializable)
{
@@ -211,7 +213,11 @@ public static class Ease.Serializer
}
// get a paramspec for the property to deserialize into
- var pspec = object.get_class().find_property(property);
+ var klass = object.get_class();
+ debug("asdf %p", klass);
+ var pspec = klass.find_property(property);
+
+ if (pspec == null) debug("Well, fuck.");
// create a GValue to serialize into
GLib.Value val = GLib.Value(pspec.value_type);
@@ -283,12 +289,12 @@ public static class Ease.Serializer
val = json.get_int_member(property);
}
- /*if (pspec.value_type == typeof(int16))
+ /*else if (pspec.value_type == typeof(int16))
{
val = json.get_int_member(property);
}
- if (pspec.value_type == typeof(uint16))
+ else if (pspec.value_type == typeof(uint16))
{
val = json.get_int_member(property);
}*/
diff --git a/ease/ease-main.vala b/ease/ease-main.vala
index ddfdeb8..6a7d937 100644
--- a/ease/ease-main.vala
+++ b/ease/ease-main.vala
@@ -212,7 +212,7 @@ internal class Ease.Main : GLib.Object
try
{
- var doc = new Document.from_saved(path);
+ var doc = Document.from_saved(path);
var win = new EditorWindow(doc);
add_window(win);
win.show_now();
@@ -236,7 +236,7 @@ internal class Ease.Main : GLib.Object
}
try
{
- var doc = new Document.from_saved(file);
+ var doc = Document.from_saved(file);
player = new Player(doc);
// if requested, quit ease when done
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]