summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNataliia Sydorchuk <n.sydorchuk@samsung.com>2017-10-03 14:45:21 +0300
committerNataliia Sydorchuk <n.sydorchuk@samsung.com>2017-10-04 11:20:01 +0300
commitbd4af2dd716205178c8958a71d9ef10fea4b45af (patch)
tree563c738db2c556bb67a7b5c9b377b644a54d7683
parentde173edcd2f5f180df788c2e7e68be90a803fa2f (diff)
downloadvoice-control-bd4af2dd716205178c8958a71d9ef10fea4b45af.tar.gz
voice-control-bd4af2dd716205178c8958a71d9ef10fea4b45af.tar.bz2
voice-control-bd4af2dd716205178c8958a71d9ef10fea4b45af.zip
TizenRefApp-9281 Implement support of "Call to" command
Change-Id: I68dab82ddb7e9d8f8ddf54f484ec20b7ed8d6961 Signed-off-by: Nataliia Sydorchuk <n.sydorchuk@samsung.com>
-rw-r--r--voice-app/inc/Model/Commands.h7
-rw-r--r--voice-app/src/Model/Commands.cpp70
-rw-r--r--voice-app/src/Voice/CommandController.cpp3
-rw-r--r--voice-app/tizen-manifest.xml4
4 files changed, 80 insertions, 4 deletions
diff --git a/voice-app/inc/Model/Commands.h b/voice-app/inc/Model/Commands.h
index 2c897f4..b98a15c 100644
--- a/voice-app/inc/Model/Commands.h
+++ b/voice-app/inc/Model/Commands.h
@@ -31,6 +31,13 @@ namespace Model
* @return Whether command started successfully or not.
*/
bool launchReadMessageFrom(const char *contactName);
+
+ /**
+ * @brief Initialize call to @a contactName.
+ * @param[in] contactName Contact to whom the call will be initialized
+ * @return Whether command started successfully or not.
+ */
+ bool launchCall(const char *contactName);
}
#endif /* MODEL_COMMANDS_H */
diff --git a/voice-app/src/Model/Commands.cpp b/voice-app/src/Model/Commands.cpp
index c13a4bc..80a66e8 100644
--- a/voice-app/src/Model/Commands.cpp
+++ b/voice-app/src/Model/Commands.cpp
@@ -15,10 +15,45 @@
*/
#include "Model/Commands.h"
-#include "Utils/Logger.h"
+#include "Utils/Logger.h"
#include "App/AppControl.h"
+#include <contacts.h>
+#include <string>
+
+namespace
+{
+ int getNumberId(const char *contactName)
+ {
+ contacts_filter_h filter = nullptr;
+ contacts_filter_create(_contacts_person._uri, &filter);
+ contacts_filter_add_str(filter, _contacts_person.display_name, CONTACTS_MATCH_FULLSTRING, contactName);
+ contacts_query_h query = nullptr;
+ contacts_query_create(_contacts_person._uri, &query);
+ contacts_query_set_filter(query, filter);
+
+ contacts_list_h list = nullptr;
+ int err = contacts_db_get_records_with_query(query, 0, 0, &list);
+ WARN_IF_ERR(err, "contacts_db_get_records_with_query() failed.");
+
+ int numberId = 0;
+ if (list) {
+ contacts_record_h record = nullptr;
+ contacts_list_get_current_record_p(list, &record);
+ int personId = 0;
+ contacts_record_get_int(record, _contacts_person.id, &personId);
+ contacts_person_get_default_property(CONTACTS_PERSON_PROPERTY_NUMBER, personId, &numberId);
+
+ contacts_list_destroy(list, true);
+ }
+
+ contacts_query_destroy(query);
+ contacts_filter_destroy(filter);
+ return numberId;
+ }
+}
+
bool Model::launchCreateMessage()
{
App::AppControl request(APP_CONTROL_OPERATION_COMPOSE, nullptr);
@@ -42,3 +77,36 @@ bool Model::launchReadMessageFrom(const char *contactName)
return TIZEN_ERROR_IS_OK(err);
}
+
+bool Model::launchCall(const char *contactName)
+{
+ RETVM_IF(!(contactName && *contactName), false, "There is no contact name");
+ int err = contacts_connect();
+ RETVM_IF_ERR(err, false, "contacts_connect() failed.");
+
+ int numberId = getNumberId(contactName);
+ WARN_IF(!numberId, "There is no number id");
+
+ if (numberId) {
+ contacts_record_h numberRecord = nullptr;
+ err = contacts_db_get_record(_contacts_number._uri, numberId, &numberRecord);
+ WARN_IF_ERR(err, "contacts_db_get_record() failed.");
+
+ if (numberRecord) {
+ char *number = nullptr;
+ err = contacts_record_get_str_p(numberRecord, _contacts_number.number, &number);
+
+ if (number) {
+ App::AppControl request(APP_CONTROL_OPERATION_CALL, nullptr,
+ std::string("tel:").append(number).c_str());
+ err = request.launch(nullptr, nullptr, false);
+ request.detach();
+ }
+
+ contacts_record_destroy(numberRecord, true);
+ }
+ }
+
+ contacts_disconnect();
+ return TIZEN_ERROR_IS_OK(err) && numberId;
+}
diff --git a/voice-app/src/Voice/CommandController.cpp b/voice-app/src/Voice/CommandController.cpp
index e4b26dc..27a85bf 100644
--- a/voice-app/src/Voice/CommandController.cpp
+++ b/voice-app/src/Voice/CommandController.cpp
@@ -53,8 +53,7 @@ struct CommandController::CommandMatch
namespace
{
CommandController::CommandData commands[] = {
- //TODO: Implement support of commands.
- { "Call to", CommandWithParam, nullptr },
+ { "Call to", CommandWithParam, launchCall },
{ "Create text message", CommandWithAction,
[](const char *) { return launchCreateMessage(); } },
{ "Read message from", CommandWithParam, launchReadMessageFrom }
diff --git a/voice-app/tizen-manifest.xml b/voice-app/tizen-manifest.xml
index e4c1942..a79deb1 100644
--- a/voice-app/tizen-manifest.xml
+++ b/voice-app/tizen-manifest.xml
@@ -1,13 +1,15 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="4.0" package="org.tizen.voice-control" version="1.0.0">
<profile name="wearable"/>
- <ui-application appid="org.tizen.voice-control" exec="voice-app" multiple="false" nodisplay="false" taskmanage="true" type="capp">
+ <ui-application appid="org.tizen.voice-control" exec="voice-app" launch_mode="single" multiple="false" nodisplay="false" taskmanage="true" type="capp">
<label>Voice</label>
<icon>svoice.png</icon>
</ui-application>
<privileges>
<privilege>http://tizen.org/privilege/appmanager.launch</privilege>
<privilege>http://tizen.org/privilege/contact.read</privilege>
+ <privilege>http://tizen.org/privilege/call</privilege>
+ <privilege>http://tizen.org/privilege/recorder</privilege>
</privileges>
<feature name="http://tizen.org/feature/microphone">true</feature>
<feature name="http://tizen.org/feature/speech.control">true</feature>