[system-setting] Framework, getProperty() method
authorJakub Siewierski <j.siewierski@samsung.com>
Fri, 12 Dec 2014 13:11:58 +0000 (14:11 +0100)
committerJakub Siewierski <j.siewierski@samsung.com>
Wed, 28 Jan 2015 09:39:06 +0000 (10:39 +0100)
Change-Id: Iee3a7d8a6400c2a844ddb10ae90ab907d8c35f38
Signed-off-by: Jakub Siewierski <j.siewierski@samsung.com>
packaging/webapi-plugins.spec
src/systemsetting/systemsetting.gyp [new file with mode: 0644]
src/systemsetting/systemsetting_api.js [new file with mode: 0644]
src/systemsetting/systemsetting_extension.cc [new file with mode: 0644]
src/systemsetting/systemsetting_extension.h [new file with mode: 0644]
src/systemsetting/systemsetting_instance.cc [new file with mode: 0644]
src/systemsetting/systemsetting_instance.h [new file with mode: 0644]
src/tizen-wrt.gyp

index a2cece6a54ed49450ee338266fa2d1cbe79ecbe8..946f0b91ca23562adf2b7be7dbbf16d5914a083f 100644 (file)
@@ -48,7 +48,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_feature_se_support                  1
 %define tizen_feature_sensor_support              0
 %define tizen_feature_sound_support               0
-%define tizen_feature_system_setting_support      0
+%define tizen_feature_system_setting_support      1
 %define tizen_feature_telephony_support           0
 %define tizen_feature_web_setting_support         0
 %define tizen_feature_wi_fi_support               0
@@ -147,6 +147,7 @@ BuildRequires: ninja
 BuildRequires: pkgconfig(appcore-common)
 BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(libpcrecpp)
 BuildRequires: pkgconfig(dbus-1)
 BuildRequires: pkgconfig(dbus-glib-1)
