3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.1 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license/
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <Elementary.h>
21 #include <extended-elm.h>
23 #include <appcore-common.h>
24 #include <memo-assist.h>
25 #include <memo_string.h>
26 #include <memo-genlist.h>
28 static void _str_append_utf8(char *s, int size, const char *utf8)
31 content = elm_entry_utf8_to_markup(utf8);
32 RETIF(content == NULL);
33 sncat(s,size, content);
41 * @param [in] data user specified data
43 * @param [in] obj evas_object of elm_genlist_item
45 * @param [in] part part name in genlist group
56 char *memo_gl_label_get(void *data, Evas_Object *obj, const char *part)
58 gl_data_t *gld = (gl_data_t *)data;
59 char buf[MEMO_BUFFER_SIZE] = {0};
60 char input[MEMO_BUFFER_SIZE] = {0};
61 char output[MEMO_BUFFER_SIZE] = {0};
63 const char *pre = NULL;
65 if (!strcmp(part, "elm.text.date")) {
66 memo_time_format(buf, MEMO_BUFFER_SIZE, gld->mod_time);
68 } else if (!strcmp(part, "elm.slide.text.1")) {
69 if (gld->index == -1) {
70 return strdup(MEMO_I18N_WELCOME_TO_TIZEN_MEMO);
72 memo_data_t *md = memo_get_data(gld->index);
73 snprintf(input, MEMO_BUFFER_SIZE, "%s",
74 (md->comment == NULL ? md->content : md->comment)); /* limit input */
78 } else if (!strcmp(part, "elm.text")) {
79 if (gld->index == -1) {
80 return strdup(MEMO_I18N_WELCOME_TO_TIZEN_MEMO);
82 memo_data_t *md = memo_get_data(gld->index);
84 if (md->comment != NULL) {
85 snprintf(input, MEMO_BUFFER_SIZE, "%s", md->comment);
87 snprintf(input, MEMO_BUFFER_SIZE, "%s", md->content);
89 /* truncate to single line */
90 p = strstr(input, "\342\200\251");
92 input[p-input] = '\0';
94 /* font color information */
95 unsigned char *color = (unsigned char *)&md->font_color;
96 snprintf(output, MEMO_BUFFER_SIZE, "<color=#%02x%02x%02x>", color[2], color[1], color[0]);
97 /* append text information */
98 if (gld->search == NULL) {
99 _str_append_utf8(output, MEMO_BUFFER_SIZE, input);
102 /* search and composite */
103 p = (const char *)strcasestr(pre, gld->search);
105 /* append characters before matched string */
108 strncat(buf, pre, p-pre);
109 _str_append_utf8(output, MEMO_BUFFER_SIZE, buf);
112 sncat(output, MEMO_BUFFER_SIZE, "<color=#FF0000>");
114 strncat(buf, p, strlen(gld->search));
115 _str_append_utf8(output, MEMO_BUFFER_SIZE, buf);
116 sncat(output, MEMO_BUFFER_SIZE, "</color>");
117 /* set pointer after matched string */
118 pre = p+strlen(gld->search);
120 /* append remaining string */
121 _str_append_utf8(output, MEMO_BUFFER_SIZE, pre);
124 return strdup(output);
135 * @param [in] data user specified data
137 * @param [in] obj evas_object of elm_genlist_item
139 * @param [in] part part name in genlist group
150 Evas_Object *memo_gl_icon_get(void *data, Evas_Object *obj, const char *part)
152 gl_data_t *gld = (gl_data_t *)data;
153 char buf[MEMO_BUFFER_SIZE];
154 Evas_Object *eo = NULL;
156 if (!strcmp(part, "elm.swallow.doodle")) {
157 if (gld->has_doodle != 0) {
158 snprintf(buf, MEMO_BUFFER_SIZE, DOODLEDIR "/%d.png", gld->index);
159 eo = elm_icon_create(obj, buf);
161 } else if (!strcmp(part, "elm.swallow.check")) {
162 if (gld->index != -1) { /* only add checkbox for non-sentinel data, as required by CQ defect H0100123202 */
163 eo = elm_check_add(obj);
164 elm_check_state_pointer_set(eo, &gld->check);
165 if (gld->on_change != NULL) {
166 evas_object_smart_callback_add(eo, "changed", gld->on_change, gld);
169 } else if (!strcmp(part, "elm.slide.swallow.1")) {
170 eo = elm_button_create(obj, MEMO_I18N_DELETE, gld->on_delete, gld);
171 } else if (!strcmp(part, "elm.slide.swallow.2")) {
172 eo = elm_button_create(obj, MEMO_I18N_SHARE, gld->on_send, gld);
177 Eina_Bool memo_gl_state_get(void *data, Evas_Object *obj, const char *part)
187 * @param [in] data user specified data
189 * @param [in] obj evas_object of elm_genlist_item
200 void memo_gl_del(void *data, Evas_Object *obj)
202 gl_data_t *gld = (gl_data_t *)data;
212 * @param [in] itc handle of Elm_Genlist_Item_Class
225 void memo_gl_itc_init(Elm_Genlist_Item_Class *itc, const char *style)
227 itc->item_style = style;
228 itc->func.text_get = memo_gl_label_get;
229 itc->func.content_get = memo_gl_icon_get;
230 itc->func.state_get = memo_gl_state_get;
231 itc->func.del = memo_gl_del;
239 * @param [in] data handle of gl_data_t
241 * @param [in] md original memo record data
243 * @param [in] user_data user specified data
245 * @param [in] on_select callback function when genlist item is selected
256 void memo_gld_init(gl_data_t *data, memo_data_t *md, void *user_data, Evas_Smart_Cb on_select)
258 data->index = md->id;
259 data->has_doodle = md->has_doodle;
260 data->mod_time = md->modi_time;
261 data->on_select = on_select;
262 data->user_data = user_data;
266 * memo_gld_sentinel_create
270 * @param [in] user_data
281 gl_data_t * memo_gld_sentinel_create(void *user_data)
283 gl_data_t *data = SMALLOC(gl_data_t);
284 RETVIF(data == NULL, NULL);
286 data->mod_time = memo_get_binary_release_date();
287 data->user_data = user_data;