Tizen souce update
[apps/home/ug-memo-efl.git] / src / memo-efl.c
1 /*
2  * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd All Rights Reserved
3  * 
4  * This file is part of the ug-memo-efl
5  * Written by Zhibin Zhou <zhibin.zhou@samsung.com>, Canjiang Lu <canjiang.lu@samsung.com>,
6  *            Feng Li <feng.li@samsung.com>
7  *
8  * PROPRIETARY/CONFIDENTIAL
9  *
10  * This software is the confidential and proprietary information of
11  * SAMSUNG ELECTRONICS ("Confidential Information").
12  * You shall not disclose such Confidential Information and shall
13  * use it only in accordance with the terms of the license agreement
14  * you entered into with SAMSUNG ELECTRONICS.  SAMSUNG make no
15  * representations or warranties about the suitability
16  * of the software, either express or implied, including but not
17  * limited to the implied warranties of merchantability, fitness for a particular purpose, or non-
18  * infringement. SAMSUNG shall not be liable for any damages suffered by licensee as
19  * a result of using, modifying or distributing this software or its derivatives.
20  *
21  */
22 #ifndef UG_MODULE_API
23 #define UG_MODULE_API __attribute__ ((visibility("default")))
24 #endif
25
26 #include <Elementary.h>
27 #include <ui-gadget-module.h>
28 #include <supplement.h>
29 #include <memo_ug.h>
30 #include "memo-efl.h"
31
32 static Evas_Object *create_fullview(Evas_Object *parent, struct ug_data *ugd)
33 {
34     Evas_Object *base;
35
36     base = elm_layout_add(parent);
37     if (!base)
38         return NULL;
39     elm_layout_theme_set(base, "layout", "application", "default");
40
41     /* set bg */
42     Evas_Object *bg = elm_bg_add(base);
43     evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
44     elm_object_part_content_set(base, "elm.swallow.bg", bg);
45
46     return base;
47 }
48
49 static Evas_Object *create_frameview(Evas_Object *parent, struct ug_data *ugd)
50 {
51     Evas_Object *base;
52
53     base = elm_layout_add(parent);
54     if (!base)
55         return NULL;
56     elm_layout_theme_set(base, "layout", "application", "default");
57
58     return base;
59 }
60
61 static Evas_Object *create_error_popup_layout(Evas_Object *parent, bool is_fullview)
62 {
63     Evas_Object *base;
64
65     base = elm_layout_add(parent);
66     if (!base)
67         return NULL;
68
69     if (is_fullview)
70         elm_layout_theme_set(base, "layout", "application", "default");
71     else
72         elm_layout_theme_set(base, "layout", "application", "noindicator");
73
74     evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75
76     return base;
77 }
78
79 void memo_ug_hide_cb(void *data, Evas_Object *obj, void *event_info)
80 {
81         ug_destroy_me(data);
82 }
83
84 static void *on_create(struct ui_gadget *ug, enum ug_mode mode, bundle *data, void *priv)
85 {
86     Evas_Object *parent;
87     struct ug_data *ugd;
88     const char *index = NULL;
89
90     if (!ug || !priv)
91         return NULL;
92
93     ugd = priv;
94     ugd->ug = ug;
95
96     bundle_dump(data);
97
98     /* theme extension */
99     ugd->th = elm_theme_new();
100     elm_theme_ref_set(ugd->th, NULL);
101     elm_theme_extension_add(ugd->th, EDJ_FILE);
102
103     /* open database */
104     memo_init(NULL);
105
106     /* i18n */
107     bindtextdomain("memo", "/opt/ug/res/locale");
108
109     parent = ug_get_parent_layout(ug);
110     if (!parent)
111         return NULL;
112
113     index = bundle_get_val(data, "index");
114     if (index != NULL) {/* legitimacy check of memo record */
115         memo_data_t *md = memo_get_data(atoi(index));
116         if (md == NULL) {
117             if (mode == UG_MODE_FULLVIEW)
118                 ugd->base = create_error_popup_layout(parent, TRUE);
119             else
120                 ugd->base = create_error_popup_layout(parent, FALSE);
121
122             Evas_Object *popup;
123             popup = elm_popup_add(ugd->base);
124             evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
125             elm_object_text_set(popup, dgettext("sys_string", "IDS_COM_POP_FILE_NOT_FOUND"));
126             elm_popup_timeout_set(popup, 1.5);
127             evas_object_show(popup);
128             ugd->ug = ug;
129             evas_object_smart_callback_add(popup, "timeout", memo_ug_hide_cb, ugd->ug);
130
131             return ugd->base;           
132         } else {
133             memo_free_data(md);
134         }
135     }
136
137     if (mode == UG_MODE_FULLVIEW)
138         ugd->base = create_fullview(parent, ugd);
139     else
140         ugd->base = create_frameview(parent, ugd);
141
142     if (ugd->base) {
143         if (bundle_key_check(data, "type", "select")) {
144             memo_load_select_view(ugd, data);
145         } else if (index != NULL) {
146             memo_load_detail_view(ugd, data);
147         } else {
148             memo_load_select_view(ugd, data);
149         }
150     }
151
152     return ugd->base;
153 }
154
155 static void on_start(struct ui_gadget *ug, bundle *data, void *priv)
156 {
157 }
158
159 static void on_pause(struct ui_gadget *ug, bundle *data, void *priv)
160 {
161
162 }
163
164 static void on_resume(struct ui_gadget *ug, bundle *data, void *priv)
165 {
166
167 }
168
169 static void on_destroy(struct ui_gadget *ug, bundle *data, void *priv)
170 {
171     struct ug_data *ugd;
172
173     if (!ug || !priv)
174         return;
175
176     /* close database */
177     memo_fini();
178
179     ugd = priv;
180
181     /* free theme */
182     elm_theme_extension_del(ugd->th, EDJ_FILE);
183     elm_theme_free(ugd->th);
184     ugd->th = NULL;
185
186     evas_object_del(ugd->base);
187     ugd->base = NULL;
188 }
189
190 static void on_message(struct ui_gadget *ug, bundle *msg, bundle *data, void *priv)
191 {
192 }
193
194 static void on_event(struct ui_gadget *ug, enum ug_event event, bundle *data, void *priv)
195 {
196     switch (event) {
197     case UG_EVENT_LOW_MEMORY:
198         break;
199     case UG_EVENT_LOW_BATTERY:
200         break;
201     case UG_EVENT_LANG_CHANGE:
202         break;
203     case UG_EVENT_ROTATE_PORTRAIT:
204         break;
205     case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
206         break;
207     case UG_EVENT_ROTATE_LANDSCAPE:
208         break;
209     case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
210         break;
211     default:
212         break;
213     }
214 }
215
216 static void on_key_event(struct ui_gadget *ug, enum ug_key_event event, bundle *data, void *priv)
217 {
218     if (!ug)
219         return;
220
221     switch (event) {
222     case UG_KEY_EVENT_END:
223         ug_destroy_me(ug);
224         break;
225     default:
226         break;
227     }
228 }
229
230 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
231 {
232     struct ug_data *ugd;
233
234     if (!ops)
235         return -1;
236
237     ugd = calloc(1, sizeof(struct ug_data));
238     if (!ugd)
239         return -1;
240
241     ops->create = on_create;
242     ops->start = on_start;
243     ops->pause = on_pause;
244     ops->resume = on_resume;
245     ops->destroy = on_destroy;
246     ops->message = on_message;
247     ops->event = on_event;
248     ops->key_event = on_key_event;
249     ops->priv = ugd;
250     ops->opt = UG_OPT_INDICATOR_ENABLE;
251
252     return 0;
253 }
254
255 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
256 {
257     struct ug_data *ugd;
258
259     if (!ops)
260         return;
261
262     ugd = ops->priv;
263     if (ugd)
264         free(ugd);
265 }