apply FSL(Flora Software License)
[apps/home/calculator.git] / src / calc-main.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
18 #include <app.h>
19 #include <dlog.h>
20 #include <Ecore_X.h>            /* ecore_x_window_size_get */
21 #include <utilX.h>              /* KEY_END */
22 #include <svi.h>
23 #include "calc-main.h"
24 #include "calc-view.h"
25
26 extern char calculator_input_str[];
27 extern int calculator_cursor_pos;
28
29 static int max_fontsize = 67;
30 extern void calc_xxx(struct appdata *ap);       /* will be removed */
31
32 Evas_Object *load_edj(Evas_Object * parent, const char *file, const char *group)
33 {
34         Evas_Object *eo;
35         int r;
36         eo = elm_layout_add(parent);
37         if (eo) {
38                 r = elm_layout_file_set(eo, file, group);
39                 if (!r) {
40                         evas_object_del(eo);
41                         return NULL;
42                 }
43                 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
44                                                  EVAS_HINT_EXPAND);
45         }
46         return eo;
47 }
48
49 /**
50 * @describe
51 *
52 *
53 * @param    ad
54 * @param    angle
55 * @return    void
56 * @exception
57 */
58 static void _to_portrait(struct appdata *ad, int angle)
59 {
60         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
61         edje_object_signal_emit(_EDJ(ad->edje), "portrait", "");
62         elm_win_rotation_with_resize_set(ad->win, angle);
63         elm_win_rotation_with_resize_set(ad->eo, angle);/*when rotating, resize the window eo*/
64         max_fontsize = 67;
65 }
66
67 int get_max_fontsize()
68 {
69         return max_fontsize;
70 }
71
72 /**
73 * @describe
74 *
75 *
76 * @param    data
77 * @param    obj
78 * @param    event_info
79 * @return    void
80 * @exception
81 */
82 static void _win_del(void *data, Evas_Object * obj, void *event_info)
83 {
84         elm_exit();
85 }
86
87 #if 0
88 /**
89 * @describe
90 *
91 *
92 * @param    data
93 * @return    int
94 * @exception
95 */
96 static int _capture_idle_image(void *data)
97 {
98         struct appdata *ad = (struct appdata *)data;
99
100         char name[128];
101         //snprintf(name, sizeof(name), COM_SAMSUNG_S, PACKAGE);
102         snprintf(name, sizeof(name), "com.%s.%s", VENDOR, PACKAGE);
103         Evas *evas = evas_object_evas_get(ad->win);
104
105         if (ui_idlecapture_exists(name) == EINA_FALSE) {
106                 ui_idlecapture_set(evas, name);
107         }
108
109         return ECORE_CALLBACK_CANCEL;   //0
110 }
111 #endif
112 /**
113 * @describe
114 *
115 *
116 * @param    data
117 * @return    int
118 * @exception
119 */
120 static int _set_input_entry_focus(void *data)
121 {
122         struct appdata *ad = (struct appdata *)data;
123         elm_object_focus_set(ad->input_entry, EINA_TRUE);       //set focus
124         _calc_entry_clear(ad->input_entry);
125
126         return ECORE_CALLBACK_CANCEL;   //0
127 }
128
129 /**
130 * @describe
131 *
132 *
133 * @param    data
134 * @return    int
135 * @exception
136 */
137 static int _load_idle_view(void *data)
138 {
139         struct appdata *ad = (struct appdata *)data;
140         calc_view_load_in_idle(ad);
141
142         return ECORE_CALLBACK_CANCEL;   //0
143 }
144
145 /**
146 * @describe
147 *
148 *
149 * @param    name
150 * @return    Evas_Object*
151 * @exception
152 */
153 static Evas_Object *_create_win(const char *name)
154 {
155         Evas_Object *eo;
156         int w, h;
157         eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
158         if (eo) {
159                 elm_win_title_set(eo, name);
160                 elm_win_borderless_set(eo, EINA_TRUE);
161                 evas_object_smart_callback_add(eo, "delete,request", _win_del,
162                                                NULL);
163                 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w,
164                                         &h);
165                 evas_object_resize(eo, w, h);
166         }
167         return eo;
168 }
169
170 /**
171 * @describe
172 *
173 *
174 * @param    ad
175 * @return    void
176 * @exception
177 */
178 static void _on_exit(struct appdata *ad)
179 {
180         //ui_bgimg_fini_noti();
181
182         if (ad->popup) {
183                 evas_object_del(ad->popup);
184                 ad->popup = NULL;
185         }
186
187         if (ad->por_pannel) {
188                 evas_object_del(ad->por_pannel);
189                 ad->por_pannel = NULL;
190         }
191
192         if (ad->lan_pannel) {
193                 evas_object_del(ad->lan_pannel);
194                 ad->lan_pannel = NULL;
195         }
196
197         if (ad->input_entry) {
198                 evas_object_del(ad->input_entry);
199                 ad->input_entry = NULL;
200         }
201 #ifdef SAVE_HISTORY
202         if (ad->hist_area) {
203                 evas_object_del(ad->hist_area);
204                 ad->hist_area = NULL;
205         }
206
207         if (ad->hist_scroll) {
208                 evas_object_del(ad->hist_scroll);
209                 ad->hist_scroll = NULL;
210         }
211 #endif
212
213         if (ad->edje) {
214                 evas_object_del(ad->edje);
215                 ad->edje = NULL;
216         }
217
218         if (ad->layout) {
219                 evas_object_del(ad->layout);
220                 ad->layout = NULL;
221         }
222
223         if (ad->win) {
224                 evas_object_del(ad->win);
225                 ad->win = NULL;
226         }
227
228         /* delete timer */
229         if (ad->calc_timer) {
230                 ecore_timer_del(ad->calc_timer);
231                 ad->calc_timer = NULL;
232         }
233         if (ad->svi_handle) {
234                 svi_fini(ad->svi_handle);
235         }
236 }
237
238 static bool app_launch(void *data)
239 {
240         CONV_FUNC_IN();
241         struct appdata *ad = (struct appdata *)data;
242
243         /*      Use elm_theme_extension_add() API before creating any widgets */
244         //elm_theme_overlay_add(NULL, CALCULATOR_THEME);
245         elm_theme_extension_add(NULL, CALCULATOR_THEME);
246
247         /* main widnow */
248         ad->win = _create_win(PACKAGE);
249         if (ad->win == NULL) {
250                 return FALSE;
251         }
252         evas_object_show(ad->win);
253
254         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
255
256         /* will be removed */
257         calc_xxx(ad);
258
259         /* load main view */
260         calc_view_load(ad);
261         _to_portrait(ad, 0);
262
263         /* register callback */
264         //ecore_idler_add((Ecore_Task_Cb)_capture_idle_image, ad);
265         ecore_idler_add((Ecore_Task_Cb) _set_input_entry_focus, ad);
266         ecore_idler_add((Ecore_Task_Cb) _load_idle_view, ad);
267
268         CONV_FUNC_OUT();
269         return TRUE;            //EXIT_SUCCESS
270 }
271
272 /**
273 * @describe
274 *
275 *
276 * @param    data
277 * @return    int
278 * @exception
279 */
280 static bool app_create(void *data)
281 {
282         return TRUE;            //EXIT_SUCCESS
283 }
284
285 /**
286 * @describe
287 *
288 *
289 * @param    data
290 * @return    int
291 * @exception
292 */
293 static void app_terminate(void *data)
294 {
295         struct appdata *ad = (struct appdata *)data;
296         _on_exit(ad);
297 }
298
299 /**
300 * @describe
301 *
302 *
303 * @param    data
304 * @return    int
305 * @exception
306 */
307 static void app_pause(void *data)
308 {
309         // Take necessary actions when application becomes invisible
310 }
311
312 /**
313 * @describe
314 *
315 *
316 * @param    data
317 * @return    int
318 * @exception
319 */
320 static void app_resume(void *data)
321 {
322         // Take necessary actions when application becomes visible.
323 }
324
325 static void app_service(service_h service, void *data)
326 {
327         CONV_FUNC_IN();
328         struct appdata *ad = (struct appdata *)data;
329
330         if (ad->win != NULL) { /* calculator has already launced. */
331                 elm_win_activate(ad->win);
332                 return;
333         }
334         app_launch(ad);
335         evas_object_show(ad->win);
336         CONV_FUNC_OUT();
337 }
338
339
340 /**
341 * @describe
342 *   The entry of the program
343 *
344 * @param    argc
345 * @param    argv
346 * @param    int
347 * @exception
348 */
349 int main(int argc, char *argv[])
350 {
351         struct appdata ad;
352
353         app_event_callback_s event_callback;
354
355         event_callback.create = app_create;
356         event_callback.terminate = app_terminate;
357         event_callback.pause = app_pause;
358         event_callback.resume = app_resume;
359         event_callback.service = app_service;
360         event_callback.low_memory = NULL;
361         event_callback.low_battery = NULL;
362         event_callback.device_orientation = NULL;
363         event_callback.language_changed = NULL;
364         event_callback.region_format_changed = NULL;
365
366         memset(&ad, 0x0, sizeof(struct appdata));
367
368         return app_efl_main(&argc, &argv, &event_callback, &ad);
369 }
370