summaryrefslogtreecommitdiff
path: root/src/memo-genlist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/memo-genlist.c')
-rw-r--r--src/memo-genlist.c290
1 files changed, 290 insertions, 0 deletions
diff --git a/src/memo-genlist.c b/src/memo-genlist.c
new file mode 100644
index 0000000..c24bf79
--- /dev/null
+++ b/src/memo-genlist.c
@@ -0,0 +1,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;
+}
+