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;
xmlNode* privilege_node = nullptr;
xmlNode* support_event_node = nullptr;
list<xmlNode*> label_list;
+ list<xmlNode*> icon_list;
if (node->children == NULL)
return false;
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")) {
}
}
+ 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");
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, \
); \
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",
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=?";
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);
--- /dev/null
+/*
+ * 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__ */
#include <glib.h>
#include <dlog.h>
#include <app_control.h>
+#include <aul.h>
#include <string>
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) {