diff options
-rw-r--r-- | lib/include/shortcut.h | 36 | ||||
-rw-r--r-- | lib/src/main.c | 235 | ||||
-rw-r--r-- | packaging/libshortcut.spec | 2 |
3 files changed, 20 insertions, 253 deletions
diff --git a/lib/include/shortcut.h b/lib/include/shortcut.h index 5edd598..ec0198a 100644 --- a/lib/include/shortcut.h +++ b/lib/include/shortcut.h @@ -46,6 +46,7 @@ extern "C" { * @param[in] content_info Specific information for creating a new shortcut. * @param[in] icon Absolute path of an icon file for this shortcut. * @param[in] pid Process ID of who request add_to_home. + * @param[in] allow_duplicate 1 if shortcut can be duplicated or a shourtcut should be exists only one. * @param[in] data Callback data. * @return int Developer should returns the result of handling shortcut creation request. * Returns 0, if succeed to handles the add_to_home request, or returns proper errno. @@ -54,7 +55,7 @@ extern "C" { * @post None * @remarks None */ -typedef int (*request_cb_t)(const char *appid, const char *name, int type, const char *content_info, const char *icon, int pid, double period, void *data); +typedef int (*request_cb_t)(const char *appid, const char *name, int type, const char *content_info, const char *icon, int pid, double period, int allow_duplicate, void *data); /** * @brief This function prototype is used to define for receiving the result of add_to_home. @@ -182,6 +183,7 @@ extern int shortcut_set_request_cb(request_cb_t request_cb, void *data); * @param[in] type 3 kinds of types are defined. * @param[in] content_info Specific information for delivering to the creating shortcut. * @param[in] icon Absolute path of an icon file + * @param[in] allow_duplicate set 1 If accept the duplicated shortcut or 0 * @param[in] result_cb Callback function pointer which will be invoked after add_to_home request. * @param[in] data Callback data to deliver to the callback function. * @@ -219,7 +221,7 @@ extern int shortcut_set_request_cb(request_cb_t request_cb, void *data); * { * add_to_home_shortcut("org.tizen.gallery", "With friends", * SHORTCUT_DATA, "gallery:0000-0000", - * "/opt/media/Pictures/Friends.jpg", result_cb, NULL); + * "/opt/media/Pictures/Friends.jpg", 0, result_cb, NULL); * return 0; * } * @@ -232,35 +234,9 @@ extern int shortcut_set_request_cb(request_cb_t request_cb, void *data); */ extern int shortcut_get_list(const char *appid, int (*cb)(const char *appid, const char *icon, const char *name, const char *extra_key, const char *extra_data, void *data), void *data); -extern int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon, result_cb_t result_cb, void *data); +extern int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data); -extern int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, result_cb_t result_cb, void *data); - - -/*! - * \brief Number of preview images for homescreen - */ -extern int homescreen_get_image_count(const char *appid); -/*! - * \return string allocated in the heap - Path of image - */ -extern char *homescreen_get_image(const char *appid, int idx); - -/*! - * \brief Description of the homescreen (based on i18n) - */ -extern int homescreen_get_description(const char *appid, void (*cb)(const char *appid, const char *icon, const char *name, const char *desc, void *data), void *data); - -/*! - * \note - * These two functions are deprecated now. - * - * Please replace the "shortcut_add_to_home" with "add_to_home_shortcut" - * Please replace the "shortcut_add_to_home_with_period" with "add_to_home_livebox" - */ -extern int shortcut_add_to_home(const char *appid, const char *name, int type, const char *content, const char *icon, result_cb_t result_cb, void *data) __attribute__ ((deprecated)); - -extern int shortcut_add_to_home_with_period(const char *appid, const char *name, int type, const char *content, const char *icon, double period, result_cb_t result_cb, void *data) __attribute__ ((deprecated)); +extern int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data); #ifdef __cplusplus } diff --git a/lib/src/main.c b/lib/src/main.c index d485a53..636db21 100644 --- a/lib/src/main.c +++ b/lib/src/main.c @@ -59,7 +59,7 @@ static struct info { int client_fd; const char *socket_file; struct { - int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, void *data); + int (*request_cb)(const char *appid, const char *name, int type, const char *content, const char *icon, pid_t pid, double period, int allow_duplicate, void *data); void *data; } server_cb; int initialized; @@ -83,20 +83,21 @@ static struct packet *add_shortcut_handler(pid_t pid, int handle, const struct p int type; const char *content; const char *icon; + int allow_duplicate; int ret; if (!packet) return NULL; - if (packet_get(packet, "ssiss", &appid, &name, &type, &content, &icon) != 5) { + if (packet_get(packet, "ssissi", &appid, &name, &type, &content, &icon, &allow_duplicate) != 6) { ErrPrint("Invalid packet\n"); return NULL; } - DbgPrint("appid[%s], name[%s], type[0x%x], content[%s], icon[%s]\n", appid, name, type, content, icon); + DbgPrint("appid[%s], name[%s], type[0x%x], content[%s], icon[%s] allow_duplicate[%d]\n", appid, name, type, content, icon, allow_duplicate); if (s_info.server_cb.request_cb) - ret = s_info.server_cb.request_cb(appid, name, type, content, icon, pid, -1.0f, s_info.server_cb.data); + ret = s_info.server_cb.request_cb(appid, name, type, content, icon, pid, -1.0f, allow_duplicate, s_info.server_cb.data); else ret = 0; @@ -113,20 +114,21 @@ static struct packet *add_livebox_handler(pid_t pid, int handle, const struct pa const char *content; const char *icon; double period; + int allow_duplicate; int ret; if (!packet) return NULL; - if (packet_get(packet, "ssissd", &appid, &name, &type, &content, &icon, &period) != 6) { + if (packet_get(packet, "ssissdi", &appid, &name, &type, &content, &icon, &period, &allow_duplicate) != 7) { ErrPrint("Invalid packet\n"); return NULL; } - DbgPrint("appid[%s], name[%s], type[0x%x], content[%s], icon[%s], period[%lf]\n", appid, name, type, content, icon, period); + DbgPrint("appid[%s], name[%s], type[0x%x], content[%s], icon[%s], period[%lf], allow_duplicate[%d]\n", appid, name, type, content, icon, period, allow_duplicate); if (s_info.server_cb.request_cb) - ret = s_info.server_cb.request_cb(appid, name, type, content, icon, pid, period, s_info.server_cb.data); + ret = s_info.server_cb.request_cb(appid, name, type, content, icon, pid, period, allow_duplicate, s_info.server_cb.data); else ret = 0; @@ -233,7 +235,7 @@ static int disconnected_cb(int handle, void *data) -EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content, const char *icon, result_cb_t result_cb, void *data) +EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, const char *content, const char *icon, int allow_duplicate, result_cb_t result_cb, void *data) { struct packet *packet; struct result_cb_item *item; @@ -280,7 +282,7 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con if (!icon) icon = ""; - packet = packet_create("add_shortcut", "ssiss", appid, name, type, content, icon); + packet = packet_create("add_shortcut", "ssissi", appid, name, type, content, icon, allow_duplicate); if (!packet) { ErrPrint("Failed to build a packet\n"); free(item); @@ -300,7 +302,7 @@ EAPI int add_to_home_shortcut(const char *appid, const char *name, int type, con -EAPI int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, result_cb_t result_cb, void *data) +EAPI int add_to_home_livebox(const char *appid, const char *name, int type, const char *content, const char *icon, double period, int allow_duplicate, result_cb_t result_cb, void *data) { struct packet *packet; struct result_cb_item *item; @@ -333,7 +335,7 @@ EAPI int add_to_home_livebox(const char *appid, const char *name, int type, cons item->result_cb = result_cb; item->data = data; - packet = packet_create("add_livebox", "ssissd", appid, name, type, content, icon, period); + packet = packet_create("add_livebox", "ssissdi", appid, name, type, content, icon, period, allow_duplicate); if (!packet) { ErrPrint("Failed to build a packet\n"); free(item); @@ -352,16 +354,6 @@ EAPI int add_to_home_livebox(const char *appid, const char *name, int type, cons } -EAPI int shortcut_add_to_home_with_period(const char *appid, const char *name, int type, const char *content, const char *icon, double period, result_cb_t result_cb, void *data) -{ - return add_to_home_livebox(appid, name, type, content, icon, period, result_cb, data); -} - -EAPI int shortcut_add_to_home(const char *appid, const char *name, int type, const char *content, const char *icon, result_cb_t result_cb, void *data) -{ - return add_to_home_shortcut(appid, name, type, content, icon, result_cb, data); -} - static inline int open_db(void) { int ret; @@ -427,207 +419,6 @@ out: -static inline int homescreen_get_i18n(const char *appid, const char *lang, char **name, char **desc) -{ - sqlite3_stmt *stmt; - static const char *query = "SELECT name, desc FROM desc WHERE appid = ? AND lang = ?"; - const unsigned char *_name; - const unsigned char *_desc; - int status; - - status = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL); - if (status != SQLITE_OK) { - ErrPrint("Failed to prepare stmt: %s\n", sqlite3_errmsg(s_info.handle)); - return -EIO; - } - - status = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); - if (status != SQLITE_OK) { - ErrPrint("Failed to bind appid: %s\n", sqlite3_errmsg(s_info.handle)); - status = -EIO; - goto out; - } - - status = sqlite3_bind_text(stmt, 2, lang, -1, SQLITE_TRANSIENT); - if (status != SQLITE_OK) { - ErrPrint("Failed to bind lang: %s\n", sqlite3_errmsg(s_info.handle)); - status = -EIO; - goto out; - } - - if (SQLITE_ROW != sqlite3_step(stmt)) { - ErrPrint("Failed to do step: %s\n", sqlite3_errmsg(s_info.handle)); - status = -EIO; - goto out; - } - - if (name) { - _name = sqlite3_column_text(stmt, 0); - *name = _name ? strdup((const char *)_name) : NULL; - } - - if (desc) { - _desc = sqlite3_column_text(stmt, 1); - *desc = _desc ? strdup((const char *)_desc) : NULL; - } - -out: - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return status; -} - - - -/*! - * cb: SYNC callback - */ -EAPI int homescreen_get_description(const char *appid, void (*cb)(const char *appid, const char *icon, const char *name, const char *desc, void *data), void *data) -{ - sqlite3_stmt *stmt; - static const char *query = "SELECT icon, name, desc FROM homescreen WHERE appid = ?"; - char *i18n_name; - char *i18n_desc; - const unsigned char *desc; - const unsigned char *name; - const unsigned char *icon; - int ret; - - ret = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Prepare failed: %s\n", sqlite3_errmsg(s_info.handle)); - ret = -EIO; - goto out; - } - - ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("Prepare failed: %s\n", sqlite3_errmsg(s_info.handle)); - ret = -EIO; - goto out; - } - - if (SQLITE_ROW != sqlite3_step(stmt)) { - ErrPrint("Step failed: %s\n", sqlite3_errmsg(s_info.handle)); - ret = -EIO; - goto out; - } - - icon = sqlite3_column_text(stmt, 0); - name = sqlite3_column_text(stmt, 1); - desc = sqlite3_column_text(stmt, 2); - - /*! - * \todo - * Get the i18n name and desc - */ - if (homescreen_get_i18n(appid, "en-us", &i18n_name, &i18n_desc) < 0) { - i18n_name = NULL; - i18n_desc = NULL; - } - - cb(appid, (const char *)icon, i18n_name ? i18n_name : (const char *)name, i18n_desc ? i18n_desc : (const char *)desc, data); - - free(i18n_name); - free(i18n_desc); - -out: - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return ret; -} - - - -EAPI char *homescreen_get_image(const char *appid, int idx) -{ - static const char *query = "SELECT path FROM image WHERE appid = ? AND id = ?"; - sqlite3_stmt *stmt; - int ret; - const unsigned char *path; - char *ret_path = NULL; - - ret = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("Prepare failed: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("bind failed: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - ret = sqlite3_bind_int(stmt, 2, idx); - if (ret != SQLITE_OK) { - ErrPrint("bind failed: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - if (SQLITE_ROW != sqlite3_step(stmt)) { - ErrPrint("Step failed: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - path = sqlite3_column_text(stmt, 0); - if (!path) { - ErrPrint("Get result: %s\n", sqlite3_errmsg(s_info.handle)); - goto out; - } - - ret_path = strdup((const char *)path); - if (!ret_path) - ErrPrint("Heap: %s\n", strerror(errno)); - -out: - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return ret_path; -} - - - -EAPI int homescreen_get_image_count(const char *appid) -{ - static const char *query = "SELECT COUNT(id) FROM image WHERE appid = ?"; - sqlite3_stmt *stmt; - int ret; - - ret = sqlite3_prepare_v2(s_info.handle, query, -1, &stmt, NULL); - if (ret != SQLITE_OK) { - ErrPrint("bind failed: %s\n", sqlite3_errmsg(s_info.handle)); - ret = -EIO; - goto out; - } - - ret = sqlite3_bind_text(stmt, 1, appid, -1, SQLITE_TRANSIENT); - if (ret != SQLITE_OK) { - ErrPrint("bind failed: %s\n", sqlite3_errmsg(s_info.handle)); - ret = -EIO; - goto out; - } - - if (SQLITE_ROW != sqlite3_step(stmt)) { - ErrPrint("step failed: %s\n", sqlite3_errmsg(s_info.handle)); - ret = -EIO; - goto out; - } - - ret = sqlite3_column_int(stmt, 0); - -out: - sqlite3_reset(stmt); - sqlite3_clear_bindings(stmt); - sqlite3_finalize(stmt); - return ret; -} - - - static inline char *cur_locale(void) { char *language; diff --git a/packaging/libshortcut.spec b/packaging/libshortcut.spec index b53a521..b8c2fc5 100644 --- a/packaging/libshortcut.spec +++ b/packaging/libshortcut.spec @@ -1,6 +1,6 @@ Name: libshortcut Summary: Shortcut add feature supporting library -Version: 0.3.20 +Version: 0.4.0 Release: 0 Group: main/devel License: Apache License |