4 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
6 * Contact: Jin Yoon <jinny.yoon@samsung.com>
7 * Junkyu Han <junkyu.han@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
30 #include "all_apps/db.h"
32 #define QUERY_LEN 1024
34 #define MENU_SCREEN_DB_FILE ".menu_screen.db"
35 #define SHORTCUT_TABLE "shortcut"
36 #define QUERY_INSERT_SHORTCUT "INSERT INTO "SHORTCUT_TABLE" ("\
43 "'%s', '%s', %d, '%s', '%s');"
44 #define QUERY_DELETE_SHORTCUT "DELETE FROM "SHORTCUT_TABLE" WHERE ROWID=%lld"
45 #define QUERY_GET_ALL "SELECT ROWID, appid, name, type, content_info, icon FROM "SHORTCUT_TABLE
46 #define QUERY_COUNT_SHORTCUT "SELECT COUNT(*) FROM "SHORTCUT_TABLE" WHERE appid='%s' AND name='%s'"
50 HAPI menu_screen_error_e all_apps_db_init(void)
52 return db_open(MENU_SCREEN_DB_FILE);
57 HAPI void all_apps_db_fini(void)
64 HAPI Eina_List *all_apps_db_retrieve_all_info(void)
67 Eina_List *list = NULL;
69 retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), NULL);
71 st = db_prepare(QUERY_GET_ALL);
72 retv_if(NULL == st, NULL);
74 menu_screen_error_e ret = MENU_SCREEN_ERROR_FAIL;
75 for (ret = db_next(st); MENU_SCREEN_ERROR_FAIL != ret && MENU_SCREEN_ERROR_NO_DATA != ret; ret = db_next(st)) {
77 info = calloc(1, sizeof(db_info));
78 break_if(NULL == info);
80 info->rowid = db_get_long_long(st, 0); // 0 : ROWID
83 tmp = (char *) db_get_str(st, 1); // 1 : appid
84 if (tmp && strlen(tmp)) {
85 info->appid = strdup(tmp);
86 goto_if(NULL == info->appid, APP_ERROR);
89 tmp = (char *) db_get_str(st, 2); // 2 : name
90 if (tmp && strlen(tmp)) {
91 info->name = strdup(tmp);
92 goto_if(NULL == info->name, APP_ERROR);
95 info->type = db_get_int(st, 3); // 3 : type
97 tmp = (char *) db_get_str(st, 4); // 4 : content_info
98 if (tmp && strlen(tmp)) {
99 info->content_info = strdup(tmp);
100 goto_if(NULL == info->content_info, APP_ERROR);
103 tmp = (char *) db_get_str(st, 5); // 5 : icon
104 if (tmp && strlen(tmp)) {
105 info->icon = strdup(tmp);
106 goto_if(NULL == info->icon, APP_ERROR);
109 list = eina_list_append(list, info);
112 free(info->content_info);
117 if (info->appid) free(info->appid);
118 if (info->name) free(info->name);
119 if (info->content_info) free(info->content_info);
120 if (info->icon) free(info->icon);
121 if (info) free(info);
131 HAPI void all_apps_db_unretrieve_info(db_info *info)
133 ret_if(NULL == info);
134 if (info->appid) free(info->appid);
135 if (info->name) free(info->name);
136 if (info->content_info) free(info->content_info);
137 if (info->icon) free(info->icon);
138 if (info) free(info);
143 HAPI void all_apps_db_unretrieve_all_info(Eina_List *list)
145 db_info *info = NULL;
147 EINA_LIST_FREE(list, info) {
148 if (NULL == info) break;
149 if (info->appid) free(info->appid);
150 if (info->name) free(info->name);
151 if (info->content_info) free(info->content_info);
152 if (info->icon) free(info->icon);
153 if (info) free(info);
156 eina_list_free(list);
161 HAPI int all_apps_db_count_shortcut(const char *appid, const char *name)
165 menu_screen_error_e ret = MENU_SCREEN_ERROR_FAIL;
167 retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), -1);
169 snprintf(q, sizeof(q), QUERY_COUNT_SHORTCUT, appid, name);
173 retv_if(NULL == st, -1);
176 if (MENU_SCREEN_ERROR_FAIL == ret) {
181 count = db_get_int(st, 0);
190 HAPI long long all_apps_db_insert_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon)
194 retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), -1l);
196 snprintf(q, sizeof(q), QUERY_INSERT_SHORTCUT, appid, name, type, content_info, icon);
197 retv_if(db_exec(q) < 0, -1l);
200 id = db_last_insert_rowid();
207 HAPI menu_screen_error_e all_apps_db_delete_shortcut(long long rowid)
211 retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), MENU_SCREEN_ERROR_FAIL);
213 snprintf(q, sizeof(q), QUERY_DELETE_SHORTCUT, rowid);
214 retv_if(db_exec(q) < 0, MENU_SCREEN_ERROR_FAIL);
216 return MENU_SCREEN_ERROR_OK;