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