Add get provider icon API 88/220888/7
authorhyunho <hhstark.kang@samsung.com>
Tue, 24 Dec 2019 08:42:35 +0000 (17:42 +0900)
committerhyunho <hhstark.kang@samsung.com>
Mon, 6 Jan 2020 07:51:46 +0000 (16:51 +0900)
- watchface_editor_get_complication_provider_icon

Change-Id: I0bcd28c38c1875831ce5a8ebf0237886e8da9a5f
Signed-off-by: hyunho <hhstark.kang@samsung.com>
parser/complication_parser_plugin.cc
parser/complication_parser_plugin_internal.cc
watchface-complication/db-manager.cc
watchface-complication/db-manager.h
watchface-editor/include/watchface-editor-internal.h [new file with mode: 0644]
watchface-editor/watchface-editor.cc

index 588fb47..5e7fea7 100644 (file)
@@ -461,6 +461,42 @@ static bool _parse_label(xmlNode* node, shared_ptr<util::DBHelper>& db,
   return true;
 }
 
+static bool _parse_icon(xmlNode* node, shared_ptr<util::DBHelper>& db,
+    string providerid) {
+  xmlChar* lang = nullptr;
+  static const char query[] =
+    "INSERT INTO provider_icon "
+    "(provider_id, locale, icon_path) "
+    "VALUES (?, ?, ?)";
+
+  if (!db->Prepare(query))
+    return false;
+
+  if (!db->Bind(1, providerid))
+    return false;
+
+  lang = xmlNodeGetLang(node);
+  if (lang) {
+    bool ret = db->Bind(2, reinterpret_cast<char*>(lang));
+    xmlFree(lang);
+    if (!ret)
+      return false;
+  } else {
+    if (!db->Bind(2, "No Locale"))
+      return false;
+  }
+
+  if (!db->Bind(3, reinterpret_cast<char*>(node->children->content)))
+    return false;
+
+  if (db->Step() != SQLITE_DONE)
+    return false;
+
+  if (db->Reset() != SQLITE_OK)
+    return false;
+  return true;
+}
+
 static bool _parse_privilege(xmlNode* node, shared_ptr<util::DBHelper>& db,
     string providerid) {
   xmlNode* tmp;
@@ -600,6 +636,7 @@ static bool _parse_complication(xmlNode* node, shared_ptr<util::DBHelper>& db,
   xmlNode* privilege_node = nullptr;
   xmlNode* support_event_node = nullptr;
   list<xmlNode*> label_list;
+  list<xmlNode*> icon_list;
 
   if (node->children == NULL)
     return false;
@@ -620,6 +657,8 @@ static bool _parse_complication(xmlNode* node, shared_ptr<util::DBHelper>& db,
         period = 60;
     } else if (!xmlStrcasecmp(tmp->name, (const xmlChar*)"label")) {
       label_list.push_back(tmp);
+    } else if (!xmlStrcasecmp(tmp->name, (const xmlChar*)"icon")) {
+      icon_list.push_back(tmp);
     } else if (!xmlStrcasecmp(tmp->name, (const xmlChar*)"privileges")) {
       privilege_node = tmp;
     } else if (!xmlStrcasecmp(tmp->name, (const xmlChar*)"support-event")) {
@@ -661,6 +700,13 @@ static bool _parse_complication(xmlNode* node, shared_ptr<util::DBHelper>& db,
     }
   }
 
+  for (auto& i : icon_list) {
+    if (!_parse_icon(i, db, providerid)) {
+      LOGE("parse icon fail");
+      return false;
+    }
+  }
+
   if (!setup_appid.empty()) {
     if (!_insert_setup_appid(db, providerid, setup_appid)) {
       LOGE("insert setup appid fail");
index 3028fc1..ce67ee9 100644 (file)
@@ -58,6 +58,13 @@ CREATE TABLE IF NOT EXISTS provider_localized_info ( \
   UNIQUE (provider_id, locale), \
   FOREIGN KEY (provider_id) REFERENCES complication_provider(provider_id) ON DELETE CASCADE \
 ); \
+CREATE TABLE IF NOT EXISTS provider_icon ( \
+  provider_id    TEXT NOT NULL, \
+  locale         TEXT NOT NULL DEFAULT 'No Locale', \
+  icon_path      TEXT, \
+  UNIQUE (provider_id, locale), \
+  FOREIGN KEY (provider_id) REFERENCES complication_provider(provider_id) ON DELETE CASCADE \
+); \
 CREATE TABLE IF NOT EXISTS provider_privilege ( \
   provider_id  TEXT NOT NULL, \
   privilege    TEXT NOT NULL, \
@@ -76,9 +83,10 @@ CREATE TABLE IF NOT EXISTS provider_support_events ( \
 ); \
 COMMIT TRANSACTION; "
 
-#define COMPLICATION_TBL_COUNT 6
+#define COMPLICATION_TBL_COUNT 7
 static const char* _complication_table_list[COMPLICATION_TBL_COUNT] = {
   "complication_provider",
+  "provider_icon",
   "provider_localized_info",
   "provider_privilege",
   "provider_setup_appid",
index 8a0ae52..4ffdd57 100644 (file)
@@ -450,6 +450,63 @@ std::string DBManager::GetLabel(const char* provider_id) {
   return label;
 }
 
+std::string DBManager::GetIcon(const char* provider_id) {
+  static const char query[] =
+    "SELECT icon_path FROM provider_icon "
+    "WHERE provider_id=? AND locale=?";
+  util::DBHelper db;
+
+  if (!db.Open())
+    return std::string();
+
+  if (!db.Prepare(query))
+    return std::string();
+
+  char* locale = GetSystemLocale();
+  if (locale == nullptr)
+    return std::string();
+
+  std::unique_ptr<char, decltype(std::free)*> locale_ptr(locale, std::free);
+
+  if (!db.Bind(1, provider_id))
+    return std::string();
+
+  if (!db.Bind(2, locale_ptr.get()))
+    return std::string();
+
+  std::string icon;
+  if (db.Step() == SQLITE_ROW) {
+    const char* ic = db.GetText(0);
+    if (ic == nullptr) {
+      LOGW("ic is nullptr");
+    } else {
+      icon = ic;
+    }
+  }
+
+  if (!icon.empty())
+    return icon;
+
+  sqlite3_reset(db.GetCursor().get());
+  sqlite3_clear_bindings(db.GetCursor().get());
+
+  if (!db.Bind(1, provider_id))
+    return std::string();
+  if (!db.Bind(2, DEFAULT_LOCALE))
+    return std::string();
+
+  if (db.Step() == SQLITE_ROW) {
+    const char* ic = db.GetText(0);
+    if (ic == nullptr) {
+      LOGW("ic is nullptr");
+    } else {
+      icon = ic;
+    }
+  }
+
+  return icon;
+}
+
 std::string DBManager::GetSetupAppId(const char* provider_id) {
   static const char query[] =
     "SELECT DISTINCT setup_appid FROM provider_setup_appid WHERE provider_id=?";
index 8c2afc6..6f5e9d1 100644 (file)
@@ -55,6 +55,7 @@ class EXPORT_API DBManager {
   static int GetSupportTypes(std::string& provider_id, int* types);
   static int GetProviderPeriod(std::string& provider_id, int* period);
   static std::string GetLabel(const char* provider_id);
+  static std::string GetIcon(const char* provider_id);
   static std::string GetSetupAppId(const char* provider_id);
   static bool IsProviderExist(std::string& provider_id, int support_type);
   static std::list<std::string> GetProviderListWithAppId(const char* provider_id);
diff --git a/watchface-editor/include/watchface-editor-internal.h b/watchface-editor/include/watchface-editor-internal.h
new file mode 100644 (file)
index 0000000..db9a145
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 __TIZEN_APPFW_WATCHFACE_EDITOR_INTERNAL_H__
+#define __TIZEN_APPFW_WATCHFACE_EDITOR_INTERNAL_H__
+
+#include <tizen.h>
+#include <bundle.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int watchface_editor_get_complication_provider_icon(
+        const bundle* candidate_data, char** icon);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* __TIZEN_APPFW_WATCHFACE_EDITOR_INTERNAL_H__ */
index 65f8bd9..b294525 100644 (file)
@@ -19,6 +19,7 @@
 #include <glib.h>
 #include <dlog.h>
 #include <app_control.h>
+#include <aul.h>
 
 #include <string>
 
@@ -637,6 +638,38 @@ extern "C" EXPORT_API int watchface_editor_get_complication_provider_name(
   return WATCHFACE_COMPLICATION_ERROR_NONE;
 }
 
+extern "C" EXPORT_API int watchface_editor_get_complication_provider_icon(
+    const bundle* candidate_data, char** icon) {
+  if (!watchface_complication::util::CheckWatchFeatureEnabled())
+    return WATCHFACE_COMPLICATION_ERROR_NOT_SUPPORTED;
+
+  if (candidate_data == NULL || icon == NULL)
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+
+  char* val = NULL;
+  bundle_get_str(const_cast<bundle*>(candidate_data),
+      Complication::GetProviderIdKey(), &val);
+  if (val != NULL) {
+    std::string ic = DBManager::GetIcon(val);
+    if (!ic.empty()) {
+      char* shared_path;
+      aul_get_app_shared_resource_path_by_appid(
+          DBManager::GetProviderAppId(val).c_str(), &shared_path);
+      std::string app_path = std::string(shared_path) + ic;
+      free(shared_path);
+      LOGI("icon path : (%s)", app_path.c_str());
+      *icon = strdup(app_path.c_str());
+    } else {
+      LOGE("fail to get name (%s)", val);
+      return WATCHFACE_COMPLICATION_ERROR_NO_DATA;
+    }
+  } else {
+    return WATCHFACE_COMPLICATION_ERROR_INVALID_PARAMETER;
+  }
+
+  return WATCHFACE_COMPLICATION_ERROR_NONE;
+}
+
 extern "C" EXPORT_API int watchface_editor_get_complication_is_supported(
     const bundle* candidate_data, bool* is_supported,
     watchface_editor_error_e* error, char** error_message) {