[ease/inspector] Support archiving and unarchiving Ease documents.
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/inspector] Support archiving and unarchiving Ease documents.
- Date: Wed, 9 Jun 2010 21:58:47 +0000 (UTC)
commit f0d051d4ca9a499c5e13b85788244dacef1f8f12
Author: Nate Stedman <natesm gmail com>
Date: Mon Jun 7 14:32:24 2010 -0400
Support archiving and unarchiving Ease documents.
.gitignore | 3 +
configure.ac | 3 +
.../Transitions}/Document.json | 0
examples/build.sh | 16 +++++
po/.intltool-merge-cache | 3 +
src/JSONParser.vala | 27 ++++++--
src/OpenDialog.vala | 8 ++-
src/SlideSet.vala | 10 ++-
src/Temp.vala | 70 ++++++++++++++++++--
9 files changed, 121 insertions(+), 19 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index a3f614b..4179925 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,9 @@ doc
# ignore theme packages
*.easetheme
+# ignore .ease files (for now at least)
+*.ease
+
# shamelessly copied from gnome-scan.
# autotools generated files
.dirstamp
diff --git a/configure.ac b/configure.ac
index 2134bb6..7dce48d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,4 +47,7 @@ AM_GNU_GETTEXT([external])
dnl Package Themes
AC_CONFIG_COMMANDS([build-themes], [sh themes/build.sh])
+dnl Package Example .ease files
+AC_CONFIG_COMMANDS([build-examples], [sh examples/build.sh])
+
AC_OUTPUT
diff --git a/Examples/Transitions.ease/Document.json b/examples/Transitions/Document.json
similarity index 100%
rename from Examples/Transitions.ease/Document.json
rename to examples/Transitions/Document.json
diff --git a/examples/build.sh b/examples/build.sh
new file mode 100755
index 0000000..57f94da
--- /dev/null
+++ b/examples/build.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+echo " Archiving example .ease files..."
+
+cd examples
+
+for DOC in `find ./* -maxdepth 0 -type d | sed "s/.\///g"`
+ do
+ echo " Archiving $DOC to $DOC.ease ..."
+ cd $DOC
+ tar -cf ../$DOC.ease `ls`
+ cd ..
+ done
+
+echo " Done archiving example .ease files."
+
diff --git a/po/.intltool-merge-cache b/po/.intltool-merge-cache
new file mode 100644
index 0000000..10799a2
--- /dev/null
+++ b/po/.intltool-merge-cache
@@ -0,0 +1,3 @@
+esNoneNingunadeError Copying FileFehler beim Kopieren der DateideEase presentation editorEase PräsentationsprogrammdeCustomBenutzerdefiniertdePanelPaneldeExport to HTMLNach HTML exportierenesPanelPanelesFadeDesvanecerslCustomPo merideInEinfrFadeFonduesRightDerechafrRightDroitedeBottom to TopVon unten nach obendeFileDateiesEffectEfectodeOutAusdeFadeÃ?berblendendeExporting as HTMLAls HTML exportierenfrUpHautfrDownBasesDownAbajoesDelayRetardodeThemeThemaslEffectUÄ?inekdeRevealEnthüllendeManuallyManuelldeTop to BottomVon oben nach untenesQuitSalirdeNewNeudeDirectionRichtungslThemeTemaslQuitKonÄ?ajesThemeTemadeNoneKeineresFlipVolteardeSlatsLattenesNew PresentationPresentacioÌ?n nuevaesManuallyManualmenteesLeftIzquierdadeQuitBeendendeUpNach obendeSlideGleitendeCreate nice and elegant presentationsErstellen ansprechender und eleganter Präsentationen
dePresentationPräsentationdeYour browser does not support the video tagIhr Browser unterstützt die Video-Markierung nichtdeFallFallendeCenterZentrierendeSpin ContentsInhalt drehendeBottom LeftUnten linksdeDelayVerzögerungfrCreate nice and elegant presentationsCréez des présentations élégantesslFileDatotekadeError loading background: %sFehler beim Laden des Hintergrunds: %sesCenterCentraresUpArribadeError playing: %sFehler beim Abspielen: %sfr%i by %i%i par %ideSlide ContentsInhalt gleiten lassenesZoomAmpliacioÌ?ndeZoom ContentsInhalt vergröÃ?erndeDownNach untenesRevealMostraresOpenAbrirdeError ExportingFehler beim Exportierendeerror parsing options: %s
+Fehler beim Verarbeiten der Optionen: %s
+deOpenÃ?ffnenesCustomPersonalizadaesDropSoltaresPresentationPresentacioÌ?nslNewNovodeError PlayingFehler beim AbspielenesFallCaiÌ?dadeBottom RightUnten rechtsdeStart TransitionÃ?bergangseffekt startendeAutomaticallyAutomatischdeDurationDauerdeUndefinedNicht definiertdeOpen FileDatei öffnendeEffectEffektesDurationDuracioÌ?ndeLeft to RightVon links nach rechtsslOpen FileOdpri datotekofrDropChutedeError copying: %sFehler beim Kopieren: %sesNewNuevafrLeftGauchedePivotUm Achse drehendeSpring ContentsInhalt federn lassenesSlideDiapositivasdeError loading: %sFehler beim Laden: %sdeTop LeftOben linksesOpen FileAbrir archivodeRightRechtsdeError LoadingFehler beim LadendeOpen DoorTür öffnendeRight to LeftVon rechts nach linksdeTopObendeRevolving DoorDrehtürdeError loading ImageActor: %sFehler beim Laden von ImageActor: %sesFileArchivofrNew PresentationNouvelle présentation
de%i by %i%i mal %iesDirectionDireccioÌ?ndeLeftLinksdeZoomVergröÃ?erungdeSwing ContentsInhalt pendelndeError SavingFehler beim SpeicherndeError exporting: %sFehler beim Exportieren: %sde - a presentation editor - ein PräsentationsprogrammdeFlipSpiegelnesExport to HTMLExportar a HTMLfrSlideGlissedeDropAbwerfendeError saving: %sFehler beim Speichern: %sdeTop RightOben rechtsdeBottomUntendeNew PresentationNeue PräsentationfrCustomPersonnalisée
\ No newline at end of file
diff --git a/src/JSONParser.vala b/src/JSONParser.vala
index eac10fb..1b6d328 100644
--- a/src/JSONParser.vala
+++ b/src/JSONParser.vala
@@ -23,17 +23,20 @@ public static class Ease.JSONParser
/**
* Parses a document JSON file, creating a { link Document}.
*
- * @param filename The filename of the { link Document}
+ * @param path The filename of the { link Document}
*/
- public static Document document(string filename) throws GLib.Error
+ public static Document document(string path) throws GLib.Error
{
+ string filename = absolute_path(path);
var document = new Document();
- document.path = filename;
+ document.path = Temp.extract(filename);
+ document.filename = filename;
var parser = new Json.Parser();
// attempt to load the file
- parser.load_from_file(Path.build_filename(filename, "Document.json"));
+ parser.load_from_file(Path.build_filename(document.path,
+ "Document.json"));
// grab the root object
var root = parser.get_root().get_object();
@@ -57,10 +60,11 @@ public static class Ease.JSONParser
/**
* Parses a theme JSON file, creating a { link Theme}.
*
- * @param filename The path to the { link Theme}
+ * @param path The path to the { link Theme}
*/
- public static Theme theme(string filename) throws GLib.Error
+ public static Theme theme(string path) throws GLib.Error
{
+ string filename = absolute_path(path);
var theme = new Theme();
theme.path = Temp.extract(filename);
@@ -180,11 +184,14 @@ public static class Ease.JSONParser
// set the root object
root.set_object(obj);
- // write to file
+ // write to JSON file
var generator = new Json.Generator();
generator.set_root(root);
generator.pretty = true;
generator.to_file(Path.build_filename(document.path, "Document.json"));
+
+ // archive
+ Temp.archive(document.path, document.filename);
}
private static Json.Node document_write_slide(Slide slide)
@@ -232,5 +239,11 @@ public static class Ease.JSONParser
node.set_object(obj);
return node;
}
+
+ private static string absolute_path(string path)
+ {
+ var file = GLib.File.new_for_path(path);
+ return file.resolve_relative_path(".").get_path();
+ }
}
diff --git a/src/OpenDialog.vala b/src/OpenDialog.vala
index 9c50781..16f5cef 100644
--- a/src/OpenDialog.vala
+++ b/src/OpenDialog.vala
@@ -48,9 +48,11 @@ public class Ease.OpenDialog : GLib.Object
{
var dialog = new Gtk.FileChooserDialog(_("Open File"),
null,
- Gtk.FileChooserAction.SELECT_FOLDER,
- "gtk-cancel", Gtk.ResponseType.CANCEL,
- "gtk-open", Gtk.ResponseType.ACCEPT, null);
+ Gtk.FileChooserAction.OPEN,
+ "gtk-cancel",
+ Gtk.ResponseType.CANCEL,
+ "gtk-open",
+ Gtk.ResponseType.ACCEPT);
if (dialog.run() == Gtk.ResponseType.ACCEPT)
{
diff --git a/src/SlideSet.vala b/src/SlideSet.vala
index 0e7b317..7fd4f7f 100644
--- a/src/SlideSet.vala
+++ b/src/SlideSet.vala
@@ -21,7 +21,13 @@
public abstract class Ease.SlideSet : Object
{
/**
- * The file path of the SlideSet.
+ * The filename of the of the SlideSet when archived. Typically, this is a
+ * .ease or .easetheme file.
+ */
+ public string filename { get; set; }
+
+ /**
+ * The file path of the SlideSet (extracted).
*/
public string path { get; set; }
@@ -47,7 +53,7 @@ public abstract class Ease.SlideSet : Object
}
/**
- * Adds a new { link Slide to the end of the SlideSet.
+ * Adds a new { link Slide} to the end of the SlideSet.
*
* @param s The { link Slide} to append.
*/
diff --git a/src/Temp.vala b/src/Temp.vala
index 2f729df..cf731f9 100644
--- a/src/Temp.vala
+++ b/src/Temp.vala
@@ -18,8 +18,8 @@
/**
* Creates temporary directories for use by Ease.
*
- * Temporary directories are (typically) stored in /tmp/ease/{PID}/{INDEX},
- * where {PID} is the process ID and {INDEX} increments with each new directory.
+ * Temporary directories are (typically) stored in /tmp/ease/[PID]/[INDEX],
+ * where [PID] is the process ID and [INDEX] increments with each new directory.
* Ease automatically cleans up temporary directories when exiting, and will
* remove /tmp/ease if no other folders are being used in it.
*/
@@ -118,6 +118,25 @@ public static class Ease.Temp : Object
}
/**
+ * Creates an archive from a temporary directory.
+ *
+ * archive() will use libarchive to archive a temporary directory (or,
+ * technically, any directory) to a single file. Currently, it runs "tar"
+ * with Posix.system(), a solution that should be replaced with a more
+ * portable alternative.
+ *
+ * @param temp_path The path of the temporary directory.
+ * @param filename The filename of the archive to save to.
+ */
+ public static void archive(string temp_path, string filename) throws Error
+ {
+ // TODO: implementation with libarchive
+ var file = GLib.File.new_for_path(filename);
+ string last_path = file.get_basename();
+ Posix.system("cd %s; tar -cf %s `ls`; mv %s %s".printf(temp_path, last_path, last_path, filename));
+ }
+
+ /**
* Deletes all temporary directories created by this instance of Ease.
* Call when exiting.
*/
@@ -126,8 +145,11 @@ public static class Ease.Temp : Object
string dir;
while ((dir = folders.poll_head()) != null)
{
- // TODO: not this
- Posix.system("rm -rf %s".printf(dir));
+ try { recursive_delete(dir); }
+ catch (FileError e)
+ {
+ debug(e.message);
+ }
}
// Attempt to delete the parent temp directory.
@@ -137,11 +159,11 @@ public static class Ease.Temp : Object
string tmp = Path.build_filename(Environment.get_tmp_dir(), TEMP_DIR);
try
{
- // delete {TEMP}/ease/pid
+ // delete [TEMP]/ease/pid
var file = GLib.File.new_for_path(temp);
file.delete(null);
- // delete {TEMP}/ease
+ // delete [TEMP]/ease
file = GLib.File.new_for_path(tmp);
file.delete(null);
}
@@ -154,11 +176,45 @@ public static class Ease.Temp : Object
* @param dir The index of the directory.
* @param tmp The parent temporary directory (typically /tmp/ease).
*/
- private static bool exists(int dir, string tmp)
+ public static bool exists(int dir, string tmp)
{
var dir_tmp = Path.build_filename(tmp, dir.to_string());
var file = GLib.File.new_for_path(dir_tmp);
return file.query_exists(null);
}
+
+ /**
+ * Recursively removes a directory.
+ *
+ * Ported from Will Thompson's code located [[http://git.collabora.co.uk/?p=telepathy-haze.git;a=blob;f=src/util.c;h=5cbb4fb30b181a6c0f32c08bdadffae43b6e6ec3;hb=HEAD|here]].
+ *
+ * @param path The directory to be recursively deleted.
+ */
+ public static void recursive_delete(string path) throws FileError
+ {
+ string child_path;
+ var dir = GLib.Dir.open(path, 0);
+
+ if (dir == null)
+ {
+ throw new FileError.NOENT(
+ _("Directory to remove doesn't exist: %s"), path);
+ }
+
+ while ((child_path = dir.read_name()) != null)
+ {
+ var child_full_path = Path.build_filename(path, child_path);
+ if (FileUtils.test(child_full_path, FileTest.IS_DIR))
+ {
+ recursive_delete(child_full_path);
+ }
+ else // the path is a file
+ {
+ FileUtils.unlink(child_full_path);
+ }
+ }
+
+ DirUtils.remove(path);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]