Updated Branches: refs/heads/master 3ad4f1c5f -> 0006871a4
camera , accelerater , compass all passed; fixes for contact:find 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/0006871a Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/tree/0006871a Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/diff/0006871a Branch: refs/heads/master Commit: 0006871a4e62d89b0946950726f73ac6518647dc Parents: 3ad4f1c Author: Longwei Su <long...@apache.org> Authored: Wed May 9 02:46:04 2012 -0400 Committer: Longwei Su <long...@apache.org> Committed: Wed May 9 02:46:04 2012 -0400 ---------------------------------------------------------------------- src/plugins/contacts.cpp | 5 +- src/plugins/fileapi.cpp | 9 +-- www/js/accelerometer.js | 28 +++++---- www/js/camera.js | 11 +++- www/js/compass.js | 138 ++++++++++++++++++++--------------------- www/js/contacts.js | 58 +++++++++++------ 6 files changed, 137 insertions(+), 112 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/0006871a/src/plugins/contacts.cpp ---------------------------------------------------------------------- diff --git a/src/plugins/contacts.cpp b/src/plugins/contacts.cpp index 87a3135..b84267d 100644 --- a/src/plugins/contacts.cpp +++ b/src/plugins/contacts.cpp @@ -306,7 +306,10 @@ void Contacts::removeContact(int scId, int ecId, const QString &localId) void Contacts::findContacts(int scId, int ecId, const QStringList &fields, const QString &filter, bool multiple) { qDebug() << Q_FUNC_INFO << filter << fields << multiple; - Q_UNUSED(ecId); +// Q_UNUSED(ecId); + if(fields.length() <= 0){ + callback(ecId, "ContactError.INVALID_ARGUMENT_ERROR"); + } QContactUnionFilter unionFilter; http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/0006871a/src/plugins/fileapi.cpp ---------------------------------------------------------------------- diff --git a/src/plugins/fileapi.cpp b/src/plugins/fileapi.cpp index 2d007db..04e8041 100644 --- a/src/plugins/fileapi.cpp +++ b/src/plugins/fileapi.cpp @@ -38,7 +38,7 @@ FileAPI::FileAPI() : CPlugin() { * LocalFileSystem.requestFileSystem - http://www.w3.org/TR/file-system-api/#widl-LocalFileSystem-requestFileSystem */ void FileAPI::requestFileSystem( int scId, int ecId, unsigned short p_type ) { - // Q_UNUSED(ecId) + Q_UNUSED(ecId) QDir dir; @@ -53,14 +53,9 @@ void FileAPI::requestFileSystem( int scId, int ecId, unsigned short p_type ) { this->callback( scId, "FileSystem.cast( 'temporary', '" + dir.dirName() + "', '" + dir.absolutePath() + "/' )" ); } else if (p_type == 1){ this->callback( scId, "FileSystem.cast( 'persistent', '" + dir.dirName() + "', '" + dir.absolutePath() + "/' )" ); - } else if (p_type == -1){ + } else { this->callback( ecId, "FileError.cast( FileError.SYNTAX_ERR )" ); } - else { - this->callback(ecId, "FileSystem.cast( 'ERROR', '" + dir.dirName() + "', '" + dir.absolutePath() + "/' )" ); - } - - } /** http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/0006871a/www/js/accelerometer.js ---------------------------------------------------------------------- diff --git a/www/js/accelerometer.js b/www/js/accelerometer.js index 278e724..2eb1bef 100644 --- a/www/js/accelerometer.js +++ b/www/js/accelerometer.js @@ -17,16 +17,12 @@ //accelerometer interface http://docs.phonegap.com/en/1.0.0/phonegap_accelerometer_accelerometer.md.html -function Acceleration() { -}; - -Acceleration.cast = function( p_acceleration) { - var acceleration = new Acceleration(); - acceleration.x = p_acceleration.x; - acceleration.y = p_acceleration.y; - acceleration.z = p_acceleration.z; - acceleration.timestamp = p_acceleration.timestamp; - return acceleration; +function Acceleration(p_x,p_y,p_z,p_ts) { + this.x = p_x || 0; + this.y = p_y || 0; + this.z = p_z || 0; + this.timestamp = p_ts || 0; + return this; }; Acceleration.prototype.x = null; @@ -34,14 +30,22 @@ Acceleration.prototype.y = null; Acceleration.prototype.z = null; Acceleration.prototype.timestamp = null; -Accelerometer.prototype.watchIds = []; +Acceleration.cast = function( p_acceleration) { + var acceleration = new Acceleration(p_acceleration.x, + p_acceleration.y, + p_acceleration.z, + p_acceleration.timestamp); + return acceleration; +}; + + /** * Accelerometer interface */ function Accelerometer() { }; - +Accelerometer.prototype.watchIds = []; Accelerometer.prototype.getCurrentAcceleration = function( successCallback, errorCallback) { // Check the callbacks http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/0006871a/www/js/camera.js ---------------------------------------------------------------------- diff --git a/www/js/camera.js b/www/js/camera.js index 7938c75..69a8713 100644 --- a/www/js/camera.js +++ b/www/js/camera.js @@ -1,4 +1,9 @@ function Camera(){ + this.DestinationType = Camera.DestinationType; + this.PictureSourceType = Camera.PictureSourceType; + this.EncodingType = Camera.EncodingType; + this.MediaType = Camera.MediaType; + return this; } Camera.DestinationType = { @@ -18,7 +23,11 @@ Camera.EncodingType = { PNG : 1 // Return PNG encoded image }; - +Camera.MediaType = { + PICTURE : 0, + VIDEO : 1, + ALLMEDIA: 2 +}; function CameraOptions() { }; http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/0006871a/www/js/compass.js ---------------------------------------------------------------------- diff --git a/www/js/compass.js b/www/js/compass.js index 6f38d40..2dab0d9 100644 --- a/www/js/compass.js +++ b/www/js/compass.js @@ -16,26 +16,24 @@ //compass interface http://docs.phonegap.com/en/1.0.0/phonegap_compass_compass.md.html - -function CompassHeading() { -}; - - -CompassHeading.cast = function( p_heading, p_trueHeading, p_accuracy, timestamp) { - var heading = new CompassHeading(); - heading.magneticHeading = p_heading; - heading.trueHeading = p_trueHeading; - heading.headingAccuracy = p_accuracy; - heading.timestamp = timestamp; - return heading; +function CompassHeading(p_heading, p_trueHeading, p_accuracy, timestamp){ + this.magneticHeading = p_heading || 0; + this.trueHeading = p_trueHeading || 0; + this.headingAccuracy = p_accuracy || 0; + this.timestamp = timestamp || 0; +return this; }; - CompassHeading.prototype.magneticHeading = 0; CompassHeading.prototype.trueHeading = 0; CompassHeading.prototype.headingAccuracy = 0; CompassHeading.prototype.timestamp = 0; +CompassHeading.cast = function(heading, trueHeading, accuracy, timestamp){ + var that = new CompassHeading(heading, trueHeading, accuracy, timestamp); +return that; +}; + //CompassError @@ -43,12 +41,12 @@ function CompassError() { }; CompassError.cast = function( p_code, p_message ) { - var CompassError = new CompassError(); - CompassError.code = p_code; - CompassError.message = p_message; + var CompassError = new CompassError(); + CompassError.code = p_code; + CompassError.message = p_message; - return CompassError; -}; + return CompassError; + }; CompassError.COMPASS_INTERNAL_ERR = 0; CompassError.COMPASS_NOT_SUPPORTED = 20; @@ -72,64 +70,64 @@ Compass.prototype.watchIds = []; Compass.prototype.cachedHeading = null; Compass.prototype.getCurrentHeading = function( successCallback, errorCallback, options ) { - // Check the callbacks - if( typeof successCallback !== "function" ) return; - if( typeof errorCallback !== "function" ) errorCallback = function() {}; - var headingOptions = new HeadingOptions(); - -// // Check the timestamp -// if( this.cachedHeading !== null && -// (this.cachedHeading.timestamp <= (new Date()).getTime) ) { -// successCallback( this.cachedHeading ); -// return; -// } - - // Call the native function and query for a new heading - var me = this; - Cordova.exec( function( p_heading ) { - received = true; - me.cachedHeading = p_heading; - successCallback( p_heading ); - }, errorCallback, "com.cordova.Compass", "getCurrentHeading", [ headingOptions ] ); - return heading = CompassHeading.cast(me.cachedHeading); -}; + // Check the callbacks + if( typeof successCallback !== "function" ) return; + if( typeof errorCallback !== "function" ) errorCallback = function() {}; + var headingOptions = new HeadingOptions(); + + // // Check the timestamp + // if( this.cachedHeading !== null && + // (this.cachedHeading.timestamp <= (new Date()).getTime) ) { + // successCallback( this.cachedHeading ); + // return; + // } + + // Call the native function and query for a new heading + var me = this; + Cordova.exec( function( p_heading ) { + received = true; + me.cachedHeading = p_heading; + successCallback( p_heading ); + }, errorCallback, "com.cordova.Compass", "getCurrentHeading", [ headingOptions ] ); + return me.cachedHeading; + }; Compass.prototype.watchHeading = function( successCallback, errorCallback, options ) { - // Check the callbacks - if( typeof successCallback !== "function" ) return; - if( typeof errorCallback !== "function" ) errorCallback = function() {}; - - var watchId = this.watchIds.length + 1; // +1 in order to avoid 0 as watchId - this.watchIds[watchId] = true; - var me = this; - - function doWatch() { - me.getCurrentHeading( function( p_heading ) { - if( !me.watchIds[watchId] ) return; - successCallback( p_heading ); - // Wait some time before starting again - setTimeout( doWatch, 100 ); - }, function( p_headingError ) { - if( !me.watchIds[watchId] ) return; - - errorCallback( p_headingError ); - // Wait some time before starting again - setTimeout( doWatch, 100 ); - }, options ); - } - - // Start watching for heading changes (slight delay, in order to simulate asynchronous behaviour) - setTimeout( doWatch, 100 ); - - return watchId; -}; + // Check the callbacks + if( typeof successCallback !== "function" ) return; + if( typeof errorCallback !== "function" ) errorCallback = function() {}; + + var watchId = this.watchIds.length + 1; // +1 in order to avoid 0 as watchId + this.watchIds[watchId] = true; + var me = this; + + function doWatch() { + me.getCurrentHeading( function( p_heading ) { + if( !me.watchIds[watchId] ) return; + successCallback( p_heading ); + // Wait some time before starting again + setTimeout( doWatch, 100 ); + }, function( p_headingError ) { + if( !me.watchIds[watchId] ) return; + + errorCallback( p_headingError ); + // Wait some time before starting again + setTimeout( doWatch, 100 ); + }, options ); + } + + // Start watching for heading changes (slight delay, in order to simulate asynchronous behaviour) + setTimeout( doWatch, 100 ); + + return watchId; + }; Compass.prototype.clearWatch = function( watchId ) { - this.watchIds[watchId] = false; -}; + this.watchIds[watchId] = false; + }; /** * Add the compass object to the navigator */ Cordova.addConstructor( "com.cordova.Compass", function () { - navigator.compass = new Compass();} ); + navigator.compass = new Compass();} ); http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/0006871a/www/js/contacts.js ---------------------------------------------------------------------- diff --git a/www/js/contacts.js b/www/js/contacts.js index 7f483a9..ba7baf1 100644 --- a/www/js/contacts.js +++ b/www/js/contacts.js @@ -40,7 +40,7 @@ ContactField.create = function(obj) { result.value = obj.value result.pref = obj.pref return result -} + } ContactField.prototype.type = "" ContactField.prototype.value = "" @@ -54,7 +54,7 @@ ContactFindOptions.create = function(obj) { var result = new ContactFindOptions() result.filter = obj.filter result.multiple = obj.multiple - return result + return result; } ContactFindOptions.prototype.filter = "" @@ -94,7 +94,7 @@ ContactName.create = function(obj) { else if (result.honorificSuffix !== "") formattedArr.push(result.honorificSuffix) - result.formatted = formattedArr.join(" ") + // result.formatted = formattedArr.join(" ") return result } @@ -141,24 +141,39 @@ ContactError.PERMISSION_DENIED_ERROR = 20 ContactError.prototype.code = ContactError.UNKNOWN_ERROR -function Contact() { - this.name = new ContactName() - this.phoneNumbers = [] - this.emails = [] - this.addresses = [] - this.ims = [] - this.organizations = [] - this.photos = [] - this.categories = [] - this.urls = [] +function Contact(p_id, p_displayName, p_name, p_nickname, + p_phoneNumbers, + p_emails, + p_addresses, + p_ims, + p_organizations, + p_birthday, + p_note, + p_photos, + p_categories, + p_urls) { + this.id = p_id || ""; + this.displayName = p_displayName || ""; + this.name = new ContactName(p_name); + this.nickname = p_nickname || ""; + this.phoneNumbers = p_phoneNumbers || [] + this.emails = p_emails || [] + this.addresses = p_addresses || [] + this.ims = p_ims || [] + this.organizations = p_organizations || [] + this.birthday = p_birthday || "" + this.note = p_note || "" + this.photos = p_photos || [] + this.categories = p_categories || [] + this.urls = p_urls || [] } Contact.create = function(obj) { var result = new Contact() result.id = obj.id result.displayName = obj.displayName - result.name = ContactName.create(obj.name || obj.displayName) - result.nickname = obj.nickname + result.name = ContactName.create(obj.name) + result.nickname = obj.nickname || null var subObj for (subObj in obj.phoneNumbers) result.phoneNumbers.push(ContactField.create(obj.phoneNumbers[subObj])) @@ -214,7 +229,7 @@ Contact.prototype.remove = function(contactSuccess,contactError) { Cordova.exec( contactSuccess, contactError, "com.cordova.Contacts", "removeContact", [ this.id ] ) console.log("Contact.remove 3") -} + } Contact.prototype.save = function(contactSuccess,contactError) { console.log("Contact.save 1") @@ -240,9 +255,10 @@ ContactsManager.prototype.create = function(properties) { ContactsManager.prototype.find = function(contactFields, contactSuccess, contactError, contactFindOptions) { // Check the callbacks - if( typeof contactSuccess !== "function" ) return - if( typeof contactError !== "function" ) contactError = function() {} - + if( typeof contactSuccess !== "function" ) {throw "no callback";} + if( typeof contactError !== "function" ) { + contactError = function() {} + } Cordova.exec( contactSuccess, contactError, "com.cordova.Contacts", "findContacts", [ contactFields, contactFindOptions.filter, contactFindOptions.multiple ] ) } @@ -250,5 +266,5 @@ ContactsManager.prototype.find = function(contactFields, contactSuccess, contact * Add the ContactsManager object to the navigator */ Cordova.addConstructor( "com.cordova.Contacts", function () { - navigator.contacts = new ContactsManager() - } ); + navigator.contacts = new ContactsManager() + } );