You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by dk...@apache.org on 2012/03/19 13:01:23 UTC
[5/8] qt commit: Qt5 support. Test page updated
Qt5 support. Test page updated
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/abb593a7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/tree/abb593a7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/diff/abb593a7
Branch: refs/heads/master
Commit: abb593a7b2ff971c15b47e6f8319c53f0b7316a9
Parents: d39b348
Author: Denis Kormalev <dk...@ics.com>
Authored: Tue Mar 6 16:06:26 2012 +0400
Committer: Denis Kormalev <dk...@ics.com>
Committed: Fri Mar 16 19:26:39 2012 +0400
----------------------------------------------------------------------
src/plugins/contacts.cpp | 30 ++++++++++++++++++++-
www/basic.js | 59 +++++++++++++++++++++++++---------------
www/index.html | 9 ++++++
www/index_qt5.html | 9 ++++++
www/js/contacts.js | 4 +-
5 files changed, 86 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/abb593a7/src/plugins/contacts.cpp
----------------------------------------------------------------------
diff --git a/src/plugins/contacts.cpp b/src/plugins/contacts.cpp
index a18ce21..3c58c7d 100644
--- a/src/plugins/contacts.cpp
+++ b/src/plugins/contacts.cpp
@@ -39,6 +39,8 @@ Contacts::Contacts() :
void Contacts::init()
{
m_fieldNamePairs.clear();
+
+#if QT_VERSION < 0x050000
m_fieldNamePairs["displayName"] = (QLatin1String)QContactDisplayLabel::DefinitionName;
m_fieldNamePairs["name"] = (QLatin1String)QContactName::DefinitionName;
m_fieldNamePairs["nickname"] = (QLatin1String)QContactNickname::DefinitionName;
@@ -51,6 +53,20 @@ void Contacts::init()
m_fieldNamePairs["note"] = (QLatin1String)QContactNote::DefinitionName;
m_fieldNamePairs["photos"] = (QLatin1String)QContactAvatar::DefinitionName;
m_fieldNamePairs["urls"] = (QLatin1String)QContactUrl::DefinitionName;
+#else
+ m_fieldNamePairs["displayName"] = QContactDisplayLabel::DefinitionName;
+ m_fieldNamePairs["name"] = QContactName::DefinitionName;
+ m_fieldNamePairs["nickname"] = QContactNickname::DefinitionName;
+ m_fieldNamePairs["phoneNumbers"] = QContactPhoneNumber::DefinitionName;
+ m_fieldNamePairs["emails"] = QContactEmailAddress::DefinitionName;
+ m_fieldNamePairs["addresses"] = QContactAddress::DefinitionName;
+ m_fieldNamePairs["ims"] = QContactOnlineAccount::DefinitionName;
+ m_fieldNamePairs["organizations"] = QContactOrganization::DefinitionName;
+ m_fieldNamePairs["birthday"] = QContactBirthday::DefinitionName;
+ m_fieldNamePairs["note"] = QContactNote::DefinitionName;
+ m_fieldNamePairs["photos"] = QContactAvatar::DefinitionName;
+ m_fieldNamePairs["urls"] = QContactUrl::DefinitionName;
+#endif
m_notSupportedFields.clear();
m_notSupportedFields << "categories";
@@ -218,7 +234,13 @@ void Contacts::saveContact(int scId, int ecId, const QVariantMap ¶ms)
void Contacts::removeContact(int scId, int ecId, const QString &localId)
{
- if (!m_manager->removeContact(localId.toUInt())) {
+#if QT_VERSION < 0x050000
+ quint32 id = localId.toUInt();
+#else
+ QContactId id = QContactId::fromString(localId);
+#endif
+
+ if (!m_manager->removeContact(id)) {
switch (m_manager->error()) {
case QContactManager::DoesNotExistError:
case QContactManager::AlreadyExistsError:
@@ -316,9 +338,15 @@ QString Contacts::jsonedContact(const QContact &contact, const QStringList &fiel
foreach (const QString &field, resultingFields) {
QString qtDefinitionName = cordovaFieldNameToQtDefinitionName(field);
if (field == "id") {
+#if QT_VERSION < 0x050000
fieldValuesList << QString("%1: \"%2\"")
.arg(field)
.arg(contact.localId());
+#else
+ fieldValuesList << QString("%1: \"%2\"")
+ .arg(field)
+ .arg(contact.id().toString());
+#endif
} else if (field == "displayName") {
QContactDisplayLabel detail = contact.detail(qtDefinitionName);
fieldValuesList << QString("%1: \"%2\"")
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/abb593a7/www/basic.js
----------------------------------------------------------------------
diff --git a/www/basic.js b/www/basic.js
index e2bec10..9ade80b 100644
--- a/www/basic.js
+++ b/www/basic.js
@@ -179,18 +179,46 @@ function fileError( p_fileError ) {
}
-function displayGiven(contacts){
- var result = ""
- for (var contact in contacts) {
- result += contacts[contact].name.formatted + ": " + contacts[contact].phoneNumbers[0].value + "\n"
- contacts[contact].remove(function() {searchForGiven()})
- }
+function createTestContact() {
+ var created = navigator.contacts.create({"name": {familyName: "Family", givenName: "Given"}, phoneNumbers: [{"value": "+123456789", pref: false, type: "work"}], emails: [{"value": "given.family@gmail.com", pref: false, type: "email"}, {"value": "given@family.com", pref: false, type: "email"}], birthday: new Date(1985, 4, 3, 0, 0, 0)})
+ created.save(function() {
+ get("create_contact_result").innerHTML = "Contact created"
+ },
+ function(error) {
+ get("create_contact_result").innerHTML = "Error occured: " + error
+ })
+}
- console.log(result)
+function searchForTestContact() {
+ navigator.contacts.find(["name", "phoneNumbers", "nickname", "displayName", "emails", "ims", "addresses", "organizations", "birthday", "photos"],
+ function(contacts) {
+ var result = ""
+ for (var contact in contacts) {
+ result += contacts[contact].name.formatted + ": " + contacts[contact].phoneNumbers[0].value + ", " + contacts[contact].emails[0].value + "<br />"
+ }
+ get("search_contact_result").innerHTML = result
+ },
+ function(error) {
+ get("search_contact_result").innerHTML = "Error occured: " + error
+ },
+ {filter:"Given", multiple: true})
}
-function searchForGiven() {
- navigator.contacts.find(["name", "phoneNumbers", "nickname", "displayName", "emails", "ims", "addresses", "organizations", "birthday", "photos"], displayGiven, 0, {filter:"Given", multiple: true})
+
+function removeTestContact() {
+ get("remove_contact_result").innerHTML = ""
+ navigator.contacts.find(["name"],
+ function(contacts){
+ for (var contact in contacts) {
+ contacts[contact].remove(function() {
+ get("remove_contact_result").innerHTML += "Contact removed; "
+ },
+ function(error) {
+ get("remove_contact_result").innerHTML += "Error occured: " + error + "; "
+ })
+ }
+ },
+ 0, {filter:"Given", multiple: true})
}
/*
@@ -199,19 +227,6 @@ function searchForGiven() {
document.addEventListener( "deviceready", function() {
console.log("basicjs.deviceReady")
get( "debug_output" ).innerHTML = "Device Ready!<br/>";
-
- var created = navigator.contacts.create({"name": {familyName: "Family", givenName: "Given"}, phoneNumbers: [{"value": "+123456789", pref: false, type: "work"}], emails: [{"value": "given.family@gmail.com", pref: false, type: "email"}, {"value": "given@family.com", pref: false, type: "email"}], birthday: new Date(1985, 4, 3, 0, 0, 0)})
- created.save(searchForGiven, 0)
-
-// navigator.contacts.find(["name", "phoneNumbers", "nickname", "displayName", "emails", "ims", "addresses", "organizations", "birthday", "photos"],
-// function(contacts){
-// var result = ""
-// for (var contact in contacts) {
-// result += contacts[contact].name.formatted + ": " + contacts[contact].phoneNumbers[0].value + "\n"
-// }
-
-// console.log(result)
-// }, 0, {filter:"mar", multiple: true})
}, false );
document.addEventListener( "resume", function() {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/abb593a7/www/index.html
----------------------------------------------------------------------
diff --git a/www/index.html b/www/index.html
index c38846d..e911300 100644
--- a/www/index.html
+++ b/www/index.html
@@ -46,5 +46,14 @@
<input type="button" value="Get Current Heading" onclick="getCurrentHeading();">
<br />
<div id="heading_val"> Heading </div>
+ <input type="button" value="Create Test Contact" onclick="createTestContact();">
+ <br />
+ <div id="create_contact_result"></div>
+ <input type="button" value="Search for Test Contact" onclick="searchForTestContact();">
+ <br />
+ <div id="search_contact_result"></div>
+ <input type="button" value="Remove Test Contact" onclick="removeTestContact();">
+ <br />
+ <div id="remove_contact_result"></div>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/abb593a7/www/index_qt5.html
----------------------------------------------------------------------
diff --git a/www/index_qt5.html b/www/index_qt5.html
index aaf1d83..5312fd5 100644
--- a/www/index_qt5.html
+++ b/www/index_qt5.html
@@ -46,5 +46,14 @@
<input type="button" value="Get Current Heading" onclick="getCurrentHeading();">
<br />
<div id="heading_val"> Heading </div>
+ <input type="button" value="Create Test Contact" onclick="createTestContact();">
+ <br />
+ <div id="create_contact_result"></div>
+ <input type="button" value="Search for Test Contact" onclick="searchForTestContact();">
+ <br />
+ <div id="search_contact_result"></div>
+ <input type="button" value="Remove Test Contact" onclick="removeTestContact();">
+ <br />
+ <div id="remove_contact_result"></div>
</body>
</html>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/abb593a7/www/js/contacts.js
----------------------------------------------------------------------
diff --git a/www/js/contacts.js b/www/js/contacts.js
index 0ce22d9..7f12294 100644
--- a/www/js/contacts.js
+++ b/www/js/contacts.js
@@ -195,7 +195,7 @@ Contact.prototype.clone = function() {
}
Contact.prototype.remove = function(contactSuccess,contactError) {
- console.log("Contact.remove 1: " + dump(this))
+ console.log("Contact.remove 1")
if( typeof contactSuccess !== "function" ) contactSuccess = function() {}
if( typeof contactError !== "function" ) contactError = function() {}
@@ -213,7 +213,7 @@ Contact.prototype.save = function(contactSuccess,contactError) {
if( typeof contactSuccess !== "function" ) contactSuccess = function() {}
if( typeof contactError !== "function" ) contactError = function() {}
- console.log("Contact.save 2: ")
+ console.log("Contact.save 2")
Cordova.exec( contactSuccess, contactError, "com.cordova.Contacts", "saveContact", [ this ] )
console.log("Contact.save 3")