[ease/themes] broken, don't push
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/themes] broken, don't push
- Date: Fri, 23 Jul 2010 23:48:48 +0000 (UTC)
commit 2499c26f290b76a485898cbc59346b483bd2d007
Author: Nate Stedman <natesm gmail com>
Date: Fri Jul 23 18:38:27 2010 -0400
broken, don't push
src/ease-document.vala | 10 +++++++-
src/ease-temp.vala | 55 +++++++++++++++++++++++++++++++++++------------
src/ease-theme.vala | 54 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 104 insertions(+), 15 deletions(-)
---
diff --git a/src/ease-document.vala b/src/ease-document.vala
index 37e3072..9e1f680 100644
--- a/src/ease-document.vala
+++ b/src/ease-document.vala
@@ -32,6 +32,11 @@ public class Ease.Document : SlideSet
* The default master slide for the first slide.
*/
private const string DEFAULT_FIRST = Theme.TITLE;
+
+ /**
+ * Path of the Document's { link Theme} data files.
+ */
+ private const string THEME_PATH = "theme";
/**
* The { link Theme} linked to this Document.
@@ -83,13 +88,16 @@ public class Ease.Document : SlideSet
{
assert(doc_theme != null);
+ // set the document's dimensions
width = w;
height = h;
- theme = doc_theme;
// allocate a temp directory for the new document
path = Temp.request();
+ // copy the theme to a path within the document
+ theme = doc_theme.copy_to_path(Path.build_filename(path, THEME_PATH));
+
// copy media to the new path
theme.copy_media(path);
diff --git a/src/ease-temp.vala b/src/ease-temp.vala
index eae9325..8240da3 100644
--- a/src/ease-temp.vala
+++ b/src/ease-temp.vala
@@ -195,23 +195,44 @@ public static class Ease.Temp : Object
}
// add files
+ archive_recursive_write(archive, dir, buffer, "", temp_path);
+
+ // close the archive
+ arc_fail(archive.close(), archive);
+ }
+
+ private static void archive_recursive_write(Archive.Write archive,
+ Dir dir,
+ char[] buffer,
+ string path_so_far,
+ string temp_path) throws Error
+ {
string child_path;
while ((child_path = dir.read_name()) != null)
{
+ debug(child_path);
var child_full_path = Path.build_filename(temp_path, child_path);
- if (!FileUtils.test(child_full_path, FileTest.IS_DIR))
+
+ var entry = new Archive.Entry();
+ entry.set_pathname(Path.build_path(path_so_far, child_path));
+ entry.set_perm(0644);
+ Posix.Stat st;
+ Posix.stat(child_full_path, out st);
+ entry.copy_stat(st);
+ arc_fail(archive.write_header(entry), archive);
+
+ if (FileUtils.test(child_full_path, FileTest.IS_DIR))
+ {
+ arc_fail(archive.finish_entry(), archive);
+ var child_dir = GLib.Dir.open(child_full_path, 0);
+ archive_recursive_write(archive, child_dir, buffer,
+ Path.build_path(path_so_far,
+ child_path),
+ temp_path);
+ }
+ else
{
- // set up the entry
- var entry = new Archive.Entry();
- entry.set_pathname(child_path);
- Posix.Stat st;
- Posix.stat(child_full_path, out st);
- entry.set_size(st.st_size);
- entry.set_filetype(0100000);
- entry.set_perm(0644);
-
// write the file
- archive.write_header(entry);
var fd = Posix.open(child_full_path, Posix.O_RDONLY);
var len = Posix.read(fd, buffer, sizeof(char) * ARCHIVE_BUFFER);
while(len > 0)
@@ -220,11 +241,17 @@ public static class Ease.Temp : Object
len = Posix.read(fd, buffer, sizeof(char) * ARCHIVE_BUFFER);
}
Posix.close(fd);
+ arc_fail(archive.finish_entry(), archive);
}
}
-
- // close the archive
- archive.close();
+ }
+
+ /**
+ * Produces an error if a libarchive error occurs.
+ */
+ private static void arc_fail(Archive.Result result, Archive.Archive archive)
+ {
+ if (result != Archive.Result.OK) error(archive.error_string());
}
/**
diff --git a/src/ease-theme.vala b/src/ease-theme.vala
index 6f98d0c..4f3b973 100644
--- a/src/ease-theme.vala
+++ b/src/ease-theme.vala
@@ -42,6 +42,19 @@ public class Ease.Theme : GLib.Object
public const string MEDIA = "media";
public const string MEDIA_HEADER = "media-header";
+ /**
+ * String identifiers for all master slides available in Ease.
+ */
+ public const string[] MASTER_SLIDES = {
+ TITLE,
+ CONTENT,
+ CONTENT_HEADER,
+ CONTENT_DUAL,
+ CONTENT_DUAL_HEADER,
+ MEDIA,
+ MEDIA_HEADER
+ };
+
// master slide properties
public const string BACKGROUND_COLOR = "background-color";
public const string S_IDENTIFIER = "slide-identifier";
@@ -178,6 +191,47 @@ public class Ease.Theme : GLib.Object
}
/**
+ * Creates a "shallow" copy of a Theme.
+ *
+ * This constructor does not copy any data from the provided Theme. It
+ * instead creates a new set of references to the same data.
+ *
+ * @param copy_from The Theme to copy from.
+ */
+ private Theme.copy(Theme copy_from)
+ {
+ // note that this doesn't duplicate the maps
+ masters = copy_from.masters;
+ elements = copy_from.elements;
+ master_defaults = copy_from.master_defaults;
+ element_defaults = copy_from.element_defaults;
+ title = copy_from.title;
+ path = copy_from.path;
+ }
+
+ /**
+ * Copies a Theme's data files to a specified path, returning a Theme
+ * pointing to those files.
+ *
+ * This method uses the private Theme.copy() constructor. This constructor
+ * performs a shallow copy - thus, the Gee.Maps holding the Theme's data
+ * are the same for both themes. This is OK, because Themes should never be
+ * modified after they are first loaded.
+ *
+ * @param copy_to The path to copy the Theme to.
+ */
+ public Theme copy_to_path(string copy_to)
+ {
+ // copy data files
+ Posix.system("cp -r %s %s".printf(path, copy_to));
+
+ // create a copy of this theme and change its path
+ var theme = new Theme.copy(this);
+ theme.path = copy_to;
+ return theme;
+ }
+
+ /**
* Loads a Theme's information from JSON
*
* This function is used to load the defaults and to load each
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]