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