4a3f1bc424a078653ed466abbc5d68d5eebafe55
[apps/core/preloaded/myfiles.git] / src / mf-main.c
1 /*
2  * Copyright 2013         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
19
20 #include <stdio.h>
21 #include <sys/time.h>
22 #include <glib.h>
23 #include <vconf.h>
24 #include <media_content.h>
25 #include <app.h>
26 #include <Elementary.h>
27 #ifdef MYFILE_MOTION_FEATURE
28 #include "mf-sensor.h"
29 #endif
30
31
32 #include "mf-main.h"
33 #include "mf-conf.h"
34 #include "mf-dlog.h"
35 #include "mf-util.h"
36 #include "mf-callback.h"
37 #include "mf-widget.h"
38 #include "mf-gadget.h"
39 #include "mf-fm-svc-wrapper.h"
40 #include "mf-ta.h"
41 #include "mf-log.h"
42 #include "mf-otg.h"
43 #include "mf-launch.h"
44 #include "mf-language-mgr.h"
45 #include "mf-s-beam.h"
46
47 #define MF_B_KEY_PATH "path"
48
49 GString *phone_folder_as_param;
50
51 static bool __mf_main_create_app(void *data);
52 static void __mf_main_terminate_app(void *data);
53 static void __mf_main_stop_app(void *data);
54 static void __mf_main_resume_app(void *data);
55 static void __mf_main_reset_app(service_h service, void *data);
56 static void __mf_main_storage_status_get(void *data);
57
58 static void __mf_main_data_init(void *data)
59 {
60         MF_TRACE_BEGIN;
61         mf_retm_if(data == NULL, "data is NULL");
62
63         struct appdata *ap = (struct appdata *)data;
64         /*set state value for create content*/
65         ap->mf_Status.more = MORE_DEFAULT;
66         ap->mf_Status.path = g_string_new(PHONE_FOLDER);
67         ap->mf_SharedGadget.ug = NULL;
68         ap->mf_Status.iStorageState = MYFILE_PHONE;
69         ap->mf_Status.iFolderSortType = MYFILE_SORT_BY_DATE_R2O;
70         ap->mf_Status.flagLCDLock = EINA_FALSE;
71         ap->mf_Status.rotation_type = MF_ROTATE_PORTRAIT;
72         ap->mf_Status.flagNaviPush = EINA_FALSE;
73
74         /* region format related */
75         ap->mf_Status.flagIcuInit = FALSE;
76         ap->mf_Status.generator = NULL;
77         ap->mf_Status.formatter = NULL;
78         ap->mf_Status.flagRootView = EINA_TRUE;
79         ap->mf_Status.flagIME = EINA_TRUE;
80         ap->mf_Status.view_type = mf_view_root;
81         ap->mf_Status.preViewType = mf_view_root;
82         mf_util_get_vconf_value(VCONF_TYPE_NFC_ENABLE, &ap->mf_Status.iNFCState);
83         mf_util_get_vconf_value(VCONF_TYPE_VIEW_STYLE, &ap->mf_Status.flagViewType);
84         mf_util_get_vconf_value(VCONF_TYPE_EXTENSION_STATE, &ap->mf_Status.iExtensionState);
85
86         MF_TRACE_END;
87
88 }
89
90 /******************************
91 ** Prototype    : mf_main_load_edj
92 ** Description  :
93 ** Input        : Evas_Object *parent
94 **                const char *file
95 **                const char *group
96 ** Output       : None
97 ** Return Value :
98 ** Calls        :
99 ** Called By    :
100 **
101 **  History        :
102 **  1.Date         : 2010/12/10
103 **    Author       : Samsung
104 **    Modification : Created function
105 **
106 ******************************/
107 Evas_Object *mf_main_load_edj(Evas_Object * parent, const char *file, const char *group)
108 {
109         mf_debug();
110         Evas_Object *eo;
111         int r;
112
113         eo = elm_layout_add(parent);
114         elm_object_focus_set(eo, EINA_FALSE);
115         if (eo) {
116                 r = elm_layout_file_set(eo, file, group);
117                 if (!r) {
118                         evas_object_del(eo);
119                         return NULL;
120                 }
121
122                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
123         }
124
125         return eo;
126 }
127
128 #ifdef MYFILE_MOTION_FEATURE
129 static void __mf_app_doubletap_cb(unsigned long long timestamp, void *data)
130 {
131         MF_TRACE_BEGIN;
132         mf_widget_first_item_bring_in(data);
133 }
134 #endif
135
136 /******************************
137 ** Prototype    : __mf_main_del_win
138 ** Description  :
139 ** Input        : void *data
140 **                Evas_Object *obj
141 **                void *event
142 ** Output       : None
143 ** Return Value :
144 ** Calls        :
145 ** Called By    :
146 **
147 **  History        :
148 **  1.Date         : 2010/12/10
149 **    Author       : Samsung
150 **    Modification : Created function
151 **
152 ******************************/
153 static void __mf_main_del_win(void *data, Evas_Object * obj, void *event)
154 {
155         elm_exit();
156 }
157
158 /******************************
159 ** Prototype    : __mf_main_create_win
160 ** Description  :
161 ** Input        : const char *name
162 ** Output       : None
163 ** Return Value :
164 ** Calls        :
165 ** Called By    :
166 **
167 **  History        :
168 **  1.Date         : 2010/12/10
169 **    Author       : Samsung
170 **    Modification : Created function
171 **
172 ******************************/
173 static Evas_Object *__mf_main_create_win(const char *name)
174 {
175         mf_debug();
176         Evas_Object *eo;
177         int w, h;
178         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
179         elm_object_focus_set(eo, EINA_FALSE);
180         elm_win_autodel_set(eo, 1);
181         if (eo) {
182                 elm_win_title_set(eo, name);
183                 evas_object_smart_callback_add(eo, "delete,request", __mf_main_del_win, NULL);
184                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
185                 evas_object_resize(eo, w, h);
186         }
187         if (eo) {
188                 evas_object_show(eo);
189                 return eo;
190         } else {
191                 return NULL;
192         }
193 }
194
195
196 static Evas_Object *__mf_main_create_bg(Evas_Object *win)
197 {
198         mf_retv_if(win == NULL, NULL);
199         Evas_Object *bg = elm_bg_add(win);
200         elm_object_focus_set(bg, EINA_FALSE);
201
202         evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
203
204         elm_win_resize_object_add(win, bg);
205
206         evas_object_show(bg);
207
208         return bg;
209 }
210
211
212 /******************************
213 ** Prototype    : __mf_main_capture_idle_img
214 ** Description  :
215 ** Input        : void *data
216 ** Output       : None
217 ** Return Value :
218 ** Calls        :
219 ** Called By    :
220 **
221 **  History        :
222 **  1.Date         : 2010/12/10
223 **    Author       : Samsung
224 **    Modification : Created function
225 **
226 ******************************/
227
228 static int __mf_main_check_path_vaild(const char *dir, int *dir_type)
229 {
230         mf_retvm_if(dir == NULL, -1, "dir is NULL");
231         mf_retvm_if(dir_type == NULL, -1, "state is NULL");
232
233         if (g_file_test(dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)
234             && strncmp(dir, ".", 1)) {
235                 if (strncmp(dir, PHONE_FOLDER, strlen(PHONE_FOLDER)) == 0) {
236                         *dir_type = MYFILE_PHONE;
237                 } else if (strncmp(dir, MEMORY_FOLDER, strlen(MEMORY_FOLDER)) == 0) {
238                         *dir_type = MYFILE_MMC;
239 #ifdef MYFILE_USB_OTG
240                 } else if (strncmp(dir, OTG_FOLDER, strlen(OTG_FOLDER)) == 0){
241                         *dir_type = MYFILE_OTG;
242 #endif
243                 }else {
244                         *dir_type = MYFILE_NONE;
245                 }
246         } else {
247                 *dir_type = MYFILE_NONE;
248         }
249         return 0;
250 }
251
252 static void __mf_main_bundle_parse(service_h service, void *data)
253 {
254         MF_TRACE_BEGIN;
255         assert(data);
256
257         struct appdata *ap = (struct appdata *)data;
258
259         service_get_extra_data (service, "path", &ap->mf_Bundle.path);
260         service_get_extra_data (service, "select_type", &ap->mf_Bundle.select_type);
261         service_get_extra_data (service, "file_type", &ap->mf_Bundle.file_type);
262         service_get_extra_data (service, "marked_mode", &ap->mf_Bundle.marked_mode);
263         service_get_extra_data (service, "drm_type", &ap->mf_Bundle.drm_type);
264         MF_TRACE_END;
265 }
266
267 static void __mf_main_view_create(void *data)
268 {
269         MF_TRACE_BEGIN;
270         assert(data);
271         MF_TA_ACUM_ITEM_BEGIN("        mf_main_view_create", 0);
272         struct appdata *ap = (struct appdata *)data;
273         //MF_TA_ACUM_ITEM_END("  create_to_reset", 0);
274
275         //create phone navibar struct
276
277         MF_TA_ACUM_ITEM_BEGIN("    mf_widget_refresh_view", 0);
278         mf_widget_refresh_view(ap);
279         MF_TA_ACUM_ITEM_END("    mf_widget_refresh_view", 0);
280         MF_TA_ACUM_ITEM_END("        mf_main_view_create", 0);
281
282 }
283
284 Eina_Bool __mf_main_prop_change(void *data, int ev_type, void *ev)
285 {
286
287         MF_TRACE_BEGIN;
288         assert(data);
289         Ecore_X_Event_Window_Property *event = ev;
290
291         if (event->win != ecore_x_window_root_first_get())
292                 return ECORE_CALLBACK_PASS_ON;
293
294         if (event->atom != ecore_x_atom_get("FONT_TYPE_change")) {
295                 return ECORE_CALLBACK_PASS_ON;
296         }
297
298         return ECORE_CALLBACK_PASS_ON;
299 }
300
301 static Eina_Bool
302 __mf_main_app_init_idler_cb(void *data)
303 {
304         MF_TRACE_BEGIN;
305         assert(data);
306         struct appdata *ap = (struct appdata *)data;
307         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_app_init_idler_cb", 0);
308
309
310         SAFE_FREE_ECORE_EVENT(ap->mf_MainWindow.font_event);
311
312         ap->mf_MainWindow.font_event = ecore_event_handler_add(ECORE_X_EVENT_WINDOW_PROPERTY,
313                                                                 __mf_main_prop_change,
314                                                                 ap);
315
316         SAFE_FREE_ECORE_EVENT(ap->mf_MainWindow.event);
317         ap->mf_MainWindow.event = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
318                                 (Ecore_Event_Handler_Cb)mousedown_cb, ap);
319
320         //MF_TA_ACUM_ITEM_BEGIN("    mmc callback set", 0);
321         mf_callback_set_mmc_state_cb(ap);
322         //MF_TA_ACUM_ITEM_END("    mmc callback set", 0);
323 #ifdef MYFILE_USB_OTG
324         //MF_TA_ACUM_ITEM_BEGIN("    otg callback set", 0);
325         mf_callback_set_otg_state_cb(ap);
326         //MF_TA_ACUM_ITEM_END("    otg callback set", 0);
327 #endif
328         ap->mf_Status.app_init_idler = NULL;
329
330         if (mf_sbeam_init()) {
331                 mf_sbeam_set_callback(mf_callback_sbeam_cb, ap);
332         }
333
334 #ifdef MYFILE_MOTION_FEATURE
335         if(!mf_sensor_init()){
336                 if(!mf_sensor_set_callback(MF_MOTION_DOUBLETAP, __mf_app_doubletap_cb, ap)){
337                         mf_sensor_start(MF_MOTION_DOUBLETAP);
338                 }
339         }
340         ap->mf_Status.doubletab_event_handler = mf_callback_motion_double_tap;
341 #endif
342         efreet_mime_init();
343
344         MF_TA_ACUM_ITEM_END("    __mf_main_app_init_idler_cb", 0);
345
346         return ECORE_CALLBACK_CANCEL;
347 }
348
349 static int __mf_main_remake_app(service_h service, void *data)
350 {
351         MF_TRACE_BEGIN;
352         assert(data);
353         MF_TA_ACUM_ITEM_BEGIN("      mf_main_remake_app", 0);
354         struct appdata *ap = (struct appdata *)data;
355         MF_TA_ACUM_ITEM_BEGIN("      check mass storage state", 0);
356
357         /*if myfile state is not normal,  it is not handled argument*/
358         if (ap->mf_Status.more != MORE_DEFAULT) {
359                 mf_warnig("Fail to handle budle, current myfiles stat is %d", ap->mf_Status.more);
360                 goto RAISE_WIN;
361         }
362         MF_TA_ACUM_ITEM_END("      check mass storage state", 0);
363         MF_TA_ACUM_ITEM_BEGIN("      __mf_main_view_create", 0);
364
365         __mf_main_view_create(ap);
366         MF_TA_ACUM_ITEM_END("      __mf_main_view_create", 0);
367
368 RAISE_WIN:
369
370 /**************pre-condition test to launch myfile app******************/
371         MF_TA_ACUM_ITEM_END("      mf_main_remake_app", 0);
372
373         MF_TA_ACUM_ITEM_END(" Myfiles Launch Time", 0);
374         return 0;
375
376 }
377
378
379 /*      system operation callbacks      */
380 /******************************
381 ** Prototype    : _keydown_event
382 ** Description  :
383 ** Input        : void *data
384 **                int type
385 **                void *event
386 ** Output       : None
387 ** Return Value :
388 ** Calls        :
389 ** Called By    :
390 **
391 **  History        :
392 **  1.Date         : 2010/12/10
393 **    Author       : Samsung
394 **    Modification : Created function
395 **
396 ******************************/
397 #define TEMP_ENDKEY_ROLLBACK
398 #if 0
399 static Eina_Bool __mf_main_keydown_event_callback(void *data, int type, void *event)
400 {
401         Ecore_Event_Key *ev = event;
402         struct appdata *ap = (struct appdata *)data;
403         mf_retvm_if(ev == NULL, ECORE_CALLBACK_RENEW, "Ecore_Event_Key is NULL");
404         mf_retvm_if(ap == NULL, ECORE_CALLBACK_RENEW, "appdata is NULL");
405
406         if (!strcmp(ev->keyname, KEY_END)) {
407 #ifdef TEMP_ENDKEY_ROLLBACK
408                 if (ap->mf_Status.more != MORE_DEFAULT) {
409                         if (ap->mf_MainWindow.pProgressPopup != NULL) {
410                                 if (ap->mf_Status.more == MORE_DATA_COPYING
411                                     || ap->mf_Status.more == MORE_DATA_MOVING
412                                     || ap->mf_Status.more == MORE_DELETE || ap->mf_Status.more == MORE_IDLE_DELETE) {
413                                         mf_callback_progress_bar_cancel_cb(ap, NULL, NULL);
414                                 }
415                         }
416                 }
417                 if (ap->mf_FileOperation.search_IME_hide_timer != NULL) {
418                         ecore_timer_del(ap->mf_FileOperation.search_IME_hide_timer);
419                         ap->mf_FileOperation.search_IME_hide_timer = NULL;
420                 }
421                 elm_exit();
422 #else
423                 mf_debug();
424                 if (ap->mf_SharedGadget.ug != NULL) {
425                         mf_debug();
426                         ug_send_key_event(UG_KEY_EVENT_END);
427                 } else {
428                         if (ap->mf_MainWindow.pContextPopup != NULL) {
429                                 mf_debug();
430                                 evas_object_del(ap->mf_MainWindow.pContextPopup);
431                                 ap->mf_MainWindow.pContextPopup = NULL;
432                         } else {
433                                 if (ap->mf_Status.more == MORE_DEFAULT) {
434                                         mf_debug();
435                                         if (mf_fm_svc_wrapper_is_root_path(ap->mf_Status.path->str)) {
436                                                 elm_exit();
437                                         } else {
438                                                 mf_callback_upper_folder_cb(ap);
439                                         }
440                                 } else {
441                                         if (ap->mf_MainWindow.pNormalPopup == NULL) {
442                                                 mf_callback_cancel_cb(ap, NULL, NULL);
443                                         } else {
444                                                 if (ap->mf_Status.more ==
445                                                     MORE_DATA_COPYING
446                                                     || ap->mf_Status.more ==
447                                                     MORE_DATA_MOVING || ap->mf_Status.more == MORE_DELETE || ap->mf_Status.more == MORE_IDLE_DELETE) {
448                                                         mf_callback_progress_bar_cancel_cb(ap, NULL, NULL);
449                                                 }
450                                         }
451                                 }
452                         }
453
454                 }
455 #endif
456         }
457         return ECORE_CALLBACK_RENEW;
458 }
459 #endif
460 /******************************
461 ** Prototype    : __mf_main_create_app
462 ** Description  :
463 ** Input        : void *data
464 ** Output       : None
465 ** Return Value :
466 ** Calls        :
467 ** Called By    :
468 **
469 **  History        :
470 **  1.Date         : 2010/12/10
471 **    Author       : Samsung
472 **    Modification : Created function
473 **
474 ******************************/
475 static void __mf_main_storage_status_get(void *data)
476 {
477         mf_retm_if(data == NULL, "data is NULL");
478         struct appdata *ap = (struct appdata*)data;
479         int mmc_card = 0;
480         int error_code = 0;
481
482         MF_TA_ACUM_ITEM_BEGIN("      storage check", 0);
483         error_code = mf_util_is_mmc_on(&mmc_card);
484         if (error_code == 0 && mmc_card == 1) {
485                 ap->mf_Status.iStorageState |= MYFILE_MMC;
486         }
487         /*check if usb otg mounted */
488 #ifdef MYFILE_USB_OTG
489         int otg = 0;
490         error_code = mf_util_is_otg_on(&otg);
491         mf_debug("error code is %d, org is %d", error_code, otg);
492         if (error_code == 0 && otg == 1) {
493                 mf_debug();
494                 ap->mf_Status.iStorageState |= MYFILE_OTG;
495         }
496 #endif
497         MF_TA_ACUM_ITEM_END("      storage check", 0);
498 }
499
500 bool __mf_main_create_app(void *data)
501 {
502         MF_TRACE_BEGIN;
503         struct appdata *ap = (struct appdata *)data;
504         int ret = 0;
505
506         MF_TA_ACUM_ITEM_END("  main-to-create", 0);
507
508
509         MF_TA_ACUM_ITEM_BEGIN("    g_thread_init", 0);
510         if (!g_thread_supported()) {
511                 g_thread_init(NULL);
512         }
513         MF_TA_ACUM_ITEM_END("    g_thread_init", 0);
514         MF_TA_ACUM_ITEM_BEGIN("  __mf_main_create_app", 0);
515
516         MF_TA_ACUM_ITEM_BEGIN("    mf_language_mgr_create", 0);
517         mf_language_mgr_create();
518         MF_TA_ACUM_ITEM_END("    mf_language_mgr_create", 0);
519
520
521         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_data_init", 0);
522         __mf_main_data_init(ap);
523         MF_TA_ACUM_ITEM_END("    __mf_main_data_init", 0);
524
525         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_create_win", 0);
526
527         ap->mf_MainWindow.pWindow = __mf_main_create_win(PACKAGE);
528         mf_retvm_if(ap->mf_MainWindow.pWindow == NULL, -1, "Fail to __mf_main_create_win()");
529
530         evas_object_geometry_get(ap->mf_MainWindow.pWindow, NULL, NULL, &ap->mf_MainWindow.root_w, &ap->mf_MainWindow.root_h);
531
532         MF_TA_ACUM_ITEM_END("    __mf_main_create_win", 0);
533
534 #ifdef MYFILE_SPLIT_VIEW
535         if(mf_util_is_rotation_lock() == 0) {
536                 mf_debug("rotation is locked");
537                 ap->mf_Status.rotation_type = MF_ROTATE_PORTRAIT;
538                 ap->mf_Status.rotation_angle = 0;
539         } else {
540                 app_device_orientation_e  rotate_mode;
541
542                 rotate_mode = app_get_device_orientation();
543
544                 mf_util_rotate_state_set(ap, rotate_mode);
545         }
546
547
548 #endif
549
550         /**************start to launch myfile app******************/
551
552
553         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_create_bg", 0);
554         ap->mf_MainWindow.pBackGround = __mf_main_create_bg(ap->mf_MainWindow.pWindow);
555         MF_TA_ACUM_ITEM_END("    __mf_main_create_bg", 0);
556
557         ap->mf_MainWindow.pConformant = mf_widget_create_conform(ap->mf_MainWindow.pWindow);
558         elm_win_resize_object_add(ap->mf_MainWindow.pWindow, ap->mf_MainWindow.pConformant);
559
560         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_create_layout_main", 0);
561         ap->mf_MainWindow.pMainLayout = mf_widget_create_layout_main(ap->mf_MainWindow.pConformant);
562         MF_TA_ACUM_ITEM_END("    __mf_main_create_layout_main", 0);
563
564         elm_object_content_set(ap->mf_MainWindow.pConformant, ap->mf_MainWindow.pMainLayout);
565         elm_win_conformant_set(ap->mf_MainWindow.pWindow, EINA_TRUE);
566         elm_win_indicator_mode_set(ap->mf_MainWindow.pWindow, ELM_WIN_INDICATOR_SHOW);
567
568         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_storage_status_get", 0);
569         __mf_main_storage_status_get(ap);
570         MF_TA_ACUM_ITEM_END("    __mf_main_storage_status_get", 0);
571
572
573         MF_TA_ACUM_ITEM_BEGIN("    create phone naviframe struct", 0);
574         mf_widget_phone_storage_init(ap);
575         MF_TA_ACUM_ITEM_END("    create phone naviframe struct", 0);
576
577         //create landscape/portrait view
578         MF_TA_ACUM_ITEM_BEGIN("    mf_widget_create", 0);
579         mf_widget_create(ap);
580         MF_TA_ACUM_ITEM_END("    mf_widget_create", 0);
581
582         MF_TA_ACUM_ITEM_BEGIN("    set_view_to_mainlayout", 0);
583
584
585         elm_object_part_content_set(ap->mf_MainWindow.pMainLayout, "elm.swallow.content", ap->mf_MainWindow.pNaviBar);
586 #ifdef MYFILE_SPLIT_VIEW
587         mf_widget_set_main_layout_content(ap);
588 #endif
589         MF_TA_ACUM_ITEM_END("    set_view_to_mainlayout", 0);
590
591
592         /*Create content frame of Main Layout*/
593         MF_TA_ACUM_ITEM_BEGIN("    media_content_connect", 0);
594         ret = media_content_connect();
595         mf_retvm_if(ret < 0, -1, "Fail to media_content_connect()");
596         MF_TA_ACUM_ITEM_END("    media_content_connect", 0);
597
598
599         MF_TA_ACUM_ITEM_BEGIN("    mf_callback_create_dir_monitor", 0);
600         ret = mf_callback_create_dir_monitor(ap);
601         mf_retvm_if(ret < 0, -1, "Fail to mf_callback_create_dir_monitor()");
602         MF_TA_ACUM_ITEM_END("    mf_callback_create_dir_monitor", 0);
603
604         MF_TA_ACUM_ITEM_BEGIN("    app_init_idler", 0);
605         ap->mf_Status.app_init_idler = ecore_idler_add(__mf_main_app_init_idler_cb, ap);
606         MF_TA_ACUM_ITEM_END("    app_init_idler", 0);
607
608         evas_object_smart_callback_add(ap->mf_MainWindow.pWindow, "profile,changed", mf_callback_profile_changed_cb, ap);
609
610         MF_TA_ACUM_ITEM_END("  __mf_main_create_app", 0);
611         MF_TA_ACUM_ITEM_BEGIN("  create_to_reset", 0);
612
613         MF_TRACE_END;
614
615         ap->mf_Status.b_run_background = false; /* 20121008 added for fix PLM P121001-0404 temporary */
616
617         return true;
618 }
619
620 static void __mf_main_reset_app(service_h service, void *data)
621 {
622         MF_TRACE_BEGIN;
623         MF_TA_ACUM_ITEM_END("  create_to_reset", 0);
624
625
626         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_reset_app", 0);
627         struct appdata *ap = (struct appdata *)data;
628         char *operation = NULL;
629
630         MF_TA_ACUM_ITEM_BEGIN("    service_get_operation", 0);
631
632         service_get_operation(service, &operation);
633         MF_TA_ACUM_ITEM_END("    service_get_operation", 0);
634
635
636         if (g_strcmp0(operation, SERVICE_OPERATION_PICK) == 0) {
637                 __mf_main_bundle_parse(service, ap);
638                 /*launch myfile ug here*/
639                 ap->mf_SharedGadget.ug = mf_launch_load_ug_myfile(ap);
640
641                 service_clone(&ap->mf_Bundle.recv_service, service);
642         } else {
643                 mf_debug();
644                 char *launch_type_str = NULL;
645                 service_get_extra_data(service, "launch-type", &launch_type_str);
646                 if(launch_type_str &&!strcasecmp(launch_type_str, "shortcut")) {
647                         SAFE_FREE_CHAR(ap->mf_Bundle.path);
648                         SAFE_FREE_CHAR(ap->mf_Bundle.select_type);
649                         SAFE_FREE_CHAR(ap->mf_Bundle.file_type);
650                         SAFE_FREE_CHAR(ap->mf_Bundle.marked_mode);
651                         SAFE_FREE_CHAR(ap->mf_Bundle.drm_type);
652                         ap->mf_Bundle.path = g_strdup(PHONE_FOLDER);
653                         ap->mf_Bundle.select_type = g_strdup("SHORTCUT");
654                         ap->mf_SharedGadget.ug = mf_launch_load_ug_myfile(ap);
655                         SAFE_FREE_CHAR(ap->mf_Bundle.path);
656                         SAFE_FREE_CHAR(ap->mf_Bundle.select_type);
657                 } else {
658                         mf_debug();
659                         char *uri = NULL;
660                         service_get_extra_data (service, "path", &uri);
661                         mf_debug("======== uri is [%s]", uri);
662                         if (uri && ecore_file_exists(uri)) {
663                                 MF_TA_ACUM_ITEM_BEGIN("    otg_launch", 0);
664                                 myfileNaviBar *pNavi_s_toshow = NULL;
665                                 myfileNaviBar *pNavi_s_inuse = NULL;
666                                 Evas_Object *pNaviBar = NULL;
667                                 ap->mf_Status.view_type = mf_view_normal;
668                                 pNavi_s_inuse = mf_navi_bar_get_in_use(ap);
669                                 if (pNavi_s_inuse == NULL || pNavi_s_inuse->pNaviLabel == NULL) {
670                                         MF_TRACE_END;
671                                         return;
672                                 }
673
674                                 int locate = mf_fm_svc_wrapper_get_location(uri);
675                                 char *storage = NULL;
676                                 switch (locate) {
677                                 case MYFILE_PHONE:
678                                         storage = GET_SYS_STR(MF_LABEL_PHONE);
679                                         break;
680                                 case MYFILE_MMC:
681                                         storage = GET_SYS_STR(MF_LABEL_MMC);
682                                         break;
683                                 case MYFILE_OTG:
684                                         storage = GET_STR(MF_LABEL_OTG);
685                                 default:
686                                         break;
687                                 }
688
689
690                                 pNavi_s_inuse->naviFlagInUse = FALSE;
691
692                                 pNaviBar = ap->mf_MainWindow.pNaviBar;
693                                 pNavi_s_toshow = mf_navi_bar_get_navi_from_navilist(ap->mf_MainWindow.plistNaviBar, storage);
694
695                                 if (pNavi_s_toshow == NULL) {
696                                         /*2.0   get root path by storage label */
697                                         char *rootpath = g_strdup(uri);
698                                         if (rootpath == NULL) {
699                                                 MF_TRACE_END;
700                                                 return;
701                                         }
702                                         /*2.1   create the navi for the tab */
703                                         pNavi_s_toshow = malloc(sizeof(myfileNaviBar));
704                                         if (pNavi_s_toshow == NULL) {
705                                                 free(rootpath);
706                                                 rootpath = NULL;
707                                                 mf_debug("pNavi_s_toshow is NULL");
708                                                 MF_TRACE_END;
709                                                 return;
710                                         }
711                                         memset(pNavi_s_toshow, 0, sizeof(myfileNaviBar));
712
713                                         pNavi_s_toshow->naviFlagInUse = TRUE;
714                                         /*2.2   set path as root path of the storage */
715                                         pNavi_s_toshow->pCurrentPath = g_strdup(rootpath);
716                                         pNavi_s_toshow->pNaviLabel = g_strdup(storage);
717                                         free(rootpath);
718                                         /*2.3   insert phone navi into the navi_list */
719                                         ap->mf_MainWindow.plistNaviBar = eina_list_append(ap->mf_MainWindow.plistNaviBar, pNavi_s_toshow);
720
721                                         if (ap->mf_Status.path != NULL) {
722                                                 g_string_free(ap->mf_Status.path, TRUE);
723                                                 ap->mf_Status.path = NULL;
724                                         }
725                                         ap->mf_Status.path = g_string_new(pNavi_s_toshow->pCurrentPath);
726                                         __mf_main_remake_app(service, ap);
727                                         MF_TRACE_END;
728
729                                 } else {
730                                         mf_debug();
731                                         /*2.1   get the navi of the tab */
732                                         pNavi_s_toshow = mf_navi_bar_get_struct_by_label(ap, storage);
733                                         pNavi_s_toshow->naviFlagInUse = TRUE;
734
735                                         /*2.2   set related status value. */
736                                         if (ap->mf_Status.path != NULL) {
737                                                 g_string_free(ap->mf_Status.path, TRUE);
738                                                 ap->mf_Status.path = NULL;
739                                         }
740                                         ap->mf_Status.path = g_string_new(uri);
741                                         SAFE_FREE_CHAR(pNavi_s_toshow->pCurrentPath);
742                                         pNavi_s_toshow->pCurrentPath = g_strdup(uri);
743                                         mf_debug();
744                                         /*2.3   update the content to catch update */
745                                         /*Todo: How to ensure insert only once */
746                                         __mf_main_remake_app(service, ap);
747                                         mf_debug();
748                                         mf_navi_bar_remove_previous_contents(ap, ap->mf_MainWindow.pNaviBar);
749                                         MF_TRACE_END;
750                                 }
751                                 MF_TA_ACUM_ITEM_END("    otg_launch", 0);
752
753                         }else {
754
755                                 /* 20121008 added for fix PLM P121001-0404 temporary { */
756                                 if (ap->mf_MainWindow.pWindow != NULL && ap->mf_Status.b_run_background)
757                                 {
758                                         elm_win_activate(ap->mf_MainWindow.pWindow);
759                                         ap->mf_Status.b_run_background = false;
760                                         return;
761                                 }
762                                 /* 20121008 added for fix PLM P121001-0404 temporary } */
763                                 MF_TA_ACUM_ITEM_BEGIN("    __mf_main_remake_app", 0);
764                                 __mf_main_remake_app(service, ap);
765                                 MF_TA_ACUM_ITEM_END("    __mf_main_remake_app", 0);
766                         }
767                 }
768         }
769
770         if (ap->mf_MainWindow.pWindow) {
771                 evas_object_show(ap->mf_MainWindow.pWindow);
772                 elm_win_activate(ap->mf_MainWindow.pWindow);
773         }
774         MF_TA_ACUM_ITEM_END("    __mf_main_reset_app", 0);
775
776 }
777
778 static void __mf_main_resume_app(void *data)
779 {
780         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_resume_app", 0);
781         MF_TRACE_BEGIN;
782         mf_retm_if(data == NULL, "data is NULL");
783 #ifdef MYFILE_SPLIT_VIEW
784         struct appdata *ap = (struct appdata *)data;
785         if (!mf_util_is_rotation_lock()) {
786                 ap->mf_Status.rotation_type = MF_ROTATE_PORTRAIT;
787                 ap->mf_Status.rotation_angle = 0;
788
789                 mf_callback_app_rotate_cb(APP_DEVICE_ORIENTATION_0, ap);
790
791         } else {
792                 app_device_orientation_e mode = APP_DEVICE_ORIENTATION_0 ;
793                 mode = app_get_device_orientation();
794                 if (mode != ap->mf_Status.rotation_type)
795                         mf_callback_app_rotate_cb(mode, ap);
796         }
797         if (ap->mf_MainWindow.pWindow) {
798                 evas_object_show(ap->mf_MainWindow.pWindow);
799         }
800 #endif
801         mf_sbeam_enable();
802         MF_TA_ACUM_ITEM_END("    __mf_main_resume_app", 0);
803 }
804
805 /******************************
806 ** Prototype    : __mf_main_terminate_app
807 ** Description  :
808 ** Input        : void *data
809 ** Output       : None
810 ** Return Value :
811 ** Calls        :
812 ** Called By    :
813 **
814 **  History        :
815 **  1.Date         : 2010/12/10
816 **    Author       : Samsung
817 **    Modification : Created function
818 **
819 ******************************/
820 void __mf_main_terminate_app(void *data)
821 {
822         MF_TRACE_BEGIN;
823         struct appdata *ap = (struct appdata *)data;
824         assert(ap);
825
826         media_content_disconnect();
827         efreet_mime_shutdown();
828
829         if (ap->mf_Status.search_handler)
830                 mf_search_finalize(&ap->mf_Status.search_handler);
831
832         mf_callback_destory_dir_monitor(ap);
833
834         mf_ecore_idler_del(ap->mf_Status.app_init_idler);
835         mf_ecore_idler_del(ap->mf_Status.popup_del_idler);
836         mf_ecore_idler_del(ap->mf_Status.navi_content_idler);
837         SAFE_DEL_ECORE_TIMER(ap->mf_MainWindow.pPopupTimer);
838         SAFE_FREE_ECORE_EVENT(ap->mf_MainWindow.event);
839         SAFE_FREE_ECORE_EVENT(ap->mf_MainWindow.font_event);
840
841 #ifdef MYFILE_MOTION_FEATURE
842         mf_sensor_finalize();
843 #endif
844
845         MF_TA_ACUM_ITEM_SHOW_RESULT_TO(MF_TA_SHOW_FILE);
846         MF_TA_RELEASE();
847 #ifdef MYFILE_USB_OTG
848         mf_otg_finalize(ap);
849 #endif
850
851 #ifdef MYFILE_CRITICAL_LOG
852         mf_log_finalize();
853 #endif
854         mf_sbeam_finalize();
855
856 #ifdef MYFILE_SPLIT_VIEW
857         SAFE_FREE_OBJ(ap->mf_MainWindow.sSplitData.pPanes);
858 #endif
859         if (ap->mf_FileOperation.job_pop_list != NULL) {        /*job callback must not run before*/
860                 mf_util_clear_handler_list(ap);
861                 ap->mf_FileOperation.job_pop_list = NULL;
862         }
863
864         if (ap->mf_FileOperation.job_push != NULL) {    /*job callback must not run before*/
865                 ecore_job_del(ap->mf_FileOperation.job_push);
866                 ap->mf_FileOperation.job_push = NULL;
867         }
868
869         if (ap->mf_Status.flagIcuInit == TRUE)
870                 mf_util_icu_finalize(ap);
871
872         if (ap->mf_FileOperation.sync_pipe) {
873                 ecore_pipe_del(ap->mf_FileOperation.sync_pipe);
874                 ap->mf_FileOperation.sync_pipe = NULL;
875         }
876         mf_util_set_pm_lock(ap, EINA_FALSE);
877         mf_language_mgr_destroy();
878 }
879
880 /******************************
881 ** Prototype    : __mf_main_stop_app
882 ** Description  :
883 ** Input        : void *data
884 ** Output       : None
885 ** Return Value :
886 ** Calls        :
887 ** Called By    :
888 **
889 **  History        :
890 **  1.Date         : 2010/12/10
891 **    Author       : Samsung
892 **    Modification : Created function
893 **
894 ******************************/
895 void __mf_main_stop_app(void *data)
896 {
897         MF_TA_ACUM_ITEM_BEGIN("    __mf_main_stop_app", 0);
898         MF_TRACE_BEGIN;
899         struct appdata *ap = (struct appdata *)data;
900         assert(ap);
901
902         /*check if phone navi is empty*/
903         if (mf_launch_myfile_ug_exist(ap)) {
904                 /*if myfile ug exists, delete the ug*/
905                 if (ap->mf_SharedGadget.ug != NULL) {
906                         ug_destroy(ap->mf_SharedGadget.ug);
907                         ap->mf_SharedGadget.ug = NULL;
908                 }
909
910                 /*terminate the process*/
911                 elm_exit();
912         } else {
913                 if (ap->mf_SharedGadget.ug != NULL) {
914                         ug_destroy(ap->mf_SharedGadget.ug);
915                         ap->mf_SharedGadget.ug = NULL;
916                 }
917         }
918
919         mf_sbeam_disable();
920         MF_TA_ACUM_ITEM_END("    __mf_main_stop_app", 0);
921
922 }
923
924 /******************************
925 ** Prototype    : main
926 ** Description  :
927 ** Input        : int argc
928 **                char *argv[]
929 ** Output       : None
930 ** Return Value :
931 ** Calls        :
932 ** Called By    :
933 **
934 **  History        :
935 **  1.Date         : 2010/12/10
936 **    Author       : Samsung
937 **    Modification : Created function
938 **
939 ******************************/
940 static void __mf_language_changed_cb(void *user_data)
941 {
942         mf_language_mgr_update();
943 }
944
945 int main(int argc, char *argv[])
946 {
947         app_event_callback_s ops;
948         struct appdata ad;
949
950         MF_TA_INIT();
951         MF_TA_ACUM_ITEM_BEGIN(" Myfiles Launch Time", 0);
952         MF_TA_ACUM_ITEM_BEGIN("  main", 0);
953
954 #ifdef MYFILE_CRITICAL_LOG
955         int ret = mf_log_init();
956         if (ret != MYFILE_ERR_NONE)
957                 mf_debug("initialize critical log failed");
958 #endif
959
960         memset(&ops, 0x0, sizeof(app_event_callback_s));
961         memset(&ad, 0x0, sizeof(struct appdata));
962
963         ops.create = __mf_main_create_app;
964         ops.terminate = __mf_main_terminate_app;
965         ops.pause = __mf_main_stop_app;
966         ops.resume = __mf_main_resume_app;
967         ops.service = __mf_main_reset_app;
968         ops.device_orientation = mf_callback_app_rotate_cb;
969         ops.region_format_changed  = mf_callback_icu_update_cb;
970         ops.language_changed = __mf_language_changed_cb;
971
972         MF_TA_ACUM_ITEM_END("  main", 0);
973         MF_TA_ACUM_ITEM_BEGIN("  main-to-create", 0);
974         return app_efl_main(&argc, &argv, &ops, &ad);
975 }