[Shortcut API] allow_duplicate
authorJin Yoon <jinny.yoon@samsung.com>
Thu, 21 Mar 2013 01:38:26 +0000 (10:38 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Thu, 21 Mar 2013 01:38:26 +0000 (10:38 +0900)
include/all_apps/db.h
src/all_apps/db.c
src/all_apps/shortcut.c

index 45aa4b5..3d74fc7 100644 (file)
@@ -41,6 +41,7 @@ extern void all_apps_db_unretrieve_all_info(Eina_List *list);
 
 extern long long all_apps_db_insert_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon);
 extern menu_screen_error_e all_apps_db_delete_shortcut(long long rowid);
+extern int all_apps_db_count_shortcut(const char *appid, const char *name);
 
 #endif // __MENU_SCREEN_ALL_APPS_DB_H__
 // End of file
index 904bdfd..9f9e3e0 100644 (file)
@@ -39,6 +39,7 @@
        "'%s', '%s', %d, '%s', '%s');"
 #define QUERY_DELETE_SHORTCUT "DELETE FROM "SHORTCUT_TABLE" WHERE ROWID=%lld"
 #define QUERY_GET_ALL "SELECT ROWID, appid, name, type, content_info, icon FROM "SHORTCUT_TABLE
+#define QUERY_COUNT_SHORTCUT "SELECT COUNT(*) FROM "SHORTCUT_TABLE" WHERE appid='%s' AND name='%s'"
 
 
 
@@ -149,6 +150,31 @@ HAPI void all_apps_db_unretrieve_all_info(Eina_List *list)
 
 
 
+HAPI int all_apps_db_count_shortcut(const char *appid, const char *name)
+{
+       retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), -1);
+
+       char q[QUERY_LEN];
+       snprintf(q, sizeof(q), QUERY_COUNT_SHORTCUT, appid, name);
+
+       stmt_h *st;
+       st = db_prepare(q);
+       retv_if(NULL == st, -1);
+
+       menu_screen_error_e ret = MENU_SCREEN_ERROR_FAIL;
+       ret = db_next(st);
+       retv_if(MENU_SCREEN_ERROR_FAIL == ret, -1);
+
+       int count = -1;
+       count = db_get_int(st, 0);
+
+       db_finalize(st);
+
+       return count;
+}
+
+
+
 HAPI long long all_apps_db_insert_shortcut(const char *appid, const char *name, int type, const char *content_info, const char *icon)
 {
        char q[QUERY_LEN];
index 0bfcd63..395f8e1 100644 (file)
@@ -170,6 +170,7 @@ static int _shorcut_request_cb(
                const char *icon,
                int pid,
                double period,
+               int allow_duplicate,
                void *data)
 {
        Evas_Object *scroller = data;
@@ -185,6 +186,15 @@ static int _shorcut_request_cb(
        _D("period : %.2f", period);
        _D("CBDATA: %p", data);
 
+       if (!allow_duplicate) {
+               int count = 0;
+               count = all_apps_db_count_shortcut(pkgname, name);
+               if (0 < count) {
+                       _D("There is already a package(%s:%s) in the Menu-screen", pkgname, name);
+                       return -1;
+               }
+       }
+
        long long rowid = -1l;
        rowid = all_apps_db_insert_shortcut(pkgname, name, type, content_info, icon);
        retv_if(0l > rowid, -1);