APPLY_RSA
[apps/home/ug-memo-efl.git] / src / ug-detail.c
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.0 (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
8 *
9 *    http://www.tizenopensource.org/license
10 *
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.
16 *
17 */
18
19 #include <stdlib.h>
20 #include <stdio.h>
21 #include <Elementary.h>
22 #include <dlog.h>
23 #include <ui-gadget-module.h>
24 #include <gravel.h>
25 #include <memo_string.h>
26 #include <extended-elm.h>
27 #include <supplement.h>
28 #include <memo-assist.h>
29 #include <memo-genlist.h>
30 #include <memo-assist.h>
31 #include <memo_ug.h>
32 #include <memo_autolink.h>
33 #include <memo-efl.h>
34
35 typedef struct __detail_view_t {
36     ug_data_t *ugd;
37     Evas_Object *navigator;
38     Evas_Object *ctrl_bar;
39     Evas_Object *body_main;
40     Evas_Object *entry;
41     char *content;
42
43     /* add more variables here */
44     int index;
45 } detail_view_t;
46
47 static void _on_quit(void *data, Evas_Object *obj, void *event_info)
48 {
49     RETIF(data == NULL);
50     detail_view_t *dv = (detail_view_t *)data;
51     ug_data_t *ugd = dv->ugd;
52     ug_destroy_me(ugd->ug);
53 }
54
55 static void _on_entry_resize(void *data, Evas_Object *obj, void *event_info)
56 {
57     LOGD("---------------_on_entry_resize");
58     detail_view_t *dv = (detail_view_t *)data;
59     elm_entry_entry_set(dv->entry, dv->content);
60     SFREE(dv->content);
61 }
62
63 static void _create_detail_layout(detail_view_t *dv)
64 {
65     ug_data_t *ugd = dv->ugd;
66     Evas_Object *content = NULL;
67     memo_data_t *md = memo_get_data(dv->index);
68
69     /* add navigationbar */
70     dv->navigator = elm_naviframe_add(ugd->base);
71
72     /* body main */
73     dv->body_main = elm_layout_create(dv->navigator, EDJ_FILE, "detail_frame");
74     if (md != NULL) {
75         /* date */
76         memo_time_format(ugd->buf, MEMO_BUFFER_SIZE, md->modi_time);
77         edje_object_part_text_set(_EDJ(dv->body_main), "elm.text.date", ugd->buf);
78         /* content */
79         if(md->has_doodle) {
80             snprintf(ugd->buf, MEMO_BUFFER_SIZE, "/opt/apps/org.tizen.memo/data/doodle/%d.png", (int)md->id);
81             content = elm_swallowed_icon(dv->body_main, "elm.swallow.content", ugd->buf);
82         } else {
83             char buf[MEMO_BUFFER_SIZE];
84             GString *text =
85                 autolink_add_anchor(elm_entry_utf8_to_markup
86                         (md->content));
87             unsigned char *color = (unsigned char *)&md->font_color;
88             snprintf(buf, MEMO_BUFFER_SIZE,
89                 "<font_size=%d><color=#%02x%02x%02x>",
90                 md->font_size, color[2], color[1], color[0]);
91             g_string_prepend(text, buf);
92
93             Evas_Object *sc = NULL;
94             sc = elm_swallowed_scroller(dv->body_main, "elm.swallow.content");
95             content = elm_entry_create(dv->body_main, text->str);
96             dv->content = strdup(text->str);
97             evas_object_smart_callback_add(content, "anchor,clicked", autolink_anchor_clicked_cb, ug_get_parent_layout(ugd->ug));
98             evas_object_size_hint_weight_set(content, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
99             evas_object_size_hint_align_set(content, EVAS_HINT_FILL, EVAS_HINT_EXPAND);
100             elm_entry_editable_set(content, EINA_FALSE);
101             elm_entry_autocapital_type_set(content, ELM_AUTOCAPITAL_TYPE_SENTENCE);
102             elm_object_content_set(sc, content);
103             dv->entry = content;
104             evas_object_render_flush_hook(dv->entry, _on_entry_resize, dv);
105
106             g_string_free(text, TRUE);
107
108             edje_object_signal_emit(_EDJ(dv->body_main), "sig_text_mode", "");
109         }
110         memo_free_data(md);
111     }
112
113     /* compose */
114     Elm_Object_Item *navi_it = elm_naviframe_item_push(dv->navigator, MEMO_I18N_MEMO, NULL, NULL, dv->body_main, NULL);
115     Evas_Object *ctrl_bar = memo_controlbar_add(dv->navigator);
116     elm_toolbar_item_append(ctrl_bar, NULL, MEMO_I18N_QUIT, _on_quit, dv);
117     elm_object_item_part_content_set(navi_it, "controlbar", ctrl_bar);
118 }
119
120 void *memo_load_detail_view(ug_data_t *ugd, service_h service)
121 {
122     detail_view_t *dv = SMALLOC(detail_view_t);
123     RETVIF(dv == NULL, NULL);
124     dv->ugd = ugd;
125
126     /* init */
127     char *str = NULL;;
128     service_get_extra_data(service, "index", &str);
129     if (str != NULL) {
130         dv->index = atoi(str);
131         SFREE(str);
132     } else {
133         SFREE(dv);
134         return NULL;
135     }
136
137     /* create */
138     _create_detail_layout(dv);
139     elm_object_part_content_set(ugd->base, "elm.swallow.content", dv->navigator);
140     return (void *)dv;
141 }