Apply sip back key concept in composer
[apps/home/message-app.git] / composer / src / gadget / msg-ui-composer-gadget.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://floralicense.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
18 #include "msg-ui-composer-data.h"
19 #include "msg-ui-composer-main.h"
20 #include "msg-ui-composer-util.h"
21 #include "msg-ui-composer-common.h"
22 #include "msg-ui-composer-recipient.h"
23 #include <Ecore_X.h>
24 #include <system_info.h>
25
26 #ifndef UG_MODULE_API
27 #define UG_MODULE_API   __attribute__ ((visibility("default")))
28 #endif
29
30 int ref_count;
31
32 int msg_ui_composer_get_ref_count(void)
33 {
34         D_MSG("ref_count = %d", ref_count);
35         return ref_count;
36 }
37
38 void msg_ui_composer_increase_ref_count(void)
39 {
40         ++ref_count;
41         D_MSG("ref_count = %d", ref_count);
42 }
43
44 void msg_ui_composer_decrease_ref_count(void)
45 {
46         --ref_count;
47         D_MSG("ref_count = %d", ref_count);
48
49         if (ref_count < 0)
50                 ref_count = 0;
51 }
52
53 static void __base_layout_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
54 {
55         D_ENTER;
56
57         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
58
59         if (!cd)
60                 return;
61
62         msg_ui_composer_destroy(cd);
63
64         D_LEAVE;
65 }
66
67 static void *__msg_ui_composer_on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv)
68 {
69         D_ENTER;
70         MSG_COMPOSER_VIEW_DATA_S *cd;
71         int win_w = 0;
72         int win_h = 0;
73
74         if (ug == NULL || priv == NULL) {
75                 D_EMSG("ug = %p, priv = %p", ug, priv);
76                 return NULL;
77         }
78
79         bindtextdomain("message", LOCALEDIR);
80
81         cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
82         cd->ug = ug;
83
84         cd->main_window = ug_get_window();
85
86         if (cd->main_window == NULL) {
87                 D_EMSG("main window is NULL");
88                 return NULL;
89         }
90
91         ecore_x_window_size_get(ecore_x_window_root_first_get(), &win_w, &win_h);
92         cd->window_w = win_w;
93         cd->window_h = win_h;
94         D_MSG("screen width = %d, screen_height = %d", win_w, win_h);
95
96         cd->xdisplay = ecore_x_display_get();
97         if (cd->xdisplay == NULL)
98                 D_EMSG("ecore_x_display_get() is failed");
99
100         cd->indicator_mode = elm_win_indicator_mode_get(cd->main_window);
101         D_MSG("cd->indicator_mode = %d", cd->indicator_mode);
102
103         elm_win_indicator_mode_set(cd->main_window, ELM_WIN_INDICATOR_SHOW);
104
105         bool show_indicator = true;
106         char *indicator = NULL;
107
108         service_get_extra_data(data, MSG_BUNDLE_KEY_INDICATOR_MODE, &indicator);
109         if (indicator && g_strcmp0(indicator, MSG_BUNDLE_VALUE_NO_INDICATOR) == 0)
110                 show_indicator = false;
111
112         cd->base = msg_ui_composer_layout_create(cd->main_window, show_indicator);
113         if (cd->base == NULL) {
114                 D_EMSG("cd->base is NULL");
115                 return NULL;
116         }
117
118         char *from = NULL;
119         char *thread_id = NULL;
120         char *msg_id = NULL;
121         char *composer_mode = NULL;
122         char *operation = NULL;
123
124         cd->bg = msg_ui_composer_bg_create(cd->base);
125         elm_object_part_content_set(cd->base, "elm.swallow.bg", cd->bg);
126         elm_object_style_set(cd->bg, "edit_mode");
127
128         char *cvalue = NULL;
129         int ret = SYSTEM_INFO_ERROR_NONE;
130
131         ret = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &cvalue);
132         if (ret == SYSTEM_INFO_ERROR_NONE && cvalue != NULL) {
133                 if (g_strcmp0(cvalue, "Emulator") == 0)
134                         cd->isEmulator = true;
135         }
136
137         if (cvalue) {
138                 g_free(cvalue);
139                 cvalue = NULL;
140         }
141
142         if (service_get_operation(data, &operation) == SERVICE_ERROR_NONE && operation)
143                 cd->isAppControl = true;
144         else
145                 cd->isAppControl = false;
146
147         service_get_extra_data(data, MSG_BUNDLE_KEY_FROM, &from);
148
149         if (from && g_strcmp0(from, MSG_BUNDLE_VALUE_INTERNAL) == 0)
150                 cd->isMsgInternal = true;
151         else
152                 cd->isMsgInternal = false;
153
154         service_get_extra_data(data, MSG_BUNDLE_KEY_THREAD_ID, &thread_id);
155         service_get_extra_data(data, MSG_BUNDLE_KEY_MSG_ID, &msg_id);
156         service_get_extra_data(data, MSG_BUNDLE_KEY_MODE, &composer_mode);
157
158         if (composer_mode) {
159                 if (g_strcmp0(composer_mode, MSG_BUNDLE_VALUE_EDIT) == 0)
160                         cd->composer_mode = MSG_COMPOSER_MODE_EDIT;
161                 else if (g_strcmp0(composer_mode, MSG_BUNDLE_VALUE_FORWARD) == 0)
162                         cd->composer_mode = MSG_COMPOSER_MODE_FORWARD;
163                 else
164                         cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
165         } else {
166                 cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
167         }
168
169         if ((thread_id || msg_id) && (cd->composer_mode == MSG_COMPOSER_MODE_NORMAL)) {
170                 cd->msg_ug_mode = MSG_UG_MODE_BUBBLE_COMPOSER;
171         } else {
172                 if (cd->isMsgInternal == true) {
173                         cd->msg_ug_mode = MSG_UG_MODE_FULL_COMPOSER;
174                 } else {
175                         cd->msg_ug_mode = MSG_UG_MODE_ONLY_COMPOSER;
176                 }
177         }
178
179         D_MSG("UG MODE %d[Internal = %d], composer mode = %d", cd->msg_ug_mode, cd->isMsgInternal, cd->composer_mode);
180
181         cd->isFullview = true;
182
183         evas_object_event_callback_add(cd->base, EVAS_CALLBACK_DEL, __base_layout_delete_cb, cd);
184
185         if (msg_ui_composer_init(cd) != COMPOSER_RETURN_SUCCESS) {
186                 D_EMSG("msg_ui_composer_init error");
187                 evas_object_del(cd->base);
188
189                 return NULL;
190         }
191
192         if (msg_ui_composer_create(cd) != COMPOSER_RETURN_SUCCESS) {
193                 D_EMSG("creating main layout failed");
194                 evas_object_del(cd->base);
195
196                 return NULL;
197         }
198
199         if (cd->base)
200                 msg_ui_composer_increase_ref_count();
201
202         return cd->base;
203 }
204
205 static void __msg_ui_composer_on_start(ui_gadget_h ug, service_h data, void *priv)
206 {
207         D_ENTER;
208
209         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
210
211         msg_ui_composer_start(cd, data);
212
213         msg_common_apply_font_size("bubble", cd->content_layout);
214         msg_ui_composer_apply_font_size(cd, true);
215
216         D_LEAVE;
217 }
218
219 static void __msg_ui_composer_on_pause(ui_gadget_h ug, service_h data, void *priv)
220 {
221         D_ENTER;
222         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
223         D_MSG_RETM_IF(cd == NULL, "Composer data is NULL");
224         D_MSG_RETM_IF(cd->state == COMPOSER_STATE_TYPE_DESTROY, "Composer state is already Destroy");
225
226         cd->state = COMPOSER_STATE_TYPE_PAUSE;
227         /* discoonect volume key handler */
228         msg_ui_composer_disconnect_handler(cd);
229
230         if (cd->bubble_data) {
231                 cd->bubble_data->ug_state = BUBBLE_UG_PAUSE;
232         }
233
234         D_LEAVE;
235 }
236
237 static void __msg_ui_composer_on_resume(ui_gadget_h ug, service_h data, void *priv)
238 {
239         D_ENTER;
240         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
241         D_MSG_RETM_IF(cd == NULL, "Composer data is NULL");
242         D_MSG_RETM_IF(cd->state == COMPOSER_STATE_TYPE_DESTROY, "Composer state is already Destroy");
243
244         if (!cd->loaded_ug)
245                 msg_common_apply_font_size("bubble", cd->content_layout);
246
247         msg_ui_composer_apply_font_size(cd, true);
248
249         /* coonect volume key handler */
250         msg_ui_composer_connect_handler(cd);
251
252         cd->state = COMPOSER_STATE_TYPE_RUNNING;
253         cd->loaded_aul = FALSE;
254         /* reset hide_keypad_op */
255         cd->hide_keypad_op = false;
256
257         if (cd->bubble_data) {
258                 cd->bubble_data->ug_state = BUBBLE_UG_START;
259
260                 msg_ui_bubble_list_update_read_status(cd->bubble_data);
261         }
262
263         if (cd->recipient)
264                 msg_ui_composer_recipient_update(cd->recipient);
265
266         D_LEAVE;
267 }
268
269 static void __msg_ui_composer_on_destroy(ui_gadget_h ug, service_h data, void *priv)
270 {
271         D_ENTER;
272
273         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
274         D_MSG_RETM_IF(cd == NULL, "Composer data is NULL");
275         D_MSG_RETM_IF(cd->state == COMPOSER_STATE_TYPE_DESTROY, "Composer state is already Destroy");
276
277         cd->state = COMPOSER_STATE_TYPE_DESTROY;
278         cd->isclosed = true;
279
280         if (cd->bubble_data)
281                 cd->bubble_data->ug_state = BUBBLE_UG_DESTROY;
282
283         msg_ui_bubble_deinit_bubble_data(cd->bubble_data);
284
285         if (cd->base) {
286                 evas_object_del(cd->base);
287                 cd->base = NULL;
288         }
289
290         D_LEAVE;
291 }
292
293 static void __msg_ui_composer_on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
294 {
295         D_ENTER;
296
297         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
298         if (msg)
299                 msg_ui_composer_reset_request(cd, msg);
300
301         D_LEAVE;
302 }
303
304
305 static void __msg_ui_composer_on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
306 {
307         D_ENTER;
308
309         switch (event) {
310         case UG_EVENT_LOW_MEMORY:
311                 break;
312         case UG_EVENT_LOW_BATTERY:
313                 break;
314         case UG_EVENT_LANG_CHANGE:
315                 msg_ui_composer_change_language(priv);
316                 break;
317         case UG_EVENT_ROTATE_PORTRAIT:
318                 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_PORTRAIT);
319                 break;
320         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
321                 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_PORTRAIT_UPSIDEDOWN);
322                 break;
323         case UG_EVENT_ROTATE_LANDSCAPE:
324                 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_LANDSCAPE);
325                 break;
326         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
327                 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_LANDSCAPE_UPSIDEDOWN);
328                 break;
329         default:
330                 break;
331         }
332 }
333
334 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
335 {
336         if (ops == NULL) {
337                 D_EMSG("[ERROR] OPS is null");
338                 return COMPOSER_RETURN_FAIL;
339         }
340
341         MSG_COMPOSER_VIEW_DATA_S *cd = NULL;
342         cd = (MSG_COMPOSER_VIEW_DATA_S *)calloc(1, sizeof(MSG_COMPOSER_VIEW_DATA_S));
343
344         if (!cd) {
345                 D_EMSG("[ERROR] cd calloc failed");
346                 return COMPOSER_RETURN_FAIL;
347         }
348
349         ops->create = __msg_ui_composer_on_create;
350         ops->start = __msg_ui_composer_on_start;
351         ops->pause = __msg_ui_composer_on_pause;
352         ops->resume = __msg_ui_composer_on_resume;
353         ops->destroy = __msg_ui_composer_on_destroy;
354         ops->message = __msg_ui_composer_on_message;
355         ops->event = __msg_ui_composer_on_event;
356         ops->key_event = NULL;
357         ops->priv = (void *)cd;
358         ops->opt = UG_OPT_INDICATOR_MANUAL;
359
360         return MSG_UI_RET_SUCCESS;
361 }
362
363 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
364 {
365         if (ops == NULL) {
366                 D_EMSG( "[ERROR] OPS is null");
367                 return;
368         }
369
370         MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)ops->priv;
371
372         if (cd) {
373                 free(cd);
374                 ops->priv = NULL;
375         }
376
377         D_LEAVE;
378 }