Add setting parser's handler 21/34921/7
authorTomasz Iwanek <t.iwanek@samsung.com>
Mon, 2 Feb 2015 13:34:03 +0000 (14:34 +0100)
committerPawel Sikorski <p.sikorski@samsung.com>
Wed, 18 Feb 2015 13:44:17 +0000 (05:44 -0800)
Change-Id: I2063f0aa5046f5981b2abbb41576d3d1150e9009

src/widget-manifest-parser/CMakeLists.txt
src/widget-manifest-parser/manifest_handler.cc
src/widget-manifest-parser/manifest_handlers/setting_handler.cc [new file with mode: 0644]
src/widget-manifest-parser/manifest_handlers/setting_handler.h [new file with mode: 0644]

index 32b506b..cfd6d53 100644 (file)
@@ -7,6 +7,7 @@ SET(SRCS
   manifest_handlers/category_handler.cc
   manifest_handlers/ime_handler.cc
   manifest_handlers/permissions_handler.cc
+  manifest_handlers/setting_handler.cc
   manifest_handlers/tizen_application_handler.cc
   manifest_handlers/widget_handler.cc
   manifest_util.cc
index 6d0fd91..57311da 100644 (file)
@@ -13,6 +13,7 @@
 #include "widget-manifest-parser/manifest_handlers/permissions_handler.h"
 #include "widget-manifest-parser/manifest_handlers/category_handler.h"
 #include "widget-manifest-parser/manifest_handlers/ime_handler.h"
+#include "widget-manifest-parser/manifest_handlers/setting_handler.h"
 #include "widget-manifest-parser/manifest_handlers/tizen_application_handler.h"
 #include "widget-manifest-parser/manifest_handlers/widget_handler.h"
 
@@ -20,7 +21,6 @@
 // #include "widget-manifest-parser/manifest_handlers/tizen_appwidget_handler.h"
 // #include "widget-manifest-parser/manifest_handlers/tizen_metadata_handler.h"
 // #include "widget-manifest-parser/manifest_handlers/tizen_navigation_handler.h"
-// #include "widget-manifest-parser/manifest_handlers/tizen_setting_handler.h"
 // #include "widget-manifest-parser/manifest_handlers/tizen_splash_screen_handler.h"
 
 namespace common_installer {
@@ -108,6 +108,7 @@ ManifestHandlerRegistry::GetInstanceForWGT() {
   handlers.push_back(new PermissionsHandler);
   handlers.push_back(new CategoryHandler);
   handlers.push_back(new ImeHandler);
+  handlers.push_back(new SettingHandler);
 
   widget_registry_ = new ManifestHandlerRegistry(handlers);
   return widget_registry_;
diff --git a/src/widget-manifest-parser/manifest_handlers/setting_handler.cc b/src/widget-manifest-parser/manifest_handlers/setting_handler.cc
new file mode 100644 (file)
index 0000000..1ae9b33
--- /dev/null
@@ -0,0 +1,121 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 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-xwalk file.
+
+#include "widget-manifest-parser/manifest_handlers/setting_handler.h"
+
+#include <cassert>
+#include <map>
+#include <utility>
+
+#include "widget-manifest-parser/application_manifest_constants.h"
+
+namespace common_installer {
+namespace widget_manifest_parser {
+
+namespace keys = application_widget_keys;
+
+SettingInfo::SettingInfo()
+    : hwkey_enabled_(true),
+      screen_orientation_(PORTRAIT),
+      background_support_enabled_(false) {}
+
+SettingInfo::~SettingInfo() {}
+
+SettingHandler::SettingHandler() {}
+
+SettingHandler::~SettingHandler() {}
+
+bool SettingHandler::Parse(std::shared_ptr<ApplicationData> application,
+                                std::string* /*error*/) {
+  std::shared_ptr<SettingInfo> app_info(new SettingInfo);
+  const Manifest* manifest = application->GetManifest();
+  assert(manifest);
+
+  std::string hwkey;
+  manifest->GetString(keys::kTizenHardwareKey, &hwkey);
+  app_info->set_hwkey_enabled(hwkey != "disable");
+
+  std::string screen_orientation;
+  manifest->GetString(keys::kTizenScreenOrientationKey, &screen_orientation);
+  if (strcasecmp("portrait", screen_orientation.c_str()) == 0)
+    app_info->set_screen_orientation(SettingInfo::PORTRAIT);
+  else if (strcasecmp("landscape", screen_orientation.c_str()) == 0)
+    app_info->set_screen_orientation(SettingInfo::LANDSCAPE);
+  else
+    app_info->set_screen_orientation(SettingInfo::AUTO);
+  std::string encryption;
+  manifest->GetString(keys::kTizenEncryptionKey, &encryption);
+  app_info->set_encryption_enabled(encryption == "enable");
+
+  std::string context_menu;
+  manifest->GetString(keys::kTizenContextMenuKey, &context_menu);
+  app_info->set_context_menu_enabled(context_menu != "disable");
+
+  std::string background_support;
+  manifest->GetString(keys::kTizenBackgroundSupportKey, &background_support);
+  app_info->set_background_support_enabled(background_support == "enable");
+
+  application->SetManifestData(keys::kTizenSettingKey, app_info);
+  return true;
+}
+
+bool SettingHandler::Validate(
+    std::shared_ptr<const ApplicationData> application,
+    std::string* error) const {
+  const Manifest* manifest = application->GetManifest();
+  assert(manifest);
+  std::string hwkey;
+  manifest->GetString(keys::kTizenHardwareKey, &hwkey);
+  if (!hwkey.empty() && hwkey != "enable" && hwkey != "disable") {
+    *error = std::string("The hwkey value must be 'enable'/'disable',"
+                         " or not specified in configuration file.");
+    return false;
+  }
+
+  std::string screen_orientation;
+  manifest->GetString(keys::kTizenScreenOrientationKey, &screen_orientation);
+  if (!screen_orientation.empty() &&
+      strcasecmp("portrait", screen_orientation.c_str()) != 0 &&
+      strcasecmp("landscape", screen_orientation.c_str()) != 0 &&
+      strcasecmp("auto-rotation", screen_orientation.c_str()) != 0) {
+    *error = std::string("The screen-orientation must be 'portrait'/"
+                         "'landscape'/'auto-rotation' or not specified.");
+    return false;
+  }
+  std::string encryption;
+  manifest->GetString(keys::kTizenEncryptionKey, &encryption);
+  if (!encryption.empty() && encryption != "enable" &&
+      encryption != "disable") {
+    *error = std::string("The encryption value must be 'enable'/'disable', "
+                         "or not specified in configuration file.");
+    return false;
+  }
+  std::string context_menu;
+  manifest->GetString(keys::kTizenContextMenuKey, &context_menu);
+  if (!context_menu.empty() &&
+      context_menu != "enable" &&
+      context_menu != "disable") {
+    *error = std::string("The context-menu value must be 'enable'/'disable', "
+                         "or not specified in configuration file.");
+    return false;
+  }
+  std::string background_support;
+  manifest->GetString(keys::kTizenBackgroundSupportKey, &background_support);
+  if (!background_support.empty() &&
+      background_support != "enable" &&
+      background_support != "disable") {
+    *error = std::string("The background-support value must be"
+                         "'enable'/'disable', or not specified in configuration"
+                         "file.");
+  }
+  return true;
+}
+
+std::vector<std::string> SettingHandler::Keys() const {
+  return std::vector<std::string>(1, keys::kTizenSettingKey);
+}
+
+}  // namespace widget_manifest_parser
+}  // namespace common_installer
diff --git a/src/widget-manifest-parser/manifest_handlers/setting_handler.h b/src/widget-manifest-parser/manifest_handlers/setting_handler.h
new file mode 100644 (file)
index 0000000..dc817df
--- /dev/null
@@ -0,0 +1,82 @@
+// Copyright (c) 2014 Intel Corporation. All rights reserved.
+// Copyright (c) 2015 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-xwalk file.
+
+#ifndef WIDGET_MANIFEST_PARSER_MANIFEST_HANDLERS_SETTING_HANDLER_H_
+#define WIDGET_MANIFEST_PARSER_MANIFEST_HANDLERS_SETTING_HANDLER_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "utils/values.h"
+#include "widget-manifest-parser/application_data.h"
+#include "widget-manifest-parser/manifest_handler.h"
+
+namespace common_installer {
+namespace widget_manifest_parser {
+
+class SettingInfo : public ApplicationData::ManifestData {
+ public:
+  SettingInfo();
+  virtual ~SettingInfo();
+
+  enum ScreenOrientation {
+    PORTRAIT,
+    LANDSCAPE,
+    AUTO
+  };
+
+  void set_hwkey_enabled(bool enabled) { hwkey_enabled_ = enabled; }
+  bool hwkey_enabled() const { return hwkey_enabled_; }
+
+  void set_screen_orientation(ScreenOrientation orientation) {
+    screen_orientation_ = orientation;
+  }
+
+  ScreenOrientation screen_orientation() const { return screen_orientation_; }
+
+  void set_encryption_enabled(bool enabled) { encryption_enabled_ = enabled; }
+  bool encryption_enabled() const { return encryption_enabled_; }
+
+  void set_context_menu_enabled(bool enabled) {
+    context_menu_enabled_ = enabled;
+  }
+  bool context_menu_enabled() const { return context_menu_enabled_; }
+
+  void set_background_support_enabled(bool enabled) {
+    background_support_enabled_ = enabled;
+  }
+  bool background_support_enabled() const {
+    return background_support_enabled_;
+  }
+
+ private:
+  bool hwkey_enabled_;
+  ScreenOrientation screen_orientation_;
+  bool encryption_enabled_;
+  bool context_menu_enabled_;
+  bool background_support_enabled_;
+};
+
+class SettingHandler : public ManifestHandler {
+ public:
+  SettingHandler();
+  virtual ~SettingHandler();
+
+  bool Parse(std::shared_ptr<ApplicationData> application,
+                     std::string* error) override;
+  bool Validate(std::shared_ptr<const ApplicationData> application,
+                        std::string* error) const override;
+  std::vector<std::string> Keys() const override;
+
+ private:
+  DISALLOW_COPY_AND_ASSIGN(SettingHandler);
+};
+
+}  // namespace widget_manifest_parser
+}  // namespace common_installer
+
+#endif  // WIDGET_MANIFEST_PARSER_MANIFEST_HANDLERS_SETTING_HANDLER_H_