diff options
-rw-r--r-- | src/widget_service.c | 148 |
1 files changed, 108 insertions, 40 deletions
diff --git a/src/widget_service.c b/src/widget_service.c index 2652843..9aaa2cc 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -387,6 +387,34 @@ static int _get_supported_size(int type, int *width, int *height) return 0; } +static int _convert_to_support_info(int *width, int *height, int *type, int count) +{ + int i; + int j; + + if (!_is_resolution_loaded) { + _resolution_update_from_file(); + _is_resolution_loaded = true; + } + + for (j = 0; j < count; j++) { + for (i = 0; i < WIDGET_SIZE_TYPE_MAX; i++) { + if (size_list[i][0] == width[j] && + size_list[i][1] == height[j]) + break; + } + if (i == WIDGET_SIZE_TYPE_MAX) { + _E("failed to get supported size type"); + return -1; + } + width[j] = size_list[i][2]; + height[j] = size_list[i][3]; + type[j] = size_list[i][4]; + } + + return 0; +} + static int _convert_to_support_size(int *width, int *height, int count) { int i; @@ -414,7 +442,7 @@ static int _convert_to_support_size(int *width, int *height, int count) return 0; } -static int _convert_to_support_size_ratio(int width, int height, int *w, int *h) +static int _convert_type_to_support_size_ratio(int type, int *w, int *h) { int i; @@ -424,8 +452,7 @@ static int _convert_to_support_size_ratio(int width, int height, int *w, int *h) } for (i = 0; i < WIDGET_SIZE_TYPE_MAX; i++) { - if (size_list[i][2] == width && - size_list[i][3] == height) + if (size_list[i][4] == type) break; } @@ -508,6 +535,79 @@ static int _get_widget_supported_sizes(const char *widget_id, uid_t uid, return WIDGET_ERROR_NONE; } + +static int _get_widget_supported_info(const char *widget_id, uid_t uid, + int *cnt, int **w, int **h, int **t) +{ + static const char query[] = + "SELECT width, height FROM support_size WHERE classid=?"; + int ret; + sqlite3 *db; + sqlite3_stmt *stmt; + int count = 0; + int i; + int *width; + int *height; + int *type; + + db = _open_db(uid); + if (db == NULL) + return WIDGET_ERROR_IO_ERROR; + + ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL); + if (ret != SQLITE_OK) { + /* LCOV_EXCL_START */ + _E("prepare error: %s", sqlite3_errmsg(db)); + sqlite3_close_v2(db); + return WIDGET_ERROR_FAULT; + /* LCOV_EXCL_STOP */ + } + + sqlite3_bind_text(stmt, 1, widget_id, -1, SQLITE_STATIC); + + while (sqlite3_step(stmt) == SQLITE_ROW) + count++; + + if (count == 0) { + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + *cnt = 0; + *w = NULL; + *h = NULL; + return WIDGET_ERROR_NOT_EXIST; + } + + sqlite3_reset(stmt); + width = malloc(sizeof(int) * count); + height = malloc(sizeof(int) * count); + type = malloc(sizeof(int) * count); + + for (i = 0; i < count; i++) { + sqlite3_step(stmt); + _get_column_int(stmt, 0, &width[i]); + _get_column_int(stmt, 1, &height[i]); + } + + if (_convert_to_support_info(width, height, type, count)) { + _E("failed to convert size"); + free(width); + free(height); + free(type); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + return WIDGET_ERROR_FAULT; + } + *t = type; + *w = width; + *h = height; + *cnt = count; + + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + + return WIDGET_ERROR_NONE; +} + static int _instance_cb(const char *widget_id, const char *instance_id, void *data) { int ret; @@ -841,10 +941,8 @@ EAPI int widget_service_get_supported_size_types(const char *widget_id, int *cnt, int **types) { int ret; - int i; int *width = NULL; int *height = NULL; - int type; if (!_is_widget_feature_enabled()) { _E("not supported"); @@ -861,11 +959,11 @@ EAPI int widget_service_get_supported_size_types(const char *widget_id, _D("id : %s", widget_id); - ret = _get_widget_supported_sizes(widget_id, getuid(), cnt, - &width, &height); + ret = _get_widget_supported_info(widget_id, getuid(), cnt, + &width, &height, types); if (ret == WIDGET_ERROR_NOT_EXIST) - ret = _get_widget_supported_sizes(widget_id, GLOBALAPP_USER, - cnt, &width, &height); + ret = _get_widget_supported_info(widget_id, GLOBALAPP_USER, + cnt, &width, &height, types); if (ret == WIDGET_ERROR_NOT_EXIST) { _E("cannot find supported sizes for widget %s", widget_id); @@ -875,25 +973,6 @@ EAPI int widget_service_get_supported_size_types(const char *widget_id, return ret; } - *types = malloc(sizeof(int) * (*cnt)); - if (*types == NULL) { - _E("out of memory"); - free(width); - free(height); - return WIDGET_ERROR_OUT_OF_MEMORY; - } - - for (i = 0; i < (*cnt); i++) { - if (_get_supported_size_type(width[i], height[i], &type)) { - free(*types); - free(width); - free(height); - return WIDGET_ERROR_NOT_SUPPORTED; - } - - (*types)[i] = type; - } - free(width); free(height); @@ -1220,8 +1299,6 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id, widget_size_type_e size_type) { char *path; - int width = -1; - int height = -1; int w = -1; int h = -1; char *lang_path; @@ -1247,16 +1324,7 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id, return NULL; } - if (_get_supported_size(size_type, &width, &height)) { - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); - return NULL; - } - - if (_convert_to_support_size_ratio(width, height, &w, &h)) { - set_last_result(WIDGET_ERROR_NOT_SUPPORTED); - return NULL; - } - + _convert_type_to_support_size_ratio(size_type, &w, &h); path = _get_preview_image_path(widget_id, w, h, getuid()); if (path == NULL && get_last_result() == WIDGET_ERROR_NOT_EXIST) path = _get_preview_image_path(widget_id, w, h, GLOBALAPP_USER); |