Seperated net-popup plugin and wearable-popup plugin
[platform/core/connectivity/stc-manager.git] / plugin / wearable-popup / stc-popup / src / stc-wearable-popup.c
1 #include "stc-wearable-popup.h"
2
3 typedef struct appdata {
4         Evas_Object *win;
5         Evas_Object *conform;
6         Evas_Object *label;
7 } appdata_s;
8
9 static void
10 win_delete_request_cb(void *data, Evas_Object *obj, void *event_info)
11 {
12         ui_app_exit();
13 }
14
15 static void
16 win_back_cb(void *data, Evas_Object *obj, void *event_info)
17 {
18         appdata_s *ad = data;
19         /* Let window go to hide state. */
20         elm_win_lower(ad->win);
21 }
22
23 static void
24 create_base_gui(appdata_s *ad)
25 {
26         /* Window */
27         /* Create and initialize elm_win.
28            elm_win is mandatory to manipulate window. */
29         ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
30         elm_win_autodel_set(ad->win, EINA_TRUE);
31
32         if (elm_win_wm_rotation_supported_get(ad->win)) {
33                 int rots[4] = { 0, 90, 180, 270 };
34                 elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
35         }
36
37         evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
38         eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
39
40         /* Conformant */
41         /* Create and initialize elm_conformant.
42            elm_conformant is mandatory for base gui to have proper size
43            when indicator or virtual keypad is visible. */
44         ad->conform = elm_conformant_add(ad->win);
45         elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
46         elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
47         evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
48         elm_win_resize_object_add(ad->win, ad->conform);
49         evas_object_show(ad->conform);
50
51         /* Label */
52         /* Create an actual view of the base gui.
53            Modify this part to change the view. */
54         ad->label = elm_label_add(ad->conform);
55         elm_object_text_set(ad->label, "<align=center>Hello Tizen</align>");
56         evas_object_size_hint_weight_set(ad->label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
57         elm_object_content_set(ad->conform, ad->label);
58
59         /* Show window after base gui is set up */
60         evas_object_show(ad->win);
61 }
62
63 static bool
64 app_create(void *data)
65 {
66         /* Hook to take necessary actions before main event loop starts
67                 Initialize UI resources and application's data
68                 If this function returns true, the main loop of application starts
69                 If this function returns false, the application is terminated */
70         appdata_s *ad = data;
71
72         create_base_gui(ad);
73
74         return true;
75 }
76
77 static void
78 app_control(app_control_h app_control, void *data)
79 {
80         /* Handle the launch request. */
81 }
82
83 static void
84 app_pause(void *data)
85 {
86         /* Take necessary actions when application becomes invisible. */
87 }
88
89 static void
90 app_resume(void *data)
91 {
92         /* Take necessary actions when application becomes visible. */
93 }
94
95 static void
96 app_terminate(void *data)
97 {
98         /* Release all resources. */
99 }
100
101 static void
102 ui_app_lang_changed(app_event_info_h event_info, void *user_data)
103 {
104         /*APP_EVENT_LANGUAGE_CHANGED*/
105         char *locale = NULL;
106         system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
107         elm_language_set(locale);
108         free(locale);
109         return;
110 }
111
112 static void
113 ui_app_orient_changed(app_event_info_h event_info, void *user_data)
114 {
115         /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
116         return;
117 }
118
119 static void
120 ui_app_region_changed(app_event_info_h event_info, void *user_data)
121 {
122         /*APP_EVENT_REGION_FORMAT_CHANGED*/
123 }
124
125 static void
126 ui_app_low_battery(app_event_info_h event_info, void *user_data)
127 {
128         /*APP_EVENT_LOW_BATTERY*/
129 }
130
131 static void
132 ui_app_low_memory(app_event_info_h event_info, void *user_data)
133 {
134         /*APP_EVENT_LOW_MEMORY*/
135 }
136
137 int
138 main(int argc, char *argv[])
139 {
140         appdata_s ad = {0,};
141         int ret = 0;
142
143         ui_app_lifecycle_callback_s event_callback = {0,};
144         app_event_handler_h handlers[5] = {NULL, };
145
146         event_callback.create = app_create;
147         event_callback.terminate = app_terminate;
148         event_callback.pause = app_pause;
149         event_callback.resume = app_resume;
150         event_callback.app_control = app_control;
151
152         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, &ad);
153         ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, &ad);
154         ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
155         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, &ad);
156         ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, &ad);
157
158         ret = ui_app_main(argc, argv, &event_callback, &ad);
159         if (ret != APP_ERROR_NONE) {
160                 dlog_print(DLOG_ERROR, LOG_TAG, "app_main() is failed. err = %d", ret);
161         }
162
163         return ret;
164 }