[ease/themes] [themes] Fixed build (can't actually run)
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/themes] [themes] Fixed build (can't actually run)
- Date: Wed, 21 Jul 2010 18:02:05 +0000 (UTC)
commit 775eba6603b52b85066ccd0e6db4042445348d69
Author: Nate Stedman <natesm gmail com>
Date: Wed Jul 21 14:01:28 2010 -0400
[themes] Fixed build (can't actually run)
src/ease-document.vala | 22 ++++++++----
src/ease-editor-window.vala | 10 ++---
src/ease-theme.vala | 76 +++++++++++++++++++++++++++--------------
src/ease-welcome-window.vala | 7 ++--
4 files changed, 71 insertions(+), 44 deletions(-)
---
diff --git a/src/ease-document.vala b/src/ease-document.vala
index d941f18..d9580c7 100644
--- a/src/ease-document.vala
+++ b/src/ease-document.vala
@@ -18,7 +18,7 @@
/**
* The internal representation of Ease documents. Contains { link Slide}s.
*
- * The Ease Document class is generated from XML and writes back to XML
+ * The Ease Document class is generated from JSON and writes back to JSON
* when saved.
*/
public class Ease.Document : SlideSet
@@ -26,7 +26,12 @@ public class Ease.Document : SlideSet
/**
* The default master title for newly created { link Slide}s.
*/
- private const string DEFAULT_SLIDE = "Standard";
+ public const string DEFAULT_SLIDE = Theme.CONTENT_HEADER;
+
+ /**
+ * The default master slide for the first slide.
+ */
+ private const string DEFAULT_FIRST = Theme.TITLE;
/**
* The { link Theme} linked to this Document.
@@ -65,21 +70,22 @@ public class Ease.Document : SlideSet
*/
public Document.from_theme(Theme doc_theme, int w, int h) throws GLib.Error
{
+ assert(doc_theme != null);
+
width = w;
height = h;
theme = doc_theme;
- assert (doc_theme != null);
// allocate a temp directory for the new document
path = Temp.request();
// copy media to the new path
- doc_theme.copy_media(path);
- // get the master
- var master = theme.slide_by_title(DEFAULT_SLIDE);
+ theme.copy_media(path);
- // add the first slide
- append_slide(new Slide.from_master(master, this, width, height, true));
+ // get the master for the first slide
+ var slide = theme.create_slide(DEFAULT_FIRST, width, height);
+ slide.parent = this;
+ append_slide(slide);
}
/**
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index ab09c3b..a63b931 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -236,17 +236,15 @@ public class Ease.EditorWindow : Gtk.Window
[CCode (instance_pos = -1)]
public void new_slide_handler(Gtk.Widget? sender)
{
- var master = document.theme.slide_by_title(slide.title);
-
- var slide = new Slide.from_master(master, document,
- document.width,
- document.height, true);
+ var slide = document.theme.create_slide(document.DEFAULT_SLIDE,
+ document.width,
+ document.height);
var index = document.index_of(slide) + 1;
document.add_slide(index, slide);
slide_button_panel.add_slide(index, slide);
- }
+ }
[CCode (instance_pos = -1)]
public void play_handler(Gtk.Widget sender)
diff --git a/src/ease-theme.vala b/src/ease-theme.vala
index ecdc6a7..f45ff4b 100644
--- a/src/ease-theme.vala
+++ b/src/ease-theme.vala
@@ -20,8 +20,12 @@
*/
public class Ease.Theme : GLib.Object
{
- // json file
+ // file paths
private const string DEFAULTS_PATH = "theme-defaults.json";
+ private const string JSON_PATH = "Theme.json";
+ private const string MEDIA_PATH = "Media";
+
+ // json root elements
private const string MASTERS = "masters";
private const string ELEMENTS = "elements";
private const string MASTER_DEF = "master-defaults";
@@ -60,7 +64,12 @@ public class Ease.Theme : GLib.Object
/**
* The title of the Theme.
*/
- public string title { get; set; }
+ public string title;
+
+ /**
+ * The path to the theme's extracted files.
+ */
+ public string path { get; set; }
/**
* A map of internal master slide settings overriden by the theme.
@@ -110,32 +119,30 @@ public class Ease.Theme : GLib.Object
/**
* Creates an empty Theme.
*
- * @param path The path to the theme's JSON file.
+ * @param path The path to the theme's archive.
*/
- public Theme(string path)
+ public Theme(string archive_path)
{
- // create collections
- masters = new Gee.HashMap<string, Gee.Map<string, string>>();
- elements = new Gee.HashMap<string, Gee.Map<string, string>>();
- master_defaults = new Gee.HashMap<string, string>();
- element_defaults = new Gee.HashMap<string, string>();
-
+ // extract the theme & load the theme's json parser into a json parser
var parser = new Json.Parser();
- try { parser.load_from_file(path); }
+ try
+ {
+ path = Temp.extract(archive_path);
+ parser.load_from_file(Path.build_filename(path, JSON_PATH));
+ }
catch (GLib.Error e)
{
- if (path == DEFAULTS_PATH)
- {
- error(_("Could not load theme defaults: %s"), e.message);
- }
- else
- {
- error_dialog(_("Error Loading Theme"),
- (_("Error loading theme: %s\n\n") + e.message).
- printf(path));
- }
+ error_dialog(_("Error Loading Theme"),
+ (_("Error loading theme: %s\n\n") + e.message).
+ printf(path));
+ return;
}
+ // create collections
+ masters = new Gee.HashMap<string, Gee.Map<string, string>>();
+ elements = new Gee.HashMap<string, Gee.Map<string, string>>();
+ master_defaults = new Gee.HashMap<string, string>();
+ element_defaults = new Gee.HashMap<string, string>();
// get the document's root element
var root = parser.get_root().get_object();
@@ -147,6 +154,21 @@ public class Ease.Theme : GLib.Object
fill_single_map(root.get_object_member(ELEMENT_DEF), element_defaults);
}
+ /**
+ * Copies all files under Media/ to a new directory.
+ *
+ * @param target The path to copy media files to.
+ */
+ public void copy_media(string target) throws GLib.Error
+ {
+ var origin_path = Path.build_filename(path, MEDIA_PATH);
+
+ var target_path = Path.build_filename(target, MEDIA_PATH);
+
+ // TODO: non-system implementation of recursive copy
+ Posix.system("cp -r %s %s".printf(origin_path, target_path));
+ }
+
public Slide? create_slide(string master, int width, int height)
{
Slide slide = new Slide();
@@ -174,8 +196,7 @@ public class Ease.Theme : GLib.Object
width - left - element_get(AUTHOR_TEXT, PAD_RIGHT).to_int(),
element_get(AUTHOR_TEXT, HEIGHT).to_int()
));
-
- return slide;
+ break;
case CONTENT:
int left = element_get(CONTENT_TEXT, PAD_LEFT).to_int(),
@@ -188,6 +209,7 @@ public class Ease.Theme : GLib.Object
width - left - element_get(CONTENT_TEXT, PAD_RIGHT).to_int(),
height - top - element_get(HEADER_TEXT, PAD_BOTTOM).to_int()
));
+ break;
case CONTENT_HEADER:
// create the slide's header
@@ -213,17 +235,19 @@ public class Ease.Theme : GLib.Object
width - left - element_get(CONTENT_TEXT, PAD_RIGHT).to_int(),
height - top - element_get(HEADER_TEXT, PAD_BOTTOM).to_int()
));
-
- return slide;
+ break;
case CONTENT_DUAL:
case CONTENT_DUAL_HEADER:
case MEDIA:
case MEDIA_HEADER:
break;
+ default:
+ error(_("Invalid master slide title: %s"), master);
+ return null;
}
- error(_("Invalid master slide title."));
+ return slide;
}
/**
diff --git a/src/ease-welcome-window.vala b/src/ease-welcome-window.vala
index eb65ee3..cc95bbe 100644
--- a/src/ease-welcome-window.vala
+++ b/src/ease-welcome-window.vala
@@ -197,19 +197,18 @@ public class Ease.WelcomeWindow : Gtk.Window
string name = directory.read_name ();
while (name != null) {
var path = Path.build_filename (filename, name);
- // FIXME : warning occurs here (g_param_spec)
- themes.add (JSONParser.theme (path));
+ themes.add (new Theme(path));
name = directory.read_name ();
}
}
}
} catch (Error e) {
error_dialog("Error loading themes : %s", e.message);
- }
+ }
// create the previews
foreach (var theme in themes) {
- var master = theme.slide_by_title (PREVIEW_ID);
+ var master = theme.create_slide(PREVIEW_ID, 1024, 768);
if (master == null) continue;
var act = new WelcomeActor (theme, previews, master);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]