incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From long...@apache.org
Subject [1/2] qt commit: fixes for readAsText
Date Tue, 15 May 2012 15:40:29 GMT
Updated Branches:
  refs/heads/master 857070180 -> 12500e5d8


fixes for readAsText


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/12500e5d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/tree/12500e5d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/diff/12500e5d

Branch: refs/heads/master
Commit: 12500e5d8ae536a2d2d4a3f43a3439909b9c7c45
Parents: 53a6965
Author: Longwei Su <longwei@apache.org>
Authored: Tue May 15 11:34:00 2012 -0400
Committer: Longwei Su <longwei@apache.org>
Committed: Tue May 15 11:34:00 2012 -0400

----------------------------------------------------------------------
 src/plugins/fileapi.cpp |   27 ++++++++++++++++++++++++---
 src/plugins/fileapi.h   |    1 +
 www/js/file.js          |    2 +-
 3 files changed, 26 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/12500e5d/src/plugins/fileapi.cpp
----------------------------------------------------------------------
diff --git a/src/plugins/fileapi.cpp b/src/plugins/fileapi.cpp
index b3d7f82..f6e1e7a 100644
--- a/src/plugins/fileapi.cpp
+++ b/src/plugins/fileapi.cpp
@@ -471,6 +471,29 @@ void FileAPI::readEntries( int scId, int ecId, QString p_path ) {
 /**
  * FileReader.readAsText - http://www.w3.org/TR/FileAPI/#dfn-readAsText
  */
+void FileAPI::readAsText( 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, "FileException.cast( FileException.NOT_FOUND_ERR )" );
+        return;
+    }
+    // Try to open file for reading
+    if( !file.open( QIODevice::ReadOnly ) ) {
+        this->callback( ecId, "FileException.cast( FileException.NOT_READABLE_ERR )" );
+        return;
+    }
+    QByteArray byteArray = file.readAll();
+    // Escape string & send back
+    this->callback( scId, "'" + byteArray.toBase64() + "'" );
+    return;
+}
+
+/**
+ * FileReader.readAsDataURL - http://www.w3.org/TR/FileAPI/#dfn-readAsText
+ */
 void FileAPI::readAsDataURL( int scId, int ecId, QString p_path ) {
     QFile file( p_path );
     QFileInfo fileInfo( p_path );
@@ -480,24 +503,22 @@ void FileAPI::readAsDataURL( int scId, int ecId, QString p_path ) {
         this->callback( ecId, "FileException.cast( FileException.NOT_READABLE_ERR )" );
         return;
     }
-
     // Check if file exists at all
     if( !file.exists() ) {
         this->callback( ecId, "FileException.cast( FileException.NOT_FOUND_ERR )" );
         return;
     }
-
     // Try to open file for reading
     if( !file.open( QIODevice::ReadOnly ) ) {
         this->callback( ecId, "FileException.cast( FileException.NOT_READABLE_ERR )" );
         return;
     }
-
     // Read the file content
     QByteArray byteArray = file.readAll();
     QString contentType( mimeMap_[fileInfo.completeSuffix()] );
 
     // Escape string & send back
+//    this->callback( scId, "'" + byteArray.toBase64() + "'" );
     this->callback( scId, "'data:" + contentType + ";base64," + byteArray.toBase64() +
"'" );
     return;
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/12500e5d/src/plugins/fileapi.h
----------------------------------------------------------------------
diff --git a/src/plugins/fileapi.h b/src/plugins/fileapi.h
index 0803fa7..6870886 100644
--- a/src/plugins/fileapi.h
+++ b/src/plugins/fileapi.h
@@ -45,6 +45,7 @@ public slots:
     void truncate( int scId, int ecId, QString p_path, unsigned long long p_size );
     void readEntries( int scId, int ecId, QString p_path );
     void readAsDataURL( int scId, int ecId, QString p_path );
+    void readAsText( int scId, int ecId, QString p_path );
 //    void copyTo();
 //    void moveTo();
 //    void canCopyMoveSrc();

http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/12500e5d/www/js/file.js
----------------------------------------------------------------------
diff --git a/www/js/file.js b/www/js/file.js
index 9df2d70..c5a2a5a 100644
--- a/www/js/file.js
+++ b/www/js/file.js
@@ -376,7 +376,7 @@ FileReader.prototype.readAsText = function( file ) {
 
                              if( typeof me.onloadend === "function" ) me.onloadend( FileSaver.createEvent(
"loadend", me) );
                              if( typeof me.onerror === "function" ) me.onerror( FileSaver.createEvent(
"error", me) );
-                         }, "com.cordova.File", "readAsDataURL", [file.fullPath]);
+                         }, "com.cordova.File", "readAsText", [file.fullPath]);
         }
 FileReader.prototype.readAsDataURL = function( file ) {
             this.readyState = FileReader.EMPTY;


Mime
View raw message