summaryrefslogtreecommitdiff
path: root/src/memo-genlist.c
blob: c24bf79cb69068a513e6094ffd014f3e2c856d6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
*
* 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://floralicense.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 <Elementary.h>
#include <gravel.h>
#include <extended-elm.h>
#include <memo-db.h>
#include <appcore-common.h>
#include <memo-assist.h>
#include <memo_string.h>
#include <memo-genlist.h>

static void _str_append_utf8(char *s, int size, const char *utf8)
{
    char *content = NULL;
    content = elm_entry_utf8_to_markup(utf8);
    RETIF(content == NULL);
    sncat(s,size, content);
    SFREE(content);
}
/**
 * memo_gl_label_get
 *
 * @brief
 *
 * @param   [in] data   user specified data
 *
 * @param   [in] obj    evas_object of elm_genlist_item
 *
 * @param   [in] part   part name in genlist group
 *
 * @return
 *
 * @exception    None
 *
 * @remark       None
 *
 * @see
 *
 */
char *memo_gl_label_get(void *data, Evas_Object *obj, const char *part)
{
    gl_data_t *gld = (gl_data_t *)data;
    char buf[MEMO_BUFFER_SIZE] = {0};
    char input[MEMO_BUFFER_SIZE] = {0};
    char output[MEMO_BUFFER_SIZE] = {0};
    const char *p = NULL;
    const char *pre = NULL;

    if (!strcmp(part, "elm.text.date")) {
        memo_time_format(buf, MEMO_BUFFER_SIZE, gld->mod_time);
        return strdup(buf);
    } else if (!strcmp(part, "elm.slide.text.1")) {
        if (gld->index == -1) {
            return strdup(MEMO_I18N_WELCOME_TO_TIZEN_MEMO);
        } else {
            memo_data_t *md = memo_get_data(gld->index);
            snprintf(input, MEMO_BUFFER_SIZE, "%s",
                (md->comment == NULL ? md->content : md->comment)); /* limit input */
            memo_free_data(md);
            return strdup(input);
        }
    } else if (!strcmp(part, "elm.text")) {
        if (gld->index == -1) {
            return strdup(MEMO_I18N_WELCOME_TO_TIZEN_MEMO);
        } else {
            memo_data_t *md = memo_get_data(gld->index);
            /* limit input */
            if (md->comment != NULL) {
                snprintf(input, MEMO_BUFFER_SIZE, "%s", md->comment);
            } else {
                snprintf(input, MEMO_BUFFER_SIZE, "%s", md->content);
            }
            /* truncate to single line */
            p = strstr(input, "\342\200\251");
            if (p != NULL) {
                input[p-input] = '\0';
            }
            /* font color information */
            unsigned char *color = (unsigned char *)&md->font_color;
            snprintf(output, MEMO_BUFFER_SIZE, "<color=#%02x%02x%02x>", color[2], color[1], color[0]);
            /* append text information */
            if (gld->search == NULL) {
                _str_append_utf8(output, MEMO_BUFFER_SIZE, input);
            } else {
                pre = input;
                /* search and composite */
                p = (const char *)strcasestr(pre, gld->search);
                if (p != NULL) {
                    /* append characters before matched string */
                    if (p != pre) {
                        buf[0]='\0';
                        strncat(buf, pre, p-pre);
                        _str_append_utf8(output, MEMO_BUFFER_SIZE, buf);
                    }
                    /* highlight str */
                    sncat(output, MEMO_BUFFER_SIZE, "<color=#FF0000>");
                    buf[0]='\0';
                    strncat(buf, p, strlen(gld->search));
                    _str_append_utf8(output, MEMO_BUFFER_SIZE, buf);
                    sncat(output, MEMO_BUFFER_SIZE, "</color>");
                    /* set pointer after matched string */
                    pre = p+strlen(gld->search);
                }
                /* append remaining string */
                _str_append_utf8(output, MEMO_BUFFER_SIZE, pre);
            }
            memo_free_data(md);
            return strdup(output);
        }
    }
    return NULL;
}

