cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lorinb...@apache.org
Subject [2/6] [CB-3367] Updates the framework to work with a smarter plugman and have a dumber packager - Re-writes cordova/plugin scripts to match the CLI interface - Includes the use of a global plugin repository for lookup - Adds a native/<arch> folder for co
Date Mon, 20 May 2013 17:44:14 GMT
http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/Notification/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Notification/plugin.xml b/blackberry10/plugins/Notification/plugin.xml
new file mode 100644
index 0000000..49566b2
--- /dev/null
+++ b/blackberry10/plugins/Notification/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+     specific language governing permissions and limitations
+      under the License.
+
+-->
+
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="org.apache.cordova.core.Notification"
+    version="0.0.1">
+
+    <name>Notification</name>
+
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="Notification" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="Notification" value="Notification"/>
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/Notification/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/Notification/src/blackberry10/index.js b/blackberry10/plugins/Notification/src/blackberry10/index.js
new file mode 100644
index 0000000..fad04f7
--- /dev/null
+++ b/blackberry10/plugins/Notification/src/blackberry10/index.js
@@ -0,0 +1,91 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+function showDialog(args, dialogType, result) {
+    //Unpack and map the args
+    var msg = JSON.parse(decodeURIComponent(args[0])),
+    title = JSON.parse(decodeURIComponent(args[1])),
+    btnLabel = JSON.parse(decodeURIComponent(args[2]));
+
+    if (!Array.isArray(btnLabel)) {
+        //Converts to array for (string) and (string,string, ...) cases
+        btnLabel = btnLabel.split(",");
+    }
+
+    if (msg && typeof msg === "string") {
+        msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"').replace(/\\\\/g, '\\');
+    } else {
+        result.error("message is undefined");
+        return;
+    }
+
+    var messageObj = {
+        title : title,
+        htmlmessage :  msg,
+        dialogType : dialogType,
+        optionalButtons : btnLabel
+    };
+
+    //TODO replace with getOverlayWebview() when available in webplatform
+    qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) {
+        if (typeof data === "number") {
+            //Confirm dialog call back needs to be called with one-based indexing [1,2,3
etc]
+            result.callbackOk(++data, false);
+        } else {
+            //Prompt dialog callback expects object
+            result.callbackOk({
+                buttonIndex: data.ok ? 1 : 0,
+                input1: (data.oktext) ? decodeURIComponent(data.oktext) : ""
+            }, false);
+        }
+    });
+
+    result.noResult(true);
+}
+
+module.exports = {
+    alert: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+
+        if (Object.keys(args).length < 3) {
+            result.error("Notification action - alert arguments not found.");
+        } else {
+            showDialog(args, "CustomAsk", result);
+        }
+    },
+    confirm: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+
+        if (Object.keys(args).length < 3) {
+            result.error("Notification action - confirm arguments not found.");
+        } else {
+            showDialog(args, "CustomAsk", result);
+        }
+    },
+    prompt: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+
+        if (Object.keys(args).length < 3) {
+            result.error("Notification action - prompt arguments not found.");
+        } else {
+            showDialog(args, "JavaScriptPrompt", result);
+        }
+    },
+    beep: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.error("Beep not supported");
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/SplashScreen/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/SplashScreen/plugin.xml b/blackberry10/plugins/SplashScreen/plugin.xml
new file mode 100644
index 0000000..0b33d5a
--- /dev/null
+++ b/blackberry10/plugins/SplashScreen/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+     specific language governing permissions and limitations
+      under the License.
+
+-->
+
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="org.apache.cordova.core.SplashScreen"
+    version="0.0.1">
+
+    <name>SplashScreen</name>
+
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="SplashScreen" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="SplashScreen" value="SplashScreen"/>
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/SplashScreen/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/SplashScreen/src/blackberry10/index.js b/blackberry10/plugins/SplashScreen/src/blackberry10/index.js
new file mode 100644
index 0000000..bd7e48c
--- /dev/null
+++ b/blackberry10/plugins/SplashScreen/src/blackberry10/index.js
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2013 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+module.exports = {
+    show: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.error("Not supported on platform", false);
+    },
+
+    hide: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        window.qnx.webplatform.getApplication().windowVisible = true;
+        result.ok(undefined, false);
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/com.blackberry.jpps/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/com.blackberry.jpps/plugin.xml b/blackberry10/plugins/com.blackberry.jpps/plugin.xml
new file mode 100644
index 0000000..0eec7c6
--- /dev/null
+++ b/blackberry10/plugins/com.blackberry.jpps/plugin.xml
@@ -0,0 +1,30 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="com.blackberry.jpps"
+    version="1.0.0">
+
+    <platform name="blackberry10">
+        <lib-file src="src/blackberry10/native/device/libjpps.so" arch="device"/>
+        <lib-file src="src/blackberry10/native/simulator/libjpps.so" arch="simulator"/>
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="com.blackberry.jpps"/>
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/device/libjpps.so
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/device/libjpps.so
b/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/device/libjpps.so
new file mode 100644
index 0000000..f0eb90d
Binary files /dev/null and b/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/device/libjpps.so
differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/simulator/libjpps.so
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/simulator/libjpps.so
b/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/simulator/libjpps.so
new file mode 100644
index 0000000..f2c12ff
Binary files /dev/null and b/blackberry10/plugins/com.blackberry.jpps/src/blackberry10/native/simulator/libjpps.so
differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/com.blackberry.utils/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/com.blackberry.utils/plugin.xml b/blackberry10/plugins/com.blackberry.utils/plugin.xml
new file mode 100644
index 0000000..746fa76
--- /dev/null
+++ b/blackberry10/plugins/com.blackberry.utils/plugin.xml
@@ -0,0 +1,30 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="com.blackberry.utils"
+    version="1.0.0">
+
+    <platform name="blackberry10">
+        <lib-file src="src/blackberry10/native/device/libutils.so" arch="device"/>
+        <lib-file src="src/blackberry10/native/simulator/libutils.so" arch="simulator"/>
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="com.blackberry.utils"/>
+        </config-file>
+    </platform>
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/device/libutils.so
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/device/libutils.so
b/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/device/libutils.so
new file mode 100644
index 0000000..126d02c
Binary files /dev/null and b/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/device/libutils.so
differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/simulator/libutils.so
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/simulator/libutils.so
b/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/simulator/libutils.so
new file mode 100644
index 0000000..392ad33
Binary files /dev/null and b/blackberry10/plugins/com.blackberry.utils/src/blackberry10/native/simulator/libutils.so
differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/plugin.xml
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/plugin.xml b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/plugin.xml
new file mode 100644
index 0000000..b35a83e
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/plugin.xml
@@ -0,0 +1,23 @@
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
+    id="org.apache.cordova.blackberry10.pimlib"
+    version="1.0.0">
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/Makefile
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/Makefile
new file mode 100644
index 0000000..0cc5eae
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/Makefile
@@ -0,0 +1,8 @@
+LIST=CPU
+ifndef QRECURSE
+QRECURSE=recurse.mk
+ifdef QCONFIG
+QRDIR=$(dir $(QCONFIG))
+endif
+endif
+include $(QRDIR)$(QRECURSE)

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/Makefile
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/Makefile
new file mode 100644
index 0000000..0e22650
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/Makefile
@@ -0,0 +1,8 @@
+LIST=VARIANT
+ifndef QRECURSE
+QRECURSE=recurse.mk
+ifdef QCONFIG
+QRDIR=$(dir $(QCONFIG))
+endif
+endif
+include $(QRDIR)$(QRECURSE)

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/Makefile
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/Makefile
new file mode 100644
index 0000000..2c76089
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/Makefile
@@ -0,0 +1 @@
+include ../../common.mk

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/libpimcontacts.so
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/libpimcontacts.so
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/libpimcontacts.so
new file mode 100755
index 0000000..f90047f
Binary files /dev/null and b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/arm/so.le-v7/libpimcontacts.so
differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/common.mk
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/common.mk
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/common.mk
new file mode 100644
index 0000000..7bc06fb
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/common.mk
@@ -0,0 +1,18 @@
+ifndef QCONFIG
+QCONFIG=qconfig.mk
+endif
+include $(QCONFIG)
+
+NAME=pimcontacts
+PLUGIN=yes
+UTILS=yes
+
+include ../../../../../../meta.mk
+
+SRCS+=pim_contacts_qt.cpp \
+      pim_contacts_js.cpp \
+      contact_account.cpp
+
+include $(MKFILES_ROOT)/qtargets.mk
+
+LIBS+=bbpim bbcascadespickers QtCore img

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.cpp
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.cpp
new file mode 100644
index 0000000..3476e70
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <webworks_utils.hpp>
+#include "contact_account.hpp"
+
+ContactAccount& ContactAccount::GetAccountInstance()
+{
+    static ContactAccount ca;
+    return ca;
+}
+
+ContactAccount::ContactAccount()
+{
+    fetchContactAccounts();
+}
+
+ContactAccount::~ContactAccount()
+{}
+
+QList<bb::pim::account::Account> ContactAccount::GetContactAccounts(bool fresh)
+{
+    if (fresh) {
+        fetchContactAccounts();
+    }
+    return _accounts;
+}
+
+bb::pim::account::Account ContactAccount::GetAccount(bb::pim::account::AccountKey id, bool
fresh)
+{
+    if (fresh) {
+        fetchContactAccounts();
+    }
+    return _accountMap.value(id);
+}
+
+Json::Value ContactAccount::Account2Json(const bb::pim::account::Account& account)
+{
+    Json::Value jsonAccount;
+    jsonAccount["id"] = webworks::Utils::intToStr(account.id());
+    jsonAccount["name"] = account.displayName().isEmpty() ? account.provider().name().toStdString()
: account.displayName().toStdString();
+    jsonAccount["enterprise"] = account.isEnterprise() == 1 ? true : false;
+
+    return jsonAccount;
+}
+
+void ContactAccount::fetchContactAccounts()
+{
+    QList<bb::pim::account::Account> accounts = _accountService.accounts(bb::pim::account::Service::Contacts);
+
+    _accounts.clear();
+    _accountMap.clear();
+    for (QList<bb::pim::account::Account>::const_iterator it = accounts.begin(); it
!= accounts.end(); ++it) {
+        if ((it->id() != ID_UNIFIED_ACCOUNT) && (it->id() != ID_ENHANCED_ACCOUNT))
{
+            _accounts.append(*it);
+            _accountMap.insert(it->id(), (bb::pim::account::Account)(*it));
+        }
+    }
+}
+
+

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.hpp
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.hpp
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.hpp
new file mode 100644
index 0000000..3910de8
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/contact_account.hpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _CONTACT_ACCOUNT_HPP_
+#define _CONTACT_ACCOUNT_HPP_
+
+#include <bb/pim/account/Account>
+#include <bb/pim/account/AccountService>
+#include <bb/pim/account/Provider>
+
+#include <json/value.h>
+#include <QList>
+#include <QDebug>
+
+class ContactAccount
+{
+public:
+    static ContactAccount& GetAccountInstance();
+
+    // get all available accounts which provide contact service
+    QList<bb::pim::account::Account> GetContactAccounts(bool fresh = false);
+    // get the contact account with the specific id
+    bb::pim::account::Account GetAccount(bb::pim::account::AccountKey id, bool fresh = false);
+    // serialize account to json object
+    static Json::Value Account2Json(const bb::pim::account::Account& account);
+
+private:
+    ContactAccount();
+    ~ContactAccount();
+    explicit ContactAccount(ContactAccount const&);
+    void operator=(ContactAccount const&);
+    // Refresh the accounts list and map
+    void fetchContactAccounts();
+    QMap<bb::pim::account::AccountKey, bb::pim::account::Account> _accountMap;
+    QList<bb::pim::account::Account> _accounts;
+    bb::pim::account::AccountService _accountService;
+    static const int ID_UNIFIED_ACCOUNT = 4;
+    static const int ID_ENHANCED_ACCOUNT = 6;
+};
+
+#endif // end of _CONTACT_ACCOUNT_HPP_

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/device/libpimcontacts.so
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/device/libpimcontacts.so
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/device/libpimcontacts.so
new file mode 100644
index 0000000..f90047f
Binary files /dev/null and b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/device/libpimcontacts.so
differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.cpp
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.cpp
new file mode 100644
index 0000000..4788bd1
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.cpp
@@ -0,0 +1,174 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <json/reader.h>
+#include <json/writer.h>
+#include <string>
+#include "pim_contacts_js.hpp"
+#include "pim_contacts_qt.hpp"
+
+PimContacts::PimContacts(const std::string& id) : m_id(id)
+{
+}
+
+char* onGetObjList()
+{
+    // Return list of classes in the object
+    static char name[] = "PimContacts";
+    return name;
+}
+
+JSExt* onCreateObject(const std::string& className, const std::string& id)
+{
+    // Make sure we are creating the right class
+    if (className != "PimContacts") {
+        return 0;
+    }
+
+    return new PimContacts(id);
+}
+
+std::string PimContacts::InvokeMethod(const std::string& command)
+{
+    unsigned int index = command.find_first_of(" ");
+
+    string strCommand;
+    string jsonObject;
+    Json::Value *obj;
+
+    if (index != std::string::npos) {
+        strCommand = command.substr(0, index);
+        jsonObject = command.substr(index + 1, command.length());
+
+        // Parse the JSON
+        obj = new Json::Value;
+        bool parse = Json::Reader().parse(jsonObject, *obj);
+
+        if (!parse) {
+            return "Cannot parse JSON object";
+        }
+    } else {
+        strCommand = command;
+        obj = NULL;
+    }
+
+    if (strCommand == "find") {
+        startThread(FindThread, obj);
+    } else if (strCommand == "save") {
+        startThread(SaveThread, obj);
+    } else if (strCommand == "remove") {
+        startThread(RemoveThread, obj);
+    } else if (strCommand == "getContact") {
+        std::string result = Json::FastWriter().write(webworks::PimContactsQt().GetContact(*obj));
+        delete obj;
+        return result;
+    } else if (strCommand == "invokePicker") {
+        Json::Value result = webworks::PimContactsQt::InvokePicker(*obj);
+        delete obj;
+
+        std::string event = Json::FastWriter().write(result);
+        NotifyEvent("invokeContactPicker.invokeEventId", event);
+    } else if (strCommand == "getContactAccounts") {
+        return Json::FastWriter().write(webworks::PimContactsQt::GetContactAccounts());
+    }
+
+    return "";
+}
+
+bool PimContacts::CanDelete()
+{
+    return true;
+}
+
+// Notifies JavaScript of an event
+void PimContacts::NotifyEvent(const std::string& eventId, const std::string& event)
+{
+    std::string eventString = m_id + " result ";
+    eventString.append(eventId);
+    eventString.append(" ");
+    eventString.append(event);
+    SendPluginEvent(eventString.c_str(), m_pContext);
+}
+
+bool PimContacts::startThread(ThreadFunc threadFunction, Json::Value *jsonObj) {
+    webworks::PimContactsThreadInfo *thread_info = new webworks::PimContactsThreadInfo;
+    thread_info->parent = this;
+    thread_info->jsonObj = jsonObj;
+    thread_info->eventId = jsonObj->removeMember("_eventId").asString();
+
+    pthread_attr_t thread_attr;
+    pthread_attr_init(&thread_attr);
+    pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
+
+    pthread_t thread;
+    pthread_create(&thread, &thread_attr, threadFunction, static_cast<void *>(thread_info));
+    pthread_attr_destroy(&thread_attr);
+
+    if (!thread) {
+        return false;
+    }
+
+    return true;
+}
+
+
+// Static functions:
+
+void* PimContacts::FindThread(void *args)
+{
+    webworks::PimContactsThreadInfo *thread_info = static_cast<webworks::PimContactsThreadInfo
*>(args);
+
+    webworks::PimContactsQt pim_qt;
+    Json::Value result = pim_qt.Find(*(thread_info->jsonObj));
+    delete thread_info->jsonObj;
+
+    std::string event = Json::FastWriter().write(result);
+    thread_info->parent->NotifyEvent(thread_info->eventId, event);
+    delete thread_info;
+
+    return NULL;
+}
+
+void* PimContacts::SaveThread(void *args)
+{
+    webworks::PimContactsThreadInfo *thread_info = static_cast<webworks::PimContactsThreadInfo
*>(args);
+
+    webworks::PimContactsQt pim_qt;
+    Json::Value result = pim_qt.Save(*(thread_info->jsonObj));
+    delete thread_info->jsonObj;
+
+    std::string event = Json::FastWriter().write(result);
+    thread_info->parent->NotifyEvent(thread_info->eventId, event);
+    delete thread_info;
+
+    return NULL;
+}
+
+void* PimContacts::RemoveThread(void *args)
+{
+    webworks::PimContactsThreadInfo *thread_info = static_cast<webworks::PimContactsThreadInfo
*>(args);
+
+    webworks::PimContactsQt pim_qt;
+    Json::Value result = pim_qt.DeleteContact(*(thread_info->jsonObj));
+    delete thread_info->jsonObj;
+
+    std::string event = Json::FastWriter().write(result);
+    thread_info->parent->NotifyEvent(thread_info->eventId, event);
+    delete thread_info;
+
+    return NULL;
+}
+

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/fa5a5900/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.hpp
----------------------------------------------------------------------
diff --git a/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.hpp
b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.hpp
new file mode 100644
index 0000000..df8bbd7
--- /dev/null
+++ b/blackberry10/plugins/org.apache.cordova.blackberry10.pimlib/src/blackberry10/native/pim_contacts_js.hpp
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef PIM_CONTACTS_JS_H_
+#define PIM_CONTACTS_JS_H_
+
+#include <json/value.h>
+#include <pthread.h>
+#include <string>
+#include "../common/plugin.h"
+
+typedef void* ThreadFunc(void *args);
+
+class PimContacts : public JSExt
+{
+public:
+    explicit PimContacts(const std::string& id);
+    virtual ~PimContacts() {}
+    virtual std::string InvokeMethod(const std::string& command);
+    virtual bool CanDelete();
+    void NotifyEvent(const std::string& eventId, const std::string& event);
+
+    static void* FindThread(void *args);
+    static void* SaveThread(void *args);
+    static void* RemoveThread(void *args);
+private:
+    bool startThread(ThreadFunc threadFunction, Json::Value *jsonObj);
+
+    std::string m_id;
+};
+
+#endif // PIM_CONTACTS_JS_H_


Mime
View raw message