diff options
-rw-r--r-- | src/widget_service.c | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/src/widget_service.c b/src/widget_service.c index 3354471..2b3600f 100644 --- a/src/widget_service.c +++ b/src/widget_service.c @@ -1196,6 +1196,59 @@ EAPI char *widget_service_get_preview_image_path(const char *widget_id, return path; } + +static char *_get_main_widget_id(const char *pkg_id, uid_t uid) +{ + static const char query[] = + "SELECT classid FROM widget_class " + "WHERE pkgid=? and prime=1 "; + int ret; + sqlite3 *db; + sqlite3_stmt *stmt; + char *widget_id; + + db = _open_db(uid); + if (db == NULL) { + set_last_result(WIDGET_ERROR_IO_ERROR); + return NULL; + } + + 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); + set_last_result(WIDGET_ERROR_FAULT); + return NULL; + /* LCOV_EXCL_STOP */ + } + + sqlite3_bind_text(stmt, 1, pkg_id, -1, SQLITE_STATIC); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_ROW) { + if (ret == SQLITE_DONE) + _E("cannot find widget_id for pkg_id %s", pkg_id); + else + _E("step error: %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + /* TODO: which error should be set? */ + set_last_result(ret == SQLITE_DONE ? WIDGET_ERROR_NOT_EXIST : + WIDGET_ERROR_FAULT); + return NULL; + } + + _get_column_str(stmt, 0, &widget_id); + + sqlite3_finalize(stmt); + sqlite3_close_v2(db); + + set_last_result(WIDGET_ERROR_NONE); + + return widget_id; +} + static char *_get_icon(const char *widget_id, const char *lang, uid_t uid) { static const char query[] = @@ -1253,9 +1306,10 @@ static char *_get_icon(const char *widget_id, const char *lang, uid_t uid) return icon; } -EAPI char *widget_service_get_icon(const char *widget_id, const char *lang) +EAPI char *widget_service_get_icon(const char *pkgid, const char *lang) { char *icon; + char *widget_id; if (!_is_widget_feature_enabled()) { _E("not supported"); @@ -1263,7 +1317,7 @@ EAPI char *widget_service_get_icon(const char *widget_id, const char *lang) return NULL; } - if (widget_id == NULL) { + if (pkgid == NULL) { _E("invalid parameter"); set_last_result(WIDGET_ERROR_INVALID_PARAMETER); return NULL; @@ -1274,6 +1328,10 @@ EAPI char *widget_service_get_icon(const char *widget_id, const char *lang) return NULL; } + widget_id = _get_main_widget_id(pkgid, getuid()); + if (widget_id == NULL && get_last_result() == WIDGET_ERROR_NOT_EXIST) + widget_id = _get_main_widget_id(pkgid, GLOBALAPP_USER); + icon = _get_icon(widget_id, lang, getuid()); if (icon == NULL && get_last_result() == WIDGET_ERROR_NOT_EXIST) icon = _get_icon(widget_id, lang, GLOBALAPP_USER); |