From 932d1a715103c225d55833de08fe1d65aeae2cf2 Mon Sep 17 00:00:00 2001 From: Soohye Shin Date: Thu, 18 Jun 2015 12:40:44 +0900 Subject: [PATCH] add utils for creating widget and launch app Change-Id: I5f4718f69182f90832321b593c5de31ec00506c1 Signed-off-by: Soohye Shin --- CMakeLists.txt | 1 + include/utils.h | 34 ++++++++++ src/utils.c | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 include/utils.h create mode 100644 src/utils.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fe857a..b980692 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,7 @@ SET(DEFCONFIG "${PROJECT_NAME}.json") SET(THEME_EDJ "${PROJECT_NAME}-theme.edj") SET(SRCS src/main.c + src/utils.c src/data/datamgr.c src/data/data_home.c src/view/view_recent.c diff --git a/include/utils.h b/include/utils.h new file mode 100644 index 0000000..4d34d14 --- /dev/null +++ b/include/utils.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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 __AIR_HOME_UTILS_H__ +#define __AIR_HOME_UTILS_H__ + +#include +#include + +Evas_Object *utils_add_layout(Evas_Object *base, const char *group, bool focus_allow, + const char *part); +Evas_Object *utils_add_icon(Evas_Object *base, const char *file, const char *part); +Evas_Object *utils_add_label(Evas_Object *base, char *text, const char *style, + const char *part); +Evas_Object *utils_add_bg(Evas_Object *base, int r, int g, int b, int a, + const char *part); +Evas_Object *utils_add_scroller(Evas_Object *base); +Evas_Object *utils_add_box(Evas_Object *base, bool horizon); +bool utils_launch_app(const char *pkg); + +#endif /* __AIR_HOME_UTILS_H__ */ diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 0000000..ae84a88 --- /dev/null +++ b/src/utils.c @@ -0,0 +1,197 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0 + * + * 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 "utils.h" +#include "defs.h" + +Evas_Object *utils_add_layout(Evas_Object *base, const char *group, + bool focus_allow, const char *part) +{ + Evas_Object *ly; + + if (!base || !group) { + _ERR("Invalid argument"); + return NULL; + } + + ly = elm_layout_add(base); + if (!ly) { + _ERR("failed to add layout"); + return false; + } + elm_layout_file_set(ly, EDJEFILE, group); + + if (focus_allow) + elm_object_focus_allow_set(ly, EINA_TRUE); + if (part) + elm_object_part_content_set(base, part, ly); + + evas_object_show(ly); + + return ly; +} + +Evas_Object *utils_add_icon(Evas_Object *base, const char *file, + const char *part) +{ + Evas_Object *ic; + + if (!base || !file) { + _ERR("Invalid argument"); + return NULL; + } + + ic = elm_icon_add(base); + if (!ic) { + _ERR("failed to add icon"); + return NULL; + } + + elm_image_file_set(ic, file, NULL); + + if (part) + elm_object_part_content_set(base, part, ic); + + evas_object_show(ic); + + return ic; +} + +Evas_Object *utils_add_label(Evas_Object *base, char *text, + const char *style, const char *part) +{ + Evas_Object *lbl; + const char *s; + + if (!base || !text) { + _ERR("Invalid argument"); + return NULL; + } + + lbl = elm_label_add(base); + if (!lbl) { + _ERR("failed to add label"); + return NULL; + } + + if (style) + elm_object_style_set(lbl, style); + + s = edje_object_data_get(elm_layout_edje_get(base), TITLE_WIDTH); + if (s) + elm_label_wrap_width_set(lbl, atoi(s)); + + elm_object_text_set(lbl, text); + + if (part) + elm_object_part_content_set(base, part, lbl); + + evas_object_show(lbl); + + return lbl; +} + +Evas_Object *utils_add_bg(Evas_Object *base, int r, int g, int b, int a, + const char *part) +{ + Evas_Object *bg; + + if (!base) { + _ERR("Invalid argument"); + return NULL; + } + + bg = evas_object_rectangle_add(evas_object_evas_get(base)); + if (!bg) { + _ERR("failed to add label"); + return NULL; + } + + evas_object_color_set(bg, r, g, b, a); + + if (part) + elm_object_part_content_set(base, part, bg); + + evas_object_show(bg); + + return bg; +} + +Evas_Object *utils_add_scroller(Evas_Object *base) +{ + Evas_Object *scr; + + scr = elm_scroller_add(base); + if (!scr) { + _ERR("failed to add scroller"); + return NULL; + } + + elm_scroller_policy_set(scr, ELM_SCROLLER_POLICY_OFF, + ELM_SCROLLER_POLICY_OFF); + evas_object_show(scr); + + return scr; +} + +Evas_Object *utils_add_box(Evas_Object *base, bool horizon) +{ + Evas_Object *box; + + box = elm_box_add(base); + if (!box) { + _ERR("failed to add box"); + return NULL; + } + + if (horizon) + elm_box_horizontal_set(box, EINA_TRUE); + + evas_object_show(box); + + return box; +} + +bool utils_launch_app(const char *pkg) +{ + app_control_h app_control; + int r; + + if (!pkg) { + _ERR("Invalid argument"); + return false; + } + + app_control_create(&app_control); + app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT); + app_control_set_app_id(app_control, pkg); + + r = app_control_send_launch_request(app_control, NULL, NULL); + if (r != APP_CONTROL_ERROR_NONE) { + _ERR("failed to launch pkg"); + app_control_destroy(app_control); + return false; + } + + app_control_destroy(app_control); + + return true; +} -- 2.7.4