apply FSL license
[apps/home/settings.git] / setting-about / src / setting-about.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 <setting-about.h>
19 #ifndef UG_MODULE_API
20 #define UG_MODULE_API __attribute__ ((visibility("default")))
21 #endif
22
23 /**
24  * Event process when the sizeof UG view changes
25  */
26 static void setting_about_ug_cb_resize(void *data, Evas *e, Evas_Object *obj,
27                                        void *event_info)
28 {
29         SettingAboutUG *ad = (SettingAboutUG *) data;
30         setting_view_update(&setting_view_about_main, ad);
31 }
32
33 /**
34  * on_create function of the UG
35  */
36 static void *setting_about_ug_on_create(struct ui_gadget *ug, enum ug_mode mode,
37                                         bundle *data, void *priv)
38 {
39         SETTING_TRACE_BEGIN;
40         setting_retvm_if((NULL == ug
41                           || NULL == priv), NULL, "NULL == ug || NULL == priv");
42         SettingAboutUG *aboutUG = priv;
43         aboutUG->ug = ug;
44
45         aboutUG->win_main_layout = (Evas_Object *) ug_get_parent_layout(ug);
46         aboutUG->win_get = (Evas_Object *) ug_get_window();
47         evas_object_show(aboutUG->win_main_layout);
48         aboutUG->evas = evas_object_evas_get(aboutUG->win_main_layout);
49
50         setting_retvm_if(aboutUG->win_main_layout == NULL, NULL,
51                          "cannot get main window ");
52
53         /* register view node table */
54         setting_view_node_table_intialize();
55         setting_view_node_table_register(&setting_view_about_main, NULL);
56         
57         setting_view_node_table_register(&setting_view_about_licences,
58                                          &setting_view_about_main);
59         /* setting_view_node_table_register(&setting_view_about_about_view, &setting_view_about_main); */
60
61         /*  creating a view. */
62         setting_create_Gendial_itc("dialogue/1text", &(aboutUG->itc_1text));
63         setting_create_Gendial_itc("dialogue/2text.3", &(aboutUG->itc_2text_2));
64         setting_create_Gendial_itc("dialogue/title",
65                                    &(aboutUG->itc_group_item));
66         setting_create_Gendial_itc("dialogue/1icon", &(aboutUG->itc_1icon));
67         setting_create_Gendial_itc("dialogue/2text.3/expandable",
68                                    &(aboutUG->itc_2text_3_parent));
69         setting_create_Gendial_itc("dialogue/1text.1icon/expandable2",
70                                    &(aboutUG->itc_1icon_1text_sub));
71         setting_create_Gendial_itc("multiline/1text",
72                                    &(aboutUG->itc_help_style));
73
74         aboutUG->itc_seperator.item_style = "dialogue/separator/21/with_line";
75         aboutUG->itc_seperator.func.text_get = NULL;
76         aboutUG->itc_seperator.func.content_get = NULL;
77         aboutUG->itc_seperator.func.state_get = NULL;
78         aboutUG->itc_seperator.func.del = NULL;
79         setting_view_node_set_cur_view(&setting_view_about_main);
80         setting_view_create(&setting_view_about_main, (void *)aboutUG);
81         evas_object_event_callback_add(aboutUG->win_main_layout,
82                                        EVAS_CALLBACK_RESIZE,
83                                        setting_about_ug_cb_resize, aboutUG);
84
85         aboutUG->popup_showed_flag = FALSE;
86         return aboutUG->ly_main;
87 }
88
89 static void setting_about_ug_on_start(struct ui_gadget *ug, bundle *data,
90                                       void *priv)
91 {
92 }
93
94 static void setting_about_ug_on_pause(struct ui_gadget *ug, bundle *data,
95                                       void *priv)
96 {
97 }
98
99 static void setting_about_ug_on_resume(struct ui_gadget *ug, bundle *data,
100                                        void *priv)
101 {
102 }
103
104 /**
105  * on_destroy function of the UG
106  */
107 static void setting_about_ug_on_destroy(struct ui_gadget *ug, bundle *data,
108                                         void *priv)
109 {
110         SETTING_TRACE_BEGIN;
111         setting_retm_if((!ug || !priv), "!ug || !priv");
112         SettingAboutUG *aboutUG = priv;
113
114         evas_object_event_callback_del(aboutUG->win_main_layout, EVAS_CALLBACK_RESIZE, setting_about_ug_cb_resize);     /* fix flash issue for gallery */
115         aboutUG->ug = ug;
116         /*  delete the allocated objects. */
117         setting_view_destroy(&setting_view_about_licences,
118                                      aboutUG);
119         setting_view_destroy(&setting_view_about_main, aboutUG);
120         if (NULL != ug_get_layout(aboutUG->ug)) {
121                 evas_object_hide((Evas_Object *) ug_get_layout(aboutUG->ug));
122                 evas_object_del((Evas_Object *) ug_get_layout(aboutUG->ug));
123         }
124
125         SETTING_TRACE_END;
126 }
127
128 static void setting_about_ug_on_message(struct ui_gadget *ug, bundle *msg,
129                                         bundle *data, void *priv)
130 {
131         SETTING_TRACE_BEGIN;
132 }
133
134 static void setting_about_ug_on_event(struct ui_gadget *ug, enum ug_event event,
135                                       bundle *data, void *priv)
136 {
137         SETTING_TRACE_BEGIN;
138         switch (event) {
139         case UG_EVENT_LOW_MEMORY:
140                 break;
141         case UG_EVENT_LOW_BATTERY:
142                 break;
143         case UG_EVENT_LANG_CHANGE:
144                 break;
145         case UG_EVENT_ROTATE_PORTRAIT:
146                 break;
147         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
148                 break;
149         case UG_EVENT_ROTATE_LANDSCAPE:
150                 break;
151         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
152                 break;
153         case UG_EVENT_REGION_CHANGE:
154                 break;
155         default:
156                 break;
157         }
158 }
159
160 static void setting_about_ug_on_key_event(struct ui_gadget *ug,
161                                           enum ug_key_event event,
162                                           bundle *data, void *priv)
163 {
164         SETTING_TRACE_BEGIN;
165         SettingAboutUG *ad = (SettingAboutUG *) priv;
166         if (!ug)
167                 return;
168
169         switch (event) {
170         case UG_KEY_EVENT_END:
171                 {
172                         if (elm_naviframe_top_item_get(ad->navi_bar) ==
173                            elm_naviframe_bottom_item_get(ad->navi_bar)) {
174                                 ug_destroy_me(ug);
175                         } else {
176                                 /* elm_naviframe_item_pop(ad->navi_bar); */
177                                 setting_view_cb_at_endKey(ad);
178                         }
179                 }
180                 break;
181         default:
182                 break;
183         }
184 }
185
186 UG_MODULE_API int UG_MODULE_INIT(struct ug_module_ops *ops)
187 {
188         SETTING_TRACE_BEGIN;
189         SettingAboutUG *aboutUG = calloc(1, sizeof(SettingAboutUG));
190         setting_retvm_if(!aboutUG, -1, "Create SettingAboutUG obj failed");
191
192         ops->create = setting_about_ug_on_create;
193         ops->start = setting_about_ug_on_start;
194         ops->pause = setting_about_ug_on_pause;
195         ops->resume = setting_about_ug_on_resume;
196         ops->destroy = setting_about_ug_on_destroy;
197         ops->message = setting_about_ug_on_message;
198         ops->event = setting_about_ug_on_event;
199         ops->key_event = setting_about_ug_on_key_event;
200         ops->priv = aboutUG;
201         ops->opt = UG_OPT_INDICATOR_ENABLE;
202
203         return 0;
204 }
205
206 UG_MODULE_API void UG_MODULE_EXIT(struct ug_module_ops *ops)
207 {
208         SETTING_TRACE_BEGIN;
209         struct SettingAboutUG *aboutUG;
210         setting_retm_if(!ops, "ops == NULL");
211
212         aboutUG = ops->priv;
213         if (aboutUG) {
214                 FREE(aboutUG);
215         }
216 }
217
218 /* ***************************************************
219  **
220  **general func
221  **
222  ****************************************************/
223 void setting_about_layout_ug_cb(struct ui_gadget *ug, enum ug_mode mode,
224                                   void *priv)
225 {
226         SettingAboutUG *ad = (SettingAboutUG *) priv;
227         Evas_Object *base;
228
229         if (!ug || !priv)
230                 return;
231         SETTING_TRACE_BEGIN;
232
233         base = (Evas_Object *) ug_get_layout(ug);
234         if (!base)
235                 return;
236
237         switch (mode) {
238         case UG_MODE_FULLVIEW:
239                 evas_object_size_hint_weight_set(base, EVAS_HINT_EXPAND,
240                                                  EVAS_HINT_EXPAND);
241                 elm_win_resize_object_add(ad->win_get, base);
242                 evas_object_show(base);
243                 break;
244         default:
245                 break;
246         }
247
248         SETTING_TRACE_END;
249 }
250
251 /**
252 * Reset function to 'reset' the settings of the UG, it will be invoked by 'Reset' UG
253 *
254 * @param[in] data
255 * @param[in] priv
256 */
257 UG_MODULE_API int setting_plugin_reset(bundle *data, void *priv)
258 {
259         SETTING_TRACE_BEGIN;
260 #if SUPPORT_RUN_SYSTEM_COMMAND
261         return excuteCmd(SETTING_POSTINST_FILE, 1, "about");    
262 #else
263         return vconf_set_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR, "Tizen");
264 #endif
265 }
266
267