From b58518bcaf588d152076db180d02e9b6ac1dba15 Mon Sep 17 00:00:00 2001 From: Jin Yoon Date: Mon, 18 Mar 2013 12:56:34 +0900 Subject: [PATCH] Merge with the private --- CMakeLists.txt | 5 + data/edje/item_4x4.edc | 6 +- debian/control | 4 +- include/all_apps/db.h | 46 ++++ include/all_apps/shortcut.h | 35 +++ include/db.h | 47 ++++ include/item.h | 3 + include/page_scroller.h | 2 +- packaging/org.tizen.menu-screen.spec | 40 +++- src/all_apps/db.c | 183 ++++++++++++++++ src/all_apps/layout.c | 30 ++- src/all_apps/shortcut.c | 225 +++++++++++++++++++ src/db.c | 316 +++++++++++++++++++++++++++ src/item.c | 101 +++++++-- src/page_scroller.c | 26 +-- src/pkgmgr.c | 4 +- src/popup.c | 12 +- 17 files changed, 1024 insertions(+), 61 deletions(-) create mode 100644 include/all_apps/db.h create mode 100644 include/all_apps/shortcut.h create mode 100644 include/db.h create mode 100644 src/all_apps/db.c create mode 100644 src/all_apps/shortcut.c create mode 100644 src/db.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 844d971..fbe6b92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ SET(VERSION 0.1.0) INCLUDE(FindPkgConfig) pkg_check_modules(MENU_PKGS REQUIRED ail + appsvc aul badge bundle @@ -35,6 +36,7 @@ pkg_check_modules(MENU_PKGS REQUIRED heynoti pkgmgr pkgmgr-info + shortcut sysman syspopup-caller utilX @@ -60,6 +62,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) ADD_EXECUTABLE(${PROJECT_NAME} + src/db.c src/index.c src/item.c src/item_badge.c @@ -74,8 +77,10 @@ ADD_EXECUTABLE(${PROJECT_NAME} src/pkgmgr.c src/popup.c src/util.c + src/all_apps/db.c src/all_apps/layout.c src/all_apps/list.c + src/all_apps/shortcut.c ) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS} -lm) diff --git a/data/edje/item_4x4.edc b/data/edje/item_4x4.edc index 527dfad..c32727f 100644 --- a/data/edje/item_4x4.edc +++ b/data/edje/item_4x4.edc @@ -56,8 +56,8 @@ collections { mouse_events: 1; description { state: "default" 0.0; - rel1 { relative: 37/180 8/180; to, "bg"; } - rel2 { relative: 143/180 114/180; to, "bg"; } + rel1 { relative: 36/180 7/180; to, "bg"; } + rel2 { relative: 144/180 115/180; to, "bg"; } color: 0 0 0 0; } } @@ -79,7 +79,7 @@ collections { mouse_events: 1; description { state: "default" 0.0; - rel1 { relative: 15/180 8/180; to, "bg"; } + rel1 { relative: 15/180 7/180; to, "bg"; } rel2 { relative: 165/180 160/180; to, "bg"; } color: 0 0 0 0; visible: 1; diff --git a/debian/control b/debian/control index deb339f..ae4e7a2 100644 --- a/debian/control +++ b/debian/control @@ -2,14 +2,14 @@ Source: menu-screen Section: utils Priority: extra Maintainer: Jin Yoon -Build-Depends: debhelper (>= 5), libelm-dev, libslp-utilx-dev, libslp-setting-dev, libefreet-dev, libslp-sysman-dev, libslp-pm-dev, dlog-dev, libecore-dev, libaul-1-dev, libpkgmgr-client-dev, syspopup-caller-dev, libheynoti-dev, libail-0-dev, librua-dev, libslp-shortcut-dev, menu-daemon, capi-appfw-application-dev, libbadge-dev, pkgmgr-info-dev, capi-system-info-dev +Build-Depends: debhelper (>= 5), libelm-dev, libslp-utilx-dev, libslp-setting-dev, libefreet-dev, libslp-sysman-dev, libslp-pm-dev, dlog-dev, libecore-dev, libaul-1-dev, libpkgmgr-client-dev, syspopup-caller-dev, libheynoti-dev, libail-0-dev, librua-dev, libslp-shortcut-dev, menu-daemon, capi-appfw-application-dev, libbadge-dev, pkgmgr-info-dev, capi-system-info-dev, libshortcut-dev, libappsvc-dev Homepage: N/A Standards-Version: 0.1.0 Package: org.tizen.menu-screen Section: utils Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libelm, libeina, libslp-utilx-0, libslp-setting-0, libefreet, libslp-sysman, libslp-pm-0, libdlog-0, libaul-1, libpkgmgr-client-0, syspopup-caller-0, libheynoti-0, libail-0, menu-daemon, capi-appfw-application, libbadge, pkgmgr-info, capi-system-info +Depends: ${shlibs:Depends}, ${misc:Depends}, libelm, libeina, libslp-utilx-0, libslp-setting-0, libefreet, libslp-sysman, libslp-pm-0, libdlog-0, libaul-1, libpkgmgr-client-0, syspopup-caller-0, libheynoti-0, libail-0, menu-daemon, capi-appfw-application, libbadge, pkgmgr-info, capi-system-info, libshortcut-0, libappsvc-0 Description: inhouse menu-screen Package: org.tizen.menu-screen-dbg diff --git a/include/all_apps/db.h b/include/all_apps/db.h new file mode 100644 index 0000000..45aa4b5 --- /dev/null +++ b/include/all_apps/db.h @@ -0,0 +1,46 @@ + /* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef __MENU_SCREEN_ALL_APPS_DB_H__ +#define __MENU_SCREEN_ALL_APPS_DB_H__ + +#include "Elementary.h" +#include "util.h" + +typedef struct _db_info { + long long rowid; + int type; + + char *appid; + char *name; + char *content_info; + char *icon; +} db_info; + +extern menu_screen_error_e all_apps_db_init(void); +extern void all_apps_db_fini(void); + +extern Eina_List *all_apps_db_retrieve_all_info(void); +extern void all_apps_db_unretrieve_info(db_info *info); +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); + +#endif // __MENU_SCREEN_ALL_APPS_DB_H__ +// End of file diff --git a/include/all_apps/shortcut.h b/include/all_apps/shortcut.h new file mode 100644 index 0000000..5db1970 --- /dev/null +++ b/include/all_apps/shortcut.h @@ -0,0 +1,35 @@ + /* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef _MENU_SCREEN_ALL_APPS_SHORTCUT_H_ +#define _MENU_SCREEN_ALL_APPS_SHORTCUT_H_ + +#include +#include + +extern Evas_Object *all_apps_shortcut_add(Evas_Object *scroller, long long rowid, const char *pkgname, const char *exec, const char *name, const char *icon, int type); +extern void all_apps_shortcut_remove(Evas_Object *item); + +extern menu_screen_error_e all_apps_shortcut_add_all(Evas_Object *scroller); + +extern bool all_apps_shortcut_init(Evas_Object *all_apps); +extern void all_apps_shortcut_fini(void); + +#endif // _MENU_SCREEN_ALL_APPS_SHORTCUT_H_ + +// End of a file diff --git a/include/db.h b/include/db.h new file mode 100644 index 0000000..c503022 --- /dev/null +++ b/include/db.h @@ -0,0 +1,47 @@ + /* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __MENU_SCREEN_DB_H__ +#define __MENU_SCREEN_DB_H__ + +#include + +#include "util.h" + +typedef struct stmt stmt_h; + +extern stmt_h *db_prepare(const char *query); +extern menu_screen_error_e db_bind_bool(stmt_h *handle, int idx, bool value); +extern menu_screen_error_e db_bind_int(stmt_h *handle, int idx, int value); +extern menu_screen_error_e db_bind_str(stmt_h *handle, int idx, const char *str); +extern menu_screen_error_e db_next(stmt_h *handle); +extern bool db_get_bool(stmt_h *handle, int index); +extern int db_get_int(stmt_h *handle, int index); +extern long long db_get_long_long(stmt_h *handle, int index); +extern const char *db_get_str(stmt_h *handle, int index); +extern menu_screen_error_e db_reset(stmt_h *handle); +extern menu_screen_error_e db_finalize(stmt_h *handle); +extern menu_screen_error_e db_exec(const char *query); +extern long long db_last_insert_rowid(void); + +extern menu_screen_error_e db_open(const char *db_file); +extern void db_close(void); + +extern menu_screen_error_e db_begin_transaction(void); +extern menu_screen_error_e db_end_transaction(bool success); + +#endif // __MENU_SCREEN_DB_H__ +// End of file diff --git a/include/item.h b/include/item.h index 60d4db7..2138e4d 100644 --- a/include/item.h +++ b/include/item.h @@ -42,6 +42,9 @@ extern void item_set_page(Evas_Object *edje, Evas_Object *page, int sync); extern char *item_get_desktop(Evas_Object *item); extern void item_set_desktop(Evas_Object *item, char *name, int sync); +extern int item_get_type(Evas_Object *item); +extern void item_set_type(Evas_Object *edje, int type, int sync); + extern void item_enable_delete(Evas_Object *obj); extern void item_disable_delete(Evas_Object *item); diff --git a/include/page_scroller.h b/include/page_scroller.h index 0a9f1ca..13d0631 100644 --- a/include/page_scroller.h +++ b/include/page_scroller.h @@ -39,7 +39,7 @@ extern Evas_Object *page_scroller_get_page_at(Evas_Object *scroller, unsigned in extern unsigned int page_scroller_count_page(Evas_Object *scroller); extern int page_scroller_get_page_no(Evas_Object* scroller, Evas_Object *page); -extern menu_screen_error_e page_scroller_push_item(Evas_Object *scroller, app_info_t *ai); +extern Evas_Object *page_scroller_push_item(Evas_Object *scroller, app_info_t *ai); extern Evas_Object *page_scroller_find_item_by_package(Evas_Object *scroller, const char *package, int *page_no); extern void page_scroller_trim_items(Evas_Object *scroller); extern void page_scroller_bring_in(Evas_Object *scroller, int idx); diff --git a/packaging/org.tizen.menu-screen.spec b/packaging/org.tizen.menu-screen.spec index 8cbec71..969b9e2 100644 --- a/packaging/org.tizen.menu-screen.spec +++ b/packaging/org.tizen.menu-screen.spec @@ -21,6 +21,7 @@ License: Flora Software License Source0: %{name}-%{version}.tar.gz BuildRequires: pkgconfig(ail) BuildRequires: pkgconfig(appcore-efl) +BuildRequires: pkgconfig(appsvc) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(badge) BuildRequires: pkgconfig(bundle) @@ -40,6 +41,7 @@ BuildRequires: pkgconfig(evas) BuildRequires: pkgconfig(heynoti) BuildRequires: pkgconfig(pkgmgr) BuildRequires: pkgconfig(pkgmgr-info) +BuildRequires: pkgconfig(shortcut) BuildRequires: pkgconfig(sysman) BuildRequires: pkgconfig(syspopup-caller) BuildRequires: pkgconfig(utilX) @@ -85,11 +87,43 @@ init_vconf() vconftool set -t int memory/menu-screen/is_menu_screen_done 0 -i -f vconftool set -t string db/setting/menuscreen/package_name "org.tizen.menu-screen" -i -u 5000 -f } - - - init_vconf +if [ ! -d %{_datadir}/dbspace ] +then + mkdir -p %{_datadir}/dbspace +fi + +if [ ! -d %{_datadir}/shortcut ] +then + mkdir -p %{_datadir}/shortcut +else + rm -rf %{_datadir}/shortcut/* +fi + +sqlite3 %{_datadir}/dbspace/.menu_screen.db 'PRAGMA journal_mode = PERSIST; + create table if not exists shortcut ( + ROWID INTEGER PRIMARY KEY AUTOINCREMENT, + appid TEXT, + name TEXT, + type INTEGER, + content_info TEXT, + icon TEXT + ); +' + +chown -R 5000:5000 %{_datadir} +chown root:5000 %{_datadir}/dbspace/.menu_screen.db +chown root:5000 %{_datadir}/dbspace/.menu_screen.db-journal + +chmod 660 %{_datadir}/dbspace/.menu_screen.db +chmod 660 %{_datadir}/dbspace/.menu_screen.db-journal + +if [ -f /usr/lib/rpm-plugins/msm.so ] +then + chsmack -a 'org.tizen.menu-screen' %{_datadir}/dbspace/.menu_screen.db* +fi + %files %manifest %{name}.manifest %defattr(-,root,root,-) diff --git a/src/all_apps/db.c b/src/all_apps/db.c new file mode 100644 index 0000000..904bdfd --- /dev/null +++ b/src/all_apps/db.c @@ -0,0 +1,183 @@ + /* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include +#include +#include +#include + +#include "db.h" +#include "util.h" +#include "all_apps/db.h" + +#define QUERY_LEN 1024 + +#define MENU_SCREEN_DB_FILE "/opt/usr/apps/com.samsung.menu-screen/data/dbspace/.menu_screen.db" +#define SHORTCUT_TABLE "shortcut" +#define QUERY_INSERT_SHORTCUT "INSERT INTO "SHORTCUT_TABLE" ("\ + "appid,"\ + "name,"\ + "type,"\ + "content_info,"\ + "icon"\ + ") VALUES ("\ + "'%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 + + + +HAPI menu_screen_error_e all_apps_db_init(void) +{ + return db_open(MENU_SCREEN_DB_FILE); +} + + + +HAPI void all_apps_db_fini(void) +{ + db_close(); +} + + + +HAPI Eina_List *all_apps_db_retrieve_all_info(void) +{ + stmt_h *st; + Eina_List *list = NULL; + + retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), NULL); + + st = db_prepare(QUERY_GET_ALL); + retv_if(NULL == st, NULL); + + menu_screen_error_e ret = MENU_SCREEN_ERROR_FAIL; + for (ret = db_next(st); MENU_SCREEN_ERROR_FAIL != ret && MENU_SCREEN_ERROR_NO_DATA != ret; ret = db_next(st)) { + db_info *info; + info = calloc(1, sizeof(db_info)); + break_if(NULL == info); + + info->rowid = db_get_long_long(st, 0); // 0 : ROWID + + char *tmp = NULL; + tmp = (char *) db_get_str(st, 1); // 1 : appid + if (tmp && strlen(tmp)) { + info->appid = strdup(tmp); + goto_if(NULL == info->appid, APP_ERROR); + } + + tmp = (char *) db_get_str(st, 2); // 2 : name + if (tmp && strlen(tmp)) { + info->name = strdup(tmp); + goto_if(NULL == info->name, APP_ERROR); + } + + info->type = db_get_int(st, 3); // 3 : type + + tmp = (char *) db_get_str(st, 4); // 4 : content_info + if (tmp && strlen(tmp)) { + info->content_info = strdup(tmp); + goto_if(NULL == info->content_info, APP_ERROR); + } + + tmp = (char *) db_get_str(st, 5); // 5 : icon + if (tmp && strlen(tmp)) { + info->icon = strdup(tmp); + goto_if(NULL == info->icon, APP_ERROR); + } + + list = eina_list_append(list, info); + + continue; +APP_ERROR: + if (info->appid) free(info->appid); + if (info->name) free(info->name); + if (info->content_info) free(info->content_info); + if (info->icon) free(info->icon); + if (info) free(info); + } + + db_finalize(st); + + return list; +} + + + +HAPI void all_apps_db_unretrieve_info(db_info *info) +{ + ret_if(NULL == info); + if (info->appid) free(info->appid); + if (info->name) free(info->name); + if (info->content_info) free(info->content_info); + if (info->icon) free(info->icon); + if (info) free(info); +} + + + +HAPI void all_apps_db_unretrieve_all_info(Eina_List *list) +{ + db_info *info = NULL; + + EINA_LIST_FREE(list, info) { + if (NULL == info) break; + if (info->appid) free(info->appid); + if (info->name) free(info->name); + if (info->content_info) free(info->content_info); + if (info->icon) free(info->icon); + if (info) free(info); + } + + eina_list_free(list); +} + + + +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]; + + retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), -1l); + + snprintf(q, sizeof(q), QUERY_INSERT_SHORTCUT, appid, name, type, content_info, icon); + retv_if(db_exec(q) < 0, -1l); + + long long id = -1l; + id = db_last_insert_rowid(); + + return id; +} + + + +HAPI menu_screen_error_e all_apps_db_delete_shortcut(long long rowid) +{ + char q[QUERY_LEN]; + + retv_if(MENU_SCREEN_ERROR_OK != db_open(MENU_SCREEN_DB_FILE), MENU_SCREEN_ERROR_FAIL); + + snprintf(q, sizeof(q), QUERY_DELETE_SHORTCUT, rowid); + retv_if(db_exec(q) < 0, MENU_SCREEN_ERROR_FAIL); + + return MENU_SCREEN_ERROR_OK; +} + + + +// END diff --git a/src/all_apps/layout.c b/src/all_apps/layout.c index b525436..9a14049 100644 --- a/src/all_apps/layout.c +++ b/src/all_apps/layout.c @@ -28,6 +28,7 @@ #include "util.h" #include "all_apps/layout.h" #include "all_apps/list.h" +#include "all_apps/shortcut.h" #define ALL_APPS_EDJE_PORTRAIT EDJEDIR"/all_apps_portrait.edj" #define ALL_APPS_GROUP "all_apps" @@ -203,7 +204,7 @@ static menu_screen_error_e _load_item(Evas_Object *scroller, app_list_item *item return MENU_SCREEN_ERROR_OK; } - retv_if(MENU_SCREEN_ERROR_FAIL == page_scroller_push_item(scroller, ai), MENU_SCREEN_ERROR_FAIL); + retv_if(NULL == page_scroller_push_item(scroller, ai), MENU_SCREEN_ERROR_FAIL); return MENU_SCREEN_ERROR_OK; @@ -237,15 +238,6 @@ ERROR: page_scroller_bring_in(scroller, 0); menu_screen_set_done(true); - do { - Evas_Object *button; - button = _add_edit_button(all_apps, scroller); - if (NULL == button) { - _D("cannot make the edit button"); - } - elm_object_part_content_set(all_apps, ALL_APPS_EDIT_BUTTON_PART, button); - } while (0); - return ECORE_CALLBACK_CANCEL; } @@ -263,6 +255,20 @@ static menu_screen_error_e _push_items(Evas_Object *all_apps) idle_timer = ecore_idler_add(_push_items_idler_cb, all_apps); retv_if(NULL == idle_timer, MENU_SCREEN_ERROR_FAIL); + Evas_Object *scroller; + scroller = evas_object_data_get(all_apps, "scroller"); + if (MENU_SCREEN_ERROR_OK != all_apps_shortcut_add_all(scroller)) + _E("Cannot add shortcuts"); + + do { + Evas_Object *button; + button = _add_edit_button(all_apps, scroller); + if (NULL == button) { + _D("cannot make the edit button"); + } + elm_object_part_content_set(all_apps, ALL_APPS_EDIT_BUTTON_PART, button); + } while (0); + return MENU_SCREEN_ERROR_OK; } @@ -334,7 +340,7 @@ HAPI Evas_Object *all_apps_layout_create(Evas_Object *controlbar, int rotate) elm_object_part_content_set(all_apps, "content", scroller); evas_object_data_set(all_apps, "scroller", scroller); - + if (!all_apps_shortcut_init(all_apps)) _E("Cannot initialize shortcut"); retv_if(MENU_SCREEN_ERROR_FAIL == _push_items(all_apps), NULL); return all_apps; @@ -349,6 +355,8 @@ HAPI void all_apps_layout_destroy(Evas_Object *all_apps) ret_if(NULL == all_apps); + all_apps_shortcut_fini(); + do { Evas_Object *button; if(all_apps) { diff --git a/src/all_apps/shortcut.c b/src/all_apps/shortcut.c new file mode 100644 index 0000000..0bfcd63 --- /dev/null +++ b/src/all_apps/shortcut.c @@ -0,0 +1,225 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include +#include + +#include "item.h" +#include "list.h" +#include "page_scroller.h" +#include "util.h" +#include "all_apps/db.h" + + + +HAPI Evas_Object *all_apps_shortcut_add( + Evas_Object *scroller, + long long rowid, + const char *pkgname, + const char *exec, + const char *name, + const char *content_info, + const char *icon, + int type) +{ + _D("Shortcut : pkgname(%s) exec(%s) name(%s) icon(%s)", pkgname, exec, name, icon); + + app_info_t ai = {0, }; + ai.package = (char *) pkgname; + ai.exec = (char *) exec; + ai.name = (char *) name; + ai.icon = (char *) icon; + ai.nodisplay = 0; + ai.enabled = 1; + ai.x_slp_removable = 1; + ai.x_slp_taskmanage = 0; + + if (ADD_TO_HOME_IS_LIVEBOX(type)) { + _D("This is a livebox"); + return NULL; + } + + Evas_Object *item = NULL; + retv_if(NULL == (item = page_scroller_push_item(scroller, &ai)), NULL); + + long long *tmp; + tmp = calloc(1, sizeof(long long)); + if (NULL == tmp) { + item_destroy(item); + return NULL; + } + + if (LAUNCH_BY_PACKAGE == type) { + _D("This is a package"); + evas_object_data_set(item, "shortcut_launch_package", (void *) true); + } else { + _D("This is a shortcut"); + evas_object_data_set(item, "shortcut_launch_package", (void *) false); + } + + *tmp = rowid; + evas_object_data_set(item, "is_shortcut", (void *) true); + evas_object_data_set(item, "rowid", tmp); + evas_object_data_set(item, "type", (void *) type); + evas_object_data_set(item, "content_info", content_info); + + return item; +} + + + +static Eina_Bool _push_items_idler_cb(void *data) +{ + Evas_Object *scroller = data; + Eina_List *list = evas_object_data_get(scroller, "list"); + Eina_List *n; + Eina_List *t; + db_info *info = NULL; + EINA_LIST_FOREACH_SAFE(list, n, t, info) { + goto_if(NULL == info, ERROR); + Evas_Object *item = NULL; + item = all_apps_shortcut_add( + scroller, + info->rowid, + info->appid, + NULL, + info->name, + info->content_info, + info->icon, + info->type); + + list = eina_list_remove(list, info); + evas_object_data_set(scroller, "list", list); + + all_apps_db_unretrieve_info(info); + break_if(NULL == item); + } + + return ECORE_CALLBACK_RENEW; +ERROR: + list = evas_object_data_del(scroller, "list"); + all_apps_db_unretrieve_all_info(list); + return ECORE_CALLBACK_CANCEL; +} + + + +HAPI menu_screen_error_e all_apps_shortcut_add_all(Evas_Object *scroller) +{ + Eina_List *list; + + list = all_apps_db_retrieve_all_info(); + if (NULL == list) { + _D("There is no shortcut"); + return MENU_SCREEN_ERROR_OK; + } + + evas_object_data_set(scroller, "list", list); + + Ecore_Idler *idle_timer = NULL; + idle_timer = ecore_idler_add(_push_items_idler_cb, scroller); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI void all_apps_shortcut_remove(Evas_Object *item) +{ + long long *tmp; + tmp = evas_object_data_del(item, "rowid"); + if (tmp) { + all_apps_db_delete_shortcut(*tmp); + free(tmp); + } + + Evas_Object *scroller; + scroller = evas_object_data_get(item, "scroller"); + + evas_object_data_del(item, "type"); + evas_object_data_del(item, "content_info"); + evas_object_data_del(item, "shortcut_launch_package"); + evas_object_data_del(item, "is_shortcut"); + item_destroy(item); + + if (scroller) page_scroller_trim_items(scroller); +} + + + +static int _shorcut_request_cb( + const char *pkgname, + const char *name, + int type, + const char *content_info, + const char *icon, + int pid, + double period, + void *data) +{ + Evas_Object *scroller = data; + + retv_if(NULL == pkgname, -1); + + _D("Package name: %s", pkgname); + _D("Name: %s", name); + _D("Type: %d", type); + _D("Content: %s", content_info); + _D("Icon: %s", icon); + _D("Requested from: %d", pid); + _D("period : %.2f", period); + _D("CBDATA: %p", data); + + long long rowid = -1l; + rowid = all_apps_db_insert_shortcut(pkgname, name, type, content_info, icon); + retv_if(0l > rowid, -1); + + Evas_Object *item = NULL; + item = all_apps_shortcut_add(scroller, rowid, pkgname, NULL, name, content_info, icon, type); + retv_if(NULL == item, -1); + + return 0; +} + + + +HAPI bool all_apps_shortcut_init(Evas_Object *all_apps) +{ + retv_if(NULL == all_apps, false); + retv_if(MENU_SCREEN_ERROR_OK != all_apps_db_init(), false); + + Evas_Object *scroller; + scroller = evas_object_data_get(all_apps, "scroller"); + retv_if(NULL == scroller, false); + + int ret; + ret = shortcut_set_request_cb(_shorcut_request_cb, scroller); + + return 0 == ret ? true : false; +} + + + +HAPI void all_apps_shortcut_fini(void) +{ + all_apps_db_fini(); +} + + + +// End of file. diff --git a/src/db.c b/src/db.c new file mode 100644 index 0000000..739e729 --- /dev/null +++ b/src/db.c @@ -0,0 +1,316 @@ +/* + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.tizenopensource.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#include +#include +#include +#include +#include +#include + +#include "util.h" +#include "db.h" + + + +#define retv_with_dbmsg_if(expr, val) do { \ + if (expr) { \ + _E("%s", sqlite3_errmsg(db_info.db)); \ + return (val); \ + } \ +} while (0) + + + +static struct { + sqlite3 *db; +} db_info = { + .db = NULL, +}; + +struct stmt { + sqlite3_stmt *stmt; +}; + + + +HAPI menu_screen_error_e db_open(const char *db_file) +{ + int ret; + + retv_if(NULL == db_file, MENU_SCREEN_ERROR_INVALID_PARAMETER); + if (db_info.db) { + return MENU_SCREEN_ERROR_OK; + } + + ret = db_util_open(db_file, &db_info.db, DB_UTIL_REGISTER_HOOK_METHOD); + retv_with_dbmsg_if(ret != SQLITE_OK, MENU_SCREEN_ERROR_FAIL); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI stmt_h *db_prepare(const char *query) +{ + int ret; + stmt_h *handle; + + retv_if(NULL == query, NULL); + + handle = calloc(1, sizeof(stmt_h)); + retv_if(NULL == handle, NULL); + + ret = sqlite3_prepare_v2(db_info.db, query, strlen(query), &(handle->stmt), NULL); + if (ret != SQLITE_OK) { + free(handle); + _E("%s", sqlite3_errmsg(db_info.db)); + return NULL; + } + + return handle; +} + + + +HAPI menu_screen_error_e db_bind_bool(stmt_h *handle, int idx, bool value) +{ + int ret; + + retv_if(NULL == handle, MENU_SCREEN_ERROR_FAIL); + + ret = sqlite3_bind_int(handle->stmt, idx, (int) value); + retv_with_dbmsg_if(ret != SQLITE_OK, MENU_SCREEN_ERROR_FAIL); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI menu_screen_error_e db_bind_int(stmt_h *handle, int idx, int value) +{ + int ret; + + retv_if(NULL == handle, MENU_SCREEN_ERROR_FAIL); + + ret = sqlite3_bind_int(handle->stmt, idx, value); + retv_with_dbmsg_if(ret != SQLITE_OK, MENU_SCREEN_ERROR_FAIL); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI menu_screen_error_e db_bind_str(stmt_h *handle, int idx, const char *str) +{ + int ret; + + retv_if(NULL == handle, MENU_SCREEN_ERROR_FAIL); + + ret = sqlite3_bind_text(handle->stmt, idx, str, strlen(str), SQLITE_TRANSIENT); + retv_with_dbmsg_if(ret != SQLITE_OK, MENU_SCREEN_ERROR_FAIL); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI menu_screen_error_e db_next(stmt_h *handle) +{ + int ret; + + retv_if(NULL == handle, MENU_SCREEN_ERROR_FAIL); + + ret = sqlite3_step(handle->stmt); + switch (ret) { + case SQLITE_ROW: + return MENU_SCREEN_ERROR_OK; + case SQLITE_DONE: + return MENU_SCREEN_ERROR_NO_DATA; + default: + retv_with_dbmsg_if(1, MENU_SCREEN_ERROR_FAIL); + } +} + + + +HAPI bool db_get_bool(stmt_h *handle, int index) +{ + retv_if(NULL == handle, false); + return (bool) sqlite3_column_int(handle->stmt, index); +} + + + +HAPI int db_get_int(stmt_h *handle, int index) +{ + retv_if(NULL == handle, 0); + return sqlite3_column_int(handle->stmt, index); +} + + + +HAPI long long db_get_long_long(stmt_h *handle, int index) +{ + retv_if(NULL == handle, 0l); + return sqlite3_column_int64(handle->stmt, index); +} + + +HAPI const char *db_get_str(stmt_h *handle, int index) +{ + retv_if(NULL == handle, NULL); + return (const char *) sqlite3_column_text(handle->stmt, index); +} + + + +HAPI menu_screen_error_e db_reset(stmt_h *handle) +{ + int ret; + + retv_if(NULL == handle, MENU_SCREEN_ERROR_INVALID_PARAMETER); + retv_if(NULL == handle->stmt, MENU_SCREEN_ERROR_INVALID_PARAMETER); + + ret = sqlite3_reset(handle->stmt); + retv_with_dbmsg_if(ret != SQLITE_OK, MENU_SCREEN_ERROR_FAIL); + + sqlite3_clear_bindings(handle->stmt); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI menu_screen_error_e db_finalize(stmt_h *handle) +{ + int ret; + + retv_if(NULL == handle, MENU_SCREEN_ERROR_INVALID_PARAMETER); + retv_if(NULL == handle->stmt, MENU_SCREEN_ERROR_INVALID_PARAMETER); + + ret = sqlite3_finalize(handle->stmt); + retv_with_dbmsg_if(ret != SQLITE_OK, MENU_SCREEN_ERROR_FAIL); + free(handle); + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI long long db_last_insert_rowid(void) +{ + retv_if(NULL == db_info.db, -1l); + + long long rowid = sqlite3_last_insert_rowid(db_info.db); + + return rowid; +} + + + +HAPI menu_screen_error_e db_exec(const char *query) +{ + int ret; + char *errmsg; + + retv_if(NULL == query, MENU_SCREEN_ERROR_INVALID_PARAMETER); + retv_if(NULL == db_info.db, MENU_SCREEN_ERROR_FAIL); + + ret = sqlite3_exec(db_info.db, query, NULL, NULL, &errmsg); + if (ret != SQLITE_OK) { + _E("Cannot execute this query - %s. because %s", + query, errmsg? errmsg:"uncatched error"); + sqlite3_free(errmsg); + return MENU_SCREEN_ERROR_FAIL; + } + + return MENU_SCREEN_ERROR_OK; +} + + + +HAPI void db_close(void) +{ + ret_if(!db_info.db); + sqlite3_close(db_info.db); + db_info.db = NULL; +} + + + +HAPI menu_screen_error_e db_begin_transaction(void) +{ + int ret = -1; + + ret = sqlite3_exec(db_info.db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL); + + while (SQLITE_BUSY == ret) { + sleep(1); + ret = sqlite3_exec(db_info.db, "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL); + } + + if (SQLITE_OK != ret) { + _E("sqlite3_exec() Failed(%d)", ret); + return MENU_SCREEN_ERROR_FAIL; + } + + return MENU_SCREEN_ERROR_OK; +} + + + +#define MENU_SCREEN_COMMIT_TRY_MAX 3 +HAPI menu_screen_error_e db_end_transaction(bool success) +{ + int ret = -1; + int i = 0; + char *errmsg = NULL; + + if (success) { + ret = sqlite3_exec(db_info.db, "COMMIT TRANSACTION", NULL, NULL, &errmsg); + if (SQLITE_OK != ret) { + _E("sqlite3_exec(COMMIT) Failed(%d, %s)", ret, errmsg); + sqlite3_free(errmsg); + + while (SQLITE_BUSY == ret && i < MENU_SCREEN_COMMIT_TRY_MAX) { + i++; + sleep(1); + ret = sqlite3_exec(db_info.db, "COMMIT TRANSACTION", NULL, NULL, NULL); + } + + if (SQLITE_OK != ret) { + _E("sqlite3_exec() Failed(%d)", ret); + ret = sqlite3_exec(db_info.db, "ROLLBACK TRANSACTION", NULL, NULL, NULL); + if (SQLITE_OK != ret) { + _E("sqlite3_exec() Failed(%d)", ret); + } + + return MENU_SCREEN_ERROR_FAIL; + } + } + } else { + sqlite3_exec(db_info.db, "ROLLBACK TRANSACTION", NULL, NULL, NULL); + } + + return MENU_SCREEN_ERROR_OK; +} + + + +// End of file. diff --git a/src/item.c b/src/item.c index 6ebfde8..035c527 100644 --- a/src/item.c +++ b/src/item.c @@ -18,8 +18,9 @@ #include #include -#include #include +#include +#include #include "menu_screen.h" #include "item_badge.h" @@ -43,6 +44,7 @@ #define STR_ATTRIBUTE_PKG_NAME "package" #define STR_ATTRIBUTE_REMOVABLE "removable" #define STR_ATTRIBUTE_DESKTOP "desktop" +#define STR_ATTRIBUTE_TYPE "type" #define STR_ATTRIBUTE_PAGE "pending,page" #define STR_ICON_IMAGE_TYPE_OBJECT "object" #define STR_ICON_IMAGE_TYPE_EDJE "edje" @@ -210,6 +212,30 @@ HAPI inline char *item_get_desktop(Evas_Object *edje) +HAPI void item_set_type(Evas_Object *edje, int type, int sync) +{ + int tmp; + int changed; + + tmp = (int) evas_object_data_get(edje, STR_ATTRIBUTE_TYPE); + changed = (tmp == type ? 0 : 1); // We have to do sync when an attribute is created + + if (!changed) { + return ; + } + + evas_object_data_set(edje, STR_ATTRIBUTE_TYPE, (void *) type); +} + + + +HAPI inline int item_get_type(Evas_Object *edje) +{ + return (int) evas_object_data_get(edje, STR_ATTRIBUTE_TYPE); +} + + + HAPI void item_set_package(Evas_Object *edje, char *package, int sync) { char *tmp; @@ -723,13 +749,19 @@ HAPI void item_destroy(Evas_Object *item) static Eina_Bool _unblock_cb(void *data) { Evas_Object *layout; - layout = evas_object_data_get(menu_screen_get_win(), "layout_current"); + layout = evas_object_data_get(menu_screen_get_win(), "layout"); layout_disable_block(layout); return EINA_FALSE; } +static void _run_cb(bundle *b, int request_code, appsvc_result_val result, void *data) +{ +} + + + HAPI void item_launch(Evas_Object *obj) { char *package; @@ -743,32 +775,55 @@ HAPI void item_launch(Evas_Object *obj) package = item_get_package(obj); ret_if(NULL == package); - layout = evas_object_data_get(menu_screen_get_win(), "layout_current"); + layout = evas_object_data_get(menu_screen_get_win(), "layout"); layout_enable_block(layout); - ret_aul = aul_open_app(package); - if (ret_aul == AUL_R_EINVAL) { - char* sinform; - int len; - - // IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS : "Unable to launch %s" - len = strlen(D_("IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS")) + strlen(name) + 1; - - sinform = calloc(len, sizeof(char)); - if (!sinform) { - _E("cannot calloc for popup."); - return; + bool is_shortcut = (bool) evas_object_data_get(obj, "is_shortcut"); + bool shortcut_launch_package = (bool) evas_object_data_get(obj, "shortcut_launch_package"); + if (is_shortcut && !shortcut_launch_package) { + bundle *b = NULL; + b = bundle_create(); + ret_if(NULL == b); + + appsvc_set_operation(b, APPSVC_OPERATION_VIEW); + appsvc_set_uri(b, evas_object_data_get(obj, "content_info")); + + int ret = -1; + ret = appsvc_run_service(b, 0, _run_cb, NULL); + if (0 > ret) { + _E("cannot run service. ret [%d]", ret); + layout_disable_block(layout); + } else { + _D("Launch app's ret : [%d]", ret); + ecore_timer_add(LAYOUT_BLOCK_INTERVAL, _unblock_cb, NULL); } - snprintf(sinform, len, D_("IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS"), name); - popup_create(obj, sinform); - - free(sinform); - layout_disable_block(layout); + bundle_free(b); } else { - _D("Launch app's ret : [%d]", ret_aul); - _T(package); - ecore_timer_add(LAYOUT_BLOCK_INTERVAL, _unblock_cb, NULL); + ret_aul = aul_open_app(package); + if (ret_aul == AUL_R_EINVAL) { + char* sinform; + int len; + + // IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS : "Unable to launch %s" + len = strlen(D_("IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS")) + strlen(name) + 1; + + sinform = calloc(len, sizeof(char)); + if (!sinform) { + _E("cannot calloc for popup."); + return; + } + + snprintf(sinform, len, D_("IDS_IDLE_POP_UNABLE_TO_LAUNCH_PS"), name); + popup_create(obj, sinform); + + free(sinform); + layout_disable_block(layout); + } else { + _D("Launch app's ret : [%d]", ret_aul); + _T(package); + ecore_timer_add(LAYOUT_BLOCK_INTERVAL, _unblock_cb, NULL); + } } } diff --git a/src/page_scroller.c b/src/page_scroller.c index cd42b1f..5ada089 100644 --- a/src/page_scroller.c +++ b/src/page_scroller.c @@ -442,7 +442,7 @@ static Evas_Object *_animated_unpack_item(Evas_Object *scroller, Evas_Object *pa -HAPI menu_screen_error_e page_scroller_push_item(Evas_Object *scroller, app_info_t *ai) +HAPI Evas_Object *page_scroller_push_item(Evas_Object *scroller, app_info_t *ai) { Evas_Object *page; Evas_Object *item; @@ -485,25 +485,25 @@ HAPI menu_screen_error_e page_scroller_push_item(Evas_Object *scroller, app_info rotate = (int) evas_object_data_get(scroller, "rotate"); new_page = page_create(scroller, nr_of_pages, rotate); - retv_if(NULL == new_page, MENU_SCREEN_ERROR_FAIL); + retv_if(NULL == new_page, NULL); mapbuf_enable(new_page, 0); } item = item_create(scroller, ai); - retv_if(NULL == item, MENU_SCREEN_ERROR_FAIL); + retv_if(NULL == item, NULL); page = page_scroller_get_page_at(scroller, candidate_page); if (!page) { _D("Impossible, page is not found"); item_destroy(item); - return MENU_SCREEN_ERROR_FAIL; + return NULL; } retv_if(MENU_SCREEN_ERROR_OK != _animated_pack_item(item, scroller, page, candidate_pos), - MENU_SCREEN_ERROR_FAIL); + NULL); - return MENU_SCREEN_ERROR_OK; + return item; } @@ -547,11 +547,10 @@ static inline menu_screen_error_e _create_cb(const char *package, void *data) if (!item) { item = page_scroller_find_item_by_package(scroller, ai.package, NULL); if (!item) { - int ret; - + Evas_Object *item; _D("package %s is installed directly", package); - ret = page_scroller_push_item(scroller, &ai); - if (ret == MENU_SCREEN_ERROR_OK) { + item = page_scroller_push_item(scroller, &ai); + if (item) { break; } else { list_free_values(&ai); @@ -606,11 +605,10 @@ static inline menu_screen_error_e _update_cb(const char *package, void *data) item_destroy(item); } } else { - int ret; + Evas_Object *item; _D("Item is not found. Create a new one"); - - ret = ((!ai.nodisplay && ai.enabled) ? page_scroller_push_item(scroller, &ai) : MENU_SCREEN_ERROR_OK); - if (ret == MENU_SCREEN_ERROR_OK) { + item = ((!ai.nodisplay && ai.enabled) ? page_scroller_push_item(scroller, &ai) : NULL); + if (item) { break; } else { list_free_values(&ai); diff --git a/src/pkgmgr.c b/src/pkgmgr.c index 9b01b2f..cb9d79f 100644 --- a/src/pkgmgr.c +++ b/src/pkgmgr.c @@ -270,7 +270,7 @@ static menu_screen_error_e _start_install(const char *package, void *scroller) pi->item = page_scroller_find_item_by_package(scroller, package, &page_no); if (!pi->item) { - if (MENU_SCREEN_ERROR_FAIL == page_scroller_push_item(scroller, &pi->ai)) _E("Cannot push an item"); + if (NULL == page_scroller_push_item(scroller, &pi->ai)) _E("Cannot push an item"); } pi->item = page_scroller_find_item_by_package(scroller, package, &page_no); pi->page = page_scroller_get_page_at(scroller, page_no); @@ -391,7 +391,7 @@ static menu_screen_error_e _icon_path(const char *package, const char *val, void pi->ai.nodisplay = false; pi->ai.enabled = true; - if (MENU_SCREEN_ERROR_FAIL == page_scroller_push_item(scroller, &pi->ai)) { + if (NULL == page_scroller_push_item(scroller, &pi->ai)) { _E("Failed to create a new item, remove this package from the installing list"); list_free_values(&pi->ai); install_list = eina_list_remove(install_list, pi); diff --git a/src/popup.c b/src/popup.c index af27631..13ea790 100644 --- a/src/popup.c +++ b/src/popup.c @@ -23,6 +23,7 @@ #include "menu_screen.h" #include "pkgmgr.h" #include "util.h" +#include "all_apps/shortcut.h" #define BUFSZE 1024 @@ -84,8 +85,15 @@ static void _uninstall_yes_cb(void *data, Evas_Object *obj, void *event_info) evas_object_del(evas_object_data_del(popup, "button2")); evas_object_del(popup); - if (MENU_SCREEN_ERROR_OK != pkgmgr_uninstall(item)) { - _E("Cannot communicate with the pkgmgr-server."); + bool is_shortcut = false; + is_shortcut = (bool) evas_object_data_get(item, "is_shortcut"); + + if (is_shortcut) { + all_apps_shortcut_remove(item); + } else { + if (MENU_SCREEN_ERROR_OK != pkgmgr_uninstall(item)) { + _E("Cannot communicate with the pkgmgr-server."); + } } } -- 2.34.1