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

[6/8] qt commit: Remove contact method added (not tested yet)

Remove contact method added (not tested yet)


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

Branch: refs/heads/master
Commit: b8243aa8a4c1fcf569a30a2701c1f61c6ce9b4a8
Parents: f773df7
Author: Denis Kormalev <dk...@ics.com>
Authored: Thu Mar 1 16:28:06 2012 +0400
Committer: Denis Kormalev <dk...@ics.com>
Committed: Fri Mar 16 19:26:38 2012 +0400

----------------------------------------------------------------------
 src/plugins/contacts.cpp |   13 +++++++++++++
 src/plugins/contacts.h   |    8 ++++----
 www/js/contacts.js       |   17 +++++++++++++++--
 3 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/b8243aa8/src/plugins/contacts.cpp
----------------------------------------------------------------------
diff --git a/src/plugins/contacts.cpp b/src/plugins/contacts.cpp
index 1274332..07f8d7a 100644
--- a/src/plugins/contacts.cpp
+++ b/src/plugins/contacts.cpp
@@ -81,6 +81,19 @@ void Contacts::saveContact(int scId, int ecId, const QVariantMap &params)
     qDeleteAll(detailsToDelete);
 }
 
+void Contacts::removeContact(int scId, int ecId, const QString &guid)
+{
+    Q_UNUSED(scId)
+    Q_UNUSED(ecId)
+
+    QContactDetailFilter idFilter;
+    idFilter.setDetailDefinitionName(QContactGuid::DefinitionName, QContactGuid::FieldGuid);
+    idFilter.setValue(guid);
+    idFilter.setMatchFlags(QContactFilter::MatchExactly);
+    QList<QContactLocalId> contacts = m_manager->contactIds(idFilter);
+    m_manager->removeContacts(contacts);
+}
+
 void Contacts::findContacts(int scId, int ecId, const QStringList &fields, const QString &filter, bool multiple)
 {
     qDebug() << Q_FUNC_INFO << filter << fields << multiple;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/b8243aa8/src/plugins/contacts.h
----------------------------------------------------------------------
diff --git a/src/plugins/contacts.h b/src/plugins/contacts.h
index e4c23d6..95f5168 100644
--- a/src/plugins/contacts.h
+++ b/src/plugins/contacts.h
@@ -15,15 +15,14 @@
 
 #ifdef QTM_NAMESPACE
 QTM_BEGIN_NAMESPACE
-#elif defined QTCONTACTS_USE_NAMESPACE
-QTCONTACTS_BEGIN_NAMESPACE
-#endif
 class QContact;
 class QContactManager;
-#ifdef QTM_NAMESPACE
 QTM_END_NAMESPACE
 QTM_USE_NAMESPACE
 #elif defined QTCONTACTS_USE_NAMESPACE
+QTCONTACTS_BEGIN_NAMESPACE
+class QContact;
+class QContactManager;
 QTCONTACTS_END_NAMESPACE
 QTCONTACTS_USE_NAMESPACE
 #endif
@@ -41,6 +40,7 @@ signals:
 
 public slots:
     void saveContact(int scId, int ecId, const QVariantMap &params);
+    void removeContact(int scId, int ecId, const QString &guid);
     void findContacts(int scId, int ecId, const QStringList &fields, const QString &filter, bool multiple);
 
 private:

http://git-wip-us.apache.org/repos/asf/incubator-cordova-qt/blob/b8243aa8/www/js/contacts.js
----------------------------------------------------------------------
diff --git a/www/js/contacts.js b/www/js/contacts.js
index 79c5e66..c8d5495 100644
--- a/www/js/contacts.js
+++ b/www/js/contacts.js
@@ -173,7 +173,7 @@ Contact.create = function(obj) {
             return result
         }
 
-Contact.prototype.id = ""
+Contact.prototype.id = null
 Contact.prototype.displayName = ""
 Contact.prototype.name = new ContactName()
 Contact.prototype.nickname = ""
@@ -189,10 +189,23 @@ Contact.prototype.categories = []
 Contact.prototype.urls = []
 
 Contact.prototype.clone = function() {
-
+            var newContact = Contact.create(this)
+            newContact.id = null
+            return newContact
         }
 
 Contact.prototype.remove = function(onSaveSuccess,onSaveError) {
+            if( typeof contactSuccess !== "function" ) return
+            if( typeof contactError !== "function" ) contactError = function() {}
+
+            //TODO: call onSaveError here
+            if (this.id == null || this.id == "")
+                return
+
+            Cordova.exec( function() {
+                              contactSuccess()
+                          }, contactError, "com.cordova.Contacts", "removeContact", [ this.id ] )
+
 
         }