From 540c6a6672100b5e162d57743d0c7e8002ba5b52 Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Mon, 4 Jul 2011 23:35:54 +0100 Subject: [PATCH 1/4] Note in the code what method I'm going to add to the "fs" object. --- src/filesystem.h | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/filesystem.h b/src/filesystem.h index 80fd60ec..58b1dbcd 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -70,25 +70,63 @@ public: FileSystem(QObject *parent = 0); public slots: + // Attributes + // int size(const QString &path) const; //< TODO - in bytes, or throw excep if doesn't exists + // QDateTime lastModified(const QString &path) const; //< TODO - returns the time that a file was last modified as a Date object. + + // Tests bool exists(const QString &path) const; bool isDirectory(const QString &path) const; bool isFile(const QString &path) const; + // bool isLink(const QString &path) const; //< TODO + // bool isReadable(const QString &path) const; //< TODO + // bool isWritable(const QString &path) const; //< TODO is it writable or creatable + // isExecutable //< TODO + // isMount //< TODO + // linkExists //< TODO + // isAbsolute //< TODO + // same //< TODO + // Files / Directory bool makeDirectory(const QString &path) const; bool makeTree(const QString &path) const; - + // copy //< TODO + // move(source, target) //< TODO - throw exception if it fails + // touch(path, date) //< TODO bool remove(const QString &path) const; bool removeDirectory(const QString &path) const; bool removeTree(const QString &path) const; + // rename //< TODO + // copyTree(source, target) //< TODO - copies files from a source path to a target path, + // copying the files of the source tree to the corresponding locations + // relative to the target, copying but not traversing into symbolic links to directories. + // Listing QStringList list(const QString &path) const; + // Links + // symbolicLink(source, target) //< TODO + // hardLink(source, target) //< TODO + // readLink(path) String //< TODO + + // Paths + // canonical //< TODO QString workingDirectory() const; bool changeWorkingDirectory(const QString &path) const; - + // absolute //< TODO + // base //< TODO + // directory //< TODO + // extension //< TODO + // join //< TODO + // normal //< TODO + // relative //< TODO QString separator() const; + // split //< TODO + // Files QObject *_open(const QString &path, const QString &mode) const; + // read //< TODO + // write //< TODO }; #endif // FILESYSTEM_H From ad33cb5b0ba64271e4c6b98c2d636421a500d504 Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Sun, 17 Jul 2011 23:13:29 +0100 Subject: [PATCH 2/4] Note in the code what method I'm going to add to the "fs" object (update). --- src/filesystem.h | 91 +++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 51 deletions(-) diff --git a/src/filesystem.h b/src/filesystem.h index 58b1dbcd..13231652 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -71,62 +71,51 @@ public: public slots: // Attributes - // int size(const QString &path) const; //< TODO - in bytes, or throw excep if doesn't exists - // QDateTime lastModified(const QString &path) const; //< TODO - returns the time that a file was last modified as a Date object. + // - int size(const QString &path) const; //< TODO - in bytes, or throw excep if doesn't exists + // - QDateTime lastModified(const QString &path) const; //< TODO - returns the time that a file was last modified as a Date object. + + // Files / Directories + // - copy() + // - move() + // - touch(path, date) + // - rename() + + // Directory + // - copyTree(source, target) //< copies files from a source path to a target path, + // copying the files of the source tree to the corresponding locations + // relative to the target, copying but not traversing into + // symbolic links to directories. + bool makeDirectory(const QString &path) const; + bool makeTree(const QString &path) const; + bool removeDirectory(const QString &path) const; + bool removeTree(const QString &path) const; + + // Files + QObject *_open(const QString &path, const QString &mode) const; + // - read() + // - write() + + bool remove(const QString &path) const; + + // Listing + QStringList list(const QString &path) const; + + // Paths + QString separator() const; + QString workingDirectory() const; + bool changeWorkingDirectory(const QString &path) const; + // - absolute(relative_path) // Tests bool exists(const QString &path) const; bool isDirectory(const QString &path) const; bool isFile(const QString &path) const; - // bool isLink(const QString &path) const; //< TODO - // bool isReadable(const QString &path) const; //< TODO - // bool isWritable(const QString &path) const; //< TODO is it writable or creatable - // isExecutable //< TODO - // isMount //< TODO - // linkExists //< TODO - // isAbsolute //< TODO - // same //< TODO - - // Files / Directory - bool makeDirectory(const QString &path) const; - bool makeTree(const QString &path) const; - // copy //< TODO - // move(source, target) //< TODO - throw exception if it fails - // touch(path, date) //< TODO - bool remove(const QString &path) const; - bool removeDirectory(const QString &path) const; - bool removeTree(const QString &path) const; - // rename //< TODO - // copyTree(source, target) //< TODO - copies files from a source path to a target path, - // copying the files of the source tree to the corresponding locations - // relative to the target, copying but not traversing into symbolic links to directories. - - // Listing - QStringList list(const QString &path) const; - - // Links - // symbolicLink(source, target) //< TODO - // hardLink(source, target) //< TODO - // readLink(path) String //< TODO - - // Paths - // canonical //< TODO - QString workingDirectory() const; - bool changeWorkingDirectory(const QString &path) const; - // absolute //< TODO - // base //< TODO - // directory //< TODO - // extension //< TODO - // join //< TODO - // normal //< TODO - // relative //< TODO - QString separator() const; - // split //< TODO - - // Files - QObject *_open(const QString &path, const QString &mode) const; - // read //< TODO - // write //< TODO + // - isAbsolute() + // - isExecutable() + // - isLink() + // - isMount() + // - isReadable() + // - isWritable() }; #endif // FILESYSTEM_H From 21d633b7868196750b50270f9de2149b7d9fdb4c Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Sun, 17 Jul 2011 23:14:23 +0100 Subject: [PATCH 3/4] Implement "fs.read" and "fs.write" in the JavaScript shim. * I'd have to do it for throwing an exception in case of error anyway * Updated a bit the code doc --- src/bootstrap.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/bootstrap.js b/src/bootstrap.js index f09938b8..cab69551 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -88,7 +88,16 @@ window.WebPage = function() { return page; }; -// Make "fs.open" throw an exception in case it fails +// window.fs +// JavaScript "shim" to throw exceptions in case a critical operation fails. + +/** Open and return a "file" object. + * It will throw exception if it fails. + * + * @param path Path of the file to open + * @param mode Open Mode. A string made of 'r', 'w', 'a/+' characters. + * @return "file" object + */ window.fs.open = function(path, mode) { var file = window.fs._open(path, mode); if (file) { @@ -96,3 +105,31 @@ window.fs.open = function(path, mode) { } throw "Unable to open file '"+ path +"'"; }; + +/** Open, read and return content of a file. + * It will throw an exception if it fails. + * + * @param path Path of the file to read from + * @return file content + */ +window.fs.read = function(path) { + var f = fs.open(path, 'r'), + content = f.read(); + + f.close(); + return content; +}; + +/** Open and write content to a file + * It will throw an exception if it fails. + * + * @param path Path of the file to read from + * @param content Content to write to the file + * @param mode Open Mode. A string made of 'w' or 'a / +' characters. + */ +window.fs.write = function(path, content, mode) { + var f = fs.open(path, mode); + + f.write(content); + f.close(); +}; From 49ee7b52fd35433442550c5567201c9c7e7ff48c Mon Sep 17 00:00:00 2001 From: Ivan De Marino Date: Sun, 17 Jul 2011 23:24:10 +0100 Subject: [PATCH 4/4] A bit more code doc --- src/filesystem.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/filesystem.h b/src/filesystem.h index 13231652..c2eee3f8 100644 --- a/src/filesystem.h +++ b/src/filesystem.h @@ -91,9 +91,10 @@ public slots: bool removeTree(const QString &path) const; // Files + // 'open(path, mode)' implemented in "bootstrap.js" JavaScript shim, using '_open(path, mode)' QObject *_open(const QString &path, const QString &mode) const; - // - read() - // - write() + // 'read(path)' implemented in "bootstrap.js" JavaScript shim + // 'write(path, mode)' implemented in the "bootstrap.js" JavaScript shim bool remove(const QString &path) const;