Implement ThemeInfoProxy
authorSangyoon Jang <jeremy.jang@samsung.com>
Wed, 22 Apr 2020 04:01:49 +0000 (13:01 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 25 May 2020 04:28:15 +0000 (13:28 +0900)
Change-Id: I2ac0d7db38ae32ec289d5db34ed8fa1e1b63b329
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/theme/loader/theme_info.cc
src/theme/loader/theme_info.h
src/theme_provider/db_manager.cc
src/theme_provider/db_manager.h
src/theme_provider/selection_request_handler.cc
src/theme_provider/theme_info_proxy.cc
src/theme_provider/theme_info_proxy.h

index 91e3e86..ae7ca63 100644 (file)
@@ -81,7 +81,7 @@ bool ThemeInfo::GetBool(const std::string& key) const {
   return true;
 }
 
-tizen_base::Bundle ThemeInfo::Serialize() {
+tizen_base::Bundle ThemeInfo::Serialize() const {
   return {};
 }
 
index dbfc02c..588856c 100644 (file)
@@ -49,7 +49,7 @@ class ThemeInfo {
   float GetFloat(const std::string& key) const;
   bool GetBool(const std::string& key) const;
 
-  tizen_base::Bundle Serialize();
+  tizen_base::Bundle Serialize() const;
 
  private:
   std::string id_;
index 9a3436e..ef27caf 100644 (file)
@@ -31,6 +31,10 @@ const char kInsertQuery[] =
     "INSERT INTO theme (id, version, tool_version, title, description,"
     "  preview, resolution, details) "
     "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
+const char kUpdateQuery[] =
+    "UPDATE theme SET version = ?, tool_version = ?, title = ?,"
+    "  description = ?, preview = ?, resolution = ?, details = ? "
+    "WHERE id = ?";
 const char kDeleteQuery[] =
     "DELETE FROM theme WHERE id = ?";
 const char kSelectQuery[] =
@@ -78,6 +82,42 @@ bool DbManager::Insert(const std::string& id, const tizen_base::Bundle& info) {
   return true;
 }
 
+bool DbManager::Update(const std::string& id, const tizen_base::Bundle& info) {
+  std::unique_ptr<SQLiteStatement> stmt = conn_.PrepareStatement(kUpdateQuery);
+  if (!stmt) {
+    LOG(ERROR) << "Failed to prepare statement";
+    return false;
+  }
+
+  int idx = 1;
+  if (!stmt->BindString(idx++, info.GetString("version")))
+    return false;
+  if (!stmt->BindString(idx++, info.GetString("tool_version")))
+    return false;
+  if (!stmt->BindString(idx++, info.GetString("title")))
+    return false;
+  if (!stmt->BindString(idx++, info.GetString("description")))
+    return false;
+  if (!stmt->BindString(idx++, info.GetString("preview")))
+    return false;
+  if (!stmt->BindString(idx++, info.GetString("resolution")))
+    return false;
+  if (!stmt->BindBlob(idx++, info.GetByte("details")))
+    return false;
+  if (!stmt->BindString(idx++, info.GetString("id")))
+    return false;
+
+  if (stmt->Step() != SQLiteStatement::StepResult::DONE) {
+    LOG(ERROR) << "Failed to update ThemeInfo into DB";
+    return false;
+  }
+
+  for (const auto& listener : listeners_)
+    listener->OnThemePackageChanged(info.GetString("id"));
+
+  return true;
+}
+
 bool DbManager::Delete(const std::string& id) {
   std::unique_ptr<SQLiteStatement> stmt = conn_.PrepareStatement(kDeleteQuery);
   if (!stmt) {
index 1fe1652..54f2134 100644 (file)
@@ -27,6 +27,7 @@ class DbManager {
   DbManager();
   ~DbManager();
   bool Insert(const std::string& id, const tizen_base::Bundle& info);
+  bool Update(const std::string& id, const tizen_base::Bundle& info);
   bool Delete(const std::string& id);
   tizen_base::Bundle Select(const std::string& id);
   bool UpdateCurrentId(const std::string& id);
index eb7e40f..aa790e4 100644 (file)
@@ -6,11 +6,15 @@
 
 #include <bundle_cpp.h>
 
+#include <string>
+
 namespace ttm {
 namespace provider {
 
 tizen_base::Bundle SelectionRequestHandler::OnRequest(dbus::Command cmd,
     const tizen_base::Bundle& args) {
+  std::string id = args.GetString("id");
+  
   return {};
 }
 
index 440a5b0..fb756a7 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "theme_provider/theme_info_proxy.h"
 
+#include <memory>
 #include <string>
 
 #include "theme/loader/theme_info.h"
 namespace ttm {
 namespace provider {
 
-class ThemeInfo;
-
-std::shared_ptr<ThemeInfo> LoadTheme(const std::string& id) {
-  return nullptr;
+std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::LoadTheme(
+    const std::string& id) {
+  return std::make_shared<loader::ThemeInfo>(db_manager_.Select(id));
 }
 
-bool SaveTheme(const ThemeInfo& info) {
-  return true;
+bool ThemeInfoProxy::SaveTheme(const loader::ThemeInfo& info) {
+  return db_manager_.Insert(info.GetId(), info.Serialize());
 }
 
-std::shared_ptr<ThemeInfo> GetLoadedTheme() {
+std::shared_ptr<loader::ThemeInfo> ThemeInfoProxy::GetLoadedTheme() {
   return nullptr;
 }
 
-bool SetCurrentTheme(const std::string& id) {
+bool ThemeInfoProxy::SetCurrentTheme(const std::string& id) {
   return true;
 }
 
-void OnThemePackageChanged(const std::string& id) {
+void ThemeInfoProxy::OnThemePackageChanged(const std::string& id) {
 }
 
 }  // namespace provider
index 0f293b7..acc9afa 100644 (file)
 namespace ttm {
 namespace provider {
 
-class ThemeInfo;
-
 class ThemeInfoProxy : public IThemePackageEvent {
  public:
-  std::shared_ptr<ThemeInfo> LoadTheme(const std::string& id);
-  bool SaveTheme(const ThemeInfo& info);
-  std::shared_ptr<ThemeInfo> GetLoadedTheme();
+  std::shared_ptr<loader::ThemeInfo> LoadTheme(const std::string& id);
+  bool SaveTheme(const loader::ThemeInfo& info);
+  std::shared_ptr<loader::ThemeInfo> GetLoadedTheme();
   bool SetCurrentTheme(const std::string& id);
   void OnThemePackageChanged(const std::string& id) override;
+
+ private:
+  DbManager db_manager_;
 };
 
 }  // namespace provider