2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file web_provider_livebox_info.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
22 #include "WebProviderDB.h"
23 #include "web_provider_livebox_info.h"
25 static const std::string infoTable("LiveboxInfo");
27 // TODO this default type should be retrieved more automatically
28 static const std::string defaultBoxType("app");
30 const char* web_provider_livebox_get_default_type()
32 return defaultBoxType.c_str();
35 const char* web_provider_livebox_get_box_type(const char* box_id)
41 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
42 if (!handle->openDB()) {
46 std::string query = "select * from " + infoTable + " where box_id = ?";
47 if (!handle->setCommand(query, "s", box_id)) {
52 if (!handle->executeCommand()) {
57 const char* box_type = handle->getText(2);
58 const char* box_type_dup = NULL;
61 box_type_dup = strdup(box_type);
69 const char* web_provider_livebox_get_app_id(const char* box_id)
75 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
76 if (!handle->openDB()) {
80 std::string query = "select * from " + infoTable + " where box_id = ?";
81 if (!handle->setCommand(query, "s", box_id)) {
86 if (!handle->executeCommand()) {
91 const char* app_id = handle->getText(1);
92 const char* app_id_dup = NULL;
95 app_id_dup = strdup(app_id);
103 int web_provider_livebox_get_auto_launch(const char* box_id)
109 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
110 if (!handle->openDB()) {
114 std::string query = "select * from " + infoTable + " where box_id = ?";
115 if (!handle->setCommand(query, "s", box_id)) {
120 if (!handle->executeCommand()) {
125 int autoLaunch = handle->getInt(3);
131 int web_provider_livebox_insert_box_info(
134 const char* box_type,
137 if (!box_id || !app_id || !box_type) {
141 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
142 if (!handle->openDB()) {
147 "insert into " + infoTable +
148 " (box_id, app_id, box_type, auto_launch) values (?,?,?,?)";
150 if (!handle->setCommand(query, "sssi", box_id, app_id, box_type, auto_launch)) {
155 if (!handle->executeCommand()) {
164 int web_provider_livebox_insert_box_type(
167 const char* box_type)
169 return web_provider_livebox_insert_box_info(box_id, app_id, box_type, 0);
172 int web_provider_livebox_delete_by_box_id(const char* box_id)
178 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
179 if (!handle->openDB()) {
184 "delete from " + infoTable + " where box_id=?";
186 if (!handle->setCommand(query, "s", box_id)) {
191 if (!handle->executeCommand()) {
200 int web_provider_livebox_delete_by_app_id(const char* app_id)
206 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
207 if (!handle->openDB()) {
212 "delete from " + infoTable + " where app_id=?";
214 if (!handle->setCommand(query, "s", app_id)) {
219 if (!handle->executeCommand()) {
228 int web_provider_livebox_delete_by_type(const char* type)
234 std::shared_ptr<WebProviderDB> handle(new WebProviderDB());
235 if (!handle->openDB()) {
240 "delete from " + infoTable + " where type=?";
242 if (!handle->setCommand(query, "s", type)) {
247 if (!handle->executeCommand()) {
256 const char* web_provider_info_get_default_type()
258 return web_provider_livebox_get_default_type();
261 const char* web_provider_info_get_box_type(const char* box_id)
263 return web_provider_livebox_get_box_type(box_id);
266 int web_provider_info_insert_box_type(
269 const char* box_type)
271 return web_provider_livebox_insert_box_info(box_id, app_id, box_type, 0);
274 int web_provider_info_delete_by_box_id(const char* box_id)
276 return web_provider_livebox_delete_by_box_id(box_id);
279 int web_provider_info_delete_by_app_id(const char* app_id)
281 return web_provider_livebox_delete_by_app_id(app_id);
284 int web_provider_info_delete_by_type(const char* type)
286 return web_provider_livebox_delete_by_type(type);