Updated Branches: refs/heads/master 8032000f6 -> 14b3d436b
fixes for File API(fullpath and relative path), 99 failings to go Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/commit/14b3d436 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/tree/14b3d436 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/diff/14b3d436 Branch: refs/heads/master Commit: 14b3d436becfc304d55c83d1a3102422de2f177c Parents: 8032000 Author: Longwei Su <long...@apache.org> Authored: Sun May 13 21:17:11 2012 -0400 Committer: Longwei Su <long...@apache.org> Committed: Sun May 13 21:17:11 2012 -0400 ---------------------------------------------------------------------- src/plugins/fileapi.cpp | 57 +++++++++++++++++++++++++++++------------ src/plugins/fileapi.h | 18 +++++++++--- www/js/device.js | 5 +++ www/js/file.js | 14 ++++++---- 4 files changed, 66 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/14b3d436/src/plugins/fileapi.cpp ---------------------------------------------------------------------- diff --git a/src/plugins/fileapi.cpp b/src/plugins/fileapi.cpp index 8de01ff..f8666ab 100644 --- a/src/plugins/fileapi.cpp +++ b/src/plugins/fileapi.cpp @@ -41,17 +41,23 @@ void FileAPI::requestFileSystem( int scId, int ecId, unsigned short p_type ) { //FIXEME, accept size parameter QDir dir; + QString absPath; + + qDebug() << "requestFileSystem: " << QDir::temp().absolutePath(); // Get correct system path if( p_type == 0 ) { dir = QDir::temp(); + absPath = dir.absolutePath(); } else { dir = QDir::home(); + absPath = dir.absolutePath(); } + if (p_type == 0){ - this->callback( scId, "FileSystem.cast( 'temporary', '" + dir.dirName() + "', '" + dir.absolutePath() + "/' )" ); + this->callback( scId, "FileSystem.cast( 'temporary', '" + dir.dirName() + "', '" + absPath + "')" ); } else if (p_type == 1){ - this->callback( scId, "FileSystem.cast( 'persistent', '" + dir.dirName() + "', '" + dir.absolutePath() + "/' )" ); + this->callback( scId, "FileSystem.cast( 'persistent', '" + dir.dirName() + "', '" + absPath + "')" ); } else { this->callback( ecId, "FileError.cast( FileError.SYNTAX_ERR )" ); } @@ -62,6 +68,7 @@ void FileAPI::requestFileSystem( int scId, int ecId, unsigned short p_type ) { */ void FileAPI::resolveLocalFileSystemURL( int scId, int ecId, QString p_url ) { QUrl url = QUrl::fromUserInput( p_url ); + qDebug() << Q_FUNC_INFO << p_url; // Check if we have a valid URL if( !url.isValid() ) { @@ -82,24 +89,25 @@ void FileAPI::resolveLocalFileSystemURL( int scId, int ecId, QString p_url ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR )" ); return; } - + this->callback( scId, "DirectoryEntry.cast( '" + fileInfo.fileName() + "', '" + + QDir::cleanPath(fileInfo.absoluteFilePath()) + "' )" ); + return; // Now check if this is a dir or a file - if( fileInfo.isDir() ) { - this->callback( scId, "DirectoryEntry.cast( '" + fileInfo.fileName() + "', '" + QDir::cleanPath(fileInfo.absoluteFilePath()) + "/' )" ); - return; - } - else { - this->callback( scId, "FileEntry.cast( '" + fileInfo.fileName() + "', '" + fileInfo.absoluteFilePath() + "' )" ); - return; - } +// if( fileInfo.isDir() ) { +// this->callback( scId, "DirectoryEntry.cast( '" + fileInfo.fileName() + "', '" + QDir::cleanPath(fileInfo.absoluteFilePath()) + "/' )" ); +// return; +// } +// else { +// this->callback( scId, "FileEntry.cast( '" + fileInfo.fileName() + "', '" + fileInfo.absoluteFilePath() + "' )" ); +// return; +// } } /** * DirectoryEntry.getFile - http://www.w3.org/TR/file-system-api/#widl-DirectoryEntry-getFile */ void FileAPI::getFile( int scId, int ecId, QString p_path, QVariantMap p_options ) { - qDebug() << "Path: " << p_path; - + qDebug() << Q_FUNC_INFO << p_path; bool create = p_options.value("create").toBool(); bool exclusive = p_options.value("exclusive").toBool(); @@ -131,15 +139,14 @@ void FileAPI::getFile( int scId, int ecId, QString p_path, QVariantMap p_options } // If we reach here, everything went well - this->callback( scId, "FileEntry.cast( '/" + fileName + "', '" + QFileInfo( file ).absoluteFilePath() + "' )" ); + this->callback( scId, "FileEntry.cast( '" + fileName + "', '" + QFileInfo( file ).absoluteFilePath() + "' )" ); } /** * DirectoryEntry.getDirectory - http://www.w3.org/TR/file-system-api/#widl-DirectoryEntry-getDirectory */ void FileAPI::getDirectory( int scId, int ecId, QString p_path, QVariantMap p_options ) { - qDebug() << "Path: " << p_path; - + qDebug() << Q_FUNC_INFO << p_path; bool create = p_options.value("create").toBool(); bool exclusive = p_options.value("exclusive").toBool(); @@ -179,6 +186,7 @@ void FileAPI::getDirectory( int scId, int ecId, QString p_path, QVariantMap p_op */ void FileAPI::removeRecursively( int scId, int ecId, QString p_path ) { QDir dir( p_path ); + qDebug() << Q_FUNC_INFO << p_path; if( FileAPI::rmDir(dir) ) { this->callback( scId, "" ); @@ -195,6 +203,7 @@ void FileAPI::removeRecursively( int scId, int ecId, QString p_path ) { */ void FileAPI::file( int scId, int ecId, QString p_path ) { QFileInfo fileInfo(p_path); + qDebug() << Q_FUNC_INFO << p_path; if( !fileInfo.exists() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR )" ); @@ -212,6 +221,8 @@ void FileAPI::file( int scId, int ecId, QString p_path ) { void FileAPI::write( int scId, int ecId, QString p_path, unsigned long long p_position, QString p_data ) { QFile file( p_path ); + qDebug() << Q_FUNC_INFO << p_path; + // Check if file exists if( !file.exists() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR ), 0, 0" ); @@ -258,6 +269,8 @@ void FileAPI::write( int scId, int ecId, QString p_path, unsigned long long p_po void FileAPI::truncate( int scId, int ecId, QString p_path, unsigned long long p_size ) { QFile file(p_path); + qDebug() << Q_FUNC_INFO << p_path; + // Check if file exists at all if( !file.exists() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR ), 0, 0" ); @@ -281,6 +294,8 @@ void FileAPI::truncate( int scId, int ecId, QString p_path, unsigned long long p void FileAPI::getParent( int scId, int ecId, QString p_path ) { QDir dir( p_path ); + qDebug() << Q_FUNC_INFO << p_path; + // Try to change into upper directory if( !dir.cdUp() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR )" ); @@ -288,7 +303,7 @@ void FileAPI::getParent( int scId, int ecId, QString p_path ) { } // Extract names and send back - this->callback( scId, "DirectoryEntry.cast( '" + dir.dirName() + "', '" + dir.absolutePath() + "/' )" ); + this->callback( scId, "DirectoryEntry.cast( '" + dir.dirName() + "', '" + dir.absolutePath() + "' )" ); return; } @@ -298,6 +313,8 @@ void FileAPI::getParent( int scId, int ecId, QString p_path ) { void FileAPI::remove( int scId, int ecId, QString p_path ) { QFileInfo fileInfo(p_path); + qDebug() << Q_FUNC_INFO << p_path; + // Check if entry exists at all if( !fileInfo.exists() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR )" ); @@ -333,6 +350,8 @@ void FileAPI::remove( int scId, int ecId, QString p_path ) { void FileAPI::getMetadata( int scId, int ecId, QString p_path ) { QFileInfo fileInfo( p_path ); + qDebug() << Q_FUNC_INFO << p_path; + // Check if file exists if( !fileInfo.exists() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR )" ); @@ -350,6 +369,8 @@ void FileAPI::getMetadata( int scId, int ecId, QString p_path ) { void FileAPI::readEntries( int scId, int ecId, QString p_path ) { QDir dir( p_path ); + qDebug() << Q_FUNC_INFO << p_path; + QString entriesList = ""; if( dir.exists() ) { @@ -382,6 +403,8 @@ void FileAPI::readEntries( int scId, int ecId, QString p_path ) { void FileAPI::readAsDataURL( int scId, int ecId, QString p_path ) { QFile file( p_path ); + qDebug() << Q_FUNC_INFO << p_path; + // Check if file exists at all if( !file.exists() ) { this->callback( ecId, "FileError.cast( FileError.NOT_FOUND_ERR )" ); http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/14b3d436/src/plugins/fileapi.h ---------------------------------------------------------------------- diff --git a/src/plugins/fileapi.h b/src/plugins/fileapi.h index 60e02f4..924beac 100644 --- a/src/plugins/fileapi.h +++ b/src/plugins/fileapi.h @@ -33,18 +33,26 @@ signals: public slots: void requestFileSystem( int scId, int ecId, unsigned short p_type ); void resolveLocalFileSystemURL( int scId, int ecId, QString p_url ); - void getFile( int scId, int ecId, QString p_path, QVariantMap p_options ); void getDirectory( int scId, int ecId, QString p_path, QVariantMap p_options ); + void getFile( int scId, int ecId, QString p_path, QVariantMap p_options ); + void getParent( int scId, int ecId, QString p_path ); + void getMetadata( int scId, int ecId, QString p_path ); + void remove( int scId, int ecId, QString p_path ); void removeRecursively( int scId, int ecId, QString p_path ); void file( int scId, int ecId, QString p_path ); void write( int scId, int ecId, QString p_path, unsigned long long p_position, QString p_data ); void truncate( int scId, int ecId, QString p_path, unsigned long long p_size ); - void getParent( int scId, int ecId, QString p_path ); - void remove( int scId, int ecId, QString p_path ); - void getMetadata( int scId, int ecId, QString p_path ); void readEntries( int scId, int ecId, QString p_path ); void readAsDataURL( int scId, int ecId, QString p_path ); - +// void copyTo(); +// void moveTo(); +// void canCopyMoveSrc(); +// void doCopyMove(); +// void getFileMetadata(); +// void readEntries(); +// void readFile(); +// void readAsText(); +// void readAsDataUrl(); protected: static bool rmDir( QDir p_dir ); http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/14b3d436/www/js/device.js ---------------------------------------------------------------------- diff --git a/www/js/device.js b/www/js/device.js index dd42393..21bae4a 100644 --- a/www/js/device.js +++ b/www/js/device.js @@ -34,3 +34,8 @@ Device.prototype.version = ""; Cordova.addConstructor( "com.cordova.Device", function() { window.device = new Device(); } ); + +var cordova = window.Cordova; +var PhoneGap = window.Cordova; +PhoneGap.addPlugin = window.Cordova.enablePlugin; +var plugins = window.Cordova; http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/14b3d436/www/js/file.js ---------------------------------------------------------------------- diff --git a/www/js/file.js b/www/js/file.js index 30b43cc..627aa3b 100644 --- a/www/js/file.js +++ b/www/js/file.js @@ -63,6 +63,11 @@ FileException.ENCODING_ERR = 5; FileException.NO_MODIFICATION_ALLOWED_ERR = 6; FileException.INVALID_STATE_ERR = 7; FileException.SYNTAX_ERR = 8; +FileException.INVALID_MODIFICATION_ERR = 9; +FileException.QUOTA_EXCEEDED_ERR = 10; +FileException.TYPE_MISMATCH_ERR = 11; +FileException.PATH_EXISTS_ERR = 12; + /** * FileMetadata (Metadata) interface @@ -88,7 +93,7 @@ function Entry() { Entry.prototype.isFile = false; Entry.prototype.isDirectory = false; Entry.prototype.name = ""; -Entry.prototype.fullPath = ""; +Entry.prototype.fullPath = "";//fullpath for cordova-test = realFullPath - "/" Entry.prototype.filesystem = null; Entry.prototype.getMetadata = function( successCallback, errorCallback ) { // Get metadata for this entry @@ -435,7 +440,6 @@ DirectoryEntry.cast = function( dirname, path ) { var de = new DirectoryEntry(); de.name = dirname; de.fullPath = path; - return de; } @@ -447,7 +451,7 @@ DirectoryEntry.prototype.getFile = function( path, options, successCallback, err var requestPath = path; // Check for a relative path - if( requestPath.charAt(0) != '/' ) requestPath = this.fullPath + requestPath; + if( requestPath.charAt(0) != '/' ) requestPath = this.fullPath + "/" + requestPath; // Lets get the file Cordova.exec(successCallback, errorCallback, "com.cordova.File", "getFile", [requestPath, options]); @@ -456,9 +460,7 @@ DirectoryEntry.prototype.getDirectory = function( path, options, successCallback var requestPath = path; // Check for a relative path - if( requestPath.charAt(0) != '/' ) requestPath = this.fullPath + requestPath; - // Make sure we have a trailing slash - if( requestPath.charAt(requestPath.length - 1) != '/' ) requestPath = requestPath + "/"; + if( requestPath.charAt(0) != '/' ) requestPath = this.fullPath + "/" + requestPath; // Lets get the directory Cordova.exec(successCallback, errorCallback, "com.cordova.File", "getDirectory", [requestPath, options]);