Initialize Tizen 2.3
[apps/home/ug-memo-efl.git] / src / memo-efl.c
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.1 (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://floralicense.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 #ifndef UG_MODULE_API
19 #define UG_MODULE_API __attribute__ ((visibility("default")))
20 #endif
21
22 #include <Elementary.h>
23 #include <ui-gadget-module.h>
24 #include <supplement.h>
25 #include <memo_ug.h>
26 #include "memo-efl.h"
27 #include "gravel.h"
28
29
30 static Evas_Object *create_fullview(Evas_Object *parent, struct ug_data *ugd)
31 {
32     Evas_Object *base;
33
34     base = elm_layout_add(parent);
35     if (!base)
36         return NULL;
37     elm_layout_theme_set(base, "layout", "application", "default");
38
39     /* set bg */
40     Evas_Object *bg = elm_bg_add(base);
41     evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
42     elm_object_part_content_set(base, "elm.swallow.bg", bg);
43
44     return base;
45 }
46
47 static Evas_Object *create_frameview(Evas_Object *parent, struct ug_data *ugd)
48 {
49     Evas_Object *base;
50
51     base = elm_layout_add(parent);
52     if (!base)
53         return NULL;
54     elm_layout_theme_set(base, "layout", "application", "default");
55
56     return base;
57 }
58
59 static Evas_Object *create_error_popup_layout(Evas_Object *parent, bool is_fullview)
60 {
61     Evas_Object *base;
62
63     base = elm_layout_add(parent);
64     if (!base)
65         return NULL;
66
67     if (is_fullview)
68         elm_layout_theme_set(base, "layout", "application", "default");
69     else
70         elm_layout_theme_set(base, "layout", "application", "noindicator");
71
72     evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
73
74     return base;
75 }
76
77 void memo_ug_hide_cb(void *data, Evas_Object *obj, void *event_info)
78 {
79         ug_destroy_me(data);
80 }
81
82 static void *on_create(ui_gadget_h ug, enum ug_mode mode, service_h service, void *priv)
83 {
84         Evas_Object *parent;
85         struct ug_data *ugd;
86         char *index = NULL;
87
88         if (!ug || !priv)
89                 return NULL;
90
91         ugd = priv;
92         ugd->ug = ug;
93
94         service_dump(service);
95
96         /* theme extension */
97         ugd->th = elm_theme_new();
98         elm_theme_ref_set(ugd->th, NULL);
99         elm_theme_extension_add(ugd->th, EDJ_FILE);
100
101         /* open database */
102         memo_init(NULL);
103
104         /* i18n */
105         bindtextdomain("memo", LOCALEDIR);
106
107         parent = ug_get_parent_layout(ug);
108         if (!parent)
109                 return NULL;
110
111         service_get_extra_data(service, "index", &index);
112         if (index != NULL) {/* legitimacy check of memo record */
113                 memo_data_t *md = memo_get_data(atoi(index));
114                 if (md == NULL) {
115                         if (mode == UG_MODE_FULLVIEW)
116                                 ugd->base = create_error_popup_layout(parent, TRUE);
117                         else
118                                 ugd->base = create_error_popup_layout(parent, FALSE);
119
120                         Evas_Object *popup;
121                         popup = elm_popup_add(ugd->base);
122                         evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
123                         elm_object_text_set(popup, dgettext("sys_string", "IDS_COM_POP_FILE_NOT_FOUND"));
124                         elm_popup_timeout_set(popup, 1.5);
125                         evas_object_show(popup);
126                         ugd->ug = ug;
127                         evas_object_smart_callback_add(popup, "timeout", memo_ug_hide_cb, ugd->ug);
128                         SFREE(index);
129                         return ugd->base;
130                 } else {
131                         memo_free_data(md);
132                 }
133         }
134
135         if (mode == UG_MODE_FULLVIEW)
136                 ugd->base = create_fullview(parent, ugd);
137         else
138                 ugd->base = create_frameview(parent, ugd);
139
140         if (ugd->base) {
141                 if (edit_view_pre_condition_check(service)) {
142                         ugd->h_ug = memo_load_edit_view(ugd, service);
143                 } else if (service_key_check(service, "type", "select")) {
144                         memo_load_select_view(ugd, service);
145                 } else if (index != NULL) {
146                         SFREE(index);
147                         memo_load_detail_view(ugd, service);
148                 } else {
149                         memo_load_select_view(ugd, service);
150                 }
151         }
152         SFREE(index);
153         return ugd->base;
154 }
155
156 static void on_start(ui_gadget_h ug, service_h service, void *priv)
157 {
158 }
159
160 static void on_pause(ui_gadget_h ug, service_h service, void *priv)
161 {
162
163 }
164
165 static void on_resume(ui_gadget_h ug, service_h service, void *priv)
166 {
167
168 }
169
170 static void on_destroy(ui_gadget_h ug, service_h service, void *priv)
171 {
172     struct ug_data *ugd;
173
174     if (!ug || !priv)
175         return;
176
177     /* close database */
178     memo_fini();
179
180     ugd = priv;
181
182     /* free theme */
183     elm_theme_extension_del(ugd->th, EDJ_FILE);
184     elm_theme_free(ugd->th);
185     ugd->th = NULL;
186
187     if (ugd->h_ug != NULL) {
188         memo_del_edit_view(ugd->h_ug);
189         ugd->h_ug = NULL;
190     }
191     evas_object_del(ugd->base);
192     ugd->base = NULL;
193 }
194
195 static void on_message(ui_gadget_h ug, service_h msg, service_h service, void *priv)
196 {
197 }
198
199 static void on_event(ui_gadget_h ug, enum ug_event event, service_h service, void *priv)
200 {
201     switch (event) {
202     case UG_EVENT_LOW_MEMORY:
203         break;
204     case UG_EVENT_LOW_BATTERY:
205         break;
206     case UG_EVENT_LANG_CHANGE:
207         break;
208     case UG_EVENT_ROTATE_PORTRAIT:
209         break;
210     case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
211         break;
212     case UG_EVENT_ROTATE_LANDSCAPE:
213         break;
214     case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
215         break;
216     default:
217         break;
218     }
219 }
220
221 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, service_h service, void *priv)
222 {
223     if (!ug)
224         return;
225
226     switch (event) {
227     case UG_KEY_EVENT_END:
228         ug_destroy_me(ug);
229         break;
230     default:
231         break;
232     }
233 }
234
235 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
236 {
237     struct ug_data *ugd;
238
239     if (!ops)
240         return -1;
241
242     ugd = calloc(1, sizeof(struct ug_data));
243     if (!ugd)
244         return -1;
245
246     ops->create = on_create;
247     ops->start = on_start;
248     ops->pause = on_pause;
249     ops->resume = on_resume;
250     ops->destroy = on_destroy;
251     ops->message = on_message;
252     ops->event = on_event;
253     ops->key_event = on_key_event;
254     ops->priv = ugd;
255     ops->opt = UG_OPT_INDICATOR_ENABLE;
256
257     return 0;
258 }
259
260 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
261 {
262     struct ug_data *ugd;
263
264     if (!ops)
265         return;
266
267     ugd = ops->priv;
268     if (ugd)
269         free(ugd);
270 }