[SelfCamera] updated SelfCamera sources
authorPiotr Dabrowski <p.dabrowski2@samsung.com>
Thu, 5 Sep 2013 14:02:27 +0000 (16:02 +0200)
committerPiotr Dabrowski <p.dabrowski2@samsung.com>
Thu, 5 Sep 2013 14:02:27 +0000 (16:02 +0200)
Change-Id: I5bd862eb3f50b2f129438d1404bd9b41872fa22a

js/app.systemIO.js
js/main.js

index 75f40d7..cf6166c 100644 (file)
@@ -37,17 +37,17 @@ function SystemIO() {
                 */
                writeFile: function SystemIO_writeFile(fileHandle, fileContent, onSuccess, onError, contentEncoding) {
                        onError = onError || function () {};
-
                        fileHandle.openStream('w', function (fileStream) {
-                               if (contentEncoding === 'base64') {
-                                       fileStream.writeBase64(fileContent);
-                               } else {
-                                       fileStream.write(fileContent);
+                               try {
+                                       if (contentEncoding === 'base64') {
+                                               fileStream.writeBase64(fileContent);
+                                       } else {
+                                               fileStream.write(fileContent);
+                                       }
+                                       fileStream.close();
+                               } catch(e) {
+                                       onError(fileHandle);
                                }
-
-                               fileStream.close();
-
-                               // launch onSuccess callback
                                if (typeof onSuccess === 'function') {
                                        onSuccess(fileHandle);
                                }
@@ -137,7 +137,7 @@ function SystemIO() {
                 * @param {string} file content
                 * @param {string} file encoding
                 */
-               saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, fileEncoding) {
+               saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, onSaveFailure, fileEncoding) {
                        var pathData = this.getPathData(filePath),
                                self = this,
                                fileHandle;
@@ -147,12 +147,14 @@ function SystemIO() {
                                fileHandle = self.createFile(dir, pathData.fileName);
                                if (fileHandle !== false) {
                                        // save data into this file
-                                       self.writeFile(fileHandle, fileContent, onSaveSuccess, false, fileEncoding);
+                                       self.writeFile(fileHandle, fileContent, onSaveSuccess, onSaveFailure, fileEncoding);
+                               } else {
+                                       onSaveFailure();
                                }
                        }
 
                        // open directory
-                       this.openDir(pathData.dirName, onOpenDirSuccess);
+                       this.openDir(pathData.dirName, onOpenDirSuccess, onSaveFailure);
                },
 
                /**
index c2a4c21..1a77e20 100644 (file)
@@ -171,15 +171,23 @@ function SelfCamera() {
        };
 
        SelfCamera.prototype.saveCanvas = function saveCanvas(canvas, fileName) {
-               var data, self = this, onSuccess = function (fileHandle) {
-                       this.setLoadDirectory(this.getFileDirectoryURI(fileHandle));
-                       tizen.content.scanFile(fileName, function () {
-                               setTimeout(function(){ self.loadThumbnail(true, true); }, 200);
-                       }, function () {
-                               console.error('scanFile: file not found');
-                               self.loadThumbnail(true, false);
-                       });
-               }.bind(this);
+               var data,
+                       self = this,
+                       onSuccess = function (fileHandle) {
+                               this.setLoadDirectory(this.getFileDirectoryURI(fileHandle));
+                               tizen.content.scanFile(
+                                       fileName,
+                                       function () {
+                                               setTimeout(function(){ self.loadThumbnail(true, true); }, 200);
+                                       },
+                                       function () {
+                                               console.error('scanFile: file not found');
+                                               self.loadThumbnail(true, false);
+                                       });
+                       }.bind(this),
+                       onFailure = function (e) {
+                               alert("Failed to take photo!");
+                       };
 
                try {
                        data = canvas.toDataURL().replace('data:image/png;base64,', '').replace('data:,', '');
@@ -196,7 +204,7 @@ function SelfCamera() {
                try {
                        this.systemIO.deleteNode(fileName, function () {
                                try {
-                                       this.systemIO.saveFileContent(fileName, data, onSuccess, 'base64');
+                                       this.systemIO.saveFileContent(fileName, data, onSuccess, onFailure, 'base64');
                                } catch (e) {
                                        console.error('saveDataToFile error: ' + e.message);
                                }