4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
30 #include <sys/types.h>
37 #include "ail_private.h"
42 #define OPT_DESKTOP_DIRECTORY "/opt/share/applications"
43 #define USR_DESKTOP_DIRECTORY "/usr/share/applications"
46 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
47 #define argsdelimiter " \t"
49 #define SQL_INSERT_LOCALNAME_STR "insert into localname (package, locale, name) values "
50 #define SQL_INSERT_LOCALNAME_STR_LEN (sizeof(SQL_INSERT_LOCALNAME_STR)-1)
52 #define SQL_INSERT_LOCALNAME_INIT_STR SQL_INSERT_LOCALNAME_STR"( ?, ?, ?) "
54 #define SQL_LOCALNAME_TRIPLET_STR ", ( ?, ?, ?)"
55 #define SQL_LOCALNAME_TRIPLET_STR_LEN (sizeof(SQL_LOCALNAME_TRIPLET_STR)-1)
66 ail_error_e (*value_cb)(void *data, char *tag, char *value);
69 inline static char *_ltrim(char *str)
71 if (!str) return NULL;
73 while (*str == ' ' || *str == '\t' || *str == '\n') str ++;
80 inline static int _rtrim(char *str)
85 while (--len >= 0 && (str[len] == ' ' || str[len] == '\n' || str[len] == '\t')) str[len] = '\0';
105 char* x_slp_packagetype;
106 char* x_slp_packagecategories;
107 char* x_slp_packageid;
110 char* x_slp_exe_path;
114 char* x_slp_submodemainid;
115 char* x_slp_installedstorage;
116 int x_slp_baselayoutwidth;
117 int x_slp_installedtime;
119 int x_slp_taskmanage;
122 int x_slp_ishorizontalscale;
131 static ail_error_e _read_exec(void *data, char *tag, char *value)
133 desktop_info_s *info = data;
134 char *token_exe_path;
138 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
139 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
141 SAFE_FREE_AND_STRDUP(value, info->exec);
142 retv_if(!info->exec, AIL_ERROR_OUT_OF_MEMORY);
144 temp_exec = strdup(value);
147 return AIL_ERROR_OUT_OF_MEMORY;
150 token_exe_path = strtok_r(temp_exec, argsdelimiter, &save_ptr);
152 info->x_slp_exe_path = strdup(token_exe_path);
153 if(!info->x_slp_exe_path) {
157 return AIL_ERROR_OUT_OF_MEMORY;
167 static ail_error_e _read_name(void *data, char *tag, char *value)
169 desktop_info_s *info = data;
171 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
172 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
173 retv_if(0 == strlen(value), AIL_ERROR_FAIL);
175 if (tag && strlen(tag) > 0) {
176 struct name_item *item;
177 item = (struct name_item *)calloc(1, sizeof(struct name_item));
178 retv_if (NULL == item, AIL_ERROR_OUT_OF_MEMORY);
180 SAFE_FREE_AND_STRDUP(tag, item->locale);
181 if(NULL == item->locale) {
182 _E("(NULL == item->locale) return\n");
184 return AIL_ERROR_OUT_OF_MEMORY;
187 SAFE_FREE_AND_STRDUP(value, item->name);
188 if(NULL == item->name) {
189 _E("(NULL == item->name) return\n");
192 return AIL_ERROR_OUT_OF_MEMORY;
195 info->localname = g_slist_append(info->localname, item);
199 SAFE_FREE_AND_STRDUP(value, info->name);
200 retv_if (!info->name, AIL_ERROR_OUT_OF_MEMORY);
208 static ail_error_e _read_type(void *data, char *tag, char *value)
210 desktop_info_s *info = data;
212 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
213 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
215 SAFE_FREE_AND_STRDUP(value, info->type);
216 retv_if (!info->type, AIL_ERROR_OUT_OF_MEMORY);
223 _get_package_from_icon(char* icon)
228 retv_if(!icon, NULL);
230 package = strdup(icon);
231 retv_if(!package, NULL);
232 extension = rindex(package, '.');
236 _E("cannot extract from icon [%s] to package.", icon);
244 _get_icon_with_path(char* icon)
246 retv_if(!icon, NULL);
248 if (index(icon, '/') == NULL) {
251 char* icon_with_path = NULL;
254 package = _get_package_from_icon(icon);
255 retv_if(!package, NULL);
257 /* "db/setting/theme" is not exist */
259 theme = vconf_get_str("db/setting/theme");
261 theme = strdup("default");
268 theme = strdup("default");
271 len = (0x01 << 7) + strlen(icon) + strlen(package) + strlen(theme);
272 icon_with_path = malloc(len);
273 if(icon_with_path == NULL) {
274 _E("(icon_with_path == NULL) return\n");
280 memset(icon_with_path, 0, len);
282 sqlite3_snprintf( len, icon_with_path,"/opt/share/icons/%q/small/%q", theme, icon);
284 if (access(icon_with_path, R_OK) == 0) break;
285 sqlite3_snprintf( len, icon_with_path,"/usr/share/icons/%q/small/%q", theme, icon);
286 if (access(icon_with_path, R_OK) == 0) break;
287 _D("cannot find icon %s", icon_with_path);
288 sqlite3_snprintf( len, icon_with_path, "/opt/share/icons/default/small/%q", icon);
289 if (access(icon_with_path, R_OK) == 0) break;
290 sqlite3_snprintf( len, icon_with_path, "/usr/share/icons/default/small/%q", icon);
291 if (access(icon_with_path, R_OK) == 0) break;
293 #if 1 /* this will be remove when finish the work for moving icon path */
294 _E("icon file must be moved to %s", icon_with_path);
295 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/%q/small/%q", package, theme, icon);
296 if (access(icon_with_path, R_OK) == 0) break;
297 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/%q/small/%q", package, theme, icon);
298 if (access(icon_with_path, R_OK) == 0) break;
299 _D("cannot find icon %s", icon_with_path);
300 sqlite3_snprintf( len, icon_with_path, "/opt/apps/%q/res/icons/default/small/%q", package, icon);
301 if (access(icon_with_path, R_OK) == 0) break;
302 sqlite3_snprintf( len, icon_with_path, "/usr/apps/%q/res/icons/default/small/%q", package, icon);
303 if (access(icon_with_path, R_OK) == 0) break;
310 _D("Icon path : %s ---> %s", icon, icon_with_path);
312 return icon_with_path;
314 char* confirmed_icon = NULL;
316 confirmed_icon = strdup(icon);
317 retv_if(!confirmed_icon, NULL);
318 return confirmed_icon;
323 static ail_error_e _read_icon(void *data, char *tag, char *value)
325 desktop_info_s *info = data;
327 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
328 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
330 info->icon = _get_icon_with_path(value);
332 retv_if (!info->icon, AIL_ERROR_OUT_OF_MEMORY);
339 static ail_error_e _read_categories(void *data, char *tag, char *value)
341 desktop_info_s *info = data;
343 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
344 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
346 SAFE_FREE_AND_STRDUP(value, info->categories);
347 retv_if (!info->categories, AIL_ERROR_OUT_OF_MEMORY);
354 static ail_error_e _read_version(void *data, char *tag, char *value)
356 desktop_info_s *info = data;
358 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
359 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
361 SAFE_FREE_AND_STRDUP(value, info->version);
362 retv_if (!info->version, AIL_ERROR_OUT_OF_MEMORY);
369 static ail_error_e _read_mimetype(void *data, char *tag, char *value)
371 desktop_info_s *info = data;
372 int size, total_len = 0;
373 char *mimes_origin, *mimes_changed, *token_unalias, *save_ptr;
375 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
376 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
377 retv_if(!strlen(value), AIL_ERROR_FAIL);
379 mimes_origin = strdup(value);
380 retv_if(!mimes_origin, AIL_ERROR_OUT_OF_MEMORY);
382 size = getpagesize();
383 mimes_changed = calloc(1, size);
384 if(mimes_changed == NULL) {
385 _E("(mimes_changed == NULL) return\n");
387 return AIL_ERROR_OUT_OF_MEMORY;
390 token_unalias = strtok_r(mimes_origin, ";", &save_ptr);
392 while (token_unalias) {
394 const char *token_alias;
396 _rtrim(token_unalias);
397 token_unalias = _ltrim(token_unalias);
399 token_alias = xdg_mime_unalias_mime_type(token_unalias);
400 if (!token_alias) continue;
402 token_len = strlen(token_alias);
403 if (total_len + token_len + (1<<1) >= size) {
406 tmp = realloc(mimes_changed, size);
409 return AIL_ERROR_OUT_OF_MEMORY;
414 strncat(mimes_changed, token_alias, size-1);
415 total_len += token_len;
417 token_unalias = strtok_r(NULL, ";", &save_ptr);
419 strncat(mimes_changed, ";", size-strlen(mimes_changed)-1);
423 SAFE_FREE(info->mimetype);
424 info->mimetype = mimes_changed;
431 static ail_error_e _read_nodisplay(void *data, char *tag, char *value)
433 desktop_info_s* info = data;
435 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
436 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
438 info->nodisplay = !strcasecmp(value, "true");
445 static ail_error_e _read_x_slp_service(void *data, char *tag, char *value)
447 desktop_info_s *info = data;
449 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
450 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
452 SAFE_FREE_AND_STRDUP(value, info->x_slp_service);
453 retv_if(!info->x_slp_service, AIL_ERROR_OUT_OF_MEMORY);
460 static ail_error_e _read_x_slp_packagetype(void *data, char *tag, char *value)
462 desktop_info_s *info = data;
464 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
465 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
467 SAFE_FREE_AND_STRDUP(value, info->x_slp_packagetype);
468 retv_if(!info->x_slp_packagetype, AIL_ERROR_OUT_OF_MEMORY);
475 static ail_error_e _read_x_slp_packagecategories(void *data, char *tag, char *value)
477 desktop_info_s *info = data;
479 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
480 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
482 SAFE_FREE_AND_STRDUP(value, info->x_slp_packagecategories);
483 retv_if(!info->x_slp_packagecategories, AIL_ERROR_OUT_OF_MEMORY);
490 static ail_error_e _read_x_slp_packageid(void *data, char *tag, char *value)
492 desktop_info_s *info = data;
494 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
495 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
497 SAFE_FREE_AND_STRDUP(value, info->x_slp_packageid);
498 retv_if(!info->x_slp_packageid, AIL_ERROR_OUT_OF_MEMORY);
503 static ail_error_e _read_x_slp_submodemainid(void *data, char *tag, char *value)
505 desktop_info_s *info = data;
507 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
508 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
510 SAFE_FREE_AND_STRDUP(value, info->x_slp_submodemainid);
511 retv_if(!info->x_slp_submodemainid, AIL_ERROR_OUT_OF_MEMORY);
516 static ail_error_e _read_x_slp_installedstorage(void *data, char *tag, char *value)
518 desktop_info_s *info = data;
520 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
521 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
523 SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage);
524 retv_if(!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY);
529 static ail_error_e _read_x_slp_uri(void *data, char *tag, char *value)
531 desktop_info_s *info = data;
533 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
534 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
536 SAFE_FREE_AND_STRDUP(value, info->x_slp_uri);
537 retv_if(!info->x_slp_uri, AIL_ERROR_OUT_OF_MEMORY);
544 static ail_error_e _read_x_slp_svc(void *data, char *tag, char *value)
546 desktop_info_s *info = data;
548 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
549 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
551 SAFE_FREE_AND_STRDUP(value, info->x_slp_svc);
552 retv_if(!info->x_slp_svc, AIL_ERROR_OUT_OF_MEMORY);
559 static ail_error_e _read_x_slp_taskmanage(void *data, char *tag, char *value)
561 desktop_info_s *info = data;
563 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
564 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
566 info->x_slp_taskmanage = !strcasecmp(value, "true");
573 static ail_error_e _read_x_slp_multiple(void *data, char *tag, char *value)
575 desktop_info_s *info = data;
577 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
578 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
580 info->x_slp_multiple = !strcasecmp(value, "true");
587 static ail_error_e _read_x_slp_removable(void *data, char *tag, char *value)
589 desktop_info_s *info = data;
591 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
592 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
594 info->x_slp_removable = !strcasecmp(value, "true");
600 static ail_error_e _read_x_slp_submode(void *data, char *tag, char *value)
602 desktop_info_s *info = data;
604 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
605 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
607 info->x_slp_submode = !strcasecmp(value, "true");
612 static ail_error_e _read_x_slp_appid(void *data, char *tag, char *value)
614 desktop_info_s *info = data;
616 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
617 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
619 SAFE_FREE_AND_STRDUP(value, info->x_slp_appid);
620 retv_if(!info->x_slp_appid, AIL_ERROR_OUT_OF_MEMORY);
626 static ail_error_e _read_x_slp_pkgid(void *data, char *tag, char *value)
628 desktop_info_s *info = data;
630 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
631 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
633 SAFE_FREE_AND_STRDUP(value, info->x_slp_pkgid);
634 retv_if(!info->x_slp_pkgid, AIL_ERROR_OUT_OF_MEMORY);
640 static ail_error_e _read_x_slp_domain(void *data, char *tag, char *value)
642 desktop_info_s *info = data;
644 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
645 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
647 SAFE_FREE_AND_STRDUP(value, info->x_slp_domain);
648 retv_if(!info->x_slp_appid, AIL_ERROR_OUT_OF_MEMORY);
654 static ail_error_e _read_x_slp_enabled(void *data, char *tag, char *value)
656 desktop_info_s *info = data;
658 retv_if(!data, AIL_ERROR_INVALID_PARAMETER);
659 retv_if(!value, AIL_ERROR_INVALID_PARAMETER);
661 info->x_slp_enabled = !strcasecmp(value, "true");
667 static struct entry_parser entry_parsers[] = {
670 .value_cb = _read_exec,
674 .value_cb = _read_name,
678 .value_cb = _read_type,
682 .value_cb = _read_icon,
685 .field = "categories",
686 .value_cb = _read_categories,
690 .value_cb = _read_version,
694 .value_cb = _read_mimetype,
697 .field = "x-tizen-service",
698 .value_cb = _read_x_slp_service,
701 .field = "x-tizen-packagetype",
702 .value_cb = _read_x_slp_packagetype,
705 .field = "x-tizen-packagecategories",
706 .value_cb = _read_x_slp_packagecategories,
709 .field = "x-tizen-packageid",
710 .value_cb = _read_x_slp_packageid,
713 .field = "x-tizen-submodemainid",
714 .value_cb = _read_x_slp_submodemainid,
717 .field = "x-tizen-installedstorage",
718 .value_cb = _read_x_slp_installedstorage,
721 .field = "x-tizen-uri",
722 .value_cb = _read_x_slp_uri,
725 .field = "x-tizen-svc",
726 .value_cb = _read_x_slp_svc,
729 .field = "nodisplay",
730 .value_cb = _read_nodisplay,
733 .field = "x-tizen-taskmanage",
734 .value_cb = _read_x_slp_taskmanage,
737 .field = "x-tizen-enabled",
738 .value_cb = _read_x_slp_enabled,
741 .field = "x-tizen-submode",
742 .value_cb = _read_x_slp_submode,
745 .field = "x-tizen-multiple",
746 .value_cb = _read_x_slp_multiple,
749 .field = "x-tizen-removable",
750 .value_cb = _read_x_slp_removable,
753 .field = "x-tizen-appid",
754 .value_cb = _read_x_slp_appid,
757 .field = "x-tizen-pkgid",
758 .value_cb = _read_x_slp_pkgid,
761 .field = "x-tizen-domain",
762 .value_cb = _read_x_slp_domain,
765 .field = "x-tizen-enabled",
766 .value_cb = _read_x_slp_domain,
776 /* Utility functions */
777 static int _count_all(void)
782 ret = ail_filter_count_appinfo(NULL, &count);
783 if(ret != AIL_ERROR_OK) {
784 _E("cannot count appinfo");
788 retv_if(ret != AIL_ERROR_OK, -1);
795 char *_pkgname_to_desktop(const char *package)
800 retv_if(!package, NULL);
802 size = strlen(OPT_DESKTOP_DIRECTORY) + strlen(package) + 10;
803 desktop = malloc(size);
804 retv_if(!desktop, NULL);
806 snprintf(desktop, size, OPT_DESKTOP_DIRECTORY"/%s.desktop", package);
808 if (access(desktop, R_OK) == 0)
811 snprintf(desktop, size, USR_DESKTOP_DIRECTORY"/%s.desktop", package);
816 static inline int _bind_local_info(desktop_info_s* info, sqlite3_stmt * stmt)
820 struct name_item *item;
822 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
823 retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
824 retv_if(!stmt, AIL_ERROR_INVALID_PARAMETER);
825 localname = info->localname;
827 item = (struct name_item *) localname->data;
828 if (item && item->locale && item->name) {
829 // Bind values for a triplet : package, locale, name
830 retv_if(db_bind_text(stmt, i+1, info->package) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
831 retv_if(db_bind_text(stmt, i+2, item->locale) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
832 retv_if(db_bind_text(stmt, i+3, item->name) != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
835 localname = g_slist_next(localname);
841 static inline int _len_local_info(desktop_info_s* info)
844 struct name_item *item;
846 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
847 if(info->localname) {
848 localname = info->localname;
850 item = (struct name_item *) localname->data;
851 if (item && item->locale && item->name)
853 localname = g_slist_next(localname);
860 static inline int _insert_local_info(desktop_info_s* info)
862 int len_query = SQL_INSERT_LOCALNAME_STR_LEN;
865 int ret = AIL_ERROR_OK;
866 sqlite3_stmt *stmt = NULL;
868 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
869 retv_if(!info->localname, AIL_ERROR_INVALID_PARAMETER);
871 nb_locale_args = _len_local_info(info);
873 retv_if(!nb_locale_args, AIL_ERROR_INVALID_PARAMETER);
875 len_query += SQL_LOCALNAME_TRIPLET_STR_LEN*nb_locale_args +1;
877 query = (char *) malloc(len_query);
878 retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
879 stpncpy(query, SQL_INSERT_LOCALNAME_INIT_STR, len_query);
880 for (i = 0; i < nb_locale_args - 1; i++)
881 strcat(query, SQL_LOCALNAME_TRIPLET_STR);
884 ret = db_prepare_rw(query, &stmt);
887 ret = _bind_local_info(info, stmt);
889 _E("Can't bind locale information to this query - %s. ",query);
894 if (ret != AIL_ERROR_NO_DATA) {
895 /* Insert Request doesn't return any data.
896 * db_step should returns AIL_ERROR_NO_DATA in this case. */
897 _E("Can't execute this query - %s. ",query);
901 ret = db_finalize(stmt);
908 static inline int _strlen_desktop_info(desktop_info_s* info)
912 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
914 if (info->package) len += strlen(info->package);
915 if (info->exec) len += strlen(info->exec);
916 if (info->name) len += strlen(info->name);
917 if (info->type) len += strlen(info->type);
918 if (info->icon) len += strlen(info->icon);
919 if (info->categories) len += strlen(info->categories);
920 if (info->version) len += strlen(info->version);
921 if (info->mimetype) len += strlen(info->mimetype);
922 if (info->x_slp_service) len += strlen(info->x_slp_service);
923 if (info->x_slp_packagetype) len += strlen(info->x_slp_packagetype);
924 if (info->x_slp_packagecategories) len += strlen(info->x_slp_packagecategories);
925 if (info->x_slp_packageid) len += strlen(info->x_slp_packageid);
926 if (info->x_slp_uri) len += strlen(info->x_slp_uri);
927 if (info->x_slp_svc) len += strlen(info->x_slp_svc);
928 if (info->x_slp_exe_path) len += strlen(info->x_slp_exe_path);
929 if (info->x_slp_appid) len += strlen(info->x_slp_appid);
930 if (info->desktop) len += strlen(info->desktop);
931 if (info->x_slp_submodemainid) len += strlen(info->x_slp_submodemainid);
932 if (info->x_slp_installedstorage) len += strlen(info->x_slp_installedstorage);
938 int __is_ail_initdb(void)
940 if( getenv("AIL_INITDB") || getenv("INITDB") )
948 /* Manipulating desktop_info functions */
949 static ail_error_e _init_desktop_info(desktop_info_s *info, const char *package)
951 static int is_initdb = -1;
954 is_initdb = __is_ail_initdb();
956 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
957 retv_if(!package, AIL_ERROR_INVALID_PARAMETER);
960 info->package = package;
962 info->x_slp_taskmanage = 1;
963 info->x_slp_removable = 1;
964 info->x_slp_submode = 0;
967 info->x_slp_installedtime = 0;
969 info->x_slp_installedtime = time(NULL);
972 info->x_slp_packagetype = strdup(PKGTYPE);
974 info->x_slp_packagetype = strdup("rpm");
976 retv_if(!info->x_slp_packagetype, AIL_ERROR_OUT_OF_MEMORY);
978 info->x_slp_packageid = strdup(package);
979 retv_if(!info->x_slp_packageid, AIL_ERROR_OUT_OF_MEMORY);
980 info->x_slp_appid = strdup(package);
981 retv_if(!info->x_slp_appid, AIL_ERROR_OUT_OF_MEMORY);
983 info->x_slp_enabled = 1;
985 info->desktop = _pkgname_to_desktop(package);
986 retv_if(!info->desktop, AIL_ERROR_FAIL);
993 static ail_error_e _read_desktop_info(desktop_info_s* info)
1000 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
1002 fp = fopen(info->desktop, "r");
1003 retv_if(!fp, AIL_ERROR_FAIL);
1005 while ((read = getline(&line, &size, fp)) != -1) {
1007 char *tmp, *field, *field_name, *tag, *value;
1010 if(tmp == NULL) continue;
1011 if (*tmp == '#') continue;
1012 if (_rtrim(tmp) <= 0) continue;
1014 len = strlen(line) + 1;
1015 field = calloc(1, len);
1016 field_name = calloc(1, len);
1017 tag = calloc(1, len);
1018 value = calloc(1, len);
1020 if (!field || !field_name || !tag || !value) {
1024 sscanf(tmp, "%[^=]=%[^\n]", field, value);
1026 tmp = _ltrim(value);
1028 sscanf(field, "%[^[][%[^]]]", field_name, tag);
1030 if (!field_name || !strlen(field_name)){
1034 for (idx = 0; entry_parsers[idx].field; idx ++) {
1035 if (!g_ascii_strcasecmp(entry_parsers[idx].field, field_name) && entry_parsers[idx].value_cb) {
1036 if (entry_parsers[idx].value_cb(info, tag, tmp) != AIL_ERROR_OK) {
1037 _E("field - [%s] is wrong.", field_name);
1044 SAFE_FREE(field_name);
1049 _D("Read (%s).", info->package);
1052 return AIL_ERROR_OK;
1056 static ail_error_e _retrieve_all_column_to_desktop_info(desktop_info_s* info, sqlite3_stmt *stmt)
1063 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
1065 values = calloc(NUM_OF_PROP, sizeof(char *));
1066 retv_if(!values, AIL_ERROR_OUT_OF_MEMORY);
1068 for (i = 0; i < NUM_OF_PROP; i++) {
1069 err = db_column_str(stmt, i, &col);
1070 if (AIL_ERROR_OK != err)
1076 values[i] = strdup(col);
1078 err = AIL_ERROR_OUT_OF_MEMORY;
1084 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_EXEC_STR], info->exec);
1085 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_NAME_STR], info->name);
1086 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_TYPE_STR], info->type);
1087 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_ICON_STR], info->icon);
1088 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_CATEGORIES_STR], info->categories);
1089 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_VERSION_STR], info->version);
1090 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_MIMETYPE_STR], info->mimetype);
1091 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_SERVICE_STR], info->x_slp_service);
1092 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_PACKAGETYPE_STR], info->x_slp_packagetype);
1093 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_PACKAGECATEGORIES_STR], info->x_slp_packagecategories);
1094 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_PACKAGEID_STR], info->x_slp_packageid);
1095 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_URI_STR], info->x_slp_uri);
1096 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_SVC_STR], info->x_slp_svc);
1097 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_EXE_PATH], info->x_slp_exe_path);
1098 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_APPID_STR], info->x_slp_appid);
1099 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_PKGID_STR], info->x_slp_pkgid);
1100 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_DOMAIN_STR], info->x_slp_domain);
1101 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_SUBMODEMAINID_STR], info->x_slp_submodemainid);
1102 SAFE_FREE_AND_STRDUP(values[E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR], info->x_slp_installedstorage);
1104 info->x_slp_installedtime = atoi(values[E_AIL_PROP_X_SLP_INSTALLEDTIME_INT]);
1106 info->nodisplay = atoi(values[E_AIL_PROP_NODISPLAY_BOOL]);
1107 info->x_slp_taskmanage = atoi(values[E_AIL_PROP_X_SLP_TASKMANAGE_BOOL]);
1108 info->x_slp_multiple = atoi(values[E_AIL_PROP_X_SLP_MULTIPLE_BOOL]);
1109 info->x_slp_removable = atoi(values[E_AIL_PROP_X_SLP_REMOVABLE_BOOL]);
1110 info->x_slp_ishorizontalscale = atoi(values[E_AIL_PROP_X_SLP_ISHORIZONTALSCALE_BOOL]);
1111 info->x_slp_enabled = atoi(values[E_AIL_PROP_X_SLP_ENABLED_BOOL]);
1112 info->x_slp_submode = atoi(values[E_AIL_PROP_X_SLP_SUBMODE_BOOL]);
1117 for (j = 0; j < i; ++j) {
1127 static ail_error_e _load_desktop_info(desktop_info_s* info)
1130 char query[AIL_SQL_QUERY_MAX_LEN];
1131 sqlite3_stmt *stmt = NULL;
1132 char w[AIL_SQL_QUERY_MAX_LEN];
1134 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
1136 snprintf(w, sizeof(w), sql_get_filter(E_AIL_PROP_X_SLP_APPID_STR), info->package);
1138 snprintf(query, sizeof(query), "SELECT %s FROM %s WHERE %s",SQL_FLD_APP_INFO, SQL_TBL_APP_INFO, w);
1141 ret = db_open(DB_OPEN_RO);
1144 ret = db_prepare(query, &stmt);
1147 ret = db_step(stmt);
1153 ret = _retrieve_all_column_to_desktop_info(info, stmt);
1159 ret = db_finalize(stmt);
1162 return AIL_ERROR_OK;
1168 static ail_error_e _modify_desktop_info_bool(desktop_info_s* info,
1169 const char *property,
1172 ail_prop_bool_e prop;
1175 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
1176 retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
1178 prop = _ail_convert_to_prop_bool(property);
1180 if (prop < E_AIL_PROP_BOOL_MIN || prop > E_AIL_PROP_BOOL_MAX)
1181 return AIL_ERROR_INVALID_PARAMETER;
1184 case E_AIL_PROP_X_SLP_ENABLED_BOOL:
1185 info->x_slp_enabled = (int)value;
1188 return AIL_ERROR_FAIL;
1191 return AIL_ERROR_OK;
1195 static ail_error_e _modify_desktop_info_str(desktop_info_s* info,
1196 const char *property,
1199 ail_prop_bool_e prop;
1202 retv_if(!info, AIL_ERROR_INVALID_PARAMETER);
1203 retv_if(!property, AIL_ERROR_INVALID_PARAMETER);
1205 prop = _ail_convert_to_prop_str(property);
1207 if (prop < E_AIL_PROP_STR_MIN || prop > E_AIL_PROP_STR_MAX)
1208 return AIL_ERROR_INVALID_PARAMETER;
1211 case E_AIL_PROP_NAME_STR:
1212 SAFE_FREE_AND_STRDUP(value, info->name);
1213 retv_if (!info->name, AIL_ERROR_OUT_OF_MEMORY);
1215 case E_AIL_PROP_X_SLP_SVC_STR:
1216 SAFE_FREE_AND_STRDUP(value, info->x_slp_svc);
1217 retv_if (!info->x_slp_svc, AIL_ERROR_OUT_OF_MEMORY);
1219 case E_AIL_PROP_X_SLP_INSTALLEDSTORAGE_STR:
1220 SAFE_FREE_AND_STRDUP(value, info->x_slp_installedstorage);
1221 retv_if (!info->x_slp_installedstorage, AIL_ERROR_OUT_OF_MEMORY);
1224 _E("prop[%d] is not defined\n", prop);
1225 return AIL_ERROR_FAIL;
1228 return AIL_ERROR_OK;
1234 static ail_error_e _create_table(void)
1238 const char *tbls[3] = {
1239 "CREATE TABLE app_info "
1240 "(package TEXT PRIMARY KEY, "
1241 "exec TEXT DEFAULT 'No Exec', "
1242 "name TEXT DEFAULT 'No Name', "
1243 "type TEXT DEFAULT 'Application', "
1244 "icon TEXT DEFAULT 'No Icon', "
1248 "x_slp_service TEXT, "
1249 "x_slp_packagetype TEXT, "
1250 "x_slp_packagecategories TEXT, "
1251 "x_slp_packageid TEXT, "
1254 "x_slp_exe_path TEXT, "
1255 "x_slp_appid TEXT, "
1256 "x_slp_pkgid TEXT, "
1257 "x_slp_domain TEXT, "
1258 "x_slp_submodemainid TEXT, "
1259 "x_slp_installedstorage TEXT, "
1260 "x_slp_baselayoutwidth INTEGER DEFAULT 0, "
1261 "x_slp_installedtime INTEGER DEFAULT 0, "
1262 "nodisplay INTEGER DEFAULT 0, "
1263 "x_slp_taskmanage INTEGER DEFAULT 1, "
1264 "x_slp_multiple INTEGER DEFAULT 0, "
1265 "x_slp_removable INTEGER DEFAULT 1, "
1266 "x_slp_ishorizontalscale INTEGER DEFAULT 0, "
1267 "x_slp_enabled INTEGER DEFAULT 1, "
1268 "x_slp_submode INTEGER DEFAULT 0, "
1269 "desktop TEXT UNIQUE NOT NULL);",
1270 "CREATE TABLE localname (package TEXT NOT NULL, "
1271 "locale TEXT NOT NULL, "
1272 "name TEXT NOT NULL, "
1273 "x_slp_pkgid TEXT NOT NULL, PRIMARY KEY (package, locale));",
1278 ret = db_open(DB_OPEN_RW);
1279 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
1281 for (i = 0; tbls[i] != NULL; i++) {
1282 ret = db_exec(tbls[i]);
1283 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
1286 return AIL_ERROR_OK;
1290 static inline void _insert_localname(gpointer data, gpointer user_data)
1294 struct name_item *item = (struct name_item *)data;
1295 desktop_info_s *info = (desktop_info_s *)user_data;
1297 sqlite3_snprintf(sizeof(query), query, "insert into localname (package, locale, name, x_slp_pkgid) "
1298 "values ('%q', '%q', '%q', '%q');",
1299 info->package, item->locale, item->name, info->x_slp_pkgid);
1300 if (db_exec(query) < 0)
1301 _E("Failed to insert local name of package[%s]",info->package);
1304 static ail_error_e _insert_desktop_info(desktop_info_s *info)
1310 len = _strlen_desktop_info(info) + (0x01 << 10);
1311 query = calloc(1, len);
1312 retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
1314 sqlite3_snprintf(len, query, "insert into app_info ("
1323 "x_slp_packagetype, "
1324 "x_slp_packagecategories, "
1332 "x_slp_submodemainid, "
1333 "x_slp_installedstorage, "
1334 "x_slp_baselayoutwidth, "
1335 "x_slp_installedtime, "
1337 "x_slp_taskmanage, "
1340 "x_slp_ishorizontalscale, "
1345 "('%q', '%q', '%q', '%q', '%q', "
1346 "'%q', '%q', '%q', '%q', '%q', "
1347 "'%q', '%q', '%q', '%q', '%q', "
1348 "'%q', '%q', '%q', '%q', '%q', "
1349 "%d, %d, %d, %d, %d, %d, %d,"
1360 info->x_slp_service,
1361 info->x_slp_packagetype,
1362 info->x_slp_packagecategories,
1363 info->x_slp_packageid,
1366 info->x_slp_exe_path,
1370 info->x_slp_submodemainid,
1371 info->x_slp_installedstorage,
1372 info->x_slp_baselayoutwidth,
1373 info->x_slp_installedtime,
1375 info->x_slp_taskmanage,
1376 info->x_slp_multiple,
1377 info->x_slp_removable,
1378 info->x_slp_ishorizontalscale,
1379 info->x_slp_enabled,
1380 info->x_slp_submode,
1384 ret = db_open(DB_OPEN_RW);
1385 if(ret != AIL_ERROR_OK) {
1386 _E("(tmp == NULL) return\n");
1388 return AIL_ERROR_DB_FAILED;
1391 ret = db_exec(query);
1393 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_DB_FAILED);
1395 if (info->localname)
1396 _insert_local_info(info);
1398 _D("Add (%s).", query);
1400 return AIL_ERROR_OK;
1405 static ail_error_e _update_desktop_info(desktop_info_s *info)
1410 retv_if (NULL == info, AIL_ERROR_INVALID_PARAMETER);
1412 if (db_open(DB_OPEN_RW) < 0) {
1413 return AIL_ERROR_DB_FAILED;
1416 len = _strlen_desktop_info(info) + (0x01 << 10);
1417 query = calloc(1, len);
1418 retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
1420 sqlite3_snprintf ( len, query, "update app_info set "
1428 "x_slp_service='%q', "
1429 "x_slp_packagetype='%q', "
1430 "x_slp_packagecategories='%q', "
1431 "x_slp_packageid='%q', "
1434 "x_slp_exe_path='%q', "
1435 "x_slp_appid='%q', "
1436 "x_slp_pkgid='%q', "
1437 "x_slp_domain='%q', "
1438 "x_slp_submodemainid='%q', "
1439 "x_slp_installedstorage='%q', "
1440 "x_slp_baselayoutwidth=%d, "
1441 "x_slp_installedtime=%d, "
1443 "x_slp_taskmanage=%d, "
1444 "x_slp_multiple=%d, "
1445 "x_slp_removable=%d, "
1446 "x_slp_ishorizontalscale=%d, "
1447 "x_slp_enabled=%d, "
1448 "x_slp_submode=%d, "
1450 "where package='%q'",
1458 info->x_slp_service,
1459 info->x_slp_packagetype,
1460 info->x_slp_packagecategories,
1461 info->x_slp_packageid,
1464 info->x_slp_exe_path,
1468 info->x_slp_submodemainid,
1469 info->x_slp_installedstorage,
1470 info->x_slp_baselayoutwidth,
1471 info->x_slp_installedtime,
1473 info->x_slp_taskmanage,
1474 info->x_slp_multiple,
1475 info->x_slp_removable,
1476 info->x_slp_ishorizontalscale,
1477 info->x_slp_enabled,
1478 info->x_slp_submode,
1482 if (db_exec(query) < 0) {
1484 return AIL_ERROR_DB_FAILED;
1487 snprintf(query, len, "delete from localname where package = '%s'", info->package);
1489 if (db_exec(query) < 0) {
1491 return AIL_ERROR_DB_FAILED;
1494 if (info->localname)
1495 _insert_local_info(info);
1497 _D("Update (%s).", info->package);
1501 return AIL_ERROR_OK;
1506 static ail_error_e _remove_package(const char* package)
1511 retv_if(!package, AIL_ERROR_INVALID_PARAMETER);
1513 if (db_open(DB_OPEN_RW) < 0) {
1514 return AIL_ERROR_DB_FAILED;
1517 size = strlen(package) + (0x01 << 10);
1518 query = calloc(1, size);
1519 retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
1521 snprintf(query, size, "delete from app_info where package = '%s'", package);
1523 if (db_exec(query) < 0) {
1525 return AIL_ERROR_DB_FAILED;
1528 snprintf(query, size, "delete from localname where package = '%s'", package);
1529 _D("query=%s",query);
1531 if (db_exec(query) < 0) {
1533 return AIL_ERROR_DB_FAILED;
1536 _D("Remove (%s).", package);
1539 return AIL_ERROR_OK;
1542 static ail_error_e _clean_pkgid_data(const char* pkgid)
1547 retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
1549 if (db_open(DB_OPEN_RW) < 0) {
1550 return AIL_ERROR_DB_FAILED;
1553 size = strlen(pkgid) + (0x01 << 10);
1554 query = calloc(1, size);
1555 retv_if(!query, AIL_ERROR_OUT_OF_MEMORY);
1557 snprintf(query, size, "delete from app_info where x_slp_pkgid = '%s'", pkgid);
1559 if (db_exec(query) < 0) {
1561 return AIL_ERROR_DB_FAILED;
1564 snprintf(query, size, "delete from localname where x_slp_pkgid = '%s'", pkgid);
1565 _D("query=%s",query);
1567 if (db_exec(query) < 0) {
1569 return AIL_ERROR_DB_FAILED;
1572 _D("Clean pkgid data (%s).", pkgid);
1575 return AIL_ERROR_OK;
1579 static ail_error_e _send_db_done_noti(noti_type type, const char *package)
1581 char *type_string, *noti_string;
1584 retv_if(!package, AIL_ERROR_INVALID_PARAMETER);
1588 type_string = "create";
1591 type_string = "update";
1594 type_string = "delete";
1597 return AIL_ERROR_FAIL;
1600 size = strlen(package) + 8;
1601 noti_string = calloc(1, size);
1602 retv_if(!noti_string, AIL_ERROR_OUT_OF_MEMORY);
1604 snprintf(noti_string, size, "%s:%s", type_string, package);
1605 vconf_set_str(VCONFKEY_AIL_INFO_STATE, noti_string);
1606 vconf_set_str(VCONFKEY_MENUSCREEN_DESKTOP, noti_string); // duplicate, will be removed
1607 _D("Noti : %s", noti_string);
1611 return AIL_ERROR_OK;
1615 static void inline _name_item_free_func(gpointer data)
1617 struct name_item *item = (struct name_item *)data;
1619 SAFE_FREE(item->locale);
1620 item->locale = NULL;
1621 SAFE_FREE(item->name);
1627 static void _fini_desktop_info(desktop_info_s *info)
1629 SAFE_FREE(info->exec);
1630 SAFE_FREE(info->name);
1631 SAFE_FREE(info->type);
1632 SAFE_FREE(info->icon);
1633 SAFE_FREE(info->categories);
1634 SAFE_FREE(info->version);
1635 SAFE_FREE(info->mimetype);
1636 SAFE_FREE(info->x_slp_service);
1637 SAFE_FREE(info->x_slp_packagetype);
1638 SAFE_FREE(info->x_slp_packagecategories);
1639 SAFE_FREE(info->x_slp_packageid);
1640 SAFE_FREE(info->x_slp_uri);
1641 SAFE_FREE(info->x_slp_svc);
1642 SAFE_FREE(info->x_slp_exe_path);
1643 SAFE_FREE(info->x_slp_appid);
1644 SAFE_FREE(info->x_slp_pkgid);
1645 SAFE_FREE(info->x_slp_domain);
1646 SAFE_FREE(info->x_slp_submodemainid);
1647 SAFE_FREE(info->x_slp_installedstorage);
1648 SAFE_FREE(info->desktop);
1649 if (info->localname) {
1650 g_slist_free_full(info->localname, _name_item_free_func);
1651 info->localname = NULL;
1657 static int __is_authorized()
1659 uid_t uid = getuid();
1660 if ((uid_t) 0 == uid )
1667 /* Public functions */
1668 EXPORT_API ail_error_e ail_desktop_add(const char *appid)
1670 desktop_info_s info = {0,};
1674 retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
1675 if (!__is_authorized()) {
1676 _E("You are not an authorized user on adding!\n");
1680 count = _count_all();
1682 ret = _create_table();
1683 if (ret != AIL_ERROR_OK) {
1684 _D("Cannot create a table. Maybe there is already a table.");
1688 ret = _init_desktop_info(&info, appid);
1689 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1691 ret = _read_desktop_info(&info);
1692 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1694 ret = _insert_desktop_info(&info);
1695 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1697 ret = _send_db_done_noti(NOTI_ADD, appid);
1698 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1700 _fini_desktop_info(&info);
1702 return AIL_ERROR_OK;
1707 EXPORT_API ail_error_e ail_desktop_update(const char *appid)
1709 desktop_info_s info = {0,};
1712 retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
1713 if (!__is_authorized()) {
1714 _E("You are not an authorized user on updating!\n");
1718 ret = _init_desktop_info(&info, appid);
1719 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1721 ret = _read_desktop_info(&info);
1722 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1724 ret = _update_desktop_info(&info);
1725 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1727 ret = _send_db_done_noti(NOTI_UPDATE, appid);
1728 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1730 _fini_desktop_info(&info);
1732 return AIL_ERROR_OK;
1737 EXPORT_API ail_error_e ail_desktop_remove(const char *appid)
1741 retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
1742 if (!__is_authorized()) {
1743 _E("You are not an authorized user on removing!\n");
1747 ret = _remove_package(appid);
1748 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1750 ret = _send_db_done_noti(NOTI_REMOVE, appid);
1751 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1753 return AIL_ERROR_OK;
1756 EXPORT_API ail_error_e ail_desktop_clean(const char *pkgid)
1760 retv_if(!pkgid, AIL_ERROR_INVALID_PARAMETER);
1761 if (!__is_authorized()) {
1762 _E("You are not an authorized user on removing!\n");
1766 _D("ail_desktop_clean=%s",pkgid);
1768 ret = _clean_pkgid_data(pkgid);
1769 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1771 return AIL_ERROR_OK;
1775 EXPORT_API ail_error_e ail_desktop_fota(const char *appid)
1777 desktop_info_s info = {0,};
1781 retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
1782 if (!__is_authorized()) {
1783 _E("You are not an authorized user on adding!\n");
1787 count = _count_all();
1789 ret = _create_table();
1790 if (ret != AIL_ERROR_OK) {
1791 _D("Cannot create a table. Maybe there is already a table.");
1795 ret = _init_desktop_info(&info, appid);
1796 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1798 ret = _read_desktop_info(&info);
1799 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1801 ret = _insert_desktop_info(&info);
1802 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1804 _fini_desktop_info(&info);
1806 return AIL_ERROR_OK;
1809 EXPORT_API ail_error_e ail_desktop_appinfo_modify_bool(const char *appid,
1810 const char *property,
1814 desktop_info_s info = {0,};
1817 retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
1819 retv_if(strcmp(property, AIL_PROP_X_SLP_ENABLED_BOOL),
1820 AIL_ERROR_INVALID_PARAMETER);
1822 ret = _init_desktop_info(&info, appid);
1823 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1825 ret = _load_desktop_info(&info);
1826 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1828 ret = _modify_desktop_info_bool(&info, property, value);
1829 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1831 ret = _update_desktop_info(&info);
1832 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1835 ret = _send_db_done_noti(NOTI_UPDATE, appid);
1836 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1839 _fini_desktop_info(&info);
1841 return AIL_ERROR_OK;
1845 EXPORT_API ail_error_e ail_desktop_appinfo_modify_str(const char *appid,
1846 const char *property,
1850 desktop_info_s info = {0,};
1853 retv_if(!appid, AIL_ERROR_INVALID_PARAMETER);
1855 ret = _init_desktop_info(&info, appid);
1856 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1858 ret = _load_desktop_info(&info);
1859 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1861 _D("info.name [%s], value [%s]", info.name, value);
1862 ret = _modify_desktop_info_str(&info, property, value);
1863 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1864 _D("info.name [%s], value [%s]", info.name, value);
1866 ret = _update_desktop_info(&info);
1867 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1870 ret = _send_db_done_noti(NOTI_UPDATE, appid);
1871 retv_if(ret != AIL_ERROR_OK, AIL_ERROR_FAIL);
1874 _fini_desktop_info(&info);
1876 return AIL_ERROR_OK;