/**
 * memo_gl_icon_get
 *
 * @brief
 *
 * @param   [in] data   user specified data
 *
 * @param   [in] obj    evas_object of elm_genlist_item
 *
 * @param   [in] part   part name in genlist group
 *
 * @return
 *
 * @exception    None
 *
 * @remark       None
 *
 * @see
 *
 */
Evas_Object *memo_gl_icon_get(void *data, Evas_Object *obj, const char *part)
{
    gl_data_t *gld = (gl_data_t *)data;
    char buf[MEMO_BUFFER_SIZE];
    Evas_Object *eo = NULL;

    if (!strcmp(part, "elm.swallow.doodle")) {
        if (gld->has_doodle != 0) {
            snprintf(buf, MEMO_BUFFER_SIZE, DOODLEDIR "/%d.png", gld->index);
            eo = elm_icon_create(obj, buf);
        }
    } else if (!strcmp(part, "elm.swallow.check")) {
        if (gld->index != -1) {    /* only add checkbox for non-sentinel data, as required by CQ defect H0100123202 */
            eo = elm_check_add(obj);
            elm_check_state_pointer_set(eo, &gld->check);
            if (gld->on_change != NULL) {
                evas_object_smart_callback_add(eo, "changed", gld->on_change, gld);
            }
        }
    } else if (!strcmp(part, "elm.slide.swallow.1")) {
        eo = elm_button_create(obj, MEMO_I18N_DELETE, gld->on_delete, gld);
    } else if (!strcmp(part, "elm.slide.swallow.2")) {
        eo = elm_button_create(obj, MEMO_I18N_SHARE, gld->on_send, gld);
    }
    return eo;
}

Eina_Bool memo_gl_state_get(void *data, Evas_Object *obj, const char *part)
{
    return EINA_FALSE;
}

/**
 * memo_gl_del
 *
 * @brief
 *
 * @param   [in] data   user specified data
 *
 * @param   [in] obj    evas_object of elm_genlist_item
 *
 * @return
 *
 * @exception    None
 *
 * @remark       None
 *
 * @see
 *
 */
void memo_gl_del(void *data, Evas_Object *obj)
{
    gl_data_t *gld = (gl_data_t *)data;
    SFREE(gld);
    return;
}

/**
 * memo_gl_itc_init
 *
 * @brief
 *
 * @param   [in] itc    handle of Elm_Genlist_Item_Class
 *
 * @param   [in] style
 *
 * @return
 *
 * @exception    None
 *
 * @remark       None
 *
 * @see
 *
 */
void memo_gl_itc_init(Elm_Genlist_Item_Class *itc, const char *style)
{
    itc->item_style = style;
    itc->func.text_get = memo_gl_label_get;
    itc->func.content_get = memo_gl_icon_get;
    itc->func.state_get = memo_gl_state_get;
    itc->func.del = memo_gl_del;
}

/**
 * memo_gld_init
 *
 * @brief
 *
 * @param   [in] data   handle of gl_data_t
 *
 * @param   [in] md     original memo record data
 *
 * @param   [in] user_data user specified data
 *
 * @param   [in] on_select callback function when genlist item is selected
 *
 * @return
 *
 * @exception    None
 *
 * @remark       None
 *
 * @see
 *
 */
void memo_gld_init(gl_data_t *data, memo_data_t *md, void *user_data, Evas_Smart_Cb on_select)
{
    data->index = md->id;
    data->has_doodle = md->has_doodle;
    data->mod_time = md->modi_time;
    data->on_select = on_select;
    data->user_data = user_data;
}

/**
 * memo_gld_sentinel_create
 *
 * @brief
 *
 * @param   [in] user_data
 *
 * @return
 *
 * @exception    None
 *
 * @remark       None
 *
 * @see
 *
 */
gl_data_t * memo_gld_sentinel_create(void *user_data)
{
    gl_data_t *data = SMALLOC(gl_data_t);
    RETVIF(data == NULL, NULL);
    data->index = -1;
    data->mod_time = memo_get_binary_release_date();
    data->user_data = user_data;
    return data;
}