2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license
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.
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"
24 #include <system_info.h>
27 #define UG_MODULE_API __attribute__ ((visibility("default")))
32 int msg_ui_composer_get_ref_count(void)
34 D_MSG("ref_count = %d", ref_count);
38 void msg_ui_composer_increase_ref_count(void)
41 D_MSG("ref_count = %d", ref_count);
44 void msg_ui_composer_decrease_ref_count(void)
47 D_MSG("ref_count = %d", ref_count);
53 static void __base_layout_delete_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
57 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)data;
62 msg_ui_composer_destroy(cd);
67 static void *__msg_ui_composer_on_create(ui_gadget_h ug, enum ug_mode mode, service_h data, void *priv)
70 MSG_COMPOSER_VIEW_DATA_S *cd;
74 if (ug == NULL || priv == NULL) {
75 D_EMSG("ug = %p, priv = %p", ug, priv);
79 bindtextdomain("message", LOCALEDIR);
81 cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
84 cd->main_window = ug_get_window();
86 if (cd->main_window == NULL) {
87 D_EMSG("main window is NULL");
91 ecore_x_window_size_get(ecore_x_window_root_first_get(), &win_w, &win_h);
94 D_MSG("screen width = %d, screen_height = %d", win_w, win_h);
96 cd->xdisplay = ecore_x_display_get();
97 if (cd->xdisplay == NULL)
98 D_EMSG("ecore_x_display_get() is failed");
100 cd->indicator_mode = elm_win_indicator_mode_get(cd->main_window);
101 D_MSG("cd->indicator_mode = %d", cd->indicator_mode);
103 elm_win_indicator_mode_set(cd->main_window, ELM_WIN_INDICATOR_SHOW);
105 bool show_indicator = true;
106 char *indicator = NULL;
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;
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");
119 char *thread_id = NULL;
121 char *composer_mode = NULL;
122 char *operation = NULL;
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");
129 int ret = SYSTEM_INFO_ERROR_NONE;
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;
142 if (service_get_operation(data, &operation) == SERVICE_ERROR_NONE && operation)
143 cd->isAppControl = true;
145 cd->isAppControl = false;
147 service_get_extra_data(data, MSG_BUNDLE_KEY_FROM, &from);
149 if (from && g_strcmp0(from, MSG_BUNDLE_VALUE_INTERNAL) == 0)
150 cd->isMsgInternal = true;
152 cd->isMsgInternal = false;
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);
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;
164 cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
166 cd->composer_mode = MSG_COMPOSER_MODE_NORMAL;
169 if ((thread_id || msg_id) && (cd->composer_mode == MSG_COMPOSER_MODE_NORMAL)) {
170 cd->msg_ug_mode = MSG_UG_MODE_BUBBLE_COMPOSER;
172 if (cd->isMsgInternal == true) {
173 cd->msg_ug_mode = MSG_UG_MODE_FULL_COMPOSER;
175 cd->msg_ug_mode = MSG_UG_MODE_ONLY_COMPOSER;
179 D_MSG("UG MODE %d[Internal = %d], composer mode = %d", cd->msg_ug_mode, cd->isMsgInternal, cd->composer_mode);
181 cd->isFullview = true;
183 evas_object_event_callback_add(cd->base, EVAS_CALLBACK_DEL, __base_layout_delete_cb, cd);
185 if (msg_ui_composer_init(cd) != COMPOSER_RETURN_SUCCESS) {
186 D_EMSG("msg_ui_composer_init error");
187 evas_object_del(cd->base);
192 if (msg_ui_composer_create(cd) != COMPOSER_RETURN_SUCCESS) {
193 D_EMSG("creating main layout failed");
194 evas_object_del(cd->base);
200 msg_ui_composer_increase_ref_count();
205 static void __msg_ui_composer_on_start(ui_gadget_h ug, service_h data, void *priv)
209 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
211 msg_ui_composer_start(cd, data);
213 msg_common_apply_font_size("bubble", cd->content_layout);
214 msg_ui_composer_apply_font_size(cd, true);
219 static void __msg_ui_composer_on_pause(ui_gadget_h ug, service_h data, void *priv)
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");
226 cd->state = COMPOSER_STATE_TYPE_PAUSE;
227 /* discoonect volume key handler */
228 msg_ui_composer_disconnect_handler(cd);
230 if (cd->bubble_data) {
231 cd->bubble_data->ug_state = BUBBLE_UG_PAUSE;
237 static void __msg_ui_composer_on_resume(ui_gadget_h ug, service_h data, void *priv)
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");
245 msg_common_apply_font_size("bubble", cd->content_layout);
247 msg_ui_composer_apply_font_size(cd, true);
249 /* coonect volume key handler */
250 msg_ui_composer_connect_handler(cd);
252 cd->state = COMPOSER_STATE_TYPE_RUNNING;
253 cd->loaded_aul = FALSE;
255 if (cd->bubble_data) {
256 cd->bubble_data->ug_state = BUBBLE_UG_START;
258 msg_ui_bubble_list_update_read_status(cd->bubble_data);
262 msg_ui_composer_recipient_update(cd->recipient);
267 static void __msg_ui_composer_on_destroy(ui_gadget_h ug, service_h data, void *priv)
271 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
272 D_MSG_RETM_IF(cd == NULL, "Composer data is NULL");
273 D_MSG_RETM_IF(cd->state == COMPOSER_STATE_TYPE_DESTROY, "Composer state is already Destroy");
275 cd->state = COMPOSER_STATE_TYPE_DESTROY;
279 cd->bubble_data->ug_state = BUBBLE_UG_DESTROY;
281 msg_ui_bubble_deinit_bubble_data(cd->bubble_data);
284 evas_object_del(cd->base);
291 static void __msg_ui_composer_on_message(ui_gadget_h ug, service_h msg, service_h data, void *priv)
295 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)priv;
297 msg_ui_composer_reset_request(cd, msg);
303 static void __msg_ui_composer_on_event(ui_gadget_h ug, enum ug_event event, service_h data, void *priv)
308 case UG_EVENT_LOW_MEMORY:
310 case UG_EVENT_LOW_BATTERY:
312 case UG_EVENT_LANG_CHANGE:
313 msg_ui_composer_change_language(priv);
315 case UG_EVENT_ROTATE_PORTRAIT:
316 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_PORTRAIT);
318 case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
319 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_PORTRAIT_UPSIDEDOWN);
321 case UG_EVENT_ROTATE_LANDSCAPE:
322 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_LANDSCAPE);
324 case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
325 msg_ui_composer_rotate(priv, COMPOSER_ROTATE_LANDSCAPE_UPSIDEDOWN);
332 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
335 D_EMSG("[ERROR] OPS is null");
336 return COMPOSER_RETURN_FAIL;
339 MSG_COMPOSER_VIEW_DATA_S *cd = NULL;
340 cd = (MSG_COMPOSER_VIEW_DATA_S *)calloc(1, sizeof(MSG_COMPOSER_VIEW_DATA_S));
343 D_EMSG("[ERROR] cd calloc failed");
344 return COMPOSER_RETURN_FAIL;
347 ops->create = __msg_ui_composer_on_create;
348 ops->start = __msg_ui_composer_on_start;
349 ops->pause = __msg_ui_composer_on_pause;
350 ops->resume = __msg_ui_composer_on_resume;
351 ops->destroy = __msg_ui_composer_on_destroy;
352 ops->message = __msg_ui_composer_on_message;
353 ops->event = __msg_ui_composer_on_event;
354 ops->key_event = NULL;
355 ops->priv = (void *)cd;
356 ops->opt = UG_OPT_INDICATOR_MANUAL;
358 return MSG_UI_RET_SUCCESS;
361 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
364 D_EMSG( "[ERROR] OPS is null");
368 MSG_COMPOSER_VIEW_DATA_S *cd = (MSG_COMPOSER_VIEW_DATA_S *)ops->priv;