2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
19 #include <extended-elm.h>
21 #include <appcore-common.h>
22 #include <memo-assist.h>
23 #include <memo_string.h>
24 #include <memo-genlist.h>
26 static void _str_append_utf8(char *s, int size, const char *utf8)
29 content = elm_entry_utf8_to_markup(utf8);
30 RETIF(content == NULL);
31 sncat(s,size, content);
39 * @param [in] data user specified data
41 * @param [in] obj evas_object of elm_genlist_item
43 * @param [in] part part name in genlist group
54 char *memo_gl_label_get(void *data, Evas_Object *obj, const char *part)
56 gl_data_t *gld = (gl_data_t *)data;
57 char buf[MEMO_BUFFER_SIZE] = {0};
58 char input[MEMO_BUFFER_SIZE] = {0};
59 char output[MEMO_BUFFER_SIZE] = {0};
61 const char *pre = NULL;
63 if (!strcmp(part, "elm.text.date")) {
64 memo_time_format(buf, MEMO_BUFFER_SIZE, gld->mod_time);
66 } else if (!strcmp(part, "elm.slide.text.1")) {
67 if (gld->index == -1) {
68 return strdup(MEMO_I18N_WELCOME_TO_TIZEN_MEMO);
70 memo_data_t *md = memo_get_data(gld->index);
71 snprintf(input, MEMO_BUFFER_SIZE, "%s",
72 (md->comment == NULL ? md->content : md->comment)); /* limit input */
76 } else if (!strcmp(part, "elm.text")) {
77 if (gld->index == -1) {
78 return strdup(MEMO_I18N_WELCOME_TO_TIZEN_MEMO);
80 memo_data_t *md = memo_get_data(gld->index);
82 if (md->comment != NULL) {
83 snprintf(input, MEMO_BUFFER_SIZE, "%s", md->comment);
85 snprintf(input, MEMO_BUFFER_SIZE, "%s", md->content);
87 /* truncate to single line */
88 p = strstr(input, "\342\200\251");
90 input[p-input] = '\0';
92 /* font color information */
93 unsigned char *color = (unsigned char *)&md->font_color;
94 snprintf(output, MEMO_BUFFER_SIZE, "<color=#%02x%02x%02x>", color[2], color[1], color[0]);
95 /* append text information */
96 if (gld->search == NULL) {
97 _str_append_utf8(output, MEMO_BUFFER_SIZE, input);
100 /* search and composite */
101 p = (const char *)strcasestr(pre, gld->search);
103 /* append characters before matched string */
106 strncat(buf, pre, p-pre);
107 _str_append_utf8(output, MEMO_BUFFER_SIZE, buf);
110 sncat(output, MEMO_BUFFER_SIZE, "<color=#FF0000>");
112 strncat(buf, p, strlen(gld->search));
113 _str_append_utf8(output, MEMO_BUFFER_SIZE, buf);
114 sncat(output, MEMO_BUFFER_SIZE, "</color>");
115 /* set pointer after matched string */
116 pre = p+strlen(gld->search);
118 /* append remaining string */
119 _str_append_utf8(output, MEMO_BUFFER_SIZE, pre);
122 return strdup(output);
133 * @param [in] data user specified data
135 * @param [in] obj evas_object of elm_genlist_item
137 * @param [in] part part name in genlist group
148 Evas_Object *memo_gl_icon_get(void *data, Evas_Object *obj, const char *part)
150 gl_data_t *gld = (gl_data_t *)data;
151 char buf[MEMO_BUFFER_SIZE];
152 Evas_Object *eo = NULL;
154 if (!strcmp(part, "elm.swallow.doodle")) {
155 if (gld->has_doodle != 0) {
156 snprintf(buf, MEMO_BUFFER_SIZE, DOODLEDIR "/%d.png", gld->index);
157 eo = elm_icon_create(obj, buf);
159 } else if (!strcmp(part, "elm.swallow.check")) {
160 if (gld->index != -1) { /* only add checkbox for non-sentinel data, as required by CQ defect H0100123202 */
161 eo = elm_check_add(obj);
162 elm_check_state_pointer_set(eo, &gld->check);
163 if (gld->on_change != NULL) {
164 evas_object_smart_callback_add(eo, "changed", gld->on_change, gld);
167 } else if (!strcmp(part, "elm.slide.swallow.1")) {
168 eo = elm_button_create(obj, MEMO_I18N_DELETE, gld->on_delete, gld);
169 } else if (!strcmp(part, "elm.slide.swallow.2")) {
170 eo = elm_button_create(obj, MEMO_I18N_SHARE, gld->on_send, gld);
175 Eina_Bool memo_gl_state_get(void *data, Evas_Object *obj, const char *part)
185 * @param [in] data user specified data
187 * @param [in] obj evas_object of elm_genlist_item
198 void memo_gl_del(void *data, Evas_Object *obj)
200 gl_data_t *gld = (gl_data_t *)data;
210 * @param [in] itc handle of Elm_Genlist_Item_Class
223 void memo_gl_itc_init(Elm_Genlist_Item_Class *itc, const char *style)
225 itc->item_style = style;
226 itc->func.text_get = memo_gl_label_get;
227 itc->func.content_get = memo_gl_icon_get;
228 itc->func.state_get = memo_gl_state_get;
229 itc->func.del = memo_gl_del;
237 * @param [in] data handle of gl_data_t
239 * @param [in] md original memo record data
241 * @param [in] user_data user specified data
243 * @param [in] on_select callback function when genlist item is selected
254 void memo_gld_init(gl_data_t *data, memo_data_t *md, void *user_data, Evas_Smart_Cb on_select)
256 data->index = md->id;
257 data->has_doodle = md->has_doodle;
258 data->mod_time = md->modi_time;
259 data->on_select = on_select;
260 data->user_data = user_data;
264 * memo_gld_sentinel_create
268 * @param [in] user_data
279 gl_data_t * memo_gld_sentinel_create(void *user_data)
281 gl_data_t *data = SMALLOC(gl_data_t);
282 RETVIF(data == NULL, NULL);
284 data->mod_time = memo_get_binary_release_date();
285 data->user_data = user_data;