diff --git a/src/systemsetting/systemsetting.gyp b/src/systemsetting/systemsetting.gyp
new file mode 100644 (file)
index 0000000..1b455ba
--- /dev/null
@@ -0,0 +1,28 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_systemsetting',
+      'type': 'loadable_module',
+      'sources': [
+        'systemsetting_api.js',
+        'systemsetting_extension.cc',
+        'systemsetting_extension.h',
+        'systemsetting_instance.cc',
+        'systemsetting_instance.h',
+      ],
+      'conditions': [
+        ['tizen == 1', {
+          'variables': {
+            'packages': [
+              'capi-system-system-settings',
+              'vconf',
+            ]
+          },
+        }],
+      ],
+    },
+  ],
+}
diff --git a/src/systemsetting/systemsetting_api.js b/src/systemsetting/systemsetting_api.js
new file mode 100644 (file)
index 0000000..e06da48
--- /dev/null
@@ -0,0 +1,65 @@
+/* global xwalk, extension, tizen */
+
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+
+var validator_ = xwalk.utils.validator;
+var type_ = xwalk.utils.type;
+var types_ = validator_.Types;
+var native_ = new xwalk.utils.NativeManager(extension);
+
+function throwException_(err) {
+    throw new tizen.WebAPIException(err.code, err.name, err.message);
+}
+
+function callSync_(msg) {
+    var ret = extension.internal.sendSyncMessage(JSON.stringify(msg));
+    var obj = JSON.parse(ret);
+    if (obj.error)
+        throwException_(obj.error);
+    return obj.result;
+}
+
+var SystemSettingType = {
+    HOME_SCREEN : 'HOME_SCREEN',
+    LOCK_SCREEN : 'LOCK_SCREEN',
+    INCOMING_CALL : 'INCOMING_CALL',
+    NOTIFICATION_EMAIL : 'NOTIFICATION_EMAIL'
+};
+
+function SystemSettingManager() {
+}
+
+SystemSettingManager.prototype.getProperty = function() {
+    var args = validator_.validateArgs(arguments, [
+        {name: 'type', type: types_.STRING},
+        {name: 'successCallback', type: types_.FUNCTION},
+        {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
+    ]);
+
+    if (!SystemSettingType.hasOwnProperty(args.type))
+        throw new tizen.WebAPIException(0, 'Invalid setting type', 'InvalidValuesError');
+
+    var callback = function(result) {
+        if (result.status === 'error') {
+            if (!type_.isNullOrUndefined(args.errorCallback)) {
+                args.errorCallback(result.error);
+            }
+        }
+        else {
+            args.successCallback(result.result.value);
+        }
+    }
+
+    var callArgs = {
+        type: args.type
+    };
+
+    native_.call('SystemSettingManager_getProperty', callArgs, callback);
+};
+
+// Exports
+exports = new SystemSettingManager();
+
diff --git a/src/systemsetting/systemsetting_extension.cc b/src/systemsetting/systemsetting_extension.cc
new file mode 100644 (file)
index 0000000..d0984e5
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "systemsetting/systemsetting_extension.h"
+
+#include "systemsetting/systemsetting_instance.h"
+
+// This will be generated from systemsetting_api.js
+extern const char kSource_systemsetting_api[];
+
+common::Extension* CreateExtension() {
+  return new SystemSettingExtension;
+}
+
+SystemSettingExtension::SystemSettingExtension() {
+  SetExtensionName("tizen.systemsetting");
+  SetJavaScriptAPI(kSource_systemsetting_api);
+}
+
+SystemSettingExtension::~SystemSettingExtension() {}
+
+common::Instance* SystemSettingExtension::CreateInstance() {
+  return new extension::systemsetting::SystemSettingInstance;
+}
diff --git a/src/systemsetting/systemsetting_extension.h b/src/systemsetting/systemsetting_extension.h
new file mode 100644 (file)
index 0000000..856b43b
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYSTEMSETTING_SYSTEMSETTING_EXTENSION_H_
+#define SYSTEMSETTING_SYSTEMSETTING_EXTENSION_H_
+
+#include "common/extension.h"
+
+class SystemSettingExtension : public common::Extension {
+ public:
+  SystemSettingExtension();
+  virtual ~SystemSettingExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif // SYSTEMSETTING_SYSTEMSETTING_EXTENSION_H_
+
diff --git a/src/systemsetting/systemsetting_instance.cc b/src/systemsetting/systemsetting_instance.cc
new file mode 100644 (file)
index 0000000..6562b50
--- /dev/null
@@ -0,0 +1,124 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "systemsetting/systemsetting_instance.h"
+
+#include <memory>
+
+#include "common/picojson.h"
+#include "common/logger.h"
+#include "common/platform_exception.h"
+#include "common/task-queue.h"
+
+#include <system_settings.h>
+
+
+namespace extension {
+namespace systemsetting {
+
+namespace {
+const std::string SETTING_HOME_SCREEN = "HOME_SCREEN";
+const std::string SETTING_LOCK_SCREEN = "LOCK_SCREEN";
+const std::string SETTING_INCOMING_CALL = "INCOMING_CALL";
+const std::string SETTING_NOTIFICATION_EMAIL = "NOTIFICATION_EMAIL";
+}
+
+using namespace common;
+using namespace extension::systemsetting;
+
+SystemSettingInstance::SystemSettingInstance()
+{
+    using namespace std::placeholders;
+
+#define REGISTER(c,x) \
+RegisterHandler(c, std::bind(&SystemSettingInstance::x, this, _1, _2));
+
+    REGISTER("SystemSettingManager_getProperty", getProperty);
+
+#undef REGISTER
+}
+
+SystemSettingInstance::~SystemSettingInstance()
+{
+}
+
+void SystemSettingInstance::getProperty(const picojson::value& args, picojson::object& out)
+{
+    LoggerD("");
+    const double callback_id = args.get("callbackId").get<double>();
+
+    const std::string& type = args.get("type").get<std::string>();
+    LoggerD("Getting property type: %s ", type.c_str());
+
+    auto get = [this, type](const std::shared_ptr<picojson::value>& response) -> void {
+        LoggerD("Getting platform value");
+        try {
+            int platformResult;
+            picojson::value result = getPlatformPropertyValue(type, platformResult);
+            ReportSuccess(result, response->get<picojson::object>());
+        } catch (const PlatformException& e) {
+            ReportError(e, response->get<picojson::object>());
+        }   
+    };  
+
+    auto get_response = [this, callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+        LoggerD("Getting response");
+        picojson::object& obj = response->get<picojson::object>();
+        obj.insert(std::make_pair("callbackId", callback_id));
+        PostMessage(response->serialize().c_str());
+    };  
+
+    TaskQueue::GetInstance().Queue<picojson::value>
+        (get, get_response, std::shared_ptr<picojson::value>(new picojson::value(picojson::object())));
+}
+
+picojson::value SystemSettingInstance::getPlatformPropertyValue(
+    const std::string &valueType, int &platformResult)
+{
+    int ret;
+    char *value = NULL;
+    picojson::value result = picojson::value(picojson::object());
+    picojson::object& result_obj = result.get<picojson::object>();
+
+    if (valueType == SETTING_HOME_SCREEN) {
+        ret = system_settings_get_value_string(
+            SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN, &value);
+    }
+    else if (valueType == SETTING_LOCK_SCREEN) {
+        ret = system_settings_get_value_string(
+            SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN, &value);
+    }
+    else if (valueType == SETTING_INCOMING_CALL) {
+        ret = system_settings_get_value_string(
+            SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE, &value);
+    }
+    else if (valueType == SETTING_NOTIFICATION_EMAIL) {
+        ret = system_settings_get_value_string(
+            SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE, &value);
+    }
+    // other values (not specified in the documentation) are handled in JS
+
+    platformResult = ret;
+
+    if (ret == SYSTEM_SETTINGS_ERROR_NONE) {
+        LoggerD("ret == SYSTEM_SETTINGS_ERROR_NONE");
+        result_obj.insert(std::make_pair("value", value));
+        free(value);
+    }
+    else if (ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API) {
+        LoggerD("ret == SYSTEM_SETTINGS_ERROR_CALL_UNSUPPORTED_API");
+        throw NotSupportedException("This property is not supported.");
+    }
+    else {
+        LoggerD("Other error");
+        throw UnknownException("Unknown error");
+    }
+
+    return result;
+}
+
+
+} // namespace systemsetting
+} // namespace extension
+
diff --git a/src/systemsetting/systemsetting_instance.h b/src/systemsetting/systemsetting_instance.h
new file mode 100644 (file)
index 0000000..f4bcbf0
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2014 Samsung Electronics Co, Ltd. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYSTEMSETTING_SYSTEMSETTING_INSTANCE_H_
+#define SYSTEMSETTING_SYSTEMSETTING_INSTANCE_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace systemsetting {
+
+class SystemSettingInstance : public common::ParsedInstance
+{
+public:
+    SystemSettingInstance();
+    virtual ~SystemSettingInstance();
+
+private:
+
+    void getProperty(const picojson::value& args, picojson::object& out);
+    picojson::value getPlatformPropertyValue(const std::string &valueType, int &platformResult);
+};
+
+} // namespace systemsetting
+} // namespace extension
+
+#endif // SYSTEMSETTING_SYSTEMSETTING_INSTANCE_H_
index 884989c7d7db274c0a42322d377390265884c4ed..d7c97ffb7fc5e76cde634e0d7f73b9df8d0949a9 100644 (file)
@@ -18,6 +18,7 @@
         'archive/archive.gyp:*',
         'exif/exif.gyp:*',
         'websetting/websetting.gyp:*',
+        'systemsetting/systemsetting.gyp:*',
       ],
       'conditions': [
         [